1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol *symbolp;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length; /* length of the .debug_info
87 unsigned short version; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
90 unsigned char addr_size; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length; /* byte length of the statement
103 unsigned short version; /* version number -- 2 for DWARF
105 unsigned int prologue_length; /* # bytes between prologue &
107 unsigned char minimum_instruction_length; /* byte size of
109 unsigned char default_is_stmt; /* initial value of is_stmt
112 unsigned char line_range;
113 unsigned char opcode_base; /* number assigned to first special
115 unsigned char *standard_opcode_lengths;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug = 0;
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname = 0;
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
131 static int processing_has_namespace_info;
133 static const struct objfile_data *dwarf2_objfile_data_key;
135 struct dwarf2_section_info
141 /* True if we have tried to read this section. */
145 /* All offsets in the index are of this type. It must be
146 architecture-independent. */
147 typedef uint32_t offset_type;
149 DEF_VEC_I (offset_type);
151 /* A description of the mapped index. The file format is described in
152 a comment by the code that writes the index. */
155 /* The total length of the buffer. */
157 /* A pointer to the address table data. */
158 const gdb_byte *address_table;
159 /* Size of the address table data in bytes. */
160 offset_type address_table_size;
161 /* The symbol table, implemented as a hash table. */
162 const offset_type *symbol_table;
163 /* Size in slots, each slot is 2 offset_types. */
164 offset_type symbol_table_slots;
165 /* A pointer to the constant pool. */
166 const char *constant_pool;
169 struct dwarf2_per_objfile
171 struct dwarf2_section_info info;
172 struct dwarf2_section_info abbrev;
173 struct dwarf2_section_info line;
174 struct dwarf2_section_info loc;
175 struct dwarf2_section_info macinfo;
176 struct dwarf2_section_info str;
177 struct dwarf2_section_info ranges;
178 struct dwarf2_section_info types;
179 struct dwarf2_section_info frame;
180 struct dwarf2_section_info eh_frame;
181 struct dwarf2_section_info gdb_index;
184 struct objfile *objfile;
186 /* A list of all the compilation units. This is used to locate
187 the target compilation unit of a particular reference. */
188 struct dwarf2_per_cu_data **all_comp_units;
190 /* The number of compilation units in ALL_COMP_UNITS. */
193 /* The number of .debug_types-related CUs. */
194 int n_type_comp_units;
196 /* The .debug_types-related CUs. */
197 struct dwarf2_per_cu_data **type_comp_units;
199 /* A chain of compilation units that are currently read in, so that
200 they can be freed later. */
201 struct dwarf2_per_cu_data *read_in_chain;
203 /* A table mapping .debug_types signatures to its signatured_type entry.
204 This is NULL if the .debug_types section hasn't been read in yet. */
205 htab_t signatured_types;
207 /* A flag indicating wether this objfile has a section loaded at a
209 int has_section_at_zero;
211 /* True if we are using the mapped index,
212 or we are faking it for OBJF_READNOW's sake. */
213 unsigned char using_index;
215 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
216 struct mapped_index *index_table;
218 /* When using index_table, this keeps track of all quick_file_names entries.
219 TUs can share line table entries with CUs or other TUs, and there can be
220 a lot more TUs than unique line tables, so we maintain a separate table
221 of all line table entries to support the sharing. */
222 htab_t quick_file_names_table;
224 /* Set during partial symbol reading, to prevent queueing of full
226 int reading_partial_symbols;
228 /* Table mapping type .debug_info DIE offsets to types.
229 This is NULL if not allocated yet.
230 It (currently) makes sense to allocate debug_types_type_hash lazily.
231 To keep things simple we allocate both lazily. */
232 htab_t debug_info_type_hash;
234 /* Table mapping type .debug_types DIE offsets to types.
235 This is NULL if not allocated yet. */
236 htab_t debug_types_type_hash;
239 static struct dwarf2_per_objfile *dwarf2_per_objfile;
241 /* names of the debugging sections */
243 /* Note that if the debugging section has been compressed, it might
244 have a name like .zdebug_info. */
246 #define INFO_SECTION "debug_info"
247 #define ABBREV_SECTION "debug_abbrev"
248 #define LINE_SECTION "debug_line"
249 #define LOC_SECTION "debug_loc"
250 #define MACINFO_SECTION "debug_macinfo"
251 #define STR_SECTION "debug_str"
252 #define RANGES_SECTION "debug_ranges"
253 #define TYPES_SECTION "debug_types"
254 #define FRAME_SECTION "debug_frame"
255 #define EH_FRAME_SECTION "eh_frame"
256 #define GDB_INDEX_SECTION "gdb_index"
258 /* local data types */
260 /* We hold several abbreviation tables in memory at the same time. */
261 #ifndef ABBREV_HASH_SIZE
262 #define ABBREV_HASH_SIZE 121
265 /* The data in a compilation unit header, after target2host
266 translation, looks like this. */
267 struct comp_unit_head
271 unsigned char addr_size;
272 unsigned char signed_addr_p;
273 unsigned int abbrev_offset;
275 /* Size of file offsets; either 4 or 8. */
276 unsigned int offset_size;
278 /* Size of the length field; either 4 or 12. */
279 unsigned int initial_length_size;
281 /* Offset to the first byte of this compilation unit header in the
282 .debug_info section, for resolving relative reference dies. */
285 /* Offset to first die in this cu from the start of the cu.
286 This will be the first byte following the compilation unit header. */
287 unsigned int first_die_offset;
290 /* Type used for delaying computation of method physnames.
291 See comments for compute_delayed_physnames. */
292 struct delayed_method_info
294 /* The type to which the method is attached, i.e., its parent class. */
297 /* The index of the method in the type's function fieldlists. */
300 /* The index of the method in the fieldlist. */
303 /* The name of the DIE. */
306 /* The DIE associated with this method. */
307 struct die_info *die;
310 typedef struct delayed_method_info delayed_method_info;
311 DEF_VEC_O (delayed_method_info);
313 /* Internal state when decoding a particular compilation unit. */
316 /* The objfile containing this compilation unit. */
317 struct objfile *objfile;
319 /* The header of the compilation unit. */
320 struct comp_unit_head header;
322 /* Base address of this compilation unit. */
323 CORE_ADDR base_address;
325 /* Non-zero if base_address has been set. */
328 struct function_range *first_fn, *last_fn, *cached_fn;
330 /* The language we are debugging. */
331 enum language language;
332 const struct language_defn *language_defn;
334 const char *producer;
336 /* The generic symbol table building routines have separate lists for
337 file scope symbols and all all other scopes (local scopes). So
338 we need to select the right one to pass to add_symbol_to_list().
339 We do it by keeping a pointer to the correct list in list_in_scope.
341 FIXME: The original dwarf code just treated the file scope as the
342 first local scope, and all other local scopes as nested local
343 scopes, and worked fine. Check to see if we really need to
344 distinguish these in buildsym.c. */
345 struct pending **list_in_scope;
347 /* DWARF abbreviation table associated with this compilation unit. */
348 struct abbrev_info **dwarf2_abbrevs;
350 /* Storage for the abbrev table. */
351 struct obstack abbrev_obstack;
353 /* Hash table holding all the loaded partial DIEs. */
356 /* Storage for things with the same lifetime as this read-in compilation
357 unit, including partial DIEs. */
358 struct obstack comp_unit_obstack;
360 /* When multiple dwarf2_cu structures are living in memory, this field
361 chains them all together, so that they can be released efficiently.
362 We will probably also want a generation counter so that most-recently-used
363 compilation units are cached... */
364 struct dwarf2_per_cu_data *read_in_chain;
366 /* Backchain to our per_cu entry if the tree has been built. */
367 struct dwarf2_per_cu_data *per_cu;
369 /* How many compilation units ago was this CU last referenced? */
372 /* A hash table of die offsets for following references. */
375 /* Full DIEs if read in. */
376 struct die_info *dies;
378 /* A set of pointers to dwarf2_per_cu_data objects for compilation
379 units referenced by this one. Only set during full symbol processing;
380 partial symbol tables do not have dependencies. */
383 /* Header data from the line table, during full symbol processing. */
384 struct line_header *line_header;
386 /* A list of methods which need to have physnames computed
387 after all type information has been read. */
388 VEC (delayed_method_info) *method_list;
390 /* Mark used when releasing cached dies. */
391 unsigned int mark : 1;
393 /* This flag will be set if this compilation unit might include
394 inter-compilation-unit references. */
395 unsigned int has_form_ref_addr : 1;
397 /* This flag will be set if this compilation unit includes any
398 DW_TAG_namespace DIEs. If we know that there are explicit
399 DIEs for namespaces, we don't need to try to infer them
400 from mangled names. */
401 unsigned int has_namespace_info : 1;
403 /* This CU references .debug_loc. See the symtab->locations_valid field.
404 This test is imperfect as there may exist optimized debug code not using
405 any location list and still facing inlining issues if handled as
406 unoptimized code. For a future better test see GCC PR other/32998. */
408 unsigned int has_loclist : 1;
411 /* Persistent data held for a compilation unit, even when not
412 processing it. We put a pointer to this structure in the
413 read_symtab_private field of the psymtab. If we encounter
414 inter-compilation-unit references, we also maintain a sorted
415 list of all compilation units. */
417 struct dwarf2_per_cu_data
419 /* The start offset and length of this compilation unit. 2**29-1
420 bytes should suffice to store the length of any compilation unit
421 - if it doesn't, GDB will fall over anyway.
422 NOTE: Unlike comp_unit_head.length, this length includes
423 initial_length_size. */
425 unsigned int length : 29;
427 /* Flag indicating this compilation unit will be read in before
428 any of the current compilation units are processed. */
429 unsigned int queued : 1;
431 /* This flag will be set if we need to load absolutely all DIEs
432 for this compilation unit, instead of just the ones we think
433 are interesting. It gets set if we look for a DIE in the
434 hash table and don't find it. */
435 unsigned int load_all_dies : 1;
437 /* Non-zero if this CU is from .debug_types.
438 Otherwise it's from .debug_info. */
439 unsigned int from_debug_types : 1;
441 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
442 of the CU cache it gets reset to NULL again. */
443 struct dwarf2_cu *cu;
445 /* The corresponding objfile. */
446 struct objfile *objfile;
448 /* When using partial symbol tables, the 'psymtab' field is active.
449 Otherwise the 'quick' field is active. */
452 /* The partial symbol table associated with this compilation unit,
453 or NULL for partial units (which do not have an associated
455 struct partial_symtab *psymtab;
457 /* Data needed by the "quick" functions. */
458 struct dwarf2_per_cu_quick_data *quick;
462 /* Entry in the signatured_types hash table. */
464 struct signatured_type
468 /* Offset in .debug_types of the TU (type_unit) for this type. */
471 /* Offset in .debug_types of the type defined by this TU. */
472 unsigned int type_offset;
474 /* The CU(/TU) of this type. */
475 struct dwarf2_per_cu_data per_cu;
478 /* Struct used to pass misc. parameters to read_die_and_children, et
479 al. which are used for both .debug_info and .debug_types dies.
480 All parameters here are unchanging for the life of the call. This
481 struct exists to abstract away the constant parameters of die
484 struct die_reader_specs
486 /* The bfd of this objfile. */
489 /* The CU of the DIE we are parsing. */
490 struct dwarf2_cu *cu;
492 /* Pointer to start of section buffer.
493 This is either the start of .debug_info or .debug_types. */
494 const gdb_byte *buffer;
497 /* The line number information for a compilation unit (found in the
498 .debug_line section) begins with a "statement program header",
499 which contains the following information. */
502 unsigned int total_length;
503 unsigned short version;
504 unsigned int header_length;
505 unsigned char minimum_instruction_length;
506 unsigned char maximum_ops_per_instruction;
507 unsigned char default_is_stmt;
509 unsigned char line_range;
510 unsigned char opcode_base;
512 /* standard_opcode_lengths[i] is the number of operands for the
513 standard opcode whose value is i. This means that
514 standard_opcode_lengths[0] is unused, and the last meaningful
515 element is standard_opcode_lengths[opcode_base - 1]. */
516 unsigned char *standard_opcode_lengths;
518 /* The include_directories table. NOTE! These strings are not
519 allocated with xmalloc; instead, they are pointers into
520 debug_line_buffer. If you try to free them, `free' will get
522 unsigned int num_include_dirs, include_dirs_size;
525 /* The file_names table. NOTE! These strings are not allocated
526 with xmalloc; instead, they are pointers into debug_line_buffer.
527 Don't try to free them directly. */
528 unsigned int num_file_names, file_names_size;
532 unsigned int dir_index;
533 unsigned int mod_time;
535 int included_p; /* Non-zero if referenced by the Line Number Program. */
536 struct symtab *symtab; /* The associated symbol table, if any. */
539 /* The start and end of the statement program following this
540 header. These point into dwarf2_per_objfile->line_buffer. */
541 gdb_byte *statement_program_start, *statement_program_end;
544 /* When we construct a partial symbol table entry we only
545 need this much information. */
546 struct partial_die_info
548 /* Offset of this DIE. */
551 /* DWARF-2 tag for this DIE. */
552 ENUM_BITFIELD(dwarf_tag) tag : 16;
554 /* Assorted flags describing the data found in this DIE. */
555 unsigned int has_children : 1;
556 unsigned int is_external : 1;
557 unsigned int is_declaration : 1;
558 unsigned int has_type : 1;
559 unsigned int has_specification : 1;
560 unsigned int has_pc_info : 1;
562 /* Flag set if the SCOPE field of this structure has been
564 unsigned int scope_set : 1;
566 /* Flag set if the DIE has a byte_size attribute. */
567 unsigned int has_byte_size : 1;
569 /* Flag set if any of the DIE's children are template arguments. */
570 unsigned int has_template_arguments : 1;
572 /* Flag set if fixup_partial_die has been called on this die. */
573 unsigned int fixup_called : 1;
575 /* The name of this DIE. Normally the value of DW_AT_name, but
576 sometimes a default name for unnamed DIEs. */
579 /* The linkage name, if present. */
580 const char *linkage_name;
582 /* The scope to prepend to our children. This is generally
583 allocated on the comp_unit_obstack, so will disappear
584 when this compilation unit leaves the cache. */
587 /* The location description associated with this DIE, if any. */
588 struct dwarf_block *locdesc;
590 /* If HAS_PC_INFO, the PC range associated with this DIE. */
594 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
595 DW_AT_sibling, if any. */
596 /* NOTE: This member isn't strictly necessary, read_partial_die could
597 return DW_AT_sibling values to its caller load_partial_dies. */
600 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
601 DW_AT_specification (or DW_AT_abstract_origin or
603 unsigned int spec_offset;
605 /* Pointers to this DIE's parent, first child, and next sibling,
607 struct partial_die_info *die_parent, *die_child, *die_sibling;
610 /* This data structure holds the information of an abbrev. */
613 unsigned int number; /* number identifying abbrev */
614 enum dwarf_tag tag; /* dwarf tag */
615 unsigned short has_children; /* boolean */
616 unsigned short num_attrs; /* number of attributes */
617 struct attr_abbrev *attrs; /* an array of attribute descriptions */
618 struct abbrev_info *next; /* next in chain */
623 ENUM_BITFIELD(dwarf_attribute) name : 16;
624 ENUM_BITFIELD(dwarf_form) form : 16;
627 /* Attributes have a name and a value. */
630 ENUM_BITFIELD(dwarf_attribute) name : 16;
631 ENUM_BITFIELD(dwarf_form) form : 15;
633 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
634 field should be in u.str (existing only for DW_STRING) but it is kept
635 here for better struct attribute alignment. */
636 unsigned int string_is_canonical : 1;
641 struct dwarf_block *blk;
645 struct signatured_type *signatured_type;
650 /* This data structure holds a complete die structure. */
653 /* DWARF-2 tag for this DIE. */
654 ENUM_BITFIELD(dwarf_tag) tag : 16;
656 /* Number of attributes */
657 unsigned char num_attrs;
659 /* True if we're presently building the full type name for the
660 type derived from this DIE. */
661 unsigned char building_fullname : 1;
666 /* Offset in .debug_info or .debug_types section. */
669 /* The dies in a compilation unit form an n-ary tree. PARENT
670 points to this die's parent; CHILD points to the first child of
671 this node; and all the children of a given node are chained
672 together via their SIBLING fields. */
673 struct die_info *child; /* Its first child, if any. */
674 struct die_info *sibling; /* Its next sibling, if any. */
675 struct die_info *parent; /* Its parent, if any. */
677 /* An array of attributes, with NUM_ATTRS elements. There may be
678 zero, but it's not common and zero-sized arrays are not
679 sufficiently portable C. */
680 struct attribute attrs[1];
683 struct function_range
686 CORE_ADDR lowpc, highpc;
688 struct function_range *next;
691 /* Get at parts of an attribute structure. */
693 #define DW_STRING(attr) ((attr)->u.str)
694 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
695 #define DW_UNSND(attr) ((attr)->u.unsnd)
696 #define DW_BLOCK(attr) ((attr)->u.blk)
697 #define DW_SND(attr) ((attr)->u.snd)
698 #define DW_ADDR(attr) ((attr)->u.addr)
699 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
701 /* Blocks are a bunch of untyped bytes. */
708 #ifndef ATTR_ALLOC_CHUNK
709 #define ATTR_ALLOC_CHUNK 4
712 /* Allocate fields for structs, unions and enums in this size. */
713 #ifndef DW_FIELD_ALLOC_CHUNK
714 #define DW_FIELD_ALLOC_CHUNK 4
717 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
718 but this would require a corresponding change in unpack_field_as_long
720 static int bits_per_byte = 8;
722 /* The routines that read and process dies for a C struct or C++ class
723 pass lists of data member fields and lists of member function fields
724 in an instance of a field_info structure, as defined below. */
727 /* List of data member and baseclasses fields. */
730 struct nextfield *next;
735 *fields, *baseclasses;
737 /* Number of fields (including baseclasses). */
740 /* Number of baseclasses. */
743 /* Set if the accesibility of one of the fields is not public. */
744 int non_public_fields;
746 /* Member function fields array, entries are allocated in the order they
747 are encountered in the object file. */
750 struct nextfnfield *next;
751 struct fn_field fnfield;
755 /* Member function fieldlist array, contains name of possibly overloaded
756 member function, number of overloaded member functions and a pointer
757 to the head of the member function field chain. */
762 struct nextfnfield *head;
766 /* Number of entries in the fnfieldlists array. */
769 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
770 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
771 struct typedef_field_list
773 struct typedef_field field;
774 struct typedef_field_list *next;
777 unsigned typedef_field_list_count;
780 /* One item on the queue of compilation units to read in full symbols
782 struct dwarf2_queue_item
784 struct dwarf2_per_cu_data *per_cu;
785 struct dwarf2_queue_item *next;
788 /* The current queue. */
789 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
791 /* Loaded secondary compilation units are kept in memory until they
792 have not been referenced for the processing of this many
793 compilation units. Set this to zero to disable caching. Cache
794 sizes of up to at least twenty will improve startup time for
795 typical inter-CU-reference binaries, at an obvious memory cost. */
796 static int dwarf2_max_cache_age = 5;
798 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
799 struct cmd_list_element *c, const char *value)
801 fprintf_filtered (file, _("The upper bound on the age of cached "
802 "dwarf2 compilation units is %s.\n"),
807 /* Various complaints about symbol reading that don't abort the process. */
810 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
812 complaint (&symfile_complaints,
813 _("statement list doesn't fit in .debug_line section"));
817 dwarf2_debug_line_missing_file_complaint (void)
819 complaint (&symfile_complaints,
820 _(".debug_line section has line data without a file"));
824 dwarf2_debug_line_missing_end_sequence_complaint (void)
826 complaint (&symfile_complaints,
827 _(".debug_line section has line "
828 "program sequence without an end"));
832 dwarf2_complex_location_expr_complaint (void)
834 complaint (&symfile_complaints, _("location expression too complex"));
838 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
841 complaint (&symfile_complaints,
842 _("const value length mismatch for '%s', got %d, expected %d"),
847 dwarf2_macros_too_long_complaint (void)
849 complaint (&symfile_complaints,
850 _("macro info runs off end of `.debug_macinfo' section"));
854 dwarf2_macro_malformed_definition_complaint (const char *arg1)
856 complaint (&symfile_complaints,
857 _("macro debug info contains a "
858 "malformed macro definition:\n`%s'"),
863 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
865 complaint (&symfile_complaints,
866 _("invalid attribute class or form for '%s' in '%s'"),
870 /* local function prototypes */
872 static void dwarf2_locate_sections (bfd *, asection *, void *);
874 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
877 static void dwarf2_build_psymtabs_hard (struct objfile *);
879 static void scan_partial_symbols (struct partial_die_info *,
880 CORE_ADDR *, CORE_ADDR *,
881 int, struct dwarf2_cu *);
883 static void add_partial_symbol (struct partial_die_info *,
886 static void add_partial_namespace (struct partial_die_info *pdi,
887 CORE_ADDR *lowpc, CORE_ADDR *highpc,
888 int need_pc, struct dwarf2_cu *cu);
890 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
891 CORE_ADDR *highpc, int need_pc,
892 struct dwarf2_cu *cu);
894 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
895 struct dwarf2_cu *cu);
897 static void add_partial_subprogram (struct partial_die_info *pdi,
898 CORE_ADDR *lowpc, CORE_ADDR *highpc,
899 int need_pc, struct dwarf2_cu *cu);
901 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
902 gdb_byte *buffer, gdb_byte *info_ptr,
903 bfd *abfd, struct dwarf2_cu *cu);
905 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
907 static void psymtab_to_symtab_1 (struct partial_symtab *);
909 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
911 static void dwarf2_free_abbrev_table (void *);
913 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
916 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
919 static struct partial_die_info *load_partial_dies (bfd *,
920 gdb_byte *, gdb_byte *,
921 int, struct dwarf2_cu *);
923 static gdb_byte *read_partial_die (struct partial_die_info *,
924 struct abbrev_info *abbrev,
926 gdb_byte *, gdb_byte *,
929 static struct partial_die_info *find_partial_die (unsigned int,
932 static void fixup_partial_die (struct partial_die_info *,
935 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
936 bfd *, gdb_byte *, struct dwarf2_cu *);
938 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
939 bfd *, gdb_byte *, struct dwarf2_cu *);
941 static unsigned int read_1_byte (bfd *, gdb_byte *);
943 static int read_1_signed_byte (bfd *, gdb_byte *);
945 static unsigned int read_2_bytes (bfd *, gdb_byte *);
947 static unsigned int read_4_bytes (bfd *, gdb_byte *);
949 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
951 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
954 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
956 static LONGEST read_checked_initial_length_and_offset
957 (bfd *, gdb_byte *, const struct comp_unit_head *,
958 unsigned int *, unsigned int *);
960 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
963 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
965 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
967 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
969 static char *read_indirect_string (bfd *, gdb_byte *,
970 const struct comp_unit_head *,
973 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
975 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
977 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
979 static void set_cu_language (unsigned int, struct dwarf2_cu *);
981 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
984 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
988 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
989 struct dwarf2_cu *cu);
991 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
993 static struct die_info *die_specification (struct die_info *die,
994 struct dwarf2_cu **);
996 static void free_line_header (struct line_header *lh);
998 static void add_file_name (struct line_header *, char *, unsigned int,
999 unsigned int, unsigned int);
1001 static struct line_header *(dwarf_decode_line_header
1002 (unsigned int offset,
1003 bfd *abfd, struct dwarf2_cu *cu));
1005 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
1006 struct dwarf2_cu *, struct partial_symtab *);
1008 static void dwarf2_start_subfile (char *, const char *, const char *);
1010 static struct symbol *new_symbol (struct die_info *, struct type *,
1011 struct dwarf2_cu *);
1013 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1014 struct dwarf2_cu *, struct symbol *);
1016 static void dwarf2_const_value (struct attribute *, struct symbol *,
1017 struct dwarf2_cu *);
1019 static void dwarf2_const_value_attr (struct attribute *attr,
1022 struct obstack *obstack,
1023 struct dwarf2_cu *cu, long *value,
1025 struct dwarf2_locexpr_baton **baton);
1027 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1029 static int need_gnat_info (struct dwarf2_cu *);
1031 static struct type *die_descriptive_type (struct die_info *,
1032 struct dwarf2_cu *);
1034 static void set_descriptive_type (struct type *, struct die_info *,
1035 struct dwarf2_cu *);
1037 static struct type *die_containing_type (struct die_info *,
1038 struct dwarf2_cu *);
1040 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1041 struct dwarf2_cu *);
1043 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1045 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1047 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1049 static char *typename_concat (struct obstack *obs, const char *prefix,
1050 const char *suffix, int physname,
1051 struct dwarf2_cu *cu);
1053 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1055 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1057 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1059 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1061 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1062 struct dwarf2_cu *, struct partial_symtab *);
1064 static int dwarf2_get_pc_bounds (struct die_info *,
1065 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1066 struct partial_symtab *);
1068 static void get_scope_pc_bounds (struct die_info *,
1069 CORE_ADDR *, CORE_ADDR *,
1070 struct dwarf2_cu *);
1072 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1073 CORE_ADDR, struct dwarf2_cu *);
1075 static void dwarf2_add_field (struct field_info *, struct die_info *,
1076 struct dwarf2_cu *);
1078 static void dwarf2_attach_fields_to_type (struct field_info *,
1079 struct type *, struct dwarf2_cu *);
1081 static void dwarf2_add_member_fn (struct field_info *,
1082 struct die_info *, struct type *,
1083 struct dwarf2_cu *);
1085 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1087 struct dwarf2_cu *);
1089 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1091 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1093 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1095 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1097 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1099 static struct type *read_module_type (struct die_info *die,
1100 struct dwarf2_cu *cu);
1102 static const char *namespace_name (struct die_info *die,
1103 int *is_anonymous, struct dwarf2_cu *);
1105 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1107 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1109 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1110 struct dwarf2_cu *);
1112 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1114 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1116 gdb_byte **new_info_ptr,
1117 struct die_info *parent);
1119 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1121 gdb_byte **new_info_ptr,
1122 struct die_info *parent);
1124 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1126 gdb_byte **new_info_ptr,
1127 struct die_info *parent);
1129 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1130 struct die_info **, gdb_byte *,
1133 static void process_die (struct die_info *, struct dwarf2_cu *);
1135 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1138 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1140 static const char *dwarf2_full_name (char *name,
1141 struct die_info *die,
1142 struct dwarf2_cu *cu);
1144 static struct die_info *dwarf2_extension (struct die_info *die,
1145 struct dwarf2_cu **);
1147 static char *dwarf_tag_name (unsigned int);
1149 static char *dwarf_attr_name (unsigned int);
1151 static char *dwarf_form_name (unsigned int);
1153 static char *dwarf_bool_name (unsigned int);
1155 static char *dwarf_type_encoding_name (unsigned int);
1158 static char *dwarf_cfi_name (unsigned int);
1161 static struct die_info *sibling_die (struct die_info *);
1163 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1165 static void dump_die_for_error (struct die_info *);
1167 static void dump_die_1 (struct ui_file *, int level, int max_level,
1170 /*static*/ void dump_die (struct die_info *, int max_level);
1172 static void store_in_ref_table (struct die_info *,
1173 struct dwarf2_cu *);
1175 static int is_ref_attr (struct attribute *);
1177 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1179 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1181 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1183 struct dwarf2_cu **);
1185 static struct die_info *follow_die_ref (struct die_info *,
1187 struct dwarf2_cu **);
1189 static struct die_info *follow_die_sig (struct die_info *,
1191 struct dwarf2_cu **);
1193 static void read_signatured_type_at_offset (struct objfile *objfile,
1194 unsigned int offset);
1196 static void read_signatured_type (struct objfile *,
1197 struct signatured_type *type_sig);
1199 /* memory allocation interface */
1201 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1203 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1205 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1207 static void initialize_cu_func_list (struct dwarf2_cu *);
1209 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1210 struct dwarf2_cu *);
1212 static void dwarf_decode_macros (struct line_header *, unsigned int,
1213 char *, bfd *, struct dwarf2_cu *);
1215 static int attr_form_is_block (struct attribute *);
1217 static int attr_form_is_section_offset (struct attribute *);
1219 static int attr_form_is_constant (struct attribute *);
1221 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1222 struct dwarf2_loclist_baton *baton,
1223 struct attribute *attr);
1225 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1227 struct dwarf2_cu *cu);
1229 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1230 struct abbrev_info *abbrev,
1231 struct dwarf2_cu *cu);
1233 static void free_stack_comp_unit (void *);
1235 static hashval_t partial_die_hash (const void *item);
1237 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1239 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1240 (unsigned int offset, struct objfile *objfile);
1242 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1243 (unsigned int offset, struct objfile *objfile);
1245 static void init_one_comp_unit (struct dwarf2_cu *cu,
1246 struct objfile *objfile);
1248 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1249 struct die_info *comp_unit_die);
1251 static void free_one_comp_unit (void *);
1253 static void free_cached_comp_units (void *);
1255 static void age_cached_comp_units (void);
1257 static void free_one_cached_comp_unit (void *);
1259 static struct type *set_die_type (struct die_info *, struct type *,
1260 struct dwarf2_cu *);
1262 static void create_all_comp_units (struct objfile *);
1264 static int create_debug_types_hash_table (struct objfile *objfile);
1266 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1269 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1271 static void dwarf2_add_dependence (struct dwarf2_cu *,
1272 struct dwarf2_per_cu_data *);
1274 static void dwarf2_mark (struct dwarf2_cu *);
1276 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1278 static struct type *get_die_type_at_offset (unsigned int,
1279 struct dwarf2_per_cu_data *per_cu);
1281 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1283 static void dwarf2_release_queue (void *dummy);
1285 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1286 struct objfile *objfile);
1288 static void process_queue (struct objfile *objfile);
1290 static void find_file_and_directory (struct die_info *die,
1291 struct dwarf2_cu *cu,
1292 char **name, char **comp_dir);
1294 static char *file_full_name (int file, struct line_header *lh,
1295 const char *comp_dir);
1297 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1300 unsigned int buffer_size,
1303 static void init_cu_die_reader (struct die_reader_specs *reader,
1304 struct dwarf2_cu *cu);
1306 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1310 /* Convert VALUE between big- and little-endian. */
1312 byte_swap (offset_type value)
1316 result = (value & 0xff) << 24;
1317 result |= (value & 0xff00) << 8;
1318 result |= (value & 0xff0000) >> 8;
1319 result |= (value & 0xff000000) >> 24;
1323 #define MAYBE_SWAP(V) byte_swap (V)
1326 #define MAYBE_SWAP(V) (V)
1327 #endif /* WORDS_BIGENDIAN */
1329 /* The suffix for an index file. */
1330 #define INDEX_SUFFIX ".gdb-index"
1332 static const char *dwarf2_physname (char *name, struct die_info *die,
1333 struct dwarf2_cu *cu);
1335 /* Try to locate the sections we need for DWARF 2 debugging
1336 information and return true if we have enough to do something. */
1339 dwarf2_has_info (struct objfile *objfile)
1341 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1342 if (!dwarf2_per_objfile)
1344 /* Initialize per-objfile state. */
1345 struct dwarf2_per_objfile *data
1346 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1348 memset (data, 0, sizeof (*data));
1349 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1350 dwarf2_per_objfile = data;
1352 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1353 dwarf2_per_objfile->objfile = objfile;
1355 return (dwarf2_per_objfile->info.asection != NULL
1356 && dwarf2_per_objfile->abbrev.asection != NULL);
1359 /* When loading sections, we can either look for ".<name>", or for
1360 * ".z<name>", which indicates a compressed section. */
1363 section_is_p (const char *section_name, const char *name)
1365 return (section_name[0] == '.'
1366 && (strcmp (section_name + 1, name) == 0
1367 || (section_name[1] == 'z'
1368 && strcmp (section_name + 2, name) == 0)));
1371 /* This function is mapped across the sections and remembers the
1372 offset and size of each of the debugging sections we are interested
1376 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1378 if (section_is_p (sectp->name, INFO_SECTION))
1380 dwarf2_per_objfile->info.asection = sectp;
1381 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1383 else if (section_is_p (sectp->name, ABBREV_SECTION))
1385 dwarf2_per_objfile->abbrev.asection = sectp;
1386 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1388 else if (section_is_p (sectp->name, LINE_SECTION))
1390 dwarf2_per_objfile->line.asection = sectp;
1391 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1393 else if (section_is_p (sectp->name, LOC_SECTION))
1395 dwarf2_per_objfile->loc.asection = sectp;
1396 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1398 else if (section_is_p (sectp->name, MACINFO_SECTION))
1400 dwarf2_per_objfile->macinfo.asection = sectp;
1401 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1403 else if (section_is_p (sectp->name, STR_SECTION))
1405 dwarf2_per_objfile->str.asection = sectp;
1406 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1408 else if (section_is_p (sectp->name, FRAME_SECTION))
1410 dwarf2_per_objfile->frame.asection = sectp;
1411 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1413 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1415 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1417 if (aflag & SEC_HAS_CONTENTS)
1419 dwarf2_per_objfile->eh_frame.asection = sectp;
1420 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1423 else if (section_is_p (sectp->name, RANGES_SECTION))
1425 dwarf2_per_objfile->ranges.asection = sectp;
1426 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1428 else if (section_is_p (sectp->name, TYPES_SECTION))
1430 dwarf2_per_objfile->types.asection = sectp;
1431 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1433 else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
1435 dwarf2_per_objfile->gdb_index.asection = sectp;
1436 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1439 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1440 && bfd_section_vma (abfd, sectp) == 0)
1441 dwarf2_per_objfile->has_section_at_zero = 1;
1444 /* Decompress a section that was compressed using zlib. Store the
1445 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1448 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1449 gdb_byte **outbuf, bfd_size_type *outsize)
1451 bfd *abfd = objfile->obfd;
1453 error (_("Support for zlib-compressed DWARF data (from '%s') "
1454 "is disabled in this copy of GDB"),
1455 bfd_get_filename (abfd));
1457 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1458 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1459 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1460 bfd_size_type uncompressed_size;
1461 gdb_byte *uncompressed_buffer;
1464 int header_size = 12;
1466 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1467 || bfd_bread (compressed_buffer,
1468 compressed_size, abfd) != compressed_size)
1469 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1470 bfd_get_filename (abfd));
1472 /* Read the zlib header. In this case, it should be "ZLIB" followed
1473 by the uncompressed section size, 8 bytes in big-endian order. */
1474 if (compressed_size < header_size
1475 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1476 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1477 bfd_get_filename (abfd));
1478 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1479 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1480 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1481 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1482 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1483 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1484 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1485 uncompressed_size += compressed_buffer[11];
1487 /* It is possible the section consists of several compressed
1488 buffers concatenated together, so we uncompress in a loop. */
1492 strm.avail_in = compressed_size - header_size;
1493 strm.next_in = (Bytef*) compressed_buffer + header_size;
1494 strm.avail_out = uncompressed_size;
1495 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1497 rc = inflateInit (&strm);
1498 while (strm.avail_in > 0)
1501 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1502 bfd_get_filename (abfd), rc);
1503 strm.next_out = ((Bytef*) uncompressed_buffer
1504 + (uncompressed_size - strm.avail_out));
1505 rc = inflate (&strm, Z_FINISH);
1506 if (rc != Z_STREAM_END)
1507 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1508 bfd_get_filename (abfd), rc);
1509 rc = inflateReset (&strm);
1511 rc = inflateEnd (&strm);
1513 || strm.avail_out != 0)
1514 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1515 bfd_get_filename (abfd), rc);
1517 do_cleanups (cleanup);
1518 *outbuf = uncompressed_buffer;
1519 *outsize = uncompressed_size;
1523 /* A helper function that decides whether a section is empty. */
1526 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1528 return info->asection == NULL || info->size == 0;
1531 /* Read the contents of the section SECTP from object file specified by
1532 OBJFILE, store info about the section into INFO.
1533 If the section is compressed, uncompress it before returning. */
1536 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1538 bfd *abfd = objfile->obfd;
1539 asection *sectp = info->asection;
1540 gdb_byte *buf, *retbuf;
1541 unsigned char header[4];
1545 info->buffer = NULL;
1546 info->was_mmapped = 0;
1549 if (dwarf2_section_empty_p (info))
1552 /* Check if the file has a 4-byte header indicating compression. */
1553 if (info->size > sizeof (header)
1554 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1555 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1557 /* Upon decompression, update the buffer and its size. */
1558 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1560 zlib_decompress_section (objfile, sectp, &info->buffer,
1568 pagesize = getpagesize ();
1570 /* Only try to mmap sections which are large enough: we don't want to
1571 waste space due to fragmentation. Also, only try mmap for sections
1572 without relocations. */
1574 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1576 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1577 size_t map_length = info->size + sectp->filepos - pg_offset;
1578 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1579 MAP_PRIVATE, pg_offset);
1581 if (retbuf != MAP_FAILED)
1583 info->was_mmapped = 1;
1584 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1585 #if HAVE_POSIX_MADVISE
1586 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1593 /* If we get here, we are a normal, not-compressed section. */
1595 = obstack_alloc (&objfile->objfile_obstack, info->size);
1597 /* When debugging .o files, we may need to apply relocations; see
1598 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1599 We never compress sections in .o files, so we only need to
1600 try this when the section is not compressed. */
1601 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1604 info->buffer = retbuf;
1608 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1609 || bfd_bread (buf, info->size, abfd) != info->size)
1610 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1611 bfd_get_filename (abfd));
1614 /* A helper function that returns the size of a section in a safe way.
1615 If you are positive that the section has been read before using the
1616 size, then it is safe to refer to the dwarf2_section_info object's
1617 "size" field directly. In other cases, you must call this
1618 function, because for compressed sections the size field is not set
1619 correctly until the section has been read. */
1621 static bfd_size_type
1622 dwarf2_section_size (struct objfile *objfile,
1623 struct dwarf2_section_info *info)
1626 dwarf2_read_section (objfile, info);
1630 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1634 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1635 asection **sectp, gdb_byte **bufp,
1636 bfd_size_type *sizep)
1638 struct dwarf2_per_objfile *data
1639 = objfile_data (objfile, dwarf2_objfile_data_key);
1640 struct dwarf2_section_info *info;
1642 /* We may see an objfile without any DWARF, in which case we just
1651 if (section_is_p (section_name, EH_FRAME_SECTION))
1652 info = &data->eh_frame;
1653 else if (section_is_p (section_name, FRAME_SECTION))
1654 info = &data->frame;
1656 gdb_assert_not_reached ("unexpected section");
1658 dwarf2_read_section (objfile, info);
1660 *sectp = info->asection;
1661 *bufp = info->buffer;
1662 *sizep = info->size;
1666 /* DWARF quick_symbols_functions support. */
1668 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1669 unique line tables, so we maintain a separate table of all .debug_line
1670 derived entries to support the sharing.
1671 All the quick functions need is the list of file names. We discard the
1672 line_header when we're done and don't need to record it here. */
1673 struct quick_file_names
1675 /* The offset in .debug_line of the line table. We hash on this. */
1676 unsigned int offset;
1678 /* The number of entries in file_names, real_names. */
1679 unsigned int num_file_names;
1681 /* The file names from the line table, after being run through
1683 const char **file_names;
1685 /* The file names from the line table after being run through
1686 gdb_realpath. These are computed lazily. */
1687 const char **real_names;
1690 /* When using the index (and thus not using psymtabs), each CU has an
1691 object of this type. This is used to hold information needed by
1692 the various "quick" methods. */
1693 struct dwarf2_per_cu_quick_data
1695 /* The file table. This can be NULL if there was no file table
1696 or it's currently not read in.
1697 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1698 struct quick_file_names *file_names;
1700 /* The corresponding symbol table. This is NULL if symbols for this
1701 CU have not yet been read. */
1702 struct symtab *symtab;
1704 /* A temporary mark bit used when iterating over all CUs in
1705 expand_symtabs_matching. */
1706 unsigned int mark : 1;
1708 /* True if we've tried to read the file table and found there isn't one.
1709 There will be no point in trying to read it again next time. */
1710 unsigned int no_file_data : 1;
1713 /* Hash function for a quick_file_names. */
1716 hash_file_name_entry (const void *e)
1718 const struct quick_file_names *file_data = e;
1720 return file_data->offset;
1723 /* Equality function for a quick_file_names. */
1726 eq_file_name_entry (const void *a, const void *b)
1728 const struct quick_file_names *ea = a;
1729 const struct quick_file_names *eb = b;
1731 return ea->offset == eb->offset;
1734 /* Delete function for a quick_file_names. */
1737 delete_file_name_entry (void *e)
1739 struct quick_file_names *file_data = e;
1742 for (i = 0; i < file_data->num_file_names; ++i)
1744 xfree ((void*) file_data->file_names[i]);
1745 if (file_data->real_names)
1746 xfree ((void*) file_data->real_names[i]);
1749 /* The space for the struct itself lives on objfile_obstack,
1750 so we don't free it here. */
1753 /* Create a quick_file_names hash table. */
1756 create_quick_file_names_table (unsigned int nr_initial_entries)
1758 return htab_create_alloc (nr_initial_entries,
1759 hash_file_name_entry, eq_file_name_entry,
1760 delete_file_name_entry, xcalloc, xfree);
1763 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1767 dw2_do_instantiate_symtab (struct objfile *objfile,
1768 struct dwarf2_per_cu_data *per_cu)
1770 struct cleanup *back_to;
1772 back_to = make_cleanup (dwarf2_release_queue, NULL);
1774 queue_comp_unit (per_cu, objfile);
1776 if (per_cu->from_debug_types)
1777 read_signatured_type_at_offset (objfile, per_cu->offset);
1779 load_full_comp_unit (per_cu, objfile);
1781 process_queue (objfile);
1783 /* Age the cache, releasing compilation units that have not
1784 been used recently. */
1785 age_cached_comp_units ();
1787 do_cleanups (back_to);
1790 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1791 the objfile from which this CU came. Returns the resulting symbol
1794 static struct symtab *
1795 dw2_instantiate_symtab (struct objfile *objfile,
1796 struct dwarf2_per_cu_data *per_cu)
1798 if (!per_cu->v.quick->symtab)
1800 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1801 increment_reading_symtab ();
1802 dw2_do_instantiate_symtab (objfile, per_cu);
1803 do_cleanups (back_to);
1805 return per_cu->v.quick->symtab;
1808 /* Return the CU given its index. */
1810 static struct dwarf2_per_cu_data *
1811 dw2_get_cu (int index)
1813 if (index >= dwarf2_per_objfile->n_comp_units)
1815 index -= dwarf2_per_objfile->n_comp_units;
1816 return dwarf2_per_objfile->type_comp_units[index];
1818 return dwarf2_per_objfile->all_comp_units[index];
1821 /* A helper function that knows how to read a 64-bit value in a way
1822 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1826 extract_cu_value (const char *bytes, ULONGEST *result)
1828 if (sizeof (ULONGEST) < 8)
1832 /* Ignore the upper 4 bytes if they are all zero. */
1833 for (i = 0; i < 4; ++i)
1834 if (bytes[i + 4] != 0)
1837 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1840 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1844 /* Read the CU list from the mapped index, and use it to create all
1845 the CU objects for this objfile. Return 0 if something went wrong,
1846 1 if everything went ok. */
1849 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1850 offset_type cu_list_elements)
1854 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1855 dwarf2_per_objfile->all_comp_units
1856 = obstack_alloc (&objfile->objfile_obstack,
1857 dwarf2_per_objfile->n_comp_units
1858 * sizeof (struct dwarf2_per_cu_data *));
1860 for (i = 0; i < cu_list_elements; i += 2)
1862 struct dwarf2_per_cu_data *the_cu;
1863 ULONGEST offset, length;
1865 if (!extract_cu_value (cu_list, &offset)
1866 || !extract_cu_value (cu_list + 8, &length))
1870 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1871 struct dwarf2_per_cu_data);
1872 the_cu->offset = offset;
1873 the_cu->length = length;
1874 the_cu->objfile = objfile;
1875 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1876 struct dwarf2_per_cu_quick_data);
1877 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1883 /* Create the signatured type hash table from the index. */
1886 create_signatured_type_table_from_index (struct objfile *objfile,
1887 const gdb_byte *bytes,
1888 offset_type elements)
1891 htab_t sig_types_hash;
1893 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1894 dwarf2_per_objfile->type_comp_units
1895 = obstack_alloc (&objfile->objfile_obstack,
1896 dwarf2_per_objfile->n_type_comp_units
1897 * sizeof (struct dwarf2_per_cu_data *));
1899 sig_types_hash = allocate_signatured_type_table (objfile);
1901 for (i = 0; i < elements; i += 3)
1903 struct signatured_type *type_sig;
1904 ULONGEST offset, type_offset, signature;
1907 if (!extract_cu_value (bytes, &offset)
1908 || !extract_cu_value (bytes + 8, &type_offset))
1910 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1913 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1914 struct signatured_type);
1915 type_sig->signature = signature;
1916 type_sig->offset = offset;
1917 type_sig->type_offset = type_offset;
1918 type_sig->per_cu.from_debug_types = 1;
1919 type_sig->per_cu.offset = offset;
1920 type_sig->per_cu.objfile = objfile;
1921 type_sig->per_cu.v.quick
1922 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1923 struct dwarf2_per_cu_quick_data);
1925 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1928 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1931 dwarf2_per_objfile->signatured_types = sig_types_hash;
1936 /* Read the address map data from the mapped index, and use it to
1937 populate the objfile's psymtabs_addrmap. */
1940 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1942 const gdb_byte *iter, *end;
1943 struct obstack temp_obstack;
1944 struct addrmap *mutable_map;
1945 struct cleanup *cleanup;
1948 obstack_init (&temp_obstack);
1949 cleanup = make_cleanup_obstack_free (&temp_obstack);
1950 mutable_map = addrmap_create_mutable (&temp_obstack);
1952 iter = index->address_table;
1953 end = iter + index->address_table_size;
1955 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1959 ULONGEST hi, lo, cu_index;
1960 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1962 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1964 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1967 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1968 dw2_get_cu (cu_index));
1971 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1972 &objfile->objfile_obstack);
1973 do_cleanups (cleanup);
1976 /* The hash function for strings in the mapped index. This is the
1977 same as the hashtab.c hash function, but we keep a separate copy to
1978 maintain control over the implementation. This is necessary
1979 because the hash function is tied to the format of the mapped index
1983 mapped_index_string_hash (const void *p)
1985 const unsigned char *str = (const unsigned char *) p;
1989 while ((c = *str++) != 0)
1990 r = r * 67 + c - 113;
1995 /* Find a slot in the mapped index INDEX for the object named NAME.
1996 If NAME is found, set *VEC_OUT to point to the CU vector in the
1997 constant pool and return 1. If NAME cannot be found, return 0. */
2000 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2001 offset_type **vec_out)
2003 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2005 offset_type slot, step;
2007 if (current_language->la_language == language_cplus
2008 || current_language->la_language == language_java
2009 || current_language->la_language == language_fortran)
2011 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2013 const char *paren = strchr (name, '(');
2019 dup = xmalloc (paren - name + 1);
2020 memcpy (dup, name, paren - name);
2021 dup[paren - name] = 0;
2023 make_cleanup (xfree, dup);
2028 hash = mapped_index_string_hash (name);
2029 slot = hash & (index->symbol_table_slots - 1);
2030 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2034 /* Convert a slot number to an offset into the table. */
2035 offset_type i = 2 * slot;
2037 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2039 do_cleanups (back_to);
2043 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2044 if (!strcmp (name, str))
2046 *vec_out = (offset_type *) (index->constant_pool
2047 + MAYBE_SWAP (index->symbol_table[i + 1]));
2048 do_cleanups (back_to);
2052 slot = (slot + step) & (index->symbol_table_slots - 1);
2056 /* Read the index file. If everything went ok, initialize the "quick"
2057 elements of all the CUs and return 1. Otherwise, return 0. */
2060 dwarf2_read_index (struct objfile *objfile)
2063 struct mapped_index *map;
2064 offset_type *metadata;
2065 const gdb_byte *cu_list;
2066 const gdb_byte *types_list = NULL;
2067 offset_type version, cu_list_elements;
2068 offset_type types_list_elements = 0;
2071 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2074 /* Older elfutils strip versions could keep the section in the main
2075 executable while splitting it for the separate debug info file. */
2076 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2077 & SEC_HAS_CONTENTS) == 0)
2080 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2082 addr = dwarf2_per_objfile->gdb_index.buffer;
2083 /* Version check. */
2084 version = MAYBE_SWAP (*(offset_type *) addr);
2085 /* Versions earlier than 3 emitted every copy of a psymbol. This
2086 causes the index to behave very poorly for certain requests. Version 3
2087 contained incomplete addrmap. So, it seems better to just ignore such
2091 /* Indexes with higher version than the one supported by GDB may be no
2092 longer backward compatible. */
2096 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2097 map->total_size = dwarf2_per_objfile->gdb_index.size;
2099 metadata = (offset_type *) (addr + sizeof (offset_type));
2102 cu_list = addr + MAYBE_SWAP (metadata[i]);
2103 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2107 types_list = addr + MAYBE_SWAP (metadata[i]);
2108 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2109 - MAYBE_SWAP (metadata[i]))
2113 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2114 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2115 - MAYBE_SWAP (metadata[i]));
2118 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2119 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2120 - MAYBE_SWAP (metadata[i]))
2121 / (2 * sizeof (offset_type)));
2124 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2126 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2129 if (types_list_elements
2130 && !create_signatured_type_table_from_index (objfile, types_list,
2131 types_list_elements))
2134 create_addrmap_from_index (objfile, map);
2136 dwarf2_per_objfile->index_table = map;
2137 dwarf2_per_objfile->using_index = 1;
2138 dwarf2_per_objfile->quick_file_names_table =
2139 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2144 /* A helper for the "quick" functions which sets the global
2145 dwarf2_per_objfile according to OBJFILE. */
2148 dw2_setup (struct objfile *objfile)
2150 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2151 gdb_assert (dwarf2_per_objfile);
2154 /* A helper for the "quick" functions which attempts to read the line
2155 table for THIS_CU. */
2157 static struct quick_file_names *
2158 dw2_get_file_names (struct objfile *objfile,
2159 struct dwarf2_per_cu_data *this_cu)
2161 bfd *abfd = objfile->obfd;
2162 struct line_header *lh;
2163 struct attribute *attr;
2164 struct cleanup *cleanups;
2165 struct die_info *comp_unit_die;
2166 struct dwarf2_section_info* sec;
2167 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2168 int has_children, i;
2169 struct dwarf2_cu cu;
2170 unsigned int bytes_read, buffer_size;
2171 struct die_reader_specs reader_specs;
2172 char *name, *comp_dir;
2174 struct quick_file_names *qfn;
2175 unsigned int line_offset;
2177 if (this_cu->v.quick->file_names != NULL)
2178 return this_cu->v.quick->file_names;
2179 /* If we know there is no line data, no point in looking again. */
2180 if (this_cu->v.quick->no_file_data)
2183 init_one_comp_unit (&cu, objfile);
2184 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2186 if (this_cu->from_debug_types)
2187 sec = &dwarf2_per_objfile->types;
2189 sec = &dwarf2_per_objfile->info;
2190 dwarf2_read_section (objfile, sec);
2191 buffer_size = sec->size;
2192 buffer = sec->buffer;
2193 info_ptr = buffer + this_cu->offset;
2194 beg_of_comp_unit = info_ptr;
2196 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2197 buffer, buffer_size,
2200 /* Complete the cu_header. */
2201 cu.header.offset = beg_of_comp_unit - buffer;
2202 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2205 cu.per_cu = this_cu;
2207 dwarf2_read_abbrevs (abfd, &cu);
2208 make_cleanup (dwarf2_free_abbrev_table, &cu);
2210 if (this_cu->from_debug_types)
2211 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2212 init_cu_die_reader (&reader_specs, &cu);
2213 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2219 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2222 struct quick_file_names find_entry;
2224 line_offset = DW_UNSND (attr);
2226 /* We may have already read in this line header (TU line header sharing).
2227 If we have we're done. */
2228 find_entry.offset = line_offset;
2229 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2230 &find_entry, INSERT);
2233 do_cleanups (cleanups);
2234 this_cu->v.quick->file_names = *slot;
2238 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2242 do_cleanups (cleanups);
2243 this_cu->v.quick->no_file_data = 1;
2247 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2248 qfn->offset = line_offset;
2249 gdb_assert (slot != NULL);
2252 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2254 qfn->num_file_names = lh->num_file_names;
2255 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2256 lh->num_file_names * sizeof (char *));
2257 for (i = 0; i < lh->num_file_names; ++i)
2258 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2259 qfn->real_names = NULL;
2261 free_line_header (lh);
2262 do_cleanups (cleanups);
2264 this_cu->v.quick->file_names = qfn;
2268 /* A helper for the "quick" functions which computes and caches the
2269 real path for a given file name from the line table. */
2272 dw2_get_real_path (struct objfile *objfile,
2273 struct quick_file_names *qfn, int index)
2275 if (qfn->real_names == NULL)
2276 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2277 qfn->num_file_names, sizeof (char *));
2279 if (qfn->real_names[index] == NULL)
2280 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2282 return qfn->real_names[index];
2285 static struct symtab *
2286 dw2_find_last_source_symtab (struct objfile *objfile)
2290 dw2_setup (objfile);
2291 index = dwarf2_per_objfile->n_comp_units - 1;
2292 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2295 /* Traversal function for dw2_forget_cached_source_info. */
2298 dw2_free_cached_file_names (void **slot, void *info)
2300 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2302 if (file_data->real_names)
2306 for (i = 0; i < file_data->num_file_names; ++i)
2308 xfree ((void*) file_data->real_names[i]);
2309 file_data->real_names[i] = NULL;
2317 dw2_forget_cached_source_info (struct objfile *objfile)
2319 dw2_setup (objfile);
2321 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2322 dw2_free_cached_file_names, NULL);
2326 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2327 const char *full_path, const char *real_path,
2328 struct symtab **result)
2331 int check_basename = lbasename (name) == name;
2332 struct dwarf2_per_cu_data *base_cu = NULL;
2334 dw2_setup (objfile);
2336 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2337 + dwarf2_per_objfile->n_type_comp_units); ++i)
2340 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2341 struct quick_file_names *file_data;
2343 if (per_cu->v.quick->symtab)
2346 file_data = dw2_get_file_names (objfile, per_cu);
2347 if (file_data == NULL)
2350 for (j = 0; j < file_data->num_file_names; ++j)
2352 const char *this_name = file_data->file_names[j];
2354 if (FILENAME_CMP (name, this_name) == 0)
2356 *result = dw2_instantiate_symtab (objfile, per_cu);
2360 if (check_basename && ! base_cu
2361 && FILENAME_CMP (lbasename (this_name), name) == 0)
2364 if (full_path != NULL)
2366 const char *this_real_name = dw2_get_real_path (objfile,
2369 if (this_real_name != NULL
2370 && FILENAME_CMP (full_path, this_real_name) == 0)
2372 *result = dw2_instantiate_symtab (objfile, per_cu);
2377 if (real_path != NULL)
2379 const char *this_real_name = dw2_get_real_path (objfile,
2382 if (this_real_name != NULL
2383 && FILENAME_CMP (real_path, this_real_name) == 0)
2385 *result = dw2_instantiate_symtab (objfile, per_cu);
2394 *result = dw2_instantiate_symtab (objfile, base_cu);
2401 static struct symtab *
2402 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2403 const char *name, domain_enum domain)
2405 /* We do all the work in the pre_expand_symtabs_matching hook
2410 /* A helper function that expands all symtabs that hold an object
2414 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2416 dw2_setup (objfile);
2418 /* index_table is NULL if OBJF_READNOW. */
2419 if (dwarf2_per_objfile->index_table)
2423 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2426 offset_type i, len = MAYBE_SWAP (*vec);
2427 for (i = 0; i < len; ++i)
2429 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2430 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2432 dw2_instantiate_symtab (objfile, per_cu);
2439 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2440 int kind, const char *name,
2443 dw2_do_expand_symtabs_matching (objfile, name);
2447 dw2_print_stats (struct objfile *objfile)
2451 dw2_setup (objfile);
2453 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2454 + dwarf2_per_objfile->n_type_comp_units); ++i)
2456 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2458 if (!per_cu->v.quick->symtab)
2461 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2465 dw2_dump (struct objfile *objfile)
2467 /* Nothing worth printing. */
2471 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2472 struct section_offsets *delta)
2474 /* There's nothing to relocate here. */
2478 dw2_expand_symtabs_for_function (struct objfile *objfile,
2479 const char *func_name)
2481 dw2_do_expand_symtabs_matching (objfile, func_name);
2485 dw2_expand_all_symtabs (struct objfile *objfile)
2489 dw2_setup (objfile);
2491 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2492 + dwarf2_per_objfile->n_type_comp_units); ++i)
2494 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2496 dw2_instantiate_symtab (objfile, per_cu);
2501 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2502 const char *filename)
2506 dw2_setup (objfile);
2508 /* We don't need to consider type units here.
2509 This is only called for examining code, e.g. expand_line_sal.
2510 There can be an order of magnitude (or more) more type units
2511 than comp units, and we avoid them if we can. */
2513 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2516 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2517 struct quick_file_names *file_data;
2519 if (per_cu->v.quick->symtab)
2522 file_data = dw2_get_file_names (objfile, per_cu);
2523 if (file_data == NULL)
2526 for (j = 0; j < file_data->num_file_names; ++j)
2528 const char *this_name = file_data->file_names[j];
2529 if (FILENAME_CMP (this_name, filename) == 0)
2531 dw2_instantiate_symtab (objfile, per_cu);
2539 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2541 struct dwarf2_per_cu_data *per_cu;
2543 struct quick_file_names *file_data;
2545 dw2_setup (objfile);
2547 /* index_table is NULL if OBJF_READNOW. */
2548 if (!dwarf2_per_objfile->index_table)
2551 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2555 /* Note that this just looks at the very first one named NAME -- but
2556 actually we are looking for a function. find_main_filename
2557 should be rewritten so that it doesn't require a custom hook. It
2558 could just use the ordinary symbol tables. */
2559 /* vec[0] is the length, which must always be >0. */
2560 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2562 file_data = dw2_get_file_names (objfile, per_cu);
2563 if (file_data == NULL)
2566 return file_data->file_names[file_data->num_file_names - 1];
2570 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2571 struct objfile *objfile, int global,
2572 int (*callback) (struct block *,
2573 struct symbol *, void *),
2574 void *data, symbol_compare_ftype *match,
2575 symbol_compare_ftype *ordered_compare)
2577 /* Currently unimplemented; used for Ada. The function can be called if the
2578 current language is Ada for a non-Ada objfile using GNU index. As Ada
2579 does not look for non-Ada symbols this function should just return. */
2583 dw2_expand_symtabs_matching (struct objfile *objfile,
2584 int (*file_matcher) (const char *, void *),
2585 int (*name_matcher) (const char *, void *),
2591 struct mapped_index *index;
2593 dw2_setup (objfile);
2595 /* index_table is NULL if OBJF_READNOW. */
2596 if (!dwarf2_per_objfile->index_table)
2598 index = dwarf2_per_objfile->index_table;
2600 if (file_matcher != NULL)
2601 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2602 + dwarf2_per_objfile->n_type_comp_units); ++i)
2605 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2606 struct quick_file_names *file_data;
2608 per_cu->v.quick->mark = 0;
2609 if (per_cu->v.quick->symtab)
2612 file_data = dw2_get_file_names (objfile, per_cu);
2613 if (file_data == NULL)
2616 for (j = 0; j < file_data->num_file_names; ++j)
2618 if (file_matcher (file_data->file_names[j], data))
2620 per_cu->v.quick->mark = 1;
2626 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2628 offset_type idx = 2 * iter;
2630 offset_type *vec, vec_len, vec_idx;
2632 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2635 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2637 if (! (*name_matcher) (name, data))
2640 /* The name was matched, now expand corresponding CUs that were
2642 vec = (offset_type *) (index->constant_pool
2643 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2644 vec_len = MAYBE_SWAP (vec[0]);
2645 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2647 struct dwarf2_per_cu_data *per_cu;
2649 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2650 if (file_matcher == NULL || per_cu->v.quick->mark)
2651 dw2_instantiate_symtab (objfile, per_cu);
2656 static struct symtab *
2657 dw2_find_pc_sect_symtab (struct objfile *objfile,
2658 struct minimal_symbol *msymbol,
2660 struct obj_section *section,
2663 struct dwarf2_per_cu_data *data;
2665 dw2_setup (objfile);
2667 if (!objfile->psymtabs_addrmap)
2670 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2674 if (warn_if_readin && data->v.quick->symtab)
2675 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2676 paddress (get_objfile_arch (objfile), pc));
2678 return dw2_instantiate_symtab (objfile, data);
2682 dw2_map_symbol_filenames (struct objfile *objfile,
2683 void (*fun) (const char *, const char *, void *),
2688 dw2_setup (objfile);
2690 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2691 + dwarf2_per_objfile->n_type_comp_units); ++i)
2694 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2695 struct quick_file_names *file_data;
2697 if (per_cu->v.quick->symtab)
2700 file_data = dw2_get_file_names (objfile, per_cu);
2701 if (file_data == NULL)
2704 for (j = 0; j < file_data->num_file_names; ++j)
2706 const char *this_real_name = dw2_get_real_path (objfile, file_data,
2708 (*fun) (file_data->file_names[j], this_real_name, data);
2714 dw2_has_symbols (struct objfile *objfile)
2719 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2722 dw2_find_last_source_symtab,
2723 dw2_forget_cached_source_info,
2726 dw2_pre_expand_symtabs_matching,
2730 dw2_expand_symtabs_for_function,
2731 dw2_expand_all_symtabs,
2732 dw2_expand_symtabs_with_filename,
2733 dw2_find_symbol_file,
2734 dw2_map_matching_symbols,
2735 dw2_expand_symtabs_matching,
2736 dw2_find_pc_sect_symtab,
2737 dw2_map_symbol_filenames
2740 /* Initialize for reading DWARF for this objfile. Return 0 if this
2741 file will use psymtabs, or 1 if using the GNU index. */
2744 dwarf2_initialize_objfile (struct objfile *objfile)
2746 /* If we're about to read full symbols, don't bother with the
2747 indices. In this case we also don't care if some other debug
2748 format is making psymtabs, because they are all about to be
2750 if ((objfile->flags & OBJF_READNOW))
2754 dwarf2_per_objfile->using_index = 1;
2755 create_all_comp_units (objfile);
2756 create_debug_types_hash_table (objfile);
2757 dwarf2_per_objfile->quick_file_names_table =
2758 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2760 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2761 + dwarf2_per_objfile->n_type_comp_units); ++i)
2763 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2765 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2766 struct dwarf2_per_cu_quick_data);
2769 /* Return 1 so that gdb sees the "quick" functions. However,
2770 these functions will be no-ops because we will have expanded
2775 if (dwarf2_read_index (objfile))
2783 /* Build a partial symbol table. */
2786 dwarf2_build_psymtabs (struct objfile *objfile)
2788 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2790 init_psymbol_list (objfile, 1024);
2793 dwarf2_build_psymtabs_hard (objfile);
2796 /* Return TRUE if OFFSET is within CU_HEADER. */
2799 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2801 unsigned int bottom = cu_header->offset;
2802 unsigned int top = (cu_header->offset
2804 + cu_header->initial_length_size);
2806 return (offset >= bottom && offset < top);
2809 /* Read in the comp unit header information from the debug_info at info_ptr.
2810 NOTE: This leaves members offset, first_die_offset to be filled in
2814 read_comp_unit_head (struct comp_unit_head *cu_header,
2815 gdb_byte *info_ptr, bfd *abfd)
2818 unsigned int bytes_read;
2820 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2821 cu_header->initial_length_size = bytes_read;
2822 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2823 info_ptr += bytes_read;
2824 cu_header->version = read_2_bytes (abfd, info_ptr);
2826 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2828 info_ptr += bytes_read;
2829 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2831 signed_addr = bfd_get_sign_extend_vma (abfd);
2832 if (signed_addr < 0)
2833 internal_error (__FILE__, __LINE__,
2834 _("read_comp_unit_head: dwarf from non elf file"));
2835 cu_header->signed_addr_p = signed_addr;
2841 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2842 gdb_byte *buffer, unsigned int buffer_size,
2845 gdb_byte *beg_of_comp_unit = info_ptr;
2847 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2849 if (header->version != 2 && header->version != 3 && header->version != 4)
2850 error (_("Dwarf Error: wrong version in compilation unit header "
2851 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2852 bfd_get_filename (abfd));
2854 if (header->abbrev_offset
2855 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2856 &dwarf2_per_objfile->abbrev))
2857 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2858 "(offset 0x%lx + 6) [in module %s]"),
2859 (long) header->abbrev_offset,
2860 (long) (beg_of_comp_unit - buffer),
2861 bfd_get_filename (abfd));
2863 if (beg_of_comp_unit + header->length + header->initial_length_size
2864 > buffer + buffer_size)
2865 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2866 "(offset 0x%lx + 0) [in module %s]"),
2867 (long) header->length,
2868 (long) (beg_of_comp_unit - buffer),
2869 bfd_get_filename (abfd));
2874 /* Read in the types comp unit header information from .debug_types entry at
2875 types_ptr. The result is a pointer to one past the end of the header. */
2878 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2879 ULONGEST *signature,
2880 gdb_byte *types_ptr, bfd *abfd)
2882 gdb_byte *initial_types_ptr = types_ptr;
2884 dwarf2_read_section (dwarf2_per_objfile->objfile,
2885 &dwarf2_per_objfile->types);
2886 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2888 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2890 *signature = read_8_bytes (abfd, types_ptr);
2892 types_ptr += cu_header->offset_size;
2893 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2898 /* Allocate a new partial symtab for file named NAME and mark this new
2899 partial symtab as being an include of PST. */
2902 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2903 struct objfile *objfile)
2905 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2907 subpst->section_offsets = pst->section_offsets;
2908 subpst->textlow = 0;
2909 subpst->texthigh = 0;
2911 subpst->dependencies = (struct partial_symtab **)
2912 obstack_alloc (&objfile->objfile_obstack,
2913 sizeof (struct partial_symtab *));
2914 subpst->dependencies[0] = pst;
2915 subpst->number_of_dependencies = 1;
2917 subpst->globals_offset = 0;
2918 subpst->n_global_syms = 0;
2919 subpst->statics_offset = 0;
2920 subpst->n_static_syms = 0;
2921 subpst->symtab = NULL;
2922 subpst->read_symtab = pst->read_symtab;
2925 /* No private part is necessary for include psymtabs. This property
2926 can be used to differentiate between such include psymtabs and
2927 the regular ones. */
2928 subpst->read_symtab_private = NULL;
2931 /* Read the Line Number Program data and extract the list of files
2932 included by the source file represented by PST. Build an include
2933 partial symtab for each of these included files. */
2936 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2937 struct die_info *die,
2938 struct partial_symtab *pst)
2940 struct objfile *objfile = cu->objfile;
2941 bfd *abfd = objfile->obfd;
2942 struct line_header *lh = NULL;
2943 struct attribute *attr;
2945 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2948 unsigned int line_offset = DW_UNSND (attr);
2950 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2953 return; /* No linetable, so no includes. */
2955 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2956 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
2958 free_line_header (lh);
2962 hash_type_signature (const void *item)
2964 const struct signatured_type *type_sig = item;
2966 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2967 return type_sig->signature;
2971 eq_type_signature (const void *item_lhs, const void *item_rhs)
2973 const struct signatured_type *lhs = item_lhs;
2974 const struct signatured_type *rhs = item_rhs;
2976 return lhs->signature == rhs->signature;
2979 /* Allocate a hash table for signatured types. */
2982 allocate_signatured_type_table (struct objfile *objfile)
2984 return htab_create_alloc_ex (41,
2985 hash_type_signature,
2988 &objfile->objfile_obstack,
2989 hashtab_obstack_allocate,
2990 dummy_obstack_deallocate);
2993 /* A helper function to add a signatured type CU to a list. */
2996 add_signatured_type_cu_to_list (void **slot, void *datum)
2998 struct signatured_type *sigt = *slot;
2999 struct dwarf2_per_cu_data ***datap = datum;
3001 **datap = &sigt->per_cu;
3007 /* Create the hash table of all entries in the .debug_types section.
3008 The result is zero if there is an error (e.g. missing .debug_types section),
3009 otherwise non-zero. */
3012 create_debug_types_hash_table (struct objfile *objfile)
3016 struct dwarf2_per_cu_data **iter;
3018 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
3019 info_ptr = dwarf2_per_objfile->types.buffer;
3021 if (info_ptr == NULL)
3023 dwarf2_per_objfile->signatured_types = NULL;
3027 types_htab = allocate_signatured_type_table (objfile);
3029 if (dwarf2_die_debug)
3030 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3032 while (info_ptr < dwarf2_per_objfile->types.buffer
3033 + dwarf2_per_objfile->types.size)
3035 unsigned int offset;
3036 unsigned int offset_size;
3037 unsigned int type_offset;
3038 unsigned int length, initial_length_size;
3039 unsigned short version;
3041 struct signatured_type *type_sig;
3043 gdb_byte *ptr = info_ptr;
3045 offset = ptr - dwarf2_per_objfile->types.buffer;
3047 /* We need to read the type's signature in order to build the hash
3048 table, but we don't need to read anything else just yet. */
3050 /* Sanity check to ensure entire cu is present. */
3051 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
3052 if (ptr + length + initial_length_size
3053 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
3055 complaint (&symfile_complaints,
3056 _("debug type entry runs off end "
3057 "of `.debug_types' section, ignored"));
3061 offset_size = initial_length_size == 4 ? 4 : 8;
3062 ptr += initial_length_size;
3063 version = bfd_get_16 (objfile->obfd, ptr);
3065 ptr += offset_size; /* abbrev offset */
3066 ptr += 1; /* address size */
3067 signature = bfd_get_64 (objfile->obfd, ptr);
3069 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3071 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3072 memset (type_sig, 0, sizeof (*type_sig));
3073 type_sig->signature = signature;
3074 type_sig->offset = offset;
3075 type_sig->type_offset = type_offset;
3076 type_sig->per_cu.objfile = objfile;
3077 type_sig->per_cu.from_debug_types = 1;
3079 slot = htab_find_slot (types_htab, type_sig, INSERT);
3080 gdb_assert (slot != NULL);
3083 if (dwarf2_die_debug)
3084 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3085 offset, phex (signature, sizeof (signature)));
3087 info_ptr = info_ptr + initial_length_size + length;
3090 dwarf2_per_objfile->signatured_types = types_htab;
3092 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3093 dwarf2_per_objfile->type_comp_units
3094 = obstack_alloc (&objfile->objfile_obstack,
3095 dwarf2_per_objfile->n_type_comp_units
3096 * sizeof (struct dwarf2_per_cu_data *));
3097 iter = &dwarf2_per_objfile->type_comp_units[0];
3098 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3099 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3100 == dwarf2_per_objfile->n_type_comp_units);
3105 /* Lookup a signature based type.
3106 Returns NULL if SIG is not present in the table. */
3108 static struct signatured_type *
3109 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3111 struct signatured_type find_entry, *entry;
3113 if (dwarf2_per_objfile->signatured_types == NULL)
3115 complaint (&symfile_complaints,
3116 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3120 find_entry.signature = sig;
3121 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3125 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3128 init_cu_die_reader (struct die_reader_specs *reader,
3129 struct dwarf2_cu *cu)
3131 reader->abfd = cu->objfile->obfd;
3133 if (cu->per_cu->from_debug_types)
3135 gdb_assert (dwarf2_per_objfile->types.readin);
3136 reader->buffer = dwarf2_per_objfile->types.buffer;
3140 gdb_assert (dwarf2_per_objfile->info.readin);
3141 reader->buffer = dwarf2_per_objfile->info.buffer;
3145 /* Find the base address of the compilation unit for range lists and
3146 location lists. It will normally be specified by DW_AT_low_pc.
3147 In DWARF-3 draft 4, the base address could be overridden by
3148 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3149 compilation units with discontinuous ranges. */
3152 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3154 struct attribute *attr;
3157 cu->base_address = 0;
3159 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3162 cu->base_address = DW_ADDR (attr);
3167 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3170 cu->base_address = DW_ADDR (attr);
3176 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3177 to combine the common parts.
3178 Process a compilation unit for a psymtab.
3179 BUFFER is a pointer to the beginning of the dwarf section buffer,
3180 either .debug_info or debug_types.
3181 INFO_PTR is a pointer to the start of the CU.
3182 Returns a pointer to the next CU. */
3185 process_psymtab_comp_unit (struct objfile *objfile,
3186 struct dwarf2_per_cu_data *this_cu,
3187 gdb_byte *buffer, gdb_byte *info_ptr,
3188 unsigned int buffer_size)
3190 bfd *abfd = objfile->obfd;
3191 gdb_byte *beg_of_comp_unit = info_ptr;
3192 struct die_info *comp_unit_die;
3193 struct partial_symtab *pst;
3195 struct cleanup *back_to_inner;
3196 struct dwarf2_cu cu;
3197 int has_children, has_pc_info;
3198 struct attribute *attr;
3199 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3200 struct die_reader_specs reader_specs;
3201 const char *filename;
3203 init_one_comp_unit (&cu, objfile);
3204 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3206 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3207 buffer, buffer_size,
3210 /* Complete the cu_header. */
3211 cu.header.offset = beg_of_comp_unit - buffer;
3212 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3214 cu.list_in_scope = &file_symbols;
3216 /* If this compilation unit was already read in, free the
3217 cached copy in order to read it in again. This is
3218 necessary because we skipped some symbols when we first
3219 read in the compilation unit (see load_partial_dies).
3220 This problem could be avoided, but the benefit is
3222 if (this_cu->cu != NULL)
3223 free_one_cached_comp_unit (this_cu->cu);
3225 /* Note that this is a pointer to our stack frame, being
3226 added to a global data structure. It will be cleaned up
3227 in free_stack_comp_unit when we finish with this
3228 compilation unit. */
3230 cu.per_cu = this_cu;
3232 /* Read the abbrevs for this compilation unit into a table. */
3233 dwarf2_read_abbrevs (abfd, &cu);
3234 make_cleanup (dwarf2_free_abbrev_table, &cu);
3236 /* Read the compilation unit die. */
3237 if (this_cu->from_debug_types)
3238 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3239 init_cu_die_reader (&reader_specs, &cu);
3240 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3243 if (this_cu->from_debug_types)
3245 /* offset,length haven't been set yet for type units. */
3246 this_cu->offset = cu.header.offset;
3247 this_cu->length = cu.header.length + cu.header.initial_length_size;
3249 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3251 info_ptr = (beg_of_comp_unit + cu.header.length
3252 + cu.header.initial_length_size);
3253 do_cleanups (back_to_inner);
3257 prepare_one_comp_unit (&cu, comp_unit_die);
3259 /* Allocate a new partial symbol table structure. */
3260 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3261 if (attr == NULL || !DW_STRING (attr))
3264 filename = DW_STRING (attr);
3265 pst = start_psymtab_common (objfile, objfile->section_offsets,
3267 /* TEXTLOW and TEXTHIGH are set below. */
3269 objfile->global_psymbols.next,
3270 objfile->static_psymbols.next);
3272 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3274 pst->dirname = DW_STRING (attr);
3276 pst->read_symtab_private = this_cu;
3278 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3280 /* Store the function that reads in the rest of the symbol table. */
3281 pst->read_symtab = dwarf2_psymtab_to_symtab;
3283 this_cu->v.psymtab = pst;
3285 dwarf2_find_base_address (comp_unit_die, &cu);
3287 /* Possibly set the default values of LOWPC and HIGHPC from
3289 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3290 &best_highpc, &cu, pst);
3291 if (has_pc_info == 1 && best_lowpc < best_highpc)
3292 /* Store the contiguous range if it is not empty; it can be empty for
3293 CUs with no code. */
3294 addrmap_set_empty (objfile->psymtabs_addrmap,
3295 best_lowpc + baseaddr,
3296 best_highpc + baseaddr - 1, pst);
3298 /* Check if comp unit has_children.
3299 If so, read the rest of the partial symbols from this comp unit.
3300 If not, there's no more debug_info for this comp unit. */
3303 struct partial_die_info *first_die;
3304 CORE_ADDR lowpc, highpc;
3306 lowpc = ((CORE_ADDR) -1);
3307 highpc = ((CORE_ADDR) 0);
3309 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3311 scan_partial_symbols (first_die, &lowpc, &highpc,
3312 ! has_pc_info, &cu);
3314 /* If we didn't find a lowpc, set it to highpc to avoid
3315 complaints from `maint check'. */
3316 if (lowpc == ((CORE_ADDR) -1))
3319 /* If the compilation unit didn't have an explicit address range,
3320 then use the information extracted from its child dies. */
3324 best_highpc = highpc;
3327 pst->textlow = best_lowpc + baseaddr;
3328 pst->texthigh = best_highpc + baseaddr;
3330 pst->n_global_syms = objfile->global_psymbols.next -
3331 (objfile->global_psymbols.list + pst->globals_offset);
3332 pst->n_static_syms = objfile->static_psymbols.next -
3333 (objfile->static_psymbols.list + pst->statics_offset);
3334 sort_pst_symbols (pst);
3336 info_ptr = (beg_of_comp_unit + cu.header.length
3337 + cu.header.initial_length_size);
3339 if (this_cu->from_debug_types)
3341 /* It's not clear we want to do anything with stmt lists here.
3342 Waiting to see what gcc ultimately does. */
3346 /* Get the list of files included in the current compilation unit,
3347 and build a psymtab for each of them. */
3348 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3351 do_cleanups (back_to_inner);
3356 /* Traversal function for htab_traverse_noresize.
3357 Process one .debug_types comp-unit. */
3360 process_type_comp_unit (void **slot, void *info)
3362 struct signatured_type *entry = (struct signatured_type *) *slot;
3363 struct objfile *objfile = (struct objfile *) info;
3364 struct dwarf2_per_cu_data *this_cu;
3366 this_cu = &entry->per_cu;
3368 gdb_assert (dwarf2_per_objfile->types.readin);
3369 process_psymtab_comp_unit (objfile, this_cu,
3370 dwarf2_per_objfile->types.buffer,
3371 dwarf2_per_objfile->types.buffer + entry->offset,
3372 dwarf2_per_objfile->types.size);
3377 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3378 Build partial symbol tables for the .debug_types comp-units. */
3381 build_type_psymtabs (struct objfile *objfile)
3383 if (! create_debug_types_hash_table (objfile))
3386 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3387 process_type_comp_unit, objfile);
3390 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3393 psymtabs_addrmap_cleanup (void *o)
3395 struct objfile *objfile = o;
3397 objfile->psymtabs_addrmap = NULL;
3400 /* Build the partial symbol table by doing a quick pass through the
3401 .debug_info and .debug_abbrev sections. */
3404 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3407 struct cleanup *back_to, *addrmap_cleanup;
3408 struct obstack temp_obstack;
3410 dwarf2_per_objfile->reading_partial_symbols = 1;
3412 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3413 info_ptr = dwarf2_per_objfile->info.buffer;
3415 /* Any cached compilation units will be linked by the per-objfile
3416 read_in_chain. Make sure to free them when we're done. */
3417 back_to = make_cleanup (free_cached_comp_units, NULL);
3419 build_type_psymtabs (objfile);
3421 create_all_comp_units (objfile);
3423 /* Create a temporary address map on a temporary obstack. We later
3424 copy this to the final obstack. */
3425 obstack_init (&temp_obstack);
3426 make_cleanup_obstack_free (&temp_obstack);
3427 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3428 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3430 /* Since the objects we're extracting from .debug_info vary in
3431 length, only the individual functions to extract them (like
3432 read_comp_unit_head and load_partial_die) can really know whether
3433 the buffer is large enough to hold another complete object.
3435 At the moment, they don't actually check that. If .debug_info
3436 holds just one extra byte after the last compilation unit's dies,
3437 then read_comp_unit_head will happily read off the end of the
3438 buffer. read_partial_die is similarly casual. Those functions
3441 For this loop condition, simply checking whether there's any data
3442 left at all should be sufficient. */
3444 while (info_ptr < (dwarf2_per_objfile->info.buffer
3445 + dwarf2_per_objfile->info.size))
3447 struct dwarf2_per_cu_data *this_cu;
3449 this_cu = dwarf2_find_comp_unit (info_ptr
3450 - dwarf2_per_objfile->info.buffer,
3453 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3454 dwarf2_per_objfile->info.buffer,
3456 dwarf2_per_objfile->info.size);
3459 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3460 &objfile->objfile_obstack);
3461 discard_cleanups (addrmap_cleanup);
3463 do_cleanups (back_to);
3466 /* Load the partial DIEs for a secondary CU into memory. */
3469 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3470 struct objfile *objfile)
3472 bfd *abfd = objfile->obfd;
3473 gdb_byte *info_ptr, *beg_of_comp_unit;
3474 struct die_info *comp_unit_die;
3475 struct dwarf2_cu *cu;
3476 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3478 struct die_reader_specs reader_specs;
3481 gdb_assert (! this_cu->from_debug_types);
3483 gdb_assert (dwarf2_per_objfile->info.readin);
3484 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3485 beg_of_comp_unit = info_ptr;
3487 if (this_cu->cu == NULL)
3489 cu = xmalloc (sizeof (*cu));
3490 init_one_comp_unit (cu, objfile);
3494 /* If an error occurs while loading, release our storage. */
3495 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3497 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3498 dwarf2_per_objfile->info.buffer,
3499 dwarf2_per_objfile->info.size,
3502 /* Complete the cu_header. */
3503 cu->header.offset = this_cu->offset;
3504 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3506 /* Link this compilation unit into the compilation unit tree. */
3508 cu->per_cu = this_cu;
3510 /* Link this CU into read_in_chain. */
3511 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3512 dwarf2_per_objfile->read_in_chain = this_cu;
3517 info_ptr += cu->header.first_die_offset;
3520 /* Read the abbrevs for this compilation unit into a table. */
3521 gdb_assert (cu->dwarf2_abbrevs == NULL);
3522 dwarf2_read_abbrevs (abfd, cu);
3523 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3525 /* Read the compilation unit die. */
3526 init_cu_die_reader (&reader_specs, cu);
3527 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3530 prepare_one_comp_unit (cu, comp_unit_die);
3532 /* Check if comp unit has_children.
3533 If so, read the rest of the partial symbols from this comp unit.
3534 If not, there's no more debug_info for this comp unit. */
3536 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3538 do_cleanups (free_abbrevs_cleanup);
3542 /* We've successfully allocated this compilation unit. Let our
3543 caller clean it up when finished with it. */
3544 discard_cleanups (free_cu_cleanup);
3548 /* Create a list of all compilation units in OBJFILE. We do this only
3549 if an inter-comp-unit reference is found; presumably if there is one,
3550 there will be many, and one will occur early in the .debug_info section.
3551 So there's no point in building this list incrementally. */
3554 create_all_comp_units (struct objfile *objfile)
3558 struct dwarf2_per_cu_data **all_comp_units;
3561 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3562 info_ptr = dwarf2_per_objfile->info.buffer;
3566 all_comp_units = xmalloc (n_allocated
3567 * sizeof (struct dwarf2_per_cu_data *));
3569 while (info_ptr < dwarf2_per_objfile->info.buffer
3570 + dwarf2_per_objfile->info.size)
3572 unsigned int length, initial_length_size;
3573 struct dwarf2_per_cu_data *this_cu;
3574 unsigned int offset;
3576 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3578 /* Read just enough information to find out where the next
3579 compilation unit is. */
3580 length = read_initial_length (objfile->obfd, info_ptr,
3581 &initial_length_size);
3583 /* Save the compilation unit for later lookup. */
3584 this_cu = obstack_alloc (&objfile->objfile_obstack,
3585 sizeof (struct dwarf2_per_cu_data));
3586 memset (this_cu, 0, sizeof (*this_cu));
3587 this_cu->offset = offset;
3588 this_cu->length = length + initial_length_size;
3589 this_cu->objfile = objfile;
3591 if (n_comp_units == n_allocated)
3594 all_comp_units = xrealloc (all_comp_units,
3596 * sizeof (struct dwarf2_per_cu_data *));
3598 all_comp_units[n_comp_units++] = this_cu;
3600 info_ptr = info_ptr + this_cu->length;
3603 dwarf2_per_objfile->all_comp_units
3604 = obstack_alloc (&objfile->objfile_obstack,
3605 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3606 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3607 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3608 xfree (all_comp_units);
3609 dwarf2_per_objfile->n_comp_units = n_comp_units;
3612 /* Process all loaded DIEs for compilation unit CU, starting at
3613 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3614 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3615 DW_AT_ranges). If NEED_PC is set, then this function will set
3616 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3617 and record the covered ranges in the addrmap. */
3620 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3621 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3623 struct partial_die_info *pdi;
3625 /* Now, march along the PDI's, descending into ones which have
3626 interesting children but skipping the children of the other ones,
3627 until we reach the end of the compilation unit. */
3633 fixup_partial_die (pdi, cu);
3635 /* Anonymous namespaces or modules have no name but have interesting
3636 children, so we need to look at them. Ditto for anonymous
3639 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3640 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3644 case DW_TAG_subprogram:
3645 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3647 case DW_TAG_constant:
3648 case DW_TAG_variable:
3649 case DW_TAG_typedef:
3650 case DW_TAG_union_type:
3651 if (!pdi->is_declaration)
3653 add_partial_symbol (pdi, cu);
3656 case DW_TAG_class_type:
3657 case DW_TAG_interface_type:
3658 case DW_TAG_structure_type:
3659 if (!pdi->is_declaration)
3661 add_partial_symbol (pdi, cu);
3664 case DW_TAG_enumeration_type:
3665 if (!pdi->is_declaration)
3666 add_partial_enumeration (pdi, cu);
3668 case DW_TAG_base_type:
3669 case DW_TAG_subrange_type:
3670 /* File scope base type definitions are added to the partial
3672 add_partial_symbol (pdi, cu);
3674 case DW_TAG_namespace:
3675 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3678 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3685 /* If the die has a sibling, skip to the sibling. */
3687 pdi = pdi->die_sibling;
3691 /* Functions used to compute the fully scoped name of a partial DIE.
3693 Normally, this is simple. For C++, the parent DIE's fully scoped
3694 name is concatenated with "::" and the partial DIE's name. For
3695 Java, the same thing occurs except that "." is used instead of "::".
3696 Enumerators are an exception; they use the scope of their parent
3697 enumeration type, i.e. the name of the enumeration type is not
3698 prepended to the enumerator.
3700 There are two complexities. One is DW_AT_specification; in this
3701 case "parent" means the parent of the target of the specification,
3702 instead of the direct parent of the DIE. The other is compilers
3703 which do not emit DW_TAG_namespace; in this case we try to guess
3704 the fully qualified name of structure types from their members'
3705 linkage names. This must be done using the DIE's children rather
3706 than the children of any DW_AT_specification target. We only need
3707 to do this for structures at the top level, i.e. if the target of
3708 any DW_AT_specification (if any; otherwise the DIE itself) does not
3711 /* Compute the scope prefix associated with PDI's parent, in
3712 compilation unit CU. The result will be allocated on CU's
3713 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3714 field. NULL is returned if no prefix is necessary. */
3716 partial_die_parent_scope (struct partial_die_info *pdi,
3717 struct dwarf2_cu *cu)
3719 char *grandparent_scope;
3720 struct partial_die_info *parent, *real_pdi;
3722 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3723 then this means the parent of the specification DIE. */
3726 while (real_pdi->has_specification)
3727 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3729 parent = real_pdi->die_parent;
3733 if (parent->scope_set)
3734 return parent->scope;
3736 fixup_partial_die (parent, cu);
3738 grandparent_scope = partial_die_parent_scope (parent, cu);
3740 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3741 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3742 Work around this problem here. */
3743 if (cu->language == language_cplus
3744 && parent->tag == DW_TAG_namespace
3745 && strcmp (parent->name, "::") == 0
3746 && grandparent_scope == NULL)
3748 parent->scope = NULL;
3749 parent->scope_set = 1;
3753 if (parent->tag == DW_TAG_namespace
3754 || parent->tag == DW_TAG_module
3755 || parent->tag == DW_TAG_structure_type
3756 || parent->tag == DW_TAG_class_type
3757 || parent->tag == DW_TAG_interface_type
3758 || parent->tag == DW_TAG_union_type
3759 || parent->tag == DW_TAG_enumeration_type)
3761 if (grandparent_scope == NULL)
3762 parent->scope = parent->name;
3764 parent->scope = typename_concat (&cu->comp_unit_obstack,
3766 parent->name, 0, cu);
3768 else if (parent->tag == DW_TAG_enumerator)
3769 /* Enumerators should not get the name of the enumeration as a prefix. */
3770 parent->scope = grandparent_scope;
3773 /* FIXME drow/2004-04-01: What should we be doing with
3774 function-local names? For partial symbols, we should probably be
3776 complaint (&symfile_complaints,
3777 _("unhandled containing DIE tag %d for DIE at %d"),
3778 parent->tag, pdi->offset);
3779 parent->scope = grandparent_scope;
3782 parent->scope_set = 1;
3783 return parent->scope;
3786 /* Return the fully scoped name associated with PDI, from compilation unit
3787 CU. The result will be allocated with malloc. */
3789 partial_die_full_name (struct partial_die_info *pdi,
3790 struct dwarf2_cu *cu)
3794 /* If this is a template instantiation, we can not work out the
3795 template arguments from partial DIEs. So, unfortunately, we have
3796 to go through the full DIEs. At least any work we do building
3797 types here will be reused if full symbols are loaded later. */
3798 if (pdi->has_template_arguments)
3800 fixup_partial_die (pdi, cu);
3802 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3804 struct die_info *die;
3805 struct attribute attr;
3806 struct dwarf2_cu *ref_cu = cu;
3809 attr.form = DW_FORM_ref_addr;
3810 attr.u.addr = pdi->offset;
3811 die = follow_die_ref (NULL, &attr, &ref_cu);
3813 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3817 parent_scope = partial_die_parent_scope (pdi, cu);
3818 if (parent_scope == NULL)
3821 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3825 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3827 struct objfile *objfile = cu->objfile;
3829 char *actual_name = NULL;
3830 const struct partial_symbol *psym = NULL;
3832 int built_actual_name = 0;
3834 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3836 actual_name = partial_die_full_name (pdi, cu);
3838 built_actual_name = 1;
3840 if (actual_name == NULL)
3841 actual_name = pdi->name;
3845 case DW_TAG_subprogram:
3846 if (pdi->is_external || cu->language == language_ada)
3848 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3849 of the global scope. But in Ada, we want to be able to access
3850 nested procedures globally. So all Ada subprograms are stored
3851 in the global scope. */
3852 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3853 mst_text, objfile); */
3854 add_psymbol_to_list (actual_name, strlen (actual_name),
3856 VAR_DOMAIN, LOC_BLOCK,
3857 &objfile->global_psymbols,
3858 0, pdi->lowpc + baseaddr,
3859 cu->language, objfile);
3863 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3864 mst_file_text, objfile); */
3865 add_psymbol_to_list (actual_name, strlen (actual_name),
3867 VAR_DOMAIN, LOC_BLOCK,
3868 &objfile->static_psymbols,
3869 0, pdi->lowpc + baseaddr,
3870 cu->language, objfile);
3873 case DW_TAG_constant:
3875 struct psymbol_allocation_list *list;
3877 if (pdi->is_external)
3878 list = &objfile->global_psymbols;
3880 list = &objfile->static_psymbols;
3881 add_psymbol_to_list (actual_name, strlen (actual_name),
3882 built_actual_name, VAR_DOMAIN, LOC_STATIC,
3883 list, 0, 0, cu->language, objfile);
3886 case DW_TAG_variable:
3888 addr = decode_locdesc (pdi->locdesc, cu);
3892 && !dwarf2_per_objfile->has_section_at_zero)
3894 /* A global or static variable may also have been stripped
3895 out by the linker if unused, in which case its address
3896 will be nullified; do not add such variables into partial
3897 symbol table then. */
3899 else if (pdi->is_external)
3902 Don't enter into the minimal symbol tables as there is
3903 a minimal symbol table entry from the ELF symbols already.
3904 Enter into partial symbol table if it has a location
3905 descriptor or a type.
3906 If the location descriptor is missing, new_symbol will create
3907 a LOC_UNRESOLVED symbol, the address of the variable will then
3908 be determined from the minimal symbol table whenever the variable
3910 The address for the partial symbol table entry is not
3911 used by GDB, but it comes in handy for debugging partial symbol
3914 if (pdi->locdesc || pdi->has_type)
3915 add_psymbol_to_list (actual_name, strlen (actual_name),
3917 VAR_DOMAIN, LOC_STATIC,
3918 &objfile->global_psymbols,
3920 cu->language, objfile);
3924 /* Static Variable. Skip symbols without location descriptors. */
3925 if (pdi->locdesc == NULL)
3927 if (built_actual_name)
3928 xfree (actual_name);
3931 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3932 mst_file_data, objfile); */
3933 add_psymbol_to_list (actual_name, strlen (actual_name),
3935 VAR_DOMAIN, LOC_STATIC,
3936 &objfile->static_psymbols,
3938 cu->language, objfile);
3941 case DW_TAG_typedef:
3942 case DW_TAG_base_type:
3943 case DW_TAG_subrange_type:
3944 add_psymbol_to_list (actual_name, strlen (actual_name),
3946 VAR_DOMAIN, LOC_TYPEDEF,
3947 &objfile->static_psymbols,
3948 0, (CORE_ADDR) 0, cu->language, objfile);
3950 case DW_TAG_namespace:
3951 add_psymbol_to_list (actual_name, strlen (actual_name),
3953 VAR_DOMAIN, LOC_TYPEDEF,
3954 &objfile->global_psymbols,
3955 0, (CORE_ADDR) 0, cu->language, objfile);
3957 case DW_TAG_class_type:
3958 case DW_TAG_interface_type:
3959 case DW_TAG_structure_type:
3960 case DW_TAG_union_type:
3961 case DW_TAG_enumeration_type:
3962 /* Skip external references. The DWARF standard says in the section
3963 about "Structure, Union, and Class Type Entries": "An incomplete
3964 structure, union or class type is represented by a structure,
3965 union or class entry that does not have a byte size attribute
3966 and that has a DW_AT_declaration attribute." */
3967 if (!pdi->has_byte_size && pdi->is_declaration)
3969 if (built_actual_name)
3970 xfree (actual_name);
3974 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3975 static vs. global. */
3976 add_psymbol_to_list (actual_name, strlen (actual_name),
3978 STRUCT_DOMAIN, LOC_TYPEDEF,
3979 (cu->language == language_cplus
3980 || cu->language == language_java)
3981 ? &objfile->global_psymbols
3982 : &objfile->static_psymbols,
3983 0, (CORE_ADDR) 0, cu->language, objfile);
3986 case DW_TAG_enumerator:
3987 add_psymbol_to_list (actual_name, strlen (actual_name),
3989 VAR_DOMAIN, LOC_CONST,
3990 (cu->language == language_cplus
3991 || cu->language == language_java)
3992 ? &objfile->global_psymbols
3993 : &objfile->static_psymbols,
3994 0, (CORE_ADDR) 0, cu->language, objfile);
4000 if (built_actual_name)
4001 xfree (actual_name);
4004 /* Read a partial die corresponding to a namespace; also, add a symbol
4005 corresponding to that namespace to the symbol table. NAMESPACE is
4006 the name of the enclosing namespace. */
4009 add_partial_namespace (struct partial_die_info *pdi,
4010 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4011 int need_pc, struct dwarf2_cu *cu)
4013 /* Add a symbol for the namespace. */
4015 add_partial_symbol (pdi, cu);
4017 /* Now scan partial symbols in that namespace. */
4019 if (pdi->has_children)
4020 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4023 /* Read a partial die corresponding to a Fortran module. */
4026 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4027 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4029 /* Now scan partial symbols in that module. */
4031 if (pdi->has_children)
4032 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4035 /* Read a partial die corresponding to a subprogram and create a partial
4036 symbol for that subprogram. When the CU language allows it, this
4037 routine also defines a partial symbol for each nested subprogram
4038 that this subprogram contains.
4040 DIE my also be a lexical block, in which case we simply search
4041 recursively for suprograms defined inside that lexical block.
4042 Again, this is only performed when the CU language allows this
4043 type of definitions. */
4046 add_partial_subprogram (struct partial_die_info *pdi,
4047 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4048 int need_pc, struct dwarf2_cu *cu)
4050 if (pdi->tag == DW_TAG_subprogram)
4052 if (pdi->has_pc_info)
4054 if (pdi->lowpc < *lowpc)
4055 *lowpc = pdi->lowpc;
4056 if (pdi->highpc > *highpc)
4057 *highpc = pdi->highpc;
4061 struct objfile *objfile = cu->objfile;
4063 baseaddr = ANOFFSET (objfile->section_offsets,
4064 SECT_OFF_TEXT (objfile));
4065 addrmap_set_empty (objfile->psymtabs_addrmap,
4066 pdi->lowpc + baseaddr,
4067 pdi->highpc - 1 + baseaddr,
4068 cu->per_cu->v.psymtab);
4070 if (!pdi->is_declaration)
4071 /* Ignore subprogram DIEs that do not have a name, they are
4072 illegal. Do not emit a complaint at this point, we will
4073 do so when we convert this psymtab into a symtab. */
4075 add_partial_symbol (pdi, cu);
4079 if (! pdi->has_children)
4082 if (cu->language == language_ada)
4084 pdi = pdi->die_child;
4087 fixup_partial_die (pdi, cu);
4088 if (pdi->tag == DW_TAG_subprogram
4089 || pdi->tag == DW_TAG_lexical_block)
4090 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4091 pdi = pdi->die_sibling;
4096 /* Read a partial die corresponding to an enumeration type. */
4099 add_partial_enumeration (struct partial_die_info *enum_pdi,
4100 struct dwarf2_cu *cu)
4102 struct partial_die_info *pdi;
4104 if (enum_pdi->name != NULL)
4105 add_partial_symbol (enum_pdi, cu);
4107 pdi = enum_pdi->die_child;
4110 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4111 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4113 add_partial_symbol (pdi, cu);
4114 pdi = pdi->die_sibling;
4118 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4119 Return the corresponding abbrev, or NULL if the number is zero (indicating
4120 an empty DIE). In either case *BYTES_READ will be set to the length of
4121 the initial number. */
4123 static struct abbrev_info *
4124 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4125 struct dwarf2_cu *cu)
4127 bfd *abfd = cu->objfile->obfd;
4128 unsigned int abbrev_number;
4129 struct abbrev_info *abbrev;
4131 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4133 if (abbrev_number == 0)
4136 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4139 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4140 abbrev_number, bfd_get_filename (abfd));
4146 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4147 Returns a pointer to the end of a series of DIEs, terminated by an empty
4148 DIE. Any children of the skipped DIEs will also be skipped. */
4151 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4153 struct abbrev_info *abbrev;
4154 unsigned int bytes_read;
4158 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4160 return info_ptr + bytes_read;
4162 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4166 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4167 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4168 abbrev corresponding to that skipped uleb128 should be passed in
4169 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4173 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4174 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4176 unsigned int bytes_read;
4177 struct attribute attr;
4178 bfd *abfd = cu->objfile->obfd;
4179 unsigned int form, i;
4181 for (i = 0; i < abbrev->num_attrs; i++)
4183 /* The only abbrev we care about is DW_AT_sibling. */
4184 if (abbrev->attrs[i].name == DW_AT_sibling)
4186 read_attribute (&attr, &abbrev->attrs[i],
4187 abfd, info_ptr, cu);
4188 if (attr.form == DW_FORM_ref_addr)
4189 complaint (&symfile_complaints,
4190 _("ignoring absolute DW_AT_sibling"));
4192 return buffer + dwarf2_get_ref_die_offset (&attr);
4195 /* If it isn't DW_AT_sibling, skip this attribute. */
4196 form = abbrev->attrs[i].form;
4200 case DW_FORM_ref_addr:
4201 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4202 and later it is offset sized. */
4203 if (cu->header.version == 2)
4204 info_ptr += cu->header.addr_size;
4206 info_ptr += cu->header.offset_size;
4209 info_ptr += cu->header.addr_size;
4216 case DW_FORM_flag_present:
4228 case DW_FORM_ref_sig8:
4231 case DW_FORM_string:
4232 read_direct_string (abfd, info_ptr, &bytes_read);
4233 info_ptr += bytes_read;
4235 case DW_FORM_sec_offset:
4237 info_ptr += cu->header.offset_size;
4239 case DW_FORM_exprloc:
4241 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4242 info_ptr += bytes_read;
4244 case DW_FORM_block1:
4245 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4247 case DW_FORM_block2:
4248 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4250 case DW_FORM_block4:
4251 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4255 case DW_FORM_ref_udata:
4256 info_ptr = skip_leb128 (abfd, info_ptr);
4258 case DW_FORM_indirect:
4259 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4260 info_ptr += bytes_read;
4261 /* We need to continue parsing from here, so just go back to
4263 goto skip_attribute;
4266 error (_("Dwarf Error: Cannot handle %s "
4267 "in DWARF reader [in module %s]"),
4268 dwarf_form_name (form),
4269 bfd_get_filename (abfd));
4273 if (abbrev->has_children)
4274 return skip_children (buffer, info_ptr, cu);
4279 /* Locate ORIG_PDI's sibling.
4280 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4284 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4285 gdb_byte *buffer, gdb_byte *info_ptr,
4286 bfd *abfd, struct dwarf2_cu *cu)
4288 /* Do we know the sibling already? */
4290 if (orig_pdi->sibling)
4291 return orig_pdi->sibling;
4293 /* Are there any children to deal with? */
4295 if (!orig_pdi->has_children)
4298 /* Skip the children the long way. */
4300 return skip_children (buffer, info_ptr, cu);
4303 /* Expand this partial symbol table into a full symbol table. */
4306 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4312 warning (_("bug: psymtab for %s is already read in."),
4319 printf_filtered (_("Reading in symbols for %s..."),
4321 gdb_flush (gdb_stdout);
4324 /* Restore our global data. */
4325 dwarf2_per_objfile = objfile_data (pst->objfile,
4326 dwarf2_objfile_data_key);
4328 /* If this psymtab is constructed from a debug-only objfile, the
4329 has_section_at_zero flag will not necessarily be correct. We
4330 can get the correct value for this flag by looking at the data
4331 associated with the (presumably stripped) associated objfile. */
4332 if (pst->objfile->separate_debug_objfile_backlink)
4334 struct dwarf2_per_objfile *dpo_backlink
4335 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4336 dwarf2_objfile_data_key);
4338 dwarf2_per_objfile->has_section_at_zero
4339 = dpo_backlink->has_section_at_zero;
4342 dwarf2_per_objfile->reading_partial_symbols = 0;
4344 psymtab_to_symtab_1 (pst);
4346 /* Finish up the debug error message. */
4348 printf_filtered (_("done.\n"));
4353 /* Add PER_CU to the queue. */
4356 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4358 struct dwarf2_queue_item *item;
4361 item = xmalloc (sizeof (*item));
4362 item->per_cu = per_cu;
4365 if (dwarf2_queue == NULL)
4366 dwarf2_queue = item;
4368 dwarf2_queue_tail->next = item;
4370 dwarf2_queue_tail = item;
4373 /* Process the queue. */
4376 process_queue (struct objfile *objfile)
4378 struct dwarf2_queue_item *item, *next_item;
4380 /* The queue starts out with one item, but following a DIE reference
4381 may load a new CU, adding it to the end of the queue. */
4382 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4384 if (dwarf2_per_objfile->using_index
4385 ? !item->per_cu->v.quick->symtab
4386 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4387 process_full_comp_unit (item->per_cu);
4389 item->per_cu->queued = 0;
4390 next_item = item->next;
4394 dwarf2_queue_tail = NULL;
4397 /* Free all allocated queue entries. This function only releases anything if
4398 an error was thrown; if the queue was processed then it would have been
4399 freed as we went along. */
4402 dwarf2_release_queue (void *dummy)
4404 struct dwarf2_queue_item *item, *last;
4406 item = dwarf2_queue;
4409 /* Anything still marked queued is likely to be in an
4410 inconsistent state, so discard it. */
4411 if (item->per_cu->queued)
4413 if (item->per_cu->cu != NULL)
4414 free_one_cached_comp_unit (item->per_cu->cu);
4415 item->per_cu->queued = 0;
4423 dwarf2_queue = dwarf2_queue_tail = NULL;
4426 /* Read in full symbols for PST, and anything it depends on. */
4429 psymtab_to_symtab_1 (struct partial_symtab *pst)
4431 struct dwarf2_per_cu_data *per_cu;
4432 struct cleanup *back_to;
4435 for (i = 0; i < pst->number_of_dependencies; i++)
4436 if (!pst->dependencies[i]->readin)
4438 /* Inform about additional files that need to be read in. */
4441 /* FIXME: i18n: Need to make this a single string. */
4442 fputs_filtered (" ", gdb_stdout);
4444 fputs_filtered ("and ", gdb_stdout);
4446 printf_filtered ("%s...", pst->dependencies[i]->filename);
4447 wrap_here (""); /* Flush output. */
4448 gdb_flush (gdb_stdout);
4450 psymtab_to_symtab_1 (pst->dependencies[i]);
4453 per_cu = pst->read_symtab_private;
4457 /* It's an include file, no symbols to read for it.
4458 Everything is in the parent symtab. */
4463 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4466 /* Load the DIEs associated with PER_CU into memory. */
4469 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4470 struct objfile *objfile)
4472 bfd *abfd = objfile->obfd;
4473 struct dwarf2_cu *cu;
4474 unsigned int offset;
4475 gdb_byte *info_ptr, *beg_of_comp_unit;
4476 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4477 struct attribute *attr;
4480 gdb_assert (! per_cu->from_debug_types);
4482 /* Set local variables from the partial symbol table info. */
4483 offset = per_cu->offset;
4485 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4486 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4487 beg_of_comp_unit = info_ptr;
4489 if (per_cu->cu == NULL)
4491 cu = xmalloc (sizeof (*cu));
4492 init_one_comp_unit (cu, objfile);
4496 /* If an error occurs while loading, release our storage. */
4497 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4499 /* Read in the comp_unit header. */
4500 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4502 /* Complete the cu_header. */
4503 cu->header.offset = offset;
4504 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4506 /* Read the abbrevs for this compilation unit. */
4507 dwarf2_read_abbrevs (abfd, cu);
4508 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4510 /* Link this compilation unit into the compilation unit tree. */
4512 cu->per_cu = per_cu;
4514 /* Link this CU into read_in_chain. */
4515 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4516 dwarf2_per_objfile->read_in_chain = per_cu;
4521 info_ptr += cu->header.first_die_offset;
4524 cu->dies = read_comp_unit (info_ptr, cu);
4526 /* We try not to read any attributes in this function, because not
4527 all objfiles needed for references have been loaded yet, and symbol
4528 table processing isn't initialized. But we have to set the CU language,
4529 or we won't be able to build types correctly. */
4530 prepare_one_comp_unit (cu, cu->dies);
4532 /* Similarly, if we do not read the producer, we can not apply
4533 producer-specific interpretation. */
4534 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4536 cu->producer = DW_STRING (attr);
4540 do_cleanups (free_abbrevs_cleanup);
4542 /* We've successfully allocated this compilation unit. Let our
4543 caller clean it up when finished with it. */
4544 discard_cleanups (free_cu_cleanup);
4548 /* Add a DIE to the delayed physname list. */
4551 add_to_method_list (struct type *type, int fnfield_index, int index,
4552 const char *name, struct die_info *die,
4553 struct dwarf2_cu *cu)
4555 struct delayed_method_info mi;
4557 mi.fnfield_index = fnfield_index;
4561 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4564 /* A cleanup for freeing the delayed method list. */
4567 free_delayed_list (void *ptr)
4569 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4570 if (cu->method_list != NULL)
4572 VEC_free (delayed_method_info, cu->method_list);
4573 cu->method_list = NULL;
4577 /* Compute the physnames of any methods on the CU's method list.
4579 The computation of method physnames is delayed in order to avoid the
4580 (bad) condition that one of the method's formal parameters is of an as yet
4584 compute_delayed_physnames (struct dwarf2_cu *cu)
4587 struct delayed_method_info *mi;
4588 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4591 struct fn_fieldlist *fn_flp
4592 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4593 physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu);
4594 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4598 /* Check for GCC >= 4.0. */
4601 producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
4606 if (cu->producer == NULL)
4608 /* For unknown compilers expect their behavior is not compliant. For GCC
4609 this case can also happen for -gdwarf-4 type units supported since
4615 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4617 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
4619 /* For non-GCC compilers expect their behavior is not compliant. */
4623 cs = &cu->producer[strlen ("GNU ")];
4624 while (*cs && !isdigit (*cs))
4626 if (sscanf (cs, "%d.%d", &major, &minor) != 2)
4628 /* Not recognized as GCC. */
4636 /* Generate full symbol information for PST and CU, whose DIEs have
4637 already been loaded into memory. */
4640 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4642 struct dwarf2_cu *cu = per_cu->cu;
4643 struct objfile *objfile = per_cu->objfile;
4644 CORE_ADDR lowpc, highpc;
4645 struct symtab *symtab;
4646 struct cleanup *back_to, *delayed_list_cleanup;
4649 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4652 back_to = make_cleanup (really_free_pendings, NULL);
4653 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4655 cu->list_in_scope = &file_symbols;
4657 dwarf2_find_base_address (cu->dies, cu);
4659 /* Do line number decoding in read_file_scope () */
4660 process_die (cu->dies, cu);
4662 /* Now that we have processed all the DIEs in the CU, all the types
4663 should be complete, and it should now be safe to compute all of the
4665 compute_delayed_physnames (cu);
4666 do_cleanups (delayed_list_cleanup);
4668 /* Some compilers don't define a DW_AT_high_pc attribute for the
4669 compilation unit. If the DW_AT_high_pc is missing, synthesize
4670 it, by scanning the DIE's below the compilation unit. */
4671 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4673 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4677 /* Set symtab language to language from DW_AT_language. If the
4678 compilation is from a C file generated by language preprocessors, do
4679 not set the language if it was already deduced by start_subfile. */
4680 if (!(cu->language == language_c && symtab->language != language_c))
4681 symtab->language = cu->language;
4683 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4684 produce DW_AT_location with location lists but it can be possibly
4685 invalid without -fvar-tracking.
4687 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4688 needed, it would be wrong due to missing DW_AT_producer there.
4690 Still one can confuse GDB by using non-standard GCC compilation
4691 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4693 if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu))
4694 symtab->locations_valid = 1;
4697 if (dwarf2_per_objfile->using_index)
4698 per_cu->v.quick->symtab = symtab;
4701 struct partial_symtab *pst = per_cu->v.psymtab;
4702 pst->symtab = symtab;
4706 do_cleanups (back_to);
4709 /* Process a die and its children. */
4712 process_die (struct die_info *die, struct dwarf2_cu *cu)
4716 case DW_TAG_padding:
4718 case DW_TAG_compile_unit:
4719 read_file_scope (die, cu);
4721 case DW_TAG_type_unit:
4722 read_type_unit_scope (die, cu);
4724 case DW_TAG_subprogram:
4725 case DW_TAG_inlined_subroutine:
4726 read_func_scope (die, cu);
4728 case DW_TAG_lexical_block:
4729 case DW_TAG_try_block:
4730 case DW_TAG_catch_block:
4731 read_lexical_block_scope (die, cu);
4733 case DW_TAG_class_type:
4734 case DW_TAG_interface_type:
4735 case DW_TAG_structure_type:
4736 case DW_TAG_union_type:
4737 process_structure_scope (die, cu);
4739 case DW_TAG_enumeration_type:
4740 process_enumeration_scope (die, cu);
4743 /* These dies have a type, but processing them does not create
4744 a symbol or recurse to process the children. Therefore we can
4745 read them on-demand through read_type_die. */
4746 case DW_TAG_subroutine_type:
4747 case DW_TAG_set_type:
4748 case DW_TAG_array_type:
4749 case DW_TAG_pointer_type:
4750 case DW_TAG_ptr_to_member_type:
4751 case DW_TAG_reference_type:
4752 case DW_TAG_string_type:
4755 case DW_TAG_base_type:
4756 case DW_TAG_subrange_type:
4757 case DW_TAG_typedef:
4758 /* Add a typedef symbol for the type definition, if it has a
4760 new_symbol (die, read_type_die (die, cu), cu);
4762 case DW_TAG_common_block:
4763 read_common_block (die, cu);
4765 case DW_TAG_common_inclusion:
4767 case DW_TAG_namespace:
4768 processing_has_namespace_info = 1;
4769 read_namespace (die, cu);
4772 processing_has_namespace_info = 1;
4773 read_module (die, cu);
4775 case DW_TAG_imported_declaration:
4776 case DW_TAG_imported_module:
4777 processing_has_namespace_info = 1;
4778 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4779 || cu->language != language_fortran))
4780 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4781 dwarf_tag_name (die->tag));
4782 read_import_statement (die, cu);
4785 new_symbol (die, NULL, cu);
4790 /* A helper function for dwarf2_compute_name which determines whether DIE
4791 needs to have the name of the scope prepended to the name listed in the
4795 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4797 struct attribute *attr;
4801 case DW_TAG_namespace:
4802 case DW_TAG_typedef:
4803 case DW_TAG_class_type:
4804 case DW_TAG_interface_type:
4805 case DW_TAG_structure_type:
4806 case DW_TAG_union_type:
4807 case DW_TAG_enumeration_type:
4808 case DW_TAG_enumerator:
4809 case DW_TAG_subprogram:
4813 case DW_TAG_variable:
4814 case DW_TAG_constant:
4815 /* We only need to prefix "globally" visible variables. These include
4816 any variable marked with DW_AT_external or any variable that
4817 lives in a namespace. [Variables in anonymous namespaces
4818 require prefixing, but they are not DW_AT_external.] */
4820 if (dwarf2_attr (die, DW_AT_specification, cu))
4822 struct dwarf2_cu *spec_cu = cu;
4824 return die_needs_namespace (die_specification (die, &spec_cu),
4828 attr = dwarf2_attr (die, DW_AT_external, cu);
4829 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4830 && die->parent->tag != DW_TAG_module)
4832 /* A variable in a lexical block of some kind does not need a
4833 namespace, even though in C++ such variables may be external
4834 and have a mangled name. */
4835 if (die->parent->tag == DW_TAG_lexical_block
4836 || die->parent->tag == DW_TAG_try_block
4837 || die->parent->tag == DW_TAG_catch_block
4838 || die->parent->tag == DW_TAG_subprogram)
4847 /* Retrieve the last character from a mem_file. */
4850 do_ui_file_peek_last (void *object, const char *buffer, long length)
4852 char *last_char_p = (char *) object;
4855 *last_char_p = buffer[length - 1];
4858 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4859 compute the physname for the object, which include a method's
4860 formal parameters (C++/Java) and return type (Java).
4862 For Ada, return the DIE's linkage name rather than the fully qualified
4863 name. PHYSNAME is ignored..
4865 The result is allocated on the objfile_obstack and canonicalized. */
4868 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4872 name = dwarf2_name (die, cu);
4874 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4875 compute it by typename_concat inside GDB. */
4876 if (cu->language == language_ada
4877 || (cu->language == language_fortran && physname))
4879 /* For Ada unit, we prefer the linkage name over the name, as
4880 the former contains the exported name, which the user expects
4881 to be able to reference. Ideally, we want the user to be able
4882 to reference this entity using either natural or linkage name,
4883 but we haven't started looking at this enhancement yet. */
4884 struct attribute *attr;
4886 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4888 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4889 if (attr && DW_STRING (attr))
4890 return DW_STRING (attr);
4893 /* These are the only languages we know how to qualify names in. */
4895 && (cu->language == language_cplus || cu->language == language_java
4896 || cu->language == language_fortran))
4898 if (die_needs_namespace (die, cu))
4902 struct ui_file *buf;
4904 prefix = determine_prefix (die, cu);
4905 buf = mem_fileopen ();
4906 if (*prefix != '\0')
4908 char *prefixed_name = typename_concat (NULL, prefix, name,
4911 fputs_unfiltered (prefixed_name, buf);
4912 xfree (prefixed_name);
4915 fputs_unfiltered (name, buf);
4917 /* Template parameters may be specified in the DIE's DW_AT_name, or
4918 as children with DW_TAG_template_type_param or
4919 DW_TAG_value_type_param. If the latter, add them to the name
4920 here. If the name already has template parameters, then
4921 skip this step; some versions of GCC emit both, and
4922 it is more efficient to use the pre-computed name.
4924 Something to keep in mind about this process: it is very
4925 unlikely, or in some cases downright impossible, to produce
4926 something that will match the mangled name of a function.
4927 If the definition of the function has the same debug info,
4928 we should be able to match up with it anyway. But fallbacks
4929 using the minimal symbol, for instance to find a method
4930 implemented in a stripped copy of libstdc++, will not work.
4931 If we do not have debug info for the definition, we will have to
4932 match them up some other way.
4934 When we do name matching there is a related problem with function
4935 templates; two instantiated function templates are allowed to
4936 differ only by their return types, which we do not add here. */
4938 if (cu->language == language_cplus && strchr (name, '<') == NULL)
4940 struct attribute *attr;
4941 struct die_info *child;
4944 die->building_fullname = 1;
4946 for (child = die->child; child != NULL; child = child->sibling)
4951 struct dwarf2_locexpr_baton *baton;
4954 if (child->tag != DW_TAG_template_type_param
4955 && child->tag != DW_TAG_template_value_param)
4960 fputs_unfiltered ("<", buf);
4964 fputs_unfiltered (", ", buf);
4966 attr = dwarf2_attr (child, DW_AT_type, cu);
4969 complaint (&symfile_complaints,
4970 _("template parameter missing DW_AT_type"));
4971 fputs_unfiltered ("UNKNOWN_TYPE", buf);
4974 type = die_type (child, cu);
4976 if (child->tag == DW_TAG_template_type_param)
4978 c_print_type (type, "", buf, -1, 0);
4982 attr = dwarf2_attr (child, DW_AT_const_value, cu);
4985 complaint (&symfile_complaints,
4986 _("template parameter missing "
4987 "DW_AT_const_value"));
4988 fputs_unfiltered ("UNKNOWN_VALUE", buf);
4992 dwarf2_const_value_attr (attr, type, name,
4993 &cu->comp_unit_obstack, cu,
4994 &value, &bytes, &baton);
4996 if (TYPE_NOSIGN (type))
4997 /* GDB prints characters as NUMBER 'CHAR'. If that's
4998 changed, this can use value_print instead. */
4999 c_printchar (value, type, buf);
5002 struct value_print_options opts;
5005 v = dwarf2_evaluate_loc_desc (type, NULL,
5009 else if (bytes != NULL)
5011 v = allocate_value (type);
5012 memcpy (value_contents_writeable (v), bytes,
5013 TYPE_LENGTH (type));
5016 v = value_from_longest (type, value);
5018 /* Specify decimal so that we do not depend on
5020 get_formatted_print_options (&opts, 'd');
5022 value_print (v, buf, &opts);
5028 die->building_fullname = 0;
5032 /* Close the argument list, with a space if necessary
5033 (nested templates). */
5034 char last_char = '\0';
5035 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5036 if (last_char == '>')
5037 fputs_unfiltered (" >", buf);
5039 fputs_unfiltered (">", buf);
5043 /* For Java and C++ methods, append formal parameter type
5044 information, if PHYSNAME. */
5046 if (physname && die->tag == DW_TAG_subprogram
5047 && (cu->language == language_cplus
5048 || cu->language == language_java))
5050 struct type *type = read_type_die (die, cu);
5052 c_type_print_args (type, buf, 1, cu->language);
5054 if (cu->language == language_java)
5056 /* For java, we must append the return type to method
5058 if (die->tag == DW_TAG_subprogram)
5059 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5062 else if (cu->language == language_cplus)
5064 /* Assume that an artificial first parameter is
5065 "this", but do not crash if it is not. RealView
5066 marks unnamed (and thus unused) parameters as
5067 artificial; there is no way to differentiate
5069 if (TYPE_NFIELDS (type) > 0
5070 && TYPE_FIELD_ARTIFICIAL (type, 0)
5071 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5072 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5074 fputs_unfiltered (" const", buf);
5078 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5080 ui_file_delete (buf);
5082 if (cu->language == language_cplus)
5085 = dwarf2_canonicalize_name (name, cu,
5086 &cu->objfile->objfile_obstack);
5097 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5098 If scope qualifiers are appropriate they will be added. The result
5099 will be allocated on the objfile_obstack, or NULL if the DIE does
5100 not have a name. NAME may either be from a previous call to
5101 dwarf2_name or NULL.
5103 The output string will be canonicalized (if C++/Java). */
5106 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5108 return dwarf2_compute_name (name, die, cu, 0);
5111 /* Construct a physname for the given DIE in CU. NAME may either be
5112 from a previous call to dwarf2_name or NULL. The result will be
5113 allocated on the objfile_objstack or NULL if the DIE does not have a
5116 The output string will be canonicalized (if C++/Java). */
5119 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5121 struct attribute *attr;
5122 const char *retval, *mangled = NULL, *canon = NULL;
5123 struct cleanup *back_to;
5126 /* In this case dwarf2_compute_name is just a shortcut not building anything
5128 if (!die_needs_namespace (die, cu))
5129 return dwarf2_compute_name (name, die, cu, 1);
5131 back_to = make_cleanup (null_cleanup, NULL);
5133 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5135 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5137 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5139 if (attr && DW_STRING (attr))
5143 mangled = DW_STRING (attr);
5145 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5146 type. It is easier for GDB users to search for such functions as
5147 `name(params)' than `long name(params)'. In such case the minimal
5148 symbol names do not match the full symbol names but for template
5149 functions there is never a need to look up their definition from their
5150 declaration so the only disadvantage remains the minimal symbol
5151 variant `long name(params)' does not have the proper inferior type.
5154 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5155 | (cu->language == language_java
5156 ? DMGL_JAVA | DMGL_RET_POSTFIX
5160 make_cleanup (xfree, demangled);
5170 if (canon == NULL || check_physname)
5172 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5174 if (canon != NULL && strcmp (physname, canon) != 0)
5176 /* It may not mean a bug in GDB. The compiler could also
5177 compute DW_AT_linkage_name incorrectly. But in such case
5178 GDB would need to be bug-to-bug compatible. */
5180 complaint (&symfile_complaints,
5181 _("Computed physname <%s> does not match demangled <%s> "
5182 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5183 physname, canon, mangled, die->offset, cu->objfile->name);
5185 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5186 is available here - over computed PHYSNAME. It is safer
5187 against both buggy GDB and buggy compilers. */
5201 retval = obsavestring (retval, strlen (retval),
5202 &cu->objfile->objfile_obstack);
5204 do_cleanups (back_to);
5208 /* Read the import statement specified by the given die and record it. */
5211 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5213 struct attribute *import_attr;
5214 struct die_info *imported_die;
5215 struct dwarf2_cu *imported_cu;
5216 const char *imported_name;
5217 const char *imported_name_prefix;
5218 const char *canonical_name;
5219 const char *import_alias;
5220 const char *imported_declaration = NULL;
5221 const char *import_prefix;
5225 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5226 if (import_attr == NULL)
5228 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5229 dwarf_tag_name (die->tag));
5234 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5235 imported_name = dwarf2_name (imported_die, imported_cu);
5236 if (imported_name == NULL)
5238 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5240 The import in the following code:
5254 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5255 <52> DW_AT_decl_file : 1
5256 <53> DW_AT_decl_line : 6
5257 <54> DW_AT_import : <0x75>
5258 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5260 <5b> DW_AT_decl_file : 1
5261 <5c> DW_AT_decl_line : 2
5262 <5d> DW_AT_type : <0x6e>
5264 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5265 <76> DW_AT_byte_size : 4
5266 <77> DW_AT_encoding : 5 (signed)
5268 imports the wrong die ( 0x75 instead of 0x58 ).
5269 This case will be ignored until the gcc bug is fixed. */
5273 /* Figure out the local name after import. */
5274 import_alias = dwarf2_name (die, cu);
5276 /* Figure out where the statement is being imported to. */
5277 import_prefix = determine_prefix (die, cu);
5279 /* Figure out what the scope of the imported die is and prepend it
5280 to the name of the imported die. */
5281 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5283 if (imported_die->tag != DW_TAG_namespace
5284 && imported_die->tag != DW_TAG_module)
5286 imported_declaration = imported_name;
5287 canonical_name = imported_name_prefix;
5289 else if (strlen (imported_name_prefix) > 0)
5291 temp = alloca (strlen (imported_name_prefix)
5292 + 2 + strlen (imported_name) + 1);
5293 strcpy (temp, imported_name_prefix);
5294 strcat (temp, "::");
5295 strcat (temp, imported_name);
5296 canonical_name = temp;
5299 canonical_name = imported_name;
5301 cp_add_using_directive (import_prefix,
5304 imported_declaration,
5305 &cu->objfile->objfile_obstack);
5309 initialize_cu_func_list (struct dwarf2_cu *cu)
5311 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5314 /* Cleanup function for read_file_scope. */
5317 free_cu_line_header (void *arg)
5319 struct dwarf2_cu *cu = arg;
5321 free_line_header (cu->line_header);
5322 cu->line_header = NULL;
5326 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5327 char **name, char **comp_dir)
5329 struct attribute *attr;
5334 /* Find the filename. Do not use dwarf2_name here, since the filename
5335 is not a source language identifier. */
5336 attr = dwarf2_attr (die, DW_AT_name, cu);
5339 *name = DW_STRING (attr);
5342 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5344 *comp_dir = DW_STRING (attr);
5345 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5347 *comp_dir = ldirname (*name);
5348 if (*comp_dir != NULL)
5349 make_cleanup (xfree, *comp_dir);
5351 if (*comp_dir != NULL)
5353 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5354 directory, get rid of it. */
5355 char *cp = strchr (*comp_dir, ':');
5357 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5362 *name = "<unknown>";
5365 /* Process DW_TAG_compile_unit. */
5368 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5370 struct objfile *objfile = cu->objfile;
5371 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5372 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5373 CORE_ADDR highpc = ((CORE_ADDR) 0);
5374 struct attribute *attr;
5376 char *comp_dir = NULL;
5377 struct die_info *child_die;
5378 bfd *abfd = objfile->obfd;
5379 struct line_header *line_header = 0;
5382 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5384 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5386 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5387 from finish_block. */
5388 if (lowpc == ((CORE_ADDR) -1))
5393 find_file_and_directory (die, cu, &name, &comp_dir);
5395 attr = dwarf2_attr (die, DW_AT_language, cu);
5398 set_cu_language (DW_UNSND (attr), cu);
5401 attr = dwarf2_attr (die, DW_AT_producer, cu);
5403 cu->producer = DW_STRING (attr);
5405 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5406 standardised yet. As a workaround for the language detection we fall
5407 back to the DW_AT_producer string. */
5408 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5409 cu->language = language_opencl;
5411 /* We assume that we're processing GCC output. */
5412 processing_gcc_compilation = 2;
5414 processing_has_namespace_info = 0;
5416 start_symtab (name, comp_dir, lowpc);
5417 record_debugformat ("DWARF 2");
5418 record_producer (cu->producer);
5420 initialize_cu_func_list (cu);
5422 /* Decode line number information if present. We do this before
5423 processing child DIEs, so that the line header table is available
5424 for DW_AT_decl_file. */
5425 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5428 unsigned int line_offset = DW_UNSND (attr);
5429 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
5432 cu->line_header = line_header;
5433 make_cleanup (free_cu_line_header, cu);
5434 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5438 /* Process all dies in compilation unit. */
5439 if (die->child != NULL)
5441 child_die = die->child;
5442 while (child_die && child_die->tag)
5444 process_die (child_die, cu);
5445 child_die = sibling_die (child_die);
5449 /* Decode macro information, if present. Dwarf 2 macro information
5450 refers to information in the line number info statement program
5451 header, so we can only read it if we've read the header
5453 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5454 if (attr && line_header)
5456 unsigned int macro_offset = DW_UNSND (attr);
5458 dwarf_decode_macros (line_header, macro_offset,
5459 comp_dir, abfd, cu);
5461 do_cleanups (back_to);
5464 /* Process DW_TAG_type_unit.
5465 For TUs we want to skip the first top level sibling if it's not the
5466 actual type being defined by this TU. In this case the first top
5467 level sibling is there to provide context only. */
5470 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5472 struct objfile *objfile = cu->objfile;
5473 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5475 struct attribute *attr;
5477 char *comp_dir = NULL;
5478 struct die_info *child_die;
5479 bfd *abfd = objfile->obfd;
5481 /* start_symtab needs a low pc, but we don't really have one.
5482 Do what read_file_scope would do in the absence of such info. */
5483 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5485 /* Find the filename. Do not use dwarf2_name here, since the filename
5486 is not a source language identifier. */
5487 attr = dwarf2_attr (die, DW_AT_name, cu);
5489 name = DW_STRING (attr);
5491 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5493 comp_dir = DW_STRING (attr);
5494 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5496 comp_dir = ldirname (name);
5497 if (comp_dir != NULL)
5498 make_cleanup (xfree, comp_dir);
5504 attr = dwarf2_attr (die, DW_AT_language, cu);
5506 set_cu_language (DW_UNSND (attr), cu);
5508 /* This isn't technically needed today. It is done for symmetry
5509 with read_file_scope. */
5510 attr = dwarf2_attr (die, DW_AT_producer, cu);
5512 cu->producer = DW_STRING (attr);
5514 /* We assume that we're processing GCC output. */
5515 processing_gcc_compilation = 2;
5517 processing_has_namespace_info = 0;
5519 start_symtab (name, comp_dir, lowpc);
5520 record_debugformat ("DWARF 2");
5521 record_producer (cu->producer);
5523 /* Process the dies in the type unit. */
5524 if (die->child == NULL)
5526 dump_die_for_error (die);
5527 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5528 bfd_get_filename (abfd));
5531 child_die = die->child;
5533 while (child_die && child_die->tag)
5535 process_die (child_die, cu);
5537 child_die = sibling_die (child_die);
5540 do_cleanups (back_to);
5544 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5545 struct dwarf2_cu *cu)
5547 struct function_range *thisfn;
5549 thisfn = (struct function_range *)
5550 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5551 thisfn->name = name;
5552 thisfn->lowpc = lowpc;
5553 thisfn->highpc = highpc;
5554 thisfn->seen_line = 0;
5555 thisfn->next = NULL;
5557 if (cu->last_fn == NULL)
5558 cu->first_fn = thisfn;
5560 cu->last_fn->next = thisfn;
5562 cu->last_fn = thisfn;
5565 /* qsort helper for inherit_abstract_dies. */
5568 unsigned_int_compar (const void *ap, const void *bp)
5570 unsigned int a = *(unsigned int *) ap;
5571 unsigned int b = *(unsigned int *) bp;
5573 return (a > b) - (b > a);
5576 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5577 Inherit only the children of the DW_AT_abstract_origin DIE not being
5578 already referenced by DW_AT_abstract_origin from the children of the
5582 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5584 struct die_info *child_die;
5585 unsigned die_children_count;
5586 /* CU offsets which were referenced by children of the current DIE. */
5588 unsigned *offsets_end, *offsetp;
5589 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5590 struct die_info *origin_die;
5591 /* Iterator of the ORIGIN_DIE children. */
5592 struct die_info *origin_child_die;
5593 struct cleanup *cleanups;
5594 struct attribute *attr;
5595 struct dwarf2_cu *origin_cu;
5596 struct pending **origin_previous_list_in_scope;
5598 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5602 /* Note that following die references may follow to a die in a
5606 origin_die = follow_die_ref (die, attr, &origin_cu);
5608 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5610 origin_previous_list_in_scope = origin_cu->list_in_scope;
5611 origin_cu->list_in_scope = cu->list_in_scope;
5613 if (die->tag != origin_die->tag
5614 && !(die->tag == DW_TAG_inlined_subroutine
5615 && origin_die->tag == DW_TAG_subprogram))
5616 complaint (&symfile_complaints,
5617 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5618 die->offset, origin_die->offset);
5620 child_die = die->child;
5621 die_children_count = 0;
5622 while (child_die && child_die->tag)
5624 child_die = sibling_die (child_die);
5625 die_children_count++;
5627 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5628 cleanups = make_cleanup (xfree, offsets);
5630 offsets_end = offsets;
5631 child_die = die->child;
5632 while (child_die && child_die->tag)
5634 /* For each CHILD_DIE, find the corresponding child of
5635 ORIGIN_DIE. If there is more than one layer of
5636 DW_AT_abstract_origin, follow them all; there shouldn't be,
5637 but GCC versions at least through 4.4 generate this (GCC PR
5639 struct die_info *child_origin_die = child_die;
5640 struct dwarf2_cu *child_origin_cu = cu;
5644 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5648 child_origin_die = follow_die_ref (child_origin_die, attr,
5652 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5653 counterpart may exist. */
5654 if (child_origin_die != child_die)
5656 if (child_die->tag != child_origin_die->tag
5657 && !(child_die->tag == DW_TAG_inlined_subroutine
5658 && child_origin_die->tag == DW_TAG_subprogram))
5659 complaint (&symfile_complaints,
5660 _("Child DIE 0x%x and its abstract origin 0x%x have "
5661 "different tags"), child_die->offset,
5662 child_origin_die->offset);
5663 if (child_origin_die->parent != origin_die)
5664 complaint (&symfile_complaints,
5665 _("Child DIE 0x%x and its abstract origin 0x%x have "
5666 "different parents"), child_die->offset,
5667 child_origin_die->offset);
5669 *offsets_end++ = child_origin_die->offset;
5671 child_die = sibling_die (child_die);
5673 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5674 unsigned_int_compar);
5675 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5676 if (offsetp[-1] == *offsetp)
5677 complaint (&symfile_complaints,
5678 _("Multiple children of DIE 0x%x refer "
5679 "to DIE 0x%x as their abstract origin"),
5680 die->offset, *offsetp);
5683 origin_child_die = origin_die->child;
5684 while (origin_child_die && origin_child_die->tag)
5686 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5687 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5689 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5691 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5692 process_die (origin_child_die, origin_cu);
5694 origin_child_die = sibling_die (origin_child_die);
5696 origin_cu->list_in_scope = origin_previous_list_in_scope;
5698 do_cleanups (cleanups);
5702 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5704 struct objfile *objfile = cu->objfile;
5705 struct context_stack *new;
5708 struct die_info *child_die;
5709 struct attribute *attr, *call_line, *call_file;
5712 struct block *block;
5713 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5714 VEC (symbolp) *template_args = NULL;
5715 struct template_symbol *templ_func = NULL;
5719 /* If we do not have call site information, we can't show the
5720 caller of this inlined function. That's too confusing, so
5721 only use the scope for local variables. */
5722 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5723 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5724 if (call_line == NULL || call_file == NULL)
5726 read_lexical_block_scope (die, cu);
5731 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5733 name = dwarf2_name (die, cu);
5735 /* Ignore functions with missing or empty names. These are actually
5736 illegal according to the DWARF standard. */
5739 complaint (&symfile_complaints,
5740 _("missing name for subprogram DIE at %d"), die->offset);
5744 /* Ignore functions with missing or invalid low and high pc attributes. */
5745 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5747 attr = dwarf2_attr (die, DW_AT_external, cu);
5748 if (!attr || !DW_UNSND (attr))
5749 complaint (&symfile_complaints,
5750 _("cannot get low and high bounds "
5751 "for subprogram DIE at %d"),
5759 /* Record the function range for dwarf_decode_lines. */
5760 add_to_cu_func_list (name, lowpc, highpc, cu);
5762 /* If we have any template arguments, then we must allocate a
5763 different sort of symbol. */
5764 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5766 if (child_die->tag == DW_TAG_template_type_param
5767 || child_die->tag == DW_TAG_template_value_param)
5769 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5770 struct template_symbol);
5771 templ_func->base.is_cplus_template_function = 1;
5776 new = push_context (0, lowpc);
5777 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5778 (struct symbol *) templ_func);
5780 /* If there is a location expression for DW_AT_frame_base, record
5782 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5784 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5785 expression is being recorded directly in the function's symbol
5786 and not in a separate frame-base object. I guess this hack is
5787 to avoid adding some sort of frame-base adjunct/annex to the
5788 function's symbol :-(. The problem with doing this is that it
5789 results in a function symbol with a location expression that
5790 has nothing to do with the location of the function, ouch! The
5791 relationship should be: a function's symbol has-a frame base; a
5792 frame-base has-a location expression. */
5793 dwarf2_symbol_mark_computed (attr, new->name, cu);
5795 cu->list_in_scope = &local_symbols;
5797 if (die->child != NULL)
5799 child_die = die->child;
5800 while (child_die && child_die->tag)
5802 if (child_die->tag == DW_TAG_template_type_param
5803 || child_die->tag == DW_TAG_template_value_param)
5805 struct symbol *arg = new_symbol (child_die, NULL, cu);
5808 VEC_safe_push (symbolp, template_args, arg);
5811 process_die (child_die, cu);
5812 child_die = sibling_die (child_die);
5816 inherit_abstract_dies (die, cu);
5818 /* If we have a DW_AT_specification, we might need to import using
5819 directives from the context of the specification DIE. See the
5820 comment in determine_prefix. */
5821 if (cu->language == language_cplus
5822 && dwarf2_attr (die, DW_AT_specification, cu))
5824 struct dwarf2_cu *spec_cu = cu;
5825 struct die_info *spec_die = die_specification (die, &spec_cu);
5829 child_die = spec_die->child;
5830 while (child_die && child_die->tag)
5832 if (child_die->tag == DW_TAG_imported_module)
5833 process_die (child_die, spec_cu);
5834 child_die = sibling_die (child_die);
5837 /* In some cases, GCC generates specification DIEs that
5838 themselves contain DW_AT_specification attributes. */
5839 spec_die = die_specification (spec_die, &spec_cu);
5843 new = pop_context ();
5844 /* Make a block for the local symbols within. */
5845 block = finish_block (new->name, &local_symbols, new->old_blocks,
5846 lowpc, highpc, objfile);
5848 /* For C++, set the block's scope. */
5849 if (cu->language == language_cplus || cu->language == language_fortran)
5850 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5851 determine_prefix (die, cu),
5852 processing_has_namespace_info);
5854 /* If we have address ranges, record them. */
5855 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5857 /* Attach template arguments to function. */
5858 if (! VEC_empty (symbolp, template_args))
5860 gdb_assert (templ_func != NULL);
5862 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
5863 templ_func->template_arguments
5864 = obstack_alloc (&objfile->objfile_obstack,
5865 (templ_func->n_template_arguments
5866 * sizeof (struct symbol *)));
5867 memcpy (templ_func->template_arguments,
5868 VEC_address (symbolp, template_args),
5869 (templ_func->n_template_arguments * sizeof (struct symbol *)));
5870 VEC_free (symbolp, template_args);
5873 /* In C++, we can have functions nested inside functions (e.g., when
5874 a function declares a class that has methods). This means that
5875 when we finish processing a function scope, we may need to go
5876 back to building a containing block's symbol lists. */
5877 local_symbols = new->locals;
5878 param_symbols = new->params;
5879 using_directives = new->using_directives;
5881 /* If we've finished processing a top-level function, subsequent
5882 symbols go in the file symbol list. */
5883 if (outermost_context_p ())
5884 cu->list_in_scope = &file_symbols;
5887 /* Process all the DIES contained within a lexical block scope. Start
5888 a new scope, process the dies, and then close the scope. */
5891 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5893 struct objfile *objfile = cu->objfile;
5894 struct context_stack *new;
5895 CORE_ADDR lowpc, highpc;
5896 struct die_info *child_die;
5899 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5901 /* Ignore blocks with missing or invalid low and high pc attributes. */
5902 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5903 as multiple lexical blocks? Handling children in a sane way would
5904 be nasty. Might be easier to properly extend generic blocks to
5906 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5911 push_context (0, lowpc);
5912 if (die->child != NULL)
5914 child_die = die->child;
5915 while (child_die && child_die->tag)
5917 process_die (child_die, cu);
5918 child_die = sibling_die (child_die);
5921 new = pop_context ();
5923 if (local_symbols != NULL || using_directives != NULL)
5926 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5929 /* Note that recording ranges after traversing children, as we
5930 do here, means that recording a parent's ranges entails
5931 walking across all its children's ranges as they appear in
5932 the address map, which is quadratic behavior.
5934 It would be nicer to record the parent's ranges before
5935 traversing its children, simply overriding whatever you find
5936 there. But since we don't even decide whether to create a
5937 block until after we've traversed its children, that's hard
5939 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5941 local_symbols = new->locals;
5942 using_directives = new->using_directives;
5945 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5946 Return 1 if the attributes are present and valid, otherwise, return 0.
5947 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5950 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5951 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5952 struct partial_symtab *ranges_pst)
5954 struct objfile *objfile = cu->objfile;
5955 struct comp_unit_head *cu_header = &cu->header;
5956 bfd *obfd = objfile->obfd;
5957 unsigned int addr_size = cu_header->addr_size;
5958 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5959 /* Base address selection entry. */
5970 found_base = cu->base_known;
5971 base = cu->base_address;
5973 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5974 if (offset >= dwarf2_per_objfile->ranges.size)
5976 complaint (&symfile_complaints,
5977 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5981 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5983 /* Read in the largest possible address. */
5984 marker = read_address (obfd, buffer, cu, &dummy);
5985 if ((marker & mask) == mask)
5987 /* If we found the largest possible address, then
5988 read the base address. */
5989 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5990 buffer += 2 * addr_size;
5991 offset += 2 * addr_size;
5997 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6001 CORE_ADDR range_beginning, range_end;
6003 range_beginning = read_address (obfd, buffer, cu, &dummy);
6004 buffer += addr_size;
6005 range_end = read_address (obfd, buffer, cu, &dummy);
6006 buffer += addr_size;
6007 offset += 2 * addr_size;
6009 /* An end of list marker is a pair of zero addresses. */
6010 if (range_beginning == 0 && range_end == 0)
6011 /* Found the end of list entry. */
6014 /* Each base address selection entry is a pair of 2 values.
6015 The first is the largest possible address, the second is
6016 the base address. Check for a base address here. */
6017 if ((range_beginning & mask) == mask)
6019 /* If we found the largest possible address, then
6020 read the base address. */
6021 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6028 /* We have no valid base address for the ranges
6030 complaint (&symfile_complaints,
6031 _("Invalid .debug_ranges data (no base address)"));
6035 if (range_beginning > range_end)
6037 /* Inverted range entries are invalid. */
6038 complaint (&symfile_complaints,
6039 _("Invalid .debug_ranges data (inverted range)"));
6043 /* Empty range entries have no effect. */
6044 if (range_beginning == range_end)
6047 range_beginning += base;
6050 if (ranges_pst != NULL)
6051 addrmap_set_empty (objfile->psymtabs_addrmap,
6052 range_beginning + baseaddr,
6053 range_end - 1 + baseaddr,
6056 /* FIXME: This is recording everything as a low-high
6057 segment of consecutive addresses. We should have a
6058 data structure for discontiguous block ranges
6062 low = range_beginning;
6068 if (range_beginning < low)
6069 low = range_beginning;
6070 if (range_end > high)
6076 /* If the first entry is an end-of-list marker, the range
6077 describes an empty scope, i.e. no instructions. */
6083 *high_return = high;
6087 /* Get low and high pc attributes from a die. Return 1 if the attributes
6088 are present and valid, otherwise, return 0. Return -1 if the range is
6089 discontinuous, i.e. derived from DW_AT_ranges information. */
6091 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6092 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6093 struct partial_symtab *pst)
6095 struct attribute *attr;
6100 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6103 high = DW_ADDR (attr);
6104 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6106 low = DW_ADDR (attr);
6108 /* Found high w/o low attribute. */
6111 /* Found consecutive range of addresses. */
6116 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6119 /* Value of the DW_AT_ranges attribute is the offset in the
6120 .debug_ranges section. */
6121 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6123 /* Found discontinuous range of addresses. */
6128 /* read_partial_die has also the strict LOW < HIGH requirement. */
6132 /* When using the GNU linker, .gnu.linkonce. sections are used to
6133 eliminate duplicate copies of functions and vtables and such.
6134 The linker will arbitrarily choose one and discard the others.
6135 The AT_*_pc values for such functions refer to local labels in
6136 these sections. If the section from that file was discarded, the
6137 labels are not in the output, so the relocs get a value of 0.
6138 If this is a discarded function, mark the pc bounds as invalid,
6139 so that GDB will ignore it. */
6140 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6148 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6149 its low and high PC addresses. Do nothing if these addresses could not
6150 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6151 and HIGHPC to the high address if greater than HIGHPC. */
6154 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6155 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6156 struct dwarf2_cu *cu)
6158 CORE_ADDR low, high;
6159 struct die_info *child = die->child;
6161 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6163 *lowpc = min (*lowpc, low);
6164 *highpc = max (*highpc, high);
6167 /* If the language does not allow nested subprograms (either inside
6168 subprograms or lexical blocks), we're done. */
6169 if (cu->language != language_ada)
6172 /* Check all the children of the given DIE. If it contains nested
6173 subprograms, then check their pc bounds. Likewise, we need to
6174 check lexical blocks as well, as they may also contain subprogram
6176 while (child && child->tag)
6178 if (child->tag == DW_TAG_subprogram
6179 || child->tag == DW_TAG_lexical_block)
6180 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6181 child = sibling_die (child);
6185 /* Get the low and high pc's represented by the scope DIE, and store
6186 them in *LOWPC and *HIGHPC. If the correct values can't be
6187 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6190 get_scope_pc_bounds (struct die_info *die,
6191 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6192 struct dwarf2_cu *cu)
6194 CORE_ADDR best_low = (CORE_ADDR) -1;
6195 CORE_ADDR best_high = (CORE_ADDR) 0;
6196 CORE_ADDR current_low, current_high;
6198 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6200 best_low = current_low;
6201 best_high = current_high;
6205 struct die_info *child = die->child;
6207 while (child && child->tag)
6209 switch (child->tag) {
6210 case DW_TAG_subprogram:
6211 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6213 case DW_TAG_namespace:
6215 /* FIXME: carlton/2004-01-16: Should we do this for
6216 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6217 that current GCC's always emit the DIEs corresponding
6218 to definitions of methods of classes as children of a
6219 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6220 the DIEs giving the declarations, which could be
6221 anywhere). But I don't see any reason why the
6222 standards says that they have to be there. */
6223 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6225 if (current_low != ((CORE_ADDR) -1))
6227 best_low = min (best_low, current_low);
6228 best_high = max (best_high, current_high);
6236 child = sibling_die (child);
6241 *highpc = best_high;
6244 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6247 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6248 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6250 struct attribute *attr;
6252 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6255 CORE_ADDR high = DW_ADDR (attr);
6257 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6260 CORE_ADDR low = DW_ADDR (attr);
6262 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6266 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6269 bfd *obfd = cu->objfile->obfd;
6271 /* The value of the DW_AT_ranges attribute is the offset of the
6272 address range list in the .debug_ranges section. */
6273 unsigned long offset = DW_UNSND (attr);
6274 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6276 /* For some target architectures, but not others, the
6277 read_address function sign-extends the addresses it returns.
6278 To recognize base address selection entries, we need a
6280 unsigned int addr_size = cu->header.addr_size;
6281 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6283 /* The base address, to which the next pair is relative. Note
6284 that this 'base' is a DWARF concept: most entries in a range
6285 list are relative, to reduce the number of relocs against the
6286 debugging information. This is separate from this function's
6287 'baseaddr' argument, which GDB uses to relocate debugging
6288 information from a shared library based on the address at
6289 which the library was loaded. */
6290 CORE_ADDR base = cu->base_address;
6291 int base_known = cu->base_known;
6293 gdb_assert (dwarf2_per_objfile->ranges.readin);
6294 if (offset >= dwarf2_per_objfile->ranges.size)
6296 complaint (&symfile_complaints,
6297 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6304 unsigned int bytes_read;
6305 CORE_ADDR start, end;
6307 start = read_address (obfd, buffer, cu, &bytes_read);
6308 buffer += bytes_read;
6309 end = read_address (obfd, buffer, cu, &bytes_read);
6310 buffer += bytes_read;
6312 /* Did we find the end of the range list? */
6313 if (start == 0 && end == 0)
6316 /* Did we find a base address selection entry? */
6317 else if ((start & base_select_mask) == base_select_mask)
6323 /* We found an ordinary address range. */
6328 complaint (&symfile_complaints,
6329 _("Invalid .debug_ranges data "
6330 "(no base address)"));
6336 /* Inverted range entries are invalid. */
6337 complaint (&symfile_complaints,
6338 _("Invalid .debug_ranges data "
6339 "(inverted range)"));
6343 /* Empty range entries have no effect. */
6347 record_block_range (block,
6348 baseaddr + base + start,
6349 baseaddr + base + end - 1);
6355 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6356 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6357 during 4.6.0 experimental. */
6360 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6363 int major, minor, release;
6365 if (cu->producer == NULL)
6367 /* For unknown compilers expect their behavior is DWARF version
6370 GCC started to support .debug_types sections by -gdwarf-4 since
6371 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6372 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6373 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6374 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6379 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6381 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6383 /* For non-GCC compilers expect their behavior is DWARF version
6388 cs = &cu->producer[strlen ("GNU ")];
6389 while (*cs && !isdigit (*cs))
6391 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6393 /* Not recognized as GCC. */
6398 return major < 4 || (major == 4 && minor < 6);
6401 /* Return the default accessibility type if it is not overriden by
6402 DW_AT_accessibility. */
6404 static enum dwarf_access_attribute
6405 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6407 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6409 /* The default DWARF 2 accessibility for members is public, the default
6410 accessibility for inheritance is private. */
6412 if (die->tag != DW_TAG_inheritance)
6413 return DW_ACCESS_public;
6415 return DW_ACCESS_private;
6419 /* DWARF 3+ defines the default accessibility a different way. The same
6420 rules apply now for DW_TAG_inheritance as for the members and it only
6421 depends on the container kind. */
6423 if (die->parent->tag == DW_TAG_class_type)
6424 return DW_ACCESS_private;
6426 return DW_ACCESS_public;
6430 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6431 offset. If the attribute was not found return 0, otherwise return
6432 1. If it was found but could not properly be handled, set *OFFSET
6436 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6439 struct attribute *attr;
6441 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6446 /* Note that we do not check for a section offset first here.
6447 This is because DW_AT_data_member_location is new in DWARF 4,
6448 so if we see it, we can assume that a constant form is really
6449 a constant and not a section offset. */
6450 if (attr_form_is_constant (attr))
6451 *offset = dwarf2_get_attr_constant_value (attr, 0);
6452 else if (attr_form_is_section_offset (attr))
6453 dwarf2_complex_location_expr_complaint ();
6454 else if (attr_form_is_block (attr))
6455 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6457 dwarf2_complex_location_expr_complaint ();
6465 /* Add an aggregate field to the field list. */
6468 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6469 struct dwarf2_cu *cu)
6471 struct objfile *objfile = cu->objfile;
6472 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6473 struct nextfield *new_field;
6474 struct attribute *attr;
6476 char *fieldname = "";
6478 /* Allocate a new field list entry and link it in. */
6479 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6480 make_cleanup (xfree, new_field);
6481 memset (new_field, 0, sizeof (struct nextfield));
6483 if (die->tag == DW_TAG_inheritance)
6485 new_field->next = fip->baseclasses;
6486 fip->baseclasses = new_field;
6490 new_field->next = fip->fields;
6491 fip->fields = new_field;
6495 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6497 new_field->accessibility = DW_UNSND (attr);
6499 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6500 if (new_field->accessibility != DW_ACCESS_public)
6501 fip->non_public_fields = 1;
6503 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6505 new_field->virtuality = DW_UNSND (attr);
6507 new_field->virtuality = DW_VIRTUALITY_none;
6509 fp = &new_field->field;
6511 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6515 /* Data member other than a C++ static data member. */
6517 /* Get type of field. */
6518 fp->type = die_type (die, cu);
6520 SET_FIELD_BITPOS (*fp, 0);
6522 /* Get bit size of field (zero if none). */
6523 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6526 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6530 FIELD_BITSIZE (*fp) = 0;
6533 /* Get bit offset of field. */
6534 if (handle_data_member_location (die, cu, &offset))
6535 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6536 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6539 if (gdbarch_bits_big_endian (gdbarch))
6541 /* For big endian bits, the DW_AT_bit_offset gives the
6542 additional bit offset from the MSB of the containing
6543 anonymous object to the MSB of the field. We don't
6544 have to do anything special since we don't need to
6545 know the size of the anonymous object. */
6546 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6550 /* For little endian bits, compute the bit offset to the
6551 MSB of the anonymous object, subtract off the number of
6552 bits from the MSB of the field to the MSB of the
6553 object, and then subtract off the number of bits of
6554 the field itself. The result is the bit offset of
6555 the LSB of the field. */
6557 int bit_offset = DW_UNSND (attr);
6559 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6562 /* The size of the anonymous object containing
6563 the bit field is explicit, so use the
6564 indicated size (in bytes). */
6565 anonymous_size = DW_UNSND (attr);
6569 /* The size of the anonymous object containing
6570 the bit field must be inferred from the type
6571 attribute of the data member containing the
6573 anonymous_size = TYPE_LENGTH (fp->type);
6575 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6576 - bit_offset - FIELD_BITSIZE (*fp);
6580 /* Get name of field. */
6581 fieldname = dwarf2_name (die, cu);
6582 if (fieldname == NULL)
6585 /* The name is already allocated along with this objfile, so we don't
6586 need to duplicate it for the type. */
6587 fp->name = fieldname;
6589 /* Change accessibility for artificial fields (e.g. virtual table
6590 pointer or virtual base class pointer) to private. */
6591 if (dwarf2_attr (die, DW_AT_artificial, cu))
6593 FIELD_ARTIFICIAL (*fp) = 1;
6594 new_field->accessibility = DW_ACCESS_private;
6595 fip->non_public_fields = 1;
6598 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6600 /* C++ static member. */
6602 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6603 is a declaration, but all versions of G++ as of this writing
6604 (so through at least 3.2.1) incorrectly generate
6605 DW_TAG_variable tags. */
6609 /* Get name of field. */
6610 fieldname = dwarf2_name (die, cu);
6611 if (fieldname == NULL)
6614 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6616 /* Only create a symbol if this is an external value.
6617 new_symbol checks this and puts the value in the global symbol
6618 table, which we want. If it is not external, new_symbol
6619 will try to put the value in cu->list_in_scope which is wrong. */
6620 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6622 /* A static const member, not much different than an enum as far as
6623 we're concerned, except that we can support more types. */
6624 new_symbol (die, NULL, cu);
6627 /* Get physical name. */
6628 physname = (char *) dwarf2_physname (fieldname, die, cu);
6630 /* The name is already allocated along with this objfile, so we don't
6631 need to duplicate it for the type. */
6632 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6633 FIELD_TYPE (*fp) = die_type (die, cu);
6634 FIELD_NAME (*fp) = fieldname;
6636 else if (die->tag == DW_TAG_inheritance)
6640 /* C++ base class field. */
6641 if (handle_data_member_location (die, cu, &offset))
6642 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6643 FIELD_BITSIZE (*fp) = 0;
6644 FIELD_TYPE (*fp) = die_type (die, cu);
6645 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6646 fip->nbaseclasses++;
6650 /* Add a typedef defined in the scope of the FIP's class. */
6653 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6654 struct dwarf2_cu *cu)
6656 struct objfile *objfile = cu->objfile;
6657 struct typedef_field_list *new_field;
6658 struct attribute *attr;
6659 struct typedef_field *fp;
6660 char *fieldname = "";
6662 /* Allocate a new field list entry and link it in. */
6663 new_field = xzalloc (sizeof (*new_field));
6664 make_cleanup (xfree, new_field);
6666 gdb_assert (die->tag == DW_TAG_typedef);
6668 fp = &new_field->field;
6670 /* Get name of field. */
6671 fp->name = dwarf2_name (die, cu);
6672 if (fp->name == NULL)
6675 fp->type = read_type_die (die, cu);
6677 new_field->next = fip->typedef_field_list;
6678 fip->typedef_field_list = new_field;
6679 fip->typedef_field_list_count++;
6682 /* Create the vector of fields, and attach it to the type. */
6685 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6686 struct dwarf2_cu *cu)
6688 int nfields = fip->nfields;
6690 /* Record the field count, allocate space for the array of fields,
6691 and create blank accessibility bitfields if necessary. */
6692 TYPE_NFIELDS (type) = nfields;
6693 TYPE_FIELDS (type) = (struct field *)
6694 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6695 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6697 if (fip->non_public_fields && cu->language != language_ada)
6699 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6701 TYPE_FIELD_PRIVATE_BITS (type) =
6702 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6703 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6705 TYPE_FIELD_PROTECTED_BITS (type) =
6706 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6707 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6709 TYPE_FIELD_IGNORE_BITS (type) =
6710 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6711 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
6714 /* If the type has baseclasses, allocate and clear a bit vector for
6715 TYPE_FIELD_VIRTUAL_BITS. */
6716 if (fip->nbaseclasses && cu->language != language_ada)
6718 int num_bytes = B_BYTES (fip->nbaseclasses);
6719 unsigned char *pointer;
6721 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6722 pointer = TYPE_ALLOC (type, num_bytes);
6723 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6724 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6725 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6728 /* Copy the saved-up fields into the field vector. Start from the head of
6729 the list, adding to the tail of the field array, so that they end up in
6730 the same order in the array in which they were added to the list. */
6731 while (nfields-- > 0)
6733 struct nextfield *fieldp;
6737 fieldp = fip->fields;
6738 fip->fields = fieldp->next;
6742 fieldp = fip->baseclasses;
6743 fip->baseclasses = fieldp->next;
6746 TYPE_FIELD (type, nfields) = fieldp->field;
6747 switch (fieldp->accessibility)
6749 case DW_ACCESS_private:
6750 if (cu->language != language_ada)
6751 SET_TYPE_FIELD_PRIVATE (type, nfields);
6754 case DW_ACCESS_protected:
6755 if (cu->language != language_ada)
6756 SET_TYPE_FIELD_PROTECTED (type, nfields);
6759 case DW_ACCESS_public:
6763 /* Unknown accessibility. Complain and treat it as public. */
6765 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6766 fieldp->accessibility);
6770 if (nfields < fip->nbaseclasses)
6772 switch (fieldp->virtuality)
6774 case DW_VIRTUALITY_virtual:
6775 case DW_VIRTUALITY_pure_virtual:
6776 if (cu->language == language_ada)
6777 error (_("unexpected virtuality in component of Ada type"));
6778 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6785 /* Add a member function to the proper fieldlist. */
6788 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6789 struct type *type, struct dwarf2_cu *cu)
6791 struct objfile *objfile = cu->objfile;
6792 struct attribute *attr;
6793 struct fnfieldlist *flp;
6795 struct fn_field *fnp;
6797 struct nextfnfield *new_fnfield;
6798 struct type *this_type;
6799 enum dwarf_access_attribute accessibility;
6801 if (cu->language == language_ada)
6802 error (_("unexpected member function in Ada type"));
6804 /* Get name of member function. */
6805 fieldname = dwarf2_name (die, cu);
6806 if (fieldname == NULL)
6809 /* Look up member function name in fieldlist. */
6810 for (i = 0; i < fip->nfnfields; i++)
6812 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6816 /* Create new list element if necessary. */
6817 if (i < fip->nfnfields)
6818 flp = &fip->fnfieldlists[i];
6821 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6823 fip->fnfieldlists = (struct fnfieldlist *)
6824 xrealloc (fip->fnfieldlists,
6825 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6826 * sizeof (struct fnfieldlist));
6827 if (fip->nfnfields == 0)
6828 make_cleanup (free_current_contents, &fip->fnfieldlists);
6830 flp = &fip->fnfieldlists[fip->nfnfields];
6831 flp->name = fieldname;
6834 i = fip->nfnfields++;
6837 /* Create a new member function field and chain it to the field list
6839 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6840 make_cleanup (xfree, new_fnfield);
6841 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6842 new_fnfield->next = flp->head;
6843 flp->head = new_fnfield;
6846 /* Fill in the member function field info. */
6847 fnp = &new_fnfield->fnfield;
6849 /* Delay processing of the physname until later. */
6850 if (cu->language == language_cplus || cu->language == language_java)
6852 add_to_method_list (type, i, flp->length - 1, fieldname,
6857 char *physname = (char *) dwarf2_physname (fieldname, die, cu);
6858 fnp->physname = physname ? physname : "";
6861 fnp->type = alloc_type (objfile);
6862 this_type = read_type_die (die, cu);
6863 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6865 int nparams = TYPE_NFIELDS (this_type);
6867 /* TYPE is the domain of this method, and THIS_TYPE is the type
6868 of the method itself (TYPE_CODE_METHOD). */
6869 smash_to_method_type (fnp->type, type,
6870 TYPE_TARGET_TYPE (this_type),
6871 TYPE_FIELDS (this_type),
6872 TYPE_NFIELDS (this_type),
6873 TYPE_VARARGS (this_type));
6875 /* Handle static member functions.
6876 Dwarf2 has no clean way to discern C++ static and non-static
6877 member functions. G++ helps GDB by marking the first
6878 parameter for non-static member functions (which is the this
6879 pointer) as artificial. We obtain this information from
6880 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6881 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6882 fnp->voffset = VOFFSET_STATIC;
6885 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6886 dwarf2_full_name (fieldname, die, cu));
6888 /* Get fcontext from DW_AT_containing_type if present. */
6889 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6890 fnp->fcontext = die_containing_type (die, cu);
6892 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6893 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6895 /* Get accessibility. */
6896 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6898 accessibility = DW_UNSND (attr);
6900 accessibility = dwarf2_default_access_attribute (die, cu);
6901 switch (accessibility)
6903 case DW_ACCESS_private:
6904 fnp->is_private = 1;
6906 case DW_ACCESS_protected:
6907 fnp->is_protected = 1;
6911 /* Check for artificial methods. */
6912 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6913 if (attr && DW_UNSND (attr) != 0)
6914 fnp->is_artificial = 1;
6916 /* Get index in virtual function table if it is a virtual member
6917 function. For older versions of GCC, this is an offset in the
6918 appropriate virtual table, as specified by DW_AT_containing_type.
6919 For everyone else, it is an expression to be evaluated relative
6920 to the object address. */
6922 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6925 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6927 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6929 /* Old-style GCC. */
6930 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6932 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6933 || (DW_BLOCK (attr)->size > 1
6934 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6935 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6937 struct dwarf_block blk;
6940 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6942 blk.size = DW_BLOCK (attr)->size - offset;
6943 blk.data = DW_BLOCK (attr)->data + offset;
6944 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6945 if ((fnp->voffset % cu->header.addr_size) != 0)
6946 dwarf2_complex_location_expr_complaint ();
6948 fnp->voffset /= cu->header.addr_size;
6952 dwarf2_complex_location_expr_complaint ();
6955 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6957 else if (attr_form_is_section_offset (attr))
6959 dwarf2_complex_location_expr_complaint ();
6963 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6969 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6970 if (attr && DW_UNSND (attr))
6972 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6973 complaint (&symfile_complaints,
6974 _("Member function \"%s\" (offset %d) is virtual "
6975 "but the vtable offset is not specified"),
6976 fieldname, die->offset);
6977 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6978 TYPE_CPLUS_DYNAMIC (type) = 1;
6983 /* Create the vector of member function fields, and attach it to the type. */
6986 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6987 struct dwarf2_cu *cu)
6989 struct fnfieldlist *flp;
6990 int total_length = 0;
6993 if (cu->language == language_ada)
6994 error (_("unexpected member functions in Ada type"));
6996 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6997 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6998 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7000 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7002 struct nextfnfield *nfp = flp->head;
7003 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7006 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7007 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7008 fn_flp->fn_fields = (struct fn_field *)
7009 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7010 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7011 fn_flp->fn_fields[k] = nfp->fnfield;
7013 total_length += flp->length;
7016 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7017 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
7020 /* Returns non-zero if NAME is the name of a vtable member in CU's
7021 language, zero otherwise. */
7023 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7025 static const char vptr[] = "_vptr";
7026 static const char vtable[] = "vtable";
7028 /* Look for the C++ and Java forms of the vtable. */
7029 if ((cu->language == language_java
7030 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7031 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7032 && is_cplus_marker (name[sizeof (vptr) - 1])))
7038 /* GCC outputs unnamed structures that are really pointers to member
7039 functions, with the ABI-specified layout. If TYPE describes
7040 such a structure, smash it into a member function type.
7042 GCC shouldn't do this; it should just output pointer to member DIEs.
7043 This is GCC PR debug/28767. */
7046 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7048 struct type *pfn_type, *domain_type, *new_type;
7050 /* Check for a structure with no name and two children. */
7051 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7054 /* Check for __pfn and __delta members. */
7055 if (TYPE_FIELD_NAME (type, 0) == NULL
7056 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7057 || TYPE_FIELD_NAME (type, 1) == NULL
7058 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7061 /* Find the type of the method. */
7062 pfn_type = TYPE_FIELD_TYPE (type, 0);
7063 if (pfn_type == NULL
7064 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7065 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7068 /* Look for the "this" argument. */
7069 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7070 if (TYPE_NFIELDS (pfn_type) == 0
7071 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7072 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7075 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7076 new_type = alloc_type (objfile);
7077 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7078 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7079 TYPE_VARARGS (pfn_type));
7080 smash_to_methodptr_type (type, new_type);
7083 /* Called when we find the DIE that starts a structure or union scope
7084 (definition) to create a type for the structure or union. Fill in
7085 the type's name and general properties; the members will not be
7086 processed until process_structure_type.
7088 NOTE: we need to call these functions regardless of whether or not the
7089 DIE has a DW_AT_name attribute, since it might be an anonymous
7090 structure or union. This gets the type entered into our set of
7093 However, if the structure is incomplete (an opaque struct/union)
7094 then suppress creating a symbol table entry for it since gdb only
7095 wants to find the one with the complete definition. Note that if
7096 it is complete, we just call new_symbol, which does it's own
7097 checking about whether the struct/union is anonymous or not (and
7098 suppresses creating a symbol table entry itself). */
7100 static struct type *
7101 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7103 struct objfile *objfile = cu->objfile;
7105 struct attribute *attr;
7108 /* If the definition of this type lives in .debug_types, read that type.
7109 Don't follow DW_AT_specification though, that will take us back up
7110 the chain and we want to go down. */
7111 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7114 struct dwarf2_cu *type_cu = cu;
7115 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7117 /* We could just recurse on read_structure_type, but we need to call
7118 get_die_type to ensure only one type for this DIE is created.
7119 This is important, for example, because for c++ classes we need
7120 TYPE_NAME set which is only done by new_symbol. Blech. */
7121 type = read_type_die (type_die, type_cu);
7123 /* TYPE_CU may not be the same as CU.
7124 Ensure TYPE is recorded in CU's type_hash table. */
7125 return set_die_type (die, type, cu);
7128 type = alloc_type (objfile);
7129 INIT_CPLUS_SPECIFIC (type);
7131 name = dwarf2_name (die, cu);
7134 if (cu->language == language_cplus
7135 || cu->language == language_java)
7137 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7139 /* dwarf2_full_name might have already finished building the DIE's
7140 type. If so, there is no need to continue. */
7141 if (get_die_type (die, cu) != NULL)
7142 return get_die_type (die, cu);
7144 TYPE_TAG_NAME (type) = full_name;
7145 if (die->tag == DW_TAG_structure_type
7146 || die->tag == DW_TAG_class_type)
7147 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7151 /* The name is already allocated along with this objfile, so
7152 we don't need to duplicate it for the type. */
7153 TYPE_TAG_NAME (type) = (char *) name;
7154 if (die->tag == DW_TAG_class_type)
7155 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7159 if (die->tag == DW_TAG_structure_type)
7161 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7163 else if (die->tag == DW_TAG_union_type)
7165 TYPE_CODE (type) = TYPE_CODE_UNION;
7169 TYPE_CODE (type) = TYPE_CODE_CLASS;
7172 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7173 TYPE_DECLARED_CLASS (type) = 1;
7175 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7178 TYPE_LENGTH (type) = DW_UNSND (attr);
7182 TYPE_LENGTH (type) = 0;
7185 TYPE_STUB_SUPPORTED (type) = 1;
7186 if (die_is_declaration (die, cu))
7187 TYPE_STUB (type) = 1;
7188 else if (attr == NULL && die->child == NULL
7189 && producer_is_realview (cu->producer))
7190 /* RealView does not output the required DW_AT_declaration
7191 on incomplete types. */
7192 TYPE_STUB (type) = 1;
7194 /* We need to add the type field to the die immediately so we don't
7195 infinitely recurse when dealing with pointers to the structure
7196 type within the structure itself. */
7197 set_die_type (die, type, cu);
7199 /* set_die_type should be already done. */
7200 set_descriptive_type (type, die, cu);
7205 /* Finish creating a structure or union type, including filling in
7206 its members and creating a symbol for it. */
7209 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7211 struct objfile *objfile = cu->objfile;
7212 struct die_info *child_die = die->child;
7215 type = get_die_type (die, cu);
7217 type = read_structure_type (die, cu);
7219 if (die->child != NULL && ! die_is_declaration (die, cu))
7221 struct field_info fi;
7222 struct die_info *child_die;
7223 VEC (symbolp) *template_args = NULL;
7224 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7226 memset (&fi, 0, sizeof (struct field_info));
7228 child_die = die->child;
7230 while (child_die && child_die->tag)
7232 if (child_die->tag == DW_TAG_member
7233 || child_die->tag == DW_TAG_variable)
7235 /* NOTE: carlton/2002-11-05: A C++ static data member
7236 should be a DW_TAG_member that is a declaration, but
7237 all versions of G++ as of this writing (so through at
7238 least 3.2.1) incorrectly generate DW_TAG_variable
7239 tags for them instead. */
7240 dwarf2_add_field (&fi, child_die, cu);
7242 else if (child_die->tag == DW_TAG_subprogram)
7244 /* C++ member function. */
7245 dwarf2_add_member_fn (&fi, child_die, type, cu);
7247 else if (child_die->tag == DW_TAG_inheritance)
7249 /* C++ base class field. */
7250 dwarf2_add_field (&fi, child_die, cu);
7252 else if (child_die->tag == DW_TAG_typedef)
7253 dwarf2_add_typedef (&fi, child_die, cu);
7254 else if (child_die->tag == DW_TAG_template_type_param
7255 || child_die->tag == DW_TAG_template_value_param)
7257 struct symbol *arg = new_symbol (child_die, NULL, cu);
7260 VEC_safe_push (symbolp, template_args, arg);
7263 child_die = sibling_die (child_die);
7266 /* Attach template arguments to type. */
7267 if (! VEC_empty (symbolp, template_args))
7269 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7270 TYPE_N_TEMPLATE_ARGUMENTS (type)
7271 = VEC_length (symbolp, template_args);
7272 TYPE_TEMPLATE_ARGUMENTS (type)
7273 = obstack_alloc (&objfile->objfile_obstack,
7274 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7275 * sizeof (struct symbol *)));
7276 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7277 VEC_address (symbolp, template_args),
7278 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7279 * sizeof (struct symbol *)));
7280 VEC_free (symbolp, template_args);
7283 /* Attach fields and member functions to the type. */
7285 dwarf2_attach_fields_to_type (&fi, type, cu);
7288 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7290 /* Get the type which refers to the base class (possibly this
7291 class itself) which contains the vtable pointer for the current
7292 class from the DW_AT_containing_type attribute. This use of
7293 DW_AT_containing_type is a GNU extension. */
7295 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7297 struct type *t = die_containing_type (die, cu);
7299 TYPE_VPTR_BASETYPE (type) = t;
7304 /* Our own class provides vtbl ptr. */
7305 for (i = TYPE_NFIELDS (t) - 1;
7306 i >= TYPE_N_BASECLASSES (t);
7309 char *fieldname = TYPE_FIELD_NAME (t, i);
7311 if (is_vtable_name (fieldname, cu))
7313 TYPE_VPTR_FIELDNO (type) = i;
7318 /* Complain if virtual function table field not found. */
7319 if (i < TYPE_N_BASECLASSES (t))
7320 complaint (&symfile_complaints,
7321 _("virtual function table pointer "
7322 "not found when defining class '%s'"),
7323 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7328 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7331 else if (cu->producer
7332 && strncmp (cu->producer,
7333 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7335 /* The IBM XLC compiler does not provide direct indication
7336 of the containing type, but the vtable pointer is
7337 always named __vfp. */
7341 for (i = TYPE_NFIELDS (type) - 1;
7342 i >= TYPE_N_BASECLASSES (type);
7345 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7347 TYPE_VPTR_FIELDNO (type) = i;
7348 TYPE_VPTR_BASETYPE (type) = type;
7355 /* Copy fi.typedef_field_list linked list elements content into the
7356 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7357 if (fi.typedef_field_list)
7359 int i = fi.typedef_field_list_count;
7361 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7362 TYPE_TYPEDEF_FIELD_ARRAY (type)
7363 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7364 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7366 /* Reverse the list order to keep the debug info elements order. */
7369 struct typedef_field *dest, *src;
7371 dest = &TYPE_TYPEDEF_FIELD (type, i);
7372 src = &fi.typedef_field_list->field;
7373 fi.typedef_field_list = fi.typedef_field_list->next;
7378 do_cleanups (back_to);
7381 quirk_gcc_member_function_pointer (type, cu->objfile);
7383 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7384 snapshots) has been known to create a die giving a declaration
7385 for a class that has, as a child, a die giving a definition for a
7386 nested class. So we have to process our children even if the
7387 current die is a declaration. Normally, of course, a declaration
7388 won't have any children at all. */
7390 while (child_die != NULL && child_die->tag)
7392 if (child_die->tag == DW_TAG_member
7393 || child_die->tag == DW_TAG_variable
7394 || child_die->tag == DW_TAG_inheritance
7395 || child_die->tag == DW_TAG_template_value_param
7396 || child_die->tag == DW_TAG_template_type_param)
7401 process_die (child_die, cu);
7403 child_die = sibling_die (child_die);
7406 /* Do not consider external references. According to the DWARF standard,
7407 these DIEs are identified by the fact that they have no byte_size
7408 attribute, and a declaration attribute. */
7409 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7410 || !die_is_declaration (die, cu))
7411 new_symbol (die, type, cu);
7414 /* Given a DW_AT_enumeration_type die, set its type. We do not
7415 complete the type's fields yet, or create any symbols. */
7417 static struct type *
7418 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7420 struct objfile *objfile = cu->objfile;
7422 struct attribute *attr;
7425 /* If the definition of this type lives in .debug_types, read that type.
7426 Don't follow DW_AT_specification though, that will take us back up
7427 the chain and we want to go down. */
7428 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7431 struct dwarf2_cu *type_cu = cu;
7432 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7434 type = read_type_die (type_die, type_cu);
7436 /* TYPE_CU may not be the same as CU.
7437 Ensure TYPE is recorded in CU's type_hash table. */
7438 return set_die_type (die, type, cu);
7441 type = alloc_type (objfile);
7443 TYPE_CODE (type) = TYPE_CODE_ENUM;
7444 name = dwarf2_full_name (NULL, die, cu);
7446 TYPE_TAG_NAME (type) = (char *) name;
7448 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7451 TYPE_LENGTH (type) = DW_UNSND (attr);
7455 TYPE_LENGTH (type) = 0;
7458 /* The enumeration DIE can be incomplete. In Ada, any type can be
7459 declared as private in the package spec, and then defined only
7460 inside the package body. Such types are known as Taft Amendment
7461 Types. When another package uses such a type, an incomplete DIE
7462 may be generated by the compiler. */
7463 if (die_is_declaration (die, cu))
7464 TYPE_STUB (type) = 1;
7466 return set_die_type (die, type, cu);
7469 /* Given a pointer to a die which begins an enumeration, process all
7470 the dies that define the members of the enumeration, and create the
7471 symbol for the enumeration type.
7473 NOTE: We reverse the order of the element list. */
7476 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7478 struct type *this_type;
7480 this_type = get_die_type (die, cu);
7481 if (this_type == NULL)
7482 this_type = read_enumeration_type (die, cu);
7484 if (die->child != NULL)
7486 struct die_info *child_die;
7488 struct field *fields = NULL;
7490 int unsigned_enum = 1;
7493 child_die = die->child;
7494 while (child_die && child_die->tag)
7496 if (child_die->tag != DW_TAG_enumerator)
7498 process_die (child_die, cu);
7502 name = dwarf2_name (child_die, cu);
7505 sym = new_symbol (child_die, this_type, cu);
7506 if (SYMBOL_VALUE (sym) < 0)
7509 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7511 fields = (struct field *)
7513 (num_fields + DW_FIELD_ALLOC_CHUNK)
7514 * sizeof (struct field));
7517 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7518 FIELD_TYPE (fields[num_fields]) = NULL;
7519 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7520 FIELD_BITSIZE (fields[num_fields]) = 0;
7526 child_die = sibling_die (child_die);
7531 TYPE_NFIELDS (this_type) = num_fields;
7532 TYPE_FIELDS (this_type) = (struct field *)
7533 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7534 memcpy (TYPE_FIELDS (this_type), fields,
7535 sizeof (struct field) * num_fields);
7539 TYPE_UNSIGNED (this_type) = 1;
7542 new_symbol (die, this_type, cu);
7545 /* Extract all information from a DW_TAG_array_type DIE and put it in
7546 the DIE's type field. For now, this only handles one dimensional
7549 static struct type *
7550 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7552 struct objfile *objfile = cu->objfile;
7553 struct die_info *child_die;
7555 struct type *element_type, *range_type, *index_type;
7556 struct type **range_types = NULL;
7557 struct attribute *attr;
7559 struct cleanup *back_to;
7562 element_type = die_type (die, cu);
7564 /* The die_type call above may have already set the type for this DIE. */
7565 type = get_die_type (die, cu);
7569 /* Irix 6.2 native cc creates array types without children for
7570 arrays with unspecified length. */
7571 if (die->child == NULL)
7573 index_type = objfile_type (objfile)->builtin_int;
7574 range_type = create_range_type (NULL, index_type, 0, -1);
7575 type = create_array_type (NULL, element_type, range_type);
7576 return set_die_type (die, type, cu);
7579 back_to = make_cleanup (null_cleanup, NULL);
7580 child_die = die->child;
7581 while (child_die && child_die->tag)
7583 if (child_die->tag == DW_TAG_subrange_type)
7585 struct type *child_type = read_type_die (child_die, cu);
7587 if (child_type != NULL)
7589 /* The range type was succesfully read. Save it for the
7590 array type creation. */
7591 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7593 range_types = (struct type **)
7594 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7595 * sizeof (struct type *));
7597 make_cleanup (free_current_contents, &range_types);
7599 range_types[ndim++] = child_type;
7602 child_die = sibling_die (child_die);
7605 /* Dwarf2 dimensions are output from left to right, create the
7606 necessary array types in backwards order. */
7608 type = element_type;
7610 if (read_array_order (die, cu) == DW_ORD_col_major)
7615 type = create_array_type (NULL, type, range_types[i++]);
7620 type = create_array_type (NULL, type, range_types[ndim]);
7623 /* Understand Dwarf2 support for vector types (like they occur on
7624 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7625 array type. This is not part of the Dwarf2/3 standard yet, but a
7626 custom vendor extension. The main difference between a regular
7627 array and the vector variant is that vectors are passed by value
7629 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7631 make_vector_type (type);
7633 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7634 implementation may choose to implement triple vectors using this
7636 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7639 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
7640 TYPE_LENGTH (type) = DW_UNSND (attr);
7642 complaint (&symfile_complaints,
7643 _("DW_AT_byte_size for array type smaller "
7644 "than the total size of elements"));
7647 name = dwarf2_name (die, cu);
7649 TYPE_NAME (type) = name;
7651 /* Install the type in the die. */
7652 set_die_type (die, type, cu);
7654 /* set_die_type should be already done. */
7655 set_descriptive_type (type, die, cu);
7657 do_cleanups (back_to);
7662 static enum dwarf_array_dim_ordering
7663 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7665 struct attribute *attr;
7667 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7669 if (attr) return DW_SND (attr);
7671 /* GNU F77 is a special case, as at 08/2004 array type info is the
7672 opposite order to the dwarf2 specification, but data is still
7673 laid out as per normal fortran.
7675 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7676 version checking. */
7678 if (cu->language == language_fortran
7679 && cu->producer && strstr (cu->producer, "GNU F77"))
7681 return DW_ORD_row_major;
7684 switch (cu->language_defn->la_array_ordering)
7686 case array_column_major:
7687 return DW_ORD_col_major;
7688 case array_row_major:
7690 return DW_ORD_row_major;
7694 /* Extract all information from a DW_TAG_set_type DIE and put it in
7695 the DIE's type field. */
7697 static struct type *
7698 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7700 struct type *domain_type, *set_type;
7701 struct attribute *attr;
7703 domain_type = die_type (die, cu);
7705 /* The die_type call above may have already set the type for this DIE. */
7706 set_type = get_die_type (die, cu);
7710 set_type = create_set_type (NULL, domain_type);
7712 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7714 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7716 return set_die_type (die, set_type, cu);
7719 /* First cut: install each common block member as a global variable. */
7722 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7724 struct die_info *child_die;
7725 struct attribute *attr;
7727 CORE_ADDR base = (CORE_ADDR) 0;
7729 attr = dwarf2_attr (die, DW_AT_location, cu);
7732 /* Support the .debug_loc offsets. */
7733 if (attr_form_is_block (attr))
7735 base = decode_locdesc (DW_BLOCK (attr), cu);
7737 else if (attr_form_is_section_offset (attr))
7739 dwarf2_complex_location_expr_complaint ();
7743 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7744 "common block member");
7747 if (die->child != NULL)
7749 child_die = die->child;
7750 while (child_die && child_die->tag)
7754 sym = new_symbol (child_die, NULL, cu);
7756 && handle_data_member_location (child_die, cu, &offset))
7758 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
7759 add_symbol_to_list (sym, &global_symbols);
7761 child_die = sibling_die (child_die);
7766 /* Create a type for a C++ namespace. */
7768 static struct type *
7769 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7771 struct objfile *objfile = cu->objfile;
7772 const char *previous_prefix, *name;
7776 /* For extensions, reuse the type of the original namespace. */
7777 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7779 struct die_info *ext_die;
7780 struct dwarf2_cu *ext_cu = cu;
7782 ext_die = dwarf2_extension (die, &ext_cu);
7783 type = read_type_die (ext_die, ext_cu);
7785 /* EXT_CU may not be the same as CU.
7786 Ensure TYPE is recorded in CU's type_hash table. */
7787 return set_die_type (die, type, cu);
7790 name = namespace_name (die, &is_anonymous, cu);
7792 /* Now build the name of the current namespace. */
7794 previous_prefix = determine_prefix (die, cu);
7795 if (previous_prefix[0] != '\0')
7796 name = typename_concat (&objfile->objfile_obstack,
7797 previous_prefix, name, 0, cu);
7799 /* Create the type. */
7800 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
7802 TYPE_NAME (type) = (char *) name;
7803 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7805 return set_die_type (die, type, cu);
7808 /* Read a C++ namespace. */
7811 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
7813 struct objfile *objfile = cu->objfile;
7816 /* Add a symbol associated to this if we haven't seen the namespace
7817 before. Also, add a using directive if it's an anonymous
7820 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
7824 type = read_type_die (die, cu);
7825 new_symbol (die, type, cu);
7827 namespace_name (die, &is_anonymous, cu);
7830 const char *previous_prefix = determine_prefix (die, cu);
7832 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
7833 NULL, &objfile->objfile_obstack);
7837 if (die->child != NULL)
7839 struct die_info *child_die = die->child;
7841 while (child_die && child_die->tag)
7843 process_die (child_die, cu);
7844 child_die = sibling_die (child_die);
7849 /* Read a Fortran module as type. This DIE can be only a declaration used for
7850 imported module. Still we need that type as local Fortran "use ... only"
7851 declaration imports depend on the created type in determine_prefix. */
7853 static struct type *
7854 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
7856 struct objfile *objfile = cu->objfile;
7860 module_name = dwarf2_name (die, cu);
7862 complaint (&symfile_complaints,
7863 _("DW_TAG_module has no name, offset 0x%x"),
7865 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
7867 /* determine_prefix uses TYPE_TAG_NAME. */
7868 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7870 return set_die_type (die, type, cu);
7873 /* Read a Fortran module. */
7876 read_module (struct die_info *die, struct dwarf2_cu *cu)
7878 struct die_info *child_die = die->child;
7880 while (child_die && child_die->tag)
7882 process_die (child_die, cu);
7883 child_die = sibling_die (child_die);
7887 /* Return the name of the namespace represented by DIE. Set
7888 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7892 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7894 struct die_info *current_die;
7895 const char *name = NULL;
7897 /* Loop through the extensions until we find a name. */
7899 for (current_die = die;
7900 current_die != NULL;
7901 current_die = dwarf2_extension (die, &cu))
7903 name = dwarf2_name (current_die, cu);
7908 /* Is it an anonymous namespace? */
7910 *is_anonymous = (name == NULL);
7912 name = CP_ANONYMOUS_NAMESPACE_STR;
7917 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7918 the user defined type vector. */
7920 static struct type *
7921 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7923 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7924 struct comp_unit_head *cu_header = &cu->header;
7926 struct attribute *attr_byte_size;
7927 struct attribute *attr_address_class;
7928 int byte_size, addr_class;
7929 struct type *target_type;
7931 target_type = die_type (die, cu);
7933 /* The die_type call above may have already set the type for this DIE. */
7934 type = get_die_type (die, cu);
7938 type = lookup_pointer_type (target_type);
7940 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7942 byte_size = DW_UNSND (attr_byte_size);
7944 byte_size = cu_header->addr_size;
7946 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7947 if (attr_address_class)
7948 addr_class = DW_UNSND (attr_address_class);
7950 addr_class = DW_ADDR_none;
7952 /* If the pointer size or address class is different than the
7953 default, create a type variant marked as such and set the
7954 length accordingly. */
7955 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7957 if (gdbarch_address_class_type_flags_p (gdbarch))
7961 type_flags = gdbarch_address_class_type_flags
7962 (gdbarch, byte_size, addr_class);
7963 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7965 type = make_type_with_address_space (type, type_flags);
7967 else if (TYPE_LENGTH (type) != byte_size)
7969 complaint (&symfile_complaints,
7970 _("invalid pointer size %d"), byte_size);
7974 /* Should we also complain about unhandled address classes? */
7978 TYPE_LENGTH (type) = byte_size;
7979 return set_die_type (die, type, cu);
7982 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7983 the user defined type vector. */
7985 static struct type *
7986 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7989 struct type *to_type;
7990 struct type *domain;
7992 to_type = die_type (die, cu);
7993 domain = die_containing_type (die, cu);
7995 /* The calls above may have already set the type for this DIE. */
7996 type = get_die_type (die, cu);
8000 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8001 type = lookup_methodptr_type (to_type);
8003 type = lookup_memberptr_type (to_type, domain);
8005 return set_die_type (die, type, cu);
8008 /* Extract all information from a DW_TAG_reference_type DIE and add to
8009 the user defined type vector. */
8011 static struct type *
8012 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8014 struct comp_unit_head *cu_header = &cu->header;
8015 struct type *type, *target_type;
8016 struct attribute *attr;
8018 target_type = die_type (die, cu);
8020 /* The die_type call above may have already set the type for this DIE. */
8021 type = get_die_type (die, cu);
8025 type = lookup_reference_type (target_type);
8026 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8029 TYPE_LENGTH (type) = DW_UNSND (attr);
8033 TYPE_LENGTH (type) = cu_header->addr_size;
8035 return set_die_type (die, type, cu);
8038 static struct type *
8039 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8041 struct type *base_type, *cv_type;
8043 base_type = die_type (die, cu);
8045 /* The die_type call above may have already set the type for this DIE. */
8046 cv_type = get_die_type (die, cu);
8050 /* In case the const qualifier is applied to an array type, the element type
8051 is so qualified, not the array type (section 6.7.3 of C99). */
8052 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8054 struct type *el_type, *inner_array;
8056 base_type = copy_type (base_type);
8057 inner_array = base_type;
8059 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8061 TYPE_TARGET_TYPE (inner_array) =
8062 copy_type (TYPE_TARGET_TYPE (inner_array));
8063 inner_array = TYPE_TARGET_TYPE (inner_array);
8066 el_type = TYPE_TARGET_TYPE (inner_array);
8067 TYPE_TARGET_TYPE (inner_array) =
8068 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8070 return set_die_type (die, base_type, cu);
8073 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8074 return set_die_type (die, cv_type, cu);
8077 static struct type *
8078 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8080 struct type *base_type, *cv_type;
8082 base_type = die_type (die, cu);
8084 /* The die_type call above may have already set the type for this DIE. */
8085 cv_type = get_die_type (die, cu);
8089 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8090 return set_die_type (die, cv_type, cu);
8093 /* Extract all information from a DW_TAG_string_type DIE and add to
8094 the user defined type vector. It isn't really a user defined type,
8095 but it behaves like one, with other DIE's using an AT_user_def_type
8096 attribute to reference it. */
8098 static struct type *
8099 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8101 struct objfile *objfile = cu->objfile;
8102 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8103 struct type *type, *range_type, *index_type, *char_type;
8104 struct attribute *attr;
8105 unsigned int length;
8107 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8110 length = DW_UNSND (attr);
8114 /* Check for the DW_AT_byte_size attribute. */
8115 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8118 length = DW_UNSND (attr);
8126 index_type = objfile_type (objfile)->builtin_int;
8127 range_type = create_range_type (NULL, index_type, 1, length);
8128 char_type = language_string_char_type (cu->language_defn, gdbarch);
8129 type = create_string_type (NULL, char_type, range_type);
8131 return set_die_type (die, type, cu);
8134 /* Handle DIES due to C code like:
8138 int (*funcp)(int a, long l);
8142 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8144 static struct type *
8145 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8147 struct type *type; /* Type that this function returns. */
8148 struct type *ftype; /* Function that returns above type. */
8149 struct attribute *attr;
8151 type = die_type (die, cu);
8153 /* The die_type call above may have already set the type for this DIE. */
8154 ftype = get_die_type (die, cu);
8158 ftype = lookup_function_type (type);
8160 /* All functions in C++, Pascal and Java have prototypes. */
8161 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8162 if ((attr && (DW_UNSND (attr) != 0))
8163 || cu->language == language_cplus
8164 || cu->language == language_java
8165 || cu->language == language_pascal)
8166 TYPE_PROTOTYPED (ftype) = 1;
8167 else if (producer_is_realview (cu->producer))
8168 /* RealView does not emit DW_AT_prototyped. We can not
8169 distinguish prototyped and unprototyped functions; default to
8170 prototyped, since that is more common in modern code (and
8171 RealView warns about unprototyped functions). */
8172 TYPE_PROTOTYPED (ftype) = 1;
8174 /* Store the calling convention in the type if it's available in
8175 the subroutine die. Otherwise set the calling convention to
8176 the default value DW_CC_normal. */
8177 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8179 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8180 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8181 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8183 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8185 /* We need to add the subroutine type to the die immediately so
8186 we don't infinitely recurse when dealing with parameters
8187 declared as the same subroutine type. */
8188 set_die_type (die, ftype, cu);
8190 if (die->child != NULL)
8192 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8193 struct die_info *child_die;
8194 int nparams, iparams;
8196 /* Count the number of parameters.
8197 FIXME: GDB currently ignores vararg functions, but knows about
8198 vararg member functions. */
8200 child_die = die->child;
8201 while (child_die && child_die->tag)
8203 if (child_die->tag == DW_TAG_formal_parameter)
8205 else if (child_die->tag == DW_TAG_unspecified_parameters)
8206 TYPE_VARARGS (ftype) = 1;
8207 child_die = sibling_die (child_die);
8210 /* Allocate storage for parameters and fill them in. */
8211 TYPE_NFIELDS (ftype) = nparams;
8212 TYPE_FIELDS (ftype) = (struct field *)
8213 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8215 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8216 even if we error out during the parameters reading below. */
8217 for (iparams = 0; iparams < nparams; iparams++)
8218 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8221 child_die = die->child;
8222 while (child_die && child_die->tag)
8224 if (child_die->tag == DW_TAG_formal_parameter)
8226 struct type *arg_type;
8228 /* DWARF version 2 has no clean way to discern C++
8229 static and non-static member functions. G++ helps
8230 GDB by marking the first parameter for non-static
8231 member functions (which is the this pointer) as
8232 artificial. We pass this information to
8233 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8235 DWARF version 3 added DW_AT_object_pointer, which GCC
8236 4.5 does not yet generate. */
8237 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8239 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8242 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8244 /* GCC/43521: In java, the formal parameter
8245 "this" is sometimes not marked with DW_AT_artificial. */
8246 if (cu->language == language_java)
8248 const char *name = dwarf2_name (child_die, cu);
8250 if (name && !strcmp (name, "this"))
8251 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8254 arg_type = die_type (child_die, cu);
8256 /* RealView does not mark THIS as const, which the testsuite
8257 expects. GCC marks THIS as const in method definitions,
8258 but not in the class specifications (GCC PR 43053). */
8259 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8260 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8263 struct dwarf2_cu *arg_cu = cu;
8264 const char *name = dwarf2_name (child_die, cu);
8266 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8269 /* If the compiler emits this, use it. */
8270 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8273 else if (name && strcmp (name, "this") == 0)
8274 /* Function definitions will have the argument names. */
8276 else if (name == NULL && iparams == 0)
8277 /* Declarations may not have the names, so like
8278 elsewhere in GDB, assume an artificial first
8279 argument is "this". */
8283 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8287 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8290 child_die = sibling_die (child_die);
8297 static struct type *
8298 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8300 struct objfile *objfile = cu->objfile;
8301 const char *name = NULL;
8302 struct type *this_type;
8304 name = dwarf2_full_name (NULL, die, cu);
8305 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8306 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8307 TYPE_NAME (this_type) = (char *) name;
8308 set_die_type (die, this_type, cu);
8309 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8313 /* Find a representation of a given base type and install
8314 it in the TYPE field of the die. */
8316 static struct type *
8317 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8319 struct objfile *objfile = cu->objfile;
8321 struct attribute *attr;
8322 int encoding = 0, size = 0;
8324 enum type_code code = TYPE_CODE_INT;
8326 struct type *target_type = NULL;
8328 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8331 encoding = DW_UNSND (attr);
8333 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8336 size = DW_UNSND (attr);
8338 name = dwarf2_name (die, cu);
8341 complaint (&symfile_complaints,
8342 _("DW_AT_name missing from DW_TAG_base_type"));
8347 case DW_ATE_address:
8348 /* Turn DW_ATE_address into a void * pointer. */
8349 code = TYPE_CODE_PTR;
8350 type_flags |= TYPE_FLAG_UNSIGNED;
8351 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8353 case DW_ATE_boolean:
8354 code = TYPE_CODE_BOOL;
8355 type_flags |= TYPE_FLAG_UNSIGNED;
8357 case DW_ATE_complex_float:
8358 code = TYPE_CODE_COMPLEX;
8359 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8361 case DW_ATE_decimal_float:
8362 code = TYPE_CODE_DECFLOAT;
8365 code = TYPE_CODE_FLT;
8369 case DW_ATE_unsigned:
8370 type_flags |= TYPE_FLAG_UNSIGNED;
8372 case DW_ATE_signed_char:
8373 if (cu->language == language_ada || cu->language == language_m2
8374 || cu->language == language_pascal)
8375 code = TYPE_CODE_CHAR;
8377 case DW_ATE_unsigned_char:
8378 if (cu->language == language_ada || cu->language == language_m2
8379 || cu->language == language_pascal)
8380 code = TYPE_CODE_CHAR;
8381 type_flags |= TYPE_FLAG_UNSIGNED;
8384 /* We just treat this as an integer and then recognize the
8385 type by name elsewhere. */
8389 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8390 dwarf_type_encoding_name (encoding));
8394 type = init_type (code, size, type_flags, NULL, objfile);
8395 TYPE_NAME (type) = name;
8396 TYPE_TARGET_TYPE (type) = target_type;
8398 if (name && strcmp (name, "char") == 0)
8399 TYPE_NOSIGN (type) = 1;
8401 return set_die_type (die, type, cu);
8404 /* Read the given DW_AT_subrange DIE. */
8406 static struct type *
8407 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8409 struct type *base_type;
8410 struct type *range_type;
8411 struct attribute *attr;
8415 LONGEST negative_mask;
8417 base_type = die_type (die, cu);
8418 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8419 check_typedef (base_type);
8421 /* The die_type call above may have already set the type for this DIE. */
8422 range_type = get_die_type (die, cu);
8426 if (cu->language == language_fortran)
8428 /* FORTRAN implies a lower bound of 1, if not given. */
8432 /* FIXME: For variable sized arrays either of these could be
8433 a variable rather than a constant value. We'll allow it,
8434 but we don't know how to handle it. */
8435 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8437 low = dwarf2_get_attr_constant_value (attr, 0);
8439 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8442 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
8444 /* GCC encodes arrays with unspecified or dynamic length
8445 with a DW_FORM_block1 attribute or a reference attribute.
8446 FIXME: GDB does not yet know how to handle dynamic
8447 arrays properly, treat them as arrays with unspecified
8450 FIXME: jimb/2003-09-22: GDB does not really know
8451 how to handle arrays of unspecified length
8452 either; we just represent them as zero-length
8453 arrays. Choose an appropriate upper bound given
8454 the lower bound we've computed above. */
8458 high = dwarf2_get_attr_constant_value (attr, 1);
8462 attr = dwarf2_attr (die, DW_AT_count, cu);
8465 int count = dwarf2_get_attr_constant_value (attr, 1);
8466 high = low + count - 1;
8470 /* Unspecified array length. */
8475 /* Dwarf-2 specifications explicitly allows to create subrange types
8476 without specifying a base type.
8477 In that case, the base type must be set to the type of
8478 the lower bound, upper bound or count, in that order, if any of these
8479 three attributes references an object that has a type.
8480 If no base type is found, the Dwarf-2 specifications say that
8481 a signed integer type of size equal to the size of an address should
8483 For the following C code: `extern char gdb_int [];'
8484 GCC produces an empty range DIE.
8485 FIXME: muller/2010-05-28: Possible references to object for low bound,
8486 high bound or count are not yet handled by this code. */
8487 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8489 struct objfile *objfile = cu->objfile;
8490 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8491 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8492 struct type *int_type = objfile_type (objfile)->builtin_int;
8494 /* Test "int", "long int", and "long long int" objfile types,
8495 and select the first one having a size above or equal to the
8496 architecture address size. */
8497 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8498 base_type = int_type;
8501 int_type = objfile_type (objfile)->builtin_long;
8502 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8503 base_type = int_type;
8506 int_type = objfile_type (objfile)->builtin_long_long;
8507 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8508 base_type = int_type;
8514 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8515 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8516 low |= negative_mask;
8517 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8518 high |= negative_mask;
8520 range_type = create_range_type (NULL, base_type, low, high);
8522 /* Mark arrays with dynamic length at least as an array of unspecified
8523 length. GDB could check the boundary but before it gets implemented at
8524 least allow accessing the array elements. */
8525 if (attr && attr->form == DW_FORM_block1)
8526 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8528 /* Ada expects an empty array on no boundary attributes. */
8529 if (attr == NULL && cu->language != language_ada)
8530 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8532 name = dwarf2_name (die, cu);
8534 TYPE_NAME (range_type) = name;
8536 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8538 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8540 set_die_type (die, range_type, cu);
8542 /* set_die_type should be already done. */
8543 set_descriptive_type (range_type, die, cu);
8548 static struct type *
8549 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8553 /* For now, we only support the C meaning of an unspecified type: void. */
8555 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8556 TYPE_NAME (type) = dwarf2_name (die, cu);
8558 return set_die_type (die, type, cu);
8561 /* Trivial hash function for die_info: the hash value of a DIE
8562 is its offset in .debug_info for this objfile. */
8565 die_hash (const void *item)
8567 const struct die_info *die = item;
8572 /* Trivial comparison function for die_info structures: two DIEs
8573 are equal if they have the same offset. */
8576 die_eq (const void *item_lhs, const void *item_rhs)
8578 const struct die_info *die_lhs = item_lhs;
8579 const struct die_info *die_rhs = item_rhs;
8581 return die_lhs->offset == die_rhs->offset;
8584 /* Read a whole compilation unit into a linked list of dies. */
8586 static struct die_info *
8587 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8589 struct die_reader_specs reader_specs;
8590 int read_abbrevs = 0;
8591 struct cleanup *back_to = NULL;
8592 struct die_info *die;
8594 if (cu->dwarf2_abbrevs == NULL)
8596 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8597 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8601 gdb_assert (cu->die_hash == NULL);
8603 = htab_create_alloc_ex (cu->header.length / 12,
8607 &cu->comp_unit_obstack,
8608 hashtab_obstack_allocate,
8609 dummy_obstack_deallocate);
8611 init_cu_die_reader (&reader_specs, cu);
8613 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8616 do_cleanups (back_to);
8621 /* Main entry point for reading a DIE and all children.
8622 Read the DIE and dump it if requested. */
8624 static struct die_info *
8625 read_die_and_children (const struct die_reader_specs *reader,
8627 gdb_byte **new_info_ptr,
8628 struct die_info *parent)
8630 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8631 new_info_ptr, parent);
8633 if (dwarf2_die_debug)
8635 fprintf_unfiltered (gdb_stdlog,
8636 "\nRead die from %s of %s:\n",
8637 reader->buffer == dwarf2_per_objfile->info.buffer
8639 : reader->buffer == dwarf2_per_objfile->types.buffer
8641 : "unknown section",
8642 reader->abfd->filename);
8643 dump_die (result, dwarf2_die_debug);
8649 /* Read a single die and all its descendents. Set the die's sibling
8650 field to NULL; set other fields in the die correctly, and set all
8651 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8652 location of the info_ptr after reading all of those dies. PARENT
8653 is the parent of the die in question. */
8655 static struct die_info *
8656 read_die_and_children_1 (const struct die_reader_specs *reader,
8658 gdb_byte **new_info_ptr,
8659 struct die_info *parent)
8661 struct die_info *die;
8665 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8668 *new_info_ptr = cur_ptr;
8671 store_in_ref_table (die, reader->cu);
8674 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8678 *new_info_ptr = cur_ptr;
8681 die->sibling = NULL;
8682 die->parent = parent;
8686 /* Read a die, all of its descendents, and all of its siblings; set
8687 all of the fields of all of the dies correctly. Arguments are as
8688 in read_die_and_children. */
8690 static struct die_info *
8691 read_die_and_siblings (const struct die_reader_specs *reader,
8693 gdb_byte **new_info_ptr,
8694 struct die_info *parent)
8696 struct die_info *first_die, *last_sibling;
8700 first_die = last_sibling = NULL;
8704 struct die_info *die
8705 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8709 *new_info_ptr = cur_ptr;
8716 last_sibling->sibling = die;
8722 /* Read the die from the .debug_info section buffer. Set DIEP to
8723 point to a newly allocated die with its information, except for its
8724 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8725 whether the die has children or not. */
8728 read_full_die (const struct die_reader_specs *reader,
8729 struct die_info **diep, gdb_byte *info_ptr,
8732 unsigned int abbrev_number, bytes_read, i, offset;
8733 struct abbrev_info *abbrev;
8734 struct die_info *die;
8735 struct dwarf2_cu *cu = reader->cu;
8736 bfd *abfd = reader->abfd;
8738 offset = info_ptr - reader->buffer;
8739 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8740 info_ptr += bytes_read;
8748 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8750 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8752 bfd_get_filename (abfd));
8754 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8755 die->offset = offset;
8756 die->tag = abbrev->tag;
8757 die->abbrev = abbrev_number;
8759 die->num_attrs = abbrev->num_attrs;
8761 for (i = 0; i < abbrev->num_attrs; ++i)
8762 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8763 abfd, info_ptr, cu);
8766 *has_children = abbrev->has_children;
8770 /* In DWARF version 2, the description of the debugging information is
8771 stored in a separate .debug_abbrev section. Before we read any
8772 dies from a section we read in all abbreviations and install them
8773 in a hash table. This function also sets flags in CU describing
8774 the data found in the abbrev table. */
8777 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8779 struct comp_unit_head *cu_header = &cu->header;
8780 gdb_byte *abbrev_ptr;
8781 struct abbrev_info *cur_abbrev;
8782 unsigned int abbrev_number, bytes_read, abbrev_name;
8783 unsigned int abbrev_form, hash_number;
8784 struct attr_abbrev *cur_attrs;
8785 unsigned int allocated_attrs;
8787 /* Initialize dwarf2 abbrevs. */
8788 obstack_init (&cu->abbrev_obstack);
8789 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
8791 * sizeof (struct abbrev_info *)));
8792 memset (cu->dwarf2_abbrevs, 0,
8793 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
8795 dwarf2_read_section (dwarf2_per_objfile->objfile,
8796 &dwarf2_per_objfile->abbrev);
8797 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
8798 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8799 abbrev_ptr += bytes_read;
8801 allocated_attrs = ATTR_ALLOC_CHUNK;
8802 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
8804 /* Loop until we reach an abbrev number of 0. */
8805 while (abbrev_number)
8807 cur_abbrev = dwarf_alloc_abbrev (cu);
8809 /* read in abbrev header */
8810 cur_abbrev->number = abbrev_number;
8811 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8812 abbrev_ptr += bytes_read;
8813 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
8816 if (cur_abbrev->tag == DW_TAG_namespace)
8817 cu->has_namespace_info = 1;
8819 /* now read in declarations */
8820 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8821 abbrev_ptr += bytes_read;
8822 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8823 abbrev_ptr += bytes_read;
8826 if (cur_abbrev->num_attrs == allocated_attrs)
8828 allocated_attrs += ATTR_ALLOC_CHUNK;
8830 = xrealloc (cur_attrs, (allocated_attrs
8831 * sizeof (struct attr_abbrev)));
8834 /* Record whether this compilation unit might have
8835 inter-compilation-unit references. If we don't know what form
8836 this attribute will have, then it might potentially be a
8837 DW_FORM_ref_addr, so we conservatively expect inter-CU
8840 if (abbrev_form == DW_FORM_ref_addr
8841 || abbrev_form == DW_FORM_indirect)
8842 cu->has_form_ref_addr = 1;
8844 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
8845 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
8846 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8847 abbrev_ptr += bytes_read;
8848 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8849 abbrev_ptr += bytes_read;
8852 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
8853 (cur_abbrev->num_attrs
8854 * sizeof (struct attr_abbrev)));
8855 memcpy (cur_abbrev->attrs, cur_attrs,
8856 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
8858 hash_number = abbrev_number % ABBREV_HASH_SIZE;
8859 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
8860 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
8862 /* Get next abbreviation.
8863 Under Irix6 the abbreviations for a compilation unit are not
8864 always properly terminated with an abbrev number of 0.
8865 Exit loop if we encounter an abbreviation which we have
8866 already read (which means we are about to read the abbreviations
8867 for the next compile unit) or if the end of the abbreviation
8868 table is reached. */
8869 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
8870 >= dwarf2_per_objfile->abbrev.size)
8872 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8873 abbrev_ptr += bytes_read;
8874 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
8881 /* Release the memory used by the abbrev table for a compilation unit. */
8884 dwarf2_free_abbrev_table (void *ptr_to_cu)
8886 struct dwarf2_cu *cu = ptr_to_cu;
8888 obstack_free (&cu->abbrev_obstack, NULL);
8889 cu->dwarf2_abbrevs = NULL;
8892 /* Lookup an abbrev_info structure in the abbrev hash table. */
8894 static struct abbrev_info *
8895 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
8897 unsigned int hash_number;
8898 struct abbrev_info *abbrev;
8900 hash_number = number % ABBREV_HASH_SIZE;
8901 abbrev = cu->dwarf2_abbrevs[hash_number];
8905 if (abbrev->number == number)
8908 abbrev = abbrev->next;
8913 /* Returns nonzero if TAG represents a type that we might generate a partial
8917 is_type_tag_for_partial (int tag)
8922 /* Some types that would be reasonable to generate partial symbols for,
8923 that we don't at present. */
8924 case DW_TAG_array_type:
8925 case DW_TAG_file_type:
8926 case DW_TAG_ptr_to_member_type:
8927 case DW_TAG_set_type:
8928 case DW_TAG_string_type:
8929 case DW_TAG_subroutine_type:
8931 case DW_TAG_base_type:
8932 case DW_TAG_class_type:
8933 case DW_TAG_interface_type:
8934 case DW_TAG_enumeration_type:
8935 case DW_TAG_structure_type:
8936 case DW_TAG_subrange_type:
8937 case DW_TAG_typedef:
8938 case DW_TAG_union_type:
8945 /* Load all DIEs that are interesting for partial symbols into memory. */
8947 static struct partial_die_info *
8948 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
8949 int building_psymtab, struct dwarf2_cu *cu)
8951 struct partial_die_info *part_die;
8952 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
8953 struct abbrev_info *abbrev;
8954 unsigned int bytes_read;
8955 unsigned int load_all = 0;
8957 int nesting_level = 1;
8962 if (cu->per_cu && cu->per_cu->load_all_dies)
8966 = htab_create_alloc_ex (cu->header.length / 12,
8970 &cu->comp_unit_obstack,
8971 hashtab_obstack_allocate,
8972 dummy_obstack_deallocate);
8974 part_die = obstack_alloc (&cu->comp_unit_obstack,
8975 sizeof (struct partial_die_info));
8979 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8981 /* A NULL abbrev means the end of a series of children. */
8984 if (--nesting_level == 0)
8986 /* PART_DIE was probably the last thing allocated on the
8987 comp_unit_obstack, so we could call obstack_free
8988 here. We don't do that because the waste is small,
8989 and will be cleaned up when we're done with this
8990 compilation unit. This way, we're also more robust
8991 against other users of the comp_unit_obstack. */
8994 info_ptr += bytes_read;
8995 last_die = parent_die;
8996 parent_die = parent_die->die_parent;
9000 /* Check for template arguments. We never save these; if
9001 they're seen, we just mark the parent, and go on our way. */
9002 if (parent_die != NULL
9003 && cu->language == language_cplus
9004 && (abbrev->tag == DW_TAG_template_type_param
9005 || abbrev->tag == DW_TAG_template_value_param))
9007 parent_die->has_template_arguments = 1;
9011 /* We don't need a partial DIE for the template argument. */
9012 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9018 /* We only recurse into subprograms looking for template arguments.
9019 Skip their other children. */
9021 && cu->language == language_cplus
9022 && parent_die != NULL
9023 && parent_die->tag == DW_TAG_subprogram)
9025 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9029 /* Check whether this DIE is interesting enough to save. Normally
9030 we would not be interested in members here, but there may be
9031 later variables referencing them via DW_AT_specification (for
9034 && !is_type_tag_for_partial (abbrev->tag)
9035 && abbrev->tag != DW_TAG_constant
9036 && abbrev->tag != DW_TAG_enumerator
9037 && abbrev->tag != DW_TAG_subprogram
9038 && abbrev->tag != DW_TAG_lexical_block
9039 && abbrev->tag != DW_TAG_variable
9040 && abbrev->tag != DW_TAG_namespace
9041 && abbrev->tag != DW_TAG_module
9042 && abbrev->tag != DW_TAG_member)
9044 /* Otherwise we skip to the next sibling, if any. */
9045 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9049 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9050 buffer, info_ptr, cu);
9052 /* This two-pass algorithm for processing partial symbols has a
9053 high cost in cache pressure. Thus, handle some simple cases
9054 here which cover the majority of C partial symbols. DIEs
9055 which neither have specification tags in them, nor could have
9056 specification tags elsewhere pointing at them, can simply be
9057 processed and discarded.
9059 This segment is also optional; scan_partial_symbols and
9060 add_partial_symbol will handle these DIEs if we chain
9061 them in normally. When compilers which do not emit large
9062 quantities of duplicate debug information are more common,
9063 this code can probably be removed. */
9065 /* Any complete simple types at the top level (pretty much all
9066 of them, for a language without namespaces), can be processed
9068 if (parent_die == NULL
9069 && part_die->has_specification == 0
9070 && part_die->is_declaration == 0
9071 && (part_die->tag == DW_TAG_typedef
9072 || part_die->tag == DW_TAG_base_type
9073 || part_die->tag == DW_TAG_subrange_type))
9075 if (building_psymtab && part_die->name != NULL)
9076 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9077 VAR_DOMAIN, LOC_TYPEDEF,
9078 &cu->objfile->static_psymbols,
9079 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9080 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9084 /* If we're at the second level, and we're an enumerator, and
9085 our parent has no specification (meaning possibly lives in a
9086 namespace elsewhere), then we can add the partial symbol now
9087 instead of queueing it. */
9088 if (part_die->tag == DW_TAG_enumerator
9089 && parent_die != NULL
9090 && parent_die->die_parent == NULL
9091 && parent_die->tag == DW_TAG_enumeration_type
9092 && parent_die->has_specification == 0)
9094 if (part_die->name == NULL)
9095 complaint (&symfile_complaints,
9096 _("malformed enumerator DIE ignored"));
9097 else if (building_psymtab)
9098 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9099 VAR_DOMAIN, LOC_CONST,
9100 (cu->language == language_cplus
9101 || cu->language == language_java)
9102 ? &cu->objfile->global_psymbols
9103 : &cu->objfile->static_psymbols,
9104 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9106 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9110 /* We'll save this DIE so link it in. */
9111 part_die->die_parent = parent_die;
9112 part_die->die_sibling = NULL;
9113 part_die->die_child = NULL;
9115 if (last_die && last_die == parent_die)
9116 last_die->die_child = part_die;
9118 last_die->die_sibling = part_die;
9120 last_die = part_die;
9122 if (first_die == NULL)
9123 first_die = part_die;
9125 /* Maybe add the DIE to the hash table. Not all DIEs that we
9126 find interesting need to be in the hash table, because we
9127 also have the parent/sibling/child chains; only those that we
9128 might refer to by offset later during partial symbol reading.
9130 For now this means things that might have be the target of a
9131 DW_AT_specification, DW_AT_abstract_origin, or
9132 DW_AT_extension. DW_AT_extension will refer only to
9133 namespaces; DW_AT_abstract_origin refers to functions (and
9134 many things under the function DIE, but we do not recurse
9135 into function DIEs during partial symbol reading) and
9136 possibly variables as well; DW_AT_specification refers to
9137 declarations. Declarations ought to have the DW_AT_declaration
9138 flag. It happens that GCC forgets to put it in sometimes, but
9139 only for functions, not for types.
9141 Adding more things than necessary to the hash table is harmless
9142 except for the performance cost. Adding too few will result in
9143 wasted time in find_partial_die, when we reread the compilation
9144 unit with load_all_dies set. */
9147 || abbrev->tag == DW_TAG_constant
9148 || abbrev->tag == DW_TAG_subprogram
9149 || abbrev->tag == DW_TAG_variable
9150 || abbrev->tag == DW_TAG_namespace
9151 || part_die->is_declaration)
9155 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9156 part_die->offset, INSERT);
9160 part_die = obstack_alloc (&cu->comp_unit_obstack,
9161 sizeof (struct partial_die_info));
9163 /* For some DIEs we want to follow their children (if any). For C
9164 we have no reason to follow the children of structures; for other
9165 languages we have to, so that we can get at method physnames
9166 to infer fully qualified class names, for DW_AT_specification,
9167 and for C++ template arguments. For C++, we also look one level
9168 inside functions to find template arguments (if the name of the
9169 function does not already contain the template arguments).
9171 For Ada, we need to scan the children of subprograms and lexical
9172 blocks as well because Ada allows the definition of nested
9173 entities that could be interesting for the debugger, such as
9174 nested subprograms for instance. */
9175 if (last_die->has_children
9177 || last_die->tag == DW_TAG_namespace
9178 || last_die->tag == DW_TAG_module
9179 || last_die->tag == DW_TAG_enumeration_type
9180 || (cu->language == language_cplus
9181 && last_die->tag == DW_TAG_subprogram
9182 && (last_die->name == NULL
9183 || strchr (last_die->name, '<') == NULL))
9184 || (cu->language != language_c
9185 && (last_die->tag == DW_TAG_class_type
9186 || last_die->tag == DW_TAG_interface_type
9187 || last_die->tag == DW_TAG_structure_type
9188 || last_die->tag == DW_TAG_union_type))
9189 || (cu->language == language_ada
9190 && (last_die->tag == DW_TAG_subprogram
9191 || last_die->tag == DW_TAG_lexical_block))))
9194 parent_die = last_die;
9198 /* Otherwise we skip to the next sibling, if any. */
9199 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9201 /* Back to the top, do it again. */
9205 /* Read a minimal amount of information into the minimal die structure. */
9208 read_partial_die (struct partial_die_info *part_die,
9209 struct abbrev_info *abbrev,
9210 unsigned int abbrev_len, bfd *abfd,
9211 gdb_byte *buffer, gdb_byte *info_ptr,
9212 struct dwarf2_cu *cu)
9215 struct attribute attr;
9216 int has_low_pc_attr = 0;
9217 int has_high_pc_attr = 0;
9219 memset (part_die, 0, sizeof (struct partial_die_info));
9221 part_die->offset = info_ptr - buffer;
9223 info_ptr += abbrev_len;
9228 part_die->tag = abbrev->tag;
9229 part_die->has_children = abbrev->has_children;
9231 for (i = 0; i < abbrev->num_attrs; ++i)
9233 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9235 /* Store the data if it is of an attribute we want to keep in a
9236 partial symbol table. */
9240 switch (part_die->tag)
9242 case DW_TAG_compile_unit:
9243 case DW_TAG_type_unit:
9244 /* Compilation units have a DW_AT_name that is a filename, not
9245 a source language identifier. */
9246 case DW_TAG_enumeration_type:
9247 case DW_TAG_enumerator:
9248 /* These tags always have simple identifiers already; no need
9249 to canonicalize them. */
9250 part_die->name = DW_STRING (&attr);
9254 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9255 &cu->objfile->objfile_obstack);
9259 case DW_AT_linkage_name:
9260 case DW_AT_MIPS_linkage_name:
9261 /* Note that both forms of linkage name might appear. We
9262 assume they will be the same, and we only store the last
9264 if (cu->language == language_ada)
9265 part_die->name = DW_STRING (&attr);
9266 part_die->linkage_name = DW_STRING (&attr);
9269 has_low_pc_attr = 1;
9270 part_die->lowpc = DW_ADDR (&attr);
9273 has_high_pc_attr = 1;
9274 part_die->highpc = DW_ADDR (&attr);
9276 case DW_AT_location:
9277 /* Support the .debug_loc offsets. */
9278 if (attr_form_is_block (&attr))
9280 part_die->locdesc = DW_BLOCK (&attr);
9282 else if (attr_form_is_section_offset (&attr))
9284 dwarf2_complex_location_expr_complaint ();
9288 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9289 "partial symbol information");
9292 case DW_AT_external:
9293 part_die->is_external = DW_UNSND (&attr);
9295 case DW_AT_declaration:
9296 part_die->is_declaration = DW_UNSND (&attr);
9299 part_die->has_type = 1;
9301 case DW_AT_abstract_origin:
9302 case DW_AT_specification:
9303 case DW_AT_extension:
9304 part_die->has_specification = 1;
9305 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9308 /* Ignore absolute siblings, they might point outside of
9309 the current compile unit. */
9310 if (attr.form == DW_FORM_ref_addr)
9311 complaint (&symfile_complaints,
9312 _("ignoring absolute DW_AT_sibling"));
9314 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9316 case DW_AT_byte_size:
9317 part_die->has_byte_size = 1;
9319 case DW_AT_calling_convention:
9320 /* DWARF doesn't provide a way to identify a program's source-level
9321 entry point. DW_AT_calling_convention attributes are only meant
9322 to describe functions' calling conventions.
9324 However, because it's a necessary piece of information in
9325 Fortran, and because DW_CC_program is the only piece of debugging
9326 information whose definition refers to a 'main program' at all,
9327 several compilers have begun marking Fortran main programs with
9328 DW_CC_program --- even when those functions use the standard
9329 calling conventions.
9331 So until DWARF specifies a way to provide this information and
9332 compilers pick up the new representation, we'll support this
9334 if (DW_UNSND (&attr) == DW_CC_program
9335 && cu->language == language_fortran)
9337 set_main_name (part_die->name);
9339 /* As this DIE has a static linkage the name would be difficult
9340 to look up later. */
9341 language_of_main = language_fortran;
9349 if (has_low_pc_attr && has_high_pc_attr)
9351 /* When using the GNU linker, .gnu.linkonce. sections are used to
9352 eliminate duplicate copies of functions and vtables and such.
9353 The linker will arbitrarily choose one and discard the others.
9354 The AT_*_pc values for such functions refer to local labels in
9355 these sections. If the section from that file was discarded, the
9356 labels are not in the output, so the relocs get a value of 0.
9357 If this is a discarded function, mark the pc bounds as invalid,
9358 so that GDB will ignore it. */
9359 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9361 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9363 complaint (&symfile_complaints,
9364 _("DW_AT_low_pc %s is zero "
9365 "for DIE at 0x%x [in module %s]"),
9366 paddress (gdbarch, part_die->lowpc),
9367 part_die->offset, cu->objfile->name);
9369 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9370 else if (part_die->lowpc >= part_die->highpc)
9372 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9374 complaint (&symfile_complaints,
9375 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9376 "for DIE at 0x%x [in module %s]"),
9377 paddress (gdbarch, part_die->lowpc),
9378 paddress (gdbarch, part_die->highpc),
9379 part_die->offset, cu->objfile->name);
9382 part_die->has_pc_info = 1;
9388 /* Find a cached partial DIE at OFFSET in CU. */
9390 static struct partial_die_info *
9391 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9393 struct partial_die_info *lookup_die = NULL;
9394 struct partial_die_info part_die;
9396 part_die.offset = offset;
9397 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9402 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9403 except in the case of .debug_types DIEs which do not reference
9404 outside their CU (they do however referencing other types via
9405 DW_FORM_ref_sig8). */
9407 static struct partial_die_info *
9408 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9410 struct dwarf2_per_cu_data *per_cu = NULL;
9411 struct partial_die_info *pd = NULL;
9413 if (cu->per_cu->from_debug_types)
9415 pd = find_partial_die_in_comp_unit (offset, cu);
9421 if (offset_in_cu_p (&cu->header, offset))
9423 pd = find_partial_die_in_comp_unit (offset, cu);
9428 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9430 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9431 load_partial_comp_unit (per_cu, cu->objfile);
9433 per_cu->cu->last_used = 0;
9434 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9436 if (pd == NULL && per_cu->load_all_dies == 0)
9438 struct cleanup *back_to;
9439 struct partial_die_info comp_unit_die;
9440 struct abbrev_info *abbrev;
9441 unsigned int bytes_read;
9444 per_cu->load_all_dies = 1;
9446 /* Re-read the DIEs. */
9447 back_to = make_cleanup (null_cleanup, 0);
9448 if (per_cu->cu->dwarf2_abbrevs == NULL)
9450 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
9451 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9453 info_ptr = (dwarf2_per_objfile->info.buffer
9454 + per_cu->cu->header.offset
9455 + per_cu->cu->header.first_die_offset);
9456 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9457 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9458 per_cu->cu->objfile->obfd,
9459 dwarf2_per_objfile->info.buffer, info_ptr,
9461 if (comp_unit_die.has_children)
9462 load_partial_dies (per_cu->cu->objfile->obfd,
9463 dwarf2_per_objfile->info.buffer, info_ptr,
9465 do_cleanups (back_to);
9467 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9473 internal_error (__FILE__, __LINE__,
9474 _("could not find partial DIE 0x%x "
9475 "in cache [from module %s]\n"),
9476 offset, bfd_get_filename (cu->objfile->obfd));
9480 /* See if we can figure out if the class lives in a namespace. We do
9481 this by looking for a member function; its demangled name will
9482 contain namespace info, if there is any. */
9485 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9486 struct dwarf2_cu *cu)
9488 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9489 what template types look like, because the demangler
9490 frequently doesn't give the same name as the debug info. We
9491 could fix this by only using the demangled name to get the
9492 prefix (but see comment in read_structure_type). */
9494 struct partial_die_info *real_pdi;
9495 struct partial_die_info *child_pdi;
9497 /* If this DIE (this DIE's specification, if any) has a parent, then
9498 we should not do this. We'll prepend the parent's fully qualified
9499 name when we create the partial symbol. */
9501 real_pdi = struct_pdi;
9502 while (real_pdi->has_specification)
9503 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9505 if (real_pdi->die_parent != NULL)
9508 for (child_pdi = struct_pdi->die_child;
9510 child_pdi = child_pdi->die_sibling)
9512 if (child_pdi->tag == DW_TAG_subprogram
9513 && child_pdi->linkage_name != NULL)
9515 char *actual_class_name
9516 = language_class_name_from_physname (cu->language_defn,
9517 child_pdi->linkage_name);
9518 if (actual_class_name != NULL)
9521 = obsavestring (actual_class_name,
9522 strlen (actual_class_name),
9523 &cu->objfile->objfile_obstack);
9524 xfree (actual_class_name);
9531 /* Adjust PART_DIE before generating a symbol for it. This function
9532 may set the is_external flag or change the DIE's name. */
9535 fixup_partial_die (struct partial_die_info *part_die,
9536 struct dwarf2_cu *cu)
9538 /* Once we've fixed up a die, there's no point in doing so again.
9539 This also avoids a memory leak if we were to call
9540 guess_partial_die_structure_name multiple times. */
9541 if (part_die->fixup_called)
9544 /* If we found a reference attribute and the DIE has no name, try
9545 to find a name in the referred to DIE. */
9547 if (part_die->name == NULL && part_die->has_specification)
9549 struct partial_die_info *spec_die;
9551 spec_die = find_partial_die (part_die->spec_offset, cu);
9553 fixup_partial_die (spec_die, cu);
9557 part_die->name = spec_die->name;
9559 /* Copy DW_AT_external attribute if it is set. */
9560 if (spec_die->is_external)
9561 part_die->is_external = spec_die->is_external;
9565 /* Set default names for some unnamed DIEs. */
9567 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
9568 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
9570 /* If there is no parent die to provide a namespace, and there are
9571 children, see if we can determine the namespace from their linkage
9573 NOTE: We need to do this even if cu->has_namespace_info != 0.
9574 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9575 if (cu->language == language_cplus
9576 && dwarf2_per_objfile->types.asection != NULL
9577 && part_die->die_parent == NULL
9578 && part_die->has_children
9579 && (part_die->tag == DW_TAG_class_type
9580 || part_die->tag == DW_TAG_structure_type
9581 || part_die->tag == DW_TAG_union_type))
9582 guess_partial_die_structure_name (part_die, cu);
9584 /* GCC might emit a nameless struct or union that has a linkage
9585 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9586 if (part_die->name == NULL
9587 && (part_die->tag == DW_TAG_structure_type
9588 || part_die->tag == DW_TAG_union_type
9589 || part_die->tag == DW_TAG_class_type)
9590 && part_die->linkage_name != NULL)
9594 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
9597 part_die->name = obsavestring (demangled, strlen (demangled),
9598 &cu->objfile->objfile_obstack);
9603 part_die->fixup_called = 1;
9606 /* Read an attribute value described by an attribute form. */
9609 read_attribute_value (struct attribute *attr, unsigned form,
9610 bfd *abfd, gdb_byte *info_ptr,
9611 struct dwarf2_cu *cu)
9613 struct comp_unit_head *cu_header = &cu->header;
9614 unsigned int bytes_read;
9615 struct dwarf_block *blk;
9620 case DW_FORM_ref_addr:
9621 if (cu->header.version == 2)
9622 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9624 DW_ADDR (attr) = read_offset (abfd, info_ptr,
9625 &cu->header, &bytes_read);
9626 info_ptr += bytes_read;
9629 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9630 info_ptr += bytes_read;
9632 case DW_FORM_block2:
9633 blk = dwarf_alloc_block (cu);
9634 blk->size = read_2_bytes (abfd, info_ptr);
9636 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9637 info_ptr += blk->size;
9638 DW_BLOCK (attr) = blk;
9640 case DW_FORM_block4:
9641 blk = dwarf_alloc_block (cu);
9642 blk->size = read_4_bytes (abfd, info_ptr);
9644 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9645 info_ptr += blk->size;
9646 DW_BLOCK (attr) = blk;
9649 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9653 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9657 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9660 case DW_FORM_sec_offset:
9661 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9662 info_ptr += bytes_read;
9664 case DW_FORM_string:
9665 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9666 DW_STRING_IS_CANONICAL (attr) = 0;
9667 info_ptr += bytes_read;
9670 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9672 DW_STRING_IS_CANONICAL (attr) = 0;
9673 info_ptr += bytes_read;
9675 case DW_FORM_exprloc:
9677 blk = dwarf_alloc_block (cu);
9678 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9679 info_ptr += bytes_read;
9680 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9681 info_ptr += blk->size;
9682 DW_BLOCK (attr) = blk;
9684 case DW_FORM_block1:
9685 blk = dwarf_alloc_block (cu);
9686 blk->size = read_1_byte (abfd, info_ptr);
9688 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9689 info_ptr += blk->size;
9690 DW_BLOCK (attr) = blk;
9693 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9697 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9700 case DW_FORM_flag_present:
9701 DW_UNSND (attr) = 1;
9704 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9705 info_ptr += bytes_read;
9708 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9709 info_ptr += bytes_read;
9712 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9716 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9720 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9724 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9727 case DW_FORM_ref_sig8:
9728 /* Convert the signature to something we can record in DW_UNSND
9730 NOTE: This is NULL if the type wasn't found. */
9731 DW_SIGNATURED_TYPE (attr) =
9732 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9735 case DW_FORM_ref_udata:
9736 DW_ADDR (attr) = (cu->header.offset
9737 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9738 info_ptr += bytes_read;
9740 case DW_FORM_indirect:
9741 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9742 info_ptr += bytes_read;
9743 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9746 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9747 dwarf_form_name (form),
9748 bfd_get_filename (abfd));
9751 /* We have seen instances where the compiler tried to emit a byte
9752 size attribute of -1 which ended up being encoded as an unsigned
9753 0xffffffff. Although 0xffffffff is technically a valid size value,
9754 an object of this size seems pretty unlikely so we can relatively
9755 safely treat these cases as if the size attribute was invalid and
9756 treat them as zero by default. */
9757 if (attr->name == DW_AT_byte_size
9758 && form == DW_FORM_data4
9759 && DW_UNSND (attr) >= 0xffffffff)
9762 (&symfile_complaints,
9763 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9764 hex_string (DW_UNSND (attr)));
9765 DW_UNSND (attr) = 0;
9771 /* Read an attribute described by an abbreviated attribute. */
9774 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
9775 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
9777 attr->name = abbrev->name;
9778 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
9781 /* Read dwarf information from a buffer. */
9784 read_1_byte (bfd *abfd, gdb_byte *buf)
9786 return bfd_get_8 (abfd, buf);
9790 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
9792 return bfd_get_signed_8 (abfd, buf);
9796 read_2_bytes (bfd *abfd, gdb_byte *buf)
9798 return bfd_get_16 (abfd, buf);
9802 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
9804 return bfd_get_signed_16 (abfd, buf);
9808 read_4_bytes (bfd *abfd, gdb_byte *buf)
9810 return bfd_get_32 (abfd, buf);
9814 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
9816 return bfd_get_signed_32 (abfd, buf);
9820 read_8_bytes (bfd *abfd, gdb_byte *buf)
9822 return bfd_get_64 (abfd, buf);
9826 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
9827 unsigned int *bytes_read)
9829 struct comp_unit_head *cu_header = &cu->header;
9830 CORE_ADDR retval = 0;
9832 if (cu_header->signed_addr_p)
9834 switch (cu_header->addr_size)
9837 retval = bfd_get_signed_16 (abfd, buf);
9840 retval = bfd_get_signed_32 (abfd, buf);
9843 retval = bfd_get_signed_64 (abfd, buf);
9846 internal_error (__FILE__, __LINE__,
9847 _("read_address: bad switch, signed [in module %s]"),
9848 bfd_get_filename (abfd));
9853 switch (cu_header->addr_size)
9856 retval = bfd_get_16 (abfd, buf);
9859 retval = bfd_get_32 (abfd, buf);
9862 retval = bfd_get_64 (abfd, buf);
9865 internal_error (__FILE__, __LINE__,
9866 _("read_address: bad switch, "
9867 "unsigned [in module %s]"),
9868 bfd_get_filename (abfd));
9872 *bytes_read = cu_header->addr_size;
9876 /* Read the initial length from a section. The (draft) DWARF 3
9877 specification allows the initial length to take up either 4 bytes
9878 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9879 bytes describe the length and all offsets will be 8 bytes in length
9882 An older, non-standard 64-bit format is also handled by this
9883 function. The older format in question stores the initial length
9884 as an 8-byte quantity without an escape value. Lengths greater
9885 than 2^32 aren't very common which means that the initial 4 bytes
9886 is almost always zero. Since a length value of zero doesn't make
9887 sense for the 32-bit format, this initial zero can be considered to
9888 be an escape value which indicates the presence of the older 64-bit
9889 format. As written, the code can't detect (old format) lengths
9890 greater than 4GB. If it becomes necessary to handle lengths
9891 somewhat larger than 4GB, we could allow other small values (such
9892 as the non-sensical values of 1, 2, and 3) to also be used as
9893 escape values indicating the presence of the old format.
9895 The value returned via bytes_read should be used to increment the
9896 relevant pointer after calling read_initial_length().
9898 [ Note: read_initial_length() and read_offset() are based on the
9899 document entitled "DWARF Debugging Information Format", revision
9900 3, draft 8, dated November 19, 2001. This document was obtained
9903 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9905 This document is only a draft and is subject to change. (So beware.)
9907 Details regarding the older, non-standard 64-bit format were
9908 determined empirically by examining 64-bit ELF files produced by
9909 the SGI toolchain on an IRIX 6.5 machine.
9911 - Kevin, July 16, 2002
9915 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
9917 LONGEST length = bfd_get_32 (abfd, buf);
9919 if (length == 0xffffffff)
9921 length = bfd_get_64 (abfd, buf + 4);
9924 else if (length == 0)
9926 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9927 length = bfd_get_64 (abfd, buf);
9938 /* Cover function for read_initial_length.
9939 Returns the length of the object at BUF, and stores the size of the
9940 initial length in *BYTES_READ and stores the size that offsets will be in
9942 If the initial length size is not equivalent to that specified in
9943 CU_HEADER then issue a complaint.
9944 This is useful when reading non-comp-unit headers. */
9947 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
9948 const struct comp_unit_head *cu_header,
9949 unsigned int *bytes_read,
9950 unsigned int *offset_size)
9952 LONGEST length = read_initial_length (abfd, buf, bytes_read);
9954 gdb_assert (cu_header->initial_length_size == 4
9955 || cu_header->initial_length_size == 8
9956 || cu_header->initial_length_size == 12);
9958 if (cu_header->initial_length_size != *bytes_read)
9959 complaint (&symfile_complaints,
9960 _("intermixed 32-bit and 64-bit DWARF sections"));
9962 *offset_size = (*bytes_read == 4) ? 4 : 8;
9966 /* Read an offset from the data stream. The size of the offset is
9967 given by cu_header->offset_size. */
9970 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
9971 unsigned int *bytes_read)
9973 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
9975 *bytes_read = cu_header->offset_size;
9979 /* Read an offset from the data stream. */
9982 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
9986 switch (offset_size)
9989 retval = bfd_get_32 (abfd, buf);
9992 retval = bfd_get_64 (abfd, buf);
9995 internal_error (__FILE__, __LINE__,
9996 _("read_offset_1: bad switch [in module %s]"),
9997 bfd_get_filename (abfd));
10004 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10006 /* If the size of a host char is 8 bits, we can return a pointer
10007 to the buffer, otherwise we have to copy the data to a buffer
10008 allocated on the temporary obstack. */
10009 gdb_assert (HOST_CHAR_BIT == 8);
10014 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10016 /* If the size of a host char is 8 bits, we can return a pointer
10017 to the string, otherwise we have to copy the string to a buffer
10018 allocated on the temporary obstack. */
10019 gdb_assert (HOST_CHAR_BIT == 8);
10022 *bytes_read_ptr = 1;
10025 *bytes_read_ptr = strlen ((char *) buf) + 1;
10026 return (char *) buf;
10030 read_indirect_string (bfd *abfd, gdb_byte *buf,
10031 const struct comp_unit_head *cu_header,
10032 unsigned int *bytes_read_ptr)
10034 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10036 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10037 if (dwarf2_per_objfile->str.buffer == NULL)
10039 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10040 bfd_get_filename (abfd));
10043 if (str_offset >= dwarf2_per_objfile->str.size)
10045 error (_("DW_FORM_strp pointing outside of "
10046 ".debug_str section [in module %s]"),
10047 bfd_get_filename (abfd));
10050 gdb_assert (HOST_CHAR_BIT == 8);
10051 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10053 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10056 static unsigned long
10057 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10059 unsigned long result;
10060 unsigned int num_read;
10062 unsigned char byte;
10070 byte = bfd_get_8 (abfd, buf);
10073 result |= ((unsigned long)(byte & 127) << shift);
10074 if ((byte & 128) == 0)
10080 *bytes_read_ptr = num_read;
10085 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10088 int i, shift, num_read;
10089 unsigned char byte;
10097 byte = bfd_get_8 (abfd, buf);
10100 result |= ((long)(byte & 127) << shift);
10102 if ((byte & 128) == 0)
10107 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10108 result |= -(((long)1) << shift);
10109 *bytes_read_ptr = num_read;
10113 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10116 skip_leb128 (bfd *abfd, gdb_byte *buf)
10122 byte = bfd_get_8 (abfd, buf);
10124 if ((byte & 128) == 0)
10130 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10137 cu->language = language_c;
10139 case DW_LANG_C_plus_plus:
10140 cu->language = language_cplus;
10143 cu->language = language_d;
10145 case DW_LANG_Fortran77:
10146 case DW_LANG_Fortran90:
10147 case DW_LANG_Fortran95:
10148 cu->language = language_fortran;
10150 case DW_LANG_Mips_Assembler:
10151 cu->language = language_asm;
10154 cu->language = language_java;
10156 case DW_LANG_Ada83:
10157 case DW_LANG_Ada95:
10158 cu->language = language_ada;
10160 case DW_LANG_Modula2:
10161 cu->language = language_m2;
10163 case DW_LANG_Pascal83:
10164 cu->language = language_pascal;
10167 cu->language = language_objc;
10169 case DW_LANG_Cobol74:
10170 case DW_LANG_Cobol85:
10172 cu->language = language_minimal;
10175 cu->language_defn = language_def (cu->language);
10178 /* Return the named attribute or NULL if not there. */
10180 static struct attribute *
10181 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10184 struct attribute *spec = NULL;
10186 for (i = 0; i < die->num_attrs; ++i)
10188 if (die->attrs[i].name == name)
10189 return &die->attrs[i];
10190 if (die->attrs[i].name == DW_AT_specification
10191 || die->attrs[i].name == DW_AT_abstract_origin)
10192 spec = &die->attrs[i];
10197 die = follow_die_ref (die, spec, &cu);
10198 return dwarf2_attr (die, name, cu);
10204 /* Return the named attribute or NULL if not there,
10205 but do not follow DW_AT_specification, etc.
10206 This is for use in contexts where we're reading .debug_types dies.
10207 Following DW_AT_specification, DW_AT_abstract_origin will take us
10208 back up the chain, and we want to go down. */
10210 static struct attribute *
10211 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10212 struct dwarf2_cu *cu)
10216 for (i = 0; i < die->num_attrs; ++i)
10217 if (die->attrs[i].name == name)
10218 return &die->attrs[i];
10223 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10224 and holds a non-zero value. This function should only be used for
10225 DW_FORM_flag or DW_FORM_flag_present attributes. */
10228 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10230 struct attribute *attr = dwarf2_attr (die, name, cu);
10232 return (attr && DW_UNSND (attr));
10236 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10238 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10239 which value is non-zero. However, we have to be careful with
10240 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10241 (via dwarf2_flag_true_p) follows this attribute. So we may
10242 end up accidently finding a declaration attribute that belongs
10243 to a different DIE referenced by the specification attribute,
10244 even though the given DIE does not have a declaration attribute. */
10245 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10246 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10249 /* Return the die giving the specification for DIE, if there is
10250 one. *SPEC_CU is the CU containing DIE on input, and the CU
10251 containing the return value on output. If there is no
10252 specification, but there is an abstract origin, that is
10255 static struct die_info *
10256 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10258 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10261 if (spec_attr == NULL)
10262 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10264 if (spec_attr == NULL)
10267 return follow_die_ref (die, spec_attr, spec_cu);
10270 /* Free the line_header structure *LH, and any arrays and strings it
10272 NOTE: This is also used as a "cleanup" function. */
10275 free_line_header (struct line_header *lh)
10277 if (lh->standard_opcode_lengths)
10278 xfree (lh->standard_opcode_lengths);
10280 /* Remember that all the lh->file_names[i].name pointers are
10281 pointers into debug_line_buffer, and don't need to be freed. */
10282 if (lh->file_names)
10283 xfree (lh->file_names);
10285 /* Similarly for the include directory names. */
10286 if (lh->include_dirs)
10287 xfree (lh->include_dirs);
10292 /* Add an entry to LH's include directory table. */
10295 add_include_dir (struct line_header *lh, char *include_dir)
10297 /* Grow the array if necessary. */
10298 if (lh->include_dirs_size == 0)
10300 lh->include_dirs_size = 1; /* for testing */
10301 lh->include_dirs = xmalloc (lh->include_dirs_size
10302 * sizeof (*lh->include_dirs));
10304 else if (lh->num_include_dirs >= lh->include_dirs_size)
10306 lh->include_dirs_size *= 2;
10307 lh->include_dirs = xrealloc (lh->include_dirs,
10308 (lh->include_dirs_size
10309 * sizeof (*lh->include_dirs)));
10312 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10315 /* Add an entry to LH's file name table. */
10318 add_file_name (struct line_header *lh,
10320 unsigned int dir_index,
10321 unsigned int mod_time,
10322 unsigned int length)
10324 struct file_entry *fe;
10326 /* Grow the array if necessary. */
10327 if (lh->file_names_size == 0)
10329 lh->file_names_size = 1; /* for testing */
10330 lh->file_names = xmalloc (lh->file_names_size
10331 * sizeof (*lh->file_names));
10333 else if (lh->num_file_names >= lh->file_names_size)
10335 lh->file_names_size *= 2;
10336 lh->file_names = xrealloc (lh->file_names,
10337 (lh->file_names_size
10338 * sizeof (*lh->file_names)));
10341 fe = &lh->file_names[lh->num_file_names++];
10343 fe->dir_index = dir_index;
10344 fe->mod_time = mod_time;
10345 fe->length = length;
10346 fe->included_p = 0;
10350 /* Read the statement program header starting at OFFSET in
10351 .debug_line, according to the endianness of ABFD. Return a pointer
10352 to a struct line_header, allocated using xmalloc.
10354 NOTE: the strings in the include directory and file name tables of
10355 the returned object point into debug_line_buffer, and must not be
10358 static struct line_header *
10359 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10360 struct dwarf2_cu *cu)
10362 struct cleanup *back_to;
10363 struct line_header *lh;
10364 gdb_byte *line_ptr;
10365 unsigned int bytes_read, offset_size;
10367 char *cur_dir, *cur_file;
10369 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10370 if (dwarf2_per_objfile->line.buffer == NULL)
10372 complaint (&symfile_complaints, _("missing .debug_line section"));
10376 /* Make sure that at least there's room for the total_length field.
10377 That could be 12 bytes long, but we're just going to fudge that. */
10378 if (offset + 4 >= dwarf2_per_objfile->line.size)
10380 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10384 lh = xmalloc (sizeof (*lh));
10385 memset (lh, 0, sizeof (*lh));
10386 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10389 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10391 /* Read in the header. */
10393 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10394 &bytes_read, &offset_size);
10395 line_ptr += bytes_read;
10396 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10397 + dwarf2_per_objfile->line.size))
10399 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10402 lh->statement_program_end = line_ptr + lh->total_length;
10403 lh->version = read_2_bytes (abfd, line_ptr);
10405 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10406 line_ptr += offset_size;
10407 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10409 if (lh->version >= 4)
10411 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10415 lh->maximum_ops_per_instruction = 1;
10417 if (lh->maximum_ops_per_instruction == 0)
10419 lh->maximum_ops_per_instruction = 1;
10420 complaint (&symfile_complaints,
10421 _("invalid maximum_ops_per_instruction "
10422 "in `.debug_line' section"));
10425 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10427 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10429 lh->line_range = read_1_byte (abfd, line_ptr);
10431 lh->opcode_base = read_1_byte (abfd, line_ptr);
10433 lh->standard_opcode_lengths
10434 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10436 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10437 for (i = 1; i < lh->opcode_base; ++i)
10439 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10443 /* Read directory table. */
10444 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10446 line_ptr += bytes_read;
10447 add_include_dir (lh, cur_dir);
10449 line_ptr += bytes_read;
10451 /* Read file name table. */
10452 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10454 unsigned int dir_index, mod_time, length;
10456 line_ptr += bytes_read;
10457 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10458 line_ptr += bytes_read;
10459 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10460 line_ptr += bytes_read;
10461 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10462 line_ptr += bytes_read;
10464 add_file_name (lh, cur_file, dir_index, mod_time, length);
10466 line_ptr += bytes_read;
10467 lh->statement_program_start = line_ptr;
10469 if (line_ptr > (dwarf2_per_objfile->line.buffer
10470 + dwarf2_per_objfile->line.size))
10471 complaint (&symfile_complaints,
10472 _("line number info header doesn't "
10473 "fit in `.debug_line' section"));
10475 discard_cleanups (back_to);
10479 /* This function exists to work around a bug in certain compilers
10480 (particularly GCC 2.95), in which the first line number marker of a
10481 function does not show up until after the prologue, right before
10482 the second line number marker. This function shifts ADDRESS down
10483 to the beginning of the function if necessary, and is called on
10484 addresses passed to record_line. */
10487 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
10489 struct function_range *fn;
10491 /* Find the function_range containing address. */
10495 if (!cu->cached_fn)
10496 cu->cached_fn = cu->first_fn;
10498 fn = cu->cached_fn;
10500 if (fn->lowpc <= address && fn->highpc > address)
10506 while (fn && fn != cu->cached_fn)
10507 if (fn->lowpc <= address && fn->highpc > address)
10517 if (address != fn->lowpc)
10518 complaint (&symfile_complaints,
10519 _("misplaced first line number at 0x%lx for '%s'"),
10520 (unsigned long) address, fn->name);
10525 /* Subroutine of dwarf_decode_lines to simplify it.
10526 Return the file name of the psymtab for included file FILE_INDEX
10527 in line header LH of PST.
10528 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10529 If space for the result is malloc'd, it will be freed by a cleanup.
10530 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10533 psymtab_include_file_name (const struct line_header *lh, int file_index,
10534 const struct partial_symtab *pst,
10535 const char *comp_dir)
10537 const struct file_entry fe = lh->file_names [file_index];
10538 char *include_name = fe.name;
10539 char *include_name_to_compare = include_name;
10540 char *dir_name = NULL;
10541 const char *pst_filename;
10542 char *copied_name = NULL;
10546 dir_name = lh->include_dirs[fe.dir_index - 1];
10548 if (!IS_ABSOLUTE_PATH (include_name)
10549 && (dir_name != NULL || comp_dir != NULL))
10551 /* Avoid creating a duplicate psymtab for PST.
10552 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10553 Before we do the comparison, however, we need to account
10554 for DIR_NAME and COMP_DIR.
10555 First prepend dir_name (if non-NULL). If we still don't
10556 have an absolute path prepend comp_dir (if non-NULL).
10557 However, the directory we record in the include-file's
10558 psymtab does not contain COMP_DIR (to match the
10559 corresponding symtab(s)).
10564 bash$ gcc -g ./hello.c
10565 include_name = "hello.c"
10567 DW_AT_comp_dir = comp_dir = "/tmp"
10568 DW_AT_name = "./hello.c" */
10570 if (dir_name != NULL)
10572 include_name = concat (dir_name, SLASH_STRING,
10573 include_name, (char *)NULL);
10574 include_name_to_compare = include_name;
10575 make_cleanup (xfree, include_name);
10577 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
10579 include_name_to_compare = concat (comp_dir, SLASH_STRING,
10580 include_name, (char *)NULL);
10584 pst_filename = pst->filename;
10585 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
10587 copied_name = concat (pst->dirname, SLASH_STRING,
10588 pst_filename, (char *)NULL);
10589 pst_filename = copied_name;
10592 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
10594 if (include_name_to_compare != include_name)
10595 xfree (include_name_to_compare);
10596 if (copied_name != NULL)
10597 xfree (copied_name);
10601 return include_name;
10604 /* Ignore this record_line request. */
10607 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
10612 /* Decode the Line Number Program (LNP) for the given line_header
10613 structure and CU. The actual information extracted and the type
10614 of structures created from the LNP depends on the value of PST.
10616 1. If PST is NULL, then this procedure uses the data from the program
10617 to create all necessary symbol tables, and their linetables.
10619 2. If PST is not NULL, this procedure reads the program to determine
10620 the list of files included by the unit represented by PST, and
10621 builds all the associated partial symbol tables.
10623 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10624 It is used for relative paths in the line table.
10625 NOTE: When processing partial symtabs (pst != NULL),
10626 comp_dir == pst->dirname.
10628 NOTE: It is important that psymtabs have the same file name (via strcmp)
10629 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10630 symtab we don't use it in the name of the psymtabs we create.
10631 E.g. expand_line_sal requires this when finding psymtabs to expand.
10632 A good testcase for this is mb-inline.exp. */
10635 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
10636 struct dwarf2_cu *cu, struct partial_symtab *pst)
10638 gdb_byte *line_ptr, *extended_end;
10639 gdb_byte *line_end;
10640 unsigned int bytes_read, extended_len;
10641 unsigned char op_code, extended_op, adj_opcode;
10642 CORE_ADDR baseaddr;
10643 struct objfile *objfile = cu->objfile;
10644 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10645 const int decode_for_pst_p = (pst != NULL);
10646 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10647 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
10650 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10652 line_ptr = lh->statement_program_start;
10653 line_end = lh->statement_program_end;
10655 /* Read the statement sequences until there's nothing left. */
10656 while (line_ptr < line_end)
10658 /* state machine registers */
10659 CORE_ADDR address = 0;
10660 unsigned int file = 1;
10661 unsigned int line = 1;
10662 unsigned int column = 0;
10663 int is_stmt = lh->default_is_stmt;
10664 int basic_block = 0;
10665 int end_sequence = 0;
10667 unsigned char op_index = 0;
10669 if (!decode_for_pst_p && lh->num_file_names >= file)
10671 /* Start a subfile for the current file of the state machine. */
10672 /* lh->include_dirs and lh->file_names are 0-based, but the
10673 directory and file name numbers in the statement program
10675 struct file_entry *fe = &lh->file_names[file - 1];
10679 dir = lh->include_dirs[fe->dir_index - 1];
10681 dwarf2_start_subfile (fe->name, dir, comp_dir);
10684 /* Decode the table. */
10685 while (!end_sequence)
10687 op_code = read_1_byte (abfd, line_ptr);
10689 if (line_ptr > line_end)
10691 dwarf2_debug_line_missing_end_sequence_complaint ();
10695 if (op_code >= lh->opcode_base)
10697 /* Special operand. */
10698 adj_opcode = op_code - lh->opcode_base;
10699 address += (((op_index + (adj_opcode / lh->line_range))
10700 / lh->maximum_ops_per_instruction)
10701 * lh->minimum_instruction_length);
10702 op_index = ((op_index + (adj_opcode / lh->line_range))
10703 % lh->maximum_ops_per_instruction);
10704 line += lh->line_base + (adj_opcode % lh->line_range);
10705 if (lh->num_file_names < file || file == 0)
10706 dwarf2_debug_line_missing_file_complaint ();
10707 /* For now we ignore lines not starting on an
10708 instruction boundary. */
10709 else if (op_index == 0)
10711 lh->file_names[file - 1].included_p = 1;
10712 if (!decode_for_pst_p && is_stmt)
10714 if (last_subfile != current_subfile)
10716 addr = gdbarch_addr_bits_remove (gdbarch, address);
10718 (*p_record_line) (last_subfile, 0, addr);
10719 last_subfile = current_subfile;
10721 /* Append row to matrix using current values. */
10722 addr = check_cu_functions (address, cu);
10723 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10724 (*p_record_line) (current_subfile, line, addr);
10729 else switch (op_code)
10731 case DW_LNS_extended_op:
10732 extended_len = read_unsigned_leb128 (abfd, line_ptr,
10734 line_ptr += bytes_read;
10735 extended_end = line_ptr + extended_len;
10736 extended_op = read_1_byte (abfd, line_ptr);
10738 switch (extended_op)
10740 case DW_LNE_end_sequence:
10741 p_record_line = record_line;
10744 case DW_LNE_set_address:
10745 address = read_address (abfd, line_ptr, cu, &bytes_read);
10747 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
10749 /* This line table is for a function which has been
10750 GCd by the linker. Ignore it. PR gdb/12528 */
10753 = line_ptr - dwarf2_per_objfile->line.buffer;
10755 complaint (&symfile_complaints,
10756 _(".debug_line address at offset 0x%lx is 0 "
10758 line_offset, cu->objfile->name);
10759 p_record_line = noop_record_line;
10763 line_ptr += bytes_read;
10764 address += baseaddr;
10766 case DW_LNE_define_file:
10769 unsigned int dir_index, mod_time, length;
10771 cur_file = read_direct_string (abfd, line_ptr,
10773 line_ptr += bytes_read;
10775 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10776 line_ptr += bytes_read;
10778 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10779 line_ptr += bytes_read;
10781 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10782 line_ptr += bytes_read;
10783 add_file_name (lh, cur_file, dir_index, mod_time, length);
10786 case DW_LNE_set_discriminator:
10787 /* The discriminator is not interesting to the debugger;
10789 line_ptr = extended_end;
10792 complaint (&symfile_complaints,
10793 _("mangled .debug_line section"));
10796 /* Make sure that we parsed the extended op correctly. If e.g.
10797 we expected a different address size than the producer used,
10798 we may have read the wrong number of bytes. */
10799 if (line_ptr != extended_end)
10801 complaint (&symfile_complaints,
10802 _("mangled .debug_line section"));
10807 if (lh->num_file_names < file || file == 0)
10808 dwarf2_debug_line_missing_file_complaint ();
10811 lh->file_names[file - 1].included_p = 1;
10812 if (!decode_for_pst_p && is_stmt)
10814 if (last_subfile != current_subfile)
10816 addr = gdbarch_addr_bits_remove (gdbarch, address);
10818 (*p_record_line) (last_subfile, 0, addr);
10819 last_subfile = current_subfile;
10821 addr = check_cu_functions (address, cu);
10822 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10823 (*p_record_line) (current_subfile, line, addr);
10828 case DW_LNS_advance_pc:
10831 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10833 address += (((op_index + adjust)
10834 / lh->maximum_ops_per_instruction)
10835 * lh->minimum_instruction_length);
10836 op_index = ((op_index + adjust)
10837 % lh->maximum_ops_per_instruction);
10838 line_ptr += bytes_read;
10841 case DW_LNS_advance_line:
10842 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
10843 line_ptr += bytes_read;
10845 case DW_LNS_set_file:
10847 /* The arrays lh->include_dirs and lh->file_names are
10848 0-based, but the directory and file name numbers in
10849 the statement program are 1-based. */
10850 struct file_entry *fe;
10853 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10854 line_ptr += bytes_read;
10855 if (lh->num_file_names < file || file == 0)
10856 dwarf2_debug_line_missing_file_complaint ();
10859 fe = &lh->file_names[file - 1];
10861 dir = lh->include_dirs[fe->dir_index - 1];
10862 if (!decode_for_pst_p)
10864 last_subfile = current_subfile;
10865 dwarf2_start_subfile (fe->name, dir, comp_dir);
10870 case DW_LNS_set_column:
10871 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10872 line_ptr += bytes_read;
10874 case DW_LNS_negate_stmt:
10875 is_stmt = (!is_stmt);
10877 case DW_LNS_set_basic_block:
10880 /* Add to the address register of the state machine the
10881 address increment value corresponding to special opcode
10882 255. I.e., this value is scaled by the minimum
10883 instruction length since special opcode 255 would have
10884 scaled the increment. */
10885 case DW_LNS_const_add_pc:
10887 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
10889 address += (((op_index + adjust)
10890 / lh->maximum_ops_per_instruction)
10891 * lh->minimum_instruction_length);
10892 op_index = ((op_index + adjust)
10893 % lh->maximum_ops_per_instruction);
10896 case DW_LNS_fixed_advance_pc:
10897 address += read_2_bytes (abfd, line_ptr);
10903 /* Unknown standard opcode, ignore it. */
10906 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
10908 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10909 line_ptr += bytes_read;
10914 if (lh->num_file_names < file || file == 0)
10915 dwarf2_debug_line_missing_file_complaint ();
10918 lh->file_names[file - 1].included_p = 1;
10919 if (!decode_for_pst_p)
10921 addr = gdbarch_addr_bits_remove (gdbarch, address);
10922 (*p_record_line) (current_subfile, 0, addr);
10927 if (decode_for_pst_p)
10931 /* Now that we're done scanning the Line Header Program, we can
10932 create the psymtab of each included file. */
10933 for (file_index = 0; file_index < lh->num_file_names; file_index++)
10934 if (lh->file_names[file_index].included_p == 1)
10936 char *include_name =
10937 psymtab_include_file_name (lh, file_index, pst, comp_dir);
10938 if (include_name != NULL)
10939 dwarf2_create_include_psymtab (include_name, pst, objfile);
10944 /* Make sure a symtab is created for every file, even files
10945 which contain only variables (i.e. no code with associated
10949 struct file_entry *fe;
10951 for (i = 0; i < lh->num_file_names; i++)
10955 fe = &lh->file_names[i];
10957 dir = lh->include_dirs[fe->dir_index - 1];
10958 dwarf2_start_subfile (fe->name, dir, comp_dir);
10960 /* Skip the main file; we don't need it, and it must be
10961 allocated last, so that it will show up before the
10962 non-primary symtabs in the objfile's symtab list. */
10963 if (current_subfile == first_subfile)
10966 if (current_subfile->symtab == NULL)
10967 current_subfile->symtab = allocate_symtab (current_subfile->name,
10969 fe->symtab = current_subfile->symtab;
10974 /* Start a subfile for DWARF. FILENAME is the name of the file and
10975 DIRNAME the name of the source directory which contains FILENAME
10976 or NULL if not known. COMP_DIR is the compilation directory for the
10977 linetable's compilation unit or NULL if not known.
10978 This routine tries to keep line numbers from identical absolute and
10979 relative file names in a common subfile.
10981 Using the `list' example from the GDB testsuite, which resides in
10982 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10983 of /srcdir/list0.c yields the following debugging information for list0.c:
10985 DW_AT_name: /srcdir/list0.c
10986 DW_AT_comp_dir: /compdir
10987 files.files[0].name: list0.h
10988 files.files[0].dir: /srcdir
10989 files.files[1].name: list0.c
10990 files.files[1].dir: /srcdir
10992 The line number information for list0.c has to end up in a single
10993 subfile, so that `break /srcdir/list0.c:1' works as expected.
10994 start_subfile will ensure that this happens provided that we pass the
10995 concatenation of files.files[1].dir and files.files[1].name as the
10999 dwarf2_start_subfile (char *filename, const char *dirname,
11000 const char *comp_dir)
11004 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11005 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11006 second argument to start_subfile. To be consistent, we do the
11007 same here. In order not to lose the line information directory,
11008 we concatenate it to the filename when it makes sense.
11009 Note that the Dwarf3 standard says (speaking of filenames in line
11010 information): ``The directory index is ignored for file names
11011 that represent full path names''. Thus ignoring dirname in the
11012 `else' branch below isn't an issue. */
11014 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11015 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11017 fullname = filename;
11019 start_subfile (fullname, comp_dir);
11021 if (fullname != filename)
11026 var_decode_location (struct attribute *attr, struct symbol *sym,
11027 struct dwarf2_cu *cu)
11029 struct objfile *objfile = cu->objfile;
11030 struct comp_unit_head *cu_header = &cu->header;
11032 /* NOTE drow/2003-01-30: There used to be a comment and some special
11033 code here to turn a symbol with DW_AT_external and a
11034 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11035 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11036 with some versions of binutils) where shared libraries could have
11037 relocations against symbols in their debug information - the
11038 minimal symbol would have the right address, but the debug info
11039 would not. It's no longer necessary, because we will explicitly
11040 apply relocations when we read in the debug information now. */
11042 /* A DW_AT_location attribute with no contents indicates that a
11043 variable has been optimized away. */
11044 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11046 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11050 /* Handle one degenerate form of location expression specially, to
11051 preserve GDB's previous behavior when section offsets are
11052 specified. If this is just a DW_OP_addr then mark this symbol
11055 if (attr_form_is_block (attr)
11056 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11057 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11059 unsigned int dummy;
11061 SYMBOL_VALUE_ADDRESS (sym) =
11062 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11063 SYMBOL_CLASS (sym) = LOC_STATIC;
11064 fixup_symbol_section (sym, objfile);
11065 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11066 SYMBOL_SECTION (sym));
11070 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11071 expression evaluator, and use LOC_COMPUTED only when necessary
11072 (i.e. when the value of a register or memory location is
11073 referenced, or a thread-local block, etc.). Then again, it might
11074 not be worthwhile. I'm assuming that it isn't unless performance
11075 or memory numbers show me otherwise. */
11077 dwarf2_symbol_mark_computed (attr, sym, cu);
11078 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11080 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11081 cu->has_loclist = 1;
11084 /* Given a pointer to a DWARF information entry, figure out if we need
11085 to make a symbol table entry for it, and if so, create a new entry
11086 and return a pointer to it.
11087 If TYPE is NULL, determine symbol type from the die, otherwise
11088 used the passed type.
11089 If SPACE is not NULL, use it to hold the new symbol. If it is
11090 NULL, allocate a new symbol on the objfile's obstack. */
11092 static struct symbol *
11093 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11094 struct symbol *space)
11096 struct objfile *objfile = cu->objfile;
11097 struct symbol *sym = NULL;
11099 struct attribute *attr = NULL;
11100 struct attribute *attr2 = NULL;
11101 CORE_ADDR baseaddr;
11102 struct pending **list_to_add = NULL;
11104 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11106 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11108 name = dwarf2_name (die, cu);
11111 const char *linkagename;
11112 int suppress_add = 0;
11117 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11118 OBJSTAT (objfile, n_syms++);
11120 /* Cache this symbol's name and the name's demangled form (if any). */
11121 SYMBOL_SET_LANGUAGE (sym, cu->language);
11122 linkagename = dwarf2_physname (name, die, cu);
11123 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11125 /* Fortran does not have mangling standard and the mangling does differ
11126 between gfortran, iFort etc. */
11127 if (cu->language == language_fortran
11128 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11129 symbol_set_demangled_name (&(sym->ginfo),
11130 (char *) dwarf2_full_name (name, die, cu),
11133 /* Default assumptions.
11134 Use the passed type or decode it from the die. */
11135 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11136 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11138 SYMBOL_TYPE (sym) = type;
11140 SYMBOL_TYPE (sym) = die_type (die, cu);
11141 attr = dwarf2_attr (die,
11142 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11146 SYMBOL_LINE (sym) = DW_UNSND (attr);
11149 attr = dwarf2_attr (die,
11150 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11154 int file_index = DW_UNSND (attr);
11156 if (cu->line_header == NULL
11157 || file_index > cu->line_header->num_file_names)
11158 complaint (&symfile_complaints,
11159 _("file index out of range"));
11160 else if (file_index > 0)
11162 struct file_entry *fe;
11164 fe = &cu->line_header->file_names[file_index - 1];
11165 SYMBOL_SYMTAB (sym) = fe->symtab;
11172 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11175 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11177 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11178 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11179 SYMBOL_CLASS (sym) = LOC_LABEL;
11180 add_symbol_to_list (sym, cu->list_in_scope);
11182 case DW_TAG_subprogram:
11183 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11185 SYMBOL_CLASS (sym) = LOC_BLOCK;
11186 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11187 if ((attr2 && (DW_UNSND (attr2) != 0))
11188 || cu->language == language_ada)
11190 /* Subprograms marked external are stored as a global symbol.
11191 Ada subprograms, whether marked external or not, are always
11192 stored as a global symbol, because we want to be able to
11193 access them globally. For instance, we want to be able
11194 to break on a nested subprogram without having to
11195 specify the context. */
11196 list_to_add = &global_symbols;
11200 list_to_add = cu->list_in_scope;
11203 case DW_TAG_inlined_subroutine:
11204 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11206 SYMBOL_CLASS (sym) = LOC_BLOCK;
11207 SYMBOL_INLINED (sym) = 1;
11208 /* Do not add the symbol to any lists. It will be found via
11209 BLOCK_FUNCTION from the blockvector. */
11211 case DW_TAG_template_value_param:
11213 /* Fall through. */
11214 case DW_TAG_constant:
11215 case DW_TAG_variable:
11216 case DW_TAG_member:
11217 /* Compilation with minimal debug info may result in
11218 variables with missing type entries. Change the
11219 misleading `void' type to something sensible. */
11220 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11222 = objfile_type (objfile)->nodebug_data_symbol;
11224 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11225 /* In the case of DW_TAG_member, we should only be called for
11226 static const members. */
11227 if (die->tag == DW_TAG_member)
11229 /* dwarf2_add_field uses die_is_declaration,
11230 so we do the same. */
11231 gdb_assert (die_is_declaration (die, cu));
11236 dwarf2_const_value (attr, sym, cu);
11237 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11240 if (attr2 && (DW_UNSND (attr2) != 0))
11241 list_to_add = &global_symbols;
11243 list_to_add = cu->list_in_scope;
11247 attr = dwarf2_attr (die, DW_AT_location, cu);
11250 var_decode_location (attr, sym, cu);
11251 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11252 if (SYMBOL_CLASS (sym) == LOC_STATIC
11253 && SYMBOL_VALUE_ADDRESS (sym) == 0
11254 && !dwarf2_per_objfile->has_section_at_zero)
11256 /* When a static variable is eliminated by the linker,
11257 the corresponding debug information is not stripped
11258 out, but the variable address is set to null;
11259 do not add such variables into symbol table. */
11261 else if (attr2 && (DW_UNSND (attr2) != 0))
11263 /* Workaround gfortran PR debug/40040 - it uses
11264 DW_AT_location for variables in -fPIC libraries which may
11265 get overriden by other libraries/executable and get
11266 a different address. Resolve it by the minimal symbol
11267 which may come from inferior's executable using copy
11268 relocation. Make this workaround only for gfortran as for
11269 other compilers GDB cannot guess the minimal symbol
11270 Fortran mangling kind. */
11271 if (cu->language == language_fortran && die->parent
11272 && die->parent->tag == DW_TAG_module
11274 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11275 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11277 /* A variable with DW_AT_external is never static,
11278 but it may be block-scoped. */
11279 list_to_add = (cu->list_in_scope == &file_symbols
11280 ? &global_symbols : cu->list_in_scope);
11283 list_to_add = cu->list_in_scope;
11287 /* We do not know the address of this symbol.
11288 If it is an external symbol and we have type information
11289 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11290 The address of the variable will then be determined from
11291 the minimal symbol table whenever the variable is
11293 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11294 if (attr2 && (DW_UNSND (attr2) != 0)
11295 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11297 /* A variable with DW_AT_external is never static, but it
11298 may be block-scoped. */
11299 list_to_add = (cu->list_in_scope == &file_symbols
11300 ? &global_symbols : cu->list_in_scope);
11302 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11304 else if (!die_is_declaration (die, cu))
11306 /* Use the default LOC_OPTIMIZED_OUT class. */
11307 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11309 list_to_add = cu->list_in_scope;
11313 case DW_TAG_formal_parameter:
11314 /* If we are inside a function, mark this as an argument. If
11315 not, we might be looking at an argument to an inlined function
11316 when we do not have enough information to show inlined frames;
11317 pretend it's a local variable in that case so that the user can
11319 if (context_stack_depth > 0
11320 && context_stack[context_stack_depth - 1].name != NULL)
11321 SYMBOL_IS_ARGUMENT (sym) = 1;
11322 attr = dwarf2_attr (die, DW_AT_location, cu);
11325 var_decode_location (attr, sym, cu);
11327 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11330 dwarf2_const_value (attr, sym, cu);
11332 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
11333 if (attr && DW_UNSND (attr))
11335 struct type *ref_type;
11337 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
11338 SYMBOL_TYPE (sym) = ref_type;
11341 list_to_add = cu->list_in_scope;
11343 case DW_TAG_unspecified_parameters:
11344 /* From varargs functions; gdb doesn't seem to have any
11345 interest in this information, so just ignore it for now.
11348 case DW_TAG_template_type_param:
11350 /* Fall through. */
11351 case DW_TAG_class_type:
11352 case DW_TAG_interface_type:
11353 case DW_TAG_structure_type:
11354 case DW_TAG_union_type:
11355 case DW_TAG_set_type:
11356 case DW_TAG_enumeration_type:
11357 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11358 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11361 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11362 really ever be static objects: otherwise, if you try
11363 to, say, break of a class's method and you're in a file
11364 which doesn't mention that class, it won't work unless
11365 the check for all static symbols in lookup_symbol_aux
11366 saves you. See the OtherFileClass tests in
11367 gdb.c++/namespace.exp. */
11371 list_to_add = (cu->list_in_scope == &file_symbols
11372 && (cu->language == language_cplus
11373 || cu->language == language_java)
11374 ? &global_symbols : cu->list_in_scope);
11376 /* The semantics of C++ state that "struct foo {
11377 ... }" also defines a typedef for "foo". A Java
11378 class declaration also defines a typedef for the
11380 if (cu->language == language_cplus
11381 || cu->language == language_java
11382 || cu->language == language_ada)
11384 /* The symbol's name is already allocated along
11385 with this objfile, so we don't need to
11386 duplicate it for the type. */
11387 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11388 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11393 case DW_TAG_typedef:
11394 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11395 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11396 list_to_add = cu->list_in_scope;
11398 case DW_TAG_base_type:
11399 case DW_TAG_subrange_type:
11400 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11401 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11402 list_to_add = cu->list_in_scope;
11404 case DW_TAG_enumerator:
11405 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11408 dwarf2_const_value (attr, sym, cu);
11411 /* NOTE: carlton/2003-11-10: See comment above in the
11412 DW_TAG_class_type, etc. block. */
11414 list_to_add = (cu->list_in_scope == &file_symbols
11415 && (cu->language == language_cplus
11416 || cu->language == language_java)
11417 ? &global_symbols : cu->list_in_scope);
11420 case DW_TAG_namespace:
11421 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11422 list_to_add = &global_symbols;
11425 /* Not a tag we recognize. Hopefully we aren't processing
11426 trash data, but since we must specifically ignore things
11427 we don't recognize, there is nothing else we should do at
11429 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11430 dwarf_tag_name (die->tag));
11436 sym->hash_next = objfile->template_symbols;
11437 objfile->template_symbols = sym;
11438 list_to_add = NULL;
11441 if (list_to_add != NULL)
11442 add_symbol_to_list (sym, list_to_add);
11444 /* For the benefit of old versions of GCC, check for anonymous
11445 namespaces based on the demangled name. */
11446 if (!processing_has_namespace_info
11447 && cu->language == language_cplus)
11448 cp_scan_for_anonymous_namespaces (sym);
11453 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11455 static struct symbol *
11456 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11458 return new_symbol_full (die, type, cu, NULL);
11461 /* Given an attr with a DW_FORM_dataN value in host byte order,
11462 zero-extend it as appropriate for the symbol's type. The DWARF
11463 standard (v4) is not entirely clear about the meaning of using
11464 DW_FORM_dataN for a constant with a signed type, where the type is
11465 wider than the data. The conclusion of a discussion on the DWARF
11466 list was that this is unspecified. We choose to always zero-extend
11467 because that is the interpretation long in use by GCC. */
11470 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11471 const char *name, struct obstack *obstack,
11472 struct dwarf2_cu *cu, long *value, int bits)
11474 struct objfile *objfile = cu->objfile;
11475 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11476 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11477 LONGEST l = DW_UNSND (attr);
11479 if (bits < sizeof (*value) * 8)
11481 l &= ((LONGEST) 1 << bits) - 1;
11484 else if (bits == sizeof (*value) * 8)
11488 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11489 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11496 /* Read a constant value from an attribute. Either set *VALUE, or if
11497 the value does not fit in *VALUE, set *BYTES - either already
11498 allocated on the objfile obstack, or newly allocated on OBSTACK,
11499 or, set *BATON, if we translated the constant to a location
11503 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11504 const char *name, struct obstack *obstack,
11505 struct dwarf2_cu *cu,
11506 long *value, gdb_byte **bytes,
11507 struct dwarf2_locexpr_baton **baton)
11509 struct objfile *objfile = cu->objfile;
11510 struct comp_unit_head *cu_header = &cu->header;
11511 struct dwarf_block *blk;
11512 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11513 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11519 switch (attr->form)
11525 if (TYPE_LENGTH (type) != cu_header->addr_size)
11526 dwarf2_const_value_length_mismatch_complaint (name,
11527 cu_header->addr_size,
11528 TYPE_LENGTH (type));
11529 /* Symbols of this form are reasonably rare, so we just
11530 piggyback on the existing location code rather than writing
11531 a new implementation of symbol_computed_ops. */
11532 *baton = obstack_alloc (&objfile->objfile_obstack,
11533 sizeof (struct dwarf2_locexpr_baton));
11534 (*baton)->per_cu = cu->per_cu;
11535 gdb_assert ((*baton)->per_cu);
11537 (*baton)->size = 2 + cu_header->addr_size;
11538 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11539 (*baton)->data = data;
11541 data[0] = DW_OP_addr;
11542 store_unsigned_integer (&data[1], cu_header->addr_size,
11543 byte_order, DW_ADDR (attr));
11544 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11547 case DW_FORM_string:
11549 /* DW_STRING is already allocated on the objfile obstack, point
11551 *bytes = (gdb_byte *) DW_STRING (attr);
11553 case DW_FORM_block1:
11554 case DW_FORM_block2:
11555 case DW_FORM_block4:
11556 case DW_FORM_block:
11557 case DW_FORM_exprloc:
11558 blk = DW_BLOCK (attr);
11559 if (TYPE_LENGTH (type) != blk->size)
11560 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11561 TYPE_LENGTH (type));
11562 *bytes = blk->data;
11565 /* The DW_AT_const_value attributes are supposed to carry the
11566 symbol's value "represented as it would be on the target
11567 architecture." By the time we get here, it's already been
11568 converted to host endianness, so we just need to sign- or
11569 zero-extend it as appropriate. */
11570 case DW_FORM_data1:
11571 *bytes = dwarf2_const_value_data (attr, type, name,
11572 obstack, cu, value, 8);
11574 case DW_FORM_data2:
11575 *bytes = dwarf2_const_value_data (attr, type, name,
11576 obstack, cu, value, 16);
11578 case DW_FORM_data4:
11579 *bytes = dwarf2_const_value_data (attr, type, name,
11580 obstack, cu, value, 32);
11582 case DW_FORM_data8:
11583 *bytes = dwarf2_const_value_data (attr, type, name,
11584 obstack, cu, value, 64);
11587 case DW_FORM_sdata:
11588 *value = DW_SND (attr);
11591 case DW_FORM_udata:
11592 *value = DW_UNSND (attr);
11596 complaint (&symfile_complaints,
11597 _("unsupported const value attribute form: '%s'"),
11598 dwarf_form_name (attr->form));
11605 /* Copy constant value from an attribute to a symbol. */
11608 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
11609 struct dwarf2_cu *cu)
11611 struct objfile *objfile = cu->objfile;
11612 struct comp_unit_head *cu_header = &cu->header;
11615 struct dwarf2_locexpr_baton *baton;
11617 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
11618 SYMBOL_PRINT_NAME (sym),
11619 &objfile->objfile_obstack, cu,
11620 &value, &bytes, &baton);
11624 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11625 SYMBOL_LOCATION_BATON (sym) = baton;
11626 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11628 else if (bytes != NULL)
11630 SYMBOL_VALUE_BYTES (sym) = bytes;
11631 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
11635 SYMBOL_VALUE (sym) = value;
11636 SYMBOL_CLASS (sym) = LOC_CONST;
11640 /* Return the type of the die in question using its DW_AT_type attribute. */
11642 static struct type *
11643 die_type (struct die_info *die, struct dwarf2_cu *cu)
11645 struct attribute *type_attr;
11647 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11650 /* A missing DW_AT_type represents a void type. */
11651 return objfile_type (cu->objfile)->builtin_void;
11654 return lookup_die_type (die, type_attr, cu);
11657 /* True iff CU's producer generates GNAT Ada auxiliary information
11658 that allows to find parallel types through that information instead
11659 of having to do expensive parallel lookups by type name. */
11662 need_gnat_info (struct dwarf2_cu *cu)
11664 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11665 of GNAT produces this auxiliary information, without any indication
11666 that it is produced. Part of enhancing the FSF version of GNAT
11667 to produce that information will be to put in place an indicator
11668 that we can use in order to determine whether the descriptive type
11669 info is available or not. One suggestion that has been made is
11670 to use a new attribute, attached to the CU die. For now, assume
11671 that the descriptive type info is not available. */
11675 /* Return the auxiliary type of the die in question using its
11676 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11677 attribute is not present. */
11679 static struct type *
11680 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11682 struct attribute *type_attr;
11684 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11688 return lookup_die_type (die, type_attr, cu);
11691 /* If DIE has a descriptive_type attribute, then set the TYPE's
11692 descriptive type accordingly. */
11695 set_descriptive_type (struct type *type, struct die_info *die,
11696 struct dwarf2_cu *cu)
11698 struct type *descriptive_type = die_descriptive_type (die, cu);
11700 if (descriptive_type)
11702 ALLOCATE_GNAT_AUX_TYPE (type);
11703 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11707 /* Return the containing type of the die in question using its
11708 DW_AT_containing_type attribute. */
11710 static struct type *
11711 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11713 struct attribute *type_attr;
11715 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11717 error (_("Dwarf Error: Problem turning containing type into gdb type "
11718 "[in module %s]"), cu->objfile->name);
11720 return lookup_die_type (die, type_attr, cu);
11723 /* Look up the type of DIE in CU using its type attribute ATTR.
11724 If there is no type substitute an error marker. */
11726 static struct type *
11727 lookup_die_type (struct die_info *die, struct attribute *attr,
11728 struct dwarf2_cu *cu)
11730 struct type *this_type;
11732 /* First see if we have it cached. */
11734 if (is_ref_attr (attr))
11736 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11738 this_type = get_die_type_at_offset (offset, cu->per_cu);
11740 else if (attr->form == DW_FORM_ref_sig8)
11742 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11743 struct dwarf2_cu *sig_cu;
11744 unsigned int offset;
11746 /* sig_type will be NULL if the signatured type is missing from
11748 if (sig_type == NULL)
11749 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11750 "at 0x%x [in module %s]"),
11751 die->offset, cu->objfile->name);
11753 gdb_assert (sig_type->per_cu.from_debug_types);
11754 offset = sig_type->offset + sig_type->type_offset;
11755 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11759 dump_die_for_error (die);
11760 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11761 dwarf_attr_name (attr->name), cu->objfile->name);
11764 /* If not cached we need to read it in. */
11766 if (this_type == NULL)
11768 struct die_info *type_die;
11769 struct dwarf2_cu *type_cu = cu;
11771 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11772 /* If the type is cached, we should have found it above. */
11773 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11774 this_type = read_type_die_1 (type_die, type_cu);
11777 /* If we still don't have a type use an error marker. */
11779 if (this_type == NULL)
11781 char *message, *saved;
11783 /* read_type_die already issued a complaint. */
11784 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11788 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
11789 message, strlen (message));
11792 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
11798 /* Return the type in DIE, CU.
11799 Returns NULL for invalid types.
11801 This first does a lookup in the appropriate type_hash table,
11802 and only reads the die in if necessary.
11804 NOTE: This can be called when reading in partial or full symbols. */
11806 static struct type *
11807 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
11809 struct type *this_type;
11811 this_type = get_die_type (die, cu);
11815 return read_type_die_1 (die, cu);
11818 /* Read the type in DIE, CU.
11819 Returns NULL for invalid types. */
11821 static struct type *
11822 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11824 struct type *this_type = NULL;
11828 case DW_TAG_class_type:
11829 case DW_TAG_interface_type:
11830 case DW_TAG_structure_type:
11831 case DW_TAG_union_type:
11832 this_type = read_structure_type (die, cu);
11834 case DW_TAG_enumeration_type:
11835 this_type = read_enumeration_type (die, cu);
11837 case DW_TAG_subprogram:
11838 case DW_TAG_subroutine_type:
11839 case DW_TAG_inlined_subroutine:
11840 this_type = read_subroutine_type (die, cu);
11842 case DW_TAG_array_type:
11843 this_type = read_array_type (die, cu);
11845 case DW_TAG_set_type:
11846 this_type = read_set_type (die, cu);
11848 case DW_TAG_pointer_type:
11849 this_type = read_tag_pointer_type (die, cu);
11851 case DW_TAG_ptr_to_member_type:
11852 this_type = read_tag_ptr_to_member_type (die, cu);
11854 case DW_TAG_reference_type:
11855 this_type = read_tag_reference_type (die, cu);
11857 case DW_TAG_const_type:
11858 this_type = read_tag_const_type (die, cu);
11860 case DW_TAG_volatile_type:
11861 this_type = read_tag_volatile_type (die, cu);
11863 case DW_TAG_string_type:
11864 this_type = read_tag_string_type (die, cu);
11866 case DW_TAG_typedef:
11867 this_type = read_typedef (die, cu);
11869 case DW_TAG_subrange_type:
11870 this_type = read_subrange_type (die, cu);
11872 case DW_TAG_base_type:
11873 this_type = read_base_type (die, cu);
11875 case DW_TAG_unspecified_type:
11876 this_type = read_unspecified_type (die, cu);
11878 case DW_TAG_namespace:
11879 this_type = read_namespace_type (die, cu);
11881 case DW_TAG_module:
11882 this_type = read_module_type (die, cu);
11885 complaint (&symfile_complaints,
11886 _("unexpected tag in read_type_die: '%s'"),
11887 dwarf_tag_name (die->tag));
11894 /* See if we can figure out if the class lives in a namespace. We do
11895 this by looking for a member function; its demangled name will
11896 contain namespace info, if there is any.
11897 Return the computed name or NULL.
11898 Space for the result is allocated on the objfile's obstack.
11899 This is the full-die version of guess_partial_die_structure_name.
11900 In this case we know DIE has no useful parent. */
11903 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
11905 struct die_info *spec_die;
11906 struct dwarf2_cu *spec_cu;
11907 struct die_info *child;
11910 spec_die = die_specification (die, &spec_cu);
11911 if (spec_die != NULL)
11917 for (child = die->child;
11919 child = child->sibling)
11921 if (child->tag == DW_TAG_subprogram)
11923 struct attribute *attr;
11925 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
11927 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
11931 = language_class_name_from_physname (cu->language_defn,
11935 if (actual_name != NULL)
11937 char *die_name = dwarf2_name (die, cu);
11939 if (die_name != NULL
11940 && strcmp (die_name, actual_name) != 0)
11942 /* Strip off the class name from the full name.
11943 We want the prefix. */
11944 int die_name_len = strlen (die_name);
11945 int actual_name_len = strlen (actual_name);
11947 /* Test for '::' as a sanity check. */
11948 if (actual_name_len > die_name_len + 2
11949 && actual_name[actual_name_len
11950 - die_name_len - 1] == ':')
11952 obsavestring (actual_name,
11953 actual_name_len - die_name_len - 2,
11954 &cu->objfile->objfile_obstack);
11957 xfree (actual_name);
11966 /* Return the name of the namespace/class that DIE is defined within,
11967 or "" if we can't tell. The caller should not xfree the result.
11969 For example, if we're within the method foo() in the following
11979 then determine_prefix on foo's die will return "N::C". */
11982 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
11984 struct die_info *parent, *spec_die;
11985 struct dwarf2_cu *spec_cu;
11986 struct type *parent_type;
11988 if (cu->language != language_cplus && cu->language != language_java
11989 && cu->language != language_fortran)
11992 /* We have to be careful in the presence of DW_AT_specification.
11993 For example, with GCC 3.4, given the code
11997 // Definition of N::foo.
12001 then we'll have a tree of DIEs like this:
12003 1: DW_TAG_compile_unit
12004 2: DW_TAG_namespace // N
12005 3: DW_TAG_subprogram // declaration of N::foo
12006 4: DW_TAG_subprogram // definition of N::foo
12007 DW_AT_specification // refers to die #3
12009 Thus, when processing die #4, we have to pretend that we're in
12010 the context of its DW_AT_specification, namely the contex of die
12013 spec_die = die_specification (die, &spec_cu);
12014 if (spec_die == NULL)
12015 parent = die->parent;
12018 parent = spec_die->parent;
12022 if (parent == NULL)
12024 else if (parent->building_fullname)
12027 const char *parent_name;
12029 /* It has been seen on RealView 2.2 built binaries,
12030 DW_TAG_template_type_param types actually _defined_ as
12031 children of the parent class:
12034 template class <class Enum> Class{};
12035 Class<enum E> class_e;
12037 1: DW_TAG_class_type (Class)
12038 2: DW_TAG_enumeration_type (E)
12039 3: DW_TAG_enumerator (enum1:0)
12040 3: DW_TAG_enumerator (enum2:1)
12042 2: DW_TAG_template_type_param
12043 DW_AT_type DW_FORM_ref_udata (E)
12045 Besides being broken debug info, it can put GDB into an
12046 infinite loop. Consider:
12048 When we're building the full name for Class<E>, we'll start
12049 at Class, and go look over its template type parameters,
12050 finding E. We'll then try to build the full name of E, and
12051 reach here. We're now trying to build the full name of E,
12052 and look over the parent DIE for containing scope. In the
12053 broken case, if we followed the parent DIE of E, we'd again
12054 find Class, and once again go look at its template type
12055 arguments, etc., etc. Simply don't consider such parent die
12056 as source-level parent of this die (it can't be, the language
12057 doesn't allow it), and break the loop here. */
12058 name = dwarf2_name (die, cu);
12059 parent_name = dwarf2_name (parent, cu);
12060 complaint (&symfile_complaints,
12061 _("template param type '%s' defined within parent '%s'"),
12062 name ? name : "<unknown>",
12063 parent_name ? parent_name : "<unknown>");
12067 switch (parent->tag)
12069 case DW_TAG_namespace:
12070 parent_type = read_type_die (parent, cu);
12071 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12072 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12073 Work around this problem here. */
12074 if (cu->language == language_cplus
12075 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12077 /* We give a name to even anonymous namespaces. */
12078 return TYPE_TAG_NAME (parent_type);
12079 case DW_TAG_class_type:
12080 case DW_TAG_interface_type:
12081 case DW_TAG_structure_type:
12082 case DW_TAG_union_type:
12083 case DW_TAG_module:
12084 parent_type = read_type_die (parent, cu);
12085 if (TYPE_TAG_NAME (parent_type) != NULL)
12086 return TYPE_TAG_NAME (parent_type);
12088 /* An anonymous structure is only allowed non-static data
12089 members; no typedefs, no member functions, et cetera.
12090 So it does not need a prefix. */
12092 case DW_TAG_compile_unit:
12093 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12094 if (cu->language == language_cplus
12095 && dwarf2_per_objfile->types.asection != NULL
12096 && die->child != NULL
12097 && (die->tag == DW_TAG_class_type
12098 || die->tag == DW_TAG_structure_type
12099 || die->tag == DW_TAG_union_type))
12101 char *name = guess_full_die_structure_name (die, cu);
12107 return determine_prefix (parent, cu);
12111 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12112 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12113 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12114 an obconcat, otherwise allocate storage for the result. The CU argument is
12115 used to determine the language and hence, the appropriate separator. */
12117 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12120 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12121 int physname, struct dwarf2_cu *cu)
12123 const char *lead = "";
12126 if (suffix == NULL || suffix[0] == '\0'
12127 || prefix == NULL || prefix[0] == '\0')
12129 else if (cu->language == language_java)
12131 else if (cu->language == language_fortran && physname)
12133 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12134 DW_AT_MIPS_linkage_name is preferred and used instead. */
12142 if (prefix == NULL)
12144 if (suffix == NULL)
12150 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12152 strcpy (retval, lead);
12153 strcat (retval, prefix);
12154 strcat (retval, sep);
12155 strcat (retval, suffix);
12160 /* We have an obstack. */
12161 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12165 /* Return sibling of die, NULL if no sibling. */
12167 static struct die_info *
12168 sibling_die (struct die_info *die)
12170 return die->sibling;
12173 /* Get name of a die, return NULL if not found. */
12176 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12177 struct obstack *obstack)
12179 if (name && cu->language == language_cplus)
12181 char *canon_name = cp_canonicalize_string (name);
12183 if (canon_name != NULL)
12185 if (strcmp (canon_name, name) != 0)
12186 name = obsavestring (canon_name, strlen (canon_name),
12188 xfree (canon_name);
12195 /* Get name of a die, return NULL if not found. */
12198 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12200 struct attribute *attr;
12202 attr = dwarf2_attr (die, DW_AT_name, cu);
12203 if ((!attr || !DW_STRING (attr))
12204 && die->tag != DW_TAG_class_type
12205 && die->tag != DW_TAG_interface_type
12206 && die->tag != DW_TAG_structure_type
12207 && die->tag != DW_TAG_union_type)
12212 case DW_TAG_compile_unit:
12213 /* Compilation units have a DW_AT_name that is a filename, not
12214 a source language identifier. */
12215 case DW_TAG_enumeration_type:
12216 case DW_TAG_enumerator:
12217 /* These tags always have simple identifiers already; no need
12218 to canonicalize them. */
12219 return DW_STRING (attr);
12221 case DW_TAG_subprogram:
12222 /* Java constructors will all be named "<init>", so return
12223 the class name when we see this special case. */
12224 if (cu->language == language_java
12225 && DW_STRING (attr) != NULL
12226 && strcmp (DW_STRING (attr), "<init>") == 0)
12228 struct dwarf2_cu *spec_cu = cu;
12229 struct die_info *spec_die;
12231 /* GCJ will output '<init>' for Java constructor names.
12232 For this special case, return the name of the parent class. */
12234 /* GCJ may output suprogram DIEs with AT_specification set.
12235 If so, use the name of the specified DIE. */
12236 spec_die = die_specification (die, &spec_cu);
12237 if (spec_die != NULL)
12238 return dwarf2_name (spec_die, spec_cu);
12243 if (die->tag == DW_TAG_class_type)
12244 return dwarf2_name (die, cu);
12246 while (die->tag != DW_TAG_compile_unit);
12250 case DW_TAG_class_type:
12251 case DW_TAG_interface_type:
12252 case DW_TAG_structure_type:
12253 case DW_TAG_union_type:
12254 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12255 structures or unions. These were of the form "._%d" in GCC 4.1,
12256 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12257 and GCC 4.4. We work around this problem by ignoring these. */
12258 if (attr && DW_STRING (attr)
12259 && (strncmp (DW_STRING (attr), "._", 2) == 0
12260 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12263 /* GCC might emit a nameless typedef that has a linkage name. See
12264 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12265 if (!attr || DW_STRING (attr) == NULL)
12267 char *demangled = NULL;
12269 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12271 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12273 if (attr == NULL || DW_STRING (attr) == NULL)
12276 /* Avoid demangling DW_STRING (attr) the second time on a second
12277 call for the same DIE. */
12278 if (!DW_STRING_IS_CANONICAL (attr))
12279 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12283 /* FIXME: we already did this for the partial symbol... */
12285 = obsavestring (demangled, strlen (demangled),
12286 &cu->objfile->objfile_obstack);
12287 DW_STRING_IS_CANONICAL (attr) = 1;
12297 if (!DW_STRING_IS_CANONICAL (attr))
12300 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12301 &cu->objfile->objfile_obstack);
12302 DW_STRING_IS_CANONICAL (attr) = 1;
12304 return DW_STRING (attr);
12307 /* Return the die that this die in an extension of, or NULL if there
12308 is none. *EXT_CU is the CU containing DIE on input, and the CU
12309 containing the return value on output. */
12311 static struct die_info *
12312 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12314 struct attribute *attr;
12316 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12320 return follow_die_ref (die, attr, ext_cu);
12323 /* Convert a DIE tag into its string name. */
12326 dwarf_tag_name (unsigned tag)
12330 case DW_TAG_padding:
12331 return "DW_TAG_padding";
12332 case DW_TAG_array_type:
12333 return "DW_TAG_array_type";
12334 case DW_TAG_class_type:
12335 return "DW_TAG_class_type";
12336 case DW_TAG_entry_point:
12337 return "DW_TAG_entry_point";
12338 case DW_TAG_enumeration_type:
12339 return "DW_TAG_enumeration_type";
12340 case DW_TAG_formal_parameter:
12341 return "DW_TAG_formal_parameter";
12342 case DW_TAG_imported_declaration:
12343 return "DW_TAG_imported_declaration";
12345 return "DW_TAG_label";
12346 case DW_TAG_lexical_block:
12347 return "DW_TAG_lexical_block";
12348 case DW_TAG_member:
12349 return "DW_TAG_member";
12350 case DW_TAG_pointer_type:
12351 return "DW_TAG_pointer_type";
12352 case DW_TAG_reference_type:
12353 return "DW_TAG_reference_type";
12354 case DW_TAG_compile_unit:
12355 return "DW_TAG_compile_unit";
12356 case DW_TAG_string_type:
12357 return "DW_TAG_string_type";
12358 case DW_TAG_structure_type:
12359 return "DW_TAG_structure_type";
12360 case DW_TAG_subroutine_type:
12361 return "DW_TAG_subroutine_type";
12362 case DW_TAG_typedef:
12363 return "DW_TAG_typedef";
12364 case DW_TAG_union_type:
12365 return "DW_TAG_union_type";
12366 case DW_TAG_unspecified_parameters:
12367 return "DW_TAG_unspecified_parameters";
12368 case DW_TAG_variant:
12369 return "DW_TAG_variant";
12370 case DW_TAG_common_block:
12371 return "DW_TAG_common_block";
12372 case DW_TAG_common_inclusion:
12373 return "DW_TAG_common_inclusion";
12374 case DW_TAG_inheritance:
12375 return "DW_TAG_inheritance";
12376 case DW_TAG_inlined_subroutine:
12377 return "DW_TAG_inlined_subroutine";
12378 case DW_TAG_module:
12379 return "DW_TAG_module";
12380 case DW_TAG_ptr_to_member_type:
12381 return "DW_TAG_ptr_to_member_type";
12382 case DW_TAG_set_type:
12383 return "DW_TAG_set_type";
12384 case DW_TAG_subrange_type:
12385 return "DW_TAG_subrange_type";
12386 case DW_TAG_with_stmt:
12387 return "DW_TAG_with_stmt";
12388 case DW_TAG_access_declaration:
12389 return "DW_TAG_access_declaration";
12390 case DW_TAG_base_type:
12391 return "DW_TAG_base_type";
12392 case DW_TAG_catch_block:
12393 return "DW_TAG_catch_block";
12394 case DW_TAG_const_type:
12395 return "DW_TAG_const_type";
12396 case DW_TAG_constant:
12397 return "DW_TAG_constant";
12398 case DW_TAG_enumerator:
12399 return "DW_TAG_enumerator";
12400 case DW_TAG_file_type:
12401 return "DW_TAG_file_type";
12402 case DW_TAG_friend:
12403 return "DW_TAG_friend";
12404 case DW_TAG_namelist:
12405 return "DW_TAG_namelist";
12406 case DW_TAG_namelist_item:
12407 return "DW_TAG_namelist_item";
12408 case DW_TAG_packed_type:
12409 return "DW_TAG_packed_type";
12410 case DW_TAG_subprogram:
12411 return "DW_TAG_subprogram";
12412 case DW_TAG_template_type_param:
12413 return "DW_TAG_template_type_param";
12414 case DW_TAG_template_value_param:
12415 return "DW_TAG_template_value_param";
12416 case DW_TAG_thrown_type:
12417 return "DW_TAG_thrown_type";
12418 case DW_TAG_try_block:
12419 return "DW_TAG_try_block";
12420 case DW_TAG_variant_part:
12421 return "DW_TAG_variant_part";
12422 case DW_TAG_variable:
12423 return "DW_TAG_variable";
12424 case DW_TAG_volatile_type:
12425 return "DW_TAG_volatile_type";
12426 case DW_TAG_dwarf_procedure:
12427 return "DW_TAG_dwarf_procedure";
12428 case DW_TAG_restrict_type:
12429 return "DW_TAG_restrict_type";
12430 case DW_TAG_interface_type:
12431 return "DW_TAG_interface_type";
12432 case DW_TAG_namespace:
12433 return "DW_TAG_namespace";
12434 case DW_TAG_imported_module:
12435 return "DW_TAG_imported_module";
12436 case DW_TAG_unspecified_type:
12437 return "DW_TAG_unspecified_type";
12438 case DW_TAG_partial_unit:
12439 return "DW_TAG_partial_unit";
12440 case DW_TAG_imported_unit:
12441 return "DW_TAG_imported_unit";
12442 case DW_TAG_condition:
12443 return "DW_TAG_condition";
12444 case DW_TAG_shared_type:
12445 return "DW_TAG_shared_type";
12446 case DW_TAG_type_unit:
12447 return "DW_TAG_type_unit";
12448 case DW_TAG_MIPS_loop:
12449 return "DW_TAG_MIPS_loop";
12450 case DW_TAG_HP_array_descriptor:
12451 return "DW_TAG_HP_array_descriptor";
12452 case DW_TAG_format_label:
12453 return "DW_TAG_format_label";
12454 case DW_TAG_function_template:
12455 return "DW_TAG_function_template";
12456 case DW_TAG_class_template:
12457 return "DW_TAG_class_template";
12458 case DW_TAG_GNU_BINCL:
12459 return "DW_TAG_GNU_BINCL";
12460 case DW_TAG_GNU_EINCL:
12461 return "DW_TAG_GNU_EINCL";
12462 case DW_TAG_upc_shared_type:
12463 return "DW_TAG_upc_shared_type";
12464 case DW_TAG_upc_strict_type:
12465 return "DW_TAG_upc_strict_type";
12466 case DW_TAG_upc_relaxed_type:
12467 return "DW_TAG_upc_relaxed_type";
12468 case DW_TAG_PGI_kanji_type:
12469 return "DW_TAG_PGI_kanji_type";
12470 case DW_TAG_PGI_interface_block:
12471 return "DW_TAG_PGI_interface_block";
12473 return "DW_TAG_<unknown>";
12477 /* Convert a DWARF attribute code into its string name. */
12480 dwarf_attr_name (unsigned attr)
12484 case DW_AT_sibling:
12485 return "DW_AT_sibling";
12486 case DW_AT_location:
12487 return "DW_AT_location";
12489 return "DW_AT_name";
12490 case DW_AT_ordering:
12491 return "DW_AT_ordering";
12492 case DW_AT_subscr_data:
12493 return "DW_AT_subscr_data";
12494 case DW_AT_byte_size:
12495 return "DW_AT_byte_size";
12496 case DW_AT_bit_offset:
12497 return "DW_AT_bit_offset";
12498 case DW_AT_bit_size:
12499 return "DW_AT_bit_size";
12500 case DW_AT_element_list:
12501 return "DW_AT_element_list";
12502 case DW_AT_stmt_list:
12503 return "DW_AT_stmt_list";
12505 return "DW_AT_low_pc";
12506 case DW_AT_high_pc:
12507 return "DW_AT_high_pc";
12508 case DW_AT_language:
12509 return "DW_AT_language";
12511 return "DW_AT_member";
12513 return "DW_AT_discr";
12514 case DW_AT_discr_value:
12515 return "DW_AT_discr_value";
12516 case DW_AT_visibility:
12517 return "DW_AT_visibility";
12519 return "DW_AT_import";
12520 case DW_AT_string_length:
12521 return "DW_AT_string_length";
12522 case DW_AT_common_reference:
12523 return "DW_AT_common_reference";
12524 case DW_AT_comp_dir:
12525 return "DW_AT_comp_dir";
12526 case DW_AT_const_value:
12527 return "DW_AT_const_value";
12528 case DW_AT_containing_type:
12529 return "DW_AT_containing_type";
12530 case DW_AT_default_value:
12531 return "DW_AT_default_value";
12533 return "DW_AT_inline";
12534 case DW_AT_is_optional:
12535 return "DW_AT_is_optional";
12536 case DW_AT_lower_bound:
12537 return "DW_AT_lower_bound";
12538 case DW_AT_producer:
12539 return "DW_AT_producer";
12540 case DW_AT_prototyped:
12541 return "DW_AT_prototyped";
12542 case DW_AT_return_addr:
12543 return "DW_AT_return_addr";
12544 case DW_AT_start_scope:
12545 return "DW_AT_start_scope";
12546 case DW_AT_bit_stride:
12547 return "DW_AT_bit_stride";
12548 case DW_AT_upper_bound:
12549 return "DW_AT_upper_bound";
12550 case DW_AT_abstract_origin:
12551 return "DW_AT_abstract_origin";
12552 case DW_AT_accessibility:
12553 return "DW_AT_accessibility";
12554 case DW_AT_address_class:
12555 return "DW_AT_address_class";
12556 case DW_AT_artificial:
12557 return "DW_AT_artificial";
12558 case DW_AT_base_types:
12559 return "DW_AT_base_types";
12560 case DW_AT_calling_convention:
12561 return "DW_AT_calling_convention";
12563 return "DW_AT_count";
12564 case DW_AT_data_member_location:
12565 return "DW_AT_data_member_location";
12566 case DW_AT_decl_column:
12567 return "DW_AT_decl_column";
12568 case DW_AT_decl_file:
12569 return "DW_AT_decl_file";
12570 case DW_AT_decl_line:
12571 return "DW_AT_decl_line";
12572 case DW_AT_declaration:
12573 return "DW_AT_declaration";
12574 case DW_AT_discr_list:
12575 return "DW_AT_discr_list";
12576 case DW_AT_encoding:
12577 return "DW_AT_encoding";
12578 case DW_AT_external:
12579 return "DW_AT_external";
12580 case DW_AT_frame_base:
12581 return "DW_AT_frame_base";
12583 return "DW_AT_friend";
12584 case DW_AT_identifier_case:
12585 return "DW_AT_identifier_case";
12586 case DW_AT_macro_info:
12587 return "DW_AT_macro_info";
12588 case DW_AT_namelist_items:
12589 return "DW_AT_namelist_items";
12590 case DW_AT_priority:
12591 return "DW_AT_priority";
12592 case DW_AT_segment:
12593 return "DW_AT_segment";
12594 case DW_AT_specification:
12595 return "DW_AT_specification";
12596 case DW_AT_static_link:
12597 return "DW_AT_static_link";
12599 return "DW_AT_type";
12600 case DW_AT_use_location:
12601 return "DW_AT_use_location";
12602 case DW_AT_variable_parameter:
12603 return "DW_AT_variable_parameter";
12604 case DW_AT_virtuality:
12605 return "DW_AT_virtuality";
12606 case DW_AT_vtable_elem_location:
12607 return "DW_AT_vtable_elem_location";
12608 /* DWARF 3 values. */
12609 case DW_AT_allocated:
12610 return "DW_AT_allocated";
12611 case DW_AT_associated:
12612 return "DW_AT_associated";
12613 case DW_AT_data_location:
12614 return "DW_AT_data_location";
12615 case DW_AT_byte_stride:
12616 return "DW_AT_byte_stride";
12617 case DW_AT_entry_pc:
12618 return "DW_AT_entry_pc";
12619 case DW_AT_use_UTF8:
12620 return "DW_AT_use_UTF8";
12621 case DW_AT_extension:
12622 return "DW_AT_extension";
12624 return "DW_AT_ranges";
12625 case DW_AT_trampoline:
12626 return "DW_AT_trampoline";
12627 case DW_AT_call_column:
12628 return "DW_AT_call_column";
12629 case DW_AT_call_file:
12630 return "DW_AT_call_file";
12631 case DW_AT_call_line:
12632 return "DW_AT_call_line";
12633 case DW_AT_description:
12634 return "DW_AT_description";
12635 case DW_AT_binary_scale:
12636 return "DW_AT_binary_scale";
12637 case DW_AT_decimal_scale:
12638 return "DW_AT_decimal_scale";
12640 return "DW_AT_small";
12641 case DW_AT_decimal_sign:
12642 return "DW_AT_decimal_sign";
12643 case DW_AT_digit_count:
12644 return "DW_AT_digit_count";
12645 case DW_AT_picture_string:
12646 return "DW_AT_picture_string";
12647 case DW_AT_mutable:
12648 return "DW_AT_mutable";
12649 case DW_AT_threads_scaled:
12650 return "DW_AT_threads_scaled";
12651 case DW_AT_explicit:
12652 return "DW_AT_explicit";
12653 case DW_AT_object_pointer:
12654 return "DW_AT_object_pointer";
12655 case DW_AT_endianity:
12656 return "DW_AT_endianity";
12657 case DW_AT_elemental:
12658 return "DW_AT_elemental";
12660 return "DW_AT_pure";
12661 case DW_AT_recursive:
12662 return "DW_AT_recursive";
12663 /* DWARF 4 values. */
12664 case DW_AT_signature:
12665 return "DW_AT_signature";
12666 case DW_AT_linkage_name:
12667 return "DW_AT_linkage_name";
12668 /* SGI/MIPS extensions. */
12669 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12670 case DW_AT_MIPS_fde:
12671 return "DW_AT_MIPS_fde";
12673 case DW_AT_MIPS_loop_begin:
12674 return "DW_AT_MIPS_loop_begin";
12675 case DW_AT_MIPS_tail_loop_begin:
12676 return "DW_AT_MIPS_tail_loop_begin";
12677 case DW_AT_MIPS_epilog_begin:
12678 return "DW_AT_MIPS_epilog_begin";
12679 case DW_AT_MIPS_loop_unroll_factor:
12680 return "DW_AT_MIPS_loop_unroll_factor";
12681 case DW_AT_MIPS_software_pipeline_depth:
12682 return "DW_AT_MIPS_software_pipeline_depth";
12683 case DW_AT_MIPS_linkage_name:
12684 return "DW_AT_MIPS_linkage_name";
12685 case DW_AT_MIPS_stride:
12686 return "DW_AT_MIPS_stride";
12687 case DW_AT_MIPS_abstract_name:
12688 return "DW_AT_MIPS_abstract_name";
12689 case DW_AT_MIPS_clone_origin:
12690 return "DW_AT_MIPS_clone_origin";
12691 case DW_AT_MIPS_has_inlines:
12692 return "DW_AT_MIPS_has_inlines";
12693 /* HP extensions. */
12694 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12695 case DW_AT_HP_block_index:
12696 return "DW_AT_HP_block_index";
12698 case DW_AT_HP_unmodifiable:
12699 return "DW_AT_HP_unmodifiable";
12700 case DW_AT_HP_actuals_stmt_list:
12701 return "DW_AT_HP_actuals_stmt_list";
12702 case DW_AT_HP_proc_per_section:
12703 return "DW_AT_HP_proc_per_section";
12704 case DW_AT_HP_raw_data_ptr:
12705 return "DW_AT_HP_raw_data_ptr";
12706 case DW_AT_HP_pass_by_reference:
12707 return "DW_AT_HP_pass_by_reference";
12708 case DW_AT_HP_opt_level:
12709 return "DW_AT_HP_opt_level";
12710 case DW_AT_HP_prof_version_id:
12711 return "DW_AT_HP_prof_version_id";
12712 case DW_AT_HP_opt_flags:
12713 return "DW_AT_HP_opt_flags";
12714 case DW_AT_HP_cold_region_low_pc:
12715 return "DW_AT_HP_cold_region_low_pc";
12716 case DW_AT_HP_cold_region_high_pc:
12717 return "DW_AT_HP_cold_region_high_pc";
12718 case DW_AT_HP_all_variables_modifiable:
12719 return "DW_AT_HP_all_variables_modifiable";
12720 case DW_AT_HP_linkage_name:
12721 return "DW_AT_HP_linkage_name";
12722 case DW_AT_HP_prof_flags:
12723 return "DW_AT_HP_prof_flags";
12724 /* GNU extensions. */
12725 case DW_AT_sf_names:
12726 return "DW_AT_sf_names";
12727 case DW_AT_src_info:
12728 return "DW_AT_src_info";
12729 case DW_AT_mac_info:
12730 return "DW_AT_mac_info";
12731 case DW_AT_src_coords:
12732 return "DW_AT_src_coords";
12733 case DW_AT_body_begin:
12734 return "DW_AT_body_begin";
12735 case DW_AT_body_end:
12736 return "DW_AT_body_end";
12737 case DW_AT_GNU_vector:
12738 return "DW_AT_GNU_vector";
12739 case DW_AT_GNU_odr_signature:
12740 return "DW_AT_GNU_odr_signature";
12741 /* VMS extensions. */
12742 case DW_AT_VMS_rtnbeg_pd_address:
12743 return "DW_AT_VMS_rtnbeg_pd_address";
12744 /* UPC extension. */
12745 case DW_AT_upc_threads_scaled:
12746 return "DW_AT_upc_threads_scaled";
12747 /* PGI (STMicroelectronics) extensions. */
12748 case DW_AT_PGI_lbase:
12749 return "DW_AT_PGI_lbase";
12750 case DW_AT_PGI_soffset:
12751 return "DW_AT_PGI_soffset";
12752 case DW_AT_PGI_lstride:
12753 return "DW_AT_PGI_lstride";
12755 return "DW_AT_<unknown>";
12759 /* Convert a DWARF value form code into its string name. */
12762 dwarf_form_name (unsigned form)
12767 return "DW_FORM_addr";
12768 case DW_FORM_block2:
12769 return "DW_FORM_block2";
12770 case DW_FORM_block4:
12771 return "DW_FORM_block4";
12772 case DW_FORM_data2:
12773 return "DW_FORM_data2";
12774 case DW_FORM_data4:
12775 return "DW_FORM_data4";
12776 case DW_FORM_data8:
12777 return "DW_FORM_data8";
12778 case DW_FORM_string:
12779 return "DW_FORM_string";
12780 case DW_FORM_block:
12781 return "DW_FORM_block";
12782 case DW_FORM_block1:
12783 return "DW_FORM_block1";
12784 case DW_FORM_data1:
12785 return "DW_FORM_data1";
12787 return "DW_FORM_flag";
12788 case DW_FORM_sdata:
12789 return "DW_FORM_sdata";
12791 return "DW_FORM_strp";
12792 case DW_FORM_udata:
12793 return "DW_FORM_udata";
12794 case DW_FORM_ref_addr:
12795 return "DW_FORM_ref_addr";
12797 return "DW_FORM_ref1";
12799 return "DW_FORM_ref2";
12801 return "DW_FORM_ref4";
12803 return "DW_FORM_ref8";
12804 case DW_FORM_ref_udata:
12805 return "DW_FORM_ref_udata";
12806 case DW_FORM_indirect:
12807 return "DW_FORM_indirect";
12808 case DW_FORM_sec_offset:
12809 return "DW_FORM_sec_offset";
12810 case DW_FORM_exprloc:
12811 return "DW_FORM_exprloc";
12812 case DW_FORM_flag_present:
12813 return "DW_FORM_flag_present";
12814 case DW_FORM_ref_sig8:
12815 return "DW_FORM_ref_sig8";
12817 return "DW_FORM_<unknown>";
12821 /* Convert a DWARF stack opcode into its string name. */
12824 dwarf_stack_op_name (unsigned op)
12829 return "DW_OP_addr";
12831 return "DW_OP_deref";
12832 case DW_OP_const1u:
12833 return "DW_OP_const1u";
12834 case DW_OP_const1s:
12835 return "DW_OP_const1s";
12836 case DW_OP_const2u:
12837 return "DW_OP_const2u";
12838 case DW_OP_const2s:
12839 return "DW_OP_const2s";
12840 case DW_OP_const4u:
12841 return "DW_OP_const4u";
12842 case DW_OP_const4s:
12843 return "DW_OP_const4s";
12844 case DW_OP_const8u:
12845 return "DW_OP_const8u";
12846 case DW_OP_const8s:
12847 return "DW_OP_const8s";
12849 return "DW_OP_constu";
12851 return "DW_OP_consts";
12853 return "DW_OP_dup";
12855 return "DW_OP_drop";
12857 return "DW_OP_over";
12859 return "DW_OP_pick";
12861 return "DW_OP_swap";
12863 return "DW_OP_rot";
12865 return "DW_OP_xderef";
12867 return "DW_OP_abs";
12869 return "DW_OP_and";
12871 return "DW_OP_div";
12873 return "DW_OP_minus";
12875 return "DW_OP_mod";
12877 return "DW_OP_mul";
12879 return "DW_OP_neg";
12881 return "DW_OP_not";
12885 return "DW_OP_plus";
12886 case DW_OP_plus_uconst:
12887 return "DW_OP_plus_uconst";
12889 return "DW_OP_shl";
12891 return "DW_OP_shr";
12893 return "DW_OP_shra";
12895 return "DW_OP_xor";
12897 return "DW_OP_bra";
12911 return "DW_OP_skip";
12913 return "DW_OP_lit0";
12915 return "DW_OP_lit1";
12917 return "DW_OP_lit2";
12919 return "DW_OP_lit3";
12921 return "DW_OP_lit4";
12923 return "DW_OP_lit5";
12925 return "DW_OP_lit6";
12927 return "DW_OP_lit7";
12929 return "DW_OP_lit8";
12931 return "DW_OP_lit9";
12933 return "DW_OP_lit10";
12935 return "DW_OP_lit11";
12937 return "DW_OP_lit12";
12939 return "DW_OP_lit13";
12941 return "DW_OP_lit14";
12943 return "DW_OP_lit15";
12945 return "DW_OP_lit16";
12947 return "DW_OP_lit17";
12949 return "DW_OP_lit18";
12951 return "DW_OP_lit19";
12953 return "DW_OP_lit20";
12955 return "DW_OP_lit21";
12957 return "DW_OP_lit22";
12959 return "DW_OP_lit23";
12961 return "DW_OP_lit24";
12963 return "DW_OP_lit25";
12965 return "DW_OP_lit26";
12967 return "DW_OP_lit27";
12969 return "DW_OP_lit28";
12971 return "DW_OP_lit29";
12973 return "DW_OP_lit30";
12975 return "DW_OP_lit31";
12977 return "DW_OP_reg0";
12979 return "DW_OP_reg1";
12981 return "DW_OP_reg2";
12983 return "DW_OP_reg3";
12985 return "DW_OP_reg4";
12987 return "DW_OP_reg5";
12989 return "DW_OP_reg6";
12991 return "DW_OP_reg7";
12993 return "DW_OP_reg8";
12995 return "DW_OP_reg9";
12997 return "DW_OP_reg10";
12999 return "DW_OP_reg11";
13001 return "DW_OP_reg12";
13003 return "DW_OP_reg13";
13005 return "DW_OP_reg14";
13007 return "DW_OP_reg15";
13009 return "DW_OP_reg16";
13011 return "DW_OP_reg17";
13013 return "DW_OP_reg18";
13015 return "DW_OP_reg19";
13017 return "DW_OP_reg20";
13019 return "DW_OP_reg21";
13021 return "DW_OP_reg22";
13023 return "DW_OP_reg23";
13025 return "DW_OP_reg24";
13027 return "DW_OP_reg25";
13029 return "DW_OP_reg26";
13031 return "DW_OP_reg27";
13033 return "DW_OP_reg28";
13035 return "DW_OP_reg29";
13037 return "DW_OP_reg30";
13039 return "DW_OP_reg31";
13041 return "DW_OP_breg0";
13043 return "DW_OP_breg1";
13045 return "DW_OP_breg2";
13047 return "DW_OP_breg3";
13049 return "DW_OP_breg4";
13051 return "DW_OP_breg5";
13053 return "DW_OP_breg6";
13055 return "DW_OP_breg7";
13057 return "DW_OP_breg8";
13059 return "DW_OP_breg9";
13061 return "DW_OP_breg10";
13063 return "DW_OP_breg11";
13065 return "DW_OP_breg12";
13067 return "DW_OP_breg13";
13069 return "DW_OP_breg14";
13071 return "DW_OP_breg15";
13073 return "DW_OP_breg16";
13075 return "DW_OP_breg17";
13077 return "DW_OP_breg18";
13079 return "DW_OP_breg19";
13081 return "DW_OP_breg20";
13083 return "DW_OP_breg21";
13085 return "DW_OP_breg22";
13087 return "DW_OP_breg23";
13089 return "DW_OP_breg24";
13091 return "DW_OP_breg25";
13093 return "DW_OP_breg26";
13095 return "DW_OP_breg27";
13097 return "DW_OP_breg28";
13099 return "DW_OP_breg29";
13101 return "DW_OP_breg30";
13103 return "DW_OP_breg31";
13105 return "DW_OP_regx";
13107 return "DW_OP_fbreg";
13109 return "DW_OP_bregx";
13111 return "DW_OP_piece";
13112 case DW_OP_deref_size:
13113 return "DW_OP_deref_size";
13114 case DW_OP_xderef_size:
13115 return "DW_OP_xderef_size";
13117 return "DW_OP_nop";
13118 /* DWARF 3 extensions. */
13119 case DW_OP_push_object_address:
13120 return "DW_OP_push_object_address";
13122 return "DW_OP_call2";
13124 return "DW_OP_call4";
13125 case DW_OP_call_ref:
13126 return "DW_OP_call_ref";
13127 case DW_OP_form_tls_address:
13128 return "DW_OP_form_tls_address";
13129 case DW_OP_call_frame_cfa:
13130 return "DW_OP_call_frame_cfa";
13131 case DW_OP_bit_piece:
13132 return "DW_OP_bit_piece";
13133 /* DWARF 4 extensions. */
13134 case DW_OP_implicit_value:
13135 return "DW_OP_implicit_value";
13136 case DW_OP_stack_value:
13137 return "DW_OP_stack_value";
13138 /* GNU extensions. */
13139 case DW_OP_GNU_push_tls_address:
13140 return "DW_OP_GNU_push_tls_address";
13141 case DW_OP_GNU_uninit:
13142 return "DW_OP_GNU_uninit";
13143 case DW_OP_GNU_implicit_pointer:
13144 return "DW_OP_GNU_implicit_pointer";
13151 dwarf_bool_name (unsigned mybool)
13159 /* Convert a DWARF type code into its string name. */
13162 dwarf_type_encoding_name (unsigned enc)
13167 return "DW_ATE_void";
13168 case DW_ATE_address:
13169 return "DW_ATE_address";
13170 case DW_ATE_boolean:
13171 return "DW_ATE_boolean";
13172 case DW_ATE_complex_float:
13173 return "DW_ATE_complex_float";
13175 return "DW_ATE_float";
13176 case DW_ATE_signed:
13177 return "DW_ATE_signed";
13178 case DW_ATE_signed_char:
13179 return "DW_ATE_signed_char";
13180 case DW_ATE_unsigned:
13181 return "DW_ATE_unsigned";
13182 case DW_ATE_unsigned_char:
13183 return "DW_ATE_unsigned_char";
13185 case DW_ATE_imaginary_float:
13186 return "DW_ATE_imaginary_float";
13187 case DW_ATE_packed_decimal:
13188 return "DW_ATE_packed_decimal";
13189 case DW_ATE_numeric_string:
13190 return "DW_ATE_numeric_string";
13191 case DW_ATE_edited:
13192 return "DW_ATE_edited";
13193 case DW_ATE_signed_fixed:
13194 return "DW_ATE_signed_fixed";
13195 case DW_ATE_unsigned_fixed:
13196 return "DW_ATE_unsigned_fixed";
13197 case DW_ATE_decimal_float:
13198 return "DW_ATE_decimal_float";
13201 return "DW_ATE_UTF";
13202 /* HP extensions. */
13203 case DW_ATE_HP_float80:
13204 return "DW_ATE_HP_float80";
13205 case DW_ATE_HP_complex_float80:
13206 return "DW_ATE_HP_complex_float80";
13207 case DW_ATE_HP_float128:
13208 return "DW_ATE_HP_float128";
13209 case DW_ATE_HP_complex_float128:
13210 return "DW_ATE_HP_complex_float128";
13211 case DW_ATE_HP_floathpintel:
13212 return "DW_ATE_HP_floathpintel";
13213 case DW_ATE_HP_imaginary_float80:
13214 return "DW_ATE_HP_imaginary_float80";
13215 case DW_ATE_HP_imaginary_float128:
13216 return "DW_ATE_HP_imaginary_float128";
13218 return "DW_ATE_<unknown>";
13222 /* Convert a DWARF call frame info operation to its string name. */
13226 dwarf_cfi_name (unsigned cfi_opc)
13230 case DW_CFA_advance_loc:
13231 return "DW_CFA_advance_loc";
13232 case DW_CFA_offset:
13233 return "DW_CFA_offset";
13234 case DW_CFA_restore:
13235 return "DW_CFA_restore";
13237 return "DW_CFA_nop";
13238 case DW_CFA_set_loc:
13239 return "DW_CFA_set_loc";
13240 case DW_CFA_advance_loc1:
13241 return "DW_CFA_advance_loc1";
13242 case DW_CFA_advance_loc2:
13243 return "DW_CFA_advance_loc2";
13244 case DW_CFA_advance_loc4:
13245 return "DW_CFA_advance_loc4";
13246 case DW_CFA_offset_extended:
13247 return "DW_CFA_offset_extended";
13248 case DW_CFA_restore_extended:
13249 return "DW_CFA_restore_extended";
13250 case DW_CFA_undefined:
13251 return "DW_CFA_undefined";
13252 case DW_CFA_same_value:
13253 return "DW_CFA_same_value";
13254 case DW_CFA_register:
13255 return "DW_CFA_register";
13256 case DW_CFA_remember_state:
13257 return "DW_CFA_remember_state";
13258 case DW_CFA_restore_state:
13259 return "DW_CFA_restore_state";
13260 case DW_CFA_def_cfa:
13261 return "DW_CFA_def_cfa";
13262 case DW_CFA_def_cfa_register:
13263 return "DW_CFA_def_cfa_register";
13264 case DW_CFA_def_cfa_offset:
13265 return "DW_CFA_def_cfa_offset";
13267 case DW_CFA_def_cfa_expression:
13268 return "DW_CFA_def_cfa_expression";
13269 case DW_CFA_expression:
13270 return "DW_CFA_expression";
13271 case DW_CFA_offset_extended_sf:
13272 return "DW_CFA_offset_extended_sf";
13273 case DW_CFA_def_cfa_sf:
13274 return "DW_CFA_def_cfa_sf";
13275 case DW_CFA_def_cfa_offset_sf:
13276 return "DW_CFA_def_cfa_offset_sf";
13277 case DW_CFA_val_offset:
13278 return "DW_CFA_val_offset";
13279 case DW_CFA_val_offset_sf:
13280 return "DW_CFA_val_offset_sf";
13281 case DW_CFA_val_expression:
13282 return "DW_CFA_val_expression";
13283 /* SGI/MIPS specific. */
13284 case DW_CFA_MIPS_advance_loc8:
13285 return "DW_CFA_MIPS_advance_loc8";
13286 /* GNU extensions. */
13287 case DW_CFA_GNU_window_save:
13288 return "DW_CFA_GNU_window_save";
13289 case DW_CFA_GNU_args_size:
13290 return "DW_CFA_GNU_args_size";
13291 case DW_CFA_GNU_negative_offset_extended:
13292 return "DW_CFA_GNU_negative_offset_extended";
13294 return "DW_CFA_<unknown>";
13300 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13304 print_spaces (indent, f);
13305 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13306 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13308 if (die->parent != NULL)
13310 print_spaces (indent, f);
13311 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13312 die->parent->offset);
13315 print_spaces (indent, f);
13316 fprintf_unfiltered (f, " has children: %s\n",
13317 dwarf_bool_name (die->child != NULL));
13319 print_spaces (indent, f);
13320 fprintf_unfiltered (f, " attributes:\n");
13322 for (i = 0; i < die->num_attrs; ++i)
13324 print_spaces (indent, f);
13325 fprintf_unfiltered (f, " %s (%s) ",
13326 dwarf_attr_name (die->attrs[i].name),
13327 dwarf_form_name (die->attrs[i].form));
13329 switch (die->attrs[i].form)
13331 case DW_FORM_ref_addr:
13333 fprintf_unfiltered (f, "address: ");
13334 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13336 case DW_FORM_block2:
13337 case DW_FORM_block4:
13338 case DW_FORM_block:
13339 case DW_FORM_block1:
13340 fprintf_unfiltered (f, "block: size %d",
13341 DW_BLOCK (&die->attrs[i])->size);
13343 case DW_FORM_exprloc:
13344 fprintf_unfiltered (f, "expression: size %u",
13345 DW_BLOCK (&die->attrs[i])->size);
13350 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13351 (long) (DW_ADDR (&die->attrs[i])));
13353 case DW_FORM_data1:
13354 case DW_FORM_data2:
13355 case DW_FORM_data4:
13356 case DW_FORM_data8:
13357 case DW_FORM_udata:
13358 case DW_FORM_sdata:
13359 fprintf_unfiltered (f, "constant: %s",
13360 pulongest (DW_UNSND (&die->attrs[i])));
13362 case DW_FORM_sec_offset:
13363 fprintf_unfiltered (f, "section offset: %s",
13364 pulongest (DW_UNSND (&die->attrs[i])));
13366 case DW_FORM_ref_sig8:
13367 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13368 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13369 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
13371 fprintf_unfiltered (f, "signatured type, offset: unknown");
13373 case DW_FORM_string:
13375 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13376 DW_STRING (&die->attrs[i])
13377 ? DW_STRING (&die->attrs[i]) : "",
13378 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13381 if (DW_UNSND (&die->attrs[i]))
13382 fprintf_unfiltered (f, "flag: TRUE");
13384 fprintf_unfiltered (f, "flag: FALSE");
13386 case DW_FORM_flag_present:
13387 fprintf_unfiltered (f, "flag: TRUE");
13389 case DW_FORM_indirect:
13390 /* The reader will have reduced the indirect form to
13391 the "base form" so this form should not occur. */
13392 fprintf_unfiltered (f,
13393 "unexpected attribute form: DW_FORM_indirect");
13396 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13397 die->attrs[i].form);
13400 fprintf_unfiltered (f, "\n");
13405 dump_die_for_error (struct die_info *die)
13407 dump_die_shallow (gdb_stderr, 0, die);
13411 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13413 int indent = level * 4;
13415 gdb_assert (die != NULL);
13417 if (level >= max_level)
13420 dump_die_shallow (f, indent, die);
13422 if (die->child != NULL)
13424 print_spaces (indent, f);
13425 fprintf_unfiltered (f, " Children:");
13426 if (level + 1 < max_level)
13428 fprintf_unfiltered (f, "\n");
13429 dump_die_1 (f, level + 1, max_level, die->child);
13433 fprintf_unfiltered (f,
13434 " [not printed, max nesting level reached]\n");
13438 if (die->sibling != NULL && level > 0)
13440 dump_die_1 (f, level, max_level, die->sibling);
13444 /* This is called from the pdie macro in gdbinit.in.
13445 It's not static so gcc will keep a copy callable from gdb. */
13448 dump_die (struct die_info *die, int max_level)
13450 dump_die_1 (gdb_stdlog, 0, max_level, die);
13454 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13458 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13464 is_ref_attr (struct attribute *attr)
13466 switch (attr->form)
13468 case DW_FORM_ref_addr:
13473 case DW_FORM_ref_udata:
13480 static unsigned int
13481 dwarf2_get_ref_die_offset (struct attribute *attr)
13483 if (is_ref_attr (attr))
13484 return DW_ADDR (attr);
13486 complaint (&symfile_complaints,
13487 _("unsupported die ref attribute form: '%s'"),
13488 dwarf_form_name (attr->form));
13492 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13493 * the value held by the attribute is not constant. */
13496 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13498 if (attr->form == DW_FORM_sdata)
13499 return DW_SND (attr);
13500 else if (attr->form == DW_FORM_udata
13501 || attr->form == DW_FORM_data1
13502 || attr->form == DW_FORM_data2
13503 || attr->form == DW_FORM_data4
13504 || attr->form == DW_FORM_data8)
13505 return DW_UNSND (attr);
13508 complaint (&symfile_complaints,
13509 _("Attribute value is not a constant (%s)"),
13510 dwarf_form_name (attr->form));
13511 return default_value;
13515 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13516 unit and add it to our queue.
13517 The result is non-zero if PER_CU was queued, otherwise the result is zero
13518 meaning either PER_CU is already queued or it is already loaded. */
13521 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
13522 struct dwarf2_per_cu_data *per_cu)
13524 /* We may arrive here during partial symbol reading, if we need full
13525 DIEs to process an unusual case (e.g. template arguments). Do
13526 not queue PER_CU, just tell our caller to load its DIEs. */
13527 if (dwarf2_per_objfile->reading_partial_symbols)
13529 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
13534 /* Mark the dependence relation so that we don't flush PER_CU
13536 dwarf2_add_dependence (this_cu, per_cu);
13538 /* If it's already on the queue, we have nothing to do. */
13539 if (per_cu->queued)
13542 /* If the compilation unit is already loaded, just mark it as
13544 if (per_cu->cu != NULL)
13546 per_cu->cu->last_used = 0;
13550 /* Add it to the queue. */
13551 queue_comp_unit (per_cu, this_cu->objfile);
13556 /* Follow reference or signature attribute ATTR of SRC_DIE.
13557 On entry *REF_CU is the CU of SRC_DIE.
13558 On exit *REF_CU is the CU of the result. */
13560 static struct die_info *
13561 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
13562 struct dwarf2_cu **ref_cu)
13564 struct die_info *die;
13566 if (is_ref_attr (attr))
13567 die = follow_die_ref (src_die, attr, ref_cu);
13568 else if (attr->form == DW_FORM_ref_sig8)
13569 die = follow_die_sig (src_die, attr, ref_cu);
13572 dump_die_for_error (src_die);
13573 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13574 (*ref_cu)->objfile->name);
13580 /* Follow reference OFFSET.
13581 On entry *REF_CU is the CU of the source die referencing OFFSET.
13582 On exit *REF_CU is the CU of the result.
13583 Returns NULL if OFFSET is invalid. */
13585 static struct die_info *
13586 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
13588 struct die_info temp_die;
13589 struct dwarf2_cu *target_cu, *cu = *ref_cu;
13591 gdb_assert (cu->per_cu != NULL);
13595 if (cu->per_cu->from_debug_types)
13597 /* .debug_types CUs cannot reference anything outside their CU.
13598 If they need to, they have to reference a signatured type via
13599 DW_FORM_ref_sig8. */
13600 if (! offset_in_cu_p (&cu->header, offset))
13603 else if (! offset_in_cu_p (&cu->header, offset))
13605 struct dwarf2_per_cu_data *per_cu;
13607 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
13609 /* If necessary, add it to the queue and load its DIEs. */
13610 if (maybe_queue_comp_unit (cu, per_cu))
13611 load_full_comp_unit (per_cu, cu->objfile);
13613 target_cu = per_cu->cu;
13615 else if (cu->dies == NULL)
13617 /* We're loading full DIEs during partial symbol reading. */
13618 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
13619 load_full_comp_unit (cu->per_cu, cu->objfile);
13622 *ref_cu = target_cu;
13623 temp_die.offset = offset;
13624 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
13627 /* Follow reference attribute ATTR of SRC_DIE.
13628 On entry *REF_CU is the CU of SRC_DIE.
13629 On exit *REF_CU is the CU of the result. */
13631 static struct die_info *
13632 follow_die_ref (struct die_info *src_die, struct attribute *attr,
13633 struct dwarf2_cu **ref_cu)
13635 unsigned int offset = dwarf2_get_ref_die_offset (attr);
13636 struct dwarf2_cu *cu = *ref_cu;
13637 struct die_info *die;
13639 die = follow_die_offset (offset, ref_cu);
13641 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13642 "at 0x%x [in module %s]"),
13643 offset, src_die->offset, cu->objfile->name);
13648 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13649 value is intended for DW_OP_call*. */
13651 struct dwarf2_locexpr_baton
13652 dwarf2_fetch_die_location_block (unsigned int offset,
13653 struct dwarf2_per_cu_data *per_cu,
13654 CORE_ADDR (*get_frame_pc) (void *baton),
13657 struct dwarf2_cu *cu = per_cu->cu;
13658 struct die_info *die;
13659 struct attribute *attr;
13660 struct dwarf2_locexpr_baton retval;
13662 dw2_setup (per_cu->objfile);
13664 die = follow_die_offset (offset, &cu);
13666 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13667 offset, per_cu->cu->objfile->name);
13669 attr = dwarf2_attr (die, DW_AT_location, cu);
13672 /* DWARF: "If there is no such attribute, then there is no effect.". */
13674 retval.data = NULL;
13677 else if (attr_form_is_section_offset (attr))
13679 struct dwarf2_loclist_baton loclist_baton;
13680 CORE_ADDR pc = (*get_frame_pc) (baton);
13683 fill_in_loclist_baton (cu, &loclist_baton, attr);
13685 retval.data = dwarf2_find_location_expression (&loclist_baton,
13687 retval.size = size;
13691 if (!attr_form_is_block (attr))
13692 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13693 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13694 offset, per_cu->cu->objfile->name);
13696 retval.data = DW_BLOCK (attr)->data;
13697 retval.size = DW_BLOCK (attr)->size;
13699 retval.per_cu = cu->per_cu;
13703 /* Follow the signature attribute ATTR in SRC_DIE.
13704 On entry *REF_CU is the CU of SRC_DIE.
13705 On exit *REF_CU is the CU of the result. */
13707 static struct die_info *
13708 follow_die_sig (struct die_info *src_die, struct attribute *attr,
13709 struct dwarf2_cu **ref_cu)
13711 struct objfile *objfile = (*ref_cu)->objfile;
13712 struct die_info temp_die;
13713 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
13714 struct dwarf2_cu *sig_cu;
13715 struct die_info *die;
13717 /* sig_type will be NULL if the signatured type is missing from
13719 if (sig_type == NULL)
13720 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13721 "at 0x%x [in module %s]"),
13722 src_die->offset, objfile->name);
13724 /* If necessary, add it to the queue and load its DIEs. */
13726 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
13727 read_signatured_type (objfile, sig_type);
13729 gdb_assert (sig_type->per_cu.cu != NULL);
13731 sig_cu = sig_type->per_cu.cu;
13732 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
13733 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
13740 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13741 "from DIE at 0x%x [in module %s]"),
13742 sig_type->type_offset, src_die->offset, objfile->name);
13745 /* Given an offset of a signatured type, return its signatured_type. */
13747 static struct signatured_type *
13748 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
13750 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
13751 unsigned int length, initial_length_size;
13752 unsigned int sig_offset;
13753 struct signatured_type find_entry, *type_sig;
13755 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
13756 sig_offset = (initial_length_size
13758 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
13759 + 1 /*address_size*/);
13760 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
13761 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
13763 /* This is only used to lookup previously recorded types.
13764 If we didn't find it, it's our bug. */
13765 gdb_assert (type_sig != NULL);
13766 gdb_assert (offset == type_sig->offset);
13771 /* Read in signatured type at OFFSET and build its CU and die(s). */
13774 read_signatured_type_at_offset (struct objfile *objfile,
13775 unsigned int offset)
13777 struct signatured_type *type_sig;
13779 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13781 /* We have the section offset, but we need the signature to do the
13782 hash table lookup. */
13783 type_sig = lookup_signatured_type_at_offset (objfile, offset);
13785 gdb_assert (type_sig->per_cu.cu == NULL);
13787 read_signatured_type (objfile, type_sig);
13789 gdb_assert (type_sig->per_cu.cu != NULL);
13792 /* Read in a signatured type and build its CU and DIEs. */
13795 read_signatured_type (struct objfile *objfile,
13796 struct signatured_type *type_sig)
13798 gdb_byte *types_ptr;
13799 struct die_reader_specs reader_specs;
13800 struct dwarf2_cu *cu;
13801 ULONGEST signature;
13802 struct cleanup *back_to, *free_cu_cleanup;
13804 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13805 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
13807 gdb_assert (type_sig->per_cu.cu == NULL);
13809 cu = xmalloc (sizeof (*cu));
13810 init_one_comp_unit (cu, objfile);
13812 type_sig->per_cu.cu = cu;
13813 cu->per_cu = &type_sig->per_cu;
13815 /* If an error occurs while loading, release our storage. */
13816 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
13818 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
13819 types_ptr, objfile->obfd);
13820 gdb_assert (signature == type_sig->signature);
13823 = htab_create_alloc_ex (cu->header.length / 12,
13827 &cu->comp_unit_obstack,
13828 hashtab_obstack_allocate,
13829 dummy_obstack_deallocate);
13831 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
13832 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
13834 init_cu_die_reader (&reader_specs, cu);
13836 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
13839 /* We try not to read any attributes in this function, because not
13840 all objfiles needed for references have been loaded yet, and symbol
13841 table processing isn't initialized. But we have to set the CU language,
13842 or we won't be able to build types correctly. */
13843 prepare_one_comp_unit (cu, cu->dies);
13845 do_cleanups (back_to);
13847 /* We've successfully allocated this compilation unit. Let our caller
13848 clean it up when finished with it. */
13849 discard_cleanups (free_cu_cleanup);
13851 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
13852 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
13855 /* Decode simple location descriptions.
13856 Given a pointer to a dwarf block that defines a location, compute
13857 the location and return the value.
13859 NOTE drow/2003-11-18: This function is called in two situations
13860 now: for the address of static or global variables (partial symbols
13861 only) and for offsets into structures which are expected to be
13862 (more or less) constant. The partial symbol case should go away,
13863 and only the constant case should remain. That will let this
13864 function complain more accurately. A few special modes are allowed
13865 without complaint for global variables (for instance, global
13866 register values and thread-local values).
13868 A location description containing no operations indicates that the
13869 object is optimized out. The return value is 0 for that case.
13870 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13871 callers will only want a very basic result and this can become a
13874 Note that stack[0] is unused except as a default error return. */
13877 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
13879 struct objfile *objfile = cu->objfile;
13881 int size = blk->size;
13882 gdb_byte *data = blk->data;
13883 CORE_ADDR stack[64];
13885 unsigned int bytes_read, unsnd;
13891 stack[++stacki] = 0;
13930 stack[++stacki] = op - DW_OP_lit0;
13965 stack[++stacki] = op - DW_OP_reg0;
13967 dwarf2_complex_location_expr_complaint ();
13971 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13973 stack[++stacki] = unsnd;
13975 dwarf2_complex_location_expr_complaint ();
13979 stack[++stacki] = read_address (objfile->obfd, &data[i],
13984 case DW_OP_const1u:
13985 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
13989 case DW_OP_const1s:
13990 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
13994 case DW_OP_const2u:
13995 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
13999 case DW_OP_const2s:
14000 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14004 case DW_OP_const4u:
14005 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14009 case DW_OP_const4s:
14010 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14015 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14021 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14026 stack[stacki + 1] = stack[stacki];
14031 stack[stacki - 1] += stack[stacki];
14035 case DW_OP_plus_uconst:
14036 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14042 stack[stacki - 1] -= stack[stacki];
14047 /* If we're not the last op, then we definitely can't encode
14048 this using GDB's address_class enum. This is valid for partial
14049 global symbols, although the variable's address will be bogus
14052 dwarf2_complex_location_expr_complaint ();
14055 case DW_OP_GNU_push_tls_address:
14056 /* The top of the stack has the offset from the beginning
14057 of the thread control block at which the variable is located. */
14058 /* Nothing should follow this operator, so the top of stack would
14060 /* This is valid for partial global symbols, but the variable's
14061 address will be bogus in the psymtab. */
14063 dwarf2_complex_location_expr_complaint ();
14066 case DW_OP_GNU_uninit:
14071 const char *name = dwarf_stack_op_name (op);
14074 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14077 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14081 return (stack[stacki]);
14084 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14085 outside of the allocated space. Also enforce minimum>0. */
14086 if (stacki >= ARRAY_SIZE (stack) - 1)
14088 complaint (&symfile_complaints,
14089 _("location description stack overflow"));
14095 complaint (&symfile_complaints,
14096 _("location description stack underflow"));
14100 return (stack[stacki]);
14103 /* memory allocation interface */
14105 static struct dwarf_block *
14106 dwarf_alloc_block (struct dwarf2_cu *cu)
14108 struct dwarf_block *blk;
14110 blk = (struct dwarf_block *)
14111 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14115 static struct abbrev_info *
14116 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14118 struct abbrev_info *abbrev;
14120 abbrev = (struct abbrev_info *)
14121 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14122 memset (abbrev, 0, sizeof (struct abbrev_info));
14126 static struct die_info *
14127 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14129 struct die_info *die;
14130 size_t size = sizeof (struct die_info);
14133 size += (num_attrs - 1) * sizeof (struct attribute);
14135 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14136 memset (die, 0, sizeof (struct die_info));
14141 /* Macro support. */
14143 /* Return the full name of file number I in *LH's file name table.
14144 Use COMP_DIR as the name of the current directory of the
14145 compilation. The result is allocated using xmalloc; the caller is
14146 responsible for freeing it. */
14148 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14150 /* Is the file number a valid index into the line header's file name
14151 table? Remember that file numbers start with one, not zero. */
14152 if (1 <= file && file <= lh->num_file_names)
14154 struct file_entry *fe = &lh->file_names[file - 1];
14156 if (IS_ABSOLUTE_PATH (fe->name))
14157 return xstrdup (fe->name);
14165 dir = lh->include_dirs[fe->dir_index - 1];
14171 dir_len = strlen (dir);
14172 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14173 strcpy (full_name, dir);
14174 full_name[dir_len] = '/';
14175 strcpy (full_name + dir_len + 1, fe->name);
14179 return xstrdup (fe->name);
14184 /* The compiler produced a bogus file number. We can at least
14185 record the macro definitions made in the file, even if we
14186 won't be able to find the file by name. */
14187 char fake_name[80];
14189 sprintf (fake_name, "<bad macro file number %d>", file);
14191 complaint (&symfile_complaints,
14192 _("bad file number in macro information (%d)"),
14195 return xstrdup (fake_name);
14200 static struct macro_source_file *
14201 macro_start_file (int file, int line,
14202 struct macro_source_file *current_file,
14203 const char *comp_dir,
14204 struct line_header *lh, struct objfile *objfile)
14206 /* The full name of this source file. */
14207 char *full_name = file_full_name (file, lh, comp_dir);
14209 /* We don't create a macro table for this compilation unit
14210 at all until we actually get a filename. */
14211 if (! pending_macros)
14212 pending_macros = new_macro_table (&objfile->objfile_obstack,
14213 objfile->macro_cache);
14215 if (! current_file)
14216 /* If we have no current file, then this must be the start_file
14217 directive for the compilation unit's main source file. */
14218 current_file = macro_set_main (pending_macros, full_name);
14220 current_file = macro_include (current_file, line, full_name);
14224 return current_file;
14228 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14229 followed by a null byte. */
14231 copy_string (const char *buf, int len)
14233 char *s = xmalloc (len + 1);
14235 memcpy (s, buf, len);
14241 static const char *
14242 consume_improper_spaces (const char *p, const char *body)
14246 complaint (&symfile_complaints,
14247 _("macro definition contains spaces "
14248 "in formal argument list:\n`%s'"),
14260 parse_macro_definition (struct macro_source_file *file, int line,
14265 /* The body string takes one of two forms. For object-like macro
14266 definitions, it should be:
14268 <macro name> " " <definition>
14270 For function-like macro definitions, it should be:
14272 <macro name> "() " <definition>
14274 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14276 Spaces may appear only where explicitly indicated, and in the
14279 The Dwarf 2 spec says that an object-like macro's name is always
14280 followed by a space, but versions of GCC around March 2002 omit
14281 the space when the macro's definition is the empty string.
14283 The Dwarf 2 spec says that there should be no spaces between the
14284 formal arguments in a function-like macro's formal argument list,
14285 but versions of GCC around March 2002 include spaces after the
14289 /* Find the extent of the macro name. The macro name is terminated
14290 by either a space or null character (for an object-like macro) or
14291 an opening paren (for a function-like macro). */
14292 for (p = body; *p; p++)
14293 if (*p == ' ' || *p == '(')
14296 if (*p == ' ' || *p == '\0')
14298 /* It's an object-like macro. */
14299 int name_len = p - body;
14300 char *name = copy_string (body, name_len);
14301 const char *replacement;
14304 replacement = body + name_len + 1;
14307 dwarf2_macro_malformed_definition_complaint (body);
14308 replacement = body + name_len;
14311 macro_define_object (file, line, name, replacement);
14315 else if (*p == '(')
14317 /* It's a function-like macro. */
14318 char *name = copy_string (body, p - body);
14321 char **argv = xmalloc (argv_size * sizeof (*argv));
14325 p = consume_improper_spaces (p, body);
14327 /* Parse the formal argument list. */
14328 while (*p && *p != ')')
14330 /* Find the extent of the current argument name. */
14331 const char *arg_start = p;
14333 while (*p && *p != ',' && *p != ')' && *p != ' ')
14336 if (! *p || p == arg_start)
14337 dwarf2_macro_malformed_definition_complaint (body);
14340 /* Make sure argv has room for the new argument. */
14341 if (argc >= argv_size)
14344 argv = xrealloc (argv, argv_size * sizeof (*argv));
14347 argv[argc++] = copy_string (arg_start, p - arg_start);
14350 p = consume_improper_spaces (p, body);
14352 /* Consume the comma, if present. */
14357 p = consume_improper_spaces (p, body);
14366 /* Perfectly formed definition, no complaints. */
14367 macro_define_function (file, line, name,
14368 argc, (const char **) argv,
14370 else if (*p == '\0')
14372 /* Complain, but do define it. */
14373 dwarf2_macro_malformed_definition_complaint (body);
14374 macro_define_function (file, line, name,
14375 argc, (const char **) argv,
14379 /* Just complain. */
14380 dwarf2_macro_malformed_definition_complaint (body);
14383 /* Just complain. */
14384 dwarf2_macro_malformed_definition_complaint (body);
14390 for (i = 0; i < argc; i++)
14396 dwarf2_macro_malformed_definition_complaint (body);
14401 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
14402 char *comp_dir, bfd *abfd,
14403 struct dwarf2_cu *cu)
14405 gdb_byte *mac_ptr, *mac_end;
14406 struct macro_source_file *current_file = 0;
14407 enum dwarf_macinfo_record_type macinfo_type;
14408 int at_commandline;
14410 dwarf2_read_section (dwarf2_per_objfile->objfile,
14411 &dwarf2_per_objfile->macinfo);
14412 if (dwarf2_per_objfile->macinfo.buffer == NULL)
14414 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
14418 /* First pass: Find the name of the base filename.
14419 This filename is needed in order to process all macros whose definition
14420 (or undefinition) comes from the command line. These macros are defined
14421 before the first DW_MACINFO_start_file entry, and yet still need to be
14422 associated to the base file.
14424 To determine the base file name, we scan the macro definitions until we
14425 reach the first DW_MACINFO_start_file entry. We then initialize
14426 CURRENT_FILE accordingly so that any macro definition found before the
14427 first DW_MACINFO_start_file can still be associated to the base file. */
14429 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14430 mac_end = dwarf2_per_objfile->macinfo.buffer
14431 + dwarf2_per_objfile->macinfo.size;
14435 /* Do we at least have room for a macinfo type byte? */
14436 if (mac_ptr >= mac_end)
14438 /* Complaint is printed during the second pass as GDB will probably
14439 stop the first pass earlier upon finding
14440 DW_MACINFO_start_file. */
14444 macinfo_type = read_1_byte (abfd, mac_ptr);
14447 switch (macinfo_type)
14449 /* A zero macinfo type indicates the end of the macro
14454 case DW_MACINFO_define:
14455 case DW_MACINFO_undef:
14456 /* Only skip the data by MAC_PTR. */
14458 unsigned int bytes_read;
14460 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14461 mac_ptr += bytes_read;
14462 read_direct_string (abfd, mac_ptr, &bytes_read);
14463 mac_ptr += bytes_read;
14467 case DW_MACINFO_start_file:
14469 unsigned int bytes_read;
14472 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14473 mac_ptr += bytes_read;
14474 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14475 mac_ptr += bytes_read;
14477 current_file = macro_start_file (file, line, current_file,
14478 comp_dir, lh, cu->objfile);
14482 case DW_MACINFO_end_file:
14483 /* No data to skip by MAC_PTR. */
14486 case DW_MACINFO_vendor_ext:
14487 /* Only skip the data by MAC_PTR. */
14489 unsigned int bytes_read;
14491 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14492 mac_ptr += bytes_read;
14493 read_direct_string (abfd, mac_ptr, &bytes_read);
14494 mac_ptr += bytes_read;
14501 } while (macinfo_type != 0 && current_file == NULL);
14503 /* Second pass: Process all entries.
14505 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14506 command-line macro definitions/undefinitions. This flag is unset when we
14507 reach the first DW_MACINFO_start_file entry. */
14509 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14511 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14512 GDB is still reading the definitions from command line. First
14513 DW_MACINFO_start_file will need to be ignored as it was already executed
14514 to create CURRENT_FILE for the main source holding also the command line
14515 definitions. On first met DW_MACINFO_start_file this flag is reset to
14516 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14518 at_commandline = 1;
14522 /* Do we at least have room for a macinfo type byte? */
14523 if (mac_ptr >= mac_end)
14525 dwarf2_macros_too_long_complaint ();
14529 macinfo_type = read_1_byte (abfd, mac_ptr);
14532 switch (macinfo_type)
14534 /* A zero macinfo type indicates the end of the macro
14539 case DW_MACINFO_define:
14540 case DW_MACINFO_undef:
14542 unsigned int bytes_read;
14546 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14547 mac_ptr += bytes_read;
14548 body = read_direct_string (abfd, mac_ptr, &bytes_read);
14549 mac_ptr += bytes_read;
14551 if (! current_file)
14553 /* DWARF violation as no main source is present. */
14554 complaint (&symfile_complaints,
14555 _("debug info with no main source gives macro %s "
14557 macinfo_type == DW_MACINFO_define ?
14559 macinfo_type == DW_MACINFO_undef ?
14560 _("undefinition") :
14561 _("something-or-other"), line, body);
14564 if ((line == 0 && !at_commandline)
14565 || (line != 0 && at_commandline))
14566 complaint (&symfile_complaints,
14567 _("debug info gives %s macro %s with %s line %d: %s"),
14568 at_commandline ? _("command-line") : _("in-file"),
14569 macinfo_type == DW_MACINFO_define ?
14571 macinfo_type == DW_MACINFO_undef ?
14572 _("undefinition") :
14573 _("something-or-other"),
14574 line == 0 ? _("zero") : _("non-zero"), line, body);
14576 if (macinfo_type == DW_MACINFO_define)
14577 parse_macro_definition (current_file, line, body);
14578 else if (macinfo_type == DW_MACINFO_undef)
14579 macro_undef (current_file, line, body);
14583 case DW_MACINFO_start_file:
14585 unsigned int bytes_read;
14588 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14589 mac_ptr += bytes_read;
14590 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14591 mac_ptr += bytes_read;
14593 if ((line == 0 && !at_commandline)
14594 || (line != 0 && at_commandline))
14595 complaint (&symfile_complaints,
14596 _("debug info gives source %d included "
14597 "from %s at %s line %d"),
14598 file, at_commandline ? _("command-line") : _("file"),
14599 line == 0 ? _("zero") : _("non-zero"), line);
14601 if (at_commandline)
14603 /* This DW_MACINFO_start_file was executed in the pass one. */
14604 at_commandline = 0;
14607 current_file = macro_start_file (file, line,
14608 current_file, comp_dir,
14613 case DW_MACINFO_end_file:
14614 if (! current_file)
14615 complaint (&symfile_complaints,
14616 _("macro debug info has an unmatched "
14617 "`close_file' directive"));
14620 current_file = current_file->included_by;
14621 if (! current_file)
14623 enum dwarf_macinfo_record_type next_type;
14625 /* GCC circa March 2002 doesn't produce the zero
14626 type byte marking the end of the compilation
14627 unit. Complain if it's not there, but exit no
14630 /* Do we at least have room for a macinfo type byte? */
14631 if (mac_ptr >= mac_end)
14633 dwarf2_macros_too_long_complaint ();
14637 /* We don't increment mac_ptr here, so this is just
14639 next_type = read_1_byte (abfd, mac_ptr);
14640 if (next_type != 0)
14641 complaint (&symfile_complaints,
14642 _("no terminating 0-type entry for "
14643 "macros in `.debug_macinfo' section"));
14650 case DW_MACINFO_vendor_ext:
14652 unsigned int bytes_read;
14655 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14656 mac_ptr += bytes_read;
14657 read_direct_string (abfd, mac_ptr, &bytes_read);
14658 mac_ptr += bytes_read;
14660 /* We don't recognize any vendor extensions. */
14664 } while (macinfo_type != 0);
14667 /* Check if the attribute's form is a DW_FORM_block*
14668 if so return true else false. */
14670 attr_form_is_block (struct attribute *attr)
14672 return (attr == NULL ? 0 :
14673 attr->form == DW_FORM_block1
14674 || attr->form == DW_FORM_block2
14675 || attr->form == DW_FORM_block4
14676 || attr->form == DW_FORM_block
14677 || attr->form == DW_FORM_exprloc);
14680 /* Return non-zero if ATTR's value is a section offset --- classes
14681 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14682 You may use DW_UNSND (attr) to retrieve such offsets.
14684 Section 7.5.4, "Attribute Encodings", explains that no attribute
14685 may have a value that belongs to more than one of these classes; it
14686 would be ambiguous if we did, because we use the same forms for all
14689 attr_form_is_section_offset (struct attribute *attr)
14691 return (attr->form == DW_FORM_data4
14692 || attr->form == DW_FORM_data8
14693 || attr->form == DW_FORM_sec_offset);
14697 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14698 zero otherwise. When this function returns true, you can apply
14699 dwarf2_get_attr_constant_value to it.
14701 However, note that for some attributes you must check
14702 attr_form_is_section_offset before using this test. DW_FORM_data4
14703 and DW_FORM_data8 are members of both the constant class, and of
14704 the classes that contain offsets into other debug sections
14705 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14706 that, if an attribute's can be either a constant or one of the
14707 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14708 taken as section offsets, not constants. */
14710 attr_form_is_constant (struct attribute *attr)
14712 switch (attr->form)
14714 case DW_FORM_sdata:
14715 case DW_FORM_udata:
14716 case DW_FORM_data1:
14717 case DW_FORM_data2:
14718 case DW_FORM_data4:
14719 case DW_FORM_data8:
14726 /* A helper function that fills in a dwarf2_loclist_baton. */
14729 fill_in_loclist_baton (struct dwarf2_cu *cu,
14730 struct dwarf2_loclist_baton *baton,
14731 struct attribute *attr)
14733 dwarf2_read_section (dwarf2_per_objfile->objfile,
14734 &dwarf2_per_objfile->loc);
14736 baton->per_cu = cu->per_cu;
14737 gdb_assert (baton->per_cu);
14738 /* We don't know how long the location list is, but make sure we
14739 don't run off the edge of the section. */
14740 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
14741 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
14742 baton->base_address = cu->base_address;
14746 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
14747 struct dwarf2_cu *cu)
14749 if (attr_form_is_section_offset (attr)
14750 /* ".debug_loc" may not exist at all, or the offset may be outside
14751 the section. If so, fall through to the complaint in the
14753 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
14754 &dwarf2_per_objfile->loc))
14756 struct dwarf2_loclist_baton *baton;
14758 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14759 sizeof (struct dwarf2_loclist_baton));
14761 fill_in_loclist_baton (cu, baton, attr);
14763 if (cu->base_known == 0)
14764 complaint (&symfile_complaints,
14765 _("Location list used without "
14766 "specifying the CU base address."));
14768 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
14769 SYMBOL_LOCATION_BATON (sym) = baton;
14773 struct dwarf2_locexpr_baton *baton;
14775 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14776 sizeof (struct dwarf2_locexpr_baton));
14777 baton->per_cu = cu->per_cu;
14778 gdb_assert (baton->per_cu);
14780 if (attr_form_is_block (attr))
14782 /* Note that we're just copying the block's data pointer
14783 here, not the actual data. We're still pointing into the
14784 info_buffer for SYM's objfile; right now we never release
14785 that buffer, but when we do clean up properly this may
14787 baton->size = DW_BLOCK (attr)->size;
14788 baton->data = DW_BLOCK (attr)->data;
14792 dwarf2_invalid_attrib_class_complaint ("location description",
14793 SYMBOL_NATURAL_NAME (sym));
14795 baton->data = NULL;
14798 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
14799 SYMBOL_LOCATION_BATON (sym) = baton;
14803 /* Return the OBJFILE associated with the compilation unit CU. If CU
14804 came from a separate debuginfo file, then the master objfile is
14808 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
14810 struct objfile *objfile = per_cu->objfile;
14812 /* Return the master objfile, so that we can report and look up the
14813 correct file containing this variable. */
14814 if (objfile->separate_debug_objfile_backlink)
14815 objfile = objfile->separate_debug_objfile_backlink;
14820 /* Return the address size given in the compilation unit header for CU. */
14823 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
14826 return per_cu->cu->header.addr_size;
14829 /* If the CU is not currently read in, we re-read its header. */
14830 struct objfile *objfile = per_cu->objfile;
14831 struct dwarf2_per_objfile *per_objfile
14832 = objfile_data (objfile, dwarf2_objfile_data_key);
14833 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14834 struct comp_unit_head cu_header;
14836 memset (&cu_header, 0, sizeof cu_header);
14837 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14838 return cu_header.addr_size;
14842 /* Return the offset size given in the compilation unit header for CU. */
14845 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
14848 return per_cu->cu->header.offset_size;
14851 /* If the CU is not currently read in, we re-read its header. */
14852 struct objfile *objfile = per_cu->objfile;
14853 struct dwarf2_per_objfile *per_objfile
14854 = objfile_data (objfile, dwarf2_objfile_data_key);
14855 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14856 struct comp_unit_head cu_header;
14858 memset (&cu_header, 0, sizeof cu_header);
14859 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14860 return cu_header.offset_size;
14864 /* Return the text offset of the CU. The returned offset comes from
14865 this CU's objfile. If this objfile came from a separate debuginfo
14866 file, then the offset may be different from the corresponding
14867 offset in the parent objfile. */
14870 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
14872 struct objfile *objfile = per_cu->objfile;
14874 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14877 /* Locate the .debug_info compilation unit from CU's objfile which contains
14878 the DIE at OFFSET. Raises an error on failure. */
14880 static struct dwarf2_per_cu_data *
14881 dwarf2_find_containing_comp_unit (unsigned int offset,
14882 struct objfile *objfile)
14884 struct dwarf2_per_cu_data *this_cu;
14888 high = dwarf2_per_objfile->n_comp_units - 1;
14891 int mid = low + (high - low) / 2;
14893 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
14898 gdb_assert (low == high);
14899 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
14902 error (_("Dwarf Error: could not find partial DIE containing "
14903 "offset 0x%lx [in module %s]"),
14904 (long) offset, bfd_get_filename (objfile->obfd));
14906 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
14907 return dwarf2_per_objfile->all_comp_units[low-1];
14911 this_cu = dwarf2_per_objfile->all_comp_units[low];
14912 if (low == dwarf2_per_objfile->n_comp_units - 1
14913 && offset >= this_cu->offset + this_cu->length)
14914 error (_("invalid dwarf2 offset %u"), offset);
14915 gdb_assert (offset < this_cu->offset + this_cu->length);
14920 /* Locate the compilation unit from OBJFILE which is located at exactly
14921 OFFSET. Raises an error on failure. */
14923 static struct dwarf2_per_cu_data *
14924 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
14926 struct dwarf2_per_cu_data *this_cu;
14928 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
14929 if (this_cu->offset != offset)
14930 error (_("no compilation unit with offset %u."), offset);
14934 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14937 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
14939 memset (cu, 0, sizeof (*cu));
14940 cu->objfile = objfile;
14941 obstack_init (&cu->comp_unit_obstack);
14944 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14947 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
14949 struct attribute *attr;
14951 /* Set the language we're debugging. */
14952 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
14954 set_cu_language (DW_UNSND (attr), cu);
14957 cu->language = language_minimal;
14958 cu->language_defn = language_def (cu->language);
14962 /* Release one cached compilation unit, CU. We unlink it from the tree
14963 of compilation units, but we don't remove it from the read_in_chain;
14964 the caller is responsible for that.
14965 NOTE: DATA is a void * because this function is also used as a
14966 cleanup routine. */
14969 free_one_comp_unit (void *data)
14971 struct dwarf2_cu *cu = data;
14973 if (cu->per_cu != NULL)
14974 cu->per_cu->cu = NULL;
14977 obstack_free (&cu->comp_unit_obstack, NULL);
14982 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14983 when we're finished with it. We can't free the pointer itself, but be
14984 sure to unlink it from the cache. Also release any associated storage
14985 and perform cache maintenance.
14987 Only used during partial symbol parsing. */
14990 free_stack_comp_unit (void *data)
14992 struct dwarf2_cu *cu = data;
14994 obstack_free (&cu->comp_unit_obstack, NULL);
14995 cu->partial_dies = NULL;
14997 if (cu->per_cu != NULL)
14999 /* This compilation unit is on the stack in our caller, so we
15000 should not xfree it. Just unlink it. */
15001 cu->per_cu->cu = NULL;
15004 /* If we had a per-cu pointer, then we may have other compilation
15005 units loaded, so age them now. */
15006 age_cached_comp_units ();
15010 /* Free all cached compilation units. */
15013 free_cached_comp_units (void *data)
15015 struct dwarf2_per_cu_data *per_cu, **last_chain;
15017 per_cu = dwarf2_per_objfile->read_in_chain;
15018 last_chain = &dwarf2_per_objfile->read_in_chain;
15019 while (per_cu != NULL)
15021 struct dwarf2_per_cu_data *next_cu;
15023 next_cu = per_cu->cu->read_in_chain;
15025 free_one_comp_unit (per_cu->cu);
15026 *last_chain = next_cu;
15032 /* Increase the age counter on each cached compilation unit, and free
15033 any that are too old. */
15036 age_cached_comp_units (void)
15038 struct dwarf2_per_cu_data *per_cu, **last_chain;
15040 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15041 per_cu = dwarf2_per_objfile->read_in_chain;
15042 while (per_cu != NULL)
15044 per_cu->cu->last_used ++;
15045 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15046 dwarf2_mark (per_cu->cu);
15047 per_cu = per_cu->cu->read_in_chain;
15050 per_cu = dwarf2_per_objfile->read_in_chain;
15051 last_chain = &dwarf2_per_objfile->read_in_chain;
15052 while (per_cu != NULL)
15054 struct dwarf2_per_cu_data *next_cu;
15056 next_cu = per_cu->cu->read_in_chain;
15058 if (!per_cu->cu->mark)
15060 free_one_comp_unit (per_cu->cu);
15061 *last_chain = next_cu;
15064 last_chain = &per_cu->cu->read_in_chain;
15070 /* Remove a single compilation unit from the cache. */
15073 free_one_cached_comp_unit (void *target_cu)
15075 struct dwarf2_per_cu_data *per_cu, **last_chain;
15077 per_cu = dwarf2_per_objfile->read_in_chain;
15078 last_chain = &dwarf2_per_objfile->read_in_chain;
15079 while (per_cu != NULL)
15081 struct dwarf2_per_cu_data *next_cu;
15083 next_cu = per_cu->cu->read_in_chain;
15085 if (per_cu->cu == target_cu)
15087 free_one_comp_unit (per_cu->cu);
15088 *last_chain = next_cu;
15092 last_chain = &per_cu->cu->read_in_chain;
15098 /* Release all extra memory associated with OBJFILE. */
15101 dwarf2_free_objfile (struct objfile *objfile)
15103 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15105 if (dwarf2_per_objfile == NULL)
15108 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15109 free_cached_comp_units (NULL);
15111 if (dwarf2_per_objfile->quick_file_names_table)
15112 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15114 /* Everything else should be on the objfile obstack. */
15117 /* A pair of DIE offset and GDB type pointer. We store these
15118 in a hash table separate from the DIEs, and preserve them
15119 when the DIEs are flushed out of cache. */
15121 struct dwarf2_offset_and_type
15123 unsigned int offset;
15127 /* Hash function for a dwarf2_offset_and_type. */
15130 offset_and_type_hash (const void *item)
15132 const struct dwarf2_offset_and_type *ofs = item;
15134 return ofs->offset;
15137 /* Equality function for a dwarf2_offset_and_type. */
15140 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15142 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15143 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15145 return ofs_lhs->offset == ofs_rhs->offset;
15148 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15149 table if necessary. For convenience, return TYPE.
15151 The DIEs reading must have careful ordering to:
15152 * Not cause infite loops trying to read in DIEs as a prerequisite for
15153 reading current DIE.
15154 * Not trying to dereference contents of still incompletely read in types
15155 while reading in other DIEs.
15156 * Enable referencing still incompletely read in types just by a pointer to
15157 the type without accessing its fields.
15159 Therefore caller should follow these rules:
15160 * Try to fetch any prerequisite types we may need to build this DIE type
15161 before building the type and calling set_die_type.
15162 * After building type call set_die_type for current DIE as soon as
15163 possible before fetching more types to complete the current type.
15164 * Make the type as complete as possible before fetching more types. */
15166 static struct type *
15167 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15169 struct dwarf2_offset_and_type **slot, ofs;
15170 struct objfile *objfile = cu->objfile;
15171 htab_t *type_hash_ptr;
15173 /* For Ada types, make sure that the gnat-specific data is always
15174 initialized (if not already set). There are a few types where
15175 we should not be doing so, because the type-specific area is
15176 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15177 where the type-specific area is used to store the floatformat).
15178 But this is not a problem, because the gnat-specific information
15179 is actually not needed for these types. */
15180 if (need_gnat_info (cu)
15181 && TYPE_CODE (type) != TYPE_CODE_FUNC
15182 && TYPE_CODE (type) != TYPE_CODE_FLT
15183 && !HAVE_GNAT_AUX_INFO (type))
15184 INIT_GNAT_SPECIFIC (type);
15186 if (cu->per_cu->from_debug_types)
15187 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
15189 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
15191 if (*type_hash_ptr == NULL)
15194 = htab_create_alloc_ex (127,
15195 offset_and_type_hash,
15196 offset_and_type_eq,
15198 &objfile->objfile_obstack,
15199 hashtab_obstack_allocate,
15200 dummy_obstack_deallocate);
15203 ofs.offset = die->offset;
15205 slot = (struct dwarf2_offset_and_type **)
15206 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
15208 complaint (&symfile_complaints,
15209 _("A problem internal to GDB: DIE 0x%x has type already set"),
15211 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
15216 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15217 table, or return NULL if the die does not have a saved type. */
15219 static struct type *
15220 get_die_type_at_offset (unsigned int offset,
15221 struct dwarf2_per_cu_data *per_cu)
15223 struct dwarf2_offset_and_type *slot, ofs;
15226 if (per_cu->from_debug_types)
15227 type_hash = dwarf2_per_objfile->debug_types_type_hash;
15229 type_hash = dwarf2_per_objfile->debug_info_type_hash;
15230 if (type_hash == NULL)
15233 ofs.offset = offset;
15234 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
15241 /* Look up the type for DIE in the appropriate type_hash table,
15242 or return NULL if DIE does not have a saved type. */
15244 static struct type *
15245 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
15247 return get_die_type_at_offset (die->offset, cu->per_cu);
15250 /* Add a dependence relationship from CU to REF_PER_CU. */
15253 dwarf2_add_dependence (struct dwarf2_cu *cu,
15254 struct dwarf2_per_cu_data *ref_per_cu)
15258 if (cu->dependencies == NULL)
15260 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
15261 NULL, &cu->comp_unit_obstack,
15262 hashtab_obstack_allocate,
15263 dummy_obstack_deallocate);
15265 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
15267 *slot = ref_per_cu;
15270 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15271 Set the mark field in every compilation unit in the
15272 cache that we must keep because we are keeping CU. */
15275 dwarf2_mark_helper (void **slot, void *data)
15277 struct dwarf2_per_cu_data *per_cu;
15279 per_cu = (struct dwarf2_per_cu_data *) *slot;
15281 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15282 reading of the chain. As such dependencies remain valid it is not much
15283 useful to track and undo them during QUIT cleanups. */
15284 if (per_cu->cu == NULL)
15287 if (per_cu->cu->mark)
15289 per_cu->cu->mark = 1;
15291 if (per_cu->cu->dependencies != NULL)
15292 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
15297 /* Set the mark field in CU and in every other compilation unit in the
15298 cache that we must keep because we are keeping CU. */
15301 dwarf2_mark (struct dwarf2_cu *cu)
15306 if (cu->dependencies != NULL)
15307 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
15311 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
15315 per_cu->cu->mark = 0;
15316 per_cu = per_cu->cu->read_in_chain;
15320 /* Trivial hash function for partial_die_info: the hash value of a DIE
15321 is its offset in .debug_info for this objfile. */
15324 partial_die_hash (const void *item)
15326 const struct partial_die_info *part_die = item;
15328 return part_die->offset;
15331 /* Trivial comparison function for partial_die_info structures: two DIEs
15332 are equal if they have the same offset. */
15335 partial_die_eq (const void *item_lhs, const void *item_rhs)
15337 const struct partial_die_info *part_die_lhs = item_lhs;
15338 const struct partial_die_info *part_die_rhs = item_rhs;
15340 return part_die_lhs->offset == part_die_rhs->offset;
15343 static struct cmd_list_element *set_dwarf2_cmdlist;
15344 static struct cmd_list_element *show_dwarf2_cmdlist;
15347 set_dwarf2_cmd (char *args, int from_tty)
15349 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
15353 show_dwarf2_cmd (char *args, int from_tty)
15355 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
15358 /* If section described by INFO was mmapped, munmap it now. */
15361 munmap_section_buffer (struct dwarf2_section_info *info)
15363 if (info->was_mmapped)
15366 intptr_t begin = (intptr_t) info->buffer;
15367 intptr_t map_begin = begin & ~(pagesize - 1);
15368 size_t map_length = info->size + begin - map_begin;
15370 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
15372 /* Without HAVE_MMAP, we should never be here to begin with. */
15373 gdb_assert_not_reached ("no mmap support");
15378 /* munmap debug sections for OBJFILE, if necessary. */
15381 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
15383 struct dwarf2_per_objfile *data = d;
15385 /* This is sorted according to the order they're defined in to make it easier
15386 to keep in sync. */
15387 munmap_section_buffer (&data->info);
15388 munmap_section_buffer (&data->abbrev);
15389 munmap_section_buffer (&data->line);
15390 munmap_section_buffer (&data->loc);
15391 munmap_section_buffer (&data->macinfo);
15392 munmap_section_buffer (&data->str);
15393 munmap_section_buffer (&data->ranges);
15394 munmap_section_buffer (&data->types);
15395 munmap_section_buffer (&data->frame);
15396 munmap_section_buffer (&data->eh_frame);
15397 munmap_section_buffer (&data->gdb_index);
15401 /* The "save gdb-index" command. */
15403 /* The contents of the hash table we create when building the string
15405 struct strtab_entry
15407 offset_type offset;
15411 /* Hash function for a strtab_entry. */
15414 hash_strtab_entry (const void *e)
15416 const struct strtab_entry *entry = e;
15417 return mapped_index_string_hash (entry->str);
15420 /* Equality function for a strtab_entry. */
15423 eq_strtab_entry (const void *a, const void *b)
15425 const struct strtab_entry *ea = a;
15426 const struct strtab_entry *eb = b;
15427 return !strcmp (ea->str, eb->str);
15430 /* Create a strtab_entry hash table. */
15433 create_strtab (void)
15435 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
15436 xfree, xcalloc, xfree);
15439 /* Add a string to the constant pool. Return the string's offset in
15443 add_string (htab_t table, struct obstack *cpool, const char *str)
15446 struct strtab_entry entry;
15447 struct strtab_entry *result;
15450 slot = htab_find_slot (table, &entry, INSERT);
15455 result = XNEW (struct strtab_entry);
15456 result->offset = obstack_object_size (cpool);
15458 obstack_grow_str0 (cpool, str);
15461 return result->offset;
15464 /* An entry in the symbol table. */
15465 struct symtab_index_entry
15467 /* The name of the symbol. */
15469 /* The offset of the name in the constant pool. */
15470 offset_type index_offset;
15471 /* A sorted vector of the indices of all the CUs that hold an object
15473 VEC (offset_type) *cu_indices;
15476 /* The symbol table. This is a power-of-2-sized hash table. */
15477 struct mapped_symtab
15479 offset_type n_elements;
15481 struct symtab_index_entry **data;
15484 /* Hash function for a symtab_index_entry. */
15487 hash_symtab_entry (const void *e)
15489 const struct symtab_index_entry *entry = e;
15490 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
15491 sizeof (offset_type) * VEC_length (offset_type,
15492 entry->cu_indices),
15496 /* Equality function for a symtab_index_entry. */
15499 eq_symtab_entry (const void *a, const void *b)
15501 const struct symtab_index_entry *ea = a;
15502 const struct symtab_index_entry *eb = b;
15503 int len = VEC_length (offset_type, ea->cu_indices);
15504 if (len != VEC_length (offset_type, eb->cu_indices))
15506 return !memcmp (VEC_address (offset_type, ea->cu_indices),
15507 VEC_address (offset_type, eb->cu_indices),
15508 sizeof (offset_type) * len);
15511 /* Destroy a symtab_index_entry. */
15514 delete_symtab_entry (void *p)
15516 struct symtab_index_entry *entry = p;
15517 VEC_free (offset_type, entry->cu_indices);
15521 /* Create a hash table holding symtab_index_entry objects. */
15524 create_symbol_hash_table (void)
15526 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
15527 delete_symtab_entry, xcalloc, xfree);
15530 /* Create a new mapped symtab object. */
15532 static struct mapped_symtab *
15533 create_mapped_symtab (void)
15535 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
15536 symtab->n_elements = 0;
15537 symtab->size = 1024;
15538 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15542 /* Destroy a mapped_symtab. */
15545 cleanup_mapped_symtab (void *p)
15547 struct mapped_symtab *symtab = p;
15548 /* The contents of the array are freed when the other hash table is
15550 xfree (symtab->data);
15554 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15557 static struct symtab_index_entry **
15558 find_slot (struct mapped_symtab *symtab, const char *name)
15560 offset_type index, step, hash = mapped_index_string_hash (name);
15562 index = hash & (symtab->size - 1);
15563 step = ((hash * 17) & (symtab->size - 1)) | 1;
15567 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
15568 return &symtab->data[index];
15569 index = (index + step) & (symtab->size - 1);
15573 /* Expand SYMTAB's hash table. */
15576 hash_expand (struct mapped_symtab *symtab)
15578 offset_type old_size = symtab->size;
15580 struct symtab_index_entry **old_entries = symtab->data;
15583 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15585 for (i = 0; i < old_size; ++i)
15587 if (old_entries[i])
15589 struct symtab_index_entry **slot = find_slot (symtab,
15590 old_entries[i]->name);
15591 *slot = old_entries[i];
15595 xfree (old_entries);
15598 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15599 is the index of the CU in which the symbol appears. */
15602 add_index_entry (struct mapped_symtab *symtab, const char *name,
15603 offset_type cu_index)
15605 struct symtab_index_entry **slot;
15607 ++symtab->n_elements;
15608 if (4 * symtab->n_elements / 3 >= symtab->size)
15609 hash_expand (symtab);
15611 slot = find_slot (symtab, name);
15614 *slot = XNEW (struct symtab_index_entry);
15615 (*slot)->name = name;
15616 (*slot)->cu_indices = NULL;
15618 /* Don't push an index twice. Due to how we add entries we only
15619 have to check the last one. */
15620 if (VEC_empty (offset_type, (*slot)->cu_indices)
15621 || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
15622 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
15625 /* Add a vector of indices to the constant pool. */
15628 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
15629 struct symtab_index_entry *entry)
15633 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
15636 offset_type len = VEC_length (offset_type, entry->cu_indices);
15637 offset_type val = MAYBE_SWAP (len);
15642 entry->index_offset = obstack_object_size (cpool);
15644 obstack_grow (cpool, &val, sizeof (val));
15646 VEC_iterate (offset_type, entry->cu_indices, i, iter);
15649 val = MAYBE_SWAP (iter);
15650 obstack_grow (cpool, &val, sizeof (val));
15655 struct symtab_index_entry *old_entry = *slot;
15656 entry->index_offset = old_entry->index_offset;
15659 return entry->index_offset;
15662 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15663 constant pool entries going into the obstack CPOOL. */
15666 write_hash_table (struct mapped_symtab *symtab,
15667 struct obstack *output, struct obstack *cpool)
15670 htab_t symbol_hash_table;
15673 symbol_hash_table = create_symbol_hash_table ();
15674 str_table = create_strtab ();
15676 /* We add all the index vectors to the constant pool first, to
15677 ensure alignment is ok. */
15678 for (i = 0; i < symtab->size; ++i)
15680 if (symtab->data[i])
15681 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
15684 /* Now write out the hash table. */
15685 for (i = 0; i < symtab->size; ++i)
15687 offset_type str_off, vec_off;
15689 if (symtab->data[i])
15691 str_off = add_string (str_table, cpool, symtab->data[i]->name);
15692 vec_off = symtab->data[i]->index_offset;
15696 /* While 0 is a valid constant pool index, it is not valid
15697 to have 0 for both offsets. */
15702 str_off = MAYBE_SWAP (str_off);
15703 vec_off = MAYBE_SWAP (vec_off);
15705 obstack_grow (output, &str_off, sizeof (str_off));
15706 obstack_grow (output, &vec_off, sizeof (vec_off));
15709 htab_delete (str_table);
15710 htab_delete (symbol_hash_table);
15713 /* Struct to map psymtab to CU index in the index file. */
15714 struct psymtab_cu_index_map
15716 struct partial_symtab *psymtab;
15717 unsigned int cu_index;
15721 hash_psymtab_cu_index (const void *item)
15723 const struct psymtab_cu_index_map *map = item;
15725 return htab_hash_pointer (map->psymtab);
15729 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
15731 const struct psymtab_cu_index_map *lhs = item_lhs;
15732 const struct psymtab_cu_index_map *rhs = item_rhs;
15734 return lhs->psymtab == rhs->psymtab;
15737 /* Helper struct for building the address table. */
15738 struct addrmap_index_data
15740 struct objfile *objfile;
15741 struct obstack *addr_obstack;
15742 htab_t cu_index_htab;
15744 /* Non-zero if the previous_* fields are valid.
15745 We can't write an entry until we see the next entry (since it is only then
15746 that we know the end of the entry). */
15747 int previous_valid;
15748 /* Index of the CU in the table of all CUs in the index file. */
15749 unsigned int previous_cu_index;
15750 /* Start address of the CU. */
15751 CORE_ADDR previous_cu_start;
15754 /* Write an address entry to OBSTACK. */
15757 add_address_entry (struct objfile *objfile, struct obstack *obstack,
15758 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
15760 offset_type cu_index_to_write;
15762 CORE_ADDR baseaddr;
15764 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15766 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
15767 obstack_grow (obstack, addr, 8);
15768 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
15769 obstack_grow (obstack, addr, 8);
15770 cu_index_to_write = MAYBE_SWAP (cu_index);
15771 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
15774 /* Worker function for traversing an addrmap to build the address table. */
15777 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
15779 struct addrmap_index_data *data = datap;
15780 struct partial_symtab *pst = obj;
15781 offset_type cu_index;
15784 if (data->previous_valid)
15785 add_address_entry (data->objfile, data->addr_obstack,
15786 data->previous_cu_start, start_addr,
15787 data->previous_cu_index);
15789 data->previous_cu_start = start_addr;
15792 struct psymtab_cu_index_map find_map, *map;
15793 find_map.psymtab = pst;
15794 map = htab_find (data->cu_index_htab, &find_map);
15795 gdb_assert (map != NULL);
15796 data->previous_cu_index = map->cu_index;
15797 data->previous_valid = 1;
15800 data->previous_valid = 0;
15805 /* Write OBJFILE's address map to OBSTACK.
15806 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15807 in the index file. */
15810 write_address_map (struct objfile *objfile, struct obstack *obstack,
15811 htab_t cu_index_htab)
15813 struct addrmap_index_data addrmap_index_data;
15815 /* When writing the address table, we have to cope with the fact that
15816 the addrmap iterator only provides the start of a region; we have to
15817 wait until the next invocation to get the start of the next region. */
15819 addrmap_index_data.objfile = objfile;
15820 addrmap_index_data.addr_obstack = obstack;
15821 addrmap_index_data.cu_index_htab = cu_index_htab;
15822 addrmap_index_data.previous_valid = 0;
15824 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
15825 &addrmap_index_data);
15827 /* It's highly unlikely the last entry (end address = 0xff...ff)
15828 is valid, but we should still handle it.
15829 The end address is recorded as the start of the next region, but that
15830 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15832 if (addrmap_index_data.previous_valid)
15833 add_address_entry (objfile, obstack,
15834 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
15835 addrmap_index_data.previous_cu_index);
15838 /* Add a list of partial symbols to SYMTAB. */
15841 write_psymbols (struct mapped_symtab *symtab,
15843 struct partial_symbol **psymp,
15845 offset_type cu_index,
15848 for (; count-- > 0; ++psymp)
15850 void **slot, *lookup;
15852 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
15853 error (_("Ada is not currently supported by the index"));
15855 /* We only want to add a given psymbol once. However, we also
15856 want to account for whether it is global or static. So, we
15857 may add it twice, using slightly different values. */
15860 uintptr_t val = 1 | (uintptr_t) *psymp;
15862 lookup = (void *) val;
15867 /* Only add a given psymbol once. */
15868 slot = htab_find_slot (psyms_seen, lookup, INSERT);
15872 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
15877 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15878 exception if there is an error. */
15881 write_obstack (FILE *file, struct obstack *obstack)
15883 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
15885 != obstack_object_size (obstack))
15886 error (_("couldn't data write to file"));
15889 /* Unlink a file if the argument is not NULL. */
15892 unlink_if_set (void *p)
15894 char **filename = p;
15896 unlink (*filename);
15899 /* A helper struct used when iterating over debug_types. */
15900 struct signatured_type_index_data
15902 struct objfile *objfile;
15903 struct mapped_symtab *symtab;
15904 struct obstack *types_list;
15909 /* A helper function that writes a single signatured_type to an
15913 write_one_signatured_type (void **slot, void *d)
15915 struct signatured_type_index_data *info = d;
15916 struct signatured_type *entry = (struct signatured_type *) *slot;
15917 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
15918 struct partial_symtab *psymtab = per_cu->v.psymtab;
15921 write_psymbols (info->symtab,
15923 info->objfile->global_psymbols.list
15924 + psymtab->globals_offset,
15925 psymtab->n_global_syms, info->cu_index,
15927 write_psymbols (info->symtab,
15929 info->objfile->static_psymbols.list
15930 + psymtab->statics_offset,
15931 psymtab->n_static_syms, info->cu_index,
15934 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
15935 obstack_grow (info->types_list, val, 8);
15936 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
15937 obstack_grow (info->types_list, val, 8);
15938 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
15939 obstack_grow (info->types_list, val, 8);
15946 /* A cleanup function for an htab_t. */
15949 cleanup_htab (void *arg)
15954 /* Create an index file for OBJFILE in the directory DIR. */
15957 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
15959 struct cleanup *cleanup;
15960 char *filename, *cleanup_filename;
15961 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
15962 struct obstack cu_list, types_cu_list;
15965 struct mapped_symtab *symtab;
15966 offset_type val, size_of_contents, total_len;
15970 htab_t cu_index_htab;
15971 struct psymtab_cu_index_map *psymtab_cu_index_map;
15973 if (!objfile->psymtabs)
15975 if (dwarf2_per_objfile->using_index)
15976 error (_("Cannot use an index to create the index"));
15978 if (stat (objfile->name, &st) < 0)
15979 perror_with_name (objfile->name);
15981 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
15982 INDEX_SUFFIX, (char *) NULL);
15983 cleanup = make_cleanup (xfree, filename);
15985 out_file = fopen (filename, "wb");
15987 error (_("Can't open `%s' for writing"), filename);
15989 cleanup_filename = filename;
15990 make_cleanup (unlink_if_set, &cleanup_filename);
15992 symtab = create_mapped_symtab ();
15993 make_cleanup (cleanup_mapped_symtab, symtab);
15995 obstack_init (&addr_obstack);
15996 make_cleanup_obstack_free (&addr_obstack);
15998 obstack_init (&cu_list);
15999 make_cleanup_obstack_free (&cu_list);
16001 obstack_init (&types_cu_list);
16002 make_cleanup_obstack_free (&types_cu_list);
16004 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16005 NULL, xcalloc, xfree);
16006 make_cleanup (cleanup_htab, psyms_seen);
16008 /* While we're scanning CU's create a table that maps a psymtab pointer
16009 (which is what addrmap records) to its index (which is what is recorded
16010 in the index file). This will later be needed to write the address
16012 cu_index_htab = htab_create_alloc (100,
16013 hash_psymtab_cu_index,
16014 eq_psymtab_cu_index,
16015 NULL, xcalloc, xfree);
16016 make_cleanup (cleanup_htab, cu_index_htab);
16017 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16018 xmalloc (sizeof (struct psymtab_cu_index_map)
16019 * dwarf2_per_objfile->n_comp_units);
16020 make_cleanup (xfree, psymtab_cu_index_map);
16022 /* The CU list is already sorted, so we don't need to do additional
16023 work here. Also, the debug_types entries do not appear in
16024 all_comp_units, but only in their own hash table. */
16025 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16027 struct dwarf2_per_cu_data *per_cu
16028 = dwarf2_per_objfile->all_comp_units[i];
16029 struct partial_symtab *psymtab = per_cu->v.psymtab;
16031 struct psymtab_cu_index_map *map;
16034 write_psymbols (symtab,
16036 objfile->global_psymbols.list + psymtab->globals_offset,
16037 psymtab->n_global_syms, i,
16039 write_psymbols (symtab,
16041 objfile->static_psymbols.list + psymtab->statics_offset,
16042 psymtab->n_static_syms, i,
16045 map = &psymtab_cu_index_map[i];
16046 map->psymtab = psymtab;
16048 slot = htab_find_slot (cu_index_htab, map, INSERT);
16049 gdb_assert (slot != NULL);
16050 gdb_assert (*slot == NULL);
16053 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16054 obstack_grow (&cu_list, val, 8);
16055 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16056 obstack_grow (&cu_list, val, 8);
16059 /* Dump the address map. */
16060 write_address_map (objfile, &addr_obstack, cu_index_htab);
16062 /* Write out the .debug_type entries, if any. */
16063 if (dwarf2_per_objfile->signatured_types)
16065 struct signatured_type_index_data sig_data;
16067 sig_data.objfile = objfile;
16068 sig_data.symtab = symtab;
16069 sig_data.types_list = &types_cu_list;
16070 sig_data.psyms_seen = psyms_seen;
16071 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
16072 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
16073 write_one_signatured_type, &sig_data);
16076 obstack_init (&constant_pool);
16077 make_cleanup_obstack_free (&constant_pool);
16078 obstack_init (&symtab_obstack);
16079 make_cleanup_obstack_free (&symtab_obstack);
16080 write_hash_table (symtab, &symtab_obstack, &constant_pool);
16082 obstack_init (&contents);
16083 make_cleanup_obstack_free (&contents);
16084 size_of_contents = 6 * sizeof (offset_type);
16085 total_len = size_of_contents;
16087 /* The version number. */
16088 val = MAYBE_SWAP (4);
16089 obstack_grow (&contents, &val, sizeof (val));
16091 /* The offset of the CU list from the start of the file. */
16092 val = MAYBE_SWAP (total_len);
16093 obstack_grow (&contents, &val, sizeof (val));
16094 total_len += obstack_object_size (&cu_list);
16096 /* The offset of the types CU list from the start of the file. */
16097 val = MAYBE_SWAP (total_len);
16098 obstack_grow (&contents, &val, sizeof (val));
16099 total_len += obstack_object_size (&types_cu_list);
16101 /* The offset of the address table from the start of the file. */
16102 val = MAYBE_SWAP (total_len);
16103 obstack_grow (&contents, &val, sizeof (val));
16104 total_len += obstack_object_size (&addr_obstack);
16106 /* The offset of the symbol table from the start of the file. */
16107 val = MAYBE_SWAP (total_len);
16108 obstack_grow (&contents, &val, sizeof (val));
16109 total_len += obstack_object_size (&symtab_obstack);
16111 /* The offset of the constant pool from the start of the file. */
16112 val = MAYBE_SWAP (total_len);
16113 obstack_grow (&contents, &val, sizeof (val));
16114 total_len += obstack_object_size (&constant_pool);
16116 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16118 write_obstack (out_file, &contents);
16119 write_obstack (out_file, &cu_list);
16120 write_obstack (out_file, &types_cu_list);
16121 write_obstack (out_file, &addr_obstack);
16122 write_obstack (out_file, &symtab_obstack);
16123 write_obstack (out_file, &constant_pool);
16127 /* We want to keep the file, so we set cleanup_filename to NULL
16128 here. See unlink_if_set. */
16129 cleanup_filename = NULL;
16131 do_cleanups (cleanup);
16134 /* The mapped index file format is designed to be directly mmap()able
16135 on any architecture. In most cases, a datum is represented using a
16136 little-endian 32-bit integer value, called an offset_type. Big
16137 endian machines must byte-swap the values before using them.
16138 Exceptions to this rule are noted. The data is laid out such that
16139 alignment is always respected.
16141 A mapped index consists of several sections.
16143 1. The file header. This is a sequence of values, of offset_type
16144 unless otherwise noted:
16146 [0] The version number, currently 4. Versions 1, 2 and 3 are
16148 [1] The offset, from the start of the file, of the CU list.
16149 [2] The offset, from the start of the file, of the types CU list.
16150 Note that this section can be empty, in which case this offset will
16151 be equal to the next offset.
16152 [3] The offset, from the start of the file, of the address section.
16153 [4] The offset, from the start of the file, of the symbol table.
16154 [5] The offset, from the start of the file, of the constant pool.
16156 2. The CU list. This is a sequence of pairs of 64-bit
16157 little-endian values, sorted by the CU offset. The first element
16158 in each pair is the offset of a CU in the .debug_info section. The
16159 second element in each pair is the length of that CU. References
16160 to a CU elsewhere in the map are done using a CU index, which is
16161 just the 0-based index into this table. Note that if there are
16162 type CUs, then conceptually CUs and type CUs form a single list for
16163 the purposes of CU indices.
16165 3. The types CU list. This is a sequence of triplets of 64-bit
16166 little-endian values. In a triplet, the first value is the CU
16167 offset, the second value is the type offset in the CU, and the
16168 third value is the type signature. The types CU list is not
16171 4. The address section. The address section consists of a sequence
16172 of address entries. Each address entry has three elements.
16173 [0] The low address. This is a 64-bit little-endian value.
16174 [1] The high address. This is a 64-bit little-endian value.
16175 Like DW_AT_high_pc, the value is one byte beyond the end.
16176 [2] The CU index. This is an offset_type value.
16178 5. The symbol table. This is a hash table. The size of the hash
16179 table is always a power of 2. The initial hash and the step are
16180 currently defined by the `find_slot' function.
16182 Each slot in the hash table consists of a pair of offset_type
16183 values. The first value is the offset of the symbol's name in the
16184 constant pool. The second value is the offset of the CU vector in
16187 If both values are 0, then this slot in the hash table is empty.
16188 This is ok because while 0 is a valid constant pool index, it
16189 cannot be a valid index for both a string and a CU vector.
16191 A string in the constant pool is stored as a \0-terminated string,
16194 A CU vector in the constant pool is a sequence of offset_type
16195 values. The first value is the number of CU indices in the vector.
16196 Each subsequent value is the index of a CU in the CU list. This
16197 element in the hash table is used to indicate which CUs define the
16200 6. The constant pool. This is simply a bunch of bytes. It is
16201 organized so that alignment is correct: CU vectors are stored
16202 first, followed by strings. */
16205 save_gdb_index_command (char *arg, int from_tty)
16207 struct objfile *objfile;
16210 error (_("usage: save gdb-index DIRECTORY"));
16212 ALL_OBJFILES (objfile)
16216 /* If the objfile does not correspond to an actual file, skip it. */
16217 if (stat (objfile->name, &st) < 0)
16220 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16221 if (dwarf2_per_objfile)
16223 volatile struct gdb_exception except;
16225 TRY_CATCH (except, RETURN_MASK_ERROR)
16227 write_psymtabs_to_index (objfile, arg);
16229 if (except.reason < 0)
16230 exception_fprintf (gdb_stderr, except,
16231 _("Error while writing index for `%s': "),
16239 int dwarf2_always_disassemble;
16242 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
16243 struct cmd_list_element *c, const char *value)
16245 fprintf_filtered (file,
16246 _("Whether to always disassemble "
16247 "DWARF expressions is %s.\n"),
16252 show_check_physname (struct ui_file *file, int from_tty,
16253 struct cmd_list_element *c, const char *value)
16255 fprintf_filtered (file,
16256 _("Whether to check \"physname\" is %s.\n"),
16260 void _initialize_dwarf2_read (void);
16263 _initialize_dwarf2_read (void)
16265 struct cmd_list_element *c;
16267 dwarf2_objfile_data_key
16268 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
16270 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
16271 Set DWARF 2 specific variables.\n\
16272 Configure DWARF 2 variables such as the cache size"),
16273 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
16274 0/*allow-unknown*/, &maintenance_set_cmdlist);
16276 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
16277 Show DWARF 2 specific variables\n\
16278 Show DWARF 2 variables such as the cache size"),
16279 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
16280 0/*allow-unknown*/, &maintenance_show_cmdlist);
16282 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
16283 &dwarf2_max_cache_age, _("\
16284 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16285 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16286 A higher limit means that cached compilation units will be stored\n\
16287 in memory longer, and more total memory will be used. Zero disables\n\
16288 caching, which can slow down startup."),
16290 show_dwarf2_max_cache_age,
16291 &set_dwarf2_cmdlist,
16292 &show_dwarf2_cmdlist);
16294 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
16295 &dwarf2_always_disassemble, _("\
16296 Set whether `info address' always disassembles DWARF expressions."), _("\
16297 Show whether `info address' always disassembles DWARF expressions."), _("\
16298 When enabled, DWARF expressions are always printed in an assembly-like\n\
16299 syntax. When disabled, expressions will be printed in a more\n\
16300 conversational style, when possible."),
16302 show_dwarf2_always_disassemble,
16303 &set_dwarf2_cmdlist,
16304 &show_dwarf2_cmdlist);
16306 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
16307 Set debugging of the dwarf2 DIE reader."), _("\
16308 Show debugging of the dwarf2 DIE reader."), _("\
16309 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16310 The value is the maximum depth to print."),
16313 &setdebuglist, &showdebuglist);
16315 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
16316 Set cross-checking of \"physname\" code against demangler."), _("\
16317 Show cross-checking of \"physname\" code against demangler."), _("\
16318 When enabled, GDB's internal \"physname\" code is checked against\n\
16320 NULL, show_check_physname,
16321 &setdebuglist, &showdebuglist);
16323 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
16325 Save a gdb-index file.\n\
16326 Usage: save gdb-index DIRECTORY"),
16328 set_cmd_completer (c, filename_completer);