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;
88 /* When non-zero, do not reject deprecated .gdb_index sections. */
89 int use_deprecated_index_sections = 0;
93 /* When set, the file that we're processing is known to have debugging
94 info for C++ namespaces. GCC 3.3.x did not produce this information,
95 but later versions do. */
97 static int processing_has_namespace_info;
99 static const struct objfile_data *dwarf2_objfile_data_key;
101 struct dwarf2_section_info
106 /* Not NULL if the section was actually mmapped. */
108 /* Page aligned size of mmapped area. */
109 bfd_size_type map_len;
110 /* True if we have tried to read this section. */
114 typedef struct dwarf2_section_info dwarf2_section_info_def;
115 DEF_VEC_O (dwarf2_section_info_def);
117 /* All offsets in the index are of this type. It must be
118 architecture-independent. */
119 typedef uint32_t offset_type;
121 DEF_VEC_I (offset_type);
123 /* A description of the mapped index. The file format is described in
124 a comment by the code that writes the index. */
127 /* Index data format version. */
130 /* The total length of the buffer. */
133 /* A pointer to the address table data. */
134 const gdb_byte *address_table;
136 /* Size of the address table data in bytes. */
137 offset_type address_table_size;
139 /* The symbol table, implemented as a hash table. */
140 const offset_type *symbol_table;
142 /* Size in slots, each slot is 2 offset_types. */
143 offset_type symbol_table_slots;
145 /* A pointer to the constant pool. */
146 const char *constant_pool;
149 /* Collection of data recorded per objfile.
150 This hangs off of dwarf2_objfile_data_key. */
152 struct dwarf2_per_objfile
154 struct dwarf2_section_info info;
155 struct dwarf2_section_info abbrev;
156 struct dwarf2_section_info line;
157 struct dwarf2_section_info loc;
158 struct dwarf2_section_info macinfo;
159 struct dwarf2_section_info macro;
160 struct dwarf2_section_info str;
161 struct dwarf2_section_info ranges;
162 struct dwarf2_section_info frame;
163 struct dwarf2_section_info eh_frame;
164 struct dwarf2_section_info gdb_index;
166 VEC (dwarf2_section_info_def) *types;
169 struct objfile *objfile;
171 /* Table of all the compilation units. This is used to locate
172 the target compilation unit of a particular reference. */
173 struct dwarf2_per_cu_data **all_comp_units;
175 /* The number of compilation units in ALL_COMP_UNITS. */
178 /* The number of .debug_types-related CUs. */
181 /* The .debug_types-related CUs (TUs). */
182 struct dwarf2_per_cu_data **all_type_units;
184 /* A chain of compilation units that are currently read in, so that
185 they can be freed later. */
186 struct dwarf2_per_cu_data *read_in_chain;
188 /* A table mapping .debug_types signatures to its signatured_type entry.
189 This is NULL if the .debug_types section hasn't been read in yet. */
190 htab_t signatured_types;
192 /* A flag indicating wether this objfile has a section loaded at a
194 int has_section_at_zero;
196 /* True if we are using the mapped index,
197 or we are faking it for OBJF_READNOW's sake. */
198 unsigned char using_index;
200 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
201 struct mapped_index *index_table;
203 /* When using index_table, this keeps track of all quick_file_names entries.
204 TUs can share line table entries with CUs or other TUs, and there can be
205 a lot more TUs than unique line tables, so we maintain a separate table
206 of all line table entries to support the sharing. */
207 htab_t quick_file_names_table;
209 /* Set during partial symbol reading, to prevent queueing of full
211 int reading_partial_symbols;
213 /* Table mapping type .debug_info DIE offsets to types.
214 This is NULL if not allocated yet.
215 It (currently) makes sense to allocate debug_types_type_hash lazily.
216 To keep things simple we allocate both lazily. */
217 htab_t debug_info_type_hash;
219 /* Table mapping type .debug_types DIE offsets to types.
220 This is NULL if not allocated yet. */
221 htab_t debug_types_type_hash;
224 static struct dwarf2_per_objfile *dwarf2_per_objfile;
226 /* Default names of the debugging sections. */
228 /* Note that if the debugging section has been compressed, it might
229 have a name like .zdebug_info. */
231 static const struct dwarf2_debug_sections dwarf2_elf_names =
233 { ".debug_info", ".zdebug_info" },
234 { ".debug_abbrev", ".zdebug_abbrev" },
235 { ".debug_line", ".zdebug_line" },
236 { ".debug_loc", ".zdebug_loc" },
237 { ".debug_macinfo", ".zdebug_macinfo" },
238 { ".debug_macro", ".zdebug_macro" },
239 { ".debug_str", ".zdebug_str" },
240 { ".debug_ranges", ".zdebug_ranges" },
241 { ".debug_types", ".zdebug_types" },
242 { ".debug_frame", ".zdebug_frame" },
243 { ".eh_frame", NULL },
244 { ".gdb_index", ".zgdb_index" },
248 /* local data types */
250 /* We hold several abbreviation tables in memory at the same time. */
251 #ifndef ABBREV_HASH_SIZE
252 #define ABBREV_HASH_SIZE 121
255 /* The data in a compilation unit header, after target2host
256 translation, looks like this. */
257 struct comp_unit_head
261 unsigned char addr_size;
262 unsigned char signed_addr_p;
263 unsigned int abbrev_offset;
265 /* Size of file offsets; either 4 or 8. */
266 unsigned int offset_size;
268 /* Size of the length field; either 4 or 12. */
269 unsigned int initial_length_size;
271 /* Offset to the first byte of this compilation unit header in the
272 .debug_info section, for resolving relative reference dies. */
275 /* Offset to first die in this cu from the start of the cu.
276 This will be the first byte following the compilation unit header. */
277 unsigned int first_die_offset;
280 /* Type used for delaying computation of method physnames.
281 See comments for compute_delayed_physnames. */
282 struct delayed_method_info
284 /* The type to which the method is attached, i.e., its parent class. */
287 /* The index of the method in the type's function fieldlists. */
290 /* The index of the method in the fieldlist. */
293 /* The name of the DIE. */
296 /* The DIE associated with this method. */
297 struct die_info *die;
300 typedef struct delayed_method_info delayed_method_info;
301 DEF_VEC_O (delayed_method_info);
303 /* Internal state when decoding a particular compilation unit. */
306 /* The objfile containing this compilation unit. */
307 struct objfile *objfile;
309 /* The header of the compilation unit. */
310 struct comp_unit_head header;
312 /* Base address of this compilation unit. */
313 CORE_ADDR base_address;
315 /* Non-zero if base_address has been set. */
318 /* The language we are debugging. */
319 enum language language;
320 const struct language_defn *language_defn;
322 const char *producer;
324 /* The generic symbol table building routines have separate lists for
325 file scope symbols and all all other scopes (local scopes). So
326 we need to select the right one to pass to add_symbol_to_list().
327 We do it by keeping a pointer to the correct list in list_in_scope.
329 FIXME: The original dwarf code just treated the file scope as the
330 first local scope, and all other local scopes as nested local
331 scopes, and worked fine. Check to see if we really need to
332 distinguish these in buildsym.c. */
333 struct pending **list_in_scope;
335 /* DWARF abbreviation table associated with this compilation unit. */
336 struct abbrev_info **dwarf2_abbrevs;
338 /* Storage for the abbrev table. */
339 struct obstack abbrev_obstack;
341 /* Hash table holding all the loaded partial DIEs. */
344 /* Storage for things with the same lifetime as this read-in compilation
345 unit, including partial DIEs. */
346 struct obstack comp_unit_obstack;
348 /* When multiple dwarf2_cu structures are living in memory, this field
349 chains them all together, so that they can be released efficiently.
350 We will probably also want a generation counter so that most-recently-used
351 compilation units are cached... */
352 struct dwarf2_per_cu_data *read_in_chain;
354 /* Backchain to our per_cu entry if the tree has been built. */
355 struct dwarf2_per_cu_data *per_cu;
357 /* How many compilation units ago was this CU last referenced? */
360 /* A hash table of die offsets for following references. */
363 /* Full DIEs if read in. */
364 struct die_info *dies;
366 /* A set of pointers to dwarf2_per_cu_data objects for compilation
367 units referenced by this one. Only set during full symbol processing;
368 partial symbol tables do not have dependencies. */
371 /* Header data from the line table, during full symbol processing. */
372 struct line_header *line_header;
374 /* A list of methods which need to have physnames computed
375 after all type information has been read. */
376 VEC (delayed_method_info) *method_list;
378 /* To be copied to symtab->call_site_htab. */
379 htab_t call_site_htab;
381 /* Mark used when releasing cached dies. */
382 unsigned int mark : 1;
384 /* This CU references .debug_loc. See the symtab->locations_valid field.
385 This test is imperfect as there may exist optimized debug code not using
386 any location list and still facing inlining issues if handled as
387 unoptimized code. For a future better test see GCC PR other/32998. */
388 unsigned int has_loclist : 1;
390 /* These cache the results of producer_is_gxx_lt_4_6.
391 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
392 information is cached because profiling CU expansion showed
393 excessive time spent in producer_is_gxx_lt_4_6. */
394 unsigned int checked_producer : 1;
395 unsigned int producer_is_gxx_lt_4_6 : 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;
545 unsigned int may_be_inlined : 1;
547 /* Flag set if the SCOPE field of this structure has been
549 unsigned int scope_set : 1;
551 /* Flag set if the DIE has a byte_size attribute. */
552 unsigned int has_byte_size : 1;
554 /* Flag set if any of the DIE's children are template arguments. */
555 unsigned int has_template_arguments : 1;
557 /* Flag set if fixup_partial_die has been called on this die. */
558 unsigned int fixup_called : 1;
560 /* The name of this DIE. Normally the value of DW_AT_name, but
561 sometimes a default name for unnamed DIEs. */
564 /* The linkage name, if present. */
565 const char *linkage_name;
567 /* The scope to prepend to our children. This is generally
568 allocated on the comp_unit_obstack, so will disappear
569 when this compilation unit leaves the cache. */
572 /* The location description associated with this DIE, if any. */
573 struct dwarf_block *locdesc;
575 /* If HAS_PC_INFO, the PC range associated with this DIE. */
579 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
580 DW_AT_sibling, if any. */
581 /* NOTE: This member isn't strictly necessary, read_partial_die could
582 return DW_AT_sibling values to its caller load_partial_dies. */
585 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
586 DW_AT_specification (or DW_AT_abstract_origin or
588 unsigned int spec_offset;
590 /* Pointers to this DIE's parent, first child, and next sibling,
592 struct partial_die_info *die_parent, *die_child, *die_sibling;
595 /* This data structure holds the information of an abbrev. */
598 unsigned int number; /* number identifying abbrev */
599 enum dwarf_tag tag; /* dwarf tag */
600 unsigned short has_children; /* boolean */
601 unsigned short num_attrs; /* number of attributes */
602 struct attr_abbrev *attrs; /* an array of attribute descriptions */
603 struct abbrev_info *next; /* next in chain */
608 ENUM_BITFIELD(dwarf_attribute) name : 16;
609 ENUM_BITFIELD(dwarf_form) form : 16;
612 /* Attributes have a name and a value. */
615 ENUM_BITFIELD(dwarf_attribute) name : 16;
616 ENUM_BITFIELD(dwarf_form) form : 15;
618 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
619 field should be in u.str (existing only for DW_STRING) but it is kept
620 here for better struct attribute alignment. */
621 unsigned int string_is_canonical : 1;
626 struct dwarf_block *blk;
630 struct signatured_type *signatured_type;
635 /* This data structure holds a complete die structure. */
638 /* DWARF-2 tag for this DIE. */
639 ENUM_BITFIELD(dwarf_tag) tag : 16;
641 /* Number of attributes */
642 unsigned char num_attrs;
644 /* True if we're presently building the full type name for the
645 type derived from this DIE. */
646 unsigned char building_fullname : 1;
651 /* Offset in .debug_info or .debug_types section. */
654 /* The dies in a compilation unit form an n-ary tree. PARENT
655 points to this die's parent; CHILD points to the first child of
656 this node; and all the children of a given node are chained
657 together via their SIBLING fields. */
658 struct die_info *child; /* Its first child, if any. */
659 struct die_info *sibling; /* Its next sibling, if any. */
660 struct die_info *parent; /* Its parent, if any. */
662 /* An array of attributes, with NUM_ATTRS elements. There may be
663 zero, but it's not common and zero-sized arrays are not
664 sufficiently portable C. */
665 struct attribute attrs[1];
668 /* Get at parts of an attribute structure. */
670 #define DW_STRING(attr) ((attr)->u.str)
671 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
672 #define DW_UNSND(attr) ((attr)->u.unsnd)
673 #define DW_BLOCK(attr) ((attr)->u.blk)
674 #define DW_SND(attr) ((attr)->u.snd)
675 #define DW_ADDR(attr) ((attr)->u.addr)
676 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
678 /* Blocks are a bunch of untyped bytes. */
683 /* Valid only if SIZE is not zero. */
687 #ifndef ATTR_ALLOC_CHUNK
688 #define ATTR_ALLOC_CHUNK 4
691 /* Allocate fields for structs, unions and enums in this size. */
692 #ifndef DW_FIELD_ALLOC_CHUNK
693 #define DW_FIELD_ALLOC_CHUNK 4
696 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
697 but this would require a corresponding change in unpack_field_as_long
699 static int bits_per_byte = 8;
701 /* The routines that read and process dies for a C struct or C++ class
702 pass lists of data member fields and lists of member function fields
703 in an instance of a field_info structure, as defined below. */
706 /* List of data member and baseclasses fields. */
709 struct nextfield *next;
714 *fields, *baseclasses;
716 /* Number of fields (including baseclasses). */
719 /* Number of baseclasses. */
722 /* Set if the accesibility of one of the fields is not public. */
723 int non_public_fields;
725 /* Member function fields array, entries are allocated in the order they
726 are encountered in the object file. */
729 struct nextfnfield *next;
730 struct fn_field fnfield;
734 /* Member function fieldlist array, contains name of possibly overloaded
735 member function, number of overloaded member functions and a pointer
736 to the head of the member function field chain. */
741 struct nextfnfield *head;
745 /* Number of entries in the fnfieldlists array. */
748 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
749 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
750 struct typedef_field_list
752 struct typedef_field field;
753 struct typedef_field_list *next;
756 unsigned typedef_field_list_count;
759 /* One item on the queue of compilation units to read in full symbols
761 struct dwarf2_queue_item
763 struct dwarf2_per_cu_data *per_cu;
764 struct dwarf2_queue_item *next;
767 /* The current queue. */
768 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
770 /* Loaded secondary compilation units are kept in memory until they
771 have not been referenced for the processing of this many
772 compilation units. Set this to zero to disable caching. Cache
773 sizes of up to at least twenty will improve startup time for
774 typical inter-CU-reference binaries, at an obvious memory cost. */
775 static int dwarf2_max_cache_age = 5;
777 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
778 struct cmd_list_element *c, const char *value)
780 fprintf_filtered (file, _("The upper bound on the age of cached "
781 "dwarf2 compilation units is %s.\n"),
786 /* Various complaints about symbol reading that don't abort the process. */
789 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
791 complaint (&symfile_complaints,
792 _("statement list doesn't fit in .debug_line section"));
796 dwarf2_debug_line_missing_file_complaint (void)
798 complaint (&symfile_complaints,
799 _(".debug_line section has line data without a file"));
803 dwarf2_debug_line_missing_end_sequence_complaint (void)
805 complaint (&symfile_complaints,
806 _(".debug_line section has line "
807 "program sequence without an end"));
811 dwarf2_complex_location_expr_complaint (void)
813 complaint (&symfile_complaints, _("location expression too complex"));
817 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
820 complaint (&symfile_complaints,
821 _("const value length mismatch for '%s', got %d, expected %d"),
826 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
828 complaint (&symfile_complaints,
829 _("macro info runs off end of `%s' section"),
830 section->asection->name);
834 dwarf2_macro_malformed_definition_complaint (const char *arg1)
836 complaint (&symfile_complaints,
837 _("macro debug info contains a "
838 "malformed macro definition:\n`%s'"),
843 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
845 complaint (&symfile_complaints,
846 _("invalid attribute class or form for '%s' in '%s'"),
850 /* local function prototypes */
852 static void dwarf2_locate_sections (bfd *, asection *, void *);
854 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
857 static void dwarf2_find_base_address (struct die_info *die,
858 struct dwarf2_cu *cu);
860 static void dwarf2_build_psymtabs_hard (struct objfile *);
862 static void scan_partial_symbols (struct partial_die_info *,
863 CORE_ADDR *, CORE_ADDR *,
864 int, struct dwarf2_cu *);
866 static void add_partial_symbol (struct partial_die_info *,
869 static void add_partial_namespace (struct partial_die_info *pdi,
870 CORE_ADDR *lowpc, CORE_ADDR *highpc,
871 int need_pc, struct dwarf2_cu *cu);
873 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
874 CORE_ADDR *highpc, int need_pc,
875 struct dwarf2_cu *cu);
877 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
878 struct dwarf2_cu *cu);
880 static void add_partial_subprogram (struct partial_die_info *pdi,
881 CORE_ADDR *lowpc, CORE_ADDR *highpc,
882 int need_pc, struct dwarf2_cu *cu);
884 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
885 gdb_byte *buffer, gdb_byte *info_ptr,
886 bfd *abfd, struct dwarf2_cu *cu);
888 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
890 static void psymtab_to_symtab_1 (struct partial_symtab *);
892 static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
894 static void dwarf2_free_abbrev_table (void *);
896 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
898 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
901 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
904 static struct partial_die_info *load_partial_dies (bfd *,
905 gdb_byte *, gdb_byte *,
906 int, struct dwarf2_cu *);
908 static gdb_byte *read_partial_die (struct partial_die_info *,
909 struct abbrev_info *abbrev,
911 gdb_byte *, gdb_byte *,
914 static struct partial_die_info *find_partial_die (unsigned int,
917 static void fixup_partial_die (struct partial_die_info *,
920 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
921 bfd *, gdb_byte *, struct dwarf2_cu *);
923 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
924 bfd *, gdb_byte *, struct dwarf2_cu *);
926 static unsigned int read_1_byte (bfd *, gdb_byte *);
928 static int read_1_signed_byte (bfd *, gdb_byte *);
930 static unsigned int read_2_bytes (bfd *, gdb_byte *);
932 static unsigned int read_4_bytes (bfd *, gdb_byte *);
934 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
936 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
939 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
941 static LONGEST read_checked_initial_length_and_offset
942 (bfd *, gdb_byte *, const struct comp_unit_head *,
943 unsigned int *, unsigned int *);
945 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
948 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
950 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
952 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
954 static char *read_indirect_string (bfd *, gdb_byte *,
955 const struct comp_unit_head *,
958 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
960 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
962 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
964 static void set_cu_language (unsigned int, struct dwarf2_cu *);
966 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
969 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
973 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
974 struct dwarf2_cu *cu);
976 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
978 static struct die_info *die_specification (struct die_info *die,
979 struct dwarf2_cu **);
981 static void free_line_header (struct line_header *lh);
983 static void add_file_name (struct line_header *, char *, unsigned int,
984 unsigned int, unsigned int);
986 static struct line_header *(dwarf_decode_line_header
987 (unsigned int offset,
988 bfd *abfd, struct dwarf2_cu *cu));
990 static void dwarf_decode_lines (struct line_header *, const char *,
991 struct dwarf2_cu *, struct partial_symtab *,
994 static void dwarf2_start_subfile (char *, const char *, const char *);
996 static struct symbol *new_symbol (struct die_info *, struct type *,
999 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1000 struct dwarf2_cu *, struct symbol *);
1002 static void dwarf2_const_value (struct attribute *, struct symbol *,
1003 struct dwarf2_cu *);
1005 static void dwarf2_const_value_attr (struct attribute *attr,
1008 struct obstack *obstack,
1009 struct dwarf2_cu *cu, long *value,
1011 struct dwarf2_locexpr_baton **baton);
1013 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1015 static int need_gnat_info (struct dwarf2_cu *);
1017 static struct type *die_descriptive_type (struct die_info *,
1018 struct dwarf2_cu *);
1020 static void set_descriptive_type (struct type *, struct die_info *,
1021 struct dwarf2_cu *);
1023 static struct type *die_containing_type (struct die_info *,
1024 struct dwarf2_cu *);
1026 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1027 struct dwarf2_cu *);
1029 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1031 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1033 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1035 static char *typename_concat (struct obstack *obs, const char *prefix,
1036 const char *suffix, int physname,
1037 struct dwarf2_cu *cu);
1039 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1041 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1043 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1045 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1047 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1049 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1050 struct dwarf2_cu *, struct partial_symtab *);
1052 static int dwarf2_get_pc_bounds (struct die_info *,
1053 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1054 struct partial_symtab *);
1056 static void get_scope_pc_bounds (struct die_info *,
1057 CORE_ADDR *, CORE_ADDR *,
1058 struct dwarf2_cu *);
1060 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1061 CORE_ADDR, struct dwarf2_cu *);
1063 static void dwarf2_add_field (struct field_info *, struct die_info *,
1064 struct dwarf2_cu *);
1066 static void dwarf2_attach_fields_to_type (struct field_info *,
1067 struct type *, struct dwarf2_cu *);
1069 static void dwarf2_add_member_fn (struct field_info *,
1070 struct die_info *, struct type *,
1071 struct dwarf2_cu *);
1073 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1075 struct dwarf2_cu *);
1077 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1079 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1081 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1083 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1085 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1087 static struct type *read_module_type (struct die_info *die,
1088 struct dwarf2_cu *cu);
1090 static const char *namespace_name (struct die_info *die,
1091 int *is_anonymous, struct dwarf2_cu *);
1093 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1095 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1097 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1098 struct dwarf2_cu *);
1100 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1102 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1104 gdb_byte **new_info_ptr,
1105 struct die_info *parent);
1107 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1109 gdb_byte **new_info_ptr,
1110 struct die_info *parent);
1112 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1114 gdb_byte **new_info_ptr,
1115 struct die_info *parent);
1117 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1118 struct die_info **, gdb_byte *,
1121 static void process_die (struct die_info *, struct dwarf2_cu *);
1123 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1126 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1128 static const char *dwarf2_full_name (char *name,
1129 struct die_info *die,
1130 struct dwarf2_cu *cu);
1132 static struct die_info *dwarf2_extension (struct die_info *die,
1133 struct dwarf2_cu **);
1135 static char *dwarf_tag_name (unsigned int);
1137 static char *dwarf_attr_name (unsigned int);
1139 static char *dwarf_form_name (unsigned int);
1141 static char *dwarf_bool_name (unsigned int);
1143 static char *dwarf_type_encoding_name (unsigned int);
1146 static char *dwarf_cfi_name (unsigned int);
1149 static struct die_info *sibling_die (struct die_info *);
1151 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1153 static void dump_die_for_error (struct die_info *);
1155 static void dump_die_1 (struct ui_file *, int level, int max_level,
1158 /*static*/ void dump_die (struct die_info *, int max_level);
1160 static void store_in_ref_table (struct die_info *,
1161 struct dwarf2_cu *);
1163 static int is_ref_attr (struct attribute *);
1165 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1167 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1169 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1171 struct dwarf2_cu **);
1173 static struct die_info *follow_die_ref (struct die_info *,
1175 struct dwarf2_cu **);
1177 static struct die_info *follow_die_sig (struct die_info *,
1179 struct dwarf2_cu **);
1181 static struct signatured_type *lookup_signatured_type_at_offset
1182 (struct objfile *objfile,
1183 struct dwarf2_section_info *section,
1184 unsigned int offset);
1186 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1188 static void read_signatured_type (struct signatured_type *type_sig);
1190 /* memory allocation interface */
1192 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1194 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1196 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1198 static void dwarf_decode_macros (struct line_header *, unsigned int,
1199 char *, bfd *, struct dwarf2_cu *,
1200 struct dwarf2_section_info *,
1203 static int attr_form_is_block (struct attribute *);
1205 static int attr_form_is_section_offset (struct attribute *);
1207 static int attr_form_is_constant (struct attribute *);
1209 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1210 struct dwarf2_loclist_baton *baton,
1211 struct attribute *attr);
1213 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1215 struct dwarf2_cu *cu);
1217 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1218 struct abbrev_info *abbrev,
1219 struct dwarf2_cu *cu);
1221 static void free_stack_comp_unit (void *);
1223 static hashval_t partial_die_hash (const void *item);
1225 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1227 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1228 (unsigned int offset, struct objfile *objfile);
1230 static void init_one_comp_unit (struct dwarf2_cu *cu,
1231 struct dwarf2_per_cu_data *per_cu);
1233 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1234 struct die_info *comp_unit_die);
1236 static void free_heap_comp_unit (void *);
1238 static void free_cached_comp_units (void *);
1240 static void age_cached_comp_units (void);
1242 static void free_one_cached_comp_unit (void *);
1244 static struct type *set_die_type (struct die_info *, struct type *,
1245 struct dwarf2_cu *);
1247 static void create_all_comp_units (struct objfile *);
1249 static int create_debug_types_hash_table (struct objfile *objfile);
1251 static void load_full_comp_unit (struct dwarf2_per_cu_data *);
1253 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1255 static void dwarf2_add_dependence (struct dwarf2_cu *,
1256 struct dwarf2_per_cu_data *);
1258 static void dwarf2_mark (struct dwarf2_cu *);
1260 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1262 static struct type *get_die_type_at_offset (unsigned int,
1263 struct dwarf2_per_cu_data *per_cu);
1265 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1267 static void dwarf2_release_queue (void *dummy);
1269 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
1271 static void process_queue (void);
1273 static void find_file_and_directory (struct die_info *die,
1274 struct dwarf2_cu *cu,
1275 char **name, char **comp_dir);
1277 static char *file_full_name (int file, struct line_header *lh,
1278 const char *comp_dir);
1280 static gdb_byte *read_and_check_comp_unit_head
1281 (struct comp_unit_head *header,
1282 struct dwarf2_section_info *section, gdb_byte *info_ptr,
1283 int is_debug_types_section);
1285 static void init_cu_die_reader (struct die_reader_specs *reader,
1286 struct dwarf2_cu *cu);
1288 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1292 /* Convert VALUE between big- and little-endian. */
1294 byte_swap (offset_type value)
1298 result = (value & 0xff) << 24;
1299 result |= (value & 0xff00) << 8;
1300 result |= (value & 0xff0000) >> 8;
1301 result |= (value & 0xff000000) >> 24;
1305 #define MAYBE_SWAP(V) byte_swap (V)
1308 #define MAYBE_SWAP(V) (V)
1309 #endif /* WORDS_BIGENDIAN */
1311 /* The suffix for an index file. */
1312 #define INDEX_SUFFIX ".gdb-index"
1314 static const char *dwarf2_physname (char *name, struct die_info *die,
1315 struct dwarf2_cu *cu);
1317 /* Try to locate the sections we need for DWARF 2 debugging
1318 information and return true if we have enough to do something.
1319 NAMES points to the dwarf2 section names, or is NULL if the standard
1320 ELF names are used. */
1323 dwarf2_has_info (struct objfile *objfile,
1324 const struct dwarf2_debug_sections *names)
1326 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1327 if (!dwarf2_per_objfile)
1329 /* Initialize per-objfile state. */
1330 struct dwarf2_per_objfile *data
1331 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1333 memset (data, 0, sizeof (*data));
1334 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1335 dwarf2_per_objfile = data;
1337 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1339 dwarf2_per_objfile->objfile = objfile;
1341 return (dwarf2_per_objfile->info.asection != NULL
1342 && dwarf2_per_objfile->abbrev.asection != NULL);
1345 /* When loading sections, we look either for uncompressed section or for
1346 compressed section names. */
1349 section_is_p (const char *section_name,
1350 const struct dwarf2_section_names *names)
1352 if (names->normal != NULL
1353 && strcmp (section_name, names->normal) == 0)
1355 if (names->compressed != NULL
1356 && strcmp (section_name, names->compressed) == 0)
1361 /* This function is mapped across the sections and remembers the
1362 offset and size of each of the debugging sections we are interested
1366 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1368 const struct dwarf2_debug_sections *names;
1371 names = &dwarf2_elf_names;
1373 names = (const struct dwarf2_debug_sections *) vnames;
1375 if (section_is_p (sectp->name, &names->info))
1377 dwarf2_per_objfile->info.asection = sectp;
1378 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1380 else if (section_is_p (sectp->name, &names->abbrev))
1382 dwarf2_per_objfile->abbrev.asection = sectp;
1383 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1385 else if (section_is_p (sectp->name, &names->line))
1387 dwarf2_per_objfile->line.asection = sectp;
1388 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1390 else if (section_is_p (sectp->name, &names->loc))
1392 dwarf2_per_objfile->loc.asection = sectp;
1393 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1395 else if (section_is_p (sectp->name, &names->macinfo))
1397 dwarf2_per_objfile->macinfo.asection = sectp;
1398 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1400 else if (section_is_p (sectp->name, &names->macro))
1402 dwarf2_per_objfile->macro.asection = sectp;
1403 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1405 else if (section_is_p (sectp->name, &names->str))
1407 dwarf2_per_objfile->str.asection = sectp;
1408 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1410 else if (section_is_p (sectp->name, &names->frame))
1412 dwarf2_per_objfile->frame.asection = sectp;
1413 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1415 else if (section_is_p (sectp->name, &names->eh_frame))
1417 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1419 if (aflag & SEC_HAS_CONTENTS)
1421 dwarf2_per_objfile->eh_frame.asection = sectp;
1422 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1425 else if (section_is_p (sectp->name, &names->ranges))
1427 dwarf2_per_objfile->ranges.asection = sectp;
1428 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1430 else if (section_is_p (sectp->name, &names->types))
1432 struct dwarf2_section_info type_section;
1434 memset (&type_section, 0, sizeof (type_section));
1435 type_section.asection = sectp;
1436 type_section.size = bfd_get_section_size (sectp);
1438 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1441 else if (section_is_p (sectp->name, &names->gdb_index))
1443 dwarf2_per_objfile->gdb_index.asection = sectp;
1444 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1447 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1448 && bfd_section_vma (abfd, sectp) == 0)
1449 dwarf2_per_objfile->has_section_at_zero = 1;
1452 /* Decompress a section that was compressed using zlib. Store the
1453 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1456 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1457 gdb_byte **outbuf, bfd_size_type *outsize)
1459 bfd *abfd = objfile->obfd;
1461 error (_("Support for zlib-compressed DWARF data (from '%s') "
1462 "is disabled in this copy of GDB"),
1463 bfd_get_filename (abfd));
1465 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1466 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1467 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1468 bfd_size_type uncompressed_size;
1469 gdb_byte *uncompressed_buffer;
1472 int header_size = 12;
1474 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1475 || bfd_bread (compressed_buffer,
1476 compressed_size, abfd) != compressed_size)
1477 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1478 bfd_get_filename (abfd));
1480 /* Read the zlib header. In this case, it should be "ZLIB" followed
1481 by the uncompressed section size, 8 bytes in big-endian order. */
1482 if (compressed_size < header_size
1483 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1484 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1485 bfd_get_filename (abfd));
1486 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1487 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1488 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1489 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1490 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1491 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1492 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1493 uncompressed_size += compressed_buffer[11];
1495 /* It is possible the section consists of several compressed
1496 buffers concatenated together, so we uncompress in a loop. */
1500 strm.avail_in = compressed_size - header_size;
1501 strm.next_in = (Bytef*) compressed_buffer + header_size;
1502 strm.avail_out = uncompressed_size;
1503 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1505 rc = inflateInit (&strm);
1506 while (strm.avail_in > 0)
1509 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1510 bfd_get_filename (abfd), rc);
1511 strm.next_out = ((Bytef*) uncompressed_buffer
1512 + (uncompressed_size - strm.avail_out));
1513 rc = inflate (&strm, Z_FINISH);
1514 if (rc != Z_STREAM_END)
1515 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1516 bfd_get_filename (abfd), rc);
1517 rc = inflateReset (&strm);
1519 rc = inflateEnd (&strm);
1521 || strm.avail_out != 0)
1522 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1523 bfd_get_filename (abfd), rc);
1525 do_cleanups (cleanup);
1526 *outbuf = uncompressed_buffer;
1527 *outsize = uncompressed_size;
1531 /* A helper function that decides whether a section is empty. */
1534 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1536 return info->asection == NULL || info->size == 0;
1539 /* Read the contents of the section INFO from object file specified by
1540 OBJFILE, store info about the section into INFO.
1541 If the section is compressed, uncompress it before returning. */
1544 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1546 bfd *abfd = objfile->obfd;
1547 asection *sectp = info->asection;
1548 gdb_byte *buf, *retbuf;
1549 unsigned char header[4];
1553 info->buffer = NULL;
1554 info->map_addr = NULL;
1557 if (dwarf2_section_empty_p (info))
1560 /* Check if the file has a 4-byte header indicating compression. */
1561 if (info->size > sizeof (header)
1562 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1563 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1565 /* Upon decompression, update the buffer and its size. */
1566 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1568 zlib_decompress_section (objfile, sectp, &info->buffer,
1576 pagesize = getpagesize ();
1578 /* Only try to mmap sections which are large enough: we don't want to
1579 waste space due to fragmentation. Also, only try mmap for sections
1580 without relocations. */
1582 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1584 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1585 MAP_PRIVATE, sectp->filepos,
1586 &info->map_addr, &info->map_len);
1588 if ((caddr_t)info->buffer != MAP_FAILED)
1590 #if HAVE_POSIX_MADVISE
1591 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1598 /* If we get here, we are a normal, not-compressed section. */
1600 = obstack_alloc (&objfile->objfile_obstack, info->size);
1602 /* When debugging .o files, we may need to apply relocations; see
1603 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1604 We never compress sections in .o files, so we only need to
1605 try this when the section is not compressed. */
1606 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1609 info->buffer = retbuf;
1613 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1614 || bfd_bread (buf, info->size, abfd) != info->size)
1615 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1616 bfd_get_filename (abfd));
1619 /* A helper function that returns the size of a section in a safe way.
1620 If you are positive that the section has been read before using the
1621 size, then it is safe to refer to the dwarf2_section_info object's
1622 "size" field directly. In other cases, you must call this
1623 function, because for compressed sections the size field is not set
1624 correctly until the section has been read. */
1626 static bfd_size_type
1627 dwarf2_section_size (struct objfile *objfile,
1628 struct dwarf2_section_info *info)
1631 dwarf2_read_section (objfile, info);
1635 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1639 dwarf2_get_section_info (struct objfile *objfile,
1640 enum dwarf2_section_enum sect,
1641 asection **sectp, gdb_byte **bufp,
1642 bfd_size_type *sizep)
1644 struct dwarf2_per_objfile *data
1645 = objfile_data (objfile, dwarf2_objfile_data_key);
1646 struct dwarf2_section_info *info;
1648 /* We may see an objfile without any DWARF, in which case we just
1659 case DWARF2_DEBUG_FRAME:
1660 info = &data->frame;
1662 case DWARF2_EH_FRAME:
1663 info = &data->eh_frame;
1666 gdb_assert_not_reached ("unexpected section");
1669 dwarf2_read_section (objfile, info);
1671 *sectp = info->asection;
1672 *bufp = info->buffer;
1673 *sizep = info->size;
1677 /* DWARF quick_symbols_functions support. */
1679 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1680 unique line tables, so we maintain a separate table of all .debug_line
1681 derived entries to support the sharing.
1682 All the quick functions need is the list of file names. We discard the
1683 line_header when we're done and don't need to record it here. */
1684 struct quick_file_names
1686 /* The offset in .debug_line of the line table. We hash on this. */
1687 unsigned int offset;
1689 /* The number of entries in file_names, real_names. */
1690 unsigned int num_file_names;
1692 /* The file names from the line table, after being run through
1694 const char **file_names;
1696 /* The file names from the line table after being run through
1697 gdb_realpath. These are computed lazily. */
1698 const char **real_names;
1701 /* When using the index (and thus not using psymtabs), each CU has an
1702 object of this type. This is used to hold information needed by
1703 the various "quick" methods. */
1704 struct dwarf2_per_cu_quick_data
1706 /* The file table. This can be NULL if there was no file table
1707 or it's currently not read in.
1708 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1709 struct quick_file_names *file_names;
1711 /* The corresponding symbol table. This is NULL if symbols for this
1712 CU have not yet been read. */
1713 struct symtab *symtab;
1715 /* A temporary mark bit used when iterating over all CUs in
1716 expand_symtabs_matching. */
1717 unsigned int mark : 1;
1719 /* True if we've tried to read the file table and found there isn't one.
1720 There will be no point in trying to read it again next time. */
1721 unsigned int no_file_data : 1;
1724 /* Hash function for a quick_file_names. */
1727 hash_file_name_entry (const void *e)
1729 const struct quick_file_names *file_data = e;
1731 return file_data->offset;
1734 /* Equality function for a quick_file_names. */
1737 eq_file_name_entry (const void *a, const void *b)
1739 const struct quick_file_names *ea = a;
1740 const struct quick_file_names *eb = b;
1742 return ea->offset == eb->offset;
1745 /* Delete function for a quick_file_names. */
1748 delete_file_name_entry (void *e)
1750 struct quick_file_names *file_data = e;
1753 for (i = 0; i < file_data->num_file_names; ++i)
1755 xfree ((void*) file_data->file_names[i]);
1756 if (file_data->real_names)
1757 xfree ((void*) file_data->real_names[i]);
1760 /* The space for the struct itself lives on objfile_obstack,
1761 so we don't free it here. */
1764 /* Create a quick_file_names hash table. */
1767 create_quick_file_names_table (unsigned int nr_initial_entries)
1769 return htab_create_alloc (nr_initial_entries,
1770 hash_file_name_entry, eq_file_name_entry,
1771 delete_file_name_entry, xcalloc, xfree);
1774 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1775 have to be created afterwards. You should call age_cached_comp_units after
1776 processing PER_CU->CU. dw2_setup must have been already called. */
1779 load_cu (struct dwarf2_per_cu_data *per_cu)
1781 if (per_cu->debug_types_section)
1782 load_full_type_unit (per_cu);
1784 load_full_comp_unit (per_cu);
1786 gdb_assert (per_cu->cu != NULL);
1788 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1791 /* Read in the symbols for PER_CU. */
1794 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1796 struct cleanup *back_to;
1798 back_to = make_cleanup (dwarf2_release_queue, NULL);
1800 queue_comp_unit (per_cu);
1806 /* Age the cache, releasing compilation units that have not
1807 been used recently. */
1808 age_cached_comp_units ();
1810 do_cleanups (back_to);
1813 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1814 the objfile from which this CU came. Returns the resulting symbol
1817 static struct symtab *
1818 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
1820 if (!per_cu->v.quick->symtab)
1822 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1823 increment_reading_symtab ();
1824 dw2_do_instantiate_symtab (per_cu);
1825 do_cleanups (back_to);
1827 return per_cu->v.quick->symtab;
1830 /* Return the CU given its index. */
1832 static struct dwarf2_per_cu_data *
1833 dw2_get_cu (int index)
1835 if (index >= dwarf2_per_objfile->n_comp_units)
1837 index -= dwarf2_per_objfile->n_comp_units;
1838 return dwarf2_per_objfile->all_type_units[index];
1840 return dwarf2_per_objfile->all_comp_units[index];
1843 /* A helper function that knows how to read a 64-bit value in a way
1844 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1848 extract_cu_value (const char *bytes, ULONGEST *result)
1850 if (sizeof (ULONGEST) < 8)
1854 /* Ignore the upper 4 bytes if they are all zero. */
1855 for (i = 0; i < 4; ++i)
1856 if (bytes[i + 4] != 0)
1859 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1862 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1866 /* Read the CU list from the mapped index, and use it to create all
1867 the CU objects for this objfile. Return 0 if something went wrong,
1868 1 if everything went ok. */
1871 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1872 offset_type cu_list_elements)
1876 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1877 dwarf2_per_objfile->all_comp_units
1878 = obstack_alloc (&objfile->objfile_obstack,
1879 dwarf2_per_objfile->n_comp_units
1880 * sizeof (struct dwarf2_per_cu_data *));
1882 for (i = 0; i < cu_list_elements; i += 2)
1884 struct dwarf2_per_cu_data *the_cu;
1885 ULONGEST offset, length;
1887 if (!extract_cu_value (cu_list, &offset)
1888 || !extract_cu_value (cu_list + 8, &length))
1892 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1893 struct dwarf2_per_cu_data);
1894 the_cu->offset = offset;
1895 the_cu->length = length;
1896 the_cu->objfile = objfile;
1897 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1898 struct dwarf2_per_cu_quick_data);
1899 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1905 /* Create the signatured type hash table from the index. */
1908 create_signatured_type_table_from_index (struct objfile *objfile,
1909 struct dwarf2_section_info *section,
1910 const gdb_byte *bytes,
1911 offset_type elements)
1914 htab_t sig_types_hash;
1916 dwarf2_per_objfile->n_type_units = elements / 3;
1917 dwarf2_per_objfile->all_type_units
1918 = obstack_alloc (&objfile->objfile_obstack,
1919 dwarf2_per_objfile->n_type_units
1920 * sizeof (struct dwarf2_per_cu_data *));
1922 sig_types_hash = allocate_signatured_type_table (objfile);
1924 for (i = 0; i < elements; i += 3)
1926 struct signatured_type *type_sig;
1927 ULONGEST offset, type_offset, signature;
1930 if (!extract_cu_value (bytes, &offset)
1931 || !extract_cu_value (bytes + 8, &type_offset))
1933 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1936 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1937 struct signatured_type);
1938 type_sig->signature = signature;
1939 type_sig->type_offset = type_offset;
1940 type_sig->per_cu.debug_types_section = section;
1941 type_sig->per_cu.offset = offset;
1942 type_sig->per_cu.objfile = objfile;
1943 type_sig->per_cu.v.quick
1944 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1945 struct dwarf2_per_cu_quick_data);
1947 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1950 dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu;
1953 dwarf2_per_objfile->signatured_types = sig_types_hash;
1958 /* Read the address map data from the mapped index, and use it to
1959 populate the objfile's psymtabs_addrmap. */
1962 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1964 const gdb_byte *iter, *end;
1965 struct obstack temp_obstack;
1966 struct addrmap *mutable_map;
1967 struct cleanup *cleanup;
1970 obstack_init (&temp_obstack);
1971 cleanup = make_cleanup_obstack_free (&temp_obstack);
1972 mutable_map = addrmap_create_mutable (&temp_obstack);
1974 iter = index->address_table;
1975 end = iter + index->address_table_size;
1977 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1981 ULONGEST hi, lo, cu_index;
1982 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1984 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1986 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1989 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1990 dw2_get_cu (cu_index));
1993 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1994 &objfile->objfile_obstack);
1995 do_cleanups (cleanup);
1998 /* The hash function for strings in the mapped index. This is the same as
1999 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2000 implementation. This is necessary because the hash function is tied to the
2001 format of the mapped index file. The hash values do not have to match with
2004 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2007 mapped_index_string_hash (int index_version, const void *p)
2009 const unsigned char *str = (const unsigned char *) p;
2013 while ((c = *str++) != 0)
2015 if (index_version >= 5)
2017 r = r * 67 + c - 113;
2023 /* Find a slot in the mapped index INDEX for the object named NAME.
2024 If NAME is found, set *VEC_OUT to point to the CU vector in the
2025 constant pool and return 1. If NAME cannot be found, return 0. */
2028 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2029 offset_type **vec_out)
2031 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2033 offset_type slot, step;
2034 int (*cmp) (const char *, const char *);
2036 if (current_language->la_language == language_cplus
2037 || current_language->la_language == language_java
2038 || current_language->la_language == language_fortran)
2040 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2042 const char *paren = strchr (name, '(');
2048 dup = xmalloc (paren - name + 1);
2049 memcpy (dup, name, paren - name);
2050 dup[paren - name] = 0;
2052 make_cleanup (xfree, dup);
2057 /* Index version 4 did not support case insensitive searches. But the
2058 indices for case insensitive languages are built in lowercase, therefore
2059 simulate our NAME being searched is also lowercased. */
2060 hash = mapped_index_string_hash ((index->version == 4
2061 && case_sensitivity == case_sensitive_off
2062 ? 5 : index->version),
2065 slot = hash & (index->symbol_table_slots - 1);
2066 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2067 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2071 /* Convert a slot number to an offset into the table. */
2072 offset_type i = 2 * slot;
2074 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2076 do_cleanups (back_to);
2080 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2081 if (!cmp (name, str))
2083 *vec_out = (offset_type *) (index->constant_pool
2084 + MAYBE_SWAP (index->symbol_table[i + 1]));
2085 do_cleanups (back_to);
2089 slot = (slot + step) & (index->symbol_table_slots - 1);
2093 /* Read the index file. If everything went ok, initialize the "quick"
2094 elements of all the CUs and return 1. Otherwise, return 0. */
2097 dwarf2_read_index (struct objfile *objfile)
2100 struct mapped_index *map;
2101 offset_type *metadata;
2102 const gdb_byte *cu_list;
2103 const gdb_byte *types_list = NULL;
2104 offset_type version, cu_list_elements;
2105 offset_type types_list_elements = 0;
2108 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2111 /* Older elfutils strip versions could keep the section in the main
2112 executable while splitting it for the separate debug info file. */
2113 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2114 & SEC_HAS_CONTENTS) == 0)
2117 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2119 addr = dwarf2_per_objfile->gdb_index.buffer;
2120 /* Version check. */
2121 version = MAYBE_SWAP (*(offset_type *) addr);
2122 /* Versions earlier than 3 emitted every copy of a psymbol. This
2123 causes the index to behave very poorly for certain requests. Version 3
2124 contained incomplete addrmap. So, it seems better to just ignore such
2128 static int warning_printed = 0;
2129 if (!warning_printed)
2131 warning (_("Skipping obsolete .gdb_index section in %s."),
2133 warning_printed = 1;
2137 /* Index version 4 uses a different hash function than index version
2140 Versions earlier than 6 did not emit psymbols for inlined
2141 functions. Using these files will cause GDB not to be able to
2142 set breakpoints on inlined functions by name, so we ignore these
2143 indices unless the --use-deprecated-index-sections command line
2144 option was supplied. */
2145 if (version < 6 && !use_deprecated_index_sections)
2147 static int warning_printed = 0;
2148 if (!warning_printed)
2150 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2151 "--use-deprecated-index-sections to use them anyway"),
2153 warning_printed = 1;
2157 /* Indexes with higher version than the one supported by GDB may be no
2158 longer backward compatible. */
2162 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2163 map->version = version;
2164 map->total_size = dwarf2_per_objfile->gdb_index.size;
2166 metadata = (offset_type *) (addr + sizeof (offset_type));
2169 cu_list = addr + MAYBE_SWAP (metadata[i]);
2170 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2174 types_list = addr + MAYBE_SWAP (metadata[i]);
2175 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2176 - MAYBE_SWAP (metadata[i]))
2180 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2181 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2182 - MAYBE_SWAP (metadata[i]));
2185 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2186 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2187 - MAYBE_SWAP (metadata[i]))
2188 / (2 * sizeof (offset_type)));
2191 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2193 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2196 if (types_list_elements)
2198 struct dwarf2_section_info *section;
2200 /* We can only handle a single .debug_types when we have an
2202 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2205 section = VEC_index (dwarf2_section_info_def,
2206 dwarf2_per_objfile->types, 0);
2208 if (!create_signatured_type_table_from_index (objfile, section,
2210 types_list_elements))
2214 create_addrmap_from_index (objfile, map);
2216 dwarf2_per_objfile->index_table = map;
2217 dwarf2_per_objfile->using_index = 1;
2218 dwarf2_per_objfile->quick_file_names_table =
2219 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2224 /* A helper for the "quick" functions which sets the global
2225 dwarf2_per_objfile according to OBJFILE. */
2228 dw2_setup (struct objfile *objfile)
2230 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2231 gdb_assert (dwarf2_per_objfile);
2234 /* A helper for the "quick" functions which attempts to read the line
2235 table for THIS_CU. */
2237 static struct quick_file_names *
2238 dw2_get_file_names (struct objfile *objfile,
2239 struct dwarf2_per_cu_data *this_cu)
2241 bfd *abfd = objfile->obfd;
2242 struct line_header *lh;
2243 struct attribute *attr;
2244 struct cleanup *cleanups;
2245 struct die_info *comp_unit_die;
2246 struct dwarf2_section_info* sec;
2248 int has_children, i;
2249 struct dwarf2_cu cu;
2250 unsigned int bytes_read;
2251 struct die_reader_specs reader_specs;
2252 char *name, *comp_dir;
2254 struct quick_file_names *qfn;
2255 unsigned int line_offset;
2257 if (this_cu->v.quick->file_names != NULL)
2258 return this_cu->v.quick->file_names;
2259 /* If we know there is no line data, no point in looking again. */
2260 if (this_cu->v.quick->no_file_data)
2263 init_one_comp_unit (&cu, this_cu);
2264 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2266 if (this_cu->debug_types_section)
2267 sec = this_cu->debug_types_section;
2269 sec = &dwarf2_per_objfile->info;
2270 dwarf2_read_section (objfile, sec);
2271 info_ptr = sec->buffer + this_cu->offset;
2273 info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr,
2274 this_cu->debug_types_section != NULL);
2276 /* Skip dummy compilation units. */
2277 if (info_ptr >= (sec->buffer + sec->size)
2278 || peek_abbrev_code (abfd, info_ptr) == 0)
2280 do_cleanups (cleanups);
2284 dwarf2_read_abbrevs (&cu);
2285 make_cleanup (dwarf2_free_abbrev_table, &cu);
2287 init_cu_die_reader (&reader_specs, &cu);
2288 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2294 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2297 struct quick_file_names find_entry;
2299 line_offset = DW_UNSND (attr);
2301 /* We may have already read in this line header (TU line header sharing).
2302 If we have we're done. */
2303 find_entry.offset = line_offset;
2304 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2305 &find_entry, INSERT);
2308 do_cleanups (cleanups);
2309 this_cu->v.quick->file_names = *slot;
2313 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2317 do_cleanups (cleanups);
2318 this_cu->v.quick->no_file_data = 1;
2322 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2323 qfn->offset = line_offset;
2324 gdb_assert (slot != NULL);
2327 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2329 qfn->num_file_names = lh->num_file_names;
2330 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2331 lh->num_file_names * sizeof (char *));
2332 for (i = 0; i < lh->num_file_names; ++i)
2333 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2334 qfn->real_names = NULL;
2336 free_line_header (lh);
2337 do_cleanups (cleanups);
2339 this_cu->v.quick->file_names = qfn;
2343 /* A helper for the "quick" functions which computes and caches the
2344 real path for a given file name from the line table. */
2347 dw2_get_real_path (struct objfile *objfile,
2348 struct quick_file_names *qfn, int index)
2350 if (qfn->real_names == NULL)
2351 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2352 qfn->num_file_names, sizeof (char *));
2354 if (qfn->real_names[index] == NULL)
2355 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2357 return qfn->real_names[index];
2360 static struct symtab *
2361 dw2_find_last_source_symtab (struct objfile *objfile)
2365 dw2_setup (objfile);
2366 index = dwarf2_per_objfile->n_comp_units - 1;
2367 return dw2_instantiate_symtab (dw2_get_cu (index));
2370 /* Traversal function for dw2_forget_cached_source_info. */
2373 dw2_free_cached_file_names (void **slot, void *info)
2375 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2377 if (file_data->real_names)
2381 for (i = 0; i < file_data->num_file_names; ++i)
2383 xfree ((void*) file_data->real_names[i]);
2384 file_data->real_names[i] = NULL;
2392 dw2_forget_cached_source_info (struct objfile *objfile)
2394 dw2_setup (objfile);
2396 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2397 dw2_free_cached_file_names, NULL);
2400 /* Helper function for dw2_map_symtabs_matching_filename that expands
2401 the symtabs and calls the iterator. */
2404 dw2_map_expand_apply (struct objfile *objfile,
2405 struct dwarf2_per_cu_data *per_cu,
2407 const char *full_path, const char *real_path,
2408 int (*callback) (struct symtab *, void *),
2411 struct symtab *last_made = objfile->symtabs;
2413 /* Don't visit already-expanded CUs. */
2414 if (per_cu->v.quick->symtab)
2417 /* This may expand more than one symtab, and we want to iterate over
2419 dw2_instantiate_symtab (per_cu);
2421 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
2422 objfile->symtabs, last_made);
2425 /* Implementation of the map_symtabs_matching_filename method. */
2428 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
2429 const char *full_path, const char *real_path,
2430 int (*callback) (struct symtab *, void *),
2434 const char *name_basename = lbasename (name);
2435 int name_len = strlen (name);
2436 int is_abs = IS_ABSOLUTE_PATH (name);
2438 dw2_setup (objfile);
2440 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2441 + dwarf2_per_objfile->n_type_units); ++i)
2444 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2445 struct quick_file_names *file_data;
2447 /* We only need to look at symtabs not already expanded. */
2448 if (per_cu->v.quick->symtab)
2451 file_data = dw2_get_file_names (objfile, per_cu);
2452 if (file_data == NULL)
2455 for (j = 0; j < file_data->num_file_names; ++j)
2457 const char *this_name = file_data->file_names[j];
2459 if (FILENAME_CMP (name, this_name) == 0
2460 || (!is_abs && compare_filenames_for_search (this_name,
2463 if (dw2_map_expand_apply (objfile, per_cu,
2464 name, full_path, real_path,
2469 /* Before we invoke realpath, which can get expensive when many
2470 files are involved, do a quick comparison of the basenames. */
2471 if (! basenames_may_differ
2472 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
2475 if (full_path != NULL)
2477 const char *this_real_name = dw2_get_real_path (objfile,
2480 if (this_real_name != NULL
2481 && (FILENAME_CMP (full_path, this_real_name) == 0
2483 && compare_filenames_for_search (this_real_name,
2486 if (dw2_map_expand_apply (objfile, per_cu,
2487 name, full_path, real_path,
2493 if (real_path != NULL)
2495 const char *this_real_name = dw2_get_real_path (objfile,
2498 if (this_real_name != NULL
2499 && (FILENAME_CMP (real_path, this_real_name) == 0
2501 && compare_filenames_for_search (this_real_name,
2504 if (dw2_map_expand_apply (objfile, per_cu,
2505 name, full_path, real_path,
2516 static struct symtab *
2517 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2518 const char *name, domain_enum domain)
2520 /* We do all the work in the pre_expand_symtabs_matching hook
2525 /* A helper function that expands all symtabs that hold an object
2529 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2531 dw2_setup (objfile);
2533 /* index_table is NULL if OBJF_READNOW. */
2534 if (dwarf2_per_objfile->index_table)
2538 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2541 offset_type i, len = MAYBE_SWAP (*vec);
2542 for (i = 0; i < len; ++i)
2544 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2545 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2547 dw2_instantiate_symtab (per_cu);
2554 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2555 enum block_enum block_kind, const char *name,
2558 dw2_do_expand_symtabs_matching (objfile, name);
2562 dw2_print_stats (struct objfile *objfile)
2566 dw2_setup (objfile);
2568 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2569 + dwarf2_per_objfile->n_type_units); ++i)
2571 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2573 if (!per_cu->v.quick->symtab)
2576 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2580 dw2_dump (struct objfile *objfile)
2582 /* Nothing worth printing. */
2586 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2587 struct section_offsets *delta)
2589 /* There's nothing to relocate here. */
2593 dw2_expand_symtabs_for_function (struct objfile *objfile,
2594 const char *func_name)
2596 dw2_do_expand_symtabs_matching (objfile, func_name);
2600 dw2_expand_all_symtabs (struct objfile *objfile)
2604 dw2_setup (objfile);
2606 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2607 + dwarf2_per_objfile->n_type_units); ++i)
2609 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2611 dw2_instantiate_symtab (per_cu);
2616 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2617 const char *filename)
2621 dw2_setup (objfile);
2623 /* We don't need to consider type units here.
2624 This is only called for examining code, e.g. expand_line_sal.
2625 There can be an order of magnitude (or more) more type units
2626 than comp units, and we avoid them if we can. */
2628 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2631 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2632 struct quick_file_names *file_data;
2634 /* We only need to look at symtabs not already expanded. */
2635 if (per_cu->v.quick->symtab)
2638 file_data = dw2_get_file_names (objfile, per_cu);
2639 if (file_data == NULL)
2642 for (j = 0; j < file_data->num_file_names; ++j)
2644 const char *this_name = file_data->file_names[j];
2645 if (FILENAME_CMP (this_name, filename) == 0)
2647 dw2_instantiate_symtab (per_cu);
2655 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2657 struct dwarf2_per_cu_data *per_cu;
2659 struct quick_file_names *file_data;
2661 dw2_setup (objfile);
2663 /* index_table is NULL if OBJF_READNOW. */
2664 if (!dwarf2_per_objfile->index_table)
2668 ALL_OBJFILE_SYMTABS (objfile, s)
2671 struct blockvector *bv = BLOCKVECTOR (s);
2672 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2673 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2676 return sym->symtab->filename;
2681 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2685 /* Note that this just looks at the very first one named NAME -- but
2686 actually we are looking for a function. find_main_filename
2687 should be rewritten so that it doesn't require a custom hook. It
2688 could just use the ordinary symbol tables. */
2689 /* vec[0] is the length, which must always be >0. */
2690 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2692 file_data = dw2_get_file_names (objfile, per_cu);
2693 if (file_data == NULL)
2696 return file_data->file_names[file_data->num_file_names - 1];
2700 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2701 struct objfile *objfile, int global,
2702 int (*callback) (struct block *,
2703 struct symbol *, void *),
2704 void *data, symbol_compare_ftype *match,
2705 symbol_compare_ftype *ordered_compare)
2707 /* Currently unimplemented; used for Ada. The function can be called if the
2708 current language is Ada for a non-Ada objfile using GNU index. As Ada
2709 does not look for non-Ada symbols this function should just return. */
2713 dw2_expand_symtabs_matching
2714 (struct objfile *objfile,
2715 int (*file_matcher) (const char *, void *),
2716 int (*name_matcher) (const char *, void *),
2717 enum search_domain kind,
2722 struct mapped_index *index;
2724 dw2_setup (objfile);
2726 /* index_table is NULL if OBJF_READNOW. */
2727 if (!dwarf2_per_objfile->index_table)
2729 index = dwarf2_per_objfile->index_table;
2731 if (file_matcher != NULL)
2733 struct cleanup *cleanup;
2734 htab_t visited_found, visited_not_found;
2736 visited_found = htab_create_alloc (10,
2737 htab_hash_pointer, htab_eq_pointer,
2738 NULL, xcalloc, xfree);
2739 cleanup = make_cleanup_htab_delete (visited_found);
2740 visited_not_found = htab_create_alloc (10,
2741 htab_hash_pointer, htab_eq_pointer,
2742 NULL, xcalloc, xfree);
2743 make_cleanup_htab_delete (visited_not_found);
2745 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2746 + dwarf2_per_objfile->n_type_units); ++i)
2749 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2750 struct quick_file_names *file_data;
2753 per_cu->v.quick->mark = 0;
2755 /* We only need to look at symtabs not already expanded. */
2756 if (per_cu->v.quick->symtab)
2759 file_data = dw2_get_file_names (objfile, per_cu);
2760 if (file_data == NULL)
2763 if (htab_find (visited_not_found, file_data) != NULL)
2765 else if (htab_find (visited_found, file_data) != NULL)
2767 per_cu->v.quick->mark = 1;
2771 for (j = 0; j < file_data->num_file_names; ++j)
2773 if (file_matcher (file_data->file_names[j], data))
2775 per_cu->v.quick->mark = 1;
2780 slot = htab_find_slot (per_cu->v.quick->mark
2782 : visited_not_found,
2787 do_cleanups (cleanup);
2790 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2792 offset_type idx = 2 * iter;
2794 offset_type *vec, vec_len, vec_idx;
2796 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2799 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2801 if (! (*name_matcher) (name, data))
2804 /* The name was matched, now expand corresponding CUs that were
2806 vec = (offset_type *) (index->constant_pool
2807 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2808 vec_len = MAYBE_SWAP (vec[0]);
2809 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2811 struct dwarf2_per_cu_data *per_cu;
2813 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2814 if (file_matcher == NULL || per_cu->v.quick->mark)
2815 dw2_instantiate_symtab (per_cu);
2820 static struct symtab *
2821 dw2_find_pc_sect_symtab (struct objfile *objfile,
2822 struct minimal_symbol *msymbol,
2824 struct obj_section *section,
2827 struct dwarf2_per_cu_data *data;
2829 dw2_setup (objfile);
2831 if (!objfile->psymtabs_addrmap)
2834 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2838 if (warn_if_readin && data->v.quick->symtab)
2839 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2840 paddress (get_objfile_arch (objfile), pc));
2842 return dw2_instantiate_symtab (data);
2846 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2847 void *data, int need_fullname)
2850 struct cleanup *cleanup;
2851 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
2852 NULL, xcalloc, xfree);
2854 cleanup = make_cleanup_htab_delete (visited);
2855 dw2_setup (objfile);
2857 /* We can ignore file names coming from already-expanded CUs. */
2858 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2859 + dwarf2_per_objfile->n_type_units); ++i)
2861 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2863 if (per_cu->v.quick->symtab)
2865 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
2868 *slot = per_cu->v.quick->file_names;
2872 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2873 + dwarf2_per_objfile->n_type_units); ++i)
2876 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2877 struct quick_file_names *file_data;
2880 /* We only need to look at symtabs not already expanded. */
2881 if (per_cu->v.quick->symtab)
2884 file_data = dw2_get_file_names (objfile, per_cu);
2885 if (file_data == NULL)
2888 slot = htab_find_slot (visited, file_data, INSERT);
2891 /* Already visited. */
2896 for (j = 0; j < file_data->num_file_names; ++j)
2898 const char *this_real_name;
2901 this_real_name = dw2_get_real_path (objfile, file_data, j);
2903 this_real_name = NULL;
2904 (*fun) (file_data->file_names[j], this_real_name, data);
2908 do_cleanups (cleanup);
2912 dw2_has_symbols (struct objfile *objfile)
2917 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2920 dw2_find_last_source_symtab,
2921 dw2_forget_cached_source_info,
2922 dw2_map_symtabs_matching_filename,
2924 dw2_pre_expand_symtabs_matching,
2928 dw2_expand_symtabs_for_function,
2929 dw2_expand_all_symtabs,
2930 dw2_expand_symtabs_with_filename,
2931 dw2_find_symbol_file,
2932 dw2_map_matching_symbols,
2933 dw2_expand_symtabs_matching,
2934 dw2_find_pc_sect_symtab,
2935 dw2_map_symbol_filenames
2938 /* Initialize for reading DWARF for this objfile. Return 0 if this
2939 file will use psymtabs, or 1 if using the GNU index. */
2942 dwarf2_initialize_objfile (struct objfile *objfile)
2944 /* If we're about to read full symbols, don't bother with the
2945 indices. In this case we also don't care if some other debug
2946 format is making psymtabs, because they are all about to be
2948 if ((objfile->flags & OBJF_READNOW))
2952 dwarf2_per_objfile->using_index = 1;
2953 create_all_comp_units (objfile);
2954 create_debug_types_hash_table (objfile);
2955 dwarf2_per_objfile->quick_file_names_table =
2956 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2958 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2959 + dwarf2_per_objfile->n_type_units); ++i)
2961 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2963 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2964 struct dwarf2_per_cu_quick_data);
2967 /* Return 1 so that gdb sees the "quick" functions. However,
2968 these functions will be no-ops because we will have expanded
2973 if (dwarf2_read_index (objfile))
2981 /* Build a partial symbol table. */
2984 dwarf2_build_psymtabs (struct objfile *objfile)
2986 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2988 init_psymbol_list (objfile, 1024);
2991 dwarf2_build_psymtabs_hard (objfile);
2994 /* Return TRUE if OFFSET is within CU_HEADER. */
2997 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2999 unsigned int bottom = cu_header->offset;
3000 unsigned int top = (cu_header->offset
3002 + cu_header->initial_length_size);
3004 return (offset >= bottom && offset < top);
3007 /* Read in the comp unit header information from the debug_info at info_ptr.
3008 NOTE: This leaves members offset, first_die_offset to be filled in
3012 read_comp_unit_head (struct comp_unit_head *cu_header,
3013 gdb_byte *info_ptr, bfd *abfd)
3016 unsigned int bytes_read;
3018 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3019 cu_header->initial_length_size = bytes_read;
3020 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3021 info_ptr += bytes_read;
3022 cu_header->version = read_2_bytes (abfd, info_ptr);
3024 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
3026 info_ptr += bytes_read;
3027 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3029 signed_addr = bfd_get_sign_extend_vma (abfd);
3030 if (signed_addr < 0)
3031 internal_error (__FILE__, __LINE__,
3032 _("read_comp_unit_head: dwarf from non elf file"));
3033 cu_header->signed_addr_p = signed_addr;
3038 /* Subroutine of read_and_check_comp_unit_head and
3039 read_and_check_type_unit_head to simplify them.
3040 Perform various error checking on the header. */
3043 error_check_comp_unit_head (struct comp_unit_head *header,
3044 struct dwarf2_section_info *section)
3046 bfd *abfd = section->asection->owner;
3047 const char *filename = bfd_get_filename (abfd);
3049 if (header->version != 2 && header->version != 3 && header->version != 4)
3050 error (_("Dwarf Error: wrong version in compilation unit header "
3051 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3054 if (header->abbrev_offset
3055 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
3056 &dwarf2_per_objfile->abbrev))
3057 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3058 "(offset 0x%lx + 6) [in module %s]"),
3059 (long) header->abbrev_offset, (long) header->offset,
3062 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3063 avoid potential 32-bit overflow. */
3064 if (((unsigned long) header->offset
3065 + header->length + header->initial_length_size)
3067 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3068 "(offset 0x%lx + 0) [in module %s]"),
3069 (long) header->length, (long) header->offset,
3073 /* Read in a CU/TU header and perform some basic error checking.
3074 The contents of the header are stored in HEADER.
3075 The result is a pointer to the start of the first DIE. */
3078 read_and_check_comp_unit_head (struct comp_unit_head *header,
3079 struct dwarf2_section_info *section,
3081 int is_debug_types_section)
3083 gdb_byte *beg_of_comp_unit = info_ptr;
3084 bfd *abfd = section->asection->owner;
3086 header->offset = beg_of_comp_unit - section->buffer;
3088 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3090 /* If we're reading a type unit, skip over the signature and
3091 type_offset fields. */
3092 if (is_debug_types_section)
3093 info_ptr += 8 /*signature*/ + header->offset_size;
3095 header->first_die_offset = info_ptr - beg_of_comp_unit;
3097 error_check_comp_unit_head (header, section);
3102 /* Read in the types comp unit header information from .debug_types entry at
3103 types_ptr. The result is a pointer to one past the end of the header. */
3106 read_and_check_type_unit_head (struct comp_unit_head *header,
3107 struct dwarf2_section_info *section,
3109 ULONGEST *signature, unsigned int *type_offset)
3111 gdb_byte *beg_of_comp_unit = info_ptr;
3112 bfd *abfd = section->asection->owner;
3114 header->offset = beg_of_comp_unit - section->buffer;
3116 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3118 /* If we're reading a type unit, skip over the signature and
3119 type_offset fields. */
3120 if (signature != NULL)
3121 *signature = read_8_bytes (abfd, info_ptr);
3123 if (type_offset != NULL)
3124 *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size);
3125 info_ptr += header->offset_size;
3127 header->first_die_offset = info_ptr - beg_of_comp_unit;
3129 error_check_comp_unit_head (header, section);
3134 /* Allocate a new partial symtab for file named NAME and mark this new
3135 partial symtab as being an include of PST. */
3138 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3139 struct objfile *objfile)
3141 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3143 subpst->section_offsets = pst->section_offsets;
3144 subpst->textlow = 0;
3145 subpst->texthigh = 0;
3147 subpst->dependencies = (struct partial_symtab **)
3148 obstack_alloc (&objfile->objfile_obstack,
3149 sizeof (struct partial_symtab *));
3150 subpst->dependencies[0] = pst;
3151 subpst->number_of_dependencies = 1;
3153 subpst->globals_offset = 0;
3154 subpst->n_global_syms = 0;
3155 subpst->statics_offset = 0;
3156 subpst->n_static_syms = 0;
3157 subpst->symtab = NULL;
3158 subpst->read_symtab = pst->read_symtab;
3161 /* No private part is necessary for include psymtabs. This property
3162 can be used to differentiate between such include psymtabs and
3163 the regular ones. */
3164 subpst->read_symtab_private = NULL;
3167 /* Read the Line Number Program data and extract the list of files
3168 included by the source file represented by PST. Build an include
3169 partial symtab for each of these included files. */
3172 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3173 struct die_info *die,
3174 struct partial_symtab *pst)
3176 struct objfile *objfile = cu->objfile;
3177 bfd *abfd = objfile->obfd;
3178 struct line_header *lh = NULL;
3179 struct attribute *attr;
3181 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3184 unsigned int line_offset = DW_UNSND (attr);
3186 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3189 return; /* No linetable, so no includes. */
3191 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3192 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
3194 free_line_header (lh);
3198 hash_type_signature (const void *item)
3200 const struct signatured_type *type_sig = item;
3202 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3203 return type_sig->signature;
3207 eq_type_signature (const void *item_lhs, const void *item_rhs)
3209 const struct signatured_type *lhs = item_lhs;
3210 const struct signatured_type *rhs = item_rhs;
3212 return lhs->signature == rhs->signature;
3215 /* Allocate a hash table for signatured types. */
3218 allocate_signatured_type_table (struct objfile *objfile)
3220 return htab_create_alloc_ex (41,
3221 hash_type_signature,
3224 &objfile->objfile_obstack,
3225 hashtab_obstack_allocate,
3226 dummy_obstack_deallocate);
3229 /* A helper function to add a signatured type CU to a table. */
3232 add_signatured_type_cu_to_table (void **slot, void *datum)
3234 struct signatured_type *sigt = *slot;
3235 struct dwarf2_per_cu_data ***datap = datum;
3237 **datap = &sigt->per_cu;
3243 /* Create the hash table of all entries in the .debug_types section(s).
3244 The result is zero if there is an error (e.g. missing .debug_types section),
3245 otherwise non-zero. */
3248 create_debug_types_hash_table (struct objfile *objfile)
3250 htab_t types_htab = NULL;
3251 struct dwarf2_per_cu_data **iter;
3253 struct dwarf2_section_info *section;
3255 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3257 dwarf2_per_objfile->signatured_types = NULL;
3262 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3266 gdb_byte *info_ptr, *end_ptr;
3268 dwarf2_read_section (objfile, section);
3269 info_ptr = section->buffer;
3271 if (info_ptr == NULL)
3274 if (types_htab == NULL)
3275 types_htab = allocate_signatured_type_table (objfile);
3277 if (dwarf2_die_debug)
3278 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3280 end_ptr = info_ptr + section->size;
3281 while (info_ptr < end_ptr)
3283 unsigned int offset;
3284 unsigned int type_offset;
3286 struct signatured_type *type_sig;
3288 gdb_byte *ptr = info_ptr;
3289 struct comp_unit_head header;
3291 offset = ptr - section->buffer;
3293 /* We need to read the type's signature in order to build the hash
3294 table, but we don't need anything else just yet. */
3296 ptr = read_and_check_type_unit_head (&header, section, ptr,
3297 &signature, &type_offset);
3299 /* Skip dummy type units. */
3300 if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
3302 info_ptr = info_ptr + header.initial_length_size + header.length;
3306 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3307 memset (type_sig, 0, sizeof (*type_sig));
3308 type_sig->signature = signature;
3309 type_sig->type_offset = type_offset;
3310 type_sig->per_cu.objfile = objfile;
3311 type_sig->per_cu.debug_types_section = section;
3312 type_sig->per_cu.offset = offset;
3314 slot = htab_find_slot (types_htab, type_sig, INSERT);
3315 gdb_assert (slot != NULL);
3318 const struct signatured_type *dup_sig = *slot;
3320 complaint (&symfile_complaints,
3321 _("debug type entry at offset 0x%x is duplicate to the "
3322 "entry at offset 0x%x, signature 0x%s"),
3323 offset, dup_sig->per_cu.offset,
3324 phex (signature, sizeof (signature)));
3325 gdb_assert (signature == dup_sig->signature);
3329 if (dwarf2_die_debug)
3330 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3331 offset, phex (signature, sizeof (signature)));
3333 info_ptr = info_ptr + header.initial_length_size + header.length;
3337 dwarf2_per_objfile->signatured_types = types_htab;
3339 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
3340 dwarf2_per_objfile->all_type_units
3341 = obstack_alloc (&objfile->objfile_obstack,
3342 dwarf2_per_objfile->n_type_units
3343 * sizeof (struct dwarf2_per_cu_data *));
3344 iter = &dwarf2_per_objfile->all_type_units[0];
3345 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
3346 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
3347 == dwarf2_per_objfile->n_type_units);
3352 /* Lookup a signature based type.
3353 Returns NULL if SIG is not present in the table. */
3355 static struct signatured_type *
3356 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3358 struct signatured_type find_entry, *entry;
3360 if (dwarf2_per_objfile->signatured_types == NULL)
3362 complaint (&symfile_complaints,
3363 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3367 find_entry.signature = sig;
3368 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3372 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3375 init_cu_die_reader (struct die_reader_specs *reader,
3376 struct dwarf2_cu *cu)
3378 reader->abfd = cu->objfile->obfd;
3380 if (cu->per_cu->debug_types_section)
3382 gdb_assert (cu->per_cu->debug_types_section->readin);
3383 reader->buffer = cu->per_cu->debug_types_section->buffer;
3387 gdb_assert (dwarf2_per_objfile->info.readin);
3388 reader->buffer = dwarf2_per_objfile->info.buffer;
3392 /* Find the base address of the compilation unit for range lists and
3393 location lists. It will normally be specified by DW_AT_low_pc.
3394 In DWARF-3 draft 4, the base address could be overridden by
3395 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3396 compilation units with discontinuous ranges. */
3399 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3401 struct attribute *attr;
3404 cu->base_address = 0;
3406 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3409 cu->base_address = DW_ADDR (attr);
3414 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3417 cu->base_address = DW_ADDR (attr);
3423 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3424 to combine the common parts.
3425 Process compilation unit THIS_CU for a psymtab.
3426 SECTION is the section the CU/TU comes from,
3427 either .debug_info or .debug_types. */
3430 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
3431 struct dwarf2_section_info *section,
3432 int is_debug_types_section)
3434 struct objfile *objfile = this_cu->objfile;
3435 bfd *abfd = objfile->obfd;
3436 gdb_byte *buffer = section->buffer;
3437 gdb_byte *info_ptr = buffer + this_cu->offset;
3438 unsigned int buffer_size = section->size;
3439 gdb_byte *beg_of_comp_unit = info_ptr;
3440 struct die_info *comp_unit_die;
3441 struct partial_symtab *pst;
3443 struct cleanup *back_to_inner;
3444 struct dwarf2_cu cu;
3445 int has_children, has_pc_info;
3446 struct attribute *attr;
3447 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3448 struct die_reader_specs reader_specs;
3449 const char *filename;
3451 /* If this compilation unit was already read in, free the
3452 cached copy in order to read it in again. This is
3453 necessary because we skipped some symbols when we first
3454 read in the compilation unit (see load_partial_dies).
3455 This problem could be avoided, but the benefit is
3457 if (this_cu->cu != NULL)
3458 free_one_cached_comp_unit (this_cu->cu);
3460 /* Note that this is a pointer to our stack frame, being
3461 added to a global data structure. It will be cleaned up
3462 in free_stack_comp_unit when we finish with this
3463 compilation unit. */
3464 init_one_comp_unit (&cu, this_cu);
3465 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3467 info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr,
3468 is_debug_types_section);
3470 /* Skip dummy compilation units. */
3471 if (info_ptr >= buffer + buffer_size
3472 || peek_abbrev_code (abfd, info_ptr) == 0)
3474 do_cleanups (back_to_inner);
3478 cu.list_in_scope = &file_symbols;
3480 /* Read the abbrevs for this compilation unit into a table. */
3481 dwarf2_read_abbrevs (&cu);
3482 make_cleanup (dwarf2_free_abbrev_table, &cu);
3484 /* Read the compilation unit die. */
3485 init_cu_die_reader (&reader_specs, &cu);
3486 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3489 if (is_debug_types_section)
3491 /* LENGTH has not been set yet for type units. */
3492 gdb_assert (this_cu->offset == cu.header.offset);
3493 this_cu->length = cu.header.length + cu.header.initial_length_size;
3495 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3497 do_cleanups (back_to_inner);
3501 prepare_one_comp_unit (&cu, comp_unit_die);
3503 /* Allocate a new partial symbol table structure. */
3504 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3505 if (attr == NULL || !DW_STRING (attr))
3508 filename = DW_STRING (attr);
3509 pst = start_psymtab_common (objfile, objfile->section_offsets,
3511 /* TEXTLOW and TEXTHIGH are set below. */
3513 objfile->global_psymbols.next,
3514 objfile->static_psymbols.next);
3515 pst->psymtabs_addrmap_supported = 1;
3517 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3519 pst->dirname = DW_STRING (attr);
3521 pst->read_symtab_private = this_cu;
3523 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3525 /* Store the function that reads in the rest of the symbol table. */
3526 pst->read_symtab = dwarf2_psymtab_to_symtab;
3528 this_cu->v.psymtab = pst;
3530 dwarf2_find_base_address (comp_unit_die, &cu);
3532 /* Possibly set the default values of LOWPC and HIGHPC from
3534 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3535 &best_highpc, &cu, pst);
3536 if (has_pc_info == 1 && best_lowpc < best_highpc)
3537 /* Store the contiguous range if it is not empty; it can be empty for
3538 CUs with no code. */
3539 addrmap_set_empty (objfile->psymtabs_addrmap,
3540 best_lowpc + baseaddr,
3541 best_highpc + baseaddr - 1, pst);
3543 /* Check if comp unit has_children.
3544 If so, read the rest of the partial symbols from this comp unit.
3545 If not, there's no more debug_info for this comp unit. */
3548 struct partial_die_info *first_die;
3549 CORE_ADDR lowpc, highpc;
3551 lowpc = ((CORE_ADDR) -1);
3552 highpc = ((CORE_ADDR) 0);
3554 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3556 scan_partial_symbols (first_die, &lowpc, &highpc,
3557 ! has_pc_info, &cu);
3559 /* If we didn't find a lowpc, set it to highpc to avoid
3560 complaints from `maint check'. */
3561 if (lowpc == ((CORE_ADDR) -1))
3564 /* If the compilation unit didn't have an explicit address range,
3565 then use the information extracted from its child dies. */
3569 best_highpc = highpc;
3572 pst->textlow = best_lowpc + baseaddr;
3573 pst->texthigh = best_highpc + baseaddr;
3575 pst->n_global_syms = objfile->global_psymbols.next -
3576 (objfile->global_psymbols.list + pst->globals_offset);
3577 pst->n_static_syms = objfile->static_psymbols.next -
3578 (objfile->static_psymbols.list + pst->statics_offset);
3579 sort_pst_symbols (pst);
3581 if (is_debug_types_section)
3583 /* It's not clear we want to do anything with stmt lists here.
3584 Waiting to see what gcc ultimately does. */
3588 /* Get the list of files included in the current compilation unit,
3589 and build a psymtab for each of them. */
3590 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3593 do_cleanups (back_to_inner);
3596 /* Traversal function for htab_traverse_noresize.
3597 Process one .debug_types comp-unit. */
3600 process_type_comp_unit (void **slot, void *info)
3602 struct signatured_type *entry = (struct signatured_type *) *slot;
3603 struct dwarf2_per_cu_data *this_cu;
3605 gdb_assert (info == NULL);
3606 this_cu = &entry->per_cu;
3608 gdb_assert (this_cu->debug_types_section->readin);
3609 process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1);
3614 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3615 Build partial symbol tables for the .debug_types comp-units. */
3618 build_type_psymtabs (struct objfile *objfile)
3620 if (! create_debug_types_hash_table (objfile))
3623 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3624 process_type_comp_unit, NULL);
3627 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3630 psymtabs_addrmap_cleanup (void *o)
3632 struct objfile *objfile = o;
3634 objfile->psymtabs_addrmap = NULL;
3637 /* Build the partial symbol table by doing a quick pass through the
3638 .debug_info and .debug_abbrev sections. */
3641 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3643 struct cleanup *back_to, *addrmap_cleanup;
3644 struct obstack temp_obstack;
3647 dwarf2_per_objfile->reading_partial_symbols = 1;
3649 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3651 /* Any cached compilation units will be linked by the per-objfile
3652 read_in_chain. Make sure to free them when we're done. */
3653 back_to = make_cleanup (free_cached_comp_units, NULL);
3655 build_type_psymtabs (objfile);
3657 create_all_comp_units (objfile);
3659 /* Create a temporary address map on a temporary obstack. We later
3660 copy this to the final obstack. */
3661 obstack_init (&temp_obstack);
3662 make_cleanup_obstack_free (&temp_obstack);
3663 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3664 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3666 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3668 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3670 process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0);
3673 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3674 &objfile->objfile_obstack);
3675 discard_cleanups (addrmap_cleanup);
3677 do_cleanups (back_to);
3680 /* Load the partial DIEs for a secondary CU into memory. */
3683 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
3685 struct objfile *objfile = this_cu->objfile;
3686 bfd *abfd = objfile->obfd;
3688 struct die_info *comp_unit_die;
3689 struct dwarf2_cu *cu;
3690 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3692 struct die_reader_specs reader_specs;
3694 struct dwarf2_section_info *section = &dwarf2_per_objfile->info;
3696 gdb_assert (! this_cu->debug_types_section);
3698 gdb_assert (section->readin);
3699 info_ptr = section->buffer + this_cu->offset;
3701 if (this_cu->cu == NULL)
3703 cu = xmalloc (sizeof (*cu));
3704 init_one_comp_unit (cu, this_cu);
3708 /* If an error occurs while loading, release our storage. */
3709 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
3711 info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr,
3714 /* Skip dummy compilation units. */
3715 if (info_ptr >= (section->buffer + section->size)
3716 || peek_abbrev_code (abfd, info_ptr) == 0)
3718 do_cleanups (free_cu_cleanup);
3725 info_ptr += cu->header.first_die_offset;
3728 /* Read the abbrevs for this compilation unit into a table. */
3729 gdb_assert (cu->dwarf2_abbrevs == NULL);
3730 dwarf2_read_abbrevs (cu);
3731 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3733 /* Read the compilation unit die. */
3734 init_cu_die_reader (&reader_specs, cu);
3735 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3738 prepare_one_comp_unit (cu, comp_unit_die);
3740 /* Check if comp unit has_children.
3741 If so, read the rest of the partial symbols from this comp unit.
3742 If not, there's no more debug_info for this comp unit. */
3744 load_partial_dies (abfd, section->buffer, info_ptr, 0, cu);
3746 do_cleanups (free_abbrevs_cleanup);
3750 /* We've successfully allocated this compilation unit. Let our
3751 caller clean it up when finished with it. */
3752 discard_cleanups (free_cu_cleanup);
3754 /* Link this CU into read_in_chain. */
3755 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3756 dwarf2_per_objfile->read_in_chain = this_cu;
3760 /* Create a list of all compilation units in OBJFILE.
3761 This is only done for -readnow and building partial symtabs. */
3764 create_all_comp_units (struct objfile *objfile)
3768 struct dwarf2_per_cu_data **all_comp_units;
3771 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3772 info_ptr = dwarf2_per_objfile->info.buffer;
3776 all_comp_units = xmalloc (n_allocated
3777 * sizeof (struct dwarf2_per_cu_data *));
3779 while (info_ptr < dwarf2_per_objfile->info.buffer
3780 + dwarf2_per_objfile->info.size)
3782 unsigned int length, initial_length_size;
3783 struct dwarf2_per_cu_data *this_cu;
3784 unsigned int offset;
3786 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3788 /* Read just enough information to find out where the next
3789 compilation unit is. */
3790 length = read_initial_length (objfile->obfd, info_ptr,
3791 &initial_length_size);
3793 /* Save the compilation unit for later lookup. */
3794 this_cu = obstack_alloc (&objfile->objfile_obstack,
3795 sizeof (struct dwarf2_per_cu_data));
3796 memset (this_cu, 0, sizeof (*this_cu));
3797 this_cu->offset = offset;
3798 this_cu->length = length + initial_length_size;
3799 this_cu->objfile = objfile;
3801 if (n_comp_units == n_allocated)
3804 all_comp_units = xrealloc (all_comp_units,
3806 * sizeof (struct dwarf2_per_cu_data *));
3808 all_comp_units[n_comp_units++] = this_cu;
3810 info_ptr = info_ptr + this_cu->length;
3813 dwarf2_per_objfile->all_comp_units
3814 = obstack_alloc (&objfile->objfile_obstack,
3815 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3816 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3817 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3818 xfree (all_comp_units);
3819 dwarf2_per_objfile->n_comp_units = n_comp_units;
3822 /* Process all loaded DIEs for compilation unit CU, starting at
3823 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3824 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3825 DW_AT_ranges). If NEED_PC is set, then this function will set
3826 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3827 and record the covered ranges in the addrmap. */
3830 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3831 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3833 struct partial_die_info *pdi;
3835 /* Now, march along the PDI's, descending into ones which have
3836 interesting children but skipping the children of the other ones,
3837 until we reach the end of the compilation unit. */
3843 fixup_partial_die (pdi, cu);
3845 /* Anonymous namespaces or modules have no name but have interesting
3846 children, so we need to look at them. Ditto for anonymous
3849 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3850 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3854 case DW_TAG_subprogram:
3855 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3857 case DW_TAG_constant:
3858 case DW_TAG_variable:
3859 case DW_TAG_typedef:
3860 case DW_TAG_union_type:
3861 if (!pdi->is_declaration)
3863 add_partial_symbol (pdi, cu);
3866 case DW_TAG_class_type:
3867 case DW_TAG_interface_type:
3868 case DW_TAG_structure_type:
3869 if (!pdi->is_declaration)
3871 add_partial_symbol (pdi, cu);
3874 case DW_TAG_enumeration_type:
3875 if (!pdi->is_declaration)
3876 add_partial_enumeration (pdi, cu);
3878 case DW_TAG_base_type:
3879 case DW_TAG_subrange_type:
3880 /* File scope base type definitions are added to the partial
3882 add_partial_symbol (pdi, cu);
3884 case DW_TAG_namespace:
3885 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3888 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3895 /* If the die has a sibling, skip to the sibling. */
3897 pdi = pdi->die_sibling;
3901 /* Functions used to compute the fully scoped name of a partial DIE.
3903 Normally, this is simple. For C++, the parent DIE's fully scoped
3904 name is concatenated with "::" and the partial DIE's name. For
3905 Java, the same thing occurs except that "." is used instead of "::".
3906 Enumerators are an exception; they use the scope of their parent
3907 enumeration type, i.e. the name of the enumeration type is not
3908 prepended to the enumerator.
3910 There are two complexities. One is DW_AT_specification; in this
3911 case "parent" means the parent of the target of the specification,
3912 instead of the direct parent of the DIE. The other is compilers
3913 which do not emit DW_TAG_namespace; in this case we try to guess
3914 the fully qualified name of structure types from their members'
3915 linkage names. This must be done using the DIE's children rather
3916 than the children of any DW_AT_specification target. We only need
3917 to do this for structures at the top level, i.e. if the target of
3918 any DW_AT_specification (if any; otherwise the DIE itself) does not
3921 /* Compute the scope prefix associated with PDI's parent, in
3922 compilation unit CU. The result will be allocated on CU's
3923 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3924 field. NULL is returned if no prefix is necessary. */
3926 partial_die_parent_scope (struct partial_die_info *pdi,
3927 struct dwarf2_cu *cu)
3929 char *grandparent_scope;
3930 struct partial_die_info *parent, *real_pdi;
3932 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3933 then this means the parent of the specification DIE. */
3936 while (real_pdi->has_specification)
3937 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3939 parent = real_pdi->die_parent;
3943 if (parent->scope_set)
3944 return parent->scope;
3946 fixup_partial_die (parent, cu);
3948 grandparent_scope = partial_die_parent_scope (parent, cu);
3950 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3951 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3952 Work around this problem here. */
3953 if (cu->language == language_cplus
3954 && parent->tag == DW_TAG_namespace
3955 && strcmp (parent->name, "::") == 0
3956 && grandparent_scope == NULL)
3958 parent->scope = NULL;
3959 parent->scope_set = 1;
3963 if (pdi->tag == DW_TAG_enumerator)
3964 /* Enumerators should not get the name of the enumeration as a prefix. */
3965 parent->scope = grandparent_scope;
3966 else if (parent->tag == DW_TAG_namespace
3967 || parent->tag == DW_TAG_module
3968 || parent->tag == DW_TAG_structure_type
3969 || parent->tag == DW_TAG_class_type
3970 || parent->tag == DW_TAG_interface_type
3971 || parent->tag == DW_TAG_union_type
3972 || parent->tag == DW_TAG_enumeration_type)
3974 if (grandparent_scope == NULL)
3975 parent->scope = parent->name;
3977 parent->scope = typename_concat (&cu->comp_unit_obstack,
3979 parent->name, 0, cu);
3983 /* FIXME drow/2004-04-01: What should we be doing with
3984 function-local names? For partial symbols, we should probably be
3986 complaint (&symfile_complaints,
3987 _("unhandled containing DIE tag %d for DIE at %d"),
3988 parent->tag, pdi->offset);
3989 parent->scope = grandparent_scope;
3992 parent->scope_set = 1;
3993 return parent->scope;
3996 /* Return the fully scoped name associated with PDI, from compilation unit
3997 CU. The result will be allocated with malloc. */
3999 partial_die_full_name (struct partial_die_info *pdi,
4000 struct dwarf2_cu *cu)
4004 /* If this is a template instantiation, we can not work out the
4005 template arguments from partial DIEs. So, unfortunately, we have
4006 to go through the full DIEs. At least any work we do building
4007 types here will be reused if full symbols are loaded later. */
4008 if (pdi->has_template_arguments)
4010 fixup_partial_die (pdi, cu);
4012 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
4014 struct die_info *die;
4015 struct attribute attr;
4016 struct dwarf2_cu *ref_cu = cu;
4019 attr.form = DW_FORM_ref_addr;
4020 attr.u.addr = pdi->offset;
4021 die = follow_die_ref (NULL, &attr, &ref_cu);
4023 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
4027 parent_scope = partial_die_parent_scope (pdi, cu);
4028 if (parent_scope == NULL)
4031 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
4035 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
4037 struct objfile *objfile = cu->objfile;
4039 char *actual_name = NULL;
4041 int built_actual_name = 0;
4043 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4045 actual_name = partial_die_full_name (pdi, cu);
4047 built_actual_name = 1;
4049 if (actual_name == NULL)
4050 actual_name = pdi->name;
4054 case DW_TAG_subprogram:
4055 if (pdi->is_external || cu->language == language_ada)
4057 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4058 of the global scope. But in Ada, we want to be able to access
4059 nested procedures globally. So all Ada subprograms are stored
4060 in the global scope. */
4061 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4062 mst_text, objfile); */
4063 add_psymbol_to_list (actual_name, strlen (actual_name),
4065 VAR_DOMAIN, LOC_BLOCK,
4066 &objfile->global_psymbols,
4067 0, pdi->lowpc + baseaddr,
4068 cu->language, objfile);
4072 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4073 mst_file_text, objfile); */
4074 add_psymbol_to_list (actual_name, strlen (actual_name),
4076 VAR_DOMAIN, LOC_BLOCK,
4077 &objfile->static_psymbols,
4078 0, pdi->lowpc + baseaddr,
4079 cu->language, objfile);
4082 case DW_TAG_constant:
4084 struct psymbol_allocation_list *list;
4086 if (pdi->is_external)
4087 list = &objfile->global_psymbols;
4089 list = &objfile->static_psymbols;
4090 add_psymbol_to_list (actual_name, strlen (actual_name),
4091 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4092 list, 0, 0, cu->language, objfile);
4095 case DW_TAG_variable:
4097 addr = decode_locdesc (pdi->locdesc, cu);
4101 && !dwarf2_per_objfile->has_section_at_zero)
4103 /* A global or static variable may also have been stripped
4104 out by the linker if unused, in which case its address
4105 will be nullified; do not add such variables into partial
4106 symbol table then. */
4108 else if (pdi->is_external)
4111 Don't enter into the minimal symbol tables as there is
4112 a minimal symbol table entry from the ELF symbols already.
4113 Enter into partial symbol table if it has a location
4114 descriptor or a type.
4115 If the location descriptor is missing, new_symbol will create
4116 a LOC_UNRESOLVED symbol, the address of the variable will then
4117 be determined from the minimal symbol table whenever the variable
4119 The address for the partial symbol table entry is not
4120 used by GDB, but it comes in handy for debugging partial symbol
4123 if (pdi->locdesc || pdi->has_type)
4124 add_psymbol_to_list (actual_name, strlen (actual_name),
4126 VAR_DOMAIN, LOC_STATIC,
4127 &objfile->global_psymbols,
4129 cu->language, objfile);
4133 /* Static Variable. Skip symbols without location descriptors. */
4134 if (pdi->locdesc == NULL)
4136 if (built_actual_name)
4137 xfree (actual_name);
4140 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4141 mst_file_data, objfile); */
4142 add_psymbol_to_list (actual_name, strlen (actual_name),
4144 VAR_DOMAIN, LOC_STATIC,
4145 &objfile->static_psymbols,
4147 cu->language, objfile);
4150 case DW_TAG_typedef:
4151 case DW_TAG_base_type:
4152 case DW_TAG_subrange_type:
4153 add_psymbol_to_list (actual_name, strlen (actual_name),
4155 VAR_DOMAIN, LOC_TYPEDEF,
4156 &objfile->static_psymbols,
4157 0, (CORE_ADDR) 0, cu->language, objfile);
4159 case DW_TAG_namespace:
4160 add_psymbol_to_list (actual_name, strlen (actual_name),
4162 VAR_DOMAIN, LOC_TYPEDEF,
4163 &objfile->global_psymbols,
4164 0, (CORE_ADDR) 0, cu->language, objfile);
4166 case DW_TAG_class_type:
4167 case DW_TAG_interface_type:
4168 case DW_TAG_structure_type:
4169 case DW_TAG_union_type:
4170 case DW_TAG_enumeration_type:
4171 /* Skip external references. The DWARF standard says in the section
4172 about "Structure, Union, and Class Type Entries": "An incomplete
4173 structure, union or class type is represented by a structure,
4174 union or class entry that does not have a byte size attribute
4175 and that has a DW_AT_declaration attribute." */
4176 if (!pdi->has_byte_size && pdi->is_declaration)
4178 if (built_actual_name)
4179 xfree (actual_name);
4183 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4184 static vs. global. */
4185 add_psymbol_to_list (actual_name, strlen (actual_name),
4187 STRUCT_DOMAIN, LOC_TYPEDEF,
4188 (cu->language == language_cplus
4189 || cu->language == language_java)
4190 ? &objfile->global_psymbols
4191 : &objfile->static_psymbols,
4192 0, (CORE_ADDR) 0, cu->language, objfile);
4195 case DW_TAG_enumerator:
4196 add_psymbol_to_list (actual_name, strlen (actual_name),
4198 VAR_DOMAIN, LOC_CONST,
4199 (cu->language == language_cplus
4200 || cu->language == language_java)
4201 ? &objfile->global_psymbols
4202 : &objfile->static_psymbols,
4203 0, (CORE_ADDR) 0, cu->language, objfile);
4209 if (built_actual_name)
4210 xfree (actual_name);
4213 /* Read a partial die corresponding to a namespace; also, add a symbol
4214 corresponding to that namespace to the symbol table. NAMESPACE is
4215 the name of the enclosing namespace. */
4218 add_partial_namespace (struct partial_die_info *pdi,
4219 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4220 int need_pc, struct dwarf2_cu *cu)
4222 /* Add a symbol for the namespace. */
4224 add_partial_symbol (pdi, cu);
4226 /* Now scan partial symbols in that namespace. */
4228 if (pdi->has_children)
4229 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4232 /* Read a partial die corresponding to a Fortran module. */
4235 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4236 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4238 /* Now scan partial symbols in that module. */
4240 if (pdi->has_children)
4241 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4244 /* Read a partial die corresponding to a subprogram and create a partial
4245 symbol for that subprogram. When the CU language allows it, this
4246 routine also defines a partial symbol for each nested subprogram
4247 that this subprogram contains.
4249 DIE my also be a lexical block, in which case we simply search
4250 recursively for suprograms defined inside that lexical block.
4251 Again, this is only performed when the CU language allows this
4252 type of definitions. */
4255 add_partial_subprogram (struct partial_die_info *pdi,
4256 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4257 int need_pc, struct dwarf2_cu *cu)
4259 if (pdi->tag == DW_TAG_subprogram)
4261 if (pdi->has_pc_info)
4263 if (pdi->lowpc < *lowpc)
4264 *lowpc = pdi->lowpc;
4265 if (pdi->highpc > *highpc)
4266 *highpc = pdi->highpc;
4270 struct objfile *objfile = cu->objfile;
4272 baseaddr = ANOFFSET (objfile->section_offsets,
4273 SECT_OFF_TEXT (objfile));
4274 addrmap_set_empty (objfile->psymtabs_addrmap,
4275 pdi->lowpc + baseaddr,
4276 pdi->highpc - 1 + baseaddr,
4277 cu->per_cu->v.psymtab);
4281 if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
4283 if (!pdi->is_declaration)
4284 /* Ignore subprogram DIEs that do not have a name, they are
4285 illegal. Do not emit a complaint at this point, we will
4286 do so when we convert this psymtab into a symtab. */
4288 add_partial_symbol (pdi, cu);
4292 if (! pdi->has_children)
4295 if (cu->language == language_ada)
4297 pdi = pdi->die_child;
4300 fixup_partial_die (pdi, cu);
4301 if (pdi->tag == DW_TAG_subprogram
4302 || pdi->tag == DW_TAG_lexical_block)
4303 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4304 pdi = pdi->die_sibling;
4309 /* Read a partial die corresponding to an enumeration type. */
4312 add_partial_enumeration (struct partial_die_info *enum_pdi,
4313 struct dwarf2_cu *cu)
4315 struct partial_die_info *pdi;
4317 if (enum_pdi->name != NULL)
4318 add_partial_symbol (enum_pdi, cu);
4320 pdi = enum_pdi->die_child;
4323 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4324 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4326 add_partial_symbol (pdi, cu);
4327 pdi = pdi->die_sibling;
4331 /* Return the initial uleb128 in the die at INFO_PTR. */
4334 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
4336 unsigned int bytes_read;
4338 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4341 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4342 Return the corresponding abbrev, or NULL if the number is zero (indicating
4343 an empty DIE). In either case *BYTES_READ will be set to the length of
4344 the initial number. */
4346 static struct abbrev_info *
4347 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4348 struct dwarf2_cu *cu)
4350 bfd *abfd = cu->objfile->obfd;
4351 unsigned int abbrev_number;
4352 struct abbrev_info *abbrev;
4354 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4356 if (abbrev_number == 0)
4359 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4362 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4363 abbrev_number, bfd_get_filename (abfd));
4369 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4370 Returns a pointer to the end of a series of DIEs, terminated by an empty
4371 DIE. Any children of the skipped DIEs will also be skipped. */
4374 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4376 struct abbrev_info *abbrev;
4377 unsigned int bytes_read;
4381 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4383 return info_ptr + bytes_read;
4385 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4389 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4390 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4391 abbrev corresponding to that skipped uleb128 should be passed in
4392 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4396 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4397 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4399 unsigned int bytes_read;
4400 struct attribute attr;
4401 bfd *abfd = cu->objfile->obfd;
4402 unsigned int form, i;
4404 for (i = 0; i < abbrev->num_attrs; i++)
4406 /* The only abbrev we care about is DW_AT_sibling. */
4407 if (abbrev->attrs[i].name == DW_AT_sibling)
4409 read_attribute (&attr, &abbrev->attrs[i],
4410 abfd, info_ptr, cu);
4411 if (attr.form == DW_FORM_ref_addr)
4412 complaint (&symfile_complaints,
4413 _("ignoring absolute DW_AT_sibling"));
4415 return buffer + dwarf2_get_ref_die_offset (&attr);
4418 /* If it isn't DW_AT_sibling, skip this attribute. */
4419 form = abbrev->attrs[i].form;
4423 case DW_FORM_ref_addr:
4424 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4425 and later it is offset sized. */
4426 if (cu->header.version == 2)
4427 info_ptr += cu->header.addr_size;
4429 info_ptr += cu->header.offset_size;
4432 info_ptr += cu->header.addr_size;
4439 case DW_FORM_flag_present:
4451 case DW_FORM_ref_sig8:
4454 case DW_FORM_string:
4455 read_direct_string (abfd, info_ptr, &bytes_read);
4456 info_ptr += bytes_read;
4458 case DW_FORM_sec_offset:
4460 info_ptr += cu->header.offset_size;
4462 case DW_FORM_exprloc:
4464 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4465 info_ptr += bytes_read;
4467 case DW_FORM_block1:
4468 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4470 case DW_FORM_block2:
4471 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4473 case DW_FORM_block4:
4474 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4478 case DW_FORM_ref_udata:
4479 info_ptr = skip_leb128 (abfd, info_ptr);
4481 case DW_FORM_indirect:
4482 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4483 info_ptr += bytes_read;
4484 /* We need to continue parsing from here, so just go back to
4486 goto skip_attribute;
4489 error (_("Dwarf Error: Cannot handle %s "
4490 "in DWARF reader [in module %s]"),
4491 dwarf_form_name (form),
4492 bfd_get_filename (abfd));
4496 if (abbrev->has_children)
4497 return skip_children (buffer, info_ptr, cu);
4502 /* Locate ORIG_PDI's sibling.
4503 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4507 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4508 gdb_byte *buffer, gdb_byte *info_ptr,
4509 bfd *abfd, struct dwarf2_cu *cu)
4511 /* Do we know the sibling already? */
4513 if (orig_pdi->sibling)
4514 return orig_pdi->sibling;
4516 /* Are there any children to deal with? */
4518 if (!orig_pdi->has_children)
4521 /* Skip the children the long way. */
4523 return skip_children (buffer, info_ptr, cu);
4526 /* Expand this partial symbol table into a full symbol table. */
4529 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4535 warning (_("bug: psymtab for %s is already read in."),
4542 printf_filtered (_("Reading in symbols for %s..."),
4544 gdb_flush (gdb_stdout);
4547 /* Restore our global data. */
4548 dwarf2_per_objfile = objfile_data (pst->objfile,
4549 dwarf2_objfile_data_key);
4551 /* If this psymtab is constructed from a debug-only objfile, the
4552 has_section_at_zero flag will not necessarily be correct. We
4553 can get the correct value for this flag by looking at the data
4554 associated with the (presumably stripped) associated objfile. */
4555 if (pst->objfile->separate_debug_objfile_backlink)
4557 struct dwarf2_per_objfile *dpo_backlink
4558 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4559 dwarf2_objfile_data_key);
4561 dwarf2_per_objfile->has_section_at_zero
4562 = dpo_backlink->has_section_at_zero;
4565 dwarf2_per_objfile->reading_partial_symbols = 0;
4567 psymtab_to_symtab_1 (pst);
4569 /* Finish up the debug error message. */
4571 printf_filtered (_("done.\n"));
4576 /* Reading in full CUs. */
4578 /* Add PER_CU to the queue. */
4581 queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
4583 struct dwarf2_queue_item *item;
4586 item = xmalloc (sizeof (*item));
4587 item->per_cu = per_cu;
4590 if (dwarf2_queue == NULL)
4591 dwarf2_queue = item;
4593 dwarf2_queue_tail->next = item;
4595 dwarf2_queue_tail = item;
4598 /* Process the queue. */
4601 process_queue (void)
4603 struct dwarf2_queue_item *item, *next_item;
4605 /* The queue starts out with one item, but following a DIE reference
4606 may load a new CU, adding it to the end of the queue. */
4607 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4609 if (dwarf2_per_objfile->using_index
4610 ? !item->per_cu->v.quick->symtab
4611 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4612 process_full_comp_unit (item->per_cu);
4614 item->per_cu->queued = 0;
4615 next_item = item->next;
4619 dwarf2_queue_tail = NULL;
4622 /* Free all allocated queue entries. This function only releases anything if
4623 an error was thrown; if the queue was processed then it would have been
4624 freed as we went along. */
4627 dwarf2_release_queue (void *dummy)
4629 struct dwarf2_queue_item *item, *last;
4631 item = dwarf2_queue;
4634 /* Anything still marked queued is likely to be in an
4635 inconsistent state, so discard it. */
4636 if (item->per_cu->queued)
4638 if (item->per_cu->cu != NULL)
4639 free_one_cached_comp_unit (item->per_cu->cu);
4640 item->per_cu->queued = 0;
4648 dwarf2_queue = dwarf2_queue_tail = NULL;
4651 /* Read in full symbols for PST, and anything it depends on. */
4654 psymtab_to_symtab_1 (struct partial_symtab *pst)
4656 struct dwarf2_per_cu_data *per_cu;
4657 struct cleanup *back_to;
4660 for (i = 0; i < pst->number_of_dependencies; i++)
4661 if (!pst->dependencies[i]->readin)
4663 /* Inform about additional files that need to be read in. */
4666 /* FIXME: i18n: Need to make this a single string. */
4667 fputs_filtered (" ", gdb_stdout);
4669 fputs_filtered ("and ", gdb_stdout);
4671 printf_filtered ("%s...", pst->dependencies[i]->filename);
4672 wrap_here (""); /* Flush output. */
4673 gdb_flush (gdb_stdout);
4675 psymtab_to_symtab_1 (pst->dependencies[i]);
4678 per_cu = pst->read_symtab_private;
4682 /* It's an include file, no symbols to read for it.
4683 Everything is in the parent symtab. */
4688 dw2_do_instantiate_symtab (per_cu);
4691 /* Load the DIEs associated with PER_CU into memory. */
4694 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4696 struct objfile *objfile = per_cu->objfile;
4697 bfd *abfd = objfile->obfd;
4698 struct dwarf2_cu *cu;
4699 unsigned int offset;
4700 gdb_byte *info_ptr, *beg_of_comp_unit;
4701 struct cleanup *free_cu_cleanup = NULL;
4702 struct attribute *attr;
4705 gdb_assert (! per_cu->debug_types_section);
4707 /* Set local variables from the partial symbol table info. */
4708 offset = per_cu->offset;
4710 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4711 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4712 beg_of_comp_unit = info_ptr;
4714 if (per_cu->cu == NULL)
4716 cu = xmalloc (sizeof (*cu));
4717 init_one_comp_unit (cu, per_cu);
4721 /* If an error occurs while loading, release our storage. */
4722 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4724 /* Read in the comp_unit header. */
4725 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4727 /* Skip dummy compilation units. */
4728 if (info_ptr >= (dwarf2_per_objfile->info.buffer
4729 + dwarf2_per_objfile->info.size)
4730 || peek_abbrev_code (abfd, info_ptr) == 0)
4732 do_cleanups (free_cu_cleanup);
4736 /* Complete the cu_header. */
4737 cu->header.offset = offset;
4738 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4743 info_ptr += cu->header.first_die_offset;
4746 cu->dies = read_comp_unit (info_ptr, cu);
4748 /* We try not to read any attributes in this function, because not
4749 all CUs needed for references have been loaded yet, and symbol
4750 table processing isn't initialized. But we have to set the CU language,
4751 or we won't be able to build types correctly. */
4752 prepare_one_comp_unit (cu, cu->dies);
4754 /* Similarly, if we do not read the producer, we can not apply
4755 producer-specific interpretation. */
4756 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4758 cu->producer = DW_STRING (attr);
4762 /* We've successfully allocated this compilation unit. Let our
4763 caller clean it up when finished with it. */
4764 discard_cleanups (free_cu_cleanup);
4766 /* Link this CU into read_in_chain. */
4767 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4768 dwarf2_per_objfile->read_in_chain = per_cu;
4772 /* Add a DIE to the delayed physname list. */
4775 add_to_method_list (struct type *type, int fnfield_index, int index,
4776 const char *name, struct die_info *die,
4777 struct dwarf2_cu *cu)
4779 struct delayed_method_info mi;
4781 mi.fnfield_index = fnfield_index;
4785 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4788 /* A cleanup for freeing the delayed method list. */
4791 free_delayed_list (void *ptr)
4793 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4794 if (cu->method_list != NULL)
4796 VEC_free (delayed_method_info, cu->method_list);
4797 cu->method_list = NULL;
4801 /* Compute the physnames of any methods on the CU's method list.
4803 The computation of method physnames is delayed in order to avoid the
4804 (bad) condition that one of the method's formal parameters is of an as yet
4808 compute_delayed_physnames (struct dwarf2_cu *cu)
4811 struct delayed_method_info *mi;
4812 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4814 const char *physname;
4815 struct fn_fieldlist *fn_flp
4816 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4817 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4818 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4822 /* Generate full symbol information for PER_CU, whose DIEs have
4823 already been loaded into memory. */
4826 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4828 struct dwarf2_cu *cu = per_cu->cu;
4829 struct objfile *objfile = per_cu->objfile;
4830 CORE_ADDR lowpc, highpc;
4831 struct symtab *symtab;
4832 struct cleanup *back_to, *delayed_list_cleanup;
4835 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4838 back_to = make_cleanup (really_free_pendings, NULL);
4839 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4841 cu->list_in_scope = &file_symbols;
4843 /* Do line number decoding in read_file_scope () */
4844 process_die (cu->dies, cu);
4846 /* Now that we have processed all the DIEs in the CU, all the types
4847 should be complete, and it should now be safe to compute all of the
4849 compute_delayed_physnames (cu);
4850 do_cleanups (delayed_list_cleanup);
4852 /* Some compilers don't define a DW_AT_high_pc attribute for the
4853 compilation unit. If the DW_AT_high_pc is missing, synthesize
4854 it, by scanning the DIE's below the compilation unit. */
4855 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4857 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4861 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4863 /* Set symtab language to language from DW_AT_language. If the
4864 compilation is from a C file generated by language preprocessors, do
4865 not set the language if it was already deduced by start_subfile. */
4866 if (!(cu->language == language_c && symtab->language != language_c))
4867 symtab->language = cu->language;
4869 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4870 produce DW_AT_location with location lists but it can be possibly
4871 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
4872 there were bugs in prologue debug info, fixed later in GCC-4.5
4873 by "unwind info for epilogues" patch (which is not directly related).
4875 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4876 needed, it would be wrong due to missing DW_AT_producer there.
4878 Still one can confuse GDB by using non-standard GCC compilation
4879 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4881 if (cu->has_loclist && gcc_4_minor >= 5)
4882 symtab->locations_valid = 1;
4884 if (gcc_4_minor >= 5)
4885 symtab->epilogue_unwind_valid = 1;
4887 symtab->call_site_htab = cu->call_site_htab;
4890 if (dwarf2_per_objfile->using_index)
4891 per_cu->v.quick->symtab = symtab;
4894 struct partial_symtab *pst = per_cu->v.psymtab;
4895 pst->symtab = symtab;
4899 do_cleanups (back_to);
4902 /* Process a die and its children. */
4905 process_die (struct die_info *die, struct dwarf2_cu *cu)
4909 case DW_TAG_padding:
4911 case DW_TAG_compile_unit:
4912 read_file_scope (die, cu);
4914 case DW_TAG_type_unit:
4915 read_type_unit_scope (die, cu);
4917 case DW_TAG_subprogram:
4918 case DW_TAG_inlined_subroutine:
4919 read_func_scope (die, cu);
4921 case DW_TAG_lexical_block:
4922 case DW_TAG_try_block:
4923 case DW_TAG_catch_block:
4924 read_lexical_block_scope (die, cu);
4926 case DW_TAG_GNU_call_site:
4927 read_call_site_scope (die, cu);
4929 case DW_TAG_class_type:
4930 case DW_TAG_interface_type:
4931 case DW_TAG_structure_type:
4932 case DW_TAG_union_type:
4933 process_structure_scope (die, cu);
4935 case DW_TAG_enumeration_type:
4936 process_enumeration_scope (die, cu);
4939 /* These dies have a type, but processing them does not create
4940 a symbol or recurse to process the children. Therefore we can
4941 read them on-demand through read_type_die. */
4942 case DW_TAG_subroutine_type:
4943 case DW_TAG_set_type:
4944 case DW_TAG_array_type:
4945 case DW_TAG_pointer_type:
4946 case DW_TAG_ptr_to_member_type:
4947 case DW_TAG_reference_type:
4948 case DW_TAG_string_type:
4951 case DW_TAG_base_type:
4952 case DW_TAG_subrange_type:
4953 case DW_TAG_typedef:
4954 /* Add a typedef symbol for the type definition, if it has a
4956 new_symbol (die, read_type_die (die, cu), cu);
4958 case DW_TAG_common_block:
4959 read_common_block (die, cu);
4961 case DW_TAG_common_inclusion:
4963 case DW_TAG_namespace:
4964 processing_has_namespace_info = 1;
4965 read_namespace (die, cu);
4968 processing_has_namespace_info = 1;
4969 read_module (die, cu);
4971 case DW_TAG_imported_declaration:
4972 case DW_TAG_imported_module:
4973 processing_has_namespace_info = 1;
4974 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4975 || cu->language != language_fortran))
4976 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4977 dwarf_tag_name (die->tag));
4978 read_import_statement (die, cu);
4981 new_symbol (die, NULL, cu);
4986 /* A helper function for dwarf2_compute_name which determines whether DIE
4987 needs to have the name of the scope prepended to the name listed in the
4991 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4993 struct attribute *attr;
4997 case DW_TAG_namespace:
4998 case DW_TAG_typedef:
4999 case DW_TAG_class_type:
5000 case DW_TAG_interface_type:
5001 case DW_TAG_structure_type:
5002 case DW_TAG_union_type:
5003 case DW_TAG_enumeration_type:
5004 case DW_TAG_enumerator:
5005 case DW_TAG_subprogram:
5009 case DW_TAG_variable:
5010 case DW_TAG_constant:
5011 /* We only need to prefix "globally" visible variables. These include
5012 any variable marked with DW_AT_external or any variable that
5013 lives in a namespace. [Variables in anonymous namespaces
5014 require prefixing, but they are not DW_AT_external.] */
5016 if (dwarf2_attr (die, DW_AT_specification, cu))
5018 struct dwarf2_cu *spec_cu = cu;
5020 return die_needs_namespace (die_specification (die, &spec_cu),
5024 attr = dwarf2_attr (die, DW_AT_external, cu);
5025 if (attr == NULL && die->parent->tag != DW_TAG_namespace
5026 && die->parent->tag != DW_TAG_module)
5028 /* A variable in a lexical block of some kind does not need a
5029 namespace, even though in C++ such variables may be external
5030 and have a mangled name. */
5031 if (die->parent->tag == DW_TAG_lexical_block
5032 || die->parent->tag == DW_TAG_try_block
5033 || die->parent->tag == DW_TAG_catch_block
5034 || die->parent->tag == DW_TAG_subprogram)
5043 /* Retrieve the last character from a mem_file. */
5046 do_ui_file_peek_last (void *object, const char *buffer, long length)
5048 char *last_char_p = (char *) object;
5051 *last_char_p = buffer[length - 1];
5054 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5055 compute the physname for the object, which include a method's
5056 formal parameters (C++/Java) and return type (Java).
5058 For Ada, return the DIE's linkage name rather than the fully qualified
5059 name. PHYSNAME is ignored..
5061 The result is allocated on the objfile_obstack and canonicalized. */
5064 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
5067 struct objfile *objfile = cu->objfile;
5070 name = dwarf2_name (die, cu);
5072 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5073 compute it by typename_concat inside GDB. */
5074 if (cu->language == language_ada
5075 || (cu->language == language_fortran && physname))
5077 /* For Ada unit, we prefer the linkage name over the name, as
5078 the former contains the exported name, which the user expects
5079 to be able to reference. Ideally, we want the user to be able
5080 to reference this entity using either natural or linkage name,
5081 but we haven't started looking at this enhancement yet. */
5082 struct attribute *attr;
5084 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5086 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5087 if (attr && DW_STRING (attr))
5088 return DW_STRING (attr);
5091 /* These are the only languages we know how to qualify names in. */
5093 && (cu->language == language_cplus || cu->language == language_java
5094 || cu->language == language_fortran))
5096 if (die_needs_namespace (die, cu))
5100 struct ui_file *buf;
5102 prefix = determine_prefix (die, cu);
5103 buf = mem_fileopen ();
5104 if (*prefix != '\0')
5106 char *prefixed_name = typename_concat (NULL, prefix, name,
5109 fputs_unfiltered (prefixed_name, buf);
5110 xfree (prefixed_name);
5113 fputs_unfiltered (name, buf);
5115 /* Template parameters may be specified in the DIE's DW_AT_name, or
5116 as children with DW_TAG_template_type_param or
5117 DW_TAG_value_type_param. If the latter, add them to the name
5118 here. If the name already has template parameters, then
5119 skip this step; some versions of GCC emit both, and
5120 it is more efficient to use the pre-computed name.
5122 Something to keep in mind about this process: it is very
5123 unlikely, or in some cases downright impossible, to produce
5124 something that will match the mangled name of a function.
5125 If the definition of the function has the same debug info,
5126 we should be able to match up with it anyway. But fallbacks
5127 using the minimal symbol, for instance to find a method
5128 implemented in a stripped copy of libstdc++, will not work.
5129 If we do not have debug info for the definition, we will have to
5130 match them up some other way.
5132 When we do name matching there is a related problem with function
5133 templates; two instantiated function templates are allowed to
5134 differ only by their return types, which we do not add here. */
5136 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5138 struct attribute *attr;
5139 struct die_info *child;
5142 die->building_fullname = 1;
5144 for (child = die->child; child != NULL; child = child->sibling)
5149 struct dwarf2_locexpr_baton *baton;
5152 if (child->tag != DW_TAG_template_type_param
5153 && child->tag != DW_TAG_template_value_param)
5158 fputs_unfiltered ("<", buf);
5162 fputs_unfiltered (", ", buf);
5164 attr = dwarf2_attr (child, DW_AT_type, cu);
5167 complaint (&symfile_complaints,
5168 _("template parameter missing DW_AT_type"));
5169 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5172 type = die_type (child, cu);
5174 if (child->tag == DW_TAG_template_type_param)
5176 c_print_type (type, "", buf, -1, 0);
5180 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5183 complaint (&symfile_complaints,
5184 _("template parameter missing "
5185 "DW_AT_const_value"));
5186 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5190 dwarf2_const_value_attr (attr, type, name,
5191 &cu->comp_unit_obstack, cu,
5192 &value, &bytes, &baton);
5194 if (TYPE_NOSIGN (type))
5195 /* GDB prints characters as NUMBER 'CHAR'. If that's
5196 changed, this can use value_print instead. */
5197 c_printchar (value, type, buf);
5200 struct value_print_options opts;
5203 v = dwarf2_evaluate_loc_desc (type, NULL,
5207 else if (bytes != NULL)
5209 v = allocate_value (type);
5210 memcpy (value_contents_writeable (v), bytes,
5211 TYPE_LENGTH (type));
5214 v = value_from_longest (type, value);
5216 /* Specify decimal so that we do not depend on
5218 get_formatted_print_options (&opts, 'd');
5220 value_print (v, buf, &opts);
5226 die->building_fullname = 0;
5230 /* Close the argument list, with a space if necessary
5231 (nested templates). */
5232 char last_char = '\0';
5233 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5234 if (last_char == '>')
5235 fputs_unfiltered (" >", buf);
5237 fputs_unfiltered (">", buf);
5241 /* For Java and C++ methods, append formal parameter type
5242 information, if PHYSNAME. */
5244 if (physname && die->tag == DW_TAG_subprogram
5245 && (cu->language == language_cplus
5246 || cu->language == language_java))
5248 struct type *type = read_type_die (die, cu);
5250 c_type_print_args (type, buf, 1, cu->language);
5252 if (cu->language == language_java)
5254 /* For java, we must append the return type to method
5256 if (die->tag == DW_TAG_subprogram)
5257 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5260 else if (cu->language == language_cplus)
5262 /* Assume that an artificial first parameter is
5263 "this", but do not crash if it is not. RealView
5264 marks unnamed (and thus unused) parameters as
5265 artificial; there is no way to differentiate
5267 if (TYPE_NFIELDS (type) > 0
5268 && TYPE_FIELD_ARTIFICIAL (type, 0)
5269 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5270 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5272 fputs_unfiltered (" const", buf);
5276 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
5278 ui_file_delete (buf);
5280 if (cu->language == language_cplus)
5283 = dwarf2_canonicalize_name (name, cu,
5284 &objfile->objfile_obstack);
5295 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5296 If scope qualifiers are appropriate they will be added. The result
5297 will be allocated on the objfile_obstack, or NULL if the DIE does
5298 not have a name. NAME may either be from a previous call to
5299 dwarf2_name or NULL.
5301 The output string will be canonicalized (if C++/Java). */
5304 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5306 return dwarf2_compute_name (name, die, cu, 0);
5309 /* Construct a physname for the given DIE in CU. NAME may either be
5310 from a previous call to dwarf2_name or NULL. The result will be
5311 allocated on the objfile_objstack or NULL if the DIE does not have a
5314 The output string will be canonicalized (if C++/Java). */
5317 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5319 struct objfile *objfile = cu->objfile;
5320 struct attribute *attr;
5321 const char *retval, *mangled = NULL, *canon = NULL;
5322 struct cleanup *back_to;
5325 /* In this case dwarf2_compute_name is just a shortcut not building anything
5327 if (!die_needs_namespace (die, cu))
5328 return dwarf2_compute_name (name, die, cu, 1);
5330 back_to = make_cleanup (null_cleanup, NULL);
5332 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5334 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5336 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5338 if (attr && DW_STRING (attr))
5342 mangled = DW_STRING (attr);
5344 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5345 type. It is easier for GDB users to search for such functions as
5346 `name(params)' than `long name(params)'. In such case the minimal
5347 symbol names do not match the full symbol names but for template
5348 functions there is never a need to look up their definition from their
5349 declaration so the only disadvantage remains the minimal symbol
5350 variant `long name(params)' does not have the proper inferior type.
5353 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5354 | (cu->language == language_java
5355 ? DMGL_JAVA | DMGL_RET_POSTFIX
5359 make_cleanup (xfree, demangled);
5369 if (canon == NULL || check_physname)
5371 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5373 if (canon != NULL && strcmp (physname, canon) != 0)
5375 /* It may not mean a bug in GDB. The compiler could also
5376 compute DW_AT_linkage_name incorrectly. But in such case
5377 GDB would need to be bug-to-bug compatible. */
5379 complaint (&symfile_complaints,
5380 _("Computed physname <%s> does not match demangled <%s> "
5381 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5382 physname, canon, mangled, die->offset, objfile->name);
5384 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5385 is available here - over computed PHYSNAME. It is safer
5386 against both buggy GDB and buggy compilers. */
5400 retval = obsavestring (retval, strlen (retval),
5401 &objfile->objfile_obstack);
5403 do_cleanups (back_to);
5407 /* Read the import statement specified by the given die and record it. */
5410 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5412 struct objfile *objfile = cu->objfile;
5413 struct attribute *import_attr;
5414 struct die_info *imported_die, *child_die;
5415 struct dwarf2_cu *imported_cu;
5416 const char *imported_name;
5417 const char *imported_name_prefix;
5418 const char *canonical_name;
5419 const char *import_alias;
5420 const char *imported_declaration = NULL;
5421 const char *import_prefix;
5422 VEC (const_char_ptr) *excludes = NULL;
5423 struct cleanup *cleanups;
5427 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5428 if (import_attr == NULL)
5430 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5431 dwarf_tag_name (die->tag));
5436 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5437 imported_name = dwarf2_name (imported_die, imported_cu);
5438 if (imported_name == NULL)
5440 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5442 The import in the following code:
5456 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5457 <52> DW_AT_decl_file : 1
5458 <53> DW_AT_decl_line : 6
5459 <54> DW_AT_import : <0x75>
5460 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5462 <5b> DW_AT_decl_file : 1
5463 <5c> DW_AT_decl_line : 2
5464 <5d> DW_AT_type : <0x6e>
5466 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5467 <76> DW_AT_byte_size : 4
5468 <77> DW_AT_encoding : 5 (signed)
5470 imports the wrong die ( 0x75 instead of 0x58 ).
5471 This case will be ignored until the gcc bug is fixed. */
5475 /* Figure out the local name after import. */
5476 import_alias = dwarf2_name (die, cu);
5478 /* Figure out where the statement is being imported to. */
5479 import_prefix = determine_prefix (die, cu);
5481 /* Figure out what the scope of the imported die is and prepend it
5482 to the name of the imported die. */
5483 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5485 if (imported_die->tag != DW_TAG_namespace
5486 && imported_die->tag != DW_TAG_module)
5488 imported_declaration = imported_name;
5489 canonical_name = imported_name_prefix;
5491 else if (strlen (imported_name_prefix) > 0)
5493 temp = alloca (strlen (imported_name_prefix)
5494 + 2 + strlen (imported_name) + 1);
5495 strcpy (temp, imported_name_prefix);
5496 strcat (temp, "::");
5497 strcat (temp, imported_name);
5498 canonical_name = temp;
5501 canonical_name = imported_name;
5503 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5505 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5506 for (child_die = die->child; child_die && child_die->tag;
5507 child_die = sibling_die (child_die))
5509 /* DWARF-4: A Fortran use statement with a “rename list” may be
5510 represented by an imported module entry with an import attribute
5511 referring to the module and owned entries corresponding to those
5512 entities that are renamed as part of being imported. */
5514 if (child_die->tag != DW_TAG_imported_declaration)
5516 complaint (&symfile_complaints,
5517 _("child DW_TAG_imported_declaration expected "
5518 "- DIE at 0x%x [in module %s]"),
5519 child_die->offset, objfile->name);
5523 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5524 if (import_attr == NULL)
5526 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5527 dwarf_tag_name (child_die->tag));
5532 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5534 imported_name = dwarf2_name (imported_die, imported_cu);
5535 if (imported_name == NULL)
5537 complaint (&symfile_complaints,
5538 _("child DW_TAG_imported_declaration has unknown "
5539 "imported name - DIE at 0x%x [in module %s]"),
5540 child_die->offset, objfile->name);
5544 VEC_safe_push (const_char_ptr, excludes, imported_name);
5546 process_die (child_die, cu);
5549 cp_add_using_directive (import_prefix,
5552 imported_declaration,
5554 &objfile->objfile_obstack);
5556 do_cleanups (cleanups);
5559 /* Cleanup function for read_file_scope. */
5562 free_cu_line_header (void *arg)
5564 struct dwarf2_cu *cu = arg;
5566 free_line_header (cu->line_header);
5567 cu->line_header = NULL;
5571 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5572 char **name, char **comp_dir)
5574 struct attribute *attr;
5579 /* Find the filename. Do not use dwarf2_name here, since the filename
5580 is not a source language identifier. */
5581 attr = dwarf2_attr (die, DW_AT_name, cu);
5584 *name = DW_STRING (attr);
5587 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5589 *comp_dir = DW_STRING (attr);
5590 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5592 *comp_dir = ldirname (*name);
5593 if (*comp_dir != NULL)
5594 make_cleanup (xfree, *comp_dir);
5596 if (*comp_dir != NULL)
5598 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5599 directory, get rid of it. */
5600 char *cp = strchr (*comp_dir, ':');
5602 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5607 *name = "<unknown>";
5610 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5611 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5612 COMP_DIR is the compilation directory.
5613 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5616 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5617 const char *comp_dir, int want_line_info)
5619 struct attribute *attr;
5620 struct objfile *objfile = cu->objfile;
5621 bfd *abfd = objfile->obfd;
5623 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5626 unsigned int line_offset = DW_UNSND (attr);
5627 struct line_header *line_header
5628 = dwarf_decode_line_header (line_offset, abfd, cu);
5632 cu->line_header = line_header;
5633 make_cleanup (free_cu_line_header, cu);
5634 dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info);
5639 /* Process DW_TAG_compile_unit. */
5642 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5644 struct objfile *objfile = cu->objfile;
5645 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5646 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5647 CORE_ADDR highpc = ((CORE_ADDR) 0);
5648 struct attribute *attr;
5650 char *comp_dir = NULL;
5651 struct die_info *child_die;
5652 bfd *abfd = objfile->obfd;
5655 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5657 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5659 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5660 from finish_block. */
5661 if (lowpc == ((CORE_ADDR) -1))
5666 find_file_and_directory (die, cu, &name, &comp_dir);
5668 attr = dwarf2_attr (die, DW_AT_language, cu);
5671 set_cu_language (DW_UNSND (attr), cu);
5674 attr = dwarf2_attr (die, DW_AT_producer, cu);
5676 cu->producer = DW_STRING (attr);
5678 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5679 standardised yet. As a workaround for the language detection we fall
5680 back to the DW_AT_producer string. */
5681 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5682 cu->language = language_opencl;
5684 /* We assume that we're processing GCC output. */
5685 processing_gcc_compilation = 2;
5687 processing_has_namespace_info = 0;
5689 start_symtab (name, comp_dir, lowpc);
5690 record_debugformat ("DWARF 2");
5691 record_producer (cu->producer);
5693 /* Decode line number information if present. We do this before
5694 processing child DIEs, so that the line header table is available
5695 for DW_AT_decl_file. */
5696 handle_DW_AT_stmt_list (die, cu, comp_dir, 1);
5698 /* Process all dies in compilation unit. */
5699 if (die->child != NULL)
5701 child_die = die->child;
5702 while (child_die && child_die->tag)
5704 process_die (child_die, cu);
5705 child_die = sibling_die (child_die);
5709 /* Decode macro information, if present. Dwarf 2 macro information
5710 refers to information in the line number info statement program
5711 header, so we can only read it if we've read the header
5713 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5714 if (attr && cu->line_header)
5716 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5717 complaint (&symfile_complaints,
5718 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5720 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5722 &dwarf2_per_objfile->macro, 1);
5726 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5727 if (attr && cu->line_header)
5729 unsigned int macro_offset = DW_UNSND (attr);
5731 dwarf_decode_macros (cu->line_header, macro_offset,
5733 &dwarf2_per_objfile->macinfo, 0);
5737 do_cleanups (back_to);
5740 /* Process DW_TAG_type_unit.
5741 For TUs we want to skip the first top level sibling if it's not the
5742 actual type being defined by this TU. In this case the first top
5743 level sibling is there to provide context only. */
5746 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5748 struct objfile *objfile = cu->objfile;
5749 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5751 struct attribute *attr;
5753 char *comp_dir = NULL;
5754 struct die_info *child_die;
5755 bfd *abfd = objfile->obfd;
5757 /* start_symtab needs a low pc, but we don't really have one.
5758 Do what read_file_scope would do in the absence of such info. */
5759 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5761 /* Find the filename. Do not use dwarf2_name here, since the filename
5762 is not a source language identifier. */
5763 attr = dwarf2_attr (die, DW_AT_name, cu);
5765 name = DW_STRING (attr);
5767 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5769 comp_dir = DW_STRING (attr);
5770 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5772 comp_dir = ldirname (name);
5773 if (comp_dir != NULL)
5774 make_cleanup (xfree, comp_dir);
5780 attr = dwarf2_attr (die, DW_AT_language, cu);
5782 set_cu_language (DW_UNSND (attr), cu);
5784 /* This isn't technically needed today. It is done for symmetry
5785 with read_file_scope. */
5786 attr = dwarf2_attr (die, DW_AT_producer, cu);
5788 cu->producer = DW_STRING (attr);
5790 /* We assume that we're processing GCC output. */
5791 processing_gcc_compilation = 2;
5793 processing_has_namespace_info = 0;
5795 start_symtab (name, comp_dir, lowpc);
5796 record_debugformat ("DWARF 2");
5797 record_producer (cu->producer);
5799 /* Decode line number information if present. We do this before
5800 processing child DIEs, so that the line header table is available
5801 for DW_AT_decl_file.
5802 We don't need the pc/line-number mapping for type units. */
5803 handle_DW_AT_stmt_list (die, cu, comp_dir, 0);
5805 /* Process the dies in the type unit. */
5806 if (die->child == NULL)
5808 dump_die_for_error (die);
5809 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5810 bfd_get_filename (abfd));
5813 child_die = die->child;
5815 while (child_die && child_die->tag)
5817 process_die (child_die, cu);
5819 child_die = sibling_die (child_die);
5822 do_cleanups (back_to);
5825 /* qsort helper for inherit_abstract_dies. */
5828 unsigned_int_compar (const void *ap, const void *bp)
5830 unsigned int a = *(unsigned int *) ap;
5831 unsigned int b = *(unsigned int *) bp;
5833 return (a > b) - (b > a);
5836 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5837 Inherit only the children of the DW_AT_abstract_origin DIE not being
5838 already referenced by DW_AT_abstract_origin from the children of the
5842 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5844 struct die_info *child_die;
5845 unsigned die_children_count;
5846 /* CU offsets which were referenced by children of the current DIE. */
5848 unsigned *offsets_end, *offsetp;
5849 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5850 struct die_info *origin_die;
5851 /* Iterator of the ORIGIN_DIE children. */
5852 struct die_info *origin_child_die;
5853 struct cleanup *cleanups;
5854 struct attribute *attr;
5855 struct dwarf2_cu *origin_cu;
5856 struct pending **origin_previous_list_in_scope;
5858 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5862 /* Note that following die references may follow to a die in a
5866 origin_die = follow_die_ref (die, attr, &origin_cu);
5868 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5870 origin_previous_list_in_scope = origin_cu->list_in_scope;
5871 origin_cu->list_in_scope = cu->list_in_scope;
5873 if (die->tag != origin_die->tag
5874 && !(die->tag == DW_TAG_inlined_subroutine
5875 && origin_die->tag == DW_TAG_subprogram))
5876 complaint (&symfile_complaints,
5877 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5878 die->offset, origin_die->offset);
5880 child_die = die->child;
5881 die_children_count = 0;
5882 while (child_die && child_die->tag)
5884 child_die = sibling_die (child_die);
5885 die_children_count++;
5887 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5888 cleanups = make_cleanup (xfree, offsets);
5890 offsets_end = offsets;
5891 child_die = die->child;
5892 while (child_die && child_die->tag)
5894 /* For each CHILD_DIE, find the corresponding child of
5895 ORIGIN_DIE. If there is more than one layer of
5896 DW_AT_abstract_origin, follow them all; there shouldn't be,
5897 but GCC versions at least through 4.4 generate this (GCC PR
5899 struct die_info *child_origin_die = child_die;
5900 struct dwarf2_cu *child_origin_cu = cu;
5904 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5908 child_origin_die = follow_die_ref (child_origin_die, attr,
5912 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5913 counterpart may exist. */
5914 if (child_origin_die != child_die)
5916 if (child_die->tag != child_origin_die->tag
5917 && !(child_die->tag == DW_TAG_inlined_subroutine
5918 && child_origin_die->tag == DW_TAG_subprogram))
5919 complaint (&symfile_complaints,
5920 _("Child DIE 0x%x and its abstract origin 0x%x have "
5921 "different tags"), child_die->offset,
5922 child_origin_die->offset);
5923 if (child_origin_die->parent != origin_die)
5924 complaint (&symfile_complaints,
5925 _("Child DIE 0x%x and its abstract origin 0x%x have "
5926 "different parents"), child_die->offset,
5927 child_origin_die->offset);
5929 *offsets_end++ = child_origin_die->offset;
5931 child_die = sibling_die (child_die);
5933 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5934 unsigned_int_compar);
5935 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5936 if (offsetp[-1] == *offsetp)
5937 complaint (&symfile_complaints,
5938 _("Multiple children of DIE 0x%x refer "
5939 "to DIE 0x%x as their abstract origin"),
5940 die->offset, *offsetp);
5943 origin_child_die = origin_die->child;
5944 while (origin_child_die && origin_child_die->tag)
5946 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5947 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5949 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5951 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5952 process_die (origin_child_die, origin_cu);
5954 origin_child_die = sibling_die (origin_child_die);
5956 origin_cu->list_in_scope = origin_previous_list_in_scope;
5958 do_cleanups (cleanups);
5962 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5964 struct objfile *objfile = cu->objfile;
5965 struct context_stack *new;
5968 struct die_info *child_die;
5969 struct attribute *attr, *call_line, *call_file;
5972 struct block *block;
5973 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5974 VEC (symbolp) *template_args = NULL;
5975 struct template_symbol *templ_func = NULL;
5979 /* If we do not have call site information, we can't show the
5980 caller of this inlined function. That's too confusing, so
5981 only use the scope for local variables. */
5982 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5983 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5984 if (call_line == NULL || call_file == NULL)
5986 read_lexical_block_scope (die, cu);
5991 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5993 name = dwarf2_name (die, cu);
5995 /* Ignore functions with missing or empty names. These are actually
5996 illegal according to the DWARF standard. */
5999 complaint (&symfile_complaints,
6000 _("missing name for subprogram DIE at %d"), die->offset);
6004 /* Ignore functions with missing or invalid low and high pc attributes. */
6005 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6007 attr = dwarf2_attr (die, DW_AT_external, cu);
6008 if (!attr || !DW_UNSND (attr))
6009 complaint (&symfile_complaints,
6010 _("cannot get low and high bounds "
6011 "for subprogram DIE at %d"),
6019 /* If we have any template arguments, then we must allocate a
6020 different sort of symbol. */
6021 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
6023 if (child_die->tag == DW_TAG_template_type_param
6024 || child_die->tag == DW_TAG_template_value_param)
6026 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
6027 struct template_symbol);
6028 templ_func->base.is_cplus_template_function = 1;
6033 new = push_context (0, lowpc);
6034 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
6035 (struct symbol *) templ_func);
6037 /* If there is a location expression for DW_AT_frame_base, record
6039 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
6041 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6042 expression is being recorded directly in the function's symbol
6043 and not in a separate frame-base object. I guess this hack is
6044 to avoid adding some sort of frame-base adjunct/annex to the
6045 function's symbol :-(. The problem with doing this is that it
6046 results in a function symbol with a location expression that
6047 has nothing to do with the location of the function, ouch! The
6048 relationship should be: a function's symbol has-a frame base; a
6049 frame-base has-a location expression. */
6050 dwarf2_symbol_mark_computed (attr, new->name, cu);
6052 cu->list_in_scope = &local_symbols;
6054 if (die->child != NULL)
6056 child_die = die->child;
6057 while (child_die && child_die->tag)
6059 if (child_die->tag == DW_TAG_template_type_param
6060 || child_die->tag == DW_TAG_template_value_param)
6062 struct symbol *arg = new_symbol (child_die, NULL, cu);
6065 VEC_safe_push (symbolp, template_args, arg);
6068 process_die (child_die, cu);
6069 child_die = sibling_die (child_die);
6073 inherit_abstract_dies (die, cu);
6075 /* If we have a DW_AT_specification, we might need to import using
6076 directives from the context of the specification DIE. See the
6077 comment in determine_prefix. */
6078 if (cu->language == language_cplus
6079 && dwarf2_attr (die, DW_AT_specification, cu))
6081 struct dwarf2_cu *spec_cu = cu;
6082 struct die_info *spec_die = die_specification (die, &spec_cu);
6086 child_die = spec_die->child;
6087 while (child_die && child_die->tag)
6089 if (child_die->tag == DW_TAG_imported_module)
6090 process_die (child_die, spec_cu);
6091 child_die = sibling_die (child_die);
6094 /* In some cases, GCC generates specification DIEs that
6095 themselves contain DW_AT_specification attributes. */
6096 spec_die = die_specification (spec_die, &spec_cu);
6100 new = pop_context ();
6101 /* Make a block for the local symbols within. */
6102 block = finish_block (new->name, &local_symbols, new->old_blocks,
6103 lowpc, highpc, objfile);
6105 /* For C++, set the block's scope. */
6106 if (cu->language == language_cplus || cu->language == language_fortran)
6107 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6108 determine_prefix (die, cu),
6109 processing_has_namespace_info);
6111 /* If we have address ranges, record them. */
6112 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6114 /* Attach template arguments to function. */
6115 if (! VEC_empty (symbolp, template_args))
6117 gdb_assert (templ_func != NULL);
6119 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6120 templ_func->template_arguments
6121 = obstack_alloc (&objfile->objfile_obstack,
6122 (templ_func->n_template_arguments
6123 * sizeof (struct symbol *)));
6124 memcpy (templ_func->template_arguments,
6125 VEC_address (symbolp, template_args),
6126 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6127 VEC_free (symbolp, template_args);
6130 /* In C++, we can have functions nested inside functions (e.g., when
6131 a function declares a class that has methods). This means that
6132 when we finish processing a function scope, we may need to go
6133 back to building a containing block's symbol lists. */
6134 local_symbols = new->locals;
6135 param_symbols = new->params;
6136 using_directives = new->using_directives;
6138 /* If we've finished processing a top-level function, subsequent
6139 symbols go in the file symbol list. */
6140 if (outermost_context_p ())
6141 cu->list_in_scope = &file_symbols;
6144 /* Process all the DIES contained within a lexical block scope. Start
6145 a new scope, process the dies, and then close the scope. */
6148 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6150 struct objfile *objfile = cu->objfile;
6151 struct context_stack *new;
6152 CORE_ADDR lowpc, highpc;
6153 struct die_info *child_die;
6156 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6158 /* Ignore blocks with missing or invalid low and high pc attributes. */
6159 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6160 as multiple lexical blocks? Handling children in a sane way would
6161 be nasty. Might be easier to properly extend generic blocks to
6163 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6168 push_context (0, lowpc);
6169 if (die->child != NULL)
6171 child_die = die->child;
6172 while (child_die && child_die->tag)
6174 process_die (child_die, cu);
6175 child_die = sibling_die (child_die);
6178 new = pop_context ();
6180 if (local_symbols != NULL || using_directives != NULL)
6183 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6186 /* Note that recording ranges after traversing children, as we
6187 do here, means that recording a parent's ranges entails
6188 walking across all its children's ranges as they appear in
6189 the address map, which is quadratic behavior.
6191 It would be nicer to record the parent's ranges before
6192 traversing its children, simply overriding whatever you find
6193 there. But since we don't even decide whether to create a
6194 block until after we've traversed its children, that's hard
6196 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6198 local_symbols = new->locals;
6199 using_directives = new->using_directives;
6202 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6205 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
6207 struct objfile *objfile = cu->objfile;
6208 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6209 CORE_ADDR pc, baseaddr;
6210 struct attribute *attr;
6211 struct call_site *call_site, call_site_local;
6214 struct die_info *child_die;
6216 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6218 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6221 complaint (&symfile_complaints,
6222 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6223 "DIE 0x%x [in module %s]"),
6224 die->offset, objfile->name);
6227 pc = DW_ADDR (attr) + baseaddr;
6229 if (cu->call_site_htab == NULL)
6230 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
6231 NULL, &objfile->objfile_obstack,
6232 hashtab_obstack_allocate, NULL);
6233 call_site_local.pc = pc;
6234 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
6237 complaint (&symfile_complaints,
6238 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6239 "DIE 0x%x [in module %s]"),
6240 paddress (gdbarch, pc), die->offset, objfile->name);
6244 /* Count parameters at the caller. */
6247 for (child_die = die->child; child_die && child_die->tag;
6248 child_die = sibling_die (child_die))
6250 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6252 complaint (&symfile_complaints,
6253 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6254 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6255 child_die->tag, child_die->offset, objfile->name);
6262 call_site = obstack_alloc (&objfile->objfile_obstack,
6263 (sizeof (*call_site)
6264 + (sizeof (*call_site->parameter)
6267 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
6270 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
6272 struct die_info *func_die;
6274 /* Skip also over DW_TAG_inlined_subroutine. */
6275 for (func_die = die->parent;
6276 func_die && func_die->tag != DW_TAG_subprogram
6277 && func_die->tag != DW_TAG_subroutine_type;
6278 func_die = func_die->parent);
6280 /* DW_AT_GNU_all_call_sites is a superset
6281 of DW_AT_GNU_all_tail_call_sites. */
6283 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
6284 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
6286 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6287 not complete. But keep CALL_SITE for look ups via call_site_htab,
6288 both the initial caller containing the real return address PC and
6289 the final callee containing the current PC of a chain of tail
6290 calls do not need to have the tail call list complete. But any
6291 function candidate for a virtual tail call frame searched via
6292 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6293 determined unambiguously. */
6297 struct type *func_type = NULL;
6300 func_type = get_die_type (func_die, cu);
6301 if (func_type != NULL)
6303 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
6305 /* Enlist this call site to the function. */
6306 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
6307 TYPE_TAIL_CALL_LIST (func_type) = call_site;
6310 complaint (&symfile_complaints,
6311 _("Cannot find function owning DW_TAG_GNU_call_site "
6312 "DIE 0x%x [in module %s]"),
6313 die->offset, objfile->name);
6317 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
6319 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
6320 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
6321 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
6322 /* Keep NULL DWARF_BLOCK. */;
6323 else if (attr_form_is_block (attr))
6325 struct dwarf2_locexpr_baton *dlbaton;
6327 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
6328 dlbaton->data = DW_BLOCK (attr)->data;
6329 dlbaton->size = DW_BLOCK (attr)->size;
6330 dlbaton->per_cu = cu->per_cu;
6332 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
6334 else if (is_ref_attr (attr))
6336 struct dwarf2_cu *target_cu = cu;
6337 struct die_info *target_die;
6339 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
6340 gdb_assert (target_cu->objfile == objfile);
6341 if (die_is_declaration (target_die, target_cu))
6343 const char *target_physname;
6345 target_physname = dwarf2_physname (NULL, target_die, target_cu);
6346 if (target_physname == NULL)
6347 complaint (&symfile_complaints,
6348 _("DW_AT_GNU_call_site_target target DIE has invalid "
6349 "physname, for referencing DIE 0x%x [in module %s]"),
6350 die->offset, objfile->name);
6352 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
6358 /* DW_AT_entry_pc should be preferred. */
6359 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
6360 complaint (&symfile_complaints,
6361 _("DW_AT_GNU_call_site_target target DIE has invalid "
6362 "low pc, for referencing DIE 0x%x [in module %s]"),
6363 die->offset, objfile->name);
6365 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
6369 complaint (&symfile_complaints,
6370 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6371 "block nor reference, for DIE 0x%x [in module %s]"),
6372 die->offset, objfile->name);
6374 call_site->per_cu = cu->per_cu;
6376 for (child_die = die->child;
6377 child_die && child_die->tag;
6378 child_die = sibling_die (child_die))
6380 struct dwarf2_locexpr_baton *dlbaton;
6381 struct call_site_parameter *parameter;
6383 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6385 /* Already printed the complaint above. */
6389 gdb_assert (call_site->parameter_count < nparams);
6390 parameter = &call_site->parameter[call_site->parameter_count];
6392 /* DW_AT_location specifies the register number. Value of the data
6393 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6395 attr = dwarf2_attr (child_die, DW_AT_location, cu);
6396 if (!attr || !attr_form_is_block (attr))
6398 complaint (&symfile_complaints,
6399 _("No DW_FORM_block* DW_AT_location for "
6400 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6401 child_die->offset, objfile->name);
6404 parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
6405 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
6406 if (parameter->dwarf_reg == -1
6407 && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
6408 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
6409 ¶meter->fb_offset))
6411 complaint (&symfile_complaints,
6412 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6413 "for DW_FORM_block* DW_AT_location for "
6414 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6415 child_die->offset, objfile->name);
6419 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
6420 if (!attr_form_is_block (attr))
6422 complaint (&symfile_complaints,
6423 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6424 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6425 child_die->offset, objfile->name);
6428 parameter->value = DW_BLOCK (attr)->data;
6429 parameter->value_size = DW_BLOCK (attr)->size;
6431 /* Parameters are not pre-cleared by memset above. */
6432 parameter->data_value = NULL;
6433 parameter->data_value_size = 0;
6434 call_site->parameter_count++;
6436 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
6439 if (!attr_form_is_block (attr))
6440 complaint (&symfile_complaints,
6441 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6442 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6443 child_die->offset, objfile->name);
6446 parameter->data_value = DW_BLOCK (attr)->data;
6447 parameter->data_value_size = DW_BLOCK (attr)->size;
6453 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6454 Return 1 if the attributes are present and valid, otherwise, return 0.
6455 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6458 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6459 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6460 struct partial_symtab *ranges_pst)
6462 struct objfile *objfile = cu->objfile;
6463 struct comp_unit_head *cu_header = &cu->header;
6464 bfd *obfd = objfile->obfd;
6465 unsigned int addr_size = cu_header->addr_size;
6466 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6467 /* Base address selection entry. */
6478 found_base = cu->base_known;
6479 base = cu->base_address;
6481 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6482 if (offset >= dwarf2_per_objfile->ranges.size)
6484 complaint (&symfile_complaints,
6485 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6489 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6491 /* Read in the largest possible address. */
6492 marker = read_address (obfd, buffer, cu, &dummy);
6493 if ((marker & mask) == mask)
6495 /* If we found the largest possible address, then
6496 read the base address. */
6497 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6498 buffer += 2 * addr_size;
6499 offset += 2 * addr_size;
6505 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6509 CORE_ADDR range_beginning, range_end;
6511 range_beginning = read_address (obfd, buffer, cu, &dummy);
6512 buffer += addr_size;
6513 range_end = read_address (obfd, buffer, cu, &dummy);
6514 buffer += addr_size;
6515 offset += 2 * addr_size;
6517 /* An end of list marker is a pair of zero addresses. */
6518 if (range_beginning == 0 && range_end == 0)
6519 /* Found the end of list entry. */
6522 /* Each base address selection entry is a pair of 2 values.
6523 The first is the largest possible address, the second is
6524 the base address. Check for a base address here. */
6525 if ((range_beginning & mask) == mask)
6527 /* If we found the largest possible address, then
6528 read the base address. */
6529 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6536 /* We have no valid base address for the ranges
6538 complaint (&symfile_complaints,
6539 _("Invalid .debug_ranges data (no base address)"));
6543 if (range_beginning > range_end)
6545 /* Inverted range entries are invalid. */
6546 complaint (&symfile_complaints,
6547 _("Invalid .debug_ranges data (inverted range)"));
6551 /* Empty range entries have no effect. */
6552 if (range_beginning == range_end)
6555 range_beginning += base;
6558 if (ranges_pst != NULL)
6559 addrmap_set_empty (objfile->psymtabs_addrmap,
6560 range_beginning + baseaddr,
6561 range_end - 1 + baseaddr,
6564 /* FIXME: This is recording everything as a low-high
6565 segment of consecutive addresses. We should have a
6566 data structure for discontiguous block ranges
6570 low = range_beginning;
6576 if (range_beginning < low)
6577 low = range_beginning;
6578 if (range_end > high)
6584 /* If the first entry is an end-of-list marker, the range
6585 describes an empty scope, i.e. no instructions. */
6591 *high_return = high;
6595 /* Get low and high pc attributes from a die. Return 1 if the attributes
6596 are present and valid, otherwise, return 0. Return -1 if the range is
6597 discontinuous, i.e. derived from DW_AT_ranges information. */
6599 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6600 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6601 struct partial_symtab *pst)
6603 struct attribute *attr;
6608 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6611 high = DW_ADDR (attr);
6612 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6614 low = DW_ADDR (attr);
6616 /* Found high w/o low attribute. */
6619 /* Found consecutive range of addresses. */
6624 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6627 /* Value of the DW_AT_ranges attribute is the offset in the
6628 .debug_ranges section. */
6629 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6631 /* Found discontinuous range of addresses. */
6636 /* read_partial_die has also the strict LOW < HIGH requirement. */
6640 /* When using the GNU linker, .gnu.linkonce. sections are used to
6641 eliminate duplicate copies of functions and vtables and such.
6642 The linker will arbitrarily choose one and discard the others.
6643 The AT_*_pc values for such functions refer to local labels in
6644 these sections. If the section from that file was discarded, the
6645 labels are not in the output, so the relocs get a value of 0.
6646 If this is a discarded function, mark the pc bounds as invalid,
6647 so that GDB will ignore it. */
6648 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6657 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6658 its low and high PC addresses. Do nothing if these addresses could not
6659 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6660 and HIGHPC to the high address if greater than HIGHPC. */
6663 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6664 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6665 struct dwarf2_cu *cu)
6667 CORE_ADDR low, high;
6668 struct die_info *child = die->child;
6670 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6672 *lowpc = min (*lowpc, low);
6673 *highpc = max (*highpc, high);
6676 /* If the language does not allow nested subprograms (either inside
6677 subprograms or lexical blocks), we're done. */
6678 if (cu->language != language_ada)
6681 /* Check all the children of the given DIE. If it contains nested
6682 subprograms, then check their pc bounds. Likewise, we need to
6683 check lexical blocks as well, as they may also contain subprogram
6685 while (child && child->tag)
6687 if (child->tag == DW_TAG_subprogram
6688 || child->tag == DW_TAG_lexical_block)
6689 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6690 child = sibling_die (child);
6694 /* Get the low and high pc's represented by the scope DIE, and store
6695 them in *LOWPC and *HIGHPC. If the correct values can't be
6696 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6699 get_scope_pc_bounds (struct die_info *die,
6700 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6701 struct dwarf2_cu *cu)
6703 CORE_ADDR best_low = (CORE_ADDR) -1;
6704 CORE_ADDR best_high = (CORE_ADDR) 0;
6705 CORE_ADDR current_low, current_high;
6707 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6709 best_low = current_low;
6710 best_high = current_high;
6714 struct die_info *child = die->child;
6716 while (child && child->tag)
6718 switch (child->tag) {
6719 case DW_TAG_subprogram:
6720 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6722 case DW_TAG_namespace:
6724 /* FIXME: carlton/2004-01-16: Should we do this for
6725 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6726 that current GCC's always emit the DIEs corresponding
6727 to definitions of methods of classes as children of a
6728 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6729 the DIEs giving the declarations, which could be
6730 anywhere). But I don't see any reason why the
6731 standards says that they have to be there. */
6732 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6734 if (current_low != ((CORE_ADDR) -1))
6736 best_low = min (best_low, current_low);
6737 best_high = max (best_high, current_high);
6745 child = sibling_die (child);
6750 *highpc = best_high;
6753 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6756 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6757 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6759 struct objfile *objfile = cu->objfile;
6760 struct attribute *attr;
6762 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6765 CORE_ADDR high = DW_ADDR (attr);
6767 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6770 CORE_ADDR low = DW_ADDR (attr);
6772 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6776 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6779 bfd *obfd = objfile->obfd;
6781 /* The value of the DW_AT_ranges attribute is the offset of the
6782 address range list in the .debug_ranges section. */
6783 unsigned long offset = DW_UNSND (attr);
6784 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6786 /* For some target architectures, but not others, the
6787 read_address function sign-extends the addresses it returns.
6788 To recognize base address selection entries, we need a
6790 unsigned int addr_size = cu->header.addr_size;
6791 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6793 /* The base address, to which the next pair is relative. Note
6794 that this 'base' is a DWARF concept: most entries in a range
6795 list are relative, to reduce the number of relocs against the
6796 debugging information. This is separate from this function's
6797 'baseaddr' argument, which GDB uses to relocate debugging
6798 information from a shared library based on the address at
6799 which the library was loaded. */
6800 CORE_ADDR base = cu->base_address;
6801 int base_known = cu->base_known;
6803 gdb_assert (dwarf2_per_objfile->ranges.readin);
6804 if (offset >= dwarf2_per_objfile->ranges.size)
6806 complaint (&symfile_complaints,
6807 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6814 unsigned int bytes_read;
6815 CORE_ADDR start, end;
6817 start = read_address (obfd, buffer, cu, &bytes_read);
6818 buffer += bytes_read;
6819 end = read_address (obfd, buffer, cu, &bytes_read);
6820 buffer += bytes_read;
6822 /* Did we find the end of the range list? */
6823 if (start == 0 && end == 0)
6826 /* Did we find a base address selection entry? */
6827 else if ((start & base_select_mask) == base_select_mask)
6833 /* We found an ordinary address range. */
6838 complaint (&symfile_complaints,
6839 _("Invalid .debug_ranges data "
6840 "(no base address)"));
6846 /* Inverted range entries are invalid. */
6847 complaint (&symfile_complaints,
6848 _("Invalid .debug_ranges data "
6849 "(inverted range)"));
6853 /* Empty range entries have no effect. */
6857 record_block_range (block,
6858 baseaddr + base + start,
6859 baseaddr + base + end - 1);
6865 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6866 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6867 during 4.6.0 experimental. */
6870 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6873 int major, minor, release;
6876 if (cu->producer == NULL)
6878 /* For unknown compilers expect their behavior is DWARF version
6881 GCC started to support .debug_types sections by -gdwarf-4 since
6882 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6883 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6884 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6885 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6890 if (cu->checked_producer)
6891 return cu->producer_is_gxx_lt_4_6;
6893 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6895 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6897 /* For non-GCC compilers expect their behavior is DWARF version
6902 cs = &cu->producer[strlen ("GNU ")];
6903 while (*cs && !isdigit (*cs))
6905 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6907 /* Not recognized as GCC. */
6910 result = major < 4 || (major == 4 && minor < 6);
6913 cu->checked_producer = 1;
6914 cu->producer_is_gxx_lt_4_6 = result;
6919 /* Return the default accessibility type if it is not overriden by
6920 DW_AT_accessibility. */
6922 static enum dwarf_access_attribute
6923 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6925 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6927 /* The default DWARF 2 accessibility for members is public, the default
6928 accessibility for inheritance is private. */
6930 if (die->tag != DW_TAG_inheritance)
6931 return DW_ACCESS_public;
6933 return DW_ACCESS_private;
6937 /* DWARF 3+ defines the default accessibility a different way. The same
6938 rules apply now for DW_TAG_inheritance as for the members and it only
6939 depends on the container kind. */
6941 if (die->parent->tag == DW_TAG_class_type)
6942 return DW_ACCESS_private;
6944 return DW_ACCESS_public;
6948 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6949 offset. If the attribute was not found return 0, otherwise return
6950 1. If it was found but could not properly be handled, set *OFFSET
6954 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6957 struct attribute *attr;
6959 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6964 /* Note that we do not check for a section offset first here.
6965 This is because DW_AT_data_member_location is new in DWARF 4,
6966 so if we see it, we can assume that a constant form is really
6967 a constant and not a section offset. */
6968 if (attr_form_is_constant (attr))
6969 *offset = dwarf2_get_attr_constant_value (attr, 0);
6970 else if (attr_form_is_section_offset (attr))
6971 dwarf2_complex_location_expr_complaint ();
6972 else if (attr_form_is_block (attr))
6973 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6975 dwarf2_complex_location_expr_complaint ();
6983 /* Add an aggregate field to the field list. */
6986 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6987 struct dwarf2_cu *cu)
6989 struct objfile *objfile = cu->objfile;
6990 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6991 struct nextfield *new_field;
6992 struct attribute *attr;
6994 char *fieldname = "";
6996 /* Allocate a new field list entry and link it in. */
6997 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6998 make_cleanup (xfree, new_field);
6999 memset (new_field, 0, sizeof (struct nextfield));
7001 if (die->tag == DW_TAG_inheritance)
7003 new_field->next = fip->baseclasses;
7004 fip->baseclasses = new_field;
7008 new_field->next = fip->fields;
7009 fip->fields = new_field;
7013 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7015 new_field->accessibility = DW_UNSND (attr);
7017 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
7018 if (new_field->accessibility != DW_ACCESS_public)
7019 fip->non_public_fields = 1;
7021 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7023 new_field->virtuality = DW_UNSND (attr);
7025 new_field->virtuality = DW_VIRTUALITY_none;
7027 fp = &new_field->field;
7029 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
7033 /* Data member other than a C++ static data member. */
7035 /* Get type of field. */
7036 fp->type = die_type (die, cu);
7038 SET_FIELD_BITPOS (*fp, 0);
7040 /* Get bit size of field (zero if none). */
7041 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
7044 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
7048 FIELD_BITSIZE (*fp) = 0;
7051 /* Get bit offset of field. */
7052 if (handle_data_member_location (die, cu, &offset))
7053 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7054 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
7057 if (gdbarch_bits_big_endian (gdbarch))
7059 /* For big endian bits, the DW_AT_bit_offset gives the
7060 additional bit offset from the MSB of the containing
7061 anonymous object to the MSB of the field. We don't
7062 have to do anything special since we don't need to
7063 know the size of the anonymous object. */
7064 FIELD_BITPOS (*fp) += DW_UNSND (attr);
7068 /* For little endian bits, compute the bit offset to the
7069 MSB of the anonymous object, subtract off the number of
7070 bits from the MSB of the field to the MSB of the
7071 object, and then subtract off the number of bits of
7072 the field itself. The result is the bit offset of
7073 the LSB of the field. */
7075 int bit_offset = DW_UNSND (attr);
7077 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7080 /* The size of the anonymous object containing
7081 the bit field is explicit, so use the
7082 indicated size (in bytes). */
7083 anonymous_size = DW_UNSND (attr);
7087 /* The size of the anonymous object containing
7088 the bit field must be inferred from the type
7089 attribute of the data member containing the
7091 anonymous_size = TYPE_LENGTH (fp->type);
7093 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
7094 - bit_offset - FIELD_BITSIZE (*fp);
7098 /* Get name of field. */
7099 fieldname = dwarf2_name (die, cu);
7100 if (fieldname == NULL)
7103 /* The name is already allocated along with this objfile, so we don't
7104 need to duplicate it for the type. */
7105 fp->name = fieldname;
7107 /* Change accessibility for artificial fields (e.g. virtual table
7108 pointer or virtual base class pointer) to private. */
7109 if (dwarf2_attr (die, DW_AT_artificial, cu))
7111 FIELD_ARTIFICIAL (*fp) = 1;
7112 new_field->accessibility = DW_ACCESS_private;
7113 fip->non_public_fields = 1;
7116 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
7118 /* C++ static member. */
7120 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7121 is a declaration, but all versions of G++ as of this writing
7122 (so through at least 3.2.1) incorrectly generate
7123 DW_TAG_variable tags. */
7125 const char *physname;
7127 /* Get name of field. */
7128 fieldname = dwarf2_name (die, cu);
7129 if (fieldname == NULL)
7132 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7134 /* Only create a symbol if this is an external value.
7135 new_symbol checks this and puts the value in the global symbol
7136 table, which we want. If it is not external, new_symbol
7137 will try to put the value in cu->list_in_scope which is wrong. */
7138 && dwarf2_flag_true_p (die, DW_AT_external, cu))
7140 /* A static const member, not much different than an enum as far as
7141 we're concerned, except that we can support more types. */
7142 new_symbol (die, NULL, cu);
7145 /* Get physical name. */
7146 physname = dwarf2_physname (fieldname, die, cu);
7148 /* The name is already allocated along with this objfile, so we don't
7149 need to duplicate it for the type. */
7150 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
7151 FIELD_TYPE (*fp) = die_type (die, cu);
7152 FIELD_NAME (*fp) = fieldname;
7154 else if (die->tag == DW_TAG_inheritance)
7158 /* C++ base class field. */
7159 if (handle_data_member_location (die, cu, &offset))
7160 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7161 FIELD_BITSIZE (*fp) = 0;
7162 FIELD_TYPE (*fp) = die_type (die, cu);
7163 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
7164 fip->nbaseclasses++;
7168 /* Add a typedef defined in the scope of the FIP's class. */
7171 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
7172 struct dwarf2_cu *cu)
7174 struct objfile *objfile = cu->objfile;
7175 struct typedef_field_list *new_field;
7176 struct attribute *attr;
7177 struct typedef_field *fp;
7178 char *fieldname = "";
7180 /* Allocate a new field list entry and link it in. */
7181 new_field = xzalloc (sizeof (*new_field));
7182 make_cleanup (xfree, new_field);
7184 gdb_assert (die->tag == DW_TAG_typedef);
7186 fp = &new_field->field;
7188 /* Get name of field. */
7189 fp->name = dwarf2_name (die, cu);
7190 if (fp->name == NULL)
7193 fp->type = read_type_die (die, cu);
7195 new_field->next = fip->typedef_field_list;
7196 fip->typedef_field_list = new_field;
7197 fip->typedef_field_list_count++;
7200 /* Create the vector of fields, and attach it to the type. */
7203 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
7204 struct dwarf2_cu *cu)
7206 int nfields = fip->nfields;
7208 /* Record the field count, allocate space for the array of fields,
7209 and create blank accessibility bitfields if necessary. */
7210 TYPE_NFIELDS (type) = nfields;
7211 TYPE_FIELDS (type) = (struct field *)
7212 TYPE_ALLOC (type, sizeof (struct field) * nfields);
7213 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
7215 if (fip->non_public_fields && cu->language != language_ada)
7217 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7219 TYPE_FIELD_PRIVATE_BITS (type) =
7220 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7221 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
7223 TYPE_FIELD_PROTECTED_BITS (type) =
7224 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7225 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
7227 TYPE_FIELD_IGNORE_BITS (type) =
7228 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7229 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
7232 /* If the type has baseclasses, allocate and clear a bit vector for
7233 TYPE_FIELD_VIRTUAL_BITS. */
7234 if (fip->nbaseclasses && cu->language != language_ada)
7236 int num_bytes = B_BYTES (fip->nbaseclasses);
7237 unsigned char *pointer;
7239 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7240 pointer = TYPE_ALLOC (type, num_bytes);
7241 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
7242 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
7243 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
7246 /* Copy the saved-up fields into the field vector. Start from the head of
7247 the list, adding to the tail of the field array, so that they end up in
7248 the same order in the array in which they were added to the list. */
7249 while (nfields-- > 0)
7251 struct nextfield *fieldp;
7255 fieldp = fip->fields;
7256 fip->fields = fieldp->next;
7260 fieldp = fip->baseclasses;
7261 fip->baseclasses = fieldp->next;
7264 TYPE_FIELD (type, nfields) = fieldp->field;
7265 switch (fieldp->accessibility)
7267 case DW_ACCESS_private:
7268 if (cu->language != language_ada)
7269 SET_TYPE_FIELD_PRIVATE (type, nfields);
7272 case DW_ACCESS_protected:
7273 if (cu->language != language_ada)
7274 SET_TYPE_FIELD_PROTECTED (type, nfields);
7277 case DW_ACCESS_public:
7281 /* Unknown accessibility. Complain and treat it as public. */
7283 complaint (&symfile_complaints, _("unsupported accessibility %d"),
7284 fieldp->accessibility);
7288 if (nfields < fip->nbaseclasses)
7290 switch (fieldp->virtuality)
7292 case DW_VIRTUALITY_virtual:
7293 case DW_VIRTUALITY_pure_virtual:
7294 if (cu->language == language_ada)
7295 error (_("unexpected virtuality in component of Ada type"));
7296 SET_TYPE_FIELD_VIRTUAL (type, nfields);
7303 /* Add a member function to the proper fieldlist. */
7306 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
7307 struct type *type, struct dwarf2_cu *cu)
7309 struct objfile *objfile = cu->objfile;
7310 struct attribute *attr;
7311 struct fnfieldlist *flp;
7313 struct fn_field *fnp;
7315 struct nextfnfield *new_fnfield;
7316 struct type *this_type;
7317 enum dwarf_access_attribute accessibility;
7319 if (cu->language == language_ada)
7320 error (_("unexpected member function in Ada type"));
7322 /* Get name of member function. */
7323 fieldname = dwarf2_name (die, cu);
7324 if (fieldname == NULL)
7327 /* Look up member function name in fieldlist. */
7328 for (i = 0; i < fip->nfnfields; i++)
7330 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7334 /* Create new list element if necessary. */
7335 if (i < fip->nfnfields)
7336 flp = &fip->fnfieldlists[i];
7339 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7341 fip->fnfieldlists = (struct fnfieldlist *)
7342 xrealloc (fip->fnfieldlists,
7343 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7344 * sizeof (struct fnfieldlist));
7345 if (fip->nfnfields == 0)
7346 make_cleanup (free_current_contents, &fip->fnfieldlists);
7348 flp = &fip->fnfieldlists[fip->nfnfields];
7349 flp->name = fieldname;
7352 i = fip->nfnfields++;
7355 /* Create a new member function field and chain it to the field list
7357 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7358 make_cleanup (xfree, new_fnfield);
7359 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7360 new_fnfield->next = flp->head;
7361 flp->head = new_fnfield;
7364 /* Fill in the member function field info. */
7365 fnp = &new_fnfield->fnfield;
7367 /* Delay processing of the physname until later. */
7368 if (cu->language == language_cplus || cu->language == language_java)
7370 add_to_method_list (type, i, flp->length - 1, fieldname,
7375 const char *physname = dwarf2_physname (fieldname, die, cu);
7376 fnp->physname = physname ? physname : "";
7379 fnp->type = alloc_type (objfile);
7380 this_type = read_type_die (die, cu);
7381 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7383 int nparams = TYPE_NFIELDS (this_type);
7385 /* TYPE is the domain of this method, and THIS_TYPE is the type
7386 of the method itself (TYPE_CODE_METHOD). */
7387 smash_to_method_type (fnp->type, type,
7388 TYPE_TARGET_TYPE (this_type),
7389 TYPE_FIELDS (this_type),
7390 TYPE_NFIELDS (this_type),
7391 TYPE_VARARGS (this_type));
7393 /* Handle static member functions.
7394 Dwarf2 has no clean way to discern C++ static and non-static
7395 member functions. G++ helps GDB by marking the first
7396 parameter for non-static member functions (which is the this
7397 pointer) as artificial. We obtain this information from
7398 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7399 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7400 fnp->voffset = VOFFSET_STATIC;
7403 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7404 dwarf2_full_name (fieldname, die, cu));
7406 /* Get fcontext from DW_AT_containing_type if present. */
7407 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7408 fnp->fcontext = die_containing_type (die, cu);
7410 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7411 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7413 /* Get accessibility. */
7414 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7416 accessibility = DW_UNSND (attr);
7418 accessibility = dwarf2_default_access_attribute (die, cu);
7419 switch (accessibility)
7421 case DW_ACCESS_private:
7422 fnp->is_private = 1;
7424 case DW_ACCESS_protected:
7425 fnp->is_protected = 1;
7429 /* Check for artificial methods. */
7430 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7431 if (attr && DW_UNSND (attr) != 0)
7432 fnp->is_artificial = 1;
7434 /* Get index in virtual function table if it is a virtual member
7435 function. For older versions of GCC, this is an offset in the
7436 appropriate virtual table, as specified by DW_AT_containing_type.
7437 For everyone else, it is an expression to be evaluated relative
7438 to the object address. */
7440 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7443 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7445 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7447 /* Old-style GCC. */
7448 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7450 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7451 || (DW_BLOCK (attr)->size > 1
7452 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7453 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7455 struct dwarf_block blk;
7458 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7460 blk.size = DW_BLOCK (attr)->size - offset;
7461 blk.data = DW_BLOCK (attr)->data + offset;
7462 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7463 if ((fnp->voffset % cu->header.addr_size) != 0)
7464 dwarf2_complex_location_expr_complaint ();
7466 fnp->voffset /= cu->header.addr_size;
7470 dwarf2_complex_location_expr_complaint ();
7473 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7475 else if (attr_form_is_section_offset (attr))
7477 dwarf2_complex_location_expr_complaint ();
7481 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7487 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7488 if (attr && DW_UNSND (attr))
7490 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7491 complaint (&symfile_complaints,
7492 _("Member function \"%s\" (offset %d) is virtual "
7493 "but the vtable offset is not specified"),
7494 fieldname, die->offset);
7495 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7496 TYPE_CPLUS_DYNAMIC (type) = 1;
7501 /* Create the vector of member function fields, and attach it to the type. */
7504 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7505 struct dwarf2_cu *cu)
7507 struct fnfieldlist *flp;
7510 if (cu->language == language_ada)
7511 error (_("unexpected member functions in Ada type"));
7513 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7514 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7515 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7517 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7519 struct nextfnfield *nfp = flp->head;
7520 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7523 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7524 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7525 fn_flp->fn_fields = (struct fn_field *)
7526 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7527 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7528 fn_flp->fn_fields[k] = nfp->fnfield;
7531 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7534 /* Returns non-zero if NAME is the name of a vtable member in CU's
7535 language, zero otherwise. */
7537 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7539 static const char vptr[] = "_vptr";
7540 static const char vtable[] = "vtable";
7542 /* Look for the C++ and Java forms of the vtable. */
7543 if ((cu->language == language_java
7544 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7545 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7546 && is_cplus_marker (name[sizeof (vptr) - 1])))
7552 /* GCC outputs unnamed structures that are really pointers to member
7553 functions, with the ABI-specified layout. If TYPE describes
7554 such a structure, smash it into a member function type.
7556 GCC shouldn't do this; it should just output pointer to member DIEs.
7557 This is GCC PR debug/28767. */
7560 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7562 struct type *pfn_type, *domain_type, *new_type;
7564 /* Check for a structure with no name and two children. */
7565 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7568 /* Check for __pfn and __delta members. */
7569 if (TYPE_FIELD_NAME (type, 0) == NULL
7570 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7571 || TYPE_FIELD_NAME (type, 1) == NULL
7572 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7575 /* Find the type of the method. */
7576 pfn_type = TYPE_FIELD_TYPE (type, 0);
7577 if (pfn_type == NULL
7578 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7579 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7582 /* Look for the "this" argument. */
7583 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7584 if (TYPE_NFIELDS (pfn_type) == 0
7585 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7586 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7589 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7590 new_type = alloc_type (objfile);
7591 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7592 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7593 TYPE_VARARGS (pfn_type));
7594 smash_to_methodptr_type (type, new_type);
7597 /* Called when we find the DIE that starts a structure or union scope
7598 (definition) to create a type for the structure or union. Fill in
7599 the type's name and general properties; the members will not be
7600 processed until process_structure_type.
7602 NOTE: we need to call these functions regardless of whether or not the
7603 DIE has a DW_AT_name attribute, since it might be an anonymous
7604 structure or union. This gets the type entered into our set of
7607 However, if the structure is incomplete (an opaque struct/union)
7608 then suppress creating a symbol table entry for it since gdb only
7609 wants to find the one with the complete definition. Note that if
7610 it is complete, we just call new_symbol, which does it's own
7611 checking about whether the struct/union is anonymous or not (and
7612 suppresses creating a symbol table entry itself). */
7614 static struct type *
7615 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7617 struct objfile *objfile = cu->objfile;
7619 struct attribute *attr;
7622 /* If the definition of this type lives in .debug_types, read that type.
7623 Don't follow DW_AT_specification though, that will take us back up
7624 the chain and we want to go down. */
7625 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7628 struct dwarf2_cu *type_cu = cu;
7629 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7631 /* We could just recurse on read_structure_type, but we need to call
7632 get_die_type to ensure only one type for this DIE is created.
7633 This is important, for example, because for c++ classes we need
7634 TYPE_NAME set which is only done by new_symbol. Blech. */
7635 type = read_type_die (type_die, type_cu);
7637 /* TYPE_CU may not be the same as CU.
7638 Ensure TYPE is recorded in CU's type_hash table. */
7639 return set_die_type (die, type, cu);
7642 type = alloc_type (objfile);
7643 INIT_CPLUS_SPECIFIC (type);
7645 name = dwarf2_name (die, cu);
7648 if (cu->language == language_cplus
7649 || cu->language == language_java)
7651 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7653 /* dwarf2_full_name might have already finished building the DIE's
7654 type. If so, there is no need to continue. */
7655 if (get_die_type (die, cu) != NULL)
7656 return get_die_type (die, cu);
7658 TYPE_TAG_NAME (type) = full_name;
7659 if (die->tag == DW_TAG_structure_type
7660 || die->tag == DW_TAG_class_type)
7661 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7665 /* The name is already allocated along with this objfile, so
7666 we don't need to duplicate it for the type. */
7667 TYPE_TAG_NAME (type) = (char *) name;
7668 if (die->tag == DW_TAG_class_type)
7669 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7673 if (die->tag == DW_TAG_structure_type)
7675 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7677 else if (die->tag == DW_TAG_union_type)
7679 TYPE_CODE (type) = TYPE_CODE_UNION;
7683 TYPE_CODE (type) = TYPE_CODE_CLASS;
7686 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7687 TYPE_DECLARED_CLASS (type) = 1;
7689 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7692 TYPE_LENGTH (type) = DW_UNSND (attr);
7696 TYPE_LENGTH (type) = 0;
7699 TYPE_STUB_SUPPORTED (type) = 1;
7700 if (die_is_declaration (die, cu))
7701 TYPE_STUB (type) = 1;
7702 else if (attr == NULL && die->child == NULL
7703 && producer_is_realview (cu->producer))
7704 /* RealView does not output the required DW_AT_declaration
7705 on incomplete types. */
7706 TYPE_STUB (type) = 1;
7708 /* We need to add the type field to the die immediately so we don't
7709 infinitely recurse when dealing with pointers to the structure
7710 type within the structure itself. */
7711 set_die_type (die, type, cu);
7713 /* set_die_type should be already done. */
7714 set_descriptive_type (type, die, cu);
7719 /* Finish creating a structure or union type, including filling in
7720 its members and creating a symbol for it. */
7723 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7725 struct objfile *objfile = cu->objfile;
7726 struct die_info *child_die = die->child;
7729 type = get_die_type (die, cu);
7731 type = read_structure_type (die, cu);
7733 if (die->child != NULL && ! die_is_declaration (die, cu))
7735 struct field_info fi;
7736 struct die_info *child_die;
7737 VEC (symbolp) *template_args = NULL;
7738 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7740 memset (&fi, 0, sizeof (struct field_info));
7742 child_die = die->child;
7744 while (child_die && child_die->tag)
7746 if (child_die->tag == DW_TAG_member
7747 || child_die->tag == DW_TAG_variable)
7749 /* NOTE: carlton/2002-11-05: A C++ static data member
7750 should be a DW_TAG_member that is a declaration, but
7751 all versions of G++ as of this writing (so through at
7752 least 3.2.1) incorrectly generate DW_TAG_variable
7753 tags for them instead. */
7754 dwarf2_add_field (&fi, child_die, cu);
7756 else if (child_die->tag == DW_TAG_subprogram)
7758 /* C++ member function. */
7759 dwarf2_add_member_fn (&fi, child_die, type, cu);
7761 else if (child_die->tag == DW_TAG_inheritance)
7763 /* C++ base class field. */
7764 dwarf2_add_field (&fi, child_die, cu);
7766 else if (child_die->tag == DW_TAG_typedef)
7767 dwarf2_add_typedef (&fi, child_die, cu);
7768 else if (child_die->tag == DW_TAG_template_type_param
7769 || child_die->tag == DW_TAG_template_value_param)
7771 struct symbol *arg = new_symbol (child_die, NULL, cu);
7774 VEC_safe_push (symbolp, template_args, arg);
7777 child_die = sibling_die (child_die);
7780 /* Attach template arguments to type. */
7781 if (! VEC_empty (symbolp, template_args))
7783 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7784 TYPE_N_TEMPLATE_ARGUMENTS (type)
7785 = VEC_length (symbolp, template_args);
7786 TYPE_TEMPLATE_ARGUMENTS (type)
7787 = obstack_alloc (&objfile->objfile_obstack,
7788 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7789 * sizeof (struct symbol *)));
7790 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7791 VEC_address (symbolp, template_args),
7792 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7793 * sizeof (struct symbol *)));
7794 VEC_free (symbolp, template_args);
7797 /* Attach fields and member functions to the type. */
7799 dwarf2_attach_fields_to_type (&fi, type, cu);
7802 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7804 /* Get the type which refers to the base class (possibly this
7805 class itself) which contains the vtable pointer for the current
7806 class from the DW_AT_containing_type attribute. This use of
7807 DW_AT_containing_type is a GNU extension. */
7809 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7811 struct type *t = die_containing_type (die, cu);
7813 TYPE_VPTR_BASETYPE (type) = t;
7818 /* Our own class provides vtbl ptr. */
7819 for (i = TYPE_NFIELDS (t) - 1;
7820 i >= TYPE_N_BASECLASSES (t);
7823 const char *fieldname = TYPE_FIELD_NAME (t, i);
7825 if (is_vtable_name (fieldname, cu))
7827 TYPE_VPTR_FIELDNO (type) = i;
7832 /* Complain if virtual function table field not found. */
7833 if (i < TYPE_N_BASECLASSES (t))
7834 complaint (&symfile_complaints,
7835 _("virtual function table pointer "
7836 "not found when defining class '%s'"),
7837 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7842 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7845 else if (cu->producer
7846 && strncmp (cu->producer,
7847 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7849 /* The IBM XLC compiler does not provide direct indication
7850 of the containing type, but the vtable pointer is
7851 always named __vfp. */
7855 for (i = TYPE_NFIELDS (type) - 1;
7856 i >= TYPE_N_BASECLASSES (type);
7859 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7861 TYPE_VPTR_FIELDNO (type) = i;
7862 TYPE_VPTR_BASETYPE (type) = type;
7869 /* Copy fi.typedef_field_list linked list elements content into the
7870 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7871 if (fi.typedef_field_list)
7873 int i = fi.typedef_field_list_count;
7875 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7876 TYPE_TYPEDEF_FIELD_ARRAY (type)
7877 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7878 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7880 /* Reverse the list order to keep the debug info elements order. */
7883 struct typedef_field *dest, *src;
7885 dest = &TYPE_TYPEDEF_FIELD (type, i);
7886 src = &fi.typedef_field_list->field;
7887 fi.typedef_field_list = fi.typedef_field_list->next;
7892 do_cleanups (back_to);
7894 if (HAVE_CPLUS_STRUCT (type))
7895 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
7898 quirk_gcc_member_function_pointer (type, objfile);
7900 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7901 snapshots) has been known to create a die giving a declaration
7902 for a class that has, as a child, a die giving a definition for a
7903 nested class. So we have to process our children even if the
7904 current die is a declaration. Normally, of course, a declaration
7905 won't have any children at all. */
7907 while (child_die != NULL && child_die->tag)
7909 if (child_die->tag == DW_TAG_member
7910 || child_die->tag == DW_TAG_variable
7911 || child_die->tag == DW_TAG_inheritance
7912 || child_die->tag == DW_TAG_template_value_param
7913 || child_die->tag == DW_TAG_template_type_param)
7918 process_die (child_die, cu);
7920 child_die = sibling_die (child_die);
7923 /* Do not consider external references. According to the DWARF standard,
7924 these DIEs are identified by the fact that they have no byte_size
7925 attribute, and a declaration attribute. */
7926 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7927 || !die_is_declaration (die, cu))
7928 new_symbol (die, type, cu);
7931 /* Given a DW_AT_enumeration_type die, set its type. We do not
7932 complete the type's fields yet, or create any symbols. */
7934 static struct type *
7935 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7937 struct objfile *objfile = cu->objfile;
7939 struct attribute *attr;
7942 /* If the definition of this type lives in .debug_types, read that type.
7943 Don't follow DW_AT_specification though, that will take us back up
7944 the chain and we want to go down. */
7945 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7948 struct dwarf2_cu *type_cu = cu;
7949 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7951 type = read_type_die (type_die, type_cu);
7953 /* TYPE_CU may not be the same as CU.
7954 Ensure TYPE is recorded in CU's type_hash table. */
7955 return set_die_type (die, type, cu);
7958 type = alloc_type (objfile);
7960 TYPE_CODE (type) = TYPE_CODE_ENUM;
7961 name = dwarf2_full_name (NULL, die, cu);
7963 TYPE_TAG_NAME (type) = (char *) name;
7965 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7968 TYPE_LENGTH (type) = DW_UNSND (attr);
7972 TYPE_LENGTH (type) = 0;
7975 /* The enumeration DIE can be incomplete. In Ada, any type can be
7976 declared as private in the package spec, and then defined only
7977 inside the package body. Such types are known as Taft Amendment
7978 Types. When another package uses such a type, an incomplete DIE
7979 may be generated by the compiler. */
7980 if (die_is_declaration (die, cu))
7981 TYPE_STUB (type) = 1;
7983 return set_die_type (die, type, cu);
7986 /* Given a pointer to a die which begins an enumeration, process all
7987 the dies that define the members of the enumeration, and create the
7988 symbol for the enumeration type.
7990 NOTE: We reverse the order of the element list. */
7993 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7995 struct type *this_type;
7997 this_type = get_die_type (die, cu);
7998 if (this_type == NULL)
7999 this_type = read_enumeration_type (die, cu);
8001 if (die->child != NULL)
8003 struct die_info *child_die;
8005 struct field *fields = NULL;
8007 int unsigned_enum = 1;
8012 child_die = die->child;
8013 while (child_die && child_die->tag)
8015 if (child_die->tag != DW_TAG_enumerator)
8017 process_die (child_die, cu);
8021 name = dwarf2_name (child_die, cu);
8024 sym = new_symbol (child_die, this_type, cu);
8025 if (SYMBOL_VALUE (sym) < 0)
8030 else if ((mask & SYMBOL_VALUE (sym)) != 0)
8033 mask |= SYMBOL_VALUE (sym);
8035 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
8037 fields = (struct field *)
8039 (num_fields + DW_FIELD_ALLOC_CHUNK)
8040 * sizeof (struct field));
8043 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
8044 FIELD_TYPE (fields[num_fields]) = NULL;
8045 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
8046 FIELD_BITSIZE (fields[num_fields]) = 0;
8052 child_die = sibling_die (child_die);
8057 TYPE_NFIELDS (this_type) = num_fields;
8058 TYPE_FIELDS (this_type) = (struct field *)
8059 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
8060 memcpy (TYPE_FIELDS (this_type), fields,
8061 sizeof (struct field) * num_fields);
8065 TYPE_UNSIGNED (this_type) = 1;
8067 TYPE_FLAG_ENUM (this_type) = 1;
8070 /* If we are reading an enum from a .debug_types unit, and the enum
8071 is a declaration, and the enum is not the signatured type in the
8072 unit, then we do not want to add a symbol for it. Adding a
8073 symbol would in some cases obscure the true definition of the
8074 enum, giving users an incomplete type when the definition is
8075 actually available. Note that we do not want to do this for all
8076 enums which are just declarations, because C++0x allows forward
8077 enum declarations. */
8078 if (cu->per_cu->debug_types_section
8079 && die_is_declaration (die, cu))
8081 struct signatured_type *type_sig;
8084 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
8085 cu->per_cu->debug_types_section,
8086 cu->per_cu->offset);
8087 if (type_sig->per_cu.offset + type_sig->type_offset
8092 new_symbol (die, this_type, cu);
8095 /* Extract all information from a DW_TAG_array_type DIE and put it in
8096 the DIE's type field. For now, this only handles one dimensional
8099 static struct type *
8100 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
8102 struct objfile *objfile = cu->objfile;
8103 struct die_info *child_die;
8105 struct type *element_type, *range_type, *index_type;
8106 struct type **range_types = NULL;
8107 struct attribute *attr;
8109 struct cleanup *back_to;
8112 element_type = die_type (die, cu);
8114 /* The die_type call above may have already set the type for this DIE. */
8115 type = get_die_type (die, cu);
8119 /* Irix 6.2 native cc creates array types without children for
8120 arrays with unspecified length. */
8121 if (die->child == NULL)
8123 index_type = objfile_type (objfile)->builtin_int;
8124 range_type = create_range_type (NULL, index_type, 0, -1);
8125 type = create_array_type (NULL, element_type, range_type);
8126 return set_die_type (die, type, cu);
8129 back_to = make_cleanup (null_cleanup, NULL);
8130 child_die = die->child;
8131 while (child_die && child_die->tag)
8133 if (child_die->tag == DW_TAG_subrange_type)
8135 struct type *child_type = read_type_die (child_die, cu);
8137 if (child_type != NULL)
8139 /* The range type was succesfully read. Save it for the
8140 array type creation. */
8141 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
8143 range_types = (struct type **)
8144 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
8145 * sizeof (struct type *));
8147 make_cleanup (free_current_contents, &range_types);
8149 range_types[ndim++] = child_type;
8152 child_die = sibling_die (child_die);
8155 /* Dwarf2 dimensions are output from left to right, create the
8156 necessary array types in backwards order. */
8158 type = element_type;
8160 if (read_array_order (die, cu) == DW_ORD_col_major)
8165 type = create_array_type (NULL, type, range_types[i++]);
8170 type = create_array_type (NULL, type, range_types[ndim]);
8173 /* Understand Dwarf2 support for vector types (like they occur on
8174 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8175 array type. This is not part of the Dwarf2/3 standard yet, but a
8176 custom vendor extension. The main difference between a regular
8177 array and the vector variant is that vectors are passed by value
8179 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
8181 make_vector_type (type);
8183 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8184 implementation may choose to implement triple vectors using this
8186 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8189 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
8190 TYPE_LENGTH (type) = DW_UNSND (attr);
8192 complaint (&symfile_complaints,
8193 _("DW_AT_byte_size for array type smaller "
8194 "than the total size of elements"));
8197 name = dwarf2_name (die, cu);
8199 TYPE_NAME (type) = name;
8201 /* Install the type in the die. */
8202 set_die_type (die, type, cu);
8204 /* set_die_type should be already done. */
8205 set_descriptive_type (type, die, cu);
8207 do_cleanups (back_to);
8212 static enum dwarf_array_dim_ordering
8213 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
8215 struct attribute *attr;
8217 attr = dwarf2_attr (die, DW_AT_ordering, cu);
8219 if (attr) return DW_SND (attr);
8221 /* GNU F77 is a special case, as at 08/2004 array type info is the
8222 opposite order to the dwarf2 specification, but data is still
8223 laid out as per normal fortran.
8225 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8226 version checking. */
8228 if (cu->language == language_fortran
8229 && cu->producer && strstr (cu->producer, "GNU F77"))
8231 return DW_ORD_row_major;
8234 switch (cu->language_defn->la_array_ordering)
8236 case array_column_major:
8237 return DW_ORD_col_major;
8238 case array_row_major:
8240 return DW_ORD_row_major;
8244 /* Extract all information from a DW_TAG_set_type DIE and put it in
8245 the DIE's type field. */
8247 static struct type *
8248 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
8250 struct type *domain_type, *set_type;
8251 struct attribute *attr;
8253 domain_type = die_type (die, cu);
8255 /* The die_type call above may have already set the type for this DIE. */
8256 set_type = get_die_type (die, cu);
8260 set_type = create_set_type (NULL, domain_type);
8262 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8264 TYPE_LENGTH (set_type) = DW_UNSND (attr);
8266 return set_die_type (die, set_type, cu);
8269 /* First cut: install each common block member as a global variable. */
8272 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
8274 struct die_info *child_die;
8275 struct attribute *attr;
8277 CORE_ADDR base = (CORE_ADDR) 0;
8279 attr = dwarf2_attr (die, DW_AT_location, cu);
8282 /* Support the .debug_loc offsets. */
8283 if (attr_form_is_block (attr))
8285 base = decode_locdesc (DW_BLOCK (attr), cu);
8287 else if (attr_form_is_section_offset (attr))
8289 dwarf2_complex_location_expr_complaint ();
8293 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8294 "common block member");
8297 if (die->child != NULL)
8299 child_die = die->child;
8300 while (child_die && child_die->tag)
8304 sym = new_symbol (child_die, NULL, cu);
8306 && handle_data_member_location (child_die, cu, &offset))
8308 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
8309 add_symbol_to_list (sym, &global_symbols);
8311 child_die = sibling_die (child_die);
8316 /* Create a type for a C++ namespace. */
8318 static struct type *
8319 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
8321 struct objfile *objfile = cu->objfile;
8322 const char *previous_prefix, *name;
8326 /* For extensions, reuse the type of the original namespace. */
8327 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
8329 struct die_info *ext_die;
8330 struct dwarf2_cu *ext_cu = cu;
8332 ext_die = dwarf2_extension (die, &ext_cu);
8333 type = read_type_die (ext_die, ext_cu);
8335 /* EXT_CU may not be the same as CU.
8336 Ensure TYPE is recorded in CU's type_hash table. */
8337 return set_die_type (die, type, cu);
8340 name = namespace_name (die, &is_anonymous, cu);
8342 /* Now build the name of the current namespace. */
8344 previous_prefix = determine_prefix (die, cu);
8345 if (previous_prefix[0] != '\0')
8346 name = typename_concat (&objfile->objfile_obstack,
8347 previous_prefix, name, 0, cu);
8349 /* Create the type. */
8350 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8352 TYPE_NAME (type) = (char *) name;
8353 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8355 return set_die_type (die, type, cu);
8358 /* Read a C++ namespace. */
8361 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8363 struct objfile *objfile = cu->objfile;
8366 /* Add a symbol associated to this if we haven't seen the namespace
8367 before. Also, add a using directive if it's an anonymous
8370 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8374 type = read_type_die (die, cu);
8375 new_symbol (die, type, cu);
8377 namespace_name (die, &is_anonymous, cu);
8380 const char *previous_prefix = determine_prefix (die, cu);
8382 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8383 NULL, NULL, &objfile->objfile_obstack);
8387 if (die->child != NULL)
8389 struct die_info *child_die = die->child;
8391 while (child_die && child_die->tag)
8393 process_die (child_die, cu);
8394 child_die = sibling_die (child_die);
8399 /* Read a Fortran module as type. This DIE can be only a declaration used for
8400 imported module. Still we need that type as local Fortran "use ... only"
8401 declaration imports depend on the created type in determine_prefix. */
8403 static struct type *
8404 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8406 struct objfile *objfile = cu->objfile;
8410 module_name = dwarf2_name (die, cu);
8412 complaint (&symfile_complaints,
8413 _("DW_TAG_module has no name, offset 0x%x"),
8415 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8417 /* determine_prefix uses TYPE_TAG_NAME. */
8418 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8420 return set_die_type (die, type, cu);
8423 /* Read a Fortran module. */
8426 read_module (struct die_info *die, struct dwarf2_cu *cu)
8428 struct die_info *child_die = die->child;
8430 while (child_die && child_die->tag)
8432 process_die (child_die, cu);
8433 child_die = sibling_die (child_die);
8437 /* Return the name of the namespace represented by DIE. Set
8438 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8442 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8444 struct die_info *current_die;
8445 const char *name = NULL;
8447 /* Loop through the extensions until we find a name. */
8449 for (current_die = die;
8450 current_die != NULL;
8451 current_die = dwarf2_extension (die, &cu))
8453 name = dwarf2_name (current_die, cu);
8458 /* Is it an anonymous namespace? */
8460 *is_anonymous = (name == NULL);
8462 name = CP_ANONYMOUS_NAMESPACE_STR;
8467 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8468 the user defined type vector. */
8470 static struct type *
8471 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8473 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8474 struct comp_unit_head *cu_header = &cu->header;
8476 struct attribute *attr_byte_size;
8477 struct attribute *attr_address_class;
8478 int byte_size, addr_class;
8479 struct type *target_type;
8481 target_type = die_type (die, cu);
8483 /* The die_type call above may have already set the type for this DIE. */
8484 type = get_die_type (die, cu);
8488 type = lookup_pointer_type (target_type);
8490 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8492 byte_size = DW_UNSND (attr_byte_size);
8494 byte_size = cu_header->addr_size;
8496 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8497 if (attr_address_class)
8498 addr_class = DW_UNSND (attr_address_class);
8500 addr_class = DW_ADDR_none;
8502 /* If the pointer size or address class is different than the
8503 default, create a type variant marked as such and set the
8504 length accordingly. */
8505 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8507 if (gdbarch_address_class_type_flags_p (gdbarch))
8511 type_flags = gdbarch_address_class_type_flags
8512 (gdbarch, byte_size, addr_class);
8513 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8515 type = make_type_with_address_space (type, type_flags);
8517 else if (TYPE_LENGTH (type) != byte_size)
8519 complaint (&symfile_complaints,
8520 _("invalid pointer size %d"), byte_size);
8524 /* Should we also complain about unhandled address classes? */
8528 TYPE_LENGTH (type) = byte_size;
8529 return set_die_type (die, type, cu);
8532 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8533 the user defined type vector. */
8535 static struct type *
8536 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8539 struct type *to_type;
8540 struct type *domain;
8542 to_type = die_type (die, cu);
8543 domain = die_containing_type (die, cu);
8545 /* The calls above may have already set the type for this DIE. */
8546 type = get_die_type (die, cu);
8550 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8551 type = lookup_methodptr_type (to_type);
8553 type = lookup_memberptr_type (to_type, domain);
8555 return set_die_type (die, type, cu);
8558 /* Extract all information from a DW_TAG_reference_type DIE and add to
8559 the user defined type vector. */
8561 static struct type *
8562 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8564 struct comp_unit_head *cu_header = &cu->header;
8565 struct type *type, *target_type;
8566 struct attribute *attr;
8568 target_type = die_type (die, cu);
8570 /* The die_type call above may have already set the type for this DIE. */
8571 type = get_die_type (die, cu);
8575 type = lookup_reference_type (target_type);
8576 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8579 TYPE_LENGTH (type) = DW_UNSND (attr);
8583 TYPE_LENGTH (type) = cu_header->addr_size;
8585 return set_die_type (die, type, cu);
8588 static struct type *
8589 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8591 struct type *base_type, *cv_type;
8593 base_type = die_type (die, cu);
8595 /* The die_type call above may have already set the type for this DIE. */
8596 cv_type = get_die_type (die, cu);
8600 /* In case the const qualifier is applied to an array type, the element type
8601 is so qualified, not the array type (section 6.7.3 of C99). */
8602 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8604 struct type *el_type, *inner_array;
8606 base_type = copy_type (base_type);
8607 inner_array = base_type;
8609 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8611 TYPE_TARGET_TYPE (inner_array) =
8612 copy_type (TYPE_TARGET_TYPE (inner_array));
8613 inner_array = TYPE_TARGET_TYPE (inner_array);
8616 el_type = TYPE_TARGET_TYPE (inner_array);
8617 TYPE_TARGET_TYPE (inner_array) =
8618 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8620 return set_die_type (die, base_type, cu);
8623 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8624 return set_die_type (die, cv_type, cu);
8627 static struct type *
8628 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8630 struct type *base_type, *cv_type;
8632 base_type = die_type (die, cu);
8634 /* The die_type call above may have already set the type for this DIE. */
8635 cv_type = get_die_type (die, cu);
8639 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8640 return set_die_type (die, cv_type, cu);
8643 /* Extract all information from a DW_TAG_string_type DIE and add to
8644 the user defined type vector. It isn't really a user defined type,
8645 but it behaves like one, with other DIE's using an AT_user_def_type
8646 attribute to reference it. */
8648 static struct type *
8649 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8651 struct objfile *objfile = cu->objfile;
8652 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8653 struct type *type, *range_type, *index_type, *char_type;
8654 struct attribute *attr;
8655 unsigned int length;
8657 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8660 length = DW_UNSND (attr);
8664 /* Check for the DW_AT_byte_size attribute. */
8665 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8668 length = DW_UNSND (attr);
8676 index_type = objfile_type (objfile)->builtin_int;
8677 range_type = create_range_type (NULL, index_type, 1, length);
8678 char_type = language_string_char_type (cu->language_defn, gdbarch);
8679 type = create_string_type (NULL, char_type, range_type);
8681 return set_die_type (die, type, cu);
8684 /* Handle DIES due to C code like:
8688 int (*funcp)(int a, long l);
8692 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8694 static struct type *
8695 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8697 struct objfile *objfile = cu->objfile;
8698 struct type *type; /* Type that this function returns. */
8699 struct type *ftype; /* Function that returns above type. */
8700 struct attribute *attr;
8702 type = die_type (die, cu);
8704 /* The die_type call above may have already set the type for this DIE. */
8705 ftype = get_die_type (die, cu);
8709 ftype = lookup_function_type (type);
8711 /* All functions in C++, Pascal and Java have prototypes. */
8712 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8713 if ((attr && (DW_UNSND (attr) != 0))
8714 || cu->language == language_cplus
8715 || cu->language == language_java
8716 || cu->language == language_pascal)
8717 TYPE_PROTOTYPED (ftype) = 1;
8718 else if (producer_is_realview (cu->producer))
8719 /* RealView does not emit DW_AT_prototyped. We can not
8720 distinguish prototyped and unprototyped functions; default to
8721 prototyped, since that is more common in modern code (and
8722 RealView warns about unprototyped functions). */
8723 TYPE_PROTOTYPED (ftype) = 1;
8725 /* Store the calling convention in the type if it's available in
8726 the subroutine die. Otherwise set the calling convention to
8727 the default value DW_CC_normal. */
8728 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8730 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8731 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8732 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8734 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8736 /* We need to add the subroutine type to the die immediately so
8737 we don't infinitely recurse when dealing with parameters
8738 declared as the same subroutine type. */
8739 set_die_type (die, ftype, cu);
8741 if (die->child != NULL)
8743 struct type *void_type = objfile_type (objfile)->builtin_void;
8744 struct die_info *child_die;
8745 int nparams, iparams;
8747 /* Count the number of parameters.
8748 FIXME: GDB currently ignores vararg functions, but knows about
8749 vararg member functions. */
8751 child_die = die->child;
8752 while (child_die && child_die->tag)
8754 if (child_die->tag == DW_TAG_formal_parameter)
8756 else if (child_die->tag == DW_TAG_unspecified_parameters)
8757 TYPE_VARARGS (ftype) = 1;
8758 child_die = sibling_die (child_die);
8761 /* Allocate storage for parameters and fill them in. */
8762 TYPE_NFIELDS (ftype) = nparams;
8763 TYPE_FIELDS (ftype) = (struct field *)
8764 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8766 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8767 even if we error out during the parameters reading below. */
8768 for (iparams = 0; iparams < nparams; iparams++)
8769 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8772 child_die = die->child;
8773 while (child_die && child_die->tag)
8775 if (child_die->tag == DW_TAG_formal_parameter)
8777 struct type *arg_type;
8779 /* DWARF version 2 has no clean way to discern C++
8780 static and non-static member functions. G++ helps
8781 GDB by marking the first parameter for non-static
8782 member functions (which is the this pointer) as
8783 artificial. We pass this information to
8784 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8786 DWARF version 3 added DW_AT_object_pointer, which GCC
8787 4.5 does not yet generate. */
8788 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8790 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8793 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8795 /* GCC/43521: In java, the formal parameter
8796 "this" is sometimes not marked with DW_AT_artificial. */
8797 if (cu->language == language_java)
8799 const char *name = dwarf2_name (child_die, cu);
8801 if (name && !strcmp (name, "this"))
8802 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8805 arg_type = die_type (child_die, cu);
8807 /* RealView does not mark THIS as const, which the testsuite
8808 expects. GCC marks THIS as const in method definitions,
8809 but not in the class specifications (GCC PR 43053). */
8810 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8811 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8814 struct dwarf2_cu *arg_cu = cu;
8815 const char *name = dwarf2_name (child_die, cu);
8817 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8820 /* If the compiler emits this, use it. */
8821 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8824 else if (name && strcmp (name, "this") == 0)
8825 /* Function definitions will have the argument names. */
8827 else if (name == NULL && iparams == 0)
8828 /* Declarations may not have the names, so like
8829 elsewhere in GDB, assume an artificial first
8830 argument is "this". */
8834 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8838 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8841 child_die = sibling_die (child_die);
8848 static struct type *
8849 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8851 struct objfile *objfile = cu->objfile;
8852 const char *name = NULL;
8853 struct type *this_type, *target_type;
8855 name = dwarf2_full_name (NULL, die, cu);
8856 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8857 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8858 TYPE_NAME (this_type) = (char *) name;
8859 set_die_type (die, this_type, cu);
8860 target_type = die_type (die, cu);
8861 if (target_type != this_type)
8862 TYPE_TARGET_TYPE (this_type) = target_type;
8865 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8866 spec and cause infinite loops in GDB. */
8867 complaint (&symfile_complaints,
8868 _("Self-referential DW_TAG_typedef "
8869 "- DIE at 0x%x [in module %s]"),
8870 die->offset, objfile->name);
8871 TYPE_TARGET_TYPE (this_type) = NULL;
8876 /* Find a representation of a given base type and install
8877 it in the TYPE field of the die. */
8879 static struct type *
8880 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8882 struct objfile *objfile = cu->objfile;
8884 struct attribute *attr;
8885 int encoding = 0, size = 0;
8887 enum type_code code = TYPE_CODE_INT;
8889 struct type *target_type = NULL;
8891 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8894 encoding = DW_UNSND (attr);
8896 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8899 size = DW_UNSND (attr);
8901 name = dwarf2_name (die, cu);
8904 complaint (&symfile_complaints,
8905 _("DW_AT_name missing from DW_TAG_base_type"));
8910 case DW_ATE_address:
8911 /* Turn DW_ATE_address into a void * pointer. */
8912 code = TYPE_CODE_PTR;
8913 type_flags |= TYPE_FLAG_UNSIGNED;
8914 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8916 case DW_ATE_boolean:
8917 code = TYPE_CODE_BOOL;
8918 type_flags |= TYPE_FLAG_UNSIGNED;
8920 case DW_ATE_complex_float:
8921 code = TYPE_CODE_COMPLEX;
8922 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8924 case DW_ATE_decimal_float:
8925 code = TYPE_CODE_DECFLOAT;
8928 code = TYPE_CODE_FLT;
8932 case DW_ATE_unsigned:
8933 type_flags |= TYPE_FLAG_UNSIGNED;
8934 if (cu->language == language_fortran
8936 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
8937 code = TYPE_CODE_CHAR;
8939 case DW_ATE_signed_char:
8940 if (cu->language == language_ada || cu->language == language_m2
8941 || cu->language == language_pascal
8942 || cu->language == language_fortran)
8943 code = TYPE_CODE_CHAR;
8945 case DW_ATE_unsigned_char:
8946 if (cu->language == language_ada || cu->language == language_m2
8947 || cu->language == language_pascal
8948 || cu->language == language_fortran)
8949 code = TYPE_CODE_CHAR;
8950 type_flags |= TYPE_FLAG_UNSIGNED;
8953 /* We just treat this as an integer and then recognize the
8954 type by name elsewhere. */
8958 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8959 dwarf_type_encoding_name (encoding));
8963 type = init_type (code, size, type_flags, NULL, objfile);
8964 TYPE_NAME (type) = name;
8965 TYPE_TARGET_TYPE (type) = target_type;
8967 if (name && strcmp (name, "char") == 0)
8968 TYPE_NOSIGN (type) = 1;
8970 return set_die_type (die, type, cu);
8973 /* Read the given DW_AT_subrange DIE. */
8975 static struct type *
8976 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8978 struct type *base_type;
8979 struct type *range_type;
8980 struct attribute *attr;
8984 LONGEST negative_mask;
8986 base_type = die_type (die, cu);
8987 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8988 check_typedef (base_type);
8990 /* The die_type call above may have already set the type for this DIE. */
8991 range_type = get_die_type (die, cu);
8995 if (cu->language == language_fortran)
8997 /* FORTRAN implies a lower bound of 1, if not given. */
9001 /* FIXME: For variable sized arrays either of these could be
9002 a variable rather than a constant value. We'll allow it,
9003 but we don't know how to handle it. */
9004 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
9006 low = dwarf2_get_attr_constant_value (attr, 0);
9008 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
9011 if (attr_form_is_block (attr) || is_ref_attr (attr))
9013 /* GCC encodes arrays with unspecified or dynamic length
9014 with a DW_FORM_block1 attribute or a reference attribute.
9015 FIXME: GDB does not yet know how to handle dynamic
9016 arrays properly, treat them as arrays with unspecified
9019 FIXME: jimb/2003-09-22: GDB does not really know
9020 how to handle arrays of unspecified length
9021 either; we just represent them as zero-length
9022 arrays. Choose an appropriate upper bound given
9023 the lower bound we've computed above. */
9027 high = dwarf2_get_attr_constant_value (attr, 1);
9031 attr = dwarf2_attr (die, DW_AT_count, cu);
9034 int count = dwarf2_get_attr_constant_value (attr, 1);
9035 high = low + count - 1;
9039 /* Unspecified array length. */
9044 /* Dwarf-2 specifications explicitly allows to create subrange types
9045 without specifying a base type.
9046 In that case, the base type must be set to the type of
9047 the lower bound, upper bound or count, in that order, if any of these
9048 three attributes references an object that has a type.
9049 If no base type is found, the Dwarf-2 specifications say that
9050 a signed integer type of size equal to the size of an address should
9052 For the following C code: `extern char gdb_int [];'
9053 GCC produces an empty range DIE.
9054 FIXME: muller/2010-05-28: Possible references to object for low bound,
9055 high bound or count are not yet handled by this code. */
9056 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
9058 struct objfile *objfile = cu->objfile;
9059 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9060 int addr_size = gdbarch_addr_bit (gdbarch) /8;
9061 struct type *int_type = objfile_type (objfile)->builtin_int;
9063 /* Test "int", "long int", and "long long int" objfile types,
9064 and select the first one having a size above or equal to the
9065 architecture address size. */
9066 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9067 base_type = int_type;
9070 int_type = objfile_type (objfile)->builtin_long;
9071 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9072 base_type = int_type;
9075 int_type = objfile_type (objfile)->builtin_long_long;
9076 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9077 base_type = int_type;
9083 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
9084 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
9085 low |= negative_mask;
9086 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
9087 high |= negative_mask;
9089 range_type = create_range_type (NULL, base_type, low, high);
9091 /* Mark arrays with dynamic length at least as an array of unspecified
9092 length. GDB could check the boundary but before it gets implemented at
9093 least allow accessing the array elements. */
9094 if (attr && attr_form_is_block (attr))
9095 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9097 /* Ada expects an empty array on no boundary attributes. */
9098 if (attr == NULL && cu->language != language_ada)
9099 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9101 name = dwarf2_name (die, cu);
9103 TYPE_NAME (range_type) = name;
9105 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
9107 TYPE_LENGTH (range_type) = DW_UNSND (attr);
9109 set_die_type (die, range_type, cu);
9111 /* set_die_type should be already done. */
9112 set_descriptive_type (range_type, die, cu);
9117 static struct type *
9118 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
9122 /* For now, we only support the C meaning of an unspecified type: void. */
9124 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
9125 TYPE_NAME (type) = dwarf2_name (die, cu);
9127 return set_die_type (die, type, cu);
9130 /* Trivial hash function for die_info: the hash value of a DIE
9131 is its offset in .debug_info for this objfile. */
9134 die_hash (const void *item)
9136 const struct die_info *die = item;
9141 /* Trivial comparison function for die_info structures: two DIEs
9142 are equal if they have the same offset. */
9145 die_eq (const void *item_lhs, const void *item_rhs)
9147 const struct die_info *die_lhs = item_lhs;
9148 const struct die_info *die_rhs = item_rhs;
9150 return die_lhs->offset == die_rhs->offset;
9153 /* Read a whole compilation unit into a linked list of dies. */
9155 static struct die_info *
9156 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
9158 struct die_reader_specs reader_specs;
9159 int read_abbrevs = 0;
9160 struct cleanup *back_to = NULL;
9161 struct die_info *die;
9163 if (cu->dwarf2_abbrevs == NULL)
9165 dwarf2_read_abbrevs (cu);
9166 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
9170 gdb_assert (cu->die_hash == NULL);
9172 = htab_create_alloc_ex (cu->header.length / 12,
9176 &cu->comp_unit_obstack,
9177 hashtab_obstack_allocate,
9178 dummy_obstack_deallocate);
9180 init_cu_die_reader (&reader_specs, cu);
9182 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
9185 do_cleanups (back_to);
9190 /* Main entry point for reading a DIE and all children.
9191 Read the DIE and dump it if requested. */
9193 static struct die_info *
9194 read_die_and_children (const struct die_reader_specs *reader,
9196 gdb_byte **new_info_ptr,
9197 struct die_info *parent)
9199 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
9200 new_info_ptr, parent);
9202 if (dwarf2_die_debug)
9204 fprintf_unfiltered (gdb_stdlog,
9205 "\nRead die from %s of %s:\n",
9206 (reader->cu->per_cu->debug_types_section
9209 reader->abfd->filename);
9210 dump_die (result, dwarf2_die_debug);
9216 /* Read a single die and all its descendents. Set the die's sibling
9217 field to NULL; set other fields in the die correctly, and set all
9218 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9219 location of the info_ptr after reading all of those dies. PARENT
9220 is the parent of the die in question. */
9222 static struct die_info *
9223 read_die_and_children_1 (const struct die_reader_specs *reader,
9225 gdb_byte **new_info_ptr,
9226 struct die_info *parent)
9228 struct die_info *die;
9232 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
9235 *new_info_ptr = cur_ptr;
9238 store_in_ref_table (die, reader->cu);
9241 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
9245 *new_info_ptr = cur_ptr;
9248 die->sibling = NULL;
9249 die->parent = parent;
9253 /* Read a die, all of its descendents, and all of its siblings; set
9254 all of the fields of all of the dies correctly. Arguments are as
9255 in read_die_and_children. */
9257 static struct die_info *
9258 read_die_and_siblings (const struct die_reader_specs *reader,
9260 gdb_byte **new_info_ptr,
9261 struct die_info *parent)
9263 struct die_info *first_die, *last_sibling;
9267 first_die = last_sibling = NULL;
9271 struct die_info *die
9272 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
9276 *new_info_ptr = cur_ptr;
9283 last_sibling->sibling = die;
9289 /* Read the die from the .debug_info section buffer. Set DIEP to
9290 point to a newly allocated die with its information, except for its
9291 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9292 whether the die has children or not. */
9295 read_full_die (const struct die_reader_specs *reader,
9296 struct die_info **diep, gdb_byte *info_ptr,
9299 unsigned int abbrev_number, bytes_read, i, offset;
9300 struct abbrev_info *abbrev;
9301 struct die_info *die;
9302 struct dwarf2_cu *cu = reader->cu;
9303 bfd *abfd = reader->abfd;
9305 offset = info_ptr - reader->buffer;
9306 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9307 info_ptr += bytes_read;
9315 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
9317 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9319 bfd_get_filename (abfd));
9321 die = dwarf_alloc_die (cu, abbrev->num_attrs);
9322 die->offset = offset;
9323 die->tag = abbrev->tag;
9324 die->abbrev = abbrev_number;
9326 die->num_attrs = abbrev->num_attrs;
9328 for (i = 0; i < abbrev->num_attrs; ++i)
9329 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
9330 abfd, info_ptr, cu);
9333 *has_children = abbrev->has_children;
9337 /* In DWARF version 2, the description of the debugging information is
9338 stored in a separate .debug_abbrev section. Before we read any
9339 dies from a section we read in all abbreviations and install them
9340 in a hash table. This function also sets flags in CU describing
9341 the data found in the abbrev table. */
9344 dwarf2_read_abbrevs (struct dwarf2_cu *cu)
9346 bfd *abfd = cu->objfile->obfd;
9347 struct comp_unit_head *cu_header = &cu->header;
9348 gdb_byte *abbrev_ptr;
9349 struct abbrev_info *cur_abbrev;
9350 unsigned int abbrev_number, bytes_read, abbrev_name;
9351 unsigned int abbrev_form, hash_number;
9352 struct attr_abbrev *cur_attrs;
9353 unsigned int allocated_attrs;
9355 /* Initialize dwarf2 abbrevs. */
9356 obstack_init (&cu->abbrev_obstack);
9357 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9359 * sizeof (struct abbrev_info *)));
9360 memset (cu->dwarf2_abbrevs, 0,
9361 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9363 dwarf2_read_section (dwarf2_per_objfile->objfile,
9364 &dwarf2_per_objfile->abbrev);
9365 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
9366 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9367 abbrev_ptr += bytes_read;
9369 allocated_attrs = ATTR_ALLOC_CHUNK;
9370 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9372 /* Loop until we reach an abbrev number of 0. */
9373 while (abbrev_number)
9375 cur_abbrev = dwarf_alloc_abbrev (cu);
9377 /* read in abbrev header */
9378 cur_abbrev->number = abbrev_number;
9379 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9380 abbrev_ptr += bytes_read;
9381 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9384 /* now read in declarations */
9385 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9386 abbrev_ptr += bytes_read;
9387 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9388 abbrev_ptr += bytes_read;
9391 if (cur_abbrev->num_attrs == allocated_attrs)
9393 allocated_attrs += ATTR_ALLOC_CHUNK;
9395 = xrealloc (cur_attrs, (allocated_attrs
9396 * sizeof (struct attr_abbrev)));
9399 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9400 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9401 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9402 abbrev_ptr += bytes_read;
9403 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9404 abbrev_ptr += bytes_read;
9407 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9408 (cur_abbrev->num_attrs
9409 * sizeof (struct attr_abbrev)));
9410 memcpy (cur_abbrev->attrs, cur_attrs,
9411 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9413 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9414 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9415 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9417 /* Get next abbreviation.
9418 Under Irix6 the abbreviations for a compilation unit are not
9419 always properly terminated with an abbrev number of 0.
9420 Exit loop if we encounter an abbreviation which we have
9421 already read (which means we are about to read the abbreviations
9422 for the next compile unit) or if the end of the abbreviation
9423 table is reached. */
9424 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9425 >= dwarf2_per_objfile->abbrev.size)
9427 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9428 abbrev_ptr += bytes_read;
9429 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9436 /* Release the memory used by the abbrev table for a compilation unit. */
9439 dwarf2_free_abbrev_table (void *ptr_to_cu)
9441 struct dwarf2_cu *cu = ptr_to_cu;
9443 obstack_free (&cu->abbrev_obstack, NULL);
9444 cu->dwarf2_abbrevs = NULL;
9447 /* Lookup an abbrev_info structure in the abbrev hash table. */
9449 static struct abbrev_info *
9450 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9452 unsigned int hash_number;
9453 struct abbrev_info *abbrev;
9455 hash_number = number % ABBREV_HASH_SIZE;
9456 abbrev = cu->dwarf2_abbrevs[hash_number];
9460 if (abbrev->number == number)
9463 abbrev = abbrev->next;
9468 /* Returns nonzero if TAG represents a type that we might generate a partial
9472 is_type_tag_for_partial (int tag)
9477 /* Some types that would be reasonable to generate partial symbols for,
9478 that we don't at present. */
9479 case DW_TAG_array_type:
9480 case DW_TAG_file_type:
9481 case DW_TAG_ptr_to_member_type:
9482 case DW_TAG_set_type:
9483 case DW_TAG_string_type:
9484 case DW_TAG_subroutine_type:
9486 case DW_TAG_base_type:
9487 case DW_TAG_class_type:
9488 case DW_TAG_interface_type:
9489 case DW_TAG_enumeration_type:
9490 case DW_TAG_structure_type:
9491 case DW_TAG_subrange_type:
9492 case DW_TAG_typedef:
9493 case DW_TAG_union_type:
9500 /* Load all DIEs that are interesting for partial symbols into memory. */
9502 static struct partial_die_info *
9503 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9504 int building_psymtab, struct dwarf2_cu *cu)
9506 struct objfile *objfile = cu->objfile;
9507 struct partial_die_info *part_die;
9508 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9509 struct abbrev_info *abbrev;
9510 unsigned int bytes_read;
9511 unsigned int load_all = 0;
9513 int nesting_level = 1;
9518 if (cu->per_cu && cu->per_cu->load_all_dies)
9522 = htab_create_alloc_ex (cu->header.length / 12,
9526 &cu->comp_unit_obstack,
9527 hashtab_obstack_allocate,
9528 dummy_obstack_deallocate);
9530 part_die = obstack_alloc (&cu->comp_unit_obstack,
9531 sizeof (struct partial_die_info));
9535 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9537 /* A NULL abbrev means the end of a series of children. */
9540 if (--nesting_level == 0)
9542 /* PART_DIE was probably the last thing allocated on the
9543 comp_unit_obstack, so we could call obstack_free
9544 here. We don't do that because the waste is small,
9545 and will be cleaned up when we're done with this
9546 compilation unit. This way, we're also more robust
9547 against other users of the comp_unit_obstack. */
9550 info_ptr += bytes_read;
9551 last_die = parent_die;
9552 parent_die = parent_die->die_parent;
9556 /* Check for template arguments. We never save these; if
9557 they're seen, we just mark the parent, and go on our way. */
9558 if (parent_die != NULL
9559 && cu->language == language_cplus
9560 && (abbrev->tag == DW_TAG_template_type_param
9561 || abbrev->tag == DW_TAG_template_value_param))
9563 parent_die->has_template_arguments = 1;
9567 /* We don't need a partial DIE for the template argument. */
9568 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9574 /* We only recurse into subprograms looking for template arguments.
9575 Skip their other children. */
9577 && cu->language == language_cplus
9578 && parent_die != NULL
9579 && parent_die->tag == DW_TAG_subprogram)
9581 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9585 /* Check whether this DIE is interesting enough to save. Normally
9586 we would not be interested in members here, but there may be
9587 later variables referencing them via DW_AT_specification (for
9590 && !is_type_tag_for_partial (abbrev->tag)
9591 && abbrev->tag != DW_TAG_constant
9592 && abbrev->tag != DW_TAG_enumerator
9593 && abbrev->tag != DW_TAG_subprogram
9594 && abbrev->tag != DW_TAG_lexical_block
9595 && abbrev->tag != DW_TAG_variable
9596 && abbrev->tag != DW_TAG_namespace
9597 && abbrev->tag != DW_TAG_module
9598 && abbrev->tag != DW_TAG_member)
9600 /* Otherwise we skip to the next sibling, if any. */
9601 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9605 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9606 buffer, info_ptr, cu);
9608 /* This two-pass algorithm for processing partial symbols has a
9609 high cost in cache pressure. Thus, handle some simple cases
9610 here which cover the majority of C partial symbols. DIEs
9611 which neither have specification tags in them, nor could have
9612 specification tags elsewhere pointing at them, can simply be
9613 processed and discarded.
9615 This segment is also optional; scan_partial_symbols and
9616 add_partial_symbol will handle these DIEs if we chain
9617 them in normally. When compilers which do not emit large
9618 quantities of duplicate debug information are more common,
9619 this code can probably be removed. */
9621 /* Any complete simple types at the top level (pretty much all
9622 of them, for a language without namespaces), can be processed
9624 if (parent_die == NULL
9625 && part_die->has_specification == 0
9626 && part_die->is_declaration == 0
9627 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9628 || part_die->tag == DW_TAG_base_type
9629 || part_die->tag == DW_TAG_subrange_type))
9631 if (building_psymtab && part_die->name != NULL)
9632 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9633 VAR_DOMAIN, LOC_TYPEDEF,
9634 &objfile->static_psymbols,
9635 0, (CORE_ADDR) 0, cu->language, objfile);
9636 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9640 /* The exception for DW_TAG_typedef with has_children above is
9641 a workaround of GCC PR debug/47510. In the case of this complaint
9642 type_name_no_tag_or_error will error on such types later.
9644 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9645 it could not find the child DIEs referenced later, this is checked
9646 above. In correct DWARF DW_TAG_typedef should have no children. */
9648 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9649 complaint (&symfile_complaints,
9650 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9651 "- DIE at 0x%x [in module %s]"),
9652 part_die->offset, objfile->name);
9654 /* If we're at the second level, and we're an enumerator, and
9655 our parent has no specification (meaning possibly lives in a
9656 namespace elsewhere), then we can add the partial symbol now
9657 instead of queueing it. */
9658 if (part_die->tag == DW_TAG_enumerator
9659 && parent_die != NULL
9660 && parent_die->die_parent == NULL
9661 && parent_die->tag == DW_TAG_enumeration_type
9662 && parent_die->has_specification == 0)
9664 if (part_die->name == NULL)
9665 complaint (&symfile_complaints,
9666 _("malformed enumerator DIE ignored"));
9667 else if (building_psymtab)
9668 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9669 VAR_DOMAIN, LOC_CONST,
9670 (cu->language == language_cplus
9671 || cu->language == language_java)
9672 ? &objfile->global_psymbols
9673 : &objfile->static_psymbols,
9674 0, (CORE_ADDR) 0, cu->language, objfile);
9676 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9680 /* We'll save this DIE so link it in. */
9681 part_die->die_parent = parent_die;
9682 part_die->die_sibling = NULL;
9683 part_die->die_child = NULL;
9685 if (last_die && last_die == parent_die)
9686 last_die->die_child = part_die;
9688 last_die->die_sibling = part_die;
9690 last_die = part_die;
9692 if (first_die == NULL)
9693 first_die = part_die;
9695 /* Maybe add the DIE to the hash table. Not all DIEs that we
9696 find interesting need to be in the hash table, because we
9697 also have the parent/sibling/child chains; only those that we
9698 might refer to by offset later during partial symbol reading.
9700 For now this means things that might have be the target of a
9701 DW_AT_specification, DW_AT_abstract_origin, or
9702 DW_AT_extension. DW_AT_extension will refer only to
9703 namespaces; DW_AT_abstract_origin refers to functions (and
9704 many things under the function DIE, but we do not recurse
9705 into function DIEs during partial symbol reading) and
9706 possibly variables as well; DW_AT_specification refers to
9707 declarations. Declarations ought to have the DW_AT_declaration
9708 flag. It happens that GCC forgets to put it in sometimes, but
9709 only for functions, not for types.
9711 Adding more things than necessary to the hash table is harmless
9712 except for the performance cost. Adding too few will result in
9713 wasted time in find_partial_die, when we reread the compilation
9714 unit with load_all_dies set. */
9717 || abbrev->tag == DW_TAG_constant
9718 || abbrev->tag == DW_TAG_subprogram
9719 || abbrev->tag == DW_TAG_variable
9720 || abbrev->tag == DW_TAG_namespace
9721 || part_die->is_declaration)
9725 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9726 part_die->offset, INSERT);
9730 part_die = obstack_alloc (&cu->comp_unit_obstack,
9731 sizeof (struct partial_die_info));
9733 /* For some DIEs we want to follow their children (if any). For C
9734 we have no reason to follow the children of structures; for other
9735 languages we have to, so that we can get at method physnames
9736 to infer fully qualified class names, for DW_AT_specification,
9737 and for C++ template arguments. For C++, we also look one level
9738 inside functions to find template arguments (if the name of the
9739 function does not already contain the template arguments).
9741 For Ada, we need to scan the children of subprograms and lexical
9742 blocks as well because Ada allows the definition of nested
9743 entities that could be interesting for the debugger, such as
9744 nested subprograms for instance. */
9745 if (last_die->has_children
9747 || last_die->tag == DW_TAG_namespace
9748 || last_die->tag == DW_TAG_module
9749 || last_die->tag == DW_TAG_enumeration_type
9750 || (cu->language == language_cplus
9751 && last_die->tag == DW_TAG_subprogram
9752 && (last_die->name == NULL
9753 || strchr (last_die->name, '<') == NULL))
9754 || (cu->language != language_c
9755 && (last_die->tag == DW_TAG_class_type
9756 || last_die->tag == DW_TAG_interface_type
9757 || last_die->tag == DW_TAG_structure_type
9758 || last_die->tag == DW_TAG_union_type))
9759 || (cu->language == language_ada
9760 && (last_die->tag == DW_TAG_subprogram
9761 || last_die->tag == DW_TAG_lexical_block))))
9764 parent_die = last_die;
9768 /* Otherwise we skip to the next sibling, if any. */
9769 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9771 /* Back to the top, do it again. */
9775 /* Read a minimal amount of information into the minimal die structure. */
9778 read_partial_die (struct partial_die_info *part_die,
9779 struct abbrev_info *abbrev,
9780 unsigned int abbrev_len, bfd *abfd,
9781 gdb_byte *buffer, gdb_byte *info_ptr,
9782 struct dwarf2_cu *cu)
9784 struct objfile *objfile = cu->objfile;
9786 struct attribute attr;
9787 int has_low_pc_attr = 0;
9788 int has_high_pc_attr = 0;
9790 memset (part_die, 0, sizeof (struct partial_die_info));
9792 part_die->offset = info_ptr - buffer;
9794 info_ptr += abbrev_len;
9799 part_die->tag = abbrev->tag;
9800 part_die->has_children = abbrev->has_children;
9802 for (i = 0; i < abbrev->num_attrs; ++i)
9804 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9806 /* Store the data if it is of an attribute we want to keep in a
9807 partial symbol table. */
9811 switch (part_die->tag)
9813 case DW_TAG_compile_unit:
9814 case DW_TAG_type_unit:
9815 /* Compilation units have a DW_AT_name that is a filename, not
9816 a source language identifier. */
9817 case DW_TAG_enumeration_type:
9818 case DW_TAG_enumerator:
9819 /* These tags always have simple identifiers already; no need
9820 to canonicalize them. */
9821 part_die->name = DW_STRING (&attr);
9825 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9826 &objfile->objfile_obstack);
9830 case DW_AT_linkage_name:
9831 case DW_AT_MIPS_linkage_name:
9832 /* Note that both forms of linkage name might appear. We
9833 assume they will be the same, and we only store the last
9835 if (cu->language == language_ada)
9836 part_die->name = DW_STRING (&attr);
9837 part_die->linkage_name = DW_STRING (&attr);
9840 has_low_pc_attr = 1;
9841 part_die->lowpc = DW_ADDR (&attr);
9844 has_high_pc_attr = 1;
9845 part_die->highpc = DW_ADDR (&attr);
9847 case DW_AT_location:
9848 /* Support the .debug_loc offsets. */
9849 if (attr_form_is_block (&attr))
9851 part_die->locdesc = DW_BLOCK (&attr);
9853 else if (attr_form_is_section_offset (&attr))
9855 dwarf2_complex_location_expr_complaint ();
9859 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9860 "partial symbol information");
9863 case DW_AT_external:
9864 part_die->is_external = DW_UNSND (&attr);
9866 case DW_AT_declaration:
9867 part_die->is_declaration = DW_UNSND (&attr);
9870 part_die->has_type = 1;
9872 case DW_AT_abstract_origin:
9873 case DW_AT_specification:
9874 case DW_AT_extension:
9875 part_die->has_specification = 1;
9876 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9879 /* Ignore absolute siblings, they might point outside of
9880 the current compile unit. */
9881 if (attr.form == DW_FORM_ref_addr)
9882 complaint (&symfile_complaints,
9883 _("ignoring absolute DW_AT_sibling"));
9885 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9887 case DW_AT_byte_size:
9888 part_die->has_byte_size = 1;
9890 case DW_AT_calling_convention:
9891 /* DWARF doesn't provide a way to identify a program's source-level
9892 entry point. DW_AT_calling_convention attributes are only meant
9893 to describe functions' calling conventions.
9895 However, because it's a necessary piece of information in
9896 Fortran, and because DW_CC_program is the only piece of debugging
9897 information whose definition refers to a 'main program' at all,
9898 several compilers have begun marking Fortran main programs with
9899 DW_CC_program --- even when those functions use the standard
9900 calling conventions.
9902 So until DWARF specifies a way to provide this information and
9903 compilers pick up the new representation, we'll support this
9905 if (DW_UNSND (&attr) == DW_CC_program
9906 && cu->language == language_fortran)
9908 set_main_name (part_die->name);
9910 /* As this DIE has a static linkage the name would be difficult
9911 to look up later. */
9912 language_of_main = language_fortran;
9916 if (DW_UNSND (&attr) == DW_INL_inlined
9917 || DW_UNSND (&attr) == DW_INL_declared_inlined)
9918 part_die->may_be_inlined = 1;
9925 if (has_low_pc_attr && has_high_pc_attr)
9927 /* When using the GNU linker, .gnu.linkonce. sections are used to
9928 eliminate duplicate copies of functions and vtables and such.
9929 The linker will arbitrarily choose one and discard the others.
9930 The AT_*_pc values for such functions refer to local labels in
9931 these sections. If the section from that file was discarded, the
9932 labels are not in the output, so the relocs get a value of 0.
9933 If this is a discarded function, mark the pc bounds as invalid,
9934 so that GDB will ignore it. */
9935 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9937 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9939 complaint (&symfile_complaints,
9940 _("DW_AT_low_pc %s is zero "
9941 "for DIE at 0x%x [in module %s]"),
9942 paddress (gdbarch, part_die->lowpc),
9943 part_die->offset, objfile->name);
9945 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9946 else if (part_die->lowpc >= part_die->highpc)
9948 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9950 complaint (&symfile_complaints,
9951 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9952 "for DIE at 0x%x [in module %s]"),
9953 paddress (gdbarch, part_die->lowpc),
9954 paddress (gdbarch, part_die->highpc),
9955 part_die->offset, objfile->name);
9958 part_die->has_pc_info = 1;
9964 /* Find a cached partial DIE at OFFSET in CU. */
9966 static struct partial_die_info *
9967 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9969 struct partial_die_info *lookup_die = NULL;
9970 struct partial_die_info part_die;
9972 part_die.offset = offset;
9973 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9978 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9979 except in the case of .debug_types DIEs which do not reference
9980 outside their CU (they do however referencing other types via
9981 DW_FORM_ref_sig8). */
9983 static struct partial_die_info *
9984 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9986 struct objfile *objfile = cu->objfile;
9987 struct dwarf2_per_cu_data *per_cu = NULL;
9988 struct partial_die_info *pd = NULL;
9990 if (cu->per_cu->debug_types_section)
9992 pd = find_partial_die_in_comp_unit (offset, cu);
9998 if (offset_in_cu_p (&cu->header, offset))
10000 pd = find_partial_die_in_comp_unit (offset, cu);
10005 per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
10007 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
10008 load_partial_comp_unit (per_cu);
10010 per_cu->cu->last_used = 0;
10011 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10013 if (pd == NULL && per_cu->load_all_dies == 0)
10015 struct cleanup *back_to;
10016 struct partial_die_info comp_unit_die;
10017 struct abbrev_info *abbrev;
10018 unsigned int bytes_read;
10021 per_cu->load_all_dies = 1;
10023 /* Re-read the DIEs. */
10024 back_to = make_cleanup (null_cleanup, 0);
10025 if (per_cu->cu->dwarf2_abbrevs == NULL)
10027 dwarf2_read_abbrevs (per_cu->cu);
10028 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
10030 info_ptr = (dwarf2_per_objfile->info.buffer
10031 + per_cu->cu->header.offset
10032 + per_cu->cu->header.first_die_offset);
10033 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
10034 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
10036 dwarf2_per_objfile->info.buffer, info_ptr,
10038 if (comp_unit_die.has_children)
10039 load_partial_dies (objfile->obfd,
10040 dwarf2_per_objfile->info.buffer, info_ptr,
10042 do_cleanups (back_to);
10044 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10050 internal_error (__FILE__, __LINE__,
10051 _("could not find partial DIE 0x%x "
10052 "in cache [from module %s]\n"),
10053 offset, bfd_get_filename (objfile->obfd));
10057 /* See if we can figure out if the class lives in a namespace. We do
10058 this by looking for a member function; its demangled name will
10059 contain namespace info, if there is any. */
10062 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
10063 struct dwarf2_cu *cu)
10065 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10066 what template types look like, because the demangler
10067 frequently doesn't give the same name as the debug info. We
10068 could fix this by only using the demangled name to get the
10069 prefix (but see comment in read_structure_type). */
10071 struct partial_die_info *real_pdi;
10072 struct partial_die_info *child_pdi;
10074 /* If this DIE (this DIE's specification, if any) has a parent, then
10075 we should not do this. We'll prepend the parent's fully qualified
10076 name when we create the partial symbol. */
10078 real_pdi = struct_pdi;
10079 while (real_pdi->has_specification)
10080 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
10082 if (real_pdi->die_parent != NULL)
10085 for (child_pdi = struct_pdi->die_child;
10087 child_pdi = child_pdi->die_sibling)
10089 if (child_pdi->tag == DW_TAG_subprogram
10090 && child_pdi->linkage_name != NULL)
10092 char *actual_class_name
10093 = language_class_name_from_physname (cu->language_defn,
10094 child_pdi->linkage_name);
10095 if (actual_class_name != NULL)
10098 = obsavestring (actual_class_name,
10099 strlen (actual_class_name),
10100 &cu->objfile->objfile_obstack);
10101 xfree (actual_class_name);
10108 /* Adjust PART_DIE before generating a symbol for it. This function
10109 may set the is_external flag or change the DIE's name. */
10112 fixup_partial_die (struct partial_die_info *part_die,
10113 struct dwarf2_cu *cu)
10115 /* Once we've fixed up a die, there's no point in doing so again.
10116 This also avoids a memory leak if we were to call
10117 guess_partial_die_structure_name multiple times. */
10118 if (part_die->fixup_called)
10121 /* If we found a reference attribute and the DIE has no name, try
10122 to find a name in the referred to DIE. */
10124 if (part_die->name == NULL && part_die->has_specification)
10126 struct partial_die_info *spec_die;
10128 spec_die = find_partial_die (part_die->spec_offset, cu);
10130 fixup_partial_die (spec_die, cu);
10132 if (spec_die->name)
10134 part_die->name = spec_die->name;
10136 /* Copy DW_AT_external attribute if it is set. */
10137 if (spec_die->is_external)
10138 part_die->is_external = spec_die->is_external;
10142 /* Set default names for some unnamed DIEs. */
10144 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
10145 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
10147 /* If there is no parent die to provide a namespace, and there are
10148 children, see if we can determine the namespace from their linkage
10150 if (cu->language == language_cplus
10151 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
10152 && part_die->die_parent == NULL
10153 && part_die->has_children
10154 && (part_die->tag == DW_TAG_class_type
10155 || part_die->tag == DW_TAG_structure_type
10156 || part_die->tag == DW_TAG_union_type))
10157 guess_partial_die_structure_name (part_die, cu);
10159 /* GCC might emit a nameless struct or union that has a linkage
10160 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10161 if (part_die->name == NULL
10162 && (part_die->tag == DW_TAG_class_type
10163 || part_die->tag == DW_TAG_interface_type
10164 || part_die->tag == DW_TAG_structure_type
10165 || part_die->tag == DW_TAG_union_type)
10166 && part_die->linkage_name != NULL)
10170 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
10175 /* Strip any leading namespaces/classes, keep only the base name.
10176 DW_AT_name for named DIEs does not contain the prefixes. */
10177 base = strrchr (demangled, ':');
10178 if (base && base > demangled && base[-1] == ':')
10183 part_die->name = obsavestring (base, strlen (base),
10184 &cu->objfile->objfile_obstack);
10189 part_die->fixup_called = 1;
10192 /* Read an attribute value described by an attribute form. */
10195 read_attribute_value (struct attribute *attr, unsigned form,
10196 bfd *abfd, gdb_byte *info_ptr,
10197 struct dwarf2_cu *cu)
10199 struct comp_unit_head *cu_header = &cu->header;
10200 unsigned int bytes_read;
10201 struct dwarf_block *blk;
10206 case DW_FORM_ref_addr:
10207 if (cu->header.version == 2)
10208 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10210 DW_ADDR (attr) = read_offset (abfd, info_ptr,
10211 &cu->header, &bytes_read);
10212 info_ptr += bytes_read;
10215 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10216 info_ptr += bytes_read;
10218 case DW_FORM_block2:
10219 blk = dwarf_alloc_block (cu);
10220 blk->size = read_2_bytes (abfd, info_ptr);
10222 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10223 info_ptr += blk->size;
10224 DW_BLOCK (attr) = blk;
10226 case DW_FORM_block4:
10227 blk = dwarf_alloc_block (cu);
10228 blk->size = read_4_bytes (abfd, info_ptr);
10230 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10231 info_ptr += blk->size;
10232 DW_BLOCK (attr) = blk;
10234 case DW_FORM_data2:
10235 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
10238 case DW_FORM_data4:
10239 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
10242 case DW_FORM_data8:
10243 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
10246 case DW_FORM_sec_offset:
10247 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
10248 info_ptr += bytes_read;
10250 case DW_FORM_string:
10251 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
10252 DW_STRING_IS_CANONICAL (attr) = 0;
10253 info_ptr += bytes_read;
10256 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
10258 DW_STRING_IS_CANONICAL (attr) = 0;
10259 info_ptr += bytes_read;
10261 case DW_FORM_exprloc:
10262 case DW_FORM_block:
10263 blk = dwarf_alloc_block (cu);
10264 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10265 info_ptr += bytes_read;
10266 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10267 info_ptr += blk->size;
10268 DW_BLOCK (attr) = blk;
10270 case DW_FORM_block1:
10271 blk = dwarf_alloc_block (cu);
10272 blk->size = read_1_byte (abfd, info_ptr);
10274 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10275 info_ptr += blk->size;
10276 DW_BLOCK (attr) = blk;
10278 case DW_FORM_data1:
10279 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10283 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10286 case DW_FORM_flag_present:
10287 DW_UNSND (attr) = 1;
10289 case DW_FORM_sdata:
10290 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
10291 info_ptr += bytes_read;
10293 case DW_FORM_udata:
10294 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10295 info_ptr += bytes_read;
10298 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
10302 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
10306 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
10310 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
10313 case DW_FORM_ref_sig8:
10314 /* Convert the signature to something we can record in DW_UNSND
10316 NOTE: This is NULL if the type wasn't found. */
10317 DW_SIGNATURED_TYPE (attr) =
10318 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
10321 case DW_FORM_ref_udata:
10322 DW_ADDR (attr) = (cu->header.offset
10323 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
10324 info_ptr += bytes_read;
10326 case DW_FORM_indirect:
10327 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10328 info_ptr += bytes_read;
10329 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
10332 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10333 dwarf_form_name (form),
10334 bfd_get_filename (abfd));
10337 /* We have seen instances where the compiler tried to emit a byte
10338 size attribute of -1 which ended up being encoded as an unsigned
10339 0xffffffff. Although 0xffffffff is technically a valid size value,
10340 an object of this size seems pretty unlikely so we can relatively
10341 safely treat these cases as if the size attribute was invalid and
10342 treat them as zero by default. */
10343 if (attr->name == DW_AT_byte_size
10344 && form == DW_FORM_data4
10345 && DW_UNSND (attr) >= 0xffffffff)
10348 (&symfile_complaints,
10349 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10350 hex_string (DW_UNSND (attr)));
10351 DW_UNSND (attr) = 0;
10357 /* Read an attribute described by an abbreviated attribute. */
10360 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10361 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10363 attr->name = abbrev->name;
10364 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10367 /* Read dwarf information from a buffer. */
10369 static unsigned int
10370 read_1_byte (bfd *abfd, gdb_byte *buf)
10372 return bfd_get_8 (abfd, buf);
10376 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10378 return bfd_get_signed_8 (abfd, buf);
10381 static unsigned int
10382 read_2_bytes (bfd *abfd, gdb_byte *buf)
10384 return bfd_get_16 (abfd, buf);
10388 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
10390 return bfd_get_signed_16 (abfd, buf);
10393 static unsigned int
10394 read_4_bytes (bfd *abfd, gdb_byte *buf)
10396 return bfd_get_32 (abfd, buf);
10400 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
10402 return bfd_get_signed_32 (abfd, buf);
10406 read_8_bytes (bfd *abfd, gdb_byte *buf)
10408 return bfd_get_64 (abfd, buf);
10412 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10413 unsigned int *bytes_read)
10415 struct comp_unit_head *cu_header = &cu->header;
10416 CORE_ADDR retval = 0;
10418 if (cu_header->signed_addr_p)
10420 switch (cu_header->addr_size)
10423 retval = bfd_get_signed_16 (abfd, buf);
10426 retval = bfd_get_signed_32 (abfd, buf);
10429 retval = bfd_get_signed_64 (abfd, buf);
10432 internal_error (__FILE__, __LINE__,
10433 _("read_address: bad switch, signed [in module %s]"),
10434 bfd_get_filename (abfd));
10439 switch (cu_header->addr_size)
10442 retval = bfd_get_16 (abfd, buf);
10445 retval = bfd_get_32 (abfd, buf);
10448 retval = bfd_get_64 (abfd, buf);
10451 internal_error (__FILE__, __LINE__,
10452 _("read_address: bad switch, "
10453 "unsigned [in module %s]"),
10454 bfd_get_filename (abfd));
10458 *bytes_read = cu_header->addr_size;
10462 /* Read the initial length from a section. The (draft) DWARF 3
10463 specification allows the initial length to take up either 4 bytes
10464 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10465 bytes describe the length and all offsets will be 8 bytes in length
10468 An older, non-standard 64-bit format is also handled by this
10469 function. The older format in question stores the initial length
10470 as an 8-byte quantity without an escape value. Lengths greater
10471 than 2^32 aren't very common which means that the initial 4 bytes
10472 is almost always zero. Since a length value of zero doesn't make
10473 sense for the 32-bit format, this initial zero can be considered to
10474 be an escape value which indicates the presence of the older 64-bit
10475 format. As written, the code can't detect (old format) lengths
10476 greater than 4GB. If it becomes necessary to handle lengths
10477 somewhat larger than 4GB, we could allow other small values (such
10478 as the non-sensical values of 1, 2, and 3) to also be used as
10479 escape values indicating the presence of the old format.
10481 The value returned via bytes_read should be used to increment the
10482 relevant pointer after calling read_initial_length().
10484 [ Note: read_initial_length() and read_offset() are based on the
10485 document entitled "DWARF Debugging Information Format", revision
10486 3, draft 8, dated November 19, 2001. This document was obtained
10489 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10491 This document is only a draft and is subject to change. (So beware.)
10493 Details regarding the older, non-standard 64-bit format were
10494 determined empirically by examining 64-bit ELF files produced by
10495 the SGI toolchain on an IRIX 6.5 machine.
10497 - Kevin, July 16, 2002
10501 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10503 LONGEST length = bfd_get_32 (abfd, buf);
10505 if (length == 0xffffffff)
10507 length = bfd_get_64 (abfd, buf + 4);
10510 else if (length == 0)
10512 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10513 length = bfd_get_64 (abfd, buf);
10524 /* Cover function for read_initial_length.
10525 Returns the length of the object at BUF, and stores the size of the
10526 initial length in *BYTES_READ and stores the size that offsets will be in
10528 If the initial length size is not equivalent to that specified in
10529 CU_HEADER then issue a complaint.
10530 This is useful when reading non-comp-unit headers. */
10533 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10534 const struct comp_unit_head *cu_header,
10535 unsigned int *bytes_read,
10536 unsigned int *offset_size)
10538 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10540 gdb_assert (cu_header->initial_length_size == 4
10541 || cu_header->initial_length_size == 8
10542 || cu_header->initial_length_size == 12);
10544 if (cu_header->initial_length_size != *bytes_read)
10545 complaint (&symfile_complaints,
10546 _("intermixed 32-bit and 64-bit DWARF sections"));
10548 *offset_size = (*bytes_read == 4) ? 4 : 8;
10552 /* Read an offset from the data stream. The size of the offset is
10553 given by cu_header->offset_size. */
10556 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10557 unsigned int *bytes_read)
10559 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10561 *bytes_read = cu_header->offset_size;
10565 /* Read an offset from the data stream. */
10568 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10570 LONGEST retval = 0;
10572 switch (offset_size)
10575 retval = bfd_get_32 (abfd, buf);
10578 retval = bfd_get_64 (abfd, buf);
10581 internal_error (__FILE__, __LINE__,
10582 _("read_offset_1: bad switch [in module %s]"),
10583 bfd_get_filename (abfd));
10590 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10592 /* If the size of a host char is 8 bits, we can return a pointer
10593 to the buffer, otherwise we have to copy the data to a buffer
10594 allocated on the temporary obstack. */
10595 gdb_assert (HOST_CHAR_BIT == 8);
10600 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10602 /* If the size of a host char is 8 bits, we can return a pointer
10603 to the string, otherwise we have to copy the string to a buffer
10604 allocated on the temporary obstack. */
10605 gdb_assert (HOST_CHAR_BIT == 8);
10608 *bytes_read_ptr = 1;
10611 *bytes_read_ptr = strlen ((char *) buf) + 1;
10612 return (char *) buf;
10616 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10618 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10619 if (dwarf2_per_objfile->str.buffer == NULL)
10620 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10621 bfd_get_filename (abfd));
10622 if (str_offset >= dwarf2_per_objfile->str.size)
10623 error (_("DW_FORM_strp pointing outside of "
10624 ".debug_str section [in module %s]"),
10625 bfd_get_filename (abfd));
10626 gdb_assert (HOST_CHAR_BIT == 8);
10627 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10629 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10633 read_indirect_string (bfd *abfd, gdb_byte *buf,
10634 const struct comp_unit_head *cu_header,
10635 unsigned int *bytes_read_ptr)
10637 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10639 return read_indirect_string_at_offset (abfd, str_offset);
10642 static unsigned long
10643 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10645 unsigned long result;
10646 unsigned int num_read;
10648 unsigned char byte;
10656 byte = bfd_get_8 (abfd, buf);
10659 result |= ((unsigned long)(byte & 127) << shift);
10660 if ((byte & 128) == 0)
10666 *bytes_read_ptr = num_read;
10671 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10674 int i, shift, num_read;
10675 unsigned char byte;
10683 byte = bfd_get_8 (abfd, buf);
10686 result |= ((long)(byte & 127) << shift);
10688 if ((byte & 128) == 0)
10693 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10694 result |= -(((long)1) << shift);
10695 *bytes_read_ptr = num_read;
10699 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10702 skip_leb128 (bfd *abfd, gdb_byte *buf)
10708 byte = bfd_get_8 (abfd, buf);
10710 if ((byte & 128) == 0)
10716 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10723 cu->language = language_c;
10725 case DW_LANG_C_plus_plus:
10726 cu->language = language_cplus;
10729 cu->language = language_d;
10731 case DW_LANG_Fortran77:
10732 case DW_LANG_Fortran90:
10733 case DW_LANG_Fortran95:
10734 cu->language = language_fortran;
10736 case DW_LANG_Mips_Assembler:
10737 cu->language = language_asm;
10740 cu->language = language_java;
10742 case DW_LANG_Ada83:
10743 case DW_LANG_Ada95:
10744 cu->language = language_ada;
10746 case DW_LANG_Modula2:
10747 cu->language = language_m2;
10749 case DW_LANG_Pascal83:
10750 cu->language = language_pascal;
10753 cu->language = language_objc;
10755 case DW_LANG_Cobol74:
10756 case DW_LANG_Cobol85:
10758 cu->language = language_minimal;
10761 cu->language_defn = language_def (cu->language);
10764 /* Return the named attribute or NULL if not there. */
10766 static struct attribute *
10767 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10772 struct attribute *spec = NULL;
10774 for (i = 0; i < die->num_attrs; ++i)
10776 if (die->attrs[i].name == name)
10777 return &die->attrs[i];
10778 if (die->attrs[i].name == DW_AT_specification
10779 || die->attrs[i].name == DW_AT_abstract_origin)
10780 spec = &die->attrs[i];
10786 die = follow_die_ref (die, spec, &cu);
10792 /* Return the named attribute or NULL if not there,
10793 but do not follow DW_AT_specification, etc.
10794 This is for use in contexts where we're reading .debug_types dies.
10795 Following DW_AT_specification, DW_AT_abstract_origin will take us
10796 back up the chain, and we want to go down. */
10798 static struct attribute *
10799 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10800 struct dwarf2_cu *cu)
10804 for (i = 0; i < die->num_attrs; ++i)
10805 if (die->attrs[i].name == name)
10806 return &die->attrs[i];
10811 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10812 and holds a non-zero value. This function should only be used for
10813 DW_FORM_flag or DW_FORM_flag_present attributes. */
10816 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10818 struct attribute *attr = dwarf2_attr (die, name, cu);
10820 return (attr && DW_UNSND (attr));
10824 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10826 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10827 which value is non-zero. However, we have to be careful with
10828 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10829 (via dwarf2_flag_true_p) follows this attribute. So we may
10830 end up accidently finding a declaration attribute that belongs
10831 to a different DIE referenced by the specification attribute,
10832 even though the given DIE does not have a declaration attribute. */
10833 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10834 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10837 /* Return the die giving the specification for DIE, if there is
10838 one. *SPEC_CU is the CU containing DIE on input, and the CU
10839 containing the return value on output. If there is no
10840 specification, but there is an abstract origin, that is
10843 static struct die_info *
10844 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10846 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10849 if (spec_attr == NULL)
10850 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10852 if (spec_attr == NULL)
10855 return follow_die_ref (die, spec_attr, spec_cu);
10858 /* Free the line_header structure *LH, and any arrays and strings it
10860 NOTE: This is also used as a "cleanup" function. */
10863 free_line_header (struct line_header *lh)
10865 if (lh->standard_opcode_lengths)
10866 xfree (lh->standard_opcode_lengths);
10868 /* Remember that all the lh->file_names[i].name pointers are
10869 pointers into debug_line_buffer, and don't need to be freed. */
10870 if (lh->file_names)
10871 xfree (lh->file_names);
10873 /* Similarly for the include directory names. */
10874 if (lh->include_dirs)
10875 xfree (lh->include_dirs);
10880 /* Add an entry to LH's include directory table. */
10883 add_include_dir (struct line_header *lh, char *include_dir)
10885 /* Grow the array if necessary. */
10886 if (lh->include_dirs_size == 0)
10888 lh->include_dirs_size = 1; /* for testing */
10889 lh->include_dirs = xmalloc (lh->include_dirs_size
10890 * sizeof (*lh->include_dirs));
10892 else if (lh->num_include_dirs >= lh->include_dirs_size)
10894 lh->include_dirs_size *= 2;
10895 lh->include_dirs = xrealloc (lh->include_dirs,
10896 (lh->include_dirs_size
10897 * sizeof (*lh->include_dirs)));
10900 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10903 /* Add an entry to LH's file name table. */
10906 add_file_name (struct line_header *lh,
10908 unsigned int dir_index,
10909 unsigned int mod_time,
10910 unsigned int length)
10912 struct file_entry *fe;
10914 /* Grow the array if necessary. */
10915 if (lh->file_names_size == 0)
10917 lh->file_names_size = 1; /* for testing */
10918 lh->file_names = xmalloc (lh->file_names_size
10919 * sizeof (*lh->file_names));
10921 else if (lh->num_file_names >= lh->file_names_size)
10923 lh->file_names_size *= 2;
10924 lh->file_names = xrealloc (lh->file_names,
10925 (lh->file_names_size
10926 * sizeof (*lh->file_names)));
10929 fe = &lh->file_names[lh->num_file_names++];
10931 fe->dir_index = dir_index;
10932 fe->mod_time = mod_time;
10933 fe->length = length;
10934 fe->included_p = 0;
10938 /* Read the statement program header starting at OFFSET in
10939 .debug_line, according to the endianness of ABFD. Return a pointer
10940 to a struct line_header, allocated using xmalloc.
10942 NOTE: the strings in the include directory and file name tables of
10943 the returned object point into debug_line_buffer, and must not be
10946 static struct line_header *
10947 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10948 struct dwarf2_cu *cu)
10950 struct cleanup *back_to;
10951 struct line_header *lh;
10952 gdb_byte *line_ptr;
10953 unsigned int bytes_read, offset_size;
10955 char *cur_dir, *cur_file;
10957 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10958 if (dwarf2_per_objfile->line.buffer == NULL)
10960 complaint (&symfile_complaints, _("missing .debug_line section"));
10964 /* Make sure that at least there's room for the total_length field.
10965 That could be 12 bytes long, but we're just going to fudge that. */
10966 if (offset + 4 >= dwarf2_per_objfile->line.size)
10968 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10972 lh = xmalloc (sizeof (*lh));
10973 memset (lh, 0, sizeof (*lh));
10974 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10977 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10979 /* Read in the header. */
10981 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10982 &bytes_read, &offset_size);
10983 line_ptr += bytes_read;
10984 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10985 + dwarf2_per_objfile->line.size))
10987 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10990 lh->statement_program_end = line_ptr + lh->total_length;
10991 lh->version = read_2_bytes (abfd, line_ptr);
10993 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10994 line_ptr += offset_size;
10995 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10997 if (lh->version >= 4)
10999 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
11003 lh->maximum_ops_per_instruction = 1;
11005 if (lh->maximum_ops_per_instruction == 0)
11007 lh->maximum_ops_per_instruction = 1;
11008 complaint (&symfile_complaints,
11009 _("invalid maximum_ops_per_instruction "
11010 "in `.debug_line' section"));
11013 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
11015 lh->line_base = read_1_signed_byte (abfd, line_ptr);
11017 lh->line_range = read_1_byte (abfd, line_ptr);
11019 lh->opcode_base = read_1_byte (abfd, line_ptr);
11021 lh->standard_opcode_lengths
11022 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
11024 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
11025 for (i = 1; i < lh->opcode_base; ++i)
11027 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
11031 /* Read directory table. */
11032 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11034 line_ptr += bytes_read;
11035 add_include_dir (lh, cur_dir);
11037 line_ptr += bytes_read;
11039 /* Read file name table. */
11040 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11042 unsigned int dir_index, mod_time, length;
11044 line_ptr += bytes_read;
11045 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11046 line_ptr += bytes_read;
11047 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11048 line_ptr += bytes_read;
11049 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11050 line_ptr += bytes_read;
11052 add_file_name (lh, cur_file, dir_index, mod_time, length);
11054 line_ptr += bytes_read;
11055 lh->statement_program_start = line_ptr;
11057 if (line_ptr > (dwarf2_per_objfile->line.buffer
11058 + dwarf2_per_objfile->line.size))
11059 complaint (&symfile_complaints,
11060 _("line number info header doesn't "
11061 "fit in `.debug_line' section"));
11063 discard_cleanups (back_to);
11067 /* Subroutine of dwarf_decode_lines to simplify it.
11068 Return the file name of the psymtab for included file FILE_INDEX
11069 in line header LH of PST.
11070 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11071 If space for the result is malloc'd, it will be freed by a cleanup.
11072 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11075 psymtab_include_file_name (const struct line_header *lh, int file_index,
11076 const struct partial_symtab *pst,
11077 const char *comp_dir)
11079 const struct file_entry fe = lh->file_names [file_index];
11080 char *include_name = fe.name;
11081 char *include_name_to_compare = include_name;
11082 char *dir_name = NULL;
11083 const char *pst_filename;
11084 char *copied_name = NULL;
11088 dir_name = lh->include_dirs[fe.dir_index - 1];
11090 if (!IS_ABSOLUTE_PATH (include_name)
11091 && (dir_name != NULL || comp_dir != NULL))
11093 /* Avoid creating a duplicate psymtab for PST.
11094 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11095 Before we do the comparison, however, we need to account
11096 for DIR_NAME and COMP_DIR.
11097 First prepend dir_name (if non-NULL). If we still don't
11098 have an absolute path prepend comp_dir (if non-NULL).
11099 However, the directory we record in the include-file's
11100 psymtab does not contain COMP_DIR (to match the
11101 corresponding symtab(s)).
11106 bash$ gcc -g ./hello.c
11107 include_name = "hello.c"
11109 DW_AT_comp_dir = comp_dir = "/tmp"
11110 DW_AT_name = "./hello.c" */
11112 if (dir_name != NULL)
11114 include_name = concat (dir_name, SLASH_STRING,
11115 include_name, (char *)NULL);
11116 include_name_to_compare = include_name;
11117 make_cleanup (xfree, include_name);
11119 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
11121 include_name_to_compare = concat (comp_dir, SLASH_STRING,
11122 include_name, (char *)NULL);
11126 pst_filename = pst->filename;
11127 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
11129 copied_name = concat (pst->dirname, SLASH_STRING,
11130 pst_filename, (char *)NULL);
11131 pst_filename = copied_name;
11134 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
11136 if (include_name_to_compare != include_name)
11137 xfree (include_name_to_compare);
11138 if (copied_name != NULL)
11139 xfree (copied_name);
11143 return include_name;
11146 /* Ignore this record_line request. */
11149 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
11154 /* Subroutine of dwarf_decode_lines to simplify it.
11155 Process the line number information in LH. */
11158 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
11159 struct dwarf2_cu *cu, struct partial_symtab *pst)
11161 gdb_byte *line_ptr, *extended_end;
11162 gdb_byte *line_end;
11163 unsigned int bytes_read, extended_len;
11164 unsigned char op_code, extended_op, adj_opcode;
11165 CORE_ADDR baseaddr;
11166 struct objfile *objfile = cu->objfile;
11167 bfd *abfd = objfile->obfd;
11168 struct gdbarch *gdbarch = get_objfile_arch (objfile);
11169 const int decode_for_pst_p = (pst != NULL);
11170 struct subfile *last_subfile = NULL;
11171 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
11174 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11176 line_ptr = lh->statement_program_start;
11177 line_end = lh->statement_program_end;
11179 /* Read the statement sequences until there's nothing left. */
11180 while (line_ptr < line_end)
11182 /* state machine registers */
11183 CORE_ADDR address = 0;
11184 unsigned int file = 1;
11185 unsigned int line = 1;
11186 unsigned int column = 0;
11187 int is_stmt = lh->default_is_stmt;
11188 int basic_block = 0;
11189 int end_sequence = 0;
11191 unsigned char op_index = 0;
11193 if (!decode_for_pst_p && lh->num_file_names >= file)
11195 /* Start a subfile for the current file of the state machine. */
11196 /* lh->include_dirs and lh->file_names are 0-based, but the
11197 directory and file name numbers in the statement program
11199 struct file_entry *fe = &lh->file_names[file - 1];
11203 dir = lh->include_dirs[fe->dir_index - 1];
11205 dwarf2_start_subfile (fe->name, dir, comp_dir);
11208 /* Decode the table. */
11209 while (!end_sequence)
11211 op_code = read_1_byte (abfd, line_ptr);
11213 if (line_ptr > line_end)
11215 dwarf2_debug_line_missing_end_sequence_complaint ();
11219 if (op_code >= lh->opcode_base)
11221 /* Special operand. */
11222 adj_opcode = op_code - lh->opcode_base;
11223 address += (((op_index + (adj_opcode / lh->line_range))
11224 / lh->maximum_ops_per_instruction)
11225 * lh->minimum_instruction_length);
11226 op_index = ((op_index + (adj_opcode / lh->line_range))
11227 % lh->maximum_ops_per_instruction);
11228 line += lh->line_base + (adj_opcode % lh->line_range);
11229 if (lh->num_file_names < file || file == 0)
11230 dwarf2_debug_line_missing_file_complaint ();
11231 /* For now we ignore lines not starting on an
11232 instruction boundary. */
11233 else if (op_index == 0)
11235 lh->file_names[file - 1].included_p = 1;
11236 if (!decode_for_pst_p && is_stmt)
11238 if (last_subfile != current_subfile)
11240 addr = gdbarch_addr_bits_remove (gdbarch, address);
11242 (*p_record_line) (last_subfile, 0, addr);
11243 last_subfile = current_subfile;
11245 /* Append row to matrix using current values. */
11246 addr = gdbarch_addr_bits_remove (gdbarch, address);
11247 (*p_record_line) (current_subfile, line, addr);
11252 else switch (op_code)
11254 case DW_LNS_extended_op:
11255 extended_len = read_unsigned_leb128 (abfd, line_ptr,
11257 line_ptr += bytes_read;
11258 extended_end = line_ptr + extended_len;
11259 extended_op = read_1_byte (abfd, line_ptr);
11261 switch (extended_op)
11263 case DW_LNE_end_sequence:
11264 p_record_line = record_line;
11267 case DW_LNE_set_address:
11268 address = read_address (abfd, line_ptr, cu, &bytes_read);
11270 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
11272 /* This line table is for a function which has been
11273 GCd by the linker. Ignore it. PR gdb/12528 */
11276 = line_ptr - dwarf2_per_objfile->line.buffer;
11278 complaint (&symfile_complaints,
11279 _(".debug_line address at offset 0x%lx is 0 "
11281 line_offset, objfile->name);
11282 p_record_line = noop_record_line;
11286 line_ptr += bytes_read;
11287 address += baseaddr;
11289 case DW_LNE_define_file:
11292 unsigned int dir_index, mod_time, length;
11294 cur_file = read_direct_string (abfd, line_ptr,
11296 line_ptr += bytes_read;
11298 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11299 line_ptr += bytes_read;
11301 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11302 line_ptr += bytes_read;
11304 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11305 line_ptr += bytes_read;
11306 add_file_name (lh, cur_file, dir_index, mod_time, length);
11309 case DW_LNE_set_discriminator:
11310 /* The discriminator is not interesting to the debugger;
11312 line_ptr = extended_end;
11315 complaint (&symfile_complaints,
11316 _("mangled .debug_line section"));
11319 /* Make sure that we parsed the extended op correctly. If e.g.
11320 we expected a different address size than the producer used,
11321 we may have read the wrong number of bytes. */
11322 if (line_ptr != extended_end)
11324 complaint (&symfile_complaints,
11325 _("mangled .debug_line section"));
11330 if (lh->num_file_names < file || file == 0)
11331 dwarf2_debug_line_missing_file_complaint ();
11334 lh->file_names[file - 1].included_p = 1;
11335 if (!decode_for_pst_p && is_stmt)
11337 if (last_subfile != current_subfile)
11339 addr = gdbarch_addr_bits_remove (gdbarch, address);
11341 (*p_record_line) (last_subfile, 0, addr);
11342 last_subfile = current_subfile;
11344 addr = gdbarch_addr_bits_remove (gdbarch, address);
11345 (*p_record_line) (current_subfile, line, addr);
11350 case DW_LNS_advance_pc:
11353 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11355 address += (((op_index + adjust)
11356 / lh->maximum_ops_per_instruction)
11357 * lh->minimum_instruction_length);
11358 op_index = ((op_index + adjust)
11359 % lh->maximum_ops_per_instruction);
11360 line_ptr += bytes_read;
11363 case DW_LNS_advance_line:
11364 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11365 line_ptr += bytes_read;
11367 case DW_LNS_set_file:
11369 /* The arrays lh->include_dirs and lh->file_names are
11370 0-based, but the directory and file name numbers in
11371 the statement program are 1-based. */
11372 struct file_entry *fe;
11375 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11376 line_ptr += bytes_read;
11377 if (lh->num_file_names < file || file == 0)
11378 dwarf2_debug_line_missing_file_complaint ();
11381 fe = &lh->file_names[file - 1];
11383 dir = lh->include_dirs[fe->dir_index - 1];
11384 if (!decode_for_pst_p)
11386 last_subfile = current_subfile;
11387 dwarf2_start_subfile (fe->name, dir, comp_dir);
11392 case DW_LNS_set_column:
11393 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11394 line_ptr += bytes_read;
11396 case DW_LNS_negate_stmt:
11397 is_stmt = (!is_stmt);
11399 case DW_LNS_set_basic_block:
11402 /* Add to the address register of the state machine the
11403 address increment value corresponding to special opcode
11404 255. I.e., this value is scaled by the minimum
11405 instruction length since special opcode 255 would have
11406 scaled the increment. */
11407 case DW_LNS_const_add_pc:
11409 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11411 address += (((op_index + adjust)
11412 / lh->maximum_ops_per_instruction)
11413 * lh->minimum_instruction_length);
11414 op_index = ((op_index + adjust)
11415 % lh->maximum_ops_per_instruction);
11418 case DW_LNS_fixed_advance_pc:
11419 address += read_2_bytes (abfd, line_ptr);
11425 /* Unknown standard opcode, ignore it. */
11428 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11430 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11431 line_ptr += bytes_read;
11436 if (lh->num_file_names < file || file == 0)
11437 dwarf2_debug_line_missing_file_complaint ();
11440 lh->file_names[file - 1].included_p = 1;
11441 if (!decode_for_pst_p)
11443 addr = gdbarch_addr_bits_remove (gdbarch, address);
11444 (*p_record_line) (current_subfile, 0, addr);
11450 /* Decode the Line Number Program (LNP) for the given line_header
11451 structure and CU. The actual information extracted and the type
11452 of structures created from the LNP depends on the value of PST.
11454 1. If PST is NULL, then this procedure uses the data from the program
11455 to create all necessary symbol tables, and their linetables.
11457 2. If PST is not NULL, this procedure reads the program to determine
11458 the list of files included by the unit represented by PST, and
11459 builds all the associated partial symbol tables.
11461 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11462 It is used for relative paths in the line table.
11463 NOTE: When processing partial symtabs (pst != NULL),
11464 comp_dir == pst->dirname.
11466 NOTE: It is important that psymtabs have the same file name (via strcmp)
11467 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11468 symtab we don't use it in the name of the psymtabs we create.
11469 E.g. expand_line_sal requires this when finding psymtabs to expand.
11470 A good testcase for this is mb-inline.exp. */
11473 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
11474 struct dwarf2_cu *cu, struct partial_symtab *pst,
11475 int want_line_info)
11477 struct objfile *objfile = cu->objfile;
11478 const int decode_for_pst_p = (pst != NULL);
11479 struct subfile *first_subfile = current_subfile;
11481 if (want_line_info)
11482 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
11484 if (decode_for_pst_p)
11488 /* Now that we're done scanning the Line Header Program, we can
11489 create the psymtab of each included file. */
11490 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11491 if (lh->file_names[file_index].included_p == 1)
11493 char *include_name =
11494 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11495 if (include_name != NULL)
11496 dwarf2_create_include_psymtab (include_name, pst, objfile);
11501 /* Make sure a symtab is created for every file, even files
11502 which contain only variables (i.e. no code with associated
11506 for (i = 0; i < lh->num_file_names; i++)
11509 struct file_entry *fe;
11511 fe = &lh->file_names[i];
11513 dir = lh->include_dirs[fe->dir_index - 1];
11514 dwarf2_start_subfile (fe->name, dir, comp_dir);
11516 /* Skip the main file; we don't need it, and it must be
11517 allocated last, so that it will show up before the
11518 non-primary symtabs in the objfile's symtab list. */
11519 if (current_subfile == first_subfile)
11522 if (current_subfile->symtab == NULL)
11523 current_subfile->symtab = allocate_symtab (current_subfile->name,
11525 fe->symtab = current_subfile->symtab;
11530 /* Start a subfile for DWARF. FILENAME is the name of the file and
11531 DIRNAME the name of the source directory which contains FILENAME
11532 or NULL if not known. COMP_DIR is the compilation directory for the
11533 linetable's compilation unit or NULL if not known.
11534 This routine tries to keep line numbers from identical absolute and
11535 relative file names in a common subfile.
11537 Using the `list' example from the GDB testsuite, which resides in
11538 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11539 of /srcdir/list0.c yields the following debugging information for list0.c:
11541 DW_AT_name: /srcdir/list0.c
11542 DW_AT_comp_dir: /compdir
11543 files.files[0].name: list0.h
11544 files.files[0].dir: /srcdir
11545 files.files[1].name: list0.c
11546 files.files[1].dir: /srcdir
11548 The line number information for list0.c has to end up in a single
11549 subfile, so that `break /srcdir/list0.c:1' works as expected.
11550 start_subfile will ensure that this happens provided that we pass the
11551 concatenation of files.files[1].dir and files.files[1].name as the
11555 dwarf2_start_subfile (char *filename, const char *dirname,
11556 const char *comp_dir)
11560 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11561 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11562 second argument to start_subfile. To be consistent, we do the
11563 same here. In order not to lose the line information directory,
11564 we concatenate it to the filename when it makes sense.
11565 Note that the Dwarf3 standard says (speaking of filenames in line
11566 information): ``The directory index is ignored for file names
11567 that represent full path names''. Thus ignoring dirname in the
11568 `else' branch below isn't an issue. */
11570 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11571 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11573 fullname = filename;
11575 start_subfile (fullname, comp_dir);
11577 if (fullname != filename)
11582 var_decode_location (struct attribute *attr, struct symbol *sym,
11583 struct dwarf2_cu *cu)
11585 struct objfile *objfile = cu->objfile;
11586 struct comp_unit_head *cu_header = &cu->header;
11588 /* NOTE drow/2003-01-30: There used to be a comment and some special
11589 code here to turn a symbol with DW_AT_external and a
11590 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11591 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11592 with some versions of binutils) where shared libraries could have
11593 relocations against symbols in their debug information - the
11594 minimal symbol would have the right address, but the debug info
11595 would not. It's no longer necessary, because we will explicitly
11596 apply relocations when we read in the debug information now. */
11598 /* A DW_AT_location attribute with no contents indicates that a
11599 variable has been optimized away. */
11600 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11602 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11606 /* Handle one degenerate form of location expression specially, to
11607 preserve GDB's previous behavior when section offsets are
11608 specified. If this is just a DW_OP_addr then mark this symbol
11611 if (attr_form_is_block (attr)
11612 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11613 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11615 unsigned int dummy;
11617 SYMBOL_VALUE_ADDRESS (sym) =
11618 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11619 SYMBOL_CLASS (sym) = LOC_STATIC;
11620 fixup_symbol_section (sym, objfile);
11621 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11622 SYMBOL_SECTION (sym));
11626 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11627 expression evaluator, and use LOC_COMPUTED only when necessary
11628 (i.e. when the value of a register or memory location is
11629 referenced, or a thread-local block, etc.). Then again, it might
11630 not be worthwhile. I'm assuming that it isn't unless performance
11631 or memory numbers show me otherwise. */
11633 dwarf2_symbol_mark_computed (attr, sym, cu);
11634 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11636 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11637 cu->has_loclist = 1;
11640 /* Given a pointer to a DWARF information entry, figure out if we need
11641 to make a symbol table entry for it, and if so, create a new entry
11642 and return a pointer to it.
11643 If TYPE is NULL, determine symbol type from the die, otherwise
11644 used the passed type.
11645 If SPACE is not NULL, use it to hold the new symbol. If it is
11646 NULL, allocate a new symbol on the objfile's obstack. */
11648 static struct symbol *
11649 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11650 struct symbol *space)
11652 struct objfile *objfile = cu->objfile;
11653 struct symbol *sym = NULL;
11655 struct attribute *attr = NULL;
11656 struct attribute *attr2 = NULL;
11657 CORE_ADDR baseaddr;
11658 struct pending **list_to_add = NULL;
11660 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11662 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11664 name = dwarf2_name (die, cu);
11667 const char *linkagename;
11668 int suppress_add = 0;
11673 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11674 OBJSTAT (objfile, n_syms++);
11676 /* Cache this symbol's name and the name's demangled form (if any). */
11677 SYMBOL_SET_LANGUAGE (sym, cu->language);
11678 linkagename = dwarf2_physname (name, die, cu);
11679 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11681 /* Fortran does not have mangling standard and the mangling does differ
11682 between gfortran, iFort etc. */
11683 if (cu->language == language_fortran
11684 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11685 symbol_set_demangled_name (&(sym->ginfo),
11686 (char *) dwarf2_full_name (name, die, cu),
11689 /* Default assumptions.
11690 Use the passed type or decode it from the die. */
11691 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11692 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11694 SYMBOL_TYPE (sym) = type;
11696 SYMBOL_TYPE (sym) = die_type (die, cu);
11697 attr = dwarf2_attr (die,
11698 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11702 SYMBOL_LINE (sym) = DW_UNSND (attr);
11705 attr = dwarf2_attr (die,
11706 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11710 int file_index = DW_UNSND (attr);
11712 if (cu->line_header == NULL
11713 || file_index > cu->line_header->num_file_names)
11714 complaint (&symfile_complaints,
11715 _("file index out of range"));
11716 else if (file_index > 0)
11718 struct file_entry *fe;
11720 fe = &cu->line_header->file_names[file_index - 1];
11721 SYMBOL_SYMTAB (sym) = fe->symtab;
11728 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11731 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11733 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11734 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11735 SYMBOL_CLASS (sym) = LOC_LABEL;
11736 add_symbol_to_list (sym, cu->list_in_scope);
11738 case DW_TAG_subprogram:
11739 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11741 SYMBOL_CLASS (sym) = LOC_BLOCK;
11742 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11743 if ((attr2 && (DW_UNSND (attr2) != 0))
11744 || cu->language == language_ada)
11746 /* Subprograms marked external are stored as a global symbol.
11747 Ada subprograms, whether marked external or not, are always
11748 stored as a global symbol, because we want to be able to
11749 access them globally. For instance, we want to be able
11750 to break on a nested subprogram without having to
11751 specify the context. */
11752 list_to_add = &global_symbols;
11756 list_to_add = cu->list_in_scope;
11759 case DW_TAG_inlined_subroutine:
11760 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11762 SYMBOL_CLASS (sym) = LOC_BLOCK;
11763 SYMBOL_INLINED (sym) = 1;
11764 list_to_add = cu->list_in_scope;
11766 case DW_TAG_template_value_param:
11768 /* Fall through. */
11769 case DW_TAG_constant:
11770 case DW_TAG_variable:
11771 case DW_TAG_member:
11772 /* Compilation with minimal debug info may result in
11773 variables with missing type entries. Change the
11774 misleading `void' type to something sensible. */
11775 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11777 = objfile_type (objfile)->nodebug_data_symbol;
11779 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11780 /* In the case of DW_TAG_member, we should only be called for
11781 static const members. */
11782 if (die->tag == DW_TAG_member)
11784 /* dwarf2_add_field uses die_is_declaration,
11785 so we do the same. */
11786 gdb_assert (die_is_declaration (die, cu));
11791 dwarf2_const_value (attr, sym, cu);
11792 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11795 if (attr2 && (DW_UNSND (attr2) != 0))
11796 list_to_add = &global_symbols;
11798 list_to_add = cu->list_in_scope;
11802 attr = dwarf2_attr (die, DW_AT_location, cu);
11805 var_decode_location (attr, sym, cu);
11806 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11807 if (SYMBOL_CLASS (sym) == LOC_STATIC
11808 && SYMBOL_VALUE_ADDRESS (sym) == 0
11809 && !dwarf2_per_objfile->has_section_at_zero)
11811 /* When a static variable is eliminated by the linker,
11812 the corresponding debug information is not stripped
11813 out, but the variable address is set to null;
11814 do not add such variables into symbol table. */
11816 else if (attr2 && (DW_UNSND (attr2) != 0))
11818 /* Workaround gfortran PR debug/40040 - it uses
11819 DW_AT_location for variables in -fPIC libraries which may
11820 get overriden by other libraries/executable and get
11821 a different address. Resolve it by the minimal symbol
11822 which may come from inferior's executable using copy
11823 relocation. Make this workaround only for gfortran as for
11824 other compilers GDB cannot guess the minimal symbol
11825 Fortran mangling kind. */
11826 if (cu->language == language_fortran && die->parent
11827 && die->parent->tag == DW_TAG_module
11829 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11830 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11832 /* A variable with DW_AT_external is never static,
11833 but it may be block-scoped. */
11834 list_to_add = (cu->list_in_scope == &file_symbols
11835 ? &global_symbols : cu->list_in_scope);
11838 list_to_add = cu->list_in_scope;
11842 /* We do not know the address of this symbol.
11843 If it is an external symbol and we have type information
11844 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11845 The address of the variable will then be determined from
11846 the minimal symbol table whenever the variable is
11848 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11849 if (attr2 && (DW_UNSND (attr2) != 0)
11850 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11852 /* A variable with DW_AT_external is never static, but it
11853 may be block-scoped. */
11854 list_to_add = (cu->list_in_scope == &file_symbols
11855 ? &global_symbols : cu->list_in_scope);
11857 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11859 else if (!die_is_declaration (die, cu))
11861 /* Use the default LOC_OPTIMIZED_OUT class. */
11862 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11864 list_to_add = cu->list_in_scope;
11868 case DW_TAG_formal_parameter:
11869 /* If we are inside a function, mark this as an argument. If
11870 not, we might be looking at an argument to an inlined function
11871 when we do not have enough information to show inlined frames;
11872 pretend it's a local variable in that case so that the user can
11874 if (context_stack_depth > 0
11875 && context_stack[context_stack_depth - 1].name != NULL)
11876 SYMBOL_IS_ARGUMENT (sym) = 1;
11877 attr = dwarf2_attr (die, DW_AT_location, cu);
11880 var_decode_location (attr, sym, cu);
11882 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11885 dwarf2_const_value (attr, sym, cu);
11888 list_to_add = cu->list_in_scope;
11890 case DW_TAG_unspecified_parameters:
11891 /* From varargs functions; gdb doesn't seem to have any
11892 interest in this information, so just ignore it for now.
11895 case DW_TAG_template_type_param:
11897 /* Fall through. */
11898 case DW_TAG_class_type:
11899 case DW_TAG_interface_type:
11900 case DW_TAG_structure_type:
11901 case DW_TAG_union_type:
11902 case DW_TAG_set_type:
11903 case DW_TAG_enumeration_type:
11904 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11905 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11908 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11909 really ever be static objects: otherwise, if you try
11910 to, say, break of a class's method and you're in a file
11911 which doesn't mention that class, it won't work unless
11912 the check for all static symbols in lookup_symbol_aux
11913 saves you. See the OtherFileClass tests in
11914 gdb.c++/namespace.exp. */
11918 list_to_add = (cu->list_in_scope == &file_symbols
11919 && (cu->language == language_cplus
11920 || cu->language == language_java)
11921 ? &global_symbols : cu->list_in_scope);
11923 /* The semantics of C++ state that "struct foo {
11924 ... }" also defines a typedef for "foo". A Java
11925 class declaration also defines a typedef for the
11927 if (cu->language == language_cplus
11928 || cu->language == language_java
11929 || cu->language == language_ada)
11931 /* The symbol's name is already allocated along
11932 with this objfile, so we don't need to
11933 duplicate it for the type. */
11934 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11935 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11940 case DW_TAG_typedef:
11941 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11942 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11943 list_to_add = cu->list_in_scope;
11945 case DW_TAG_base_type:
11946 case DW_TAG_subrange_type:
11947 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11948 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11949 list_to_add = cu->list_in_scope;
11951 case DW_TAG_enumerator:
11952 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11955 dwarf2_const_value (attr, sym, cu);
11958 /* NOTE: carlton/2003-11-10: See comment above in the
11959 DW_TAG_class_type, etc. block. */
11961 list_to_add = (cu->list_in_scope == &file_symbols
11962 && (cu->language == language_cplus
11963 || cu->language == language_java)
11964 ? &global_symbols : cu->list_in_scope);
11967 case DW_TAG_namespace:
11968 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11969 list_to_add = &global_symbols;
11972 /* Not a tag we recognize. Hopefully we aren't processing
11973 trash data, but since we must specifically ignore things
11974 we don't recognize, there is nothing else we should do at
11976 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11977 dwarf_tag_name (die->tag));
11983 sym->hash_next = objfile->template_symbols;
11984 objfile->template_symbols = sym;
11985 list_to_add = NULL;
11988 if (list_to_add != NULL)
11989 add_symbol_to_list (sym, list_to_add);
11991 /* For the benefit of old versions of GCC, check for anonymous
11992 namespaces based on the demangled name. */
11993 if (!processing_has_namespace_info
11994 && cu->language == language_cplus)
11995 cp_scan_for_anonymous_namespaces (sym, objfile);
12000 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12002 static struct symbol *
12003 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
12005 return new_symbol_full (die, type, cu, NULL);
12008 /* Given an attr with a DW_FORM_dataN value in host byte order,
12009 zero-extend it as appropriate for the symbol's type. The DWARF
12010 standard (v4) is not entirely clear about the meaning of using
12011 DW_FORM_dataN for a constant with a signed type, where the type is
12012 wider than the data. The conclusion of a discussion on the DWARF
12013 list was that this is unspecified. We choose to always zero-extend
12014 because that is the interpretation long in use by GCC. */
12017 dwarf2_const_value_data (struct attribute *attr, struct type *type,
12018 const char *name, struct obstack *obstack,
12019 struct dwarf2_cu *cu, long *value, int bits)
12021 struct objfile *objfile = cu->objfile;
12022 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
12023 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
12024 LONGEST l = DW_UNSND (attr);
12026 if (bits < sizeof (*value) * 8)
12028 l &= ((LONGEST) 1 << bits) - 1;
12031 else if (bits == sizeof (*value) * 8)
12035 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
12036 store_unsigned_integer (bytes, bits / 8, byte_order, l);
12043 /* Read a constant value from an attribute. Either set *VALUE, or if
12044 the value does not fit in *VALUE, set *BYTES - either already
12045 allocated on the objfile obstack, or newly allocated on OBSTACK,
12046 or, set *BATON, if we translated the constant to a location
12050 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
12051 const char *name, struct obstack *obstack,
12052 struct dwarf2_cu *cu,
12053 long *value, gdb_byte **bytes,
12054 struct dwarf2_locexpr_baton **baton)
12056 struct objfile *objfile = cu->objfile;
12057 struct comp_unit_head *cu_header = &cu->header;
12058 struct dwarf_block *blk;
12059 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
12060 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
12066 switch (attr->form)
12072 if (TYPE_LENGTH (type) != cu_header->addr_size)
12073 dwarf2_const_value_length_mismatch_complaint (name,
12074 cu_header->addr_size,
12075 TYPE_LENGTH (type));
12076 /* Symbols of this form are reasonably rare, so we just
12077 piggyback on the existing location code rather than writing
12078 a new implementation of symbol_computed_ops. */
12079 *baton = obstack_alloc (&objfile->objfile_obstack,
12080 sizeof (struct dwarf2_locexpr_baton));
12081 (*baton)->per_cu = cu->per_cu;
12082 gdb_assert ((*baton)->per_cu);
12084 (*baton)->size = 2 + cu_header->addr_size;
12085 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
12086 (*baton)->data = data;
12088 data[0] = DW_OP_addr;
12089 store_unsigned_integer (&data[1], cu_header->addr_size,
12090 byte_order, DW_ADDR (attr));
12091 data[cu_header->addr_size + 1] = DW_OP_stack_value;
12094 case DW_FORM_string:
12096 /* DW_STRING is already allocated on the objfile obstack, point
12098 *bytes = (gdb_byte *) DW_STRING (attr);
12100 case DW_FORM_block1:
12101 case DW_FORM_block2:
12102 case DW_FORM_block4:
12103 case DW_FORM_block:
12104 case DW_FORM_exprloc:
12105 blk = DW_BLOCK (attr);
12106 if (TYPE_LENGTH (type) != blk->size)
12107 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
12108 TYPE_LENGTH (type));
12109 *bytes = blk->data;
12112 /* The DW_AT_const_value attributes are supposed to carry the
12113 symbol's value "represented as it would be on the target
12114 architecture." By the time we get here, it's already been
12115 converted to host endianness, so we just need to sign- or
12116 zero-extend it as appropriate. */
12117 case DW_FORM_data1:
12118 *bytes = dwarf2_const_value_data (attr, type, name,
12119 obstack, cu, value, 8);
12121 case DW_FORM_data2:
12122 *bytes = dwarf2_const_value_data (attr, type, name,
12123 obstack, cu, value, 16);
12125 case DW_FORM_data4:
12126 *bytes = dwarf2_const_value_data (attr, type, name,
12127 obstack, cu, value, 32);
12129 case DW_FORM_data8:
12130 *bytes = dwarf2_const_value_data (attr, type, name,
12131 obstack, cu, value, 64);
12134 case DW_FORM_sdata:
12135 *value = DW_SND (attr);
12138 case DW_FORM_udata:
12139 *value = DW_UNSND (attr);
12143 complaint (&symfile_complaints,
12144 _("unsupported const value attribute form: '%s'"),
12145 dwarf_form_name (attr->form));
12152 /* Copy constant value from an attribute to a symbol. */
12155 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
12156 struct dwarf2_cu *cu)
12158 struct objfile *objfile = cu->objfile;
12159 struct comp_unit_head *cu_header = &cu->header;
12162 struct dwarf2_locexpr_baton *baton;
12164 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
12165 SYMBOL_PRINT_NAME (sym),
12166 &objfile->objfile_obstack, cu,
12167 &value, &bytes, &baton);
12171 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12172 SYMBOL_LOCATION_BATON (sym) = baton;
12173 SYMBOL_CLASS (sym) = LOC_COMPUTED;
12175 else if (bytes != NULL)
12177 SYMBOL_VALUE_BYTES (sym) = bytes;
12178 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
12182 SYMBOL_VALUE (sym) = value;
12183 SYMBOL_CLASS (sym) = LOC_CONST;
12187 /* Return the type of the die in question using its DW_AT_type attribute. */
12189 static struct type *
12190 die_type (struct die_info *die, struct dwarf2_cu *cu)
12192 struct attribute *type_attr;
12194 type_attr = dwarf2_attr (die, DW_AT_type, cu);
12197 /* A missing DW_AT_type represents a void type. */
12198 return objfile_type (cu->objfile)->builtin_void;
12201 return lookup_die_type (die, type_attr, cu);
12204 /* True iff CU's producer generates GNAT Ada auxiliary information
12205 that allows to find parallel types through that information instead
12206 of having to do expensive parallel lookups by type name. */
12209 need_gnat_info (struct dwarf2_cu *cu)
12211 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12212 of GNAT produces this auxiliary information, without any indication
12213 that it is produced. Part of enhancing the FSF version of GNAT
12214 to produce that information will be to put in place an indicator
12215 that we can use in order to determine whether the descriptive type
12216 info is available or not. One suggestion that has been made is
12217 to use a new attribute, attached to the CU die. For now, assume
12218 that the descriptive type info is not available. */
12222 /* Return the auxiliary type of the die in question using its
12223 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12224 attribute is not present. */
12226 static struct type *
12227 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
12229 struct attribute *type_attr;
12231 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
12235 return lookup_die_type (die, type_attr, cu);
12238 /* If DIE has a descriptive_type attribute, then set the TYPE's
12239 descriptive type accordingly. */
12242 set_descriptive_type (struct type *type, struct die_info *die,
12243 struct dwarf2_cu *cu)
12245 struct type *descriptive_type = die_descriptive_type (die, cu);
12247 if (descriptive_type)
12249 ALLOCATE_GNAT_AUX_TYPE (type);
12250 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
12254 /* Return the containing type of the die in question using its
12255 DW_AT_containing_type attribute. */
12257 static struct type *
12258 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12260 struct attribute *type_attr;
12262 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
12264 error (_("Dwarf Error: Problem turning containing type into gdb type "
12265 "[in module %s]"), cu->objfile->name);
12267 return lookup_die_type (die, type_attr, cu);
12270 /* Look up the type of DIE in CU using its type attribute ATTR.
12271 If there is no type substitute an error marker. */
12273 static struct type *
12274 lookup_die_type (struct die_info *die, struct attribute *attr,
12275 struct dwarf2_cu *cu)
12277 struct objfile *objfile = cu->objfile;
12278 struct type *this_type;
12280 /* First see if we have it cached. */
12282 if (is_ref_attr (attr))
12284 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12286 this_type = get_die_type_at_offset (offset, cu->per_cu);
12288 else if (attr->form == DW_FORM_ref_sig8)
12290 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12291 struct dwarf2_cu *sig_cu;
12292 unsigned int offset;
12294 /* sig_type will be NULL if the signatured type is missing from
12296 if (sig_type == NULL)
12297 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12298 "at 0x%x [in module %s]"),
12299 die->offset, objfile->name);
12301 gdb_assert (sig_type->per_cu.debug_types_section);
12302 offset = sig_type->per_cu.offset + sig_type->type_offset;
12303 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
12307 dump_die_for_error (die);
12308 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12309 dwarf_attr_name (attr->name), objfile->name);
12312 /* If not cached we need to read it in. */
12314 if (this_type == NULL)
12316 struct die_info *type_die;
12317 struct dwarf2_cu *type_cu = cu;
12319 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
12320 /* If the type is cached, we should have found it above. */
12321 gdb_assert (get_die_type (type_die, type_cu) == NULL);
12322 this_type = read_type_die_1 (type_die, type_cu);
12325 /* If we still don't have a type use an error marker. */
12327 if (this_type == NULL)
12329 char *message, *saved;
12331 /* read_type_die already issued a complaint. */
12332 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12336 saved = obstack_copy0 (&objfile->objfile_obstack,
12337 message, strlen (message));
12340 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
12346 /* Return the type in DIE, CU.
12347 Returns NULL for invalid types.
12349 This first does a lookup in the appropriate type_hash table,
12350 and only reads the die in if necessary.
12352 NOTE: This can be called when reading in partial or full symbols. */
12354 static struct type *
12355 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12357 struct type *this_type;
12359 this_type = get_die_type (die, cu);
12363 return read_type_die_1 (die, cu);
12366 /* Read the type in DIE, CU.
12367 Returns NULL for invalid types. */
12369 static struct type *
12370 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12372 struct type *this_type = NULL;
12376 case DW_TAG_class_type:
12377 case DW_TAG_interface_type:
12378 case DW_TAG_structure_type:
12379 case DW_TAG_union_type:
12380 this_type = read_structure_type (die, cu);
12382 case DW_TAG_enumeration_type:
12383 this_type = read_enumeration_type (die, cu);
12385 case DW_TAG_subprogram:
12386 case DW_TAG_subroutine_type:
12387 case DW_TAG_inlined_subroutine:
12388 this_type = read_subroutine_type (die, cu);
12390 case DW_TAG_array_type:
12391 this_type = read_array_type (die, cu);
12393 case DW_TAG_set_type:
12394 this_type = read_set_type (die, cu);
12396 case DW_TAG_pointer_type:
12397 this_type = read_tag_pointer_type (die, cu);
12399 case DW_TAG_ptr_to_member_type:
12400 this_type = read_tag_ptr_to_member_type (die, cu);
12402 case DW_TAG_reference_type:
12403 this_type = read_tag_reference_type (die, cu);
12405 case DW_TAG_const_type:
12406 this_type = read_tag_const_type (die, cu);
12408 case DW_TAG_volatile_type:
12409 this_type = read_tag_volatile_type (die, cu);
12411 case DW_TAG_string_type:
12412 this_type = read_tag_string_type (die, cu);
12414 case DW_TAG_typedef:
12415 this_type = read_typedef (die, cu);
12417 case DW_TAG_subrange_type:
12418 this_type = read_subrange_type (die, cu);
12420 case DW_TAG_base_type:
12421 this_type = read_base_type (die, cu);
12423 case DW_TAG_unspecified_type:
12424 this_type = read_unspecified_type (die, cu);
12426 case DW_TAG_namespace:
12427 this_type = read_namespace_type (die, cu);
12429 case DW_TAG_module:
12430 this_type = read_module_type (die, cu);
12433 complaint (&symfile_complaints,
12434 _("unexpected tag in read_type_die: '%s'"),
12435 dwarf_tag_name (die->tag));
12442 /* See if we can figure out if the class lives in a namespace. We do
12443 this by looking for a member function; its demangled name will
12444 contain namespace info, if there is any.
12445 Return the computed name or NULL.
12446 Space for the result is allocated on the objfile's obstack.
12447 This is the full-die version of guess_partial_die_structure_name.
12448 In this case we know DIE has no useful parent. */
12451 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12453 struct die_info *spec_die;
12454 struct dwarf2_cu *spec_cu;
12455 struct die_info *child;
12458 spec_die = die_specification (die, &spec_cu);
12459 if (spec_die != NULL)
12465 for (child = die->child;
12467 child = child->sibling)
12469 if (child->tag == DW_TAG_subprogram)
12471 struct attribute *attr;
12473 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12475 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12479 = language_class_name_from_physname (cu->language_defn,
12483 if (actual_name != NULL)
12485 char *die_name = dwarf2_name (die, cu);
12487 if (die_name != NULL
12488 && strcmp (die_name, actual_name) != 0)
12490 /* Strip off the class name from the full name.
12491 We want the prefix. */
12492 int die_name_len = strlen (die_name);
12493 int actual_name_len = strlen (actual_name);
12495 /* Test for '::' as a sanity check. */
12496 if (actual_name_len > die_name_len + 2
12497 && actual_name[actual_name_len
12498 - die_name_len - 1] == ':')
12500 obsavestring (actual_name,
12501 actual_name_len - die_name_len - 2,
12502 &cu->objfile->objfile_obstack);
12505 xfree (actual_name);
12514 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12515 prefix part in such case. See
12516 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12519 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12521 struct attribute *attr;
12524 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12525 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12528 attr = dwarf2_attr (die, DW_AT_name, cu);
12529 if (attr != NULL && DW_STRING (attr) != NULL)
12532 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12534 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12535 if (attr == NULL || DW_STRING (attr) == NULL)
12538 /* dwarf2_name had to be already called. */
12539 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12541 /* Strip the base name, keep any leading namespaces/classes. */
12542 base = strrchr (DW_STRING (attr), ':');
12543 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12546 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12547 &cu->objfile->objfile_obstack);
12550 /* Return the name of the namespace/class that DIE is defined within,
12551 or "" if we can't tell. The caller should not xfree the result.
12553 For example, if we're within the method foo() in the following
12563 then determine_prefix on foo's die will return "N::C". */
12565 static const char *
12566 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12568 struct die_info *parent, *spec_die;
12569 struct dwarf2_cu *spec_cu;
12570 struct type *parent_type;
12573 if (cu->language != language_cplus && cu->language != language_java
12574 && cu->language != language_fortran)
12577 retval = anonymous_struct_prefix (die, cu);
12581 /* We have to be careful in the presence of DW_AT_specification.
12582 For example, with GCC 3.4, given the code
12586 // Definition of N::foo.
12590 then we'll have a tree of DIEs like this:
12592 1: DW_TAG_compile_unit
12593 2: DW_TAG_namespace // N
12594 3: DW_TAG_subprogram // declaration of N::foo
12595 4: DW_TAG_subprogram // definition of N::foo
12596 DW_AT_specification // refers to die #3
12598 Thus, when processing die #4, we have to pretend that we're in
12599 the context of its DW_AT_specification, namely the contex of die
12602 spec_die = die_specification (die, &spec_cu);
12603 if (spec_die == NULL)
12604 parent = die->parent;
12607 parent = spec_die->parent;
12611 if (parent == NULL)
12613 else if (parent->building_fullname)
12616 const char *parent_name;
12618 /* It has been seen on RealView 2.2 built binaries,
12619 DW_TAG_template_type_param types actually _defined_ as
12620 children of the parent class:
12623 template class <class Enum> Class{};
12624 Class<enum E> class_e;
12626 1: DW_TAG_class_type (Class)
12627 2: DW_TAG_enumeration_type (E)
12628 3: DW_TAG_enumerator (enum1:0)
12629 3: DW_TAG_enumerator (enum2:1)
12631 2: DW_TAG_template_type_param
12632 DW_AT_type DW_FORM_ref_udata (E)
12634 Besides being broken debug info, it can put GDB into an
12635 infinite loop. Consider:
12637 When we're building the full name for Class<E>, we'll start
12638 at Class, and go look over its template type parameters,
12639 finding E. We'll then try to build the full name of E, and
12640 reach here. We're now trying to build the full name of E,
12641 and look over the parent DIE for containing scope. In the
12642 broken case, if we followed the parent DIE of E, we'd again
12643 find Class, and once again go look at its template type
12644 arguments, etc., etc. Simply don't consider such parent die
12645 as source-level parent of this die (it can't be, the language
12646 doesn't allow it), and break the loop here. */
12647 name = dwarf2_name (die, cu);
12648 parent_name = dwarf2_name (parent, cu);
12649 complaint (&symfile_complaints,
12650 _("template param type '%s' defined within parent '%s'"),
12651 name ? name : "<unknown>",
12652 parent_name ? parent_name : "<unknown>");
12656 switch (parent->tag)
12658 case DW_TAG_namespace:
12659 parent_type = read_type_die (parent, cu);
12660 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12661 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12662 Work around this problem here. */
12663 if (cu->language == language_cplus
12664 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12666 /* We give a name to even anonymous namespaces. */
12667 return TYPE_TAG_NAME (parent_type);
12668 case DW_TAG_class_type:
12669 case DW_TAG_interface_type:
12670 case DW_TAG_structure_type:
12671 case DW_TAG_union_type:
12672 case DW_TAG_module:
12673 parent_type = read_type_die (parent, cu);
12674 if (TYPE_TAG_NAME (parent_type) != NULL)
12675 return TYPE_TAG_NAME (parent_type);
12677 /* An anonymous structure is only allowed non-static data
12678 members; no typedefs, no member functions, et cetera.
12679 So it does not need a prefix. */
12681 case DW_TAG_compile_unit:
12682 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12683 if (cu->language == language_cplus
12684 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12685 && die->child != NULL
12686 && (die->tag == DW_TAG_class_type
12687 || die->tag == DW_TAG_structure_type
12688 || die->tag == DW_TAG_union_type))
12690 char *name = guess_full_die_structure_name (die, cu);
12696 return determine_prefix (parent, cu);
12700 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12701 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12702 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12703 an obconcat, otherwise allocate storage for the result. The CU argument is
12704 used to determine the language and hence, the appropriate separator. */
12706 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12709 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12710 int physname, struct dwarf2_cu *cu)
12712 const char *lead = "";
12715 if (suffix == NULL || suffix[0] == '\0'
12716 || prefix == NULL || prefix[0] == '\0')
12718 else if (cu->language == language_java)
12720 else if (cu->language == language_fortran && physname)
12722 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12723 DW_AT_MIPS_linkage_name is preferred and used instead. */
12731 if (prefix == NULL)
12733 if (suffix == NULL)
12739 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12741 strcpy (retval, lead);
12742 strcat (retval, prefix);
12743 strcat (retval, sep);
12744 strcat (retval, suffix);
12749 /* We have an obstack. */
12750 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12754 /* Return sibling of die, NULL if no sibling. */
12756 static struct die_info *
12757 sibling_die (struct die_info *die)
12759 return die->sibling;
12762 /* Get name of a die, return NULL if not found. */
12765 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12766 struct obstack *obstack)
12768 if (name && cu->language == language_cplus)
12770 char *canon_name = cp_canonicalize_string (name);
12772 if (canon_name != NULL)
12774 if (strcmp (canon_name, name) != 0)
12775 name = obsavestring (canon_name, strlen (canon_name),
12777 xfree (canon_name);
12784 /* Get name of a die, return NULL if not found. */
12787 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12789 struct attribute *attr;
12791 attr = dwarf2_attr (die, DW_AT_name, cu);
12792 if ((!attr || !DW_STRING (attr))
12793 && die->tag != DW_TAG_class_type
12794 && die->tag != DW_TAG_interface_type
12795 && die->tag != DW_TAG_structure_type
12796 && die->tag != DW_TAG_union_type)
12801 case DW_TAG_compile_unit:
12802 /* Compilation units have a DW_AT_name that is a filename, not
12803 a source language identifier. */
12804 case DW_TAG_enumeration_type:
12805 case DW_TAG_enumerator:
12806 /* These tags always have simple identifiers already; no need
12807 to canonicalize them. */
12808 return DW_STRING (attr);
12810 case DW_TAG_subprogram:
12811 /* Java constructors will all be named "<init>", so return
12812 the class name when we see this special case. */
12813 if (cu->language == language_java
12814 && DW_STRING (attr) != NULL
12815 && strcmp (DW_STRING (attr), "<init>") == 0)
12817 struct dwarf2_cu *spec_cu = cu;
12818 struct die_info *spec_die;
12820 /* GCJ will output '<init>' for Java constructor names.
12821 For this special case, return the name of the parent class. */
12823 /* GCJ may output suprogram DIEs with AT_specification set.
12824 If so, use the name of the specified DIE. */
12825 spec_die = die_specification (die, &spec_cu);
12826 if (spec_die != NULL)
12827 return dwarf2_name (spec_die, spec_cu);
12832 if (die->tag == DW_TAG_class_type)
12833 return dwarf2_name (die, cu);
12835 while (die->tag != DW_TAG_compile_unit);
12839 case DW_TAG_class_type:
12840 case DW_TAG_interface_type:
12841 case DW_TAG_structure_type:
12842 case DW_TAG_union_type:
12843 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12844 structures or unions. These were of the form "._%d" in GCC 4.1,
12845 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12846 and GCC 4.4. We work around this problem by ignoring these. */
12847 if (attr && DW_STRING (attr)
12848 && (strncmp (DW_STRING (attr), "._", 2) == 0
12849 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12852 /* GCC might emit a nameless typedef that has a linkage name. See
12853 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12854 if (!attr || DW_STRING (attr) == NULL)
12856 char *demangled = NULL;
12858 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12860 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12862 if (attr == NULL || DW_STRING (attr) == NULL)
12865 /* Avoid demangling DW_STRING (attr) the second time on a second
12866 call for the same DIE. */
12867 if (!DW_STRING_IS_CANONICAL (attr))
12868 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12874 /* FIXME: we already did this for the partial symbol... */
12875 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
12876 &cu->objfile->objfile_obstack);
12877 DW_STRING_IS_CANONICAL (attr) = 1;
12880 /* Strip any leading namespaces/classes, keep only the base name.
12881 DW_AT_name for named DIEs does not contain the prefixes. */
12882 base = strrchr (DW_STRING (attr), ':');
12883 if (base && base > DW_STRING (attr) && base[-1] == ':')
12886 return DW_STRING (attr);
12895 if (!DW_STRING_IS_CANONICAL (attr))
12898 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12899 &cu->objfile->objfile_obstack);
12900 DW_STRING_IS_CANONICAL (attr) = 1;
12902 return DW_STRING (attr);
12905 /* Return the die that this die in an extension of, or NULL if there
12906 is none. *EXT_CU is the CU containing DIE on input, and the CU
12907 containing the return value on output. */
12909 static struct die_info *
12910 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12912 struct attribute *attr;
12914 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12918 return follow_die_ref (die, attr, ext_cu);
12921 /* Convert a DIE tag into its string name. */
12924 dwarf_tag_name (unsigned tag)
12928 case DW_TAG_padding:
12929 return "DW_TAG_padding";
12930 case DW_TAG_array_type:
12931 return "DW_TAG_array_type";
12932 case DW_TAG_class_type:
12933 return "DW_TAG_class_type";
12934 case DW_TAG_entry_point:
12935 return "DW_TAG_entry_point";
12936 case DW_TAG_enumeration_type:
12937 return "DW_TAG_enumeration_type";
12938 case DW_TAG_formal_parameter:
12939 return "DW_TAG_formal_parameter";
12940 case DW_TAG_imported_declaration:
12941 return "DW_TAG_imported_declaration";
12943 return "DW_TAG_label";
12944 case DW_TAG_lexical_block:
12945 return "DW_TAG_lexical_block";
12946 case DW_TAG_member:
12947 return "DW_TAG_member";
12948 case DW_TAG_pointer_type:
12949 return "DW_TAG_pointer_type";
12950 case DW_TAG_reference_type:
12951 return "DW_TAG_reference_type";
12952 case DW_TAG_compile_unit:
12953 return "DW_TAG_compile_unit";
12954 case DW_TAG_string_type:
12955 return "DW_TAG_string_type";
12956 case DW_TAG_structure_type:
12957 return "DW_TAG_structure_type";
12958 case DW_TAG_subroutine_type:
12959 return "DW_TAG_subroutine_type";
12960 case DW_TAG_typedef:
12961 return "DW_TAG_typedef";
12962 case DW_TAG_union_type:
12963 return "DW_TAG_union_type";
12964 case DW_TAG_unspecified_parameters:
12965 return "DW_TAG_unspecified_parameters";
12966 case DW_TAG_variant:
12967 return "DW_TAG_variant";
12968 case DW_TAG_common_block:
12969 return "DW_TAG_common_block";
12970 case DW_TAG_common_inclusion:
12971 return "DW_TAG_common_inclusion";
12972 case DW_TAG_inheritance:
12973 return "DW_TAG_inheritance";
12974 case DW_TAG_inlined_subroutine:
12975 return "DW_TAG_inlined_subroutine";
12976 case DW_TAG_module:
12977 return "DW_TAG_module";
12978 case DW_TAG_ptr_to_member_type:
12979 return "DW_TAG_ptr_to_member_type";
12980 case DW_TAG_set_type:
12981 return "DW_TAG_set_type";
12982 case DW_TAG_subrange_type:
12983 return "DW_TAG_subrange_type";
12984 case DW_TAG_with_stmt:
12985 return "DW_TAG_with_stmt";
12986 case DW_TAG_access_declaration:
12987 return "DW_TAG_access_declaration";
12988 case DW_TAG_base_type:
12989 return "DW_TAG_base_type";
12990 case DW_TAG_catch_block:
12991 return "DW_TAG_catch_block";
12992 case DW_TAG_const_type:
12993 return "DW_TAG_const_type";
12994 case DW_TAG_constant:
12995 return "DW_TAG_constant";
12996 case DW_TAG_enumerator:
12997 return "DW_TAG_enumerator";
12998 case DW_TAG_file_type:
12999 return "DW_TAG_file_type";
13000 case DW_TAG_friend:
13001 return "DW_TAG_friend";
13002 case DW_TAG_namelist:
13003 return "DW_TAG_namelist";
13004 case DW_TAG_namelist_item:
13005 return "DW_TAG_namelist_item";
13006 case DW_TAG_packed_type:
13007 return "DW_TAG_packed_type";
13008 case DW_TAG_subprogram:
13009 return "DW_TAG_subprogram";
13010 case DW_TAG_template_type_param:
13011 return "DW_TAG_template_type_param";
13012 case DW_TAG_template_value_param:
13013 return "DW_TAG_template_value_param";
13014 case DW_TAG_thrown_type:
13015 return "DW_TAG_thrown_type";
13016 case DW_TAG_try_block:
13017 return "DW_TAG_try_block";
13018 case DW_TAG_variant_part:
13019 return "DW_TAG_variant_part";
13020 case DW_TAG_variable:
13021 return "DW_TAG_variable";
13022 case DW_TAG_volatile_type:
13023 return "DW_TAG_volatile_type";
13024 case DW_TAG_dwarf_procedure:
13025 return "DW_TAG_dwarf_procedure";
13026 case DW_TAG_restrict_type:
13027 return "DW_TAG_restrict_type";
13028 case DW_TAG_interface_type:
13029 return "DW_TAG_interface_type";
13030 case DW_TAG_namespace:
13031 return "DW_TAG_namespace";
13032 case DW_TAG_imported_module:
13033 return "DW_TAG_imported_module";
13034 case DW_TAG_unspecified_type:
13035 return "DW_TAG_unspecified_type";
13036 case DW_TAG_partial_unit:
13037 return "DW_TAG_partial_unit";
13038 case DW_TAG_imported_unit:
13039 return "DW_TAG_imported_unit";
13040 case DW_TAG_condition:
13041 return "DW_TAG_condition";
13042 case DW_TAG_shared_type:
13043 return "DW_TAG_shared_type";
13044 case DW_TAG_type_unit:
13045 return "DW_TAG_type_unit";
13046 case DW_TAG_MIPS_loop:
13047 return "DW_TAG_MIPS_loop";
13048 case DW_TAG_HP_array_descriptor:
13049 return "DW_TAG_HP_array_descriptor";
13050 case DW_TAG_format_label:
13051 return "DW_TAG_format_label";
13052 case DW_TAG_function_template:
13053 return "DW_TAG_function_template";
13054 case DW_TAG_class_template:
13055 return "DW_TAG_class_template";
13056 case DW_TAG_GNU_BINCL:
13057 return "DW_TAG_GNU_BINCL";
13058 case DW_TAG_GNU_EINCL:
13059 return "DW_TAG_GNU_EINCL";
13060 case DW_TAG_upc_shared_type:
13061 return "DW_TAG_upc_shared_type";
13062 case DW_TAG_upc_strict_type:
13063 return "DW_TAG_upc_strict_type";
13064 case DW_TAG_upc_relaxed_type:
13065 return "DW_TAG_upc_relaxed_type";
13066 case DW_TAG_PGI_kanji_type:
13067 return "DW_TAG_PGI_kanji_type";
13068 case DW_TAG_PGI_interface_block:
13069 return "DW_TAG_PGI_interface_block";
13070 case DW_TAG_GNU_call_site:
13071 return "DW_TAG_GNU_call_site";
13073 return "DW_TAG_<unknown>";
13077 /* Convert a DWARF attribute code into its string name. */
13080 dwarf_attr_name (unsigned attr)
13084 case DW_AT_sibling:
13085 return "DW_AT_sibling";
13086 case DW_AT_location:
13087 return "DW_AT_location";
13089 return "DW_AT_name";
13090 case DW_AT_ordering:
13091 return "DW_AT_ordering";
13092 case DW_AT_subscr_data:
13093 return "DW_AT_subscr_data";
13094 case DW_AT_byte_size:
13095 return "DW_AT_byte_size";
13096 case DW_AT_bit_offset:
13097 return "DW_AT_bit_offset";
13098 case DW_AT_bit_size:
13099 return "DW_AT_bit_size";
13100 case DW_AT_element_list:
13101 return "DW_AT_element_list";
13102 case DW_AT_stmt_list:
13103 return "DW_AT_stmt_list";
13105 return "DW_AT_low_pc";
13106 case DW_AT_high_pc:
13107 return "DW_AT_high_pc";
13108 case DW_AT_language:
13109 return "DW_AT_language";
13111 return "DW_AT_member";
13113 return "DW_AT_discr";
13114 case DW_AT_discr_value:
13115 return "DW_AT_discr_value";
13116 case DW_AT_visibility:
13117 return "DW_AT_visibility";
13119 return "DW_AT_import";
13120 case DW_AT_string_length:
13121 return "DW_AT_string_length";
13122 case DW_AT_common_reference:
13123 return "DW_AT_common_reference";
13124 case DW_AT_comp_dir:
13125 return "DW_AT_comp_dir";
13126 case DW_AT_const_value:
13127 return "DW_AT_const_value";
13128 case DW_AT_containing_type:
13129 return "DW_AT_containing_type";
13130 case DW_AT_default_value:
13131 return "DW_AT_default_value";
13133 return "DW_AT_inline";
13134 case DW_AT_is_optional:
13135 return "DW_AT_is_optional";
13136 case DW_AT_lower_bound:
13137 return "DW_AT_lower_bound";
13138 case DW_AT_producer:
13139 return "DW_AT_producer";
13140 case DW_AT_prototyped:
13141 return "DW_AT_prototyped";
13142 case DW_AT_return_addr:
13143 return "DW_AT_return_addr";
13144 case DW_AT_start_scope:
13145 return "DW_AT_start_scope";
13146 case DW_AT_bit_stride:
13147 return "DW_AT_bit_stride";
13148 case DW_AT_upper_bound:
13149 return "DW_AT_upper_bound";
13150 case DW_AT_abstract_origin:
13151 return "DW_AT_abstract_origin";
13152 case DW_AT_accessibility:
13153 return "DW_AT_accessibility";
13154 case DW_AT_address_class:
13155 return "DW_AT_address_class";
13156 case DW_AT_artificial:
13157 return "DW_AT_artificial";
13158 case DW_AT_base_types:
13159 return "DW_AT_base_types";
13160 case DW_AT_calling_convention:
13161 return "DW_AT_calling_convention";
13163 return "DW_AT_count";
13164 case DW_AT_data_member_location:
13165 return "DW_AT_data_member_location";
13166 case DW_AT_decl_column:
13167 return "DW_AT_decl_column";
13168 case DW_AT_decl_file:
13169 return "DW_AT_decl_file";
13170 case DW_AT_decl_line:
13171 return "DW_AT_decl_line";
13172 case DW_AT_declaration:
13173 return "DW_AT_declaration";
13174 case DW_AT_discr_list:
13175 return "DW_AT_discr_list";
13176 case DW_AT_encoding:
13177 return "DW_AT_encoding";
13178 case DW_AT_external:
13179 return "DW_AT_external";
13180 case DW_AT_frame_base:
13181 return "DW_AT_frame_base";
13183 return "DW_AT_friend";
13184 case DW_AT_identifier_case:
13185 return "DW_AT_identifier_case";
13186 case DW_AT_macro_info:
13187 return "DW_AT_macro_info";
13188 case DW_AT_namelist_items:
13189 return "DW_AT_namelist_items";
13190 case DW_AT_priority:
13191 return "DW_AT_priority";
13192 case DW_AT_segment:
13193 return "DW_AT_segment";
13194 case DW_AT_specification:
13195 return "DW_AT_specification";
13196 case DW_AT_static_link:
13197 return "DW_AT_static_link";
13199 return "DW_AT_type";
13200 case DW_AT_use_location:
13201 return "DW_AT_use_location";
13202 case DW_AT_variable_parameter:
13203 return "DW_AT_variable_parameter";
13204 case DW_AT_virtuality:
13205 return "DW_AT_virtuality";
13206 case DW_AT_vtable_elem_location:
13207 return "DW_AT_vtable_elem_location";
13208 /* DWARF 3 values. */
13209 case DW_AT_allocated:
13210 return "DW_AT_allocated";
13211 case DW_AT_associated:
13212 return "DW_AT_associated";
13213 case DW_AT_data_location:
13214 return "DW_AT_data_location";
13215 case DW_AT_byte_stride:
13216 return "DW_AT_byte_stride";
13217 case DW_AT_entry_pc:
13218 return "DW_AT_entry_pc";
13219 case DW_AT_use_UTF8:
13220 return "DW_AT_use_UTF8";
13221 case DW_AT_extension:
13222 return "DW_AT_extension";
13224 return "DW_AT_ranges";
13225 case DW_AT_trampoline:
13226 return "DW_AT_trampoline";
13227 case DW_AT_call_column:
13228 return "DW_AT_call_column";
13229 case DW_AT_call_file:
13230 return "DW_AT_call_file";
13231 case DW_AT_call_line:
13232 return "DW_AT_call_line";
13233 case DW_AT_description:
13234 return "DW_AT_description";
13235 case DW_AT_binary_scale:
13236 return "DW_AT_binary_scale";
13237 case DW_AT_decimal_scale:
13238 return "DW_AT_decimal_scale";
13240 return "DW_AT_small";
13241 case DW_AT_decimal_sign:
13242 return "DW_AT_decimal_sign";
13243 case DW_AT_digit_count:
13244 return "DW_AT_digit_count";
13245 case DW_AT_picture_string:
13246 return "DW_AT_picture_string";
13247 case DW_AT_mutable:
13248 return "DW_AT_mutable";
13249 case DW_AT_threads_scaled:
13250 return "DW_AT_threads_scaled";
13251 case DW_AT_explicit:
13252 return "DW_AT_explicit";
13253 case DW_AT_object_pointer:
13254 return "DW_AT_object_pointer";
13255 case DW_AT_endianity:
13256 return "DW_AT_endianity";
13257 case DW_AT_elemental:
13258 return "DW_AT_elemental";
13260 return "DW_AT_pure";
13261 case DW_AT_recursive:
13262 return "DW_AT_recursive";
13263 /* DWARF 4 values. */
13264 case DW_AT_signature:
13265 return "DW_AT_signature";
13266 case DW_AT_linkage_name:
13267 return "DW_AT_linkage_name";
13268 /* SGI/MIPS extensions. */
13269 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13270 case DW_AT_MIPS_fde:
13271 return "DW_AT_MIPS_fde";
13273 case DW_AT_MIPS_loop_begin:
13274 return "DW_AT_MIPS_loop_begin";
13275 case DW_AT_MIPS_tail_loop_begin:
13276 return "DW_AT_MIPS_tail_loop_begin";
13277 case DW_AT_MIPS_epilog_begin:
13278 return "DW_AT_MIPS_epilog_begin";
13279 case DW_AT_MIPS_loop_unroll_factor:
13280 return "DW_AT_MIPS_loop_unroll_factor";
13281 case DW_AT_MIPS_software_pipeline_depth:
13282 return "DW_AT_MIPS_software_pipeline_depth";
13283 case DW_AT_MIPS_linkage_name:
13284 return "DW_AT_MIPS_linkage_name";
13285 case DW_AT_MIPS_stride:
13286 return "DW_AT_MIPS_stride";
13287 case DW_AT_MIPS_abstract_name:
13288 return "DW_AT_MIPS_abstract_name";
13289 case DW_AT_MIPS_clone_origin:
13290 return "DW_AT_MIPS_clone_origin";
13291 case DW_AT_MIPS_has_inlines:
13292 return "DW_AT_MIPS_has_inlines";
13293 /* HP extensions. */
13294 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13295 case DW_AT_HP_block_index:
13296 return "DW_AT_HP_block_index";
13298 case DW_AT_HP_unmodifiable:
13299 return "DW_AT_HP_unmodifiable";
13300 case DW_AT_HP_actuals_stmt_list:
13301 return "DW_AT_HP_actuals_stmt_list";
13302 case DW_AT_HP_proc_per_section:
13303 return "DW_AT_HP_proc_per_section";
13304 case DW_AT_HP_raw_data_ptr:
13305 return "DW_AT_HP_raw_data_ptr";
13306 case DW_AT_HP_pass_by_reference:
13307 return "DW_AT_HP_pass_by_reference";
13308 case DW_AT_HP_opt_level:
13309 return "DW_AT_HP_opt_level";
13310 case DW_AT_HP_prof_version_id:
13311 return "DW_AT_HP_prof_version_id";
13312 case DW_AT_HP_opt_flags:
13313 return "DW_AT_HP_opt_flags";
13314 case DW_AT_HP_cold_region_low_pc:
13315 return "DW_AT_HP_cold_region_low_pc";
13316 case DW_AT_HP_cold_region_high_pc:
13317 return "DW_AT_HP_cold_region_high_pc";
13318 case DW_AT_HP_all_variables_modifiable:
13319 return "DW_AT_HP_all_variables_modifiable";
13320 case DW_AT_HP_linkage_name:
13321 return "DW_AT_HP_linkage_name";
13322 case DW_AT_HP_prof_flags:
13323 return "DW_AT_HP_prof_flags";
13324 /* GNU extensions. */
13325 case DW_AT_sf_names:
13326 return "DW_AT_sf_names";
13327 case DW_AT_src_info:
13328 return "DW_AT_src_info";
13329 case DW_AT_mac_info:
13330 return "DW_AT_mac_info";
13331 case DW_AT_src_coords:
13332 return "DW_AT_src_coords";
13333 case DW_AT_body_begin:
13334 return "DW_AT_body_begin";
13335 case DW_AT_body_end:
13336 return "DW_AT_body_end";
13337 case DW_AT_GNU_vector:
13338 return "DW_AT_GNU_vector";
13339 case DW_AT_GNU_odr_signature:
13340 return "DW_AT_GNU_odr_signature";
13341 /* VMS extensions. */
13342 case DW_AT_VMS_rtnbeg_pd_address:
13343 return "DW_AT_VMS_rtnbeg_pd_address";
13344 /* UPC extension. */
13345 case DW_AT_upc_threads_scaled:
13346 return "DW_AT_upc_threads_scaled";
13347 /* PGI (STMicroelectronics) extensions. */
13348 case DW_AT_PGI_lbase:
13349 return "DW_AT_PGI_lbase";
13350 case DW_AT_PGI_soffset:
13351 return "DW_AT_PGI_soffset";
13352 case DW_AT_PGI_lstride:
13353 return "DW_AT_PGI_lstride";
13355 return "DW_AT_<unknown>";
13359 /* Convert a DWARF value form code into its string name. */
13362 dwarf_form_name (unsigned form)
13367 return "DW_FORM_addr";
13368 case DW_FORM_block2:
13369 return "DW_FORM_block2";
13370 case DW_FORM_block4:
13371 return "DW_FORM_block4";
13372 case DW_FORM_data2:
13373 return "DW_FORM_data2";
13374 case DW_FORM_data4:
13375 return "DW_FORM_data4";
13376 case DW_FORM_data8:
13377 return "DW_FORM_data8";
13378 case DW_FORM_string:
13379 return "DW_FORM_string";
13380 case DW_FORM_block:
13381 return "DW_FORM_block";
13382 case DW_FORM_block1:
13383 return "DW_FORM_block1";
13384 case DW_FORM_data1:
13385 return "DW_FORM_data1";
13387 return "DW_FORM_flag";
13388 case DW_FORM_sdata:
13389 return "DW_FORM_sdata";
13391 return "DW_FORM_strp";
13392 case DW_FORM_udata:
13393 return "DW_FORM_udata";
13394 case DW_FORM_ref_addr:
13395 return "DW_FORM_ref_addr";
13397 return "DW_FORM_ref1";
13399 return "DW_FORM_ref2";
13401 return "DW_FORM_ref4";
13403 return "DW_FORM_ref8";
13404 case DW_FORM_ref_udata:
13405 return "DW_FORM_ref_udata";
13406 case DW_FORM_indirect:
13407 return "DW_FORM_indirect";
13408 case DW_FORM_sec_offset:
13409 return "DW_FORM_sec_offset";
13410 case DW_FORM_exprloc:
13411 return "DW_FORM_exprloc";
13412 case DW_FORM_flag_present:
13413 return "DW_FORM_flag_present";
13414 case DW_FORM_ref_sig8:
13415 return "DW_FORM_ref_sig8";
13417 return "DW_FORM_<unknown>";
13421 /* Convert a DWARF stack opcode into its string name. */
13424 dwarf_stack_op_name (unsigned op)
13429 return "DW_OP_addr";
13431 return "DW_OP_deref";
13432 case DW_OP_const1u:
13433 return "DW_OP_const1u";
13434 case DW_OP_const1s:
13435 return "DW_OP_const1s";
13436 case DW_OP_const2u:
13437 return "DW_OP_const2u";
13438 case DW_OP_const2s:
13439 return "DW_OP_const2s";
13440 case DW_OP_const4u:
13441 return "DW_OP_const4u";
13442 case DW_OP_const4s:
13443 return "DW_OP_const4s";
13444 case DW_OP_const8u:
13445 return "DW_OP_const8u";
13446 case DW_OP_const8s:
13447 return "DW_OP_const8s";
13449 return "DW_OP_constu";
13451 return "DW_OP_consts";
13453 return "DW_OP_dup";
13455 return "DW_OP_drop";
13457 return "DW_OP_over";
13459 return "DW_OP_pick";
13461 return "DW_OP_swap";
13463 return "DW_OP_rot";
13465 return "DW_OP_xderef";
13467 return "DW_OP_abs";
13469 return "DW_OP_and";
13471 return "DW_OP_div";
13473 return "DW_OP_minus";
13475 return "DW_OP_mod";
13477 return "DW_OP_mul";
13479 return "DW_OP_neg";
13481 return "DW_OP_not";
13485 return "DW_OP_plus";
13486 case DW_OP_plus_uconst:
13487 return "DW_OP_plus_uconst";
13489 return "DW_OP_shl";
13491 return "DW_OP_shr";
13493 return "DW_OP_shra";
13495 return "DW_OP_xor";
13497 return "DW_OP_bra";
13511 return "DW_OP_skip";
13513 return "DW_OP_lit0";
13515 return "DW_OP_lit1";
13517 return "DW_OP_lit2";
13519 return "DW_OP_lit3";
13521 return "DW_OP_lit4";
13523 return "DW_OP_lit5";
13525 return "DW_OP_lit6";
13527 return "DW_OP_lit7";
13529 return "DW_OP_lit8";
13531 return "DW_OP_lit9";
13533 return "DW_OP_lit10";
13535 return "DW_OP_lit11";
13537 return "DW_OP_lit12";
13539 return "DW_OP_lit13";
13541 return "DW_OP_lit14";
13543 return "DW_OP_lit15";
13545 return "DW_OP_lit16";
13547 return "DW_OP_lit17";
13549 return "DW_OP_lit18";
13551 return "DW_OP_lit19";
13553 return "DW_OP_lit20";
13555 return "DW_OP_lit21";
13557 return "DW_OP_lit22";
13559 return "DW_OP_lit23";
13561 return "DW_OP_lit24";
13563 return "DW_OP_lit25";
13565 return "DW_OP_lit26";
13567 return "DW_OP_lit27";
13569 return "DW_OP_lit28";
13571 return "DW_OP_lit29";
13573 return "DW_OP_lit30";
13575 return "DW_OP_lit31";
13577 return "DW_OP_reg0";
13579 return "DW_OP_reg1";
13581 return "DW_OP_reg2";
13583 return "DW_OP_reg3";
13585 return "DW_OP_reg4";
13587 return "DW_OP_reg5";
13589 return "DW_OP_reg6";
13591 return "DW_OP_reg7";
13593 return "DW_OP_reg8";
13595 return "DW_OP_reg9";
13597 return "DW_OP_reg10";
13599 return "DW_OP_reg11";
13601 return "DW_OP_reg12";
13603 return "DW_OP_reg13";
13605 return "DW_OP_reg14";
13607 return "DW_OP_reg15";
13609 return "DW_OP_reg16";
13611 return "DW_OP_reg17";
13613 return "DW_OP_reg18";
13615 return "DW_OP_reg19";
13617 return "DW_OP_reg20";
13619 return "DW_OP_reg21";
13621 return "DW_OP_reg22";
13623 return "DW_OP_reg23";
13625 return "DW_OP_reg24";
13627 return "DW_OP_reg25";
13629 return "DW_OP_reg26";
13631 return "DW_OP_reg27";
13633 return "DW_OP_reg28";
13635 return "DW_OP_reg29";
13637 return "DW_OP_reg30";
13639 return "DW_OP_reg31";
13641 return "DW_OP_breg0";
13643 return "DW_OP_breg1";
13645 return "DW_OP_breg2";
13647 return "DW_OP_breg3";
13649 return "DW_OP_breg4";
13651 return "DW_OP_breg5";
13653 return "DW_OP_breg6";
13655 return "DW_OP_breg7";
13657 return "DW_OP_breg8";
13659 return "DW_OP_breg9";
13661 return "DW_OP_breg10";
13663 return "DW_OP_breg11";
13665 return "DW_OP_breg12";
13667 return "DW_OP_breg13";
13669 return "DW_OP_breg14";
13671 return "DW_OP_breg15";
13673 return "DW_OP_breg16";
13675 return "DW_OP_breg17";
13677 return "DW_OP_breg18";
13679 return "DW_OP_breg19";
13681 return "DW_OP_breg20";
13683 return "DW_OP_breg21";
13685 return "DW_OP_breg22";
13687 return "DW_OP_breg23";
13689 return "DW_OP_breg24";
13691 return "DW_OP_breg25";
13693 return "DW_OP_breg26";
13695 return "DW_OP_breg27";
13697 return "DW_OP_breg28";
13699 return "DW_OP_breg29";
13701 return "DW_OP_breg30";
13703 return "DW_OP_breg31";
13705 return "DW_OP_regx";
13707 return "DW_OP_fbreg";
13709 return "DW_OP_bregx";
13711 return "DW_OP_piece";
13712 case DW_OP_deref_size:
13713 return "DW_OP_deref_size";
13714 case DW_OP_xderef_size:
13715 return "DW_OP_xderef_size";
13717 return "DW_OP_nop";
13718 /* DWARF 3 extensions. */
13719 case DW_OP_push_object_address:
13720 return "DW_OP_push_object_address";
13722 return "DW_OP_call2";
13724 return "DW_OP_call4";
13725 case DW_OP_call_ref:
13726 return "DW_OP_call_ref";
13727 case DW_OP_form_tls_address:
13728 return "DW_OP_form_tls_address";
13729 case DW_OP_call_frame_cfa:
13730 return "DW_OP_call_frame_cfa";
13731 case DW_OP_bit_piece:
13732 return "DW_OP_bit_piece";
13733 /* DWARF 4 extensions. */
13734 case DW_OP_implicit_value:
13735 return "DW_OP_implicit_value";
13736 case DW_OP_stack_value:
13737 return "DW_OP_stack_value";
13738 /* GNU extensions. */
13739 case DW_OP_GNU_push_tls_address:
13740 return "DW_OP_GNU_push_tls_address";
13741 case DW_OP_GNU_uninit:
13742 return "DW_OP_GNU_uninit";
13743 case DW_OP_GNU_encoded_addr:
13744 return "DW_OP_GNU_encoded_addr";
13745 case DW_OP_GNU_implicit_pointer:
13746 return "DW_OP_GNU_implicit_pointer";
13747 case DW_OP_GNU_entry_value:
13748 return "DW_OP_GNU_entry_value";
13749 case DW_OP_GNU_const_type:
13750 return "DW_OP_GNU_const_type";
13751 case DW_OP_GNU_regval_type:
13752 return "DW_OP_GNU_regval_type";
13753 case DW_OP_GNU_deref_type:
13754 return "DW_OP_GNU_deref_type";
13755 case DW_OP_GNU_convert:
13756 return "DW_OP_GNU_convert";
13757 case DW_OP_GNU_reinterpret:
13758 return "DW_OP_GNU_reinterpret";
13759 case DW_OP_GNU_parameter_ref:
13760 return "DW_OP_GNU_parameter_ref";
13767 dwarf_bool_name (unsigned mybool)
13775 /* Convert a DWARF type code into its string name. */
13778 dwarf_type_encoding_name (unsigned enc)
13783 return "DW_ATE_void";
13784 case DW_ATE_address:
13785 return "DW_ATE_address";
13786 case DW_ATE_boolean:
13787 return "DW_ATE_boolean";
13788 case DW_ATE_complex_float:
13789 return "DW_ATE_complex_float";
13791 return "DW_ATE_float";
13792 case DW_ATE_signed:
13793 return "DW_ATE_signed";
13794 case DW_ATE_signed_char:
13795 return "DW_ATE_signed_char";
13796 case DW_ATE_unsigned:
13797 return "DW_ATE_unsigned";
13798 case DW_ATE_unsigned_char:
13799 return "DW_ATE_unsigned_char";
13801 case DW_ATE_imaginary_float:
13802 return "DW_ATE_imaginary_float";
13803 case DW_ATE_packed_decimal:
13804 return "DW_ATE_packed_decimal";
13805 case DW_ATE_numeric_string:
13806 return "DW_ATE_numeric_string";
13807 case DW_ATE_edited:
13808 return "DW_ATE_edited";
13809 case DW_ATE_signed_fixed:
13810 return "DW_ATE_signed_fixed";
13811 case DW_ATE_unsigned_fixed:
13812 return "DW_ATE_unsigned_fixed";
13813 case DW_ATE_decimal_float:
13814 return "DW_ATE_decimal_float";
13817 return "DW_ATE_UTF";
13818 /* HP extensions. */
13819 case DW_ATE_HP_float80:
13820 return "DW_ATE_HP_float80";
13821 case DW_ATE_HP_complex_float80:
13822 return "DW_ATE_HP_complex_float80";
13823 case DW_ATE_HP_float128:
13824 return "DW_ATE_HP_float128";
13825 case DW_ATE_HP_complex_float128:
13826 return "DW_ATE_HP_complex_float128";
13827 case DW_ATE_HP_floathpintel:
13828 return "DW_ATE_HP_floathpintel";
13829 case DW_ATE_HP_imaginary_float80:
13830 return "DW_ATE_HP_imaginary_float80";
13831 case DW_ATE_HP_imaginary_float128:
13832 return "DW_ATE_HP_imaginary_float128";
13834 return "DW_ATE_<unknown>";
13838 /* Convert a DWARF call frame info operation to its string name. */
13842 dwarf_cfi_name (unsigned cfi_opc)
13846 case DW_CFA_advance_loc:
13847 return "DW_CFA_advance_loc";
13848 case DW_CFA_offset:
13849 return "DW_CFA_offset";
13850 case DW_CFA_restore:
13851 return "DW_CFA_restore";
13853 return "DW_CFA_nop";
13854 case DW_CFA_set_loc:
13855 return "DW_CFA_set_loc";
13856 case DW_CFA_advance_loc1:
13857 return "DW_CFA_advance_loc1";
13858 case DW_CFA_advance_loc2:
13859 return "DW_CFA_advance_loc2";
13860 case DW_CFA_advance_loc4:
13861 return "DW_CFA_advance_loc4";
13862 case DW_CFA_offset_extended:
13863 return "DW_CFA_offset_extended";
13864 case DW_CFA_restore_extended:
13865 return "DW_CFA_restore_extended";
13866 case DW_CFA_undefined:
13867 return "DW_CFA_undefined";
13868 case DW_CFA_same_value:
13869 return "DW_CFA_same_value";
13870 case DW_CFA_register:
13871 return "DW_CFA_register";
13872 case DW_CFA_remember_state:
13873 return "DW_CFA_remember_state";
13874 case DW_CFA_restore_state:
13875 return "DW_CFA_restore_state";
13876 case DW_CFA_def_cfa:
13877 return "DW_CFA_def_cfa";
13878 case DW_CFA_def_cfa_register:
13879 return "DW_CFA_def_cfa_register";
13880 case DW_CFA_def_cfa_offset:
13881 return "DW_CFA_def_cfa_offset";
13883 case DW_CFA_def_cfa_expression:
13884 return "DW_CFA_def_cfa_expression";
13885 case DW_CFA_expression:
13886 return "DW_CFA_expression";
13887 case DW_CFA_offset_extended_sf:
13888 return "DW_CFA_offset_extended_sf";
13889 case DW_CFA_def_cfa_sf:
13890 return "DW_CFA_def_cfa_sf";
13891 case DW_CFA_def_cfa_offset_sf:
13892 return "DW_CFA_def_cfa_offset_sf";
13893 case DW_CFA_val_offset:
13894 return "DW_CFA_val_offset";
13895 case DW_CFA_val_offset_sf:
13896 return "DW_CFA_val_offset_sf";
13897 case DW_CFA_val_expression:
13898 return "DW_CFA_val_expression";
13899 /* SGI/MIPS specific. */
13900 case DW_CFA_MIPS_advance_loc8:
13901 return "DW_CFA_MIPS_advance_loc8";
13902 /* GNU extensions. */
13903 case DW_CFA_GNU_window_save:
13904 return "DW_CFA_GNU_window_save";
13905 case DW_CFA_GNU_args_size:
13906 return "DW_CFA_GNU_args_size";
13907 case DW_CFA_GNU_negative_offset_extended:
13908 return "DW_CFA_GNU_negative_offset_extended";
13910 return "DW_CFA_<unknown>";
13916 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13920 print_spaces (indent, f);
13921 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13922 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13924 if (die->parent != NULL)
13926 print_spaces (indent, f);
13927 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13928 die->parent->offset);
13931 print_spaces (indent, f);
13932 fprintf_unfiltered (f, " has children: %s\n",
13933 dwarf_bool_name (die->child != NULL));
13935 print_spaces (indent, f);
13936 fprintf_unfiltered (f, " attributes:\n");
13938 for (i = 0; i < die->num_attrs; ++i)
13940 print_spaces (indent, f);
13941 fprintf_unfiltered (f, " %s (%s) ",
13942 dwarf_attr_name (die->attrs[i].name),
13943 dwarf_form_name (die->attrs[i].form));
13945 switch (die->attrs[i].form)
13947 case DW_FORM_ref_addr:
13949 fprintf_unfiltered (f, "address: ");
13950 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13952 case DW_FORM_block2:
13953 case DW_FORM_block4:
13954 case DW_FORM_block:
13955 case DW_FORM_block1:
13956 fprintf_unfiltered (f, "block: size %d",
13957 DW_BLOCK (&die->attrs[i])->size);
13959 case DW_FORM_exprloc:
13960 fprintf_unfiltered (f, "expression: size %u",
13961 DW_BLOCK (&die->attrs[i])->size);
13966 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13967 (long) (DW_ADDR (&die->attrs[i])));
13969 case DW_FORM_data1:
13970 case DW_FORM_data2:
13971 case DW_FORM_data4:
13972 case DW_FORM_data8:
13973 case DW_FORM_udata:
13974 case DW_FORM_sdata:
13975 fprintf_unfiltered (f, "constant: %s",
13976 pulongest (DW_UNSND (&die->attrs[i])));
13978 case DW_FORM_sec_offset:
13979 fprintf_unfiltered (f, "section offset: %s",
13980 pulongest (DW_UNSND (&die->attrs[i])));
13982 case DW_FORM_ref_sig8:
13983 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13984 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13985 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13987 fprintf_unfiltered (f, "signatured type, offset: unknown");
13989 case DW_FORM_string:
13991 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13992 DW_STRING (&die->attrs[i])
13993 ? DW_STRING (&die->attrs[i]) : "",
13994 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13997 if (DW_UNSND (&die->attrs[i]))
13998 fprintf_unfiltered (f, "flag: TRUE");
14000 fprintf_unfiltered (f, "flag: FALSE");
14002 case DW_FORM_flag_present:
14003 fprintf_unfiltered (f, "flag: TRUE");
14005 case DW_FORM_indirect:
14006 /* The reader will have reduced the indirect form to
14007 the "base form" so this form should not occur. */
14008 fprintf_unfiltered (f,
14009 "unexpected attribute form: DW_FORM_indirect");
14012 fprintf_unfiltered (f, "unsupported attribute form: %d.",
14013 die->attrs[i].form);
14016 fprintf_unfiltered (f, "\n");
14021 dump_die_for_error (struct die_info *die)
14023 dump_die_shallow (gdb_stderr, 0, die);
14027 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
14029 int indent = level * 4;
14031 gdb_assert (die != NULL);
14033 if (level >= max_level)
14036 dump_die_shallow (f, indent, die);
14038 if (die->child != NULL)
14040 print_spaces (indent, f);
14041 fprintf_unfiltered (f, " Children:");
14042 if (level + 1 < max_level)
14044 fprintf_unfiltered (f, "\n");
14045 dump_die_1 (f, level + 1, max_level, die->child);
14049 fprintf_unfiltered (f,
14050 " [not printed, max nesting level reached]\n");
14054 if (die->sibling != NULL && level > 0)
14056 dump_die_1 (f, level, max_level, die->sibling);
14060 /* This is called from the pdie macro in gdbinit.in.
14061 It's not static so gcc will keep a copy callable from gdb. */
14064 dump_die (struct die_info *die, int max_level)
14066 dump_die_1 (gdb_stdlog, 0, max_level, die);
14070 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
14074 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
14080 is_ref_attr (struct attribute *attr)
14082 switch (attr->form)
14084 case DW_FORM_ref_addr:
14089 case DW_FORM_ref_udata:
14096 static unsigned int
14097 dwarf2_get_ref_die_offset (struct attribute *attr)
14099 if (is_ref_attr (attr))
14100 return DW_ADDR (attr);
14102 complaint (&symfile_complaints,
14103 _("unsupported die ref attribute form: '%s'"),
14104 dwarf_form_name (attr->form));
14108 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14109 * the value held by the attribute is not constant. */
14112 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
14114 if (attr->form == DW_FORM_sdata)
14115 return DW_SND (attr);
14116 else if (attr->form == DW_FORM_udata
14117 || attr->form == DW_FORM_data1
14118 || attr->form == DW_FORM_data2
14119 || attr->form == DW_FORM_data4
14120 || attr->form == DW_FORM_data8)
14121 return DW_UNSND (attr);
14124 complaint (&symfile_complaints,
14125 _("Attribute value is not a constant (%s)"),
14126 dwarf_form_name (attr->form));
14127 return default_value;
14131 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14132 unit and add it to our queue.
14133 The result is non-zero if PER_CU was queued, otherwise the result is zero
14134 meaning either PER_CU is already queued or it is already loaded. */
14137 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
14138 struct dwarf2_per_cu_data *per_cu)
14140 /* We may arrive here during partial symbol reading, if we need full
14141 DIEs to process an unusual case (e.g. template arguments). Do
14142 not queue PER_CU, just tell our caller to load its DIEs. */
14143 if (dwarf2_per_objfile->reading_partial_symbols)
14145 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
14150 /* Mark the dependence relation so that we don't flush PER_CU
14152 dwarf2_add_dependence (this_cu, per_cu);
14154 /* If it's already on the queue, we have nothing to do. */
14155 if (per_cu->queued)
14158 /* If the compilation unit is already loaded, just mark it as
14160 if (per_cu->cu != NULL)
14162 per_cu->cu->last_used = 0;
14166 /* Add it to the queue. */
14167 queue_comp_unit (per_cu);
14172 /* Follow reference or signature attribute ATTR of SRC_DIE.
14173 On entry *REF_CU is the CU of SRC_DIE.
14174 On exit *REF_CU is the CU of the result. */
14176 static struct die_info *
14177 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
14178 struct dwarf2_cu **ref_cu)
14180 struct die_info *die;
14182 if (is_ref_attr (attr))
14183 die = follow_die_ref (src_die, attr, ref_cu);
14184 else if (attr->form == DW_FORM_ref_sig8)
14185 die = follow_die_sig (src_die, attr, ref_cu);
14188 dump_die_for_error (src_die);
14189 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14190 (*ref_cu)->objfile->name);
14196 /* Follow reference OFFSET.
14197 On entry *REF_CU is the CU of the source die referencing OFFSET.
14198 On exit *REF_CU is the CU of the result.
14199 Returns NULL if OFFSET is invalid. */
14201 static struct die_info *
14202 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
14204 struct die_info temp_die;
14205 struct dwarf2_cu *target_cu, *cu = *ref_cu;
14207 gdb_assert (cu->per_cu != NULL);
14211 if (cu->per_cu->debug_types_section)
14213 /* .debug_types CUs cannot reference anything outside their CU.
14214 If they need to, they have to reference a signatured type via
14215 DW_FORM_ref_sig8. */
14216 if (! offset_in_cu_p (&cu->header, offset))
14219 else if (! offset_in_cu_p (&cu->header, offset))
14221 struct dwarf2_per_cu_data *per_cu;
14223 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
14225 /* If necessary, add it to the queue and load its DIEs. */
14226 if (maybe_queue_comp_unit (cu, per_cu))
14227 load_full_comp_unit (per_cu);
14229 target_cu = per_cu->cu;
14231 else if (cu->dies == NULL)
14233 /* We're loading full DIEs during partial symbol reading. */
14234 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
14235 load_full_comp_unit (cu->per_cu);
14238 *ref_cu = target_cu;
14239 temp_die.offset = offset;
14240 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
14243 /* Follow reference attribute ATTR of SRC_DIE.
14244 On entry *REF_CU is the CU of SRC_DIE.
14245 On exit *REF_CU is the CU of the result. */
14247 static struct die_info *
14248 follow_die_ref (struct die_info *src_die, struct attribute *attr,
14249 struct dwarf2_cu **ref_cu)
14251 unsigned int offset = dwarf2_get_ref_die_offset (attr);
14252 struct dwarf2_cu *cu = *ref_cu;
14253 struct die_info *die;
14255 die = follow_die_offset (offset, ref_cu);
14257 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14258 "at 0x%x [in module %s]"),
14259 offset, src_die->offset, cu->objfile->name);
14264 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14265 Returned value is intended for DW_OP_call*. Returned
14266 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14268 struct dwarf2_locexpr_baton
14269 dwarf2_fetch_die_location_block (unsigned int offset_in_cu,
14270 struct dwarf2_per_cu_data *per_cu,
14271 CORE_ADDR (*get_frame_pc) (void *baton),
14274 unsigned int offset = per_cu->offset + offset_in_cu;
14275 struct dwarf2_cu *cu;
14276 struct die_info *die;
14277 struct attribute *attr;
14278 struct dwarf2_locexpr_baton retval;
14280 dw2_setup (per_cu->objfile);
14282 if (per_cu->cu == NULL)
14286 die = follow_die_offset (offset, &cu);
14288 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14289 offset, per_cu->objfile->name);
14291 attr = dwarf2_attr (die, DW_AT_location, cu);
14294 /* DWARF: "If there is no such attribute, then there is no effect.".
14295 DATA is ignored if SIZE is 0. */
14297 retval.data = NULL;
14300 else if (attr_form_is_section_offset (attr))
14302 struct dwarf2_loclist_baton loclist_baton;
14303 CORE_ADDR pc = (*get_frame_pc) (baton);
14306 fill_in_loclist_baton (cu, &loclist_baton, attr);
14308 retval.data = dwarf2_find_location_expression (&loclist_baton,
14310 retval.size = size;
14314 if (!attr_form_is_block (attr))
14315 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14316 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14317 offset, per_cu->objfile->name);
14319 retval.data = DW_BLOCK (attr)->data;
14320 retval.size = DW_BLOCK (attr)->size;
14322 retval.per_cu = cu->per_cu;
14324 age_cached_comp_units ();
14329 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14333 dwarf2_get_die_type (unsigned int die_offset,
14334 struct dwarf2_per_cu_data *per_cu)
14336 dw2_setup (per_cu->objfile);
14337 return get_die_type_at_offset (per_cu->offset + die_offset, per_cu);
14340 /* Follow the signature attribute ATTR in SRC_DIE.
14341 On entry *REF_CU is the CU of SRC_DIE.
14342 On exit *REF_CU is the CU of the result. */
14344 static struct die_info *
14345 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14346 struct dwarf2_cu **ref_cu)
14348 struct objfile *objfile = (*ref_cu)->objfile;
14349 struct die_info temp_die;
14350 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14351 struct dwarf2_cu *sig_cu;
14352 struct die_info *die;
14354 /* sig_type will be NULL if the signatured type is missing from
14356 if (sig_type == NULL)
14357 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14358 "at 0x%x [in module %s]"),
14359 src_die->offset, objfile->name);
14361 /* If necessary, add it to the queue and load its DIEs. */
14363 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14364 read_signatured_type (sig_type);
14366 gdb_assert (sig_type->per_cu.cu != NULL);
14368 sig_cu = sig_type->per_cu.cu;
14369 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
14370 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
14377 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14378 "from DIE at 0x%x [in module %s]"),
14379 sig_type->type_offset, src_die->offset, objfile->name);
14382 /* Given an offset of a signatured type, return its signatured_type. */
14384 static struct signatured_type *
14385 lookup_signatured_type_at_offset (struct objfile *objfile,
14386 struct dwarf2_section_info *section,
14387 unsigned int offset)
14389 gdb_byte *info_ptr = section->buffer + offset;
14390 unsigned int length, initial_length_size;
14391 unsigned int sig_offset;
14392 struct signatured_type find_entry, *type_sig;
14394 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14395 sig_offset = (initial_length_size
14397 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14398 + 1 /*address_size*/);
14399 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14400 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14402 /* This is only used to lookup previously recorded types.
14403 If we didn't find it, it's our bug. */
14404 gdb_assert (type_sig != NULL);
14405 gdb_assert (offset == type_sig->per_cu.offset);
14410 /* Load the DIEs associated with type unit PER_CU into memory. */
14413 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
14415 struct objfile *objfile = per_cu->objfile;
14416 struct dwarf2_section_info *sect = per_cu->debug_types_section;
14417 unsigned int offset = per_cu->offset;
14418 struct signatured_type *type_sig;
14420 dwarf2_read_section (objfile, sect);
14422 /* We have the section offset, but we need the signature to do the
14423 hash table lookup. */
14424 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14425 the signature to assert we found the right one.
14426 Ok, but it's a lot of work. We should simplify things so any needed
14427 assert doesn't require all this clumsiness. */
14428 type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
14430 gdb_assert (type_sig->per_cu.cu == NULL);
14432 read_signatured_type (type_sig);
14434 gdb_assert (type_sig->per_cu.cu != NULL);
14437 /* Read in a signatured type and build its CU and DIEs. */
14440 read_signatured_type (struct signatured_type *type_sig)
14442 struct objfile *objfile = type_sig->per_cu.objfile;
14443 gdb_byte *types_ptr;
14444 struct die_reader_specs reader_specs;
14445 struct dwarf2_cu *cu;
14446 ULONGEST signature;
14447 struct cleanup *back_to, *free_cu_cleanup;
14448 struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section;
14450 dwarf2_read_section (objfile, section);
14451 types_ptr = section->buffer + type_sig->per_cu.offset;
14453 gdb_assert (type_sig->per_cu.cu == NULL);
14455 cu = xmalloc (sizeof (*cu));
14456 init_one_comp_unit (cu, &type_sig->per_cu);
14458 /* If an error occurs while loading, release our storage. */
14459 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
14461 types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr,
14463 gdb_assert (signature == type_sig->signature);
14466 = htab_create_alloc_ex (cu->header.length / 12,
14470 &cu->comp_unit_obstack,
14471 hashtab_obstack_allocate,
14472 dummy_obstack_deallocate);
14474 dwarf2_read_abbrevs (cu);
14475 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14477 init_cu_die_reader (&reader_specs, cu);
14479 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14482 /* We try not to read any attributes in this function, because not
14483 all CUs needed for references have been loaded yet, and symbol
14484 table processing isn't initialized. But we have to set the CU language,
14485 or we won't be able to build types correctly. */
14486 prepare_one_comp_unit (cu, cu->dies);
14488 do_cleanups (back_to);
14490 /* We've successfully allocated this compilation unit. Let our caller
14491 clean it up when finished with it. */
14492 discard_cleanups (free_cu_cleanup);
14494 /* Link this TU into read_in_chain. */
14495 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14496 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
14499 /* Decode simple location descriptions.
14500 Given a pointer to a dwarf block that defines a location, compute
14501 the location and return the value.
14503 NOTE drow/2003-11-18: This function is called in two situations
14504 now: for the address of static or global variables (partial symbols
14505 only) and for offsets into structures which are expected to be
14506 (more or less) constant. The partial symbol case should go away,
14507 and only the constant case should remain. That will let this
14508 function complain more accurately. A few special modes are allowed
14509 without complaint for global variables (for instance, global
14510 register values and thread-local values).
14512 A location description containing no operations indicates that the
14513 object is optimized out. The return value is 0 for that case.
14514 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14515 callers will only want a very basic result and this can become a
14518 Note that stack[0] is unused except as a default error return. */
14521 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14523 struct objfile *objfile = cu->objfile;
14525 int size = blk->size;
14526 gdb_byte *data = blk->data;
14527 CORE_ADDR stack[64];
14529 unsigned int bytes_read, unsnd;
14535 stack[++stacki] = 0;
14574 stack[++stacki] = op - DW_OP_lit0;
14609 stack[++stacki] = op - DW_OP_reg0;
14611 dwarf2_complex_location_expr_complaint ();
14615 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
14617 stack[++stacki] = unsnd;
14619 dwarf2_complex_location_expr_complaint ();
14623 stack[++stacki] = read_address (objfile->obfd, &data[i],
14628 case DW_OP_const1u:
14629 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
14633 case DW_OP_const1s:
14634 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
14638 case DW_OP_const2u:
14639 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14643 case DW_OP_const2s:
14644 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14648 case DW_OP_const4u:
14649 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14653 case DW_OP_const4s:
14654 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14658 case DW_OP_const8u:
14659 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
14664 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14670 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14675 stack[stacki + 1] = stack[stacki];
14680 stack[stacki - 1] += stack[stacki];
14684 case DW_OP_plus_uconst:
14685 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14691 stack[stacki - 1] -= stack[stacki];
14696 /* If we're not the last op, then we definitely can't encode
14697 this using GDB's address_class enum. This is valid for partial
14698 global symbols, although the variable's address will be bogus
14701 dwarf2_complex_location_expr_complaint ();
14704 case DW_OP_GNU_push_tls_address:
14705 /* The top of the stack has the offset from the beginning
14706 of the thread control block at which the variable is located. */
14707 /* Nothing should follow this operator, so the top of stack would
14709 /* This is valid for partial global symbols, but the variable's
14710 address will be bogus in the psymtab. Make it always at least
14711 non-zero to not look as a variable garbage collected by linker
14712 which have DW_OP_addr 0. */
14714 dwarf2_complex_location_expr_complaint ();
14718 case DW_OP_GNU_uninit:
14723 const char *name = dwarf_stack_op_name (op);
14726 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14729 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14733 return (stack[stacki]);
14736 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14737 outside of the allocated space. Also enforce minimum>0. */
14738 if (stacki >= ARRAY_SIZE (stack) - 1)
14740 complaint (&symfile_complaints,
14741 _("location description stack overflow"));
14747 complaint (&symfile_complaints,
14748 _("location description stack underflow"));
14752 return (stack[stacki]);
14755 /* memory allocation interface */
14757 static struct dwarf_block *
14758 dwarf_alloc_block (struct dwarf2_cu *cu)
14760 struct dwarf_block *blk;
14762 blk = (struct dwarf_block *)
14763 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14767 static struct abbrev_info *
14768 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14770 struct abbrev_info *abbrev;
14772 abbrev = (struct abbrev_info *)
14773 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14774 memset (abbrev, 0, sizeof (struct abbrev_info));
14778 static struct die_info *
14779 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14781 struct die_info *die;
14782 size_t size = sizeof (struct die_info);
14785 size += (num_attrs - 1) * sizeof (struct attribute);
14787 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14788 memset (die, 0, sizeof (struct die_info));
14793 /* Macro support. */
14795 /* Return the full name of file number I in *LH's file name table.
14796 Use COMP_DIR as the name of the current directory of the
14797 compilation. The result is allocated using xmalloc; the caller is
14798 responsible for freeing it. */
14800 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14802 /* Is the file number a valid index into the line header's file name
14803 table? Remember that file numbers start with one, not zero. */
14804 if (1 <= file && file <= lh->num_file_names)
14806 struct file_entry *fe = &lh->file_names[file - 1];
14808 if (IS_ABSOLUTE_PATH (fe->name))
14809 return xstrdup (fe->name);
14817 dir = lh->include_dirs[fe->dir_index - 1];
14823 dir_len = strlen (dir);
14824 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14825 strcpy (full_name, dir);
14826 full_name[dir_len] = '/';
14827 strcpy (full_name + dir_len + 1, fe->name);
14831 return xstrdup (fe->name);
14836 /* The compiler produced a bogus file number. We can at least
14837 record the macro definitions made in the file, even if we
14838 won't be able to find the file by name. */
14839 char fake_name[80];
14841 sprintf (fake_name, "<bad macro file number %d>", file);
14843 complaint (&symfile_complaints,
14844 _("bad file number in macro information (%d)"),
14847 return xstrdup (fake_name);
14852 static struct macro_source_file *
14853 macro_start_file (int file, int line,
14854 struct macro_source_file *current_file,
14855 const char *comp_dir,
14856 struct line_header *lh, struct objfile *objfile)
14858 /* The full name of this source file. */
14859 char *full_name = file_full_name (file, lh, comp_dir);
14861 /* We don't create a macro table for this compilation unit
14862 at all until we actually get a filename. */
14863 if (! pending_macros)
14864 pending_macros = new_macro_table (&objfile->objfile_obstack,
14865 objfile->macro_cache);
14867 if (! current_file)
14868 /* If we have no current file, then this must be the start_file
14869 directive for the compilation unit's main source file. */
14870 current_file = macro_set_main (pending_macros, full_name);
14872 current_file = macro_include (current_file, line, full_name);
14876 return current_file;
14880 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14881 followed by a null byte. */
14883 copy_string (const char *buf, int len)
14885 char *s = xmalloc (len + 1);
14887 memcpy (s, buf, len);
14893 static const char *
14894 consume_improper_spaces (const char *p, const char *body)
14898 complaint (&symfile_complaints,
14899 _("macro definition contains spaces "
14900 "in formal argument list:\n`%s'"),
14912 parse_macro_definition (struct macro_source_file *file, int line,
14917 /* The body string takes one of two forms. For object-like macro
14918 definitions, it should be:
14920 <macro name> " " <definition>
14922 For function-like macro definitions, it should be:
14924 <macro name> "() " <definition>
14926 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14928 Spaces may appear only where explicitly indicated, and in the
14931 The Dwarf 2 spec says that an object-like macro's name is always
14932 followed by a space, but versions of GCC around March 2002 omit
14933 the space when the macro's definition is the empty string.
14935 The Dwarf 2 spec says that there should be no spaces between the
14936 formal arguments in a function-like macro's formal argument list,
14937 but versions of GCC around March 2002 include spaces after the
14941 /* Find the extent of the macro name. The macro name is terminated
14942 by either a space or null character (for an object-like macro) or
14943 an opening paren (for a function-like macro). */
14944 for (p = body; *p; p++)
14945 if (*p == ' ' || *p == '(')
14948 if (*p == ' ' || *p == '\0')
14950 /* It's an object-like macro. */
14951 int name_len = p - body;
14952 char *name = copy_string (body, name_len);
14953 const char *replacement;
14956 replacement = body + name_len + 1;
14959 dwarf2_macro_malformed_definition_complaint (body);
14960 replacement = body + name_len;
14963 macro_define_object (file, line, name, replacement);
14967 else if (*p == '(')
14969 /* It's a function-like macro. */
14970 char *name = copy_string (body, p - body);
14973 char **argv = xmalloc (argv_size * sizeof (*argv));
14977 p = consume_improper_spaces (p, body);
14979 /* Parse the formal argument list. */
14980 while (*p && *p != ')')
14982 /* Find the extent of the current argument name. */
14983 const char *arg_start = p;
14985 while (*p && *p != ',' && *p != ')' && *p != ' ')
14988 if (! *p || p == arg_start)
14989 dwarf2_macro_malformed_definition_complaint (body);
14992 /* Make sure argv has room for the new argument. */
14993 if (argc >= argv_size)
14996 argv = xrealloc (argv, argv_size * sizeof (*argv));
14999 argv[argc++] = copy_string (arg_start, p - arg_start);
15002 p = consume_improper_spaces (p, body);
15004 /* Consume the comma, if present. */
15009 p = consume_improper_spaces (p, body);
15018 /* Perfectly formed definition, no complaints. */
15019 macro_define_function (file, line, name,
15020 argc, (const char **) argv,
15022 else if (*p == '\0')
15024 /* Complain, but do define it. */
15025 dwarf2_macro_malformed_definition_complaint (body);
15026 macro_define_function (file, line, name,
15027 argc, (const char **) argv,
15031 /* Just complain. */
15032 dwarf2_macro_malformed_definition_complaint (body);
15035 /* Just complain. */
15036 dwarf2_macro_malformed_definition_complaint (body);
15042 for (i = 0; i < argc; i++)
15048 dwarf2_macro_malformed_definition_complaint (body);
15051 /* Skip some bytes from BYTES according to the form given in FORM.
15052 Returns the new pointer. */
15055 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
15056 enum dwarf_form form,
15057 unsigned int offset_size,
15058 struct dwarf2_section_info *section)
15060 unsigned int bytes_read;
15064 case DW_FORM_data1:
15069 case DW_FORM_data2:
15073 case DW_FORM_data4:
15077 case DW_FORM_data8:
15081 case DW_FORM_string:
15082 read_direct_string (abfd, bytes, &bytes_read);
15083 bytes += bytes_read;
15086 case DW_FORM_sec_offset:
15088 bytes += offset_size;
15091 case DW_FORM_block:
15092 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
15093 bytes += bytes_read;
15096 case DW_FORM_block1:
15097 bytes += 1 + read_1_byte (abfd, bytes);
15099 case DW_FORM_block2:
15100 bytes += 2 + read_2_bytes (abfd, bytes);
15102 case DW_FORM_block4:
15103 bytes += 4 + read_4_bytes (abfd, bytes);
15106 case DW_FORM_sdata:
15107 case DW_FORM_udata:
15108 bytes = skip_leb128 (abfd, bytes);
15114 complaint (&symfile_complaints,
15115 _("invalid form 0x%x in `%s'"),
15117 section->asection->name);
15125 /* A helper for dwarf_decode_macros that handles skipping an unknown
15126 opcode. Returns an updated pointer to the macro data buffer; or,
15127 on error, issues a complaint and returns NULL. */
15130 skip_unknown_opcode (unsigned int opcode,
15131 gdb_byte **opcode_definitions,
15134 unsigned int offset_size,
15135 struct dwarf2_section_info *section)
15137 unsigned int bytes_read, i;
15141 if (opcode_definitions[opcode] == NULL)
15143 complaint (&symfile_complaints,
15144 _("unrecognized DW_MACFINO opcode 0x%x"),
15149 defn = opcode_definitions[opcode];
15150 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
15151 defn += bytes_read;
15153 for (i = 0; i < arg; ++i)
15155 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
15156 if (mac_ptr == NULL)
15158 /* skip_form_bytes already issued the complaint. */
15166 /* A helper function which parses the header of a macro section.
15167 If the macro section is the extended (for now called "GNU") type,
15168 then this updates *OFFSET_SIZE. Returns a pointer to just after
15169 the header, or issues a complaint and returns NULL on error. */
15172 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
15175 unsigned int *offset_size,
15176 int section_is_gnu)
15178 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
15180 if (section_is_gnu)
15182 unsigned int version, flags;
15184 version = read_2_bytes (abfd, mac_ptr);
15187 complaint (&symfile_complaints,
15188 _("unrecognized version `%d' in .debug_macro section"),
15194 flags = read_1_byte (abfd, mac_ptr);
15196 *offset_size = (flags & 1) ? 8 : 4;
15198 if ((flags & 2) != 0)
15199 /* We don't need the line table offset. */
15200 mac_ptr += *offset_size;
15202 /* Vendor opcode descriptions. */
15203 if ((flags & 4) != 0)
15205 unsigned int i, count;
15207 count = read_1_byte (abfd, mac_ptr);
15209 for (i = 0; i < count; ++i)
15211 unsigned int opcode, bytes_read;
15214 opcode = read_1_byte (abfd, mac_ptr);
15216 opcode_definitions[opcode] = mac_ptr;
15217 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15218 mac_ptr += bytes_read;
15227 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15228 including DW_MACRO_GNU_transparent_include. */
15231 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
15232 struct macro_source_file *current_file,
15233 struct line_header *lh, char *comp_dir,
15234 struct dwarf2_section_info *section,
15235 int section_is_gnu,
15236 unsigned int offset_size,
15237 struct objfile *objfile,
15238 htab_t include_hash)
15240 enum dwarf_macro_record_type macinfo_type;
15241 int at_commandline;
15242 gdb_byte *opcode_definitions[256];
15244 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15245 &offset_size, section_is_gnu);
15246 if (mac_ptr == NULL)
15248 /* We already issued a complaint. */
15252 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15253 GDB is still reading the definitions from command line. First
15254 DW_MACINFO_start_file will need to be ignored as it was already executed
15255 to create CURRENT_FILE for the main source holding also the command line
15256 definitions. On first met DW_MACINFO_start_file this flag is reset to
15257 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15259 at_commandline = 1;
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 macinfo_type = read_1_byte (abfd, mac_ptr);
15273 /* Note that we rely on the fact that the corresponding GNU and
15274 DWARF constants are the same. */
15275 switch (macinfo_type)
15277 /* A zero macinfo type indicates the end of the macro
15282 case DW_MACRO_GNU_define:
15283 case DW_MACRO_GNU_undef:
15284 case DW_MACRO_GNU_define_indirect:
15285 case DW_MACRO_GNU_undef_indirect:
15287 unsigned int bytes_read;
15292 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15293 mac_ptr += bytes_read;
15295 if (macinfo_type == DW_MACRO_GNU_define
15296 || macinfo_type == DW_MACRO_GNU_undef)
15298 body = read_direct_string (abfd, mac_ptr, &bytes_read);
15299 mac_ptr += bytes_read;
15303 LONGEST str_offset;
15305 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
15306 mac_ptr += offset_size;
15308 body = read_indirect_string_at_offset (abfd, str_offset);
15311 is_define = (macinfo_type == DW_MACRO_GNU_define
15312 || macinfo_type == DW_MACRO_GNU_define_indirect);
15313 if (! current_file)
15315 /* DWARF violation as no main source is present. */
15316 complaint (&symfile_complaints,
15317 _("debug info with no main source gives macro %s "
15319 is_define ? _("definition") : _("undefinition"),
15323 if ((line == 0 && !at_commandline)
15324 || (line != 0 && at_commandline))
15325 complaint (&symfile_complaints,
15326 _("debug info gives %s macro %s with %s line %d: %s"),
15327 at_commandline ? _("command-line") : _("in-file"),
15328 is_define ? _("definition") : _("undefinition"),
15329 line == 0 ? _("zero") : _("non-zero"), line, body);
15332 parse_macro_definition (current_file, line, body);
15335 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
15336 || macinfo_type == DW_MACRO_GNU_undef_indirect);
15337 macro_undef (current_file, line, body);
15342 case DW_MACRO_GNU_start_file:
15344 unsigned int bytes_read;
15347 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15348 mac_ptr += bytes_read;
15349 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15350 mac_ptr += bytes_read;
15352 if ((line == 0 && !at_commandline)
15353 || (line != 0 && at_commandline))
15354 complaint (&symfile_complaints,
15355 _("debug info gives source %d included "
15356 "from %s at %s line %d"),
15357 file, at_commandline ? _("command-line") : _("file"),
15358 line == 0 ? _("zero") : _("non-zero"), line);
15360 if (at_commandline)
15362 /* This DW_MACRO_GNU_start_file was executed in the
15364 at_commandline = 0;
15367 current_file = macro_start_file (file, line,
15368 current_file, comp_dir,
15373 case DW_MACRO_GNU_end_file:
15374 if (! current_file)
15375 complaint (&symfile_complaints,
15376 _("macro debug info has an unmatched "
15377 "`close_file' directive"));
15380 current_file = current_file->included_by;
15381 if (! current_file)
15383 enum dwarf_macro_record_type next_type;
15385 /* GCC circa March 2002 doesn't produce the zero
15386 type byte marking the end of the compilation
15387 unit. Complain if it's not there, but exit no
15390 /* Do we at least have room for a macinfo type byte? */
15391 if (mac_ptr >= mac_end)
15393 dwarf2_macros_too_long_complaint (section);
15397 /* We don't increment mac_ptr here, so this is just
15399 next_type = read_1_byte (abfd, mac_ptr);
15400 if (next_type != 0)
15401 complaint (&symfile_complaints,
15402 _("no terminating 0-type entry for "
15403 "macros in `.debug_macinfo' section"));
15410 case DW_MACRO_GNU_transparent_include:
15415 offset = read_offset_1 (abfd, mac_ptr, offset_size);
15416 mac_ptr += offset_size;
15418 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15421 /* This has actually happened; see
15422 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15423 complaint (&symfile_complaints,
15424 _("recursive DW_MACRO_GNU_transparent_include in "
15425 ".debug_macro section"));
15431 dwarf_decode_macro_bytes (abfd,
15432 section->buffer + offset,
15433 mac_end, current_file,
15435 section, section_is_gnu,
15436 offset_size, objfile, include_hash);
15438 htab_remove_elt (include_hash, mac_ptr);
15443 case DW_MACINFO_vendor_ext:
15444 if (!section_is_gnu)
15446 unsigned int bytes_read;
15449 constant = 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;
15454 /* We don't recognize any vendor extensions. */
15460 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15461 mac_ptr, abfd, offset_size,
15463 if (mac_ptr == NULL)
15467 } while (macinfo_type != 0);
15471 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
15472 char *comp_dir, bfd *abfd,
15473 struct dwarf2_cu *cu,
15474 struct dwarf2_section_info *section,
15475 int section_is_gnu)
15477 struct objfile *objfile = dwarf2_per_objfile->objfile;
15478 gdb_byte *mac_ptr, *mac_end;
15479 struct macro_source_file *current_file = 0;
15480 enum dwarf_macro_record_type macinfo_type;
15481 unsigned int offset_size = cu->header.offset_size;
15482 gdb_byte *opcode_definitions[256];
15483 struct cleanup *cleanup;
15484 htab_t include_hash;
15487 dwarf2_read_section (objfile, section);
15488 if (section->buffer == NULL)
15490 complaint (&symfile_complaints, _("missing %s section"),
15491 section->asection->name);
15495 /* First pass: Find the name of the base filename.
15496 This filename is needed in order to process all macros whose definition
15497 (or undefinition) comes from the command line. These macros are defined
15498 before the first DW_MACINFO_start_file entry, and yet still need to be
15499 associated to the base file.
15501 To determine the base file name, we scan the macro definitions until we
15502 reach the first DW_MACINFO_start_file entry. We then initialize
15503 CURRENT_FILE accordingly so that any macro definition found before the
15504 first DW_MACINFO_start_file can still be associated to the base file. */
15506 mac_ptr = section->buffer + offset;
15507 mac_end = section->buffer + section->size;
15509 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15510 &offset_size, section_is_gnu);
15511 if (mac_ptr == NULL)
15513 /* We already issued a complaint. */
15519 /* Do we at least have room for a macinfo type byte? */
15520 if (mac_ptr >= mac_end)
15522 /* Complaint is printed during the second pass as GDB will probably
15523 stop the first pass earlier upon finding
15524 DW_MACINFO_start_file. */
15528 macinfo_type = read_1_byte (abfd, mac_ptr);
15531 /* Note that we rely on the fact that the corresponding GNU and
15532 DWARF constants are the same. */
15533 switch (macinfo_type)
15535 /* A zero macinfo type indicates the end of the macro
15540 case DW_MACRO_GNU_define:
15541 case DW_MACRO_GNU_undef:
15542 /* Only skip the data by MAC_PTR. */
15544 unsigned int bytes_read;
15546 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15547 mac_ptr += bytes_read;
15548 read_direct_string (abfd, mac_ptr, &bytes_read);
15549 mac_ptr += bytes_read;
15553 case DW_MACRO_GNU_start_file:
15555 unsigned int bytes_read;
15558 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15559 mac_ptr += bytes_read;
15560 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15561 mac_ptr += bytes_read;
15563 current_file = macro_start_file (file, line, current_file,
15564 comp_dir, lh, objfile);
15568 case DW_MACRO_GNU_end_file:
15569 /* No data to skip by MAC_PTR. */
15572 case DW_MACRO_GNU_define_indirect:
15573 case DW_MACRO_GNU_undef_indirect:
15575 unsigned int bytes_read;
15577 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15578 mac_ptr += bytes_read;
15579 mac_ptr += offset_size;
15583 case DW_MACRO_GNU_transparent_include:
15584 /* Note that, according to the spec, a transparent include
15585 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15586 skip this opcode. */
15587 mac_ptr += offset_size;
15590 case DW_MACINFO_vendor_ext:
15591 /* Only skip the data by MAC_PTR. */
15592 if (!section_is_gnu)
15594 unsigned int bytes_read;
15596 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15597 mac_ptr += bytes_read;
15598 read_direct_string (abfd, mac_ptr, &bytes_read);
15599 mac_ptr += bytes_read;
15604 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15605 mac_ptr, abfd, offset_size,
15607 if (mac_ptr == NULL)
15611 } while (macinfo_type != 0 && current_file == NULL);
15613 /* Second pass: Process all entries.
15615 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15616 command-line macro definitions/undefinitions. This flag is unset when we
15617 reach the first DW_MACINFO_start_file entry. */
15619 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
15620 NULL, xcalloc, xfree);
15621 cleanup = make_cleanup_htab_delete (include_hash);
15622 mac_ptr = section->buffer + offset;
15623 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
15625 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
15626 current_file, lh, comp_dir, section, section_is_gnu,
15627 offset_size, objfile, include_hash);
15628 do_cleanups (cleanup);
15631 /* Check if the attribute's form is a DW_FORM_block*
15632 if so return true else false. */
15634 attr_form_is_block (struct attribute *attr)
15636 return (attr == NULL ? 0 :
15637 attr->form == DW_FORM_block1
15638 || attr->form == DW_FORM_block2
15639 || attr->form == DW_FORM_block4
15640 || attr->form == DW_FORM_block
15641 || attr->form == DW_FORM_exprloc);
15644 /* Return non-zero if ATTR's value is a section offset --- classes
15645 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15646 You may use DW_UNSND (attr) to retrieve such offsets.
15648 Section 7.5.4, "Attribute Encodings", explains that no attribute
15649 may have a value that belongs to more than one of these classes; it
15650 would be ambiguous if we did, because we use the same forms for all
15653 attr_form_is_section_offset (struct attribute *attr)
15655 return (attr->form == DW_FORM_data4
15656 || attr->form == DW_FORM_data8
15657 || attr->form == DW_FORM_sec_offset);
15661 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15662 zero otherwise. When this function returns true, you can apply
15663 dwarf2_get_attr_constant_value to it.
15665 However, note that for some attributes you must check
15666 attr_form_is_section_offset before using this test. DW_FORM_data4
15667 and DW_FORM_data8 are members of both the constant class, and of
15668 the classes that contain offsets into other debug sections
15669 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15670 that, if an attribute's can be either a constant or one of the
15671 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15672 taken as section offsets, not constants. */
15674 attr_form_is_constant (struct attribute *attr)
15676 switch (attr->form)
15678 case DW_FORM_sdata:
15679 case DW_FORM_udata:
15680 case DW_FORM_data1:
15681 case DW_FORM_data2:
15682 case DW_FORM_data4:
15683 case DW_FORM_data8:
15690 /* A helper function that fills in a dwarf2_loclist_baton. */
15693 fill_in_loclist_baton (struct dwarf2_cu *cu,
15694 struct dwarf2_loclist_baton *baton,
15695 struct attribute *attr)
15697 dwarf2_read_section (dwarf2_per_objfile->objfile,
15698 &dwarf2_per_objfile->loc);
15700 baton->per_cu = cu->per_cu;
15701 gdb_assert (baton->per_cu);
15702 /* We don't know how long the location list is, but make sure we
15703 don't run off the edge of the section. */
15704 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15705 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15706 baton->base_address = cu->base_address;
15710 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15711 struct dwarf2_cu *cu)
15713 struct objfile *objfile = dwarf2_per_objfile->objfile;
15715 if (attr_form_is_section_offset (attr)
15716 /* ".debug_loc" may not exist at all, or the offset may be outside
15717 the section. If so, fall through to the complaint in the
15719 && DW_UNSND (attr) < dwarf2_section_size (objfile,
15720 &dwarf2_per_objfile->loc))
15722 struct dwarf2_loclist_baton *baton;
15724 baton = obstack_alloc (&objfile->objfile_obstack,
15725 sizeof (struct dwarf2_loclist_baton));
15727 fill_in_loclist_baton (cu, baton, attr);
15729 if (cu->base_known == 0)
15730 complaint (&symfile_complaints,
15731 _("Location list used without "
15732 "specifying the CU base address."));
15734 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15735 SYMBOL_LOCATION_BATON (sym) = baton;
15739 struct dwarf2_locexpr_baton *baton;
15741 baton = obstack_alloc (&objfile->objfile_obstack,
15742 sizeof (struct dwarf2_locexpr_baton));
15743 baton->per_cu = cu->per_cu;
15744 gdb_assert (baton->per_cu);
15746 if (attr_form_is_block (attr))
15748 /* Note that we're just copying the block's data pointer
15749 here, not the actual data. We're still pointing into the
15750 info_buffer for SYM's objfile; right now we never release
15751 that buffer, but when we do clean up properly this may
15753 baton->size = DW_BLOCK (attr)->size;
15754 baton->data = DW_BLOCK (attr)->data;
15758 dwarf2_invalid_attrib_class_complaint ("location description",
15759 SYMBOL_NATURAL_NAME (sym));
15763 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15764 SYMBOL_LOCATION_BATON (sym) = baton;
15768 /* Return the OBJFILE associated with the compilation unit CU. If CU
15769 came from a separate debuginfo file, then the master objfile is
15773 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15775 struct objfile *objfile = per_cu->objfile;
15777 /* Return the master objfile, so that we can report and look up the
15778 correct file containing this variable. */
15779 if (objfile->separate_debug_objfile_backlink)
15780 objfile = objfile->separate_debug_objfile_backlink;
15785 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15786 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15787 CU_HEADERP first. */
15789 static const struct comp_unit_head *
15790 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15791 struct dwarf2_per_cu_data *per_cu)
15793 struct objfile *objfile;
15794 struct dwarf2_per_objfile *per_objfile;
15795 gdb_byte *info_ptr;
15798 return &per_cu->cu->header;
15800 objfile = per_cu->objfile;
15801 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15802 info_ptr = per_objfile->info.buffer + per_cu->offset;
15804 memset (cu_headerp, 0, sizeof (*cu_headerp));
15805 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15810 /* Return the address size given in the compilation unit header for CU. */
15813 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15815 struct comp_unit_head cu_header_local;
15816 const struct comp_unit_head *cu_headerp;
15818 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15820 return cu_headerp->addr_size;
15823 /* Return the offset size given in the compilation unit header for CU. */
15826 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15828 struct comp_unit_head cu_header_local;
15829 const struct comp_unit_head *cu_headerp;
15831 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15833 return cu_headerp->offset_size;
15836 /* See its dwarf2loc.h declaration. */
15839 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
15841 struct comp_unit_head cu_header_local;
15842 const struct comp_unit_head *cu_headerp;
15844 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15846 if (cu_headerp->version == 2)
15847 return cu_headerp->addr_size;
15849 return cu_headerp->offset_size;
15852 /* Return the text offset of the CU. The returned offset comes from
15853 this CU's objfile. If this objfile came from a separate debuginfo
15854 file, then the offset may be different from the corresponding
15855 offset in the parent objfile. */
15858 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
15860 struct objfile *objfile = per_cu->objfile;
15862 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15865 /* Locate the .debug_info compilation unit from CU's objfile which contains
15866 the DIE at OFFSET. Raises an error on failure. */
15868 static struct dwarf2_per_cu_data *
15869 dwarf2_find_containing_comp_unit (unsigned int offset,
15870 struct objfile *objfile)
15872 struct dwarf2_per_cu_data *this_cu;
15876 high = dwarf2_per_objfile->n_comp_units - 1;
15879 int mid = low + (high - low) / 2;
15881 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
15886 gdb_assert (low == high);
15887 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
15890 error (_("Dwarf Error: could not find partial DIE containing "
15891 "offset 0x%lx [in module %s]"),
15892 (long) offset, bfd_get_filename (objfile->obfd));
15894 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
15895 return dwarf2_per_objfile->all_comp_units[low-1];
15899 this_cu = dwarf2_per_objfile->all_comp_units[low];
15900 if (low == dwarf2_per_objfile->n_comp_units - 1
15901 && offset >= this_cu->offset + this_cu->length)
15902 error (_("invalid dwarf2 offset %u"), offset);
15903 gdb_assert (offset < this_cu->offset + this_cu->length);
15908 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15911 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
15913 memset (cu, 0, sizeof (*cu));
15915 cu->per_cu = per_cu;
15916 cu->objfile = per_cu->objfile;
15917 obstack_init (&cu->comp_unit_obstack);
15920 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15923 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
15925 struct attribute *attr;
15927 /* Set the language we're debugging. */
15928 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
15930 set_cu_language (DW_UNSND (attr), cu);
15933 cu->language = language_minimal;
15934 cu->language_defn = language_def (cu->language);
15938 /* Release one cached compilation unit, CU. We unlink it from the tree
15939 of compilation units, but we don't remove it from the read_in_chain;
15940 the caller is responsible for that.
15941 NOTE: DATA is a void * because this function is also used as a
15942 cleanup routine. */
15945 free_heap_comp_unit (void *data)
15947 struct dwarf2_cu *cu = data;
15949 gdb_assert (cu->per_cu != NULL);
15950 cu->per_cu->cu = NULL;
15953 obstack_free (&cu->comp_unit_obstack, NULL);
15958 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15959 when we're finished with it. We can't free the pointer itself, but be
15960 sure to unlink it from the cache. Also release any associated storage
15961 and perform cache maintenance.
15963 Only used during partial symbol parsing. */
15966 free_stack_comp_unit (void *data)
15968 struct dwarf2_cu *cu = data;
15970 gdb_assert (cu->per_cu != NULL);
15971 cu->per_cu->cu = NULL;
15974 obstack_free (&cu->comp_unit_obstack, NULL);
15975 cu->partial_dies = NULL;
15977 /* The previous code only did this if per_cu != NULL.
15978 But that would always succeed, so now we just unconditionally do
15979 the aging. This seems like the wrong place to do such aging,
15980 but cleaning that up is left for later. */
15981 age_cached_comp_units ();
15984 /* Free all cached compilation units. */
15987 free_cached_comp_units (void *data)
15989 struct dwarf2_per_cu_data *per_cu, **last_chain;
15991 per_cu = dwarf2_per_objfile->read_in_chain;
15992 last_chain = &dwarf2_per_objfile->read_in_chain;
15993 while (per_cu != NULL)
15995 struct dwarf2_per_cu_data *next_cu;
15997 next_cu = per_cu->cu->read_in_chain;
15999 free_heap_comp_unit (per_cu->cu);
16000 *last_chain = next_cu;
16006 /* Increase the age counter on each cached compilation unit, and free
16007 any that are too old. */
16010 age_cached_comp_units (void)
16012 struct dwarf2_per_cu_data *per_cu, **last_chain;
16014 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
16015 per_cu = dwarf2_per_objfile->read_in_chain;
16016 while (per_cu != NULL)
16018 per_cu->cu->last_used ++;
16019 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
16020 dwarf2_mark (per_cu->cu);
16021 per_cu = per_cu->cu->read_in_chain;
16024 per_cu = dwarf2_per_objfile->read_in_chain;
16025 last_chain = &dwarf2_per_objfile->read_in_chain;
16026 while (per_cu != NULL)
16028 struct dwarf2_per_cu_data *next_cu;
16030 next_cu = per_cu->cu->read_in_chain;
16032 if (!per_cu->cu->mark)
16034 free_heap_comp_unit (per_cu->cu);
16035 *last_chain = next_cu;
16038 last_chain = &per_cu->cu->read_in_chain;
16044 /* Remove a single compilation unit from the cache. */
16047 free_one_cached_comp_unit (void *target_cu)
16049 struct dwarf2_per_cu_data *per_cu, **last_chain;
16051 per_cu = dwarf2_per_objfile->read_in_chain;
16052 last_chain = &dwarf2_per_objfile->read_in_chain;
16053 while (per_cu != NULL)
16055 struct dwarf2_per_cu_data *next_cu;
16057 next_cu = per_cu->cu->read_in_chain;
16059 if (per_cu->cu == target_cu)
16061 free_heap_comp_unit (per_cu->cu);
16062 *last_chain = next_cu;
16066 last_chain = &per_cu->cu->read_in_chain;
16072 /* Release all extra memory associated with OBJFILE. */
16075 dwarf2_free_objfile (struct objfile *objfile)
16077 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16079 if (dwarf2_per_objfile == NULL)
16082 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16083 free_cached_comp_units (NULL);
16085 if (dwarf2_per_objfile->quick_file_names_table)
16086 htab_delete (dwarf2_per_objfile->quick_file_names_table);
16088 /* Everything else should be on the objfile obstack. */
16091 /* A pair of DIE offset and GDB type pointer. We store these
16092 in a hash table separate from the DIEs, and preserve them
16093 when the DIEs are flushed out of cache. */
16095 struct dwarf2_offset_and_type
16097 unsigned int offset;
16101 /* Hash function for a dwarf2_offset_and_type. */
16104 offset_and_type_hash (const void *item)
16106 const struct dwarf2_offset_and_type *ofs = item;
16108 return ofs->offset;
16111 /* Equality function for a dwarf2_offset_and_type. */
16114 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
16116 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
16117 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
16119 return ofs_lhs->offset == ofs_rhs->offset;
16122 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16123 table if necessary. For convenience, return TYPE.
16125 The DIEs reading must have careful ordering to:
16126 * Not cause infite loops trying to read in DIEs as a prerequisite for
16127 reading current DIE.
16128 * Not trying to dereference contents of still incompletely read in types
16129 while reading in other DIEs.
16130 * Enable referencing still incompletely read in types just by a pointer to
16131 the type without accessing its fields.
16133 Therefore caller should follow these rules:
16134 * Try to fetch any prerequisite types we may need to build this DIE type
16135 before building the type and calling set_die_type.
16136 * After building type call set_die_type for current DIE as soon as
16137 possible before fetching more types to complete the current type.
16138 * Make the type as complete as possible before fetching more types. */
16140 static struct type *
16141 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16143 struct dwarf2_offset_and_type **slot, ofs;
16144 struct objfile *objfile = cu->objfile;
16145 htab_t *type_hash_ptr;
16147 /* For Ada types, make sure that the gnat-specific data is always
16148 initialized (if not already set). There are a few types where
16149 we should not be doing so, because the type-specific area is
16150 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16151 where the type-specific area is used to store the floatformat).
16152 But this is not a problem, because the gnat-specific information
16153 is actually not needed for these types. */
16154 if (need_gnat_info (cu)
16155 && TYPE_CODE (type) != TYPE_CODE_FUNC
16156 && TYPE_CODE (type) != TYPE_CODE_FLT
16157 && !HAVE_GNAT_AUX_INFO (type))
16158 INIT_GNAT_SPECIFIC (type);
16160 if (cu->per_cu->debug_types_section)
16161 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
16163 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
16165 if (*type_hash_ptr == NULL)
16168 = htab_create_alloc_ex (127,
16169 offset_and_type_hash,
16170 offset_and_type_eq,
16172 &objfile->objfile_obstack,
16173 hashtab_obstack_allocate,
16174 dummy_obstack_deallocate);
16177 ofs.offset = die->offset;
16179 slot = (struct dwarf2_offset_and_type **)
16180 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
16182 complaint (&symfile_complaints,
16183 _("A problem internal to GDB: DIE 0x%x has type already set"),
16185 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
16190 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16191 table, or return NULL if the die does not have a saved type. */
16193 static struct type *
16194 get_die_type_at_offset (unsigned int offset,
16195 struct dwarf2_per_cu_data *per_cu)
16197 struct dwarf2_offset_and_type *slot, ofs;
16200 if (per_cu->debug_types_section)
16201 type_hash = dwarf2_per_objfile->debug_types_type_hash;
16203 type_hash = dwarf2_per_objfile->debug_info_type_hash;
16204 if (type_hash == NULL)
16207 ofs.offset = offset;
16208 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
16215 /* Look up the type for DIE in the appropriate type_hash table,
16216 or return NULL if DIE does not have a saved type. */
16218 static struct type *
16219 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
16221 return get_die_type_at_offset (die->offset, cu->per_cu);
16224 /* Add a dependence relationship from CU to REF_PER_CU. */
16227 dwarf2_add_dependence (struct dwarf2_cu *cu,
16228 struct dwarf2_per_cu_data *ref_per_cu)
16232 if (cu->dependencies == NULL)
16234 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
16235 NULL, &cu->comp_unit_obstack,
16236 hashtab_obstack_allocate,
16237 dummy_obstack_deallocate);
16239 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
16241 *slot = ref_per_cu;
16244 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16245 Set the mark field in every compilation unit in the
16246 cache that we must keep because we are keeping CU. */
16249 dwarf2_mark_helper (void **slot, void *data)
16251 struct dwarf2_per_cu_data *per_cu;
16253 per_cu = (struct dwarf2_per_cu_data *) *slot;
16255 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16256 reading of the chain. As such dependencies remain valid it is not much
16257 useful to track and undo them during QUIT cleanups. */
16258 if (per_cu->cu == NULL)
16261 if (per_cu->cu->mark)
16263 per_cu->cu->mark = 1;
16265 if (per_cu->cu->dependencies != NULL)
16266 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
16271 /* Set the mark field in CU and in every other compilation unit in the
16272 cache that we must keep because we are keeping CU. */
16275 dwarf2_mark (struct dwarf2_cu *cu)
16280 if (cu->dependencies != NULL)
16281 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
16285 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
16289 per_cu->cu->mark = 0;
16290 per_cu = per_cu->cu->read_in_chain;
16294 /* Trivial hash function for partial_die_info: the hash value of a DIE
16295 is its offset in .debug_info for this objfile. */
16298 partial_die_hash (const void *item)
16300 const struct partial_die_info *part_die = item;
16302 return part_die->offset;
16305 /* Trivial comparison function for partial_die_info structures: two DIEs
16306 are equal if they have the same offset. */
16309 partial_die_eq (const void *item_lhs, const void *item_rhs)
16311 const struct partial_die_info *part_die_lhs = item_lhs;
16312 const struct partial_die_info *part_die_rhs = item_rhs;
16314 return part_die_lhs->offset == part_die_rhs->offset;
16317 static struct cmd_list_element *set_dwarf2_cmdlist;
16318 static struct cmd_list_element *show_dwarf2_cmdlist;
16321 set_dwarf2_cmd (char *args, int from_tty)
16323 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
16327 show_dwarf2_cmd (char *args, int from_tty)
16329 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
16332 /* If section described by INFO was mmapped, munmap it now. */
16335 munmap_section_buffer (struct dwarf2_section_info *info)
16337 if (info->map_addr != NULL)
16342 res = munmap (info->map_addr, info->map_len);
16343 gdb_assert (res == 0);
16345 /* Without HAVE_MMAP, we should never be here to begin with. */
16346 gdb_assert_not_reached ("no mmap support");
16351 /* munmap debug sections for OBJFILE, if necessary. */
16354 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
16356 struct dwarf2_per_objfile *data = d;
16358 struct dwarf2_section_info *section;
16360 /* This is sorted according to the order they're defined in to make it easier
16361 to keep in sync. */
16362 munmap_section_buffer (&data->info);
16363 munmap_section_buffer (&data->abbrev);
16364 munmap_section_buffer (&data->line);
16365 munmap_section_buffer (&data->loc);
16366 munmap_section_buffer (&data->macinfo);
16367 munmap_section_buffer (&data->macro);
16368 munmap_section_buffer (&data->str);
16369 munmap_section_buffer (&data->ranges);
16370 munmap_section_buffer (&data->frame);
16371 munmap_section_buffer (&data->eh_frame);
16372 munmap_section_buffer (&data->gdb_index);
16375 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
16377 munmap_section_buffer (section);
16379 VEC_free (dwarf2_section_info_def, data->types);
16383 /* The "save gdb-index" command. */
16385 /* The contents of the hash table we create when building the string
16387 struct strtab_entry
16389 offset_type offset;
16393 /* Hash function for a strtab_entry.
16395 Function is used only during write_hash_table so no index format backward
16396 compatibility is needed. */
16399 hash_strtab_entry (const void *e)
16401 const struct strtab_entry *entry = e;
16402 return mapped_index_string_hash (INT_MAX, entry->str);
16405 /* Equality function for a strtab_entry. */
16408 eq_strtab_entry (const void *a, const void *b)
16410 const struct strtab_entry *ea = a;
16411 const struct strtab_entry *eb = b;
16412 return !strcmp (ea->str, eb->str);
16415 /* Create a strtab_entry hash table. */
16418 create_strtab (void)
16420 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
16421 xfree, xcalloc, xfree);
16424 /* Add a string to the constant pool. Return the string's offset in
16428 add_string (htab_t table, struct obstack *cpool, const char *str)
16431 struct strtab_entry entry;
16432 struct strtab_entry *result;
16435 slot = htab_find_slot (table, &entry, INSERT);
16440 result = XNEW (struct strtab_entry);
16441 result->offset = obstack_object_size (cpool);
16443 obstack_grow_str0 (cpool, str);
16446 return result->offset;
16449 /* An entry in the symbol table. */
16450 struct symtab_index_entry
16452 /* The name of the symbol. */
16454 /* The offset of the name in the constant pool. */
16455 offset_type index_offset;
16456 /* A sorted vector of the indices of all the CUs that hold an object
16458 VEC (offset_type) *cu_indices;
16461 /* The symbol table. This is a power-of-2-sized hash table. */
16462 struct mapped_symtab
16464 offset_type n_elements;
16466 struct symtab_index_entry **data;
16469 /* Hash function for a symtab_index_entry. */
16472 hash_symtab_entry (const void *e)
16474 const struct symtab_index_entry *entry = e;
16475 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
16476 sizeof (offset_type) * VEC_length (offset_type,
16477 entry->cu_indices),
16481 /* Equality function for a symtab_index_entry. */
16484 eq_symtab_entry (const void *a, const void *b)
16486 const struct symtab_index_entry *ea = a;
16487 const struct symtab_index_entry *eb = b;
16488 int len = VEC_length (offset_type, ea->cu_indices);
16489 if (len != VEC_length (offset_type, eb->cu_indices))
16491 return !memcmp (VEC_address (offset_type, ea->cu_indices),
16492 VEC_address (offset_type, eb->cu_indices),
16493 sizeof (offset_type) * len);
16496 /* Destroy a symtab_index_entry. */
16499 delete_symtab_entry (void *p)
16501 struct symtab_index_entry *entry = p;
16502 VEC_free (offset_type, entry->cu_indices);
16506 /* Create a hash table holding symtab_index_entry objects. */
16509 create_symbol_hash_table (void)
16511 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
16512 delete_symtab_entry, xcalloc, xfree);
16515 /* Create a new mapped symtab object. */
16517 static struct mapped_symtab *
16518 create_mapped_symtab (void)
16520 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
16521 symtab->n_elements = 0;
16522 symtab->size = 1024;
16523 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16527 /* Destroy a mapped_symtab. */
16530 cleanup_mapped_symtab (void *p)
16532 struct mapped_symtab *symtab = p;
16533 /* The contents of the array are freed when the other hash table is
16535 xfree (symtab->data);
16539 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16542 Function is used only during write_hash_table so no index format backward
16543 compatibility is needed. */
16545 static struct symtab_index_entry **
16546 find_slot (struct mapped_symtab *symtab, const char *name)
16548 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16550 index = hash & (symtab->size - 1);
16551 step = ((hash * 17) & (symtab->size - 1)) | 1;
16555 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16556 return &symtab->data[index];
16557 index = (index + step) & (symtab->size - 1);
16561 /* Expand SYMTAB's hash table. */
16564 hash_expand (struct mapped_symtab *symtab)
16566 offset_type old_size = symtab->size;
16568 struct symtab_index_entry **old_entries = symtab->data;
16571 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16573 for (i = 0; i < old_size; ++i)
16575 if (old_entries[i])
16577 struct symtab_index_entry **slot = find_slot (symtab,
16578 old_entries[i]->name);
16579 *slot = old_entries[i];
16583 xfree (old_entries);
16586 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16587 is the index of the CU in which the symbol appears. */
16590 add_index_entry (struct mapped_symtab *symtab, const char *name,
16591 offset_type cu_index)
16593 struct symtab_index_entry **slot;
16595 ++symtab->n_elements;
16596 if (4 * symtab->n_elements / 3 >= symtab->size)
16597 hash_expand (symtab);
16599 slot = find_slot (symtab, name);
16602 *slot = XNEW (struct symtab_index_entry);
16603 (*slot)->name = name;
16604 (*slot)->cu_indices = NULL;
16606 /* Don't push an index twice. Due to how we add entries we only
16607 have to check the last one. */
16608 if (VEC_empty (offset_type, (*slot)->cu_indices)
16609 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16610 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16613 /* Add a vector of indices to the constant pool. */
16616 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16617 struct symtab_index_entry *entry)
16621 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16624 offset_type len = VEC_length (offset_type, entry->cu_indices);
16625 offset_type val = MAYBE_SWAP (len);
16630 entry->index_offset = obstack_object_size (cpool);
16632 obstack_grow (cpool, &val, sizeof (val));
16634 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16637 val = MAYBE_SWAP (iter);
16638 obstack_grow (cpool, &val, sizeof (val));
16643 struct symtab_index_entry *old_entry = *slot;
16644 entry->index_offset = old_entry->index_offset;
16647 return entry->index_offset;
16650 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16651 constant pool entries going into the obstack CPOOL. */
16654 write_hash_table (struct mapped_symtab *symtab,
16655 struct obstack *output, struct obstack *cpool)
16658 htab_t symbol_hash_table;
16661 symbol_hash_table = create_symbol_hash_table ();
16662 str_table = create_strtab ();
16664 /* We add all the index vectors to the constant pool first, to
16665 ensure alignment is ok. */
16666 for (i = 0; i < symtab->size; ++i)
16668 if (symtab->data[i])
16669 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16672 /* Now write out the hash table. */
16673 for (i = 0; i < symtab->size; ++i)
16675 offset_type str_off, vec_off;
16677 if (symtab->data[i])
16679 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16680 vec_off = symtab->data[i]->index_offset;
16684 /* While 0 is a valid constant pool index, it is not valid
16685 to have 0 for both offsets. */
16690 str_off = MAYBE_SWAP (str_off);
16691 vec_off = MAYBE_SWAP (vec_off);
16693 obstack_grow (output, &str_off, sizeof (str_off));
16694 obstack_grow (output, &vec_off, sizeof (vec_off));
16697 htab_delete (str_table);
16698 htab_delete (symbol_hash_table);
16701 /* Struct to map psymtab to CU index in the index file. */
16702 struct psymtab_cu_index_map
16704 struct partial_symtab *psymtab;
16705 unsigned int cu_index;
16709 hash_psymtab_cu_index (const void *item)
16711 const struct psymtab_cu_index_map *map = item;
16713 return htab_hash_pointer (map->psymtab);
16717 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16719 const struct psymtab_cu_index_map *lhs = item_lhs;
16720 const struct psymtab_cu_index_map *rhs = item_rhs;
16722 return lhs->psymtab == rhs->psymtab;
16725 /* Helper struct for building the address table. */
16726 struct addrmap_index_data
16728 struct objfile *objfile;
16729 struct obstack *addr_obstack;
16730 htab_t cu_index_htab;
16732 /* Non-zero if the previous_* fields are valid.
16733 We can't write an entry until we see the next entry (since it is only then
16734 that we know the end of the entry). */
16735 int previous_valid;
16736 /* Index of the CU in the table of all CUs in the index file. */
16737 unsigned int previous_cu_index;
16738 /* Start address of the CU. */
16739 CORE_ADDR previous_cu_start;
16742 /* Write an address entry to OBSTACK. */
16745 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16746 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16748 offset_type cu_index_to_write;
16750 CORE_ADDR baseaddr;
16752 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16754 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16755 obstack_grow (obstack, addr, 8);
16756 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16757 obstack_grow (obstack, addr, 8);
16758 cu_index_to_write = MAYBE_SWAP (cu_index);
16759 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16762 /* Worker function for traversing an addrmap to build the address table. */
16765 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16767 struct addrmap_index_data *data = datap;
16768 struct partial_symtab *pst = obj;
16769 offset_type cu_index;
16772 if (data->previous_valid)
16773 add_address_entry (data->objfile, data->addr_obstack,
16774 data->previous_cu_start, start_addr,
16775 data->previous_cu_index);
16777 data->previous_cu_start = start_addr;
16780 struct psymtab_cu_index_map find_map, *map;
16781 find_map.psymtab = pst;
16782 map = htab_find (data->cu_index_htab, &find_map);
16783 gdb_assert (map != NULL);
16784 data->previous_cu_index = map->cu_index;
16785 data->previous_valid = 1;
16788 data->previous_valid = 0;
16793 /* Write OBJFILE's address map to OBSTACK.
16794 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16795 in the index file. */
16798 write_address_map (struct objfile *objfile, struct obstack *obstack,
16799 htab_t cu_index_htab)
16801 struct addrmap_index_data addrmap_index_data;
16803 /* When writing the address table, we have to cope with the fact that
16804 the addrmap iterator only provides the start of a region; we have to
16805 wait until the next invocation to get the start of the next region. */
16807 addrmap_index_data.objfile = objfile;
16808 addrmap_index_data.addr_obstack = obstack;
16809 addrmap_index_data.cu_index_htab = cu_index_htab;
16810 addrmap_index_data.previous_valid = 0;
16812 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16813 &addrmap_index_data);
16815 /* It's highly unlikely the last entry (end address = 0xff...ff)
16816 is valid, but we should still handle it.
16817 The end address is recorded as the start of the next region, but that
16818 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16820 if (addrmap_index_data.previous_valid)
16821 add_address_entry (objfile, obstack,
16822 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16823 addrmap_index_data.previous_cu_index);
16826 /* Add a list of partial symbols to SYMTAB. */
16829 write_psymbols (struct mapped_symtab *symtab,
16831 struct partial_symbol **psymp,
16833 offset_type cu_index,
16836 for (; count-- > 0; ++psymp)
16838 void **slot, *lookup;
16840 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16841 error (_("Ada is not currently supported by the index"));
16843 /* We only want to add a given psymbol once. However, we also
16844 want to account for whether it is global or static. So, we
16845 may add it twice, using slightly different values. */
16848 uintptr_t val = 1 | (uintptr_t) *psymp;
16850 lookup = (void *) val;
16855 /* Only add a given psymbol once. */
16856 slot = htab_find_slot (psyms_seen, lookup, INSERT);
16860 add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index);
16865 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16866 exception if there is an error. */
16869 write_obstack (FILE *file, struct obstack *obstack)
16871 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
16873 != obstack_object_size (obstack))
16874 error (_("couldn't data write to file"));
16877 /* Unlink a file if the argument is not NULL. */
16880 unlink_if_set (void *p)
16882 char **filename = p;
16884 unlink (*filename);
16887 /* A helper struct used when iterating over debug_types. */
16888 struct signatured_type_index_data
16890 struct objfile *objfile;
16891 struct mapped_symtab *symtab;
16892 struct obstack *types_list;
16897 /* A helper function that writes a single signatured_type to an
16901 write_one_signatured_type (void **slot, void *d)
16903 struct signatured_type_index_data *info = d;
16904 struct signatured_type *entry = (struct signatured_type *) *slot;
16905 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
16906 struct partial_symtab *psymtab = per_cu->v.psymtab;
16909 write_psymbols (info->symtab,
16911 info->objfile->global_psymbols.list
16912 + psymtab->globals_offset,
16913 psymtab->n_global_syms, info->cu_index,
16915 write_psymbols (info->symtab,
16917 info->objfile->static_psymbols.list
16918 + psymtab->statics_offset,
16919 psymtab->n_static_syms, info->cu_index,
16922 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
16923 obstack_grow (info->types_list, val, 8);
16924 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
16925 obstack_grow (info->types_list, val, 8);
16926 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
16927 obstack_grow (info->types_list, val, 8);
16934 /* Create an index file for OBJFILE in the directory DIR. */
16937 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
16939 struct cleanup *cleanup;
16940 char *filename, *cleanup_filename;
16941 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
16942 struct obstack cu_list, types_cu_list;
16945 struct mapped_symtab *symtab;
16946 offset_type val, size_of_contents, total_len;
16950 htab_t cu_index_htab;
16951 struct psymtab_cu_index_map *psymtab_cu_index_map;
16953 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
16956 if (dwarf2_per_objfile->using_index)
16957 error (_("Cannot use an index to create the index"));
16959 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
16960 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16962 if (stat (objfile->name, &st) < 0)
16963 perror_with_name (objfile->name);
16965 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
16966 INDEX_SUFFIX, (char *) NULL);
16967 cleanup = make_cleanup (xfree, filename);
16969 out_file = fopen (filename, "wb");
16971 error (_("Can't open `%s' for writing"), filename);
16973 cleanup_filename = filename;
16974 make_cleanup (unlink_if_set, &cleanup_filename);
16976 symtab = create_mapped_symtab ();
16977 make_cleanup (cleanup_mapped_symtab, symtab);
16979 obstack_init (&addr_obstack);
16980 make_cleanup_obstack_free (&addr_obstack);
16982 obstack_init (&cu_list);
16983 make_cleanup_obstack_free (&cu_list);
16985 obstack_init (&types_cu_list);
16986 make_cleanup_obstack_free (&types_cu_list);
16988 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16989 NULL, xcalloc, xfree);
16990 make_cleanup_htab_delete (psyms_seen);
16992 /* While we're scanning CU's create a table that maps a psymtab pointer
16993 (which is what addrmap records) to its index (which is what is recorded
16994 in the index file). This will later be needed to write the address
16996 cu_index_htab = htab_create_alloc (100,
16997 hash_psymtab_cu_index,
16998 eq_psymtab_cu_index,
16999 NULL, xcalloc, xfree);
17000 make_cleanup_htab_delete (cu_index_htab);
17001 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
17002 xmalloc (sizeof (struct psymtab_cu_index_map)
17003 * dwarf2_per_objfile->n_comp_units);
17004 make_cleanup (xfree, psymtab_cu_index_map);
17006 /* The CU list is already sorted, so we don't need to do additional
17007 work here. Also, the debug_types entries do not appear in
17008 all_comp_units, but only in their own hash table. */
17009 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
17011 struct dwarf2_per_cu_data *per_cu
17012 = dwarf2_per_objfile->all_comp_units[i];
17013 struct partial_symtab *psymtab = per_cu->v.psymtab;
17015 struct psymtab_cu_index_map *map;
17018 write_psymbols (symtab,
17020 objfile->global_psymbols.list + psymtab->globals_offset,
17021 psymtab->n_global_syms, i,
17023 write_psymbols (symtab,
17025 objfile->static_psymbols.list + psymtab->statics_offset,
17026 psymtab->n_static_syms, i,
17029 map = &psymtab_cu_index_map[i];
17030 map->psymtab = psymtab;
17032 slot = htab_find_slot (cu_index_htab, map, INSERT);
17033 gdb_assert (slot != NULL);
17034 gdb_assert (*slot == NULL);
17037 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
17038 obstack_grow (&cu_list, val, 8);
17039 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
17040 obstack_grow (&cu_list, val, 8);
17043 /* Dump the address map. */
17044 write_address_map (objfile, &addr_obstack, cu_index_htab);
17046 /* Write out the .debug_type entries, if any. */
17047 if (dwarf2_per_objfile->signatured_types)
17049 struct signatured_type_index_data sig_data;
17051 sig_data.objfile = objfile;
17052 sig_data.symtab = symtab;
17053 sig_data.types_list = &types_cu_list;
17054 sig_data.psyms_seen = psyms_seen;
17055 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
17056 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
17057 write_one_signatured_type, &sig_data);
17060 obstack_init (&constant_pool);
17061 make_cleanup_obstack_free (&constant_pool);
17062 obstack_init (&symtab_obstack);
17063 make_cleanup_obstack_free (&symtab_obstack);
17064 write_hash_table (symtab, &symtab_obstack, &constant_pool);
17066 obstack_init (&contents);
17067 make_cleanup_obstack_free (&contents);
17068 size_of_contents = 6 * sizeof (offset_type);
17069 total_len = size_of_contents;
17071 /* The version number. */
17072 val = MAYBE_SWAP (6);
17073 obstack_grow (&contents, &val, sizeof (val));
17075 /* The offset of the CU list from the start of the file. */
17076 val = MAYBE_SWAP (total_len);
17077 obstack_grow (&contents, &val, sizeof (val));
17078 total_len += obstack_object_size (&cu_list);
17080 /* The offset of the types CU list from the start of the file. */
17081 val = MAYBE_SWAP (total_len);
17082 obstack_grow (&contents, &val, sizeof (val));
17083 total_len += obstack_object_size (&types_cu_list);
17085 /* The offset of the address table from the start of the file. */
17086 val = MAYBE_SWAP (total_len);
17087 obstack_grow (&contents, &val, sizeof (val));
17088 total_len += obstack_object_size (&addr_obstack);
17090 /* The offset of the symbol table from the start of the file. */
17091 val = MAYBE_SWAP (total_len);
17092 obstack_grow (&contents, &val, sizeof (val));
17093 total_len += obstack_object_size (&symtab_obstack);
17095 /* The offset of the constant pool from the start of the file. */
17096 val = MAYBE_SWAP (total_len);
17097 obstack_grow (&contents, &val, sizeof (val));
17098 total_len += obstack_object_size (&constant_pool);
17100 gdb_assert (obstack_object_size (&contents) == size_of_contents);
17102 write_obstack (out_file, &contents);
17103 write_obstack (out_file, &cu_list);
17104 write_obstack (out_file, &types_cu_list);
17105 write_obstack (out_file, &addr_obstack);
17106 write_obstack (out_file, &symtab_obstack);
17107 write_obstack (out_file, &constant_pool);
17111 /* We want to keep the file, so we set cleanup_filename to NULL
17112 here. See unlink_if_set. */
17113 cleanup_filename = NULL;
17115 do_cleanups (cleanup);
17118 /* Implementation of the `save gdb-index' command.
17120 Note that the file format used by this command is documented in the
17121 GDB manual. Any changes here must be documented there. */
17124 save_gdb_index_command (char *arg, int from_tty)
17126 struct objfile *objfile;
17129 error (_("usage: save gdb-index DIRECTORY"));
17131 ALL_OBJFILES (objfile)
17135 /* If the objfile does not correspond to an actual file, skip it. */
17136 if (stat (objfile->name, &st) < 0)
17139 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
17140 if (dwarf2_per_objfile)
17142 volatile struct gdb_exception except;
17144 TRY_CATCH (except, RETURN_MASK_ERROR)
17146 write_psymtabs_to_index (objfile, arg);
17148 if (except.reason < 0)
17149 exception_fprintf (gdb_stderr, except,
17150 _("Error while writing index for `%s': "),
17158 int dwarf2_always_disassemble;
17161 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
17162 struct cmd_list_element *c, const char *value)
17164 fprintf_filtered (file,
17165 _("Whether to always disassemble "
17166 "DWARF expressions is %s.\n"),
17171 show_check_physname (struct ui_file *file, int from_tty,
17172 struct cmd_list_element *c, const char *value)
17174 fprintf_filtered (file,
17175 _("Whether to check \"physname\" is %s.\n"),
17179 void _initialize_dwarf2_read (void);
17182 _initialize_dwarf2_read (void)
17184 struct cmd_list_element *c;
17186 dwarf2_objfile_data_key
17187 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
17189 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
17190 Set DWARF 2 specific variables.\n\
17191 Configure DWARF 2 variables such as the cache size"),
17192 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
17193 0/*allow-unknown*/, &maintenance_set_cmdlist);
17195 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
17196 Show DWARF 2 specific variables\n\
17197 Show DWARF 2 variables such as the cache size"),
17198 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
17199 0/*allow-unknown*/, &maintenance_show_cmdlist);
17201 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
17202 &dwarf2_max_cache_age, _("\
17203 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17204 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17205 A higher limit means that cached compilation units will be stored\n\
17206 in memory longer, and more total memory will be used. Zero disables\n\
17207 caching, which can slow down startup."),
17209 show_dwarf2_max_cache_age,
17210 &set_dwarf2_cmdlist,
17211 &show_dwarf2_cmdlist);
17213 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
17214 &dwarf2_always_disassemble, _("\
17215 Set whether `info address' always disassembles DWARF expressions."), _("\
17216 Show whether `info address' always disassembles DWARF expressions."), _("\
17217 When enabled, DWARF expressions are always printed in an assembly-like\n\
17218 syntax. When disabled, expressions will be printed in a more\n\
17219 conversational style, when possible."),
17221 show_dwarf2_always_disassemble,
17222 &set_dwarf2_cmdlist,
17223 &show_dwarf2_cmdlist);
17225 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
17226 Set debugging of the dwarf2 DIE reader."), _("\
17227 Show debugging of the dwarf2 DIE reader."), _("\
17228 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17229 The value is the maximum depth to print."),
17232 &setdebuglist, &showdebuglist);
17234 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
17235 Set cross-checking of \"physname\" code against demangler."), _("\
17236 Show cross-checking of \"physname\" code against demangler."), _("\
17237 When enabled, GDB's internal \"physname\" code is checked against\n\
17239 NULL, show_check_physname,
17240 &setdebuglist, &showdebuglist);
17242 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
17244 Save a gdb-index file.\n\
17245 Usage: save gdb-index DIRECTORY"),
17247 set_cmd_completer (c, filename_completer);