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 flag will be set if this compilation unit might include
382 inter-compilation-unit references. */
383 unsigned int has_form_ref_addr : 1;
385 /* This flag will be set if this compilation unit includes any
386 DW_TAG_namespace DIEs. If we know that there are explicit
387 DIEs for namespaces, we don't need to try to infer them
388 from mangled names. */
389 unsigned int has_namespace_info : 1;
391 /* This CU references .debug_loc. See the symtab->locations_valid field.
392 This test is imperfect as there may exist optimized debug code not using
393 any location list and still facing inlining issues if handled as
394 unoptimized code. For a future better test see GCC PR other/32998. */
395 unsigned int has_loclist : 1;
398 /* Persistent data held for a compilation unit, even when not
399 processing it. We put a pointer to this structure in the
400 read_symtab_private field of the psymtab. */
402 struct dwarf2_per_cu_data
404 /* The start offset and length of this compilation unit. 2**29-1
405 bytes should suffice to store the length of any compilation unit
406 - if it doesn't, GDB will fall over anyway.
407 NOTE: Unlike comp_unit_head.length, this length includes
408 initial_length_size. */
410 unsigned int length : 29;
412 /* Flag indicating this compilation unit will be read in before
413 any of the current compilation units are processed. */
414 unsigned int queued : 1;
416 /* This flag will be set if we need to load absolutely all DIEs
417 for this compilation unit, instead of just the ones we think
418 are interesting. It gets set if we look for a DIE in the
419 hash table and don't find it. */
420 unsigned int load_all_dies : 1;
422 /* Non-null if this CU is from .debug_types; in which case it points
423 to the section. Otherwise it's from .debug_info. */
424 struct dwarf2_section_info *debug_types_section;
426 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
427 of the CU cache it gets reset to NULL again. */
428 struct dwarf2_cu *cu;
430 /* The corresponding objfile.
431 Normally we can get the objfile from dwarf2_per_objfile.
432 However we can enter this file with just a "per_cu" handle. */
433 struct objfile *objfile;
435 /* When using partial symbol tables, the 'psymtab' field is active.
436 Otherwise the 'quick' field is active. */
439 /* The partial symbol table associated with this compilation unit,
440 or NULL for partial units (which do not have an associated
442 struct partial_symtab *psymtab;
444 /* Data needed by the "quick" functions. */
445 struct dwarf2_per_cu_quick_data *quick;
449 /* Entry in the signatured_types hash table. */
451 struct signatured_type
455 /* Offset in .debug_types of the type defined by this TU. */
456 unsigned int type_offset;
458 /* The CU(/TU) of this type. */
459 struct dwarf2_per_cu_data per_cu;
462 /* Struct used to pass misc. parameters to read_die_and_children, et
463 al. which are used for both .debug_info and .debug_types dies.
464 All parameters here are unchanging for the life of the call. This
465 struct exists to abstract away the constant parameters of die
468 struct die_reader_specs
470 /* The bfd of this objfile. */
473 /* The CU of the DIE we are parsing. */
474 struct dwarf2_cu *cu;
476 /* Pointer to start of section buffer.
477 This is either the start of .debug_info or .debug_types. */
478 const gdb_byte *buffer;
481 /* The line number information for a compilation unit (found in the
482 .debug_line section) begins with a "statement program header",
483 which contains the following information. */
486 unsigned int total_length;
487 unsigned short version;
488 unsigned int header_length;
489 unsigned char minimum_instruction_length;
490 unsigned char maximum_ops_per_instruction;
491 unsigned char default_is_stmt;
493 unsigned char line_range;
494 unsigned char opcode_base;
496 /* standard_opcode_lengths[i] is the number of operands for the
497 standard opcode whose value is i. This means that
498 standard_opcode_lengths[0] is unused, and the last meaningful
499 element is standard_opcode_lengths[opcode_base - 1]. */
500 unsigned char *standard_opcode_lengths;
502 /* The include_directories table. NOTE! These strings are not
503 allocated with xmalloc; instead, they are pointers into
504 debug_line_buffer. If you try to free them, `free' will get
506 unsigned int num_include_dirs, include_dirs_size;
509 /* The file_names table. NOTE! These strings are not allocated
510 with xmalloc; instead, they are pointers into debug_line_buffer.
511 Don't try to free them directly. */
512 unsigned int num_file_names, file_names_size;
516 unsigned int dir_index;
517 unsigned int mod_time;
519 int included_p; /* Non-zero if referenced by the Line Number Program. */
520 struct symtab *symtab; /* The associated symbol table, if any. */
523 /* The start and end of the statement program following this
524 header. These point into dwarf2_per_objfile->line_buffer. */
525 gdb_byte *statement_program_start, *statement_program_end;
528 /* When we construct a partial symbol table entry we only
529 need this much information. */
530 struct partial_die_info
532 /* Offset of this DIE. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag) tag : 16;
538 /* Assorted flags describing the data found in this DIE. */
539 unsigned int has_children : 1;
540 unsigned int is_external : 1;
541 unsigned int is_declaration : 1;
542 unsigned int has_type : 1;
543 unsigned int has_specification : 1;
544 unsigned int has_pc_info : 1;
546 /* Flag set if the SCOPE field of this structure has been
548 unsigned int scope_set : 1;
550 /* Flag set if the DIE has a byte_size attribute. */
551 unsigned int has_byte_size : 1;
553 /* Flag set if any of the DIE's children are template arguments. */
554 unsigned int has_template_arguments : 1;
556 /* Flag set if fixup_partial_die has been called on this die. */
557 unsigned int fixup_called : 1;
559 /* The name of this DIE. Normally the value of DW_AT_name, but
560 sometimes a default name for unnamed DIEs. */
563 /* The linkage name, if present. */
564 const char *linkage_name;
566 /* The scope to prepend to our children. This is generally
567 allocated on the comp_unit_obstack, so will disappear
568 when this compilation unit leaves the cache. */
571 /* The location description associated with this DIE, if any. */
572 struct dwarf_block *locdesc;
574 /* If HAS_PC_INFO, the PC range associated with this DIE. */
578 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
579 DW_AT_sibling, if any. */
580 /* NOTE: This member isn't strictly necessary, read_partial_die could
581 return DW_AT_sibling values to its caller load_partial_dies. */
584 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
585 DW_AT_specification (or DW_AT_abstract_origin or
587 unsigned int spec_offset;
589 /* Pointers to this DIE's parent, first child, and next sibling,
591 struct partial_die_info *die_parent, *die_child, *die_sibling;
594 /* This data structure holds the information of an abbrev. */
597 unsigned int number; /* number identifying abbrev */
598 enum dwarf_tag tag; /* dwarf tag */
599 unsigned short has_children; /* boolean */
600 unsigned short num_attrs; /* number of attributes */
601 struct attr_abbrev *attrs; /* an array of attribute descriptions */
602 struct abbrev_info *next; /* next in chain */
607 ENUM_BITFIELD(dwarf_attribute) name : 16;
608 ENUM_BITFIELD(dwarf_form) form : 16;
611 /* Attributes have a name and a value. */
614 ENUM_BITFIELD(dwarf_attribute) name : 16;
615 ENUM_BITFIELD(dwarf_form) form : 15;
617 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
618 field should be in u.str (existing only for DW_STRING) but it is kept
619 here for better struct attribute alignment. */
620 unsigned int string_is_canonical : 1;
625 struct dwarf_block *blk;
629 struct signatured_type *signatured_type;
634 /* This data structure holds a complete die structure. */
637 /* DWARF-2 tag for this DIE. */
638 ENUM_BITFIELD(dwarf_tag) tag : 16;
640 /* Number of attributes */
641 unsigned char num_attrs;
643 /* True if we're presently building the full type name for the
644 type derived from this DIE. */
645 unsigned char building_fullname : 1;
650 /* Offset in .debug_info or .debug_types section. */
653 /* The dies in a compilation unit form an n-ary tree. PARENT
654 points to this die's parent; CHILD points to the first child of
655 this node; and all the children of a given node are chained
656 together via their SIBLING fields. */
657 struct die_info *child; /* Its first child, if any. */
658 struct die_info *sibling; /* Its next sibling, if any. */
659 struct die_info *parent; /* Its parent, if any. */
661 /* An array of attributes, with NUM_ATTRS elements. There may be
662 zero, but it's not common and zero-sized arrays are not
663 sufficiently portable C. */
664 struct attribute attrs[1];
667 /* Get at parts of an attribute structure. */
669 #define DW_STRING(attr) ((attr)->u.str)
670 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
671 #define DW_UNSND(attr) ((attr)->u.unsnd)
672 #define DW_BLOCK(attr) ((attr)->u.blk)
673 #define DW_SND(attr) ((attr)->u.snd)
674 #define DW_ADDR(attr) ((attr)->u.addr)
675 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
677 /* Blocks are a bunch of untyped bytes. */
682 /* Valid only if SIZE is not zero. */
686 #ifndef ATTR_ALLOC_CHUNK
687 #define ATTR_ALLOC_CHUNK 4
690 /* Allocate fields for structs, unions and enums in this size. */
691 #ifndef DW_FIELD_ALLOC_CHUNK
692 #define DW_FIELD_ALLOC_CHUNK 4
695 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
696 but this would require a corresponding change in unpack_field_as_long
698 static int bits_per_byte = 8;
700 /* The routines that read and process dies for a C struct or C++ class
701 pass lists of data member fields and lists of member function fields
702 in an instance of a field_info structure, as defined below. */
705 /* List of data member and baseclasses fields. */
708 struct nextfield *next;
713 *fields, *baseclasses;
715 /* Number of fields (including baseclasses). */
718 /* Number of baseclasses. */
721 /* Set if the accesibility of one of the fields is not public. */
722 int non_public_fields;
724 /* Member function fields array, entries are allocated in the order they
725 are encountered in the object file. */
728 struct nextfnfield *next;
729 struct fn_field fnfield;
733 /* Member function fieldlist array, contains name of possibly overloaded
734 member function, number of overloaded member functions and a pointer
735 to the head of the member function field chain. */
740 struct nextfnfield *head;
744 /* Number of entries in the fnfieldlists array. */
747 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
748 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
749 struct typedef_field_list
751 struct typedef_field field;
752 struct typedef_field_list *next;
755 unsigned typedef_field_list_count;
758 /* One item on the queue of compilation units to read in full symbols
760 struct dwarf2_queue_item
762 struct dwarf2_per_cu_data *per_cu;
763 struct dwarf2_queue_item *next;
766 /* The current queue. */
767 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
769 /* Loaded secondary compilation units are kept in memory until they
770 have not been referenced for the processing of this many
771 compilation units. Set this to zero to disable caching. Cache
772 sizes of up to at least twenty will improve startup time for
773 typical inter-CU-reference binaries, at an obvious memory cost. */
774 static int dwarf2_max_cache_age = 5;
776 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
777 struct cmd_list_element *c, const char *value)
779 fprintf_filtered (file, _("The upper bound on the age of cached "
780 "dwarf2 compilation units is %s.\n"),
785 /* Various complaints about symbol reading that don't abort the process. */
788 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
790 complaint (&symfile_complaints,
791 _("statement list doesn't fit in .debug_line section"));
795 dwarf2_debug_line_missing_file_complaint (void)
797 complaint (&symfile_complaints,
798 _(".debug_line section has line data without a file"));
802 dwarf2_debug_line_missing_end_sequence_complaint (void)
804 complaint (&symfile_complaints,
805 _(".debug_line section has line "
806 "program sequence without an end"));
810 dwarf2_complex_location_expr_complaint (void)
812 complaint (&symfile_complaints, _("location expression too complex"));
816 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
819 complaint (&symfile_complaints,
820 _("const value length mismatch for '%s', got %d, expected %d"),
825 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
827 complaint (&symfile_complaints,
828 _("macro info runs off end of `%s' section"),
829 section->asection->name);
833 dwarf2_macro_malformed_definition_complaint (const char *arg1)
835 complaint (&symfile_complaints,
836 _("macro debug info contains a "
837 "malformed macro definition:\n`%s'"),
842 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
844 complaint (&symfile_complaints,
845 _("invalid attribute class or form for '%s' in '%s'"),
849 /* local function prototypes */
851 static void dwarf2_locate_sections (bfd *, asection *, void *);
853 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
856 static void dwarf2_find_base_address (struct die_info *die,
857 struct dwarf2_cu *cu);
859 static void dwarf2_build_psymtabs_hard (struct objfile *);
861 static void scan_partial_symbols (struct partial_die_info *,
862 CORE_ADDR *, CORE_ADDR *,
863 int, struct dwarf2_cu *);
865 static void add_partial_symbol (struct partial_die_info *,
868 static void add_partial_namespace (struct partial_die_info *pdi,
869 CORE_ADDR *lowpc, CORE_ADDR *highpc,
870 int need_pc, struct dwarf2_cu *cu);
872 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
873 CORE_ADDR *highpc, int need_pc,
874 struct dwarf2_cu *cu);
876 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
877 struct dwarf2_cu *cu);
879 static void add_partial_subprogram (struct partial_die_info *pdi,
880 CORE_ADDR *lowpc, CORE_ADDR *highpc,
881 int need_pc, struct dwarf2_cu *cu);
883 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
884 gdb_byte *buffer, gdb_byte *info_ptr,
885 bfd *abfd, struct dwarf2_cu *cu);
887 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
889 static void psymtab_to_symtab_1 (struct partial_symtab *);
891 static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
893 static void dwarf2_free_abbrev_table (void *);
895 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
897 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
900 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
903 static struct partial_die_info *load_partial_dies (bfd *,
904 gdb_byte *, gdb_byte *,
905 int, struct dwarf2_cu *);
907 static gdb_byte *read_partial_die (struct partial_die_info *,
908 struct abbrev_info *abbrev,
910 gdb_byte *, gdb_byte *,
913 static struct partial_die_info *find_partial_die (unsigned int,
916 static void fixup_partial_die (struct partial_die_info *,
919 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
920 bfd *, gdb_byte *, struct dwarf2_cu *);
922 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
923 bfd *, gdb_byte *, struct dwarf2_cu *);
925 static unsigned int read_1_byte (bfd *, gdb_byte *);
927 static int read_1_signed_byte (bfd *, gdb_byte *);
929 static unsigned int read_2_bytes (bfd *, gdb_byte *);
931 static unsigned int read_4_bytes (bfd *, gdb_byte *);
933 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
935 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
938 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
940 static LONGEST read_checked_initial_length_and_offset
941 (bfd *, gdb_byte *, const struct comp_unit_head *,
942 unsigned int *, unsigned int *);
944 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
947 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
949 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
951 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
953 static char *read_indirect_string (bfd *, gdb_byte *,
954 const struct comp_unit_head *,
957 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
959 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
961 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
963 static void set_cu_language (unsigned int, struct dwarf2_cu *);
965 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
968 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
972 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
973 struct dwarf2_cu *cu);
975 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
977 static struct die_info *die_specification (struct die_info *die,
978 struct dwarf2_cu **);
980 static void free_line_header (struct line_header *lh);
982 static void add_file_name (struct line_header *, char *, unsigned int,
983 unsigned int, unsigned int);
985 static struct line_header *(dwarf_decode_line_header
986 (unsigned int offset,
987 bfd *abfd, struct dwarf2_cu *cu));
989 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
990 struct dwarf2_cu *, struct partial_symtab *);
992 static void dwarf2_start_subfile (char *, const char *, const char *);
994 static struct symbol *new_symbol (struct die_info *, struct type *,
997 static struct symbol *new_symbol_full (struct die_info *, struct type *,
998 struct dwarf2_cu *, struct symbol *);
1000 static void dwarf2_const_value (struct attribute *, struct symbol *,
1001 struct dwarf2_cu *);
1003 static void dwarf2_const_value_attr (struct attribute *attr,
1006 struct obstack *obstack,
1007 struct dwarf2_cu *cu, long *value,
1009 struct dwarf2_locexpr_baton **baton);
1011 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1013 static int need_gnat_info (struct dwarf2_cu *);
1015 static struct type *die_descriptive_type (struct die_info *,
1016 struct dwarf2_cu *);
1018 static void set_descriptive_type (struct type *, struct die_info *,
1019 struct dwarf2_cu *);
1021 static struct type *die_containing_type (struct die_info *,
1022 struct dwarf2_cu *);
1024 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1025 struct dwarf2_cu *);
1027 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1029 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1031 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1033 static char *typename_concat (struct obstack *obs, const char *prefix,
1034 const char *suffix, int physname,
1035 struct dwarf2_cu *cu);
1037 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1039 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1041 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1043 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1045 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1047 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1048 struct dwarf2_cu *, struct partial_symtab *);
1050 static int dwarf2_get_pc_bounds (struct die_info *,
1051 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1052 struct partial_symtab *);
1054 static void get_scope_pc_bounds (struct die_info *,
1055 CORE_ADDR *, CORE_ADDR *,
1056 struct dwarf2_cu *);
1058 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1059 CORE_ADDR, struct dwarf2_cu *);
1061 static void dwarf2_add_field (struct field_info *, struct die_info *,
1062 struct dwarf2_cu *);
1064 static void dwarf2_attach_fields_to_type (struct field_info *,
1065 struct type *, struct dwarf2_cu *);
1067 static void dwarf2_add_member_fn (struct field_info *,
1068 struct die_info *, struct type *,
1069 struct dwarf2_cu *);
1071 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1073 struct dwarf2_cu *);
1075 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1077 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1079 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1081 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1083 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1085 static struct type *read_module_type (struct die_info *die,
1086 struct dwarf2_cu *cu);
1088 static const char *namespace_name (struct die_info *die,
1089 int *is_anonymous, struct dwarf2_cu *);
1091 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1093 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1095 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1096 struct dwarf2_cu *);
1098 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1100 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1102 gdb_byte **new_info_ptr,
1103 struct die_info *parent);
1105 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1107 gdb_byte **new_info_ptr,
1108 struct die_info *parent);
1110 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1112 gdb_byte **new_info_ptr,
1113 struct die_info *parent);
1115 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1116 struct die_info **, gdb_byte *,
1119 static void process_die (struct die_info *, struct dwarf2_cu *);
1121 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1124 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1126 static const char *dwarf2_full_name (char *name,
1127 struct die_info *die,
1128 struct dwarf2_cu *cu);
1130 static struct die_info *dwarf2_extension (struct die_info *die,
1131 struct dwarf2_cu **);
1133 static char *dwarf_tag_name (unsigned int);
1135 static char *dwarf_attr_name (unsigned int);
1137 static char *dwarf_form_name (unsigned int);
1139 static char *dwarf_bool_name (unsigned int);
1141 static char *dwarf_type_encoding_name (unsigned int);
1144 static char *dwarf_cfi_name (unsigned int);
1147 static struct die_info *sibling_die (struct die_info *);
1149 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1151 static void dump_die_for_error (struct die_info *);
1153 static void dump_die_1 (struct ui_file *, int level, int max_level,
1156 /*static*/ void dump_die (struct die_info *, int max_level);
1158 static void store_in_ref_table (struct die_info *,
1159 struct dwarf2_cu *);
1161 static int is_ref_attr (struct attribute *);
1163 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1165 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1167 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1169 struct dwarf2_cu **);
1171 static struct die_info *follow_die_ref (struct die_info *,
1173 struct dwarf2_cu **);
1175 static struct die_info *follow_die_sig (struct die_info *,
1177 struct dwarf2_cu **);
1179 static struct signatured_type *lookup_signatured_type_at_offset
1180 (struct objfile *objfile,
1181 struct dwarf2_section_info *section,
1182 unsigned int offset);
1184 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1186 static void read_signatured_type (struct signatured_type *type_sig);
1188 /* memory allocation interface */
1190 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1192 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1194 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1196 static void dwarf_decode_macros (struct line_header *, unsigned int,
1197 char *, bfd *, struct dwarf2_cu *,
1198 struct dwarf2_section_info *,
1201 static int attr_form_is_block (struct attribute *);
1203 static int attr_form_is_section_offset (struct attribute *);
1205 static int attr_form_is_constant (struct attribute *);
1207 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1208 struct dwarf2_loclist_baton *baton,
1209 struct attribute *attr);
1211 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1213 struct dwarf2_cu *cu);
1215 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1216 struct abbrev_info *abbrev,
1217 struct dwarf2_cu *cu);
1219 static void free_stack_comp_unit (void *);
1221 static hashval_t partial_die_hash (const void *item);
1223 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1225 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1226 (unsigned int offset, struct objfile *objfile);
1228 static void init_one_comp_unit (struct dwarf2_cu *cu,
1229 struct dwarf2_per_cu_data *per_cu);
1231 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1232 struct die_info *comp_unit_die);
1234 static void free_heap_comp_unit (void *);
1236 static void free_cached_comp_units (void *);
1238 static void age_cached_comp_units (void);
1240 static void free_one_cached_comp_unit (void *);
1242 static struct type *set_die_type (struct die_info *, struct type *,
1243 struct dwarf2_cu *);
1245 static void create_all_comp_units (struct objfile *);
1247 static int create_debug_types_hash_table (struct objfile *objfile);
1249 static void load_full_comp_unit (struct dwarf2_per_cu_data *);
1251 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1253 static void dwarf2_add_dependence (struct dwarf2_cu *,
1254 struct dwarf2_per_cu_data *);
1256 static void dwarf2_mark (struct dwarf2_cu *);
1258 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1260 static struct type *get_die_type_at_offset (unsigned int,
1261 struct dwarf2_per_cu_data *per_cu);
1263 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1265 static void dwarf2_release_queue (void *dummy);
1267 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
1269 static void process_queue (void);
1271 static void find_file_and_directory (struct die_info *die,
1272 struct dwarf2_cu *cu,
1273 char **name, char **comp_dir);
1275 static char *file_full_name (int file, struct line_header *lh,
1276 const char *comp_dir);
1278 static gdb_byte *read_and_check_comp_unit_head
1279 (struct comp_unit_head *header,
1280 struct dwarf2_section_info *section, gdb_byte *info_ptr,
1281 int is_debug_types_section);
1283 static void init_cu_die_reader (struct die_reader_specs *reader,
1284 struct dwarf2_cu *cu);
1286 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1290 /* Convert VALUE between big- and little-endian. */
1292 byte_swap (offset_type value)
1296 result = (value & 0xff) << 24;
1297 result |= (value & 0xff00) << 8;
1298 result |= (value & 0xff0000) >> 8;
1299 result |= (value & 0xff000000) >> 24;
1303 #define MAYBE_SWAP(V) byte_swap (V)
1306 #define MAYBE_SWAP(V) (V)
1307 #endif /* WORDS_BIGENDIAN */
1309 /* The suffix for an index file. */
1310 #define INDEX_SUFFIX ".gdb-index"
1312 static const char *dwarf2_physname (char *name, struct die_info *die,
1313 struct dwarf2_cu *cu);
1315 /* Try to locate the sections we need for DWARF 2 debugging
1316 information and return true if we have enough to do something.
1317 NAMES points to the dwarf2 section names, or is NULL if the standard
1318 ELF names are used. */
1321 dwarf2_has_info (struct objfile *objfile,
1322 const struct dwarf2_debug_sections *names)
1324 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1325 if (!dwarf2_per_objfile)
1327 /* Initialize per-objfile state. */
1328 struct dwarf2_per_objfile *data
1329 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1331 memset (data, 0, sizeof (*data));
1332 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1333 dwarf2_per_objfile = data;
1335 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1337 dwarf2_per_objfile->objfile = objfile;
1339 return (dwarf2_per_objfile->info.asection != NULL
1340 && dwarf2_per_objfile->abbrev.asection != NULL);
1343 /* When loading sections, we look either for uncompressed section or for
1344 compressed section names. */
1347 section_is_p (const char *section_name,
1348 const struct dwarf2_section_names *names)
1350 if (names->normal != NULL
1351 && strcmp (section_name, names->normal) == 0)
1353 if (names->compressed != NULL
1354 && strcmp (section_name, names->compressed) == 0)
1359 /* This function is mapped across the sections and remembers the
1360 offset and size of each of the debugging sections we are interested
1364 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1366 const struct dwarf2_debug_sections *names;
1369 names = &dwarf2_elf_names;
1371 names = (const struct dwarf2_debug_sections *) vnames;
1373 if (section_is_p (sectp->name, &names->info))
1375 dwarf2_per_objfile->info.asection = sectp;
1376 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1378 else if (section_is_p (sectp->name, &names->abbrev))
1380 dwarf2_per_objfile->abbrev.asection = sectp;
1381 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1383 else if (section_is_p (sectp->name, &names->line))
1385 dwarf2_per_objfile->line.asection = sectp;
1386 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1388 else if (section_is_p (sectp->name, &names->loc))
1390 dwarf2_per_objfile->loc.asection = sectp;
1391 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1393 else if (section_is_p (sectp->name, &names->macinfo))
1395 dwarf2_per_objfile->macinfo.asection = sectp;
1396 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1398 else if (section_is_p (sectp->name, &names->macro))
1400 dwarf2_per_objfile->macro.asection = sectp;
1401 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1403 else if (section_is_p (sectp->name, &names->str))
1405 dwarf2_per_objfile->str.asection = sectp;
1406 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1408 else if (section_is_p (sectp->name, &names->frame))
1410 dwarf2_per_objfile->frame.asection = sectp;
1411 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1413 else if (section_is_p (sectp->name, &names->eh_frame))
1415 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1417 if (aflag & SEC_HAS_CONTENTS)
1419 dwarf2_per_objfile->eh_frame.asection = sectp;
1420 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1423 else if (section_is_p (sectp->name, &names->ranges))
1425 dwarf2_per_objfile->ranges.asection = sectp;
1426 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1428 else if (section_is_p (sectp->name, &names->types))
1430 struct dwarf2_section_info type_section;
1432 memset (&type_section, 0, sizeof (type_section));
1433 type_section.asection = sectp;
1434 type_section.size = bfd_get_section_size (sectp);
1436 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1439 else if (section_is_p (sectp->name, &names->gdb_index))
1441 dwarf2_per_objfile->gdb_index.asection = sectp;
1442 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1445 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1446 && bfd_section_vma (abfd, sectp) == 0)
1447 dwarf2_per_objfile->has_section_at_zero = 1;
1450 /* Decompress a section that was compressed using zlib. Store the
1451 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1454 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1455 gdb_byte **outbuf, bfd_size_type *outsize)
1457 bfd *abfd = objfile->obfd;
1459 error (_("Support for zlib-compressed DWARF data (from '%s') "
1460 "is disabled in this copy of GDB"),
1461 bfd_get_filename (abfd));
1463 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1464 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1465 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1466 bfd_size_type uncompressed_size;
1467 gdb_byte *uncompressed_buffer;
1470 int header_size = 12;
1472 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1473 || bfd_bread (compressed_buffer,
1474 compressed_size, abfd) != compressed_size)
1475 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1476 bfd_get_filename (abfd));
1478 /* Read the zlib header. In this case, it should be "ZLIB" followed
1479 by the uncompressed section size, 8 bytes in big-endian order. */
1480 if (compressed_size < header_size
1481 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1482 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1483 bfd_get_filename (abfd));
1484 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1485 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1486 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1487 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1488 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1489 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1490 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1491 uncompressed_size += compressed_buffer[11];
1493 /* It is possible the section consists of several compressed
1494 buffers concatenated together, so we uncompress in a loop. */
1498 strm.avail_in = compressed_size - header_size;
1499 strm.next_in = (Bytef*) compressed_buffer + header_size;
1500 strm.avail_out = uncompressed_size;
1501 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1503 rc = inflateInit (&strm);
1504 while (strm.avail_in > 0)
1507 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1508 bfd_get_filename (abfd), rc);
1509 strm.next_out = ((Bytef*) uncompressed_buffer
1510 + (uncompressed_size - strm.avail_out));
1511 rc = inflate (&strm, Z_FINISH);
1512 if (rc != Z_STREAM_END)
1513 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1514 bfd_get_filename (abfd), rc);
1515 rc = inflateReset (&strm);
1517 rc = inflateEnd (&strm);
1519 || strm.avail_out != 0)
1520 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1521 bfd_get_filename (abfd), rc);
1523 do_cleanups (cleanup);
1524 *outbuf = uncompressed_buffer;
1525 *outsize = uncompressed_size;
1529 /* A helper function that decides whether a section is empty. */
1532 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1534 return info->asection == NULL || info->size == 0;
1537 /* Read the contents of the section INFO from object file specified by
1538 OBJFILE, store info about the section into INFO.
1539 If the section is compressed, uncompress it before returning. */
1542 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1544 bfd *abfd = objfile->obfd;
1545 asection *sectp = info->asection;
1546 gdb_byte *buf, *retbuf;
1547 unsigned char header[4];
1551 info->buffer = NULL;
1552 info->map_addr = NULL;
1555 if (dwarf2_section_empty_p (info))
1558 /* Check if the file has a 4-byte header indicating compression. */
1559 if (info->size > sizeof (header)
1560 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1561 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1563 /* Upon decompression, update the buffer and its size. */
1564 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1566 zlib_decompress_section (objfile, sectp, &info->buffer,
1574 pagesize = getpagesize ();
1576 /* Only try to mmap sections which are large enough: we don't want to
1577 waste space due to fragmentation. Also, only try mmap for sections
1578 without relocations. */
1580 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1582 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1583 MAP_PRIVATE, sectp->filepos,
1584 &info->map_addr, &info->map_len);
1586 if ((caddr_t)info->buffer != MAP_FAILED)
1588 #if HAVE_POSIX_MADVISE
1589 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1596 /* If we get here, we are a normal, not-compressed section. */
1598 = obstack_alloc (&objfile->objfile_obstack, info->size);
1600 /* When debugging .o files, we may need to apply relocations; see
1601 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1602 We never compress sections in .o files, so we only need to
1603 try this when the section is not compressed. */
1604 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1607 info->buffer = retbuf;
1611 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1612 || bfd_bread (buf, info->size, abfd) != info->size)
1613 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1614 bfd_get_filename (abfd));
1617 /* A helper function that returns the size of a section in a safe way.
1618 If you are positive that the section has been read before using the
1619 size, then it is safe to refer to the dwarf2_section_info object's
1620 "size" field directly. In other cases, you must call this
1621 function, because for compressed sections the size field is not set
1622 correctly until the section has been read. */
1624 static bfd_size_type
1625 dwarf2_section_size (struct objfile *objfile,
1626 struct dwarf2_section_info *info)
1629 dwarf2_read_section (objfile, info);
1633 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1637 dwarf2_get_section_info (struct objfile *objfile,
1638 enum dwarf2_section_enum sect,
1639 asection **sectp, gdb_byte **bufp,
1640 bfd_size_type *sizep)
1642 struct dwarf2_per_objfile *data
1643 = objfile_data (objfile, dwarf2_objfile_data_key);
1644 struct dwarf2_section_info *info;
1646 /* We may see an objfile without any DWARF, in which case we just
1657 case DWARF2_DEBUG_FRAME:
1658 info = &data->frame;
1660 case DWARF2_EH_FRAME:
1661 info = &data->eh_frame;
1664 gdb_assert_not_reached ("unexpected section");
1667 dwarf2_read_section (objfile, info);
1669 *sectp = info->asection;
1670 *bufp = info->buffer;
1671 *sizep = info->size;
1675 /* DWARF quick_symbols_functions support. */
1677 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1678 unique line tables, so we maintain a separate table of all .debug_line
1679 derived entries to support the sharing.
1680 All the quick functions need is the list of file names. We discard the
1681 line_header when we're done and don't need to record it here. */
1682 struct quick_file_names
1684 /* The offset in .debug_line of the line table. We hash on this. */
1685 unsigned int offset;
1687 /* The number of entries in file_names, real_names. */
1688 unsigned int num_file_names;
1690 /* The file names from the line table, after being run through
1692 const char **file_names;
1694 /* The file names from the line table after being run through
1695 gdb_realpath. These are computed lazily. */
1696 const char **real_names;
1699 /* When using the index (and thus not using psymtabs), each CU has an
1700 object of this type. This is used to hold information needed by
1701 the various "quick" methods. */
1702 struct dwarf2_per_cu_quick_data
1704 /* The file table. This can be NULL if there was no file table
1705 or it's currently not read in.
1706 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1707 struct quick_file_names *file_names;
1709 /* The corresponding symbol table. This is NULL if symbols for this
1710 CU have not yet been read. */
1711 struct symtab *symtab;
1713 /* A temporary mark bit used when iterating over all CUs in
1714 expand_symtabs_matching. */
1715 unsigned int mark : 1;
1717 /* True if we've tried to read the file table and found there isn't one.
1718 There will be no point in trying to read it again next time. */
1719 unsigned int no_file_data : 1;
1722 /* Hash function for a quick_file_names. */
1725 hash_file_name_entry (const void *e)
1727 const struct quick_file_names *file_data = e;
1729 return file_data->offset;
1732 /* Equality function for a quick_file_names. */
1735 eq_file_name_entry (const void *a, const void *b)
1737 const struct quick_file_names *ea = a;
1738 const struct quick_file_names *eb = b;
1740 return ea->offset == eb->offset;
1743 /* Delete function for a quick_file_names. */
1746 delete_file_name_entry (void *e)
1748 struct quick_file_names *file_data = e;
1751 for (i = 0; i < file_data->num_file_names; ++i)
1753 xfree ((void*) file_data->file_names[i]);
1754 if (file_data->real_names)
1755 xfree ((void*) file_data->real_names[i]);
1758 /* The space for the struct itself lives on objfile_obstack,
1759 so we don't free it here. */
1762 /* Create a quick_file_names hash table. */
1765 create_quick_file_names_table (unsigned int nr_initial_entries)
1767 return htab_create_alloc (nr_initial_entries,
1768 hash_file_name_entry, eq_file_name_entry,
1769 delete_file_name_entry, xcalloc, xfree);
1772 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1773 have to be created afterwards. You should call age_cached_comp_units after
1774 processing PER_CU->CU. dw2_setup must have been already called. */
1777 load_cu (struct dwarf2_per_cu_data *per_cu)
1779 if (per_cu->debug_types_section)
1780 load_full_type_unit (per_cu);
1782 load_full_comp_unit (per_cu);
1784 gdb_assert (per_cu->cu != NULL);
1786 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1789 /* Read in the symbols for PER_CU. */
1792 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1794 struct cleanup *back_to;
1796 back_to = make_cleanup (dwarf2_release_queue, NULL);
1798 queue_comp_unit (per_cu);
1804 /* Age the cache, releasing compilation units that have not
1805 been used recently. */
1806 age_cached_comp_units ();
1808 do_cleanups (back_to);
1811 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1812 the objfile from which this CU came. Returns the resulting symbol
1815 static struct symtab *
1816 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1818 if (!per_cu->v.quick->symtab)
1820 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1821 increment_reading_symtab ();
1822 dw2_do_instantiate_symtab (per_cu);
1823 do_cleanups (back_to);
1825 return per_cu->v.quick->symtab;
1828 /* Return the CU given its index. */
1830 static struct dwarf2_per_cu_data *
1831 dw2_get_cu (int index)
1833 if (index >= dwarf2_per_objfile->n_comp_units)
1835 index -= dwarf2_per_objfile->n_comp_units;
1836 return dwarf2_per_objfile->all_type_units[index];
1838 return dwarf2_per_objfile->all_comp_units[index];
1841 /* A helper function that knows how to read a 64-bit value in a way
1842 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1846 extract_cu_value (const char *bytes, ULONGEST *result)
1848 if (sizeof (ULONGEST) < 8)
1852 /* Ignore the upper 4 bytes if they are all zero. */
1853 for (i = 0; i < 4; ++i)
1854 if (bytes[i + 4] != 0)
1857 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1860 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1864 /* Read the CU list from the mapped index, and use it to create all
1865 the CU objects for this objfile. Return 0 if something went wrong,
1866 1 if everything went ok. */
1869 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1870 offset_type cu_list_elements)
1874 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1875 dwarf2_per_objfile->all_comp_units
1876 = obstack_alloc (&objfile->objfile_obstack,
1877 dwarf2_per_objfile->n_comp_units
1878 * sizeof (struct dwarf2_per_cu_data *));
1880 for (i = 0; i < cu_list_elements; i += 2)
1882 struct dwarf2_per_cu_data *the_cu;
1883 ULONGEST offset, length;
1885 if (!extract_cu_value (cu_list, &offset)
1886 || !extract_cu_value (cu_list + 8, &length))
1890 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1891 struct dwarf2_per_cu_data);
1892 the_cu->offset = offset;
1893 the_cu->length = length;
1894 the_cu->objfile = objfile;
1895 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1896 struct dwarf2_per_cu_quick_data);
1897 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1903 /* Create the signatured type hash table from the index. */
1906 create_signatured_type_table_from_index (struct objfile *objfile,
1907 struct dwarf2_section_info *section,
1908 const gdb_byte *bytes,
1909 offset_type elements)
1912 htab_t sig_types_hash;
1914 dwarf2_per_objfile->n_type_units = elements / 3;
1915 dwarf2_per_objfile->all_type_units
1916 = obstack_alloc (&objfile->objfile_obstack,
1917 dwarf2_per_objfile->n_type_units
1918 * sizeof (struct dwarf2_per_cu_data *));
1920 sig_types_hash = allocate_signatured_type_table (objfile);
1922 for (i = 0; i < elements; i += 3)
1924 struct signatured_type *type_sig;
1925 ULONGEST offset, type_offset, signature;
1928 if (!extract_cu_value (bytes, &offset)
1929 || !extract_cu_value (bytes + 8, &type_offset))
1931 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1934 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1935 struct signatured_type);
1936 type_sig->signature = signature;
1937 type_sig->type_offset = type_offset;
1938 type_sig->per_cu.debug_types_section = section;
1939 type_sig->per_cu.offset = offset;
1940 type_sig->per_cu.objfile = objfile;
1941 type_sig->per_cu.v.quick
1942 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1943 struct dwarf2_per_cu_quick_data);
1945 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1948 dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu;
1951 dwarf2_per_objfile->signatured_types = sig_types_hash;
1956 /* Read the address map data from the mapped index, and use it to
1957 populate the objfile's psymtabs_addrmap. */
1960 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1962 const gdb_byte *iter, *end;
1963 struct obstack temp_obstack;
1964 struct addrmap *mutable_map;
1965 struct cleanup *cleanup;
1968 obstack_init (&temp_obstack);
1969 cleanup = make_cleanup_obstack_free (&temp_obstack);
1970 mutable_map = addrmap_create_mutable (&temp_obstack);
1972 iter = index->address_table;
1973 end = iter + index->address_table_size;
1975 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1979 ULONGEST hi, lo, cu_index;
1980 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1982 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1984 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1987 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1988 dw2_get_cu (cu_index));
1991 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1992 &objfile->objfile_obstack);
1993 do_cleanups (cleanup);
1996 /* The hash function for strings in the mapped index. This is the same as
1997 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1998 implementation. This is necessary because the hash function is tied to the
1999 format of the mapped index file. The hash values do not have to match with
2002 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2005 mapped_index_string_hash (int index_version, const void *p)
2007 const unsigned char *str = (const unsigned char *) p;
2011 while ((c = *str++) != 0)
2013 if (index_version >= 5)
2015 r = r * 67 + c - 113;
2021 /* Find a slot in the mapped index INDEX for the object named NAME.
2022 If NAME is found, set *VEC_OUT to point to the CU vector in the
2023 constant pool and return 1. If NAME cannot be found, return 0. */
2026 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2027 offset_type **vec_out)
2029 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2031 offset_type slot, step;
2032 int (*cmp) (const char *, const char *);
2034 if (current_language->la_language == language_cplus
2035 || current_language->la_language == language_java
2036 || current_language->la_language == language_fortran)
2038 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2040 const char *paren = strchr (name, '(');
2046 dup = xmalloc (paren - name + 1);
2047 memcpy (dup, name, paren - name);
2048 dup[paren - name] = 0;
2050 make_cleanup (xfree, dup);
2055 /* Index version 4 did not support case insensitive searches. But the
2056 indexes for case insensitive languages are built in lowercase, therefore
2057 simulate our NAME being searched is also lowercased. */
2058 hash = mapped_index_string_hash ((index->version == 4
2059 && case_sensitivity == case_sensitive_off
2060 ? 5 : index->version),
2063 slot = hash & (index->symbol_table_slots - 1);
2064 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2065 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2069 /* Convert a slot number to an offset into the table. */
2070 offset_type i = 2 * slot;
2072 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2074 do_cleanups (back_to);
2078 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2079 if (!cmp (name, str))
2081 *vec_out = (offset_type *) (index->constant_pool
2082 + MAYBE_SWAP (index->symbol_table[i + 1]));
2083 do_cleanups (back_to);
2087 slot = (slot + step) & (index->symbol_table_slots - 1);
2091 /* Read the index file. If everything went ok, initialize the "quick"
2092 elements of all the CUs and return 1. Otherwise, return 0. */
2095 dwarf2_read_index (struct objfile *objfile)
2098 struct mapped_index *map;
2099 offset_type *metadata;
2100 const gdb_byte *cu_list;
2101 const gdb_byte *types_list = NULL;
2102 offset_type version, cu_list_elements;
2103 offset_type types_list_elements = 0;
2106 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2109 /* Older elfutils strip versions could keep the section in the main
2110 executable while splitting it for the separate debug info file. */
2111 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2112 & SEC_HAS_CONTENTS) == 0)
2115 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2117 addr = dwarf2_per_objfile->gdb_index.buffer;
2118 /* Version check. */
2119 version = MAYBE_SWAP (*(offset_type *) addr);
2120 /* Versions earlier than 3 emitted every copy of a psymbol. This
2121 causes the index to behave very poorly for certain requests. Version 3
2122 contained incomplete addrmap. So, it seems better to just ignore such
2123 indices. Index version 4 uses a different hash function than index
2124 version 5 and later. */
2127 /* Indexes with higher version than the one supported by GDB may be no
2128 longer backward compatible. */
2132 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2133 map->version = version;
2134 map->total_size = dwarf2_per_objfile->gdb_index.size;
2136 metadata = (offset_type *) (addr + sizeof (offset_type));
2139 cu_list = addr + MAYBE_SWAP (metadata[i]);
2140 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2144 types_list = addr + MAYBE_SWAP (metadata[i]);
2145 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2146 - MAYBE_SWAP (metadata[i]))
2150 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2151 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2152 - MAYBE_SWAP (metadata[i]));
2155 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2156 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2157 - MAYBE_SWAP (metadata[i]))
2158 / (2 * sizeof (offset_type)));
2161 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2163 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2166 if (types_list_elements)
2168 struct dwarf2_section_info *section;
2170 /* We can only handle a single .debug_types when we have an
2172 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2175 section = VEC_index (dwarf2_section_info_def,
2176 dwarf2_per_objfile->types, 0);
2178 if (!create_signatured_type_table_from_index (objfile, section,
2180 types_list_elements))
2184 create_addrmap_from_index (objfile, map);
2186 dwarf2_per_objfile->index_table = map;
2187 dwarf2_per_objfile->using_index = 1;
2188 dwarf2_per_objfile->quick_file_names_table =
2189 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2194 /* A helper for the "quick" functions which sets the global
2195 dwarf2_per_objfile according to OBJFILE. */
2198 dw2_setup (struct objfile *objfile)
2200 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2201 gdb_assert (dwarf2_per_objfile);
2204 /* A helper for the "quick" functions which attempts to read the line
2205 table for THIS_CU. */
2207 static struct quick_file_names *
2208 dw2_get_file_names (struct objfile *objfile,
2209 struct dwarf2_per_cu_data *this_cu)
2211 bfd *abfd = objfile->obfd;
2212 struct line_header *lh;
2213 struct attribute *attr;
2214 struct cleanup *cleanups;
2215 struct die_info *comp_unit_die;
2216 struct dwarf2_section_info* sec;
2218 int has_children, i;
2219 struct dwarf2_cu cu;
2220 unsigned int bytes_read;
2221 struct die_reader_specs reader_specs;
2222 char *name, *comp_dir;
2224 struct quick_file_names *qfn;
2225 unsigned int line_offset;
2227 if (this_cu->v.quick->file_names != NULL)
2228 return this_cu->v.quick->file_names;
2229 /* If we know there is no line data, no point in looking again. */
2230 if (this_cu->v.quick->no_file_data)
2233 init_one_comp_unit (&cu, this_cu);
2234 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2236 if (this_cu->debug_types_section)
2237 sec = this_cu->debug_types_section;
2239 sec = &dwarf2_per_objfile->info;
2240 dwarf2_read_section (objfile, sec);
2241 info_ptr = sec->buffer + this_cu->offset;
2243 info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr,
2244 this_cu->debug_types_section != NULL);
2246 /* Skip dummy compilation units. */
2247 if (info_ptr >= (sec->buffer + sec->size)
2248 || peek_abbrev_code (abfd, info_ptr) == 0)
2250 do_cleanups (cleanups);
2254 dwarf2_read_abbrevs (&cu);
2255 make_cleanup (dwarf2_free_abbrev_table, &cu);
2257 init_cu_die_reader (&reader_specs, &cu);
2258 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2264 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2267 struct quick_file_names find_entry;
2269 line_offset = DW_UNSND (attr);
2271 /* We may have already read in this line header (TU line header sharing).
2272 If we have we're done. */
2273 find_entry.offset = line_offset;
2274 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2275 &find_entry, INSERT);
2278 do_cleanups (cleanups);
2279 this_cu->v.quick->file_names = *slot;
2283 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2287 do_cleanups (cleanups);
2288 this_cu->v.quick->no_file_data = 1;
2292 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2293 qfn->offset = line_offset;
2294 gdb_assert (slot != NULL);
2297 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2299 qfn->num_file_names = lh->num_file_names;
2300 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2301 lh->num_file_names * sizeof (char *));
2302 for (i = 0; i < lh->num_file_names; ++i)
2303 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2304 qfn->real_names = NULL;
2306 free_line_header (lh);
2307 do_cleanups (cleanups);
2309 this_cu->v.quick->file_names = qfn;
2313 /* A helper for the "quick" functions which computes and caches the
2314 real path for a given file name from the line table. */
2317 dw2_get_real_path (struct objfile *objfile,
2318 struct quick_file_names *qfn, int index)
2320 if (qfn->real_names == NULL)
2321 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2322 qfn->num_file_names, sizeof (char *));
2324 if (qfn->real_names[index] == NULL)
2325 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2327 return qfn->real_names[index];
2330 static struct symtab *
2331 dw2_find_last_source_symtab (struct objfile *objfile)
2335 dw2_setup (objfile);
2336 index = dwarf2_per_objfile->n_comp_units - 1;
2337 return dw2_instantiate_symtab (dw2_get_cu (index));
2340 /* Traversal function for dw2_forget_cached_source_info. */
2343 dw2_free_cached_file_names (void **slot, void *info)
2345 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2347 if (file_data->real_names)
2351 for (i = 0; i < file_data->num_file_names; ++i)
2353 xfree ((void*) file_data->real_names[i]);
2354 file_data->real_names[i] = NULL;
2362 dw2_forget_cached_source_info (struct objfile *objfile)
2364 dw2_setup (objfile);
2366 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2367 dw2_free_cached_file_names, NULL);
2370 /* Helper function for dw2_map_symtabs_matching_filename that expands
2371 the symtabs and calls the iterator. */
2374 dw2_map_expand_apply (struct objfile *objfile,
2375 struct dwarf2_per_cu_data *per_cu,
2377 const char *full_path, const char *real_path,
2378 int (*callback) (struct symtab *, void *),
2381 struct symtab *last_made = objfile->symtabs;
2383 /* Don't visit already-expanded CUs. */
2384 if (per_cu->v.quick->symtab)
2387 /* This may expand more than one symtab, and we want to iterate over
2389 dw2_instantiate_symtab (per_cu);
2391 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
2392 objfile->symtabs, last_made);
2395 /* Implementation of the map_symtabs_matching_filename method. */
2398 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
2399 const char *full_path, const char *real_path,
2400 int (*callback) (struct symtab *, void *),
2404 const char *name_basename = lbasename (name);
2405 int check_basename = name_basename == name;
2406 struct dwarf2_per_cu_data *base_cu = NULL;
2408 dw2_setup (objfile);
2410 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2411 + dwarf2_per_objfile->n_type_units); ++i)
2414 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2415 struct quick_file_names *file_data;
2417 /* We only need to look at symtabs not already expanded. */
2418 if (per_cu->v.quick->symtab)
2421 file_data = dw2_get_file_names (objfile, per_cu);
2422 if (file_data == NULL)
2425 for (j = 0; j < file_data->num_file_names; ++j)
2427 const char *this_name = file_data->file_names[j];
2429 if (FILENAME_CMP (name, this_name) == 0)
2431 if (dw2_map_expand_apply (objfile, per_cu,
2432 name, full_path, real_path,
2437 if (check_basename && ! base_cu
2438 && FILENAME_CMP (lbasename (this_name), name) == 0)
2441 /* Before we invoke realpath, which can get expensive when many
2442 files are involved, do a quick comparison of the basenames. */
2443 if (! basenames_may_differ
2444 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
2447 if (full_path != NULL)
2449 const char *this_real_name = dw2_get_real_path (objfile,
2452 if (this_real_name != NULL
2453 && FILENAME_CMP (full_path, this_real_name) == 0)
2455 if (dw2_map_expand_apply (objfile, per_cu,
2456 name, full_path, real_path,
2462 if (real_path != NULL)
2464 const char *this_real_name = dw2_get_real_path (objfile,
2467 if (this_real_name != NULL
2468 && FILENAME_CMP (real_path, this_real_name) == 0)
2470 if (dw2_map_expand_apply (objfile, per_cu,
2471 name, full_path, real_path,
2481 if (dw2_map_expand_apply (objfile, base_cu,
2482 name, full_path, real_path,
2490 static struct symtab *
2491 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2492 const char *name, domain_enum domain)
2494 /* We do all the work in the pre_expand_symtabs_matching hook
2499 /* A helper function that expands all symtabs that hold an object
2503 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2505 dw2_setup (objfile);
2507 /* index_table is NULL if OBJF_READNOW. */
2508 if (dwarf2_per_objfile->index_table)
2512 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2515 offset_type i, len = MAYBE_SWAP (*vec);
2516 for (i = 0; i < len; ++i)
2518 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2519 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2521 dw2_instantiate_symtab (per_cu);
2528 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2529 enum block_enum block_kind, const char *name,
2532 dw2_do_expand_symtabs_matching (objfile, name);
2536 dw2_print_stats (struct objfile *objfile)
2540 dw2_setup (objfile);
2542 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2543 + dwarf2_per_objfile->n_type_units); ++i)
2545 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2547 if (!per_cu->v.quick->symtab)
2550 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2554 dw2_dump (struct objfile *objfile)
2556 /* Nothing worth printing. */
2560 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2561 struct section_offsets *delta)
2563 /* There's nothing to relocate here. */
2567 dw2_expand_symtabs_for_function (struct objfile *objfile,
2568 const char *func_name)
2570 dw2_do_expand_symtabs_matching (objfile, func_name);
2574 dw2_expand_all_symtabs (struct objfile *objfile)
2578 dw2_setup (objfile);
2580 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2581 + dwarf2_per_objfile->n_type_units); ++i)
2583 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2585 dw2_instantiate_symtab (per_cu);
2590 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2591 const char *filename)
2595 dw2_setup (objfile);
2597 /* We don't need to consider type units here.
2598 This is only called for examining code, e.g. expand_line_sal.
2599 There can be an order of magnitude (or more) more type units
2600 than comp units, and we avoid them if we can. */
2602 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2605 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2606 struct quick_file_names *file_data;
2608 /* We only need to look at symtabs not already expanded. */
2609 if (per_cu->v.quick->symtab)
2612 file_data = dw2_get_file_names (objfile, per_cu);
2613 if (file_data == NULL)
2616 for (j = 0; j < file_data->num_file_names; ++j)
2618 const char *this_name = file_data->file_names[j];
2619 if (FILENAME_CMP (this_name, filename) == 0)
2621 dw2_instantiate_symtab (per_cu);
2629 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2631 struct dwarf2_per_cu_data *per_cu;
2633 struct quick_file_names *file_data;
2635 dw2_setup (objfile);
2637 /* index_table is NULL if OBJF_READNOW. */
2638 if (!dwarf2_per_objfile->index_table)
2642 ALL_OBJFILE_SYMTABS (objfile, s)
2645 struct blockvector *bv = BLOCKVECTOR (s);
2646 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2647 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2650 return sym->symtab->filename;
2655 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2659 /* Note that this just looks at the very first one named NAME -- but
2660 actually we are looking for a function. find_main_filename
2661 should be rewritten so that it doesn't require a custom hook. It
2662 could just use the ordinary symbol tables. */
2663 /* vec[0] is the length, which must always be >0. */
2664 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2666 file_data = dw2_get_file_names (objfile, per_cu);
2667 if (file_data == NULL)
2670 return file_data->file_names[file_data->num_file_names - 1];
2674 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2675 struct objfile *objfile, int global,
2676 int (*callback) (struct block *,
2677 struct symbol *, void *),
2678 void *data, symbol_compare_ftype *match,
2679 symbol_compare_ftype *ordered_compare)
2681 /* Currently unimplemented; used for Ada. The function can be called if the
2682 current language is Ada for a non-Ada objfile using GNU index. As Ada
2683 does not look for non-Ada symbols this function should just return. */
2687 dw2_expand_symtabs_matching
2688 (struct objfile *objfile,
2689 int (*file_matcher) (const char *, void *),
2690 int (*name_matcher) (const struct language_defn *, const char *, void *),
2691 enum search_domain kind,
2696 struct mapped_index *index;
2698 dw2_setup (objfile);
2700 /* index_table is NULL if OBJF_READNOW. */
2701 if (!dwarf2_per_objfile->index_table)
2703 index = dwarf2_per_objfile->index_table;
2705 if (file_matcher != NULL)
2706 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2707 + dwarf2_per_objfile->n_type_units); ++i)
2710 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2711 struct quick_file_names *file_data;
2713 per_cu->v.quick->mark = 0;
2715 /* We only need to look at symtabs not already expanded. */
2716 if (per_cu->v.quick->symtab)
2719 file_data = dw2_get_file_names (objfile, per_cu);
2720 if (file_data == NULL)
2723 for (j = 0; j < file_data->num_file_names; ++j)
2725 if (file_matcher (file_data->file_names[j], data))
2727 per_cu->v.quick->mark = 1;
2733 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2735 offset_type idx = 2 * iter;
2737 offset_type *vec, vec_len, vec_idx;
2739 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2742 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2744 if (! (*name_matcher) (current_language, name, data))
2747 /* The name was matched, now expand corresponding CUs that were
2749 vec = (offset_type *) (index->constant_pool
2750 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2751 vec_len = MAYBE_SWAP (vec[0]);
2752 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2754 struct dwarf2_per_cu_data *per_cu;
2756 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2757 if (file_matcher == NULL || per_cu->v.quick->mark)
2758 dw2_instantiate_symtab (per_cu);
2763 static struct symtab *
2764 dw2_find_pc_sect_symtab (struct objfile *objfile,
2765 struct minimal_symbol *msymbol,
2767 struct obj_section *section,
2770 struct dwarf2_per_cu_data *data;
2772 dw2_setup (objfile);
2774 if (!objfile->psymtabs_addrmap)
2777 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2781 if (warn_if_readin && data->v.quick->symtab)
2782 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2783 paddress (get_objfile_arch (objfile), pc));
2785 return dw2_instantiate_symtab (data);
2789 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2790 void *data, int need_fullname)
2794 dw2_setup (objfile);
2796 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2797 + dwarf2_per_objfile->n_type_units); ++i)
2800 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2801 struct quick_file_names *file_data;
2803 /* We only need to look at symtabs not already expanded. */
2804 if (per_cu->v.quick->symtab)
2807 file_data = dw2_get_file_names (objfile, per_cu);
2808 if (file_data == NULL)
2811 for (j = 0; j < file_data->num_file_names; ++j)
2813 const char *this_real_name;
2816 this_real_name = dw2_get_real_path (objfile, file_data, j);
2818 this_real_name = NULL;
2819 (*fun) (file_data->file_names[j], this_real_name, data);
2825 dw2_has_symbols (struct objfile *objfile)
2830 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2833 dw2_find_last_source_symtab,
2834 dw2_forget_cached_source_info,
2835 dw2_map_symtabs_matching_filename,
2837 dw2_pre_expand_symtabs_matching,
2841 dw2_expand_symtabs_for_function,
2842 dw2_expand_all_symtabs,
2843 dw2_expand_symtabs_with_filename,
2844 dw2_find_symbol_file,
2845 dw2_map_matching_symbols,
2846 dw2_expand_symtabs_matching,
2847 dw2_find_pc_sect_symtab,
2848 dw2_map_symbol_filenames
2851 /* Initialize for reading DWARF for this objfile. Return 0 if this
2852 file will use psymtabs, or 1 if using the GNU index. */
2855 dwarf2_initialize_objfile (struct objfile *objfile)
2857 /* If we're about to read full symbols, don't bother with the
2858 indices. In this case we also don't care if some other debug
2859 format is making psymtabs, because they are all about to be
2861 if ((objfile->flags & OBJF_READNOW))
2865 dwarf2_per_objfile->using_index = 1;
2866 create_all_comp_units (objfile);
2867 create_debug_types_hash_table (objfile);
2868 dwarf2_per_objfile->quick_file_names_table =
2869 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2871 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2872 + dwarf2_per_objfile->n_type_units); ++i)
2874 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2876 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2877 struct dwarf2_per_cu_quick_data);
2880 /* Return 1 so that gdb sees the "quick" functions. However,
2881 these functions will be no-ops because we will have expanded
2886 if (dwarf2_read_index (objfile))
2894 /* Build a partial symbol table. */
2897 dwarf2_build_psymtabs (struct objfile *objfile)
2899 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2901 init_psymbol_list (objfile, 1024);
2904 dwarf2_build_psymtabs_hard (objfile);
2907 /* Return TRUE if OFFSET is within CU_HEADER. */
2910 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2912 unsigned int bottom = cu_header->offset;
2913 unsigned int top = (cu_header->offset
2915 + cu_header->initial_length_size);
2917 return (offset >= bottom && offset < top);
2920 /* Read in the comp unit header information from the debug_info at info_ptr.
2921 NOTE: This leaves members offset, first_die_offset to be filled in
2925 read_comp_unit_head (struct comp_unit_head *cu_header,
2926 gdb_byte *info_ptr, bfd *abfd)
2929 unsigned int bytes_read;
2931 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2932 cu_header->initial_length_size = bytes_read;
2933 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2934 info_ptr += bytes_read;
2935 cu_header->version = read_2_bytes (abfd, info_ptr);
2937 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2939 info_ptr += bytes_read;
2940 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2942 signed_addr = bfd_get_sign_extend_vma (abfd);
2943 if (signed_addr < 0)
2944 internal_error (__FILE__, __LINE__,
2945 _("read_comp_unit_head: dwarf from non elf file"));
2946 cu_header->signed_addr_p = signed_addr;
2951 /* Subroutine of read_and_check_comp_unit_head and
2952 read_and_check_type_unit_head to simplify them.
2953 Perform various error checking on the header. */
2956 error_check_comp_unit_head (struct comp_unit_head *header,
2957 struct dwarf2_section_info *section)
2959 bfd *abfd = section->asection->owner;
2960 const char *filename = bfd_get_filename (abfd);
2962 if (header->version != 2 && header->version != 3 && header->version != 4)
2963 error (_("Dwarf Error: wrong version in compilation unit header "
2964 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2967 if (header->abbrev_offset
2968 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2969 &dwarf2_per_objfile->abbrev))
2970 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2971 "(offset 0x%lx + 6) [in module %s]"),
2972 (long) header->abbrev_offset, (long) header->offset,
2975 /* Cast to unsigned long to use 64-bit arithmetic when possible to
2976 avoid potential 32-bit overflow. */
2977 if (((unsigned long) header->offset
2978 + header->length + header->initial_length_size)
2980 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2981 "(offset 0x%lx + 0) [in module %s]"),
2982 (long) header->length, (long) header->offset,
2986 /* Read in a CU/TU header and perform some basic error checking.
2987 The contents of the header are stored in HEADER.
2988 The result is a pointer to the start of the first DIE. */
2991 read_and_check_comp_unit_head (struct comp_unit_head *header,
2992 struct dwarf2_section_info *section,
2994 int is_debug_types_section)
2996 gdb_byte *beg_of_comp_unit = info_ptr;
2997 bfd *abfd = section->asection->owner;
2999 header->offset = beg_of_comp_unit - section->buffer;
3001 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3003 /* If we're reading a type unit, skip over the signature and
3004 type_offset fields. */
3005 if (is_debug_types_section)
3006 info_ptr += 8 /*signature*/ + header->offset_size;
3008 header->first_die_offset = info_ptr - beg_of_comp_unit;
3010 error_check_comp_unit_head (header, section);
3015 /* Read in the types comp unit header information from .debug_types entry at
3016 types_ptr. The result is a pointer to one past the end of the header. */
3019 read_and_check_type_unit_head (struct comp_unit_head *header,
3020 struct dwarf2_section_info *section,
3022 ULONGEST *signature, unsigned int *type_offset)
3024 gdb_byte *beg_of_comp_unit = info_ptr;
3025 bfd *abfd = section->asection->owner;
3027 header->offset = beg_of_comp_unit - section->buffer;
3029 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3031 /* If we're reading a type unit, skip over the signature and
3032 type_offset fields. */
3033 if (signature != NULL)
3034 *signature = read_8_bytes (abfd, info_ptr);
3036 if (type_offset != NULL)
3037 *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size);
3038 info_ptr += header->offset_size;
3040 header->first_die_offset = info_ptr - beg_of_comp_unit;
3042 error_check_comp_unit_head (header, section);
3047 /* Allocate a new partial symtab for file named NAME and mark this new
3048 partial symtab as being an include of PST. */
3051 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3052 struct objfile *objfile)
3054 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3056 subpst->section_offsets = pst->section_offsets;
3057 subpst->textlow = 0;
3058 subpst->texthigh = 0;
3060 subpst->dependencies = (struct partial_symtab **)
3061 obstack_alloc (&objfile->objfile_obstack,
3062 sizeof (struct partial_symtab *));
3063 subpst->dependencies[0] = pst;
3064 subpst->number_of_dependencies = 1;
3066 subpst->globals_offset = 0;
3067 subpst->n_global_syms = 0;
3068 subpst->statics_offset = 0;
3069 subpst->n_static_syms = 0;
3070 subpst->symtab = NULL;
3071 subpst->read_symtab = pst->read_symtab;
3074 /* No private part is necessary for include psymtabs. This property
3075 can be used to differentiate between such include psymtabs and
3076 the regular ones. */
3077 subpst->read_symtab_private = NULL;
3080 /* Read the Line Number Program data and extract the list of files
3081 included by the source file represented by PST. Build an include
3082 partial symtab for each of these included files. */
3085 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3086 struct die_info *die,
3087 struct partial_symtab *pst)
3089 struct objfile *objfile = cu->objfile;
3090 bfd *abfd = objfile->obfd;
3091 struct line_header *lh = NULL;
3092 struct attribute *attr;
3094 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3097 unsigned int line_offset = DW_UNSND (attr);
3099 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3102 return; /* No linetable, so no includes. */
3104 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3105 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
3107 free_line_header (lh);
3111 hash_type_signature (const void *item)
3113 const struct signatured_type *type_sig = item;
3115 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3116 return type_sig->signature;
3120 eq_type_signature (const void *item_lhs, const void *item_rhs)
3122 const struct signatured_type *lhs = item_lhs;
3123 const struct signatured_type *rhs = item_rhs;
3125 return lhs->signature == rhs->signature;
3128 /* Allocate a hash table for signatured types. */
3131 allocate_signatured_type_table (struct objfile *objfile)
3133 return htab_create_alloc_ex (41,
3134 hash_type_signature,
3137 &objfile->objfile_obstack,
3138 hashtab_obstack_allocate,
3139 dummy_obstack_deallocate);
3142 /* A helper function to add a signatured type CU to a table. */
3145 add_signatured_type_cu_to_table (void **slot, void *datum)
3147 struct signatured_type *sigt = *slot;
3148 struct dwarf2_per_cu_data ***datap = datum;
3150 **datap = &sigt->per_cu;
3156 /* Create the hash table of all entries in the .debug_types section(s).
3157 The result is zero if there is an error (e.g. missing .debug_types section),
3158 otherwise non-zero. */
3161 create_debug_types_hash_table (struct objfile *objfile)
3163 htab_t types_htab = NULL;
3164 struct dwarf2_per_cu_data **iter;
3166 struct dwarf2_section_info *section;
3168 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3170 dwarf2_per_objfile->signatured_types = NULL;
3175 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3179 gdb_byte *info_ptr, *end_ptr;
3181 dwarf2_read_section (objfile, section);
3182 info_ptr = section->buffer;
3184 if (info_ptr == NULL)
3187 if (types_htab == NULL)
3188 types_htab = allocate_signatured_type_table (objfile);
3190 if (dwarf2_die_debug)
3191 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3193 end_ptr = info_ptr + section->size;
3194 while (info_ptr < end_ptr)
3196 unsigned int offset;
3197 unsigned int type_offset;
3199 struct signatured_type *type_sig;
3201 gdb_byte *ptr = info_ptr;
3202 struct comp_unit_head header;
3204 offset = ptr - section->buffer;
3206 /* We need to read the type's signature in order to build the hash
3207 table, but we don't need anything else just yet. */
3209 ptr = read_and_check_type_unit_head (&header, section, ptr,
3210 &signature, &type_offset);
3212 /* Skip dummy type units. */
3213 if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
3215 info_ptr = info_ptr + header.initial_length_size + header.length;
3219 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3220 memset (type_sig, 0, sizeof (*type_sig));
3221 type_sig->signature = signature;
3222 type_sig->type_offset = type_offset;
3223 type_sig->per_cu.objfile = objfile;
3224 type_sig->per_cu.debug_types_section = section;
3225 type_sig->per_cu.offset = offset;
3227 slot = htab_find_slot (types_htab, type_sig, INSERT);
3228 gdb_assert (slot != NULL);
3231 const struct signatured_type *dup_sig = *slot;
3233 complaint (&symfile_complaints,
3234 _("debug type entry at offset 0x%x is duplicate to the "
3235 "entry at offset 0x%x, signature 0x%s"),
3236 offset, dup_sig->per_cu.offset,
3237 phex (signature, sizeof (signature)));
3238 gdb_assert (signature == dup_sig->signature);
3242 if (dwarf2_die_debug)
3243 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3244 offset, phex (signature, sizeof (signature)));
3246 info_ptr = info_ptr + header.initial_length_size + header.length;
3250 dwarf2_per_objfile->signatured_types = types_htab;
3252 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
3253 dwarf2_per_objfile->all_type_units
3254 = obstack_alloc (&objfile->objfile_obstack,
3255 dwarf2_per_objfile->n_type_units
3256 * sizeof (struct dwarf2_per_cu_data *));
3257 iter = &dwarf2_per_objfile->all_type_units[0];
3258 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
3259 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
3260 == dwarf2_per_objfile->n_type_units);
3265 /* Lookup a signature based type.
3266 Returns NULL if SIG is not present in the table. */
3268 static struct signatured_type *
3269 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3271 struct signatured_type find_entry, *entry;
3273 if (dwarf2_per_objfile->signatured_types == NULL)
3275 complaint (&symfile_complaints,
3276 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3280 find_entry.signature = sig;
3281 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3285 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3288 init_cu_die_reader (struct die_reader_specs *reader,
3289 struct dwarf2_cu *cu)
3291 reader->abfd = cu->objfile->obfd;
3293 if (cu->per_cu->debug_types_section)
3295 gdb_assert (cu->per_cu->debug_types_section->readin);
3296 reader->buffer = cu->per_cu->debug_types_section->buffer;
3300 gdb_assert (dwarf2_per_objfile->info.readin);
3301 reader->buffer = dwarf2_per_objfile->info.buffer;
3305 /* Find the base address of the compilation unit for range lists and
3306 location lists. It will normally be specified by DW_AT_low_pc.
3307 In DWARF-3 draft 4, the base address could be overridden by
3308 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3309 compilation units with discontinuous ranges. */
3312 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3314 struct attribute *attr;
3317 cu->base_address = 0;
3319 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3322 cu->base_address = DW_ADDR (attr);
3327 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3330 cu->base_address = DW_ADDR (attr);
3336 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3337 to combine the common parts.
3338 Process compilation unit THIS_CU for a psymtab.
3339 SECTION is the section the CU/TU comes from,
3340 either .debug_info or .debug_types. */
3343 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
3344 struct dwarf2_section_info *section,
3345 int is_debug_types_section)
3347 struct objfile *objfile = this_cu->objfile;
3348 bfd *abfd = objfile->obfd;
3349 gdb_byte *buffer = section->buffer;
3350 gdb_byte *info_ptr = buffer + this_cu->offset;
3351 unsigned int buffer_size = section->size;
3352 gdb_byte *beg_of_comp_unit = info_ptr;
3353 struct die_info *comp_unit_die;
3354 struct partial_symtab *pst;
3356 struct cleanup *back_to_inner;
3357 struct dwarf2_cu cu;
3358 int has_children, has_pc_info;
3359 struct attribute *attr;
3360 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3361 struct die_reader_specs reader_specs;
3362 const char *filename;
3364 /* If this compilation unit was already read in, free the
3365 cached copy in order to read it in again. This is
3366 necessary because we skipped some symbols when we first
3367 read in the compilation unit (see load_partial_dies).
3368 This problem could be avoided, but the benefit is
3370 if (this_cu->cu != NULL)
3371 free_one_cached_comp_unit (this_cu->cu);
3373 /* Note that this is a pointer to our stack frame, being
3374 added to a global data structure. It will be cleaned up
3375 in free_stack_comp_unit when we finish with this
3376 compilation unit. */
3377 init_one_comp_unit (&cu, this_cu);
3378 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3380 info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr,
3381 is_debug_types_section);
3383 /* Skip dummy compilation units. */
3384 if (info_ptr >= buffer + buffer_size
3385 || peek_abbrev_code (abfd, info_ptr) == 0)
3387 do_cleanups (back_to_inner);
3391 cu.list_in_scope = &file_symbols;
3393 /* Read the abbrevs for this compilation unit into a table. */
3394 dwarf2_read_abbrevs (&cu);
3395 make_cleanup (dwarf2_free_abbrev_table, &cu);
3397 /* Read the compilation unit die. */
3398 init_cu_die_reader (&reader_specs, &cu);
3399 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3402 if (is_debug_types_section)
3404 /* LENGTH has not been set yet for type units. */
3405 gdb_assert (this_cu->offset == cu.header.offset);
3406 this_cu->length = cu.header.length + cu.header.initial_length_size;
3408 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3410 do_cleanups (back_to_inner);
3414 prepare_one_comp_unit (&cu, comp_unit_die);
3416 /* Allocate a new partial symbol table structure. */
3417 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3418 if (attr == NULL || !DW_STRING (attr))
3421 filename = DW_STRING (attr);
3422 pst = start_psymtab_common (objfile, objfile->section_offsets,
3424 /* TEXTLOW and TEXTHIGH are set below. */
3426 objfile->global_psymbols.next,
3427 objfile->static_psymbols.next);
3428 pst->psymtabs_addrmap_supported = 1;
3430 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3432 pst->dirname = DW_STRING (attr);
3434 pst->read_symtab_private = this_cu;
3436 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3438 /* Store the function that reads in the rest of the symbol table. */
3439 pst->read_symtab = dwarf2_psymtab_to_symtab;
3441 this_cu->v.psymtab = pst;
3443 dwarf2_find_base_address (comp_unit_die, &cu);
3445 /* Possibly set the default values of LOWPC and HIGHPC from
3447 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3448 &best_highpc, &cu, pst);
3449 if (has_pc_info == 1 && best_lowpc < best_highpc)
3450 /* Store the contiguous range if it is not empty; it can be empty for
3451 CUs with no code. */
3452 addrmap_set_empty (objfile->psymtabs_addrmap,
3453 best_lowpc + baseaddr,
3454 best_highpc + baseaddr - 1, pst);
3456 /* Check if comp unit has_children.
3457 If so, read the rest of the partial symbols from this comp unit.
3458 If not, there's no more debug_info for this comp unit. */
3461 struct partial_die_info *first_die;
3462 CORE_ADDR lowpc, highpc;
3464 lowpc = ((CORE_ADDR) -1);
3465 highpc = ((CORE_ADDR) 0);
3467 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3469 scan_partial_symbols (first_die, &lowpc, &highpc,
3470 ! has_pc_info, &cu);
3472 /* If we didn't find a lowpc, set it to highpc to avoid
3473 complaints from `maint check'. */
3474 if (lowpc == ((CORE_ADDR) -1))
3477 /* If the compilation unit didn't have an explicit address range,
3478 then use the information extracted from its child dies. */
3482 best_highpc = highpc;
3485 pst->textlow = best_lowpc + baseaddr;
3486 pst->texthigh = best_highpc + baseaddr;
3488 pst->n_global_syms = objfile->global_psymbols.next -
3489 (objfile->global_psymbols.list + pst->globals_offset);
3490 pst->n_static_syms = objfile->static_psymbols.next -
3491 (objfile->static_psymbols.list + pst->statics_offset);
3492 sort_pst_symbols (pst);
3494 if (is_debug_types_section)
3496 /* It's not clear we want to do anything with stmt lists here.
3497 Waiting to see what gcc ultimately does. */
3501 /* Get the list of files included in the current compilation unit,
3502 and build a psymtab for each of them. */
3503 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3506 do_cleanups (back_to_inner);
3509 /* Traversal function for htab_traverse_noresize.
3510 Process one .debug_types comp-unit. */
3513 process_type_comp_unit (void **slot, void *info)
3515 struct signatured_type *entry = (struct signatured_type *) *slot;
3516 struct dwarf2_per_cu_data *this_cu;
3518 gdb_assert (info == NULL);
3519 this_cu = &entry->per_cu;
3521 gdb_assert (this_cu->debug_types_section->readin);
3522 process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1);
3527 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3528 Build partial symbol tables for the .debug_types comp-units. */
3531 build_type_psymtabs (struct objfile *objfile)
3533 if (! create_debug_types_hash_table (objfile))
3536 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3537 process_type_comp_unit, NULL);
3540 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3543 psymtabs_addrmap_cleanup (void *o)
3545 struct objfile *objfile = o;
3547 objfile->psymtabs_addrmap = NULL;
3550 /* Build the partial symbol table by doing a quick pass through the
3551 .debug_info and .debug_abbrev sections. */
3554 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3556 struct cleanup *back_to, *addrmap_cleanup;
3557 struct obstack temp_obstack;
3560 dwarf2_per_objfile->reading_partial_symbols = 1;
3562 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3564 /* Any cached compilation units will be linked by the per-objfile
3565 read_in_chain. Make sure to free them when we're done. */
3566 back_to = make_cleanup (free_cached_comp_units, NULL);
3568 build_type_psymtabs (objfile);
3570 create_all_comp_units (objfile);
3572 /* Create a temporary address map on a temporary obstack. We later
3573 copy this to the final obstack. */
3574 obstack_init (&temp_obstack);
3575 make_cleanup_obstack_free (&temp_obstack);
3576 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3577 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3579 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3581 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3583 process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0);
3586 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3587 &objfile->objfile_obstack);
3588 discard_cleanups (addrmap_cleanup);
3590 do_cleanups (back_to);
3593 /* Load the partial DIEs for a secondary CU into memory. */
3596 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
3598 struct objfile *objfile = this_cu->objfile;
3599 bfd *abfd = objfile->obfd;
3601 struct die_info *comp_unit_die;
3602 struct dwarf2_cu *cu;
3603 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3605 struct die_reader_specs reader_specs;
3607 struct dwarf2_section_info *section = &dwarf2_per_objfile->info;
3609 gdb_assert (! this_cu->debug_types_section);
3611 gdb_assert (section->readin);
3612 info_ptr = section->buffer + this_cu->offset;
3614 if (this_cu->cu == NULL)
3616 cu = xmalloc (sizeof (*cu));
3617 init_one_comp_unit (cu, this_cu);
3621 /* If an error occurs while loading, release our storage. */
3622 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
3624 info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr,
3627 /* Skip dummy compilation units. */
3628 if (info_ptr >= (section->buffer + section->size)
3629 || peek_abbrev_code (abfd, info_ptr) == 0)
3631 do_cleanups (free_cu_cleanup);
3635 /* Link this CU into read_in_chain. */
3636 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3637 dwarf2_per_objfile->read_in_chain = this_cu;
3642 info_ptr += cu->header.first_die_offset;
3645 /* Read the abbrevs for this compilation unit into a table. */
3646 gdb_assert (cu->dwarf2_abbrevs == NULL);
3647 dwarf2_read_abbrevs (cu);
3648 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3650 /* Read the compilation unit die. */
3651 init_cu_die_reader (&reader_specs, cu);
3652 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3655 prepare_one_comp_unit (cu, comp_unit_die);
3657 /* Check if comp unit has_children.
3658 If so, read the rest of the partial symbols from this comp unit.
3659 If not, there's no more debug_info for this comp unit. */
3661 load_partial_dies (abfd, section->buffer, info_ptr, 0, cu);
3663 do_cleanups (free_abbrevs_cleanup);
3667 /* We've successfully allocated this compilation unit. Let our
3668 caller clean it up when finished with it. */
3669 discard_cleanups (free_cu_cleanup);
3673 /* Create a list of all compilation units in OBJFILE.
3674 This is only done for -readnow and building partial symtabs. */
3677 create_all_comp_units (struct objfile *objfile)
3681 struct dwarf2_per_cu_data **all_comp_units;
3684 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3685 info_ptr = dwarf2_per_objfile->info.buffer;
3689 all_comp_units = xmalloc (n_allocated
3690 * sizeof (struct dwarf2_per_cu_data *));
3692 while (info_ptr < dwarf2_per_objfile->info.buffer
3693 + dwarf2_per_objfile->info.size)
3695 unsigned int length, initial_length_size;
3696 struct dwarf2_per_cu_data *this_cu;
3697 unsigned int offset;
3699 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3701 /* Read just enough information to find out where the next
3702 compilation unit is. */
3703 length = read_initial_length (objfile->obfd, info_ptr,
3704 &initial_length_size);
3706 /* Save the compilation unit for later lookup. */
3707 this_cu = obstack_alloc (&objfile->objfile_obstack,
3708 sizeof (struct dwarf2_per_cu_data));
3709 memset (this_cu, 0, sizeof (*this_cu));
3710 this_cu->offset = offset;
3711 this_cu->length = length + initial_length_size;
3712 this_cu->objfile = objfile;
3714 if (n_comp_units == n_allocated)
3717 all_comp_units = xrealloc (all_comp_units,
3719 * sizeof (struct dwarf2_per_cu_data *));
3721 all_comp_units[n_comp_units++] = this_cu;
3723 info_ptr = info_ptr + this_cu->length;
3726 dwarf2_per_objfile->all_comp_units
3727 = obstack_alloc (&objfile->objfile_obstack,
3728 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3729 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3730 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3731 xfree (all_comp_units);
3732 dwarf2_per_objfile->n_comp_units = n_comp_units;
3735 /* Process all loaded DIEs for compilation unit CU, starting at
3736 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3737 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3738 DW_AT_ranges). If NEED_PC is set, then this function will set
3739 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3740 and record the covered ranges in the addrmap. */
3743 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3744 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3746 struct partial_die_info *pdi;
3748 /* Now, march along the PDI's, descending into ones which have
3749 interesting children but skipping the children of the other ones,
3750 until we reach the end of the compilation unit. */
3756 fixup_partial_die (pdi, cu);
3758 /* Anonymous namespaces or modules have no name but have interesting
3759 children, so we need to look at them. Ditto for anonymous
3762 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3763 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3767 case DW_TAG_subprogram:
3768 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3770 case DW_TAG_constant:
3771 case DW_TAG_variable:
3772 case DW_TAG_typedef:
3773 case DW_TAG_union_type:
3774 if (!pdi->is_declaration)
3776 add_partial_symbol (pdi, cu);
3779 case DW_TAG_class_type:
3780 case DW_TAG_interface_type:
3781 case DW_TAG_structure_type:
3782 if (!pdi->is_declaration)
3784 add_partial_symbol (pdi, cu);
3787 case DW_TAG_enumeration_type:
3788 if (!pdi->is_declaration)
3789 add_partial_enumeration (pdi, cu);
3791 case DW_TAG_base_type:
3792 case DW_TAG_subrange_type:
3793 /* File scope base type definitions are added to the partial
3795 add_partial_symbol (pdi, cu);
3797 case DW_TAG_namespace:
3798 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3801 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3808 /* If the die has a sibling, skip to the sibling. */
3810 pdi = pdi->die_sibling;
3814 /* Functions used to compute the fully scoped name of a partial DIE.
3816 Normally, this is simple. For C++, the parent DIE's fully scoped
3817 name is concatenated with "::" and the partial DIE's name. For
3818 Java, the same thing occurs except that "." is used instead of "::".
3819 Enumerators are an exception; they use the scope of their parent
3820 enumeration type, i.e. the name of the enumeration type is not
3821 prepended to the enumerator.
3823 There are two complexities. One is DW_AT_specification; in this
3824 case "parent" means the parent of the target of the specification,
3825 instead of the direct parent of the DIE. The other is compilers
3826 which do not emit DW_TAG_namespace; in this case we try to guess
3827 the fully qualified name of structure types from their members'
3828 linkage names. This must be done using the DIE's children rather
3829 than the children of any DW_AT_specification target. We only need
3830 to do this for structures at the top level, i.e. if the target of
3831 any DW_AT_specification (if any; otherwise the DIE itself) does not
3834 /* Compute the scope prefix associated with PDI's parent, in
3835 compilation unit CU. The result will be allocated on CU's
3836 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3837 field. NULL is returned if no prefix is necessary. */
3839 partial_die_parent_scope (struct partial_die_info *pdi,
3840 struct dwarf2_cu *cu)
3842 char *grandparent_scope;
3843 struct partial_die_info *parent, *real_pdi;
3845 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3846 then this means the parent of the specification DIE. */
3849 while (real_pdi->has_specification)
3850 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3852 parent = real_pdi->die_parent;
3856 if (parent->scope_set)
3857 return parent->scope;
3859 fixup_partial_die (parent, cu);
3861 grandparent_scope = partial_die_parent_scope (parent, cu);
3863 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3864 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3865 Work around this problem here. */
3866 if (cu->language == language_cplus
3867 && parent->tag == DW_TAG_namespace
3868 && strcmp (parent->name, "::") == 0
3869 && grandparent_scope == NULL)
3871 parent->scope = NULL;
3872 parent->scope_set = 1;
3876 if (pdi->tag == DW_TAG_enumerator)
3877 /* Enumerators should not get the name of the enumeration as a prefix. */
3878 parent->scope = grandparent_scope;
3879 else if (parent->tag == DW_TAG_namespace
3880 || parent->tag == DW_TAG_module
3881 || parent->tag == DW_TAG_structure_type
3882 || parent->tag == DW_TAG_class_type
3883 || parent->tag == DW_TAG_interface_type
3884 || parent->tag == DW_TAG_union_type
3885 || parent->tag == DW_TAG_enumeration_type)
3887 if (grandparent_scope == NULL)
3888 parent->scope = parent->name;
3890 parent->scope = typename_concat (&cu->comp_unit_obstack,
3892 parent->name, 0, cu);
3896 /* FIXME drow/2004-04-01: What should we be doing with
3897 function-local names? For partial symbols, we should probably be
3899 complaint (&symfile_complaints,
3900 _("unhandled containing DIE tag %d for DIE at %d"),
3901 parent->tag, pdi->offset);
3902 parent->scope = grandparent_scope;
3905 parent->scope_set = 1;
3906 return parent->scope;
3909 /* Return the fully scoped name associated with PDI, from compilation unit
3910 CU. The result will be allocated with malloc. */
3912 partial_die_full_name (struct partial_die_info *pdi,
3913 struct dwarf2_cu *cu)
3917 /* If this is a template instantiation, we can not work out the
3918 template arguments from partial DIEs. So, unfortunately, we have
3919 to go through the full DIEs. At least any work we do building
3920 types here will be reused if full symbols are loaded later. */
3921 if (pdi->has_template_arguments)
3923 fixup_partial_die (pdi, cu);
3925 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3927 struct die_info *die;
3928 struct attribute attr;
3929 struct dwarf2_cu *ref_cu = cu;
3932 attr.form = DW_FORM_ref_addr;
3933 attr.u.addr = pdi->offset;
3934 die = follow_die_ref (NULL, &attr, &ref_cu);
3936 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3940 parent_scope = partial_die_parent_scope (pdi, cu);
3941 if (parent_scope == NULL)
3944 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3948 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3950 struct objfile *objfile = cu->objfile;
3952 char *actual_name = NULL;
3953 const struct partial_symbol *psym = NULL;
3955 int built_actual_name = 0;
3957 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3959 actual_name = partial_die_full_name (pdi, cu);
3961 built_actual_name = 1;
3963 if (actual_name == NULL)
3964 actual_name = pdi->name;
3968 case DW_TAG_subprogram:
3969 if (pdi->is_external || cu->language == language_ada)
3971 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3972 of the global scope. But in Ada, we want to be able to access
3973 nested procedures globally. So all Ada subprograms are stored
3974 in the global scope. */
3975 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3976 mst_text, objfile); */
3977 add_psymbol_to_list (actual_name, strlen (actual_name),
3979 VAR_DOMAIN, LOC_BLOCK,
3980 &objfile->global_psymbols,
3981 0, pdi->lowpc + baseaddr,
3982 cu->language, objfile);
3986 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3987 mst_file_text, objfile); */
3988 add_psymbol_to_list (actual_name, strlen (actual_name),
3990 VAR_DOMAIN, LOC_BLOCK,
3991 &objfile->static_psymbols,
3992 0, pdi->lowpc + baseaddr,
3993 cu->language, objfile);
3996 case DW_TAG_constant:
3998 struct psymbol_allocation_list *list;
4000 if (pdi->is_external)
4001 list = &objfile->global_psymbols;
4003 list = &objfile->static_psymbols;
4004 add_psymbol_to_list (actual_name, strlen (actual_name),
4005 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4006 list, 0, 0, cu->language, objfile);
4009 case DW_TAG_variable:
4011 addr = decode_locdesc (pdi->locdesc, cu);
4015 && !dwarf2_per_objfile->has_section_at_zero)
4017 /* A global or static variable may also have been stripped
4018 out by the linker if unused, in which case its address
4019 will be nullified; do not add such variables into partial
4020 symbol table then. */
4022 else if (pdi->is_external)
4025 Don't enter into the minimal symbol tables as there is
4026 a minimal symbol table entry from the ELF symbols already.
4027 Enter into partial symbol table if it has a location
4028 descriptor or a type.
4029 If the location descriptor is missing, new_symbol will create
4030 a LOC_UNRESOLVED symbol, the address of the variable will then
4031 be determined from the minimal symbol table whenever the variable
4033 The address for the partial symbol table entry is not
4034 used by GDB, but it comes in handy for debugging partial symbol
4037 if (pdi->locdesc || pdi->has_type)
4038 add_psymbol_to_list (actual_name, strlen (actual_name),
4040 VAR_DOMAIN, LOC_STATIC,
4041 &objfile->global_psymbols,
4043 cu->language, objfile);
4047 /* Static Variable. Skip symbols without location descriptors. */
4048 if (pdi->locdesc == NULL)
4050 if (built_actual_name)
4051 xfree (actual_name);
4054 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4055 mst_file_data, objfile); */
4056 add_psymbol_to_list (actual_name, strlen (actual_name),
4058 VAR_DOMAIN, LOC_STATIC,
4059 &objfile->static_psymbols,
4061 cu->language, objfile);
4064 case DW_TAG_typedef:
4065 case DW_TAG_base_type:
4066 case DW_TAG_subrange_type:
4067 add_psymbol_to_list (actual_name, strlen (actual_name),
4069 VAR_DOMAIN, LOC_TYPEDEF,
4070 &objfile->static_psymbols,
4071 0, (CORE_ADDR) 0, cu->language, objfile);
4073 case DW_TAG_namespace:
4074 add_psymbol_to_list (actual_name, strlen (actual_name),
4076 VAR_DOMAIN, LOC_TYPEDEF,
4077 &objfile->global_psymbols,
4078 0, (CORE_ADDR) 0, cu->language, objfile);
4080 case DW_TAG_class_type:
4081 case DW_TAG_interface_type:
4082 case DW_TAG_structure_type:
4083 case DW_TAG_union_type:
4084 case DW_TAG_enumeration_type:
4085 /* Skip external references. The DWARF standard says in the section
4086 about "Structure, Union, and Class Type Entries": "An incomplete
4087 structure, union or class type is represented by a structure,
4088 union or class entry that does not have a byte size attribute
4089 and that has a DW_AT_declaration attribute." */
4090 if (!pdi->has_byte_size && pdi->is_declaration)
4092 if (built_actual_name)
4093 xfree (actual_name);
4097 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4098 static vs. global. */
4099 add_psymbol_to_list (actual_name, strlen (actual_name),
4101 STRUCT_DOMAIN, LOC_TYPEDEF,
4102 (cu->language == language_cplus
4103 || cu->language == language_java)
4104 ? &objfile->global_psymbols
4105 : &objfile->static_psymbols,
4106 0, (CORE_ADDR) 0, cu->language, objfile);
4109 case DW_TAG_enumerator:
4110 add_psymbol_to_list (actual_name, strlen (actual_name),
4112 VAR_DOMAIN, LOC_CONST,
4113 (cu->language == language_cplus
4114 || cu->language == language_java)
4115 ? &objfile->global_psymbols
4116 : &objfile->static_psymbols,
4117 0, (CORE_ADDR) 0, cu->language, objfile);
4123 if (built_actual_name)
4124 xfree (actual_name);
4127 /* Read a partial die corresponding to a namespace; also, add a symbol
4128 corresponding to that namespace to the symbol table. NAMESPACE is
4129 the name of the enclosing namespace. */
4132 add_partial_namespace (struct partial_die_info *pdi,
4133 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4134 int need_pc, struct dwarf2_cu *cu)
4136 /* Add a symbol for the namespace. */
4138 add_partial_symbol (pdi, cu);
4140 /* Now scan partial symbols in that namespace. */
4142 if (pdi->has_children)
4143 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4146 /* Read a partial die corresponding to a Fortran module. */
4149 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4150 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4152 /* Now scan partial symbols in that module. */
4154 if (pdi->has_children)
4155 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4158 /* Read a partial die corresponding to a subprogram and create a partial
4159 symbol for that subprogram. When the CU language allows it, this
4160 routine also defines a partial symbol for each nested subprogram
4161 that this subprogram contains.
4163 DIE my also be a lexical block, in which case we simply search
4164 recursively for suprograms defined inside that lexical block.
4165 Again, this is only performed when the CU language allows this
4166 type of definitions. */
4169 add_partial_subprogram (struct partial_die_info *pdi,
4170 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4171 int need_pc, struct dwarf2_cu *cu)
4173 if (pdi->tag == DW_TAG_subprogram)
4175 if (pdi->has_pc_info)
4177 if (pdi->lowpc < *lowpc)
4178 *lowpc = pdi->lowpc;
4179 if (pdi->highpc > *highpc)
4180 *highpc = pdi->highpc;
4184 struct objfile *objfile = cu->objfile;
4186 baseaddr = ANOFFSET (objfile->section_offsets,
4187 SECT_OFF_TEXT (objfile));
4188 addrmap_set_empty (objfile->psymtabs_addrmap,
4189 pdi->lowpc + baseaddr,
4190 pdi->highpc - 1 + baseaddr,
4191 cu->per_cu->v.psymtab);
4193 if (!pdi->is_declaration)
4194 /* Ignore subprogram DIEs that do not have a name, they are
4195 illegal. Do not emit a complaint at this point, we will
4196 do so when we convert this psymtab into a symtab. */
4198 add_partial_symbol (pdi, cu);
4202 if (! pdi->has_children)
4205 if (cu->language == language_ada)
4207 pdi = pdi->die_child;
4210 fixup_partial_die (pdi, cu);
4211 if (pdi->tag == DW_TAG_subprogram
4212 || pdi->tag == DW_TAG_lexical_block)
4213 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4214 pdi = pdi->die_sibling;
4219 /* Read a partial die corresponding to an enumeration type. */
4222 add_partial_enumeration (struct partial_die_info *enum_pdi,
4223 struct dwarf2_cu *cu)
4225 struct partial_die_info *pdi;
4227 if (enum_pdi->name != NULL)
4228 add_partial_symbol (enum_pdi, cu);
4230 pdi = enum_pdi->die_child;
4233 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4234 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4236 add_partial_symbol (pdi, cu);
4237 pdi = pdi->die_sibling;
4241 /* Return the initial uleb128 in the die at INFO_PTR. */
4244 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
4246 unsigned int bytes_read;
4248 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4251 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4252 Return the corresponding abbrev, or NULL if the number is zero (indicating
4253 an empty DIE). In either case *BYTES_READ will be set to the length of
4254 the initial number. */
4256 static struct abbrev_info *
4257 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4258 struct dwarf2_cu *cu)
4260 bfd *abfd = cu->objfile->obfd;
4261 unsigned int abbrev_number;
4262 struct abbrev_info *abbrev;
4264 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4266 if (abbrev_number == 0)
4269 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4272 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4273 abbrev_number, bfd_get_filename (abfd));
4279 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4280 Returns a pointer to the end of a series of DIEs, terminated by an empty
4281 DIE. Any children of the skipped DIEs will also be skipped. */
4284 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4286 struct abbrev_info *abbrev;
4287 unsigned int bytes_read;
4291 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4293 return info_ptr + bytes_read;
4295 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4299 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4300 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4301 abbrev corresponding to that skipped uleb128 should be passed in
4302 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4306 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4307 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4309 unsigned int bytes_read;
4310 struct attribute attr;
4311 bfd *abfd = cu->objfile->obfd;
4312 unsigned int form, i;
4314 for (i = 0; i < abbrev->num_attrs; i++)
4316 /* The only abbrev we care about is DW_AT_sibling. */
4317 if (abbrev->attrs[i].name == DW_AT_sibling)
4319 read_attribute (&attr, &abbrev->attrs[i],
4320 abfd, info_ptr, cu);
4321 if (attr.form == DW_FORM_ref_addr)
4322 complaint (&symfile_complaints,
4323 _("ignoring absolute DW_AT_sibling"));
4325 return buffer + dwarf2_get_ref_die_offset (&attr);
4328 /* If it isn't DW_AT_sibling, skip this attribute. */
4329 form = abbrev->attrs[i].form;
4333 case DW_FORM_ref_addr:
4334 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4335 and later it is offset sized. */
4336 if (cu->header.version == 2)
4337 info_ptr += cu->header.addr_size;
4339 info_ptr += cu->header.offset_size;
4342 info_ptr += cu->header.addr_size;
4349 case DW_FORM_flag_present:
4361 case DW_FORM_ref_sig8:
4364 case DW_FORM_string:
4365 read_direct_string (abfd, info_ptr, &bytes_read);
4366 info_ptr += bytes_read;
4368 case DW_FORM_sec_offset:
4370 info_ptr += cu->header.offset_size;
4372 case DW_FORM_exprloc:
4374 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4375 info_ptr += bytes_read;
4377 case DW_FORM_block1:
4378 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4380 case DW_FORM_block2:
4381 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4383 case DW_FORM_block4:
4384 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4388 case DW_FORM_ref_udata:
4389 info_ptr = skip_leb128 (abfd, info_ptr);
4391 case DW_FORM_indirect:
4392 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4393 info_ptr += bytes_read;
4394 /* We need to continue parsing from here, so just go back to
4396 goto skip_attribute;
4399 error (_("Dwarf Error: Cannot handle %s "
4400 "in DWARF reader [in module %s]"),
4401 dwarf_form_name (form),
4402 bfd_get_filename (abfd));
4406 if (abbrev->has_children)
4407 return skip_children (buffer, info_ptr, cu);
4412 /* Locate ORIG_PDI's sibling.
4413 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4417 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4418 gdb_byte *buffer, gdb_byte *info_ptr,
4419 bfd *abfd, struct dwarf2_cu *cu)
4421 /* Do we know the sibling already? */
4423 if (orig_pdi->sibling)
4424 return orig_pdi->sibling;
4426 /* Are there any children to deal with? */
4428 if (!orig_pdi->has_children)
4431 /* Skip the children the long way. */
4433 return skip_children (buffer, info_ptr, cu);
4436 /* Expand this partial symbol table into a full symbol table. */
4439 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4445 warning (_("bug: psymtab for %s is already read in."),
4452 printf_filtered (_("Reading in symbols for %s..."),
4454 gdb_flush (gdb_stdout);
4457 /* Restore our global data. */
4458 dwarf2_per_objfile = objfile_data (pst->objfile,
4459 dwarf2_objfile_data_key);
4461 /* If this psymtab is constructed from a debug-only objfile, the
4462 has_section_at_zero flag will not necessarily be correct. We
4463 can get the correct value for this flag by looking at the data
4464 associated with the (presumably stripped) associated objfile. */
4465 if (pst->objfile->separate_debug_objfile_backlink)
4467 struct dwarf2_per_objfile *dpo_backlink
4468 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4469 dwarf2_objfile_data_key);
4471 dwarf2_per_objfile->has_section_at_zero
4472 = dpo_backlink->has_section_at_zero;
4475 dwarf2_per_objfile->reading_partial_symbols = 0;
4477 psymtab_to_symtab_1 (pst);
4479 /* Finish up the debug error message. */
4481 printf_filtered (_("done.\n"));
4486 /* Reading in full CUs. */
4488 /* Add PER_CU to the queue. */
4491 queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
4493 struct dwarf2_queue_item *item;
4496 item = xmalloc (sizeof (*item));
4497 item->per_cu = per_cu;
4500 if (dwarf2_queue == NULL)
4501 dwarf2_queue = item;
4503 dwarf2_queue_tail->next = item;
4505 dwarf2_queue_tail = item;
4508 /* Process the queue. */
4511 process_queue (void)
4513 struct dwarf2_queue_item *item, *next_item;
4515 /* The queue starts out with one item, but following a DIE reference
4516 may load a new CU, adding it to the end of the queue. */
4517 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4519 if (dwarf2_per_objfile->using_index
4520 ? !item->per_cu->v.quick->symtab
4521 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4522 process_full_comp_unit (item->per_cu);
4524 item->per_cu->queued = 0;
4525 next_item = item->next;
4529 dwarf2_queue_tail = NULL;
4532 /* Free all allocated queue entries. This function only releases anything if
4533 an error was thrown; if the queue was processed then it would have been
4534 freed as we went along. */
4537 dwarf2_release_queue (void *dummy)
4539 struct dwarf2_queue_item *item, *last;
4541 item = dwarf2_queue;
4544 /* Anything still marked queued is likely to be in an
4545 inconsistent state, so discard it. */
4546 if (item->per_cu->queued)
4548 if (item->per_cu->cu != NULL)
4549 free_one_cached_comp_unit (item->per_cu->cu);
4550 item->per_cu->queued = 0;
4558 dwarf2_queue = dwarf2_queue_tail = NULL;
4561 /* Read in full symbols for PST, and anything it depends on. */
4564 psymtab_to_symtab_1 (struct partial_symtab *pst)
4566 struct dwarf2_per_cu_data *per_cu;
4567 struct cleanup *back_to;
4570 for (i = 0; i < pst->number_of_dependencies; i++)
4571 if (!pst->dependencies[i]->readin)
4573 /* Inform about additional files that need to be read in. */
4576 /* FIXME: i18n: Need to make this a single string. */
4577 fputs_filtered (" ", gdb_stdout);
4579 fputs_filtered ("and ", gdb_stdout);
4581 printf_filtered ("%s...", pst->dependencies[i]->filename);
4582 wrap_here (""); /* Flush output. */
4583 gdb_flush (gdb_stdout);
4585 psymtab_to_symtab_1 (pst->dependencies[i]);
4588 per_cu = pst->read_symtab_private;
4592 /* It's an include file, no symbols to read for it.
4593 Everything is in the parent symtab. */
4598 dw2_do_instantiate_symtab (per_cu);
4601 /* Load the DIEs associated with PER_CU into memory. */
4604 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4606 struct objfile *objfile = per_cu->objfile;
4607 bfd *abfd = objfile->obfd;
4608 struct dwarf2_cu *cu;
4609 unsigned int offset;
4610 gdb_byte *info_ptr, *beg_of_comp_unit;
4611 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4612 struct attribute *attr;
4615 gdb_assert (! per_cu->debug_types_section);
4617 /* Set local variables from the partial symbol table info. */
4618 offset = per_cu->offset;
4620 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4621 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4622 beg_of_comp_unit = info_ptr;
4624 if (per_cu->cu == NULL)
4626 cu = xmalloc (sizeof (*cu));
4627 init_one_comp_unit (cu, per_cu);
4631 /* If an error occurs while loading, release our storage. */
4632 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4634 /* Read in the comp_unit header. */
4635 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4637 /* Skip dummy compilation units. */
4638 if (info_ptr >= (dwarf2_per_objfile->info.buffer
4639 + dwarf2_per_objfile->info.size)
4640 || peek_abbrev_code (abfd, info_ptr) == 0)
4642 do_cleanups (free_cu_cleanup);
4646 /* Complete the cu_header. */
4647 cu->header.offset = offset;
4648 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4650 /* Read the abbrevs for this compilation unit. */
4651 dwarf2_read_abbrevs (cu);
4652 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4654 /* Link this CU into read_in_chain. */
4655 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4656 dwarf2_per_objfile->read_in_chain = per_cu;
4661 info_ptr += cu->header.first_die_offset;
4664 cu->dies = read_comp_unit (info_ptr, cu);
4666 /* We try not to read any attributes in this function, because not
4667 all CUs needed for references have been loaded yet, and symbol
4668 table processing isn't initialized. But we have to set the CU language,
4669 or we won't be able to build types correctly. */
4670 prepare_one_comp_unit (cu, cu->dies);
4672 /* Similarly, if we do not read the producer, we can not apply
4673 producer-specific interpretation. */
4674 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4676 cu->producer = DW_STRING (attr);
4680 do_cleanups (free_abbrevs_cleanup);
4682 /* We've successfully allocated this compilation unit. Let our
4683 caller clean it up when finished with it. */
4684 discard_cleanups (free_cu_cleanup);
4688 /* Add a DIE to the delayed physname list. */
4691 add_to_method_list (struct type *type, int fnfield_index, int index,
4692 const char *name, struct die_info *die,
4693 struct dwarf2_cu *cu)
4695 struct delayed_method_info mi;
4697 mi.fnfield_index = fnfield_index;
4701 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4704 /* A cleanup for freeing the delayed method list. */
4707 free_delayed_list (void *ptr)
4709 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4710 if (cu->method_list != NULL)
4712 VEC_free (delayed_method_info, cu->method_list);
4713 cu->method_list = NULL;
4717 /* Compute the physnames of any methods on the CU's method list.
4719 The computation of method physnames is delayed in order to avoid the
4720 (bad) condition that one of the method's formal parameters is of an as yet
4724 compute_delayed_physnames (struct dwarf2_cu *cu)
4727 struct delayed_method_info *mi;
4728 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4730 const char *physname;
4731 struct fn_fieldlist *fn_flp
4732 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4733 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4734 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4738 /* Generate full symbol information for PER_CU, whose DIEs have
4739 already been loaded into memory. */
4742 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4744 struct dwarf2_cu *cu = per_cu->cu;
4745 struct objfile *objfile = per_cu->objfile;
4746 CORE_ADDR lowpc, highpc;
4747 struct symtab *symtab;
4748 struct cleanup *back_to, *delayed_list_cleanup;
4751 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4754 back_to = make_cleanup (really_free_pendings, NULL);
4755 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4757 cu->list_in_scope = &file_symbols;
4759 /* Do line number decoding in read_file_scope () */
4760 process_die (cu->dies, cu);
4762 /* Now that we have processed all the DIEs in the CU, all the types
4763 should be complete, and it should now be safe to compute all of the
4765 compute_delayed_physnames (cu);
4766 do_cleanups (delayed_list_cleanup);
4768 /* Some compilers don't define a DW_AT_high_pc attribute for the
4769 compilation unit. If the DW_AT_high_pc is missing, synthesize
4770 it, by scanning the DIE's below the compilation unit. */
4771 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4773 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4777 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4779 /* Set symtab language to language from DW_AT_language. If the
4780 compilation is from a C file generated by language preprocessors, do
4781 not set the language if it was already deduced by start_subfile. */
4782 if (!(cu->language == language_c && symtab->language != language_c))
4783 symtab->language = cu->language;
4785 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4786 produce DW_AT_location with location lists but it can be possibly
4787 invalid without -fvar-tracking.
4789 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4790 needed, it would be wrong due to missing DW_AT_producer there.
4792 Still one can confuse GDB by using non-standard GCC compilation
4793 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4795 if (cu->has_loclist && gcc_4_minor >= 0)
4796 symtab->locations_valid = 1;
4798 if (gcc_4_minor >= 5)
4799 symtab->epilogue_unwind_valid = 1;
4801 symtab->call_site_htab = cu->call_site_htab;
4804 if (dwarf2_per_objfile->using_index)
4805 per_cu->v.quick->symtab = symtab;
4808 struct partial_symtab *pst = per_cu->v.psymtab;
4809 pst->symtab = symtab;
4813 do_cleanups (back_to);
4816 /* Process a die and its children. */
4819 process_die (struct die_info *die, struct dwarf2_cu *cu)
4823 case DW_TAG_padding:
4825 case DW_TAG_compile_unit:
4826 read_file_scope (die, cu);
4828 case DW_TAG_type_unit:
4829 read_type_unit_scope (die, cu);
4831 case DW_TAG_subprogram:
4832 case DW_TAG_inlined_subroutine:
4833 read_func_scope (die, cu);
4835 case DW_TAG_lexical_block:
4836 case DW_TAG_try_block:
4837 case DW_TAG_catch_block:
4838 read_lexical_block_scope (die, cu);
4840 case DW_TAG_GNU_call_site:
4841 read_call_site_scope (die, cu);
4843 case DW_TAG_class_type:
4844 case DW_TAG_interface_type:
4845 case DW_TAG_structure_type:
4846 case DW_TAG_union_type:
4847 process_structure_scope (die, cu);
4849 case DW_TAG_enumeration_type:
4850 process_enumeration_scope (die, cu);
4853 /* These dies have a type, but processing them does not create
4854 a symbol or recurse to process the children. Therefore we can
4855 read them on-demand through read_type_die. */
4856 case DW_TAG_subroutine_type:
4857 case DW_TAG_set_type:
4858 case DW_TAG_array_type:
4859 case DW_TAG_pointer_type:
4860 case DW_TAG_ptr_to_member_type:
4861 case DW_TAG_reference_type:
4862 case DW_TAG_string_type:
4865 case DW_TAG_base_type:
4866 case DW_TAG_subrange_type:
4867 case DW_TAG_typedef:
4868 /* Add a typedef symbol for the type definition, if it has a
4870 new_symbol (die, read_type_die (die, cu), cu);
4872 case DW_TAG_common_block:
4873 read_common_block (die, cu);
4875 case DW_TAG_common_inclusion:
4877 case DW_TAG_namespace:
4878 processing_has_namespace_info = 1;
4879 read_namespace (die, cu);
4882 processing_has_namespace_info = 1;
4883 read_module (die, cu);
4885 case DW_TAG_imported_declaration:
4886 case DW_TAG_imported_module:
4887 processing_has_namespace_info = 1;
4888 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4889 || cu->language != language_fortran))
4890 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4891 dwarf_tag_name (die->tag));
4892 read_import_statement (die, cu);
4895 new_symbol (die, NULL, cu);
4900 /* A helper function for dwarf2_compute_name which determines whether DIE
4901 needs to have the name of the scope prepended to the name listed in the
4905 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4907 struct attribute *attr;
4911 case DW_TAG_namespace:
4912 case DW_TAG_typedef:
4913 case DW_TAG_class_type:
4914 case DW_TAG_interface_type:
4915 case DW_TAG_structure_type:
4916 case DW_TAG_union_type:
4917 case DW_TAG_enumeration_type:
4918 case DW_TAG_enumerator:
4919 case DW_TAG_subprogram:
4923 case DW_TAG_variable:
4924 case DW_TAG_constant:
4925 /* We only need to prefix "globally" visible variables. These include
4926 any variable marked with DW_AT_external or any variable that
4927 lives in a namespace. [Variables in anonymous namespaces
4928 require prefixing, but they are not DW_AT_external.] */
4930 if (dwarf2_attr (die, DW_AT_specification, cu))
4932 struct dwarf2_cu *spec_cu = cu;
4934 return die_needs_namespace (die_specification (die, &spec_cu),
4938 attr = dwarf2_attr (die, DW_AT_external, cu);
4939 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4940 && die->parent->tag != DW_TAG_module)
4942 /* A variable in a lexical block of some kind does not need a
4943 namespace, even though in C++ such variables may be external
4944 and have a mangled name. */
4945 if (die->parent->tag == DW_TAG_lexical_block
4946 || die->parent->tag == DW_TAG_try_block
4947 || die->parent->tag == DW_TAG_catch_block
4948 || die->parent->tag == DW_TAG_subprogram)
4957 /* Retrieve the last character from a mem_file. */
4960 do_ui_file_peek_last (void *object, const char *buffer, long length)
4962 char *last_char_p = (char *) object;
4965 *last_char_p = buffer[length - 1];
4968 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4969 compute the physname for the object, which include a method's
4970 formal parameters (C++/Java) and return type (Java).
4972 For Ada, return the DIE's linkage name rather than the fully qualified
4973 name. PHYSNAME is ignored..
4975 The result is allocated on the objfile_obstack and canonicalized. */
4978 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4981 struct objfile *objfile = cu->objfile;
4984 name = dwarf2_name (die, cu);
4986 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4987 compute it by typename_concat inside GDB. */
4988 if (cu->language == language_ada
4989 || (cu->language == language_fortran && physname))
4991 /* For Ada unit, we prefer the linkage name over the name, as
4992 the former contains the exported name, which the user expects
4993 to be able to reference. Ideally, we want the user to be able
4994 to reference this entity using either natural or linkage name,
4995 but we haven't started looking at this enhancement yet. */
4996 struct attribute *attr;
4998 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5000 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5001 if (attr && DW_STRING (attr))
5002 return DW_STRING (attr);
5005 /* These are the only languages we know how to qualify names in. */
5007 && (cu->language == language_cplus || cu->language == language_java
5008 || cu->language == language_fortran))
5010 if (die_needs_namespace (die, cu))
5014 struct ui_file *buf;
5016 prefix = determine_prefix (die, cu);
5017 buf = mem_fileopen ();
5018 if (*prefix != '\0')
5020 char *prefixed_name = typename_concat (NULL, prefix, name,
5023 fputs_unfiltered (prefixed_name, buf);
5024 xfree (prefixed_name);
5027 fputs_unfiltered (name, buf);
5029 /* Template parameters may be specified in the DIE's DW_AT_name, or
5030 as children with DW_TAG_template_type_param or
5031 DW_TAG_value_type_param. If the latter, add them to the name
5032 here. If the name already has template parameters, then
5033 skip this step; some versions of GCC emit both, and
5034 it is more efficient to use the pre-computed name.
5036 Something to keep in mind about this process: it is very
5037 unlikely, or in some cases downright impossible, to produce
5038 something that will match the mangled name of a function.
5039 If the definition of the function has the same debug info,
5040 we should be able to match up with it anyway. But fallbacks
5041 using the minimal symbol, for instance to find a method
5042 implemented in a stripped copy of libstdc++, will not work.
5043 If we do not have debug info for the definition, we will have to
5044 match them up some other way.
5046 When we do name matching there is a related problem with function
5047 templates; two instantiated function templates are allowed to
5048 differ only by their return types, which we do not add here. */
5050 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5052 struct attribute *attr;
5053 struct die_info *child;
5056 die->building_fullname = 1;
5058 for (child = die->child; child != NULL; child = child->sibling)
5063 struct dwarf2_locexpr_baton *baton;
5066 if (child->tag != DW_TAG_template_type_param
5067 && child->tag != DW_TAG_template_value_param)
5072 fputs_unfiltered ("<", buf);
5076 fputs_unfiltered (", ", buf);
5078 attr = dwarf2_attr (child, DW_AT_type, cu);
5081 complaint (&symfile_complaints,
5082 _("template parameter missing DW_AT_type"));
5083 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5086 type = die_type (child, cu);
5088 if (child->tag == DW_TAG_template_type_param)
5090 c_print_type (type, "", buf, -1, 0);
5094 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5097 complaint (&symfile_complaints,
5098 _("template parameter missing "
5099 "DW_AT_const_value"));
5100 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5104 dwarf2_const_value_attr (attr, type, name,
5105 &cu->comp_unit_obstack, cu,
5106 &value, &bytes, &baton);
5108 if (TYPE_NOSIGN (type))
5109 /* GDB prints characters as NUMBER 'CHAR'. If that's
5110 changed, this can use value_print instead. */
5111 c_printchar (value, type, buf);
5114 struct value_print_options opts;
5117 v = dwarf2_evaluate_loc_desc (type, NULL,
5121 else if (bytes != NULL)
5123 v = allocate_value (type);
5124 memcpy (value_contents_writeable (v), bytes,
5125 TYPE_LENGTH (type));
5128 v = value_from_longest (type, value);
5130 /* Specify decimal so that we do not depend on
5132 get_formatted_print_options (&opts, 'd');
5134 value_print (v, buf, &opts);
5140 die->building_fullname = 0;
5144 /* Close the argument list, with a space if necessary
5145 (nested templates). */
5146 char last_char = '\0';
5147 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5148 if (last_char == '>')
5149 fputs_unfiltered (" >", buf);
5151 fputs_unfiltered (">", buf);
5155 /* For Java and C++ methods, append formal parameter type
5156 information, if PHYSNAME. */
5158 if (physname && die->tag == DW_TAG_subprogram
5159 && (cu->language == language_cplus
5160 || cu->language == language_java))
5162 struct type *type = read_type_die (die, cu);
5164 c_type_print_args (type, buf, 1, cu->language);
5166 if (cu->language == language_java)
5168 /* For java, we must append the return type to method
5170 if (die->tag == DW_TAG_subprogram)
5171 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5174 else if (cu->language == language_cplus)
5176 /* Assume that an artificial first parameter is
5177 "this", but do not crash if it is not. RealView
5178 marks unnamed (and thus unused) parameters as
5179 artificial; there is no way to differentiate
5181 if (TYPE_NFIELDS (type) > 0
5182 && TYPE_FIELD_ARTIFICIAL (type, 0)
5183 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5184 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5186 fputs_unfiltered (" const", buf);
5190 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
5192 ui_file_delete (buf);
5194 if (cu->language == language_cplus)
5197 = dwarf2_canonicalize_name (name, cu,
5198 &objfile->objfile_obstack);
5209 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5210 If scope qualifiers are appropriate they will be added. The result
5211 will be allocated on the objfile_obstack, or NULL if the DIE does
5212 not have a name. NAME may either be from a previous call to
5213 dwarf2_name or NULL.
5215 The output string will be canonicalized (if C++/Java). */
5218 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5220 return dwarf2_compute_name (name, die, cu, 0);
5223 /* Construct a physname for the given DIE in CU. NAME may either be
5224 from a previous call to dwarf2_name or NULL. The result will be
5225 allocated on the objfile_objstack or NULL if the DIE does not have a
5228 The output string will be canonicalized (if C++/Java). */
5231 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5233 struct objfile *objfile = cu->objfile;
5234 struct attribute *attr;
5235 const char *retval, *mangled = NULL, *canon = NULL;
5236 struct cleanup *back_to;
5239 /* In this case dwarf2_compute_name is just a shortcut not building anything
5241 if (!die_needs_namespace (die, cu))
5242 return dwarf2_compute_name (name, die, cu, 1);
5244 back_to = make_cleanup (null_cleanup, NULL);
5246 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5248 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5250 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5252 if (attr && DW_STRING (attr))
5256 mangled = DW_STRING (attr);
5258 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5259 type. It is easier for GDB users to search for such functions as
5260 `name(params)' than `long name(params)'. In such case the minimal
5261 symbol names do not match the full symbol names but for template
5262 functions there is never a need to look up their definition from their
5263 declaration so the only disadvantage remains the minimal symbol
5264 variant `long name(params)' does not have the proper inferior type.
5267 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5268 | (cu->language == language_java
5269 ? DMGL_JAVA | DMGL_RET_POSTFIX
5273 make_cleanup (xfree, demangled);
5283 if (canon == NULL || check_physname)
5285 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5287 if (canon != NULL && strcmp (physname, canon) != 0)
5289 /* It may not mean a bug in GDB. The compiler could also
5290 compute DW_AT_linkage_name incorrectly. But in such case
5291 GDB would need to be bug-to-bug compatible. */
5293 complaint (&symfile_complaints,
5294 _("Computed physname <%s> does not match demangled <%s> "
5295 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5296 physname, canon, mangled, die->offset, objfile->name);
5298 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5299 is available here - over computed PHYSNAME. It is safer
5300 against both buggy GDB and buggy compilers. */
5314 retval = obsavestring (retval, strlen (retval),
5315 &objfile->objfile_obstack);
5317 do_cleanups (back_to);
5321 /* Read the import statement specified by the given die and record it. */
5324 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5326 struct objfile *objfile = cu->objfile;
5327 struct attribute *import_attr;
5328 struct die_info *imported_die, *child_die;
5329 struct dwarf2_cu *imported_cu;
5330 const char *imported_name;
5331 const char *imported_name_prefix;
5332 const char *canonical_name;
5333 const char *import_alias;
5334 const char *imported_declaration = NULL;
5335 const char *import_prefix;
5336 VEC (const_char_ptr) *excludes = NULL;
5337 struct cleanup *cleanups;
5341 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5342 if (import_attr == NULL)
5344 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5345 dwarf_tag_name (die->tag));
5350 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5351 imported_name = dwarf2_name (imported_die, imported_cu);
5352 if (imported_name == NULL)
5354 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5356 The import in the following code:
5370 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5371 <52> DW_AT_decl_file : 1
5372 <53> DW_AT_decl_line : 6
5373 <54> DW_AT_import : <0x75>
5374 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5376 <5b> DW_AT_decl_file : 1
5377 <5c> DW_AT_decl_line : 2
5378 <5d> DW_AT_type : <0x6e>
5380 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5381 <76> DW_AT_byte_size : 4
5382 <77> DW_AT_encoding : 5 (signed)
5384 imports the wrong die ( 0x75 instead of 0x58 ).
5385 This case will be ignored until the gcc bug is fixed. */
5389 /* Figure out the local name after import. */
5390 import_alias = dwarf2_name (die, cu);
5392 /* Figure out where the statement is being imported to. */
5393 import_prefix = determine_prefix (die, cu);
5395 /* Figure out what the scope of the imported die is and prepend it
5396 to the name of the imported die. */
5397 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5399 if (imported_die->tag != DW_TAG_namespace
5400 && imported_die->tag != DW_TAG_module)
5402 imported_declaration = imported_name;
5403 canonical_name = imported_name_prefix;
5405 else if (strlen (imported_name_prefix) > 0)
5407 temp = alloca (strlen (imported_name_prefix)
5408 + 2 + strlen (imported_name) + 1);
5409 strcpy (temp, imported_name_prefix);
5410 strcat (temp, "::");
5411 strcat (temp, imported_name);
5412 canonical_name = temp;
5415 canonical_name = imported_name;
5417 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5419 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5420 for (child_die = die->child; child_die && child_die->tag;
5421 child_die = sibling_die (child_die))
5423 /* DWARF-4: A Fortran use statement with a “rename list” may be
5424 represented by an imported module entry with an import attribute
5425 referring to the module and owned entries corresponding to those
5426 entities that are renamed as part of being imported. */
5428 if (child_die->tag != DW_TAG_imported_declaration)
5430 complaint (&symfile_complaints,
5431 _("child DW_TAG_imported_declaration expected "
5432 "- DIE at 0x%x [in module %s]"),
5433 child_die->offset, objfile->name);
5437 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5438 if (import_attr == NULL)
5440 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5441 dwarf_tag_name (child_die->tag));
5446 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5448 imported_name = dwarf2_name (imported_die, imported_cu);
5449 if (imported_name == NULL)
5451 complaint (&symfile_complaints,
5452 _("child DW_TAG_imported_declaration has unknown "
5453 "imported name - DIE at 0x%x [in module %s]"),
5454 child_die->offset, objfile->name);
5458 VEC_safe_push (const_char_ptr, excludes, imported_name);
5460 process_die (child_die, cu);
5463 cp_add_using_directive (import_prefix,
5466 imported_declaration,
5468 &objfile->objfile_obstack);
5470 do_cleanups (cleanups);
5473 /* Cleanup function for read_file_scope. */
5476 free_cu_line_header (void *arg)
5478 struct dwarf2_cu *cu = arg;
5480 free_line_header (cu->line_header);
5481 cu->line_header = NULL;
5485 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5486 char **name, char **comp_dir)
5488 struct attribute *attr;
5493 /* Find the filename. Do not use dwarf2_name here, since the filename
5494 is not a source language identifier. */
5495 attr = dwarf2_attr (die, DW_AT_name, cu);
5498 *name = DW_STRING (attr);
5501 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5503 *comp_dir = DW_STRING (attr);
5504 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5506 *comp_dir = ldirname (*name);
5507 if (*comp_dir != NULL)
5508 make_cleanup (xfree, *comp_dir);
5510 if (*comp_dir != NULL)
5512 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5513 directory, get rid of it. */
5514 char *cp = strchr (*comp_dir, ':');
5516 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5521 *name = "<unknown>";
5524 /* Handle DW_AT_stmt_list for a compilation unit. */
5527 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5528 const char *comp_dir)
5530 struct attribute *attr;
5531 struct objfile *objfile = cu->objfile;
5532 bfd *abfd = objfile->obfd;
5534 /* Decode line number information if present. We do this before
5535 processing child DIEs, so that the line header table is available
5536 for DW_AT_decl_file. */
5537 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5540 unsigned int line_offset = DW_UNSND (attr);
5541 struct line_header *line_header
5542 = dwarf_decode_line_header (line_offset, abfd, cu);
5546 cu->line_header = line_header;
5547 make_cleanup (free_cu_line_header, cu);
5548 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5553 /* Process DW_TAG_compile_unit. */
5556 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5558 struct objfile *objfile = cu->objfile;
5559 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5560 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5561 CORE_ADDR highpc = ((CORE_ADDR) 0);
5562 struct attribute *attr;
5564 char *comp_dir = NULL;
5565 struct die_info *child_die;
5566 bfd *abfd = objfile->obfd;
5569 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5571 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5573 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5574 from finish_block. */
5575 if (lowpc == ((CORE_ADDR) -1))
5580 find_file_and_directory (die, cu, &name, &comp_dir);
5582 attr = dwarf2_attr (die, DW_AT_language, cu);
5585 set_cu_language (DW_UNSND (attr), cu);
5588 attr = dwarf2_attr (die, DW_AT_producer, cu);
5590 cu->producer = DW_STRING (attr);
5592 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5593 standardised yet. As a workaround for the language detection we fall
5594 back to the DW_AT_producer string. */
5595 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5596 cu->language = language_opencl;
5598 /* We assume that we're processing GCC output. */
5599 processing_gcc_compilation = 2;
5601 processing_has_namespace_info = 0;
5603 start_symtab (name, comp_dir, lowpc);
5604 record_debugformat ("DWARF 2");
5605 record_producer (cu->producer);
5607 handle_DW_AT_stmt_list (die, cu, comp_dir);
5609 /* Process all dies in compilation unit. */
5610 if (die->child != NULL)
5612 child_die = die->child;
5613 while (child_die && child_die->tag)
5615 process_die (child_die, cu);
5616 child_die = sibling_die (child_die);
5620 /* Decode macro information, if present. Dwarf 2 macro information
5621 refers to information in the line number info statement program
5622 header, so we can only read it if we've read the header
5624 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5625 if (attr && cu->line_header)
5627 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5628 complaint (&symfile_complaints,
5629 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5631 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5633 &dwarf2_per_objfile->macro, 1);
5637 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5638 if (attr && cu->line_header)
5640 unsigned int macro_offset = DW_UNSND (attr);
5642 dwarf_decode_macros (cu->line_header, macro_offset,
5644 &dwarf2_per_objfile->macinfo, 0);
5648 do_cleanups (back_to);
5651 /* Process DW_TAG_type_unit.
5652 For TUs we want to skip the first top level sibling if it's not the
5653 actual type being defined by this TU. In this case the first top
5654 level sibling is there to provide context only. */
5657 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5659 struct objfile *objfile = cu->objfile;
5660 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5662 struct attribute *attr;
5664 char *comp_dir = NULL;
5665 struct die_info *child_die;
5666 bfd *abfd = objfile->obfd;
5668 /* start_symtab needs a low pc, but we don't really have one.
5669 Do what read_file_scope would do in the absence of such info. */
5670 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5672 /* Find the filename. Do not use dwarf2_name here, since the filename
5673 is not a source language identifier. */
5674 attr = dwarf2_attr (die, DW_AT_name, cu);
5676 name = DW_STRING (attr);
5678 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5680 comp_dir = DW_STRING (attr);
5681 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5683 comp_dir = ldirname (name);
5684 if (comp_dir != NULL)
5685 make_cleanup (xfree, comp_dir);
5691 attr = dwarf2_attr (die, DW_AT_language, cu);
5693 set_cu_language (DW_UNSND (attr), cu);
5695 /* This isn't technically needed today. It is done for symmetry
5696 with read_file_scope. */
5697 attr = dwarf2_attr (die, DW_AT_producer, cu);
5699 cu->producer = DW_STRING (attr);
5701 /* We assume that we're processing GCC output. */
5702 processing_gcc_compilation = 2;
5704 processing_has_namespace_info = 0;
5706 start_symtab (name, comp_dir, lowpc);
5707 record_debugformat ("DWARF 2");
5708 record_producer (cu->producer);
5710 handle_DW_AT_stmt_list (die, cu, comp_dir);
5712 /* Process the dies in the type unit. */
5713 if (die->child == NULL)
5715 dump_die_for_error (die);
5716 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5717 bfd_get_filename (abfd));
5720 child_die = die->child;
5722 while (child_die && child_die->tag)
5724 process_die (child_die, cu);
5726 child_die = sibling_die (child_die);
5729 do_cleanups (back_to);
5732 /* qsort helper for inherit_abstract_dies. */
5735 unsigned_int_compar (const void *ap, const void *bp)
5737 unsigned int a = *(unsigned int *) ap;
5738 unsigned int b = *(unsigned int *) bp;
5740 return (a > b) - (b > a);
5743 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5744 Inherit only the children of the DW_AT_abstract_origin DIE not being
5745 already referenced by DW_AT_abstract_origin from the children of the
5749 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5751 struct die_info *child_die;
5752 unsigned die_children_count;
5753 /* CU offsets which were referenced by children of the current DIE. */
5755 unsigned *offsets_end, *offsetp;
5756 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5757 struct die_info *origin_die;
5758 /* Iterator of the ORIGIN_DIE children. */
5759 struct die_info *origin_child_die;
5760 struct cleanup *cleanups;
5761 struct attribute *attr;
5762 struct dwarf2_cu *origin_cu;
5763 struct pending **origin_previous_list_in_scope;
5765 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5769 /* Note that following die references may follow to a die in a
5773 origin_die = follow_die_ref (die, attr, &origin_cu);
5775 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5777 origin_previous_list_in_scope = origin_cu->list_in_scope;
5778 origin_cu->list_in_scope = cu->list_in_scope;
5780 if (die->tag != origin_die->tag
5781 && !(die->tag == DW_TAG_inlined_subroutine
5782 && origin_die->tag == DW_TAG_subprogram))
5783 complaint (&symfile_complaints,
5784 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5785 die->offset, origin_die->offset);
5787 child_die = die->child;
5788 die_children_count = 0;
5789 while (child_die && child_die->tag)
5791 child_die = sibling_die (child_die);
5792 die_children_count++;
5794 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5795 cleanups = make_cleanup (xfree, offsets);
5797 offsets_end = offsets;
5798 child_die = die->child;
5799 while (child_die && child_die->tag)
5801 /* For each CHILD_DIE, find the corresponding child of
5802 ORIGIN_DIE. If there is more than one layer of
5803 DW_AT_abstract_origin, follow them all; there shouldn't be,
5804 but GCC versions at least through 4.4 generate this (GCC PR
5806 struct die_info *child_origin_die = child_die;
5807 struct dwarf2_cu *child_origin_cu = cu;
5811 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5815 child_origin_die = follow_die_ref (child_origin_die, attr,
5819 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5820 counterpart may exist. */
5821 if (child_origin_die != child_die)
5823 if (child_die->tag != child_origin_die->tag
5824 && !(child_die->tag == DW_TAG_inlined_subroutine
5825 && child_origin_die->tag == DW_TAG_subprogram))
5826 complaint (&symfile_complaints,
5827 _("Child DIE 0x%x and its abstract origin 0x%x have "
5828 "different tags"), child_die->offset,
5829 child_origin_die->offset);
5830 if (child_origin_die->parent != origin_die)
5831 complaint (&symfile_complaints,
5832 _("Child DIE 0x%x and its abstract origin 0x%x have "
5833 "different parents"), child_die->offset,
5834 child_origin_die->offset);
5836 *offsets_end++ = child_origin_die->offset;
5838 child_die = sibling_die (child_die);
5840 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5841 unsigned_int_compar);
5842 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5843 if (offsetp[-1] == *offsetp)
5844 complaint (&symfile_complaints,
5845 _("Multiple children of DIE 0x%x refer "
5846 "to DIE 0x%x as their abstract origin"),
5847 die->offset, *offsetp);
5850 origin_child_die = origin_die->child;
5851 while (origin_child_die && origin_child_die->tag)
5853 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5854 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5856 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5858 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5859 process_die (origin_child_die, origin_cu);
5861 origin_child_die = sibling_die (origin_child_die);
5863 origin_cu->list_in_scope = origin_previous_list_in_scope;
5865 do_cleanups (cleanups);
5869 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5871 struct objfile *objfile = cu->objfile;
5872 struct context_stack *new;
5875 struct die_info *child_die;
5876 struct attribute *attr, *call_line, *call_file;
5879 struct block *block;
5880 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5881 VEC (symbolp) *template_args = NULL;
5882 struct template_symbol *templ_func = NULL;
5886 /* If we do not have call site information, we can't show the
5887 caller of this inlined function. That's too confusing, so
5888 only use the scope for local variables. */
5889 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5890 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5891 if (call_line == NULL || call_file == NULL)
5893 read_lexical_block_scope (die, cu);
5898 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5900 name = dwarf2_name (die, cu);
5902 /* Ignore functions with missing or empty names. These are actually
5903 illegal according to the DWARF standard. */
5906 complaint (&symfile_complaints,
5907 _("missing name for subprogram DIE at %d"), die->offset);
5911 /* Ignore functions with missing or invalid low and high pc attributes. */
5912 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5914 attr = dwarf2_attr (die, DW_AT_external, cu);
5915 if (!attr || !DW_UNSND (attr))
5916 complaint (&symfile_complaints,
5917 _("cannot get low and high bounds "
5918 "for subprogram DIE at %d"),
5926 /* If we have any template arguments, then we must allocate a
5927 different sort of symbol. */
5928 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5930 if (child_die->tag == DW_TAG_template_type_param
5931 || child_die->tag == DW_TAG_template_value_param)
5933 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5934 struct template_symbol);
5935 templ_func->base.is_cplus_template_function = 1;
5940 new = push_context (0, lowpc);
5941 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5942 (struct symbol *) templ_func);
5944 /* If there is a location expression for DW_AT_frame_base, record
5946 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5948 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5949 expression is being recorded directly in the function's symbol
5950 and not in a separate frame-base object. I guess this hack is
5951 to avoid adding some sort of frame-base adjunct/annex to the
5952 function's symbol :-(. The problem with doing this is that it
5953 results in a function symbol with a location expression that
5954 has nothing to do with the location of the function, ouch! The
5955 relationship should be: a function's symbol has-a frame base; a
5956 frame-base has-a location expression. */
5957 dwarf2_symbol_mark_computed (attr, new->name, cu);
5959 cu->list_in_scope = &local_symbols;
5961 if (die->child != NULL)
5963 child_die = die->child;
5964 while (child_die && child_die->tag)
5966 if (child_die->tag == DW_TAG_template_type_param
5967 || child_die->tag == DW_TAG_template_value_param)
5969 struct symbol *arg = new_symbol (child_die, NULL, cu);
5972 VEC_safe_push (symbolp, template_args, arg);
5975 process_die (child_die, cu);
5976 child_die = sibling_die (child_die);
5980 inherit_abstract_dies (die, cu);
5982 /* If we have a DW_AT_specification, we might need to import using
5983 directives from the context of the specification DIE. See the
5984 comment in determine_prefix. */
5985 if (cu->language == language_cplus
5986 && dwarf2_attr (die, DW_AT_specification, cu))
5988 struct dwarf2_cu *spec_cu = cu;
5989 struct die_info *spec_die = die_specification (die, &spec_cu);
5993 child_die = spec_die->child;
5994 while (child_die && child_die->tag)
5996 if (child_die->tag == DW_TAG_imported_module)
5997 process_die (child_die, spec_cu);
5998 child_die = sibling_die (child_die);
6001 /* In some cases, GCC generates specification DIEs that
6002 themselves contain DW_AT_specification attributes. */
6003 spec_die = die_specification (spec_die, &spec_cu);
6007 new = pop_context ();
6008 /* Make a block for the local symbols within. */
6009 block = finish_block (new->name, &local_symbols, new->old_blocks,
6010 lowpc, highpc, objfile);
6012 /* For C++, set the block's scope. */
6013 if (cu->language == language_cplus || cu->language == language_fortran)
6014 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6015 determine_prefix (die, cu),
6016 processing_has_namespace_info);
6018 /* If we have address ranges, record them. */
6019 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6021 /* Attach template arguments to function. */
6022 if (! VEC_empty (symbolp, template_args))
6024 gdb_assert (templ_func != NULL);
6026 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6027 templ_func->template_arguments
6028 = obstack_alloc (&objfile->objfile_obstack,
6029 (templ_func->n_template_arguments
6030 * sizeof (struct symbol *)));
6031 memcpy (templ_func->template_arguments,
6032 VEC_address (symbolp, template_args),
6033 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6034 VEC_free (symbolp, template_args);
6037 /* In C++, we can have functions nested inside functions (e.g., when
6038 a function declares a class that has methods). This means that
6039 when we finish processing a function scope, we may need to go
6040 back to building a containing block's symbol lists. */
6041 local_symbols = new->locals;
6042 param_symbols = new->params;
6043 using_directives = new->using_directives;
6045 /* If we've finished processing a top-level function, subsequent
6046 symbols go in the file symbol list. */
6047 if (outermost_context_p ())
6048 cu->list_in_scope = &file_symbols;
6051 /* Process all the DIES contained within a lexical block scope. Start
6052 a new scope, process the dies, and then close the scope. */
6055 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6057 struct objfile *objfile = cu->objfile;
6058 struct context_stack *new;
6059 CORE_ADDR lowpc, highpc;
6060 struct die_info *child_die;
6063 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6065 /* Ignore blocks with missing or invalid low and high pc attributes. */
6066 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6067 as multiple lexical blocks? Handling children in a sane way would
6068 be nasty. Might be easier to properly extend generic blocks to
6070 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6075 push_context (0, lowpc);
6076 if (die->child != NULL)
6078 child_die = die->child;
6079 while (child_die && child_die->tag)
6081 process_die (child_die, cu);
6082 child_die = sibling_die (child_die);
6085 new = pop_context ();
6087 if (local_symbols != NULL || using_directives != NULL)
6090 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6093 /* Note that recording ranges after traversing children, as we
6094 do here, means that recording a parent's ranges entails
6095 walking across all its children's ranges as they appear in
6096 the address map, which is quadratic behavior.
6098 It would be nicer to record the parent's ranges before
6099 traversing its children, simply overriding whatever you find
6100 there. But since we don't even decide whether to create a
6101 block until after we've traversed its children, that's hard
6103 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6105 local_symbols = new->locals;
6106 using_directives = new->using_directives;
6109 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6112 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
6114 struct objfile *objfile = cu->objfile;
6115 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6116 CORE_ADDR pc, baseaddr;
6117 struct attribute *attr;
6118 struct call_site *call_site, call_site_local;
6121 struct die_info *child_die;
6123 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6125 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6128 complaint (&symfile_complaints,
6129 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6130 "DIE 0x%x [in module %s]"),
6131 die->offset, objfile->name);
6134 pc = DW_ADDR (attr) + baseaddr;
6136 if (cu->call_site_htab == NULL)
6137 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
6138 NULL, &objfile->objfile_obstack,
6139 hashtab_obstack_allocate, NULL);
6140 call_site_local.pc = pc;
6141 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
6144 complaint (&symfile_complaints,
6145 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6146 "DIE 0x%x [in module %s]"),
6147 paddress (gdbarch, pc), die->offset, objfile->name);
6151 /* Count parameters at the caller. */
6154 for (child_die = die->child; child_die && child_die->tag;
6155 child_die = sibling_die (child_die))
6157 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6159 complaint (&symfile_complaints,
6160 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6161 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6162 child_die->tag, child_die->offset, objfile->name);
6169 call_site = obstack_alloc (&objfile->objfile_obstack,
6170 (sizeof (*call_site)
6171 + (sizeof (*call_site->parameter)
6174 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
6177 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
6179 struct die_info *func_die;
6181 /* Skip also over DW_TAG_inlined_subroutine. */
6182 for (func_die = die->parent;
6183 func_die && func_die->tag != DW_TAG_subprogram
6184 && func_die->tag != DW_TAG_subroutine_type;
6185 func_die = func_die->parent);
6187 /* DW_AT_GNU_all_call_sites is a superset
6188 of DW_AT_GNU_all_tail_call_sites. */
6190 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
6191 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
6193 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6194 not complete. But keep CALL_SITE for look ups via call_site_htab,
6195 both the initial caller containing the real return address PC and
6196 the final callee containing the current PC of a chain of tail
6197 calls do not need to have the tail call list complete. But any
6198 function candidate for a virtual tail call frame searched via
6199 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6200 determined unambiguously. */
6204 struct type *func_type = NULL;
6207 func_type = get_die_type (func_die, cu);
6208 if (func_type != NULL)
6210 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
6212 /* Enlist this call site to the function. */
6213 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
6214 TYPE_TAIL_CALL_LIST (func_type) = call_site;
6217 complaint (&symfile_complaints,
6218 _("Cannot find function owning DW_TAG_GNU_call_site "
6219 "DIE 0x%x [in module %s]"),
6220 die->offset, objfile->name);
6224 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
6226 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
6227 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
6228 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
6229 /* Keep NULL DWARF_BLOCK. */;
6230 else if (attr_form_is_block (attr))
6232 struct dwarf2_locexpr_baton *dlbaton;
6234 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
6235 dlbaton->data = DW_BLOCK (attr)->data;
6236 dlbaton->size = DW_BLOCK (attr)->size;
6237 dlbaton->per_cu = cu->per_cu;
6239 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
6241 else if (is_ref_attr (attr))
6243 struct dwarf2_cu *target_cu = cu;
6244 struct die_info *target_die;
6246 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
6247 gdb_assert (target_cu->objfile == objfile);
6248 if (die_is_declaration (target_die, target_cu))
6250 const char *target_physname;
6252 target_physname = dwarf2_physname (NULL, target_die, target_cu);
6253 if (target_physname == NULL)
6254 complaint (&symfile_complaints,
6255 _("DW_AT_GNU_call_site_target target DIE has invalid "
6256 "physname, for referencing DIE 0x%x [in module %s]"),
6257 die->offset, objfile->name);
6259 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
6265 /* DW_AT_entry_pc should be preferred. */
6266 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
6267 complaint (&symfile_complaints,
6268 _("DW_AT_GNU_call_site_target target DIE has invalid "
6269 "low pc, for referencing DIE 0x%x [in module %s]"),
6270 die->offset, objfile->name);
6272 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
6276 complaint (&symfile_complaints,
6277 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6278 "block nor reference, for DIE 0x%x [in module %s]"),
6279 die->offset, objfile->name);
6281 call_site->per_cu = cu->per_cu;
6283 for (child_die = die->child;
6284 child_die && child_die->tag;
6285 child_die = sibling_die (child_die))
6287 struct dwarf2_locexpr_baton *dlbaton;
6288 struct call_site_parameter *parameter;
6290 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6292 /* Already printed the complaint above. */
6296 gdb_assert (call_site->parameter_count < nparams);
6297 parameter = &call_site->parameter[call_site->parameter_count];
6299 /* DW_AT_location specifies the register number. Value of the data
6300 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6302 attr = dwarf2_attr (child_die, DW_AT_location, cu);
6303 if (!attr || !attr_form_is_block (attr))
6305 complaint (&symfile_complaints,
6306 _("No DW_FORM_block* DW_AT_location for "
6307 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6308 child_die->offset, objfile->name);
6311 parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
6312 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
6313 if (parameter->dwarf_reg == -1
6314 && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
6315 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
6316 ¶meter->fb_offset))
6318 complaint (&symfile_complaints,
6319 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6320 "for DW_FORM_block* DW_AT_location for "
6321 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6322 child_die->offset, objfile->name);
6326 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
6327 if (!attr_form_is_block (attr))
6329 complaint (&symfile_complaints,
6330 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6331 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6332 child_die->offset, objfile->name);
6335 parameter->value = DW_BLOCK (attr)->data;
6336 parameter->value_size = DW_BLOCK (attr)->size;
6338 /* Parameters are not pre-cleared by memset above. */
6339 parameter->data_value = NULL;
6340 parameter->data_value_size = 0;
6341 call_site->parameter_count++;
6343 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
6346 if (!attr_form_is_block (attr))
6347 complaint (&symfile_complaints,
6348 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6349 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6350 child_die->offset, objfile->name);
6353 parameter->data_value = DW_BLOCK (attr)->data;
6354 parameter->data_value_size = DW_BLOCK (attr)->size;
6360 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6361 Return 1 if the attributes are present and valid, otherwise, return 0.
6362 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6365 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6366 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6367 struct partial_symtab *ranges_pst)
6369 struct objfile *objfile = cu->objfile;
6370 struct comp_unit_head *cu_header = &cu->header;
6371 bfd *obfd = objfile->obfd;
6372 unsigned int addr_size = cu_header->addr_size;
6373 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6374 /* Base address selection entry. */
6385 found_base = cu->base_known;
6386 base = cu->base_address;
6388 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6389 if (offset >= dwarf2_per_objfile->ranges.size)
6391 complaint (&symfile_complaints,
6392 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6396 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6398 /* Read in the largest possible address. */
6399 marker = read_address (obfd, buffer, cu, &dummy);
6400 if ((marker & mask) == mask)
6402 /* If we found the largest possible address, then
6403 read the base address. */
6404 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6405 buffer += 2 * addr_size;
6406 offset += 2 * addr_size;
6412 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6416 CORE_ADDR range_beginning, range_end;
6418 range_beginning = read_address (obfd, buffer, cu, &dummy);
6419 buffer += addr_size;
6420 range_end = read_address (obfd, buffer, cu, &dummy);
6421 buffer += addr_size;
6422 offset += 2 * addr_size;
6424 /* An end of list marker is a pair of zero addresses. */
6425 if (range_beginning == 0 && range_end == 0)
6426 /* Found the end of list entry. */
6429 /* Each base address selection entry is a pair of 2 values.
6430 The first is the largest possible address, the second is
6431 the base address. Check for a base address here. */
6432 if ((range_beginning & mask) == mask)
6434 /* If we found the largest possible address, then
6435 read the base address. */
6436 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6443 /* We have no valid base address for the ranges
6445 complaint (&symfile_complaints,
6446 _("Invalid .debug_ranges data (no base address)"));
6450 if (range_beginning > range_end)
6452 /* Inverted range entries are invalid. */
6453 complaint (&symfile_complaints,
6454 _("Invalid .debug_ranges data (inverted range)"));
6458 /* Empty range entries have no effect. */
6459 if (range_beginning == range_end)
6462 range_beginning += base;
6465 if (ranges_pst != NULL)
6466 addrmap_set_empty (objfile->psymtabs_addrmap,
6467 range_beginning + baseaddr,
6468 range_end - 1 + baseaddr,
6471 /* FIXME: This is recording everything as a low-high
6472 segment of consecutive addresses. We should have a
6473 data structure for discontiguous block ranges
6477 low = range_beginning;
6483 if (range_beginning < low)
6484 low = range_beginning;
6485 if (range_end > high)
6491 /* If the first entry is an end-of-list marker, the range
6492 describes an empty scope, i.e. no instructions. */
6498 *high_return = high;
6502 /* Get low and high pc attributes from a die. Return 1 if the attributes
6503 are present and valid, otherwise, return 0. Return -1 if the range is
6504 discontinuous, i.e. derived from DW_AT_ranges information. */
6506 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6507 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6508 struct partial_symtab *pst)
6510 struct attribute *attr;
6515 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6518 high = DW_ADDR (attr);
6519 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6521 low = DW_ADDR (attr);
6523 /* Found high w/o low attribute. */
6526 /* Found consecutive range of addresses. */
6531 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6534 /* Value of the DW_AT_ranges attribute is the offset in the
6535 .debug_ranges section. */
6536 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6538 /* Found discontinuous range of addresses. */
6543 /* read_partial_die has also the strict LOW < HIGH requirement. */
6547 /* When using the GNU linker, .gnu.linkonce. sections are used to
6548 eliminate duplicate copies of functions and vtables and such.
6549 The linker will arbitrarily choose one and discard the others.
6550 The AT_*_pc values for such functions refer to local labels in
6551 these sections. If the section from that file was discarded, the
6552 labels are not in the output, so the relocs get a value of 0.
6553 If this is a discarded function, mark the pc bounds as invalid,
6554 so that GDB will ignore it. */
6555 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6564 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6565 its low and high PC addresses. Do nothing if these addresses could not
6566 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6567 and HIGHPC to the high address if greater than HIGHPC. */
6570 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6571 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6572 struct dwarf2_cu *cu)
6574 CORE_ADDR low, high;
6575 struct die_info *child = die->child;
6577 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6579 *lowpc = min (*lowpc, low);
6580 *highpc = max (*highpc, high);
6583 /* If the language does not allow nested subprograms (either inside
6584 subprograms or lexical blocks), we're done. */
6585 if (cu->language != language_ada)
6588 /* Check all the children of the given DIE. If it contains nested
6589 subprograms, then check their pc bounds. Likewise, we need to
6590 check lexical blocks as well, as they may also contain subprogram
6592 while (child && child->tag)
6594 if (child->tag == DW_TAG_subprogram
6595 || child->tag == DW_TAG_lexical_block)
6596 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6597 child = sibling_die (child);
6601 /* Get the low and high pc's represented by the scope DIE, and store
6602 them in *LOWPC and *HIGHPC. If the correct values can't be
6603 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6606 get_scope_pc_bounds (struct die_info *die,
6607 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6608 struct dwarf2_cu *cu)
6610 CORE_ADDR best_low = (CORE_ADDR) -1;
6611 CORE_ADDR best_high = (CORE_ADDR) 0;
6612 CORE_ADDR current_low, current_high;
6614 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6616 best_low = current_low;
6617 best_high = current_high;
6621 struct die_info *child = die->child;
6623 while (child && child->tag)
6625 switch (child->tag) {
6626 case DW_TAG_subprogram:
6627 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6629 case DW_TAG_namespace:
6631 /* FIXME: carlton/2004-01-16: Should we do this for
6632 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6633 that current GCC's always emit the DIEs corresponding
6634 to definitions of methods of classes as children of a
6635 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6636 the DIEs giving the declarations, which could be
6637 anywhere). But I don't see any reason why the
6638 standards says that they have to be there. */
6639 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6641 if (current_low != ((CORE_ADDR) -1))
6643 best_low = min (best_low, current_low);
6644 best_high = max (best_high, current_high);
6652 child = sibling_die (child);
6657 *highpc = best_high;
6660 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6663 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6664 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6666 struct objfile *objfile = cu->objfile;
6667 struct attribute *attr;
6669 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6672 CORE_ADDR high = DW_ADDR (attr);
6674 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6677 CORE_ADDR low = DW_ADDR (attr);
6679 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6683 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6686 bfd *obfd = objfile->obfd;
6688 /* The value of the DW_AT_ranges attribute is the offset of the
6689 address range list in the .debug_ranges section. */
6690 unsigned long offset = DW_UNSND (attr);
6691 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6693 /* For some target architectures, but not others, the
6694 read_address function sign-extends the addresses it returns.
6695 To recognize base address selection entries, we need a
6697 unsigned int addr_size = cu->header.addr_size;
6698 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6700 /* The base address, to which the next pair is relative. Note
6701 that this 'base' is a DWARF concept: most entries in a range
6702 list are relative, to reduce the number of relocs against the
6703 debugging information. This is separate from this function's
6704 'baseaddr' argument, which GDB uses to relocate debugging
6705 information from a shared library based on the address at
6706 which the library was loaded. */
6707 CORE_ADDR base = cu->base_address;
6708 int base_known = cu->base_known;
6710 gdb_assert (dwarf2_per_objfile->ranges.readin);
6711 if (offset >= dwarf2_per_objfile->ranges.size)
6713 complaint (&symfile_complaints,
6714 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6721 unsigned int bytes_read;
6722 CORE_ADDR start, end;
6724 start = read_address (obfd, buffer, cu, &bytes_read);
6725 buffer += bytes_read;
6726 end = read_address (obfd, buffer, cu, &bytes_read);
6727 buffer += bytes_read;
6729 /* Did we find the end of the range list? */
6730 if (start == 0 && end == 0)
6733 /* Did we find a base address selection entry? */
6734 else if ((start & base_select_mask) == base_select_mask)
6740 /* We found an ordinary address range. */
6745 complaint (&symfile_complaints,
6746 _("Invalid .debug_ranges data "
6747 "(no base address)"));
6753 /* Inverted range entries are invalid. */
6754 complaint (&symfile_complaints,
6755 _("Invalid .debug_ranges data "
6756 "(inverted range)"));
6760 /* Empty range entries have no effect. */
6764 record_block_range (block,
6765 baseaddr + base + start,
6766 baseaddr + base + end - 1);
6772 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6773 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6774 during 4.6.0 experimental. */
6777 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6780 int major, minor, release;
6782 if (cu->producer == NULL)
6784 /* For unknown compilers expect their behavior is DWARF version
6787 GCC started to support .debug_types sections by -gdwarf-4 since
6788 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6789 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6790 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6791 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6796 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6798 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6800 /* For non-GCC compilers expect their behavior is DWARF version
6805 cs = &cu->producer[strlen ("GNU ")];
6806 while (*cs && !isdigit (*cs))
6808 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6810 /* Not recognized as GCC. */
6815 return major < 4 || (major == 4 && minor < 6);
6818 /* Return the default accessibility type if it is not overriden by
6819 DW_AT_accessibility. */
6821 static enum dwarf_access_attribute
6822 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6824 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6826 /* The default DWARF 2 accessibility for members is public, the default
6827 accessibility for inheritance is private. */
6829 if (die->tag != DW_TAG_inheritance)
6830 return DW_ACCESS_public;
6832 return DW_ACCESS_private;
6836 /* DWARF 3+ defines the default accessibility a different way. The same
6837 rules apply now for DW_TAG_inheritance as for the members and it only
6838 depends on the container kind. */
6840 if (die->parent->tag == DW_TAG_class_type)
6841 return DW_ACCESS_private;
6843 return DW_ACCESS_public;
6847 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6848 offset. If the attribute was not found return 0, otherwise return
6849 1. If it was found but could not properly be handled, set *OFFSET
6853 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6856 struct attribute *attr;
6858 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6863 /* Note that we do not check for a section offset first here.
6864 This is because DW_AT_data_member_location is new in DWARF 4,
6865 so if we see it, we can assume that a constant form is really
6866 a constant and not a section offset. */
6867 if (attr_form_is_constant (attr))
6868 *offset = dwarf2_get_attr_constant_value (attr, 0);
6869 else if (attr_form_is_section_offset (attr))
6870 dwarf2_complex_location_expr_complaint ();
6871 else if (attr_form_is_block (attr))
6872 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6874 dwarf2_complex_location_expr_complaint ();
6882 /* Add an aggregate field to the field list. */
6885 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6886 struct dwarf2_cu *cu)
6888 struct objfile *objfile = cu->objfile;
6889 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6890 struct nextfield *new_field;
6891 struct attribute *attr;
6893 char *fieldname = "";
6895 /* Allocate a new field list entry and link it in. */
6896 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6897 make_cleanup (xfree, new_field);
6898 memset (new_field, 0, sizeof (struct nextfield));
6900 if (die->tag == DW_TAG_inheritance)
6902 new_field->next = fip->baseclasses;
6903 fip->baseclasses = new_field;
6907 new_field->next = fip->fields;
6908 fip->fields = new_field;
6912 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6914 new_field->accessibility = DW_UNSND (attr);
6916 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6917 if (new_field->accessibility != DW_ACCESS_public)
6918 fip->non_public_fields = 1;
6920 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6922 new_field->virtuality = DW_UNSND (attr);
6924 new_field->virtuality = DW_VIRTUALITY_none;
6926 fp = &new_field->field;
6928 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6932 /* Data member other than a C++ static data member. */
6934 /* Get type of field. */
6935 fp->type = die_type (die, cu);
6937 SET_FIELD_BITPOS (*fp, 0);
6939 /* Get bit size of field (zero if none). */
6940 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6943 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6947 FIELD_BITSIZE (*fp) = 0;
6950 /* Get bit offset of field. */
6951 if (handle_data_member_location (die, cu, &offset))
6952 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6953 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6956 if (gdbarch_bits_big_endian (gdbarch))
6958 /* For big endian bits, the DW_AT_bit_offset gives the
6959 additional bit offset from the MSB of the containing
6960 anonymous object to the MSB of the field. We don't
6961 have to do anything special since we don't need to
6962 know the size of the anonymous object. */
6963 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6967 /* For little endian bits, compute the bit offset to the
6968 MSB of the anonymous object, subtract off the number of
6969 bits from the MSB of the field to the MSB of the
6970 object, and then subtract off the number of bits of
6971 the field itself. The result is the bit offset of
6972 the LSB of the field. */
6974 int bit_offset = DW_UNSND (attr);
6976 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6979 /* The size of the anonymous object containing
6980 the bit field is explicit, so use the
6981 indicated size (in bytes). */
6982 anonymous_size = DW_UNSND (attr);
6986 /* The size of the anonymous object containing
6987 the bit field must be inferred from the type
6988 attribute of the data member containing the
6990 anonymous_size = TYPE_LENGTH (fp->type);
6992 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6993 - bit_offset - FIELD_BITSIZE (*fp);
6997 /* Get name of field. */
6998 fieldname = dwarf2_name (die, cu);
6999 if (fieldname == NULL)
7002 /* The name is already allocated along with this objfile, so we don't
7003 need to duplicate it for the type. */
7004 fp->name = fieldname;
7006 /* Change accessibility for artificial fields (e.g. virtual table
7007 pointer or virtual base class pointer) to private. */
7008 if (dwarf2_attr (die, DW_AT_artificial, cu))
7010 FIELD_ARTIFICIAL (*fp) = 1;
7011 new_field->accessibility = DW_ACCESS_private;
7012 fip->non_public_fields = 1;
7015 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
7017 /* C++ static member. */
7019 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7020 is a declaration, but all versions of G++ as of this writing
7021 (so through at least 3.2.1) incorrectly generate
7022 DW_TAG_variable tags. */
7024 const char *physname;
7026 /* Get name of field. */
7027 fieldname = dwarf2_name (die, cu);
7028 if (fieldname == NULL)
7031 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7033 /* Only create a symbol if this is an external value.
7034 new_symbol checks this and puts the value in the global symbol
7035 table, which we want. If it is not external, new_symbol
7036 will try to put the value in cu->list_in_scope which is wrong. */
7037 && dwarf2_flag_true_p (die, DW_AT_external, cu))
7039 /* A static const member, not much different than an enum as far as
7040 we're concerned, except that we can support more types. */
7041 new_symbol (die, NULL, cu);
7044 /* Get physical name. */
7045 physname = dwarf2_physname (fieldname, die, cu);
7047 /* The name is already allocated along with this objfile, so we don't
7048 need to duplicate it for the type. */
7049 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
7050 FIELD_TYPE (*fp) = die_type (die, cu);
7051 FIELD_NAME (*fp) = fieldname;
7053 else if (die->tag == DW_TAG_inheritance)
7057 /* C++ base class field. */
7058 if (handle_data_member_location (die, cu, &offset))
7059 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7060 FIELD_BITSIZE (*fp) = 0;
7061 FIELD_TYPE (*fp) = die_type (die, cu);
7062 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
7063 fip->nbaseclasses++;
7067 /* Add a typedef defined in the scope of the FIP's class. */
7070 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
7071 struct dwarf2_cu *cu)
7073 struct objfile *objfile = cu->objfile;
7074 struct typedef_field_list *new_field;
7075 struct attribute *attr;
7076 struct typedef_field *fp;
7077 char *fieldname = "";
7079 /* Allocate a new field list entry and link it in. */
7080 new_field = xzalloc (sizeof (*new_field));
7081 make_cleanup (xfree, new_field);
7083 gdb_assert (die->tag == DW_TAG_typedef);
7085 fp = &new_field->field;
7087 /* Get name of field. */
7088 fp->name = dwarf2_name (die, cu);
7089 if (fp->name == NULL)
7092 fp->type = read_type_die (die, cu);
7094 new_field->next = fip->typedef_field_list;
7095 fip->typedef_field_list = new_field;
7096 fip->typedef_field_list_count++;
7099 /* Create the vector of fields, and attach it to the type. */
7102 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
7103 struct dwarf2_cu *cu)
7105 int nfields = fip->nfields;
7107 /* Record the field count, allocate space for the array of fields,
7108 and create blank accessibility bitfields if necessary. */
7109 TYPE_NFIELDS (type) = nfields;
7110 TYPE_FIELDS (type) = (struct field *)
7111 TYPE_ALLOC (type, sizeof (struct field) * nfields);
7112 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
7114 if (fip->non_public_fields && cu->language != language_ada)
7116 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7118 TYPE_FIELD_PRIVATE_BITS (type) =
7119 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7120 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
7122 TYPE_FIELD_PROTECTED_BITS (type) =
7123 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7124 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
7126 TYPE_FIELD_IGNORE_BITS (type) =
7127 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7128 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
7131 /* If the type has baseclasses, allocate and clear a bit vector for
7132 TYPE_FIELD_VIRTUAL_BITS. */
7133 if (fip->nbaseclasses && cu->language != language_ada)
7135 int num_bytes = B_BYTES (fip->nbaseclasses);
7136 unsigned char *pointer;
7138 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7139 pointer = TYPE_ALLOC (type, num_bytes);
7140 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
7141 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
7142 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
7145 /* Copy the saved-up fields into the field vector. Start from the head of
7146 the list, adding to the tail of the field array, so that they end up in
7147 the same order in the array in which they were added to the list. */
7148 while (nfields-- > 0)
7150 struct nextfield *fieldp;
7154 fieldp = fip->fields;
7155 fip->fields = fieldp->next;
7159 fieldp = fip->baseclasses;
7160 fip->baseclasses = fieldp->next;
7163 TYPE_FIELD (type, nfields) = fieldp->field;
7164 switch (fieldp->accessibility)
7166 case DW_ACCESS_private:
7167 if (cu->language != language_ada)
7168 SET_TYPE_FIELD_PRIVATE (type, nfields);
7171 case DW_ACCESS_protected:
7172 if (cu->language != language_ada)
7173 SET_TYPE_FIELD_PROTECTED (type, nfields);
7176 case DW_ACCESS_public:
7180 /* Unknown accessibility. Complain and treat it as public. */
7182 complaint (&symfile_complaints, _("unsupported accessibility %d"),
7183 fieldp->accessibility);
7187 if (nfields < fip->nbaseclasses)
7189 switch (fieldp->virtuality)
7191 case DW_VIRTUALITY_virtual:
7192 case DW_VIRTUALITY_pure_virtual:
7193 if (cu->language == language_ada)
7194 error (_("unexpected virtuality in component of Ada type"));
7195 SET_TYPE_FIELD_VIRTUAL (type, nfields);
7202 /* Add a member function to the proper fieldlist. */
7205 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
7206 struct type *type, struct dwarf2_cu *cu)
7208 struct objfile *objfile = cu->objfile;
7209 struct attribute *attr;
7210 struct fnfieldlist *flp;
7212 struct fn_field *fnp;
7214 struct nextfnfield *new_fnfield;
7215 struct type *this_type;
7216 enum dwarf_access_attribute accessibility;
7218 if (cu->language == language_ada)
7219 error (_("unexpected member function in Ada type"));
7221 /* Get name of member function. */
7222 fieldname = dwarf2_name (die, cu);
7223 if (fieldname == NULL)
7226 /* Look up member function name in fieldlist. */
7227 for (i = 0; i < fip->nfnfields; i++)
7229 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7233 /* Create new list element if necessary. */
7234 if (i < fip->nfnfields)
7235 flp = &fip->fnfieldlists[i];
7238 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7240 fip->fnfieldlists = (struct fnfieldlist *)
7241 xrealloc (fip->fnfieldlists,
7242 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7243 * sizeof (struct fnfieldlist));
7244 if (fip->nfnfields == 0)
7245 make_cleanup (free_current_contents, &fip->fnfieldlists);
7247 flp = &fip->fnfieldlists[fip->nfnfields];
7248 flp->name = fieldname;
7251 i = fip->nfnfields++;
7254 /* Create a new member function field and chain it to the field list
7256 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7257 make_cleanup (xfree, new_fnfield);
7258 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7259 new_fnfield->next = flp->head;
7260 flp->head = new_fnfield;
7263 /* Fill in the member function field info. */
7264 fnp = &new_fnfield->fnfield;
7266 /* Delay processing of the physname until later. */
7267 if (cu->language == language_cplus || cu->language == language_java)
7269 add_to_method_list (type, i, flp->length - 1, fieldname,
7274 const char *physname = dwarf2_physname (fieldname, die, cu);
7275 fnp->physname = physname ? physname : "";
7278 fnp->type = alloc_type (objfile);
7279 this_type = read_type_die (die, cu);
7280 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7282 int nparams = TYPE_NFIELDS (this_type);
7284 /* TYPE is the domain of this method, and THIS_TYPE is the type
7285 of the method itself (TYPE_CODE_METHOD). */
7286 smash_to_method_type (fnp->type, type,
7287 TYPE_TARGET_TYPE (this_type),
7288 TYPE_FIELDS (this_type),
7289 TYPE_NFIELDS (this_type),
7290 TYPE_VARARGS (this_type));
7292 /* Handle static member functions.
7293 Dwarf2 has no clean way to discern C++ static and non-static
7294 member functions. G++ helps GDB by marking the first
7295 parameter for non-static member functions (which is the this
7296 pointer) as artificial. We obtain this information from
7297 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7298 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7299 fnp->voffset = VOFFSET_STATIC;
7302 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7303 dwarf2_full_name (fieldname, die, cu));
7305 /* Get fcontext from DW_AT_containing_type if present. */
7306 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7307 fnp->fcontext = die_containing_type (die, cu);
7309 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7310 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7312 /* Get accessibility. */
7313 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7315 accessibility = DW_UNSND (attr);
7317 accessibility = dwarf2_default_access_attribute (die, cu);
7318 switch (accessibility)
7320 case DW_ACCESS_private:
7321 fnp->is_private = 1;
7323 case DW_ACCESS_protected:
7324 fnp->is_protected = 1;
7328 /* Check for artificial methods. */
7329 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7330 if (attr && DW_UNSND (attr) != 0)
7331 fnp->is_artificial = 1;
7333 /* Get index in virtual function table if it is a virtual member
7334 function. For older versions of GCC, this is an offset in the
7335 appropriate virtual table, as specified by DW_AT_containing_type.
7336 For everyone else, it is an expression to be evaluated relative
7337 to the object address. */
7339 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7342 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7344 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7346 /* Old-style GCC. */
7347 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7349 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7350 || (DW_BLOCK (attr)->size > 1
7351 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7352 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7354 struct dwarf_block blk;
7357 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7359 blk.size = DW_BLOCK (attr)->size - offset;
7360 blk.data = DW_BLOCK (attr)->data + offset;
7361 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7362 if ((fnp->voffset % cu->header.addr_size) != 0)
7363 dwarf2_complex_location_expr_complaint ();
7365 fnp->voffset /= cu->header.addr_size;
7369 dwarf2_complex_location_expr_complaint ();
7372 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7374 else if (attr_form_is_section_offset (attr))
7376 dwarf2_complex_location_expr_complaint ();
7380 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7386 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7387 if (attr && DW_UNSND (attr))
7389 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7390 complaint (&symfile_complaints,
7391 _("Member function \"%s\" (offset %d) is virtual "
7392 "but the vtable offset is not specified"),
7393 fieldname, die->offset);
7394 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7395 TYPE_CPLUS_DYNAMIC (type) = 1;
7400 /* Create the vector of member function fields, and attach it to the type. */
7403 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7404 struct dwarf2_cu *cu)
7406 struct fnfieldlist *flp;
7409 if (cu->language == language_ada)
7410 error (_("unexpected member functions in Ada type"));
7412 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7413 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7414 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7416 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7418 struct nextfnfield *nfp = flp->head;
7419 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7422 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7423 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7424 fn_flp->fn_fields = (struct fn_field *)
7425 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7426 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7427 fn_flp->fn_fields[k] = nfp->fnfield;
7430 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7433 /* Returns non-zero if NAME is the name of a vtable member in CU's
7434 language, zero otherwise. */
7436 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7438 static const char vptr[] = "_vptr";
7439 static const char vtable[] = "vtable";
7441 /* Look for the C++ and Java forms of the vtable. */
7442 if ((cu->language == language_java
7443 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7444 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7445 && is_cplus_marker (name[sizeof (vptr) - 1])))
7451 /* GCC outputs unnamed structures that are really pointers to member
7452 functions, with the ABI-specified layout. If TYPE describes
7453 such a structure, smash it into a member function type.
7455 GCC shouldn't do this; it should just output pointer to member DIEs.
7456 This is GCC PR debug/28767. */
7459 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7461 struct type *pfn_type, *domain_type, *new_type;
7463 /* Check for a structure with no name and two children. */
7464 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7467 /* Check for __pfn and __delta members. */
7468 if (TYPE_FIELD_NAME (type, 0) == NULL
7469 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7470 || TYPE_FIELD_NAME (type, 1) == NULL
7471 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7474 /* Find the type of the method. */
7475 pfn_type = TYPE_FIELD_TYPE (type, 0);
7476 if (pfn_type == NULL
7477 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7478 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7481 /* Look for the "this" argument. */
7482 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7483 if (TYPE_NFIELDS (pfn_type) == 0
7484 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7485 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7488 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7489 new_type = alloc_type (objfile);
7490 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7491 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7492 TYPE_VARARGS (pfn_type));
7493 smash_to_methodptr_type (type, new_type);
7496 /* Called when we find the DIE that starts a structure or union scope
7497 (definition) to create a type for the structure or union. Fill in
7498 the type's name and general properties; the members will not be
7499 processed until process_structure_type.
7501 NOTE: we need to call these functions regardless of whether or not the
7502 DIE has a DW_AT_name attribute, since it might be an anonymous
7503 structure or union. This gets the type entered into our set of
7506 However, if the structure is incomplete (an opaque struct/union)
7507 then suppress creating a symbol table entry for it since gdb only
7508 wants to find the one with the complete definition. Note that if
7509 it is complete, we just call new_symbol, which does it's own
7510 checking about whether the struct/union is anonymous or not (and
7511 suppresses creating a symbol table entry itself). */
7513 static struct type *
7514 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7516 struct objfile *objfile = cu->objfile;
7518 struct attribute *attr;
7521 /* If the definition of this type lives in .debug_types, read that type.
7522 Don't follow DW_AT_specification though, that will take us back up
7523 the chain and we want to go down. */
7524 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7527 struct dwarf2_cu *type_cu = cu;
7528 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7530 /* We could just recurse on read_structure_type, but we need to call
7531 get_die_type to ensure only one type for this DIE is created.
7532 This is important, for example, because for c++ classes we need
7533 TYPE_NAME set which is only done by new_symbol. Blech. */
7534 type = read_type_die (type_die, type_cu);
7536 /* TYPE_CU may not be the same as CU.
7537 Ensure TYPE is recorded in CU's type_hash table. */
7538 return set_die_type (die, type, cu);
7541 type = alloc_type (objfile);
7542 INIT_CPLUS_SPECIFIC (type);
7544 name = dwarf2_name (die, cu);
7547 if (cu->language == language_cplus
7548 || cu->language == language_java)
7550 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7552 /* dwarf2_full_name might have already finished building the DIE's
7553 type. If so, there is no need to continue. */
7554 if (get_die_type (die, cu) != NULL)
7555 return get_die_type (die, cu);
7557 TYPE_TAG_NAME (type) = full_name;
7558 if (die->tag == DW_TAG_structure_type
7559 || die->tag == DW_TAG_class_type)
7560 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7564 /* The name is already allocated along with this objfile, so
7565 we don't need to duplicate it for the type. */
7566 TYPE_TAG_NAME (type) = (char *) name;
7567 if (die->tag == DW_TAG_class_type)
7568 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7572 if (die->tag == DW_TAG_structure_type)
7574 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7576 else if (die->tag == DW_TAG_union_type)
7578 TYPE_CODE (type) = TYPE_CODE_UNION;
7582 TYPE_CODE (type) = TYPE_CODE_CLASS;
7585 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7586 TYPE_DECLARED_CLASS (type) = 1;
7588 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7591 TYPE_LENGTH (type) = DW_UNSND (attr);
7595 TYPE_LENGTH (type) = 0;
7598 TYPE_STUB_SUPPORTED (type) = 1;
7599 if (die_is_declaration (die, cu))
7600 TYPE_STUB (type) = 1;
7601 else if (attr == NULL && die->child == NULL
7602 && producer_is_realview (cu->producer))
7603 /* RealView does not output the required DW_AT_declaration
7604 on incomplete types. */
7605 TYPE_STUB (type) = 1;
7607 /* We need to add the type field to the die immediately so we don't
7608 infinitely recurse when dealing with pointers to the structure
7609 type within the structure itself. */
7610 set_die_type (die, type, cu);
7612 /* set_die_type should be already done. */
7613 set_descriptive_type (type, die, cu);
7618 /* Finish creating a structure or union type, including filling in
7619 its members and creating a symbol for it. */
7622 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7624 struct objfile *objfile = cu->objfile;
7625 struct die_info *child_die = die->child;
7628 type = get_die_type (die, cu);
7630 type = read_structure_type (die, cu);
7632 if (die->child != NULL && ! die_is_declaration (die, cu))
7634 struct field_info fi;
7635 struct die_info *child_die;
7636 VEC (symbolp) *template_args = NULL;
7637 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7639 memset (&fi, 0, sizeof (struct field_info));
7641 child_die = die->child;
7643 while (child_die && child_die->tag)
7645 if (child_die->tag == DW_TAG_member
7646 || child_die->tag == DW_TAG_variable)
7648 /* NOTE: carlton/2002-11-05: A C++ static data member
7649 should be a DW_TAG_member that is a declaration, but
7650 all versions of G++ as of this writing (so through at
7651 least 3.2.1) incorrectly generate DW_TAG_variable
7652 tags for them instead. */
7653 dwarf2_add_field (&fi, child_die, cu);
7655 else if (child_die->tag == DW_TAG_subprogram)
7657 /* C++ member function. */
7658 dwarf2_add_member_fn (&fi, child_die, type, cu);
7660 else if (child_die->tag == DW_TAG_inheritance)
7662 /* C++ base class field. */
7663 dwarf2_add_field (&fi, child_die, cu);
7665 else if (child_die->tag == DW_TAG_typedef)
7666 dwarf2_add_typedef (&fi, child_die, cu);
7667 else if (child_die->tag == DW_TAG_template_type_param
7668 || child_die->tag == DW_TAG_template_value_param)
7670 struct symbol *arg = new_symbol (child_die, NULL, cu);
7673 VEC_safe_push (symbolp, template_args, arg);
7676 child_die = sibling_die (child_die);
7679 /* Attach template arguments to type. */
7680 if (! VEC_empty (symbolp, template_args))
7682 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7683 TYPE_N_TEMPLATE_ARGUMENTS (type)
7684 = VEC_length (symbolp, template_args);
7685 TYPE_TEMPLATE_ARGUMENTS (type)
7686 = obstack_alloc (&objfile->objfile_obstack,
7687 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7688 * sizeof (struct symbol *)));
7689 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7690 VEC_address (symbolp, template_args),
7691 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7692 * sizeof (struct symbol *)));
7693 VEC_free (symbolp, template_args);
7696 /* Attach fields and member functions to the type. */
7698 dwarf2_attach_fields_to_type (&fi, type, cu);
7701 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7703 /* Get the type which refers to the base class (possibly this
7704 class itself) which contains the vtable pointer for the current
7705 class from the DW_AT_containing_type attribute. This use of
7706 DW_AT_containing_type is a GNU extension. */
7708 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7710 struct type *t = die_containing_type (die, cu);
7712 TYPE_VPTR_BASETYPE (type) = t;
7717 /* Our own class provides vtbl ptr. */
7718 for (i = TYPE_NFIELDS (t) - 1;
7719 i >= TYPE_N_BASECLASSES (t);
7722 char *fieldname = TYPE_FIELD_NAME (t, i);
7724 if (is_vtable_name (fieldname, cu))
7726 TYPE_VPTR_FIELDNO (type) = i;
7731 /* Complain if virtual function table field not found. */
7732 if (i < TYPE_N_BASECLASSES (t))
7733 complaint (&symfile_complaints,
7734 _("virtual function table pointer "
7735 "not found when defining class '%s'"),
7736 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7741 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7744 else if (cu->producer
7745 && strncmp (cu->producer,
7746 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7748 /* The IBM XLC compiler does not provide direct indication
7749 of the containing type, but the vtable pointer is
7750 always named __vfp. */
7754 for (i = TYPE_NFIELDS (type) - 1;
7755 i >= TYPE_N_BASECLASSES (type);
7758 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7760 TYPE_VPTR_FIELDNO (type) = i;
7761 TYPE_VPTR_BASETYPE (type) = type;
7768 /* Copy fi.typedef_field_list linked list elements content into the
7769 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7770 if (fi.typedef_field_list)
7772 int i = fi.typedef_field_list_count;
7774 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7775 TYPE_TYPEDEF_FIELD_ARRAY (type)
7776 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7777 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7779 /* Reverse the list order to keep the debug info elements order. */
7782 struct typedef_field *dest, *src;
7784 dest = &TYPE_TYPEDEF_FIELD (type, i);
7785 src = &fi.typedef_field_list->field;
7786 fi.typedef_field_list = fi.typedef_field_list->next;
7791 do_cleanups (back_to);
7793 if (HAVE_CPLUS_STRUCT (type))
7794 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
7797 quirk_gcc_member_function_pointer (type, objfile);
7799 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7800 snapshots) has been known to create a die giving a declaration
7801 for a class that has, as a child, a die giving a definition for a
7802 nested class. So we have to process our children even if the
7803 current die is a declaration. Normally, of course, a declaration
7804 won't have any children at all. */
7806 while (child_die != NULL && child_die->tag)
7808 if (child_die->tag == DW_TAG_member
7809 || child_die->tag == DW_TAG_variable
7810 || child_die->tag == DW_TAG_inheritance
7811 || child_die->tag == DW_TAG_template_value_param
7812 || child_die->tag == DW_TAG_template_type_param)
7817 process_die (child_die, cu);
7819 child_die = sibling_die (child_die);
7822 /* Do not consider external references. According to the DWARF standard,
7823 these DIEs are identified by the fact that they have no byte_size
7824 attribute, and a declaration attribute. */
7825 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7826 || !die_is_declaration (die, cu))
7827 new_symbol (die, type, cu);
7830 /* Given a DW_AT_enumeration_type die, set its type. We do not
7831 complete the type's fields yet, or create any symbols. */
7833 static struct type *
7834 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7836 struct objfile *objfile = cu->objfile;
7838 struct attribute *attr;
7841 /* If the definition of this type lives in .debug_types, read that type.
7842 Don't follow DW_AT_specification though, that will take us back up
7843 the chain and we want to go down. */
7844 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7847 struct dwarf2_cu *type_cu = cu;
7848 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7850 type = read_type_die (type_die, type_cu);
7852 /* TYPE_CU may not be the same as CU.
7853 Ensure TYPE is recorded in CU's type_hash table. */
7854 return set_die_type (die, type, cu);
7857 type = alloc_type (objfile);
7859 TYPE_CODE (type) = TYPE_CODE_ENUM;
7860 name = dwarf2_full_name (NULL, die, cu);
7862 TYPE_TAG_NAME (type) = (char *) name;
7864 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7867 TYPE_LENGTH (type) = DW_UNSND (attr);
7871 TYPE_LENGTH (type) = 0;
7874 /* The enumeration DIE can be incomplete. In Ada, any type can be
7875 declared as private in the package spec, and then defined only
7876 inside the package body. Such types are known as Taft Amendment
7877 Types. When another package uses such a type, an incomplete DIE
7878 may be generated by the compiler. */
7879 if (die_is_declaration (die, cu))
7880 TYPE_STUB (type) = 1;
7882 return set_die_type (die, type, cu);
7885 /* Given a pointer to a die which begins an enumeration, process all
7886 the dies that define the members of the enumeration, and create the
7887 symbol for the enumeration type.
7889 NOTE: We reverse the order of the element list. */
7892 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7894 struct type *this_type;
7896 this_type = get_die_type (die, cu);
7897 if (this_type == NULL)
7898 this_type = read_enumeration_type (die, cu);
7900 if (die->child != NULL)
7902 struct die_info *child_die;
7904 struct field *fields = NULL;
7906 int unsigned_enum = 1;
7909 child_die = die->child;
7910 while (child_die && child_die->tag)
7912 if (child_die->tag != DW_TAG_enumerator)
7914 process_die (child_die, cu);
7918 name = dwarf2_name (child_die, cu);
7921 sym = new_symbol (child_die, this_type, cu);
7922 if (SYMBOL_VALUE (sym) < 0)
7925 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7927 fields = (struct field *)
7929 (num_fields + DW_FIELD_ALLOC_CHUNK)
7930 * sizeof (struct field));
7933 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7934 FIELD_TYPE (fields[num_fields]) = NULL;
7935 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7936 FIELD_BITSIZE (fields[num_fields]) = 0;
7942 child_die = sibling_die (child_die);
7947 TYPE_NFIELDS (this_type) = num_fields;
7948 TYPE_FIELDS (this_type) = (struct field *)
7949 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7950 memcpy (TYPE_FIELDS (this_type), fields,
7951 sizeof (struct field) * num_fields);
7955 TYPE_UNSIGNED (this_type) = 1;
7958 /* If we are reading an enum from a .debug_types unit, and the enum
7959 is a declaration, and the enum is not the signatured type in the
7960 unit, then we do not want to add a symbol for it. Adding a
7961 symbol would in some cases obscure the true definition of the
7962 enum, giving users an incomplete type when the definition is
7963 actually available. Note that we do not want to do this for all
7964 enums which are just declarations, because C++0x allows forward
7965 enum declarations. */
7966 if (cu->per_cu->debug_types_section
7967 && die_is_declaration (die, cu))
7969 struct signatured_type *type_sig;
7972 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
7973 cu->per_cu->debug_types_section,
7974 cu->per_cu->offset);
7975 if (type_sig->type_offset != die->offset)
7979 new_symbol (die, this_type, cu);
7982 /* Extract all information from a DW_TAG_array_type DIE and put it in
7983 the DIE's type field. For now, this only handles one dimensional
7986 static struct type *
7987 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7989 struct objfile *objfile = cu->objfile;
7990 struct die_info *child_die;
7992 struct type *element_type, *range_type, *index_type;
7993 struct type **range_types = NULL;
7994 struct attribute *attr;
7996 struct cleanup *back_to;
7999 element_type = die_type (die, cu);
8001 /* The die_type call above may have already set the type for this DIE. */
8002 type = get_die_type (die, cu);
8006 /* Irix 6.2 native cc creates array types without children for
8007 arrays with unspecified length. */
8008 if (die->child == NULL)
8010 index_type = objfile_type (objfile)->builtin_int;
8011 range_type = create_range_type (NULL, index_type, 0, -1);
8012 type = create_array_type (NULL, element_type, range_type);
8013 return set_die_type (die, type, cu);
8016 back_to = make_cleanup (null_cleanup, NULL);
8017 child_die = die->child;
8018 while (child_die && child_die->tag)
8020 if (child_die->tag == DW_TAG_subrange_type)
8022 struct type *child_type = read_type_die (child_die, cu);
8024 if (child_type != NULL)
8026 /* The range type was succesfully read. Save it for the
8027 array type creation. */
8028 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
8030 range_types = (struct type **)
8031 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
8032 * sizeof (struct type *));
8034 make_cleanup (free_current_contents, &range_types);
8036 range_types[ndim++] = child_type;
8039 child_die = sibling_die (child_die);
8042 /* Dwarf2 dimensions are output from left to right, create the
8043 necessary array types in backwards order. */
8045 type = element_type;
8047 if (read_array_order (die, cu) == DW_ORD_col_major)
8052 type = create_array_type (NULL, type, range_types[i++]);
8057 type = create_array_type (NULL, type, range_types[ndim]);
8060 /* Understand Dwarf2 support for vector types (like they occur on
8061 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8062 array type. This is not part of the Dwarf2/3 standard yet, but a
8063 custom vendor extension. The main difference between a regular
8064 array and the vector variant is that vectors are passed by value
8066 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
8068 make_vector_type (type);
8070 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8071 implementation may choose to implement triple vectors using this
8073 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8076 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
8077 TYPE_LENGTH (type) = DW_UNSND (attr);
8079 complaint (&symfile_complaints,
8080 _("DW_AT_byte_size for array type smaller "
8081 "than the total size of elements"));
8084 name = dwarf2_name (die, cu);
8086 TYPE_NAME (type) = name;
8088 /* Install the type in the die. */
8089 set_die_type (die, type, cu);
8091 /* set_die_type should be already done. */
8092 set_descriptive_type (type, die, cu);
8094 do_cleanups (back_to);
8099 static enum dwarf_array_dim_ordering
8100 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
8102 struct attribute *attr;
8104 attr = dwarf2_attr (die, DW_AT_ordering, cu);
8106 if (attr) return DW_SND (attr);
8108 /* GNU F77 is a special case, as at 08/2004 array type info is the
8109 opposite order to the dwarf2 specification, but data is still
8110 laid out as per normal fortran.
8112 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8113 version checking. */
8115 if (cu->language == language_fortran
8116 && cu->producer && strstr (cu->producer, "GNU F77"))
8118 return DW_ORD_row_major;
8121 switch (cu->language_defn->la_array_ordering)
8123 case array_column_major:
8124 return DW_ORD_col_major;
8125 case array_row_major:
8127 return DW_ORD_row_major;
8131 /* Extract all information from a DW_TAG_set_type DIE and put it in
8132 the DIE's type field. */
8134 static struct type *
8135 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
8137 struct type *domain_type, *set_type;
8138 struct attribute *attr;
8140 domain_type = die_type (die, cu);
8142 /* The die_type call above may have already set the type for this DIE. */
8143 set_type = get_die_type (die, cu);
8147 set_type = create_set_type (NULL, domain_type);
8149 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8151 TYPE_LENGTH (set_type) = DW_UNSND (attr);
8153 return set_die_type (die, set_type, cu);
8156 /* First cut: install each common block member as a global variable. */
8159 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
8161 struct die_info *child_die;
8162 struct attribute *attr;
8164 CORE_ADDR base = (CORE_ADDR) 0;
8166 attr = dwarf2_attr (die, DW_AT_location, cu);
8169 /* Support the .debug_loc offsets. */
8170 if (attr_form_is_block (attr))
8172 base = decode_locdesc (DW_BLOCK (attr), cu);
8174 else if (attr_form_is_section_offset (attr))
8176 dwarf2_complex_location_expr_complaint ();
8180 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8181 "common block member");
8184 if (die->child != NULL)
8186 child_die = die->child;
8187 while (child_die && child_die->tag)
8191 sym = new_symbol (child_die, NULL, cu);
8193 && handle_data_member_location (child_die, cu, &offset))
8195 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
8196 add_symbol_to_list (sym, &global_symbols);
8198 child_die = sibling_die (child_die);
8203 /* Create a type for a C++ namespace. */
8205 static struct type *
8206 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
8208 struct objfile *objfile = cu->objfile;
8209 const char *previous_prefix, *name;
8213 /* For extensions, reuse the type of the original namespace. */
8214 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
8216 struct die_info *ext_die;
8217 struct dwarf2_cu *ext_cu = cu;
8219 ext_die = dwarf2_extension (die, &ext_cu);
8220 type = read_type_die (ext_die, ext_cu);
8222 /* EXT_CU may not be the same as CU.
8223 Ensure TYPE is recorded in CU's type_hash table. */
8224 return set_die_type (die, type, cu);
8227 name = namespace_name (die, &is_anonymous, cu);
8229 /* Now build the name of the current namespace. */
8231 previous_prefix = determine_prefix (die, cu);
8232 if (previous_prefix[0] != '\0')
8233 name = typename_concat (&objfile->objfile_obstack,
8234 previous_prefix, name, 0, cu);
8236 /* Create the type. */
8237 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8239 TYPE_NAME (type) = (char *) name;
8240 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8242 return set_die_type (die, type, cu);
8245 /* Read a C++ namespace. */
8248 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8250 struct objfile *objfile = cu->objfile;
8253 /* Add a symbol associated to this if we haven't seen the namespace
8254 before. Also, add a using directive if it's an anonymous
8257 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8261 type = read_type_die (die, cu);
8262 new_symbol (die, type, cu);
8264 namespace_name (die, &is_anonymous, cu);
8267 const char *previous_prefix = determine_prefix (die, cu);
8269 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8270 NULL, NULL, &objfile->objfile_obstack);
8274 if (die->child != NULL)
8276 struct die_info *child_die = die->child;
8278 while (child_die && child_die->tag)
8280 process_die (child_die, cu);
8281 child_die = sibling_die (child_die);
8286 /* Read a Fortran module as type. This DIE can be only a declaration used for
8287 imported module. Still we need that type as local Fortran "use ... only"
8288 declaration imports depend on the created type in determine_prefix. */
8290 static struct type *
8291 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8293 struct objfile *objfile = cu->objfile;
8297 module_name = dwarf2_name (die, cu);
8299 complaint (&symfile_complaints,
8300 _("DW_TAG_module has no name, offset 0x%x"),
8302 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8304 /* determine_prefix uses TYPE_TAG_NAME. */
8305 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8307 return set_die_type (die, type, cu);
8310 /* Read a Fortran module. */
8313 read_module (struct die_info *die, struct dwarf2_cu *cu)
8315 struct die_info *child_die = die->child;
8317 while (child_die && child_die->tag)
8319 process_die (child_die, cu);
8320 child_die = sibling_die (child_die);
8324 /* Return the name of the namespace represented by DIE. Set
8325 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8329 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8331 struct die_info *current_die;
8332 const char *name = NULL;
8334 /* Loop through the extensions until we find a name. */
8336 for (current_die = die;
8337 current_die != NULL;
8338 current_die = dwarf2_extension (die, &cu))
8340 name = dwarf2_name (current_die, cu);
8345 /* Is it an anonymous namespace? */
8347 *is_anonymous = (name == NULL);
8349 name = CP_ANONYMOUS_NAMESPACE_STR;
8354 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8355 the user defined type vector. */
8357 static struct type *
8358 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8360 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8361 struct comp_unit_head *cu_header = &cu->header;
8363 struct attribute *attr_byte_size;
8364 struct attribute *attr_address_class;
8365 int byte_size, addr_class;
8366 struct type *target_type;
8368 target_type = die_type (die, cu);
8370 /* The die_type call above may have already set the type for this DIE. */
8371 type = get_die_type (die, cu);
8375 type = lookup_pointer_type (target_type);
8377 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8379 byte_size = DW_UNSND (attr_byte_size);
8381 byte_size = cu_header->addr_size;
8383 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8384 if (attr_address_class)
8385 addr_class = DW_UNSND (attr_address_class);
8387 addr_class = DW_ADDR_none;
8389 /* If the pointer size or address class is different than the
8390 default, create a type variant marked as such and set the
8391 length accordingly. */
8392 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8394 if (gdbarch_address_class_type_flags_p (gdbarch))
8398 type_flags = gdbarch_address_class_type_flags
8399 (gdbarch, byte_size, addr_class);
8400 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8402 type = make_type_with_address_space (type, type_flags);
8404 else if (TYPE_LENGTH (type) != byte_size)
8406 complaint (&symfile_complaints,
8407 _("invalid pointer size %d"), byte_size);
8411 /* Should we also complain about unhandled address classes? */
8415 TYPE_LENGTH (type) = byte_size;
8416 return set_die_type (die, type, cu);
8419 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8420 the user defined type vector. */
8422 static struct type *
8423 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8426 struct type *to_type;
8427 struct type *domain;
8429 to_type = die_type (die, cu);
8430 domain = die_containing_type (die, cu);
8432 /* The calls above may have already set the type for this DIE. */
8433 type = get_die_type (die, cu);
8437 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8438 type = lookup_methodptr_type (to_type);
8440 type = lookup_memberptr_type (to_type, domain);
8442 return set_die_type (die, type, cu);
8445 /* Extract all information from a DW_TAG_reference_type DIE and add to
8446 the user defined type vector. */
8448 static struct type *
8449 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8451 struct comp_unit_head *cu_header = &cu->header;
8452 struct type *type, *target_type;
8453 struct attribute *attr;
8455 target_type = die_type (die, cu);
8457 /* The die_type call above may have already set the type for this DIE. */
8458 type = get_die_type (die, cu);
8462 type = lookup_reference_type (target_type);
8463 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8466 TYPE_LENGTH (type) = DW_UNSND (attr);
8470 TYPE_LENGTH (type) = cu_header->addr_size;
8472 return set_die_type (die, type, cu);
8475 static struct type *
8476 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8478 struct type *base_type, *cv_type;
8480 base_type = die_type (die, cu);
8482 /* The die_type call above may have already set the type for this DIE. */
8483 cv_type = get_die_type (die, cu);
8487 /* In case the const qualifier is applied to an array type, the element type
8488 is so qualified, not the array type (section 6.7.3 of C99). */
8489 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8491 struct type *el_type, *inner_array;
8493 base_type = copy_type (base_type);
8494 inner_array = base_type;
8496 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8498 TYPE_TARGET_TYPE (inner_array) =
8499 copy_type (TYPE_TARGET_TYPE (inner_array));
8500 inner_array = TYPE_TARGET_TYPE (inner_array);
8503 el_type = TYPE_TARGET_TYPE (inner_array);
8504 TYPE_TARGET_TYPE (inner_array) =
8505 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8507 return set_die_type (die, base_type, cu);
8510 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8511 return set_die_type (die, cv_type, cu);
8514 static struct type *
8515 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8517 struct type *base_type, *cv_type;
8519 base_type = die_type (die, cu);
8521 /* The die_type call above may have already set the type for this DIE. */
8522 cv_type = get_die_type (die, cu);
8526 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8527 return set_die_type (die, cv_type, cu);
8530 /* Extract all information from a DW_TAG_string_type DIE and add to
8531 the user defined type vector. It isn't really a user defined type,
8532 but it behaves like one, with other DIE's using an AT_user_def_type
8533 attribute to reference it. */
8535 static struct type *
8536 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8538 struct objfile *objfile = cu->objfile;
8539 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8540 struct type *type, *range_type, *index_type, *char_type;
8541 struct attribute *attr;
8542 unsigned int length;
8544 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8547 length = DW_UNSND (attr);
8551 /* Check for the DW_AT_byte_size attribute. */
8552 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8555 length = DW_UNSND (attr);
8563 index_type = objfile_type (objfile)->builtin_int;
8564 range_type = create_range_type (NULL, index_type, 1, length);
8565 char_type = language_string_char_type (cu->language_defn, gdbarch);
8566 type = create_string_type (NULL, char_type, range_type);
8568 return set_die_type (die, type, cu);
8571 /* Handle DIES due to C code like:
8575 int (*funcp)(int a, long l);
8579 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8581 static struct type *
8582 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8584 struct objfile *objfile = cu->objfile;
8585 struct type *type; /* Type that this function returns. */
8586 struct type *ftype; /* Function that returns above type. */
8587 struct attribute *attr;
8589 type = die_type (die, cu);
8591 /* The die_type call above may have already set the type for this DIE. */
8592 ftype = get_die_type (die, cu);
8596 ftype = lookup_function_type (type);
8598 /* All functions in C++, Pascal and Java have prototypes. */
8599 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8600 if ((attr && (DW_UNSND (attr) != 0))
8601 || cu->language == language_cplus
8602 || cu->language == language_java
8603 || cu->language == language_pascal)
8604 TYPE_PROTOTYPED (ftype) = 1;
8605 else if (producer_is_realview (cu->producer))
8606 /* RealView does not emit DW_AT_prototyped. We can not
8607 distinguish prototyped and unprototyped functions; default to
8608 prototyped, since that is more common in modern code (and
8609 RealView warns about unprototyped functions). */
8610 TYPE_PROTOTYPED (ftype) = 1;
8612 /* Store the calling convention in the type if it's available in
8613 the subroutine die. Otherwise set the calling convention to
8614 the default value DW_CC_normal. */
8615 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8617 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8618 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8619 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8621 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8623 /* We need to add the subroutine type to the die immediately so
8624 we don't infinitely recurse when dealing with parameters
8625 declared as the same subroutine type. */
8626 set_die_type (die, ftype, cu);
8628 if (die->child != NULL)
8630 struct type *void_type = objfile_type (objfile)->builtin_void;
8631 struct die_info *child_die;
8632 int nparams, iparams;
8634 /* Count the number of parameters.
8635 FIXME: GDB currently ignores vararg functions, but knows about
8636 vararg member functions. */
8638 child_die = die->child;
8639 while (child_die && child_die->tag)
8641 if (child_die->tag == DW_TAG_formal_parameter)
8643 else if (child_die->tag == DW_TAG_unspecified_parameters)
8644 TYPE_VARARGS (ftype) = 1;
8645 child_die = sibling_die (child_die);
8648 /* Allocate storage for parameters and fill them in. */
8649 TYPE_NFIELDS (ftype) = nparams;
8650 TYPE_FIELDS (ftype) = (struct field *)
8651 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8653 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8654 even if we error out during the parameters reading below. */
8655 for (iparams = 0; iparams < nparams; iparams++)
8656 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8659 child_die = die->child;
8660 while (child_die && child_die->tag)
8662 if (child_die->tag == DW_TAG_formal_parameter)
8664 struct type *arg_type;
8666 /* DWARF version 2 has no clean way to discern C++
8667 static and non-static member functions. G++ helps
8668 GDB by marking the first parameter for non-static
8669 member functions (which is the this pointer) as
8670 artificial. We pass this information to
8671 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8673 DWARF version 3 added DW_AT_object_pointer, which GCC
8674 4.5 does not yet generate. */
8675 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8677 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8680 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8682 /* GCC/43521: In java, the formal parameter
8683 "this" is sometimes not marked with DW_AT_artificial. */
8684 if (cu->language == language_java)
8686 const char *name = dwarf2_name (child_die, cu);
8688 if (name && !strcmp (name, "this"))
8689 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8692 arg_type = die_type (child_die, cu);
8694 /* RealView does not mark THIS as const, which the testsuite
8695 expects. GCC marks THIS as const in method definitions,
8696 but not in the class specifications (GCC PR 43053). */
8697 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8698 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8701 struct dwarf2_cu *arg_cu = cu;
8702 const char *name = dwarf2_name (child_die, cu);
8704 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8707 /* If the compiler emits this, use it. */
8708 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8711 else if (name && strcmp (name, "this") == 0)
8712 /* Function definitions will have the argument names. */
8714 else if (name == NULL && iparams == 0)
8715 /* Declarations may not have the names, so like
8716 elsewhere in GDB, assume an artificial first
8717 argument is "this". */
8721 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8725 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8728 child_die = sibling_die (child_die);
8735 static struct type *
8736 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8738 struct objfile *objfile = cu->objfile;
8739 const char *name = NULL;
8740 struct type *this_type, *target_type;
8742 name = dwarf2_full_name (NULL, die, cu);
8743 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8744 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8745 TYPE_NAME (this_type) = (char *) name;
8746 set_die_type (die, this_type, cu);
8747 target_type = die_type (die, cu);
8748 if (target_type != this_type)
8749 TYPE_TARGET_TYPE (this_type) = target_type;
8752 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8753 spec and cause infinite loops in GDB. */
8754 complaint (&symfile_complaints,
8755 _("Self-referential DW_TAG_typedef "
8756 "- DIE at 0x%x [in module %s]"),
8757 die->offset, objfile->name);
8758 TYPE_TARGET_TYPE (this_type) = NULL;
8763 /* Find a representation of a given base type and install
8764 it in the TYPE field of the die. */
8766 static struct type *
8767 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8769 struct objfile *objfile = cu->objfile;
8771 struct attribute *attr;
8772 int encoding = 0, size = 0;
8774 enum type_code code = TYPE_CODE_INT;
8776 struct type *target_type = NULL;
8778 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8781 encoding = DW_UNSND (attr);
8783 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8786 size = DW_UNSND (attr);
8788 name = dwarf2_name (die, cu);
8791 complaint (&symfile_complaints,
8792 _("DW_AT_name missing from DW_TAG_base_type"));
8797 case DW_ATE_address:
8798 /* Turn DW_ATE_address into a void * pointer. */
8799 code = TYPE_CODE_PTR;
8800 type_flags |= TYPE_FLAG_UNSIGNED;
8801 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8803 case DW_ATE_boolean:
8804 code = TYPE_CODE_BOOL;
8805 type_flags |= TYPE_FLAG_UNSIGNED;
8807 case DW_ATE_complex_float:
8808 code = TYPE_CODE_COMPLEX;
8809 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8811 case DW_ATE_decimal_float:
8812 code = TYPE_CODE_DECFLOAT;
8815 code = TYPE_CODE_FLT;
8819 case DW_ATE_unsigned:
8820 type_flags |= TYPE_FLAG_UNSIGNED;
8821 if (cu->language == language_fortran
8823 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
8824 code = TYPE_CODE_CHAR;
8826 case DW_ATE_signed_char:
8827 if (cu->language == language_ada || cu->language == language_m2
8828 || cu->language == language_pascal
8829 || cu->language == language_fortran)
8830 code = TYPE_CODE_CHAR;
8832 case DW_ATE_unsigned_char:
8833 if (cu->language == language_ada || cu->language == language_m2
8834 || cu->language == language_pascal
8835 || cu->language == language_fortran)
8836 code = TYPE_CODE_CHAR;
8837 type_flags |= TYPE_FLAG_UNSIGNED;
8840 /* We just treat this as an integer and then recognize the
8841 type by name elsewhere. */
8845 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8846 dwarf_type_encoding_name (encoding));
8850 type = init_type (code, size, type_flags, NULL, objfile);
8851 TYPE_NAME (type) = name;
8852 TYPE_TARGET_TYPE (type) = target_type;
8854 if (name && strcmp (name, "char") == 0)
8855 TYPE_NOSIGN (type) = 1;
8857 return set_die_type (die, type, cu);
8860 /* Read the given DW_AT_subrange DIE. */
8862 static struct type *
8863 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8865 struct type *base_type;
8866 struct type *range_type;
8867 struct attribute *attr;
8871 LONGEST negative_mask;
8873 base_type = die_type (die, cu);
8874 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8875 check_typedef (base_type);
8877 /* The die_type call above may have already set the type for this DIE. */
8878 range_type = get_die_type (die, cu);
8882 if (cu->language == language_fortran)
8884 /* FORTRAN implies a lower bound of 1, if not given. */
8888 /* FIXME: For variable sized arrays either of these could be
8889 a variable rather than a constant value. We'll allow it,
8890 but we don't know how to handle it. */
8891 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8893 low = dwarf2_get_attr_constant_value (attr, 0);
8895 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8898 if (attr_form_is_block (attr) || is_ref_attr (attr))
8900 /* GCC encodes arrays with unspecified or dynamic length
8901 with a DW_FORM_block1 attribute or a reference attribute.
8902 FIXME: GDB does not yet know how to handle dynamic
8903 arrays properly, treat them as arrays with unspecified
8906 FIXME: jimb/2003-09-22: GDB does not really know
8907 how to handle arrays of unspecified length
8908 either; we just represent them as zero-length
8909 arrays. Choose an appropriate upper bound given
8910 the lower bound we've computed above. */
8914 high = dwarf2_get_attr_constant_value (attr, 1);
8918 attr = dwarf2_attr (die, DW_AT_count, cu);
8921 int count = dwarf2_get_attr_constant_value (attr, 1);
8922 high = low + count - 1;
8926 /* Unspecified array length. */
8931 /* Dwarf-2 specifications explicitly allows to create subrange types
8932 without specifying a base type.
8933 In that case, the base type must be set to the type of
8934 the lower bound, upper bound or count, in that order, if any of these
8935 three attributes references an object that has a type.
8936 If no base type is found, the Dwarf-2 specifications say that
8937 a signed integer type of size equal to the size of an address should
8939 For the following C code: `extern char gdb_int [];'
8940 GCC produces an empty range DIE.
8941 FIXME: muller/2010-05-28: Possible references to object for low bound,
8942 high bound or count are not yet handled by this code. */
8943 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8945 struct objfile *objfile = cu->objfile;
8946 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8947 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8948 struct type *int_type = objfile_type (objfile)->builtin_int;
8950 /* Test "int", "long int", and "long long int" objfile types,
8951 and select the first one having a size above or equal to the
8952 architecture address size. */
8953 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8954 base_type = int_type;
8957 int_type = objfile_type (objfile)->builtin_long;
8958 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8959 base_type = int_type;
8962 int_type = objfile_type (objfile)->builtin_long_long;
8963 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8964 base_type = int_type;
8970 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8971 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8972 low |= negative_mask;
8973 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8974 high |= negative_mask;
8976 range_type = create_range_type (NULL, base_type, low, high);
8978 /* Mark arrays with dynamic length at least as an array of unspecified
8979 length. GDB could check the boundary but before it gets implemented at
8980 least allow accessing the array elements. */
8981 if (attr && attr_form_is_block (attr))
8982 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8984 /* Ada expects an empty array on no boundary attributes. */
8985 if (attr == NULL && cu->language != language_ada)
8986 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8988 name = dwarf2_name (die, cu);
8990 TYPE_NAME (range_type) = name;
8992 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8994 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8996 set_die_type (die, range_type, cu);
8998 /* set_die_type should be already done. */
8999 set_descriptive_type (range_type, die, cu);
9004 static struct type *
9005 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
9009 /* For now, we only support the C meaning of an unspecified type: void. */
9011 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
9012 TYPE_NAME (type) = dwarf2_name (die, cu);
9014 return set_die_type (die, type, cu);
9017 /* Trivial hash function for die_info: the hash value of a DIE
9018 is its offset in .debug_info for this objfile. */
9021 die_hash (const void *item)
9023 const struct die_info *die = item;
9028 /* Trivial comparison function for die_info structures: two DIEs
9029 are equal if they have the same offset. */
9032 die_eq (const void *item_lhs, const void *item_rhs)
9034 const struct die_info *die_lhs = item_lhs;
9035 const struct die_info *die_rhs = item_rhs;
9037 return die_lhs->offset == die_rhs->offset;
9040 /* Read a whole compilation unit into a linked list of dies. */
9042 static struct die_info *
9043 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
9045 struct die_reader_specs reader_specs;
9046 int read_abbrevs = 0;
9047 struct cleanup *back_to = NULL;
9048 struct die_info *die;
9050 if (cu->dwarf2_abbrevs == NULL)
9052 dwarf2_read_abbrevs (cu);
9053 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
9057 gdb_assert (cu->die_hash == NULL);
9059 = htab_create_alloc_ex (cu->header.length / 12,
9063 &cu->comp_unit_obstack,
9064 hashtab_obstack_allocate,
9065 dummy_obstack_deallocate);
9067 init_cu_die_reader (&reader_specs, cu);
9069 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
9072 do_cleanups (back_to);
9077 /* Main entry point for reading a DIE and all children.
9078 Read the DIE and dump it if requested. */
9080 static struct die_info *
9081 read_die_and_children (const struct die_reader_specs *reader,
9083 gdb_byte **new_info_ptr,
9084 struct die_info *parent)
9086 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
9087 new_info_ptr, parent);
9089 if (dwarf2_die_debug)
9091 fprintf_unfiltered (gdb_stdlog,
9092 "\nRead die from %s of %s:\n",
9093 (reader->cu->per_cu->debug_types_section
9096 reader->abfd->filename);
9097 dump_die (result, dwarf2_die_debug);
9103 /* Read a single die and all its descendents. Set the die's sibling
9104 field to NULL; set other fields in the die correctly, and set all
9105 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9106 location of the info_ptr after reading all of those dies. PARENT
9107 is the parent of the die in question. */
9109 static struct die_info *
9110 read_die_and_children_1 (const struct die_reader_specs *reader,
9112 gdb_byte **new_info_ptr,
9113 struct die_info *parent)
9115 struct die_info *die;
9119 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
9122 *new_info_ptr = cur_ptr;
9125 store_in_ref_table (die, reader->cu);
9128 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
9132 *new_info_ptr = cur_ptr;
9135 die->sibling = NULL;
9136 die->parent = parent;
9140 /* Read a die, all of its descendents, and all of its siblings; set
9141 all of the fields of all of the dies correctly. Arguments are as
9142 in read_die_and_children. */
9144 static struct die_info *
9145 read_die_and_siblings (const struct die_reader_specs *reader,
9147 gdb_byte **new_info_ptr,
9148 struct die_info *parent)
9150 struct die_info *first_die, *last_sibling;
9154 first_die = last_sibling = NULL;
9158 struct die_info *die
9159 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
9163 *new_info_ptr = cur_ptr;
9170 last_sibling->sibling = die;
9176 /* Read the die from the .debug_info section buffer. Set DIEP to
9177 point to a newly allocated die with its information, except for its
9178 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9179 whether the die has children or not. */
9182 read_full_die (const struct die_reader_specs *reader,
9183 struct die_info **diep, gdb_byte *info_ptr,
9186 unsigned int abbrev_number, bytes_read, i, offset;
9187 struct abbrev_info *abbrev;
9188 struct die_info *die;
9189 struct dwarf2_cu *cu = reader->cu;
9190 bfd *abfd = reader->abfd;
9192 offset = info_ptr - reader->buffer;
9193 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9194 info_ptr += bytes_read;
9202 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
9204 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9206 bfd_get_filename (abfd));
9208 die = dwarf_alloc_die (cu, abbrev->num_attrs);
9209 die->offset = offset;
9210 die->tag = abbrev->tag;
9211 die->abbrev = abbrev_number;
9213 die->num_attrs = abbrev->num_attrs;
9215 for (i = 0; i < abbrev->num_attrs; ++i)
9216 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
9217 abfd, info_ptr, cu);
9220 *has_children = abbrev->has_children;
9224 /* In DWARF version 2, the description of the debugging information is
9225 stored in a separate .debug_abbrev section. Before we read any
9226 dies from a section we read in all abbreviations and install them
9227 in a hash table. This function also sets flags in CU describing
9228 the data found in the abbrev table. */
9231 dwarf2_read_abbrevs (struct dwarf2_cu *cu)
9233 bfd *abfd = cu->objfile->obfd;
9234 struct comp_unit_head *cu_header = &cu->header;
9235 gdb_byte *abbrev_ptr;
9236 struct abbrev_info *cur_abbrev;
9237 unsigned int abbrev_number, bytes_read, abbrev_name;
9238 unsigned int abbrev_form, hash_number;
9239 struct attr_abbrev *cur_attrs;
9240 unsigned int allocated_attrs;
9242 /* Initialize dwarf2 abbrevs. */
9243 obstack_init (&cu->abbrev_obstack);
9244 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9246 * sizeof (struct abbrev_info *)));
9247 memset (cu->dwarf2_abbrevs, 0,
9248 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9250 dwarf2_read_section (dwarf2_per_objfile->objfile,
9251 &dwarf2_per_objfile->abbrev);
9252 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
9253 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9254 abbrev_ptr += bytes_read;
9256 allocated_attrs = ATTR_ALLOC_CHUNK;
9257 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9259 /* Loop until we reach an abbrev number of 0. */
9260 while (abbrev_number)
9262 cur_abbrev = dwarf_alloc_abbrev (cu);
9264 /* read in abbrev header */
9265 cur_abbrev->number = abbrev_number;
9266 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9267 abbrev_ptr += bytes_read;
9268 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9271 if (cur_abbrev->tag == DW_TAG_namespace)
9272 cu->has_namespace_info = 1;
9274 /* now read in declarations */
9275 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9276 abbrev_ptr += bytes_read;
9277 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9278 abbrev_ptr += bytes_read;
9281 if (cur_abbrev->num_attrs == allocated_attrs)
9283 allocated_attrs += ATTR_ALLOC_CHUNK;
9285 = xrealloc (cur_attrs, (allocated_attrs
9286 * sizeof (struct attr_abbrev)));
9289 /* Record whether this compilation unit might have
9290 inter-compilation-unit references. If we don't know what form
9291 this attribute will have, then it might potentially be a
9292 DW_FORM_ref_addr, so we conservatively expect inter-CU
9295 if (abbrev_form == DW_FORM_ref_addr
9296 || abbrev_form == DW_FORM_indirect)
9297 cu->has_form_ref_addr = 1;
9299 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9300 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9301 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9302 abbrev_ptr += bytes_read;
9303 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9304 abbrev_ptr += bytes_read;
9307 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9308 (cur_abbrev->num_attrs
9309 * sizeof (struct attr_abbrev)));
9310 memcpy (cur_abbrev->attrs, cur_attrs,
9311 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9313 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9314 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9315 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9317 /* Get next abbreviation.
9318 Under Irix6 the abbreviations for a compilation unit are not
9319 always properly terminated with an abbrev number of 0.
9320 Exit loop if we encounter an abbreviation which we have
9321 already read (which means we are about to read the abbreviations
9322 for the next compile unit) or if the end of the abbreviation
9323 table is reached. */
9324 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9325 >= dwarf2_per_objfile->abbrev.size)
9327 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9328 abbrev_ptr += bytes_read;
9329 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9336 /* Release the memory used by the abbrev table for a compilation unit. */
9339 dwarf2_free_abbrev_table (void *ptr_to_cu)
9341 struct dwarf2_cu *cu = ptr_to_cu;
9343 obstack_free (&cu->abbrev_obstack, NULL);
9344 cu->dwarf2_abbrevs = NULL;
9347 /* Lookup an abbrev_info structure in the abbrev hash table. */
9349 static struct abbrev_info *
9350 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9352 unsigned int hash_number;
9353 struct abbrev_info *abbrev;
9355 hash_number = number % ABBREV_HASH_SIZE;
9356 abbrev = cu->dwarf2_abbrevs[hash_number];
9360 if (abbrev->number == number)
9363 abbrev = abbrev->next;
9368 /* Returns nonzero if TAG represents a type that we might generate a partial
9372 is_type_tag_for_partial (int tag)
9377 /* Some types that would be reasonable to generate partial symbols for,
9378 that we don't at present. */
9379 case DW_TAG_array_type:
9380 case DW_TAG_file_type:
9381 case DW_TAG_ptr_to_member_type:
9382 case DW_TAG_set_type:
9383 case DW_TAG_string_type:
9384 case DW_TAG_subroutine_type:
9386 case DW_TAG_base_type:
9387 case DW_TAG_class_type:
9388 case DW_TAG_interface_type:
9389 case DW_TAG_enumeration_type:
9390 case DW_TAG_structure_type:
9391 case DW_TAG_subrange_type:
9392 case DW_TAG_typedef:
9393 case DW_TAG_union_type:
9400 /* Load all DIEs that are interesting for partial symbols into memory. */
9402 static struct partial_die_info *
9403 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9404 int building_psymtab, struct dwarf2_cu *cu)
9406 struct objfile *objfile = cu->objfile;
9407 struct partial_die_info *part_die;
9408 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9409 struct abbrev_info *abbrev;
9410 unsigned int bytes_read;
9411 unsigned int load_all = 0;
9413 int nesting_level = 1;
9418 if (cu->per_cu && cu->per_cu->load_all_dies)
9422 = htab_create_alloc_ex (cu->header.length / 12,
9426 &cu->comp_unit_obstack,
9427 hashtab_obstack_allocate,
9428 dummy_obstack_deallocate);
9430 part_die = obstack_alloc (&cu->comp_unit_obstack,
9431 sizeof (struct partial_die_info));
9435 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9437 /* A NULL abbrev means the end of a series of children. */
9440 if (--nesting_level == 0)
9442 /* PART_DIE was probably the last thing allocated on the
9443 comp_unit_obstack, so we could call obstack_free
9444 here. We don't do that because the waste is small,
9445 and will be cleaned up when we're done with this
9446 compilation unit. This way, we're also more robust
9447 against other users of the comp_unit_obstack. */
9450 info_ptr += bytes_read;
9451 last_die = parent_die;
9452 parent_die = parent_die->die_parent;
9456 /* Check for template arguments. We never save these; if
9457 they're seen, we just mark the parent, and go on our way. */
9458 if (parent_die != NULL
9459 && cu->language == language_cplus
9460 && (abbrev->tag == DW_TAG_template_type_param
9461 || abbrev->tag == DW_TAG_template_value_param))
9463 parent_die->has_template_arguments = 1;
9467 /* We don't need a partial DIE for the template argument. */
9468 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9474 /* We only recurse into subprograms looking for template arguments.
9475 Skip their other children. */
9477 && cu->language == language_cplus
9478 && parent_die != NULL
9479 && parent_die->tag == DW_TAG_subprogram)
9481 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9485 /* Check whether this DIE is interesting enough to save. Normally
9486 we would not be interested in members here, but there may be
9487 later variables referencing them via DW_AT_specification (for
9490 && !is_type_tag_for_partial (abbrev->tag)
9491 && abbrev->tag != DW_TAG_constant
9492 && abbrev->tag != DW_TAG_enumerator
9493 && abbrev->tag != DW_TAG_subprogram
9494 && abbrev->tag != DW_TAG_lexical_block
9495 && abbrev->tag != DW_TAG_variable
9496 && abbrev->tag != DW_TAG_namespace
9497 && abbrev->tag != DW_TAG_module
9498 && abbrev->tag != DW_TAG_member)
9500 /* Otherwise we skip to the next sibling, if any. */
9501 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9505 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9506 buffer, info_ptr, cu);
9508 /* This two-pass algorithm for processing partial symbols has a
9509 high cost in cache pressure. Thus, handle some simple cases
9510 here which cover the majority of C partial symbols. DIEs
9511 which neither have specification tags in them, nor could have
9512 specification tags elsewhere pointing at them, can simply be
9513 processed and discarded.
9515 This segment is also optional; scan_partial_symbols and
9516 add_partial_symbol will handle these DIEs if we chain
9517 them in normally. When compilers which do not emit large
9518 quantities of duplicate debug information are more common,
9519 this code can probably be removed. */
9521 /* Any complete simple types at the top level (pretty much all
9522 of them, for a language without namespaces), can be processed
9524 if (parent_die == NULL
9525 && part_die->has_specification == 0
9526 && part_die->is_declaration == 0
9527 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9528 || part_die->tag == DW_TAG_base_type
9529 || part_die->tag == DW_TAG_subrange_type))
9531 if (building_psymtab && part_die->name != NULL)
9532 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9533 VAR_DOMAIN, LOC_TYPEDEF,
9534 &objfile->static_psymbols,
9535 0, (CORE_ADDR) 0, cu->language, objfile);
9536 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9540 /* The exception for DW_TAG_typedef with has_children above is
9541 a workaround of GCC PR debug/47510. In the case of this complaint
9542 type_name_no_tag_or_error will error on such types later.
9544 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9545 it could not find the child DIEs referenced later, this is checked
9546 above. In correct DWARF DW_TAG_typedef should have no children. */
9548 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9549 complaint (&symfile_complaints,
9550 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9551 "- DIE at 0x%x [in module %s]"),
9552 part_die->offset, objfile->name);
9554 /* If we're at the second level, and we're an enumerator, and
9555 our parent has no specification (meaning possibly lives in a
9556 namespace elsewhere), then we can add the partial symbol now
9557 instead of queueing it. */
9558 if (part_die->tag == DW_TAG_enumerator
9559 && parent_die != NULL
9560 && parent_die->die_parent == NULL
9561 && parent_die->tag == DW_TAG_enumeration_type
9562 && parent_die->has_specification == 0)
9564 if (part_die->name == NULL)
9565 complaint (&symfile_complaints,
9566 _("malformed enumerator DIE ignored"));
9567 else if (building_psymtab)
9568 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9569 VAR_DOMAIN, LOC_CONST,
9570 (cu->language == language_cplus
9571 || cu->language == language_java)
9572 ? &objfile->global_psymbols
9573 : &objfile->static_psymbols,
9574 0, (CORE_ADDR) 0, cu->language, objfile);
9576 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9580 /* We'll save this DIE so link it in. */
9581 part_die->die_parent = parent_die;
9582 part_die->die_sibling = NULL;
9583 part_die->die_child = NULL;
9585 if (last_die && last_die == parent_die)
9586 last_die->die_child = part_die;
9588 last_die->die_sibling = part_die;
9590 last_die = part_die;
9592 if (first_die == NULL)
9593 first_die = part_die;
9595 /* Maybe add the DIE to the hash table. Not all DIEs that we
9596 find interesting need to be in the hash table, because we
9597 also have the parent/sibling/child chains; only those that we
9598 might refer to by offset later during partial symbol reading.
9600 For now this means things that might have be the target of a
9601 DW_AT_specification, DW_AT_abstract_origin, or
9602 DW_AT_extension. DW_AT_extension will refer only to
9603 namespaces; DW_AT_abstract_origin refers to functions (and
9604 many things under the function DIE, but we do not recurse
9605 into function DIEs during partial symbol reading) and
9606 possibly variables as well; DW_AT_specification refers to
9607 declarations. Declarations ought to have the DW_AT_declaration
9608 flag. It happens that GCC forgets to put it in sometimes, but
9609 only for functions, not for types.
9611 Adding more things than necessary to the hash table is harmless
9612 except for the performance cost. Adding too few will result in
9613 wasted time in find_partial_die, when we reread the compilation
9614 unit with load_all_dies set. */
9617 || abbrev->tag == DW_TAG_constant
9618 || abbrev->tag == DW_TAG_subprogram
9619 || abbrev->tag == DW_TAG_variable
9620 || abbrev->tag == DW_TAG_namespace
9621 || part_die->is_declaration)
9625 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9626 part_die->offset, INSERT);
9630 part_die = obstack_alloc (&cu->comp_unit_obstack,
9631 sizeof (struct partial_die_info));
9633 /* For some DIEs we want to follow their children (if any). For C
9634 we have no reason to follow the children of structures; for other
9635 languages we have to, so that we can get at method physnames
9636 to infer fully qualified class names, for DW_AT_specification,
9637 and for C++ template arguments. For C++, we also look one level
9638 inside functions to find template arguments (if the name of the
9639 function does not already contain the template arguments).
9641 For Ada, we need to scan the children of subprograms and lexical
9642 blocks as well because Ada allows the definition of nested
9643 entities that could be interesting for the debugger, such as
9644 nested subprograms for instance. */
9645 if (last_die->has_children
9647 || last_die->tag == DW_TAG_namespace
9648 || last_die->tag == DW_TAG_module
9649 || last_die->tag == DW_TAG_enumeration_type
9650 || (cu->language == language_cplus
9651 && last_die->tag == DW_TAG_subprogram
9652 && (last_die->name == NULL
9653 || strchr (last_die->name, '<') == NULL))
9654 || (cu->language != language_c
9655 && (last_die->tag == DW_TAG_class_type
9656 || last_die->tag == DW_TAG_interface_type
9657 || last_die->tag == DW_TAG_structure_type
9658 || last_die->tag == DW_TAG_union_type))
9659 || (cu->language == language_ada
9660 && (last_die->tag == DW_TAG_subprogram
9661 || last_die->tag == DW_TAG_lexical_block))))
9664 parent_die = last_die;
9668 /* Otherwise we skip to the next sibling, if any. */
9669 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9671 /* Back to the top, do it again. */
9675 /* Read a minimal amount of information into the minimal die structure. */
9678 read_partial_die (struct partial_die_info *part_die,
9679 struct abbrev_info *abbrev,
9680 unsigned int abbrev_len, bfd *abfd,
9681 gdb_byte *buffer, gdb_byte *info_ptr,
9682 struct dwarf2_cu *cu)
9684 struct objfile *objfile = cu->objfile;
9686 struct attribute attr;
9687 int has_low_pc_attr = 0;
9688 int has_high_pc_attr = 0;
9690 memset (part_die, 0, sizeof (struct partial_die_info));
9692 part_die->offset = info_ptr - buffer;
9694 info_ptr += abbrev_len;
9699 part_die->tag = abbrev->tag;
9700 part_die->has_children = abbrev->has_children;
9702 for (i = 0; i < abbrev->num_attrs; ++i)
9704 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9706 /* Store the data if it is of an attribute we want to keep in a
9707 partial symbol table. */
9711 switch (part_die->tag)
9713 case DW_TAG_compile_unit:
9714 case DW_TAG_type_unit:
9715 /* Compilation units have a DW_AT_name that is a filename, not
9716 a source language identifier. */
9717 case DW_TAG_enumeration_type:
9718 case DW_TAG_enumerator:
9719 /* These tags always have simple identifiers already; no need
9720 to canonicalize them. */
9721 part_die->name = DW_STRING (&attr);
9725 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9726 &objfile->objfile_obstack);
9730 case DW_AT_linkage_name:
9731 case DW_AT_MIPS_linkage_name:
9732 /* Note that both forms of linkage name might appear. We
9733 assume they will be the same, and we only store the last
9735 if (cu->language == language_ada)
9736 part_die->name = DW_STRING (&attr);
9737 part_die->linkage_name = DW_STRING (&attr);
9740 has_low_pc_attr = 1;
9741 part_die->lowpc = DW_ADDR (&attr);
9744 has_high_pc_attr = 1;
9745 part_die->highpc = DW_ADDR (&attr);
9747 case DW_AT_location:
9748 /* Support the .debug_loc offsets. */
9749 if (attr_form_is_block (&attr))
9751 part_die->locdesc = DW_BLOCK (&attr);
9753 else if (attr_form_is_section_offset (&attr))
9755 dwarf2_complex_location_expr_complaint ();
9759 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9760 "partial symbol information");
9763 case DW_AT_external:
9764 part_die->is_external = DW_UNSND (&attr);
9766 case DW_AT_declaration:
9767 part_die->is_declaration = DW_UNSND (&attr);
9770 part_die->has_type = 1;
9772 case DW_AT_abstract_origin:
9773 case DW_AT_specification:
9774 case DW_AT_extension:
9775 part_die->has_specification = 1;
9776 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9779 /* Ignore absolute siblings, they might point outside of
9780 the current compile unit. */
9781 if (attr.form == DW_FORM_ref_addr)
9782 complaint (&symfile_complaints,
9783 _("ignoring absolute DW_AT_sibling"));
9785 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9787 case DW_AT_byte_size:
9788 part_die->has_byte_size = 1;
9790 case DW_AT_calling_convention:
9791 /* DWARF doesn't provide a way to identify a program's source-level
9792 entry point. DW_AT_calling_convention attributes are only meant
9793 to describe functions' calling conventions.
9795 However, because it's a necessary piece of information in
9796 Fortran, and because DW_CC_program is the only piece of debugging
9797 information whose definition refers to a 'main program' at all,
9798 several compilers have begun marking Fortran main programs with
9799 DW_CC_program --- even when those functions use the standard
9800 calling conventions.
9802 So until DWARF specifies a way to provide this information and
9803 compilers pick up the new representation, we'll support this
9805 if (DW_UNSND (&attr) == DW_CC_program
9806 && cu->language == language_fortran)
9808 set_main_name (part_die->name);
9810 /* As this DIE has a static linkage the name would be difficult
9811 to look up later. */
9812 language_of_main = language_fortran;
9820 if (has_low_pc_attr && has_high_pc_attr)
9822 /* When using the GNU linker, .gnu.linkonce. sections are used to
9823 eliminate duplicate copies of functions and vtables and such.
9824 The linker will arbitrarily choose one and discard the others.
9825 The AT_*_pc values for such functions refer to local labels in
9826 these sections. If the section from that file was discarded, the
9827 labels are not in the output, so the relocs get a value of 0.
9828 If this is a discarded function, mark the pc bounds as invalid,
9829 so that GDB will ignore it. */
9830 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9832 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9834 complaint (&symfile_complaints,
9835 _("DW_AT_low_pc %s is zero "
9836 "for DIE at 0x%x [in module %s]"),
9837 paddress (gdbarch, part_die->lowpc),
9838 part_die->offset, objfile->name);
9840 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9841 else if (part_die->lowpc >= part_die->highpc)
9843 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9845 complaint (&symfile_complaints,
9846 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9847 "for DIE at 0x%x [in module %s]"),
9848 paddress (gdbarch, part_die->lowpc),
9849 paddress (gdbarch, part_die->highpc),
9850 part_die->offset, objfile->name);
9853 part_die->has_pc_info = 1;
9859 /* Find a cached partial DIE at OFFSET in CU. */
9861 static struct partial_die_info *
9862 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9864 struct partial_die_info *lookup_die = NULL;
9865 struct partial_die_info part_die;
9867 part_die.offset = offset;
9868 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9873 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9874 except in the case of .debug_types DIEs which do not reference
9875 outside their CU (they do however referencing other types via
9876 DW_FORM_ref_sig8). */
9878 static struct partial_die_info *
9879 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9881 struct objfile *objfile = cu->objfile;
9882 struct dwarf2_per_cu_data *per_cu = NULL;
9883 struct partial_die_info *pd = NULL;
9885 if (cu->per_cu->debug_types_section)
9887 pd = find_partial_die_in_comp_unit (offset, cu);
9893 if (offset_in_cu_p (&cu->header, offset))
9895 pd = find_partial_die_in_comp_unit (offset, cu);
9900 per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
9902 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9903 load_partial_comp_unit (per_cu);
9905 per_cu->cu->last_used = 0;
9906 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9908 if (pd == NULL && per_cu->load_all_dies == 0)
9910 struct cleanup *back_to;
9911 struct partial_die_info comp_unit_die;
9912 struct abbrev_info *abbrev;
9913 unsigned int bytes_read;
9916 per_cu->load_all_dies = 1;
9918 /* Re-read the DIEs. */
9919 back_to = make_cleanup (null_cleanup, 0);
9920 if (per_cu->cu->dwarf2_abbrevs == NULL)
9922 dwarf2_read_abbrevs (per_cu->cu);
9923 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9925 info_ptr = (dwarf2_per_objfile->info.buffer
9926 + per_cu->cu->header.offset
9927 + per_cu->cu->header.first_die_offset);
9928 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9929 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9931 dwarf2_per_objfile->info.buffer, info_ptr,
9933 if (comp_unit_die.has_children)
9934 load_partial_dies (objfile->obfd,
9935 dwarf2_per_objfile->info.buffer, info_ptr,
9937 do_cleanups (back_to);
9939 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9945 internal_error (__FILE__, __LINE__,
9946 _("could not find partial DIE 0x%x "
9947 "in cache [from module %s]\n"),
9948 offset, bfd_get_filename (objfile->obfd));
9952 /* See if we can figure out if the class lives in a namespace. We do
9953 this by looking for a member function; its demangled name will
9954 contain namespace info, if there is any. */
9957 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9958 struct dwarf2_cu *cu)
9960 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9961 what template types look like, because the demangler
9962 frequently doesn't give the same name as the debug info. We
9963 could fix this by only using the demangled name to get the
9964 prefix (but see comment in read_structure_type). */
9966 struct partial_die_info *real_pdi;
9967 struct partial_die_info *child_pdi;
9969 /* If this DIE (this DIE's specification, if any) has a parent, then
9970 we should not do this. We'll prepend the parent's fully qualified
9971 name when we create the partial symbol. */
9973 real_pdi = struct_pdi;
9974 while (real_pdi->has_specification)
9975 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9977 if (real_pdi->die_parent != NULL)
9980 for (child_pdi = struct_pdi->die_child;
9982 child_pdi = child_pdi->die_sibling)
9984 if (child_pdi->tag == DW_TAG_subprogram
9985 && child_pdi->linkage_name != NULL)
9987 char *actual_class_name
9988 = language_class_name_from_physname (cu->language_defn,
9989 child_pdi->linkage_name);
9990 if (actual_class_name != NULL)
9993 = obsavestring (actual_class_name,
9994 strlen (actual_class_name),
9995 &cu->objfile->objfile_obstack);
9996 xfree (actual_class_name);
10003 /* Adjust PART_DIE before generating a symbol for it. This function
10004 may set the is_external flag or change the DIE's name. */
10007 fixup_partial_die (struct partial_die_info *part_die,
10008 struct dwarf2_cu *cu)
10010 /* Once we've fixed up a die, there's no point in doing so again.
10011 This also avoids a memory leak if we were to call
10012 guess_partial_die_structure_name multiple times. */
10013 if (part_die->fixup_called)
10016 /* If we found a reference attribute and the DIE has no name, try
10017 to find a name in the referred to DIE. */
10019 if (part_die->name == NULL && part_die->has_specification)
10021 struct partial_die_info *spec_die;
10023 spec_die = find_partial_die (part_die->spec_offset, cu);
10025 fixup_partial_die (spec_die, cu);
10027 if (spec_die->name)
10029 part_die->name = spec_die->name;
10031 /* Copy DW_AT_external attribute if it is set. */
10032 if (spec_die->is_external)
10033 part_die->is_external = spec_die->is_external;
10037 /* Set default names for some unnamed DIEs. */
10039 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
10040 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
10042 /* If there is no parent die to provide a namespace, and there are
10043 children, see if we can determine the namespace from their linkage
10045 NOTE: We need to do this even if cu->has_namespace_info != 0.
10046 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10047 if (cu->language == language_cplus
10048 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
10049 && part_die->die_parent == NULL
10050 && part_die->has_children
10051 && (part_die->tag == DW_TAG_class_type
10052 || part_die->tag == DW_TAG_structure_type
10053 || part_die->tag == DW_TAG_union_type))
10054 guess_partial_die_structure_name (part_die, cu);
10056 /* GCC might emit a nameless struct or union that has a linkage
10057 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10058 if (part_die->name == NULL
10059 && (part_die->tag == DW_TAG_class_type
10060 || part_die->tag == DW_TAG_interface_type
10061 || part_die->tag == DW_TAG_structure_type
10062 || part_die->tag == DW_TAG_union_type)
10063 && part_die->linkage_name != NULL)
10067 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
10072 /* Strip any leading namespaces/classes, keep only the base name.
10073 DW_AT_name for named DIEs does not contain the prefixes. */
10074 base = strrchr (demangled, ':');
10075 if (base && base > demangled && base[-1] == ':')
10080 part_die->name = obsavestring (base, strlen (base),
10081 &cu->objfile->objfile_obstack);
10086 part_die->fixup_called = 1;
10089 /* Read an attribute value described by an attribute form. */
10092 read_attribute_value (struct attribute *attr, unsigned form,
10093 bfd *abfd, gdb_byte *info_ptr,
10094 struct dwarf2_cu *cu)
10096 struct comp_unit_head *cu_header = &cu->header;
10097 unsigned int bytes_read;
10098 struct dwarf_block *blk;
10103 case DW_FORM_ref_addr:
10104 if (cu->header.version == 2)
10105 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10107 DW_ADDR (attr) = read_offset (abfd, info_ptr,
10108 &cu->header, &bytes_read);
10109 info_ptr += bytes_read;
10112 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10113 info_ptr += bytes_read;
10115 case DW_FORM_block2:
10116 blk = dwarf_alloc_block (cu);
10117 blk->size = read_2_bytes (abfd, info_ptr);
10119 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10120 info_ptr += blk->size;
10121 DW_BLOCK (attr) = blk;
10123 case DW_FORM_block4:
10124 blk = dwarf_alloc_block (cu);
10125 blk->size = read_4_bytes (abfd, info_ptr);
10127 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10128 info_ptr += blk->size;
10129 DW_BLOCK (attr) = blk;
10131 case DW_FORM_data2:
10132 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
10135 case DW_FORM_data4:
10136 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
10139 case DW_FORM_data8:
10140 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
10143 case DW_FORM_sec_offset:
10144 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
10145 info_ptr += bytes_read;
10147 case DW_FORM_string:
10148 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
10149 DW_STRING_IS_CANONICAL (attr) = 0;
10150 info_ptr += bytes_read;
10153 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
10155 DW_STRING_IS_CANONICAL (attr) = 0;
10156 info_ptr += bytes_read;
10158 case DW_FORM_exprloc:
10159 case DW_FORM_block:
10160 blk = dwarf_alloc_block (cu);
10161 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10162 info_ptr += bytes_read;
10163 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10164 info_ptr += blk->size;
10165 DW_BLOCK (attr) = blk;
10167 case DW_FORM_block1:
10168 blk = dwarf_alloc_block (cu);
10169 blk->size = read_1_byte (abfd, info_ptr);
10171 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10172 info_ptr += blk->size;
10173 DW_BLOCK (attr) = blk;
10175 case DW_FORM_data1:
10176 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10180 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10183 case DW_FORM_flag_present:
10184 DW_UNSND (attr) = 1;
10186 case DW_FORM_sdata:
10187 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
10188 info_ptr += bytes_read;
10190 case DW_FORM_udata:
10191 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10192 info_ptr += bytes_read;
10195 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
10199 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
10203 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
10207 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
10210 case DW_FORM_ref_sig8:
10211 /* Convert the signature to something we can record in DW_UNSND
10213 NOTE: This is NULL if the type wasn't found. */
10214 DW_SIGNATURED_TYPE (attr) =
10215 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
10218 case DW_FORM_ref_udata:
10219 DW_ADDR (attr) = (cu->header.offset
10220 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
10221 info_ptr += bytes_read;
10223 case DW_FORM_indirect:
10224 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10225 info_ptr += bytes_read;
10226 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
10229 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10230 dwarf_form_name (form),
10231 bfd_get_filename (abfd));
10234 /* We have seen instances where the compiler tried to emit a byte
10235 size attribute of -1 which ended up being encoded as an unsigned
10236 0xffffffff. Although 0xffffffff is technically a valid size value,
10237 an object of this size seems pretty unlikely so we can relatively
10238 safely treat these cases as if the size attribute was invalid and
10239 treat them as zero by default. */
10240 if (attr->name == DW_AT_byte_size
10241 && form == DW_FORM_data4
10242 && DW_UNSND (attr) >= 0xffffffff)
10245 (&symfile_complaints,
10246 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10247 hex_string (DW_UNSND (attr)));
10248 DW_UNSND (attr) = 0;
10254 /* Read an attribute described by an abbreviated attribute. */
10257 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10258 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10260 attr->name = abbrev->name;
10261 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10264 /* Read dwarf information from a buffer. */
10266 static unsigned int
10267 read_1_byte (bfd *abfd, gdb_byte *buf)
10269 return bfd_get_8 (abfd, buf);
10273 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10275 return bfd_get_signed_8 (abfd, buf);
10278 static unsigned int
10279 read_2_bytes (bfd *abfd, gdb_byte *buf)
10281 return bfd_get_16 (abfd, buf);
10285 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
10287 return bfd_get_signed_16 (abfd, buf);
10290 static unsigned int
10291 read_4_bytes (bfd *abfd, gdb_byte *buf)
10293 return bfd_get_32 (abfd, buf);
10297 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
10299 return bfd_get_signed_32 (abfd, buf);
10303 read_8_bytes (bfd *abfd, gdb_byte *buf)
10305 return bfd_get_64 (abfd, buf);
10309 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10310 unsigned int *bytes_read)
10312 struct comp_unit_head *cu_header = &cu->header;
10313 CORE_ADDR retval = 0;
10315 if (cu_header->signed_addr_p)
10317 switch (cu_header->addr_size)
10320 retval = bfd_get_signed_16 (abfd, buf);
10323 retval = bfd_get_signed_32 (abfd, buf);
10326 retval = bfd_get_signed_64 (abfd, buf);
10329 internal_error (__FILE__, __LINE__,
10330 _("read_address: bad switch, signed [in module %s]"),
10331 bfd_get_filename (abfd));
10336 switch (cu_header->addr_size)
10339 retval = bfd_get_16 (abfd, buf);
10342 retval = bfd_get_32 (abfd, buf);
10345 retval = bfd_get_64 (abfd, buf);
10348 internal_error (__FILE__, __LINE__,
10349 _("read_address: bad switch, "
10350 "unsigned [in module %s]"),
10351 bfd_get_filename (abfd));
10355 *bytes_read = cu_header->addr_size;
10359 /* Read the initial length from a section. The (draft) DWARF 3
10360 specification allows the initial length to take up either 4 bytes
10361 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10362 bytes describe the length and all offsets will be 8 bytes in length
10365 An older, non-standard 64-bit format is also handled by this
10366 function. The older format in question stores the initial length
10367 as an 8-byte quantity without an escape value. Lengths greater
10368 than 2^32 aren't very common which means that the initial 4 bytes
10369 is almost always zero. Since a length value of zero doesn't make
10370 sense for the 32-bit format, this initial zero can be considered to
10371 be an escape value which indicates the presence of the older 64-bit
10372 format. As written, the code can't detect (old format) lengths
10373 greater than 4GB. If it becomes necessary to handle lengths
10374 somewhat larger than 4GB, we could allow other small values (such
10375 as the non-sensical values of 1, 2, and 3) to also be used as
10376 escape values indicating the presence of the old format.
10378 The value returned via bytes_read should be used to increment the
10379 relevant pointer after calling read_initial_length().
10381 [ Note: read_initial_length() and read_offset() are based on the
10382 document entitled "DWARF Debugging Information Format", revision
10383 3, draft 8, dated November 19, 2001. This document was obtained
10386 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10388 This document is only a draft and is subject to change. (So beware.)
10390 Details regarding the older, non-standard 64-bit format were
10391 determined empirically by examining 64-bit ELF files produced by
10392 the SGI toolchain on an IRIX 6.5 machine.
10394 - Kevin, July 16, 2002
10398 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10400 LONGEST length = bfd_get_32 (abfd, buf);
10402 if (length == 0xffffffff)
10404 length = bfd_get_64 (abfd, buf + 4);
10407 else if (length == 0)
10409 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10410 length = bfd_get_64 (abfd, buf);
10421 /* Cover function for read_initial_length.
10422 Returns the length of the object at BUF, and stores the size of the
10423 initial length in *BYTES_READ and stores the size that offsets will be in
10425 If the initial length size is not equivalent to that specified in
10426 CU_HEADER then issue a complaint.
10427 This is useful when reading non-comp-unit headers. */
10430 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10431 const struct comp_unit_head *cu_header,
10432 unsigned int *bytes_read,
10433 unsigned int *offset_size)
10435 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10437 gdb_assert (cu_header->initial_length_size == 4
10438 || cu_header->initial_length_size == 8
10439 || cu_header->initial_length_size == 12);
10441 if (cu_header->initial_length_size != *bytes_read)
10442 complaint (&symfile_complaints,
10443 _("intermixed 32-bit and 64-bit DWARF sections"));
10445 *offset_size = (*bytes_read == 4) ? 4 : 8;
10449 /* Read an offset from the data stream. The size of the offset is
10450 given by cu_header->offset_size. */
10453 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10454 unsigned int *bytes_read)
10456 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10458 *bytes_read = cu_header->offset_size;
10462 /* Read an offset from the data stream. */
10465 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10467 LONGEST retval = 0;
10469 switch (offset_size)
10472 retval = bfd_get_32 (abfd, buf);
10475 retval = bfd_get_64 (abfd, buf);
10478 internal_error (__FILE__, __LINE__,
10479 _("read_offset_1: bad switch [in module %s]"),
10480 bfd_get_filename (abfd));
10487 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10489 /* If the size of a host char is 8 bits, we can return a pointer
10490 to the buffer, otherwise we have to copy the data to a buffer
10491 allocated on the temporary obstack. */
10492 gdb_assert (HOST_CHAR_BIT == 8);
10497 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10499 /* If the size of a host char is 8 bits, we can return a pointer
10500 to the string, otherwise we have to copy the string to a buffer
10501 allocated on the temporary obstack. */
10502 gdb_assert (HOST_CHAR_BIT == 8);
10505 *bytes_read_ptr = 1;
10508 *bytes_read_ptr = strlen ((char *) buf) + 1;
10509 return (char *) buf;
10513 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10515 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10516 if (dwarf2_per_objfile->str.buffer == NULL)
10517 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10518 bfd_get_filename (abfd));
10519 if (str_offset >= dwarf2_per_objfile->str.size)
10520 error (_("DW_FORM_strp pointing outside of "
10521 ".debug_str section [in module %s]"),
10522 bfd_get_filename (abfd));
10523 gdb_assert (HOST_CHAR_BIT == 8);
10524 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10526 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10530 read_indirect_string (bfd *abfd, gdb_byte *buf,
10531 const struct comp_unit_head *cu_header,
10532 unsigned int *bytes_read_ptr)
10534 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10536 return read_indirect_string_at_offset (abfd, str_offset);
10539 static unsigned long
10540 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10542 unsigned long result;
10543 unsigned int num_read;
10545 unsigned char byte;
10553 byte = bfd_get_8 (abfd, buf);
10556 result |= ((unsigned long)(byte & 127) << shift);
10557 if ((byte & 128) == 0)
10563 *bytes_read_ptr = num_read;
10568 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10571 int i, shift, num_read;
10572 unsigned char byte;
10580 byte = bfd_get_8 (abfd, buf);
10583 result |= ((long)(byte & 127) << shift);
10585 if ((byte & 128) == 0)
10590 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10591 result |= -(((long)1) << shift);
10592 *bytes_read_ptr = num_read;
10596 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10599 skip_leb128 (bfd *abfd, gdb_byte *buf)
10605 byte = bfd_get_8 (abfd, buf);
10607 if ((byte & 128) == 0)
10613 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10620 cu->language = language_c;
10622 case DW_LANG_C_plus_plus:
10623 cu->language = language_cplus;
10626 cu->language = language_d;
10628 case DW_LANG_Fortran77:
10629 case DW_LANG_Fortran90:
10630 case DW_LANG_Fortran95:
10631 cu->language = language_fortran;
10633 case DW_LANG_Mips_Assembler:
10634 cu->language = language_asm;
10637 cu->language = language_java;
10639 case DW_LANG_Ada83:
10640 case DW_LANG_Ada95:
10641 cu->language = language_ada;
10643 case DW_LANG_Modula2:
10644 cu->language = language_m2;
10646 case DW_LANG_Pascal83:
10647 cu->language = language_pascal;
10650 cu->language = language_objc;
10652 case DW_LANG_Cobol74:
10653 case DW_LANG_Cobol85:
10655 cu->language = language_minimal;
10658 cu->language_defn = language_def (cu->language);
10661 /* Return the named attribute or NULL if not there. */
10663 static struct attribute *
10664 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10667 struct attribute *spec = NULL;
10669 for (i = 0; i < die->num_attrs; ++i)
10671 if (die->attrs[i].name == name)
10672 return &die->attrs[i];
10673 if (die->attrs[i].name == DW_AT_specification
10674 || die->attrs[i].name == DW_AT_abstract_origin)
10675 spec = &die->attrs[i];
10680 die = follow_die_ref (die, spec, &cu);
10681 return dwarf2_attr (die, name, cu);
10687 /* Return the named attribute or NULL if not there,
10688 but do not follow DW_AT_specification, etc.
10689 This is for use in contexts where we're reading .debug_types dies.
10690 Following DW_AT_specification, DW_AT_abstract_origin will take us
10691 back up the chain, and we want to go down. */
10693 static struct attribute *
10694 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10695 struct dwarf2_cu *cu)
10699 for (i = 0; i < die->num_attrs; ++i)
10700 if (die->attrs[i].name == name)
10701 return &die->attrs[i];
10706 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10707 and holds a non-zero value. This function should only be used for
10708 DW_FORM_flag or DW_FORM_flag_present attributes. */
10711 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10713 struct attribute *attr = dwarf2_attr (die, name, cu);
10715 return (attr && DW_UNSND (attr));
10719 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10721 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10722 which value is non-zero. However, we have to be careful with
10723 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10724 (via dwarf2_flag_true_p) follows this attribute. So we may
10725 end up accidently finding a declaration attribute that belongs
10726 to a different DIE referenced by the specification attribute,
10727 even though the given DIE does not have a declaration attribute. */
10728 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10729 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10732 /* Return the die giving the specification for DIE, if there is
10733 one. *SPEC_CU is the CU containing DIE on input, and the CU
10734 containing the return value on output. If there is no
10735 specification, but there is an abstract origin, that is
10738 static struct die_info *
10739 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10741 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10744 if (spec_attr == NULL)
10745 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10747 if (spec_attr == NULL)
10750 return follow_die_ref (die, spec_attr, spec_cu);
10753 /* Free the line_header structure *LH, and any arrays and strings it
10755 NOTE: This is also used as a "cleanup" function. */
10758 free_line_header (struct line_header *lh)
10760 if (lh->standard_opcode_lengths)
10761 xfree (lh->standard_opcode_lengths);
10763 /* Remember that all the lh->file_names[i].name pointers are
10764 pointers into debug_line_buffer, and don't need to be freed. */
10765 if (lh->file_names)
10766 xfree (lh->file_names);
10768 /* Similarly for the include directory names. */
10769 if (lh->include_dirs)
10770 xfree (lh->include_dirs);
10775 /* Add an entry to LH's include directory table. */
10778 add_include_dir (struct line_header *lh, char *include_dir)
10780 /* Grow the array if necessary. */
10781 if (lh->include_dirs_size == 0)
10783 lh->include_dirs_size = 1; /* for testing */
10784 lh->include_dirs = xmalloc (lh->include_dirs_size
10785 * sizeof (*lh->include_dirs));
10787 else if (lh->num_include_dirs >= lh->include_dirs_size)
10789 lh->include_dirs_size *= 2;
10790 lh->include_dirs = xrealloc (lh->include_dirs,
10791 (lh->include_dirs_size
10792 * sizeof (*lh->include_dirs)));
10795 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10798 /* Add an entry to LH's file name table. */
10801 add_file_name (struct line_header *lh,
10803 unsigned int dir_index,
10804 unsigned int mod_time,
10805 unsigned int length)
10807 struct file_entry *fe;
10809 /* Grow the array if necessary. */
10810 if (lh->file_names_size == 0)
10812 lh->file_names_size = 1; /* for testing */
10813 lh->file_names = xmalloc (lh->file_names_size
10814 * sizeof (*lh->file_names));
10816 else if (lh->num_file_names >= lh->file_names_size)
10818 lh->file_names_size *= 2;
10819 lh->file_names = xrealloc (lh->file_names,
10820 (lh->file_names_size
10821 * sizeof (*lh->file_names)));
10824 fe = &lh->file_names[lh->num_file_names++];
10826 fe->dir_index = dir_index;
10827 fe->mod_time = mod_time;
10828 fe->length = length;
10829 fe->included_p = 0;
10833 /* Read the statement program header starting at OFFSET in
10834 .debug_line, according to the endianness of ABFD. Return a pointer
10835 to a struct line_header, allocated using xmalloc.
10837 NOTE: the strings in the include directory and file name tables of
10838 the returned object point into debug_line_buffer, and must not be
10841 static struct line_header *
10842 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10843 struct dwarf2_cu *cu)
10845 struct cleanup *back_to;
10846 struct line_header *lh;
10847 gdb_byte *line_ptr;
10848 unsigned int bytes_read, offset_size;
10850 char *cur_dir, *cur_file;
10852 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10853 if (dwarf2_per_objfile->line.buffer == NULL)
10855 complaint (&symfile_complaints, _("missing .debug_line section"));
10859 /* Make sure that at least there's room for the total_length field.
10860 That could be 12 bytes long, but we're just going to fudge that. */
10861 if (offset + 4 >= dwarf2_per_objfile->line.size)
10863 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10867 lh = xmalloc (sizeof (*lh));
10868 memset (lh, 0, sizeof (*lh));
10869 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10872 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10874 /* Read in the header. */
10876 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10877 &bytes_read, &offset_size);
10878 line_ptr += bytes_read;
10879 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10880 + dwarf2_per_objfile->line.size))
10882 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10885 lh->statement_program_end = line_ptr + lh->total_length;
10886 lh->version = read_2_bytes (abfd, line_ptr);
10888 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10889 line_ptr += offset_size;
10890 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10892 if (lh->version >= 4)
10894 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10898 lh->maximum_ops_per_instruction = 1;
10900 if (lh->maximum_ops_per_instruction == 0)
10902 lh->maximum_ops_per_instruction = 1;
10903 complaint (&symfile_complaints,
10904 _("invalid maximum_ops_per_instruction "
10905 "in `.debug_line' section"));
10908 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10910 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10912 lh->line_range = read_1_byte (abfd, line_ptr);
10914 lh->opcode_base = read_1_byte (abfd, line_ptr);
10916 lh->standard_opcode_lengths
10917 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10919 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10920 for (i = 1; i < lh->opcode_base; ++i)
10922 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10926 /* Read directory table. */
10927 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10929 line_ptr += bytes_read;
10930 add_include_dir (lh, cur_dir);
10932 line_ptr += bytes_read;
10934 /* Read file name table. */
10935 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10937 unsigned int dir_index, mod_time, length;
10939 line_ptr += bytes_read;
10940 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10941 line_ptr += bytes_read;
10942 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10943 line_ptr += bytes_read;
10944 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10945 line_ptr += bytes_read;
10947 add_file_name (lh, cur_file, dir_index, mod_time, length);
10949 line_ptr += bytes_read;
10950 lh->statement_program_start = line_ptr;
10952 if (line_ptr > (dwarf2_per_objfile->line.buffer
10953 + dwarf2_per_objfile->line.size))
10954 complaint (&symfile_complaints,
10955 _("line number info header doesn't "
10956 "fit in `.debug_line' section"));
10958 discard_cleanups (back_to);
10962 /* Subroutine of dwarf_decode_lines to simplify it.
10963 Return the file name of the psymtab for included file FILE_INDEX
10964 in line header LH of PST.
10965 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10966 If space for the result is malloc'd, it will be freed by a cleanup.
10967 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10970 psymtab_include_file_name (const struct line_header *lh, int file_index,
10971 const struct partial_symtab *pst,
10972 const char *comp_dir)
10974 const struct file_entry fe = lh->file_names [file_index];
10975 char *include_name = fe.name;
10976 char *include_name_to_compare = include_name;
10977 char *dir_name = NULL;
10978 const char *pst_filename;
10979 char *copied_name = NULL;
10983 dir_name = lh->include_dirs[fe.dir_index - 1];
10985 if (!IS_ABSOLUTE_PATH (include_name)
10986 && (dir_name != NULL || comp_dir != NULL))
10988 /* Avoid creating a duplicate psymtab for PST.
10989 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10990 Before we do the comparison, however, we need to account
10991 for DIR_NAME and COMP_DIR.
10992 First prepend dir_name (if non-NULL). If we still don't
10993 have an absolute path prepend comp_dir (if non-NULL).
10994 However, the directory we record in the include-file's
10995 psymtab does not contain COMP_DIR (to match the
10996 corresponding symtab(s)).
11001 bash$ gcc -g ./hello.c
11002 include_name = "hello.c"
11004 DW_AT_comp_dir = comp_dir = "/tmp"
11005 DW_AT_name = "./hello.c" */
11007 if (dir_name != NULL)
11009 include_name = concat (dir_name, SLASH_STRING,
11010 include_name, (char *)NULL);
11011 include_name_to_compare = include_name;
11012 make_cleanup (xfree, include_name);
11014 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
11016 include_name_to_compare = concat (comp_dir, SLASH_STRING,
11017 include_name, (char *)NULL);
11021 pst_filename = pst->filename;
11022 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
11024 copied_name = concat (pst->dirname, SLASH_STRING,
11025 pst_filename, (char *)NULL);
11026 pst_filename = copied_name;
11029 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
11031 if (include_name_to_compare != include_name)
11032 xfree (include_name_to_compare);
11033 if (copied_name != NULL)
11034 xfree (copied_name);
11038 return include_name;
11041 /* Ignore this record_line request. */
11044 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
11049 /* Decode the Line Number Program (LNP) for the given line_header
11050 structure and CU. The actual information extracted and the type
11051 of structures created from the LNP depends on the value of PST.
11053 1. If PST is NULL, then this procedure uses the data from the program
11054 to create all necessary symbol tables, and their linetables.
11056 2. If PST is not NULL, this procedure reads the program to determine
11057 the list of files included by the unit represented by PST, and
11058 builds all the associated partial symbol tables.
11060 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11061 It is used for relative paths in the line table.
11062 NOTE: When processing partial symtabs (pst != NULL),
11063 comp_dir == pst->dirname.
11065 NOTE: It is important that psymtabs have the same file name (via strcmp)
11066 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11067 symtab we don't use it in the name of the psymtabs we create.
11068 E.g. expand_line_sal requires this when finding psymtabs to expand.
11069 A good testcase for this is mb-inline.exp. */
11072 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
11073 struct dwarf2_cu *cu, struct partial_symtab *pst)
11075 gdb_byte *line_ptr, *extended_end;
11076 gdb_byte *line_end;
11077 unsigned int bytes_read, extended_len;
11078 unsigned char op_code, extended_op, adj_opcode;
11079 CORE_ADDR baseaddr;
11080 struct objfile *objfile = cu->objfile;
11081 struct gdbarch *gdbarch = get_objfile_arch (objfile);
11082 const int decode_for_pst_p = (pst != NULL);
11083 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
11084 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
11087 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11089 line_ptr = lh->statement_program_start;
11090 line_end = lh->statement_program_end;
11092 /* Read the statement sequences until there's nothing left. */
11093 while (line_ptr < line_end)
11095 /* state machine registers */
11096 CORE_ADDR address = 0;
11097 unsigned int file = 1;
11098 unsigned int line = 1;
11099 unsigned int column = 0;
11100 int is_stmt = lh->default_is_stmt;
11101 int basic_block = 0;
11102 int end_sequence = 0;
11104 unsigned char op_index = 0;
11106 if (!decode_for_pst_p && lh->num_file_names >= file)
11108 /* Start a subfile for the current file of the state machine. */
11109 /* lh->include_dirs and lh->file_names are 0-based, but the
11110 directory and file name numbers in the statement program
11112 struct file_entry *fe = &lh->file_names[file - 1];
11116 dir = lh->include_dirs[fe->dir_index - 1];
11118 dwarf2_start_subfile (fe->name, dir, comp_dir);
11121 /* Decode the table. */
11122 while (!end_sequence)
11124 op_code = read_1_byte (abfd, line_ptr);
11126 if (line_ptr > line_end)
11128 dwarf2_debug_line_missing_end_sequence_complaint ();
11132 if (op_code >= lh->opcode_base)
11134 /* Special operand. */
11135 adj_opcode = op_code - lh->opcode_base;
11136 address += (((op_index + (adj_opcode / lh->line_range))
11137 / lh->maximum_ops_per_instruction)
11138 * lh->minimum_instruction_length);
11139 op_index = ((op_index + (adj_opcode / lh->line_range))
11140 % lh->maximum_ops_per_instruction);
11141 line += lh->line_base + (adj_opcode % lh->line_range);
11142 if (lh->num_file_names < file || file == 0)
11143 dwarf2_debug_line_missing_file_complaint ();
11144 /* For now we ignore lines not starting on an
11145 instruction boundary. */
11146 else if (op_index == 0)
11148 lh->file_names[file - 1].included_p = 1;
11149 if (!decode_for_pst_p && is_stmt)
11151 if (last_subfile != current_subfile)
11153 addr = gdbarch_addr_bits_remove (gdbarch, address);
11155 (*p_record_line) (last_subfile, 0, addr);
11156 last_subfile = current_subfile;
11158 /* Append row to matrix using current values. */
11159 addr = gdbarch_addr_bits_remove (gdbarch, address);
11160 (*p_record_line) (current_subfile, line, addr);
11165 else switch (op_code)
11167 case DW_LNS_extended_op:
11168 extended_len = read_unsigned_leb128 (abfd, line_ptr,
11170 line_ptr += bytes_read;
11171 extended_end = line_ptr + extended_len;
11172 extended_op = read_1_byte (abfd, line_ptr);
11174 switch (extended_op)
11176 case DW_LNE_end_sequence:
11177 p_record_line = record_line;
11180 case DW_LNE_set_address:
11181 address = read_address (abfd, line_ptr, cu, &bytes_read);
11183 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
11185 /* This line table is for a function which has been
11186 GCd by the linker. Ignore it. PR gdb/12528 */
11189 = line_ptr - dwarf2_per_objfile->line.buffer;
11191 complaint (&symfile_complaints,
11192 _(".debug_line address at offset 0x%lx is 0 "
11194 line_offset, objfile->name);
11195 p_record_line = noop_record_line;
11199 line_ptr += bytes_read;
11200 address += baseaddr;
11202 case DW_LNE_define_file:
11205 unsigned int dir_index, mod_time, length;
11207 cur_file = read_direct_string (abfd, line_ptr,
11209 line_ptr += bytes_read;
11211 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11212 line_ptr += bytes_read;
11214 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11215 line_ptr += bytes_read;
11217 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11218 line_ptr += bytes_read;
11219 add_file_name (lh, cur_file, dir_index, mod_time, length);
11222 case DW_LNE_set_discriminator:
11223 /* The discriminator is not interesting to the debugger;
11225 line_ptr = extended_end;
11228 complaint (&symfile_complaints,
11229 _("mangled .debug_line section"));
11232 /* Make sure that we parsed the extended op correctly. If e.g.
11233 we expected a different address size than the producer used,
11234 we may have read the wrong number of bytes. */
11235 if (line_ptr != extended_end)
11237 complaint (&symfile_complaints,
11238 _("mangled .debug_line section"));
11243 if (lh->num_file_names < file || file == 0)
11244 dwarf2_debug_line_missing_file_complaint ();
11247 lh->file_names[file - 1].included_p = 1;
11248 if (!decode_for_pst_p && is_stmt)
11250 if (last_subfile != current_subfile)
11252 addr = gdbarch_addr_bits_remove (gdbarch, address);
11254 (*p_record_line) (last_subfile, 0, addr);
11255 last_subfile = current_subfile;
11257 addr = gdbarch_addr_bits_remove (gdbarch, address);
11258 (*p_record_line) (current_subfile, line, addr);
11263 case DW_LNS_advance_pc:
11266 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11268 address += (((op_index + adjust)
11269 / lh->maximum_ops_per_instruction)
11270 * lh->minimum_instruction_length);
11271 op_index = ((op_index + adjust)
11272 % lh->maximum_ops_per_instruction);
11273 line_ptr += bytes_read;
11276 case DW_LNS_advance_line:
11277 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11278 line_ptr += bytes_read;
11280 case DW_LNS_set_file:
11282 /* The arrays lh->include_dirs and lh->file_names are
11283 0-based, but the directory and file name numbers in
11284 the statement program are 1-based. */
11285 struct file_entry *fe;
11288 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11289 line_ptr += bytes_read;
11290 if (lh->num_file_names < file || file == 0)
11291 dwarf2_debug_line_missing_file_complaint ();
11294 fe = &lh->file_names[file - 1];
11296 dir = lh->include_dirs[fe->dir_index - 1];
11297 if (!decode_for_pst_p)
11299 last_subfile = current_subfile;
11300 dwarf2_start_subfile (fe->name, dir, comp_dir);
11305 case DW_LNS_set_column:
11306 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11307 line_ptr += bytes_read;
11309 case DW_LNS_negate_stmt:
11310 is_stmt = (!is_stmt);
11312 case DW_LNS_set_basic_block:
11315 /* Add to the address register of the state machine the
11316 address increment value corresponding to special opcode
11317 255. I.e., this value is scaled by the minimum
11318 instruction length since special opcode 255 would have
11319 scaled the increment. */
11320 case DW_LNS_const_add_pc:
11322 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11324 address += (((op_index + adjust)
11325 / lh->maximum_ops_per_instruction)
11326 * lh->minimum_instruction_length);
11327 op_index = ((op_index + adjust)
11328 % lh->maximum_ops_per_instruction);
11331 case DW_LNS_fixed_advance_pc:
11332 address += read_2_bytes (abfd, line_ptr);
11338 /* Unknown standard opcode, ignore it. */
11341 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11343 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11344 line_ptr += bytes_read;
11349 if (lh->num_file_names < file || file == 0)
11350 dwarf2_debug_line_missing_file_complaint ();
11353 lh->file_names[file - 1].included_p = 1;
11354 if (!decode_for_pst_p)
11356 addr = gdbarch_addr_bits_remove (gdbarch, address);
11357 (*p_record_line) (current_subfile, 0, addr);
11362 if (decode_for_pst_p)
11366 /* Now that we're done scanning the Line Header Program, we can
11367 create the psymtab of each included file. */
11368 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11369 if (lh->file_names[file_index].included_p == 1)
11371 char *include_name =
11372 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11373 if (include_name != NULL)
11374 dwarf2_create_include_psymtab (include_name, pst, objfile);
11379 /* Make sure a symtab is created for every file, even files
11380 which contain only variables (i.e. no code with associated
11384 struct file_entry *fe;
11386 for (i = 0; i < lh->num_file_names; i++)
11390 fe = &lh->file_names[i];
11392 dir = lh->include_dirs[fe->dir_index - 1];
11393 dwarf2_start_subfile (fe->name, dir, comp_dir);
11395 /* Skip the main file; we don't need it, and it must be
11396 allocated last, so that it will show up before the
11397 non-primary symtabs in the objfile's symtab list. */
11398 if (current_subfile == first_subfile)
11401 if (current_subfile->symtab == NULL)
11402 current_subfile->symtab = allocate_symtab (current_subfile->name,
11404 fe->symtab = current_subfile->symtab;
11409 /* Start a subfile for DWARF. FILENAME is the name of the file and
11410 DIRNAME the name of the source directory which contains FILENAME
11411 or NULL if not known. COMP_DIR is the compilation directory for the
11412 linetable's compilation unit or NULL if not known.
11413 This routine tries to keep line numbers from identical absolute and
11414 relative file names in a common subfile.
11416 Using the `list' example from the GDB testsuite, which resides in
11417 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11418 of /srcdir/list0.c yields the following debugging information for list0.c:
11420 DW_AT_name: /srcdir/list0.c
11421 DW_AT_comp_dir: /compdir
11422 files.files[0].name: list0.h
11423 files.files[0].dir: /srcdir
11424 files.files[1].name: list0.c
11425 files.files[1].dir: /srcdir
11427 The line number information for list0.c has to end up in a single
11428 subfile, so that `break /srcdir/list0.c:1' works as expected.
11429 start_subfile will ensure that this happens provided that we pass the
11430 concatenation of files.files[1].dir and files.files[1].name as the
11434 dwarf2_start_subfile (char *filename, const char *dirname,
11435 const char *comp_dir)
11439 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11440 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11441 second argument to start_subfile. To be consistent, we do the
11442 same here. In order not to lose the line information directory,
11443 we concatenate it to the filename when it makes sense.
11444 Note that the Dwarf3 standard says (speaking of filenames in line
11445 information): ``The directory index is ignored for file names
11446 that represent full path names''. Thus ignoring dirname in the
11447 `else' branch below isn't an issue. */
11449 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11450 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11452 fullname = filename;
11454 start_subfile (fullname, comp_dir);
11456 if (fullname != filename)
11461 var_decode_location (struct attribute *attr, struct symbol *sym,
11462 struct dwarf2_cu *cu)
11464 struct objfile *objfile = cu->objfile;
11465 struct comp_unit_head *cu_header = &cu->header;
11467 /* NOTE drow/2003-01-30: There used to be a comment and some special
11468 code here to turn a symbol with DW_AT_external and a
11469 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11470 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11471 with some versions of binutils) where shared libraries could have
11472 relocations against symbols in their debug information - the
11473 minimal symbol would have the right address, but the debug info
11474 would not. It's no longer necessary, because we will explicitly
11475 apply relocations when we read in the debug information now. */
11477 /* A DW_AT_location attribute with no contents indicates that a
11478 variable has been optimized away. */
11479 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11481 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11485 /* Handle one degenerate form of location expression specially, to
11486 preserve GDB's previous behavior when section offsets are
11487 specified. If this is just a DW_OP_addr then mark this symbol
11490 if (attr_form_is_block (attr)
11491 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11492 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11494 unsigned int dummy;
11496 SYMBOL_VALUE_ADDRESS (sym) =
11497 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11498 SYMBOL_CLASS (sym) = LOC_STATIC;
11499 fixup_symbol_section (sym, objfile);
11500 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11501 SYMBOL_SECTION (sym));
11505 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11506 expression evaluator, and use LOC_COMPUTED only when necessary
11507 (i.e. when the value of a register or memory location is
11508 referenced, or a thread-local block, etc.). Then again, it might
11509 not be worthwhile. I'm assuming that it isn't unless performance
11510 or memory numbers show me otherwise. */
11512 dwarf2_symbol_mark_computed (attr, sym, cu);
11513 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11515 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11516 cu->has_loclist = 1;
11519 /* Given a pointer to a DWARF information entry, figure out if we need
11520 to make a symbol table entry for it, and if so, create a new entry
11521 and return a pointer to it.
11522 If TYPE is NULL, determine symbol type from the die, otherwise
11523 used the passed type.
11524 If SPACE is not NULL, use it to hold the new symbol. If it is
11525 NULL, allocate a new symbol on the objfile's obstack. */
11527 static struct symbol *
11528 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11529 struct symbol *space)
11531 struct objfile *objfile = cu->objfile;
11532 struct symbol *sym = NULL;
11534 struct attribute *attr = NULL;
11535 struct attribute *attr2 = NULL;
11536 CORE_ADDR baseaddr;
11537 struct pending **list_to_add = NULL;
11539 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11541 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11543 name = dwarf2_name (die, cu);
11546 const char *linkagename;
11547 int suppress_add = 0;
11552 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11553 OBJSTAT (objfile, n_syms++);
11555 /* Cache this symbol's name and the name's demangled form (if any). */
11556 SYMBOL_SET_LANGUAGE (sym, cu->language);
11557 linkagename = dwarf2_physname (name, die, cu);
11558 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11560 /* Fortran does not have mangling standard and the mangling does differ
11561 between gfortran, iFort etc. */
11562 if (cu->language == language_fortran
11563 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11564 symbol_set_demangled_name (&(sym->ginfo),
11565 (char *) dwarf2_full_name (name, die, cu),
11568 /* Default assumptions.
11569 Use the passed type or decode it from the die. */
11570 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11571 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11573 SYMBOL_TYPE (sym) = type;
11575 SYMBOL_TYPE (sym) = die_type (die, cu);
11576 attr = dwarf2_attr (die,
11577 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11581 SYMBOL_LINE (sym) = DW_UNSND (attr);
11584 attr = dwarf2_attr (die,
11585 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11589 int file_index = DW_UNSND (attr);
11591 if (cu->line_header == NULL
11592 || file_index > cu->line_header->num_file_names)
11593 complaint (&symfile_complaints,
11594 _("file index out of range"));
11595 else if (file_index > 0)
11597 struct file_entry *fe;
11599 fe = &cu->line_header->file_names[file_index - 1];
11600 SYMBOL_SYMTAB (sym) = fe->symtab;
11607 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11610 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11612 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11613 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11614 SYMBOL_CLASS (sym) = LOC_LABEL;
11615 add_symbol_to_list (sym, cu->list_in_scope);
11617 case DW_TAG_subprogram:
11618 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11620 SYMBOL_CLASS (sym) = LOC_BLOCK;
11621 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11622 if ((attr2 && (DW_UNSND (attr2) != 0))
11623 || cu->language == language_ada)
11625 /* Subprograms marked external are stored as a global symbol.
11626 Ada subprograms, whether marked external or not, are always
11627 stored as a global symbol, because we want to be able to
11628 access them globally. For instance, we want to be able
11629 to break on a nested subprogram without having to
11630 specify the context. */
11631 list_to_add = &global_symbols;
11635 list_to_add = cu->list_in_scope;
11638 case DW_TAG_inlined_subroutine:
11639 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11641 SYMBOL_CLASS (sym) = LOC_BLOCK;
11642 SYMBOL_INLINED (sym) = 1;
11643 /* Do not add the symbol to any lists. It will be found via
11644 BLOCK_FUNCTION from the blockvector. */
11646 case DW_TAG_template_value_param:
11648 /* Fall through. */
11649 case DW_TAG_constant:
11650 case DW_TAG_variable:
11651 case DW_TAG_member:
11652 /* Compilation with minimal debug info may result in
11653 variables with missing type entries. Change the
11654 misleading `void' type to something sensible. */
11655 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11657 = objfile_type (objfile)->nodebug_data_symbol;
11659 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11660 /* In the case of DW_TAG_member, we should only be called for
11661 static const members. */
11662 if (die->tag == DW_TAG_member)
11664 /* dwarf2_add_field uses die_is_declaration,
11665 so we do the same. */
11666 gdb_assert (die_is_declaration (die, cu));
11671 dwarf2_const_value (attr, sym, cu);
11672 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11675 if (attr2 && (DW_UNSND (attr2) != 0))
11676 list_to_add = &global_symbols;
11678 list_to_add = cu->list_in_scope;
11682 attr = dwarf2_attr (die, DW_AT_location, cu);
11685 var_decode_location (attr, sym, cu);
11686 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11687 if (SYMBOL_CLASS (sym) == LOC_STATIC
11688 && SYMBOL_VALUE_ADDRESS (sym) == 0
11689 && !dwarf2_per_objfile->has_section_at_zero)
11691 /* When a static variable is eliminated by the linker,
11692 the corresponding debug information is not stripped
11693 out, but the variable address is set to null;
11694 do not add such variables into symbol table. */
11696 else if (attr2 && (DW_UNSND (attr2) != 0))
11698 /* Workaround gfortran PR debug/40040 - it uses
11699 DW_AT_location for variables in -fPIC libraries which may
11700 get overriden by other libraries/executable and get
11701 a different address. Resolve it by the minimal symbol
11702 which may come from inferior's executable using copy
11703 relocation. Make this workaround only for gfortran as for
11704 other compilers GDB cannot guess the minimal symbol
11705 Fortran mangling kind. */
11706 if (cu->language == language_fortran && die->parent
11707 && die->parent->tag == DW_TAG_module
11709 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11710 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11712 /* A variable with DW_AT_external is never static,
11713 but it may be block-scoped. */
11714 list_to_add = (cu->list_in_scope == &file_symbols
11715 ? &global_symbols : cu->list_in_scope);
11718 list_to_add = cu->list_in_scope;
11722 /* We do not know the address of this symbol.
11723 If it is an external symbol and we have type information
11724 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11725 The address of the variable will then be determined from
11726 the minimal symbol table whenever the variable is
11728 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11729 if (attr2 && (DW_UNSND (attr2) != 0)
11730 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11732 /* A variable with DW_AT_external is never static, but it
11733 may be block-scoped. */
11734 list_to_add = (cu->list_in_scope == &file_symbols
11735 ? &global_symbols : cu->list_in_scope);
11737 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11739 else if (!die_is_declaration (die, cu))
11741 /* Use the default LOC_OPTIMIZED_OUT class. */
11742 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11744 list_to_add = cu->list_in_scope;
11748 case DW_TAG_formal_parameter:
11749 /* If we are inside a function, mark this as an argument. If
11750 not, we might be looking at an argument to an inlined function
11751 when we do not have enough information to show inlined frames;
11752 pretend it's a local variable in that case so that the user can
11754 if (context_stack_depth > 0
11755 && context_stack[context_stack_depth - 1].name != NULL)
11756 SYMBOL_IS_ARGUMENT (sym) = 1;
11757 attr = dwarf2_attr (die, DW_AT_location, cu);
11760 var_decode_location (attr, sym, cu);
11762 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11765 dwarf2_const_value (attr, sym, cu);
11768 list_to_add = cu->list_in_scope;
11770 case DW_TAG_unspecified_parameters:
11771 /* From varargs functions; gdb doesn't seem to have any
11772 interest in this information, so just ignore it for now.
11775 case DW_TAG_template_type_param:
11777 /* Fall through. */
11778 case DW_TAG_class_type:
11779 case DW_TAG_interface_type:
11780 case DW_TAG_structure_type:
11781 case DW_TAG_union_type:
11782 case DW_TAG_set_type:
11783 case DW_TAG_enumeration_type:
11784 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11785 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11788 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11789 really ever be static objects: otherwise, if you try
11790 to, say, break of a class's method and you're in a file
11791 which doesn't mention that class, it won't work unless
11792 the check for all static symbols in lookup_symbol_aux
11793 saves you. See the OtherFileClass tests in
11794 gdb.c++/namespace.exp. */
11798 list_to_add = (cu->list_in_scope == &file_symbols
11799 && (cu->language == language_cplus
11800 || cu->language == language_java)
11801 ? &global_symbols : cu->list_in_scope);
11803 /* The semantics of C++ state that "struct foo {
11804 ... }" also defines a typedef for "foo". A Java
11805 class declaration also defines a typedef for the
11807 if (cu->language == language_cplus
11808 || cu->language == language_java
11809 || cu->language == language_ada)
11811 /* The symbol's name is already allocated along
11812 with this objfile, so we don't need to
11813 duplicate it for the type. */
11814 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11815 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11820 case DW_TAG_typedef:
11821 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11822 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11823 list_to_add = cu->list_in_scope;
11825 case DW_TAG_base_type:
11826 case DW_TAG_subrange_type:
11827 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11828 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11829 list_to_add = cu->list_in_scope;
11831 case DW_TAG_enumerator:
11832 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11835 dwarf2_const_value (attr, sym, cu);
11838 /* NOTE: carlton/2003-11-10: See comment above in the
11839 DW_TAG_class_type, etc. block. */
11841 list_to_add = (cu->list_in_scope == &file_symbols
11842 && (cu->language == language_cplus
11843 || cu->language == language_java)
11844 ? &global_symbols : cu->list_in_scope);
11847 case DW_TAG_namespace:
11848 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11849 list_to_add = &global_symbols;
11852 /* Not a tag we recognize. Hopefully we aren't processing
11853 trash data, but since we must specifically ignore things
11854 we don't recognize, there is nothing else we should do at
11856 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11857 dwarf_tag_name (die->tag));
11863 sym->hash_next = objfile->template_symbols;
11864 objfile->template_symbols = sym;
11865 list_to_add = NULL;
11868 if (list_to_add != NULL)
11869 add_symbol_to_list (sym, list_to_add);
11871 /* For the benefit of old versions of GCC, check for anonymous
11872 namespaces based on the demangled name. */
11873 if (!processing_has_namespace_info
11874 && cu->language == language_cplus)
11875 cp_scan_for_anonymous_namespaces (sym, objfile);
11880 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11882 static struct symbol *
11883 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11885 return new_symbol_full (die, type, cu, NULL);
11888 /* Given an attr with a DW_FORM_dataN value in host byte order,
11889 zero-extend it as appropriate for the symbol's type. The DWARF
11890 standard (v4) is not entirely clear about the meaning of using
11891 DW_FORM_dataN for a constant with a signed type, where the type is
11892 wider than the data. The conclusion of a discussion on the DWARF
11893 list was that this is unspecified. We choose to always zero-extend
11894 because that is the interpretation long in use by GCC. */
11897 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11898 const char *name, struct obstack *obstack,
11899 struct dwarf2_cu *cu, long *value, int bits)
11901 struct objfile *objfile = cu->objfile;
11902 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11903 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11904 LONGEST l = DW_UNSND (attr);
11906 if (bits < sizeof (*value) * 8)
11908 l &= ((LONGEST) 1 << bits) - 1;
11911 else if (bits == sizeof (*value) * 8)
11915 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11916 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11923 /* Read a constant value from an attribute. Either set *VALUE, or if
11924 the value does not fit in *VALUE, set *BYTES - either already
11925 allocated on the objfile obstack, or newly allocated on OBSTACK,
11926 or, set *BATON, if we translated the constant to a location
11930 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11931 const char *name, struct obstack *obstack,
11932 struct dwarf2_cu *cu,
11933 long *value, gdb_byte **bytes,
11934 struct dwarf2_locexpr_baton **baton)
11936 struct objfile *objfile = cu->objfile;
11937 struct comp_unit_head *cu_header = &cu->header;
11938 struct dwarf_block *blk;
11939 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11940 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11946 switch (attr->form)
11952 if (TYPE_LENGTH (type) != cu_header->addr_size)
11953 dwarf2_const_value_length_mismatch_complaint (name,
11954 cu_header->addr_size,
11955 TYPE_LENGTH (type));
11956 /* Symbols of this form are reasonably rare, so we just
11957 piggyback on the existing location code rather than writing
11958 a new implementation of symbol_computed_ops. */
11959 *baton = obstack_alloc (&objfile->objfile_obstack,
11960 sizeof (struct dwarf2_locexpr_baton));
11961 (*baton)->per_cu = cu->per_cu;
11962 gdb_assert ((*baton)->per_cu);
11964 (*baton)->size = 2 + cu_header->addr_size;
11965 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11966 (*baton)->data = data;
11968 data[0] = DW_OP_addr;
11969 store_unsigned_integer (&data[1], cu_header->addr_size,
11970 byte_order, DW_ADDR (attr));
11971 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11974 case DW_FORM_string:
11976 /* DW_STRING is already allocated on the objfile obstack, point
11978 *bytes = (gdb_byte *) DW_STRING (attr);
11980 case DW_FORM_block1:
11981 case DW_FORM_block2:
11982 case DW_FORM_block4:
11983 case DW_FORM_block:
11984 case DW_FORM_exprloc:
11985 blk = DW_BLOCK (attr);
11986 if (TYPE_LENGTH (type) != blk->size)
11987 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11988 TYPE_LENGTH (type));
11989 *bytes = blk->data;
11992 /* The DW_AT_const_value attributes are supposed to carry the
11993 symbol's value "represented as it would be on the target
11994 architecture." By the time we get here, it's already been
11995 converted to host endianness, so we just need to sign- or
11996 zero-extend it as appropriate. */
11997 case DW_FORM_data1:
11998 *bytes = dwarf2_const_value_data (attr, type, name,
11999 obstack, cu, value, 8);
12001 case DW_FORM_data2:
12002 *bytes = dwarf2_const_value_data (attr, type, name,
12003 obstack, cu, value, 16);
12005 case DW_FORM_data4:
12006 *bytes = dwarf2_const_value_data (attr, type, name,
12007 obstack, cu, value, 32);
12009 case DW_FORM_data8:
12010 *bytes = dwarf2_const_value_data (attr, type, name,
12011 obstack, cu, value, 64);
12014 case DW_FORM_sdata:
12015 *value = DW_SND (attr);
12018 case DW_FORM_udata:
12019 *value = DW_UNSND (attr);
12023 complaint (&symfile_complaints,
12024 _("unsupported const value attribute form: '%s'"),
12025 dwarf_form_name (attr->form));
12032 /* Copy constant value from an attribute to a symbol. */
12035 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
12036 struct dwarf2_cu *cu)
12038 struct objfile *objfile = cu->objfile;
12039 struct comp_unit_head *cu_header = &cu->header;
12042 struct dwarf2_locexpr_baton *baton;
12044 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
12045 SYMBOL_PRINT_NAME (sym),
12046 &objfile->objfile_obstack, cu,
12047 &value, &bytes, &baton);
12051 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12052 SYMBOL_LOCATION_BATON (sym) = baton;
12053 SYMBOL_CLASS (sym) = LOC_COMPUTED;
12055 else if (bytes != NULL)
12057 SYMBOL_VALUE_BYTES (sym) = bytes;
12058 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
12062 SYMBOL_VALUE (sym) = value;
12063 SYMBOL_CLASS (sym) = LOC_CONST;
12067 /* Return the type of the die in question using its DW_AT_type attribute. */
12069 static struct type *
12070 die_type (struct die_info *die, struct dwarf2_cu *cu)
12072 struct attribute *type_attr;
12074 type_attr = dwarf2_attr (die, DW_AT_type, cu);
12077 /* A missing DW_AT_type represents a void type. */
12078 return objfile_type (cu->objfile)->builtin_void;
12081 return lookup_die_type (die, type_attr, cu);
12084 /* True iff CU's producer generates GNAT Ada auxiliary information
12085 that allows to find parallel types through that information instead
12086 of having to do expensive parallel lookups by type name. */
12089 need_gnat_info (struct dwarf2_cu *cu)
12091 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12092 of GNAT produces this auxiliary information, without any indication
12093 that it is produced. Part of enhancing the FSF version of GNAT
12094 to produce that information will be to put in place an indicator
12095 that we can use in order to determine whether the descriptive type
12096 info is available or not. One suggestion that has been made is
12097 to use a new attribute, attached to the CU die. For now, assume
12098 that the descriptive type info is not available. */
12102 /* Return the auxiliary type of the die in question using its
12103 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12104 attribute is not present. */
12106 static struct type *
12107 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
12109 struct attribute *type_attr;
12111 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
12115 return lookup_die_type (die, type_attr, cu);
12118 /* If DIE has a descriptive_type attribute, then set the TYPE's
12119 descriptive type accordingly. */
12122 set_descriptive_type (struct type *type, struct die_info *die,
12123 struct dwarf2_cu *cu)
12125 struct type *descriptive_type = die_descriptive_type (die, cu);
12127 if (descriptive_type)
12129 ALLOCATE_GNAT_AUX_TYPE (type);
12130 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
12134 /* Return the containing type of the die in question using its
12135 DW_AT_containing_type attribute. */
12137 static struct type *
12138 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12140 struct attribute *type_attr;
12142 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
12144 error (_("Dwarf Error: Problem turning containing type into gdb type "
12145 "[in module %s]"), cu->objfile->name);
12147 return lookup_die_type (die, type_attr, cu);
12150 /* Look up the type of DIE in CU using its type attribute ATTR.
12151 If there is no type substitute an error marker. */
12153 static struct type *
12154 lookup_die_type (struct die_info *die, struct attribute *attr,
12155 struct dwarf2_cu *cu)
12157 struct objfile *objfile = cu->objfile;
12158 struct type *this_type;
12160 /* First see if we have it cached. */
12162 if (is_ref_attr (attr))
12164 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12166 this_type = get_die_type_at_offset (offset, cu->per_cu);
12168 else if (attr->form == DW_FORM_ref_sig8)
12170 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12171 struct dwarf2_cu *sig_cu;
12172 unsigned int offset;
12174 /* sig_type will be NULL if the signatured type is missing from
12176 if (sig_type == NULL)
12177 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12178 "at 0x%x [in module %s]"),
12179 die->offset, objfile->name);
12181 gdb_assert (sig_type->per_cu.debug_types_section);
12182 offset = sig_type->per_cu.offset + sig_type->type_offset;
12183 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
12187 dump_die_for_error (die);
12188 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12189 dwarf_attr_name (attr->name), objfile->name);
12192 /* If not cached we need to read it in. */
12194 if (this_type == NULL)
12196 struct die_info *type_die;
12197 struct dwarf2_cu *type_cu = cu;
12199 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
12200 /* If the type is cached, we should have found it above. */
12201 gdb_assert (get_die_type (type_die, type_cu) == NULL);
12202 this_type = read_type_die_1 (type_die, type_cu);
12205 /* If we still don't have a type use an error marker. */
12207 if (this_type == NULL)
12209 char *message, *saved;
12211 /* read_type_die already issued a complaint. */
12212 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12216 saved = obstack_copy0 (&objfile->objfile_obstack,
12217 message, strlen (message));
12220 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
12226 /* Return the type in DIE, CU.
12227 Returns NULL for invalid types.
12229 This first does a lookup in the appropriate type_hash table,
12230 and only reads the die in if necessary.
12232 NOTE: This can be called when reading in partial or full symbols. */
12234 static struct type *
12235 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12237 struct type *this_type;
12239 this_type = get_die_type (die, cu);
12243 return read_type_die_1 (die, cu);
12246 /* Read the type in DIE, CU.
12247 Returns NULL for invalid types. */
12249 static struct type *
12250 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12252 struct type *this_type = NULL;
12256 case DW_TAG_class_type:
12257 case DW_TAG_interface_type:
12258 case DW_TAG_structure_type:
12259 case DW_TAG_union_type:
12260 this_type = read_structure_type (die, cu);
12262 case DW_TAG_enumeration_type:
12263 this_type = read_enumeration_type (die, cu);
12265 case DW_TAG_subprogram:
12266 case DW_TAG_subroutine_type:
12267 case DW_TAG_inlined_subroutine:
12268 this_type = read_subroutine_type (die, cu);
12270 case DW_TAG_array_type:
12271 this_type = read_array_type (die, cu);
12273 case DW_TAG_set_type:
12274 this_type = read_set_type (die, cu);
12276 case DW_TAG_pointer_type:
12277 this_type = read_tag_pointer_type (die, cu);
12279 case DW_TAG_ptr_to_member_type:
12280 this_type = read_tag_ptr_to_member_type (die, cu);
12282 case DW_TAG_reference_type:
12283 this_type = read_tag_reference_type (die, cu);
12285 case DW_TAG_const_type:
12286 this_type = read_tag_const_type (die, cu);
12288 case DW_TAG_volatile_type:
12289 this_type = read_tag_volatile_type (die, cu);
12291 case DW_TAG_string_type:
12292 this_type = read_tag_string_type (die, cu);
12294 case DW_TAG_typedef:
12295 this_type = read_typedef (die, cu);
12297 case DW_TAG_subrange_type:
12298 this_type = read_subrange_type (die, cu);
12300 case DW_TAG_base_type:
12301 this_type = read_base_type (die, cu);
12303 case DW_TAG_unspecified_type:
12304 this_type = read_unspecified_type (die, cu);
12306 case DW_TAG_namespace:
12307 this_type = read_namespace_type (die, cu);
12309 case DW_TAG_module:
12310 this_type = read_module_type (die, cu);
12313 complaint (&symfile_complaints,
12314 _("unexpected tag in read_type_die: '%s'"),
12315 dwarf_tag_name (die->tag));
12322 /* See if we can figure out if the class lives in a namespace. We do
12323 this by looking for a member function; its demangled name will
12324 contain namespace info, if there is any.
12325 Return the computed name or NULL.
12326 Space for the result is allocated on the objfile's obstack.
12327 This is the full-die version of guess_partial_die_structure_name.
12328 In this case we know DIE has no useful parent. */
12331 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12333 struct die_info *spec_die;
12334 struct dwarf2_cu *spec_cu;
12335 struct die_info *child;
12338 spec_die = die_specification (die, &spec_cu);
12339 if (spec_die != NULL)
12345 for (child = die->child;
12347 child = child->sibling)
12349 if (child->tag == DW_TAG_subprogram)
12351 struct attribute *attr;
12353 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12355 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12359 = language_class_name_from_physname (cu->language_defn,
12363 if (actual_name != NULL)
12365 char *die_name = dwarf2_name (die, cu);
12367 if (die_name != NULL
12368 && strcmp (die_name, actual_name) != 0)
12370 /* Strip off the class name from the full name.
12371 We want the prefix. */
12372 int die_name_len = strlen (die_name);
12373 int actual_name_len = strlen (actual_name);
12375 /* Test for '::' as a sanity check. */
12376 if (actual_name_len > die_name_len + 2
12377 && actual_name[actual_name_len
12378 - die_name_len - 1] == ':')
12380 obsavestring (actual_name,
12381 actual_name_len - die_name_len - 2,
12382 &cu->objfile->objfile_obstack);
12385 xfree (actual_name);
12394 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12395 prefix part in such case. See
12396 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12399 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12401 struct attribute *attr;
12404 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12405 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12408 attr = dwarf2_attr (die, DW_AT_name, cu);
12409 if (attr != NULL && DW_STRING (attr) != NULL)
12412 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12414 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12415 if (attr == NULL || DW_STRING (attr) == NULL)
12418 /* dwarf2_name had to be already called. */
12419 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12421 /* Strip the base name, keep any leading namespaces/classes. */
12422 base = strrchr (DW_STRING (attr), ':');
12423 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12426 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12427 &cu->objfile->objfile_obstack);
12430 /* Return the name of the namespace/class that DIE is defined within,
12431 or "" if we can't tell. The caller should not xfree the result.
12433 For example, if we're within the method foo() in the following
12443 then determine_prefix on foo's die will return "N::C". */
12446 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12448 struct die_info *parent, *spec_die;
12449 struct dwarf2_cu *spec_cu;
12450 struct type *parent_type;
12453 if (cu->language != language_cplus && cu->language != language_java
12454 && cu->language != language_fortran)
12457 retval = anonymous_struct_prefix (die, cu);
12461 /* We have to be careful in the presence of DW_AT_specification.
12462 For example, with GCC 3.4, given the code
12466 // Definition of N::foo.
12470 then we'll have a tree of DIEs like this:
12472 1: DW_TAG_compile_unit
12473 2: DW_TAG_namespace // N
12474 3: DW_TAG_subprogram // declaration of N::foo
12475 4: DW_TAG_subprogram // definition of N::foo
12476 DW_AT_specification // refers to die #3
12478 Thus, when processing die #4, we have to pretend that we're in
12479 the context of its DW_AT_specification, namely the contex of die
12482 spec_die = die_specification (die, &spec_cu);
12483 if (spec_die == NULL)
12484 parent = die->parent;
12487 parent = spec_die->parent;
12491 if (parent == NULL)
12493 else if (parent->building_fullname)
12496 const char *parent_name;
12498 /* It has been seen on RealView 2.2 built binaries,
12499 DW_TAG_template_type_param types actually _defined_ as
12500 children of the parent class:
12503 template class <class Enum> Class{};
12504 Class<enum E> class_e;
12506 1: DW_TAG_class_type (Class)
12507 2: DW_TAG_enumeration_type (E)
12508 3: DW_TAG_enumerator (enum1:0)
12509 3: DW_TAG_enumerator (enum2:1)
12511 2: DW_TAG_template_type_param
12512 DW_AT_type DW_FORM_ref_udata (E)
12514 Besides being broken debug info, it can put GDB into an
12515 infinite loop. Consider:
12517 When we're building the full name for Class<E>, we'll start
12518 at Class, and go look over its template type parameters,
12519 finding E. We'll then try to build the full name of E, and
12520 reach here. We're now trying to build the full name of E,
12521 and look over the parent DIE for containing scope. In the
12522 broken case, if we followed the parent DIE of E, we'd again
12523 find Class, and once again go look at its template type
12524 arguments, etc., etc. Simply don't consider such parent die
12525 as source-level parent of this die (it can't be, the language
12526 doesn't allow it), and break the loop here. */
12527 name = dwarf2_name (die, cu);
12528 parent_name = dwarf2_name (parent, cu);
12529 complaint (&symfile_complaints,
12530 _("template param type '%s' defined within parent '%s'"),
12531 name ? name : "<unknown>",
12532 parent_name ? parent_name : "<unknown>");
12536 switch (parent->tag)
12538 case DW_TAG_namespace:
12539 parent_type = read_type_die (parent, cu);
12540 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12541 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12542 Work around this problem here. */
12543 if (cu->language == language_cplus
12544 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12546 /* We give a name to even anonymous namespaces. */
12547 return TYPE_TAG_NAME (parent_type);
12548 case DW_TAG_class_type:
12549 case DW_TAG_interface_type:
12550 case DW_TAG_structure_type:
12551 case DW_TAG_union_type:
12552 case DW_TAG_module:
12553 parent_type = read_type_die (parent, cu);
12554 if (TYPE_TAG_NAME (parent_type) != NULL)
12555 return TYPE_TAG_NAME (parent_type);
12557 /* An anonymous structure is only allowed non-static data
12558 members; no typedefs, no member functions, et cetera.
12559 So it does not need a prefix. */
12561 case DW_TAG_compile_unit:
12562 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12563 if (cu->language == language_cplus
12564 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12565 && die->child != NULL
12566 && (die->tag == DW_TAG_class_type
12567 || die->tag == DW_TAG_structure_type
12568 || die->tag == DW_TAG_union_type))
12570 char *name = guess_full_die_structure_name (die, cu);
12576 return determine_prefix (parent, cu);
12580 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12581 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12582 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12583 an obconcat, otherwise allocate storage for the result. The CU argument is
12584 used to determine the language and hence, the appropriate separator. */
12586 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12589 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12590 int physname, struct dwarf2_cu *cu)
12592 const char *lead = "";
12595 if (suffix == NULL || suffix[0] == '\0'
12596 || prefix == NULL || prefix[0] == '\0')
12598 else if (cu->language == language_java)
12600 else if (cu->language == language_fortran && physname)
12602 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12603 DW_AT_MIPS_linkage_name is preferred and used instead. */
12611 if (prefix == NULL)
12613 if (suffix == NULL)
12619 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12621 strcpy (retval, lead);
12622 strcat (retval, prefix);
12623 strcat (retval, sep);
12624 strcat (retval, suffix);
12629 /* We have an obstack. */
12630 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12634 /* Return sibling of die, NULL if no sibling. */
12636 static struct die_info *
12637 sibling_die (struct die_info *die)
12639 return die->sibling;
12642 /* Get name of a die, return NULL if not found. */
12645 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12646 struct obstack *obstack)
12648 if (name && cu->language == language_cplus)
12650 char *canon_name = cp_canonicalize_string (name);
12652 if (canon_name != NULL)
12654 if (strcmp (canon_name, name) != 0)
12655 name = obsavestring (canon_name, strlen (canon_name),
12657 xfree (canon_name);
12664 /* Get name of a die, return NULL if not found. */
12667 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12669 struct attribute *attr;
12671 attr = dwarf2_attr (die, DW_AT_name, cu);
12672 if ((!attr || !DW_STRING (attr))
12673 && die->tag != DW_TAG_class_type
12674 && die->tag != DW_TAG_interface_type
12675 && die->tag != DW_TAG_structure_type
12676 && die->tag != DW_TAG_union_type)
12681 case DW_TAG_compile_unit:
12682 /* Compilation units have a DW_AT_name that is a filename, not
12683 a source language identifier. */
12684 case DW_TAG_enumeration_type:
12685 case DW_TAG_enumerator:
12686 /* These tags always have simple identifiers already; no need
12687 to canonicalize them. */
12688 return DW_STRING (attr);
12690 case DW_TAG_subprogram:
12691 /* Java constructors will all be named "<init>", so return
12692 the class name when we see this special case. */
12693 if (cu->language == language_java
12694 && DW_STRING (attr) != NULL
12695 && strcmp (DW_STRING (attr), "<init>") == 0)
12697 struct dwarf2_cu *spec_cu = cu;
12698 struct die_info *spec_die;
12700 /* GCJ will output '<init>' for Java constructor names.
12701 For this special case, return the name of the parent class. */
12703 /* GCJ may output suprogram DIEs with AT_specification set.
12704 If so, use the name of the specified DIE. */
12705 spec_die = die_specification (die, &spec_cu);
12706 if (spec_die != NULL)
12707 return dwarf2_name (spec_die, spec_cu);
12712 if (die->tag == DW_TAG_class_type)
12713 return dwarf2_name (die, cu);
12715 while (die->tag != DW_TAG_compile_unit);
12719 case DW_TAG_class_type:
12720 case DW_TAG_interface_type:
12721 case DW_TAG_structure_type:
12722 case DW_TAG_union_type:
12723 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12724 structures or unions. These were of the form "._%d" in GCC 4.1,
12725 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12726 and GCC 4.4. We work around this problem by ignoring these. */
12727 if (attr && DW_STRING (attr)
12728 && (strncmp (DW_STRING (attr), "._", 2) == 0
12729 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12732 /* GCC might emit a nameless typedef that has a linkage name. See
12733 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12734 if (!attr || DW_STRING (attr) == NULL)
12736 char *demangled = NULL;
12738 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12740 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12742 if (attr == NULL || DW_STRING (attr) == NULL)
12745 /* Avoid demangling DW_STRING (attr) the second time on a second
12746 call for the same DIE. */
12747 if (!DW_STRING_IS_CANONICAL (attr))
12748 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12754 /* FIXME: we already did this for the partial symbol... */
12755 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
12756 &cu->objfile->objfile_obstack);
12757 DW_STRING_IS_CANONICAL (attr) = 1;
12760 /* Strip any leading namespaces/classes, keep only the base name.
12761 DW_AT_name for named DIEs does not contain the prefixes. */
12762 base = strrchr (DW_STRING (attr), ':');
12763 if (base && base > DW_STRING (attr) && base[-1] == ':')
12766 return DW_STRING (attr);
12775 if (!DW_STRING_IS_CANONICAL (attr))
12778 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12779 &cu->objfile->objfile_obstack);
12780 DW_STRING_IS_CANONICAL (attr) = 1;
12782 return DW_STRING (attr);
12785 /* Return the die that this die in an extension of, or NULL if there
12786 is none. *EXT_CU is the CU containing DIE on input, and the CU
12787 containing the return value on output. */
12789 static struct die_info *
12790 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12792 struct attribute *attr;
12794 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12798 return follow_die_ref (die, attr, ext_cu);
12801 /* Convert a DIE tag into its string name. */
12804 dwarf_tag_name (unsigned tag)
12808 case DW_TAG_padding:
12809 return "DW_TAG_padding";
12810 case DW_TAG_array_type:
12811 return "DW_TAG_array_type";
12812 case DW_TAG_class_type:
12813 return "DW_TAG_class_type";
12814 case DW_TAG_entry_point:
12815 return "DW_TAG_entry_point";
12816 case DW_TAG_enumeration_type:
12817 return "DW_TAG_enumeration_type";
12818 case DW_TAG_formal_parameter:
12819 return "DW_TAG_formal_parameter";
12820 case DW_TAG_imported_declaration:
12821 return "DW_TAG_imported_declaration";
12823 return "DW_TAG_label";
12824 case DW_TAG_lexical_block:
12825 return "DW_TAG_lexical_block";
12826 case DW_TAG_member:
12827 return "DW_TAG_member";
12828 case DW_TAG_pointer_type:
12829 return "DW_TAG_pointer_type";
12830 case DW_TAG_reference_type:
12831 return "DW_TAG_reference_type";
12832 case DW_TAG_compile_unit:
12833 return "DW_TAG_compile_unit";
12834 case DW_TAG_string_type:
12835 return "DW_TAG_string_type";
12836 case DW_TAG_structure_type:
12837 return "DW_TAG_structure_type";
12838 case DW_TAG_subroutine_type:
12839 return "DW_TAG_subroutine_type";
12840 case DW_TAG_typedef:
12841 return "DW_TAG_typedef";
12842 case DW_TAG_union_type:
12843 return "DW_TAG_union_type";
12844 case DW_TAG_unspecified_parameters:
12845 return "DW_TAG_unspecified_parameters";
12846 case DW_TAG_variant:
12847 return "DW_TAG_variant";
12848 case DW_TAG_common_block:
12849 return "DW_TAG_common_block";
12850 case DW_TAG_common_inclusion:
12851 return "DW_TAG_common_inclusion";
12852 case DW_TAG_inheritance:
12853 return "DW_TAG_inheritance";
12854 case DW_TAG_inlined_subroutine:
12855 return "DW_TAG_inlined_subroutine";
12856 case DW_TAG_module:
12857 return "DW_TAG_module";
12858 case DW_TAG_ptr_to_member_type:
12859 return "DW_TAG_ptr_to_member_type";
12860 case DW_TAG_set_type:
12861 return "DW_TAG_set_type";
12862 case DW_TAG_subrange_type:
12863 return "DW_TAG_subrange_type";
12864 case DW_TAG_with_stmt:
12865 return "DW_TAG_with_stmt";
12866 case DW_TAG_access_declaration:
12867 return "DW_TAG_access_declaration";
12868 case DW_TAG_base_type:
12869 return "DW_TAG_base_type";
12870 case DW_TAG_catch_block:
12871 return "DW_TAG_catch_block";
12872 case DW_TAG_const_type:
12873 return "DW_TAG_const_type";
12874 case DW_TAG_constant:
12875 return "DW_TAG_constant";
12876 case DW_TAG_enumerator:
12877 return "DW_TAG_enumerator";
12878 case DW_TAG_file_type:
12879 return "DW_TAG_file_type";
12880 case DW_TAG_friend:
12881 return "DW_TAG_friend";
12882 case DW_TAG_namelist:
12883 return "DW_TAG_namelist";
12884 case DW_TAG_namelist_item:
12885 return "DW_TAG_namelist_item";
12886 case DW_TAG_packed_type:
12887 return "DW_TAG_packed_type";
12888 case DW_TAG_subprogram:
12889 return "DW_TAG_subprogram";
12890 case DW_TAG_template_type_param:
12891 return "DW_TAG_template_type_param";
12892 case DW_TAG_template_value_param:
12893 return "DW_TAG_template_value_param";
12894 case DW_TAG_thrown_type:
12895 return "DW_TAG_thrown_type";
12896 case DW_TAG_try_block:
12897 return "DW_TAG_try_block";
12898 case DW_TAG_variant_part:
12899 return "DW_TAG_variant_part";
12900 case DW_TAG_variable:
12901 return "DW_TAG_variable";
12902 case DW_TAG_volatile_type:
12903 return "DW_TAG_volatile_type";
12904 case DW_TAG_dwarf_procedure:
12905 return "DW_TAG_dwarf_procedure";
12906 case DW_TAG_restrict_type:
12907 return "DW_TAG_restrict_type";
12908 case DW_TAG_interface_type:
12909 return "DW_TAG_interface_type";
12910 case DW_TAG_namespace:
12911 return "DW_TAG_namespace";
12912 case DW_TAG_imported_module:
12913 return "DW_TAG_imported_module";
12914 case DW_TAG_unspecified_type:
12915 return "DW_TAG_unspecified_type";
12916 case DW_TAG_partial_unit:
12917 return "DW_TAG_partial_unit";
12918 case DW_TAG_imported_unit:
12919 return "DW_TAG_imported_unit";
12920 case DW_TAG_condition:
12921 return "DW_TAG_condition";
12922 case DW_TAG_shared_type:
12923 return "DW_TAG_shared_type";
12924 case DW_TAG_type_unit:
12925 return "DW_TAG_type_unit";
12926 case DW_TAG_MIPS_loop:
12927 return "DW_TAG_MIPS_loop";
12928 case DW_TAG_HP_array_descriptor:
12929 return "DW_TAG_HP_array_descriptor";
12930 case DW_TAG_format_label:
12931 return "DW_TAG_format_label";
12932 case DW_TAG_function_template:
12933 return "DW_TAG_function_template";
12934 case DW_TAG_class_template:
12935 return "DW_TAG_class_template";
12936 case DW_TAG_GNU_BINCL:
12937 return "DW_TAG_GNU_BINCL";
12938 case DW_TAG_GNU_EINCL:
12939 return "DW_TAG_GNU_EINCL";
12940 case DW_TAG_upc_shared_type:
12941 return "DW_TAG_upc_shared_type";
12942 case DW_TAG_upc_strict_type:
12943 return "DW_TAG_upc_strict_type";
12944 case DW_TAG_upc_relaxed_type:
12945 return "DW_TAG_upc_relaxed_type";
12946 case DW_TAG_PGI_kanji_type:
12947 return "DW_TAG_PGI_kanji_type";
12948 case DW_TAG_PGI_interface_block:
12949 return "DW_TAG_PGI_interface_block";
12950 case DW_TAG_GNU_call_site:
12951 return "DW_TAG_GNU_call_site";
12953 return "DW_TAG_<unknown>";
12957 /* Convert a DWARF attribute code into its string name. */
12960 dwarf_attr_name (unsigned attr)
12964 case DW_AT_sibling:
12965 return "DW_AT_sibling";
12966 case DW_AT_location:
12967 return "DW_AT_location";
12969 return "DW_AT_name";
12970 case DW_AT_ordering:
12971 return "DW_AT_ordering";
12972 case DW_AT_subscr_data:
12973 return "DW_AT_subscr_data";
12974 case DW_AT_byte_size:
12975 return "DW_AT_byte_size";
12976 case DW_AT_bit_offset:
12977 return "DW_AT_bit_offset";
12978 case DW_AT_bit_size:
12979 return "DW_AT_bit_size";
12980 case DW_AT_element_list:
12981 return "DW_AT_element_list";
12982 case DW_AT_stmt_list:
12983 return "DW_AT_stmt_list";
12985 return "DW_AT_low_pc";
12986 case DW_AT_high_pc:
12987 return "DW_AT_high_pc";
12988 case DW_AT_language:
12989 return "DW_AT_language";
12991 return "DW_AT_member";
12993 return "DW_AT_discr";
12994 case DW_AT_discr_value:
12995 return "DW_AT_discr_value";
12996 case DW_AT_visibility:
12997 return "DW_AT_visibility";
12999 return "DW_AT_import";
13000 case DW_AT_string_length:
13001 return "DW_AT_string_length";
13002 case DW_AT_common_reference:
13003 return "DW_AT_common_reference";
13004 case DW_AT_comp_dir:
13005 return "DW_AT_comp_dir";
13006 case DW_AT_const_value:
13007 return "DW_AT_const_value";
13008 case DW_AT_containing_type:
13009 return "DW_AT_containing_type";
13010 case DW_AT_default_value:
13011 return "DW_AT_default_value";
13013 return "DW_AT_inline";
13014 case DW_AT_is_optional:
13015 return "DW_AT_is_optional";
13016 case DW_AT_lower_bound:
13017 return "DW_AT_lower_bound";
13018 case DW_AT_producer:
13019 return "DW_AT_producer";
13020 case DW_AT_prototyped:
13021 return "DW_AT_prototyped";
13022 case DW_AT_return_addr:
13023 return "DW_AT_return_addr";
13024 case DW_AT_start_scope:
13025 return "DW_AT_start_scope";
13026 case DW_AT_bit_stride:
13027 return "DW_AT_bit_stride";
13028 case DW_AT_upper_bound:
13029 return "DW_AT_upper_bound";
13030 case DW_AT_abstract_origin:
13031 return "DW_AT_abstract_origin";
13032 case DW_AT_accessibility:
13033 return "DW_AT_accessibility";
13034 case DW_AT_address_class:
13035 return "DW_AT_address_class";
13036 case DW_AT_artificial:
13037 return "DW_AT_artificial";
13038 case DW_AT_base_types:
13039 return "DW_AT_base_types";
13040 case DW_AT_calling_convention:
13041 return "DW_AT_calling_convention";
13043 return "DW_AT_count";
13044 case DW_AT_data_member_location:
13045 return "DW_AT_data_member_location";
13046 case DW_AT_decl_column:
13047 return "DW_AT_decl_column";
13048 case DW_AT_decl_file:
13049 return "DW_AT_decl_file";
13050 case DW_AT_decl_line:
13051 return "DW_AT_decl_line";
13052 case DW_AT_declaration:
13053 return "DW_AT_declaration";
13054 case DW_AT_discr_list:
13055 return "DW_AT_discr_list";
13056 case DW_AT_encoding:
13057 return "DW_AT_encoding";
13058 case DW_AT_external:
13059 return "DW_AT_external";
13060 case DW_AT_frame_base:
13061 return "DW_AT_frame_base";
13063 return "DW_AT_friend";
13064 case DW_AT_identifier_case:
13065 return "DW_AT_identifier_case";
13066 case DW_AT_macro_info:
13067 return "DW_AT_macro_info";
13068 case DW_AT_namelist_items:
13069 return "DW_AT_namelist_items";
13070 case DW_AT_priority:
13071 return "DW_AT_priority";
13072 case DW_AT_segment:
13073 return "DW_AT_segment";
13074 case DW_AT_specification:
13075 return "DW_AT_specification";
13076 case DW_AT_static_link:
13077 return "DW_AT_static_link";
13079 return "DW_AT_type";
13080 case DW_AT_use_location:
13081 return "DW_AT_use_location";
13082 case DW_AT_variable_parameter:
13083 return "DW_AT_variable_parameter";
13084 case DW_AT_virtuality:
13085 return "DW_AT_virtuality";
13086 case DW_AT_vtable_elem_location:
13087 return "DW_AT_vtable_elem_location";
13088 /* DWARF 3 values. */
13089 case DW_AT_allocated:
13090 return "DW_AT_allocated";
13091 case DW_AT_associated:
13092 return "DW_AT_associated";
13093 case DW_AT_data_location:
13094 return "DW_AT_data_location";
13095 case DW_AT_byte_stride:
13096 return "DW_AT_byte_stride";
13097 case DW_AT_entry_pc:
13098 return "DW_AT_entry_pc";
13099 case DW_AT_use_UTF8:
13100 return "DW_AT_use_UTF8";
13101 case DW_AT_extension:
13102 return "DW_AT_extension";
13104 return "DW_AT_ranges";
13105 case DW_AT_trampoline:
13106 return "DW_AT_trampoline";
13107 case DW_AT_call_column:
13108 return "DW_AT_call_column";
13109 case DW_AT_call_file:
13110 return "DW_AT_call_file";
13111 case DW_AT_call_line:
13112 return "DW_AT_call_line";
13113 case DW_AT_description:
13114 return "DW_AT_description";
13115 case DW_AT_binary_scale:
13116 return "DW_AT_binary_scale";
13117 case DW_AT_decimal_scale:
13118 return "DW_AT_decimal_scale";
13120 return "DW_AT_small";
13121 case DW_AT_decimal_sign:
13122 return "DW_AT_decimal_sign";
13123 case DW_AT_digit_count:
13124 return "DW_AT_digit_count";
13125 case DW_AT_picture_string:
13126 return "DW_AT_picture_string";
13127 case DW_AT_mutable:
13128 return "DW_AT_mutable";
13129 case DW_AT_threads_scaled:
13130 return "DW_AT_threads_scaled";
13131 case DW_AT_explicit:
13132 return "DW_AT_explicit";
13133 case DW_AT_object_pointer:
13134 return "DW_AT_object_pointer";
13135 case DW_AT_endianity:
13136 return "DW_AT_endianity";
13137 case DW_AT_elemental:
13138 return "DW_AT_elemental";
13140 return "DW_AT_pure";
13141 case DW_AT_recursive:
13142 return "DW_AT_recursive";
13143 /* DWARF 4 values. */
13144 case DW_AT_signature:
13145 return "DW_AT_signature";
13146 case DW_AT_linkage_name:
13147 return "DW_AT_linkage_name";
13148 /* SGI/MIPS extensions. */
13149 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13150 case DW_AT_MIPS_fde:
13151 return "DW_AT_MIPS_fde";
13153 case DW_AT_MIPS_loop_begin:
13154 return "DW_AT_MIPS_loop_begin";
13155 case DW_AT_MIPS_tail_loop_begin:
13156 return "DW_AT_MIPS_tail_loop_begin";
13157 case DW_AT_MIPS_epilog_begin:
13158 return "DW_AT_MIPS_epilog_begin";
13159 case DW_AT_MIPS_loop_unroll_factor:
13160 return "DW_AT_MIPS_loop_unroll_factor";
13161 case DW_AT_MIPS_software_pipeline_depth:
13162 return "DW_AT_MIPS_software_pipeline_depth";
13163 case DW_AT_MIPS_linkage_name:
13164 return "DW_AT_MIPS_linkage_name";
13165 case DW_AT_MIPS_stride:
13166 return "DW_AT_MIPS_stride";
13167 case DW_AT_MIPS_abstract_name:
13168 return "DW_AT_MIPS_abstract_name";
13169 case DW_AT_MIPS_clone_origin:
13170 return "DW_AT_MIPS_clone_origin";
13171 case DW_AT_MIPS_has_inlines:
13172 return "DW_AT_MIPS_has_inlines";
13173 /* HP extensions. */
13174 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13175 case DW_AT_HP_block_index:
13176 return "DW_AT_HP_block_index";
13178 case DW_AT_HP_unmodifiable:
13179 return "DW_AT_HP_unmodifiable";
13180 case DW_AT_HP_actuals_stmt_list:
13181 return "DW_AT_HP_actuals_stmt_list";
13182 case DW_AT_HP_proc_per_section:
13183 return "DW_AT_HP_proc_per_section";
13184 case DW_AT_HP_raw_data_ptr:
13185 return "DW_AT_HP_raw_data_ptr";
13186 case DW_AT_HP_pass_by_reference:
13187 return "DW_AT_HP_pass_by_reference";
13188 case DW_AT_HP_opt_level:
13189 return "DW_AT_HP_opt_level";
13190 case DW_AT_HP_prof_version_id:
13191 return "DW_AT_HP_prof_version_id";
13192 case DW_AT_HP_opt_flags:
13193 return "DW_AT_HP_opt_flags";
13194 case DW_AT_HP_cold_region_low_pc:
13195 return "DW_AT_HP_cold_region_low_pc";
13196 case DW_AT_HP_cold_region_high_pc:
13197 return "DW_AT_HP_cold_region_high_pc";
13198 case DW_AT_HP_all_variables_modifiable:
13199 return "DW_AT_HP_all_variables_modifiable";
13200 case DW_AT_HP_linkage_name:
13201 return "DW_AT_HP_linkage_name";
13202 case DW_AT_HP_prof_flags:
13203 return "DW_AT_HP_prof_flags";
13204 /* GNU extensions. */
13205 case DW_AT_sf_names:
13206 return "DW_AT_sf_names";
13207 case DW_AT_src_info:
13208 return "DW_AT_src_info";
13209 case DW_AT_mac_info:
13210 return "DW_AT_mac_info";
13211 case DW_AT_src_coords:
13212 return "DW_AT_src_coords";
13213 case DW_AT_body_begin:
13214 return "DW_AT_body_begin";
13215 case DW_AT_body_end:
13216 return "DW_AT_body_end";
13217 case DW_AT_GNU_vector:
13218 return "DW_AT_GNU_vector";
13219 case DW_AT_GNU_odr_signature:
13220 return "DW_AT_GNU_odr_signature";
13221 /* VMS extensions. */
13222 case DW_AT_VMS_rtnbeg_pd_address:
13223 return "DW_AT_VMS_rtnbeg_pd_address";
13224 /* UPC extension. */
13225 case DW_AT_upc_threads_scaled:
13226 return "DW_AT_upc_threads_scaled";
13227 /* PGI (STMicroelectronics) extensions. */
13228 case DW_AT_PGI_lbase:
13229 return "DW_AT_PGI_lbase";
13230 case DW_AT_PGI_soffset:
13231 return "DW_AT_PGI_soffset";
13232 case DW_AT_PGI_lstride:
13233 return "DW_AT_PGI_lstride";
13235 return "DW_AT_<unknown>";
13239 /* Convert a DWARF value form code into its string name. */
13242 dwarf_form_name (unsigned form)
13247 return "DW_FORM_addr";
13248 case DW_FORM_block2:
13249 return "DW_FORM_block2";
13250 case DW_FORM_block4:
13251 return "DW_FORM_block4";
13252 case DW_FORM_data2:
13253 return "DW_FORM_data2";
13254 case DW_FORM_data4:
13255 return "DW_FORM_data4";
13256 case DW_FORM_data8:
13257 return "DW_FORM_data8";
13258 case DW_FORM_string:
13259 return "DW_FORM_string";
13260 case DW_FORM_block:
13261 return "DW_FORM_block";
13262 case DW_FORM_block1:
13263 return "DW_FORM_block1";
13264 case DW_FORM_data1:
13265 return "DW_FORM_data1";
13267 return "DW_FORM_flag";
13268 case DW_FORM_sdata:
13269 return "DW_FORM_sdata";
13271 return "DW_FORM_strp";
13272 case DW_FORM_udata:
13273 return "DW_FORM_udata";
13274 case DW_FORM_ref_addr:
13275 return "DW_FORM_ref_addr";
13277 return "DW_FORM_ref1";
13279 return "DW_FORM_ref2";
13281 return "DW_FORM_ref4";
13283 return "DW_FORM_ref8";
13284 case DW_FORM_ref_udata:
13285 return "DW_FORM_ref_udata";
13286 case DW_FORM_indirect:
13287 return "DW_FORM_indirect";
13288 case DW_FORM_sec_offset:
13289 return "DW_FORM_sec_offset";
13290 case DW_FORM_exprloc:
13291 return "DW_FORM_exprloc";
13292 case DW_FORM_flag_present:
13293 return "DW_FORM_flag_present";
13294 case DW_FORM_ref_sig8:
13295 return "DW_FORM_ref_sig8";
13297 return "DW_FORM_<unknown>";
13301 /* Convert a DWARF stack opcode into its string name. */
13304 dwarf_stack_op_name (unsigned op)
13309 return "DW_OP_addr";
13311 return "DW_OP_deref";
13312 case DW_OP_const1u:
13313 return "DW_OP_const1u";
13314 case DW_OP_const1s:
13315 return "DW_OP_const1s";
13316 case DW_OP_const2u:
13317 return "DW_OP_const2u";
13318 case DW_OP_const2s:
13319 return "DW_OP_const2s";
13320 case DW_OP_const4u:
13321 return "DW_OP_const4u";
13322 case DW_OP_const4s:
13323 return "DW_OP_const4s";
13324 case DW_OP_const8u:
13325 return "DW_OP_const8u";
13326 case DW_OP_const8s:
13327 return "DW_OP_const8s";
13329 return "DW_OP_constu";
13331 return "DW_OP_consts";
13333 return "DW_OP_dup";
13335 return "DW_OP_drop";
13337 return "DW_OP_over";
13339 return "DW_OP_pick";
13341 return "DW_OP_swap";
13343 return "DW_OP_rot";
13345 return "DW_OP_xderef";
13347 return "DW_OP_abs";
13349 return "DW_OP_and";
13351 return "DW_OP_div";
13353 return "DW_OP_minus";
13355 return "DW_OP_mod";
13357 return "DW_OP_mul";
13359 return "DW_OP_neg";
13361 return "DW_OP_not";
13365 return "DW_OP_plus";
13366 case DW_OP_plus_uconst:
13367 return "DW_OP_plus_uconst";
13369 return "DW_OP_shl";
13371 return "DW_OP_shr";
13373 return "DW_OP_shra";
13375 return "DW_OP_xor";
13377 return "DW_OP_bra";
13391 return "DW_OP_skip";
13393 return "DW_OP_lit0";
13395 return "DW_OP_lit1";
13397 return "DW_OP_lit2";
13399 return "DW_OP_lit3";
13401 return "DW_OP_lit4";
13403 return "DW_OP_lit5";
13405 return "DW_OP_lit6";
13407 return "DW_OP_lit7";
13409 return "DW_OP_lit8";
13411 return "DW_OP_lit9";
13413 return "DW_OP_lit10";
13415 return "DW_OP_lit11";
13417 return "DW_OP_lit12";
13419 return "DW_OP_lit13";
13421 return "DW_OP_lit14";
13423 return "DW_OP_lit15";
13425 return "DW_OP_lit16";
13427 return "DW_OP_lit17";
13429 return "DW_OP_lit18";
13431 return "DW_OP_lit19";
13433 return "DW_OP_lit20";
13435 return "DW_OP_lit21";
13437 return "DW_OP_lit22";
13439 return "DW_OP_lit23";
13441 return "DW_OP_lit24";
13443 return "DW_OP_lit25";
13445 return "DW_OP_lit26";
13447 return "DW_OP_lit27";
13449 return "DW_OP_lit28";
13451 return "DW_OP_lit29";
13453 return "DW_OP_lit30";
13455 return "DW_OP_lit31";
13457 return "DW_OP_reg0";
13459 return "DW_OP_reg1";
13461 return "DW_OP_reg2";
13463 return "DW_OP_reg3";
13465 return "DW_OP_reg4";
13467 return "DW_OP_reg5";
13469 return "DW_OP_reg6";
13471 return "DW_OP_reg7";
13473 return "DW_OP_reg8";
13475 return "DW_OP_reg9";
13477 return "DW_OP_reg10";
13479 return "DW_OP_reg11";
13481 return "DW_OP_reg12";
13483 return "DW_OP_reg13";
13485 return "DW_OP_reg14";
13487 return "DW_OP_reg15";
13489 return "DW_OP_reg16";
13491 return "DW_OP_reg17";
13493 return "DW_OP_reg18";
13495 return "DW_OP_reg19";
13497 return "DW_OP_reg20";
13499 return "DW_OP_reg21";
13501 return "DW_OP_reg22";
13503 return "DW_OP_reg23";
13505 return "DW_OP_reg24";
13507 return "DW_OP_reg25";
13509 return "DW_OP_reg26";
13511 return "DW_OP_reg27";
13513 return "DW_OP_reg28";
13515 return "DW_OP_reg29";
13517 return "DW_OP_reg30";
13519 return "DW_OP_reg31";
13521 return "DW_OP_breg0";
13523 return "DW_OP_breg1";
13525 return "DW_OP_breg2";
13527 return "DW_OP_breg3";
13529 return "DW_OP_breg4";
13531 return "DW_OP_breg5";
13533 return "DW_OP_breg6";
13535 return "DW_OP_breg7";
13537 return "DW_OP_breg8";
13539 return "DW_OP_breg9";
13541 return "DW_OP_breg10";
13543 return "DW_OP_breg11";
13545 return "DW_OP_breg12";
13547 return "DW_OP_breg13";
13549 return "DW_OP_breg14";
13551 return "DW_OP_breg15";
13553 return "DW_OP_breg16";
13555 return "DW_OP_breg17";
13557 return "DW_OP_breg18";
13559 return "DW_OP_breg19";
13561 return "DW_OP_breg20";
13563 return "DW_OP_breg21";
13565 return "DW_OP_breg22";
13567 return "DW_OP_breg23";
13569 return "DW_OP_breg24";
13571 return "DW_OP_breg25";
13573 return "DW_OP_breg26";
13575 return "DW_OP_breg27";
13577 return "DW_OP_breg28";
13579 return "DW_OP_breg29";
13581 return "DW_OP_breg30";
13583 return "DW_OP_breg31";
13585 return "DW_OP_regx";
13587 return "DW_OP_fbreg";
13589 return "DW_OP_bregx";
13591 return "DW_OP_piece";
13592 case DW_OP_deref_size:
13593 return "DW_OP_deref_size";
13594 case DW_OP_xderef_size:
13595 return "DW_OP_xderef_size";
13597 return "DW_OP_nop";
13598 /* DWARF 3 extensions. */
13599 case DW_OP_push_object_address:
13600 return "DW_OP_push_object_address";
13602 return "DW_OP_call2";
13604 return "DW_OP_call4";
13605 case DW_OP_call_ref:
13606 return "DW_OP_call_ref";
13607 case DW_OP_form_tls_address:
13608 return "DW_OP_form_tls_address";
13609 case DW_OP_call_frame_cfa:
13610 return "DW_OP_call_frame_cfa";
13611 case DW_OP_bit_piece:
13612 return "DW_OP_bit_piece";
13613 /* DWARF 4 extensions. */
13614 case DW_OP_implicit_value:
13615 return "DW_OP_implicit_value";
13616 case DW_OP_stack_value:
13617 return "DW_OP_stack_value";
13618 /* GNU extensions. */
13619 case DW_OP_GNU_push_tls_address:
13620 return "DW_OP_GNU_push_tls_address";
13621 case DW_OP_GNU_uninit:
13622 return "DW_OP_GNU_uninit";
13623 case DW_OP_GNU_implicit_pointer:
13624 return "DW_OP_GNU_implicit_pointer";
13625 case DW_OP_GNU_entry_value:
13626 return "DW_OP_GNU_entry_value";
13627 case DW_OP_GNU_const_type:
13628 return "DW_OP_GNU_const_type";
13629 case DW_OP_GNU_regval_type:
13630 return "DW_OP_GNU_regval_type";
13631 case DW_OP_GNU_deref_type:
13632 return "DW_OP_GNU_deref_type";
13633 case DW_OP_GNU_convert:
13634 return "DW_OP_GNU_convert";
13635 case DW_OP_GNU_reinterpret:
13636 return "DW_OP_GNU_reinterpret";
13643 dwarf_bool_name (unsigned mybool)
13651 /* Convert a DWARF type code into its string name. */
13654 dwarf_type_encoding_name (unsigned enc)
13659 return "DW_ATE_void";
13660 case DW_ATE_address:
13661 return "DW_ATE_address";
13662 case DW_ATE_boolean:
13663 return "DW_ATE_boolean";
13664 case DW_ATE_complex_float:
13665 return "DW_ATE_complex_float";
13667 return "DW_ATE_float";
13668 case DW_ATE_signed:
13669 return "DW_ATE_signed";
13670 case DW_ATE_signed_char:
13671 return "DW_ATE_signed_char";
13672 case DW_ATE_unsigned:
13673 return "DW_ATE_unsigned";
13674 case DW_ATE_unsigned_char:
13675 return "DW_ATE_unsigned_char";
13677 case DW_ATE_imaginary_float:
13678 return "DW_ATE_imaginary_float";
13679 case DW_ATE_packed_decimal:
13680 return "DW_ATE_packed_decimal";
13681 case DW_ATE_numeric_string:
13682 return "DW_ATE_numeric_string";
13683 case DW_ATE_edited:
13684 return "DW_ATE_edited";
13685 case DW_ATE_signed_fixed:
13686 return "DW_ATE_signed_fixed";
13687 case DW_ATE_unsigned_fixed:
13688 return "DW_ATE_unsigned_fixed";
13689 case DW_ATE_decimal_float:
13690 return "DW_ATE_decimal_float";
13693 return "DW_ATE_UTF";
13694 /* HP extensions. */
13695 case DW_ATE_HP_float80:
13696 return "DW_ATE_HP_float80";
13697 case DW_ATE_HP_complex_float80:
13698 return "DW_ATE_HP_complex_float80";
13699 case DW_ATE_HP_float128:
13700 return "DW_ATE_HP_float128";
13701 case DW_ATE_HP_complex_float128:
13702 return "DW_ATE_HP_complex_float128";
13703 case DW_ATE_HP_floathpintel:
13704 return "DW_ATE_HP_floathpintel";
13705 case DW_ATE_HP_imaginary_float80:
13706 return "DW_ATE_HP_imaginary_float80";
13707 case DW_ATE_HP_imaginary_float128:
13708 return "DW_ATE_HP_imaginary_float128";
13710 return "DW_ATE_<unknown>";
13714 /* Convert a DWARF call frame info operation to its string name. */
13718 dwarf_cfi_name (unsigned cfi_opc)
13722 case DW_CFA_advance_loc:
13723 return "DW_CFA_advance_loc";
13724 case DW_CFA_offset:
13725 return "DW_CFA_offset";
13726 case DW_CFA_restore:
13727 return "DW_CFA_restore";
13729 return "DW_CFA_nop";
13730 case DW_CFA_set_loc:
13731 return "DW_CFA_set_loc";
13732 case DW_CFA_advance_loc1:
13733 return "DW_CFA_advance_loc1";
13734 case DW_CFA_advance_loc2:
13735 return "DW_CFA_advance_loc2";
13736 case DW_CFA_advance_loc4:
13737 return "DW_CFA_advance_loc4";
13738 case DW_CFA_offset_extended:
13739 return "DW_CFA_offset_extended";
13740 case DW_CFA_restore_extended:
13741 return "DW_CFA_restore_extended";
13742 case DW_CFA_undefined:
13743 return "DW_CFA_undefined";
13744 case DW_CFA_same_value:
13745 return "DW_CFA_same_value";
13746 case DW_CFA_register:
13747 return "DW_CFA_register";
13748 case DW_CFA_remember_state:
13749 return "DW_CFA_remember_state";
13750 case DW_CFA_restore_state:
13751 return "DW_CFA_restore_state";
13752 case DW_CFA_def_cfa:
13753 return "DW_CFA_def_cfa";
13754 case DW_CFA_def_cfa_register:
13755 return "DW_CFA_def_cfa_register";
13756 case DW_CFA_def_cfa_offset:
13757 return "DW_CFA_def_cfa_offset";
13759 case DW_CFA_def_cfa_expression:
13760 return "DW_CFA_def_cfa_expression";
13761 case DW_CFA_expression:
13762 return "DW_CFA_expression";
13763 case DW_CFA_offset_extended_sf:
13764 return "DW_CFA_offset_extended_sf";
13765 case DW_CFA_def_cfa_sf:
13766 return "DW_CFA_def_cfa_sf";
13767 case DW_CFA_def_cfa_offset_sf:
13768 return "DW_CFA_def_cfa_offset_sf";
13769 case DW_CFA_val_offset:
13770 return "DW_CFA_val_offset";
13771 case DW_CFA_val_offset_sf:
13772 return "DW_CFA_val_offset_sf";
13773 case DW_CFA_val_expression:
13774 return "DW_CFA_val_expression";
13775 /* SGI/MIPS specific. */
13776 case DW_CFA_MIPS_advance_loc8:
13777 return "DW_CFA_MIPS_advance_loc8";
13778 /* GNU extensions. */
13779 case DW_CFA_GNU_window_save:
13780 return "DW_CFA_GNU_window_save";
13781 case DW_CFA_GNU_args_size:
13782 return "DW_CFA_GNU_args_size";
13783 case DW_CFA_GNU_negative_offset_extended:
13784 return "DW_CFA_GNU_negative_offset_extended";
13786 return "DW_CFA_<unknown>";
13792 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13796 print_spaces (indent, f);
13797 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13798 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13800 if (die->parent != NULL)
13802 print_spaces (indent, f);
13803 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13804 die->parent->offset);
13807 print_spaces (indent, f);
13808 fprintf_unfiltered (f, " has children: %s\n",
13809 dwarf_bool_name (die->child != NULL));
13811 print_spaces (indent, f);
13812 fprintf_unfiltered (f, " attributes:\n");
13814 for (i = 0; i < die->num_attrs; ++i)
13816 print_spaces (indent, f);
13817 fprintf_unfiltered (f, " %s (%s) ",
13818 dwarf_attr_name (die->attrs[i].name),
13819 dwarf_form_name (die->attrs[i].form));
13821 switch (die->attrs[i].form)
13823 case DW_FORM_ref_addr:
13825 fprintf_unfiltered (f, "address: ");
13826 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13828 case DW_FORM_block2:
13829 case DW_FORM_block4:
13830 case DW_FORM_block:
13831 case DW_FORM_block1:
13832 fprintf_unfiltered (f, "block: size %d",
13833 DW_BLOCK (&die->attrs[i])->size);
13835 case DW_FORM_exprloc:
13836 fprintf_unfiltered (f, "expression: size %u",
13837 DW_BLOCK (&die->attrs[i])->size);
13842 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13843 (long) (DW_ADDR (&die->attrs[i])));
13845 case DW_FORM_data1:
13846 case DW_FORM_data2:
13847 case DW_FORM_data4:
13848 case DW_FORM_data8:
13849 case DW_FORM_udata:
13850 case DW_FORM_sdata:
13851 fprintf_unfiltered (f, "constant: %s",
13852 pulongest (DW_UNSND (&die->attrs[i])));
13854 case DW_FORM_sec_offset:
13855 fprintf_unfiltered (f, "section offset: %s",
13856 pulongest (DW_UNSND (&die->attrs[i])));
13858 case DW_FORM_ref_sig8:
13859 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13860 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13861 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13863 fprintf_unfiltered (f, "signatured type, offset: unknown");
13865 case DW_FORM_string:
13867 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13868 DW_STRING (&die->attrs[i])
13869 ? DW_STRING (&die->attrs[i]) : "",
13870 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13873 if (DW_UNSND (&die->attrs[i]))
13874 fprintf_unfiltered (f, "flag: TRUE");
13876 fprintf_unfiltered (f, "flag: FALSE");
13878 case DW_FORM_flag_present:
13879 fprintf_unfiltered (f, "flag: TRUE");
13881 case DW_FORM_indirect:
13882 /* The reader will have reduced the indirect form to
13883 the "base form" so this form should not occur. */
13884 fprintf_unfiltered (f,
13885 "unexpected attribute form: DW_FORM_indirect");
13888 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13889 die->attrs[i].form);
13892 fprintf_unfiltered (f, "\n");
13897 dump_die_for_error (struct die_info *die)
13899 dump_die_shallow (gdb_stderr, 0, die);
13903 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13905 int indent = level * 4;
13907 gdb_assert (die != NULL);
13909 if (level >= max_level)
13912 dump_die_shallow (f, indent, die);
13914 if (die->child != NULL)
13916 print_spaces (indent, f);
13917 fprintf_unfiltered (f, " Children:");
13918 if (level + 1 < max_level)
13920 fprintf_unfiltered (f, "\n");
13921 dump_die_1 (f, level + 1, max_level, die->child);
13925 fprintf_unfiltered (f,
13926 " [not printed, max nesting level reached]\n");
13930 if (die->sibling != NULL && level > 0)
13932 dump_die_1 (f, level, max_level, die->sibling);
13936 /* This is called from the pdie macro in gdbinit.in.
13937 It's not static so gcc will keep a copy callable from gdb. */
13940 dump_die (struct die_info *die, int max_level)
13942 dump_die_1 (gdb_stdlog, 0, max_level, die);
13946 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13950 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13956 is_ref_attr (struct attribute *attr)
13958 switch (attr->form)
13960 case DW_FORM_ref_addr:
13965 case DW_FORM_ref_udata:
13972 static unsigned int
13973 dwarf2_get_ref_die_offset (struct attribute *attr)
13975 if (is_ref_attr (attr))
13976 return DW_ADDR (attr);
13978 complaint (&symfile_complaints,
13979 _("unsupported die ref attribute form: '%s'"),
13980 dwarf_form_name (attr->form));
13984 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13985 * the value held by the attribute is not constant. */
13988 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13990 if (attr->form == DW_FORM_sdata)
13991 return DW_SND (attr);
13992 else if (attr->form == DW_FORM_udata
13993 || attr->form == DW_FORM_data1
13994 || attr->form == DW_FORM_data2
13995 || attr->form == DW_FORM_data4
13996 || attr->form == DW_FORM_data8)
13997 return DW_UNSND (attr);
14000 complaint (&symfile_complaints,
14001 _("Attribute value is not a constant (%s)"),
14002 dwarf_form_name (attr->form));
14003 return default_value;
14007 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14008 unit and add it to our queue.
14009 The result is non-zero if PER_CU was queued, otherwise the result is zero
14010 meaning either PER_CU is already queued or it is already loaded. */
14013 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
14014 struct dwarf2_per_cu_data *per_cu)
14016 /* We may arrive here during partial symbol reading, if we need full
14017 DIEs to process an unusual case (e.g. template arguments). Do
14018 not queue PER_CU, just tell our caller to load its DIEs. */
14019 if (dwarf2_per_objfile->reading_partial_symbols)
14021 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
14026 /* Mark the dependence relation so that we don't flush PER_CU
14028 dwarf2_add_dependence (this_cu, per_cu);
14030 /* If it's already on the queue, we have nothing to do. */
14031 if (per_cu->queued)
14034 /* If the compilation unit is already loaded, just mark it as
14036 if (per_cu->cu != NULL)
14038 per_cu->cu->last_used = 0;
14042 /* Add it to the queue. */
14043 queue_comp_unit (per_cu);
14048 /* Follow reference or signature attribute ATTR of SRC_DIE.
14049 On entry *REF_CU is the CU of SRC_DIE.
14050 On exit *REF_CU is the CU of the result. */
14052 static struct die_info *
14053 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
14054 struct dwarf2_cu **ref_cu)
14056 struct die_info *die;
14058 if (is_ref_attr (attr))
14059 die = follow_die_ref (src_die, attr, ref_cu);
14060 else if (attr->form == DW_FORM_ref_sig8)
14061 die = follow_die_sig (src_die, attr, ref_cu);
14064 dump_die_for_error (src_die);
14065 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14066 (*ref_cu)->objfile->name);
14072 /* Follow reference OFFSET.
14073 On entry *REF_CU is the CU of the source die referencing OFFSET.
14074 On exit *REF_CU is the CU of the result.
14075 Returns NULL if OFFSET is invalid. */
14077 static struct die_info *
14078 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
14080 struct die_info temp_die;
14081 struct dwarf2_cu *target_cu, *cu = *ref_cu;
14083 gdb_assert (cu->per_cu != NULL);
14087 if (cu->per_cu->debug_types_section)
14089 /* .debug_types CUs cannot reference anything outside their CU.
14090 If they need to, they have to reference a signatured type via
14091 DW_FORM_ref_sig8. */
14092 if (! offset_in_cu_p (&cu->header, offset))
14095 else if (! offset_in_cu_p (&cu->header, offset))
14097 struct dwarf2_per_cu_data *per_cu;
14099 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
14101 /* If necessary, add it to the queue and load its DIEs. */
14102 if (maybe_queue_comp_unit (cu, per_cu))
14103 load_full_comp_unit (per_cu);
14105 target_cu = per_cu->cu;
14107 else if (cu->dies == NULL)
14109 /* We're loading full DIEs during partial symbol reading. */
14110 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
14111 load_full_comp_unit (cu->per_cu);
14114 *ref_cu = target_cu;
14115 temp_die.offset = offset;
14116 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
14119 /* Follow reference attribute ATTR of SRC_DIE.
14120 On entry *REF_CU is the CU of SRC_DIE.
14121 On exit *REF_CU is the CU of the result. */
14123 static struct die_info *
14124 follow_die_ref (struct die_info *src_die, struct attribute *attr,
14125 struct dwarf2_cu **ref_cu)
14127 unsigned int offset = dwarf2_get_ref_die_offset (attr);
14128 struct dwarf2_cu *cu = *ref_cu;
14129 struct die_info *die;
14131 die = follow_die_offset (offset, ref_cu);
14133 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14134 "at 0x%x [in module %s]"),
14135 offset, src_die->offset, cu->objfile->name);
14140 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14141 Returned value is intended for DW_OP_call*. Returned
14142 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14144 struct dwarf2_locexpr_baton
14145 dwarf2_fetch_die_location_block (unsigned int offset,
14146 struct dwarf2_per_cu_data *per_cu,
14147 CORE_ADDR (*get_frame_pc) (void *baton),
14150 struct dwarf2_cu *cu;
14151 struct die_info *die;
14152 struct attribute *attr;
14153 struct dwarf2_locexpr_baton retval;
14155 dw2_setup (per_cu->objfile);
14157 if (per_cu->cu == NULL)
14161 die = follow_die_offset (offset, &cu);
14163 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14164 offset, per_cu->objfile->name);
14166 attr = dwarf2_attr (die, DW_AT_location, cu);
14169 /* DWARF: "If there is no such attribute, then there is no effect.".
14170 DATA is ignored if SIZE is 0. */
14172 retval.data = NULL;
14175 else if (attr_form_is_section_offset (attr))
14177 struct dwarf2_loclist_baton loclist_baton;
14178 CORE_ADDR pc = (*get_frame_pc) (baton);
14181 fill_in_loclist_baton (cu, &loclist_baton, attr);
14183 retval.data = dwarf2_find_location_expression (&loclist_baton,
14185 retval.size = size;
14189 if (!attr_form_is_block (attr))
14190 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14191 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14192 offset, per_cu->objfile->name);
14194 retval.data = DW_BLOCK (attr)->data;
14195 retval.size = DW_BLOCK (attr)->size;
14197 retval.per_cu = cu->per_cu;
14199 age_cached_comp_units ();
14204 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14208 dwarf2_get_die_type (unsigned int die_offset,
14209 struct dwarf2_per_cu_data *per_cu)
14211 dw2_setup (per_cu->objfile);
14212 return get_die_type_at_offset (die_offset, per_cu);
14215 /* Follow the signature attribute ATTR in SRC_DIE.
14216 On entry *REF_CU is the CU of SRC_DIE.
14217 On exit *REF_CU is the CU of the result. */
14219 static struct die_info *
14220 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14221 struct dwarf2_cu **ref_cu)
14223 struct objfile *objfile = (*ref_cu)->objfile;
14224 struct die_info temp_die;
14225 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14226 struct dwarf2_cu *sig_cu;
14227 struct die_info *die;
14229 /* sig_type will be NULL if the signatured type is missing from
14231 if (sig_type == NULL)
14232 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14233 "at 0x%x [in module %s]"),
14234 src_die->offset, objfile->name);
14236 /* If necessary, add it to the queue and load its DIEs. */
14238 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14239 read_signatured_type (sig_type);
14241 gdb_assert (sig_type->per_cu.cu != NULL);
14243 sig_cu = sig_type->per_cu.cu;
14244 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
14245 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
14252 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14253 "from DIE at 0x%x [in module %s]"),
14254 sig_type->type_offset, src_die->offset, objfile->name);
14257 /* Given an offset of a signatured type, return its signatured_type. */
14259 static struct signatured_type *
14260 lookup_signatured_type_at_offset (struct objfile *objfile,
14261 struct dwarf2_section_info *section,
14262 unsigned int offset)
14264 gdb_byte *info_ptr = section->buffer + offset;
14265 unsigned int length, initial_length_size;
14266 unsigned int sig_offset;
14267 struct signatured_type find_entry, *type_sig;
14269 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14270 sig_offset = (initial_length_size
14272 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14273 + 1 /*address_size*/);
14274 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14275 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14277 /* This is only used to lookup previously recorded types.
14278 If we didn't find it, it's our bug. */
14279 gdb_assert (type_sig != NULL);
14280 gdb_assert (offset == type_sig->per_cu.offset);
14285 /* Load the DIEs associated with type unit PER_CU into memory. */
14288 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
14290 struct objfile *objfile = per_cu->objfile;
14291 struct dwarf2_section_info *sect = per_cu->debug_types_section;
14292 unsigned int offset = per_cu->offset;
14293 struct signatured_type *type_sig;
14295 dwarf2_read_section (objfile, sect);
14297 /* We have the section offset, but we need the signature to do the
14298 hash table lookup. */
14299 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14300 the signature to assert we found the right one.
14301 Ok, but it's a lot of work. We should simplify things so any needed
14302 assert doesn't require all this clumsiness. */
14303 type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
14305 gdb_assert (type_sig->per_cu.cu == NULL);
14307 read_signatured_type (type_sig);
14309 gdb_assert (type_sig->per_cu.cu != NULL);
14312 /* Read in a signatured type and build its CU and DIEs. */
14315 read_signatured_type (struct signatured_type *type_sig)
14317 struct objfile *objfile = type_sig->per_cu.objfile;
14318 gdb_byte *types_ptr;
14319 struct die_reader_specs reader_specs;
14320 struct dwarf2_cu *cu;
14321 ULONGEST signature;
14322 struct cleanup *back_to, *free_cu_cleanup;
14323 struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section;
14325 dwarf2_read_section (objfile, section);
14326 types_ptr = section->buffer + type_sig->per_cu.offset;
14328 gdb_assert (type_sig->per_cu.cu == NULL);
14330 cu = xmalloc (sizeof (*cu));
14331 init_one_comp_unit (cu, &type_sig->per_cu);
14333 /* If an error occurs while loading, release our storage. */
14334 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
14336 types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr,
14338 gdb_assert (signature == type_sig->signature);
14341 = htab_create_alloc_ex (cu->header.length / 12,
14345 &cu->comp_unit_obstack,
14346 hashtab_obstack_allocate,
14347 dummy_obstack_deallocate);
14349 dwarf2_read_abbrevs (cu);
14350 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14352 init_cu_die_reader (&reader_specs, cu);
14354 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14357 /* We try not to read any attributes in this function, because not
14358 all CUs needed for references have been loaded yet, and symbol
14359 table processing isn't initialized. But we have to set the CU language,
14360 or we won't be able to build types correctly. */
14361 prepare_one_comp_unit (cu, cu->dies);
14363 do_cleanups (back_to);
14365 /* We've successfully allocated this compilation unit. Let our caller
14366 clean it up when finished with it. */
14367 discard_cleanups (free_cu_cleanup);
14369 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14370 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
14373 /* Decode simple location descriptions.
14374 Given a pointer to a dwarf block that defines a location, compute
14375 the location and return the value.
14377 NOTE drow/2003-11-18: This function is called in two situations
14378 now: for the address of static or global variables (partial symbols
14379 only) and for offsets into structures which are expected to be
14380 (more or less) constant. The partial symbol case should go away,
14381 and only the constant case should remain. That will let this
14382 function complain more accurately. A few special modes are allowed
14383 without complaint for global variables (for instance, global
14384 register values and thread-local values).
14386 A location description containing no operations indicates that the
14387 object is optimized out. The return value is 0 for that case.
14388 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14389 callers will only want a very basic result and this can become a
14392 Note that stack[0] is unused except as a default error return. */
14395 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14397 struct objfile *objfile = cu->objfile;
14399 int size = blk->size;
14400 gdb_byte *data = blk->data;
14401 CORE_ADDR stack[64];
14403 unsigned int bytes_read, unsnd;
14409 stack[++stacki] = 0;
14448 stack[++stacki] = op - DW_OP_lit0;
14483 stack[++stacki] = op - DW_OP_reg0;
14485 dwarf2_complex_location_expr_complaint ();
14489 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
14491 stack[++stacki] = unsnd;
14493 dwarf2_complex_location_expr_complaint ();
14497 stack[++stacki] = read_address (objfile->obfd, &data[i],
14502 case DW_OP_const1u:
14503 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
14507 case DW_OP_const1s:
14508 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
14512 case DW_OP_const2u:
14513 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14517 case DW_OP_const2s:
14518 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14522 case DW_OP_const4u:
14523 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14527 case DW_OP_const4s:
14528 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14532 case DW_OP_const8u:
14533 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
14538 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14544 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14549 stack[stacki + 1] = stack[stacki];
14554 stack[stacki - 1] += stack[stacki];
14558 case DW_OP_plus_uconst:
14559 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14565 stack[stacki - 1] -= stack[stacki];
14570 /* If we're not the last op, then we definitely can't encode
14571 this using GDB's address_class enum. This is valid for partial
14572 global symbols, although the variable's address will be bogus
14575 dwarf2_complex_location_expr_complaint ();
14578 case DW_OP_GNU_push_tls_address:
14579 /* The top of the stack has the offset from the beginning
14580 of the thread control block at which the variable is located. */
14581 /* Nothing should follow this operator, so the top of stack would
14583 /* This is valid for partial global symbols, but the variable's
14584 address will be bogus in the psymtab. Make it always at least
14585 non-zero to not look as a variable garbage collected by linker
14586 which have DW_OP_addr 0. */
14588 dwarf2_complex_location_expr_complaint ();
14592 case DW_OP_GNU_uninit:
14597 const char *name = dwarf_stack_op_name (op);
14600 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14603 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14607 return (stack[stacki]);
14610 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14611 outside of the allocated space. Also enforce minimum>0. */
14612 if (stacki >= ARRAY_SIZE (stack) - 1)
14614 complaint (&symfile_complaints,
14615 _("location description stack overflow"));
14621 complaint (&symfile_complaints,
14622 _("location description stack underflow"));
14626 return (stack[stacki]);
14629 /* memory allocation interface */
14631 static struct dwarf_block *
14632 dwarf_alloc_block (struct dwarf2_cu *cu)
14634 struct dwarf_block *blk;
14636 blk = (struct dwarf_block *)
14637 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14641 static struct abbrev_info *
14642 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14644 struct abbrev_info *abbrev;
14646 abbrev = (struct abbrev_info *)
14647 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14648 memset (abbrev, 0, sizeof (struct abbrev_info));
14652 static struct die_info *
14653 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14655 struct die_info *die;
14656 size_t size = sizeof (struct die_info);
14659 size += (num_attrs - 1) * sizeof (struct attribute);
14661 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14662 memset (die, 0, sizeof (struct die_info));
14667 /* Macro support. */
14669 /* Return the full name of file number I in *LH's file name table.
14670 Use COMP_DIR as the name of the current directory of the
14671 compilation. The result is allocated using xmalloc; the caller is
14672 responsible for freeing it. */
14674 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14676 /* Is the file number a valid index into the line header's file name
14677 table? Remember that file numbers start with one, not zero. */
14678 if (1 <= file && file <= lh->num_file_names)
14680 struct file_entry *fe = &lh->file_names[file - 1];
14682 if (IS_ABSOLUTE_PATH (fe->name))
14683 return xstrdup (fe->name);
14691 dir = lh->include_dirs[fe->dir_index - 1];
14697 dir_len = strlen (dir);
14698 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14699 strcpy (full_name, dir);
14700 full_name[dir_len] = '/';
14701 strcpy (full_name + dir_len + 1, fe->name);
14705 return xstrdup (fe->name);
14710 /* The compiler produced a bogus file number. We can at least
14711 record the macro definitions made in the file, even if we
14712 won't be able to find the file by name. */
14713 char fake_name[80];
14715 sprintf (fake_name, "<bad macro file number %d>", file);
14717 complaint (&symfile_complaints,
14718 _("bad file number in macro information (%d)"),
14721 return xstrdup (fake_name);
14726 static struct macro_source_file *
14727 macro_start_file (int file, int line,
14728 struct macro_source_file *current_file,
14729 const char *comp_dir,
14730 struct line_header *lh, struct objfile *objfile)
14732 /* The full name of this source file. */
14733 char *full_name = file_full_name (file, lh, comp_dir);
14735 /* We don't create a macro table for this compilation unit
14736 at all until we actually get a filename. */
14737 if (! pending_macros)
14738 pending_macros = new_macro_table (&objfile->objfile_obstack,
14739 objfile->macro_cache);
14741 if (! current_file)
14742 /* If we have no current file, then this must be the start_file
14743 directive for the compilation unit's main source file. */
14744 current_file = macro_set_main (pending_macros, full_name);
14746 current_file = macro_include (current_file, line, full_name);
14750 return current_file;
14754 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14755 followed by a null byte. */
14757 copy_string (const char *buf, int len)
14759 char *s = xmalloc (len + 1);
14761 memcpy (s, buf, len);
14767 static const char *
14768 consume_improper_spaces (const char *p, const char *body)
14772 complaint (&symfile_complaints,
14773 _("macro definition contains spaces "
14774 "in formal argument list:\n`%s'"),
14786 parse_macro_definition (struct macro_source_file *file, int line,
14791 /* The body string takes one of two forms. For object-like macro
14792 definitions, it should be:
14794 <macro name> " " <definition>
14796 For function-like macro definitions, it should be:
14798 <macro name> "() " <definition>
14800 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14802 Spaces may appear only where explicitly indicated, and in the
14805 The Dwarf 2 spec says that an object-like macro's name is always
14806 followed by a space, but versions of GCC around March 2002 omit
14807 the space when the macro's definition is the empty string.
14809 The Dwarf 2 spec says that there should be no spaces between the
14810 formal arguments in a function-like macro's formal argument list,
14811 but versions of GCC around March 2002 include spaces after the
14815 /* Find the extent of the macro name. The macro name is terminated
14816 by either a space or null character (for an object-like macro) or
14817 an opening paren (for a function-like macro). */
14818 for (p = body; *p; p++)
14819 if (*p == ' ' || *p == '(')
14822 if (*p == ' ' || *p == '\0')
14824 /* It's an object-like macro. */
14825 int name_len = p - body;
14826 char *name = copy_string (body, name_len);
14827 const char *replacement;
14830 replacement = body + name_len + 1;
14833 dwarf2_macro_malformed_definition_complaint (body);
14834 replacement = body + name_len;
14837 macro_define_object (file, line, name, replacement);
14841 else if (*p == '(')
14843 /* It's a function-like macro. */
14844 char *name = copy_string (body, p - body);
14847 char **argv = xmalloc (argv_size * sizeof (*argv));
14851 p = consume_improper_spaces (p, body);
14853 /* Parse the formal argument list. */
14854 while (*p && *p != ')')
14856 /* Find the extent of the current argument name. */
14857 const char *arg_start = p;
14859 while (*p && *p != ',' && *p != ')' && *p != ' ')
14862 if (! *p || p == arg_start)
14863 dwarf2_macro_malformed_definition_complaint (body);
14866 /* Make sure argv has room for the new argument. */
14867 if (argc >= argv_size)
14870 argv = xrealloc (argv, argv_size * sizeof (*argv));
14873 argv[argc++] = copy_string (arg_start, p - arg_start);
14876 p = consume_improper_spaces (p, body);
14878 /* Consume the comma, if present. */
14883 p = consume_improper_spaces (p, body);
14892 /* Perfectly formed definition, no complaints. */
14893 macro_define_function (file, line, name,
14894 argc, (const char **) argv,
14896 else if (*p == '\0')
14898 /* Complain, but do define it. */
14899 dwarf2_macro_malformed_definition_complaint (body);
14900 macro_define_function (file, line, name,
14901 argc, (const char **) argv,
14905 /* Just complain. */
14906 dwarf2_macro_malformed_definition_complaint (body);
14909 /* Just complain. */
14910 dwarf2_macro_malformed_definition_complaint (body);
14916 for (i = 0; i < argc; i++)
14922 dwarf2_macro_malformed_definition_complaint (body);
14925 /* Skip some bytes from BYTES according to the form given in FORM.
14926 Returns the new pointer. */
14929 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
14930 enum dwarf_form form,
14931 unsigned int offset_size,
14932 struct dwarf2_section_info *section)
14934 unsigned int bytes_read;
14938 case DW_FORM_data1:
14943 case DW_FORM_data2:
14947 case DW_FORM_data4:
14951 case DW_FORM_data8:
14955 case DW_FORM_string:
14956 read_direct_string (abfd, bytes, &bytes_read);
14957 bytes += bytes_read;
14960 case DW_FORM_sec_offset:
14962 bytes += offset_size;
14965 case DW_FORM_block:
14966 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
14967 bytes += bytes_read;
14970 case DW_FORM_block1:
14971 bytes += 1 + read_1_byte (abfd, bytes);
14973 case DW_FORM_block2:
14974 bytes += 2 + read_2_bytes (abfd, bytes);
14976 case DW_FORM_block4:
14977 bytes += 4 + read_4_bytes (abfd, bytes);
14980 case DW_FORM_sdata:
14981 case DW_FORM_udata:
14982 bytes = skip_leb128 (abfd, bytes);
14988 complaint (&symfile_complaints,
14989 _("invalid form 0x%x in `%s'"),
14991 section->asection->name);
14999 /* A helper for dwarf_decode_macros that handles skipping an unknown
15000 opcode. Returns an updated pointer to the macro data buffer; or,
15001 on error, issues a complaint and returns NULL. */
15004 skip_unknown_opcode (unsigned int opcode,
15005 gdb_byte **opcode_definitions,
15008 unsigned int offset_size,
15009 struct dwarf2_section_info *section)
15011 unsigned int bytes_read, i;
15015 if (opcode_definitions[opcode] == NULL)
15017 complaint (&symfile_complaints,
15018 _("unrecognized DW_MACFINO opcode 0x%x"),
15023 defn = opcode_definitions[opcode];
15024 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
15025 defn += bytes_read;
15027 for (i = 0; i < arg; ++i)
15029 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
15030 if (mac_ptr == NULL)
15032 /* skip_form_bytes already issued the complaint. */
15040 /* A helper function which parses the header of a macro section.
15041 If the macro section is the extended (for now called "GNU") type,
15042 then this updates *OFFSET_SIZE. Returns a pointer to just after
15043 the header, or issues a complaint and returns NULL on error. */
15046 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
15049 unsigned int *offset_size,
15050 int section_is_gnu)
15052 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
15054 if (section_is_gnu)
15056 unsigned int version, flags;
15058 version = read_2_bytes (abfd, mac_ptr);
15061 complaint (&symfile_complaints,
15062 _("unrecognized version `%d' in .debug_macro section"),
15068 flags = read_1_byte (abfd, mac_ptr);
15070 *offset_size = (flags & 1) ? 8 : 4;
15072 if ((flags & 2) != 0)
15073 /* We don't need the line table offset. */
15074 mac_ptr += *offset_size;
15076 /* Vendor opcode descriptions. */
15077 if ((flags & 4) != 0)
15079 unsigned int i, count;
15081 count = read_1_byte (abfd, mac_ptr);
15083 for (i = 0; i < count; ++i)
15085 unsigned int opcode, bytes_read;
15088 opcode = read_1_byte (abfd, mac_ptr);
15090 opcode_definitions[opcode] = mac_ptr;
15091 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15092 mac_ptr += bytes_read;
15101 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15102 including DW_GNU_MACINFO_transparent_include. */
15105 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
15106 struct macro_source_file *current_file,
15107 struct line_header *lh, char *comp_dir,
15108 struct dwarf2_section_info *section,
15109 int section_is_gnu,
15110 unsigned int offset_size,
15111 struct objfile *objfile)
15113 enum dwarf_macro_record_type macinfo_type;
15114 int at_commandline;
15115 gdb_byte *opcode_definitions[256];
15117 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15118 &offset_size, section_is_gnu);
15119 if (mac_ptr == NULL)
15121 /* We already issued a complaint. */
15125 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15126 GDB is still reading the definitions from command line. First
15127 DW_MACINFO_start_file will need to be ignored as it was already executed
15128 to create CURRENT_FILE for the main source holding also the command line
15129 definitions. On first met DW_MACINFO_start_file this flag is reset to
15130 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15132 at_commandline = 1;
15136 /* Do we at least have room for a macinfo type byte? */
15137 if (mac_ptr >= mac_end)
15139 dwarf2_macros_too_long_complaint (section);
15143 macinfo_type = read_1_byte (abfd, mac_ptr);
15146 /* Note that we rely on the fact that the corresponding GNU and
15147 DWARF constants are the same. */
15148 switch (macinfo_type)
15150 /* A zero macinfo type indicates the end of the macro
15155 case DW_MACRO_GNU_define:
15156 case DW_MACRO_GNU_undef:
15157 case DW_MACRO_GNU_define_indirect:
15158 case DW_MACRO_GNU_undef_indirect:
15160 unsigned int bytes_read;
15165 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15166 mac_ptr += bytes_read;
15168 if (macinfo_type == DW_MACRO_GNU_define
15169 || macinfo_type == DW_MACRO_GNU_undef)
15171 body = read_direct_string (abfd, mac_ptr, &bytes_read);
15172 mac_ptr += bytes_read;
15176 LONGEST str_offset;
15178 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
15179 mac_ptr += offset_size;
15181 body = read_indirect_string_at_offset (abfd, str_offset);
15184 is_define = (macinfo_type == DW_MACRO_GNU_define
15185 || macinfo_type == DW_MACRO_GNU_define_indirect);
15186 if (! current_file)
15188 /* DWARF violation as no main source is present. */
15189 complaint (&symfile_complaints,
15190 _("debug info with no main source gives macro %s "
15192 is_define ? _("definition") : _("undefinition"),
15196 if ((line == 0 && !at_commandline)
15197 || (line != 0 && at_commandline))
15198 complaint (&symfile_complaints,
15199 _("debug info gives %s macro %s with %s line %d: %s"),
15200 at_commandline ? _("command-line") : _("in-file"),
15201 is_define ? _("definition") : _("undefinition"),
15202 line == 0 ? _("zero") : _("non-zero"), line, body);
15205 parse_macro_definition (current_file, line, body);
15208 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
15209 || macinfo_type == DW_MACRO_GNU_undef_indirect);
15210 macro_undef (current_file, line, body);
15215 case DW_MACRO_GNU_start_file:
15217 unsigned int bytes_read;
15220 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15221 mac_ptr += bytes_read;
15222 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15223 mac_ptr += bytes_read;
15225 if ((line == 0 && !at_commandline)
15226 || (line != 0 && at_commandline))
15227 complaint (&symfile_complaints,
15228 _("debug info gives source %d included "
15229 "from %s at %s line %d"),
15230 file, at_commandline ? _("command-line") : _("file"),
15231 line == 0 ? _("zero") : _("non-zero"), line);
15233 if (at_commandline)
15235 /* This DW_MACRO_GNU_start_file was executed in the
15237 at_commandline = 0;
15240 current_file = macro_start_file (file, line,
15241 current_file, comp_dir,
15246 case DW_MACRO_GNU_end_file:
15247 if (! current_file)
15248 complaint (&symfile_complaints,
15249 _("macro debug info has an unmatched "
15250 "`close_file' directive"));
15253 current_file = current_file->included_by;
15254 if (! current_file)
15256 enum dwarf_macro_record_type next_type;
15258 /* GCC circa March 2002 doesn't produce the zero
15259 type byte marking the end of the compilation
15260 unit. Complain if it's not there, but exit no
15263 /* Do we at least have room for a macinfo type byte? */
15264 if (mac_ptr >= mac_end)
15266 dwarf2_macros_too_long_complaint (section);
15270 /* We don't increment mac_ptr here, so this is just
15272 next_type = read_1_byte (abfd, mac_ptr);
15273 if (next_type != 0)
15274 complaint (&symfile_complaints,
15275 _("no terminating 0-type entry for "
15276 "macros in `.debug_macinfo' section"));
15283 case DW_MACRO_GNU_transparent_include:
15287 offset = read_offset_1 (abfd, mac_ptr, offset_size);
15288 mac_ptr += offset_size;
15290 dwarf_decode_macro_bytes (abfd,
15291 section->buffer + offset,
15292 mac_end, current_file,
15294 section, section_is_gnu,
15295 offset_size, objfile);
15299 case DW_MACINFO_vendor_ext:
15300 if (!section_is_gnu)
15302 unsigned int bytes_read;
15305 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15306 mac_ptr += bytes_read;
15307 read_direct_string (abfd, mac_ptr, &bytes_read);
15308 mac_ptr += bytes_read;
15310 /* We don't recognize any vendor extensions. */
15316 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15317 mac_ptr, abfd, offset_size,
15319 if (mac_ptr == NULL)
15323 } while (macinfo_type != 0);
15327 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
15328 char *comp_dir, bfd *abfd,
15329 struct dwarf2_cu *cu,
15330 struct dwarf2_section_info *section,
15331 int section_is_gnu)
15333 struct objfile *objfile = dwarf2_per_objfile->objfile;
15334 gdb_byte *mac_ptr, *mac_end;
15335 struct macro_source_file *current_file = 0;
15336 enum dwarf_macro_record_type macinfo_type;
15337 unsigned int offset_size = cu->header.offset_size;
15338 gdb_byte *opcode_definitions[256];
15340 dwarf2_read_section (objfile, section);
15341 if (section->buffer == NULL)
15343 complaint (&symfile_complaints, _("missing %s section"),
15344 section->asection->name);
15348 /* First pass: Find the name of the base filename.
15349 This filename is needed in order to process all macros whose definition
15350 (or undefinition) comes from the command line. These macros are defined
15351 before the first DW_MACINFO_start_file entry, and yet still need to be
15352 associated to the base file.
15354 To determine the base file name, we scan the macro definitions until we
15355 reach the first DW_MACINFO_start_file entry. We then initialize
15356 CURRENT_FILE accordingly so that any macro definition found before the
15357 first DW_MACINFO_start_file can still be associated to the base file. */
15359 mac_ptr = section->buffer + offset;
15360 mac_end = section->buffer + section->size;
15362 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15363 &offset_size, section_is_gnu);
15364 if (mac_ptr == NULL)
15366 /* We already issued a complaint. */
15372 /* Do we at least have room for a macinfo type byte? */
15373 if (mac_ptr >= mac_end)
15375 /* Complaint is printed during the second pass as GDB will probably
15376 stop the first pass earlier upon finding
15377 DW_MACINFO_start_file. */
15381 macinfo_type = read_1_byte (abfd, mac_ptr);
15384 /* Note that we rely on the fact that the corresponding GNU and
15385 DWARF constants are the same. */
15386 switch (macinfo_type)
15388 /* A zero macinfo type indicates the end of the macro
15393 case DW_MACRO_GNU_define:
15394 case DW_MACRO_GNU_undef:
15395 /* Only skip the data by MAC_PTR. */
15397 unsigned int bytes_read;
15399 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15400 mac_ptr += bytes_read;
15401 read_direct_string (abfd, mac_ptr, &bytes_read);
15402 mac_ptr += bytes_read;
15406 case DW_MACRO_GNU_start_file:
15408 unsigned int bytes_read;
15411 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15412 mac_ptr += bytes_read;
15413 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15414 mac_ptr += bytes_read;
15416 current_file = macro_start_file (file, line, current_file,
15417 comp_dir, lh, objfile);
15421 case DW_MACRO_GNU_end_file:
15422 /* No data to skip by MAC_PTR. */
15425 case DW_MACRO_GNU_define_indirect:
15426 case DW_MACRO_GNU_undef_indirect:
15428 unsigned int bytes_read;
15430 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15431 mac_ptr += bytes_read;
15432 mac_ptr += offset_size;
15436 case DW_MACRO_GNU_transparent_include:
15437 /* Note that, according to the spec, a transparent include
15438 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15439 skip this opcode. */
15440 mac_ptr += offset_size;
15443 case DW_MACINFO_vendor_ext:
15444 /* Only skip the data by MAC_PTR. */
15445 if (!section_is_gnu)
15447 unsigned int bytes_read;
15449 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15450 mac_ptr += bytes_read;
15451 read_direct_string (abfd, mac_ptr, &bytes_read);
15452 mac_ptr += bytes_read;
15457 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15458 mac_ptr, abfd, offset_size,
15460 if (mac_ptr == NULL)
15464 } while (macinfo_type != 0 && current_file == NULL);
15466 /* Second pass: Process all entries.
15468 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15469 command-line macro definitions/undefinitions. This flag is unset when we
15470 reach the first DW_MACINFO_start_file entry. */
15472 dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end,
15473 current_file, lh, comp_dir, section, section_is_gnu,
15474 offset_size, objfile);
15477 /* Check if the attribute's form is a DW_FORM_block*
15478 if so return true else false. */
15480 attr_form_is_block (struct attribute *attr)
15482 return (attr == NULL ? 0 :
15483 attr->form == DW_FORM_block1
15484 || attr->form == DW_FORM_block2
15485 || attr->form == DW_FORM_block4
15486 || attr->form == DW_FORM_block
15487 || attr->form == DW_FORM_exprloc);
15490 /* Return non-zero if ATTR's value is a section offset --- classes
15491 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15492 You may use DW_UNSND (attr) to retrieve such offsets.
15494 Section 7.5.4, "Attribute Encodings", explains that no attribute
15495 may have a value that belongs to more than one of these classes; it
15496 would be ambiguous if we did, because we use the same forms for all
15499 attr_form_is_section_offset (struct attribute *attr)
15501 return (attr->form == DW_FORM_data4
15502 || attr->form == DW_FORM_data8
15503 || attr->form == DW_FORM_sec_offset);
15507 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15508 zero otherwise. When this function returns true, you can apply
15509 dwarf2_get_attr_constant_value to it.
15511 However, note that for some attributes you must check
15512 attr_form_is_section_offset before using this test. DW_FORM_data4
15513 and DW_FORM_data8 are members of both the constant class, and of
15514 the classes that contain offsets into other debug sections
15515 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15516 that, if an attribute's can be either a constant or one of the
15517 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15518 taken as section offsets, not constants. */
15520 attr_form_is_constant (struct attribute *attr)
15522 switch (attr->form)
15524 case DW_FORM_sdata:
15525 case DW_FORM_udata:
15526 case DW_FORM_data1:
15527 case DW_FORM_data2:
15528 case DW_FORM_data4:
15529 case DW_FORM_data8:
15536 /* A helper function that fills in a dwarf2_loclist_baton. */
15539 fill_in_loclist_baton (struct dwarf2_cu *cu,
15540 struct dwarf2_loclist_baton *baton,
15541 struct attribute *attr)
15543 dwarf2_read_section (dwarf2_per_objfile->objfile,
15544 &dwarf2_per_objfile->loc);
15546 baton->per_cu = cu->per_cu;
15547 gdb_assert (baton->per_cu);
15548 /* We don't know how long the location list is, but make sure we
15549 don't run off the edge of the section. */
15550 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15551 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15552 baton->base_address = cu->base_address;
15556 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15557 struct dwarf2_cu *cu)
15559 struct objfile *objfile = dwarf2_per_objfile->objfile;
15561 if (attr_form_is_section_offset (attr)
15562 /* ".debug_loc" may not exist at all, or the offset may be outside
15563 the section. If so, fall through to the complaint in the
15565 && DW_UNSND (attr) < dwarf2_section_size (objfile,
15566 &dwarf2_per_objfile->loc))
15568 struct dwarf2_loclist_baton *baton;
15570 baton = obstack_alloc (&objfile->objfile_obstack,
15571 sizeof (struct dwarf2_loclist_baton));
15573 fill_in_loclist_baton (cu, baton, attr);
15575 if (cu->base_known == 0)
15576 complaint (&symfile_complaints,
15577 _("Location list used without "
15578 "specifying the CU base address."));
15580 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15581 SYMBOL_LOCATION_BATON (sym) = baton;
15585 struct dwarf2_locexpr_baton *baton;
15587 baton = obstack_alloc (&objfile->objfile_obstack,
15588 sizeof (struct dwarf2_locexpr_baton));
15589 baton->per_cu = cu->per_cu;
15590 gdb_assert (baton->per_cu);
15592 if (attr_form_is_block (attr))
15594 /* Note that we're just copying the block's data pointer
15595 here, not the actual data. We're still pointing into the
15596 info_buffer for SYM's objfile; right now we never release
15597 that buffer, but when we do clean up properly this may
15599 baton->size = DW_BLOCK (attr)->size;
15600 baton->data = DW_BLOCK (attr)->data;
15604 dwarf2_invalid_attrib_class_complaint ("location description",
15605 SYMBOL_NATURAL_NAME (sym));
15609 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15610 SYMBOL_LOCATION_BATON (sym) = baton;
15614 /* Return the OBJFILE associated with the compilation unit CU. If CU
15615 came from a separate debuginfo file, then the master objfile is
15619 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15621 struct objfile *objfile = per_cu->objfile;
15623 /* Return the master objfile, so that we can report and look up the
15624 correct file containing this variable. */
15625 if (objfile->separate_debug_objfile_backlink)
15626 objfile = objfile->separate_debug_objfile_backlink;
15631 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15632 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15633 CU_HEADERP first. */
15635 static const struct comp_unit_head *
15636 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15637 struct dwarf2_per_cu_data *per_cu)
15639 struct objfile *objfile;
15640 struct dwarf2_per_objfile *per_objfile;
15641 gdb_byte *info_ptr;
15644 return &per_cu->cu->header;
15646 objfile = per_cu->objfile;
15647 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15648 info_ptr = per_objfile->info.buffer + per_cu->offset;
15650 memset (cu_headerp, 0, sizeof (*cu_headerp));
15651 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15656 /* Return the address size given in the compilation unit header for CU. */
15659 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15661 struct comp_unit_head cu_header_local;
15662 const struct comp_unit_head *cu_headerp;
15664 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15666 return cu_headerp->addr_size;
15669 /* Return the offset size given in the compilation unit header for CU. */
15672 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15674 struct comp_unit_head cu_header_local;
15675 const struct comp_unit_head *cu_headerp;
15677 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15679 return cu_headerp->offset_size;
15682 /* See its dwarf2loc.h declaration. */
15685 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
15687 struct comp_unit_head cu_header_local;
15688 const struct comp_unit_head *cu_headerp;
15690 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15692 if (cu_headerp->version == 2)
15693 return cu_headerp->addr_size;
15695 return cu_headerp->offset_size;
15698 /* Return the text offset of the CU. The returned offset comes from
15699 this CU's objfile. If this objfile came from a separate debuginfo
15700 file, then the offset may be different from the corresponding
15701 offset in the parent objfile. */
15704 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
15706 struct objfile *objfile = per_cu->objfile;
15708 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15711 /* Locate the .debug_info compilation unit from CU's objfile which contains
15712 the DIE at OFFSET. Raises an error on failure. */
15714 static struct dwarf2_per_cu_data *
15715 dwarf2_find_containing_comp_unit (unsigned int offset,
15716 struct objfile *objfile)
15718 struct dwarf2_per_cu_data *this_cu;
15722 high = dwarf2_per_objfile->n_comp_units - 1;
15725 int mid = low + (high - low) / 2;
15727 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
15732 gdb_assert (low == high);
15733 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
15736 error (_("Dwarf Error: could not find partial DIE containing "
15737 "offset 0x%lx [in module %s]"),
15738 (long) offset, bfd_get_filename (objfile->obfd));
15740 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
15741 return dwarf2_per_objfile->all_comp_units[low-1];
15745 this_cu = dwarf2_per_objfile->all_comp_units[low];
15746 if (low == dwarf2_per_objfile->n_comp_units - 1
15747 && offset >= this_cu->offset + this_cu->length)
15748 error (_("invalid dwarf2 offset %u"), offset);
15749 gdb_assert (offset < this_cu->offset + this_cu->length);
15754 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15757 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
15759 memset (cu, 0, sizeof (*cu));
15761 cu->per_cu = per_cu;
15762 cu->objfile = per_cu->objfile;
15763 obstack_init (&cu->comp_unit_obstack);
15766 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15769 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
15771 struct attribute *attr;
15773 /* Set the language we're debugging. */
15774 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
15776 set_cu_language (DW_UNSND (attr), cu);
15779 cu->language = language_minimal;
15780 cu->language_defn = language_def (cu->language);
15784 /* Release one cached compilation unit, CU. We unlink it from the tree
15785 of compilation units, but we don't remove it from the read_in_chain;
15786 the caller is responsible for that.
15787 NOTE: DATA is a void * because this function is also used as a
15788 cleanup routine. */
15791 free_heap_comp_unit (void *data)
15793 struct dwarf2_cu *cu = data;
15795 gdb_assert (cu->per_cu != NULL);
15796 cu->per_cu->cu = NULL;
15799 obstack_free (&cu->comp_unit_obstack, NULL);
15804 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15805 when we're finished with it. We can't free the pointer itself, but be
15806 sure to unlink it from the cache. Also release any associated storage
15807 and perform cache maintenance.
15809 Only used during partial symbol parsing. */
15812 free_stack_comp_unit (void *data)
15814 struct dwarf2_cu *cu = data;
15816 gdb_assert (cu->per_cu != NULL);
15817 cu->per_cu->cu = NULL;
15820 obstack_free (&cu->comp_unit_obstack, NULL);
15821 cu->partial_dies = NULL;
15823 /* The previous code only did this if per_cu != NULL.
15824 But that would always succeed, so now we just unconditionally do
15825 the aging. This seems like the wrong place to do such aging,
15826 but cleaning that up is left for later. */
15827 age_cached_comp_units ();
15830 /* Free all cached compilation units. */
15833 free_cached_comp_units (void *data)
15835 struct dwarf2_per_cu_data *per_cu, **last_chain;
15837 per_cu = dwarf2_per_objfile->read_in_chain;
15838 last_chain = &dwarf2_per_objfile->read_in_chain;
15839 while (per_cu != NULL)
15841 struct dwarf2_per_cu_data *next_cu;
15843 next_cu = per_cu->cu->read_in_chain;
15845 free_heap_comp_unit (per_cu->cu);
15846 *last_chain = next_cu;
15852 /* Increase the age counter on each cached compilation unit, and free
15853 any that are too old. */
15856 age_cached_comp_units (void)
15858 struct dwarf2_per_cu_data *per_cu, **last_chain;
15860 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15861 per_cu = dwarf2_per_objfile->read_in_chain;
15862 while (per_cu != NULL)
15864 per_cu->cu->last_used ++;
15865 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15866 dwarf2_mark (per_cu->cu);
15867 per_cu = per_cu->cu->read_in_chain;
15870 per_cu = dwarf2_per_objfile->read_in_chain;
15871 last_chain = &dwarf2_per_objfile->read_in_chain;
15872 while (per_cu != NULL)
15874 struct dwarf2_per_cu_data *next_cu;
15876 next_cu = per_cu->cu->read_in_chain;
15878 if (!per_cu->cu->mark)
15880 free_heap_comp_unit (per_cu->cu);
15881 *last_chain = next_cu;
15884 last_chain = &per_cu->cu->read_in_chain;
15890 /* Remove a single compilation unit from the cache. */
15893 free_one_cached_comp_unit (void *target_cu)
15895 struct dwarf2_per_cu_data *per_cu, **last_chain;
15897 per_cu = dwarf2_per_objfile->read_in_chain;
15898 last_chain = &dwarf2_per_objfile->read_in_chain;
15899 while (per_cu != NULL)
15901 struct dwarf2_per_cu_data *next_cu;
15903 next_cu = per_cu->cu->read_in_chain;
15905 if (per_cu->cu == target_cu)
15907 free_heap_comp_unit (per_cu->cu);
15908 *last_chain = next_cu;
15912 last_chain = &per_cu->cu->read_in_chain;
15918 /* Release all extra memory associated with OBJFILE. */
15921 dwarf2_free_objfile (struct objfile *objfile)
15923 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15925 if (dwarf2_per_objfile == NULL)
15928 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15929 free_cached_comp_units (NULL);
15931 if (dwarf2_per_objfile->quick_file_names_table)
15932 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15934 /* Everything else should be on the objfile obstack. */
15937 /* A pair of DIE offset and GDB type pointer. We store these
15938 in a hash table separate from the DIEs, and preserve them
15939 when the DIEs are flushed out of cache. */
15941 struct dwarf2_offset_and_type
15943 unsigned int offset;
15947 /* Hash function for a dwarf2_offset_and_type. */
15950 offset_and_type_hash (const void *item)
15952 const struct dwarf2_offset_and_type *ofs = item;
15954 return ofs->offset;
15957 /* Equality function for a dwarf2_offset_and_type. */
15960 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15962 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15963 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15965 return ofs_lhs->offset == ofs_rhs->offset;
15968 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15969 table if necessary. For convenience, return TYPE.
15971 The DIEs reading must have careful ordering to:
15972 * Not cause infite loops trying to read in DIEs as a prerequisite for
15973 reading current DIE.
15974 * Not trying to dereference contents of still incompletely read in types
15975 while reading in other DIEs.
15976 * Enable referencing still incompletely read in types just by a pointer to
15977 the type without accessing its fields.
15979 Therefore caller should follow these rules:
15980 * Try to fetch any prerequisite types we may need to build this DIE type
15981 before building the type and calling set_die_type.
15982 * After building type call set_die_type for current DIE as soon as
15983 possible before fetching more types to complete the current type.
15984 * Make the type as complete as possible before fetching more types. */
15986 static struct type *
15987 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15989 struct dwarf2_offset_and_type **slot, ofs;
15990 struct objfile *objfile = cu->objfile;
15991 htab_t *type_hash_ptr;
15993 /* For Ada types, make sure that the gnat-specific data is always
15994 initialized (if not already set). There are a few types where
15995 we should not be doing so, because the type-specific area is
15996 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15997 where the type-specific area is used to store the floatformat).
15998 But this is not a problem, because the gnat-specific information
15999 is actually not needed for these types. */
16000 if (need_gnat_info (cu)
16001 && TYPE_CODE (type) != TYPE_CODE_FUNC
16002 && TYPE_CODE (type) != TYPE_CODE_FLT
16003 && !HAVE_GNAT_AUX_INFO (type))
16004 INIT_GNAT_SPECIFIC (type);
16006 if (cu->per_cu->debug_types_section)
16007 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
16009 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
16011 if (*type_hash_ptr == NULL)
16014 = htab_create_alloc_ex (127,
16015 offset_and_type_hash,
16016 offset_and_type_eq,
16018 &objfile->objfile_obstack,
16019 hashtab_obstack_allocate,
16020 dummy_obstack_deallocate);
16023 ofs.offset = die->offset;
16025 slot = (struct dwarf2_offset_and_type **)
16026 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
16028 complaint (&symfile_complaints,
16029 _("A problem internal to GDB: DIE 0x%x has type already set"),
16031 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
16036 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16037 table, or return NULL if the die does not have a saved type. */
16039 static struct type *
16040 get_die_type_at_offset (unsigned int offset,
16041 struct dwarf2_per_cu_data *per_cu)
16043 struct dwarf2_offset_and_type *slot, ofs;
16046 if (per_cu->debug_types_section)
16047 type_hash = dwarf2_per_objfile->debug_types_type_hash;
16049 type_hash = dwarf2_per_objfile->debug_info_type_hash;
16050 if (type_hash == NULL)
16053 ofs.offset = offset;
16054 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
16061 /* Look up the type for DIE in the appropriate type_hash table,
16062 or return NULL if DIE does not have a saved type. */
16064 static struct type *
16065 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
16067 return get_die_type_at_offset (die->offset, cu->per_cu);
16070 /* Add a dependence relationship from CU to REF_PER_CU. */
16073 dwarf2_add_dependence (struct dwarf2_cu *cu,
16074 struct dwarf2_per_cu_data *ref_per_cu)
16078 if (cu->dependencies == NULL)
16080 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
16081 NULL, &cu->comp_unit_obstack,
16082 hashtab_obstack_allocate,
16083 dummy_obstack_deallocate);
16085 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
16087 *slot = ref_per_cu;
16090 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16091 Set the mark field in every compilation unit in the
16092 cache that we must keep because we are keeping CU. */
16095 dwarf2_mark_helper (void **slot, void *data)
16097 struct dwarf2_per_cu_data *per_cu;
16099 per_cu = (struct dwarf2_per_cu_data *) *slot;
16101 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16102 reading of the chain. As such dependencies remain valid it is not much
16103 useful to track and undo them during QUIT cleanups. */
16104 if (per_cu->cu == NULL)
16107 if (per_cu->cu->mark)
16109 per_cu->cu->mark = 1;
16111 if (per_cu->cu->dependencies != NULL)
16112 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
16117 /* Set the mark field in CU and in every other compilation unit in the
16118 cache that we must keep because we are keeping CU. */
16121 dwarf2_mark (struct dwarf2_cu *cu)
16126 if (cu->dependencies != NULL)
16127 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
16131 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
16135 per_cu->cu->mark = 0;
16136 per_cu = per_cu->cu->read_in_chain;
16140 /* Trivial hash function for partial_die_info: the hash value of a DIE
16141 is its offset in .debug_info for this objfile. */
16144 partial_die_hash (const void *item)
16146 const struct partial_die_info *part_die = item;
16148 return part_die->offset;
16151 /* Trivial comparison function for partial_die_info structures: two DIEs
16152 are equal if they have the same offset. */
16155 partial_die_eq (const void *item_lhs, const void *item_rhs)
16157 const struct partial_die_info *part_die_lhs = item_lhs;
16158 const struct partial_die_info *part_die_rhs = item_rhs;
16160 return part_die_lhs->offset == part_die_rhs->offset;
16163 static struct cmd_list_element *set_dwarf2_cmdlist;
16164 static struct cmd_list_element *show_dwarf2_cmdlist;
16167 set_dwarf2_cmd (char *args, int from_tty)
16169 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
16173 show_dwarf2_cmd (char *args, int from_tty)
16175 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
16178 /* If section described by INFO was mmapped, munmap it now. */
16181 munmap_section_buffer (struct dwarf2_section_info *info)
16183 if (info->map_addr != NULL)
16188 res = munmap (info->map_addr, info->map_len);
16189 gdb_assert (res == 0);
16191 /* Without HAVE_MMAP, we should never be here to begin with. */
16192 gdb_assert_not_reached ("no mmap support");
16197 /* munmap debug sections for OBJFILE, if necessary. */
16200 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
16202 struct dwarf2_per_objfile *data = d;
16204 struct dwarf2_section_info *section;
16206 /* This is sorted according to the order they're defined in to make it easier
16207 to keep in sync. */
16208 munmap_section_buffer (&data->info);
16209 munmap_section_buffer (&data->abbrev);
16210 munmap_section_buffer (&data->line);
16211 munmap_section_buffer (&data->loc);
16212 munmap_section_buffer (&data->macinfo);
16213 munmap_section_buffer (&data->macro);
16214 munmap_section_buffer (&data->str);
16215 munmap_section_buffer (&data->ranges);
16216 munmap_section_buffer (&data->frame);
16217 munmap_section_buffer (&data->eh_frame);
16218 munmap_section_buffer (&data->gdb_index);
16221 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
16223 munmap_section_buffer (section);
16225 VEC_free (dwarf2_section_info_def, data->types);
16229 /* The "save gdb-index" command. */
16231 /* The contents of the hash table we create when building the string
16233 struct strtab_entry
16235 offset_type offset;
16239 /* Hash function for a strtab_entry.
16241 Function is used only during write_hash_table so no index format backward
16242 compatibility is needed. */
16245 hash_strtab_entry (const void *e)
16247 const struct strtab_entry *entry = e;
16248 return mapped_index_string_hash (INT_MAX, entry->str);
16251 /* Equality function for a strtab_entry. */
16254 eq_strtab_entry (const void *a, const void *b)
16256 const struct strtab_entry *ea = a;
16257 const struct strtab_entry *eb = b;
16258 return !strcmp (ea->str, eb->str);
16261 /* Create a strtab_entry hash table. */
16264 create_strtab (void)
16266 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
16267 xfree, xcalloc, xfree);
16270 /* Add a string to the constant pool. Return the string's offset in
16274 add_string (htab_t table, struct obstack *cpool, const char *str)
16277 struct strtab_entry entry;
16278 struct strtab_entry *result;
16281 slot = htab_find_slot (table, &entry, INSERT);
16286 result = XNEW (struct strtab_entry);
16287 result->offset = obstack_object_size (cpool);
16289 obstack_grow_str0 (cpool, str);
16292 return result->offset;
16295 /* An entry in the symbol table. */
16296 struct symtab_index_entry
16298 /* The name of the symbol. */
16300 /* The offset of the name in the constant pool. */
16301 offset_type index_offset;
16302 /* A sorted vector of the indices of all the CUs that hold an object
16304 VEC (offset_type) *cu_indices;
16307 /* The symbol table. This is a power-of-2-sized hash table. */
16308 struct mapped_symtab
16310 offset_type n_elements;
16312 struct symtab_index_entry **data;
16315 /* Hash function for a symtab_index_entry. */
16318 hash_symtab_entry (const void *e)
16320 const struct symtab_index_entry *entry = e;
16321 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
16322 sizeof (offset_type) * VEC_length (offset_type,
16323 entry->cu_indices),
16327 /* Equality function for a symtab_index_entry. */
16330 eq_symtab_entry (const void *a, const void *b)
16332 const struct symtab_index_entry *ea = a;
16333 const struct symtab_index_entry *eb = b;
16334 int len = VEC_length (offset_type, ea->cu_indices);
16335 if (len != VEC_length (offset_type, eb->cu_indices))
16337 return !memcmp (VEC_address (offset_type, ea->cu_indices),
16338 VEC_address (offset_type, eb->cu_indices),
16339 sizeof (offset_type) * len);
16342 /* Destroy a symtab_index_entry. */
16345 delete_symtab_entry (void *p)
16347 struct symtab_index_entry *entry = p;
16348 VEC_free (offset_type, entry->cu_indices);
16352 /* Create a hash table holding symtab_index_entry objects. */
16355 create_symbol_hash_table (void)
16357 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
16358 delete_symtab_entry, xcalloc, xfree);
16361 /* Create a new mapped symtab object. */
16363 static struct mapped_symtab *
16364 create_mapped_symtab (void)
16366 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
16367 symtab->n_elements = 0;
16368 symtab->size = 1024;
16369 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16373 /* Destroy a mapped_symtab. */
16376 cleanup_mapped_symtab (void *p)
16378 struct mapped_symtab *symtab = p;
16379 /* The contents of the array are freed when the other hash table is
16381 xfree (symtab->data);
16385 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16388 Function is used only during write_hash_table so no index format backward
16389 compatibility is needed. */
16391 static struct symtab_index_entry **
16392 find_slot (struct mapped_symtab *symtab, const char *name)
16394 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16396 index = hash & (symtab->size - 1);
16397 step = ((hash * 17) & (symtab->size - 1)) | 1;
16401 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16402 return &symtab->data[index];
16403 index = (index + step) & (symtab->size - 1);
16407 /* Expand SYMTAB's hash table. */
16410 hash_expand (struct mapped_symtab *symtab)
16412 offset_type old_size = symtab->size;
16414 struct symtab_index_entry **old_entries = symtab->data;
16417 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16419 for (i = 0; i < old_size; ++i)
16421 if (old_entries[i])
16423 struct symtab_index_entry **slot = find_slot (symtab,
16424 old_entries[i]->name);
16425 *slot = old_entries[i];
16429 xfree (old_entries);
16432 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16433 is the index of the CU in which the symbol appears. */
16436 add_index_entry (struct mapped_symtab *symtab, const char *name,
16437 offset_type cu_index)
16439 struct symtab_index_entry **slot;
16441 ++symtab->n_elements;
16442 if (4 * symtab->n_elements / 3 >= symtab->size)
16443 hash_expand (symtab);
16445 slot = find_slot (symtab, name);
16448 *slot = XNEW (struct symtab_index_entry);
16449 (*slot)->name = name;
16450 (*slot)->cu_indices = NULL;
16452 /* Don't push an index twice. Due to how we add entries we only
16453 have to check the last one. */
16454 if (VEC_empty (offset_type, (*slot)->cu_indices)
16455 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16456 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16459 /* Add a vector of indices to the constant pool. */
16462 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16463 struct symtab_index_entry *entry)
16467 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16470 offset_type len = VEC_length (offset_type, entry->cu_indices);
16471 offset_type val = MAYBE_SWAP (len);
16476 entry->index_offset = obstack_object_size (cpool);
16478 obstack_grow (cpool, &val, sizeof (val));
16480 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16483 val = MAYBE_SWAP (iter);
16484 obstack_grow (cpool, &val, sizeof (val));
16489 struct symtab_index_entry *old_entry = *slot;
16490 entry->index_offset = old_entry->index_offset;
16493 return entry->index_offset;
16496 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16497 constant pool entries going into the obstack CPOOL. */
16500 write_hash_table (struct mapped_symtab *symtab,
16501 struct obstack *output, struct obstack *cpool)
16504 htab_t symbol_hash_table;
16507 symbol_hash_table = create_symbol_hash_table ();
16508 str_table = create_strtab ();
16510 /* We add all the index vectors to the constant pool first, to
16511 ensure alignment is ok. */
16512 for (i = 0; i < symtab->size; ++i)
16514 if (symtab->data[i])
16515 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16518 /* Now write out the hash table. */
16519 for (i = 0; i < symtab->size; ++i)
16521 offset_type str_off, vec_off;
16523 if (symtab->data[i])
16525 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16526 vec_off = symtab->data[i]->index_offset;
16530 /* While 0 is a valid constant pool index, it is not valid
16531 to have 0 for both offsets. */
16536 str_off = MAYBE_SWAP (str_off);
16537 vec_off = MAYBE_SWAP (vec_off);
16539 obstack_grow (output, &str_off, sizeof (str_off));
16540 obstack_grow (output, &vec_off, sizeof (vec_off));
16543 htab_delete (str_table);
16544 htab_delete (symbol_hash_table);
16547 /* Struct to map psymtab to CU index in the index file. */
16548 struct psymtab_cu_index_map
16550 struct partial_symtab *psymtab;
16551 unsigned int cu_index;
16555 hash_psymtab_cu_index (const void *item)
16557 const struct psymtab_cu_index_map *map = item;
16559 return htab_hash_pointer (map->psymtab);
16563 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16565 const struct psymtab_cu_index_map *lhs = item_lhs;
16566 const struct psymtab_cu_index_map *rhs = item_rhs;
16568 return lhs->psymtab == rhs->psymtab;
16571 /* Helper struct for building the address table. */
16572 struct addrmap_index_data
16574 struct objfile *objfile;
16575 struct obstack *addr_obstack;
16576 htab_t cu_index_htab;
16578 /* Non-zero if the previous_* fields are valid.
16579 We can't write an entry until we see the next entry (since it is only then
16580 that we know the end of the entry). */
16581 int previous_valid;
16582 /* Index of the CU in the table of all CUs in the index file. */
16583 unsigned int previous_cu_index;
16584 /* Start address of the CU. */
16585 CORE_ADDR previous_cu_start;
16588 /* Write an address entry to OBSTACK. */
16591 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16592 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16594 offset_type cu_index_to_write;
16596 CORE_ADDR baseaddr;
16598 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16600 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16601 obstack_grow (obstack, addr, 8);
16602 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16603 obstack_grow (obstack, addr, 8);
16604 cu_index_to_write = MAYBE_SWAP (cu_index);
16605 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16608 /* Worker function for traversing an addrmap to build the address table. */
16611 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16613 struct addrmap_index_data *data = datap;
16614 struct partial_symtab *pst = obj;
16615 offset_type cu_index;
16618 if (data->previous_valid)
16619 add_address_entry (data->objfile, data->addr_obstack,
16620 data->previous_cu_start, start_addr,
16621 data->previous_cu_index);
16623 data->previous_cu_start = start_addr;
16626 struct psymtab_cu_index_map find_map, *map;
16627 find_map.psymtab = pst;
16628 map = htab_find (data->cu_index_htab, &find_map);
16629 gdb_assert (map != NULL);
16630 data->previous_cu_index = map->cu_index;
16631 data->previous_valid = 1;
16634 data->previous_valid = 0;
16639 /* Write OBJFILE's address map to OBSTACK.
16640 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16641 in the index file. */
16644 write_address_map (struct objfile *objfile, struct obstack *obstack,
16645 htab_t cu_index_htab)
16647 struct addrmap_index_data addrmap_index_data;
16649 /* When writing the address table, we have to cope with the fact that
16650 the addrmap iterator only provides the start of a region; we have to
16651 wait until the next invocation to get the start of the next region. */
16653 addrmap_index_data.objfile = objfile;
16654 addrmap_index_data.addr_obstack = obstack;
16655 addrmap_index_data.cu_index_htab = cu_index_htab;
16656 addrmap_index_data.previous_valid = 0;
16658 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16659 &addrmap_index_data);
16661 /* It's highly unlikely the last entry (end address = 0xff...ff)
16662 is valid, but we should still handle it.
16663 The end address is recorded as the start of the next region, but that
16664 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16666 if (addrmap_index_data.previous_valid)
16667 add_address_entry (objfile, obstack,
16668 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16669 addrmap_index_data.previous_cu_index);
16672 /* Add a list of partial symbols to SYMTAB. */
16675 write_psymbols (struct mapped_symtab *symtab,
16677 struct partial_symbol **psymp,
16679 offset_type cu_index,
16682 for (; count-- > 0; ++psymp)
16684 void **slot, *lookup;
16686 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16687 error (_("Ada is not currently supported by the index"));
16689 /* We only want to add a given psymbol once. However, we also
16690 want to account for whether it is global or static. So, we
16691 may add it twice, using slightly different values. */
16694 uintptr_t val = 1 | (uintptr_t) *psymp;
16696 lookup = (void *) val;
16701 /* Only add a given psymbol once. */
16702 slot = htab_find_slot (psyms_seen, lookup, INSERT);
16706 add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index);
16711 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16712 exception if there is an error. */
16715 write_obstack (FILE *file, struct obstack *obstack)
16717 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
16719 != obstack_object_size (obstack))
16720 error (_("couldn't data write to file"));
16723 /* Unlink a file if the argument is not NULL. */
16726 unlink_if_set (void *p)
16728 char **filename = p;
16730 unlink (*filename);
16733 /* A helper struct used when iterating over debug_types. */
16734 struct signatured_type_index_data
16736 struct objfile *objfile;
16737 struct mapped_symtab *symtab;
16738 struct obstack *types_list;
16743 /* A helper function that writes a single signatured_type to an
16747 write_one_signatured_type (void **slot, void *d)
16749 struct signatured_type_index_data *info = d;
16750 struct signatured_type *entry = (struct signatured_type *) *slot;
16751 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
16752 struct partial_symtab *psymtab = per_cu->v.psymtab;
16755 write_psymbols (info->symtab,
16757 info->objfile->global_psymbols.list
16758 + psymtab->globals_offset,
16759 psymtab->n_global_syms, info->cu_index,
16761 write_psymbols (info->symtab,
16763 info->objfile->static_psymbols.list
16764 + psymtab->statics_offset,
16765 psymtab->n_static_syms, info->cu_index,
16768 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
16769 obstack_grow (info->types_list, val, 8);
16770 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
16771 obstack_grow (info->types_list, val, 8);
16772 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
16773 obstack_grow (info->types_list, val, 8);
16780 /* Create an index file for OBJFILE in the directory DIR. */
16783 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
16785 struct cleanup *cleanup;
16786 char *filename, *cleanup_filename;
16787 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
16788 struct obstack cu_list, types_cu_list;
16791 struct mapped_symtab *symtab;
16792 offset_type val, size_of_contents, total_len;
16796 htab_t cu_index_htab;
16797 struct psymtab_cu_index_map *psymtab_cu_index_map;
16799 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
16802 if (dwarf2_per_objfile->using_index)
16803 error (_("Cannot use an index to create the index"));
16805 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
16806 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16808 if (stat (objfile->name, &st) < 0)
16809 perror_with_name (objfile->name);
16811 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
16812 INDEX_SUFFIX, (char *) NULL);
16813 cleanup = make_cleanup (xfree, filename);
16815 out_file = fopen (filename, "wb");
16817 error (_("Can't open `%s' for writing"), filename);
16819 cleanup_filename = filename;
16820 make_cleanup (unlink_if_set, &cleanup_filename);
16822 symtab = create_mapped_symtab ();
16823 make_cleanup (cleanup_mapped_symtab, symtab);
16825 obstack_init (&addr_obstack);
16826 make_cleanup_obstack_free (&addr_obstack);
16828 obstack_init (&cu_list);
16829 make_cleanup_obstack_free (&cu_list);
16831 obstack_init (&types_cu_list);
16832 make_cleanup_obstack_free (&types_cu_list);
16834 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16835 NULL, xcalloc, xfree);
16836 make_cleanup_htab_delete (psyms_seen);
16838 /* While we're scanning CU's create a table that maps a psymtab pointer
16839 (which is what addrmap records) to its index (which is what is recorded
16840 in the index file). This will later be needed to write the address
16842 cu_index_htab = htab_create_alloc (100,
16843 hash_psymtab_cu_index,
16844 eq_psymtab_cu_index,
16845 NULL, xcalloc, xfree);
16846 make_cleanup_htab_delete (cu_index_htab);
16847 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16848 xmalloc (sizeof (struct psymtab_cu_index_map)
16849 * dwarf2_per_objfile->n_comp_units);
16850 make_cleanup (xfree, psymtab_cu_index_map);
16852 /* The CU list is already sorted, so we don't need to do additional
16853 work here. Also, the debug_types entries do not appear in
16854 all_comp_units, but only in their own hash table. */
16855 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16857 struct dwarf2_per_cu_data *per_cu
16858 = dwarf2_per_objfile->all_comp_units[i];
16859 struct partial_symtab *psymtab = per_cu->v.psymtab;
16861 struct psymtab_cu_index_map *map;
16864 write_psymbols (symtab,
16866 objfile->global_psymbols.list + psymtab->globals_offset,
16867 psymtab->n_global_syms, i,
16869 write_psymbols (symtab,
16871 objfile->static_psymbols.list + psymtab->statics_offset,
16872 psymtab->n_static_syms, i,
16875 map = &psymtab_cu_index_map[i];
16876 map->psymtab = psymtab;
16878 slot = htab_find_slot (cu_index_htab, map, INSERT);
16879 gdb_assert (slot != NULL);
16880 gdb_assert (*slot == NULL);
16883 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16884 obstack_grow (&cu_list, val, 8);
16885 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16886 obstack_grow (&cu_list, val, 8);
16889 /* Dump the address map. */
16890 write_address_map (objfile, &addr_obstack, cu_index_htab);
16892 /* Write out the .debug_type entries, if any. */
16893 if (dwarf2_per_objfile->signatured_types)
16895 struct signatured_type_index_data sig_data;
16897 sig_data.objfile = objfile;
16898 sig_data.symtab = symtab;
16899 sig_data.types_list = &types_cu_list;
16900 sig_data.psyms_seen = psyms_seen;
16901 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
16902 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
16903 write_one_signatured_type, &sig_data);
16906 obstack_init (&constant_pool);
16907 make_cleanup_obstack_free (&constant_pool);
16908 obstack_init (&symtab_obstack);
16909 make_cleanup_obstack_free (&symtab_obstack);
16910 write_hash_table (symtab, &symtab_obstack, &constant_pool);
16912 obstack_init (&contents);
16913 make_cleanup_obstack_free (&contents);
16914 size_of_contents = 6 * sizeof (offset_type);
16915 total_len = size_of_contents;
16917 /* The version number. */
16918 val = MAYBE_SWAP (5);
16919 obstack_grow (&contents, &val, sizeof (val));
16921 /* The offset of the CU list from the start of the file. */
16922 val = MAYBE_SWAP (total_len);
16923 obstack_grow (&contents, &val, sizeof (val));
16924 total_len += obstack_object_size (&cu_list);
16926 /* The offset of the types CU list from the start of the file. */
16927 val = MAYBE_SWAP (total_len);
16928 obstack_grow (&contents, &val, sizeof (val));
16929 total_len += obstack_object_size (&types_cu_list);
16931 /* The offset of the address table from the start of the file. */
16932 val = MAYBE_SWAP (total_len);
16933 obstack_grow (&contents, &val, sizeof (val));
16934 total_len += obstack_object_size (&addr_obstack);
16936 /* The offset of the symbol table from the start of the file. */
16937 val = MAYBE_SWAP (total_len);
16938 obstack_grow (&contents, &val, sizeof (val));
16939 total_len += obstack_object_size (&symtab_obstack);
16941 /* The offset of the constant pool from the start of the file. */
16942 val = MAYBE_SWAP (total_len);
16943 obstack_grow (&contents, &val, sizeof (val));
16944 total_len += obstack_object_size (&constant_pool);
16946 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16948 write_obstack (out_file, &contents);
16949 write_obstack (out_file, &cu_list);
16950 write_obstack (out_file, &types_cu_list);
16951 write_obstack (out_file, &addr_obstack);
16952 write_obstack (out_file, &symtab_obstack);
16953 write_obstack (out_file, &constant_pool);
16957 /* We want to keep the file, so we set cleanup_filename to NULL
16958 here. See unlink_if_set. */
16959 cleanup_filename = NULL;
16961 do_cleanups (cleanup);
16964 /* Implementation of the `save gdb-index' command.
16966 Note that the file format used by this command is documented in the
16967 GDB manual. Any changes here must be documented there. */
16970 save_gdb_index_command (char *arg, int from_tty)
16972 struct objfile *objfile;
16975 error (_("usage: save gdb-index DIRECTORY"));
16977 ALL_OBJFILES (objfile)
16981 /* If the objfile does not correspond to an actual file, skip it. */
16982 if (stat (objfile->name, &st) < 0)
16985 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16986 if (dwarf2_per_objfile)
16988 volatile struct gdb_exception except;
16990 TRY_CATCH (except, RETURN_MASK_ERROR)
16992 write_psymtabs_to_index (objfile, arg);
16994 if (except.reason < 0)
16995 exception_fprintf (gdb_stderr, except,
16996 _("Error while writing index for `%s': "),
17004 int dwarf2_always_disassemble;
17007 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
17008 struct cmd_list_element *c, const char *value)
17010 fprintf_filtered (file,
17011 _("Whether to always disassemble "
17012 "DWARF expressions is %s.\n"),
17017 show_check_physname (struct ui_file *file, int from_tty,
17018 struct cmd_list_element *c, const char *value)
17020 fprintf_filtered (file,
17021 _("Whether to check \"physname\" is %s.\n"),
17025 void _initialize_dwarf2_read (void);
17028 _initialize_dwarf2_read (void)
17030 struct cmd_list_element *c;
17032 dwarf2_objfile_data_key
17033 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
17035 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
17036 Set DWARF 2 specific variables.\n\
17037 Configure DWARF 2 variables such as the cache size"),
17038 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
17039 0/*allow-unknown*/, &maintenance_set_cmdlist);
17041 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
17042 Show DWARF 2 specific variables\n\
17043 Show DWARF 2 variables such as the cache size"),
17044 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
17045 0/*allow-unknown*/, &maintenance_show_cmdlist);
17047 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
17048 &dwarf2_max_cache_age, _("\
17049 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17050 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17051 A higher limit means that cached compilation units will be stored\n\
17052 in memory longer, and more total memory will be used. Zero disables\n\
17053 caching, which can slow down startup."),
17055 show_dwarf2_max_cache_age,
17056 &set_dwarf2_cmdlist,
17057 &show_dwarf2_cmdlist);
17059 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
17060 &dwarf2_always_disassemble, _("\
17061 Set whether `info address' always disassembles DWARF expressions."), _("\
17062 Show whether `info address' always disassembles DWARF expressions."), _("\
17063 When enabled, DWARF expressions are always printed in an assembly-like\n\
17064 syntax. When disabled, expressions will be printed in a more\n\
17065 conversational style, when possible."),
17067 show_dwarf2_always_disassemble,
17068 &set_dwarf2_cmdlist,
17069 &show_dwarf2_cmdlist);
17071 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
17072 Set debugging of the dwarf2 DIE reader."), _("\
17073 Show debugging of the dwarf2 DIE reader."), _("\
17074 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17075 The value is the maximum depth to print."),
17078 &setdebuglist, &showdebuglist);
17080 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
17081 Set cross-checking of \"physname\" code against demangler."), _("\
17082 Show cross-checking of \"physname\" code against demangler."), _("\
17083 When enabled, GDB's internal \"physname\" code is checked against\n\
17085 NULL, show_check_physname,
17086 &setdebuglist, &showdebuglist);
17088 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
17090 Save a gdb-index file.\n\
17091 Usage: save gdb-index DIRECTORY"),
17093 set_cmd_completer (c, filename_completer);