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/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
66 #include "gdb_string.h"
67 #include "gdb_assert.h"
68 #include <sys/types.h>
75 #define MAP_FAILED ((void *) -1)
79 typedef struct symbol *symbolp;
82 /* When non-zero, dump DIEs after they are read in. */
83 static int dwarf2_die_debug = 0;
85 /* When non-zero, cross-check physname against demangler. */
86 static int check_physname = 0;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info;
96 static const struct objfile_data *dwarf2_objfile_data_key;
98 struct dwarf2_section_info
103 /* Not NULL if the section was actually mmapped. */
105 /* Page aligned size of mmapped area. */
106 bfd_size_type map_len;
107 /* True if we have tried to read this section. */
111 typedef struct dwarf2_section_info dwarf2_section_info_def;
112 DEF_VEC_O (dwarf2_section_info_def);
114 /* All offsets in the index are of this type. It must be
115 architecture-independent. */
116 typedef uint32_t offset_type;
118 DEF_VEC_I (offset_type);
120 /* A description of the mapped index. The file format is described in
121 a comment by the code that writes the index. */
124 /* Index data format version. */
127 /* The total length of the buffer. */
130 /* A pointer to the address table data. */
131 const gdb_byte *address_table;
133 /* Size of the address table data in bytes. */
134 offset_type address_table_size;
136 /* The symbol table, implemented as a hash table. */
137 const offset_type *symbol_table;
139 /* Size in slots, each slot is 2 offset_types. */
140 offset_type symbol_table_slots;
142 /* A pointer to the constant pool. */
143 const char *constant_pool;
146 /* Collection of data recorded per objfile.
147 This hangs off of dwarf2_objfile_data_key. */
149 struct dwarf2_per_objfile
151 struct dwarf2_section_info info;
152 struct dwarf2_section_info abbrev;
153 struct dwarf2_section_info line;
154 struct dwarf2_section_info loc;
155 struct dwarf2_section_info macinfo;
156 struct dwarf2_section_info macro;
157 struct dwarf2_section_info str;
158 struct dwarf2_section_info ranges;
159 struct dwarf2_section_info frame;
160 struct dwarf2_section_info eh_frame;
161 struct dwarf2_section_info gdb_index;
163 VEC (dwarf2_section_info_def) *types;
166 struct objfile *objfile;
168 /* Table of all the compilation units. This is used to locate
169 the target compilation unit of a particular reference. */
170 struct dwarf2_per_cu_data **all_comp_units;
172 /* The number of compilation units in ALL_COMP_UNITS. */
175 /* The number of .debug_types-related CUs. */
178 /* The .debug_types-related CUs (TUs). */
179 struct dwarf2_per_cu_data **all_type_units;
181 /* A chain of compilation units that are currently read in, so that
182 they can be freed later. */
183 struct dwarf2_per_cu_data *read_in_chain;
185 /* A table mapping .debug_types signatures to its signatured_type entry.
186 This is NULL if the .debug_types section hasn't been read in yet. */
187 htab_t signatured_types;
189 /* A flag indicating wether this objfile has a section loaded at a
191 int has_section_at_zero;
193 /* True if we are using the mapped index,
194 or we are faking it for OBJF_READNOW's sake. */
195 unsigned char using_index;
197 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
198 struct mapped_index *index_table;
200 /* When using index_table, this keeps track of all quick_file_names entries.
201 TUs can share line table entries with CUs or other TUs, and there can be
202 a lot more TUs than unique line tables, so we maintain a separate table
203 of all line table entries to support the sharing. */
204 htab_t quick_file_names_table;
206 /* Set during partial symbol reading, to prevent queueing of full
208 int reading_partial_symbols;
210 /* Table mapping type .debug_info DIE offsets to types.
211 This is NULL if not allocated yet.
212 It (currently) makes sense to allocate debug_types_type_hash lazily.
213 To keep things simple we allocate both lazily. */
214 htab_t debug_info_type_hash;
216 /* Table mapping type .debug_types DIE offsets to types.
217 This is NULL if not allocated yet. */
218 htab_t debug_types_type_hash;
221 static struct dwarf2_per_objfile *dwarf2_per_objfile;
223 /* Default names of the debugging sections. */
225 /* Note that if the debugging section has been compressed, it might
226 have a name like .zdebug_info. */
228 static const struct dwarf2_debug_sections dwarf2_elf_names =
230 { ".debug_info", ".zdebug_info" },
231 { ".debug_abbrev", ".zdebug_abbrev" },
232 { ".debug_line", ".zdebug_line" },
233 { ".debug_loc", ".zdebug_loc" },
234 { ".debug_macinfo", ".zdebug_macinfo" },
235 { ".debug_macro", ".zdebug_macro" },
236 { ".debug_str", ".zdebug_str" },
237 { ".debug_ranges", ".zdebug_ranges" },
238 { ".debug_types", ".zdebug_types" },
239 { ".debug_frame", ".zdebug_frame" },
240 { ".eh_frame", NULL },
241 { ".gdb_index", ".zgdb_index" },
245 /* local data types */
247 /* We hold several abbreviation tables in memory at the same time. */
248 #ifndef ABBREV_HASH_SIZE
249 #define ABBREV_HASH_SIZE 121
252 /* The data in a compilation unit header, after target2host
253 translation, looks like this. */
254 struct comp_unit_head
258 unsigned char addr_size;
259 unsigned char signed_addr_p;
260 unsigned int abbrev_offset;
262 /* Size of file offsets; either 4 or 8. */
263 unsigned int offset_size;
265 /* Size of the length field; either 4 or 12. */
266 unsigned int initial_length_size;
268 /* Offset to the first byte of this compilation unit header in the
269 .debug_info section, for resolving relative reference dies. */
272 /* Offset to first die in this cu from the start of the cu.
273 This will be the first byte following the compilation unit header. */
274 unsigned int first_die_offset;
277 /* Type used for delaying computation of method physnames.
278 See comments for compute_delayed_physnames. */
279 struct delayed_method_info
281 /* The type to which the method is attached, i.e., its parent class. */
284 /* The index of the method in the type's function fieldlists. */
287 /* The index of the method in the fieldlist. */
290 /* The name of the DIE. */
293 /* The DIE associated with this method. */
294 struct die_info *die;
297 typedef struct delayed_method_info delayed_method_info;
298 DEF_VEC_O (delayed_method_info);
300 /* Internal state when decoding a particular compilation unit. */
303 /* The objfile containing this compilation unit. */
304 struct objfile *objfile;
306 /* The header of the compilation unit. */
307 struct comp_unit_head header;
309 /* Base address of this compilation unit. */
310 CORE_ADDR base_address;
312 /* Non-zero if base_address has been set. */
315 /* The language we are debugging. */
316 enum language language;
317 const struct language_defn *language_defn;
319 const char *producer;
321 /* The generic symbol table building routines have separate lists for
322 file scope symbols and all all other scopes (local scopes). So
323 we need to select the right one to pass to add_symbol_to_list().
324 We do it by keeping a pointer to the correct list in list_in_scope.
326 FIXME: The original dwarf code just treated the file scope as the
327 first local scope, and all other local scopes as nested local
328 scopes, and worked fine. Check to see if we really need to
329 distinguish these in buildsym.c. */
330 struct pending **list_in_scope;
332 /* DWARF abbreviation table associated with this compilation unit. */
333 struct abbrev_info **dwarf2_abbrevs;
335 /* Storage for the abbrev table. */
336 struct obstack abbrev_obstack;
338 /* Hash table holding all the loaded partial DIEs. */
341 /* Storage for things with the same lifetime as this read-in compilation
342 unit, including partial DIEs. */
343 struct obstack comp_unit_obstack;
345 /* When multiple dwarf2_cu structures are living in memory, this field
346 chains them all together, so that they can be released efficiently.
347 We will probably also want a generation counter so that most-recently-used
348 compilation units are cached... */
349 struct dwarf2_per_cu_data *read_in_chain;
351 /* Backchain to our per_cu entry if the tree has been built. */
352 struct dwarf2_per_cu_data *per_cu;
354 /* How many compilation units ago was this CU last referenced? */
357 /* A hash table of die offsets for following references. */
360 /* Full DIEs if read in. */
361 struct die_info *dies;
363 /* A set of pointers to dwarf2_per_cu_data objects for compilation
364 units referenced by this one. Only set during full symbol processing;
365 partial symbol tables do not have dependencies. */
368 /* Header data from the line table, during full symbol processing. */
369 struct line_header *line_header;
371 /* A list of methods which need to have physnames computed
372 after all type information has been read. */
373 VEC (delayed_method_info) *method_list;
375 /* To be copied to symtab->call_site_htab. */
376 htab_t call_site_htab;
378 /* Mark used when releasing cached dies. */
379 unsigned int mark : 1;
381 /* This CU references .debug_loc. See the symtab->locations_valid field.
382 This test is imperfect as there may exist optimized debug code not using
383 any location list and still facing inlining issues if handled as
384 unoptimized code. For a future better test see GCC PR other/32998. */
385 unsigned int has_loclist : 1;
387 /* These cache the results of producer_is_gxx_lt_4_6.
388 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
389 information is cached because profiling CU expansion showed
390 excessive time spent in producer_is_gxx_lt_4_6. */
391 unsigned int checked_producer : 1;
392 unsigned int producer_is_gxx_lt_4_6 : 1;
395 /* Persistent data held for a compilation unit, even when not
396 processing it. We put a pointer to this structure in the
397 read_symtab_private field of the psymtab. */
399 struct dwarf2_per_cu_data
401 /* The start offset and length of this compilation unit. 2**29-1
402 bytes should suffice to store the length of any compilation unit
403 - if it doesn't, GDB will fall over anyway.
404 NOTE: Unlike comp_unit_head.length, this length includes
405 initial_length_size. */
407 unsigned int length : 29;
409 /* Flag indicating this compilation unit will be read in before
410 any of the current compilation units are processed. */
411 unsigned int queued : 1;
413 /* This flag will be set if we need to load absolutely all DIEs
414 for this compilation unit, instead of just the ones we think
415 are interesting. It gets set if we look for a DIE in the
416 hash table and don't find it. */
417 unsigned int load_all_dies : 1;
419 /* Non-null if this CU is from .debug_types; in which case it points
420 to the section. Otherwise it's from .debug_info. */
421 struct dwarf2_section_info *debug_types_section;
423 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
424 of the CU cache it gets reset to NULL again. */
425 struct dwarf2_cu *cu;
427 /* The corresponding objfile.
428 Normally we can get the objfile from dwarf2_per_objfile.
429 However we can enter this file with just a "per_cu" handle. */
430 struct objfile *objfile;
432 /* When using partial symbol tables, the 'psymtab' field is active.
433 Otherwise the 'quick' field is active. */
436 /* The partial symbol table associated with this compilation unit,
437 or NULL for partial units (which do not have an associated
439 struct partial_symtab *psymtab;
441 /* Data needed by the "quick" functions. */
442 struct dwarf2_per_cu_quick_data *quick;
446 /* Entry in the signatured_types hash table. */
448 struct signatured_type
452 /* Offset in .debug_types of the type defined by this TU. */
453 unsigned int type_offset;
455 /* The CU(/TU) of this type. */
456 struct dwarf2_per_cu_data per_cu;
459 /* Struct used to pass misc. parameters to read_die_and_children, et
460 al. which are used for both .debug_info and .debug_types dies.
461 All parameters here are unchanging for the life of the call. This
462 struct exists to abstract away the constant parameters of die
465 struct die_reader_specs
467 /* The bfd of this objfile. */
470 /* The CU of the DIE we are parsing. */
471 struct dwarf2_cu *cu;
473 /* Pointer to start of section buffer.
474 This is either the start of .debug_info or .debug_types. */
475 const gdb_byte *buffer;
478 /* The line number information for a compilation unit (found in the
479 .debug_line section) begins with a "statement program header",
480 which contains the following information. */
483 unsigned int total_length;
484 unsigned short version;
485 unsigned int header_length;
486 unsigned char minimum_instruction_length;
487 unsigned char maximum_ops_per_instruction;
488 unsigned char default_is_stmt;
490 unsigned char line_range;
491 unsigned char opcode_base;
493 /* standard_opcode_lengths[i] is the number of operands for the
494 standard opcode whose value is i. This means that
495 standard_opcode_lengths[0] is unused, and the last meaningful
496 element is standard_opcode_lengths[opcode_base - 1]. */
497 unsigned char *standard_opcode_lengths;
499 /* The include_directories table. NOTE! These strings are not
500 allocated with xmalloc; instead, they are pointers into
501 debug_line_buffer. If you try to free them, `free' will get
503 unsigned int num_include_dirs, include_dirs_size;
506 /* The file_names table. NOTE! These strings are not allocated
507 with xmalloc; instead, they are pointers into debug_line_buffer.
508 Don't try to free them directly. */
509 unsigned int num_file_names, file_names_size;
513 unsigned int dir_index;
514 unsigned int mod_time;
516 int included_p; /* Non-zero if referenced by the Line Number Program. */
517 struct symtab *symtab; /* The associated symbol table, if any. */
520 /* The start and end of the statement program following this
521 header. These point into dwarf2_per_objfile->line_buffer. */
522 gdb_byte *statement_program_start, *statement_program_end;
525 /* When we construct a partial symbol table entry we only
526 need this much information. */
527 struct partial_die_info
529 /* Offset of this DIE. */
532 /* DWARF-2 tag for this DIE. */
533 ENUM_BITFIELD(dwarf_tag) tag : 16;
535 /* Assorted flags describing the data found in this DIE. */
536 unsigned int has_children : 1;
537 unsigned int is_external : 1;
538 unsigned int is_declaration : 1;
539 unsigned int has_type : 1;
540 unsigned int has_specification : 1;
541 unsigned int has_pc_info : 1;
543 /* Flag set if the SCOPE field of this structure has been
545 unsigned int scope_set : 1;
547 /* Flag set if the DIE has a byte_size attribute. */
548 unsigned int has_byte_size : 1;
550 /* Flag set if any of the DIE's children are template arguments. */
551 unsigned int has_template_arguments : 1;
553 /* Flag set if fixup_partial_die has been called on this die. */
554 unsigned int fixup_called : 1;
556 /* The name of this DIE. Normally the value of DW_AT_name, but
557 sometimes a default name for unnamed DIEs. */
560 /* The linkage name, if present. */
561 const char *linkage_name;
563 /* The scope to prepend to our children. This is generally
564 allocated on the comp_unit_obstack, so will disappear
565 when this compilation unit leaves the cache. */
568 /* The location description associated with this DIE, if any. */
569 struct dwarf_block *locdesc;
571 /* If HAS_PC_INFO, the PC range associated with this DIE. */
575 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
576 DW_AT_sibling, if any. */
577 /* NOTE: This member isn't strictly necessary, read_partial_die could
578 return DW_AT_sibling values to its caller load_partial_dies. */
581 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
582 DW_AT_specification (or DW_AT_abstract_origin or
584 unsigned int spec_offset;
586 /* Pointers to this DIE's parent, first child, and next sibling,
588 struct partial_die_info *die_parent, *die_child, *die_sibling;
591 /* This data structure holds the information of an abbrev. */
594 unsigned int number; /* number identifying abbrev */
595 enum dwarf_tag tag; /* dwarf tag */
596 unsigned short has_children; /* boolean */
597 unsigned short num_attrs; /* number of attributes */
598 struct attr_abbrev *attrs; /* an array of attribute descriptions */
599 struct abbrev_info *next; /* next in chain */
604 ENUM_BITFIELD(dwarf_attribute) name : 16;
605 ENUM_BITFIELD(dwarf_form) form : 16;
608 /* Attributes have a name and a value. */
611 ENUM_BITFIELD(dwarf_attribute) name : 16;
612 ENUM_BITFIELD(dwarf_form) form : 15;
614 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
615 field should be in u.str (existing only for DW_STRING) but it is kept
616 here for better struct attribute alignment. */
617 unsigned int string_is_canonical : 1;
622 struct dwarf_block *blk;
626 struct signatured_type *signatured_type;
631 /* This data structure holds a complete die structure. */
634 /* DWARF-2 tag for this DIE. */
635 ENUM_BITFIELD(dwarf_tag) tag : 16;
637 /* Number of attributes */
638 unsigned char num_attrs;
640 /* True if we're presently building the full type name for the
641 type derived from this DIE. */
642 unsigned char building_fullname : 1;
647 /* Offset in .debug_info or .debug_types section. */
650 /* The dies in a compilation unit form an n-ary tree. PARENT
651 points to this die's parent; CHILD points to the first child of
652 this node; and all the children of a given node are chained
653 together via their SIBLING fields. */
654 struct die_info *child; /* Its first child, if any. */
655 struct die_info *sibling; /* Its next sibling, if any. */
656 struct die_info *parent; /* Its parent, if any. */
658 /* An array of attributes, with NUM_ATTRS elements. There may be
659 zero, but it's not common and zero-sized arrays are not
660 sufficiently portable C. */
661 struct attribute attrs[1];
664 /* Get at parts of an attribute structure. */
666 #define DW_STRING(attr) ((attr)->u.str)
667 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
668 #define DW_UNSND(attr) ((attr)->u.unsnd)
669 #define DW_BLOCK(attr) ((attr)->u.blk)
670 #define DW_SND(attr) ((attr)->u.snd)
671 #define DW_ADDR(attr) ((attr)->u.addr)
672 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
674 /* Blocks are a bunch of untyped bytes. */
679 /* Valid only if SIZE is not zero. */
683 #ifndef ATTR_ALLOC_CHUNK
684 #define ATTR_ALLOC_CHUNK 4
687 /* Allocate fields for structs, unions and enums in this size. */
688 #ifndef DW_FIELD_ALLOC_CHUNK
689 #define DW_FIELD_ALLOC_CHUNK 4
692 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
693 but this would require a corresponding change in unpack_field_as_long
695 static int bits_per_byte = 8;
697 /* The routines that read and process dies for a C struct or C++ class
698 pass lists of data member fields and lists of member function fields
699 in an instance of a field_info structure, as defined below. */
702 /* List of data member and baseclasses fields. */
705 struct nextfield *next;
710 *fields, *baseclasses;
712 /* Number of fields (including baseclasses). */
715 /* Number of baseclasses. */
718 /* Set if the accesibility of one of the fields is not public. */
719 int non_public_fields;
721 /* Member function fields array, entries are allocated in the order they
722 are encountered in the object file. */
725 struct nextfnfield *next;
726 struct fn_field fnfield;
730 /* Member function fieldlist array, contains name of possibly overloaded
731 member function, number of overloaded member functions and a pointer
732 to the head of the member function field chain. */
737 struct nextfnfield *head;
741 /* Number of entries in the fnfieldlists array. */
744 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
745 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
746 struct typedef_field_list
748 struct typedef_field field;
749 struct typedef_field_list *next;
752 unsigned typedef_field_list_count;
755 /* One item on the queue of compilation units to read in full symbols
757 struct dwarf2_queue_item
759 struct dwarf2_per_cu_data *per_cu;
760 struct dwarf2_queue_item *next;
763 /* The current queue. */
764 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
766 /* Loaded secondary compilation units are kept in memory until they
767 have not been referenced for the processing of this many
768 compilation units. Set this to zero to disable caching. Cache
769 sizes of up to at least twenty will improve startup time for
770 typical inter-CU-reference binaries, at an obvious memory cost. */
771 static int dwarf2_max_cache_age = 5;
773 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
774 struct cmd_list_element *c, const char *value)
776 fprintf_filtered (file, _("The upper bound on the age of cached "
777 "dwarf2 compilation units is %s.\n"),
782 /* Various complaints about symbol reading that don't abort the process. */
785 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
787 complaint (&symfile_complaints,
788 _("statement list doesn't fit in .debug_line section"));
792 dwarf2_debug_line_missing_file_complaint (void)
794 complaint (&symfile_complaints,
795 _(".debug_line section has line data without a file"));
799 dwarf2_debug_line_missing_end_sequence_complaint (void)
801 complaint (&symfile_complaints,
802 _(".debug_line section has line "
803 "program sequence without an end"));
807 dwarf2_complex_location_expr_complaint (void)
809 complaint (&symfile_complaints, _("location expression too complex"));
813 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
816 complaint (&symfile_complaints,
817 _("const value length mismatch for '%s', got %d, expected %d"),
822 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
824 complaint (&symfile_complaints,
825 _("macro info runs off end of `%s' section"),
826 section->asection->name);
830 dwarf2_macro_malformed_definition_complaint (const char *arg1)
832 complaint (&symfile_complaints,
833 _("macro debug info contains a "
834 "malformed macro definition:\n`%s'"),
839 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
841 complaint (&symfile_complaints,
842 _("invalid attribute class or form for '%s' in '%s'"),
846 /* local function prototypes */
848 static void dwarf2_locate_sections (bfd *, asection *, void *);
850 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
853 static void dwarf2_find_base_address (struct die_info *die,
854 struct dwarf2_cu *cu);
856 static void dwarf2_build_psymtabs_hard (struct objfile *);
858 static void scan_partial_symbols (struct partial_die_info *,
859 CORE_ADDR *, CORE_ADDR *,
860 int, struct dwarf2_cu *);
862 static void add_partial_symbol (struct partial_die_info *,
865 static void add_partial_namespace (struct partial_die_info *pdi,
866 CORE_ADDR *lowpc, CORE_ADDR *highpc,
867 int need_pc, struct dwarf2_cu *cu);
869 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
870 CORE_ADDR *highpc, int need_pc,
871 struct dwarf2_cu *cu);
873 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
874 struct dwarf2_cu *cu);
876 static void add_partial_subprogram (struct partial_die_info *pdi,
877 CORE_ADDR *lowpc, CORE_ADDR *highpc,
878 int need_pc, struct dwarf2_cu *cu);
880 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
881 gdb_byte *buffer, gdb_byte *info_ptr,
882 bfd *abfd, struct dwarf2_cu *cu);
884 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
886 static void psymtab_to_symtab_1 (struct partial_symtab *);
888 static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
890 static void dwarf2_free_abbrev_table (void *);
892 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
894 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
897 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
900 static struct partial_die_info *load_partial_dies (bfd *,
901 gdb_byte *, gdb_byte *,
902 int, struct dwarf2_cu *);
904 static gdb_byte *read_partial_die (struct partial_die_info *,
905 struct abbrev_info *abbrev,
907 gdb_byte *, gdb_byte *,
910 static struct partial_die_info *find_partial_die (unsigned int,
913 static void fixup_partial_die (struct partial_die_info *,
916 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
917 bfd *, gdb_byte *, struct dwarf2_cu *);
919 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
920 bfd *, gdb_byte *, struct dwarf2_cu *);
922 static unsigned int read_1_byte (bfd *, gdb_byte *);
924 static int read_1_signed_byte (bfd *, gdb_byte *);
926 static unsigned int read_2_bytes (bfd *, gdb_byte *);
928 static unsigned int read_4_bytes (bfd *, gdb_byte *);
930 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
932 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
935 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
937 static LONGEST read_checked_initial_length_and_offset
938 (bfd *, gdb_byte *, const struct comp_unit_head *,
939 unsigned int *, unsigned int *);
941 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
944 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
946 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
948 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
950 static char *read_indirect_string (bfd *, gdb_byte *,
951 const struct comp_unit_head *,
954 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
956 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
958 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
960 static void set_cu_language (unsigned int, struct dwarf2_cu *);
962 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
965 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
969 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
970 struct dwarf2_cu *cu);
972 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
974 static struct die_info *die_specification (struct die_info *die,
975 struct dwarf2_cu **);
977 static void free_line_header (struct line_header *lh);
979 static void add_file_name (struct line_header *, char *, unsigned int,
980 unsigned int, unsigned int);
982 static struct line_header *(dwarf_decode_line_header
983 (unsigned int offset,
984 bfd *abfd, struct dwarf2_cu *cu));
986 static void dwarf_decode_lines (struct line_header *, const char *,
987 struct dwarf2_cu *, struct partial_symtab *,
990 static void dwarf2_start_subfile (char *, const char *, const char *);
992 static struct symbol *new_symbol (struct die_info *, struct type *,
995 static struct symbol *new_symbol_full (struct die_info *, struct type *,
996 struct dwarf2_cu *, struct symbol *);
998 static void dwarf2_const_value (struct attribute *, struct symbol *,
1001 static void dwarf2_const_value_attr (struct attribute *attr,
1004 struct obstack *obstack,
1005 struct dwarf2_cu *cu, long *value,
1007 struct dwarf2_locexpr_baton **baton);
1009 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1011 static int need_gnat_info (struct dwarf2_cu *);
1013 static struct type *die_descriptive_type (struct die_info *,
1014 struct dwarf2_cu *);
1016 static void set_descriptive_type (struct type *, struct die_info *,
1017 struct dwarf2_cu *);
1019 static struct type *die_containing_type (struct die_info *,
1020 struct dwarf2_cu *);
1022 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1023 struct dwarf2_cu *);
1025 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1027 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1029 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1031 static char *typename_concat (struct obstack *obs, const char *prefix,
1032 const char *suffix, int physname,
1033 struct dwarf2_cu *cu);
1035 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1037 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1039 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1041 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1043 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1045 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1046 struct dwarf2_cu *, struct partial_symtab *);
1048 static int dwarf2_get_pc_bounds (struct die_info *,
1049 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1050 struct partial_symtab *);
1052 static void get_scope_pc_bounds (struct die_info *,
1053 CORE_ADDR *, CORE_ADDR *,
1054 struct dwarf2_cu *);
1056 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1057 CORE_ADDR, struct dwarf2_cu *);
1059 static void dwarf2_add_field (struct field_info *, struct die_info *,
1060 struct dwarf2_cu *);
1062 static void dwarf2_attach_fields_to_type (struct field_info *,
1063 struct type *, struct dwarf2_cu *);
1065 static void dwarf2_add_member_fn (struct field_info *,
1066 struct die_info *, struct type *,
1067 struct dwarf2_cu *);
1069 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1071 struct dwarf2_cu *);
1073 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1075 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1077 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1079 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1081 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1083 static struct type *read_module_type (struct die_info *die,
1084 struct dwarf2_cu *cu);
1086 static const char *namespace_name (struct die_info *die,
1087 int *is_anonymous, struct dwarf2_cu *);
1089 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1091 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1093 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1094 struct dwarf2_cu *);
1096 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1098 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1100 gdb_byte **new_info_ptr,
1101 struct die_info *parent);
1103 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1105 gdb_byte **new_info_ptr,
1106 struct die_info *parent);
1108 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1110 gdb_byte **new_info_ptr,
1111 struct die_info *parent);
1113 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1114 struct die_info **, gdb_byte *,
1117 static void process_die (struct die_info *, struct dwarf2_cu *);
1119 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1122 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1124 static const char *dwarf2_full_name (char *name,
1125 struct die_info *die,
1126 struct dwarf2_cu *cu);
1128 static struct die_info *dwarf2_extension (struct die_info *die,
1129 struct dwarf2_cu **);
1131 static char *dwarf_tag_name (unsigned int);
1133 static char *dwarf_attr_name (unsigned int);
1135 static char *dwarf_form_name (unsigned int);
1137 static char *dwarf_bool_name (unsigned int);
1139 static char *dwarf_type_encoding_name (unsigned int);
1142 static char *dwarf_cfi_name (unsigned int);
1145 static struct die_info *sibling_die (struct die_info *);
1147 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1149 static void dump_die_for_error (struct die_info *);
1151 static void dump_die_1 (struct ui_file *, int level, int max_level,
1154 /*static*/ void dump_die (struct die_info *, int max_level);
1156 static void store_in_ref_table (struct die_info *,
1157 struct dwarf2_cu *);
1159 static int is_ref_attr (struct attribute *);
1161 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1163 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1165 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1167 struct dwarf2_cu **);
1169 static struct die_info *follow_die_ref (struct die_info *,
1171 struct dwarf2_cu **);
1173 static struct die_info *follow_die_sig (struct die_info *,
1175 struct dwarf2_cu **);
1177 static struct signatured_type *lookup_signatured_type_at_offset
1178 (struct objfile *objfile,
1179 struct dwarf2_section_info *section,
1180 unsigned int offset);
1182 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1184 static void read_signatured_type (struct signatured_type *type_sig);
1186 /* memory allocation interface */
1188 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1190 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1192 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1194 static void dwarf_decode_macros (struct line_header *, unsigned int,
1195 char *, bfd *, struct dwarf2_cu *,
1196 struct dwarf2_section_info *,
1199 static int attr_form_is_block (struct attribute *);
1201 static int attr_form_is_section_offset (struct attribute *);
1203 static int attr_form_is_constant (struct attribute *);
1205 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1206 struct dwarf2_loclist_baton *baton,
1207 struct attribute *attr);
1209 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1211 struct dwarf2_cu *cu);
1213 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1214 struct abbrev_info *abbrev,
1215 struct dwarf2_cu *cu);
1217 static void free_stack_comp_unit (void *);
1219 static hashval_t partial_die_hash (const void *item);
1221 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1223 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1224 (unsigned int offset, struct objfile *objfile);
1226 static void init_one_comp_unit (struct dwarf2_cu *cu,
1227 struct dwarf2_per_cu_data *per_cu);
1229 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1230 struct die_info *comp_unit_die);
1232 static void free_heap_comp_unit (void *);
1234 static void free_cached_comp_units (void *);
1236 static void age_cached_comp_units (void);
1238 static void free_one_cached_comp_unit (void *);
1240 static struct type *set_die_type (struct die_info *, struct type *,
1241 struct dwarf2_cu *);
1243 static void create_all_comp_units (struct objfile *);
1245 static int create_debug_types_hash_table (struct objfile *objfile);
1247 static void load_full_comp_unit (struct dwarf2_per_cu_data *);
1249 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1251 static void dwarf2_add_dependence (struct dwarf2_cu *,
1252 struct dwarf2_per_cu_data *);
1254 static void dwarf2_mark (struct dwarf2_cu *);
1256 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1258 static struct type *get_die_type_at_offset (unsigned int,
1259 struct dwarf2_per_cu_data *per_cu);
1261 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1263 static void dwarf2_release_queue (void *dummy);
1265 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
1267 static void process_queue (void);
1269 static void find_file_and_directory (struct die_info *die,
1270 struct dwarf2_cu *cu,
1271 char **name, char **comp_dir);
1273 static char *file_full_name (int file, struct line_header *lh,
1274 const char *comp_dir);
1276 static gdb_byte *read_and_check_comp_unit_head
1277 (struct comp_unit_head *header,
1278 struct dwarf2_section_info *section, gdb_byte *info_ptr,
1279 int is_debug_types_section);
1281 static void init_cu_die_reader (struct die_reader_specs *reader,
1282 struct dwarf2_cu *cu);
1284 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1288 /* Convert VALUE between big- and little-endian. */
1290 byte_swap (offset_type value)
1294 result = (value & 0xff) << 24;
1295 result |= (value & 0xff00) << 8;
1296 result |= (value & 0xff0000) >> 8;
1297 result |= (value & 0xff000000) >> 24;
1301 #define MAYBE_SWAP(V) byte_swap (V)
1304 #define MAYBE_SWAP(V) (V)
1305 #endif /* WORDS_BIGENDIAN */
1307 /* The suffix for an index file. */
1308 #define INDEX_SUFFIX ".gdb-index"
1310 static const char *dwarf2_physname (char *name, struct die_info *die,
1311 struct dwarf2_cu *cu);
1313 /* Try to locate the sections we need for DWARF 2 debugging
1314 information and return true if we have enough to do something.
1315 NAMES points to the dwarf2 section names, or is NULL if the standard
1316 ELF names are used. */
1319 dwarf2_has_info (struct objfile *objfile,
1320 const struct dwarf2_debug_sections *names)
1322 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1323 if (!dwarf2_per_objfile)
1325 /* Initialize per-objfile state. */
1326 struct dwarf2_per_objfile *data
1327 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1329 memset (data, 0, sizeof (*data));
1330 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1331 dwarf2_per_objfile = data;
1333 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1335 dwarf2_per_objfile->objfile = objfile;
1337 return (dwarf2_per_objfile->info.asection != NULL
1338 && dwarf2_per_objfile->abbrev.asection != NULL);
1341 /* When loading sections, we look either for uncompressed section or for
1342 compressed section names. */
1345 section_is_p (const char *section_name,
1346 const struct dwarf2_section_names *names)
1348 if (names->normal != NULL
1349 && strcmp (section_name, names->normal) == 0)
1351 if (names->compressed != NULL
1352 && strcmp (section_name, names->compressed) == 0)
1357 /* This function is mapped across the sections and remembers the
1358 offset and size of each of the debugging sections we are interested
1362 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1364 const struct dwarf2_debug_sections *names;
1367 names = &dwarf2_elf_names;
1369 names = (const struct dwarf2_debug_sections *) vnames;
1371 if (section_is_p (sectp->name, &names->info))
1373 dwarf2_per_objfile->info.asection = sectp;
1374 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1376 else if (section_is_p (sectp->name, &names->abbrev))
1378 dwarf2_per_objfile->abbrev.asection = sectp;
1379 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1381 else if (section_is_p (sectp->name, &names->line))
1383 dwarf2_per_objfile->line.asection = sectp;
1384 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1386 else if (section_is_p (sectp->name, &names->loc))
1388 dwarf2_per_objfile->loc.asection = sectp;
1389 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1391 else if (section_is_p (sectp->name, &names->macinfo))
1393 dwarf2_per_objfile->macinfo.asection = sectp;
1394 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1396 else if (section_is_p (sectp->name, &names->macro))
1398 dwarf2_per_objfile->macro.asection = sectp;
1399 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1401 else if (section_is_p (sectp->name, &names->str))
1403 dwarf2_per_objfile->str.asection = sectp;
1404 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1406 else if (section_is_p (sectp->name, &names->frame))
1408 dwarf2_per_objfile->frame.asection = sectp;
1409 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1411 else if (section_is_p (sectp->name, &names->eh_frame))
1413 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1415 if (aflag & SEC_HAS_CONTENTS)
1417 dwarf2_per_objfile->eh_frame.asection = sectp;
1418 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1421 else if (section_is_p (sectp->name, &names->ranges))
1423 dwarf2_per_objfile->ranges.asection = sectp;
1424 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1426 else if (section_is_p (sectp->name, &names->types))
1428 struct dwarf2_section_info type_section;
1430 memset (&type_section, 0, sizeof (type_section));
1431 type_section.asection = sectp;
1432 type_section.size = bfd_get_section_size (sectp);
1434 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1437 else if (section_is_p (sectp->name, &names->gdb_index))
1439 dwarf2_per_objfile->gdb_index.asection = sectp;
1440 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1443 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1444 && bfd_section_vma (abfd, sectp) == 0)
1445 dwarf2_per_objfile->has_section_at_zero = 1;
1448 /* Decompress a section that was compressed using zlib. Store the
1449 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1452 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1453 gdb_byte **outbuf, bfd_size_type *outsize)
1455 bfd *abfd = objfile->obfd;
1457 error (_("Support for zlib-compressed DWARF data (from '%s') "
1458 "is disabled in this copy of GDB"),
1459 bfd_get_filename (abfd));
1461 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1462 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1463 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1464 bfd_size_type uncompressed_size;
1465 gdb_byte *uncompressed_buffer;
1468 int header_size = 12;
1470 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1471 || bfd_bread (compressed_buffer,
1472 compressed_size, abfd) != compressed_size)
1473 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1474 bfd_get_filename (abfd));
1476 /* Read the zlib header. In this case, it should be "ZLIB" followed
1477 by the uncompressed section size, 8 bytes in big-endian order. */
1478 if (compressed_size < header_size
1479 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1480 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1481 bfd_get_filename (abfd));
1482 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1483 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1484 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1485 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1486 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1487 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1488 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1489 uncompressed_size += compressed_buffer[11];
1491 /* It is possible the section consists of several compressed
1492 buffers concatenated together, so we uncompress in a loop. */
1496 strm.avail_in = compressed_size - header_size;
1497 strm.next_in = (Bytef*) compressed_buffer + header_size;
1498 strm.avail_out = uncompressed_size;
1499 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1501 rc = inflateInit (&strm);
1502 while (strm.avail_in > 0)
1505 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1506 bfd_get_filename (abfd), rc);
1507 strm.next_out = ((Bytef*) uncompressed_buffer
1508 + (uncompressed_size - strm.avail_out));
1509 rc = inflate (&strm, Z_FINISH);
1510 if (rc != Z_STREAM_END)
1511 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1512 bfd_get_filename (abfd), rc);
1513 rc = inflateReset (&strm);
1515 rc = inflateEnd (&strm);
1517 || strm.avail_out != 0)
1518 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1519 bfd_get_filename (abfd), rc);
1521 do_cleanups (cleanup);
1522 *outbuf = uncompressed_buffer;
1523 *outsize = uncompressed_size;
1527 /* A helper function that decides whether a section is empty. */
1530 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1532 return info->asection == NULL || info->size == 0;
1535 /* Read the contents of the section INFO from object file specified by
1536 OBJFILE, store info about the section into INFO.
1537 If the section is compressed, uncompress it before returning. */
1540 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1542 bfd *abfd = objfile->obfd;
1543 asection *sectp = info->asection;
1544 gdb_byte *buf, *retbuf;
1545 unsigned char header[4];
1549 info->buffer = NULL;
1550 info->map_addr = NULL;
1553 if (dwarf2_section_empty_p (info))
1556 /* Check if the file has a 4-byte header indicating compression. */
1557 if (info->size > sizeof (header)
1558 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1559 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1561 /* Upon decompression, update the buffer and its size. */
1562 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1564 zlib_decompress_section (objfile, sectp, &info->buffer,
1572 pagesize = getpagesize ();
1574 /* Only try to mmap sections which are large enough: we don't want to
1575 waste space due to fragmentation. Also, only try mmap for sections
1576 without relocations. */
1578 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1580 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1581 MAP_PRIVATE, sectp->filepos,
1582 &info->map_addr, &info->map_len);
1584 if ((caddr_t)info->buffer != MAP_FAILED)
1586 #if HAVE_POSIX_MADVISE
1587 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1594 /* If we get here, we are a normal, not-compressed section. */
1596 = obstack_alloc (&objfile->objfile_obstack, info->size);
1598 /* When debugging .o files, we may need to apply relocations; see
1599 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1600 We never compress sections in .o files, so we only need to
1601 try this when the section is not compressed. */
1602 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1605 info->buffer = retbuf;
1609 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1610 || bfd_bread (buf, info->size, abfd) != info->size)
1611 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1612 bfd_get_filename (abfd));
1615 /* A helper function that returns the size of a section in a safe way.
1616 If you are positive that the section has been read before using the
1617 size, then it is safe to refer to the dwarf2_section_info object's
1618 "size" field directly. In other cases, you must call this
1619 function, because for compressed sections the size field is not set
1620 correctly until the section has been read. */
1622 static bfd_size_type
1623 dwarf2_section_size (struct objfile *objfile,
1624 struct dwarf2_section_info *info)
1627 dwarf2_read_section (objfile, info);
1631 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1635 dwarf2_get_section_info (struct objfile *objfile,
1636 enum dwarf2_section_enum sect,
1637 asection **sectp, gdb_byte **bufp,
1638 bfd_size_type *sizep)
1640 struct dwarf2_per_objfile *data
1641 = objfile_data (objfile, dwarf2_objfile_data_key);
1642 struct dwarf2_section_info *info;
1644 /* We may see an objfile without any DWARF, in which case we just
1655 case DWARF2_DEBUG_FRAME:
1656 info = &data->frame;
1658 case DWARF2_EH_FRAME:
1659 info = &data->eh_frame;
1662 gdb_assert_not_reached ("unexpected section");
1665 dwarf2_read_section (objfile, info);
1667 *sectp = info->asection;
1668 *bufp = info->buffer;
1669 *sizep = info->size;
1673 /* DWARF quick_symbols_functions support. */
1675 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1676 unique line tables, so we maintain a separate table of all .debug_line
1677 derived entries to support the sharing.
1678 All the quick functions need is the list of file names. We discard the
1679 line_header when we're done and don't need to record it here. */
1680 struct quick_file_names
1682 /* The offset in .debug_line of the line table. We hash on this. */
1683 unsigned int offset;
1685 /* The number of entries in file_names, real_names. */
1686 unsigned int num_file_names;
1688 /* The file names from the line table, after being run through
1690 const char **file_names;
1692 /* The file names from the line table after being run through
1693 gdb_realpath. These are computed lazily. */
1694 const char **real_names;
1697 /* When using the index (and thus not using psymtabs), each CU has an
1698 object of this type. This is used to hold information needed by
1699 the various "quick" methods. */
1700 struct dwarf2_per_cu_quick_data
1702 /* The file table. This can be NULL if there was no file table
1703 or it's currently not read in.
1704 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1705 struct quick_file_names *file_names;
1707 /* The corresponding symbol table. This is NULL if symbols for this
1708 CU have not yet been read. */
1709 struct symtab *symtab;
1711 /* A temporary mark bit used when iterating over all CUs in
1712 expand_symtabs_matching. */
1713 unsigned int mark : 1;
1715 /* True if we've tried to read the file table and found there isn't one.
1716 There will be no point in trying to read it again next time. */
1717 unsigned int no_file_data : 1;
1720 /* Hash function for a quick_file_names. */
1723 hash_file_name_entry (const void *e)
1725 const struct quick_file_names *file_data = e;
1727 return file_data->offset;
1730 /* Equality function for a quick_file_names. */
1733 eq_file_name_entry (const void *a, const void *b)
1735 const struct quick_file_names *ea = a;
1736 const struct quick_file_names *eb = b;
1738 return ea->offset == eb->offset;
1741 /* Delete function for a quick_file_names. */
1744 delete_file_name_entry (void *e)
1746 struct quick_file_names *file_data = e;
1749 for (i = 0; i < file_data->num_file_names; ++i)
1751 xfree ((void*) file_data->file_names[i]);
1752 if (file_data->real_names)
1753 xfree ((void*) file_data->real_names[i]);
1756 /* The space for the struct itself lives on objfile_obstack,
1757 so we don't free it here. */
1760 /* Create a quick_file_names hash table. */
1763 create_quick_file_names_table (unsigned int nr_initial_entries)
1765 return htab_create_alloc (nr_initial_entries,
1766 hash_file_name_entry, eq_file_name_entry,
1767 delete_file_name_entry, xcalloc, xfree);
1770 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1771 have to be created afterwards. You should call age_cached_comp_units after
1772 processing PER_CU->CU. dw2_setup must have been already called. */
1775 load_cu (struct dwarf2_per_cu_data *per_cu)
1777 if (per_cu->debug_types_section)
1778 load_full_type_unit (per_cu);
1780 load_full_comp_unit (per_cu);
1782 gdb_assert (per_cu->cu != NULL);
1784 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1787 /* Read in the symbols for PER_CU. */
1790 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1792 struct cleanup *back_to;
1794 back_to = make_cleanup (dwarf2_release_queue, NULL);
1796 queue_comp_unit (per_cu);
1802 /* Age the cache, releasing compilation units that have not
1803 been used recently. */
1804 age_cached_comp_units ();
1806 do_cleanups (back_to);
1809 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1810 the objfile from which this CU came. Returns the resulting symbol
1813 static struct symtab *
1814 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1816 if (!per_cu->v.quick->symtab)
1818 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1819 increment_reading_symtab ();
1820 dw2_do_instantiate_symtab (per_cu);
1821 do_cleanups (back_to);
1823 return per_cu->v.quick->symtab;
1826 /* Return the CU given its index. */
1828 static struct dwarf2_per_cu_data *
1829 dw2_get_cu (int index)
1831 if (index >= dwarf2_per_objfile->n_comp_units)
1833 index -= dwarf2_per_objfile->n_comp_units;
1834 return dwarf2_per_objfile->all_type_units[index];
1836 return dwarf2_per_objfile->all_comp_units[index];
1839 /* A helper function that knows how to read a 64-bit value in a way
1840 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1844 extract_cu_value (const char *bytes, ULONGEST *result)
1846 if (sizeof (ULONGEST) < 8)
1850 /* Ignore the upper 4 bytes if they are all zero. */
1851 for (i = 0; i < 4; ++i)
1852 if (bytes[i + 4] != 0)
1855 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1858 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1862 /* Read the CU list from the mapped index, and use it to create all
1863 the CU objects for this objfile. Return 0 if something went wrong,
1864 1 if everything went ok. */
1867 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1868 offset_type cu_list_elements)
1872 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1873 dwarf2_per_objfile->all_comp_units
1874 = obstack_alloc (&objfile->objfile_obstack,
1875 dwarf2_per_objfile->n_comp_units
1876 * sizeof (struct dwarf2_per_cu_data *));
1878 for (i = 0; i < cu_list_elements; i += 2)
1880 struct dwarf2_per_cu_data *the_cu;
1881 ULONGEST offset, length;
1883 if (!extract_cu_value (cu_list, &offset)
1884 || !extract_cu_value (cu_list + 8, &length))
1888 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1889 struct dwarf2_per_cu_data);
1890 the_cu->offset = offset;
1891 the_cu->length = length;
1892 the_cu->objfile = objfile;
1893 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1894 struct dwarf2_per_cu_quick_data);
1895 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1901 /* Create the signatured type hash table from the index. */
1904 create_signatured_type_table_from_index (struct objfile *objfile,
1905 struct dwarf2_section_info *section,
1906 const gdb_byte *bytes,
1907 offset_type elements)
1910 htab_t sig_types_hash;
1912 dwarf2_per_objfile->n_type_units = elements / 3;
1913 dwarf2_per_objfile->all_type_units
1914 = obstack_alloc (&objfile->objfile_obstack,
1915 dwarf2_per_objfile->n_type_units
1916 * sizeof (struct dwarf2_per_cu_data *));
1918 sig_types_hash = allocate_signatured_type_table (objfile);
1920 for (i = 0; i < elements; i += 3)
1922 struct signatured_type *type_sig;
1923 ULONGEST offset, type_offset, signature;
1926 if (!extract_cu_value (bytes, &offset)
1927 || !extract_cu_value (bytes + 8, &type_offset))
1929 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1932 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1933 struct signatured_type);
1934 type_sig->signature = signature;
1935 type_sig->type_offset = type_offset;
1936 type_sig->per_cu.debug_types_section = section;
1937 type_sig->per_cu.offset = offset;
1938 type_sig->per_cu.objfile = objfile;
1939 type_sig->per_cu.v.quick
1940 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1941 struct dwarf2_per_cu_quick_data);
1943 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1946 dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu;
1949 dwarf2_per_objfile->signatured_types = sig_types_hash;
1954 /* Read the address map data from the mapped index, and use it to
1955 populate the objfile's psymtabs_addrmap. */
1958 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1960 const gdb_byte *iter, *end;
1961 struct obstack temp_obstack;
1962 struct addrmap *mutable_map;
1963 struct cleanup *cleanup;
1966 obstack_init (&temp_obstack);
1967 cleanup = make_cleanup_obstack_free (&temp_obstack);
1968 mutable_map = addrmap_create_mutable (&temp_obstack);
1970 iter = index->address_table;
1971 end = iter + index->address_table_size;
1973 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1977 ULONGEST hi, lo, cu_index;
1978 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1980 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1982 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1985 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1986 dw2_get_cu (cu_index));
1989 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1990 &objfile->objfile_obstack);
1991 do_cleanups (cleanup);
1994 /* The hash function for strings in the mapped index. This is the same as
1995 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1996 implementation. This is necessary because the hash function is tied to the
1997 format of the mapped index file. The hash values do not have to match with
2000 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2003 mapped_index_string_hash (int index_version, const void *p)
2005 const unsigned char *str = (const unsigned char *) p;
2009 while ((c = *str++) != 0)
2011 if (index_version >= 5)
2013 r = r * 67 + c - 113;
2019 /* Find a slot in the mapped index INDEX for the object named NAME.
2020 If NAME is found, set *VEC_OUT to point to the CU vector in the
2021 constant pool and return 1. If NAME cannot be found, return 0. */
2024 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2025 offset_type **vec_out)
2027 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2029 offset_type slot, step;
2030 int (*cmp) (const char *, const char *);
2032 if (current_language->la_language == language_cplus
2033 || current_language->la_language == language_java
2034 || current_language->la_language == language_fortran)
2036 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2038 const char *paren = strchr (name, '(');
2044 dup = xmalloc (paren - name + 1);
2045 memcpy (dup, name, paren - name);
2046 dup[paren - name] = 0;
2048 make_cleanup (xfree, dup);
2053 /* Index version 4 did not support case insensitive searches. But the
2054 indices for case insensitive languages are built in lowercase, therefore
2055 simulate our NAME being searched is also lowercased. */
2056 hash = mapped_index_string_hash ((index->version == 4
2057 && case_sensitivity == case_sensitive_off
2058 ? 5 : index->version),
2061 slot = hash & (index->symbol_table_slots - 1);
2062 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2063 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2067 /* Convert a slot number to an offset into the table. */
2068 offset_type i = 2 * slot;
2070 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2072 do_cleanups (back_to);
2076 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2077 if (!cmp (name, str))
2079 *vec_out = (offset_type *) (index->constant_pool
2080 + MAYBE_SWAP (index->symbol_table[i + 1]));
2081 do_cleanups (back_to);
2085 slot = (slot + step) & (index->symbol_table_slots - 1);
2089 /* Read the index file. If everything went ok, initialize the "quick"
2090 elements of all the CUs and return 1. Otherwise, return 0. */
2093 dwarf2_read_index (struct objfile *objfile)
2096 struct mapped_index *map;
2097 offset_type *metadata;
2098 const gdb_byte *cu_list;
2099 const gdb_byte *types_list = NULL;
2100 offset_type version, cu_list_elements;
2101 offset_type types_list_elements = 0;
2104 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2107 /* Older elfutils strip versions could keep the section in the main
2108 executable while splitting it for the separate debug info file. */
2109 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2110 & SEC_HAS_CONTENTS) == 0)
2113 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2115 addr = dwarf2_per_objfile->gdb_index.buffer;
2116 /* Version check. */
2117 version = MAYBE_SWAP (*(offset_type *) addr);
2118 /* Versions earlier than 3 emitted every copy of a psymbol. This
2119 causes the index to behave very poorly for certain requests. Version 3
2120 contained incomplete addrmap. So, it seems better to just ignore such
2121 indices. Index version 4 uses a different hash function than index
2122 version 5 and later. */
2125 /* Indices with higher version than the one supported by GDB may be no
2126 longer backward compatible. */
2130 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2131 map->version = version;
2132 map->total_size = dwarf2_per_objfile->gdb_index.size;
2134 metadata = (offset_type *) (addr + sizeof (offset_type));
2137 cu_list = addr + MAYBE_SWAP (metadata[i]);
2138 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2142 types_list = addr + MAYBE_SWAP (metadata[i]);
2143 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2144 - MAYBE_SWAP (metadata[i]))
2148 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2149 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2150 - MAYBE_SWAP (metadata[i]));
2153 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2154 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2155 - MAYBE_SWAP (metadata[i]))
2156 / (2 * sizeof (offset_type)));
2159 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2161 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2164 if (types_list_elements)
2166 struct dwarf2_section_info *section;
2168 /* We can only handle a single .debug_types when we have an
2170 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2173 section = VEC_index (dwarf2_section_info_def,
2174 dwarf2_per_objfile->types, 0);
2176 if (!create_signatured_type_table_from_index (objfile, section,
2178 types_list_elements))
2182 create_addrmap_from_index (objfile, map);
2184 dwarf2_per_objfile->index_table = map;
2185 dwarf2_per_objfile->using_index = 1;
2186 dwarf2_per_objfile->quick_file_names_table =
2187 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2192 /* A helper for the "quick" functions which sets the global
2193 dwarf2_per_objfile according to OBJFILE. */
2196 dw2_setup (struct objfile *objfile)
2198 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2199 gdb_assert (dwarf2_per_objfile);
2202 /* A helper for the "quick" functions which attempts to read the line
2203 table for THIS_CU. */
2205 static struct quick_file_names *
2206 dw2_get_file_names (struct objfile *objfile,
2207 struct dwarf2_per_cu_data *this_cu)
2209 bfd *abfd = objfile->obfd;
2210 struct line_header *lh;
2211 struct attribute *attr;
2212 struct cleanup *cleanups;
2213 struct die_info *comp_unit_die;
2214 struct dwarf2_section_info* sec;
2216 int has_children, i;
2217 struct dwarf2_cu cu;
2218 unsigned int bytes_read;
2219 struct die_reader_specs reader_specs;
2220 char *name, *comp_dir;
2222 struct quick_file_names *qfn;
2223 unsigned int line_offset;
2225 if (this_cu->v.quick->file_names != NULL)
2226 return this_cu->v.quick->file_names;
2227 /* If we know there is no line data, no point in looking again. */
2228 if (this_cu->v.quick->no_file_data)
2231 init_one_comp_unit (&cu, this_cu);
2232 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2234 if (this_cu->debug_types_section)
2235 sec = this_cu->debug_types_section;
2237 sec = &dwarf2_per_objfile->info;
2238 dwarf2_read_section (objfile, sec);
2239 info_ptr = sec->buffer + this_cu->offset;
2241 info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr,
2242 this_cu->debug_types_section != NULL);
2244 /* Skip dummy compilation units. */
2245 if (info_ptr >= (sec->buffer + sec->size)
2246 || peek_abbrev_code (abfd, info_ptr) == 0)
2248 do_cleanups (cleanups);
2252 dwarf2_read_abbrevs (&cu);
2253 make_cleanup (dwarf2_free_abbrev_table, &cu);
2255 init_cu_die_reader (&reader_specs, &cu);
2256 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2262 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2265 struct quick_file_names find_entry;
2267 line_offset = DW_UNSND (attr);
2269 /* We may have already read in this line header (TU line header sharing).
2270 If we have we're done. */
2271 find_entry.offset = line_offset;
2272 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2273 &find_entry, INSERT);
2276 do_cleanups (cleanups);
2277 this_cu->v.quick->file_names = *slot;
2281 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2285 do_cleanups (cleanups);
2286 this_cu->v.quick->no_file_data = 1;
2290 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2291 qfn->offset = line_offset;
2292 gdb_assert (slot != NULL);
2295 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2297 qfn->num_file_names = lh->num_file_names;
2298 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2299 lh->num_file_names * sizeof (char *));
2300 for (i = 0; i < lh->num_file_names; ++i)
2301 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2302 qfn->real_names = NULL;
2304 free_line_header (lh);
2305 do_cleanups (cleanups);
2307 this_cu->v.quick->file_names = qfn;
2311 /* A helper for the "quick" functions which computes and caches the
2312 real path for a given file name from the line table. */
2315 dw2_get_real_path (struct objfile *objfile,
2316 struct quick_file_names *qfn, int index)
2318 if (qfn->real_names == NULL)
2319 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2320 qfn->num_file_names, sizeof (char *));
2322 if (qfn->real_names[index] == NULL)
2323 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2325 return qfn->real_names[index];
2328 static struct symtab *
2329 dw2_find_last_source_symtab (struct objfile *objfile)
2333 dw2_setup (objfile);
2334 index = dwarf2_per_objfile->n_comp_units - 1;
2335 return dw2_instantiate_symtab (dw2_get_cu (index));
2338 /* Traversal function for dw2_forget_cached_source_info. */
2341 dw2_free_cached_file_names (void **slot, void *info)
2343 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2345 if (file_data->real_names)
2349 for (i = 0; i < file_data->num_file_names; ++i)
2351 xfree ((void*) file_data->real_names[i]);
2352 file_data->real_names[i] = NULL;
2360 dw2_forget_cached_source_info (struct objfile *objfile)
2362 dw2_setup (objfile);
2364 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2365 dw2_free_cached_file_names, NULL);
2368 /* Helper function for dw2_map_symtabs_matching_filename that expands
2369 the symtabs and calls the iterator. */
2372 dw2_map_expand_apply (struct objfile *objfile,
2373 struct dwarf2_per_cu_data *per_cu,
2375 const char *full_path, const char *real_path,
2376 int (*callback) (struct symtab *, void *),
2379 struct symtab *last_made = objfile->symtabs;
2381 /* Don't visit already-expanded CUs. */
2382 if (per_cu->v.quick->symtab)
2385 /* This may expand more than one symtab, and we want to iterate over
2387 dw2_instantiate_symtab (per_cu);
2389 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
2390 objfile->symtabs, last_made);
2393 /* Implementation of the map_symtabs_matching_filename method. */
2396 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
2397 const char *full_path, const char *real_path,
2398 int (*callback) (struct symtab *, void *),
2402 const char *name_basename = lbasename (name);
2403 int name_len = strlen (name);
2404 int is_abs = IS_ABSOLUTE_PATH (name);
2406 dw2_setup (objfile);
2408 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2409 + dwarf2_per_objfile->n_type_units); ++i)
2412 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2413 struct quick_file_names *file_data;
2415 /* We only need to look at symtabs not already expanded. */
2416 if (per_cu->v.quick->symtab)
2419 file_data = dw2_get_file_names (objfile, per_cu);
2420 if (file_data == NULL)
2423 for (j = 0; j < file_data->num_file_names; ++j)
2425 const char *this_name = file_data->file_names[j];
2427 if (FILENAME_CMP (name, this_name) == 0
2428 || (!is_abs && compare_filenames_for_search (this_name,
2431 if (dw2_map_expand_apply (objfile, per_cu,
2432 name, full_path, real_path,
2437 /* Before we invoke realpath, which can get expensive when many
2438 files are involved, do a quick comparison of the basenames. */
2439 if (! basenames_may_differ
2440 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
2443 if (full_path != NULL)
2445 const char *this_real_name = dw2_get_real_path (objfile,
2448 if (this_real_name != NULL
2449 && (FILENAME_CMP (full_path, this_real_name) == 0
2451 && compare_filenames_for_search (this_real_name,
2454 if (dw2_map_expand_apply (objfile, per_cu,
2455 name, full_path, real_path,
2461 if (real_path != NULL)
2463 const char *this_real_name = dw2_get_real_path (objfile,
2466 if (this_real_name != NULL
2467 && (FILENAME_CMP (real_path, this_real_name) == 0
2469 && compare_filenames_for_search (this_real_name,
2472 if (dw2_map_expand_apply (objfile, per_cu,
2473 name, full_path, real_path,
2484 static struct symtab *
2485 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2486 const char *name, domain_enum domain)
2488 /* We do all the work in the pre_expand_symtabs_matching hook
2493 /* A helper function that expands all symtabs that hold an object
2497 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2499 dw2_setup (objfile);
2501 /* index_table is NULL if OBJF_READNOW. */
2502 if (dwarf2_per_objfile->index_table)
2506 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2509 offset_type i, len = MAYBE_SWAP (*vec);
2510 for (i = 0; i < len; ++i)
2512 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2513 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2515 dw2_instantiate_symtab (per_cu);
2522 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2523 enum block_enum block_kind, const char *name,
2526 dw2_do_expand_symtabs_matching (objfile, name);
2530 dw2_print_stats (struct objfile *objfile)
2534 dw2_setup (objfile);
2536 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2537 + dwarf2_per_objfile->n_type_units); ++i)
2539 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2541 if (!per_cu->v.quick->symtab)
2544 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2548 dw2_dump (struct objfile *objfile)
2550 /* Nothing worth printing. */
2554 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2555 struct section_offsets *delta)
2557 /* There's nothing to relocate here. */
2561 dw2_expand_symtabs_for_function (struct objfile *objfile,
2562 const char *func_name)
2564 dw2_do_expand_symtabs_matching (objfile, func_name);
2568 dw2_expand_all_symtabs (struct objfile *objfile)
2572 dw2_setup (objfile);
2574 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2575 + dwarf2_per_objfile->n_type_units); ++i)
2577 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2579 dw2_instantiate_symtab (per_cu);
2584 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2585 const char *filename)
2589 dw2_setup (objfile);
2591 /* We don't need to consider type units here.
2592 This is only called for examining code, e.g. expand_line_sal.
2593 There can be an order of magnitude (or more) more type units
2594 than comp units, and we avoid them if we can. */
2596 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2599 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2600 struct quick_file_names *file_data;
2602 /* We only need to look at symtabs not already expanded. */
2603 if (per_cu->v.quick->symtab)
2606 file_data = dw2_get_file_names (objfile, per_cu);
2607 if (file_data == NULL)
2610 for (j = 0; j < file_data->num_file_names; ++j)
2612 const char *this_name = file_data->file_names[j];
2613 if (FILENAME_CMP (this_name, filename) == 0)
2615 dw2_instantiate_symtab (per_cu);
2623 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2625 struct dwarf2_per_cu_data *per_cu;
2627 struct quick_file_names *file_data;
2629 dw2_setup (objfile);
2631 /* index_table is NULL if OBJF_READNOW. */
2632 if (!dwarf2_per_objfile->index_table)
2636 ALL_OBJFILE_SYMTABS (objfile, s)
2639 struct blockvector *bv = BLOCKVECTOR (s);
2640 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2641 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2644 return sym->symtab->filename;
2649 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2653 /* Note that this just looks at the very first one named NAME -- but
2654 actually we are looking for a function. find_main_filename
2655 should be rewritten so that it doesn't require a custom hook. It
2656 could just use the ordinary symbol tables. */
2657 /* vec[0] is the length, which must always be >0. */
2658 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2660 file_data = dw2_get_file_names (objfile, per_cu);
2661 if (file_data == NULL)
2664 return file_data->file_names[file_data->num_file_names - 1];
2668 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2669 struct objfile *objfile, int global,
2670 int (*callback) (struct block *,
2671 struct symbol *, void *),
2672 void *data, symbol_compare_ftype *match,
2673 symbol_compare_ftype *ordered_compare)
2675 /* Currently unimplemented; used for Ada. The function can be called if the
2676 current language is Ada for a non-Ada objfile using GNU index. As Ada
2677 does not look for non-Ada symbols this function should just return. */
2681 dw2_expand_symtabs_matching
2682 (struct objfile *objfile,
2683 int (*file_matcher) (const char *, void *),
2684 int (*name_matcher) (const char *, void *),
2685 enum search_domain kind,
2690 struct mapped_index *index;
2692 dw2_setup (objfile);
2694 /* index_table is NULL if OBJF_READNOW. */
2695 if (!dwarf2_per_objfile->index_table)
2697 index = dwarf2_per_objfile->index_table;
2699 if (file_matcher != NULL)
2701 struct cleanup *cleanup;
2702 htab_t visited_found, visited_not_found;
2704 visited_found = htab_create_alloc (10,
2705 htab_hash_pointer, htab_eq_pointer,
2706 NULL, xcalloc, xfree);
2707 cleanup = make_cleanup_htab_delete (visited_found);
2708 visited_not_found = htab_create_alloc (10,
2709 htab_hash_pointer, htab_eq_pointer,
2710 NULL, xcalloc, xfree);
2711 make_cleanup_htab_delete (visited_not_found);
2713 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2714 + dwarf2_per_objfile->n_type_units); ++i)
2717 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2718 struct quick_file_names *file_data;
2721 per_cu->v.quick->mark = 0;
2723 /* We only need to look at symtabs not already expanded. */
2724 if (per_cu->v.quick->symtab)
2727 file_data = dw2_get_file_names (objfile, per_cu);
2728 if (file_data == NULL)
2731 if (htab_find (visited_not_found, file_data) != NULL)
2733 else if (htab_find (visited_found, file_data) != NULL)
2735 per_cu->v.quick->mark = 1;
2739 for (j = 0; j < file_data->num_file_names; ++j)
2741 if (file_matcher (file_data->file_names[j], data))
2743 per_cu->v.quick->mark = 1;
2748 slot = htab_find_slot (per_cu->v.quick->mark
2750 : visited_not_found,
2755 do_cleanups (cleanup);
2758 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2760 offset_type idx = 2 * iter;
2762 offset_type *vec, vec_len, vec_idx;
2764 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2767 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2769 if (! (*name_matcher) (name, data))
2772 /* The name was matched, now expand corresponding CUs that were
2774 vec = (offset_type *) (index->constant_pool
2775 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2776 vec_len = MAYBE_SWAP (vec[0]);
2777 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2779 struct dwarf2_per_cu_data *per_cu;
2781 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2782 if (file_matcher == NULL || per_cu->v.quick->mark)
2783 dw2_instantiate_symtab (per_cu);
2788 static struct symtab *
2789 dw2_find_pc_sect_symtab (struct objfile *objfile,
2790 struct minimal_symbol *msymbol,
2792 struct obj_section *section,
2795 struct dwarf2_per_cu_data *data;
2797 dw2_setup (objfile);
2799 if (!objfile->psymtabs_addrmap)
2802 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2806 if (warn_if_readin && data->v.quick->symtab)
2807 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2808 paddress (get_objfile_arch (objfile), pc));
2810 return dw2_instantiate_symtab (data);
2814 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2815 void *data, int need_fullname)
2818 struct cleanup *cleanup;
2819 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
2820 NULL, xcalloc, xfree);
2822 cleanup = make_cleanup_htab_delete (visited);
2823 dw2_setup (objfile);
2825 /* We can ignore file names coming from already-expanded CUs. */
2826 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2827 + dwarf2_per_objfile->n_type_units); ++i)
2829 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2831 if (per_cu->v.quick->symtab)
2833 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
2836 *slot = per_cu->v.quick->file_names;
2840 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2841 + dwarf2_per_objfile->n_type_units); ++i)
2844 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2845 struct quick_file_names *file_data;
2848 /* We only need to look at symtabs not already expanded. */
2849 if (per_cu->v.quick->symtab)
2852 file_data = dw2_get_file_names (objfile, per_cu);
2853 if (file_data == NULL)
2856 slot = htab_find_slot (visited, file_data, INSERT);
2859 /* Already visited. */
2864 for (j = 0; j < file_data->num_file_names; ++j)
2866 const char *this_real_name;
2869 this_real_name = dw2_get_real_path (objfile, file_data, j);
2871 this_real_name = NULL;
2872 (*fun) (file_data->file_names[j], this_real_name, data);
2876 do_cleanups (cleanup);
2880 dw2_has_symbols (struct objfile *objfile)
2885 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2888 dw2_find_last_source_symtab,
2889 dw2_forget_cached_source_info,
2890 dw2_map_symtabs_matching_filename,
2892 dw2_pre_expand_symtabs_matching,
2896 dw2_expand_symtabs_for_function,
2897 dw2_expand_all_symtabs,
2898 dw2_expand_symtabs_with_filename,
2899 dw2_find_symbol_file,
2900 dw2_map_matching_symbols,
2901 dw2_expand_symtabs_matching,
2902 dw2_find_pc_sect_symtab,
2903 dw2_map_symbol_filenames
2906 /* Initialize for reading DWARF for this objfile. Return 0 if this
2907 file will use psymtabs, or 1 if using the GNU index. */
2910 dwarf2_initialize_objfile (struct objfile *objfile)
2912 /* If we're about to read full symbols, don't bother with the
2913 indices. In this case we also don't care if some other debug
2914 format is making psymtabs, because they are all about to be
2916 if ((objfile->flags & OBJF_READNOW))
2920 dwarf2_per_objfile->using_index = 1;
2921 create_all_comp_units (objfile);
2922 create_debug_types_hash_table (objfile);
2923 dwarf2_per_objfile->quick_file_names_table =
2924 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2926 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2927 + dwarf2_per_objfile->n_type_units); ++i)
2929 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2931 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2932 struct dwarf2_per_cu_quick_data);
2935 /* Return 1 so that gdb sees the "quick" functions. However,
2936 these functions will be no-ops because we will have expanded
2941 if (dwarf2_read_index (objfile))
2949 /* Build a partial symbol table. */
2952 dwarf2_build_psymtabs (struct objfile *objfile)
2954 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2956 init_psymbol_list (objfile, 1024);
2959 dwarf2_build_psymtabs_hard (objfile);
2962 /* Return TRUE if OFFSET is within CU_HEADER. */
2965 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2967 unsigned int bottom = cu_header->offset;
2968 unsigned int top = (cu_header->offset
2970 + cu_header->initial_length_size);
2972 return (offset >= bottom && offset < top);
2975 /* Read in the comp unit header information from the debug_info at info_ptr.
2976 NOTE: This leaves members offset, first_die_offset to be filled in
2980 read_comp_unit_head (struct comp_unit_head *cu_header,
2981 gdb_byte *info_ptr, bfd *abfd)
2984 unsigned int bytes_read;
2986 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2987 cu_header->initial_length_size = bytes_read;
2988 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2989 info_ptr += bytes_read;
2990 cu_header->version = read_2_bytes (abfd, info_ptr);
2992 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2994 info_ptr += bytes_read;
2995 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2997 signed_addr = bfd_get_sign_extend_vma (abfd);
2998 if (signed_addr < 0)
2999 internal_error (__FILE__, __LINE__,
3000 _("read_comp_unit_head: dwarf from non elf file"));
3001 cu_header->signed_addr_p = signed_addr;
3006 /* Subroutine of read_and_check_comp_unit_head and
3007 read_and_check_type_unit_head to simplify them.
3008 Perform various error checking on the header. */
3011 error_check_comp_unit_head (struct comp_unit_head *header,
3012 struct dwarf2_section_info *section)
3014 bfd *abfd = section->asection->owner;
3015 const char *filename = bfd_get_filename (abfd);
3017 if (header->version != 2 && header->version != 3 && header->version != 4)
3018 error (_("Dwarf Error: wrong version in compilation unit header "
3019 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3022 if (header->abbrev_offset
3023 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
3024 &dwarf2_per_objfile->abbrev))
3025 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3026 "(offset 0x%lx + 6) [in module %s]"),
3027 (long) header->abbrev_offset, (long) header->offset,
3030 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3031 avoid potential 32-bit overflow. */
3032 if (((unsigned long) header->offset
3033 + header->length + header->initial_length_size)
3035 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3036 "(offset 0x%lx + 0) [in module %s]"),
3037 (long) header->length, (long) header->offset,
3041 /* Read in a CU/TU header and perform some basic error checking.
3042 The contents of the header are stored in HEADER.
3043 The result is a pointer to the start of the first DIE. */
3046 read_and_check_comp_unit_head (struct comp_unit_head *header,
3047 struct dwarf2_section_info *section,
3049 int is_debug_types_section)
3051 gdb_byte *beg_of_comp_unit = info_ptr;
3052 bfd *abfd = section->asection->owner;
3054 header->offset = beg_of_comp_unit - section->buffer;
3056 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3058 /* If we're reading a type unit, skip over the signature and
3059 type_offset fields. */
3060 if (is_debug_types_section)
3061 info_ptr += 8 /*signature*/ + header->offset_size;
3063 header->first_die_offset = info_ptr - beg_of_comp_unit;
3065 error_check_comp_unit_head (header, section);
3070 /* Read in the types comp unit header information from .debug_types entry at
3071 types_ptr. The result is a pointer to one past the end of the header. */
3074 read_and_check_type_unit_head (struct comp_unit_head *header,
3075 struct dwarf2_section_info *section,
3077 ULONGEST *signature, unsigned int *type_offset)
3079 gdb_byte *beg_of_comp_unit = info_ptr;
3080 bfd *abfd = section->asection->owner;
3082 header->offset = beg_of_comp_unit - section->buffer;
3084 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3086 /* If we're reading a type unit, skip over the signature and
3087 type_offset fields. */
3088 if (signature != NULL)
3089 *signature = read_8_bytes (abfd, info_ptr);
3091 if (type_offset != NULL)
3092 *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size);
3093 info_ptr += header->offset_size;
3095 header->first_die_offset = info_ptr - beg_of_comp_unit;
3097 error_check_comp_unit_head (header, section);
3102 /* Allocate a new partial symtab for file named NAME and mark this new
3103 partial symtab as being an include of PST. */
3106 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3107 struct objfile *objfile)
3109 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3111 subpst->section_offsets = pst->section_offsets;
3112 subpst->textlow = 0;
3113 subpst->texthigh = 0;
3115 subpst->dependencies = (struct partial_symtab **)
3116 obstack_alloc (&objfile->objfile_obstack,
3117 sizeof (struct partial_symtab *));
3118 subpst->dependencies[0] = pst;
3119 subpst->number_of_dependencies = 1;
3121 subpst->globals_offset = 0;
3122 subpst->n_global_syms = 0;
3123 subpst->statics_offset = 0;
3124 subpst->n_static_syms = 0;
3125 subpst->symtab = NULL;
3126 subpst->read_symtab = pst->read_symtab;
3129 /* No private part is necessary for include psymtabs. This property
3130 can be used to differentiate between such include psymtabs and
3131 the regular ones. */
3132 subpst->read_symtab_private = NULL;
3135 /* Read the Line Number Program data and extract the list of files
3136 included by the source file represented by PST. Build an include
3137 partial symtab for each of these included files. */
3140 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3141 struct die_info *die,
3142 struct partial_symtab *pst)
3144 struct objfile *objfile = cu->objfile;
3145 bfd *abfd = objfile->obfd;
3146 struct line_header *lh = NULL;
3147 struct attribute *attr;
3149 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3152 unsigned int line_offset = DW_UNSND (attr);
3154 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3157 return; /* No linetable, so no includes. */
3159 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3160 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
3162 free_line_header (lh);
3166 hash_type_signature (const void *item)
3168 const struct signatured_type *type_sig = item;
3170 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3171 return type_sig->signature;
3175 eq_type_signature (const void *item_lhs, const void *item_rhs)
3177 const struct signatured_type *lhs = item_lhs;
3178 const struct signatured_type *rhs = item_rhs;
3180 return lhs->signature == rhs->signature;
3183 /* Allocate a hash table for signatured types. */
3186 allocate_signatured_type_table (struct objfile *objfile)
3188 return htab_create_alloc_ex (41,
3189 hash_type_signature,
3192 &objfile->objfile_obstack,
3193 hashtab_obstack_allocate,
3194 dummy_obstack_deallocate);
3197 /* A helper function to add a signatured type CU to a table. */
3200 add_signatured_type_cu_to_table (void **slot, void *datum)
3202 struct signatured_type *sigt = *slot;
3203 struct dwarf2_per_cu_data ***datap = datum;
3205 **datap = &sigt->per_cu;
3211 /* Create the hash table of all entries in the .debug_types section(s).
3212 The result is zero if there is an error (e.g. missing .debug_types section),
3213 otherwise non-zero. */
3216 create_debug_types_hash_table (struct objfile *objfile)
3218 htab_t types_htab = NULL;
3219 struct dwarf2_per_cu_data **iter;
3221 struct dwarf2_section_info *section;
3223 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3225 dwarf2_per_objfile->signatured_types = NULL;
3230 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3234 gdb_byte *info_ptr, *end_ptr;
3236 dwarf2_read_section (objfile, section);
3237 info_ptr = section->buffer;
3239 if (info_ptr == NULL)
3242 if (types_htab == NULL)
3243 types_htab = allocate_signatured_type_table (objfile);
3245 if (dwarf2_die_debug)
3246 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3248 end_ptr = info_ptr + section->size;
3249 while (info_ptr < end_ptr)
3251 unsigned int offset;
3252 unsigned int type_offset;
3254 struct signatured_type *type_sig;
3256 gdb_byte *ptr = info_ptr;
3257 struct comp_unit_head header;
3259 offset = ptr - section->buffer;
3261 /* We need to read the type's signature in order to build the hash
3262 table, but we don't need anything else just yet. */
3264 ptr = read_and_check_type_unit_head (&header, section, ptr,
3265 &signature, &type_offset);
3267 /* Skip dummy type units. */
3268 if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
3270 info_ptr = info_ptr + header.initial_length_size + header.length;
3274 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3275 memset (type_sig, 0, sizeof (*type_sig));
3276 type_sig->signature = signature;
3277 type_sig->type_offset = type_offset;
3278 type_sig->per_cu.objfile = objfile;
3279 type_sig->per_cu.debug_types_section = section;
3280 type_sig->per_cu.offset = offset;
3282 slot = htab_find_slot (types_htab, type_sig, INSERT);
3283 gdb_assert (slot != NULL);
3286 const struct signatured_type *dup_sig = *slot;
3288 complaint (&symfile_complaints,
3289 _("debug type entry at offset 0x%x is duplicate to the "
3290 "entry at offset 0x%x, signature 0x%s"),
3291 offset, dup_sig->per_cu.offset,
3292 phex (signature, sizeof (signature)));
3293 gdb_assert (signature == dup_sig->signature);
3297 if (dwarf2_die_debug)
3298 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3299 offset, phex (signature, sizeof (signature)));
3301 info_ptr = info_ptr + header.initial_length_size + header.length;
3305 dwarf2_per_objfile->signatured_types = types_htab;
3307 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
3308 dwarf2_per_objfile->all_type_units
3309 = obstack_alloc (&objfile->objfile_obstack,
3310 dwarf2_per_objfile->n_type_units
3311 * sizeof (struct dwarf2_per_cu_data *));
3312 iter = &dwarf2_per_objfile->all_type_units[0];
3313 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
3314 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
3315 == dwarf2_per_objfile->n_type_units);
3320 /* Lookup a signature based type.
3321 Returns NULL if SIG is not present in the table. */
3323 static struct signatured_type *
3324 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3326 struct signatured_type find_entry, *entry;
3328 if (dwarf2_per_objfile->signatured_types == NULL)
3330 complaint (&symfile_complaints,
3331 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3335 find_entry.signature = sig;
3336 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3340 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3343 init_cu_die_reader (struct die_reader_specs *reader,
3344 struct dwarf2_cu *cu)
3346 reader->abfd = cu->objfile->obfd;
3348 if (cu->per_cu->debug_types_section)
3350 gdb_assert (cu->per_cu->debug_types_section->readin);
3351 reader->buffer = cu->per_cu->debug_types_section->buffer;
3355 gdb_assert (dwarf2_per_objfile->info.readin);
3356 reader->buffer = dwarf2_per_objfile->info.buffer;
3360 /* Find the base address of the compilation unit for range lists and
3361 location lists. It will normally be specified by DW_AT_low_pc.
3362 In DWARF-3 draft 4, the base address could be overridden by
3363 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3364 compilation units with discontinuous ranges. */
3367 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3369 struct attribute *attr;
3372 cu->base_address = 0;
3374 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3377 cu->base_address = DW_ADDR (attr);
3382 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3385 cu->base_address = DW_ADDR (attr);
3391 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3392 to combine the common parts.
3393 Process compilation unit THIS_CU for a psymtab.
3394 SECTION is the section the CU/TU comes from,
3395 either .debug_info or .debug_types. */
3398 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
3399 struct dwarf2_section_info *section,
3400 int is_debug_types_section)
3402 struct objfile *objfile = this_cu->objfile;
3403 bfd *abfd = objfile->obfd;
3404 gdb_byte *buffer = section->buffer;
3405 gdb_byte *info_ptr = buffer + this_cu->offset;
3406 unsigned int buffer_size = section->size;
3407 gdb_byte *beg_of_comp_unit = info_ptr;
3408 struct die_info *comp_unit_die;
3409 struct partial_symtab *pst;
3411 struct cleanup *back_to_inner;
3412 struct dwarf2_cu cu;
3413 int has_children, has_pc_info;
3414 struct attribute *attr;
3415 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3416 struct die_reader_specs reader_specs;
3417 const char *filename;
3419 /* If this compilation unit was already read in, free the
3420 cached copy in order to read it in again. This is
3421 necessary because we skipped some symbols when we first
3422 read in the compilation unit (see load_partial_dies).
3423 This problem could be avoided, but the benefit is
3425 if (this_cu->cu != NULL)
3426 free_one_cached_comp_unit (this_cu->cu);
3428 /* Note that this is a pointer to our stack frame, being
3429 added to a global data structure. It will be cleaned up
3430 in free_stack_comp_unit when we finish with this
3431 compilation unit. */
3432 init_one_comp_unit (&cu, this_cu);
3433 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3435 info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr,
3436 is_debug_types_section);
3438 /* Skip dummy compilation units. */
3439 if (info_ptr >= buffer + buffer_size
3440 || peek_abbrev_code (abfd, info_ptr) == 0)
3442 do_cleanups (back_to_inner);
3446 cu.list_in_scope = &file_symbols;
3448 /* Read the abbrevs for this compilation unit into a table. */
3449 dwarf2_read_abbrevs (&cu);
3450 make_cleanup (dwarf2_free_abbrev_table, &cu);
3452 /* Read the compilation unit die. */
3453 init_cu_die_reader (&reader_specs, &cu);
3454 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3457 if (is_debug_types_section)
3459 /* LENGTH has not been set yet for type units. */
3460 gdb_assert (this_cu->offset == cu.header.offset);
3461 this_cu->length = cu.header.length + cu.header.initial_length_size;
3463 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3465 do_cleanups (back_to_inner);
3469 prepare_one_comp_unit (&cu, comp_unit_die);
3471 /* Allocate a new partial symbol table structure. */
3472 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3473 if (attr == NULL || !DW_STRING (attr))
3476 filename = DW_STRING (attr);
3477 pst = start_psymtab_common (objfile, objfile->section_offsets,
3479 /* TEXTLOW and TEXTHIGH are set below. */
3481 objfile->global_psymbols.next,
3482 objfile->static_psymbols.next);
3483 pst->psymtabs_addrmap_supported = 1;
3485 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3487 pst->dirname = DW_STRING (attr);
3489 pst->read_symtab_private = this_cu;
3491 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3493 /* Store the function that reads in the rest of the symbol table. */
3494 pst->read_symtab = dwarf2_psymtab_to_symtab;
3496 this_cu->v.psymtab = pst;
3498 dwarf2_find_base_address (comp_unit_die, &cu);
3500 /* Possibly set the default values of LOWPC and HIGHPC from
3502 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3503 &best_highpc, &cu, pst);
3504 if (has_pc_info == 1 && best_lowpc < best_highpc)
3505 /* Store the contiguous range if it is not empty; it can be empty for
3506 CUs with no code. */
3507 addrmap_set_empty (objfile->psymtabs_addrmap,
3508 best_lowpc + baseaddr,
3509 best_highpc + baseaddr - 1, pst);
3511 /* Check if comp unit has_children.
3512 If so, read the rest of the partial symbols from this comp unit.
3513 If not, there's no more debug_info for this comp unit. */
3516 struct partial_die_info *first_die;
3517 CORE_ADDR lowpc, highpc;
3519 lowpc = ((CORE_ADDR) -1);
3520 highpc = ((CORE_ADDR) 0);
3522 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3524 scan_partial_symbols (first_die, &lowpc, &highpc,
3525 ! has_pc_info, &cu);
3527 /* If we didn't find a lowpc, set it to highpc to avoid
3528 complaints from `maint check'. */
3529 if (lowpc == ((CORE_ADDR) -1))
3532 /* If the compilation unit didn't have an explicit address range,
3533 then use the information extracted from its child dies. */
3537 best_highpc = highpc;
3540 pst->textlow = best_lowpc + baseaddr;
3541 pst->texthigh = best_highpc + baseaddr;
3543 pst->n_global_syms = objfile->global_psymbols.next -
3544 (objfile->global_psymbols.list + pst->globals_offset);
3545 pst->n_static_syms = objfile->static_psymbols.next -
3546 (objfile->static_psymbols.list + pst->statics_offset);
3547 sort_pst_symbols (pst);
3549 if (is_debug_types_section)
3551 /* It's not clear we want to do anything with stmt lists here.
3552 Waiting to see what gcc ultimately does. */
3556 /* Get the list of files included in the current compilation unit,
3557 and build a psymtab for each of them. */
3558 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3561 do_cleanups (back_to_inner);
3564 /* Traversal function for htab_traverse_noresize.
3565 Process one .debug_types comp-unit. */
3568 process_type_comp_unit (void **slot, void *info)
3570 struct signatured_type *entry = (struct signatured_type *) *slot;
3571 struct dwarf2_per_cu_data *this_cu;
3573 gdb_assert (info == NULL);
3574 this_cu = &entry->per_cu;
3576 gdb_assert (this_cu->debug_types_section->readin);
3577 process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1);
3582 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3583 Build partial symbol tables for the .debug_types comp-units. */
3586 build_type_psymtabs (struct objfile *objfile)
3588 if (! create_debug_types_hash_table (objfile))
3591 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3592 process_type_comp_unit, NULL);
3595 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3598 psymtabs_addrmap_cleanup (void *o)
3600 struct objfile *objfile = o;
3602 objfile->psymtabs_addrmap = NULL;
3605 /* Build the partial symbol table by doing a quick pass through the
3606 .debug_info and .debug_abbrev sections. */
3609 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3611 struct cleanup *back_to, *addrmap_cleanup;
3612 struct obstack temp_obstack;
3615 dwarf2_per_objfile->reading_partial_symbols = 1;
3617 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3619 /* Any cached compilation units will be linked by the per-objfile
3620 read_in_chain. Make sure to free them when we're done. */
3621 back_to = make_cleanup (free_cached_comp_units, NULL);
3623 build_type_psymtabs (objfile);
3625 create_all_comp_units (objfile);
3627 /* Create a temporary address map on a temporary obstack. We later
3628 copy this to the final obstack. */
3629 obstack_init (&temp_obstack);
3630 make_cleanup_obstack_free (&temp_obstack);
3631 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3632 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3634 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3636 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3638 process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0);
3641 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3642 &objfile->objfile_obstack);
3643 discard_cleanups (addrmap_cleanup);
3645 do_cleanups (back_to);
3648 /* Load the partial DIEs for a secondary CU into memory. */
3651 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
3653 struct objfile *objfile = this_cu->objfile;
3654 bfd *abfd = objfile->obfd;
3656 struct die_info *comp_unit_die;
3657 struct dwarf2_cu *cu;
3658 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3660 struct die_reader_specs reader_specs;
3662 struct dwarf2_section_info *section = &dwarf2_per_objfile->info;
3664 gdb_assert (! this_cu->debug_types_section);
3666 gdb_assert (section->readin);
3667 info_ptr = section->buffer + this_cu->offset;
3669 if (this_cu->cu == NULL)
3671 cu = xmalloc (sizeof (*cu));
3672 init_one_comp_unit (cu, this_cu);
3676 /* If an error occurs while loading, release our storage. */
3677 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
3679 info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr,
3682 /* Skip dummy compilation units. */
3683 if (info_ptr >= (section->buffer + section->size)
3684 || peek_abbrev_code (abfd, info_ptr) == 0)
3686 do_cleanups (free_cu_cleanup);
3690 /* Link this CU into read_in_chain. */
3691 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3692 dwarf2_per_objfile->read_in_chain = this_cu;
3697 info_ptr += cu->header.first_die_offset;
3700 /* Read the abbrevs for this compilation unit into a table. */
3701 gdb_assert (cu->dwarf2_abbrevs == NULL);
3702 dwarf2_read_abbrevs (cu);
3703 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3705 /* Read the compilation unit die. */
3706 init_cu_die_reader (&reader_specs, cu);
3707 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3710 prepare_one_comp_unit (cu, comp_unit_die);
3712 /* Check if comp unit has_children.
3713 If so, read the rest of the partial symbols from this comp unit.
3714 If not, there's no more debug_info for this comp unit. */
3716 load_partial_dies (abfd, section->buffer, info_ptr, 0, cu);
3718 do_cleanups (free_abbrevs_cleanup);
3722 /* We've successfully allocated this compilation unit. Let our
3723 caller clean it up when finished with it. */
3724 discard_cleanups (free_cu_cleanup);
3728 /* Create a list of all compilation units in OBJFILE.
3729 This is only done for -readnow and building partial symtabs. */
3732 create_all_comp_units (struct objfile *objfile)
3736 struct dwarf2_per_cu_data **all_comp_units;
3739 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3740 info_ptr = dwarf2_per_objfile->info.buffer;
3744 all_comp_units = xmalloc (n_allocated
3745 * sizeof (struct dwarf2_per_cu_data *));
3747 while (info_ptr < dwarf2_per_objfile->info.buffer
3748 + dwarf2_per_objfile->info.size)
3750 unsigned int length, initial_length_size;
3751 struct dwarf2_per_cu_data *this_cu;
3752 unsigned int offset;
3754 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3756 /* Read just enough information to find out where the next
3757 compilation unit is. */
3758 length = read_initial_length (objfile->obfd, info_ptr,
3759 &initial_length_size);
3761 /* Save the compilation unit for later lookup. */
3762 this_cu = obstack_alloc (&objfile->objfile_obstack,
3763 sizeof (struct dwarf2_per_cu_data));
3764 memset (this_cu, 0, sizeof (*this_cu));
3765 this_cu->offset = offset;
3766 this_cu->length = length + initial_length_size;
3767 this_cu->objfile = objfile;
3769 if (n_comp_units == n_allocated)
3772 all_comp_units = xrealloc (all_comp_units,
3774 * sizeof (struct dwarf2_per_cu_data *));
3776 all_comp_units[n_comp_units++] = this_cu;
3778 info_ptr = info_ptr + this_cu->length;
3781 dwarf2_per_objfile->all_comp_units
3782 = obstack_alloc (&objfile->objfile_obstack,
3783 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3784 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3785 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3786 xfree (all_comp_units);
3787 dwarf2_per_objfile->n_comp_units = n_comp_units;
3790 /* Process all loaded DIEs for compilation unit CU, starting at
3791 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3792 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3793 DW_AT_ranges). If NEED_PC is set, then this function will set
3794 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3795 and record the covered ranges in the addrmap. */
3798 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3799 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3801 struct partial_die_info *pdi;
3803 /* Now, march along the PDI's, descending into ones which have
3804 interesting children but skipping the children of the other ones,
3805 until we reach the end of the compilation unit. */
3811 fixup_partial_die (pdi, cu);
3813 /* Anonymous namespaces or modules have no name but have interesting
3814 children, so we need to look at them. Ditto for anonymous
3817 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3818 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3822 case DW_TAG_subprogram:
3823 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3825 case DW_TAG_constant:
3826 case DW_TAG_variable:
3827 case DW_TAG_typedef:
3828 case DW_TAG_union_type:
3829 if (!pdi->is_declaration)
3831 add_partial_symbol (pdi, cu);
3834 case DW_TAG_class_type:
3835 case DW_TAG_interface_type:
3836 case DW_TAG_structure_type:
3837 if (!pdi->is_declaration)
3839 add_partial_symbol (pdi, cu);
3842 case DW_TAG_enumeration_type:
3843 if (!pdi->is_declaration)
3844 add_partial_enumeration (pdi, cu);
3846 case DW_TAG_base_type:
3847 case DW_TAG_subrange_type:
3848 /* File scope base type definitions are added to the partial
3850 add_partial_symbol (pdi, cu);
3852 case DW_TAG_namespace:
3853 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3856 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3863 /* If the die has a sibling, skip to the sibling. */
3865 pdi = pdi->die_sibling;
3869 /* Functions used to compute the fully scoped name of a partial DIE.
3871 Normally, this is simple. For C++, the parent DIE's fully scoped
3872 name is concatenated with "::" and the partial DIE's name. For
3873 Java, the same thing occurs except that "." is used instead of "::".
3874 Enumerators are an exception; they use the scope of their parent
3875 enumeration type, i.e. the name of the enumeration type is not
3876 prepended to the enumerator.
3878 There are two complexities. One is DW_AT_specification; in this
3879 case "parent" means the parent of the target of the specification,
3880 instead of the direct parent of the DIE. The other is compilers
3881 which do not emit DW_TAG_namespace; in this case we try to guess
3882 the fully qualified name of structure types from their members'
3883 linkage names. This must be done using the DIE's children rather
3884 than the children of any DW_AT_specification target. We only need
3885 to do this for structures at the top level, i.e. if the target of
3886 any DW_AT_specification (if any; otherwise the DIE itself) does not
3889 /* Compute the scope prefix associated with PDI's parent, in
3890 compilation unit CU. The result will be allocated on CU's
3891 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3892 field. NULL is returned if no prefix is necessary. */
3894 partial_die_parent_scope (struct partial_die_info *pdi,
3895 struct dwarf2_cu *cu)
3897 char *grandparent_scope;
3898 struct partial_die_info *parent, *real_pdi;
3900 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3901 then this means the parent of the specification DIE. */
3904 while (real_pdi->has_specification)
3905 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3907 parent = real_pdi->die_parent;
3911 if (parent->scope_set)
3912 return parent->scope;
3914 fixup_partial_die (parent, cu);
3916 grandparent_scope = partial_die_parent_scope (parent, cu);
3918 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3919 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3920 Work around this problem here. */
3921 if (cu->language == language_cplus
3922 && parent->tag == DW_TAG_namespace
3923 && strcmp (parent->name, "::") == 0
3924 && grandparent_scope == NULL)
3926 parent->scope = NULL;
3927 parent->scope_set = 1;
3931 if (pdi->tag == DW_TAG_enumerator)
3932 /* Enumerators should not get the name of the enumeration as a prefix. */
3933 parent->scope = grandparent_scope;
3934 else if (parent->tag == DW_TAG_namespace
3935 || parent->tag == DW_TAG_module
3936 || parent->tag == DW_TAG_structure_type
3937 || parent->tag == DW_TAG_class_type
3938 || parent->tag == DW_TAG_interface_type
3939 || parent->tag == DW_TAG_union_type
3940 || parent->tag == DW_TAG_enumeration_type)
3942 if (grandparent_scope == NULL)
3943 parent->scope = parent->name;
3945 parent->scope = typename_concat (&cu->comp_unit_obstack,
3947 parent->name, 0, cu);
3951 /* FIXME drow/2004-04-01: What should we be doing with
3952 function-local names? For partial symbols, we should probably be
3954 complaint (&symfile_complaints,
3955 _("unhandled containing DIE tag %d for DIE at %d"),
3956 parent->tag, pdi->offset);
3957 parent->scope = grandparent_scope;
3960 parent->scope_set = 1;
3961 return parent->scope;
3964 /* Return the fully scoped name associated with PDI, from compilation unit
3965 CU. The result will be allocated with malloc. */
3967 partial_die_full_name (struct partial_die_info *pdi,
3968 struct dwarf2_cu *cu)
3972 /* If this is a template instantiation, we can not work out the
3973 template arguments from partial DIEs. So, unfortunately, we have
3974 to go through the full DIEs. At least any work we do building
3975 types here will be reused if full symbols are loaded later. */
3976 if (pdi->has_template_arguments)
3978 fixup_partial_die (pdi, cu);
3980 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3982 struct die_info *die;
3983 struct attribute attr;
3984 struct dwarf2_cu *ref_cu = cu;
3987 attr.form = DW_FORM_ref_addr;
3988 attr.u.addr = pdi->offset;
3989 die = follow_die_ref (NULL, &attr, &ref_cu);
3991 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3995 parent_scope = partial_die_parent_scope (pdi, cu);
3996 if (parent_scope == NULL)
3999 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
4003 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
4005 struct objfile *objfile = cu->objfile;
4007 char *actual_name = NULL;
4009 int built_actual_name = 0;
4011 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4013 actual_name = partial_die_full_name (pdi, cu);
4015 built_actual_name = 1;
4017 if (actual_name == NULL)
4018 actual_name = pdi->name;
4022 case DW_TAG_subprogram:
4023 if (pdi->is_external || cu->language == language_ada)
4025 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4026 of the global scope. But in Ada, we want to be able to access
4027 nested procedures globally. So all Ada subprograms are stored
4028 in the global scope. */
4029 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4030 mst_text, objfile); */
4031 add_psymbol_to_list (actual_name, strlen (actual_name),
4033 VAR_DOMAIN, LOC_BLOCK,
4034 &objfile->global_psymbols,
4035 0, pdi->lowpc + baseaddr,
4036 cu->language, objfile);
4040 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4041 mst_file_text, objfile); */
4042 add_psymbol_to_list (actual_name, strlen (actual_name),
4044 VAR_DOMAIN, LOC_BLOCK,
4045 &objfile->static_psymbols,
4046 0, pdi->lowpc + baseaddr,
4047 cu->language, objfile);
4050 case DW_TAG_constant:
4052 struct psymbol_allocation_list *list;
4054 if (pdi->is_external)
4055 list = &objfile->global_psymbols;
4057 list = &objfile->static_psymbols;
4058 add_psymbol_to_list (actual_name, strlen (actual_name),
4059 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4060 list, 0, 0, cu->language, objfile);
4063 case DW_TAG_variable:
4065 addr = decode_locdesc (pdi->locdesc, cu);
4069 && !dwarf2_per_objfile->has_section_at_zero)
4071 /* A global or static variable may also have been stripped
4072 out by the linker if unused, in which case its address
4073 will be nullified; do not add such variables into partial
4074 symbol table then. */
4076 else if (pdi->is_external)
4079 Don't enter into the minimal symbol tables as there is
4080 a minimal symbol table entry from the ELF symbols already.
4081 Enter into partial symbol table if it has a location
4082 descriptor or a type.
4083 If the location descriptor is missing, new_symbol will create
4084 a LOC_UNRESOLVED symbol, the address of the variable will then
4085 be determined from the minimal symbol table whenever the variable
4087 The address for the partial symbol table entry is not
4088 used by GDB, but it comes in handy for debugging partial symbol
4091 if (pdi->locdesc || pdi->has_type)
4092 add_psymbol_to_list (actual_name, strlen (actual_name),
4094 VAR_DOMAIN, LOC_STATIC,
4095 &objfile->global_psymbols,
4097 cu->language, objfile);
4101 /* Static Variable. Skip symbols without location descriptors. */
4102 if (pdi->locdesc == NULL)
4104 if (built_actual_name)
4105 xfree (actual_name);
4108 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4109 mst_file_data, objfile); */
4110 add_psymbol_to_list (actual_name, strlen (actual_name),
4112 VAR_DOMAIN, LOC_STATIC,
4113 &objfile->static_psymbols,
4115 cu->language, objfile);
4118 case DW_TAG_typedef:
4119 case DW_TAG_base_type:
4120 case DW_TAG_subrange_type:
4121 add_psymbol_to_list (actual_name, strlen (actual_name),
4123 VAR_DOMAIN, LOC_TYPEDEF,
4124 &objfile->static_psymbols,
4125 0, (CORE_ADDR) 0, cu->language, objfile);
4127 case DW_TAG_namespace:
4128 add_psymbol_to_list (actual_name, strlen (actual_name),
4130 VAR_DOMAIN, LOC_TYPEDEF,
4131 &objfile->global_psymbols,
4132 0, (CORE_ADDR) 0, cu->language, objfile);
4134 case DW_TAG_class_type:
4135 case DW_TAG_interface_type:
4136 case DW_TAG_structure_type:
4137 case DW_TAG_union_type:
4138 case DW_TAG_enumeration_type:
4139 /* Skip external references. The DWARF standard says in the section
4140 about "Structure, Union, and Class Type Entries": "An incomplete
4141 structure, union or class type is represented by a structure,
4142 union or class entry that does not have a byte size attribute
4143 and that has a DW_AT_declaration attribute." */
4144 if (!pdi->has_byte_size && pdi->is_declaration)
4146 if (built_actual_name)
4147 xfree (actual_name);
4151 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4152 static vs. global. */
4153 add_psymbol_to_list (actual_name, strlen (actual_name),
4155 STRUCT_DOMAIN, LOC_TYPEDEF,
4156 (cu->language == language_cplus
4157 || cu->language == language_java)
4158 ? &objfile->global_psymbols
4159 : &objfile->static_psymbols,
4160 0, (CORE_ADDR) 0, cu->language, objfile);
4163 case DW_TAG_enumerator:
4164 add_psymbol_to_list (actual_name, strlen (actual_name),
4166 VAR_DOMAIN, LOC_CONST,
4167 (cu->language == language_cplus
4168 || cu->language == language_java)
4169 ? &objfile->global_psymbols
4170 : &objfile->static_psymbols,
4171 0, (CORE_ADDR) 0, cu->language, objfile);
4177 if (built_actual_name)
4178 xfree (actual_name);
4181 /* Read a partial die corresponding to a namespace; also, add a symbol
4182 corresponding to that namespace to the symbol table. NAMESPACE is
4183 the name of the enclosing namespace. */
4186 add_partial_namespace (struct partial_die_info *pdi,
4187 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4188 int need_pc, struct dwarf2_cu *cu)
4190 /* Add a symbol for the namespace. */
4192 add_partial_symbol (pdi, cu);
4194 /* Now scan partial symbols in that namespace. */
4196 if (pdi->has_children)
4197 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4200 /* Read a partial die corresponding to a Fortran module. */
4203 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4204 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4206 /* Now scan partial symbols in that module. */
4208 if (pdi->has_children)
4209 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4212 /* Read a partial die corresponding to a subprogram and create a partial
4213 symbol for that subprogram. When the CU language allows it, this
4214 routine also defines a partial symbol for each nested subprogram
4215 that this subprogram contains.
4217 DIE my also be a lexical block, in which case we simply search
4218 recursively for suprograms defined inside that lexical block.
4219 Again, this is only performed when the CU language allows this
4220 type of definitions. */
4223 add_partial_subprogram (struct partial_die_info *pdi,
4224 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4225 int need_pc, struct dwarf2_cu *cu)
4227 if (pdi->tag == DW_TAG_subprogram)
4229 if (pdi->has_pc_info)
4231 if (pdi->lowpc < *lowpc)
4232 *lowpc = pdi->lowpc;
4233 if (pdi->highpc > *highpc)
4234 *highpc = pdi->highpc;
4238 struct objfile *objfile = cu->objfile;
4240 baseaddr = ANOFFSET (objfile->section_offsets,
4241 SECT_OFF_TEXT (objfile));
4242 addrmap_set_empty (objfile->psymtabs_addrmap,
4243 pdi->lowpc + baseaddr,
4244 pdi->highpc - 1 + baseaddr,
4245 cu->per_cu->v.psymtab);
4247 if (!pdi->is_declaration)
4248 /* Ignore subprogram DIEs that do not have a name, they are
4249 illegal. Do not emit a complaint at this point, we will
4250 do so when we convert this psymtab into a symtab. */
4252 add_partial_symbol (pdi, cu);
4256 if (! pdi->has_children)
4259 if (cu->language == language_ada)
4261 pdi = pdi->die_child;
4264 fixup_partial_die (pdi, cu);
4265 if (pdi->tag == DW_TAG_subprogram
4266 || pdi->tag == DW_TAG_lexical_block)
4267 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4268 pdi = pdi->die_sibling;
4273 /* Read a partial die corresponding to an enumeration type. */
4276 add_partial_enumeration (struct partial_die_info *enum_pdi,
4277 struct dwarf2_cu *cu)
4279 struct partial_die_info *pdi;
4281 if (enum_pdi->name != NULL)
4282 add_partial_symbol (enum_pdi, cu);
4284 pdi = enum_pdi->die_child;
4287 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4288 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4290 add_partial_symbol (pdi, cu);
4291 pdi = pdi->die_sibling;
4295 /* Return the initial uleb128 in the die at INFO_PTR. */
4298 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
4300 unsigned int bytes_read;
4302 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4305 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4306 Return the corresponding abbrev, or NULL if the number is zero (indicating
4307 an empty DIE). In either case *BYTES_READ will be set to the length of
4308 the initial number. */
4310 static struct abbrev_info *
4311 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4312 struct dwarf2_cu *cu)
4314 bfd *abfd = cu->objfile->obfd;
4315 unsigned int abbrev_number;
4316 struct abbrev_info *abbrev;
4318 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4320 if (abbrev_number == 0)
4323 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4326 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4327 abbrev_number, bfd_get_filename (abfd));
4333 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4334 Returns a pointer to the end of a series of DIEs, terminated by an empty
4335 DIE. Any children of the skipped DIEs will also be skipped. */
4338 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4340 struct abbrev_info *abbrev;
4341 unsigned int bytes_read;
4345 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4347 return info_ptr + bytes_read;
4349 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4353 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4354 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4355 abbrev corresponding to that skipped uleb128 should be passed in
4356 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4360 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4361 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4363 unsigned int bytes_read;
4364 struct attribute attr;
4365 bfd *abfd = cu->objfile->obfd;
4366 unsigned int form, i;
4368 for (i = 0; i < abbrev->num_attrs; i++)
4370 /* The only abbrev we care about is DW_AT_sibling. */
4371 if (abbrev->attrs[i].name == DW_AT_sibling)
4373 read_attribute (&attr, &abbrev->attrs[i],
4374 abfd, info_ptr, cu);
4375 if (attr.form == DW_FORM_ref_addr)
4376 complaint (&symfile_complaints,
4377 _("ignoring absolute DW_AT_sibling"));
4379 return buffer + dwarf2_get_ref_die_offset (&attr);
4382 /* If it isn't DW_AT_sibling, skip this attribute. */
4383 form = abbrev->attrs[i].form;
4387 case DW_FORM_ref_addr:
4388 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4389 and later it is offset sized. */
4390 if (cu->header.version == 2)
4391 info_ptr += cu->header.addr_size;
4393 info_ptr += cu->header.offset_size;
4396 info_ptr += cu->header.addr_size;
4403 case DW_FORM_flag_present:
4415 case DW_FORM_ref_sig8:
4418 case DW_FORM_string:
4419 read_direct_string (abfd, info_ptr, &bytes_read);
4420 info_ptr += bytes_read;
4422 case DW_FORM_sec_offset:
4424 info_ptr += cu->header.offset_size;
4426 case DW_FORM_exprloc:
4428 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4429 info_ptr += bytes_read;
4431 case DW_FORM_block1:
4432 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4434 case DW_FORM_block2:
4435 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4437 case DW_FORM_block4:
4438 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4442 case DW_FORM_ref_udata:
4443 info_ptr = skip_leb128 (abfd, info_ptr);
4445 case DW_FORM_indirect:
4446 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4447 info_ptr += bytes_read;
4448 /* We need to continue parsing from here, so just go back to
4450 goto skip_attribute;
4453 error (_("Dwarf Error: Cannot handle %s "
4454 "in DWARF reader [in module %s]"),
4455 dwarf_form_name (form),
4456 bfd_get_filename (abfd));
4460 if (abbrev->has_children)
4461 return skip_children (buffer, info_ptr, cu);
4466 /* Locate ORIG_PDI's sibling.
4467 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4471 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4472 gdb_byte *buffer, gdb_byte *info_ptr,
4473 bfd *abfd, struct dwarf2_cu *cu)
4475 /* Do we know the sibling already? */
4477 if (orig_pdi->sibling)
4478 return orig_pdi->sibling;
4480 /* Are there any children to deal with? */
4482 if (!orig_pdi->has_children)
4485 /* Skip the children the long way. */
4487 return skip_children (buffer, info_ptr, cu);
4490 /* Expand this partial symbol table into a full symbol table. */
4493 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4499 warning (_("bug: psymtab for %s is already read in."),
4506 printf_filtered (_("Reading in symbols for %s..."),
4508 gdb_flush (gdb_stdout);
4511 /* Restore our global data. */
4512 dwarf2_per_objfile = objfile_data (pst->objfile,
4513 dwarf2_objfile_data_key);
4515 /* If this psymtab is constructed from a debug-only objfile, the
4516 has_section_at_zero flag will not necessarily be correct. We
4517 can get the correct value for this flag by looking at the data
4518 associated with the (presumably stripped) associated objfile. */
4519 if (pst->objfile->separate_debug_objfile_backlink)
4521 struct dwarf2_per_objfile *dpo_backlink
4522 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4523 dwarf2_objfile_data_key);
4525 dwarf2_per_objfile->has_section_at_zero
4526 = dpo_backlink->has_section_at_zero;
4529 dwarf2_per_objfile->reading_partial_symbols = 0;
4531 psymtab_to_symtab_1 (pst);
4533 /* Finish up the debug error message. */
4535 printf_filtered (_("done.\n"));
4540 /* Reading in full CUs. */
4542 /* Add PER_CU to the queue. */
4545 queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
4547 struct dwarf2_queue_item *item;
4550 item = xmalloc (sizeof (*item));
4551 item->per_cu = per_cu;
4554 if (dwarf2_queue == NULL)
4555 dwarf2_queue = item;
4557 dwarf2_queue_tail->next = item;
4559 dwarf2_queue_tail = item;
4562 /* Process the queue. */
4565 process_queue (void)
4567 struct dwarf2_queue_item *item, *next_item;
4569 /* The queue starts out with one item, but following a DIE reference
4570 may load a new CU, adding it to the end of the queue. */
4571 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4573 if (dwarf2_per_objfile->using_index
4574 ? !item->per_cu->v.quick->symtab
4575 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4576 process_full_comp_unit (item->per_cu);
4578 item->per_cu->queued = 0;
4579 next_item = item->next;
4583 dwarf2_queue_tail = NULL;
4586 /* Free all allocated queue entries. This function only releases anything if
4587 an error was thrown; if the queue was processed then it would have been
4588 freed as we went along. */
4591 dwarf2_release_queue (void *dummy)
4593 struct dwarf2_queue_item *item, *last;
4595 item = dwarf2_queue;
4598 /* Anything still marked queued is likely to be in an
4599 inconsistent state, so discard it. */
4600 if (item->per_cu->queued)
4602 if (item->per_cu->cu != NULL)
4603 free_one_cached_comp_unit (item->per_cu->cu);
4604 item->per_cu->queued = 0;
4612 dwarf2_queue = dwarf2_queue_tail = NULL;
4615 /* Read in full symbols for PST, and anything it depends on. */
4618 psymtab_to_symtab_1 (struct partial_symtab *pst)
4620 struct dwarf2_per_cu_data *per_cu;
4621 struct cleanup *back_to;
4624 for (i = 0; i < pst->number_of_dependencies; i++)
4625 if (!pst->dependencies[i]->readin)
4627 /* Inform about additional files that need to be read in. */
4630 /* FIXME: i18n: Need to make this a single string. */
4631 fputs_filtered (" ", gdb_stdout);
4633 fputs_filtered ("and ", gdb_stdout);
4635 printf_filtered ("%s...", pst->dependencies[i]->filename);
4636 wrap_here (""); /* Flush output. */
4637 gdb_flush (gdb_stdout);
4639 psymtab_to_symtab_1 (pst->dependencies[i]);
4642 per_cu = pst->read_symtab_private;
4646 /* It's an include file, no symbols to read for it.
4647 Everything is in the parent symtab. */
4652 dw2_do_instantiate_symtab (per_cu);
4655 /* Load the DIEs associated with PER_CU into memory. */
4658 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4660 struct objfile *objfile = per_cu->objfile;
4661 bfd *abfd = objfile->obfd;
4662 struct dwarf2_cu *cu;
4663 unsigned int offset;
4664 gdb_byte *info_ptr, *beg_of_comp_unit;
4665 struct cleanup *free_cu_cleanup = NULL;
4666 struct attribute *attr;
4669 gdb_assert (! per_cu->debug_types_section);
4671 /* Set local variables from the partial symbol table info. */
4672 offset = per_cu->offset;
4674 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4675 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4676 beg_of_comp_unit = info_ptr;
4678 if (per_cu->cu == NULL)
4680 cu = xmalloc (sizeof (*cu));
4681 init_one_comp_unit (cu, per_cu);
4685 /* If an error occurs while loading, release our storage. */
4686 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4688 /* Read in the comp_unit header. */
4689 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4691 /* Skip dummy compilation units. */
4692 if (info_ptr >= (dwarf2_per_objfile->info.buffer
4693 + dwarf2_per_objfile->info.size)
4694 || peek_abbrev_code (abfd, info_ptr) == 0)
4696 do_cleanups (free_cu_cleanup);
4700 /* Complete the cu_header. */
4701 cu->header.offset = offset;
4702 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4704 /* Link this CU into read_in_chain. */
4705 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4706 dwarf2_per_objfile->read_in_chain = per_cu;
4711 info_ptr += cu->header.first_die_offset;
4714 cu->dies = read_comp_unit (info_ptr, cu);
4716 /* We try not to read any attributes in this function, because not
4717 all CUs needed for references have been loaded yet, and symbol
4718 table processing isn't initialized. But we have to set the CU language,
4719 or we won't be able to build types correctly. */
4720 prepare_one_comp_unit (cu, cu->dies);
4722 /* Similarly, if we do not read the producer, we can not apply
4723 producer-specific interpretation. */
4724 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4726 cu->producer = DW_STRING (attr);
4730 /* We've successfully allocated this compilation unit. Let our
4731 caller clean it up when finished with it. */
4732 discard_cleanups (free_cu_cleanup);
4736 /* Add a DIE to the delayed physname list. */
4739 add_to_method_list (struct type *type, int fnfield_index, int index,
4740 const char *name, struct die_info *die,
4741 struct dwarf2_cu *cu)
4743 struct delayed_method_info mi;
4745 mi.fnfield_index = fnfield_index;
4749 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4752 /* A cleanup for freeing the delayed method list. */
4755 free_delayed_list (void *ptr)
4757 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4758 if (cu->method_list != NULL)
4760 VEC_free (delayed_method_info, cu->method_list);
4761 cu->method_list = NULL;
4765 /* Compute the physnames of any methods on the CU's method list.
4767 The computation of method physnames is delayed in order to avoid the
4768 (bad) condition that one of the method's formal parameters is of an as yet
4772 compute_delayed_physnames (struct dwarf2_cu *cu)
4775 struct delayed_method_info *mi;
4776 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4778 const char *physname;
4779 struct fn_fieldlist *fn_flp
4780 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4781 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4782 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4786 /* Generate full symbol information for PER_CU, whose DIEs have
4787 already been loaded into memory. */
4790 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4792 struct dwarf2_cu *cu = per_cu->cu;
4793 struct objfile *objfile = per_cu->objfile;
4794 CORE_ADDR lowpc, highpc;
4795 struct symtab *symtab;
4796 struct cleanup *back_to, *delayed_list_cleanup;
4799 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4802 back_to = make_cleanup (really_free_pendings, NULL);
4803 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4805 cu->list_in_scope = &file_symbols;
4807 /* Do line number decoding in read_file_scope () */
4808 process_die (cu->dies, cu);
4810 /* Now that we have processed all the DIEs in the CU, all the types
4811 should be complete, and it should now be safe to compute all of the
4813 compute_delayed_physnames (cu);
4814 do_cleanups (delayed_list_cleanup);
4816 /* Some compilers don't define a DW_AT_high_pc attribute for the
4817 compilation unit. If the DW_AT_high_pc is missing, synthesize
4818 it, by scanning the DIE's below the compilation unit. */
4819 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4821 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4825 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4827 /* Set symtab language to language from DW_AT_language. If the
4828 compilation is from a C file generated by language preprocessors, do
4829 not set the language if it was already deduced by start_subfile. */
4830 if (!(cu->language == language_c && symtab->language != language_c))
4831 symtab->language = cu->language;
4833 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4834 produce DW_AT_location with location lists but it can be possibly
4835 invalid without -fvar-tracking.
4837 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4838 needed, it would be wrong due to missing DW_AT_producer there.
4840 Still one can confuse GDB by using non-standard GCC compilation
4841 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4843 if (cu->has_loclist && gcc_4_minor >= 0)
4844 symtab->locations_valid = 1;
4846 if (gcc_4_minor >= 5)
4847 symtab->epilogue_unwind_valid = 1;
4849 symtab->call_site_htab = cu->call_site_htab;
4852 if (dwarf2_per_objfile->using_index)
4853 per_cu->v.quick->symtab = symtab;
4856 struct partial_symtab *pst = per_cu->v.psymtab;
4857 pst->symtab = symtab;
4861 do_cleanups (back_to);
4864 /* Process a die and its children. */
4867 process_die (struct die_info *die, struct dwarf2_cu *cu)
4871 case DW_TAG_padding:
4873 case DW_TAG_compile_unit:
4874 read_file_scope (die, cu);
4876 case DW_TAG_type_unit:
4877 read_type_unit_scope (die, cu);
4879 case DW_TAG_subprogram:
4880 case DW_TAG_inlined_subroutine:
4881 read_func_scope (die, cu);
4883 case DW_TAG_lexical_block:
4884 case DW_TAG_try_block:
4885 case DW_TAG_catch_block:
4886 read_lexical_block_scope (die, cu);
4888 case DW_TAG_GNU_call_site:
4889 read_call_site_scope (die, cu);
4891 case DW_TAG_class_type:
4892 case DW_TAG_interface_type:
4893 case DW_TAG_structure_type:
4894 case DW_TAG_union_type:
4895 process_structure_scope (die, cu);
4897 case DW_TAG_enumeration_type:
4898 process_enumeration_scope (die, cu);
4901 /* These dies have a type, but processing them does not create
4902 a symbol or recurse to process the children. Therefore we can
4903 read them on-demand through read_type_die. */
4904 case DW_TAG_subroutine_type:
4905 case DW_TAG_set_type:
4906 case DW_TAG_array_type:
4907 case DW_TAG_pointer_type:
4908 case DW_TAG_ptr_to_member_type:
4909 case DW_TAG_reference_type:
4910 case DW_TAG_string_type:
4913 case DW_TAG_base_type:
4914 case DW_TAG_subrange_type:
4915 case DW_TAG_typedef:
4916 /* Add a typedef symbol for the type definition, if it has a
4918 new_symbol (die, read_type_die (die, cu), cu);
4920 case DW_TAG_common_block:
4921 read_common_block (die, cu);
4923 case DW_TAG_common_inclusion:
4925 case DW_TAG_namespace:
4926 processing_has_namespace_info = 1;
4927 read_namespace (die, cu);
4930 processing_has_namespace_info = 1;
4931 read_module (die, cu);
4933 case DW_TAG_imported_declaration:
4934 case DW_TAG_imported_module:
4935 processing_has_namespace_info = 1;
4936 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4937 || cu->language != language_fortran))
4938 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4939 dwarf_tag_name (die->tag));
4940 read_import_statement (die, cu);
4943 new_symbol (die, NULL, cu);
4948 /* A helper function for dwarf2_compute_name which determines whether DIE
4949 needs to have the name of the scope prepended to the name listed in the
4953 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4955 struct attribute *attr;
4959 case DW_TAG_namespace:
4960 case DW_TAG_typedef:
4961 case DW_TAG_class_type:
4962 case DW_TAG_interface_type:
4963 case DW_TAG_structure_type:
4964 case DW_TAG_union_type:
4965 case DW_TAG_enumeration_type:
4966 case DW_TAG_enumerator:
4967 case DW_TAG_subprogram:
4971 case DW_TAG_variable:
4972 case DW_TAG_constant:
4973 /* We only need to prefix "globally" visible variables. These include
4974 any variable marked with DW_AT_external or any variable that
4975 lives in a namespace. [Variables in anonymous namespaces
4976 require prefixing, but they are not DW_AT_external.] */
4978 if (dwarf2_attr (die, DW_AT_specification, cu))
4980 struct dwarf2_cu *spec_cu = cu;
4982 return die_needs_namespace (die_specification (die, &spec_cu),
4986 attr = dwarf2_attr (die, DW_AT_external, cu);
4987 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4988 && die->parent->tag != DW_TAG_module)
4990 /* A variable in a lexical block of some kind does not need a
4991 namespace, even though in C++ such variables may be external
4992 and have a mangled name. */
4993 if (die->parent->tag == DW_TAG_lexical_block
4994 || die->parent->tag == DW_TAG_try_block
4995 || die->parent->tag == DW_TAG_catch_block
4996 || die->parent->tag == DW_TAG_subprogram)
5005 /* Retrieve the last character from a mem_file. */
5008 do_ui_file_peek_last (void *object, const char *buffer, long length)
5010 char *last_char_p = (char *) object;
5013 *last_char_p = buffer[length - 1];
5016 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5017 compute the physname for the object, which include a method's
5018 formal parameters (C++/Java) and return type (Java).
5020 For Ada, return the DIE's linkage name rather than the fully qualified
5021 name. PHYSNAME is ignored..
5023 The result is allocated on the objfile_obstack and canonicalized. */
5026 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
5029 struct objfile *objfile = cu->objfile;
5032 name = dwarf2_name (die, cu);
5034 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5035 compute it by typename_concat inside GDB. */
5036 if (cu->language == language_ada
5037 || (cu->language == language_fortran && physname))
5039 /* For Ada unit, we prefer the linkage name over the name, as
5040 the former contains the exported name, which the user expects
5041 to be able to reference. Ideally, we want the user to be able
5042 to reference this entity using either natural or linkage name,
5043 but we haven't started looking at this enhancement yet. */
5044 struct attribute *attr;
5046 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5048 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5049 if (attr && DW_STRING (attr))
5050 return DW_STRING (attr);
5053 /* These are the only languages we know how to qualify names in. */
5055 && (cu->language == language_cplus || cu->language == language_java
5056 || cu->language == language_fortran))
5058 if (die_needs_namespace (die, cu))
5062 struct ui_file *buf;
5064 prefix = determine_prefix (die, cu);
5065 buf = mem_fileopen ();
5066 if (*prefix != '\0')
5068 char *prefixed_name = typename_concat (NULL, prefix, name,
5071 fputs_unfiltered (prefixed_name, buf);
5072 xfree (prefixed_name);
5075 fputs_unfiltered (name, buf);
5077 /* Template parameters may be specified in the DIE's DW_AT_name, or
5078 as children with DW_TAG_template_type_param or
5079 DW_TAG_value_type_param. If the latter, add them to the name
5080 here. If the name already has template parameters, then
5081 skip this step; some versions of GCC emit both, and
5082 it is more efficient to use the pre-computed name.
5084 Something to keep in mind about this process: it is very
5085 unlikely, or in some cases downright impossible, to produce
5086 something that will match the mangled name of a function.
5087 If the definition of the function has the same debug info,
5088 we should be able to match up with it anyway. But fallbacks
5089 using the minimal symbol, for instance to find a method
5090 implemented in a stripped copy of libstdc++, will not work.
5091 If we do not have debug info for the definition, we will have to
5092 match them up some other way.
5094 When we do name matching there is a related problem with function
5095 templates; two instantiated function templates are allowed to
5096 differ only by their return types, which we do not add here. */
5098 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5100 struct attribute *attr;
5101 struct die_info *child;
5104 die->building_fullname = 1;
5106 for (child = die->child; child != NULL; child = child->sibling)
5111 struct dwarf2_locexpr_baton *baton;
5114 if (child->tag != DW_TAG_template_type_param
5115 && child->tag != DW_TAG_template_value_param)
5120 fputs_unfiltered ("<", buf);
5124 fputs_unfiltered (", ", buf);
5126 attr = dwarf2_attr (child, DW_AT_type, cu);
5129 complaint (&symfile_complaints,
5130 _("template parameter missing DW_AT_type"));
5131 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5134 type = die_type (child, cu);
5136 if (child->tag == DW_TAG_template_type_param)
5138 c_print_type (type, "", buf, -1, 0);
5142 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5145 complaint (&symfile_complaints,
5146 _("template parameter missing "
5147 "DW_AT_const_value"));
5148 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5152 dwarf2_const_value_attr (attr, type, name,
5153 &cu->comp_unit_obstack, cu,
5154 &value, &bytes, &baton);
5156 if (TYPE_NOSIGN (type))
5157 /* GDB prints characters as NUMBER 'CHAR'. If that's
5158 changed, this can use value_print instead. */
5159 c_printchar (value, type, buf);
5162 struct value_print_options opts;
5165 v = dwarf2_evaluate_loc_desc (type, NULL,
5169 else if (bytes != NULL)
5171 v = allocate_value (type);
5172 memcpy (value_contents_writeable (v), bytes,
5173 TYPE_LENGTH (type));
5176 v = value_from_longest (type, value);
5178 /* Specify decimal so that we do not depend on
5180 get_formatted_print_options (&opts, 'd');
5182 value_print (v, buf, &opts);
5188 die->building_fullname = 0;
5192 /* Close the argument list, with a space if necessary
5193 (nested templates). */
5194 char last_char = '\0';
5195 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5196 if (last_char == '>')
5197 fputs_unfiltered (" >", buf);
5199 fputs_unfiltered (">", buf);
5203 /* For Java and C++ methods, append formal parameter type
5204 information, if PHYSNAME. */
5206 if (physname && die->tag == DW_TAG_subprogram
5207 && (cu->language == language_cplus
5208 || cu->language == language_java))
5210 struct type *type = read_type_die (die, cu);
5212 c_type_print_args (type, buf, 1, cu->language);
5214 if (cu->language == language_java)
5216 /* For java, we must append the return type to method
5218 if (die->tag == DW_TAG_subprogram)
5219 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5222 else if (cu->language == language_cplus)
5224 /* Assume that an artificial first parameter is
5225 "this", but do not crash if it is not. RealView
5226 marks unnamed (and thus unused) parameters as
5227 artificial; there is no way to differentiate
5229 if (TYPE_NFIELDS (type) > 0
5230 && TYPE_FIELD_ARTIFICIAL (type, 0)
5231 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5232 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5234 fputs_unfiltered (" const", buf);
5238 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
5240 ui_file_delete (buf);
5242 if (cu->language == language_cplus)
5245 = dwarf2_canonicalize_name (name, cu,
5246 &objfile->objfile_obstack);
5257 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5258 If scope qualifiers are appropriate they will be added. The result
5259 will be allocated on the objfile_obstack, or NULL if the DIE does
5260 not have a name. NAME may either be from a previous call to
5261 dwarf2_name or NULL.
5263 The output string will be canonicalized (if C++/Java). */
5266 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5268 return dwarf2_compute_name (name, die, cu, 0);
5271 /* Construct a physname for the given DIE in CU. NAME may either be
5272 from a previous call to dwarf2_name or NULL. The result will be
5273 allocated on the objfile_objstack or NULL if the DIE does not have a
5276 The output string will be canonicalized (if C++/Java). */
5279 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5281 struct objfile *objfile = cu->objfile;
5282 struct attribute *attr;
5283 const char *retval, *mangled = NULL, *canon = NULL;
5284 struct cleanup *back_to;
5287 /* In this case dwarf2_compute_name is just a shortcut not building anything
5289 if (!die_needs_namespace (die, cu))
5290 return dwarf2_compute_name (name, die, cu, 1);
5292 back_to = make_cleanup (null_cleanup, NULL);
5294 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5296 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5298 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5300 if (attr && DW_STRING (attr))
5304 mangled = DW_STRING (attr);
5306 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5307 type. It is easier for GDB users to search for such functions as
5308 `name(params)' than `long name(params)'. In such case the minimal
5309 symbol names do not match the full symbol names but for template
5310 functions there is never a need to look up their definition from their
5311 declaration so the only disadvantage remains the minimal symbol
5312 variant `long name(params)' does not have the proper inferior type.
5315 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5316 | (cu->language == language_java
5317 ? DMGL_JAVA | DMGL_RET_POSTFIX
5321 make_cleanup (xfree, demangled);
5331 if (canon == NULL || check_physname)
5333 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5335 if (canon != NULL && strcmp (physname, canon) != 0)
5337 /* It may not mean a bug in GDB. The compiler could also
5338 compute DW_AT_linkage_name incorrectly. But in such case
5339 GDB would need to be bug-to-bug compatible. */
5341 complaint (&symfile_complaints,
5342 _("Computed physname <%s> does not match demangled <%s> "
5343 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5344 physname, canon, mangled, die->offset, objfile->name);
5346 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5347 is available here - over computed PHYSNAME. It is safer
5348 against both buggy GDB and buggy compilers. */
5362 retval = obsavestring (retval, strlen (retval),
5363 &objfile->objfile_obstack);
5365 do_cleanups (back_to);
5369 /* Read the import statement specified by the given die and record it. */
5372 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5374 struct objfile *objfile = cu->objfile;
5375 struct attribute *import_attr;
5376 struct die_info *imported_die, *child_die;
5377 struct dwarf2_cu *imported_cu;
5378 const char *imported_name;
5379 const char *imported_name_prefix;
5380 const char *canonical_name;
5381 const char *import_alias;
5382 const char *imported_declaration = NULL;
5383 const char *import_prefix;
5384 VEC (const_char_ptr) *excludes = NULL;
5385 struct cleanup *cleanups;
5389 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5390 if (import_attr == NULL)
5392 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5393 dwarf_tag_name (die->tag));
5398 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5399 imported_name = dwarf2_name (imported_die, imported_cu);
5400 if (imported_name == NULL)
5402 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5404 The import in the following code:
5418 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5419 <52> DW_AT_decl_file : 1
5420 <53> DW_AT_decl_line : 6
5421 <54> DW_AT_import : <0x75>
5422 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5424 <5b> DW_AT_decl_file : 1
5425 <5c> DW_AT_decl_line : 2
5426 <5d> DW_AT_type : <0x6e>
5428 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5429 <76> DW_AT_byte_size : 4
5430 <77> DW_AT_encoding : 5 (signed)
5432 imports the wrong die ( 0x75 instead of 0x58 ).
5433 This case will be ignored until the gcc bug is fixed. */
5437 /* Figure out the local name after import. */
5438 import_alias = dwarf2_name (die, cu);
5440 /* Figure out where the statement is being imported to. */
5441 import_prefix = determine_prefix (die, cu);
5443 /* Figure out what the scope of the imported die is and prepend it
5444 to the name of the imported die. */
5445 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5447 if (imported_die->tag != DW_TAG_namespace
5448 && imported_die->tag != DW_TAG_module)
5450 imported_declaration = imported_name;
5451 canonical_name = imported_name_prefix;
5453 else if (strlen (imported_name_prefix) > 0)
5455 temp = alloca (strlen (imported_name_prefix)
5456 + 2 + strlen (imported_name) + 1);
5457 strcpy (temp, imported_name_prefix);
5458 strcat (temp, "::");
5459 strcat (temp, imported_name);
5460 canonical_name = temp;
5463 canonical_name = imported_name;
5465 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5467 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5468 for (child_die = die->child; child_die && child_die->tag;
5469 child_die = sibling_die (child_die))
5471 /* DWARF-4: A Fortran use statement with a “rename list” may be
5472 represented by an imported module entry with an import attribute
5473 referring to the module and owned entries corresponding to those
5474 entities that are renamed as part of being imported. */
5476 if (child_die->tag != DW_TAG_imported_declaration)
5478 complaint (&symfile_complaints,
5479 _("child DW_TAG_imported_declaration expected "
5480 "- DIE at 0x%x [in module %s]"),
5481 child_die->offset, objfile->name);
5485 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5486 if (import_attr == NULL)
5488 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5489 dwarf_tag_name (child_die->tag));
5494 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5496 imported_name = dwarf2_name (imported_die, imported_cu);
5497 if (imported_name == NULL)
5499 complaint (&symfile_complaints,
5500 _("child DW_TAG_imported_declaration has unknown "
5501 "imported name - DIE at 0x%x [in module %s]"),
5502 child_die->offset, objfile->name);
5506 VEC_safe_push (const_char_ptr, excludes, imported_name);
5508 process_die (child_die, cu);
5511 cp_add_using_directive (import_prefix,
5514 imported_declaration,
5516 &objfile->objfile_obstack);
5518 do_cleanups (cleanups);
5521 /* Cleanup function for read_file_scope. */
5524 free_cu_line_header (void *arg)
5526 struct dwarf2_cu *cu = arg;
5528 free_line_header (cu->line_header);
5529 cu->line_header = NULL;
5533 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5534 char **name, char **comp_dir)
5536 struct attribute *attr;
5541 /* Find the filename. Do not use dwarf2_name here, since the filename
5542 is not a source language identifier. */
5543 attr = dwarf2_attr (die, DW_AT_name, cu);
5546 *name = DW_STRING (attr);
5549 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5551 *comp_dir = DW_STRING (attr);
5552 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5554 *comp_dir = ldirname (*name);
5555 if (*comp_dir != NULL)
5556 make_cleanup (xfree, *comp_dir);
5558 if (*comp_dir != NULL)
5560 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5561 directory, get rid of it. */
5562 char *cp = strchr (*comp_dir, ':');
5564 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5569 *name = "<unknown>";
5572 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5573 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5574 COMP_DIR is the compilation directory.
5575 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5578 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5579 const char *comp_dir, int want_line_info)
5581 struct attribute *attr;
5582 struct objfile *objfile = cu->objfile;
5583 bfd *abfd = objfile->obfd;
5585 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5588 unsigned int line_offset = DW_UNSND (attr);
5589 struct line_header *line_header
5590 = dwarf_decode_line_header (line_offset, abfd, cu);
5594 cu->line_header = line_header;
5595 make_cleanup (free_cu_line_header, cu);
5596 dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info);
5601 /* Process DW_TAG_compile_unit. */
5604 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5606 struct objfile *objfile = cu->objfile;
5607 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5608 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5609 CORE_ADDR highpc = ((CORE_ADDR) 0);
5610 struct attribute *attr;
5612 char *comp_dir = NULL;
5613 struct die_info *child_die;
5614 bfd *abfd = objfile->obfd;
5617 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5619 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5621 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5622 from finish_block. */
5623 if (lowpc == ((CORE_ADDR) -1))
5628 find_file_and_directory (die, cu, &name, &comp_dir);
5630 attr = dwarf2_attr (die, DW_AT_language, cu);
5633 set_cu_language (DW_UNSND (attr), cu);
5636 attr = dwarf2_attr (die, DW_AT_producer, cu);
5638 cu->producer = DW_STRING (attr);
5640 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5641 standardised yet. As a workaround for the language detection we fall
5642 back to the DW_AT_producer string. */
5643 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5644 cu->language = language_opencl;
5646 /* We assume that we're processing GCC output. */
5647 processing_gcc_compilation = 2;
5649 processing_has_namespace_info = 0;
5651 start_symtab (name, comp_dir, lowpc);
5652 record_debugformat ("DWARF 2");
5653 record_producer (cu->producer);
5655 /* Decode line number information if present. We do this before
5656 processing child DIEs, so that the line header table is available
5657 for DW_AT_decl_file. */
5658 handle_DW_AT_stmt_list (die, cu, comp_dir, 1);
5660 /* Process all dies in compilation unit. */
5661 if (die->child != NULL)
5663 child_die = die->child;
5664 while (child_die && child_die->tag)
5666 process_die (child_die, cu);
5667 child_die = sibling_die (child_die);
5671 /* Decode macro information, if present. Dwarf 2 macro information
5672 refers to information in the line number info statement program
5673 header, so we can only read it if we've read the header
5675 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5676 if (attr && cu->line_header)
5678 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5679 complaint (&symfile_complaints,
5680 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5682 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5684 &dwarf2_per_objfile->macro, 1);
5688 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5689 if (attr && cu->line_header)
5691 unsigned int macro_offset = DW_UNSND (attr);
5693 dwarf_decode_macros (cu->line_header, macro_offset,
5695 &dwarf2_per_objfile->macinfo, 0);
5699 do_cleanups (back_to);
5702 /* Process DW_TAG_type_unit.
5703 For TUs we want to skip the first top level sibling if it's not the
5704 actual type being defined by this TU. In this case the first top
5705 level sibling is there to provide context only. */
5708 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5710 struct objfile *objfile = cu->objfile;
5711 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5713 struct attribute *attr;
5715 char *comp_dir = NULL;
5716 struct die_info *child_die;
5717 bfd *abfd = objfile->obfd;
5719 /* start_symtab needs a low pc, but we don't really have one.
5720 Do what read_file_scope would do in the absence of such info. */
5721 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5723 /* Find the filename. Do not use dwarf2_name here, since the filename
5724 is not a source language identifier. */
5725 attr = dwarf2_attr (die, DW_AT_name, cu);
5727 name = DW_STRING (attr);
5729 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5731 comp_dir = DW_STRING (attr);
5732 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5734 comp_dir = ldirname (name);
5735 if (comp_dir != NULL)
5736 make_cleanup (xfree, comp_dir);
5742 attr = dwarf2_attr (die, DW_AT_language, cu);
5744 set_cu_language (DW_UNSND (attr), cu);
5746 /* This isn't technically needed today. It is done for symmetry
5747 with read_file_scope. */
5748 attr = dwarf2_attr (die, DW_AT_producer, cu);
5750 cu->producer = DW_STRING (attr);
5752 /* We assume that we're processing GCC output. */
5753 processing_gcc_compilation = 2;
5755 processing_has_namespace_info = 0;
5757 start_symtab (name, comp_dir, lowpc);
5758 record_debugformat ("DWARF 2");
5759 record_producer (cu->producer);
5761 /* Decode line number information if present. We do this before
5762 processing child DIEs, so that the line header table is available
5763 for DW_AT_decl_file.
5764 We don't need the pc/line-number mapping for type units. */
5765 handle_DW_AT_stmt_list (die, cu, comp_dir, 0);
5767 /* Process the dies in the type unit. */
5768 if (die->child == NULL)
5770 dump_die_for_error (die);
5771 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5772 bfd_get_filename (abfd));
5775 child_die = die->child;
5777 while (child_die && child_die->tag)
5779 process_die (child_die, cu);
5781 child_die = sibling_die (child_die);
5784 do_cleanups (back_to);
5787 /* qsort helper for inherit_abstract_dies. */
5790 unsigned_int_compar (const void *ap, const void *bp)
5792 unsigned int a = *(unsigned int *) ap;
5793 unsigned int b = *(unsigned int *) bp;
5795 return (a > b) - (b > a);
5798 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5799 Inherit only the children of the DW_AT_abstract_origin DIE not being
5800 already referenced by DW_AT_abstract_origin from the children of the
5804 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5806 struct die_info *child_die;
5807 unsigned die_children_count;
5808 /* CU offsets which were referenced by children of the current DIE. */
5810 unsigned *offsets_end, *offsetp;
5811 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5812 struct die_info *origin_die;
5813 /* Iterator of the ORIGIN_DIE children. */
5814 struct die_info *origin_child_die;
5815 struct cleanup *cleanups;
5816 struct attribute *attr;
5817 struct dwarf2_cu *origin_cu;
5818 struct pending **origin_previous_list_in_scope;
5820 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5824 /* Note that following die references may follow to a die in a
5828 origin_die = follow_die_ref (die, attr, &origin_cu);
5830 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5832 origin_previous_list_in_scope = origin_cu->list_in_scope;
5833 origin_cu->list_in_scope = cu->list_in_scope;
5835 if (die->tag != origin_die->tag
5836 && !(die->tag == DW_TAG_inlined_subroutine
5837 && origin_die->tag == DW_TAG_subprogram))
5838 complaint (&symfile_complaints,
5839 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5840 die->offset, origin_die->offset);
5842 child_die = die->child;
5843 die_children_count = 0;
5844 while (child_die && child_die->tag)
5846 child_die = sibling_die (child_die);
5847 die_children_count++;
5849 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5850 cleanups = make_cleanup (xfree, offsets);
5852 offsets_end = offsets;
5853 child_die = die->child;
5854 while (child_die && child_die->tag)
5856 /* For each CHILD_DIE, find the corresponding child of
5857 ORIGIN_DIE. If there is more than one layer of
5858 DW_AT_abstract_origin, follow them all; there shouldn't be,
5859 but GCC versions at least through 4.4 generate this (GCC PR
5861 struct die_info *child_origin_die = child_die;
5862 struct dwarf2_cu *child_origin_cu = cu;
5866 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5870 child_origin_die = follow_die_ref (child_origin_die, attr,
5874 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5875 counterpart may exist. */
5876 if (child_origin_die != child_die)
5878 if (child_die->tag != child_origin_die->tag
5879 && !(child_die->tag == DW_TAG_inlined_subroutine
5880 && child_origin_die->tag == DW_TAG_subprogram))
5881 complaint (&symfile_complaints,
5882 _("Child DIE 0x%x and its abstract origin 0x%x have "
5883 "different tags"), child_die->offset,
5884 child_origin_die->offset);
5885 if (child_origin_die->parent != origin_die)
5886 complaint (&symfile_complaints,
5887 _("Child DIE 0x%x and its abstract origin 0x%x have "
5888 "different parents"), child_die->offset,
5889 child_origin_die->offset);
5891 *offsets_end++ = child_origin_die->offset;
5893 child_die = sibling_die (child_die);
5895 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5896 unsigned_int_compar);
5897 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5898 if (offsetp[-1] == *offsetp)
5899 complaint (&symfile_complaints,
5900 _("Multiple children of DIE 0x%x refer "
5901 "to DIE 0x%x as their abstract origin"),
5902 die->offset, *offsetp);
5905 origin_child_die = origin_die->child;
5906 while (origin_child_die && origin_child_die->tag)
5908 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5909 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5911 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5913 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5914 process_die (origin_child_die, origin_cu);
5916 origin_child_die = sibling_die (origin_child_die);
5918 origin_cu->list_in_scope = origin_previous_list_in_scope;
5920 do_cleanups (cleanups);
5924 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5926 struct objfile *objfile = cu->objfile;
5927 struct context_stack *new;
5930 struct die_info *child_die;
5931 struct attribute *attr, *call_line, *call_file;
5934 struct block *block;
5935 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5936 VEC (symbolp) *template_args = NULL;
5937 struct template_symbol *templ_func = NULL;
5941 /* If we do not have call site information, we can't show the
5942 caller of this inlined function. That's too confusing, so
5943 only use the scope for local variables. */
5944 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5945 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5946 if (call_line == NULL || call_file == NULL)
5948 read_lexical_block_scope (die, cu);
5953 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5955 name = dwarf2_name (die, cu);
5957 /* Ignore functions with missing or empty names. These are actually
5958 illegal according to the DWARF standard. */
5961 complaint (&symfile_complaints,
5962 _("missing name for subprogram DIE at %d"), die->offset);
5966 /* Ignore functions with missing or invalid low and high pc attributes. */
5967 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5969 attr = dwarf2_attr (die, DW_AT_external, cu);
5970 if (!attr || !DW_UNSND (attr))
5971 complaint (&symfile_complaints,
5972 _("cannot get low and high bounds "
5973 "for subprogram DIE at %d"),
5981 /* If we have any template arguments, then we must allocate a
5982 different sort of symbol. */
5983 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5985 if (child_die->tag == DW_TAG_template_type_param
5986 || child_die->tag == DW_TAG_template_value_param)
5988 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5989 struct template_symbol);
5990 templ_func->base.is_cplus_template_function = 1;
5995 new = push_context (0, lowpc);
5996 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5997 (struct symbol *) templ_func);
5999 /* If there is a location expression for DW_AT_frame_base, record
6001 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
6003 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6004 expression is being recorded directly in the function's symbol
6005 and not in a separate frame-base object. I guess this hack is
6006 to avoid adding some sort of frame-base adjunct/annex to the
6007 function's symbol :-(. The problem with doing this is that it
6008 results in a function symbol with a location expression that
6009 has nothing to do with the location of the function, ouch! The
6010 relationship should be: a function's symbol has-a frame base; a
6011 frame-base has-a location expression. */
6012 dwarf2_symbol_mark_computed (attr, new->name, cu);
6014 cu->list_in_scope = &local_symbols;
6016 if (die->child != NULL)
6018 child_die = die->child;
6019 while (child_die && child_die->tag)
6021 if (child_die->tag == DW_TAG_template_type_param
6022 || child_die->tag == DW_TAG_template_value_param)
6024 struct symbol *arg = new_symbol (child_die, NULL, cu);
6027 VEC_safe_push (symbolp, template_args, arg);
6030 process_die (child_die, cu);
6031 child_die = sibling_die (child_die);
6035 inherit_abstract_dies (die, cu);
6037 /* If we have a DW_AT_specification, we might need to import using
6038 directives from the context of the specification DIE. See the
6039 comment in determine_prefix. */
6040 if (cu->language == language_cplus
6041 && dwarf2_attr (die, DW_AT_specification, cu))
6043 struct dwarf2_cu *spec_cu = cu;
6044 struct die_info *spec_die = die_specification (die, &spec_cu);
6048 child_die = spec_die->child;
6049 while (child_die && child_die->tag)
6051 if (child_die->tag == DW_TAG_imported_module)
6052 process_die (child_die, spec_cu);
6053 child_die = sibling_die (child_die);
6056 /* In some cases, GCC generates specification DIEs that
6057 themselves contain DW_AT_specification attributes. */
6058 spec_die = die_specification (spec_die, &spec_cu);
6062 new = pop_context ();
6063 /* Make a block for the local symbols within. */
6064 block = finish_block (new->name, &local_symbols, new->old_blocks,
6065 lowpc, highpc, objfile);
6067 /* For C++, set the block's scope. */
6068 if (cu->language == language_cplus || cu->language == language_fortran)
6069 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6070 determine_prefix (die, cu),
6071 processing_has_namespace_info);
6073 /* If we have address ranges, record them. */
6074 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6076 /* Attach template arguments to function. */
6077 if (! VEC_empty (symbolp, template_args))
6079 gdb_assert (templ_func != NULL);
6081 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6082 templ_func->template_arguments
6083 = obstack_alloc (&objfile->objfile_obstack,
6084 (templ_func->n_template_arguments
6085 * sizeof (struct symbol *)));
6086 memcpy (templ_func->template_arguments,
6087 VEC_address (symbolp, template_args),
6088 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6089 VEC_free (symbolp, template_args);
6092 /* In C++, we can have functions nested inside functions (e.g., when
6093 a function declares a class that has methods). This means that
6094 when we finish processing a function scope, we may need to go
6095 back to building a containing block's symbol lists. */
6096 local_symbols = new->locals;
6097 param_symbols = new->params;
6098 using_directives = new->using_directives;
6100 /* If we've finished processing a top-level function, subsequent
6101 symbols go in the file symbol list. */
6102 if (outermost_context_p ())
6103 cu->list_in_scope = &file_symbols;
6106 /* Process all the DIES contained within a lexical block scope. Start
6107 a new scope, process the dies, and then close the scope. */
6110 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6112 struct objfile *objfile = cu->objfile;
6113 struct context_stack *new;
6114 CORE_ADDR lowpc, highpc;
6115 struct die_info *child_die;
6118 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6120 /* Ignore blocks with missing or invalid low and high pc attributes. */
6121 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6122 as multiple lexical blocks? Handling children in a sane way would
6123 be nasty. Might be easier to properly extend generic blocks to
6125 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6130 push_context (0, lowpc);
6131 if (die->child != NULL)
6133 child_die = die->child;
6134 while (child_die && child_die->tag)
6136 process_die (child_die, cu);
6137 child_die = sibling_die (child_die);
6140 new = pop_context ();
6142 if (local_symbols != NULL || using_directives != NULL)
6145 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6148 /* Note that recording ranges after traversing children, as we
6149 do here, means that recording a parent's ranges entails
6150 walking across all its children's ranges as they appear in
6151 the address map, which is quadratic behavior.
6153 It would be nicer to record the parent's ranges before
6154 traversing its children, simply overriding whatever you find
6155 there. But since we don't even decide whether to create a
6156 block until after we've traversed its children, that's hard
6158 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6160 local_symbols = new->locals;
6161 using_directives = new->using_directives;
6164 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6167 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
6169 struct objfile *objfile = cu->objfile;
6170 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6171 CORE_ADDR pc, baseaddr;
6172 struct attribute *attr;
6173 struct call_site *call_site, call_site_local;
6176 struct die_info *child_die;
6178 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6180 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6183 complaint (&symfile_complaints,
6184 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6185 "DIE 0x%x [in module %s]"),
6186 die->offset, objfile->name);
6189 pc = DW_ADDR (attr) + baseaddr;
6191 if (cu->call_site_htab == NULL)
6192 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
6193 NULL, &objfile->objfile_obstack,
6194 hashtab_obstack_allocate, NULL);
6195 call_site_local.pc = pc;
6196 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
6199 complaint (&symfile_complaints,
6200 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6201 "DIE 0x%x [in module %s]"),
6202 paddress (gdbarch, pc), die->offset, objfile->name);
6206 /* Count parameters at the caller. */
6209 for (child_die = die->child; child_die && child_die->tag;
6210 child_die = sibling_die (child_die))
6212 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6214 complaint (&symfile_complaints,
6215 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6216 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6217 child_die->tag, child_die->offset, objfile->name);
6224 call_site = obstack_alloc (&objfile->objfile_obstack,
6225 (sizeof (*call_site)
6226 + (sizeof (*call_site->parameter)
6229 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
6232 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
6234 struct die_info *func_die;
6236 /* Skip also over DW_TAG_inlined_subroutine. */
6237 for (func_die = die->parent;
6238 func_die && func_die->tag != DW_TAG_subprogram
6239 && func_die->tag != DW_TAG_subroutine_type;
6240 func_die = func_die->parent);
6242 /* DW_AT_GNU_all_call_sites is a superset
6243 of DW_AT_GNU_all_tail_call_sites. */
6245 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
6246 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
6248 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6249 not complete. But keep CALL_SITE for look ups via call_site_htab,
6250 both the initial caller containing the real return address PC and
6251 the final callee containing the current PC of a chain of tail
6252 calls do not need to have the tail call list complete. But any
6253 function candidate for a virtual tail call frame searched via
6254 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6255 determined unambiguously. */
6259 struct type *func_type = NULL;
6262 func_type = get_die_type (func_die, cu);
6263 if (func_type != NULL)
6265 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
6267 /* Enlist this call site to the function. */
6268 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
6269 TYPE_TAIL_CALL_LIST (func_type) = call_site;
6272 complaint (&symfile_complaints,
6273 _("Cannot find function owning DW_TAG_GNU_call_site "
6274 "DIE 0x%x [in module %s]"),
6275 die->offset, objfile->name);
6279 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
6281 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
6282 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
6283 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
6284 /* Keep NULL DWARF_BLOCK. */;
6285 else if (attr_form_is_block (attr))
6287 struct dwarf2_locexpr_baton *dlbaton;
6289 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
6290 dlbaton->data = DW_BLOCK (attr)->data;
6291 dlbaton->size = DW_BLOCK (attr)->size;
6292 dlbaton->per_cu = cu->per_cu;
6294 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
6296 else if (is_ref_attr (attr))
6298 struct dwarf2_cu *target_cu = cu;
6299 struct die_info *target_die;
6301 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
6302 gdb_assert (target_cu->objfile == objfile);
6303 if (die_is_declaration (target_die, target_cu))
6305 const char *target_physname;
6307 target_physname = dwarf2_physname (NULL, target_die, target_cu);
6308 if (target_physname == NULL)
6309 complaint (&symfile_complaints,
6310 _("DW_AT_GNU_call_site_target target DIE has invalid "
6311 "physname, for referencing DIE 0x%x [in module %s]"),
6312 die->offset, objfile->name);
6314 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
6320 /* DW_AT_entry_pc should be preferred. */
6321 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
6322 complaint (&symfile_complaints,
6323 _("DW_AT_GNU_call_site_target target DIE has invalid "
6324 "low pc, for referencing DIE 0x%x [in module %s]"),
6325 die->offset, objfile->name);
6327 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
6331 complaint (&symfile_complaints,
6332 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6333 "block nor reference, for DIE 0x%x [in module %s]"),
6334 die->offset, objfile->name);
6336 call_site->per_cu = cu->per_cu;
6338 for (child_die = die->child;
6339 child_die && child_die->tag;
6340 child_die = sibling_die (child_die))
6342 struct dwarf2_locexpr_baton *dlbaton;
6343 struct call_site_parameter *parameter;
6345 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6347 /* Already printed the complaint above. */
6351 gdb_assert (call_site->parameter_count < nparams);
6352 parameter = &call_site->parameter[call_site->parameter_count];
6354 /* DW_AT_location specifies the register number. Value of the data
6355 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6357 attr = dwarf2_attr (child_die, DW_AT_location, cu);
6358 if (!attr || !attr_form_is_block (attr))
6360 complaint (&symfile_complaints,
6361 _("No DW_FORM_block* DW_AT_location for "
6362 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6363 child_die->offset, objfile->name);
6366 parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
6367 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
6368 if (parameter->dwarf_reg == -1
6369 && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
6370 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
6371 ¶meter->fb_offset))
6373 complaint (&symfile_complaints,
6374 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6375 "for DW_FORM_block* DW_AT_location for "
6376 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6377 child_die->offset, objfile->name);
6381 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
6382 if (!attr_form_is_block (attr))
6384 complaint (&symfile_complaints,
6385 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6386 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6387 child_die->offset, objfile->name);
6390 parameter->value = DW_BLOCK (attr)->data;
6391 parameter->value_size = DW_BLOCK (attr)->size;
6393 /* Parameters are not pre-cleared by memset above. */
6394 parameter->data_value = NULL;
6395 parameter->data_value_size = 0;
6396 call_site->parameter_count++;
6398 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
6401 if (!attr_form_is_block (attr))
6402 complaint (&symfile_complaints,
6403 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6404 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6405 child_die->offset, objfile->name);
6408 parameter->data_value = DW_BLOCK (attr)->data;
6409 parameter->data_value_size = DW_BLOCK (attr)->size;
6415 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6416 Return 1 if the attributes are present and valid, otherwise, return 0.
6417 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6420 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6421 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6422 struct partial_symtab *ranges_pst)
6424 struct objfile *objfile = cu->objfile;
6425 struct comp_unit_head *cu_header = &cu->header;
6426 bfd *obfd = objfile->obfd;
6427 unsigned int addr_size = cu_header->addr_size;
6428 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6429 /* Base address selection entry. */
6440 found_base = cu->base_known;
6441 base = cu->base_address;
6443 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6444 if (offset >= dwarf2_per_objfile->ranges.size)
6446 complaint (&symfile_complaints,
6447 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6451 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6453 /* Read in the largest possible address. */
6454 marker = read_address (obfd, buffer, cu, &dummy);
6455 if ((marker & mask) == mask)
6457 /* If we found the largest possible address, then
6458 read the base address. */
6459 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6460 buffer += 2 * addr_size;
6461 offset += 2 * addr_size;
6467 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6471 CORE_ADDR range_beginning, range_end;
6473 range_beginning = read_address (obfd, buffer, cu, &dummy);
6474 buffer += addr_size;
6475 range_end = read_address (obfd, buffer, cu, &dummy);
6476 buffer += addr_size;
6477 offset += 2 * addr_size;
6479 /* An end of list marker is a pair of zero addresses. */
6480 if (range_beginning == 0 && range_end == 0)
6481 /* Found the end of list entry. */
6484 /* Each base address selection entry is a pair of 2 values.
6485 The first is the largest possible address, the second is
6486 the base address. Check for a base address here. */
6487 if ((range_beginning & mask) == mask)
6489 /* If we found the largest possible address, then
6490 read the base address. */
6491 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6498 /* We have no valid base address for the ranges
6500 complaint (&symfile_complaints,
6501 _("Invalid .debug_ranges data (no base address)"));
6505 if (range_beginning > range_end)
6507 /* Inverted range entries are invalid. */
6508 complaint (&symfile_complaints,
6509 _("Invalid .debug_ranges data (inverted range)"));
6513 /* Empty range entries have no effect. */
6514 if (range_beginning == range_end)
6517 range_beginning += base;
6520 if (ranges_pst != NULL)
6521 addrmap_set_empty (objfile->psymtabs_addrmap,
6522 range_beginning + baseaddr,
6523 range_end - 1 + baseaddr,
6526 /* FIXME: This is recording everything as a low-high
6527 segment of consecutive addresses. We should have a
6528 data structure for discontiguous block ranges
6532 low = range_beginning;
6538 if (range_beginning < low)
6539 low = range_beginning;
6540 if (range_end > high)
6546 /* If the first entry is an end-of-list marker, the range
6547 describes an empty scope, i.e. no instructions. */
6553 *high_return = high;
6557 /* Get low and high pc attributes from a die. Return 1 if the attributes
6558 are present and valid, otherwise, return 0. Return -1 if the range is
6559 discontinuous, i.e. derived from DW_AT_ranges information. */
6561 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6562 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6563 struct partial_symtab *pst)
6565 struct attribute *attr;
6570 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6573 high = DW_ADDR (attr);
6574 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6576 low = DW_ADDR (attr);
6578 /* Found high w/o low attribute. */
6581 /* Found consecutive range of addresses. */
6586 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6589 /* Value of the DW_AT_ranges attribute is the offset in the
6590 .debug_ranges section. */
6591 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6593 /* Found discontinuous range of addresses. */
6598 /* read_partial_die has also the strict LOW < HIGH requirement. */
6602 /* When using the GNU linker, .gnu.linkonce. sections are used to
6603 eliminate duplicate copies of functions and vtables and such.
6604 The linker will arbitrarily choose one and discard the others.
6605 The AT_*_pc values for such functions refer to local labels in
6606 these sections. If the section from that file was discarded, the
6607 labels are not in the output, so the relocs get a value of 0.
6608 If this is a discarded function, mark the pc bounds as invalid,
6609 so that GDB will ignore it. */
6610 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6619 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6620 its low and high PC addresses. Do nothing if these addresses could not
6621 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6622 and HIGHPC to the high address if greater than HIGHPC. */
6625 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6626 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6627 struct dwarf2_cu *cu)
6629 CORE_ADDR low, high;
6630 struct die_info *child = die->child;
6632 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6634 *lowpc = min (*lowpc, low);
6635 *highpc = max (*highpc, high);
6638 /* If the language does not allow nested subprograms (either inside
6639 subprograms or lexical blocks), we're done. */
6640 if (cu->language != language_ada)
6643 /* Check all the children of the given DIE. If it contains nested
6644 subprograms, then check their pc bounds. Likewise, we need to
6645 check lexical blocks as well, as they may also contain subprogram
6647 while (child && child->tag)
6649 if (child->tag == DW_TAG_subprogram
6650 || child->tag == DW_TAG_lexical_block)
6651 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6652 child = sibling_die (child);
6656 /* Get the low and high pc's represented by the scope DIE, and store
6657 them in *LOWPC and *HIGHPC. If the correct values can't be
6658 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6661 get_scope_pc_bounds (struct die_info *die,
6662 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6663 struct dwarf2_cu *cu)
6665 CORE_ADDR best_low = (CORE_ADDR) -1;
6666 CORE_ADDR best_high = (CORE_ADDR) 0;
6667 CORE_ADDR current_low, current_high;
6669 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6671 best_low = current_low;
6672 best_high = current_high;
6676 struct die_info *child = die->child;
6678 while (child && child->tag)
6680 switch (child->tag) {
6681 case DW_TAG_subprogram:
6682 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6684 case DW_TAG_namespace:
6686 /* FIXME: carlton/2004-01-16: Should we do this for
6687 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6688 that current GCC's always emit the DIEs corresponding
6689 to definitions of methods of classes as children of a
6690 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6691 the DIEs giving the declarations, which could be
6692 anywhere). But I don't see any reason why the
6693 standards says that they have to be there. */
6694 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6696 if (current_low != ((CORE_ADDR) -1))
6698 best_low = min (best_low, current_low);
6699 best_high = max (best_high, current_high);
6707 child = sibling_die (child);
6712 *highpc = best_high;
6715 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6718 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6719 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6721 struct objfile *objfile = cu->objfile;
6722 struct attribute *attr;
6724 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6727 CORE_ADDR high = DW_ADDR (attr);
6729 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6732 CORE_ADDR low = DW_ADDR (attr);
6734 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6738 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6741 bfd *obfd = objfile->obfd;
6743 /* The value of the DW_AT_ranges attribute is the offset of the
6744 address range list in the .debug_ranges section. */
6745 unsigned long offset = DW_UNSND (attr);
6746 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6748 /* For some target architectures, but not others, the
6749 read_address function sign-extends the addresses it returns.
6750 To recognize base address selection entries, we need a
6752 unsigned int addr_size = cu->header.addr_size;
6753 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6755 /* The base address, to which the next pair is relative. Note
6756 that this 'base' is a DWARF concept: most entries in a range
6757 list are relative, to reduce the number of relocs against the
6758 debugging information. This is separate from this function's
6759 'baseaddr' argument, which GDB uses to relocate debugging
6760 information from a shared library based on the address at
6761 which the library was loaded. */
6762 CORE_ADDR base = cu->base_address;
6763 int base_known = cu->base_known;
6765 gdb_assert (dwarf2_per_objfile->ranges.readin);
6766 if (offset >= dwarf2_per_objfile->ranges.size)
6768 complaint (&symfile_complaints,
6769 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6776 unsigned int bytes_read;
6777 CORE_ADDR start, end;
6779 start = read_address (obfd, buffer, cu, &bytes_read);
6780 buffer += bytes_read;
6781 end = read_address (obfd, buffer, cu, &bytes_read);
6782 buffer += bytes_read;
6784 /* Did we find the end of the range list? */
6785 if (start == 0 && end == 0)
6788 /* Did we find a base address selection entry? */
6789 else if ((start & base_select_mask) == base_select_mask)
6795 /* We found an ordinary address range. */
6800 complaint (&symfile_complaints,
6801 _("Invalid .debug_ranges data "
6802 "(no base address)"));
6808 /* Inverted range entries are invalid. */
6809 complaint (&symfile_complaints,
6810 _("Invalid .debug_ranges data "
6811 "(inverted range)"));
6815 /* Empty range entries have no effect. */
6819 record_block_range (block,
6820 baseaddr + base + start,
6821 baseaddr + base + end - 1);
6827 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6828 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6829 during 4.6.0 experimental. */
6832 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6835 int major, minor, release;
6838 if (cu->producer == NULL)
6840 /* For unknown compilers expect their behavior is DWARF version
6843 GCC started to support .debug_types sections by -gdwarf-4 since
6844 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6845 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6846 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6847 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6852 if (cu->checked_producer)
6853 return cu->producer_is_gxx_lt_4_6;
6855 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6857 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6859 /* For non-GCC compilers expect their behavior is DWARF version
6864 cs = &cu->producer[strlen ("GNU ")];
6865 while (*cs && !isdigit (*cs))
6867 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6869 /* Not recognized as GCC. */
6872 result = major < 4 || (major == 4 && minor < 6);
6875 cu->checked_producer = 1;
6876 cu->producer_is_gxx_lt_4_6 = result;
6881 /* Return the default accessibility type if it is not overriden by
6882 DW_AT_accessibility. */
6884 static enum dwarf_access_attribute
6885 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6887 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6889 /* The default DWARF 2 accessibility for members is public, the default
6890 accessibility for inheritance is private. */
6892 if (die->tag != DW_TAG_inheritance)
6893 return DW_ACCESS_public;
6895 return DW_ACCESS_private;
6899 /* DWARF 3+ defines the default accessibility a different way. The same
6900 rules apply now for DW_TAG_inheritance as for the members and it only
6901 depends on the container kind. */
6903 if (die->parent->tag == DW_TAG_class_type)
6904 return DW_ACCESS_private;
6906 return DW_ACCESS_public;
6910 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6911 offset. If the attribute was not found return 0, otherwise return
6912 1. If it was found but could not properly be handled, set *OFFSET
6916 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6919 struct attribute *attr;
6921 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6926 /* Note that we do not check for a section offset first here.
6927 This is because DW_AT_data_member_location is new in DWARF 4,
6928 so if we see it, we can assume that a constant form is really
6929 a constant and not a section offset. */
6930 if (attr_form_is_constant (attr))
6931 *offset = dwarf2_get_attr_constant_value (attr, 0);
6932 else if (attr_form_is_section_offset (attr))
6933 dwarf2_complex_location_expr_complaint ();
6934 else if (attr_form_is_block (attr))
6935 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6937 dwarf2_complex_location_expr_complaint ();
6945 /* Add an aggregate field to the field list. */
6948 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6949 struct dwarf2_cu *cu)
6951 struct objfile *objfile = cu->objfile;
6952 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6953 struct nextfield *new_field;
6954 struct attribute *attr;
6956 char *fieldname = "";
6958 /* Allocate a new field list entry and link it in. */
6959 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6960 make_cleanup (xfree, new_field);
6961 memset (new_field, 0, sizeof (struct nextfield));
6963 if (die->tag == DW_TAG_inheritance)
6965 new_field->next = fip->baseclasses;
6966 fip->baseclasses = new_field;
6970 new_field->next = fip->fields;
6971 fip->fields = new_field;
6975 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6977 new_field->accessibility = DW_UNSND (attr);
6979 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6980 if (new_field->accessibility != DW_ACCESS_public)
6981 fip->non_public_fields = 1;
6983 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6985 new_field->virtuality = DW_UNSND (attr);
6987 new_field->virtuality = DW_VIRTUALITY_none;
6989 fp = &new_field->field;
6991 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6995 /* Data member other than a C++ static data member. */
6997 /* Get type of field. */
6998 fp->type = die_type (die, cu);
7000 SET_FIELD_BITPOS (*fp, 0);
7002 /* Get bit size of field (zero if none). */
7003 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
7006 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
7010 FIELD_BITSIZE (*fp) = 0;
7013 /* Get bit offset of field. */
7014 if (handle_data_member_location (die, cu, &offset))
7015 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7016 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
7019 if (gdbarch_bits_big_endian (gdbarch))
7021 /* For big endian bits, the DW_AT_bit_offset gives the
7022 additional bit offset from the MSB of the containing
7023 anonymous object to the MSB of the field. We don't
7024 have to do anything special since we don't need to
7025 know the size of the anonymous object. */
7026 FIELD_BITPOS (*fp) += DW_UNSND (attr);
7030 /* For little endian bits, compute the bit offset to the
7031 MSB of the anonymous object, subtract off the number of
7032 bits from the MSB of the field to the MSB of the
7033 object, and then subtract off the number of bits of
7034 the field itself. The result is the bit offset of
7035 the LSB of the field. */
7037 int bit_offset = DW_UNSND (attr);
7039 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7042 /* The size of the anonymous object containing
7043 the bit field is explicit, so use the
7044 indicated size (in bytes). */
7045 anonymous_size = DW_UNSND (attr);
7049 /* The size of the anonymous object containing
7050 the bit field must be inferred from the type
7051 attribute of the data member containing the
7053 anonymous_size = TYPE_LENGTH (fp->type);
7055 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
7056 - bit_offset - FIELD_BITSIZE (*fp);
7060 /* Get name of field. */
7061 fieldname = dwarf2_name (die, cu);
7062 if (fieldname == NULL)
7065 /* The name is already allocated along with this objfile, so we don't
7066 need to duplicate it for the type. */
7067 fp->name = fieldname;
7069 /* Change accessibility for artificial fields (e.g. virtual table
7070 pointer or virtual base class pointer) to private. */
7071 if (dwarf2_attr (die, DW_AT_artificial, cu))
7073 FIELD_ARTIFICIAL (*fp) = 1;
7074 new_field->accessibility = DW_ACCESS_private;
7075 fip->non_public_fields = 1;
7078 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
7080 /* C++ static member. */
7082 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7083 is a declaration, but all versions of G++ as of this writing
7084 (so through at least 3.2.1) incorrectly generate
7085 DW_TAG_variable tags. */
7087 const char *physname;
7089 /* Get name of field. */
7090 fieldname = dwarf2_name (die, cu);
7091 if (fieldname == NULL)
7094 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7096 /* Only create a symbol if this is an external value.
7097 new_symbol checks this and puts the value in the global symbol
7098 table, which we want. If it is not external, new_symbol
7099 will try to put the value in cu->list_in_scope which is wrong. */
7100 && dwarf2_flag_true_p (die, DW_AT_external, cu))
7102 /* A static const member, not much different than an enum as far as
7103 we're concerned, except that we can support more types. */
7104 new_symbol (die, NULL, cu);
7107 /* Get physical name. */
7108 physname = dwarf2_physname (fieldname, die, cu);
7110 /* The name is already allocated along with this objfile, so we don't
7111 need to duplicate it for the type. */
7112 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
7113 FIELD_TYPE (*fp) = die_type (die, cu);
7114 FIELD_NAME (*fp) = fieldname;
7116 else if (die->tag == DW_TAG_inheritance)
7120 /* C++ base class field. */
7121 if (handle_data_member_location (die, cu, &offset))
7122 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7123 FIELD_BITSIZE (*fp) = 0;
7124 FIELD_TYPE (*fp) = die_type (die, cu);
7125 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
7126 fip->nbaseclasses++;
7130 /* Add a typedef defined in the scope of the FIP's class. */
7133 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
7134 struct dwarf2_cu *cu)
7136 struct objfile *objfile = cu->objfile;
7137 struct typedef_field_list *new_field;
7138 struct attribute *attr;
7139 struct typedef_field *fp;
7140 char *fieldname = "";
7142 /* Allocate a new field list entry and link it in. */
7143 new_field = xzalloc (sizeof (*new_field));
7144 make_cleanup (xfree, new_field);
7146 gdb_assert (die->tag == DW_TAG_typedef);
7148 fp = &new_field->field;
7150 /* Get name of field. */
7151 fp->name = dwarf2_name (die, cu);
7152 if (fp->name == NULL)
7155 fp->type = read_type_die (die, cu);
7157 new_field->next = fip->typedef_field_list;
7158 fip->typedef_field_list = new_field;
7159 fip->typedef_field_list_count++;
7162 /* Create the vector of fields, and attach it to the type. */
7165 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
7166 struct dwarf2_cu *cu)
7168 int nfields = fip->nfields;
7170 /* Record the field count, allocate space for the array of fields,
7171 and create blank accessibility bitfields if necessary. */
7172 TYPE_NFIELDS (type) = nfields;
7173 TYPE_FIELDS (type) = (struct field *)
7174 TYPE_ALLOC (type, sizeof (struct field) * nfields);
7175 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
7177 if (fip->non_public_fields && cu->language != language_ada)
7179 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7181 TYPE_FIELD_PRIVATE_BITS (type) =
7182 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7183 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
7185 TYPE_FIELD_PROTECTED_BITS (type) =
7186 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7187 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
7189 TYPE_FIELD_IGNORE_BITS (type) =
7190 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7191 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
7194 /* If the type has baseclasses, allocate and clear a bit vector for
7195 TYPE_FIELD_VIRTUAL_BITS. */
7196 if (fip->nbaseclasses && cu->language != language_ada)
7198 int num_bytes = B_BYTES (fip->nbaseclasses);
7199 unsigned char *pointer;
7201 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7202 pointer = TYPE_ALLOC (type, num_bytes);
7203 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
7204 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
7205 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
7208 /* Copy the saved-up fields into the field vector. Start from the head of
7209 the list, adding to the tail of the field array, so that they end up in
7210 the same order in the array in which they were added to the list. */
7211 while (nfields-- > 0)
7213 struct nextfield *fieldp;
7217 fieldp = fip->fields;
7218 fip->fields = fieldp->next;
7222 fieldp = fip->baseclasses;
7223 fip->baseclasses = fieldp->next;
7226 TYPE_FIELD (type, nfields) = fieldp->field;
7227 switch (fieldp->accessibility)
7229 case DW_ACCESS_private:
7230 if (cu->language != language_ada)
7231 SET_TYPE_FIELD_PRIVATE (type, nfields);
7234 case DW_ACCESS_protected:
7235 if (cu->language != language_ada)
7236 SET_TYPE_FIELD_PROTECTED (type, nfields);
7239 case DW_ACCESS_public:
7243 /* Unknown accessibility. Complain and treat it as public. */
7245 complaint (&symfile_complaints, _("unsupported accessibility %d"),
7246 fieldp->accessibility);
7250 if (nfields < fip->nbaseclasses)
7252 switch (fieldp->virtuality)
7254 case DW_VIRTUALITY_virtual:
7255 case DW_VIRTUALITY_pure_virtual:
7256 if (cu->language == language_ada)
7257 error (_("unexpected virtuality in component of Ada type"));
7258 SET_TYPE_FIELD_VIRTUAL (type, nfields);
7265 /* Add a member function to the proper fieldlist. */
7268 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
7269 struct type *type, struct dwarf2_cu *cu)
7271 struct objfile *objfile = cu->objfile;
7272 struct attribute *attr;
7273 struct fnfieldlist *flp;
7275 struct fn_field *fnp;
7277 struct nextfnfield *new_fnfield;
7278 struct type *this_type;
7279 enum dwarf_access_attribute accessibility;
7281 if (cu->language == language_ada)
7282 error (_("unexpected member function in Ada type"));
7284 /* Get name of member function. */
7285 fieldname = dwarf2_name (die, cu);
7286 if (fieldname == NULL)
7289 /* Look up member function name in fieldlist. */
7290 for (i = 0; i < fip->nfnfields; i++)
7292 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7296 /* Create new list element if necessary. */
7297 if (i < fip->nfnfields)
7298 flp = &fip->fnfieldlists[i];
7301 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7303 fip->fnfieldlists = (struct fnfieldlist *)
7304 xrealloc (fip->fnfieldlists,
7305 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7306 * sizeof (struct fnfieldlist));
7307 if (fip->nfnfields == 0)
7308 make_cleanup (free_current_contents, &fip->fnfieldlists);
7310 flp = &fip->fnfieldlists[fip->nfnfields];
7311 flp->name = fieldname;
7314 i = fip->nfnfields++;
7317 /* Create a new member function field and chain it to the field list
7319 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7320 make_cleanup (xfree, new_fnfield);
7321 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7322 new_fnfield->next = flp->head;
7323 flp->head = new_fnfield;
7326 /* Fill in the member function field info. */
7327 fnp = &new_fnfield->fnfield;
7329 /* Delay processing of the physname until later. */
7330 if (cu->language == language_cplus || cu->language == language_java)
7332 add_to_method_list (type, i, flp->length - 1, fieldname,
7337 const char *physname = dwarf2_physname (fieldname, die, cu);
7338 fnp->physname = physname ? physname : "";
7341 fnp->type = alloc_type (objfile);
7342 this_type = read_type_die (die, cu);
7343 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7345 int nparams = TYPE_NFIELDS (this_type);
7347 /* TYPE is the domain of this method, and THIS_TYPE is the type
7348 of the method itself (TYPE_CODE_METHOD). */
7349 smash_to_method_type (fnp->type, type,
7350 TYPE_TARGET_TYPE (this_type),
7351 TYPE_FIELDS (this_type),
7352 TYPE_NFIELDS (this_type),
7353 TYPE_VARARGS (this_type));
7355 /* Handle static member functions.
7356 Dwarf2 has no clean way to discern C++ static and non-static
7357 member functions. G++ helps GDB by marking the first
7358 parameter for non-static member functions (which is the this
7359 pointer) as artificial. We obtain this information from
7360 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7361 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7362 fnp->voffset = VOFFSET_STATIC;
7365 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7366 dwarf2_full_name (fieldname, die, cu));
7368 /* Get fcontext from DW_AT_containing_type if present. */
7369 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7370 fnp->fcontext = die_containing_type (die, cu);
7372 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7373 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7375 /* Get accessibility. */
7376 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7378 accessibility = DW_UNSND (attr);
7380 accessibility = dwarf2_default_access_attribute (die, cu);
7381 switch (accessibility)
7383 case DW_ACCESS_private:
7384 fnp->is_private = 1;
7386 case DW_ACCESS_protected:
7387 fnp->is_protected = 1;
7391 /* Check for artificial methods. */
7392 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7393 if (attr && DW_UNSND (attr) != 0)
7394 fnp->is_artificial = 1;
7396 /* Get index in virtual function table if it is a virtual member
7397 function. For older versions of GCC, this is an offset in the
7398 appropriate virtual table, as specified by DW_AT_containing_type.
7399 For everyone else, it is an expression to be evaluated relative
7400 to the object address. */
7402 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7405 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7407 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7409 /* Old-style GCC. */
7410 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7412 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7413 || (DW_BLOCK (attr)->size > 1
7414 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7415 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7417 struct dwarf_block blk;
7420 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7422 blk.size = DW_BLOCK (attr)->size - offset;
7423 blk.data = DW_BLOCK (attr)->data + offset;
7424 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7425 if ((fnp->voffset % cu->header.addr_size) != 0)
7426 dwarf2_complex_location_expr_complaint ();
7428 fnp->voffset /= cu->header.addr_size;
7432 dwarf2_complex_location_expr_complaint ();
7435 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7437 else if (attr_form_is_section_offset (attr))
7439 dwarf2_complex_location_expr_complaint ();
7443 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7449 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7450 if (attr && DW_UNSND (attr))
7452 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7453 complaint (&symfile_complaints,
7454 _("Member function \"%s\" (offset %d) is virtual "
7455 "but the vtable offset is not specified"),
7456 fieldname, die->offset);
7457 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7458 TYPE_CPLUS_DYNAMIC (type) = 1;
7463 /* Create the vector of member function fields, and attach it to the type. */
7466 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7467 struct dwarf2_cu *cu)
7469 struct fnfieldlist *flp;
7472 if (cu->language == language_ada)
7473 error (_("unexpected member functions in Ada type"));
7475 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7476 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7477 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7479 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7481 struct nextfnfield *nfp = flp->head;
7482 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7485 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7486 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7487 fn_flp->fn_fields = (struct fn_field *)
7488 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7489 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7490 fn_flp->fn_fields[k] = nfp->fnfield;
7493 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7496 /* Returns non-zero if NAME is the name of a vtable member in CU's
7497 language, zero otherwise. */
7499 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7501 static const char vptr[] = "_vptr";
7502 static const char vtable[] = "vtable";
7504 /* Look for the C++ and Java forms of the vtable. */
7505 if ((cu->language == language_java
7506 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7507 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7508 && is_cplus_marker (name[sizeof (vptr) - 1])))
7514 /* GCC outputs unnamed structures that are really pointers to member
7515 functions, with the ABI-specified layout. If TYPE describes
7516 such a structure, smash it into a member function type.
7518 GCC shouldn't do this; it should just output pointer to member DIEs.
7519 This is GCC PR debug/28767. */
7522 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7524 struct type *pfn_type, *domain_type, *new_type;
7526 /* Check for a structure with no name and two children. */
7527 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7530 /* Check for __pfn and __delta members. */
7531 if (TYPE_FIELD_NAME (type, 0) == NULL
7532 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7533 || TYPE_FIELD_NAME (type, 1) == NULL
7534 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7537 /* Find the type of the method. */
7538 pfn_type = TYPE_FIELD_TYPE (type, 0);
7539 if (pfn_type == NULL
7540 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7541 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7544 /* Look for the "this" argument. */
7545 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7546 if (TYPE_NFIELDS (pfn_type) == 0
7547 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7548 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7551 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7552 new_type = alloc_type (objfile);
7553 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7554 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7555 TYPE_VARARGS (pfn_type));
7556 smash_to_methodptr_type (type, new_type);
7559 /* Called when we find the DIE that starts a structure or union scope
7560 (definition) to create a type for the structure or union. Fill in
7561 the type's name and general properties; the members will not be
7562 processed until process_structure_type.
7564 NOTE: we need to call these functions regardless of whether or not the
7565 DIE has a DW_AT_name attribute, since it might be an anonymous
7566 structure or union. This gets the type entered into our set of
7569 However, if the structure is incomplete (an opaque struct/union)
7570 then suppress creating a symbol table entry for it since gdb only
7571 wants to find the one with the complete definition. Note that if
7572 it is complete, we just call new_symbol, which does it's own
7573 checking about whether the struct/union is anonymous or not (and
7574 suppresses creating a symbol table entry itself). */
7576 static struct type *
7577 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7579 struct objfile *objfile = cu->objfile;
7581 struct attribute *attr;
7584 /* If the definition of this type lives in .debug_types, read that type.
7585 Don't follow DW_AT_specification though, that will take us back up
7586 the chain and we want to go down. */
7587 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7590 struct dwarf2_cu *type_cu = cu;
7591 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7593 /* We could just recurse on read_structure_type, but we need to call
7594 get_die_type to ensure only one type for this DIE is created.
7595 This is important, for example, because for c++ classes we need
7596 TYPE_NAME set which is only done by new_symbol. Blech. */
7597 type = read_type_die (type_die, type_cu);
7599 /* TYPE_CU may not be the same as CU.
7600 Ensure TYPE is recorded in CU's type_hash table. */
7601 return set_die_type (die, type, cu);
7604 type = alloc_type (objfile);
7605 INIT_CPLUS_SPECIFIC (type);
7607 name = dwarf2_name (die, cu);
7610 if (cu->language == language_cplus
7611 || cu->language == language_java)
7613 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7615 /* dwarf2_full_name might have already finished building the DIE's
7616 type. If so, there is no need to continue. */
7617 if (get_die_type (die, cu) != NULL)
7618 return get_die_type (die, cu);
7620 TYPE_TAG_NAME (type) = full_name;
7621 if (die->tag == DW_TAG_structure_type
7622 || die->tag == DW_TAG_class_type)
7623 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7627 /* The name is already allocated along with this objfile, so
7628 we don't need to duplicate it for the type. */
7629 TYPE_TAG_NAME (type) = (char *) name;
7630 if (die->tag == DW_TAG_class_type)
7631 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7635 if (die->tag == DW_TAG_structure_type)
7637 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7639 else if (die->tag == DW_TAG_union_type)
7641 TYPE_CODE (type) = TYPE_CODE_UNION;
7645 TYPE_CODE (type) = TYPE_CODE_CLASS;
7648 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7649 TYPE_DECLARED_CLASS (type) = 1;
7651 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7654 TYPE_LENGTH (type) = DW_UNSND (attr);
7658 TYPE_LENGTH (type) = 0;
7661 TYPE_STUB_SUPPORTED (type) = 1;
7662 if (die_is_declaration (die, cu))
7663 TYPE_STUB (type) = 1;
7664 else if (attr == NULL && die->child == NULL
7665 && producer_is_realview (cu->producer))
7666 /* RealView does not output the required DW_AT_declaration
7667 on incomplete types. */
7668 TYPE_STUB (type) = 1;
7670 /* We need to add the type field to the die immediately so we don't
7671 infinitely recurse when dealing with pointers to the structure
7672 type within the structure itself. */
7673 set_die_type (die, type, cu);
7675 /* set_die_type should be already done. */
7676 set_descriptive_type (type, die, cu);
7681 /* Finish creating a structure or union type, including filling in
7682 its members and creating a symbol for it. */
7685 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7687 struct objfile *objfile = cu->objfile;
7688 struct die_info *child_die = die->child;
7691 type = get_die_type (die, cu);
7693 type = read_structure_type (die, cu);
7695 if (die->child != NULL && ! die_is_declaration (die, cu))
7697 struct field_info fi;
7698 struct die_info *child_die;
7699 VEC (symbolp) *template_args = NULL;
7700 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7702 memset (&fi, 0, sizeof (struct field_info));
7704 child_die = die->child;
7706 while (child_die && child_die->tag)
7708 if (child_die->tag == DW_TAG_member
7709 || child_die->tag == DW_TAG_variable)
7711 /* NOTE: carlton/2002-11-05: A C++ static data member
7712 should be a DW_TAG_member that is a declaration, but
7713 all versions of G++ as of this writing (so through at
7714 least 3.2.1) incorrectly generate DW_TAG_variable
7715 tags for them instead. */
7716 dwarf2_add_field (&fi, child_die, cu);
7718 else if (child_die->tag == DW_TAG_subprogram)
7720 /* C++ member function. */
7721 dwarf2_add_member_fn (&fi, child_die, type, cu);
7723 else if (child_die->tag == DW_TAG_inheritance)
7725 /* C++ base class field. */
7726 dwarf2_add_field (&fi, child_die, cu);
7728 else if (child_die->tag == DW_TAG_typedef)
7729 dwarf2_add_typedef (&fi, child_die, cu);
7730 else if (child_die->tag == DW_TAG_template_type_param
7731 || child_die->tag == DW_TAG_template_value_param)
7733 struct symbol *arg = new_symbol (child_die, NULL, cu);
7736 VEC_safe_push (symbolp, template_args, arg);
7739 child_die = sibling_die (child_die);
7742 /* Attach template arguments to type. */
7743 if (! VEC_empty (symbolp, template_args))
7745 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7746 TYPE_N_TEMPLATE_ARGUMENTS (type)
7747 = VEC_length (symbolp, template_args);
7748 TYPE_TEMPLATE_ARGUMENTS (type)
7749 = obstack_alloc (&objfile->objfile_obstack,
7750 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7751 * sizeof (struct symbol *)));
7752 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7753 VEC_address (symbolp, template_args),
7754 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7755 * sizeof (struct symbol *)));
7756 VEC_free (symbolp, template_args);
7759 /* Attach fields and member functions to the type. */
7761 dwarf2_attach_fields_to_type (&fi, type, cu);
7764 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7766 /* Get the type which refers to the base class (possibly this
7767 class itself) which contains the vtable pointer for the current
7768 class from the DW_AT_containing_type attribute. This use of
7769 DW_AT_containing_type is a GNU extension. */
7771 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7773 struct type *t = die_containing_type (die, cu);
7775 TYPE_VPTR_BASETYPE (type) = t;
7780 /* Our own class provides vtbl ptr. */
7781 for (i = TYPE_NFIELDS (t) - 1;
7782 i >= TYPE_N_BASECLASSES (t);
7785 const char *fieldname = TYPE_FIELD_NAME (t, i);
7787 if (is_vtable_name (fieldname, cu))
7789 TYPE_VPTR_FIELDNO (type) = i;
7794 /* Complain if virtual function table field not found. */
7795 if (i < TYPE_N_BASECLASSES (t))
7796 complaint (&symfile_complaints,
7797 _("virtual function table pointer "
7798 "not found when defining class '%s'"),
7799 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7804 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7807 else if (cu->producer
7808 && strncmp (cu->producer,
7809 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7811 /* The IBM XLC compiler does not provide direct indication
7812 of the containing type, but the vtable pointer is
7813 always named __vfp. */
7817 for (i = TYPE_NFIELDS (type) - 1;
7818 i >= TYPE_N_BASECLASSES (type);
7821 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7823 TYPE_VPTR_FIELDNO (type) = i;
7824 TYPE_VPTR_BASETYPE (type) = type;
7831 /* Copy fi.typedef_field_list linked list elements content into the
7832 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7833 if (fi.typedef_field_list)
7835 int i = fi.typedef_field_list_count;
7837 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7838 TYPE_TYPEDEF_FIELD_ARRAY (type)
7839 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7840 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7842 /* Reverse the list order to keep the debug info elements order. */
7845 struct typedef_field *dest, *src;
7847 dest = &TYPE_TYPEDEF_FIELD (type, i);
7848 src = &fi.typedef_field_list->field;
7849 fi.typedef_field_list = fi.typedef_field_list->next;
7854 do_cleanups (back_to);
7856 if (HAVE_CPLUS_STRUCT (type))
7857 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
7860 quirk_gcc_member_function_pointer (type, objfile);
7862 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7863 snapshots) has been known to create a die giving a declaration
7864 for a class that has, as a child, a die giving a definition for a
7865 nested class. So we have to process our children even if the
7866 current die is a declaration. Normally, of course, a declaration
7867 won't have any children at all. */
7869 while (child_die != NULL && child_die->tag)
7871 if (child_die->tag == DW_TAG_member
7872 || child_die->tag == DW_TAG_variable
7873 || child_die->tag == DW_TAG_inheritance
7874 || child_die->tag == DW_TAG_template_value_param
7875 || child_die->tag == DW_TAG_template_type_param)
7880 process_die (child_die, cu);
7882 child_die = sibling_die (child_die);
7885 /* Do not consider external references. According to the DWARF standard,
7886 these DIEs are identified by the fact that they have no byte_size
7887 attribute, and a declaration attribute. */
7888 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7889 || !die_is_declaration (die, cu))
7890 new_symbol (die, type, cu);
7893 /* Given a DW_AT_enumeration_type die, set its type. We do not
7894 complete the type's fields yet, or create any symbols. */
7896 static struct type *
7897 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7899 struct objfile *objfile = cu->objfile;
7901 struct attribute *attr;
7904 /* If the definition of this type lives in .debug_types, read that type.
7905 Don't follow DW_AT_specification though, that will take us back up
7906 the chain and we want to go down. */
7907 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7910 struct dwarf2_cu *type_cu = cu;
7911 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7913 type = read_type_die (type_die, type_cu);
7915 /* TYPE_CU may not be the same as CU.
7916 Ensure TYPE is recorded in CU's type_hash table. */
7917 return set_die_type (die, type, cu);
7920 type = alloc_type (objfile);
7922 TYPE_CODE (type) = TYPE_CODE_ENUM;
7923 name = dwarf2_full_name (NULL, die, cu);
7925 TYPE_TAG_NAME (type) = (char *) name;
7927 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7930 TYPE_LENGTH (type) = DW_UNSND (attr);
7934 TYPE_LENGTH (type) = 0;
7937 /* The enumeration DIE can be incomplete. In Ada, any type can be
7938 declared as private in the package spec, and then defined only
7939 inside the package body. Such types are known as Taft Amendment
7940 Types. When another package uses such a type, an incomplete DIE
7941 may be generated by the compiler. */
7942 if (die_is_declaration (die, cu))
7943 TYPE_STUB (type) = 1;
7945 return set_die_type (die, type, cu);
7948 /* Given a pointer to a die which begins an enumeration, process all
7949 the dies that define the members of the enumeration, and create the
7950 symbol for the enumeration type.
7952 NOTE: We reverse the order of the element list. */
7955 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7957 struct type *this_type;
7959 this_type = get_die_type (die, cu);
7960 if (this_type == NULL)
7961 this_type = read_enumeration_type (die, cu);
7963 if (die->child != NULL)
7965 struct die_info *child_die;
7967 struct field *fields = NULL;
7969 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)
7992 else if ((mask & SYMBOL_VALUE (sym)) != 0)
7995 mask |= SYMBOL_VALUE (sym);
7997 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7999 fields = (struct field *)
8001 (num_fields + DW_FIELD_ALLOC_CHUNK)
8002 * sizeof (struct field));
8005 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
8006 FIELD_TYPE (fields[num_fields]) = NULL;
8007 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
8008 FIELD_BITSIZE (fields[num_fields]) = 0;
8014 child_die = sibling_die (child_die);
8019 TYPE_NFIELDS (this_type) = num_fields;
8020 TYPE_FIELDS (this_type) = (struct field *)
8021 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
8022 memcpy (TYPE_FIELDS (this_type), fields,
8023 sizeof (struct field) * num_fields);
8027 TYPE_UNSIGNED (this_type) = 1;
8029 TYPE_FLAG_ENUM (this_type) = 1;
8032 /* If we are reading an enum from a .debug_types unit, and the enum
8033 is a declaration, and the enum is not the signatured type in the
8034 unit, then we do not want to add a symbol for it. Adding a
8035 symbol would in some cases obscure the true definition of the
8036 enum, giving users an incomplete type when the definition is
8037 actually available. Note that we do not want to do this for all
8038 enums which are just declarations, because C++0x allows forward
8039 enum declarations. */
8040 if (cu->per_cu->debug_types_section
8041 && die_is_declaration (die, cu))
8043 struct signatured_type *type_sig;
8046 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
8047 cu->per_cu->debug_types_section,
8048 cu->per_cu->offset);
8049 if (type_sig->per_cu.offset + type_sig->type_offset
8054 new_symbol (die, this_type, cu);
8057 /* Extract all information from a DW_TAG_array_type DIE and put it in
8058 the DIE's type field. For now, this only handles one dimensional
8061 static struct type *
8062 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
8064 struct objfile *objfile = cu->objfile;
8065 struct die_info *child_die;
8067 struct type *element_type, *range_type, *index_type;
8068 struct type **range_types = NULL;
8069 struct attribute *attr;
8071 struct cleanup *back_to;
8074 element_type = die_type (die, cu);
8076 /* The die_type call above may have already set the type for this DIE. */
8077 type = get_die_type (die, cu);
8081 /* Irix 6.2 native cc creates array types without children for
8082 arrays with unspecified length. */
8083 if (die->child == NULL)
8085 index_type = objfile_type (objfile)->builtin_int;
8086 range_type = create_range_type (NULL, index_type, 0, -1);
8087 type = create_array_type (NULL, element_type, range_type);
8088 return set_die_type (die, type, cu);
8091 back_to = make_cleanup (null_cleanup, NULL);
8092 child_die = die->child;
8093 while (child_die && child_die->tag)
8095 if (child_die->tag == DW_TAG_subrange_type)
8097 struct type *child_type = read_type_die (child_die, cu);
8099 if (child_type != NULL)
8101 /* The range type was succesfully read. Save it for the
8102 array type creation. */
8103 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
8105 range_types = (struct type **)
8106 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
8107 * sizeof (struct type *));
8109 make_cleanup (free_current_contents, &range_types);
8111 range_types[ndim++] = child_type;
8114 child_die = sibling_die (child_die);
8117 /* Dwarf2 dimensions are output from left to right, create the
8118 necessary array types in backwards order. */
8120 type = element_type;
8122 if (read_array_order (die, cu) == DW_ORD_col_major)
8127 type = create_array_type (NULL, type, range_types[i++]);
8132 type = create_array_type (NULL, type, range_types[ndim]);
8135 /* Understand Dwarf2 support for vector types (like they occur on
8136 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8137 array type. This is not part of the Dwarf2/3 standard yet, but a
8138 custom vendor extension. The main difference between a regular
8139 array and the vector variant is that vectors are passed by value
8141 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
8143 make_vector_type (type);
8145 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8146 implementation may choose to implement triple vectors using this
8148 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8151 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
8152 TYPE_LENGTH (type) = DW_UNSND (attr);
8154 complaint (&symfile_complaints,
8155 _("DW_AT_byte_size for array type smaller "
8156 "than the total size of elements"));
8159 name = dwarf2_name (die, cu);
8161 TYPE_NAME (type) = name;
8163 /* Install the type in the die. */
8164 set_die_type (die, type, cu);
8166 /* set_die_type should be already done. */
8167 set_descriptive_type (type, die, cu);
8169 do_cleanups (back_to);
8174 static enum dwarf_array_dim_ordering
8175 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
8177 struct attribute *attr;
8179 attr = dwarf2_attr (die, DW_AT_ordering, cu);
8181 if (attr) return DW_SND (attr);
8183 /* GNU F77 is a special case, as at 08/2004 array type info is the
8184 opposite order to the dwarf2 specification, but data is still
8185 laid out as per normal fortran.
8187 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8188 version checking. */
8190 if (cu->language == language_fortran
8191 && cu->producer && strstr (cu->producer, "GNU F77"))
8193 return DW_ORD_row_major;
8196 switch (cu->language_defn->la_array_ordering)
8198 case array_column_major:
8199 return DW_ORD_col_major;
8200 case array_row_major:
8202 return DW_ORD_row_major;
8206 /* Extract all information from a DW_TAG_set_type DIE and put it in
8207 the DIE's type field. */
8209 static struct type *
8210 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
8212 struct type *domain_type, *set_type;
8213 struct attribute *attr;
8215 domain_type = die_type (die, cu);
8217 /* The die_type call above may have already set the type for this DIE. */
8218 set_type = get_die_type (die, cu);
8222 set_type = create_set_type (NULL, domain_type);
8224 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8226 TYPE_LENGTH (set_type) = DW_UNSND (attr);
8228 return set_die_type (die, set_type, cu);
8231 /* First cut: install each common block member as a global variable. */
8234 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
8236 struct die_info *child_die;
8237 struct attribute *attr;
8239 CORE_ADDR base = (CORE_ADDR) 0;
8241 attr = dwarf2_attr (die, DW_AT_location, cu);
8244 /* Support the .debug_loc offsets. */
8245 if (attr_form_is_block (attr))
8247 base = decode_locdesc (DW_BLOCK (attr), cu);
8249 else if (attr_form_is_section_offset (attr))
8251 dwarf2_complex_location_expr_complaint ();
8255 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8256 "common block member");
8259 if (die->child != NULL)
8261 child_die = die->child;
8262 while (child_die && child_die->tag)
8266 sym = new_symbol (child_die, NULL, cu);
8268 && handle_data_member_location (child_die, cu, &offset))
8270 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
8271 add_symbol_to_list (sym, &global_symbols);
8273 child_die = sibling_die (child_die);
8278 /* Create a type for a C++ namespace. */
8280 static struct type *
8281 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
8283 struct objfile *objfile = cu->objfile;
8284 const char *previous_prefix, *name;
8288 /* For extensions, reuse the type of the original namespace. */
8289 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
8291 struct die_info *ext_die;
8292 struct dwarf2_cu *ext_cu = cu;
8294 ext_die = dwarf2_extension (die, &ext_cu);
8295 type = read_type_die (ext_die, ext_cu);
8297 /* EXT_CU may not be the same as CU.
8298 Ensure TYPE is recorded in CU's type_hash table. */
8299 return set_die_type (die, type, cu);
8302 name = namespace_name (die, &is_anonymous, cu);
8304 /* Now build the name of the current namespace. */
8306 previous_prefix = determine_prefix (die, cu);
8307 if (previous_prefix[0] != '\0')
8308 name = typename_concat (&objfile->objfile_obstack,
8309 previous_prefix, name, 0, cu);
8311 /* Create the type. */
8312 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8314 TYPE_NAME (type) = (char *) name;
8315 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8317 return set_die_type (die, type, cu);
8320 /* Read a C++ namespace. */
8323 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8325 struct objfile *objfile = cu->objfile;
8328 /* Add a symbol associated to this if we haven't seen the namespace
8329 before. Also, add a using directive if it's an anonymous
8332 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8336 type = read_type_die (die, cu);
8337 new_symbol (die, type, cu);
8339 namespace_name (die, &is_anonymous, cu);
8342 const char *previous_prefix = determine_prefix (die, cu);
8344 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8345 NULL, NULL, &objfile->objfile_obstack);
8349 if (die->child != NULL)
8351 struct die_info *child_die = die->child;
8353 while (child_die && child_die->tag)
8355 process_die (child_die, cu);
8356 child_die = sibling_die (child_die);
8361 /* Read a Fortran module as type. This DIE can be only a declaration used for
8362 imported module. Still we need that type as local Fortran "use ... only"
8363 declaration imports depend on the created type in determine_prefix. */
8365 static struct type *
8366 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8368 struct objfile *objfile = cu->objfile;
8372 module_name = dwarf2_name (die, cu);
8374 complaint (&symfile_complaints,
8375 _("DW_TAG_module has no name, offset 0x%x"),
8377 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8379 /* determine_prefix uses TYPE_TAG_NAME. */
8380 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8382 return set_die_type (die, type, cu);
8385 /* Read a Fortran module. */
8388 read_module (struct die_info *die, struct dwarf2_cu *cu)
8390 struct die_info *child_die = die->child;
8392 while (child_die && child_die->tag)
8394 process_die (child_die, cu);
8395 child_die = sibling_die (child_die);
8399 /* Return the name of the namespace represented by DIE. Set
8400 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8404 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8406 struct die_info *current_die;
8407 const char *name = NULL;
8409 /* Loop through the extensions until we find a name. */
8411 for (current_die = die;
8412 current_die != NULL;
8413 current_die = dwarf2_extension (die, &cu))
8415 name = dwarf2_name (current_die, cu);
8420 /* Is it an anonymous namespace? */
8422 *is_anonymous = (name == NULL);
8424 name = CP_ANONYMOUS_NAMESPACE_STR;
8429 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8430 the user defined type vector. */
8432 static struct type *
8433 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8435 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8436 struct comp_unit_head *cu_header = &cu->header;
8438 struct attribute *attr_byte_size;
8439 struct attribute *attr_address_class;
8440 int byte_size, addr_class;
8441 struct type *target_type;
8443 target_type = die_type (die, cu);
8445 /* The die_type call above may have already set the type for this DIE. */
8446 type = get_die_type (die, cu);
8450 type = lookup_pointer_type (target_type);
8452 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8454 byte_size = DW_UNSND (attr_byte_size);
8456 byte_size = cu_header->addr_size;
8458 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8459 if (attr_address_class)
8460 addr_class = DW_UNSND (attr_address_class);
8462 addr_class = DW_ADDR_none;
8464 /* If the pointer size or address class is different than the
8465 default, create a type variant marked as such and set the
8466 length accordingly. */
8467 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8469 if (gdbarch_address_class_type_flags_p (gdbarch))
8473 type_flags = gdbarch_address_class_type_flags
8474 (gdbarch, byte_size, addr_class);
8475 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8477 type = make_type_with_address_space (type, type_flags);
8479 else if (TYPE_LENGTH (type) != byte_size)
8481 complaint (&symfile_complaints,
8482 _("invalid pointer size %d"), byte_size);
8486 /* Should we also complain about unhandled address classes? */
8490 TYPE_LENGTH (type) = byte_size;
8491 return set_die_type (die, type, cu);
8494 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8495 the user defined type vector. */
8497 static struct type *
8498 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8501 struct type *to_type;
8502 struct type *domain;
8504 to_type = die_type (die, cu);
8505 domain = die_containing_type (die, cu);
8507 /* The calls above may have already set the type for this DIE. */
8508 type = get_die_type (die, cu);
8512 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8513 type = lookup_methodptr_type (to_type);
8515 type = lookup_memberptr_type (to_type, domain);
8517 return set_die_type (die, type, cu);
8520 /* Extract all information from a DW_TAG_reference_type DIE and add to
8521 the user defined type vector. */
8523 static struct type *
8524 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8526 struct comp_unit_head *cu_header = &cu->header;
8527 struct type *type, *target_type;
8528 struct attribute *attr;
8530 target_type = die_type (die, cu);
8532 /* The die_type call above may have already set the type for this DIE. */
8533 type = get_die_type (die, cu);
8537 type = lookup_reference_type (target_type);
8538 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8541 TYPE_LENGTH (type) = DW_UNSND (attr);
8545 TYPE_LENGTH (type) = cu_header->addr_size;
8547 return set_die_type (die, type, cu);
8550 static struct type *
8551 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8553 struct type *base_type, *cv_type;
8555 base_type = die_type (die, cu);
8557 /* The die_type call above may have already set the type for this DIE. */
8558 cv_type = get_die_type (die, cu);
8562 /* In case the const qualifier is applied to an array type, the element type
8563 is so qualified, not the array type (section 6.7.3 of C99). */
8564 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8566 struct type *el_type, *inner_array;
8568 base_type = copy_type (base_type);
8569 inner_array = base_type;
8571 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8573 TYPE_TARGET_TYPE (inner_array) =
8574 copy_type (TYPE_TARGET_TYPE (inner_array));
8575 inner_array = TYPE_TARGET_TYPE (inner_array);
8578 el_type = TYPE_TARGET_TYPE (inner_array);
8579 TYPE_TARGET_TYPE (inner_array) =
8580 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8582 return set_die_type (die, base_type, cu);
8585 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8586 return set_die_type (die, cv_type, cu);
8589 static struct type *
8590 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8592 struct type *base_type, *cv_type;
8594 base_type = die_type (die, cu);
8596 /* The die_type call above may have already set the type for this DIE. */
8597 cv_type = get_die_type (die, cu);
8601 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8602 return set_die_type (die, cv_type, cu);
8605 /* Extract all information from a DW_TAG_string_type DIE and add to
8606 the user defined type vector. It isn't really a user defined type,
8607 but it behaves like one, with other DIE's using an AT_user_def_type
8608 attribute to reference it. */
8610 static struct type *
8611 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8613 struct objfile *objfile = cu->objfile;
8614 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8615 struct type *type, *range_type, *index_type, *char_type;
8616 struct attribute *attr;
8617 unsigned int length;
8619 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8622 length = DW_UNSND (attr);
8626 /* Check for the DW_AT_byte_size attribute. */
8627 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8630 length = DW_UNSND (attr);
8638 index_type = objfile_type (objfile)->builtin_int;
8639 range_type = create_range_type (NULL, index_type, 1, length);
8640 char_type = language_string_char_type (cu->language_defn, gdbarch);
8641 type = create_string_type (NULL, char_type, range_type);
8643 return set_die_type (die, type, cu);
8646 /* Handle DIES due to C code like:
8650 int (*funcp)(int a, long l);
8654 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8656 static struct type *
8657 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8659 struct objfile *objfile = cu->objfile;
8660 struct type *type; /* Type that this function returns. */
8661 struct type *ftype; /* Function that returns above type. */
8662 struct attribute *attr;
8664 type = die_type (die, cu);
8666 /* The die_type call above may have already set the type for this DIE. */
8667 ftype = get_die_type (die, cu);
8671 ftype = lookup_function_type (type);
8673 /* All functions in C++, Pascal and Java have prototypes. */
8674 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8675 if ((attr && (DW_UNSND (attr) != 0))
8676 || cu->language == language_cplus
8677 || cu->language == language_java
8678 || cu->language == language_pascal)
8679 TYPE_PROTOTYPED (ftype) = 1;
8680 else if (producer_is_realview (cu->producer))
8681 /* RealView does not emit DW_AT_prototyped. We can not
8682 distinguish prototyped and unprototyped functions; default to
8683 prototyped, since that is more common in modern code (and
8684 RealView warns about unprototyped functions). */
8685 TYPE_PROTOTYPED (ftype) = 1;
8687 /* Store the calling convention in the type if it's available in
8688 the subroutine die. Otherwise set the calling convention to
8689 the default value DW_CC_normal. */
8690 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8692 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8693 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8694 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8696 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8698 /* We need to add the subroutine type to the die immediately so
8699 we don't infinitely recurse when dealing with parameters
8700 declared as the same subroutine type. */
8701 set_die_type (die, ftype, cu);
8703 if (die->child != NULL)
8705 struct type *void_type = objfile_type (objfile)->builtin_void;
8706 struct die_info *child_die;
8707 int nparams, iparams;
8709 /* Count the number of parameters.
8710 FIXME: GDB currently ignores vararg functions, but knows about
8711 vararg member functions. */
8713 child_die = die->child;
8714 while (child_die && child_die->tag)
8716 if (child_die->tag == DW_TAG_formal_parameter)
8718 else if (child_die->tag == DW_TAG_unspecified_parameters)
8719 TYPE_VARARGS (ftype) = 1;
8720 child_die = sibling_die (child_die);
8723 /* Allocate storage for parameters and fill them in. */
8724 TYPE_NFIELDS (ftype) = nparams;
8725 TYPE_FIELDS (ftype) = (struct field *)
8726 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8728 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8729 even if we error out during the parameters reading below. */
8730 for (iparams = 0; iparams < nparams; iparams++)
8731 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8734 child_die = die->child;
8735 while (child_die && child_die->tag)
8737 if (child_die->tag == DW_TAG_formal_parameter)
8739 struct type *arg_type;
8741 /* DWARF version 2 has no clean way to discern C++
8742 static and non-static member functions. G++ helps
8743 GDB by marking the first parameter for non-static
8744 member functions (which is the this pointer) as
8745 artificial. We pass this information to
8746 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8748 DWARF version 3 added DW_AT_object_pointer, which GCC
8749 4.5 does not yet generate. */
8750 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8752 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8755 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8757 /* GCC/43521: In java, the formal parameter
8758 "this" is sometimes not marked with DW_AT_artificial. */
8759 if (cu->language == language_java)
8761 const char *name = dwarf2_name (child_die, cu);
8763 if (name && !strcmp (name, "this"))
8764 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8767 arg_type = die_type (child_die, cu);
8769 /* RealView does not mark THIS as const, which the testsuite
8770 expects. GCC marks THIS as const in method definitions,
8771 but not in the class specifications (GCC PR 43053). */
8772 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8773 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8776 struct dwarf2_cu *arg_cu = cu;
8777 const char *name = dwarf2_name (child_die, cu);
8779 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8782 /* If the compiler emits this, use it. */
8783 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8786 else if (name && strcmp (name, "this") == 0)
8787 /* Function definitions will have the argument names. */
8789 else if (name == NULL && iparams == 0)
8790 /* Declarations may not have the names, so like
8791 elsewhere in GDB, assume an artificial first
8792 argument is "this". */
8796 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8800 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8803 child_die = sibling_die (child_die);
8810 static struct type *
8811 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8813 struct objfile *objfile = cu->objfile;
8814 const char *name = NULL;
8815 struct type *this_type, *target_type;
8817 name = dwarf2_full_name (NULL, die, cu);
8818 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8819 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8820 TYPE_NAME (this_type) = (char *) name;
8821 set_die_type (die, this_type, cu);
8822 target_type = die_type (die, cu);
8823 if (target_type != this_type)
8824 TYPE_TARGET_TYPE (this_type) = target_type;
8827 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8828 spec and cause infinite loops in GDB. */
8829 complaint (&symfile_complaints,
8830 _("Self-referential DW_TAG_typedef "
8831 "- DIE at 0x%x [in module %s]"),
8832 die->offset, objfile->name);
8833 TYPE_TARGET_TYPE (this_type) = NULL;
8838 /* Find a representation of a given base type and install
8839 it in the TYPE field of the die. */
8841 static struct type *
8842 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8844 struct objfile *objfile = cu->objfile;
8846 struct attribute *attr;
8847 int encoding = 0, size = 0;
8849 enum type_code code = TYPE_CODE_INT;
8851 struct type *target_type = NULL;
8853 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8856 encoding = DW_UNSND (attr);
8858 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8861 size = DW_UNSND (attr);
8863 name = dwarf2_name (die, cu);
8866 complaint (&symfile_complaints,
8867 _("DW_AT_name missing from DW_TAG_base_type"));
8872 case DW_ATE_address:
8873 /* Turn DW_ATE_address into a void * pointer. */
8874 code = TYPE_CODE_PTR;
8875 type_flags |= TYPE_FLAG_UNSIGNED;
8876 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8878 case DW_ATE_boolean:
8879 code = TYPE_CODE_BOOL;
8880 type_flags |= TYPE_FLAG_UNSIGNED;
8882 case DW_ATE_complex_float:
8883 code = TYPE_CODE_COMPLEX;
8884 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8886 case DW_ATE_decimal_float:
8887 code = TYPE_CODE_DECFLOAT;
8890 code = TYPE_CODE_FLT;
8894 case DW_ATE_unsigned:
8895 type_flags |= TYPE_FLAG_UNSIGNED;
8896 if (cu->language == language_fortran
8898 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
8899 code = TYPE_CODE_CHAR;
8901 case DW_ATE_signed_char:
8902 if (cu->language == language_ada || cu->language == language_m2
8903 || cu->language == language_pascal
8904 || cu->language == language_fortran)
8905 code = TYPE_CODE_CHAR;
8907 case DW_ATE_unsigned_char:
8908 if (cu->language == language_ada || cu->language == language_m2
8909 || cu->language == language_pascal
8910 || cu->language == language_fortran)
8911 code = TYPE_CODE_CHAR;
8912 type_flags |= TYPE_FLAG_UNSIGNED;
8915 /* We just treat this as an integer and then recognize the
8916 type by name elsewhere. */
8920 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8921 dwarf_type_encoding_name (encoding));
8925 type = init_type (code, size, type_flags, NULL, objfile);
8926 TYPE_NAME (type) = name;
8927 TYPE_TARGET_TYPE (type) = target_type;
8929 if (name && strcmp (name, "char") == 0)
8930 TYPE_NOSIGN (type) = 1;
8932 return set_die_type (die, type, cu);
8935 /* Read the given DW_AT_subrange DIE. */
8937 static struct type *
8938 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8940 struct type *base_type;
8941 struct type *range_type;
8942 struct attribute *attr;
8946 LONGEST negative_mask;
8948 base_type = die_type (die, cu);
8949 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8950 check_typedef (base_type);
8952 /* The die_type call above may have already set the type for this DIE. */
8953 range_type = get_die_type (die, cu);
8957 if (cu->language == language_fortran)
8959 /* FORTRAN implies a lower bound of 1, if not given. */
8963 /* FIXME: For variable sized arrays either of these could be
8964 a variable rather than a constant value. We'll allow it,
8965 but we don't know how to handle it. */
8966 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8968 low = dwarf2_get_attr_constant_value (attr, 0);
8970 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8973 if (attr_form_is_block (attr) || is_ref_attr (attr))
8975 /* GCC encodes arrays with unspecified or dynamic length
8976 with a DW_FORM_block1 attribute or a reference attribute.
8977 FIXME: GDB does not yet know how to handle dynamic
8978 arrays properly, treat them as arrays with unspecified
8981 FIXME: jimb/2003-09-22: GDB does not really know
8982 how to handle arrays of unspecified length
8983 either; we just represent them as zero-length
8984 arrays. Choose an appropriate upper bound given
8985 the lower bound we've computed above. */
8989 high = dwarf2_get_attr_constant_value (attr, 1);
8993 attr = dwarf2_attr (die, DW_AT_count, cu);
8996 int count = dwarf2_get_attr_constant_value (attr, 1);
8997 high = low + count - 1;
9001 /* Unspecified array length. */
9006 /* Dwarf-2 specifications explicitly allows to create subrange types
9007 without specifying a base type.
9008 In that case, the base type must be set to the type of
9009 the lower bound, upper bound or count, in that order, if any of these
9010 three attributes references an object that has a type.
9011 If no base type is found, the Dwarf-2 specifications say that
9012 a signed integer type of size equal to the size of an address should
9014 For the following C code: `extern char gdb_int [];'
9015 GCC produces an empty range DIE.
9016 FIXME: muller/2010-05-28: Possible references to object for low bound,
9017 high bound or count are not yet handled by this code. */
9018 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
9020 struct objfile *objfile = cu->objfile;
9021 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9022 int addr_size = gdbarch_addr_bit (gdbarch) /8;
9023 struct type *int_type = objfile_type (objfile)->builtin_int;
9025 /* Test "int", "long int", and "long long int" objfile types,
9026 and select the first one having a size above or equal to the
9027 architecture address size. */
9028 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9029 base_type = int_type;
9032 int_type = objfile_type (objfile)->builtin_long;
9033 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9034 base_type = int_type;
9037 int_type = objfile_type (objfile)->builtin_long_long;
9038 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9039 base_type = int_type;
9045 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
9046 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
9047 low |= negative_mask;
9048 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
9049 high |= negative_mask;
9051 range_type = create_range_type (NULL, base_type, low, high);
9053 /* Mark arrays with dynamic length at least as an array of unspecified
9054 length. GDB could check the boundary but before it gets implemented at
9055 least allow accessing the array elements. */
9056 if (attr && attr_form_is_block (attr))
9057 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9059 /* Ada expects an empty array on no boundary attributes. */
9060 if (attr == NULL && cu->language != language_ada)
9061 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9063 name = dwarf2_name (die, cu);
9065 TYPE_NAME (range_type) = name;
9067 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
9069 TYPE_LENGTH (range_type) = DW_UNSND (attr);
9071 set_die_type (die, range_type, cu);
9073 /* set_die_type should be already done. */
9074 set_descriptive_type (range_type, die, cu);
9079 static struct type *
9080 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
9084 /* For now, we only support the C meaning of an unspecified type: void. */
9086 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
9087 TYPE_NAME (type) = dwarf2_name (die, cu);
9089 return set_die_type (die, type, cu);
9092 /* Trivial hash function for die_info: the hash value of a DIE
9093 is its offset in .debug_info for this objfile. */
9096 die_hash (const void *item)
9098 const struct die_info *die = item;
9103 /* Trivial comparison function for die_info structures: two DIEs
9104 are equal if they have the same offset. */
9107 die_eq (const void *item_lhs, const void *item_rhs)
9109 const struct die_info *die_lhs = item_lhs;
9110 const struct die_info *die_rhs = item_rhs;
9112 return die_lhs->offset == die_rhs->offset;
9115 /* Read a whole compilation unit into a linked list of dies. */
9117 static struct die_info *
9118 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
9120 struct die_reader_specs reader_specs;
9121 int read_abbrevs = 0;
9122 struct cleanup *back_to = NULL;
9123 struct die_info *die;
9125 if (cu->dwarf2_abbrevs == NULL)
9127 dwarf2_read_abbrevs (cu);
9128 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
9132 gdb_assert (cu->die_hash == NULL);
9134 = htab_create_alloc_ex (cu->header.length / 12,
9138 &cu->comp_unit_obstack,
9139 hashtab_obstack_allocate,
9140 dummy_obstack_deallocate);
9142 init_cu_die_reader (&reader_specs, cu);
9144 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
9147 do_cleanups (back_to);
9152 /* Main entry point for reading a DIE and all children.
9153 Read the DIE and dump it if requested. */
9155 static struct die_info *
9156 read_die_and_children (const struct die_reader_specs *reader,
9158 gdb_byte **new_info_ptr,
9159 struct die_info *parent)
9161 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
9162 new_info_ptr, parent);
9164 if (dwarf2_die_debug)
9166 fprintf_unfiltered (gdb_stdlog,
9167 "\nRead die from %s of %s:\n",
9168 (reader->cu->per_cu->debug_types_section
9171 reader->abfd->filename);
9172 dump_die (result, dwarf2_die_debug);
9178 /* Read a single die and all its descendents. Set the die's sibling
9179 field to NULL; set other fields in the die correctly, and set all
9180 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9181 location of the info_ptr after reading all of those dies. PARENT
9182 is the parent of the die in question. */
9184 static struct die_info *
9185 read_die_and_children_1 (const struct die_reader_specs *reader,
9187 gdb_byte **new_info_ptr,
9188 struct die_info *parent)
9190 struct die_info *die;
9194 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
9197 *new_info_ptr = cur_ptr;
9200 store_in_ref_table (die, reader->cu);
9203 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
9207 *new_info_ptr = cur_ptr;
9210 die->sibling = NULL;
9211 die->parent = parent;
9215 /* Read a die, all of its descendents, and all of its siblings; set
9216 all of the fields of all of the dies correctly. Arguments are as
9217 in read_die_and_children. */
9219 static struct die_info *
9220 read_die_and_siblings (const struct die_reader_specs *reader,
9222 gdb_byte **new_info_ptr,
9223 struct die_info *parent)
9225 struct die_info *first_die, *last_sibling;
9229 first_die = last_sibling = NULL;
9233 struct die_info *die
9234 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
9238 *new_info_ptr = cur_ptr;
9245 last_sibling->sibling = die;
9251 /* Read the die from the .debug_info section buffer. Set DIEP to
9252 point to a newly allocated die with its information, except for its
9253 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9254 whether the die has children or not. */
9257 read_full_die (const struct die_reader_specs *reader,
9258 struct die_info **diep, gdb_byte *info_ptr,
9261 unsigned int abbrev_number, bytes_read, i, offset;
9262 struct abbrev_info *abbrev;
9263 struct die_info *die;
9264 struct dwarf2_cu *cu = reader->cu;
9265 bfd *abfd = reader->abfd;
9267 offset = info_ptr - reader->buffer;
9268 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9269 info_ptr += bytes_read;
9277 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
9279 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9281 bfd_get_filename (abfd));
9283 die = dwarf_alloc_die (cu, abbrev->num_attrs);
9284 die->offset = offset;
9285 die->tag = abbrev->tag;
9286 die->abbrev = abbrev_number;
9288 die->num_attrs = abbrev->num_attrs;
9290 for (i = 0; i < abbrev->num_attrs; ++i)
9291 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
9292 abfd, info_ptr, cu);
9295 *has_children = abbrev->has_children;
9299 /* In DWARF version 2, the description of the debugging information is
9300 stored in a separate .debug_abbrev section. Before we read any
9301 dies from a section we read in all abbreviations and install them
9302 in a hash table. This function also sets flags in CU describing
9303 the data found in the abbrev table. */
9306 dwarf2_read_abbrevs (struct dwarf2_cu *cu)
9308 bfd *abfd = cu->objfile->obfd;
9309 struct comp_unit_head *cu_header = &cu->header;
9310 gdb_byte *abbrev_ptr;
9311 struct abbrev_info *cur_abbrev;
9312 unsigned int abbrev_number, bytes_read, abbrev_name;
9313 unsigned int abbrev_form, hash_number;
9314 struct attr_abbrev *cur_attrs;
9315 unsigned int allocated_attrs;
9317 /* Initialize dwarf2 abbrevs. */
9318 obstack_init (&cu->abbrev_obstack);
9319 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9321 * sizeof (struct abbrev_info *)));
9322 memset (cu->dwarf2_abbrevs, 0,
9323 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9325 dwarf2_read_section (dwarf2_per_objfile->objfile,
9326 &dwarf2_per_objfile->abbrev);
9327 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
9328 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9329 abbrev_ptr += bytes_read;
9331 allocated_attrs = ATTR_ALLOC_CHUNK;
9332 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9334 /* Loop until we reach an abbrev number of 0. */
9335 while (abbrev_number)
9337 cur_abbrev = dwarf_alloc_abbrev (cu);
9339 /* read in abbrev header */
9340 cur_abbrev->number = abbrev_number;
9341 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9342 abbrev_ptr += bytes_read;
9343 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9346 /* now read in declarations */
9347 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9348 abbrev_ptr += bytes_read;
9349 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9350 abbrev_ptr += bytes_read;
9353 if (cur_abbrev->num_attrs == allocated_attrs)
9355 allocated_attrs += ATTR_ALLOC_CHUNK;
9357 = xrealloc (cur_attrs, (allocated_attrs
9358 * sizeof (struct attr_abbrev)));
9361 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9362 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9363 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9364 abbrev_ptr += bytes_read;
9365 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9366 abbrev_ptr += bytes_read;
9369 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9370 (cur_abbrev->num_attrs
9371 * sizeof (struct attr_abbrev)));
9372 memcpy (cur_abbrev->attrs, cur_attrs,
9373 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9375 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9376 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9377 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9379 /* Get next abbreviation.
9380 Under Irix6 the abbreviations for a compilation unit are not
9381 always properly terminated with an abbrev number of 0.
9382 Exit loop if we encounter an abbreviation which we have
9383 already read (which means we are about to read the abbreviations
9384 for the next compile unit) or if the end of the abbreviation
9385 table is reached. */
9386 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9387 >= dwarf2_per_objfile->abbrev.size)
9389 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9390 abbrev_ptr += bytes_read;
9391 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9398 /* Release the memory used by the abbrev table for a compilation unit. */
9401 dwarf2_free_abbrev_table (void *ptr_to_cu)
9403 struct dwarf2_cu *cu = ptr_to_cu;
9405 obstack_free (&cu->abbrev_obstack, NULL);
9406 cu->dwarf2_abbrevs = NULL;
9409 /* Lookup an abbrev_info structure in the abbrev hash table. */
9411 static struct abbrev_info *
9412 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9414 unsigned int hash_number;
9415 struct abbrev_info *abbrev;
9417 hash_number = number % ABBREV_HASH_SIZE;
9418 abbrev = cu->dwarf2_abbrevs[hash_number];
9422 if (abbrev->number == number)
9425 abbrev = abbrev->next;
9430 /* Returns nonzero if TAG represents a type that we might generate a partial
9434 is_type_tag_for_partial (int tag)
9439 /* Some types that would be reasonable to generate partial symbols for,
9440 that we don't at present. */
9441 case DW_TAG_array_type:
9442 case DW_TAG_file_type:
9443 case DW_TAG_ptr_to_member_type:
9444 case DW_TAG_set_type:
9445 case DW_TAG_string_type:
9446 case DW_TAG_subroutine_type:
9448 case DW_TAG_base_type:
9449 case DW_TAG_class_type:
9450 case DW_TAG_interface_type:
9451 case DW_TAG_enumeration_type:
9452 case DW_TAG_structure_type:
9453 case DW_TAG_subrange_type:
9454 case DW_TAG_typedef:
9455 case DW_TAG_union_type:
9462 /* Load all DIEs that are interesting for partial symbols into memory. */
9464 static struct partial_die_info *
9465 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9466 int building_psymtab, struct dwarf2_cu *cu)
9468 struct objfile *objfile = cu->objfile;
9469 struct partial_die_info *part_die;
9470 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9471 struct abbrev_info *abbrev;
9472 unsigned int bytes_read;
9473 unsigned int load_all = 0;
9475 int nesting_level = 1;
9480 if (cu->per_cu && cu->per_cu->load_all_dies)
9484 = htab_create_alloc_ex (cu->header.length / 12,
9488 &cu->comp_unit_obstack,
9489 hashtab_obstack_allocate,
9490 dummy_obstack_deallocate);
9492 part_die = obstack_alloc (&cu->comp_unit_obstack,
9493 sizeof (struct partial_die_info));
9497 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9499 /* A NULL abbrev means the end of a series of children. */
9502 if (--nesting_level == 0)
9504 /* PART_DIE was probably the last thing allocated on the
9505 comp_unit_obstack, so we could call obstack_free
9506 here. We don't do that because the waste is small,
9507 and will be cleaned up when we're done with this
9508 compilation unit. This way, we're also more robust
9509 against other users of the comp_unit_obstack. */
9512 info_ptr += bytes_read;
9513 last_die = parent_die;
9514 parent_die = parent_die->die_parent;
9518 /* Check for template arguments. We never save these; if
9519 they're seen, we just mark the parent, and go on our way. */
9520 if (parent_die != NULL
9521 && cu->language == language_cplus
9522 && (abbrev->tag == DW_TAG_template_type_param
9523 || abbrev->tag == DW_TAG_template_value_param))
9525 parent_die->has_template_arguments = 1;
9529 /* We don't need a partial DIE for the template argument. */
9530 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9536 /* We only recurse into subprograms looking for template arguments.
9537 Skip their other children. */
9539 && cu->language == language_cplus
9540 && parent_die != NULL
9541 && parent_die->tag == DW_TAG_subprogram)
9543 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9547 /* Check whether this DIE is interesting enough to save. Normally
9548 we would not be interested in members here, but there may be
9549 later variables referencing them via DW_AT_specification (for
9552 && !is_type_tag_for_partial (abbrev->tag)
9553 && abbrev->tag != DW_TAG_constant
9554 && abbrev->tag != DW_TAG_enumerator
9555 && abbrev->tag != DW_TAG_subprogram
9556 && abbrev->tag != DW_TAG_lexical_block
9557 && abbrev->tag != DW_TAG_variable
9558 && abbrev->tag != DW_TAG_namespace
9559 && abbrev->tag != DW_TAG_module
9560 && abbrev->tag != DW_TAG_member)
9562 /* Otherwise we skip to the next sibling, if any. */
9563 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9567 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9568 buffer, info_ptr, cu);
9570 /* This two-pass algorithm for processing partial symbols has a
9571 high cost in cache pressure. Thus, handle some simple cases
9572 here which cover the majority of C partial symbols. DIEs
9573 which neither have specification tags in them, nor could have
9574 specification tags elsewhere pointing at them, can simply be
9575 processed and discarded.
9577 This segment is also optional; scan_partial_symbols and
9578 add_partial_symbol will handle these DIEs if we chain
9579 them in normally. When compilers which do not emit large
9580 quantities of duplicate debug information are more common,
9581 this code can probably be removed. */
9583 /* Any complete simple types at the top level (pretty much all
9584 of them, for a language without namespaces), can be processed
9586 if (parent_die == NULL
9587 && part_die->has_specification == 0
9588 && part_die->is_declaration == 0
9589 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9590 || part_die->tag == DW_TAG_base_type
9591 || part_die->tag == DW_TAG_subrange_type))
9593 if (building_psymtab && part_die->name != NULL)
9594 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9595 VAR_DOMAIN, LOC_TYPEDEF,
9596 &objfile->static_psymbols,
9597 0, (CORE_ADDR) 0, cu->language, objfile);
9598 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9602 /* The exception for DW_TAG_typedef with has_children above is
9603 a workaround of GCC PR debug/47510. In the case of this complaint
9604 type_name_no_tag_or_error will error on such types later.
9606 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9607 it could not find the child DIEs referenced later, this is checked
9608 above. In correct DWARF DW_TAG_typedef should have no children. */
9610 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9611 complaint (&symfile_complaints,
9612 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9613 "- DIE at 0x%x [in module %s]"),
9614 part_die->offset, objfile->name);
9616 /* If we're at the second level, and we're an enumerator, and
9617 our parent has no specification (meaning possibly lives in a
9618 namespace elsewhere), then we can add the partial symbol now
9619 instead of queueing it. */
9620 if (part_die->tag == DW_TAG_enumerator
9621 && parent_die != NULL
9622 && parent_die->die_parent == NULL
9623 && parent_die->tag == DW_TAG_enumeration_type
9624 && parent_die->has_specification == 0)
9626 if (part_die->name == NULL)
9627 complaint (&symfile_complaints,
9628 _("malformed enumerator DIE ignored"));
9629 else if (building_psymtab)
9630 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9631 VAR_DOMAIN, LOC_CONST,
9632 (cu->language == language_cplus
9633 || cu->language == language_java)
9634 ? &objfile->global_psymbols
9635 : &objfile->static_psymbols,
9636 0, (CORE_ADDR) 0, cu->language, objfile);
9638 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9642 /* We'll save this DIE so link it in. */
9643 part_die->die_parent = parent_die;
9644 part_die->die_sibling = NULL;
9645 part_die->die_child = NULL;
9647 if (last_die && last_die == parent_die)
9648 last_die->die_child = part_die;
9650 last_die->die_sibling = part_die;
9652 last_die = part_die;
9654 if (first_die == NULL)
9655 first_die = part_die;
9657 /* Maybe add the DIE to the hash table. Not all DIEs that we
9658 find interesting need to be in the hash table, because we
9659 also have the parent/sibling/child chains; only those that we
9660 might refer to by offset later during partial symbol reading.
9662 For now this means things that might have be the target of a
9663 DW_AT_specification, DW_AT_abstract_origin, or
9664 DW_AT_extension. DW_AT_extension will refer only to
9665 namespaces; DW_AT_abstract_origin refers to functions (and
9666 many things under the function DIE, but we do not recurse
9667 into function DIEs during partial symbol reading) and
9668 possibly variables as well; DW_AT_specification refers to
9669 declarations. Declarations ought to have the DW_AT_declaration
9670 flag. It happens that GCC forgets to put it in sometimes, but
9671 only for functions, not for types.
9673 Adding more things than necessary to the hash table is harmless
9674 except for the performance cost. Adding too few will result in
9675 wasted time in find_partial_die, when we reread the compilation
9676 unit with load_all_dies set. */
9679 || abbrev->tag == DW_TAG_constant
9680 || abbrev->tag == DW_TAG_subprogram
9681 || abbrev->tag == DW_TAG_variable
9682 || abbrev->tag == DW_TAG_namespace
9683 || part_die->is_declaration)
9687 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9688 part_die->offset, INSERT);
9692 part_die = obstack_alloc (&cu->comp_unit_obstack,
9693 sizeof (struct partial_die_info));
9695 /* For some DIEs we want to follow their children (if any). For C
9696 we have no reason to follow the children of structures; for other
9697 languages we have to, so that we can get at method physnames
9698 to infer fully qualified class names, for DW_AT_specification,
9699 and for C++ template arguments. For C++, we also look one level
9700 inside functions to find template arguments (if the name of the
9701 function does not already contain the template arguments).
9703 For Ada, we need to scan the children of subprograms and lexical
9704 blocks as well because Ada allows the definition of nested
9705 entities that could be interesting for the debugger, such as
9706 nested subprograms for instance. */
9707 if (last_die->has_children
9709 || last_die->tag == DW_TAG_namespace
9710 || last_die->tag == DW_TAG_module
9711 || last_die->tag == DW_TAG_enumeration_type
9712 || (cu->language == language_cplus
9713 && last_die->tag == DW_TAG_subprogram
9714 && (last_die->name == NULL
9715 || strchr (last_die->name, '<') == NULL))
9716 || (cu->language != language_c
9717 && (last_die->tag == DW_TAG_class_type
9718 || last_die->tag == DW_TAG_interface_type
9719 || last_die->tag == DW_TAG_structure_type
9720 || last_die->tag == DW_TAG_union_type))
9721 || (cu->language == language_ada
9722 && (last_die->tag == DW_TAG_subprogram
9723 || last_die->tag == DW_TAG_lexical_block))))
9726 parent_die = last_die;
9730 /* Otherwise we skip to the next sibling, if any. */
9731 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9733 /* Back to the top, do it again. */
9737 /* Read a minimal amount of information into the minimal die structure. */
9740 read_partial_die (struct partial_die_info *part_die,
9741 struct abbrev_info *abbrev,
9742 unsigned int abbrev_len, bfd *abfd,
9743 gdb_byte *buffer, gdb_byte *info_ptr,
9744 struct dwarf2_cu *cu)
9746 struct objfile *objfile = cu->objfile;
9748 struct attribute attr;
9749 int has_low_pc_attr = 0;
9750 int has_high_pc_attr = 0;
9752 memset (part_die, 0, sizeof (struct partial_die_info));
9754 part_die->offset = info_ptr - buffer;
9756 info_ptr += abbrev_len;
9761 part_die->tag = abbrev->tag;
9762 part_die->has_children = abbrev->has_children;
9764 for (i = 0; i < abbrev->num_attrs; ++i)
9766 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9768 /* Store the data if it is of an attribute we want to keep in a
9769 partial symbol table. */
9773 switch (part_die->tag)
9775 case DW_TAG_compile_unit:
9776 case DW_TAG_type_unit:
9777 /* Compilation units have a DW_AT_name that is a filename, not
9778 a source language identifier. */
9779 case DW_TAG_enumeration_type:
9780 case DW_TAG_enumerator:
9781 /* These tags always have simple identifiers already; no need
9782 to canonicalize them. */
9783 part_die->name = DW_STRING (&attr);
9787 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9788 &objfile->objfile_obstack);
9792 case DW_AT_linkage_name:
9793 case DW_AT_MIPS_linkage_name:
9794 /* Note that both forms of linkage name might appear. We
9795 assume they will be the same, and we only store the last
9797 if (cu->language == language_ada)
9798 part_die->name = DW_STRING (&attr);
9799 part_die->linkage_name = DW_STRING (&attr);
9802 has_low_pc_attr = 1;
9803 part_die->lowpc = DW_ADDR (&attr);
9806 has_high_pc_attr = 1;
9807 part_die->highpc = DW_ADDR (&attr);
9809 case DW_AT_location:
9810 /* Support the .debug_loc offsets. */
9811 if (attr_form_is_block (&attr))
9813 part_die->locdesc = DW_BLOCK (&attr);
9815 else if (attr_form_is_section_offset (&attr))
9817 dwarf2_complex_location_expr_complaint ();
9821 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9822 "partial symbol information");
9825 case DW_AT_external:
9826 part_die->is_external = DW_UNSND (&attr);
9828 case DW_AT_declaration:
9829 part_die->is_declaration = DW_UNSND (&attr);
9832 part_die->has_type = 1;
9834 case DW_AT_abstract_origin:
9835 case DW_AT_specification:
9836 case DW_AT_extension:
9837 part_die->has_specification = 1;
9838 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9841 /* Ignore absolute siblings, they might point outside of
9842 the current compile unit. */
9843 if (attr.form == DW_FORM_ref_addr)
9844 complaint (&symfile_complaints,
9845 _("ignoring absolute DW_AT_sibling"));
9847 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9849 case DW_AT_byte_size:
9850 part_die->has_byte_size = 1;
9852 case DW_AT_calling_convention:
9853 /* DWARF doesn't provide a way to identify a program's source-level
9854 entry point. DW_AT_calling_convention attributes are only meant
9855 to describe functions' calling conventions.
9857 However, because it's a necessary piece of information in
9858 Fortran, and because DW_CC_program is the only piece of debugging
9859 information whose definition refers to a 'main program' at all,
9860 several compilers have begun marking Fortran main programs with
9861 DW_CC_program --- even when those functions use the standard
9862 calling conventions.
9864 So until DWARF specifies a way to provide this information and
9865 compilers pick up the new representation, we'll support this
9867 if (DW_UNSND (&attr) == DW_CC_program
9868 && cu->language == language_fortran)
9870 set_main_name (part_die->name);
9872 /* As this DIE has a static linkage the name would be difficult
9873 to look up later. */
9874 language_of_main = language_fortran;
9882 if (has_low_pc_attr && has_high_pc_attr)
9884 /* When using the GNU linker, .gnu.linkonce. sections are used to
9885 eliminate duplicate copies of functions and vtables and such.
9886 The linker will arbitrarily choose one and discard the others.
9887 The AT_*_pc values for such functions refer to local labels in
9888 these sections. If the section from that file was discarded, the
9889 labels are not in the output, so the relocs get a value of 0.
9890 If this is a discarded function, mark the pc bounds as invalid,
9891 so that GDB will ignore it. */
9892 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9894 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9896 complaint (&symfile_complaints,
9897 _("DW_AT_low_pc %s is zero "
9898 "for DIE at 0x%x [in module %s]"),
9899 paddress (gdbarch, part_die->lowpc),
9900 part_die->offset, objfile->name);
9902 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9903 else if (part_die->lowpc >= part_die->highpc)
9905 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9907 complaint (&symfile_complaints,
9908 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9909 "for DIE at 0x%x [in module %s]"),
9910 paddress (gdbarch, part_die->lowpc),
9911 paddress (gdbarch, part_die->highpc),
9912 part_die->offset, objfile->name);
9915 part_die->has_pc_info = 1;
9921 /* Find a cached partial DIE at OFFSET in CU. */
9923 static struct partial_die_info *
9924 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9926 struct partial_die_info *lookup_die = NULL;
9927 struct partial_die_info part_die;
9929 part_die.offset = offset;
9930 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9935 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9936 except in the case of .debug_types DIEs which do not reference
9937 outside their CU (they do however referencing other types via
9938 DW_FORM_ref_sig8). */
9940 static struct partial_die_info *
9941 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9943 struct objfile *objfile = cu->objfile;
9944 struct dwarf2_per_cu_data *per_cu = NULL;
9945 struct partial_die_info *pd = NULL;
9947 if (cu->per_cu->debug_types_section)
9949 pd = find_partial_die_in_comp_unit (offset, cu);
9955 if (offset_in_cu_p (&cu->header, offset))
9957 pd = find_partial_die_in_comp_unit (offset, cu);
9962 per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
9964 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9965 load_partial_comp_unit (per_cu);
9967 per_cu->cu->last_used = 0;
9968 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9970 if (pd == NULL && per_cu->load_all_dies == 0)
9972 struct cleanup *back_to;
9973 struct partial_die_info comp_unit_die;
9974 struct abbrev_info *abbrev;
9975 unsigned int bytes_read;
9978 per_cu->load_all_dies = 1;
9980 /* Re-read the DIEs. */
9981 back_to = make_cleanup (null_cleanup, 0);
9982 if (per_cu->cu->dwarf2_abbrevs == NULL)
9984 dwarf2_read_abbrevs (per_cu->cu);
9985 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9987 info_ptr = (dwarf2_per_objfile->info.buffer
9988 + per_cu->cu->header.offset
9989 + per_cu->cu->header.first_die_offset);
9990 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9991 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9993 dwarf2_per_objfile->info.buffer, info_ptr,
9995 if (comp_unit_die.has_children)
9996 load_partial_dies (objfile->obfd,
9997 dwarf2_per_objfile->info.buffer, info_ptr,
9999 do_cleanups (back_to);
10001 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10007 internal_error (__FILE__, __LINE__,
10008 _("could not find partial DIE 0x%x "
10009 "in cache [from module %s]\n"),
10010 offset, bfd_get_filename (objfile->obfd));
10014 /* See if we can figure out if the class lives in a namespace. We do
10015 this by looking for a member function; its demangled name will
10016 contain namespace info, if there is any. */
10019 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
10020 struct dwarf2_cu *cu)
10022 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10023 what template types look like, because the demangler
10024 frequently doesn't give the same name as the debug info. We
10025 could fix this by only using the demangled name to get the
10026 prefix (but see comment in read_structure_type). */
10028 struct partial_die_info *real_pdi;
10029 struct partial_die_info *child_pdi;
10031 /* If this DIE (this DIE's specification, if any) has a parent, then
10032 we should not do this. We'll prepend the parent's fully qualified
10033 name when we create the partial symbol. */
10035 real_pdi = struct_pdi;
10036 while (real_pdi->has_specification)
10037 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
10039 if (real_pdi->die_parent != NULL)
10042 for (child_pdi = struct_pdi->die_child;
10044 child_pdi = child_pdi->die_sibling)
10046 if (child_pdi->tag == DW_TAG_subprogram
10047 && child_pdi->linkage_name != NULL)
10049 char *actual_class_name
10050 = language_class_name_from_physname (cu->language_defn,
10051 child_pdi->linkage_name);
10052 if (actual_class_name != NULL)
10055 = obsavestring (actual_class_name,
10056 strlen (actual_class_name),
10057 &cu->objfile->objfile_obstack);
10058 xfree (actual_class_name);
10065 /* Adjust PART_DIE before generating a symbol for it. This function
10066 may set the is_external flag or change the DIE's name. */
10069 fixup_partial_die (struct partial_die_info *part_die,
10070 struct dwarf2_cu *cu)
10072 /* Once we've fixed up a die, there's no point in doing so again.
10073 This also avoids a memory leak if we were to call
10074 guess_partial_die_structure_name multiple times. */
10075 if (part_die->fixup_called)
10078 /* If we found a reference attribute and the DIE has no name, try
10079 to find a name in the referred to DIE. */
10081 if (part_die->name == NULL && part_die->has_specification)
10083 struct partial_die_info *spec_die;
10085 spec_die = find_partial_die (part_die->spec_offset, cu);
10087 fixup_partial_die (spec_die, cu);
10089 if (spec_die->name)
10091 part_die->name = spec_die->name;
10093 /* Copy DW_AT_external attribute if it is set. */
10094 if (spec_die->is_external)
10095 part_die->is_external = spec_die->is_external;
10099 /* Set default names for some unnamed DIEs. */
10101 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
10102 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
10104 /* If there is no parent die to provide a namespace, and there are
10105 children, see if we can determine the namespace from their linkage
10107 if (cu->language == language_cplus
10108 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
10109 && part_die->die_parent == NULL
10110 && part_die->has_children
10111 && (part_die->tag == DW_TAG_class_type
10112 || part_die->tag == DW_TAG_structure_type
10113 || part_die->tag == DW_TAG_union_type))
10114 guess_partial_die_structure_name (part_die, cu);
10116 /* GCC might emit a nameless struct or union that has a linkage
10117 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10118 if (part_die->name == NULL
10119 && (part_die->tag == DW_TAG_class_type
10120 || part_die->tag == DW_TAG_interface_type
10121 || part_die->tag == DW_TAG_structure_type
10122 || part_die->tag == DW_TAG_union_type)
10123 && part_die->linkage_name != NULL)
10127 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
10132 /* Strip any leading namespaces/classes, keep only the base name.
10133 DW_AT_name for named DIEs does not contain the prefixes. */
10134 base = strrchr (demangled, ':');
10135 if (base && base > demangled && base[-1] == ':')
10140 part_die->name = obsavestring (base, strlen (base),
10141 &cu->objfile->objfile_obstack);
10146 part_die->fixup_called = 1;
10149 /* Read an attribute value described by an attribute form. */
10152 read_attribute_value (struct attribute *attr, unsigned form,
10153 bfd *abfd, gdb_byte *info_ptr,
10154 struct dwarf2_cu *cu)
10156 struct comp_unit_head *cu_header = &cu->header;
10157 unsigned int bytes_read;
10158 struct dwarf_block *blk;
10163 case DW_FORM_ref_addr:
10164 if (cu->header.version == 2)
10165 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10167 DW_ADDR (attr) = read_offset (abfd, info_ptr,
10168 &cu->header, &bytes_read);
10169 info_ptr += bytes_read;
10172 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10173 info_ptr += bytes_read;
10175 case DW_FORM_block2:
10176 blk = dwarf_alloc_block (cu);
10177 blk->size = read_2_bytes (abfd, info_ptr);
10179 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10180 info_ptr += blk->size;
10181 DW_BLOCK (attr) = blk;
10183 case DW_FORM_block4:
10184 blk = dwarf_alloc_block (cu);
10185 blk->size = read_4_bytes (abfd, info_ptr);
10187 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10188 info_ptr += blk->size;
10189 DW_BLOCK (attr) = blk;
10191 case DW_FORM_data2:
10192 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
10195 case DW_FORM_data4:
10196 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
10199 case DW_FORM_data8:
10200 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
10203 case DW_FORM_sec_offset:
10204 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
10205 info_ptr += bytes_read;
10207 case DW_FORM_string:
10208 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
10209 DW_STRING_IS_CANONICAL (attr) = 0;
10210 info_ptr += bytes_read;
10213 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
10215 DW_STRING_IS_CANONICAL (attr) = 0;
10216 info_ptr += bytes_read;
10218 case DW_FORM_exprloc:
10219 case DW_FORM_block:
10220 blk = dwarf_alloc_block (cu);
10221 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10222 info_ptr += bytes_read;
10223 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10224 info_ptr += blk->size;
10225 DW_BLOCK (attr) = blk;
10227 case DW_FORM_block1:
10228 blk = dwarf_alloc_block (cu);
10229 blk->size = read_1_byte (abfd, info_ptr);
10231 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10232 info_ptr += blk->size;
10233 DW_BLOCK (attr) = blk;
10235 case DW_FORM_data1:
10236 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10240 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10243 case DW_FORM_flag_present:
10244 DW_UNSND (attr) = 1;
10246 case DW_FORM_sdata:
10247 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
10248 info_ptr += bytes_read;
10250 case DW_FORM_udata:
10251 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10252 info_ptr += bytes_read;
10255 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
10259 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
10263 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
10267 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
10270 case DW_FORM_ref_sig8:
10271 /* Convert the signature to something we can record in DW_UNSND
10273 NOTE: This is NULL if the type wasn't found. */
10274 DW_SIGNATURED_TYPE (attr) =
10275 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
10278 case DW_FORM_ref_udata:
10279 DW_ADDR (attr) = (cu->header.offset
10280 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
10281 info_ptr += bytes_read;
10283 case DW_FORM_indirect:
10284 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10285 info_ptr += bytes_read;
10286 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
10289 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10290 dwarf_form_name (form),
10291 bfd_get_filename (abfd));
10294 /* We have seen instances where the compiler tried to emit a byte
10295 size attribute of -1 which ended up being encoded as an unsigned
10296 0xffffffff. Although 0xffffffff is technically a valid size value,
10297 an object of this size seems pretty unlikely so we can relatively
10298 safely treat these cases as if the size attribute was invalid and
10299 treat them as zero by default. */
10300 if (attr->name == DW_AT_byte_size
10301 && form == DW_FORM_data4
10302 && DW_UNSND (attr) >= 0xffffffff)
10305 (&symfile_complaints,
10306 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10307 hex_string (DW_UNSND (attr)));
10308 DW_UNSND (attr) = 0;
10314 /* Read an attribute described by an abbreviated attribute. */
10317 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10318 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10320 attr->name = abbrev->name;
10321 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10324 /* Read dwarf information from a buffer. */
10326 static unsigned int
10327 read_1_byte (bfd *abfd, gdb_byte *buf)
10329 return bfd_get_8 (abfd, buf);
10333 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10335 return bfd_get_signed_8 (abfd, buf);
10338 static unsigned int
10339 read_2_bytes (bfd *abfd, gdb_byte *buf)
10341 return bfd_get_16 (abfd, buf);
10345 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
10347 return bfd_get_signed_16 (abfd, buf);
10350 static unsigned int
10351 read_4_bytes (bfd *abfd, gdb_byte *buf)
10353 return bfd_get_32 (abfd, buf);
10357 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
10359 return bfd_get_signed_32 (abfd, buf);
10363 read_8_bytes (bfd *abfd, gdb_byte *buf)
10365 return bfd_get_64 (abfd, buf);
10369 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10370 unsigned int *bytes_read)
10372 struct comp_unit_head *cu_header = &cu->header;
10373 CORE_ADDR retval = 0;
10375 if (cu_header->signed_addr_p)
10377 switch (cu_header->addr_size)
10380 retval = bfd_get_signed_16 (abfd, buf);
10383 retval = bfd_get_signed_32 (abfd, buf);
10386 retval = bfd_get_signed_64 (abfd, buf);
10389 internal_error (__FILE__, __LINE__,
10390 _("read_address: bad switch, signed [in module %s]"),
10391 bfd_get_filename (abfd));
10396 switch (cu_header->addr_size)
10399 retval = bfd_get_16 (abfd, buf);
10402 retval = bfd_get_32 (abfd, buf);
10405 retval = bfd_get_64 (abfd, buf);
10408 internal_error (__FILE__, __LINE__,
10409 _("read_address: bad switch, "
10410 "unsigned [in module %s]"),
10411 bfd_get_filename (abfd));
10415 *bytes_read = cu_header->addr_size;
10419 /* Read the initial length from a section. The (draft) DWARF 3
10420 specification allows the initial length to take up either 4 bytes
10421 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10422 bytes describe the length and all offsets will be 8 bytes in length
10425 An older, non-standard 64-bit format is also handled by this
10426 function. The older format in question stores the initial length
10427 as an 8-byte quantity without an escape value. Lengths greater
10428 than 2^32 aren't very common which means that the initial 4 bytes
10429 is almost always zero. Since a length value of zero doesn't make
10430 sense for the 32-bit format, this initial zero can be considered to
10431 be an escape value which indicates the presence of the older 64-bit
10432 format. As written, the code can't detect (old format) lengths
10433 greater than 4GB. If it becomes necessary to handle lengths
10434 somewhat larger than 4GB, we could allow other small values (such
10435 as the non-sensical values of 1, 2, and 3) to also be used as
10436 escape values indicating the presence of the old format.
10438 The value returned via bytes_read should be used to increment the
10439 relevant pointer after calling read_initial_length().
10441 [ Note: read_initial_length() and read_offset() are based on the
10442 document entitled "DWARF Debugging Information Format", revision
10443 3, draft 8, dated November 19, 2001. This document was obtained
10446 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10448 This document is only a draft and is subject to change. (So beware.)
10450 Details regarding the older, non-standard 64-bit format were
10451 determined empirically by examining 64-bit ELF files produced by
10452 the SGI toolchain on an IRIX 6.5 machine.
10454 - Kevin, July 16, 2002
10458 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10460 LONGEST length = bfd_get_32 (abfd, buf);
10462 if (length == 0xffffffff)
10464 length = bfd_get_64 (abfd, buf + 4);
10467 else if (length == 0)
10469 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10470 length = bfd_get_64 (abfd, buf);
10481 /* Cover function for read_initial_length.
10482 Returns the length of the object at BUF, and stores the size of the
10483 initial length in *BYTES_READ and stores the size that offsets will be in
10485 If the initial length size is not equivalent to that specified in
10486 CU_HEADER then issue a complaint.
10487 This is useful when reading non-comp-unit headers. */
10490 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10491 const struct comp_unit_head *cu_header,
10492 unsigned int *bytes_read,
10493 unsigned int *offset_size)
10495 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10497 gdb_assert (cu_header->initial_length_size == 4
10498 || cu_header->initial_length_size == 8
10499 || cu_header->initial_length_size == 12);
10501 if (cu_header->initial_length_size != *bytes_read)
10502 complaint (&symfile_complaints,
10503 _("intermixed 32-bit and 64-bit DWARF sections"));
10505 *offset_size = (*bytes_read == 4) ? 4 : 8;
10509 /* Read an offset from the data stream. The size of the offset is
10510 given by cu_header->offset_size. */
10513 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10514 unsigned int *bytes_read)
10516 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10518 *bytes_read = cu_header->offset_size;
10522 /* Read an offset from the data stream. */
10525 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10527 LONGEST retval = 0;
10529 switch (offset_size)
10532 retval = bfd_get_32 (abfd, buf);
10535 retval = bfd_get_64 (abfd, buf);
10538 internal_error (__FILE__, __LINE__,
10539 _("read_offset_1: bad switch [in module %s]"),
10540 bfd_get_filename (abfd));
10547 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10549 /* If the size of a host char is 8 bits, we can return a pointer
10550 to the buffer, otherwise we have to copy the data to a buffer
10551 allocated on the temporary obstack. */
10552 gdb_assert (HOST_CHAR_BIT == 8);
10557 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10559 /* If the size of a host char is 8 bits, we can return a pointer
10560 to the string, otherwise we have to copy the string to a buffer
10561 allocated on the temporary obstack. */
10562 gdb_assert (HOST_CHAR_BIT == 8);
10565 *bytes_read_ptr = 1;
10568 *bytes_read_ptr = strlen ((char *) buf) + 1;
10569 return (char *) buf;
10573 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10575 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10576 if (dwarf2_per_objfile->str.buffer == NULL)
10577 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10578 bfd_get_filename (abfd));
10579 if (str_offset >= dwarf2_per_objfile->str.size)
10580 error (_("DW_FORM_strp pointing outside of "
10581 ".debug_str section [in module %s]"),
10582 bfd_get_filename (abfd));
10583 gdb_assert (HOST_CHAR_BIT == 8);
10584 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10586 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10590 read_indirect_string (bfd *abfd, gdb_byte *buf,
10591 const struct comp_unit_head *cu_header,
10592 unsigned int *bytes_read_ptr)
10594 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10596 return read_indirect_string_at_offset (abfd, str_offset);
10599 static unsigned long
10600 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10602 unsigned long result;
10603 unsigned int num_read;
10605 unsigned char byte;
10613 byte = bfd_get_8 (abfd, buf);
10616 result |= ((unsigned long)(byte & 127) << shift);
10617 if ((byte & 128) == 0)
10623 *bytes_read_ptr = num_read;
10628 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10631 int i, shift, num_read;
10632 unsigned char byte;
10640 byte = bfd_get_8 (abfd, buf);
10643 result |= ((long)(byte & 127) << shift);
10645 if ((byte & 128) == 0)
10650 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10651 result |= -(((long)1) << shift);
10652 *bytes_read_ptr = num_read;
10656 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10659 skip_leb128 (bfd *abfd, gdb_byte *buf)
10665 byte = bfd_get_8 (abfd, buf);
10667 if ((byte & 128) == 0)
10673 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10680 cu->language = language_c;
10682 case DW_LANG_C_plus_plus:
10683 cu->language = language_cplus;
10686 cu->language = language_d;
10688 case DW_LANG_Fortran77:
10689 case DW_LANG_Fortran90:
10690 case DW_LANG_Fortran95:
10691 cu->language = language_fortran;
10693 case DW_LANG_Mips_Assembler:
10694 cu->language = language_asm;
10697 cu->language = language_java;
10699 case DW_LANG_Ada83:
10700 case DW_LANG_Ada95:
10701 cu->language = language_ada;
10703 case DW_LANG_Modula2:
10704 cu->language = language_m2;
10706 case DW_LANG_Pascal83:
10707 cu->language = language_pascal;
10710 cu->language = language_objc;
10712 case DW_LANG_Cobol74:
10713 case DW_LANG_Cobol85:
10715 cu->language = language_minimal;
10718 cu->language_defn = language_def (cu->language);
10721 /* Return the named attribute or NULL if not there. */
10723 static struct attribute *
10724 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10729 struct attribute *spec = NULL;
10731 for (i = 0; i < die->num_attrs; ++i)
10733 if (die->attrs[i].name == name)
10734 return &die->attrs[i];
10735 if (die->attrs[i].name == DW_AT_specification
10736 || die->attrs[i].name == DW_AT_abstract_origin)
10737 spec = &die->attrs[i];
10743 die = follow_die_ref (die, spec, &cu);
10749 /* Return the named attribute or NULL if not there,
10750 but do not follow DW_AT_specification, etc.
10751 This is for use in contexts where we're reading .debug_types dies.
10752 Following DW_AT_specification, DW_AT_abstract_origin will take us
10753 back up the chain, and we want to go down. */
10755 static struct attribute *
10756 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10757 struct dwarf2_cu *cu)
10761 for (i = 0; i < die->num_attrs; ++i)
10762 if (die->attrs[i].name == name)
10763 return &die->attrs[i];
10768 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10769 and holds a non-zero value. This function should only be used for
10770 DW_FORM_flag or DW_FORM_flag_present attributes. */
10773 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10775 struct attribute *attr = dwarf2_attr (die, name, cu);
10777 return (attr && DW_UNSND (attr));
10781 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10783 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10784 which value is non-zero. However, we have to be careful with
10785 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10786 (via dwarf2_flag_true_p) follows this attribute. So we may
10787 end up accidently finding a declaration attribute that belongs
10788 to a different DIE referenced by the specification attribute,
10789 even though the given DIE does not have a declaration attribute. */
10790 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10791 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10794 /* Return the die giving the specification for DIE, if there is
10795 one. *SPEC_CU is the CU containing DIE on input, and the CU
10796 containing the return value on output. If there is no
10797 specification, but there is an abstract origin, that is
10800 static struct die_info *
10801 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10803 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10806 if (spec_attr == NULL)
10807 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10809 if (spec_attr == NULL)
10812 return follow_die_ref (die, spec_attr, spec_cu);
10815 /* Free the line_header structure *LH, and any arrays and strings it
10817 NOTE: This is also used as a "cleanup" function. */
10820 free_line_header (struct line_header *lh)
10822 if (lh->standard_opcode_lengths)
10823 xfree (lh->standard_opcode_lengths);
10825 /* Remember that all the lh->file_names[i].name pointers are
10826 pointers into debug_line_buffer, and don't need to be freed. */
10827 if (lh->file_names)
10828 xfree (lh->file_names);
10830 /* Similarly for the include directory names. */
10831 if (lh->include_dirs)
10832 xfree (lh->include_dirs);
10837 /* Add an entry to LH's include directory table. */
10840 add_include_dir (struct line_header *lh, char *include_dir)
10842 /* Grow the array if necessary. */
10843 if (lh->include_dirs_size == 0)
10845 lh->include_dirs_size = 1; /* for testing */
10846 lh->include_dirs = xmalloc (lh->include_dirs_size
10847 * sizeof (*lh->include_dirs));
10849 else if (lh->num_include_dirs >= lh->include_dirs_size)
10851 lh->include_dirs_size *= 2;
10852 lh->include_dirs = xrealloc (lh->include_dirs,
10853 (lh->include_dirs_size
10854 * sizeof (*lh->include_dirs)));
10857 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10860 /* Add an entry to LH's file name table. */
10863 add_file_name (struct line_header *lh,
10865 unsigned int dir_index,
10866 unsigned int mod_time,
10867 unsigned int length)
10869 struct file_entry *fe;
10871 /* Grow the array if necessary. */
10872 if (lh->file_names_size == 0)
10874 lh->file_names_size = 1; /* for testing */
10875 lh->file_names = xmalloc (lh->file_names_size
10876 * sizeof (*lh->file_names));
10878 else if (lh->num_file_names >= lh->file_names_size)
10880 lh->file_names_size *= 2;
10881 lh->file_names = xrealloc (lh->file_names,
10882 (lh->file_names_size
10883 * sizeof (*lh->file_names)));
10886 fe = &lh->file_names[lh->num_file_names++];
10888 fe->dir_index = dir_index;
10889 fe->mod_time = mod_time;
10890 fe->length = length;
10891 fe->included_p = 0;
10895 /* Read the statement program header starting at OFFSET in
10896 .debug_line, according to the endianness of ABFD. Return a pointer
10897 to a struct line_header, allocated using xmalloc.
10899 NOTE: the strings in the include directory and file name tables of
10900 the returned object point into debug_line_buffer, and must not be
10903 static struct line_header *
10904 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10905 struct dwarf2_cu *cu)
10907 struct cleanup *back_to;
10908 struct line_header *lh;
10909 gdb_byte *line_ptr;
10910 unsigned int bytes_read, offset_size;
10912 char *cur_dir, *cur_file;
10914 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10915 if (dwarf2_per_objfile->line.buffer == NULL)
10917 complaint (&symfile_complaints, _("missing .debug_line section"));
10921 /* Make sure that at least there's room for the total_length field.
10922 That could be 12 bytes long, but we're just going to fudge that. */
10923 if (offset + 4 >= dwarf2_per_objfile->line.size)
10925 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10929 lh = xmalloc (sizeof (*lh));
10930 memset (lh, 0, sizeof (*lh));
10931 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10934 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10936 /* Read in the header. */
10938 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10939 &bytes_read, &offset_size);
10940 line_ptr += bytes_read;
10941 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10942 + dwarf2_per_objfile->line.size))
10944 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10947 lh->statement_program_end = line_ptr + lh->total_length;
10948 lh->version = read_2_bytes (abfd, line_ptr);
10950 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10951 line_ptr += offset_size;
10952 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10954 if (lh->version >= 4)
10956 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10960 lh->maximum_ops_per_instruction = 1;
10962 if (lh->maximum_ops_per_instruction == 0)
10964 lh->maximum_ops_per_instruction = 1;
10965 complaint (&symfile_complaints,
10966 _("invalid maximum_ops_per_instruction "
10967 "in `.debug_line' section"));
10970 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10972 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10974 lh->line_range = read_1_byte (abfd, line_ptr);
10976 lh->opcode_base = read_1_byte (abfd, line_ptr);
10978 lh->standard_opcode_lengths
10979 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10981 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10982 for (i = 1; i < lh->opcode_base; ++i)
10984 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10988 /* Read directory table. */
10989 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10991 line_ptr += bytes_read;
10992 add_include_dir (lh, cur_dir);
10994 line_ptr += bytes_read;
10996 /* Read file name table. */
10997 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10999 unsigned int dir_index, mod_time, length;
11001 line_ptr += bytes_read;
11002 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11003 line_ptr += bytes_read;
11004 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11005 line_ptr += bytes_read;
11006 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11007 line_ptr += bytes_read;
11009 add_file_name (lh, cur_file, dir_index, mod_time, length);
11011 line_ptr += bytes_read;
11012 lh->statement_program_start = line_ptr;
11014 if (line_ptr > (dwarf2_per_objfile->line.buffer
11015 + dwarf2_per_objfile->line.size))
11016 complaint (&symfile_complaints,
11017 _("line number info header doesn't "
11018 "fit in `.debug_line' section"));
11020 discard_cleanups (back_to);
11024 /* Subroutine of dwarf_decode_lines to simplify it.
11025 Return the file name of the psymtab for included file FILE_INDEX
11026 in line header LH of PST.
11027 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11028 If space for the result is malloc'd, it will be freed by a cleanup.
11029 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11032 psymtab_include_file_name (const struct line_header *lh, int file_index,
11033 const struct partial_symtab *pst,
11034 const char *comp_dir)
11036 const struct file_entry fe = lh->file_names [file_index];
11037 char *include_name = fe.name;
11038 char *include_name_to_compare = include_name;
11039 char *dir_name = NULL;
11040 const char *pst_filename;
11041 char *copied_name = NULL;
11045 dir_name = lh->include_dirs[fe.dir_index - 1];
11047 if (!IS_ABSOLUTE_PATH (include_name)
11048 && (dir_name != NULL || comp_dir != NULL))
11050 /* Avoid creating a duplicate psymtab for PST.
11051 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11052 Before we do the comparison, however, we need to account
11053 for DIR_NAME and COMP_DIR.
11054 First prepend dir_name (if non-NULL). If we still don't
11055 have an absolute path prepend comp_dir (if non-NULL).
11056 However, the directory we record in the include-file's
11057 psymtab does not contain COMP_DIR (to match the
11058 corresponding symtab(s)).
11063 bash$ gcc -g ./hello.c
11064 include_name = "hello.c"
11066 DW_AT_comp_dir = comp_dir = "/tmp"
11067 DW_AT_name = "./hello.c" */
11069 if (dir_name != NULL)
11071 include_name = concat (dir_name, SLASH_STRING,
11072 include_name, (char *)NULL);
11073 include_name_to_compare = include_name;
11074 make_cleanup (xfree, include_name);
11076 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
11078 include_name_to_compare = concat (comp_dir, SLASH_STRING,
11079 include_name, (char *)NULL);
11083 pst_filename = pst->filename;
11084 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
11086 copied_name = concat (pst->dirname, SLASH_STRING,
11087 pst_filename, (char *)NULL);
11088 pst_filename = copied_name;
11091 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
11093 if (include_name_to_compare != include_name)
11094 xfree (include_name_to_compare);
11095 if (copied_name != NULL)
11096 xfree (copied_name);
11100 return include_name;
11103 /* Ignore this record_line request. */
11106 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
11111 /* Subroutine of dwarf_decode_lines to simplify it.
11112 Process the line number information in LH. */
11115 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
11116 struct dwarf2_cu *cu, struct partial_symtab *pst)
11118 gdb_byte *line_ptr, *extended_end;
11119 gdb_byte *line_end;
11120 unsigned int bytes_read, extended_len;
11121 unsigned char op_code, extended_op, adj_opcode;
11122 CORE_ADDR baseaddr;
11123 struct objfile *objfile = cu->objfile;
11124 bfd *abfd = objfile->obfd;
11125 struct gdbarch *gdbarch = get_objfile_arch (objfile);
11126 const int decode_for_pst_p = (pst != NULL);
11127 struct subfile *last_subfile = NULL;
11128 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
11131 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11133 line_ptr = lh->statement_program_start;
11134 line_end = lh->statement_program_end;
11136 /* Read the statement sequences until there's nothing left. */
11137 while (line_ptr < line_end)
11139 /* state machine registers */
11140 CORE_ADDR address = 0;
11141 unsigned int file = 1;
11142 unsigned int line = 1;
11143 unsigned int column = 0;
11144 int is_stmt = lh->default_is_stmt;
11145 int basic_block = 0;
11146 int end_sequence = 0;
11148 unsigned char op_index = 0;
11150 if (!decode_for_pst_p && lh->num_file_names >= file)
11152 /* Start a subfile for the current file of the state machine. */
11153 /* lh->include_dirs and lh->file_names are 0-based, but the
11154 directory and file name numbers in the statement program
11156 struct file_entry *fe = &lh->file_names[file - 1];
11160 dir = lh->include_dirs[fe->dir_index - 1];
11162 dwarf2_start_subfile (fe->name, dir, comp_dir);
11165 /* Decode the table. */
11166 while (!end_sequence)
11168 op_code = read_1_byte (abfd, line_ptr);
11170 if (line_ptr > line_end)
11172 dwarf2_debug_line_missing_end_sequence_complaint ();
11176 if (op_code >= lh->opcode_base)
11178 /* Special operand. */
11179 adj_opcode = op_code - lh->opcode_base;
11180 address += (((op_index + (adj_opcode / lh->line_range))
11181 / lh->maximum_ops_per_instruction)
11182 * lh->minimum_instruction_length);
11183 op_index = ((op_index + (adj_opcode / lh->line_range))
11184 % lh->maximum_ops_per_instruction);
11185 line += lh->line_base + (adj_opcode % lh->line_range);
11186 if (lh->num_file_names < file || file == 0)
11187 dwarf2_debug_line_missing_file_complaint ();
11188 /* For now we ignore lines not starting on an
11189 instruction boundary. */
11190 else if (op_index == 0)
11192 lh->file_names[file - 1].included_p = 1;
11193 if (!decode_for_pst_p && is_stmt)
11195 if (last_subfile != current_subfile)
11197 addr = gdbarch_addr_bits_remove (gdbarch, address);
11199 (*p_record_line) (last_subfile, 0, addr);
11200 last_subfile = current_subfile;
11202 /* Append row to matrix using current values. */
11203 addr = gdbarch_addr_bits_remove (gdbarch, address);
11204 (*p_record_line) (current_subfile, line, addr);
11209 else switch (op_code)
11211 case DW_LNS_extended_op:
11212 extended_len = read_unsigned_leb128 (abfd, line_ptr,
11214 line_ptr += bytes_read;
11215 extended_end = line_ptr + extended_len;
11216 extended_op = read_1_byte (abfd, line_ptr);
11218 switch (extended_op)
11220 case DW_LNE_end_sequence:
11221 p_record_line = record_line;
11224 case DW_LNE_set_address:
11225 address = read_address (abfd, line_ptr, cu, &bytes_read);
11227 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
11229 /* This line table is for a function which has been
11230 GCd by the linker. Ignore it. PR gdb/12528 */
11233 = line_ptr - dwarf2_per_objfile->line.buffer;
11235 complaint (&symfile_complaints,
11236 _(".debug_line address at offset 0x%lx is 0 "
11238 line_offset, objfile->name);
11239 p_record_line = noop_record_line;
11243 line_ptr += bytes_read;
11244 address += baseaddr;
11246 case DW_LNE_define_file:
11249 unsigned int dir_index, mod_time, length;
11251 cur_file = read_direct_string (abfd, line_ptr,
11253 line_ptr += bytes_read;
11255 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11256 line_ptr += bytes_read;
11258 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11259 line_ptr += bytes_read;
11261 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11262 line_ptr += bytes_read;
11263 add_file_name (lh, cur_file, dir_index, mod_time, length);
11266 case DW_LNE_set_discriminator:
11267 /* The discriminator is not interesting to the debugger;
11269 line_ptr = extended_end;
11272 complaint (&symfile_complaints,
11273 _("mangled .debug_line section"));
11276 /* Make sure that we parsed the extended op correctly. If e.g.
11277 we expected a different address size than the producer used,
11278 we may have read the wrong number of bytes. */
11279 if (line_ptr != extended_end)
11281 complaint (&symfile_complaints,
11282 _("mangled .debug_line section"));
11287 if (lh->num_file_names < file || file == 0)
11288 dwarf2_debug_line_missing_file_complaint ();
11291 lh->file_names[file - 1].included_p = 1;
11292 if (!decode_for_pst_p && is_stmt)
11294 if (last_subfile != current_subfile)
11296 addr = gdbarch_addr_bits_remove (gdbarch, address);
11298 (*p_record_line) (last_subfile, 0, addr);
11299 last_subfile = current_subfile;
11301 addr = gdbarch_addr_bits_remove (gdbarch, address);
11302 (*p_record_line) (current_subfile, line, addr);
11307 case DW_LNS_advance_pc:
11310 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11312 address += (((op_index + adjust)
11313 / lh->maximum_ops_per_instruction)
11314 * lh->minimum_instruction_length);
11315 op_index = ((op_index + adjust)
11316 % lh->maximum_ops_per_instruction);
11317 line_ptr += bytes_read;
11320 case DW_LNS_advance_line:
11321 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11322 line_ptr += bytes_read;
11324 case DW_LNS_set_file:
11326 /* The arrays lh->include_dirs and lh->file_names are
11327 0-based, but the directory and file name numbers in
11328 the statement program are 1-based. */
11329 struct file_entry *fe;
11332 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11333 line_ptr += bytes_read;
11334 if (lh->num_file_names < file || file == 0)
11335 dwarf2_debug_line_missing_file_complaint ();
11338 fe = &lh->file_names[file - 1];
11340 dir = lh->include_dirs[fe->dir_index - 1];
11341 if (!decode_for_pst_p)
11343 last_subfile = current_subfile;
11344 dwarf2_start_subfile (fe->name, dir, comp_dir);
11349 case DW_LNS_set_column:
11350 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11351 line_ptr += bytes_read;
11353 case DW_LNS_negate_stmt:
11354 is_stmt = (!is_stmt);
11356 case DW_LNS_set_basic_block:
11359 /* Add to the address register of the state machine the
11360 address increment value corresponding to special opcode
11361 255. I.e., this value is scaled by the minimum
11362 instruction length since special opcode 255 would have
11363 scaled the increment. */
11364 case DW_LNS_const_add_pc:
11366 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11368 address += (((op_index + adjust)
11369 / lh->maximum_ops_per_instruction)
11370 * lh->minimum_instruction_length);
11371 op_index = ((op_index + adjust)
11372 % lh->maximum_ops_per_instruction);
11375 case DW_LNS_fixed_advance_pc:
11376 address += read_2_bytes (abfd, line_ptr);
11382 /* Unknown standard opcode, ignore it. */
11385 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11387 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11388 line_ptr += bytes_read;
11393 if (lh->num_file_names < file || file == 0)
11394 dwarf2_debug_line_missing_file_complaint ();
11397 lh->file_names[file - 1].included_p = 1;
11398 if (!decode_for_pst_p)
11400 addr = gdbarch_addr_bits_remove (gdbarch, address);
11401 (*p_record_line) (current_subfile, 0, addr);
11407 /* Decode the Line Number Program (LNP) for the given line_header
11408 structure and CU. The actual information extracted and the type
11409 of structures created from the LNP depends on the value of PST.
11411 1. If PST is NULL, then this procedure uses the data from the program
11412 to create all necessary symbol tables, and their linetables.
11414 2. If PST is not NULL, this procedure reads the program to determine
11415 the list of files included by the unit represented by PST, and
11416 builds all the associated partial symbol tables.
11418 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11419 It is used for relative paths in the line table.
11420 NOTE: When processing partial symtabs (pst != NULL),
11421 comp_dir == pst->dirname.
11423 NOTE: It is important that psymtabs have the same file name (via strcmp)
11424 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11425 symtab we don't use it in the name of the psymtabs we create.
11426 E.g. expand_line_sal requires this when finding psymtabs to expand.
11427 A good testcase for this is mb-inline.exp. */
11430 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
11431 struct dwarf2_cu *cu, struct partial_symtab *pst,
11432 int want_line_info)
11434 struct objfile *objfile = cu->objfile;
11435 const int decode_for_pst_p = (pst != NULL);
11436 struct subfile *first_subfile = current_subfile;
11438 if (want_line_info)
11439 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
11441 if (decode_for_pst_p)
11445 /* Now that we're done scanning the Line Header Program, we can
11446 create the psymtab of each included file. */
11447 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11448 if (lh->file_names[file_index].included_p == 1)
11450 char *include_name =
11451 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11452 if (include_name != NULL)
11453 dwarf2_create_include_psymtab (include_name, pst, objfile);
11458 /* Make sure a symtab is created for every file, even files
11459 which contain only variables (i.e. no code with associated
11463 for (i = 0; i < lh->num_file_names; i++)
11466 struct file_entry *fe;
11468 fe = &lh->file_names[i];
11470 dir = lh->include_dirs[fe->dir_index - 1];
11471 dwarf2_start_subfile (fe->name, dir, comp_dir);
11473 /* Skip the main file; we don't need it, and it must be
11474 allocated last, so that it will show up before the
11475 non-primary symtabs in the objfile's symtab list. */
11476 if (current_subfile == first_subfile)
11479 if (current_subfile->symtab == NULL)
11480 current_subfile->symtab = allocate_symtab (current_subfile->name,
11482 fe->symtab = current_subfile->symtab;
11487 /* Start a subfile for DWARF. FILENAME is the name of the file and
11488 DIRNAME the name of the source directory which contains FILENAME
11489 or NULL if not known. COMP_DIR is the compilation directory for the
11490 linetable's compilation unit or NULL if not known.
11491 This routine tries to keep line numbers from identical absolute and
11492 relative file names in a common subfile.
11494 Using the `list' example from the GDB testsuite, which resides in
11495 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11496 of /srcdir/list0.c yields the following debugging information for list0.c:
11498 DW_AT_name: /srcdir/list0.c
11499 DW_AT_comp_dir: /compdir
11500 files.files[0].name: list0.h
11501 files.files[0].dir: /srcdir
11502 files.files[1].name: list0.c
11503 files.files[1].dir: /srcdir
11505 The line number information for list0.c has to end up in a single
11506 subfile, so that `break /srcdir/list0.c:1' works as expected.
11507 start_subfile will ensure that this happens provided that we pass the
11508 concatenation of files.files[1].dir and files.files[1].name as the
11512 dwarf2_start_subfile (char *filename, const char *dirname,
11513 const char *comp_dir)
11517 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11518 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11519 second argument to start_subfile. To be consistent, we do the
11520 same here. In order not to lose the line information directory,
11521 we concatenate it to the filename when it makes sense.
11522 Note that the Dwarf3 standard says (speaking of filenames in line
11523 information): ``The directory index is ignored for file names
11524 that represent full path names''. Thus ignoring dirname in the
11525 `else' branch below isn't an issue. */
11527 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11528 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11530 fullname = filename;
11532 start_subfile (fullname, comp_dir);
11534 if (fullname != filename)
11539 var_decode_location (struct attribute *attr, struct symbol *sym,
11540 struct dwarf2_cu *cu)
11542 struct objfile *objfile = cu->objfile;
11543 struct comp_unit_head *cu_header = &cu->header;
11545 /* NOTE drow/2003-01-30: There used to be a comment and some special
11546 code here to turn a symbol with DW_AT_external and a
11547 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11548 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11549 with some versions of binutils) where shared libraries could have
11550 relocations against symbols in their debug information - the
11551 minimal symbol would have the right address, but the debug info
11552 would not. It's no longer necessary, because we will explicitly
11553 apply relocations when we read in the debug information now. */
11555 /* A DW_AT_location attribute with no contents indicates that a
11556 variable has been optimized away. */
11557 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11559 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11563 /* Handle one degenerate form of location expression specially, to
11564 preserve GDB's previous behavior when section offsets are
11565 specified. If this is just a DW_OP_addr then mark this symbol
11568 if (attr_form_is_block (attr)
11569 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11570 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11572 unsigned int dummy;
11574 SYMBOL_VALUE_ADDRESS (sym) =
11575 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11576 SYMBOL_CLASS (sym) = LOC_STATIC;
11577 fixup_symbol_section (sym, objfile);
11578 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11579 SYMBOL_SECTION (sym));
11583 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11584 expression evaluator, and use LOC_COMPUTED only when necessary
11585 (i.e. when the value of a register or memory location is
11586 referenced, or a thread-local block, etc.). Then again, it might
11587 not be worthwhile. I'm assuming that it isn't unless performance
11588 or memory numbers show me otherwise. */
11590 dwarf2_symbol_mark_computed (attr, sym, cu);
11591 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11593 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11594 cu->has_loclist = 1;
11597 /* Given a pointer to a DWARF information entry, figure out if we need
11598 to make a symbol table entry for it, and if so, create a new entry
11599 and return a pointer to it.
11600 If TYPE is NULL, determine symbol type from the die, otherwise
11601 used the passed type.
11602 If SPACE is not NULL, use it to hold the new symbol. If it is
11603 NULL, allocate a new symbol on the objfile's obstack. */
11605 static struct symbol *
11606 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11607 struct symbol *space)
11609 struct objfile *objfile = cu->objfile;
11610 struct symbol *sym = NULL;
11612 struct attribute *attr = NULL;
11613 struct attribute *attr2 = NULL;
11614 CORE_ADDR baseaddr;
11615 struct pending **list_to_add = NULL;
11617 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11619 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11621 name = dwarf2_name (die, cu);
11624 const char *linkagename;
11625 int suppress_add = 0;
11630 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11631 OBJSTAT (objfile, n_syms++);
11633 /* Cache this symbol's name and the name's demangled form (if any). */
11634 SYMBOL_SET_LANGUAGE (sym, cu->language);
11635 linkagename = dwarf2_physname (name, die, cu);
11636 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11638 /* Fortran does not have mangling standard and the mangling does differ
11639 between gfortran, iFort etc. */
11640 if (cu->language == language_fortran
11641 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11642 symbol_set_demangled_name (&(sym->ginfo),
11643 (char *) dwarf2_full_name (name, die, cu),
11646 /* Default assumptions.
11647 Use the passed type or decode it from the die. */
11648 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11649 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11651 SYMBOL_TYPE (sym) = type;
11653 SYMBOL_TYPE (sym) = die_type (die, cu);
11654 attr = dwarf2_attr (die,
11655 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11659 SYMBOL_LINE (sym) = DW_UNSND (attr);
11662 attr = dwarf2_attr (die,
11663 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11667 int file_index = DW_UNSND (attr);
11669 if (cu->line_header == NULL
11670 || file_index > cu->line_header->num_file_names)
11671 complaint (&symfile_complaints,
11672 _("file index out of range"));
11673 else if (file_index > 0)
11675 struct file_entry *fe;
11677 fe = &cu->line_header->file_names[file_index - 1];
11678 SYMBOL_SYMTAB (sym) = fe->symtab;
11685 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11688 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11690 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11691 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11692 SYMBOL_CLASS (sym) = LOC_LABEL;
11693 add_symbol_to_list (sym, cu->list_in_scope);
11695 case DW_TAG_subprogram:
11696 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11698 SYMBOL_CLASS (sym) = LOC_BLOCK;
11699 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11700 if ((attr2 && (DW_UNSND (attr2) != 0))
11701 || cu->language == language_ada)
11703 /* Subprograms marked external are stored as a global symbol.
11704 Ada subprograms, whether marked external or not, are always
11705 stored as a global symbol, because we want to be able to
11706 access them globally. For instance, we want to be able
11707 to break on a nested subprogram without having to
11708 specify the context. */
11709 list_to_add = &global_symbols;
11713 list_to_add = cu->list_in_scope;
11716 case DW_TAG_inlined_subroutine:
11717 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11719 SYMBOL_CLASS (sym) = LOC_BLOCK;
11720 SYMBOL_INLINED (sym) = 1;
11721 /* Do not add the symbol to any lists. It will be found via
11722 BLOCK_FUNCTION from the blockvector. */
11724 case DW_TAG_template_value_param:
11726 /* Fall through. */
11727 case DW_TAG_constant:
11728 case DW_TAG_variable:
11729 case DW_TAG_member:
11730 /* Compilation with minimal debug info may result in
11731 variables with missing type entries. Change the
11732 misleading `void' type to something sensible. */
11733 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11735 = objfile_type (objfile)->nodebug_data_symbol;
11737 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11738 /* In the case of DW_TAG_member, we should only be called for
11739 static const members. */
11740 if (die->tag == DW_TAG_member)
11742 /* dwarf2_add_field uses die_is_declaration,
11743 so we do the same. */
11744 gdb_assert (die_is_declaration (die, cu));
11749 dwarf2_const_value (attr, sym, cu);
11750 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11753 if (attr2 && (DW_UNSND (attr2) != 0))
11754 list_to_add = &global_symbols;
11756 list_to_add = cu->list_in_scope;
11760 attr = dwarf2_attr (die, DW_AT_location, cu);
11763 var_decode_location (attr, sym, cu);
11764 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11765 if (SYMBOL_CLASS (sym) == LOC_STATIC
11766 && SYMBOL_VALUE_ADDRESS (sym) == 0
11767 && !dwarf2_per_objfile->has_section_at_zero)
11769 /* When a static variable is eliminated by the linker,
11770 the corresponding debug information is not stripped
11771 out, but the variable address is set to null;
11772 do not add such variables into symbol table. */
11774 else if (attr2 && (DW_UNSND (attr2) != 0))
11776 /* Workaround gfortran PR debug/40040 - it uses
11777 DW_AT_location for variables in -fPIC libraries which may
11778 get overriden by other libraries/executable and get
11779 a different address. Resolve it by the minimal symbol
11780 which may come from inferior's executable using copy
11781 relocation. Make this workaround only for gfortran as for
11782 other compilers GDB cannot guess the minimal symbol
11783 Fortran mangling kind. */
11784 if (cu->language == language_fortran && die->parent
11785 && die->parent->tag == DW_TAG_module
11787 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11788 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11790 /* A variable with DW_AT_external is never static,
11791 but it may be block-scoped. */
11792 list_to_add = (cu->list_in_scope == &file_symbols
11793 ? &global_symbols : cu->list_in_scope);
11796 list_to_add = cu->list_in_scope;
11800 /* We do not know the address of this symbol.
11801 If it is an external symbol and we have type information
11802 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11803 The address of the variable will then be determined from
11804 the minimal symbol table whenever the variable is
11806 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11807 if (attr2 && (DW_UNSND (attr2) != 0)
11808 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11810 /* A variable with DW_AT_external is never static, but it
11811 may be block-scoped. */
11812 list_to_add = (cu->list_in_scope == &file_symbols
11813 ? &global_symbols : cu->list_in_scope);
11815 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11817 else if (!die_is_declaration (die, cu))
11819 /* Use the default LOC_OPTIMIZED_OUT class. */
11820 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11822 list_to_add = cu->list_in_scope;
11826 case DW_TAG_formal_parameter:
11827 /* If we are inside a function, mark this as an argument. If
11828 not, we might be looking at an argument to an inlined function
11829 when we do not have enough information to show inlined frames;
11830 pretend it's a local variable in that case so that the user can
11832 if (context_stack_depth > 0
11833 && context_stack[context_stack_depth - 1].name != NULL)
11834 SYMBOL_IS_ARGUMENT (sym) = 1;
11835 attr = dwarf2_attr (die, DW_AT_location, cu);
11838 var_decode_location (attr, sym, cu);
11840 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11843 dwarf2_const_value (attr, sym, cu);
11846 list_to_add = cu->list_in_scope;
11848 case DW_TAG_unspecified_parameters:
11849 /* From varargs functions; gdb doesn't seem to have any
11850 interest in this information, so just ignore it for now.
11853 case DW_TAG_template_type_param:
11855 /* Fall through. */
11856 case DW_TAG_class_type:
11857 case DW_TAG_interface_type:
11858 case DW_TAG_structure_type:
11859 case DW_TAG_union_type:
11860 case DW_TAG_set_type:
11861 case DW_TAG_enumeration_type:
11862 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11863 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11866 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11867 really ever be static objects: otherwise, if you try
11868 to, say, break of a class's method and you're in a file
11869 which doesn't mention that class, it won't work unless
11870 the check for all static symbols in lookup_symbol_aux
11871 saves you. See the OtherFileClass tests in
11872 gdb.c++/namespace.exp. */
11876 list_to_add = (cu->list_in_scope == &file_symbols
11877 && (cu->language == language_cplus
11878 || cu->language == language_java)
11879 ? &global_symbols : cu->list_in_scope);
11881 /* The semantics of C++ state that "struct foo {
11882 ... }" also defines a typedef for "foo". A Java
11883 class declaration also defines a typedef for the
11885 if (cu->language == language_cplus
11886 || cu->language == language_java
11887 || cu->language == language_ada)
11889 /* The symbol's name is already allocated along
11890 with this objfile, so we don't need to
11891 duplicate it for the type. */
11892 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11893 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11898 case DW_TAG_typedef:
11899 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11900 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11901 list_to_add = cu->list_in_scope;
11903 case DW_TAG_base_type:
11904 case DW_TAG_subrange_type:
11905 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11906 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11907 list_to_add = cu->list_in_scope;
11909 case DW_TAG_enumerator:
11910 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11913 dwarf2_const_value (attr, sym, cu);
11916 /* NOTE: carlton/2003-11-10: See comment above in the
11917 DW_TAG_class_type, etc. block. */
11919 list_to_add = (cu->list_in_scope == &file_symbols
11920 && (cu->language == language_cplus
11921 || cu->language == language_java)
11922 ? &global_symbols : cu->list_in_scope);
11925 case DW_TAG_namespace:
11926 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11927 list_to_add = &global_symbols;
11930 /* Not a tag we recognize. Hopefully we aren't processing
11931 trash data, but since we must specifically ignore things
11932 we don't recognize, there is nothing else we should do at
11934 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11935 dwarf_tag_name (die->tag));
11941 sym->hash_next = objfile->template_symbols;
11942 objfile->template_symbols = sym;
11943 list_to_add = NULL;
11946 if (list_to_add != NULL)
11947 add_symbol_to_list (sym, list_to_add);
11949 /* For the benefit of old versions of GCC, check for anonymous
11950 namespaces based on the demangled name. */
11951 if (!processing_has_namespace_info
11952 && cu->language == language_cplus)
11953 cp_scan_for_anonymous_namespaces (sym, objfile);
11958 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11960 static struct symbol *
11961 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11963 return new_symbol_full (die, type, cu, NULL);
11966 /* Given an attr with a DW_FORM_dataN value in host byte order,
11967 zero-extend it as appropriate for the symbol's type. The DWARF
11968 standard (v4) is not entirely clear about the meaning of using
11969 DW_FORM_dataN for a constant with a signed type, where the type is
11970 wider than the data. The conclusion of a discussion on the DWARF
11971 list was that this is unspecified. We choose to always zero-extend
11972 because that is the interpretation long in use by GCC. */
11975 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11976 const char *name, struct obstack *obstack,
11977 struct dwarf2_cu *cu, long *value, int bits)
11979 struct objfile *objfile = cu->objfile;
11980 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11981 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11982 LONGEST l = DW_UNSND (attr);
11984 if (bits < sizeof (*value) * 8)
11986 l &= ((LONGEST) 1 << bits) - 1;
11989 else if (bits == sizeof (*value) * 8)
11993 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11994 store_unsigned_integer (bytes, bits / 8, byte_order, l);
12001 /* Read a constant value from an attribute. Either set *VALUE, or if
12002 the value does not fit in *VALUE, set *BYTES - either already
12003 allocated on the objfile obstack, or newly allocated on OBSTACK,
12004 or, set *BATON, if we translated the constant to a location
12008 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
12009 const char *name, struct obstack *obstack,
12010 struct dwarf2_cu *cu,
12011 long *value, gdb_byte **bytes,
12012 struct dwarf2_locexpr_baton **baton)
12014 struct objfile *objfile = cu->objfile;
12015 struct comp_unit_head *cu_header = &cu->header;
12016 struct dwarf_block *blk;
12017 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
12018 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
12024 switch (attr->form)
12030 if (TYPE_LENGTH (type) != cu_header->addr_size)
12031 dwarf2_const_value_length_mismatch_complaint (name,
12032 cu_header->addr_size,
12033 TYPE_LENGTH (type));
12034 /* Symbols of this form are reasonably rare, so we just
12035 piggyback on the existing location code rather than writing
12036 a new implementation of symbol_computed_ops. */
12037 *baton = obstack_alloc (&objfile->objfile_obstack,
12038 sizeof (struct dwarf2_locexpr_baton));
12039 (*baton)->per_cu = cu->per_cu;
12040 gdb_assert ((*baton)->per_cu);
12042 (*baton)->size = 2 + cu_header->addr_size;
12043 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
12044 (*baton)->data = data;
12046 data[0] = DW_OP_addr;
12047 store_unsigned_integer (&data[1], cu_header->addr_size,
12048 byte_order, DW_ADDR (attr));
12049 data[cu_header->addr_size + 1] = DW_OP_stack_value;
12052 case DW_FORM_string:
12054 /* DW_STRING is already allocated on the objfile obstack, point
12056 *bytes = (gdb_byte *) DW_STRING (attr);
12058 case DW_FORM_block1:
12059 case DW_FORM_block2:
12060 case DW_FORM_block4:
12061 case DW_FORM_block:
12062 case DW_FORM_exprloc:
12063 blk = DW_BLOCK (attr);
12064 if (TYPE_LENGTH (type) != blk->size)
12065 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
12066 TYPE_LENGTH (type));
12067 *bytes = blk->data;
12070 /* The DW_AT_const_value attributes are supposed to carry the
12071 symbol's value "represented as it would be on the target
12072 architecture." By the time we get here, it's already been
12073 converted to host endianness, so we just need to sign- or
12074 zero-extend it as appropriate. */
12075 case DW_FORM_data1:
12076 *bytes = dwarf2_const_value_data (attr, type, name,
12077 obstack, cu, value, 8);
12079 case DW_FORM_data2:
12080 *bytes = dwarf2_const_value_data (attr, type, name,
12081 obstack, cu, value, 16);
12083 case DW_FORM_data4:
12084 *bytes = dwarf2_const_value_data (attr, type, name,
12085 obstack, cu, value, 32);
12087 case DW_FORM_data8:
12088 *bytes = dwarf2_const_value_data (attr, type, name,
12089 obstack, cu, value, 64);
12092 case DW_FORM_sdata:
12093 *value = DW_SND (attr);
12096 case DW_FORM_udata:
12097 *value = DW_UNSND (attr);
12101 complaint (&symfile_complaints,
12102 _("unsupported const value attribute form: '%s'"),
12103 dwarf_form_name (attr->form));
12110 /* Copy constant value from an attribute to a symbol. */
12113 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
12114 struct dwarf2_cu *cu)
12116 struct objfile *objfile = cu->objfile;
12117 struct comp_unit_head *cu_header = &cu->header;
12120 struct dwarf2_locexpr_baton *baton;
12122 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
12123 SYMBOL_PRINT_NAME (sym),
12124 &objfile->objfile_obstack, cu,
12125 &value, &bytes, &baton);
12129 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12130 SYMBOL_LOCATION_BATON (sym) = baton;
12131 SYMBOL_CLASS (sym) = LOC_COMPUTED;
12133 else if (bytes != NULL)
12135 SYMBOL_VALUE_BYTES (sym) = bytes;
12136 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
12140 SYMBOL_VALUE (sym) = value;
12141 SYMBOL_CLASS (sym) = LOC_CONST;
12145 /* Return the type of the die in question using its DW_AT_type attribute. */
12147 static struct type *
12148 die_type (struct die_info *die, struct dwarf2_cu *cu)
12150 struct attribute *type_attr;
12152 type_attr = dwarf2_attr (die, DW_AT_type, cu);
12155 /* A missing DW_AT_type represents a void type. */
12156 return objfile_type (cu->objfile)->builtin_void;
12159 return lookup_die_type (die, type_attr, cu);
12162 /* True iff CU's producer generates GNAT Ada auxiliary information
12163 that allows to find parallel types through that information instead
12164 of having to do expensive parallel lookups by type name. */
12167 need_gnat_info (struct dwarf2_cu *cu)
12169 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12170 of GNAT produces this auxiliary information, without any indication
12171 that it is produced. Part of enhancing the FSF version of GNAT
12172 to produce that information will be to put in place an indicator
12173 that we can use in order to determine whether the descriptive type
12174 info is available or not. One suggestion that has been made is
12175 to use a new attribute, attached to the CU die. For now, assume
12176 that the descriptive type info is not available. */
12180 /* Return the auxiliary type of the die in question using its
12181 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12182 attribute is not present. */
12184 static struct type *
12185 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
12187 struct attribute *type_attr;
12189 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
12193 return lookup_die_type (die, type_attr, cu);
12196 /* If DIE has a descriptive_type attribute, then set the TYPE's
12197 descriptive type accordingly. */
12200 set_descriptive_type (struct type *type, struct die_info *die,
12201 struct dwarf2_cu *cu)
12203 struct type *descriptive_type = die_descriptive_type (die, cu);
12205 if (descriptive_type)
12207 ALLOCATE_GNAT_AUX_TYPE (type);
12208 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
12212 /* Return the containing type of the die in question using its
12213 DW_AT_containing_type attribute. */
12215 static struct type *
12216 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12218 struct attribute *type_attr;
12220 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
12222 error (_("Dwarf Error: Problem turning containing type into gdb type "
12223 "[in module %s]"), cu->objfile->name);
12225 return lookup_die_type (die, type_attr, cu);
12228 /* Look up the type of DIE in CU using its type attribute ATTR.
12229 If there is no type substitute an error marker. */
12231 static struct type *
12232 lookup_die_type (struct die_info *die, struct attribute *attr,
12233 struct dwarf2_cu *cu)
12235 struct objfile *objfile = cu->objfile;
12236 struct type *this_type;
12238 /* First see if we have it cached. */
12240 if (is_ref_attr (attr))
12242 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12244 this_type = get_die_type_at_offset (offset, cu->per_cu);
12246 else if (attr->form == DW_FORM_ref_sig8)
12248 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12249 struct dwarf2_cu *sig_cu;
12250 unsigned int offset;
12252 /* sig_type will be NULL if the signatured type is missing from
12254 if (sig_type == NULL)
12255 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12256 "at 0x%x [in module %s]"),
12257 die->offset, objfile->name);
12259 gdb_assert (sig_type->per_cu.debug_types_section);
12260 offset = sig_type->per_cu.offset + sig_type->type_offset;
12261 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
12265 dump_die_for_error (die);
12266 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12267 dwarf_attr_name (attr->name), objfile->name);
12270 /* If not cached we need to read it in. */
12272 if (this_type == NULL)
12274 struct die_info *type_die;
12275 struct dwarf2_cu *type_cu = cu;
12277 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
12278 /* If the type is cached, we should have found it above. */
12279 gdb_assert (get_die_type (type_die, type_cu) == NULL);
12280 this_type = read_type_die_1 (type_die, type_cu);
12283 /* If we still don't have a type use an error marker. */
12285 if (this_type == NULL)
12287 char *message, *saved;
12289 /* read_type_die already issued a complaint. */
12290 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12294 saved = obstack_copy0 (&objfile->objfile_obstack,
12295 message, strlen (message));
12298 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
12304 /* Return the type in DIE, CU.
12305 Returns NULL for invalid types.
12307 This first does a lookup in the appropriate type_hash table,
12308 and only reads the die in if necessary.
12310 NOTE: This can be called when reading in partial or full symbols. */
12312 static struct type *
12313 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12315 struct type *this_type;
12317 this_type = get_die_type (die, cu);
12321 return read_type_die_1 (die, cu);
12324 /* Read the type in DIE, CU.
12325 Returns NULL for invalid types. */
12327 static struct type *
12328 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12330 struct type *this_type = NULL;
12334 case DW_TAG_class_type:
12335 case DW_TAG_interface_type:
12336 case DW_TAG_structure_type:
12337 case DW_TAG_union_type:
12338 this_type = read_structure_type (die, cu);
12340 case DW_TAG_enumeration_type:
12341 this_type = read_enumeration_type (die, cu);
12343 case DW_TAG_subprogram:
12344 case DW_TAG_subroutine_type:
12345 case DW_TAG_inlined_subroutine:
12346 this_type = read_subroutine_type (die, cu);
12348 case DW_TAG_array_type:
12349 this_type = read_array_type (die, cu);
12351 case DW_TAG_set_type:
12352 this_type = read_set_type (die, cu);
12354 case DW_TAG_pointer_type:
12355 this_type = read_tag_pointer_type (die, cu);
12357 case DW_TAG_ptr_to_member_type:
12358 this_type = read_tag_ptr_to_member_type (die, cu);
12360 case DW_TAG_reference_type:
12361 this_type = read_tag_reference_type (die, cu);
12363 case DW_TAG_const_type:
12364 this_type = read_tag_const_type (die, cu);
12366 case DW_TAG_volatile_type:
12367 this_type = read_tag_volatile_type (die, cu);
12369 case DW_TAG_string_type:
12370 this_type = read_tag_string_type (die, cu);
12372 case DW_TAG_typedef:
12373 this_type = read_typedef (die, cu);
12375 case DW_TAG_subrange_type:
12376 this_type = read_subrange_type (die, cu);
12378 case DW_TAG_base_type:
12379 this_type = read_base_type (die, cu);
12381 case DW_TAG_unspecified_type:
12382 this_type = read_unspecified_type (die, cu);
12384 case DW_TAG_namespace:
12385 this_type = read_namespace_type (die, cu);
12387 case DW_TAG_module:
12388 this_type = read_module_type (die, cu);
12391 complaint (&symfile_complaints,
12392 _("unexpected tag in read_type_die: '%s'"),
12393 dwarf_tag_name (die->tag));
12400 /* See if we can figure out if the class lives in a namespace. We do
12401 this by looking for a member function; its demangled name will
12402 contain namespace info, if there is any.
12403 Return the computed name or NULL.
12404 Space for the result is allocated on the objfile's obstack.
12405 This is the full-die version of guess_partial_die_structure_name.
12406 In this case we know DIE has no useful parent. */
12409 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12411 struct die_info *spec_die;
12412 struct dwarf2_cu *spec_cu;
12413 struct die_info *child;
12416 spec_die = die_specification (die, &spec_cu);
12417 if (spec_die != NULL)
12423 for (child = die->child;
12425 child = child->sibling)
12427 if (child->tag == DW_TAG_subprogram)
12429 struct attribute *attr;
12431 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12433 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12437 = language_class_name_from_physname (cu->language_defn,
12441 if (actual_name != NULL)
12443 char *die_name = dwarf2_name (die, cu);
12445 if (die_name != NULL
12446 && strcmp (die_name, actual_name) != 0)
12448 /* Strip off the class name from the full name.
12449 We want the prefix. */
12450 int die_name_len = strlen (die_name);
12451 int actual_name_len = strlen (actual_name);
12453 /* Test for '::' as a sanity check. */
12454 if (actual_name_len > die_name_len + 2
12455 && actual_name[actual_name_len
12456 - die_name_len - 1] == ':')
12458 obsavestring (actual_name,
12459 actual_name_len - die_name_len - 2,
12460 &cu->objfile->objfile_obstack);
12463 xfree (actual_name);
12472 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12473 prefix part in such case. See
12474 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12477 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12479 struct attribute *attr;
12482 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12483 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12486 attr = dwarf2_attr (die, DW_AT_name, cu);
12487 if (attr != NULL && DW_STRING (attr) != NULL)
12490 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12492 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12493 if (attr == NULL || DW_STRING (attr) == NULL)
12496 /* dwarf2_name had to be already called. */
12497 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12499 /* Strip the base name, keep any leading namespaces/classes. */
12500 base = strrchr (DW_STRING (attr), ':');
12501 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12504 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12505 &cu->objfile->objfile_obstack);
12508 /* Return the name of the namespace/class that DIE is defined within,
12509 or "" if we can't tell. The caller should not xfree the result.
12511 For example, if we're within the method foo() in the following
12521 then determine_prefix on foo's die will return "N::C". */
12523 static const char *
12524 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12526 struct die_info *parent, *spec_die;
12527 struct dwarf2_cu *spec_cu;
12528 struct type *parent_type;
12531 if (cu->language != language_cplus && cu->language != language_java
12532 && cu->language != language_fortran)
12535 retval = anonymous_struct_prefix (die, cu);
12539 /* We have to be careful in the presence of DW_AT_specification.
12540 For example, with GCC 3.4, given the code
12544 // Definition of N::foo.
12548 then we'll have a tree of DIEs like this:
12550 1: DW_TAG_compile_unit
12551 2: DW_TAG_namespace // N
12552 3: DW_TAG_subprogram // declaration of N::foo
12553 4: DW_TAG_subprogram // definition of N::foo
12554 DW_AT_specification // refers to die #3
12556 Thus, when processing die #4, we have to pretend that we're in
12557 the context of its DW_AT_specification, namely the contex of die
12560 spec_die = die_specification (die, &spec_cu);
12561 if (spec_die == NULL)
12562 parent = die->parent;
12565 parent = spec_die->parent;
12569 if (parent == NULL)
12571 else if (parent->building_fullname)
12574 const char *parent_name;
12576 /* It has been seen on RealView 2.2 built binaries,
12577 DW_TAG_template_type_param types actually _defined_ as
12578 children of the parent class:
12581 template class <class Enum> Class{};
12582 Class<enum E> class_e;
12584 1: DW_TAG_class_type (Class)
12585 2: DW_TAG_enumeration_type (E)
12586 3: DW_TAG_enumerator (enum1:0)
12587 3: DW_TAG_enumerator (enum2:1)
12589 2: DW_TAG_template_type_param
12590 DW_AT_type DW_FORM_ref_udata (E)
12592 Besides being broken debug info, it can put GDB into an
12593 infinite loop. Consider:
12595 When we're building the full name for Class<E>, we'll start
12596 at Class, and go look over its template type parameters,
12597 finding E. We'll then try to build the full name of E, and
12598 reach here. We're now trying to build the full name of E,
12599 and look over the parent DIE for containing scope. In the
12600 broken case, if we followed the parent DIE of E, we'd again
12601 find Class, and once again go look at its template type
12602 arguments, etc., etc. Simply don't consider such parent die
12603 as source-level parent of this die (it can't be, the language
12604 doesn't allow it), and break the loop here. */
12605 name = dwarf2_name (die, cu);
12606 parent_name = dwarf2_name (parent, cu);
12607 complaint (&symfile_complaints,
12608 _("template param type '%s' defined within parent '%s'"),
12609 name ? name : "<unknown>",
12610 parent_name ? parent_name : "<unknown>");
12614 switch (parent->tag)
12616 case DW_TAG_namespace:
12617 parent_type = read_type_die (parent, cu);
12618 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12619 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12620 Work around this problem here. */
12621 if (cu->language == language_cplus
12622 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12624 /* We give a name to even anonymous namespaces. */
12625 return TYPE_TAG_NAME (parent_type);
12626 case DW_TAG_class_type:
12627 case DW_TAG_interface_type:
12628 case DW_TAG_structure_type:
12629 case DW_TAG_union_type:
12630 case DW_TAG_module:
12631 parent_type = read_type_die (parent, cu);
12632 if (TYPE_TAG_NAME (parent_type) != NULL)
12633 return TYPE_TAG_NAME (parent_type);
12635 /* An anonymous structure is only allowed non-static data
12636 members; no typedefs, no member functions, et cetera.
12637 So it does not need a prefix. */
12639 case DW_TAG_compile_unit:
12640 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12641 if (cu->language == language_cplus
12642 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12643 && die->child != NULL
12644 && (die->tag == DW_TAG_class_type
12645 || die->tag == DW_TAG_structure_type
12646 || die->tag == DW_TAG_union_type))
12648 char *name = guess_full_die_structure_name (die, cu);
12654 return determine_prefix (parent, cu);
12658 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12659 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12660 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12661 an obconcat, otherwise allocate storage for the result. The CU argument is
12662 used to determine the language and hence, the appropriate separator. */
12664 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12667 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12668 int physname, struct dwarf2_cu *cu)
12670 const char *lead = "";
12673 if (suffix == NULL || suffix[0] == '\0'
12674 || prefix == NULL || prefix[0] == '\0')
12676 else if (cu->language == language_java)
12678 else if (cu->language == language_fortran && physname)
12680 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12681 DW_AT_MIPS_linkage_name is preferred and used instead. */
12689 if (prefix == NULL)
12691 if (suffix == NULL)
12697 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12699 strcpy (retval, lead);
12700 strcat (retval, prefix);
12701 strcat (retval, sep);
12702 strcat (retval, suffix);
12707 /* We have an obstack. */
12708 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12712 /* Return sibling of die, NULL if no sibling. */
12714 static struct die_info *
12715 sibling_die (struct die_info *die)
12717 return die->sibling;
12720 /* Get name of a die, return NULL if not found. */
12723 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12724 struct obstack *obstack)
12726 if (name && cu->language == language_cplus)
12728 char *canon_name = cp_canonicalize_string (name);
12730 if (canon_name != NULL)
12732 if (strcmp (canon_name, name) != 0)
12733 name = obsavestring (canon_name, strlen (canon_name),
12735 xfree (canon_name);
12742 /* Get name of a die, return NULL if not found. */
12745 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12747 struct attribute *attr;
12749 attr = dwarf2_attr (die, DW_AT_name, cu);
12750 if ((!attr || !DW_STRING (attr))
12751 && die->tag != DW_TAG_class_type
12752 && die->tag != DW_TAG_interface_type
12753 && die->tag != DW_TAG_structure_type
12754 && die->tag != DW_TAG_union_type)
12759 case DW_TAG_compile_unit:
12760 /* Compilation units have a DW_AT_name that is a filename, not
12761 a source language identifier. */
12762 case DW_TAG_enumeration_type:
12763 case DW_TAG_enumerator:
12764 /* These tags always have simple identifiers already; no need
12765 to canonicalize them. */
12766 return DW_STRING (attr);
12768 case DW_TAG_subprogram:
12769 /* Java constructors will all be named "<init>", so return
12770 the class name when we see this special case. */
12771 if (cu->language == language_java
12772 && DW_STRING (attr) != NULL
12773 && strcmp (DW_STRING (attr), "<init>") == 0)
12775 struct dwarf2_cu *spec_cu = cu;
12776 struct die_info *spec_die;
12778 /* GCJ will output '<init>' for Java constructor names.
12779 For this special case, return the name of the parent class. */
12781 /* GCJ may output suprogram DIEs with AT_specification set.
12782 If so, use the name of the specified DIE. */
12783 spec_die = die_specification (die, &spec_cu);
12784 if (spec_die != NULL)
12785 return dwarf2_name (spec_die, spec_cu);
12790 if (die->tag == DW_TAG_class_type)
12791 return dwarf2_name (die, cu);
12793 while (die->tag != DW_TAG_compile_unit);
12797 case DW_TAG_class_type:
12798 case DW_TAG_interface_type:
12799 case DW_TAG_structure_type:
12800 case DW_TAG_union_type:
12801 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12802 structures or unions. These were of the form "._%d" in GCC 4.1,
12803 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12804 and GCC 4.4. We work around this problem by ignoring these. */
12805 if (attr && DW_STRING (attr)
12806 && (strncmp (DW_STRING (attr), "._", 2) == 0
12807 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12810 /* GCC might emit a nameless typedef that has a linkage name. See
12811 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12812 if (!attr || DW_STRING (attr) == NULL)
12814 char *demangled = NULL;
12816 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12818 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12820 if (attr == NULL || DW_STRING (attr) == NULL)
12823 /* Avoid demangling DW_STRING (attr) the second time on a second
12824 call for the same DIE. */
12825 if (!DW_STRING_IS_CANONICAL (attr))
12826 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12832 /* FIXME: we already did this for the partial symbol... */
12833 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
12834 &cu->objfile->objfile_obstack);
12835 DW_STRING_IS_CANONICAL (attr) = 1;
12838 /* Strip any leading namespaces/classes, keep only the base name.
12839 DW_AT_name for named DIEs does not contain the prefixes. */
12840 base = strrchr (DW_STRING (attr), ':');
12841 if (base && base > DW_STRING (attr) && base[-1] == ':')
12844 return DW_STRING (attr);
12853 if (!DW_STRING_IS_CANONICAL (attr))
12856 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12857 &cu->objfile->objfile_obstack);
12858 DW_STRING_IS_CANONICAL (attr) = 1;
12860 return DW_STRING (attr);
12863 /* Return the die that this die in an extension of, or NULL if there
12864 is none. *EXT_CU is the CU containing DIE on input, and the CU
12865 containing the return value on output. */
12867 static struct die_info *
12868 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12870 struct attribute *attr;
12872 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12876 return follow_die_ref (die, attr, ext_cu);
12879 /* Convert a DIE tag into its string name. */
12882 dwarf_tag_name (unsigned tag)
12886 case DW_TAG_padding:
12887 return "DW_TAG_padding";
12888 case DW_TAG_array_type:
12889 return "DW_TAG_array_type";
12890 case DW_TAG_class_type:
12891 return "DW_TAG_class_type";
12892 case DW_TAG_entry_point:
12893 return "DW_TAG_entry_point";
12894 case DW_TAG_enumeration_type:
12895 return "DW_TAG_enumeration_type";
12896 case DW_TAG_formal_parameter:
12897 return "DW_TAG_formal_parameter";
12898 case DW_TAG_imported_declaration:
12899 return "DW_TAG_imported_declaration";
12901 return "DW_TAG_label";
12902 case DW_TAG_lexical_block:
12903 return "DW_TAG_lexical_block";
12904 case DW_TAG_member:
12905 return "DW_TAG_member";
12906 case DW_TAG_pointer_type:
12907 return "DW_TAG_pointer_type";
12908 case DW_TAG_reference_type:
12909 return "DW_TAG_reference_type";
12910 case DW_TAG_compile_unit:
12911 return "DW_TAG_compile_unit";
12912 case DW_TAG_string_type:
12913 return "DW_TAG_string_type";
12914 case DW_TAG_structure_type:
12915 return "DW_TAG_structure_type";
12916 case DW_TAG_subroutine_type:
12917 return "DW_TAG_subroutine_type";
12918 case DW_TAG_typedef:
12919 return "DW_TAG_typedef";
12920 case DW_TAG_union_type:
12921 return "DW_TAG_union_type";
12922 case DW_TAG_unspecified_parameters:
12923 return "DW_TAG_unspecified_parameters";
12924 case DW_TAG_variant:
12925 return "DW_TAG_variant";
12926 case DW_TAG_common_block:
12927 return "DW_TAG_common_block";
12928 case DW_TAG_common_inclusion:
12929 return "DW_TAG_common_inclusion";
12930 case DW_TAG_inheritance:
12931 return "DW_TAG_inheritance";
12932 case DW_TAG_inlined_subroutine:
12933 return "DW_TAG_inlined_subroutine";
12934 case DW_TAG_module:
12935 return "DW_TAG_module";
12936 case DW_TAG_ptr_to_member_type:
12937 return "DW_TAG_ptr_to_member_type";
12938 case DW_TAG_set_type:
12939 return "DW_TAG_set_type";
12940 case DW_TAG_subrange_type:
12941 return "DW_TAG_subrange_type";
12942 case DW_TAG_with_stmt:
12943 return "DW_TAG_with_stmt";
12944 case DW_TAG_access_declaration:
12945 return "DW_TAG_access_declaration";
12946 case DW_TAG_base_type:
12947 return "DW_TAG_base_type";
12948 case DW_TAG_catch_block:
12949 return "DW_TAG_catch_block";
12950 case DW_TAG_const_type:
12951 return "DW_TAG_const_type";
12952 case DW_TAG_constant:
12953 return "DW_TAG_constant";
12954 case DW_TAG_enumerator:
12955 return "DW_TAG_enumerator";
12956 case DW_TAG_file_type:
12957 return "DW_TAG_file_type";
12958 case DW_TAG_friend:
12959 return "DW_TAG_friend";
12960 case DW_TAG_namelist:
12961 return "DW_TAG_namelist";
12962 case DW_TAG_namelist_item:
12963 return "DW_TAG_namelist_item";
12964 case DW_TAG_packed_type:
12965 return "DW_TAG_packed_type";
12966 case DW_TAG_subprogram:
12967 return "DW_TAG_subprogram";
12968 case DW_TAG_template_type_param:
12969 return "DW_TAG_template_type_param";
12970 case DW_TAG_template_value_param:
12971 return "DW_TAG_template_value_param";
12972 case DW_TAG_thrown_type:
12973 return "DW_TAG_thrown_type";
12974 case DW_TAG_try_block:
12975 return "DW_TAG_try_block";
12976 case DW_TAG_variant_part:
12977 return "DW_TAG_variant_part";
12978 case DW_TAG_variable:
12979 return "DW_TAG_variable";
12980 case DW_TAG_volatile_type:
12981 return "DW_TAG_volatile_type";
12982 case DW_TAG_dwarf_procedure:
12983 return "DW_TAG_dwarf_procedure";
12984 case DW_TAG_restrict_type:
12985 return "DW_TAG_restrict_type";
12986 case DW_TAG_interface_type:
12987 return "DW_TAG_interface_type";
12988 case DW_TAG_namespace:
12989 return "DW_TAG_namespace";
12990 case DW_TAG_imported_module:
12991 return "DW_TAG_imported_module";
12992 case DW_TAG_unspecified_type:
12993 return "DW_TAG_unspecified_type";
12994 case DW_TAG_partial_unit:
12995 return "DW_TAG_partial_unit";
12996 case DW_TAG_imported_unit:
12997 return "DW_TAG_imported_unit";
12998 case DW_TAG_condition:
12999 return "DW_TAG_condition";
13000 case DW_TAG_shared_type:
13001 return "DW_TAG_shared_type";
13002 case DW_TAG_type_unit:
13003 return "DW_TAG_type_unit";
13004 case DW_TAG_MIPS_loop:
13005 return "DW_TAG_MIPS_loop";
13006 case DW_TAG_HP_array_descriptor:
13007 return "DW_TAG_HP_array_descriptor";
13008 case DW_TAG_format_label:
13009 return "DW_TAG_format_label";
13010 case DW_TAG_function_template:
13011 return "DW_TAG_function_template";
13012 case DW_TAG_class_template:
13013 return "DW_TAG_class_template";
13014 case DW_TAG_GNU_BINCL:
13015 return "DW_TAG_GNU_BINCL";
13016 case DW_TAG_GNU_EINCL:
13017 return "DW_TAG_GNU_EINCL";
13018 case DW_TAG_upc_shared_type:
13019 return "DW_TAG_upc_shared_type";
13020 case DW_TAG_upc_strict_type:
13021 return "DW_TAG_upc_strict_type";
13022 case DW_TAG_upc_relaxed_type:
13023 return "DW_TAG_upc_relaxed_type";
13024 case DW_TAG_PGI_kanji_type:
13025 return "DW_TAG_PGI_kanji_type";
13026 case DW_TAG_PGI_interface_block:
13027 return "DW_TAG_PGI_interface_block";
13028 case DW_TAG_GNU_call_site:
13029 return "DW_TAG_GNU_call_site";
13031 return "DW_TAG_<unknown>";
13035 /* Convert a DWARF attribute code into its string name. */
13038 dwarf_attr_name (unsigned attr)
13042 case DW_AT_sibling:
13043 return "DW_AT_sibling";
13044 case DW_AT_location:
13045 return "DW_AT_location";
13047 return "DW_AT_name";
13048 case DW_AT_ordering:
13049 return "DW_AT_ordering";
13050 case DW_AT_subscr_data:
13051 return "DW_AT_subscr_data";
13052 case DW_AT_byte_size:
13053 return "DW_AT_byte_size";
13054 case DW_AT_bit_offset:
13055 return "DW_AT_bit_offset";
13056 case DW_AT_bit_size:
13057 return "DW_AT_bit_size";
13058 case DW_AT_element_list:
13059 return "DW_AT_element_list";
13060 case DW_AT_stmt_list:
13061 return "DW_AT_stmt_list";
13063 return "DW_AT_low_pc";
13064 case DW_AT_high_pc:
13065 return "DW_AT_high_pc";
13066 case DW_AT_language:
13067 return "DW_AT_language";
13069 return "DW_AT_member";
13071 return "DW_AT_discr";
13072 case DW_AT_discr_value:
13073 return "DW_AT_discr_value";
13074 case DW_AT_visibility:
13075 return "DW_AT_visibility";
13077 return "DW_AT_import";
13078 case DW_AT_string_length:
13079 return "DW_AT_string_length";
13080 case DW_AT_common_reference:
13081 return "DW_AT_common_reference";
13082 case DW_AT_comp_dir:
13083 return "DW_AT_comp_dir";
13084 case DW_AT_const_value:
13085 return "DW_AT_const_value";
13086 case DW_AT_containing_type:
13087 return "DW_AT_containing_type";
13088 case DW_AT_default_value:
13089 return "DW_AT_default_value";
13091 return "DW_AT_inline";
13092 case DW_AT_is_optional:
13093 return "DW_AT_is_optional";
13094 case DW_AT_lower_bound:
13095 return "DW_AT_lower_bound";
13096 case DW_AT_producer:
13097 return "DW_AT_producer";
13098 case DW_AT_prototyped:
13099 return "DW_AT_prototyped";
13100 case DW_AT_return_addr:
13101 return "DW_AT_return_addr";
13102 case DW_AT_start_scope:
13103 return "DW_AT_start_scope";
13104 case DW_AT_bit_stride:
13105 return "DW_AT_bit_stride";
13106 case DW_AT_upper_bound:
13107 return "DW_AT_upper_bound";
13108 case DW_AT_abstract_origin:
13109 return "DW_AT_abstract_origin";
13110 case DW_AT_accessibility:
13111 return "DW_AT_accessibility";
13112 case DW_AT_address_class:
13113 return "DW_AT_address_class";
13114 case DW_AT_artificial:
13115 return "DW_AT_artificial";
13116 case DW_AT_base_types:
13117 return "DW_AT_base_types";
13118 case DW_AT_calling_convention:
13119 return "DW_AT_calling_convention";
13121 return "DW_AT_count";
13122 case DW_AT_data_member_location:
13123 return "DW_AT_data_member_location";
13124 case DW_AT_decl_column:
13125 return "DW_AT_decl_column";
13126 case DW_AT_decl_file:
13127 return "DW_AT_decl_file";
13128 case DW_AT_decl_line:
13129 return "DW_AT_decl_line";
13130 case DW_AT_declaration:
13131 return "DW_AT_declaration";
13132 case DW_AT_discr_list:
13133 return "DW_AT_discr_list";
13134 case DW_AT_encoding:
13135 return "DW_AT_encoding";
13136 case DW_AT_external:
13137 return "DW_AT_external";
13138 case DW_AT_frame_base:
13139 return "DW_AT_frame_base";
13141 return "DW_AT_friend";
13142 case DW_AT_identifier_case:
13143 return "DW_AT_identifier_case";
13144 case DW_AT_macro_info:
13145 return "DW_AT_macro_info";
13146 case DW_AT_namelist_items:
13147 return "DW_AT_namelist_items";
13148 case DW_AT_priority:
13149 return "DW_AT_priority";
13150 case DW_AT_segment:
13151 return "DW_AT_segment";
13152 case DW_AT_specification:
13153 return "DW_AT_specification";
13154 case DW_AT_static_link:
13155 return "DW_AT_static_link";
13157 return "DW_AT_type";
13158 case DW_AT_use_location:
13159 return "DW_AT_use_location";
13160 case DW_AT_variable_parameter:
13161 return "DW_AT_variable_parameter";
13162 case DW_AT_virtuality:
13163 return "DW_AT_virtuality";
13164 case DW_AT_vtable_elem_location:
13165 return "DW_AT_vtable_elem_location";
13166 /* DWARF 3 values. */
13167 case DW_AT_allocated:
13168 return "DW_AT_allocated";
13169 case DW_AT_associated:
13170 return "DW_AT_associated";
13171 case DW_AT_data_location:
13172 return "DW_AT_data_location";
13173 case DW_AT_byte_stride:
13174 return "DW_AT_byte_stride";
13175 case DW_AT_entry_pc:
13176 return "DW_AT_entry_pc";
13177 case DW_AT_use_UTF8:
13178 return "DW_AT_use_UTF8";
13179 case DW_AT_extension:
13180 return "DW_AT_extension";
13182 return "DW_AT_ranges";
13183 case DW_AT_trampoline:
13184 return "DW_AT_trampoline";
13185 case DW_AT_call_column:
13186 return "DW_AT_call_column";
13187 case DW_AT_call_file:
13188 return "DW_AT_call_file";
13189 case DW_AT_call_line:
13190 return "DW_AT_call_line";
13191 case DW_AT_description:
13192 return "DW_AT_description";
13193 case DW_AT_binary_scale:
13194 return "DW_AT_binary_scale";
13195 case DW_AT_decimal_scale:
13196 return "DW_AT_decimal_scale";
13198 return "DW_AT_small";
13199 case DW_AT_decimal_sign:
13200 return "DW_AT_decimal_sign";
13201 case DW_AT_digit_count:
13202 return "DW_AT_digit_count";
13203 case DW_AT_picture_string:
13204 return "DW_AT_picture_string";
13205 case DW_AT_mutable:
13206 return "DW_AT_mutable";
13207 case DW_AT_threads_scaled:
13208 return "DW_AT_threads_scaled";
13209 case DW_AT_explicit:
13210 return "DW_AT_explicit";
13211 case DW_AT_object_pointer:
13212 return "DW_AT_object_pointer";
13213 case DW_AT_endianity:
13214 return "DW_AT_endianity";
13215 case DW_AT_elemental:
13216 return "DW_AT_elemental";
13218 return "DW_AT_pure";
13219 case DW_AT_recursive:
13220 return "DW_AT_recursive";
13221 /* DWARF 4 values. */
13222 case DW_AT_signature:
13223 return "DW_AT_signature";
13224 case DW_AT_linkage_name:
13225 return "DW_AT_linkage_name";
13226 /* SGI/MIPS extensions. */
13227 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13228 case DW_AT_MIPS_fde:
13229 return "DW_AT_MIPS_fde";
13231 case DW_AT_MIPS_loop_begin:
13232 return "DW_AT_MIPS_loop_begin";
13233 case DW_AT_MIPS_tail_loop_begin:
13234 return "DW_AT_MIPS_tail_loop_begin";
13235 case DW_AT_MIPS_epilog_begin:
13236 return "DW_AT_MIPS_epilog_begin";
13237 case DW_AT_MIPS_loop_unroll_factor:
13238 return "DW_AT_MIPS_loop_unroll_factor";
13239 case DW_AT_MIPS_software_pipeline_depth:
13240 return "DW_AT_MIPS_software_pipeline_depth";
13241 case DW_AT_MIPS_linkage_name:
13242 return "DW_AT_MIPS_linkage_name";
13243 case DW_AT_MIPS_stride:
13244 return "DW_AT_MIPS_stride";
13245 case DW_AT_MIPS_abstract_name:
13246 return "DW_AT_MIPS_abstract_name";
13247 case DW_AT_MIPS_clone_origin:
13248 return "DW_AT_MIPS_clone_origin";
13249 case DW_AT_MIPS_has_inlines:
13250 return "DW_AT_MIPS_has_inlines";
13251 /* HP extensions. */
13252 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13253 case DW_AT_HP_block_index:
13254 return "DW_AT_HP_block_index";
13256 case DW_AT_HP_unmodifiable:
13257 return "DW_AT_HP_unmodifiable";
13258 case DW_AT_HP_actuals_stmt_list:
13259 return "DW_AT_HP_actuals_stmt_list";
13260 case DW_AT_HP_proc_per_section:
13261 return "DW_AT_HP_proc_per_section";
13262 case DW_AT_HP_raw_data_ptr:
13263 return "DW_AT_HP_raw_data_ptr";
13264 case DW_AT_HP_pass_by_reference:
13265 return "DW_AT_HP_pass_by_reference";
13266 case DW_AT_HP_opt_level:
13267 return "DW_AT_HP_opt_level";
13268 case DW_AT_HP_prof_version_id:
13269 return "DW_AT_HP_prof_version_id";
13270 case DW_AT_HP_opt_flags:
13271 return "DW_AT_HP_opt_flags";
13272 case DW_AT_HP_cold_region_low_pc:
13273 return "DW_AT_HP_cold_region_low_pc";
13274 case DW_AT_HP_cold_region_high_pc:
13275 return "DW_AT_HP_cold_region_high_pc";
13276 case DW_AT_HP_all_variables_modifiable:
13277 return "DW_AT_HP_all_variables_modifiable";
13278 case DW_AT_HP_linkage_name:
13279 return "DW_AT_HP_linkage_name";
13280 case DW_AT_HP_prof_flags:
13281 return "DW_AT_HP_prof_flags";
13282 /* GNU extensions. */
13283 case DW_AT_sf_names:
13284 return "DW_AT_sf_names";
13285 case DW_AT_src_info:
13286 return "DW_AT_src_info";
13287 case DW_AT_mac_info:
13288 return "DW_AT_mac_info";
13289 case DW_AT_src_coords:
13290 return "DW_AT_src_coords";
13291 case DW_AT_body_begin:
13292 return "DW_AT_body_begin";
13293 case DW_AT_body_end:
13294 return "DW_AT_body_end";
13295 case DW_AT_GNU_vector:
13296 return "DW_AT_GNU_vector";
13297 case DW_AT_GNU_odr_signature:
13298 return "DW_AT_GNU_odr_signature";
13299 /* VMS extensions. */
13300 case DW_AT_VMS_rtnbeg_pd_address:
13301 return "DW_AT_VMS_rtnbeg_pd_address";
13302 /* UPC extension. */
13303 case DW_AT_upc_threads_scaled:
13304 return "DW_AT_upc_threads_scaled";
13305 /* PGI (STMicroelectronics) extensions. */
13306 case DW_AT_PGI_lbase:
13307 return "DW_AT_PGI_lbase";
13308 case DW_AT_PGI_soffset:
13309 return "DW_AT_PGI_soffset";
13310 case DW_AT_PGI_lstride:
13311 return "DW_AT_PGI_lstride";
13313 return "DW_AT_<unknown>";
13317 /* Convert a DWARF value form code into its string name. */
13320 dwarf_form_name (unsigned form)
13325 return "DW_FORM_addr";
13326 case DW_FORM_block2:
13327 return "DW_FORM_block2";
13328 case DW_FORM_block4:
13329 return "DW_FORM_block4";
13330 case DW_FORM_data2:
13331 return "DW_FORM_data2";
13332 case DW_FORM_data4:
13333 return "DW_FORM_data4";
13334 case DW_FORM_data8:
13335 return "DW_FORM_data8";
13336 case DW_FORM_string:
13337 return "DW_FORM_string";
13338 case DW_FORM_block:
13339 return "DW_FORM_block";
13340 case DW_FORM_block1:
13341 return "DW_FORM_block1";
13342 case DW_FORM_data1:
13343 return "DW_FORM_data1";
13345 return "DW_FORM_flag";
13346 case DW_FORM_sdata:
13347 return "DW_FORM_sdata";
13349 return "DW_FORM_strp";
13350 case DW_FORM_udata:
13351 return "DW_FORM_udata";
13352 case DW_FORM_ref_addr:
13353 return "DW_FORM_ref_addr";
13355 return "DW_FORM_ref1";
13357 return "DW_FORM_ref2";
13359 return "DW_FORM_ref4";
13361 return "DW_FORM_ref8";
13362 case DW_FORM_ref_udata:
13363 return "DW_FORM_ref_udata";
13364 case DW_FORM_indirect:
13365 return "DW_FORM_indirect";
13366 case DW_FORM_sec_offset:
13367 return "DW_FORM_sec_offset";
13368 case DW_FORM_exprloc:
13369 return "DW_FORM_exprloc";
13370 case DW_FORM_flag_present:
13371 return "DW_FORM_flag_present";
13372 case DW_FORM_ref_sig8:
13373 return "DW_FORM_ref_sig8";
13375 return "DW_FORM_<unknown>";
13379 /* Convert a DWARF stack opcode into its string name. */
13382 dwarf_stack_op_name (unsigned op)
13387 return "DW_OP_addr";
13389 return "DW_OP_deref";
13390 case DW_OP_const1u:
13391 return "DW_OP_const1u";
13392 case DW_OP_const1s:
13393 return "DW_OP_const1s";
13394 case DW_OP_const2u:
13395 return "DW_OP_const2u";
13396 case DW_OP_const2s:
13397 return "DW_OP_const2s";
13398 case DW_OP_const4u:
13399 return "DW_OP_const4u";
13400 case DW_OP_const4s:
13401 return "DW_OP_const4s";
13402 case DW_OP_const8u:
13403 return "DW_OP_const8u";
13404 case DW_OP_const8s:
13405 return "DW_OP_const8s";
13407 return "DW_OP_constu";
13409 return "DW_OP_consts";
13411 return "DW_OP_dup";
13413 return "DW_OP_drop";
13415 return "DW_OP_over";
13417 return "DW_OP_pick";
13419 return "DW_OP_swap";
13421 return "DW_OP_rot";
13423 return "DW_OP_xderef";
13425 return "DW_OP_abs";
13427 return "DW_OP_and";
13429 return "DW_OP_div";
13431 return "DW_OP_minus";
13433 return "DW_OP_mod";
13435 return "DW_OP_mul";
13437 return "DW_OP_neg";
13439 return "DW_OP_not";
13443 return "DW_OP_plus";
13444 case DW_OP_plus_uconst:
13445 return "DW_OP_plus_uconst";
13447 return "DW_OP_shl";
13449 return "DW_OP_shr";
13451 return "DW_OP_shra";
13453 return "DW_OP_xor";
13455 return "DW_OP_bra";
13469 return "DW_OP_skip";
13471 return "DW_OP_lit0";
13473 return "DW_OP_lit1";
13475 return "DW_OP_lit2";
13477 return "DW_OP_lit3";
13479 return "DW_OP_lit4";
13481 return "DW_OP_lit5";
13483 return "DW_OP_lit6";
13485 return "DW_OP_lit7";
13487 return "DW_OP_lit8";
13489 return "DW_OP_lit9";
13491 return "DW_OP_lit10";
13493 return "DW_OP_lit11";
13495 return "DW_OP_lit12";
13497 return "DW_OP_lit13";
13499 return "DW_OP_lit14";
13501 return "DW_OP_lit15";
13503 return "DW_OP_lit16";
13505 return "DW_OP_lit17";
13507 return "DW_OP_lit18";
13509 return "DW_OP_lit19";
13511 return "DW_OP_lit20";
13513 return "DW_OP_lit21";
13515 return "DW_OP_lit22";
13517 return "DW_OP_lit23";
13519 return "DW_OP_lit24";
13521 return "DW_OP_lit25";
13523 return "DW_OP_lit26";
13525 return "DW_OP_lit27";
13527 return "DW_OP_lit28";
13529 return "DW_OP_lit29";
13531 return "DW_OP_lit30";
13533 return "DW_OP_lit31";
13535 return "DW_OP_reg0";
13537 return "DW_OP_reg1";
13539 return "DW_OP_reg2";
13541 return "DW_OP_reg3";
13543 return "DW_OP_reg4";
13545 return "DW_OP_reg5";
13547 return "DW_OP_reg6";
13549 return "DW_OP_reg7";
13551 return "DW_OP_reg8";
13553 return "DW_OP_reg9";
13555 return "DW_OP_reg10";
13557 return "DW_OP_reg11";
13559 return "DW_OP_reg12";
13561 return "DW_OP_reg13";
13563 return "DW_OP_reg14";
13565 return "DW_OP_reg15";
13567 return "DW_OP_reg16";
13569 return "DW_OP_reg17";
13571 return "DW_OP_reg18";
13573 return "DW_OP_reg19";
13575 return "DW_OP_reg20";
13577 return "DW_OP_reg21";
13579 return "DW_OP_reg22";
13581 return "DW_OP_reg23";
13583 return "DW_OP_reg24";
13585 return "DW_OP_reg25";
13587 return "DW_OP_reg26";
13589 return "DW_OP_reg27";
13591 return "DW_OP_reg28";
13593 return "DW_OP_reg29";
13595 return "DW_OP_reg30";
13597 return "DW_OP_reg31";
13599 return "DW_OP_breg0";
13601 return "DW_OP_breg1";
13603 return "DW_OP_breg2";
13605 return "DW_OP_breg3";
13607 return "DW_OP_breg4";
13609 return "DW_OP_breg5";
13611 return "DW_OP_breg6";
13613 return "DW_OP_breg7";
13615 return "DW_OP_breg8";
13617 return "DW_OP_breg9";
13619 return "DW_OP_breg10";
13621 return "DW_OP_breg11";
13623 return "DW_OP_breg12";
13625 return "DW_OP_breg13";
13627 return "DW_OP_breg14";
13629 return "DW_OP_breg15";
13631 return "DW_OP_breg16";
13633 return "DW_OP_breg17";
13635 return "DW_OP_breg18";
13637 return "DW_OP_breg19";
13639 return "DW_OP_breg20";
13641 return "DW_OP_breg21";
13643 return "DW_OP_breg22";
13645 return "DW_OP_breg23";
13647 return "DW_OP_breg24";
13649 return "DW_OP_breg25";
13651 return "DW_OP_breg26";
13653 return "DW_OP_breg27";
13655 return "DW_OP_breg28";
13657 return "DW_OP_breg29";
13659 return "DW_OP_breg30";
13661 return "DW_OP_breg31";
13663 return "DW_OP_regx";
13665 return "DW_OP_fbreg";
13667 return "DW_OP_bregx";
13669 return "DW_OP_piece";
13670 case DW_OP_deref_size:
13671 return "DW_OP_deref_size";
13672 case DW_OP_xderef_size:
13673 return "DW_OP_xderef_size";
13675 return "DW_OP_nop";
13676 /* DWARF 3 extensions. */
13677 case DW_OP_push_object_address:
13678 return "DW_OP_push_object_address";
13680 return "DW_OP_call2";
13682 return "DW_OP_call4";
13683 case DW_OP_call_ref:
13684 return "DW_OP_call_ref";
13685 case DW_OP_form_tls_address:
13686 return "DW_OP_form_tls_address";
13687 case DW_OP_call_frame_cfa:
13688 return "DW_OP_call_frame_cfa";
13689 case DW_OP_bit_piece:
13690 return "DW_OP_bit_piece";
13691 /* DWARF 4 extensions. */
13692 case DW_OP_implicit_value:
13693 return "DW_OP_implicit_value";
13694 case DW_OP_stack_value:
13695 return "DW_OP_stack_value";
13696 /* GNU extensions. */
13697 case DW_OP_GNU_push_tls_address:
13698 return "DW_OP_GNU_push_tls_address";
13699 case DW_OP_GNU_uninit:
13700 return "DW_OP_GNU_uninit";
13701 case DW_OP_GNU_implicit_pointer:
13702 return "DW_OP_GNU_implicit_pointer";
13703 case DW_OP_GNU_entry_value:
13704 return "DW_OP_GNU_entry_value";
13705 case DW_OP_GNU_const_type:
13706 return "DW_OP_GNU_const_type";
13707 case DW_OP_GNU_regval_type:
13708 return "DW_OP_GNU_regval_type";
13709 case DW_OP_GNU_deref_type:
13710 return "DW_OP_GNU_deref_type";
13711 case DW_OP_GNU_convert:
13712 return "DW_OP_GNU_convert";
13713 case DW_OP_GNU_reinterpret:
13714 return "DW_OP_GNU_reinterpret";
13721 dwarf_bool_name (unsigned mybool)
13729 /* Convert a DWARF type code into its string name. */
13732 dwarf_type_encoding_name (unsigned enc)
13737 return "DW_ATE_void";
13738 case DW_ATE_address:
13739 return "DW_ATE_address";
13740 case DW_ATE_boolean:
13741 return "DW_ATE_boolean";
13742 case DW_ATE_complex_float:
13743 return "DW_ATE_complex_float";
13745 return "DW_ATE_float";
13746 case DW_ATE_signed:
13747 return "DW_ATE_signed";
13748 case DW_ATE_signed_char:
13749 return "DW_ATE_signed_char";
13750 case DW_ATE_unsigned:
13751 return "DW_ATE_unsigned";
13752 case DW_ATE_unsigned_char:
13753 return "DW_ATE_unsigned_char";
13755 case DW_ATE_imaginary_float:
13756 return "DW_ATE_imaginary_float";
13757 case DW_ATE_packed_decimal:
13758 return "DW_ATE_packed_decimal";
13759 case DW_ATE_numeric_string:
13760 return "DW_ATE_numeric_string";
13761 case DW_ATE_edited:
13762 return "DW_ATE_edited";
13763 case DW_ATE_signed_fixed:
13764 return "DW_ATE_signed_fixed";
13765 case DW_ATE_unsigned_fixed:
13766 return "DW_ATE_unsigned_fixed";
13767 case DW_ATE_decimal_float:
13768 return "DW_ATE_decimal_float";
13771 return "DW_ATE_UTF";
13772 /* HP extensions. */
13773 case DW_ATE_HP_float80:
13774 return "DW_ATE_HP_float80";
13775 case DW_ATE_HP_complex_float80:
13776 return "DW_ATE_HP_complex_float80";
13777 case DW_ATE_HP_float128:
13778 return "DW_ATE_HP_float128";
13779 case DW_ATE_HP_complex_float128:
13780 return "DW_ATE_HP_complex_float128";
13781 case DW_ATE_HP_floathpintel:
13782 return "DW_ATE_HP_floathpintel";
13783 case DW_ATE_HP_imaginary_float80:
13784 return "DW_ATE_HP_imaginary_float80";
13785 case DW_ATE_HP_imaginary_float128:
13786 return "DW_ATE_HP_imaginary_float128";
13788 return "DW_ATE_<unknown>";
13792 /* Convert a DWARF call frame info operation to its string name. */
13796 dwarf_cfi_name (unsigned cfi_opc)
13800 case DW_CFA_advance_loc:
13801 return "DW_CFA_advance_loc";
13802 case DW_CFA_offset:
13803 return "DW_CFA_offset";
13804 case DW_CFA_restore:
13805 return "DW_CFA_restore";
13807 return "DW_CFA_nop";
13808 case DW_CFA_set_loc:
13809 return "DW_CFA_set_loc";
13810 case DW_CFA_advance_loc1:
13811 return "DW_CFA_advance_loc1";
13812 case DW_CFA_advance_loc2:
13813 return "DW_CFA_advance_loc2";
13814 case DW_CFA_advance_loc4:
13815 return "DW_CFA_advance_loc4";
13816 case DW_CFA_offset_extended:
13817 return "DW_CFA_offset_extended";
13818 case DW_CFA_restore_extended:
13819 return "DW_CFA_restore_extended";
13820 case DW_CFA_undefined:
13821 return "DW_CFA_undefined";
13822 case DW_CFA_same_value:
13823 return "DW_CFA_same_value";
13824 case DW_CFA_register:
13825 return "DW_CFA_register";
13826 case DW_CFA_remember_state:
13827 return "DW_CFA_remember_state";
13828 case DW_CFA_restore_state:
13829 return "DW_CFA_restore_state";
13830 case DW_CFA_def_cfa:
13831 return "DW_CFA_def_cfa";
13832 case DW_CFA_def_cfa_register:
13833 return "DW_CFA_def_cfa_register";
13834 case DW_CFA_def_cfa_offset:
13835 return "DW_CFA_def_cfa_offset";
13837 case DW_CFA_def_cfa_expression:
13838 return "DW_CFA_def_cfa_expression";
13839 case DW_CFA_expression:
13840 return "DW_CFA_expression";
13841 case DW_CFA_offset_extended_sf:
13842 return "DW_CFA_offset_extended_sf";
13843 case DW_CFA_def_cfa_sf:
13844 return "DW_CFA_def_cfa_sf";
13845 case DW_CFA_def_cfa_offset_sf:
13846 return "DW_CFA_def_cfa_offset_sf";
13847 case DW_CFA_val_offset:
13848 return "DW_CFA_val_offset";
13849 case DW_CFA_val_offset_sf:
13850 return "DW_CFA_val_offset_sf";
13851 case DW_CFA_val_expression:
13852 return "DW_CFA_val_expression";
13853 /* SGI/MIPS specific. */
13854 case DW_CFA_MIPS_advance_loc8:
13855 return "DW_CFA_MIPS_advance_loc8";
13856 /* GNU extensions. */
13857 case DW_CFA_GNU_window_save:
13858 return "DW_CFA_GNU_window_save";
13859 case DW_CFA_GNU_args_size:
13860 return "DW_CFA_GNU_args_size";
13861 case DW_CFA_GNU_negative_offset_extended:
13862 return "DW_CFA_GNU_negative_offset_extended";
13864 return "DW_CFA_<unknown>";
13870 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13874 print_spaces (indent, f);
13875 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13876 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13878 if (die->parent != NULL)
13880 print_spaces (indent, f);
13881 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13882 die->parent->offset);
13885 print_spaces (indent, f);
13886 fprintf_unfiltered (f, " has children: %s\n",
13887 dwarf_bool_name (die->child != NULL));
13889 print_spaces (indent, f);
13890 fprintf_unfiltered (f, " attributes:\n");
13892 for (i = 0; i < die->num_attrs; ++i)
13894 print_spaces (indent, f);
13895 fprintf_unfiltered (f, " %s (%s) ",
13896 dwarf_attr_name (die->attrs[i].name),
13897 dwarf_form_name (die->attrs[i].form));
13899 switch (die->attrs[i].form)
13901 case DW_FORM_ref_addr:
13903 fprintf_unfiltered (f, "address: ");
13904 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13906 case DW_FORM_block2:
13907 case DW_FORM_block4:
13908 case DW_FORM_block:
13909 case DW_FORM_block1:
13910 fprintf_unfiltered (f, "block: size %d",
13911 DW_BLOCK (&die->attrs[i])->size);
13913 case DW_FORM_exprloc:
13914 fprintf_unfiltered (f, "expression: size %u",
13915 DW_BLOCK (&die->attrs[i])->size);
13920 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13921 (long) (DW_ADDR (&die->attrs[i])));
13923 case DW_FORM_data1:
13924 case DW_FORM_data2:
13925 case DW_FORM_data4:
13926 case DW_FORM_data8:
13927 case DW_FORM_udata:
13928 case DW_FORM_sdata:
13929 fprintf_unfiltered (f, "constant: %s",
13930 pulongest (DW_UNSND (&die->attrs[i])));
13932 case DW_FORM_sec_offset:
13933 fprintf_unfiltered (f, "section offset: %s",
13934 pulongest (DW_UNSND (&die->attrs[i])));
13936 case DW_FORM_ref_sig8:
13937 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13938 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13939 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13941 fprintf_unfiltered (f, "signatured type, offset: unknown");
13943 case DW_FORM_string:
13945 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13946 DW_STRING (&die->attrs[i])
13947 ? DW_STRING (&die->attrs[i]) : "",
13948 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13951 if (DW_UNSND (&die->attrs[i]))
13952 fprintf_unfiltered (f, "flag: TRUE");
13954 fprintf_unfiltered (f, "flag: FALSE");
13956 case DW_FORM_flag_present:
13957 fprintf_unfiltered (f, "flag: TRUE");
13959 case DW_FORM_indirect:
13960 /* The reader will have reduced the indirect form to
13961 the "base form" so this form should not occur. */
13962 fprintf_unfiltered (f,
13963 "unexpected attribute form: DW_FORM_indirect");
13966 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13967 die->attrs[i].form);
13970 fprintf_unfiltered (f, "\n");
13975 dump_die_for_error (struct die_info *die)
13977 dump_die_shallow (gdb_stderr, 0, die);
13981 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13983 int indent = level * 4;
13985 gdb_assert (die != NULL);
13987 if (level >= max_level)
13990 dump_die_shallow (f, indent, die);
13992 if (die->child != NULL)
13994 print_spaces (indent, f);
13995 fprintf_unfiltered (f, " Children:");
13996 if (level + 1 < max_level)
13998 fprintf_unfiltered (f, "\n");
13999 dump_die_1 (f, level + 1, max_level, die->child);
14003 fprintf_unfiltered (f,
14004 " [not printed, max nesting level reached]\n");
14008 if (die->sibling != NULL && level > 0)
14010 dump_die_1 (f, level, max_level, die->sibling);
14014 /* This is called from the pdie macro in gdbinit.in.
14015 It's not static so gcc will keep a copy callable from gdb. */
14018 dump_die (struct die_info *die, int max_level)
14020 dump_die_1 (gdb_stdlog, 0, max_level, die);
14024 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
14028 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
14034 is_ref_attr (struct attribute *attr)
14036 switch (attr->form)
14038 case DW_FORM_ref_addr:
14043 case DW_FORM_ref_udata:
14050 static unsigned int
14051 dwarf2_get_ref_die_offset (struct attribute *attr)
14053 if (is_ref_attr (attr))
14054 return DW_ADDR (attr);
14056 complaint (&symfile_complaints,
14057 _("unsupported die ref attribute form: '%s'"),
14058 dwarf_form_name (attr->form));
14062 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14063 * the value held by the attribute is not constant. */
14066 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
14068 if (attr->form == DW_FORM_sdata)
14069 return DW_SND (attr);
14070 else if (attr->form == DW_FORM_udata
14071 || attr->form == DW_FORM_data1
14072 || attr->form == DW_FORM_data2
14073 || attr->form == DW_FORM_data4
14074 || attr->form == DW_FORM_data8)
14075 return DW_UNSND (attr);
14078 complaint (&symfile_complaints,
14079 _("Attribute value is not a constant (%s)"),
14080 dwarf_form_name (attr->form));
14081 return default_value;
14085 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14086 unit and add it to our queue.
14087 The result is non-zero if PER_CU was queued, otherwise the result is zero
14088 meaning either PER_CU is already queued or it is already loaded. */
14091 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
14092 struct dwarf2_per_cu_data *per_cu)
14094 /* We may arrive here during partial symbol reading, if we need full
14095 DIEs to process an unusual case (e.g. template arguments). Do
14096 not queue PER_CU, just tell our caller to load its DIEs. */
14097 if (dwarf2_per_objfile->reading_partial_symbols)
14099 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
14104 /* Mark the dependence relation so that we don't flush PER_CU
14106 dwarf2_add_dependence (this_cu, per_cu);
14108 /* If it's already on the queue, we have nothing to do. */
14109 if (per_cu->queued)
14112 /* If the compilation unit is already loaded, just mark it as
14114 if (per_cu->cu != NULL)
14116 per_cu->cu->last_used = 0;
14120 /* Add it to the queue. */
14121 queue_comp_unit (per_cu);
14126 /* Follow reference or signature attribute ATTR of SRC_DIE.
14127 On entry *REF_CU is the CU of SRC_DIE.
14128 On exit *REF_CU is the CU of the result. */
14130 static struct die_info *
14131 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
14132 struct dwarf2_cu **ref_cu)
14134 struct die_info *die;
14136 if (is_ref_attr (attr))
14137 die = follow_die_ref (src_die, attr, ref_cu);
14138 else if (attr->form == DW_FORM_ref_sig8)
14139 die = follow_die_sig (src_die, attr, ref_cu);
14142 dump_die_for_error (src_die);
14143 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14144 (*ref_cu)->objfile->name);
14150 /* Follow reference OFFSET.
14151 On entry *REF_CU is the CU of the source die referencing OFFSET.
14152 On exit *REF_CU is the CU of the result.
14153 Returns NULL if OFFSET is invalid. */
14155 static struct die_info *
14156 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
14158 struct die_info temp_die;
14159 struct dwarf2_cu *target_cu, *cu = *ref_cu;
14161 gdb_assert (cu->per_cu != NULL);
14165 if (cu->per_cu->debug_types_section)
14167 /* .debug_types CUs cannot reference anything outside their CU.
14168 If they need to, they have to reference a signatured type via
14169 DW_FORM_ref_sig8. */
14170 if (! offset_in_cu_p (&cu->header, offset))
14173 else if (! offset_in_cu_p (&cu->header, offset))
14175 struct dwarf2_per_cu_data *per_cu;
14177 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
14179 /* If necessary, add it to the queue and load its DIEs. */
14180 if (maybe_queue_comp_unit (cu, per_cu))
14181 load_full_comp_unit (per_cu);
14183 target_cu = per_cu->cu;
14185 else if (cu->dies == NULL)
14187 /* We're loading full DIEs during partial symbol reading. */
14188 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
14189 load_full_comp_unit (cu->per_cu);
14192 *ref_cu = target_cu;
14193 temp_die.offset = offset;
14194 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
14197 /* Follow reference attribute ATTR of SRC_DIE.
14198 On entry *REF_CU is the CU of SRC_DIE.
14199 On exit *REF_CU is the CU of the result. */
14201 static struct die_info *
14202 follow_die_ref (struct die_info *src_die, struct attribute *attr,
14203 struct dwarf2_cu **ref_cu)
14205 unsigned int offset = dwarf2_get_ref_die_offset (attr);
14206 struct dwarf2_cu *cu = *ref_cu;
14207 struct die_info *die;
14209 die = follow_die_offset (offset, ref_cu);
14211 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14212 "at 0x%x [in module %s]"),
14213 offset, src_die->offset, cu->objfile->name);
14218 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14219 Returned value is intended for DW_OP_call*. Returned
14220 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14222 struct dwarf2_locexpr_baton
14223 dwarf2_fetch_die_location_block (unsigned int offset_in_cu,
14224 struct dwarf2_per_cu_data *per_cu,
14225 CORE_ADDR (*get_frame_pc) (void *baton),
14228 unsigned int offset = per_cu->offset + offset_in_cu;
14229 struct dwarf2_cu *cu;
14230 struct die_info *die;
14231 struct attribute *attr;
14232 struct dwarf2_locexpr_baton retval;
14234 dw2_setup (per_cu->objfile);
14236 if (per_cu->cu == NULL)
14240 die = follow_die_offset (offset, &cu);
14242 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14243 offset, per_cu->objfile->name);
14245 attr = dwarf2_attr (die, DW_AT_location, cu);
14248 /* DWARF: "If there is no such attribute, then there is no effect.".
14249 DATA is ignored if SIZE is 0. */
14251 retval.data = NULL;
14254 else if (attr_form_is_section_offset (attr))
14256 struct dwarf2_loclist_baton loclist_baton;
14257 CORE_ADDR pc = (*get_frame_pc) (baton);
14260 fill_in_loclist_baton (cu, &loclist_baton, attr);
14262 retval.data = dwarf2_find_location_expression (&loclist_baton,
14264 retval.size = size;
14268 if (!attr_form_is_block (attr))
14269 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14270 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14271 offset, per_cu->objfile->name);
14273 retval.data = DW_BLOCK (attr)->data;
14274 retval.size = DW_BLOCK (attr)->size;
14276 retval.per_cu = cu->per_cu;
14278 age_cached_comp_units ();
14283 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14287 dwarf2_get_die_type (unsigned int die_offset,
14288 struct dwarf2_per_cu_data *per_cu)
14290 dw2_setup (per_cu->objfile);
14291 return get_die_type_at_offset (per_cu->offset + die_offset, per_cu);
14294 /* Follow the signature attribute ATTR in SRC_DIE.
14295 On entry *REF_CU is the CU of SRC_DIE.
14296 On exit *REF_CU is the CU of the result. */
14298 static struct die_info *
14299 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14300 struct dwarf2_cu **ref_cu)
14302 struct objfile *objfile = (*ref_cu)->objfile;
14303 struct die_info temp_die;
14304 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14305 struct dwarf2_cu *sig_cu;
14306 struct die_info *die;
14308 /* sig_type will be NULL if the signatured type is missing from
14310 if (sig_type == NULL)
14311 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14312 "at 0x%x [in module %s]"),
14313 src_die->offset, objfile->name);
14315 /* If necessary, add it to the queue and load its DIEs. */
14317 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14318 read_signatured_type (sig_type);
14320 gdb_assert (sig_type->per_cu.cu != NULL);
14322 sig_cu = sig_type->per_cu.cu;
14323 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
14324 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
14331 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14332 "from DIE at 0x%x [in module %s]"),
14333 sig_type->type_offset, src_die->offset, objfile->name);
14336 /* Given an offset of a signatured type, return its signatured_type. */
14338 static struct signatured_type *
14339 lookup_signatured_type_at_offset (struct objfile *objfile,
14340 struct dwarf2_section_info *section,
14341 unsigned int offset)
14343 gdb_byte *info_ptr = section->buffer + offset;
14344 unsigned int length, initial_length_size;
14345 unsigned int sig_offset;
14346 struct signatured_type find_entry, *type_sig;
14348 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14349 sig_offset = (initial_length_size
14351 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14352 + 1 /*address_size*/);
14353 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14354 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14356 /* This is only used to lookup previously recorded types.
14357 If we didn't find it, it's our bug. */
14358 gdb_assert (type_sig != NULL);
14359 gdb_assert (offset == type_sig->per_cu.offset);
14364 /* Load the DIEs associated with type unit PER_CU into memory. */
14367 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
14369 struct objfile *objfile = per_cu->objfile;
14370 struct dwarf2_section_info *sect = per_cu->debug_types_section;
14371 unsigned int offset = per_cu->offset;
14372 struct signatured_type *type_sig;
14374 dwarf2_read_section (objfile, sect);
14376 /* We have the section offset, but we need the signature to do the
14377 hash table lookup. */
14378 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14379 the signature to assert we found the right one.
14380 Ok, but it's a lot of work. We should simplify things so any needed
14381 assert doesn't require all this clumsiness. */
14382 type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
14384 gdb_assert (type_sig->per_cu.cu == NULL);
14386 read_signatured_type (type_sig);
14388 gdb_assert (type_sig->per_cu.cu != NULL);
14391 /* Read in a signatured type and build its CU and DIEs. */
14394 read_signatured_type (struct signatured_type *type_sig)
14396 struct objfile *objfile = type_sig->per_cu.objfile;
14397 gdb_byte *types_ptr;
14398 struct die_reader_specs reader_specs;
14399 struct dwarf2_cu *cu;
14400 ULONGEST signature;
14401 struct cleanup *back_to, *free_cu_cleanup;
14402 struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section;
14404 dwarf2_read_section (objfile, section);
14405 types_ptr = section->buffer + type_sig->per_cu.offset;
14407 gdb_assert (type_sig->per_cu.cu == NULL);
14409 cu = xmalloc (sizeof (*cu));
14410 init_one_comp_unit (cu, &type_sig->per_cu);
14412 /* If an error occurs while loading, release our storage. */
14413 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
14415 types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr,
14417 gdb_assert (signature == type_sig->signature);
14420 = htab_create_alloc_ex (cu->header.length / 12,
14424 &cu->comp_unit_obstack,
14425 hashtab_obstack_allocate,
14426 dummy_obstack_deallocate);
14428 dwarf2_read_abbrevs (cu);
14429 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14431 init_cu_die_reader (&reader_specs, cu);
14433 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14436 /* We try not to read any attributes in this function, because not
14437 all CUs needed for references have been loaded yet, and symbol
14438 table processing isn't initialized. But we have to set the CU language,
14439 or we won't be able to build types correctly. */
14440 prepare_one_comp_unit (cu, cu->dies);
14442 do_cleanups (back_to);
14444 /* We've successfully allocated this compilation unit. Let our caller
14445 clean it up when finished with it. */
14446 discard_cleanups (free_cu_cleanup);
14448 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14449 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
14452 /* Decode simple location descriptions.
14453 Given a pointer to a dwarf block that defines a location, compute
14454 the location and return the value.
14456 NOTE drow/2003-11-18: This function is called in two situations
14457 now: for the address of static or global variables (partial symbols
14458 only) and for offsets into structures which are expected to be
14459 (more or less) constant. The partial symbol case should go away,
14460 and only the constant case should remain. That will let this
14461 function complain more accurately. A few special modes are allowed
14462 without complaint for global variables (for instance, global
14463 register values and thread-local values).
14465 A location description containing no operations indicates that the
14466 object is optimized out. The return value is 0 for that case.
14467 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14468 callers will only want a very basic result and this can become a
14471 Note that stack[0] is unused except as a default error return. */
14474 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14476 struct objfile *objfile = cu->objfile;
14478 int size = blk->size;
14479 gdb_byte *data = blk->data;
14480 CORE_ADDR stack[64];
14482 unsigned int bytes_read, unsnd;
14488 stack[++stacki] = 0;
14527 stack[++stacki] = op - DW_OP_lit0;
14562 stack[++stacki] = op - DW_OP_reg0;
14564 dwarf2_complex_location_expr_complaint ();
14568 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
14570 stack[++stacki] = unsnd;
14572 dwarf2_complex_location_expr_complaint ();
14576 stack[++stacki] = read_address (objfile->obfd, &data[i],
14581 case DW_OP_const1u:
14582 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
14586 case DW_OP_const1s:
14587 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
14591 case DW_OP_const2u:
14592 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14596 case DW_OP_const2s:
14597 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14601 case DW_OP_const4u:
14602 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14606 case DW_OP_const4s:
14607 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14611 case DW_OP_const8u:
14612 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
14617 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14623 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14628 stack[stacki + 1] = stack[stacki];
14633 stack[stacki - 1] += stack[stacki];
14637 case DW_OP_plus_uconst:
14638 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14644 stack[stacki - 1] -= stack[stacki];
14649 /* If we're not the last op, then we definitely can't encode
14650 this using GDB's address_class enum. This is valid for partial
14651 global symbols, although the variable's address will be bogus
14654 dwarf2_complex_location_expr_complaint ();
14657 case DW_OP_GNU_push_tls_address:
14658 /* The top of the stack has the offset from the beginning
14659 of the thread control block at which the variable is located. */
14660 /* Nothing should follow this operator, so the top of stack would
14662 /* This is valid for partial global symbols, but the variable's
14663 address will be bogus in the psymtab. Make it always at least
14664 non-zero to not look as a variable garbage collected by linker
14665 which have DW_OP_addr 0. */
14667 dwarf2_complex_location_expr_complaint ();
14671 case DW_OP_GNU_uninit:
14676 const char *name = dwarf_stack_op_name (op);
14679 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14682 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14686 return (stack[stacki]);
14689 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14690 outside of the allocated space. Also enforce minimum>0. */
14691 if (stacki >= ARRAY_SIZE (stack) - 1)
14693 complaint (&symfile_complaints,
14694 _("location description stack overflow"));
14700 complaint (&symfile_complaints,
14701 _("location description stack underflow"));
14705 return (stack[stacki]);
14708 /* memory allocation interface */
14710 static struct dwarf_block *
14711 dwarf_alloc_block (struct dwarf2_cu *cu)
14713 struct dwarf_block *blk;
14715 blk = (struct dwarf_block *)
14716 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14720 static struct abbrev_info *
14721 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14723 struct abbrev_info *abbrev;
14725 abbrev = (struct abbrev_info *)
14726 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14727 memset (abbrev, 0, sizeof (struct abbrev_info));
14731 static struct die_info *
14732 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14734 struct die_info *die;
14735 size_t size = sizeof (struct die_info);
14738 size += (num_attrs - 1) * sizeof (struct attribute);
14740 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14741 memset (die, 0, sizeof (struct die_info));
14746 /* Macro support. */
14748 /* Return the full name of file number I in *LH's file name table.
14749 Use COMP_DIR as the name of the current directory of the
14750 compilation. The result is allocated using xmalloc; the caller is
14751 responsible for freeing it. */
14753 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14755 /* Is the file number a valid index into the line header's file name
14756 table? Remember that file numbers start with one, not zero. */
14757 if (1 <= file && file <= lh->num_file_names)
14759 struct file_entry *fe = &lh->file_names[file - 1];
14761 if (IS_ABSOLUTE_PATH (fe->name))
14762 return xstrdup (fe->name);
14770 dir = lh->include_dirs[fe->dir_index - 1];
14776 dir_len = strlen (dir);
14777 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14778 strcpy (full_name, dir);
14779 full_name[dir_len] = '/';
14780 strcpy (full_name + dir_len + 1, fe->name);
14784 return xstrdup (fe->name);
14789 /* The compiler produced a bogus file number. We can at least
14790 record the macro definitions made in the file, even if we
14791 won't be able to find the file by name. */
14792 char fake_name[80];
14794 sprintf (fake_name, "<bad macro file number %d>", file);
14796 complaint (&symfile_complaints,
14797 _("bad file number in macro information (%d)"),
14800 return xstrdup (fake_name);
14805 static struct macro_source_file *
14806 macro_start_file (int file, int line,
14807 struct macro_source_file *current_file,
14808 const char *comp_dir,
14809 struct line_header *lh, struct objfile *objfile)
14811 /* The full name of this source file. */
14812 char *full_name = file_full_name (file, lh, comp_dir);
14814 /* We don't create a macro table for this compilation unit
14815 at all until we actually get a filename. */
14816 if (! pending_macros)
14817 pending_macros = new_macro_table (&objfile->objfile_obstack,
14818 objfile->macro_cache);
14820 if (! current_file)
14821 /* If we have no current file, then this must be the start_file
14822 directive for the compilation unit's main source file. */
14823 current_file = macro_set_main (pending_macros, full_name);
14825 current_file = macro_include (current_file, line, full_name);
14829 return current_file;
14833 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14834 followed by a null byte. */
14836 copy_string (const char *buf, int len)
14838 char *s = xmalloc (len + 1);
14840 memcpy (s, buf, len);
14846 static const char *
14847 consume_improper_spaces (const char *p, const char *body)
14851 complaint (&symfile_complaints,
14852 _("macro definition contains spaces "
14853 "in formal argument list:\n`%s'"),
14865 parse_macro_definition (struct macro_source_file *file, int line,
14870 /* The body string takes one of two forms. For object-like macro
14871 definitions, it should be:
14873 <macro name> " " <definition>
14875 For function-like macro definitions, it should be:
14877 <macro name> "() " <definition>
14879 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14881 Spaces may appear only where explicitly indicated, and in the
14884 The Dwarf 2 spec says that an object-like macro's name is always
14885 followed by a space, but versions of GCC around March 2002 omit
14886 the space when the macro's definition is the empty string.
14888 The Dwarf 2 spec says that there should be no spaces between the
14889 formal arguments in a function-like macro's formal argument list,
14890 but versions of GCC around March 2002 include spaces after the
14894 /* Find the extent of the macro name. The macro name is terminated
14895 by either a space or null character (for an object-like macro) or
14896 an opening paren (for a function-like macro). */
14897 for (p = body; *p; p++)
14898 if (*p == ' ' || *p == '(')
14901 if (*p == ' ' || *p == '\0')
14903 /* It's an object-like macro. */
14904 int name_len = p - body;
14905 char *name = copy_string (body, name_len);
14906 const char *replacement;
14909 replacement = body + name_len + 1;
14912 dwarf2_macro_malformed_definition_complaint (body);
14913 replacement = body + name_len;
14916 macro_define_object (file, line, name, replacement);
14920 else if (*p == '(')
14922 /* It's a function-like macro. */
14923 char *name = copy_string (body, p - body);
14926 char **argv = xmalloc (argv_size * sizeof (*argv));
14930 p = consume_improper_spaces (p, body);
14932 /* Parse the formal argument list. */
14933 while (*p && *p != ')')
14935 /* Find the extent of the current argument name. */
14936 const char *arg_start = p;
14938 while (*p && *p != ',' && *p != ')' && *p != ' ')
14941 if (! *p || p == arg_start)
14942 dwarf2_macro_malformed_definition_complaint (body);
14945 /* Make sure argv has room for the new argument. */
14946 if (argc >= argv_size)
14949 argv = xrealloc (argv, argv_size * sizeof (*argv));
14952 argv[argc++] = copy_string (arg_start, p - arg_start);
14955 p = consume_improper_spaces (p, body);
14957 /* Consume the comma, if present. */
14962 p = consume_improper_spaces (p, body);
14971 /* Perfectly formed definition, no complaints. */
14972 macro_define_function (file, line, name,
14973 argc, (const char **) argv,
14975 else if (*p == '\0')
14977 /* Complain, but do define it. */
14978 dwarf2_macro_malformed_definition_complaint (body);
14979 macro_define_function (file, line, name,
14980 argc, (const char **) argv,
14984 /* Just complain. */
14985 dwarf2_macro_malformed_definition_complaint (body);
14988 /* Just complain. */
14989 dwarf2_macro_malformed_definition_complaint (body);
14995 for (i = 0; i < argc; i++)
15001 dwarf2_macro_malformed_definition_complaint (body);
15004 /* Skip some bytes from BYTES according to the form given in FORM.
15005 Returns the new pointer. */
15008 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
15009 enum dwarf_form form,
15010 unsigned int offset_size,
15011 struct dwarf2_section_info *section)
15013 unsigned int bytes_read;
15017 case DW_FORM_data1:
15022 case DW_FORM_data2:
15026 case DW_FORM_data4:
15030 case DW_FORM_data8:
15034 case DW_FORM_string:
15035 read_direct_string (abfd, bytes, &bytes_read);
15036 bytes += bytes_read;
15039 case DW_FORM_sec_offset:
15041 bytes += offset_size;
15044 case DW_FORM_block:
15045 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
15046 bytes += bytes_read;
15049 case DW_FORM_block1:
15050 bytes += 1 + read_1_byte (abfd, bytes);
15052 case DW_FORM_block2:
15053 bytes += 2 + read_2_bytes (abfd, bytes);
15055 case DW_FORM_block4:
15056 bytes += 4 + read_4_bytes (abfd, bytes);
15059 case DW_FORM_sdata:
15060 case DW_FORM_udata:
15061 bytes = skip_leb128 (abfd, bytes);
15067 complaint (&symfile_complaints,
15068 _("invalid form 0x%x in `%s'"),
15070 section->asection->name);
15078 /* A helper for dwarf_decode_macros that handles skipping an unknown
15079 opcode. Returns an updated pointer to the macro data buffer; or,
15080 on error, issues a complaint and returns NULL. */
15083 skip_unknown_opcode (unsigned int opcode,
15084 gdb_byte **opcode_definitions,
15087 unsigned int offset_size,
15088 struct dwarf2_section_info *section)
15090 unsigned int bytes_read, i;
15094 if (opcode_definitions[opcode] == NULL)
15096 complaint (&symfile_complaints,
15097 _("unrecognized DW_MACFINO opcode 0x%x"),
15102 defn = opcode_definitions[opcode];
15103 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
15104 defn += bytes_read;
15106 for (i = 0; i < arg; ++i)
15108 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
15109 if (mac_ptr == NULL)
15111 /* skip_form_bytes already issued the complaint. */
15119 /* A helper function which parses the header of a macro section.
15120 If the macro section is the extended (for now called "GNU") type,
15121 then this updates *OFFSET_SIZE. Returns a pointer to just after
15122 the header, or issues a complaint and returns NULL on error. */
15125 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
15128 unsigned int *offset_size,
15129 int section_is_gnu)
15131 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
15133 if (section_is_gnu)
15135 unsigned int version, flags;
15137 version = read_2_bytes (abfd, mac_ptr);
15140 complaint (&symfile_complaints,
15141 _("unrecognized version `%d' in .debug_macro section"),
15147 flags = read_1_byte (abfd, mac_ptr);
15149 *offset_size = (flags & 1) ? 8 : 4;
15151 if ((flags & 2) != 0)
15152 /* We don't need the line table offset. */
15153 mac_ptr += *offset_size;
15155 /* Vendor opcode descriptions. */
15156 if ((flags & 4) != 0)
15158 unsigned int i, count;
15160 count = read_1_byte (abfd, mac_ptr);
15162 for (i = 0; i < count; ++i)
15164 unsigned int opcode, bytes_read;
15167 opcode = read_1_byte (abfd, mac_ptr);
15169 opcode_definitions[opcode] = mac_ptr;
15170 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15171 mac_ptr += bytes_read;
15180 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15181 including DW_MACRO_GNU_transparent_include. */
15184 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
15185 struct macro_source_file *current_file,
15186 struct line_header *lh, char *comp_dir,
15187 struct dwarf2_section_info *section,
15188 int section_is_gnu,
15189 unsigned int offset_size,
15190 struct objfile *objfile,
15191 htab_t include_hash)
15193 enum dwarf_macro_record_type macinfo_type;
15194 int at_commandline;
15195 gdb_byte *opcode_definitions[256];
15197 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15198 &offset_size, section_is_gnu);
15199 if (mac_ptr == NULL)
15201 /* We already issued a complaint. */
15205 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15206 GDB is still reading the definitions from command line. First
15207 DW_MACINFO_start_file will need to be ignored as it was already executed
15208 to create CURRENT_FILE for the main source holding also the command line
15209 definitions. On first met DW_MACINFO_start_file this flag is reset to
15210 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15212 at_commandline = 1;
15216 /* Do we at least have room for a macinfo type byte? */
15217 if (mac_ptr >= mac_end)
15219 dwarf2_macros_too_long_complaint (section);
15223 macinfo_type = read_1_byte (abfd, mac_ptr);
15226 /* Note that we rely on the fact that the corresponding GNU and
15227 DWARF constants are the same. */
15228 switch (macinfo_type)
15230 /* A zero macinfo type indicates the end of the macro
15235 case DW_MACRO_GNU_define:
15236 case DW_MACRO_GNU_undef:
15237 case DW_MACRO_GNU_define_indirect:
15238 case DW_MACRO_GNU_undef_indirect:
15240 unsigned int bytes_read;
15245 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15246 mac_ptr += bytes_read;
15248 if (macinfo_type == DW_MACRO_GNU_define
15249 || macinfo_type == DW_MACRO_GNU_undef)
15251 body = read_direct_string (abfd, mac_ptr, &bytes_read);
15252 mac_ptr += bytes_read;
15256 LONGEST str_offset;
15258 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
15259 mac_ptr += offset_size;
15261 body = read_indirect_string_at_offset (abfd, str_offset);
15264 is_define = (macinfo_type == DW_MACRO_GNU_define
15265 || macinfo_type == DW_MACRO_GNU_define_indirect);
15266 if (! current_file)
15268 /* DWARF violation as no main source is present. */
15269 complaint (&symfile_complaints,
15270 _("debug info with no main source gives macro %s "
15272 is_define ? _("definition") : _("undefinition"),
15276 if ((line == 0 && !at_commandline)
15277 || (line != 0 && at_commandline))
15278 complaint (&symfile_complaints,
15279 _("debug info gives %s macro %s with %s line %d: %s"),
15280 at_commandline ? _("command-line") : _("in-file"),
15281 is_define ? _("definition") : _("undefinition"),
15282 line == 0 ? _("zero") : _("non-zero"), line, body);
15285 parse_macro_definition (current_file, line, body);
15288 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
15289 || macinfo_type == DW_MACRO_GNU_undef_indirect);
15290 macro_undef (current_file, line, body);
15295 case DW_MACRO_GNU_start_file:
15297 unsigned int bytes_read;
15300 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15301 mac_ptr += bytes_read;
15302 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15303 mac_ptr += bytes_read;
15305 if ((line == 0 && !at_commandline)
15306 || (line != 0 && at_commandline))
15307 complaint (&symfile_complaints,
15308 _("debug info gives source %d included "
15309 "from %s at %s line %d"),
15310 file, at_commandline ? _("command-line") : _("file"),
15311 line == 0 ? _("zero") : _("non-zero"), line);
15313 if (at_commandline)
15315 /* This DW_MACRO_GNU_start_file was executed in the
15317 at_commandline = 0;
15320 current_file = macro_start_file (file, line,
15321 current_file, comp_dir,
15326 case DW_MACRO_GNU_end_file:
15327 if (! current_file)
15328 complaint (&symfile_complaints,
15329 _("macro debug info has an unmatched "
15330 "`close_file' directive"));
15333 current_file = current_file->included_by;
15334 if (! current_file)
15336 enum dwarf_macro_record_type next_type;
15338 /* GCC circa March 2002 doesn't produce the zero
15339 type byte marking the end of the compilation
15340 unit. Complain if it's not there, but exit no
15343 /* Do we at least have room for a macinfo type byte? */
15344 if (mac_ptr >= mac_end)
15346 dwarf2_macros_too_long_complaint (section);
15350 /* We don't increment mac_ptr here, so this is just
15352 next_type = read_1_byte (abfd, mac_ptr);
15353 if (next_type != 0)
15354 complaint (&symfile_complaints,
15355 _("no terminating 0-type entry for "
15356 "macros in `.debug_macinfo' section"));
15363 case DW_MACRO_GNU_transparent_include:
15368 offset = read_offset_1 (abfd, mac_ptr, offset_size);
15369 mac_ptr += offset_size;
15371 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15374 /* This has actually happened; see
15375 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15376 complaint (&symfile_complaints,
15377 _("recursive DW_MACRO_GNU_transparent_include in "
15378 ".debug_macro section"));
15384 dwarf_decode_macro_bytes (abfd,
15385 section->buffer + offset,
15386 mac_end, current_file,
15388 section, section_is_gnu,
15389 offset_size, objfile, include_hash);
15391 htab_remove_elt (include_hash, mac_ptr);
15396 case DW_MACINFO_vendor_ext:
15397 if (!section_is_gnu)
15399 unsigned int bytes_read;
15402 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15403 mac_ptr += bytes_read;
15404 read_direct_string (abfd, mac_ptr, &bytes_read);
15405 mac_ptr += bytes_read;
15407 /* We don't recognize any vendor extensions. */
15413 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15414 mac_ptr, abfd, offset_size,
15416 if (mac_ptr == NULL)
15420 } while (macinfo_type != 0);
15424 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
15425 char *comp_dir, bfd *abfd,
15426 struct dwarf2_cu *cu,
15427 struct dwarf2_section_info *section,
15428 int section_is_gnu)
15430 struct objfile *objfile = dwarf2_per_objfile->objfile;
15431 gdb_byte *mac_ptr, *mac_end;
15432 struct macro_source_file *current_file = 0;
15433 enum dwarf_macro_record_type macinfo_type;
15434 unsigned int offset_size = cu->header.offset_size;
15435 gdb_byte *opcode_definitions[256];
15436 struct cleanup *cleanup;
15437 htab_t include_hash;
15440 dwarf2_read_section (objfile, section);
15441 if (section->buffer == NULL)
15443 complaint (&symfile_complaints, _("missing %s section"),
15444 section->asection->name);
15448 /* First pass: Find the name of the base filename.
15449 This filename is needed in order to process all macros whose definition
15450 (or undefinition) comes from the command line. These macros are defined
15451 before the first DW_MACINFO_start_file entry, and yet still need to be
15452 associated to the base file.
15454 To determine the base file name, we scan the macro definitions until we
15455 reach the first DW_MACINFO_start_file entry. We then initialize
15456 CURRENT_FILE accordingly so that any macro definition found before the
15457 first DW_MACINFO_start_file can still be associated to the base file. */
15459 mac_ptr = section->buffer + offset;
15460 mac_end = section->buffer + section->size;
15462 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15463 &offset_size, section_is_gnu);
15464 if (mac_ptr == NULL)
15466 /* We already issued a complaint. */
15472 /* Do we at least have room for a macinfo type byte? */
15473 if (mac_ptr >= mac_end)
15475 /* Complaint is printed during the second pass as GDB will probably
15476 stop the first pass earlier upon finding
15477 DW_MACINFO_start_file. */
15481 macinfo_type = read_1_byte (abfd, mac_ptr);
15484 /* Note that we rely on the fact that the corresponding GNU and
15485 DWARF constants are the same. */
15486 switch (macinfo_type)
15488 /* A zero macinfo type indicates the end of the macro
15493 case DW_MACRO_GNU_define:
15494 case DW_MACRO_GNU_undef:
15495 /* Only skip the data by MAC_PTR. */
15497 unsigned int bytes_read;
15499 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15500 mac_ptr += bytes_read;
15501 read_direct_string (abfd, mac_ptr, &bytes_read);
15502 mac_ptr += bytes_read;
15506 case DW_MACRO_GNU_start_file:
15508 unsigned int bytes_read;
15511 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15512 mac_ptr += bytes_read;
15513 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15514 mac_ptr += bytes_read;
15516 current_file = macro_start_file (file, line, current_file,
15517 comp_dir, lh, objfile);
15521 case DW_MACRO_GNU_end_file:
15522 /* No data to skip by MAC_PTR. */
15525 case DW_MACRO_GNU_define_indirect:
15526 case DW_MACRO_GNU_undef_indirect:
15528 unsigned int bytes_read;
15530 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15531 mac_ptr += bytes_read;
15532 mac_ptr += offset_size;
15536 case DW_MACRO_GNU_transparent_include:
15537 /* Note that, according to the spec, a transparent include
15538 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15539 skip this opcode. */
15540 mac_ptr += offset_size;
15543 case DW_MACINFO_vendor_ext:
15544 /* Only skip the data by MAC_PTR. */
15545 if (!section_is_gnu)
15547 unsigned int bytes_read;
15549 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15550 mac_ptr += bytes_read;
15551 read_direct_string (abfd, mac_ptr, &bytes_read);
15552 mac_ptr += bytes_read;
15557 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15558 mac_ptr, abfd, offset_size,
15560 if (mac_ptr == NULL)
15564 } while (macinfo_type != 0 && current_file == NULL);
15566 /* Second pass: Process all entries.
15568 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15569 command-line macro definitions/undefinitions. This flag is unset when we
15570 reach the first DW_MACINFO_start_file entry. */
15572 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
15573 NULL, xcalloc, xfree);
15574 cleanup = make_cleanup_htab_delete (include_hash);
15575 mac_ptr = section->buffer + offset;
15576 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15578 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
15579 current_file, lh, comp_dir, section, section_is_gnu,
15580 offset_size, objfile, include_hash);
15581 do_cleanups (cleanup);
15584 /* Check if the attribute's form is a DW_FORM_block*
15585 if so return true else false. */
15587 attr_form_is_block (struct attribute *attr)
15589 return (attr == NULL ? 0 :
15590 attr->form == DW_FORM_block1
15591 || attr->form == DW_FORM_block2
15592 || attr->form == DW_FORM_block4
15593 || attr->form == DW_FORM_block
15594 || attr->form == DW_FORM_exprloc);
15597 /* Return non-zero if ATTR's value is a section offset --- classes
15598 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15599 You may use DW_UNSND (attr) to retrieve such offsets.
15601 Section 7.5.4, "Attribute Encodings", explains that no attribute
15602 may have a value that belongs to more than one of these classes; it
15603 would be ambiguous if we did, because we use the same forms for all
15606 attr_form_is_section_offset (struct attribute *attr)
15608 return (attr->form == DW_FORM_data4
15609 || attr->form == DW_FORM_data8
15610 || attr->form == DW_FORM_sec_offset);
15614 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15615 zero otherwise. When this function returns true, you can apply
15616 dwarf2_get_attr_constant_value to it.
15618 However, note that for some attributes you must check
15619 attr_form_is_section_offset before using this test. DW_FORM_data4
15620 and DW_FORM_data8 are members of both the constant class, and of
15621 the classes that contain offsets into other debug sections
15622 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15623 that, if an attribute's can be either a constant or one of the
15624 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15625 taken as section offsets, not constants. */
15627 attr_form_is_constant (struct attribute *attr)
15629 switch (attr->form)
15631 case DW_FORM_sdata:
15632 case DW_FORM_udata:
15633 case DW_FORM_data1:
15634 case DW_FORM_data2:
15635 case DW_FORM_data4:
15636 case DW_FORM_data8:
15643 /* A helper function that fills in a dwarf2_loclist_baton. */
15646 fill_in_loclist_baton (struct dwarf2_cu *cu,
15647 struct dwarf2_loclist_baton *baton,
15648 struct attribute *attr)
15650 dwarf2_read_section (dwarf2_per_objfile->objfile,
15651 &dwarf2_per_objfile->loc);
15653 baton->per_cu = cu->per_cu;
15654 gdb_assert (baton->per_cu);
15655 /* We don't know how long the location list is, but make sure we
15656 don't run off the edge of the section. */
15657 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15658 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15659 baton->base_address = cu->base_address;
15663 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15664 struct dwarf2_cu *cu)
15666 struct objfile *objfile = dwarf2_per_objfile->objfile;
15668 if (attr_form_is_section_offset (attr)
15669 /* ".debug_loc" may not exist at all, or the offset may be outside
15670 the section. If so, fall through to the complaint in the
15672 && DW_UNSND (attr) < dwarf2_section_size (objfile,
15673 &dwarf2_per_objfile->loc))
15675 struct dwarf2_loclist_baton *baton;
15677 baton = obstack_alloc (&objfile->objfile_obstack,
15678 sizeof (struct dwarf2_loclist_baton));
15680 fill_in_loclist_baton (cu, baton, attr);
15682 if (cu->base_known == 0)
15683 complaint (&symfile_complaints,
15684 _("Location list used without "
15685 "specifying the CU base address."));
15687 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15688 SYMBOL_LOCATION_BATON (sym) = baton;
15692 struct dwarf2_locexpr_baton *baton;
15694 baton = obstack_alloc (&objfile->objfile_obstack,
15695 sizeof (struct dwarf2_locexpr_baton));
15696 baton->per_cu = cu->per_cu;
15697 gdb_assert (baton->per_cu);
15699 if (attr_form_is_block (attr))
15701 /* Note that we're just copying the block's data pointer
15702 here, not the actual data. We're still pointing into the
15703 info_buffer for SYM's objfile; right now we never release
15704 that buffer, but when we do clean up properly this may
15706 baton->size = DW_BLOCK (attr)->size;
15707 baton->data = DW_BLOCK (attr)->data;
15711 dwarf2_invalid_attrib_class_complaint ("location description",
15712 SYMBOL_NATURAL_NAME (sym));
15716 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15717 SYMBOL_LOCATION_BATON (sym) = baton;
15721 /* Return the OBJFILE associated with the compilation unit CU. If CU
15722 came from a separate debuginfo file, then the master objfile is
15726 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15728 struct objfile *objfile = per_cu->objfile;
15730 /* Return the master objfile, so that we can report and look up the
15731 correct file containing this variable. */
15732 if (objfile->separate_debug_objfile_backlink)
15733 objfile = objfile->separate_debug_objfile_backlink;
15738 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15739 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15740 CU_HEADERP first. */
15742 static const struct comp_unit_head *
15743 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15744 struct dwarf2_per_cu_data *per_cu)
15746 struct objfile *objfile;
15747 struct dwarf2_per_objfile *per_objfile;
15748 gdb_byte *info_ptr;
15751 return &per_cu->cu->header;
15753 objfile = per_cu->objfile;
15754 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15755 info_ptr = per_objfile->info.buffer + per_cu->offset;
15757 memset (cu_headerp, 0, sizeof (*cu_headerp));
15758 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15763 /* Return the address size given in the compilation unit header for CU. */
15766 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15768 struct comp_unit_head cu_header_local;
15769 const struct comp_unit_head *cu_headerp;
15771 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15773 return cu_headerp->addr_size;
15776 /* Return the offset size given in the compilation unit header for CU. */
15779 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15781 struct comp_unit_head cu_header_local;
15782 const struct comp_unit_head *cu_headerp;
15784 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15786 return cu_headerp->offset_size;
15789 /* See its dwarf2loc.h declaration. */
15792 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
15794 struct comp_unit_head cu_header_local;
15795 const struct comp_unit_head *cu_headerp;
15797 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15799 if (cu_headerp->version == 2)
15800 return cu_headerp->addr_size;
15802 return cu_headerp->offset_size;
15805 /* Return the text offset of the CU. The returned offset comes from
15806 this CU's objfile. If this objfile came from a separate debuginfo
15807 file, then the offset may be different from the corresponding
15808 offset in the parent objfile. */
15811 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
15813 struct objfile *objfile = per_cu->objfile;
15815 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15818 /* Locate the .debug_info compilation unit from CU's objfile which contains
15819 the DIE at OFFSET. Raises an error on failure. */
15821 static struct dwarf2_per_cu_data *
15822 dwarf2_find_containing_comp_unit (unsigned int offset,
15823 struct objfile *objfile)
15825 struct dwarf2_per_cu_data *this_cu;
15829 high = dwarf2_per_objfile->n_comp_units - 1;
15832 int mid = low + (high - low) / 2;
15834 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
15839 gdb_assert (low == high);
15840 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
15843 error (_("Dwarf Error: could not find partial DIE containing "
15844 "offset 0x%lx [in module %s]"),
15845 (long) offset, bfd_get_filename (objfile->obfd));
15847 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
15848 return dwarf2_per_objfile->all_comp_units[low-1];
15852 this_cu = dwarf2_per_objfile->all_comp_units[low];
15853 if (low == dwarf2_per_objfile->n_comp_units - 1
15854 && offset >= this_cu->offset + this_cu->length)
15855 error (_("invalid dwarf2 offset %u"), offset);
15856 gdb_assert (offset < this_cu->offset + this_cu->length);
15861 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15864 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
15866 memset (cu, 0, sizeof (*cu));
15868 cu->per_cu = per_cu;
15869 cu->objfile = per_cu->objfile;
15870 obstack_init (&cu->comp_unit_obstack);
15873 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15876 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
15878 struct attribute *attr;
15880 /* Set the language we're debugging. */
15881 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
15883 set_cu_language (DW_UNSND (attr), cu);
15886 cu->language = language_minimal;
15887 cu->language_defn = language_def (cu->language);
15891 /* Release one cached compilation unit, CU. We unlink it from the tree
15892 of compilation units, but we don't remove it from the read_in_chain;
15893 the caller is responsible for that.
15894 NOTE: DATA is a void * because this function is also used as a
15895 cleanup routine. */
15898 free_heap_comp_unit (void *data)
15900 struct dwarf2_cu *cu = data;
15902 gdb_assert (cu->per_cu != NULL);
15903 cu->per_cu->cu = NULL;
15906 obstack_free (&cu->comp_unit_obstack, NULL);
15911 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15912 when we're finished with it. We can't free the pointer itself, but be
15913 sure to unlink it from the cache. Also release any associated storage
15914 and perform cache maintenance.
15916 Only used during partial symbol parsing. */
15919 free_stack_comp_unit (void *data)
15921 struct dwarf2_cu *cu = data;
15923 gdb_assert (cu->per_cu != NULL);
15924 cu->per_cu->cu = NULL;
15927 obstack_free (&cu->comp_unit_obstack, NULL);
15928 cu->partial_dies = NULL;
15930 /* The previous code only did this if per_cu != NULL.
15931 But that would always succeed, so now we just unconditionally do
15932 the aging. This seems like the wrong place to do such aging,
15933 but cleaning that up is left for later. */
15934 age_cached_comp_units ();
15937 /* Free all cached compilation units. */
15940 free_cached_comp_units (void *data)
15942 struct dwarf2_per_cu_data *per_cu, **last_chain;
15944 per_cu = dwarf2_per_objfile->read_in_chain;
15945 last_chain = &dwarf2_per_objfile->read_in_chain;
15946 while (per_cu != NULL)
15948 struct dwarf2_per_cu_data *next_cu;
15950 next_cu = per_cu->cu->read_in_chain;
15952 free_heap_comp_unit (per_cu->cu);
15953 *last_chain = next_cu;
15959 /* Increase the age counter on each cached compilation unit, and free
15960 any that are too old. */
15963 age_cached_comp_units (void)
15965 struct dwarf2_per_cu_data *per_cu, **last_chain;
15967 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15968 per_cu = dwarf2_per_objfile->read_in_chain;
15969 while (per_cu != NULL)
15971 per_cu->cu->last_used ++;
15972 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15973 dwarf2_mark (per_cu->cu);
15974 per_cu = per_cu->cu->read_in_chain;
15977 per_cu = dwarf2_per_objfile->read_in_chain;
15978 last_chain = &dwarf2_per_objfile->read_in_chain;
15979 while (per_cu != NULL)
15981 struct dwarf2_per_cu_data *next_cu;
15983 next_cu = per_cu->cu->read_in_chain;
15985 if (!per_cu->cu->mark)
15987 free_heap_comp_unit (per_cu->cu);
15988 *last_chain = next_cu;
15991 last_chain = &per_cu->cu->read_in_chain;
15997 /* Remove a single compilation unit from the cache. */
16000 free_one_cached_comp_unit (void *target_cu)
16002 struct dwarf2_per_cu_data *per_cu, **last_chain;
16004 per_cu = dwarf2_per_objfile->read_in_chain;
16005 last_chain = &dwarf2_per_objfile->read_in_chain;
16006 while (per_cu != NULL)
16008 struct dwarf2_per_cu_data *next_cu;
16010 next_cu = per_cu->cu->read_in_chain;
16012 if (per_cu->cu == target_cu)
16014 free_heap_comp_unit (per_cu->cu);
16015 *last_chain = next_cu;
16019 last_chain = &per_cu->cu->read_in_chain;
16025 /* Release all extra memory associated with OBJFILE. */
16028 dwarf2_free_objfile (struct objfile *objfile)
16030 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16032 if (dwarf2_per_objfile == NULL)
16035 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16036 free_cached_comp_units (NULL);
16038 if (dwarf2_per_objfile->quick_file_names_table)
16039 htab_delete (dwarf2_per_objfile->quick_file_names_table);
16041 /* Everything else should be on the objfile obstack. */
16044 /* A pair of DIE offset and GDB type pointer. We store these
16045 in a hash table separate from the DIEs, and preserve them
16046 when the DIEs are flushed out of cache. */
16048 struct dwarf2_offset_and_type
16050 unsigned int offset;
16054 /* Hash function for a dwarf2_offset_and_type. */
16057 offset_and_type_hash (const void *item)
16059 const struct dwarf2_offset_and_type *ofs = item;
16061 return ofs->offset;
16064 /* Equality function for a dwarf2_offset_and_type. */
16067 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
16069 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
16070 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
16072 return ofs_lhs->offset == ofs_rhs->offset;
16075 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16076 table if necessary. For convenience, return TYPE.
16078 The DIEs reading must have careful ordering to:
16079 * Not cause infite loops trying to read in DIEs as a prerequisite for
16080 reading current DIE.
16081 * Not trying to dereference contents of still incompletely read in types
16082 while reading in other DIEs.
16083 * Enable referencing still incompletely read in types just by a pointer to
16084 the type without accessing its fields.
16086 Therefore caller should follow these rules:
16087 * Try to fetch any prerequisite types we may need to build this DIE type
16088 before building the type and calling set_die_type.
16089 * After building type call set_die_type for current DIE as soon as
16090 possible before fetching more types to complete the current type.
16091 * Make the type as complete as possible before fetching more types. */
16093 static struct type *
16094 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16096 struct dwarf2_offset_and_type **slot, ofs;
16097 struct objfile *objfile = cu->objfile;
16098 htab_t *type_hash_ptr;
16100 /* For Ada types, make sure that the gnat-specific data is always
16101 initialized (if not already set). There are a few types where
16102 we should not be doing so, because the type-specific area is
16103 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16104 where the type-specific area is used to store the floatformat).
16105 But this is not a problem, because the gnat-specific information
16106 is actually not needed for these types. */
16107 if (need_gnat_info (cu)
16108 && TYPE_CODE (type) != TYPE_CODE_FUNC
16109 && TYPE_CODE (type) != TYPE_CODE_FLT
16110 && !HAVE_GNAT_AUX_INFO (type))
16111 INIT_GNAT_SPECIFIC (type);
16113 if (cu->per_cu->debug_types_section)
16114 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
16116 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
16118 if (*type_hash_ptr == NULL)
16121 = htab_create_alloc_ex (127,
16122 offset_and_type_hash,
16123 offset_and_type_eq,
16125 &objfile->objfile_obstack,
16126 hashtab_obstack_allocate,
16127 dummy_obstack_deallocate);
16130 ofs.offset = die->offset;
16132 slot = (struct dwarf2_offset_and_type **)
16133 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
16135 complaint (&symfile_complaints,
16136 _("A problem internal to GDB: DIE 0x%x has type already set"),
16138 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
16143 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16144 table, or return NULL if the die does not have a saved type. */
16146 static struct type *
16147 get_die_type_at_offset (unsigned int offset,
16148 struct dwarf2_per_cu_data *per_cu)
16150 struct dwarf2_offset_and_type *slot, ofs;
16153 if (per_cu->debug_types_section)
16154 type_hash = dwarf2_per_objfile->debug_types_type_hash;
16156 type_hash = dwarf2_per_objfile->debug_info_type_hash;
16157 if (type_hash == NULL)
16160 ofs.offset = offset;
16161 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
16168 /* Look up the type for DIE in the appropriate type_hash table,
16169 or return NULL if DIE does not have a saved type. */
16171 static struct type *
16172 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
16174 return get_die_type_at_offset (die->offset, cu->per_cu);
16177 /* Add a dependence relationship from CU to REF_PER_CU. */
16180 dwarf2_add_dependence (struct dwarf2_cu *cu,
16181 struct dwarf2_per_cu_data *ref_per_cu)
16185 if (cu->dependencies == NULL)
16187 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
16188 NULL, &cu->comp_unit_obstack,
16189 hashtab_obstack_allocate,
16190 dummy_obstack_deallocate);
16192 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
16194 *slot = ref_per_cu;
16197 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16198 Set the mark field in every compilation unit in the
16199 cache that we must keep because we are keeping CU. */
16202 dwarf2_mark_helper (void **slot, void *data)
16204 struct dwarf2_per_cu_data *per_cu;
16206 per_cu = (struct dwarf2_per_cu_data *) *slot;
16208 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16209 reading of the chain. As such dependencies remain valid it is not much
16210 useful to track and undo them during QUIT cleanups. */
16211 if (per_cu->cu == NULL)
16214 if (per_cu->cu->mark)
16216 per_cu->cu->mark = 1;
16218 if (per_cu->cu->dependencies != NULL)
16219 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
16224 /* Set the mark field in CU and in every other compilation unit in the
16225 cache that we must keep because we are keeping CU. */
16228 dwarf2_mark (struct dwarf2_cu *cu)
16233 if (cu->dependencies != NULL)
16234 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
16238 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
16242 per_cu->cu->mark = 0;
16243 per_cu = per_cu->cu->read_in_chain;
16247 /* Trivial hash function for partial_die_info: the hash value of a DIE
16248 is its offset in .debug_info for this objfile. */
16251 partial_die_hash (const void *item)
16253 const struct partial_die_info *part_die = item;
16255 return part_die->offset;
16258 /* Trivial comparison function for partial_die_info structures: two DIEs
16259 are equal if they have the same offset. */
16262 partial_die_eq (const void *item_lhs, const void *item_rhs)
16264 const struct partial_die_info *part_die_lhs = item_lhs;
16265 const struct partial_die_info *part_die_rhs = item_rhs;
16267 return part_die_lhs->offset == part_die_rhs->offset;
16270 static struct cmd_list_element *set_dwarf2_cmdlist;
16271 static struct cmd_list_element *show_dwarf2_cmdlist;
16274 set_dwarf2_cmd (char *args, int from_tty)
16276 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
16280 show_dwarf2_cmd (char *args, int from_tty)
16282 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
16285 /* If section described by INFO was mmapped, munmap it now. */
16288 munmap_section_buffer (struct dwarf2_section_info *info)
16290 if (info->map_addr != NULL)
16295 res = munmap (info->map_addr, info->map_len);
16296 gdb_assert (res == 0);
16298 /* Without HAVE_MMAP, we should never be here to begin with. */
16299 gdb_assert_not_reached ("no mmap support");
16304 /* munmap debug sections for OBJFILE, if necessary. */
16307 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
16309 struct dwarf2_per_objfile *data = d;
16311 struct dwarf2_section_info *section;
16313 /* This is sorted according to the order they're defined in to make it easier
16314 to keep in sync. */
16315 munmap_section_buffer (&data->info);
16316 munmap_section_buffer (&data->abbrev);
16317 munmap_section_buffer (&data->line);
16318 munmap_section_buffer (&data->loc);
16319 munmap_section_buffer (&data->macinfo);
16320 munmap_section_buffer (&data->macro);
16321 munmap_section_buffer (&data->str);
16322 munmap_section_buffer (&data->ranges);
16323 munmap_section_buffer (&data->frame);
16324 munmap_section_buffer (&data->eh_frame);
16325 munmap_section_buffer (&data->gdb_index);
16328 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
16330 munmap_section_buffer (section);
16332 VEC_free (dwarf2_section_info_def, data->types);
16336 /* The "save gdb-index" command. */
16338 /* The contents of the hash table we create when building the string
16340 struct strtab_entry
16342 offset_type offset;
16346 /* Hash function for a strtab_entry.
16348 Function is used only during write_hash_table so no index format backward
16349 compatibility is needed. */
16352 hash_strtab_entry (const void *e)
16354 const struct strtab_entry *entry = e;
16355 return mapped_index_string_hash (INT_MAX, entry->str);
16358 /* Equality function for a strtab_entry. */
16361 eq_strtab_entry (const void *a, const void *b)
16363 const struct strtab_entry *ea = a;
16364 const struct strtab_entry *eb = b;
16365 return !strcmp (ea->str, eb->str);
16368 /* Create a strtab_entry hash table. */
16371 create_strtab (void)
16373 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
16374 xfree, xcalloc, xfree);
16377 /* Add a string to the constant pool. Return the string's offset in
16381 add_string (htab_t table, struct obstack *cpool, const char *str)
16384 struct strtab_entry entry;
16385 struct strtab_entry *result;
16388 slot = htab_find_slot (table, &entry, INSERT);
16393 result = XNEW (struct strtab_entry);
16394 result->offset = obstack_object_size (cpool);
16396 obstack_grow_str0 (cpool, str);
16399 return result->offset;
16402 /* An entry in the symbol table. */
16403 struct symtab_index_entry
16405 /* The name of the symbol. */
16407 /* The offset of the name in the constant pool. */
16408 offset_type index_offset;
16409 /* A sorted vector of the indices of all the CUs that hold an object
16411 VEC (offset_type) *cu_indices;
16414 /* The symbol table. This is a power-of-2-sized hash table. */
16415 struct mapped_symtab
16417 offset_type n_elements;
16419 struct symtab_index_entry **data;
16422 /* Hash function for a symtab_index_entry. */
16425 hash_symtab_entry (const void *e)
16427 const struct symtab_index_entry *entry = e;
16428 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
16429 sizeof (offset_type) * VEC_length (offset_type,
16430 entry->cu_indices),
16434 /* Equality function for a symtab_index_entry. */
16437 eq_symtab_entry (const void *a, const void *b)
16439 const struct symtab_index_entry *ea = a;
16440 const struct symtab_index_entry *eb = b;
16441 int len = VEC_length (offset_type, ea->cu_indices);
16442 if (len != VEC_length (offset_type, eb->cu_indices))
16444 return !memcmp (VEC_address (offset_type, ea->cu_indices),
16445 VEC_address (offset_type, eb->cu_indices),
16446 sizeof (offset_type) * len);
16449 /* Destroy a symtab_index_entry. */
16452 delete_symtab_entry (void *p)
16454 struct symtab_index_entry *entry = p;
16455 VEC_free (offset_type, entry->cu_indices);
16459 /* Create a hash table holding symtab_index_entry objects. */
16462 create_symbol_hash_table (void)
16464 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
16465 delete_symtab_entry, xcalloc, xfree);
16468 /* Create a new mapped symtab object. */
16470 static struct mapped_symtab *
16471 create_mapped_symtab (void)
16473 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
16474 symtab->n_elements = 0;
16475 symtab->size = 1024;
16476 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16480 /* Destroy a mapped_symtab. */
16483 cleanup_mapped_symtab (void *p)
16485 struct mapped_symtab *symtab = p;
16486 /* The contents of the array are freed when the other hash table is
16488 xfree (symtab->data);
16492 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16495 Function is used only during write_hash_table so no index format backward
16496 compatibility is needed. */
16498 static struct symtab_index_entry **
16499 find_slot (struct mapped_symtab *symtab, const char *name)
16501 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16503 index = hash & (symtab->size - 1);
16504 step = ((hash * 17) & (symtab->size - 1)) | 1;
16508 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16509 return &symtab->data[index];
16510 index = (index + step) & (symtab->size - 1);
16514 /* Expand SYMTAB's hash table. */
16517 hash_expand (struct mapped_symtab *symtab)
16519 offset_type old_size = symtab->size;
16521 struct symtab_index_entry **old_entries = symtab->data;
16524 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16526 for (i = 0; i < old_size; ++i)
16528 if (old_entries[i])
16530 struct symtab_index_entry **slot = find_slot (symtab,
16531 old_entries[i]->name);
16532 *slot = old_entries[i];
16536 xfree (old_entries);
16539 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16540 is the index of the CU in which the symbol appears. */
16543 add_index_entry (struct mapped_symtab *symtab, const char *name,
16544 offset_type cu_index)
16546 struct symtab_index_entry **slot;
16548 ++symtab->n_elements;
16549 if (4 * symtab->n_elements / 3 >= symtab->size)
16550 hash_expand (symtab);
16552 slot = find_slot (symtab, name);
16555 *slot = XNEW (struct symtab_index_entry);
16556 (*slot)->name = name;
16557 (*slot)->cu_indices = NULL;
16559 /* Don't push an index twice. Due to how we add entries we only
16560 have to check the last one. */
16561 if (VEC_empty (offset_type, (*slot)->cu_indices)
16562 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16563 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16566 /* Add a vector of indices to the constant pool. */
16569 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16570 struct symtab_index_entry *entry)
16574 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16577 offset_type len = VEC_length (offset_type, entry->cu_indices);
16578 offset_type val = MAYBE_SWAP (len);
16583 entry->index_offset = obstack_object_size (cpool);
16585 obstack_grow (cpool, &val, sizeof (val));
16587 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16590 val = MAYBE_SWAP (iter);
16591 obstack_grow (cpool, &val, sizeof (val));
16596 struct symtab_index_entry *old_entry = *slot;
16597 entry->index_offset = old_entry->index_offset;
16600 return entry->index_offset;
16603 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16604 constant pool entries going into the obstack CPOOL. */
16607 write_hash_table (struct mapped_symtab *symtab,
16608 struct obstack *output, struct obstack *cpool)
16611 htab_t symbol_hash_table;
16614 symbol_hash_table = create_symbol_hash_table ();
16615 str_table = create_strtab ();
16617 /* We add all the index vectors to the constant pool first, to
16618 ensure alignment is ok. */
16619 for (i = 0; i < symtab->size; ++i)
16621 if (symtab->data[i])
16622 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16625 /* Now write out the hash table. */
16626 for (i = 0; i < symtab->size; ++i)
16628 offset_type str_off, vec_off;
16630 if (symtab->data[i])
16632 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16633 vec_off = symtab->data[i]->index_offset;
16637 /* While 0 is a valid constant pool index, it is not valid
16638 to have 0 for both offsets. */
16643 str_off = MAYBE_SWAP (str_off);
16644 vec_off = MAYBE_SWAP (vec_off);
16646 obstack_grow (output, &str_off, sizeof (str_off));
16647 obstack_grow (output, &vec_off, sizeof (vec_off));
16650 htab_delete (str_table);
16651 htab_delete (symbol_hash_table);
16654 /* Struct to map psymtab to CU index in the index file. */
16655 struct psymtab_cu_index_map
16657 struct partial_symtab *psymtab;
16658 unsigned int cu_index;
16662 hash_psymtab_cu_index (const void *item)
16664 const struct psymtab_cu_index_map *map = item;
16666 return htab_hash_pointer (map->psymtab);
16670 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16672 const struct psymtab_cu_index_map *lhs = item_lhs;
16673 const struct psymtab_cu_index_map *rhs = item_rhs;
16675 return lhs->psymtab == rhs->psymtab;
16678 /* Helper struct for building the address table. */
16679 struct addrmap_index_data
16681 struct objfile *objfile;
16682 struct obstack *addr_obstack;
16683 htab_t cu_index_htab;
16685 /* Non-zero if the previous_* fields are valid.
16686 We can't write an entry until we see the next entry (since it is only then
16687 that we know the end of the entry). */
16688 int previous_valid;
16689 /* Index of the CU in the table of all CUs in the index file. */
16690 unsigned int previous_cu_index;
16691 /* Start address of the CU. */
16692 CORE_ADDR previous_cu_start;
16695 /* Write an address entry to OBSTACK. */
16698 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16699 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16701 offset_type cu_index_to_write;
16703 CORE_ADDR baseaddr;
16705 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16707 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16708 obstack_grow (obstack, addr, 8);
16709 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16710 obstack_grow (obstack, addr, 8);
16711 cu_index_to_write = MAYBE_SWAP (cu_index);
16712 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16715 /* Worker function for traversing an addrmap to build the address table. */
16718 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16720 struct addrmap_index_data *data = datap;
16721 struct partial_symtab *pst = obj;
16722 offset_type cu_index;
16725 if (data->previous_valid)
16726 add_address_entry (data->objfile, data->addr_obstack,
16727 data->previous_cu_start, start_addr,
16728 data->previous_cu_index);
16730 data->previous_cu_start = start_addr;
16733 struct psymtab_cu_index_map find_map, *map;
16734 find_map.psymtab = pst;
16735 map = htab_find (data->cu_index_htab, &find_map);
16736 gdb_assert (map != NULL);
16737 data->previous_cu_index = map->cu_index;
16738 data->previous_valid = 1;
16741 data->previous_valid = 0;
16746 /* Write OBJFILE's address map to OBSTACK.
16747 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16748 in the index file. */
16751 write_address_map (struct objfile *objfile, struct obstack *obstack,
16752 htab_t cu_index_htab)
16754 struct addrmap_index_data addrmap_index_data;
16756 /* When writing the address table, we have to cope with the fact that
16757 the addrmap iterator only provides the start of a region; we have to
16758 wait until the next invocation to get the start of the next region. */
16760 addrmap_index_data.objfile = objfile;
16761 addrmap_index_data.addr_obstack = obstack;
16762 addrmap_index_data.cu_index_htab = cu_index_htab;
16763 addrmap_index_data.previous_valid = 0;
16765 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16766 &addrmap_index_data);
16768 /* It's highly unlikely the last entry (end address = 0xff...ff)
16769 is valid, but we should still handle it.
16770 The end address is recorded as the start of the next region, but that
16771 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16773 if (addrmap_index_data.previous_valid)
16774 add_address_entry (objfile, obstack,
16775 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16776 addrmap_index_data.previous_cu_index);
16779 /* Add a list of partial symbols to SYMTAB. */
16782 write_psymbols (struct mapped_symtab *symtab,
16784 struct partial_symbol **psymp,
16786 offset_type cu_index,
16789 for (; count-- > 0; ++psymp)
16791 void **slot, *lookup;
16793 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16794 error (_("Ada is not currently supported by the index"));
16796 /* We only want to add a given psymbol once. However, we also
16797 want to account for whether it is global or static. So, we
16798 may add it twice, using slightly different values. */
16801 uintptr_t val = 1 | (uintptr_t) *psymp;
16803 lookup = (void *) val;
16808 /* Only add a given psymbol once. */
16809 slot = htab_find_slot (psyms_seen, lookup, INSERT);
16813 add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index);
16818 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16819 exception if there is an error. */
16822 write_obstack (FILE *file, struct obstack *obstack)
16824 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
16826 != obstack_object_size (obstack))
16827 error (_("couldn't data write to file"));
16830 /* Unlink a file if the argument is not NULL. */
16833 unlink_if_set (void *p)
16835 char **filename = p;
16837 unlink (*filename);
16840 /* A helper struct used when iterating over debug_types. */
16841 struct signatured_type_index_data
16843 struct objfile *objfile;
16844 struct mapped_symtab *symtab;
16845 struct obstack *types_list;
16850 /* A helper function that writes a single signatured_type to an
16854 write_one_signatured_type (void **slot, void *d)
16856 struct signatured_type_index_data *info = d;
16857 struct signatured_type *entry = (struct signatured_type *) *slot;
16858 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
16859 struct partial_symtab *psymtab = per_cu->v.psymtab;
16862 write_psymbols (info->symtab,
16864 info->objfile->global_psymbols.list
16865 + psymtab->globals_offset,
16866 psymtab->n_global_syms, info->cu_index,
16868 write_psymbols (info->symtab,
16870 info->objfile->static_psymbols.list
16871 + psymtab->statics_offset,
16872 psymtab->n_static_syms, info->cu_index,
16875 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
16876 obstack_grow (info->types_list, val, 8);
16877 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
16878 obstack_grow (info->types_list, val, 8);
16879 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
16880 obstack_grow (info->types_list, val, 8);
16887 /* Create an index file for OBJFILE in the directory DIR. */
16890 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
16892 struct cleanup *cleanup;
16893 char *filename, *cleanup_filename;
16894 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
16895 struct obstack cu_list, types_cu_list;
16898 struct mapped_symtab *symtab;
16899 offset_type val, size_of_contents, total_len;
16903 htab_t cu_index_htab;
16904 struct psymtab_cu_index_map *psymtab_cu_index_map;
16906 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
16909 if (dwarf2_per_objfile->using_index)
16910 error (_("Cannot use an index to create the index"));
16912 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
16913 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16915 if (stat (objfile->name, &st) < 0)
16916 perror_with_name (objfile->name);
16918 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
16919 INDEX_SUFFIX, (char *) NULL);
16920 cleanup = make_cleanup (xfree, filename);
16922 out_file = fopen (filename, "wb");
16924 error (_("Can't open `%s' for writing"), filename);
16926 cleanup_filename = filename;
16927 make_cleanup (unlink_if_set, &cleanup_filename);
16929 symtab = create_mapped_symtab ();
16930 make_cleanup (cleanup_mapped_symtab, symtab);
16932 obstack_init (&addr_obstack);
16933 make_cleanup_obstack_free (&addr_obstack);
16935 obstack_init (&cu_list);
16936 make_cleanup_obstack_free (&cu_list);
16938 obstack_init (&types_cu_list);
16939 make_cleanup_obstack_free (&types_cu_list);
16941 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16942 NULL, xcalloc, xfree);
16943 make_cleanup_htab_delete (psyms_seen);
16945 /* While we're scanning CU's create a table that maps a psymtab pointer
16946 (which is what addrmap records) to its index (which is what is recorded
16947 in the index file). This will later be needed to write the address
16949 cu_index_htab = htab_create_alloc (100,
16950 hash_psymtab_cu_index,
16951 eq_psymtab_cu_index,
16952 NULL, xcalloc, xfree);
16953 make_cleanup_htab_delete (cu_index_htab);
16954 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16955 xmalloc (sizeof (struct psymtab_cu_index_map)
16956 * dwarf2_per_objfile->n_comp_units);
16957 make_cleanup (xfree, psymtab_cu_index_map);
16959 /* The CU list is already sorted, so we don't need to do additional
16960 work here. Also, the debug_types entries do not appear in
16961 all_comp_units, but only in their own hash table. */
16962 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16964 struct dwarf2_per_cu_data *per_cu
16965 = dwarf2_per_objfile->all_comp_units[i];
16966 struct partial_symtab *psymtab = per_cu->v.psymtab;
16968 struct psymtab_cu_index_map *map;
16971 write_psymbols (symtab,
16973 objfile->global_psymbols.list + psymtab->globals_offset,
16974 psymtab->n_global_syms, i,
16976 write_psymbols (symtab,
16978 objfile->static_psymbols.list + psymtab->statics_offset,
16979 psymtab->n_static_syms, i,
16982 map = &psymtab_cu_index_map[i];
16983 map->psymtab = psymtab;
16985 slot = htab_find_slot (cu_index_htab, map, INSERT);
16986 gdb_assert (slot != NULL);
16987 gdb_assert (*slot == NULL);
16990 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16991 obstack_grow (&cu_list, val, 8);
16992 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16993 obstack_grow (&cu_list, val, 8);
16996 /* Dump the address map. */
16997 write_address_map (objfile, &addr_obstack, cu_index_htab);
16999 /* Write out the .debug_type entries, if any. */
17000 if (dwarf2_per_objfile->signatured_types)
17002 struct signatured_type_index_data sig_data;
17004 sig_data.objfile = objfile;
17005 sig_data.symtab = symtab;
17006 sig_data.types_list = &types_cu_list;
17007 sig_data.psyms_seen = psyms_seen;
17008 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
17009 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
17010 write_one_signatured_type, &sig_data);
17013 obstack_init (&constant_pool);
17014 make_cleanup_obstack_free (&constant_pool);
17015 obstack_init (&symtab_obstack);
17016 make_cleanup_obstack_free (&symtab_obstack);
17017 write_hash_table (symtab, &symtab_obstack, &constant_pool);
17019 obstack_init (&contents);
17020 make_cleanup_obstack_free (&contents);
17021 size_of_contents = 6 * sizeof (offset_type);
17022 total_len = size_of_contents;
17024 /* The version number. */
17025 val = MAYBE_SWAP (5);
17026 obstack_grow (&contents, &val, sizeof (val));
17028 /* The offset of the CU list from the start of the file. */
17029 val = MAYBE_SWAP (total_len);
17030 obstack_grow (&contents, &val, sizeof (val));
17031 total_len += obstack_object_size (&cu_list);
17033 /* The offset of the types CU list from the start of the file. */
17034 val = MAYBE_SWAP (total_len);
17035 obstack_grow (&contents, &val, sizeof (val));
17036 total_len += obstack_object_size (&types_cu_list);
17038 /* The offset of the address table from the start of the file. */
17039 val = MAYBE_SWAP (total_len);
17040 obstack_grow (&contents, &val, sizeof (val));
17041 total_len += obstack_object_size (&addr_obstack);
17043 /* The offset of the symbol table from the start of the file. */
17044 val = MAYBE_SWAP (total_len);
17045 obstack_grow (&contents, &val, sizeof (val));
17046 total_len += obstack_object_size (&symtab_obstack);
17048 /* The offset of the constant pool from the start of the file. */
17049 val = MAYBE_SWAP (total_len);
17050 obstack_grow (&contents, &val, sizeof (val));
17051 total_len += obstack_object_size (&constant_pool);
17053 gdb_assert (obstack_object_size (&contents) == size_of_contents);
17055 write_obstack (out_file, &contents);
17056 write_obstack (out_file, &cu_list);
17057 write_obstack (out_file, &types_cu_list);
17058 write_obstack (out_file, &addr_obstack);
17059 write_obstack (out_file, &symtab_obstack);
17060 write_obstack (out_file, &constant_pool);
17064 /* We want to keep the file, so we set cleanup_filename to NULL
17065 here. See unlink_if_set. */
17066 cleanup_filename = NULL;
17068 do_cleanups (cleanup);
17071 /* Implementation of the `save gdb-index' command.
17073 Note that the file format used by this command is documented in the
17074 GDB manual. Any changes here must be documented there. */
17077 save_gdb_index_command (char *arg, int from_tty)
17079 struct objfile *objfile;
17082 error (_("usage: save gdb-index DIRECTORY"));
17084 ALL_OBJFILES (objfile)
17088 /* If the objfile does not correspond to an actual file, skip it. */
17089 if (stat (objfile->name, &st) < 0)
17092 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
17093 if (dwarf2_per_objfile)
17095 volatile struct gdb_exception except;
17097 TRY_CATCH (except, RETURN_MASK_ERROR)
17099 write_psymtabs_to_index (objfile, arg);
17101 if (except.reason < 0)
17102 exception_fprintf (gdb_stderr, except,
17103 _("Error while writing index for `%s': "),
17111 int dwarf2_always_disassemble;
17114 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
17115 struct cmd_list_element *c, const char *value)
17117 fprintf_filtered (file,
17118 _("Whether to always disassemble "
17119 "DWARF expressions is %s.\n"),
17124 show_check_physname (struct ui_file *file, int from_tty,
17125 struct cmd_list_element *c, const char *value)
17127 fprintf_filtered (file,
17128 _("Whether to check \"physname\" is %s.\n"),
17132 void _initialize_dwarf2_read (void);
17135 _initialize_dwarf2_read (void)
17137 struct cmd_list_element *c;
17139 dwarf2_objfile_data_key
17140 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
17142 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
17143 Set DWARF 2 specific variables.\n\
17144 Configure DWARF 2 variables such as the cache size"),
17145 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
17146 0/*allow-unknown*/, &maintenance_set_cmdlist);
17148 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
17149 Show DWARF 2 specific variables\n\
17150 Show DWARF 2 variables such as the cache size"),
17151 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
17152 0/*allow-unknown*/, &maintenance_show_cmdlist);
17154 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
17155 &dwarf2_max_cache_age, _("\
17156 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17157 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17158 A higher limit means that cached compilation units will be stored\n\
17159 in memory longer, and more total memory will be used. Zero disables\n\
17160 caching, which can slow down startup."),
17162 show_dwarf2_max_cache_age,
17163 &set_dwarf2_cmdlist,
17164 &show_dwarf2_cmdlist);
17166 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
17167 &dwarf2_always_disassemble, _("\
17168 Set whether `info address' always disassembles DWARF expressions."), _("\
17169 Show whether `info address' always disassembles DWARF expressions."), _("\
17170 When enabled, DWARF expressions are always printed in an assembly-like\n\
17171 syntax. When disabled, expressions will be printed in a more\n\
17172 conversational style, when possible."),
17174 show_dwarf2_always_disassemble,
17175 &set_dwarf2_cmdlist,
17176 &show_dwarf2_cmdlist);
17178 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
17179 Set debugging of the dwarf2 DIE reader."), _("\
17180 Show debugging of the dwarf2 DIE reader."), _("\
17181 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17182 The value is the maximum depth to print."),
17185 &setdebuglist, &showdebuglist);
17187 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
17188 Set cross-checking of \"physname\" code against demangler."), _("\
17189 Show cross-checking of \"physname\" code against demangler."), _("\
17190 When enabled, GDB's internal \"physname\" code is checked against\n\
17192 NULL, show_check_physname,
17193 &setdebuglist, &showdebuglist);
17195 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
17197 Save a gdb-index file.\n\
17198 Usage: save gdb-index DIRECTORY"),
17200 set_cmd_completer (c, filename_completer);