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
5 Free Software Foundation, Inc.
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"
59 #include "gdb_string.h"
60 #include "gdb_assert.h"
61 #include <sys/types.h>
68 #define MAP_FAILED ((void *) -1)
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length; /* length of the .debug_info
80 unsigned short version; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
83 unsigned char addr_size; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_line statement program prologue
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct statement_prologue
94 unsigned int total_length; /* byte length of the statement
96 unsigned short version; /* version number -- 2 for DWARF
98 unsigned int prologue_length; /* # bytes between prologue &
100 unsigned char minimum_instruction_length; /* byte size of
102 unsigned char default_is_stmt; /* initial value of is_stmt
105 unsigned char line_range;
106 unsigned char opcode_base; /* number assigned to first special
108 unsigned char *standard_opcode_lengths;
112 /* When non-zero, dump DIEs after they are read in. */
113 static int dwarf2_die_debug = 0;
117 /* When set, the file that we're processing is known to have debugging
118 info for C++ namespaces. GCC 3.3.x did not produce this information,
119 but later versions do. */
121 static int processing_has_namespace_info;
123 static const struct objfile_data *dwarf2_objfile_data_key;
125 struct dwarf2_section_info
131 /* True if we have tried to read this section. */
135 /* All offsets in the index are of this type. It must be
136 architecture-independent. */
137 typedef uint32_t offset_type;
139 DEF_VEC_I (offset_type);
141 /* A description of the mapped index. The file format is described in
142 a comment by the code that writes the index. */
145 /* The total length of the buffer. */
147 /* A pointer to the address table data. */
148 const gdb_byte *address_table;
149 /* Size of the address table data in bytes. */
150 offset_type address_table_size;
151 /* The hash table. */
152 const offset_type *index_table;
153 /* Size in slots, each slot is 2 offset_types. */
154 offset_type index_table_slots;
155 /* A pointer to the constant pool. */
156 const char *constant_pool;
159 struct dwarf2_per_objfile
161 struct dwarf2_section_info info;
162 struct dwarf2_section_info abbrev;
163 struct dwarf2_section_info line;
164 struct dwarf2_section_info loc;
165 struct dwarf2_section_info macinfo;
166 struct dwarf2_section_info str;
167 struct dwarf2_section_info ranges;
168 struct dwarf2_section_info types;
169 struct dwarf2_section_info frame;
170 struct dwarf2_section_info eh_frame;
171 struct dwarf2_section_info gdb_index;
174 struct objfile *objfile;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data **all_comp_units;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* The number of .debug_types-related CUs. */
184 int n_type_comp_units;
186 /* The .debug_types-related CUs. */
187 struct dwarf2_per_cu_data **type_comp_units;
189 /* A chain of compilation units that are currently read in, so that
190 they can be freed later. */
191 struct dwarf2_per_cu_data *read_in_chain;
193 /* A table mapping .debug_types signatures to its signatured_type entry.
194 This is NULL if the .debug_types section hasn't been read in yet. */
195 htab_t signatured_types;
197 /* A flag indicating wether this objfile has a section loaded at a
199 int has_section_at_zero;
201 /* True if we are using the mapped index. */
202 unsigned char using_index;
204 /* The mapped index. */
205 struct mapped_index *index_table;
208 static struct dwarf2_per_objfile *dwarf2_per_objfile;
210 /* names of the debugging sections */
212 /* Note that if the debugging section has been compressed, it might
213 have a name like .zdebug_info. */
215 #define INFO_SECTION "debug_info"
216 #define ABBREV_SECTION "debug_abbrev"
217 #define LINE_SECTION "debug_line"
218 #define LOC_SECTION "debug_loc"
219 #define MACINFO_SECTION "debug_macinfo"
220 #define STR_SECTION "debug_str"
221 #define RANGES_SECTION "debug_ranges"
222 #define TYPES_SECTION "debug_types"
223 #define FRAME_SECTION "debug_frame"
224 #define EH_FRAME_SECTION "eh_frame"
225 #define GDB_INDEX_SECTION "gdb_index"
227 /* local data types */
229 /* We hold several abbreviation tables in memory at the same time. */
230 #ifndef ABBREV_HASH_SIZE
231 #define ABBREV_HASH_SIZE 121
234 /* The data in a compilation unit header, after target2host
235 translation, looks like this. */
236 struct comp_unit_head
240 unsigned char addr_size;
241 unsigned char signed_addr_p;
242 unsigned int abbrev_offset;
244 /* Size of file offsets; either 4 or 8. */
245 unsigned int offset_size;
247 /* Size of the length field; either 4 or 12. */
248 unsigned int initial_length_size;
250 /* Offset to the first byte of this compilation unit header in the
251 .debug_info section, for resolving relative reference dies. */
254 /* Offset to first die in this cu from the start of the cu.
255 This will be the first byte following the compilation unit header. */
256 unsigned int first_die_offset;
259 /* Internal state when decoding a particular compilation unit. */
262 /* The objfile containing this compilation unit. */
263 struct objfile *objfile;
265 /* The header of the compilation unit. */
266 struct comp_unit_head header;
268 /* Base address of this compilation unit. */
269 CORE_ADDR base_address;
271 /* Non-zero if base_address has been set. */
274 struct function_range *first_fn, *last_fn, *cached_fn;
276 /* The language we are debugging. */
277 enum language language;
278 const struct language_defn *language_defn;
280 const char *producer;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending **list_in_scope;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info **dwarf2_abbrevs;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* Storage for things with the same lifetime as this read-in compilation
303 unit, including partial DIEs. */
304 struct obstack comp_unit_obstack;
306 /* When multiple dwarf2_cu structures are living in memory, this field
307 chains them all together, so that they can be released efficiently.
308 We will probably also want a generation counter so that most-recently-used
309 compilation units are cached... */
310 struct dwarf2_per_cu_data *read_in_chain;
312 /* Backchain to our per_cu entry if the tree has been built. */
313 struct dwarf2_per_cu_data *per_cu;
315 /* Pointer to the die -> type map. Although it is stored
316 permanently in per_cu, we copy it here to avoid double
320 /* How many compilation units ago was this CU last referenced? */
323 /* A hash table of die offsets for following references. */
326 /* Full DIEs if read in. */
327 struct die_info *dies;
329 /* A set of pointers to dwarf2_per_cu_data objects for compilation
330 units referenced by this one. Only set during full symbol processing;
331 partial symbol tables do not have dependencies. */
334 /* Header data from the line table, during full symbol processing. */
335 struct line_header *line_header;
337 /* Mark used when releasing cached dies. */
338 unsigned int mark : 1;
340 /* This flag will be set if this compilation unit might include
341 inter-compilation-unit references. */
342 unsigned int has_form_ref_addr : 1;
344 /* This flag will be set if this compilation unit includes any
345 DW_TAG_namespace DIEs. If we know that there are explicit
346 DIEs for namespaces, we don't need to try to infer them
347 from mangled names. */
348 unsigned int has_namespace_info : 1;
351 /* When using the index (and thus not using psymtabs), each CU has an
352 object of this type. This is used to hold information needed by
353 the various "quick" methods. */
354 struct dwarf2_per_cu_quick_data
356 /* The line table. This can be NULL if there was no line table. */
357 struct line_header *lines;
359 /* The file names from the line table. */
360 const char **file_names;
361 /* The file names from the line table after being run through
363 const char **full_names;
365 /* The corresponding symbol table. This is NULL if symbols for this
366 CU have not yet been read. */
367 struct symtab *symtab;
369 /* A temporary mark bit used when iterating over all CUs in
370 expand_symtabs_matching. */
371 unsigned int mark : 1;
373 /* True if we've tried to read the line table. */
374 unsigned int read_lines : 1;
377 /* Persistent data held for a compilation unit, even when not
378 processing it. We put a pointer to this structure in the
379 read_symtab_private field of the psymtab. If we encounter
380 inter-compilation-unit references, we also maintain a sorted
381 list of all compilation units. */
383 struct dwarf2_per_cu_data
385 /* The start offset and length of this compilation unit. 2**29-1
386 bytes should suffice to store the length of any compilation unit
387 - if it doesn't, GDB will fall over anyway.
388 NOTE: Unlike comp_unit_head.length, this length includes
389 initial_length_size. */
391 unsigned int length : 29;
393 /* Flag indicating this compilation unit will be read in before
394 any of the current compilation units are processed. */
395 unsigned int queued : 1;
397 /* This flag will be set if we need to load absolutely all DIEs
398 for this compilation unit, instead of just the ones we think
399 are interesting. It gets set if we look for a DIE in the
400 hash table and don't find it. */
401 unsigned int load_all_dies : 1;
403 /* Non-zero if this CU is from .debug_types.
404 Otherwise it's from .debug_info. */
405 unsigned int from_debug_types : 1;
407 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
408 of the CU cache it gets reset to NULL again. */
409 struct dwarf2_cu *cu;
411 /* If full symbols for this CU have been read in, then this field
412 holds a map of DIE offsets to types. It isn't always possible
413 to reconstruct this information later, so we have to preserve
417 /* The corresponding objfile. */
418 struct objfile *objfile;
420 /* When using partial symbol tables, the 'psymtab' field is active.
421 Otherwise the 'quick' field is active. */
424 /* The partial symbol table associated with this compilation unit,
425 or NULL for partial units (which do not have an associated
427 struct partial_symtab *psymtab;
429 /* Data needed by the "quick" functions. */
430 struct dwarf2_per_cu_quick_data *quick;
434 /* Entry in the signatured_types hash table. */
436 struct signatured_type
440 /* Offset in .debug_types of the TU (type_unit) for this type. */
443 /* Offset in .debug_types of the type defined by this TU. */
444 unsigned int type_offset;
446 /* The CU(/TU) of this type. */
447 struct dwarf2_per_cu_data per_cu;
450 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
451 which are used for both .debug_info and .debug_types dies.
452 All parameters here are unchanging for the life of the call.
453 This struct exists to abstract away the constant parameters of
456 struct die_reader_specs
458 /* The bfd of this objfile. */
461 /* The CU of the DIE we are parsing. */
462 struct dwarf2_cu *cu;
464 /* Pointer to start of section buffer.
465 This is either the start of .debug_info or .debug_types. */
466 const gdb_byte *buffer;
469 /* The line number information for a compilation unit (found in the
470 .debug_line section) begins with a "statement program header",
471 which contains the following information. */
474 unsigned int total_length;
475 unsigned short version;
476 unsigned int header_length;
477 unsigned char minimum_instruction_length;
478 unsigned char maximum_ops_per_instruction;
479 unsigned char default_is_stmt;
481 unsigned char line_range;
482 unsigned char opcode_base;
484 /* standard_opcode_lengths[i] is the number of operands for the
485 standard opcode whose value is i. This means that
486 standard_opcode_lengths[0] is unused, and the last meaningful
487 element is standard_opcode_lengths[opcode_base - 1]. */
488 unsigned char *standard_opcode_lengths;
490 /* The include_directories table. NOTE! These strings are not
491 allocated with xmalloc; instead, they are pointers into
492 debug_line_buffer. If you try to free them, `free' will get
494 unsigned int num_include_dirs, include_dirs_size;
497 /* The file_names table. NOTE! These strings are not allocated
498 with xmalloc; instead, they are pointers into debug_line_buffer.
499 Don't try to free them directly. */
500 unsigned int num_file_names, file_names_size;
504 unsigned int dir_index;
505 unsigned int mod_time;
507 int included_p; /* Non-zero if referenced by the Line Number Program. */
508 struct symtab *symtab; /* The associated symbol table, if any. */
511 /* The start and end of the statement program following this
512 header. These point into dwarf2_per_objfile->line_buffer. */
513 gdb_byte *statement_program_start, *statement_program_end;
516 /* When we construct a partial symbol table entry we only
517 need this much information. */
518 struct partial_die_info
520 /* Offset of this DIE. */
523 /* DWARF-2 tag for this DIE. */
524 ENUM_BITFIELD(dwarf_tag) tag : 16;
526 /* Assorted flags describing the data found in this DIE. */
527 unsigned int has_children : 1;
528 unsigned int is_external : 1;
529 unsigned int is_declaration : 1;
530 unsigned int has_type : 1;
531 unsigned int has_specification : 1;
532 unsigned int has_pc_info : 1;
534 /* Flag set if the SCOPE field of this structure has been
536 unsigned int scope_set : 1;
538 /* Flag set if the DIE has a byte_size attribute. */
539 unsigned int has_byte_size : 1;
541 /* The name of this DIE. Normally the value of DW_AT_name, but
542 sometimes a default name for unnamed DIEs. */
545 /* The scope to prepend to our children. This is generally
546 allocated on the comp_unit_obstack, so will disappear
547 when this compilation unit leaves the cache. */
550 /* The location description associated with this DIE, if any. */
551 struct dwarf_block *locdesc;
553 /* If HAS_PC_INFO, the PC range associated with this DIE. */
557 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
558 DW_AT_sibling, if any. */
561 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
562 DW_AT_specification (or DW_AT_abstract_origin or
564 unsigned int spec_offset;
566 /* Pointers to this DIE's parent, first child, and next sibling,
568 struct partial_die_info *die_parent, *die_child, *die_sibling;
571 /* This data structure holds the information of an abbrev. */
574 unsigned int number; /* number identifying abbrev */
575 enum dwarf_tag tag; /* dwarf tag */
576 unsigned short has_children; /* boolean */
577 unsigned short num_attrs; /* number of attributes */
578 struct attr_abbrev *attrs; /* an array of attribute descriptions */
579 struct abbrev_info *next; /* next in chain */
584 ENUM_BITFIELD(dwarf_attribute) name : 16;
585 ENUM_BITFIELD(dwarf_form) form : 16;
588 /* Attributes have a name and a value */
591 ENUM_BITFIELD(dwarf_attribute) name : 16;
592 ENUM_BITFIELD(dwarf_form) form : 15;
594 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
595 field should be in u.str (existing only for DW_STRING) but it is kept
596 here for better struct attribute alignment. */
597 unsigned int string_is_canonical : 1;
602 struct dwarf_block *blk;
606 struct signatured_type *signatured_type;
611 /* This data structure holds a complete die structure. */
614 /* DWARF-2 tag for this DIE. */
615 ENUM_BITFIELD(dwarf_tag) tag : 16;
617 /* Number of attributes */
618 unsigned short num_attrs;
623 /* Offset in .debug_info or .debug_types section. */
626 /* The dies in a compilation unit form an n-ary tree. PARENT
627 points to this die's parent; CHILD points to the first child of
628 this node; and all the children of a given node are chained
629 together via their SIBLING fields, terminated by a die whose
631 struct die_info *child; /* Its first child, if any. */
632 struct die_info *sibling; /* Its next sibling, if any. */
633 struct die_info *parent; /* Its parent, if any. */
635 /* An array of attributes, with NUM_ATTRS elements. There may be
636 zero, but it's not common and zero-sized arrays are not
637 sufficiently portable C. */
638 struct attribute attrs[1];
641 struct function_range
644 CORE_ADDR lowpc, highpc;
646 struct function_range *next;
649 /* Get at parts of an attribute structure */
651 #define DW_STRING(attr) ((attr)->u.str)
652 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
653 #define DW_UNSND(attr) ((attr)->u.unsnd)
654 #define DW_BLOCK(attr) ((attr)->u.blk)
655 #define DW_SND(attr) ((attr)->u.snd)
656 #define DW_ADDR(attr) ((attr)->u.addr)
657 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
659 /* Blocks are a bunch of untyped bytes. */
666 #ifndef ATTR_ALLOC_CHUNK
667 #define ATTR_ALLOC_CHUNK 4
670 /* Allocate fields for structs, unions and enums in this size. */
671 #ifndef DW_FIELD_ALLOC_CHUNK
672 #define DW_FIELD_ALLOC_CHUNK 4
675 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
676 but this would require a corresponding change in unpack_field_as_long
678 static int bits_per_byte = 8;
680 /* The routines that read and process dies for a C struct or C++ class
681 pass lists of data member fields and lists of member function fields
682 in an instance of a field_info structure, as defined below. */
685 /* List of data member and baseclasses fields. */
688 struct nextfield *next;
693 *fields, *baseclasses;
695 /* Number of fields (including baseclasses). */
698 /* Number of baseclasses. */
701 /* Set if the accesibility of one of the fields is not public. */
702 int non_public_fields;
704 /* Member function fields array, entries are allocated in the order they
705 are encountered in the object file. */
708 struct nextfnfield *next;
709 struct fn_field fnfield;
713 /* Member function fieldlist array, contains name of possibly overloaded
714 member function, number of overloaded member functions and a pointer
715 to the head of the member function field chain. */
720 struct nextfnfield *head;
724 /* Number of entries in the fnfieldlists array. */
727 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
728 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
729 struct typedef_field_list
731 struct typedef_field field;
732 struct typedef_field_list *next;
735 unsigned typedef_field_list_count;
738 /* One item on the queue of compilation units to read in full symbols
740 struct dwarf2_queue_item
742 struct dwarf2_per_cu_data *per_cu;
743 struct dwarf2_queue_item *next;
746 /* The current queue. */
747 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
749 /* Loaded secondary compilation units are kept in memory until they
750 have not been referenced for the processing of this many
751 compilation units. Set this to zero to disable caching. Cache
752 sizes of up to at least twenty will improve startup time for
753 typical inter-CU-reference binaries, at an obvious memory cost. */
754 static int dwarf2_max_cache_age = 5;
756 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
757 struct cmd_list_element *c, const char *value)
759 fprintf_filtered (file, _("\
760 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
765 /* Various complaints about symbol reading that don't abort the process */
768 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
770 complaint (&symfile_complaints,
771 _("statement list doesn't fit in .debug_line section"));
775 dwarf2_debug_line_missing_file_complaint (void)
777 complaint (&symfile_complaints,
778 _(".debug_line section has line data without a file"));
782 dwarf2_debug_line_missing_end_sequence_complaint (void)
784 complaint (&symfile_complaints,
785 _(".debug_line section has line program sequence without an end"));
789 dwarf2_complex_location_expr_complaint (void)
791 complaint (&symfile_complaints, _("location expression too complex"));
795 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
798 complaint (&symfile_complaints,
799 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
804 dwarf2_macros_too_long_complaint (void)
806 complaint (&symfile_complaints,
807 _("macro info runs off end of `.debug_macinfo' section"));
811 dwarf2_macro_malformed_definition_complaint (const char *arg1)
813 complaint (&symfile_complaints,
814 _("macro debug info contains a malformed macro definition:\n`%s'"),
819 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
821 complaint (&symfile_complaints,
822 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
825 /* local function prototypes */
827 static void dwarf2_locate_sections (bfd *, asection *, void *);
829 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
832 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
834 struct partial_symtab *);
836 static void dwarf2_build_psymtabs_hard (struct objfile *);
838 static void scan_partial_symbols (struct partial_die_info *,
839 CORE_ADDR *, CORE_ADDR *,
840 int, struct dwarf2_cu *);
842 static void add_partial_symbol (struct partial_die_info *,
845 static void add_partial_namespace (struct partial_die_info *pdi,
846 CORE_ADDR *lowpc, CORE_ADDR *highpc,
847 int need_pc, struct dwarf2_cu *cu);
849 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
850 CORE_ADDR *highpc, int need_pc,
851 struct dwarf2_cu *cu);
853 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
854 struct dwarf2_cu *cu);
856 static void add_partial_subprogram (struct partial_die_info *pdi,
857 CORE_ADDR *lowpc, CORE_ADDR *highpc,
858 int need_pc, struct dwarf2_cu *cu);
860 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
861 gdb_byte *buffer, gdb_byte *info_ptr,
862 bfd *abfd, struct dwarf2_cu *cu);
864 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
866 static void psymtab_to_symtab_1 (struct partial_symtab *);
868 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
870 static void dwarf2_free_abbrev_table (void *);
872 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
875 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
878 static struct partial_die_info *load_partial_dies (bfd *,
879 gdb_byte *, gdb_byte *,
880 int, struct dwarf2_cu *);
882 static gdb_byte *read_partial_die (struct partial_die_info *,
883 struct abbrev_info *abbrev,
885 gdb_byte *, gdb_byte *,
888 static struct partial_die_info *find_partial_die (unsigned int,
891 static void fixup_partial_die (struct partial_die_info *,
894 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
895 bfd *, gdb_byte *, struct dwarf2_cu *);
897 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
898 bfd *, gdb_byte *, struct dwarf2_cu *);
900 static unsigned int read_1_byte (bfd *, gdb_byte *);
902 static int read_1_signed_byte (bfd *, gdb_byte *);
904 static unsigned int read_2_bytes (bfd *, gdb_byte *);
906 static unsigned int read_4_bytes (bfd *, gdb_byte *);
908 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
910 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
913 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
915 static LONGEST read_checked_initial_length_and_offset
916 (bfd *, gdb_byte *, const struct comp_unit_head *,
917 unsigned int *, unsigned int *);
919 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
922 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
924 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
926 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
928 static char *read_indirect_string (bfd *, gdb_byte *,
929 const struct comp_unit_head *,
932 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
934 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
936 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
938 static void set_cu_language (unsigned int, struct dwarf2_cu *);
940 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
943 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
947 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
948 struct dwarf2_cu *cu);
950 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
952 static struct die_info *die_specification (struct die_info *die,
953 struct dwarf2_cu **);
955 static void free_line_header (struct line_header *lh);
957 static void add_file_name (struct line_header *, char *, unsigned int,
958 unsigned int, unsigned int);
960 static struct line_header *(dwarf_decode_line_header
961 (unsigned int offset,
962 bfd *abfd, struct dwarf2_cu *cu));
964 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
965 struct dwarf2_cu *, struct partial_symtab *);
967 static void dwarf2_start_subfile (char *, char *, char *);
969 static struct symbol *new_symbol (struct die_info *, struct type *,
972 static void dwarf2_const_value (struct attribute *, struct symbol *,
975 static void dwarf2_const_value_data (struct attribute *attr,
979 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
981 static int need_gnat_info (struct dwarf2_cu *);
983 static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *);
985 static void set_descriptive_type (struct type *, struct die_info *,
988 static struct type *die_containing_type (struct die_info *,
991 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
993 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
995 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
997 static char *typename_concat (struct obstack *obs, const char *prefix,
998 const char *suffix, int physname,
999 struct dwarf2_cu *cu);
1001 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1003 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1005 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1007 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1009 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1010 struct dwarf2_cu *, struct partial_symtab *);
1012 static int dwarf2_get_pc_bounds (struct die_info *,
1013 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1014 struct partial_symtab *);
1016 static void get_scope_pc_bounds (struct die_info *,
1017 CORE_ADDR *, CORE_ADDR *,
1018 struct dwarf2_cu *);
1020 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1021 CORE_ADDR, struct dwarf2_cu *);
1023 static void dwarf2_add_field (struct field_info *, struct die_info *,
1024 struct dwarf2_cu *);
1026 static void dwarf2_attach_fields_to_type (struct field_info *,
1027 struct type *, struct dwarf2_cu *);
1029 static void dwarf2_add_member_fn (struct field_info *,
1030 struct die_info *, struct type *,
1031 struct dwarf2_cu *);
1033 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1034 struct type *, struct dwarf2_cu *);
1036 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1038 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1040 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1042 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1044 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1046 static struct type *read_module_type (struct die_info *die,
1047 struct dwarf2_cu *cu);
1049 static const char *namespace_name (struct die_info *die,
1050 int *is_anonymous, struct dwarf2_cu *);
1052 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1054 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1056 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1057 struct dwarf2_cu *);
1059 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1061 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1063 gdb_byte **new_info_ptr,
1064 struct die_info *parent);
1066 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1068 gdb_byte **new_info_ptr,
1069 struct die_info *parent);
1071 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1073 gdb_byte **new_info_ptr,
1074 struct die_info *parent);
1076 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1077 struct die_info **, gdb_byte *,
1080 static void process_die (struct die_info *, struct dwarf2_cu *);
1082 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1085 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1087 static struct die_info *dwarf2_extension (struct die_info *die,
1088 struct dwarf2_cu **);
1090 static char *dwarf_tag_name (unsigned int);
1092 static char *dwarf_attr_name (unsigned int);
1094 static char *dwarf_form_name (unsigned int);
1096 static char *dwarf_bool_name (unsigned int);
1098 static char *dwarf_type_encoding_name (unsigned int);
1101 static char *dwarf_cfi_name (unsigned int);
1104 static struct die_info *sibling_die (struct die_info *);
1106 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1108 static void dump_die_for_error (struct die_info *);
1110 static void dump_die_1 (struct ui_file *, int level, int max_level,
1113 /*static*/ void dump_die (struct die_info *, int max_level);
1115 static void store_in_ref_table (struct die_info *,
1116 struct dwarf2_cu *);
1118 static int is_ref_attr (struct attribute *);
1120 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1122 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1124 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1126 struct dwarf2_cu **);
1128 static struct die_info *follow_die_ref (struct die_info *,
1130 struct dwarf2_cu **);
1132 static struct die_info *follow_die_sig (struct die_info *,
1134 struct dwarf2_cu **);
1136 static void read_signatured_type_at_offset (struct objfile *objfile,
1137 unsigned int offset);
1139 static void read_signatured_type (struct objfile *,
1140 struct signatured_type *type_sig);
1142 /* memory allocation interface */
1144 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1146 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1148 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1150 static void initialize_cu_func_list (struct dwarf2_cu *);
1152 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1153 struct dwarf2_cu *);
1155 static void dwarf_decode_macros (struct line_header *, unsigned int,
1156 char *, bfd *, struct dwarf2_cu *);
1158 static int attr_form_is_block (struct attribute *);
1160 static int attr_form_is_section_offset (struct attribute *);
1162 static int attr_form_is_constant (struct attribute *);
1164 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1166 struct dwarf2_cu *cu);
1168 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1169 struct abbrev_info *abbrev,
1170 struct dwarf2_cu *cu);
1172 static void free_stack_comp_unit (void *);
1174 static hashval_t partial_die_hash (const void *item);
1176 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1178 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1179 (unsigned int offset, struct objfile *objfile);
1181 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1182 (unsigned int offset, struct objfile *objfile);
1184 static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
1186 static void free_one_comp_unit (void *);
1188 static void free_cached_comp_units (void *);
1190 static void age_cached_comp_units (void);
1192 static void free_one_cached_comp_unit (void *);
1194 static struct type *set_die_type (struct die_info *, struct type *,
1195 struct dwarf2_cu *);
1197 static void create_all_comp_units (struct objfile *);
1199 static int create_debug_types_hash_table (struct objfile *objfile);
1201 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1204 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1206 static void dwarf2_add_dependence (struct dwarf2_cu *,
1207 struct dwarf2_per_cu_data *);
1209 static void dwarf2_mark (struct dwarf2_cu *);
1211 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1213 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1215 static void dwarf2_release_queue (void *dummy);
1217 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1218 struct objfile *objfile);
1220 static void process_queue (struct objfile *objfile);
1222 static void find_file_and_directory (struct die_info *die,
1223 struct dwarf2_cu *cu,
1224 char **name, char **comp_dir);
1226 static char *file_full_name (int file, struct line_header *lh,
1227 const char *comp_dir);
1229 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1232 unsigned int buffer_size,
1235 static void init_cu_die_reader (struct die_reader_specs *reader,
1236 struct dwarf2_cu *cu);
1238 static htab_t allocate_signatured_type_hash_table (struct objfile *objfile);
1242 /* Convert VALUE between big- and little-endian. */
1244 byte_swap (offset_type value)
1248 result = (value & 0xff) << 24;
1249 result |= (value & 0xff00) << 8;
1250 result |= (value & 0xff0000) >> 8;
1251 result |= (value & 0xff000000) >> 24;
1255 #define MAYBE_SWAP(V) byte_swap (V)
1258 #define MAYBE_SWAP(V) (V)
1259 #endif /* WORDS_BIGENDIAN */
1261 /* The suffix for an index file. */
1262 #define INDEX_SUFFIX ".gdb-index"
1264 /* Try to locate the sections we need for DWARF 2 debugging
1265 information and return true if we have enough to do something. */
1268 dwarf2_has_info (struct objfile *objfile)
1270 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1271 if (!dwarf2_per_objfile)
1273 /* Initialize per-objfile state. */
1274 struct dwarf2_per_objfile *data
1275 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1277 memset (data, 0, sizeof (*data));
1278 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1279 dwarf2_per_objfile = data;
1281 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1282 dwarf2_per_objfile->objfile = objfile;
1284 return (dwarf2_per_objfile->info.asection != NULL
1285 && dwarf2_per_objfile->abbrev.asection != NULL);
1288 /* When loading sections, we can either look for ".<name>", or for
1289 * ".z<name>", which indicates a compressed section. */
1292 section_is_p (const char *section_name, const char *name)
1294 return (section_name[0] == '.'
1295 && (strcmp (section_name + 1, name) == 0
1296 || (section_name[1] == 'z'
1297 && strcmp (section_name + 2, name) == 0)));
1300 /* This function is mapped across the sections and remembers the
1301 offset and size of each of the debugging sections we are interested
1305 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1307 if (section_is_p (sectp->name, INFO_SECTION))
1309 dwarf2_per_objfile->info.asection = sectp;
1310 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1312 else if (section_is_p (sectp->name, ABBREV_SECTION))
1314 dwarf2_per_objfile->abbrev.asection = sectp;
1315 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1317 else if (section_is_p (sectp->name, LINE_SECTION))
1319 dwarf2_per_objfile->line.asection = sectp;
1320 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1322 else if (section_is_p (sectp->name, LOC_SECTION))
1324 dwarf2_per_objfile->loc.asection = sectp;
1325 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1327 else if (section_is_p (sectp->name, MACINFO_SECTION))
1329 dwarf2_per_objfile->macinfo.asection = sectp;
1330 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1332 else if (section_is_p (sectp->name, STR_SECTION))
1334 dwarf2_per_objfile->str.asection = sectp;
1335 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1337 else if (section_is_p (sectp->name, FRAME_SECTION))
1339 dwarf2_per_objfile->frame.asection = sectp;
1340 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1342 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1344 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1346 if (aflag & SEC_HAS_CONTENTS)
1348 dwarf2_per_objfile->eh_frame.asection = sectp;
1349 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1352 else if (section_is_p (sectp->name, RANGES_SECTION))
1354 dwarf2_per_objfile->ranges.asection = sectp;
1355 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1357 else if (section_is_p (sectp->name, TYPES_SECTION))
1359 dwarf2_per_objfile->types.asection = sectp;
1360 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1362 else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
1364 dwarf2_per_objfile->gdb_index.asection = sectp;
1365 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1368 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1369 && bfd_section_vma (abfd, sectp) == 0)
1370 dwarf2_per_objfile->has_section_at_zero = 1;
1373 /* Decompress a section that was compressed using zlib. Store the
1374 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1377 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1378 gdb_byte **outbuf, bfd_size_type *outsize)
1380 bfd *abfd = objfile->obfd;
1382 error (_("Support for zlib-compressed DWARF data (from '%s') "
1383 "is disabled in this copy of GDB"),
1384 bfd_get_filename (abfd));
1386 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1387 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1388 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1389 bfd_size_type uncompressed_size;
1390 gdb_byte *uncompressed_buffer;
1393 int header_size = 12;
1395 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1396 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1397 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1398 bfd_get_filename (abfd));
1400 /* Read the zlib header. In this case, it should be "ZLIB" followed
1401 by the uncompressed section size, 8 bytes in big-endian order. */
1402 if (compressed_size < header_size
1403 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1404 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1405 bfd_get_filename (abfd));
1406 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1407 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1408 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1409 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1410 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1411 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1412 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1413 uncompressed_size += compressed_buffer[11];
1415 /* It is possible the section consists of several compressed
1416 buffers concatenated together, so we uncompress in a loop. */
1420 strm.avail_in = compressed_size - header_size;
1421 strm.next_in = (Bytef*) compressed_buffer + header_size;
1422 strm.avail_out = uncompressed_size;
1423 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1425 rc = inflateInit (&strm);
1426 while (strm.avail_in > 0)
1429 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1430 bfd_get_filename (abfd), rc);
1431 strm.next_out = ((Bytef*) uncompressed_buffer
1432 + (uncompressed_size - strm.avail_out));
1433 rc = inflate (&strm, Z_FINISH);
1434 if (rc != Z_STREAM_END)
1435 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1436 bfd_get_filename (abfd), rc);
1437 rc = inflateReset (&strm);
1439 rc = inflateEnd (&strm);
1441 || strm.avail_out != 0)
1442 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1443 bfd_get_filename (abfd), rc);
1445 do_cleanups (cleanup);
1446 *outbuf = uncompressed_buffer;
1447 *outsize = uncompressed_size;
1451 /* Read the contents of the section SECTP from object file specified by
1452 OBJFILE, store info about the section into INFO.
1453 If the section is compressed, uncompress it before returning. */
1456 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1458 bfd *abfd = objfile->obfd;
1459 asection *sectp = info->asection;
1460 gdb_byte *buf, *retbuf;
1461 unsigned char header[4];
1465 info->buffer = NULL;
1466 info->was_mmapped = 0;
1469 if (info->asection == NULL || info->size == 0)
1472 /* Check if the file has a 4-byte header indicating compression. */
1473 if (info->size > sizeof (header)
1474 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1475 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1477 /* Upon decompression, update the buffer and its size. */
1478 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1480 zlib_decompress_section (objfile, sectp, &info->buffer,
1488 pagesize = getpagesize ();
1490 /* Only try to mmap sections which are large enough: we don't want to
1491 waste space due to fragmentation. Also, only try mmap for sections
1492 without relocations. */
1494 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1496 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1497 size_t map_length = info->size + sectp->filepos - pg_offset;
1498 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1499 MAP_PRIVATE, pg_offset);
1501 if (retbuf != MAP_FAILED)
1503 info->was_mmapped = 1;
1504 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1505 #if HAVE_POSIX_MADVISE
1506 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1513 /* If we get here, we are a normal, not-compressed section. */
1515 = obstack_alloc (&objfile->objfile_obstack, info->size);
1517 /* When debugging .o files, we may need to apply relocations; see
1518 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1519 We never compress sections in .o files, so we only need to
1520 try this when the section is not compressed. */
1521 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1524 info->buffer = retbuf;
1528 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1529 || bfd_bread (buf, info->size, abfd) != info->size)
1530 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1531 bfd_get_filename (abfd));
1534 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1538 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1539 asection **sectp, gdb_byte **bufp,
1540 bfd_size_type *sizep)
1542 struct dwarf2_per_objfile *data
1543 = objfile_data (objfile, dwarf2_objfile_data_key);
1544 struct dwarf2_section_info *info;
1546 /* We may see an objfile without any DWARF, in which case we just
1555 if (section_is_p (section_name, EH_FRAME_SECTION))
1556 info = &data->eh_frame;
1557 else if (section_is_p (section_name, FRAME_SECTION))
1558 info = &data->frame;
1562 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1563 /* We haven't read this section in yet. Do it now. */
1564 dwarf2_read_section (objfile, info);
1566 *sectp = info->asection;
1567 *bufp = info->buffer;
1568 *sizep = info->size;
1573 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1576 dw2_do_instantiate_symtab (struct objfile *objfile,
1577 struct dwarf2_per_cu_data *per_cu)
1579 struct cleanup *back_to;
1581 back_to = make_cleanup (dwarf2_release_queue, NULL);
1583 queue_comp_unit (per_cu, objfile);
1585 if (per_cu->from_debug_types)
1586 read_signatured_type_at_offset (objfile, per_cu->offset);
1588 load_full_comp_unit (per_cu, objfile);
1590 process_queue (objfile);
1592 /* Age the cache, releasing compilation units that have not
1593 been used recently. */
1594 age_cached_comp_units ();
1596 do_cleanups (back_to);
1599 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1600 the objfile from which this CU came. Returns the resulting symbol
1602 static struct symtab *
1603 dw2_instantiate_symtab (struct objfile *objfile,
1604 struct dwarf2_per_cu_data *per_cu)
1606 if (!per_cu->v.quick->symtab)
1608 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1609 increment_reading_symtab ();
1610 dw2_do_instantiate_symtab (objfile, per_cu);
1611 do_cleanups (back_to);
1613 return per_cu->v.quick->symtab;
1616 /* Return the CU given its index. */
1617 static struct dwarf2_per_cu_data *
1618 dw2_get_cu (int index)
1620 if (index >= dwarf2_per_objfile->n_comp_units)
1622 index -= dwarf2_per_objfile->n_comp_units;
1623 return dwarf2_per_objfile->type_comp_units[index];
1625 return dwarf2_per_objfile->all_comp_units[index];
1628 /* A helper function that knows how to read a 64-bit value in a way
1629 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1632 extract_cu_value (const char *bytes, ULONGEST *result)
1634 if (sizeof (ULONGEST) < 8)
1638 /* Ignore the upper 4 bytes if they are all zero. */
1639 for (i = 0; i < 4; ++i)
1640 if (bytes[i + 4] != 0)
1643 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1646 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1650 /* Read the CU list from the mapped index, and use it to create all
1651 the CU objects for this objfile. Return 0 if something went wrong,
1652 1 if everything went ok. */
1654 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1655 offset_type cu_list_elements)
1659 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1660 dwarf2_per_objfile->all_comp_units
1661 = obstack_alloc (&objfile->objfile_obstack,
1662 dwarf2_per_objfile->n_comp_units
1663 * sizeof (struct dwarf2_per_cu_data *));
1665 for (i = 0; i < cu_list_elements; i += 2)
1667 struct dwarf2_per_cu_data *the_cu;
1668 ULONGEST offset, length;
1670 if (!extract_cu_value (cu_list, &offset)
1671 || !extract_cu_value (cu_list + 8, &length))
1675 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1676 struct dwarf2_per_cu_data);
1677 the_cu->offset = offset;
1678 the_cu->length = length;
1679 the_cu->objfile = objfile;
1680 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1681 struct dwarf2_per_cu_quick_data);
1682 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1688 /* Create the signatured type hash table from the index. */
1690 create_signatured_type_hash_from_index (struct objfile *objfile,
1691 const gdb_byte *bytes,
1692 offset_type elements)
1697 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1698 dwarf2_per_objfile->type_comp_units
1699 = obstack_alloc (&objfile->objfile_obstack,
1700 dwarf2_per_objfile->n_type_comp_units
1701 * sizeof (struct dwarf2_per_cu_data *));
1703 type_hash = allocate_signatured_type_hash_table (objfile);
1705 for (i = 0; i < elements; i += 3)
1707 struct signatured_type *type_sig;
1708 ULONGEST offset, type_offset, signature;
1711 if (!extract_cu_value (bytes, &offset)
1712 || !extract_cu_value (bytes + 8, &type_offset))
1714 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1717 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1718 struct signatured_type);
1719 type_sig->signature = signature;
1720 type_sig->offset = offset;
1721 type_sig->type_offset = type_offset;
1722 type_sig->per_cu.from_debug_types = 1;
1723 type_sig->per_cu.offset = offset;
1724 type_sig->per_cu.objfile = objfile;
1725 type_sig->per_cu.v.quick
1726 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1727 struct dwarf2_per_cu_quick_data);
1729 slot = htab_find_slot (type_hash, type_sig, INSERT);
1732 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1735 dwarf2_per_objfile->signatured_types = type_hash;
1740 /* Read the address map data from the mapped index, and use it to
1741 populate the objfile's psymtabs_addrmap. */
1743 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1745 const gdb_byte *iter, *end;
1746 struct obstack temp_obstack;
1747 struct addrmap *mutable_map;
1748 struct cleanup *cleanup;
1751 obstack_init (&temp_obstack);
1752 cleanup = make_cleanup_obstack_free (&temp_obstack);
1753 mutable_map = addrmap_create_mutable (&temp_obstack);
1755 iter = index->address_table;
1756 end = iter + index->address_table_size;
1758 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1762 ULONGEST hi, lo, cu_index;
1763 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1765 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1767 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1770 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1771 dw2_get_cu (cu_index));
1774 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1775 &objfile->objfile_obstack);
1776 do_cleanups (cleanup);
1779 /* The hash function for strings in the mapped index. This is the
1780 same as the hashtab.c hash function, but we keep a separate copy to
1781 maintain control over the implementation. This is necessary
1782 because the hash function is tied to the format of the mapped index
1785 mapped_index_string_hash (const void *p)
1787 const unsigned char *str = (const unsigned char *) p;
1791 while ((c = *str++) != 0)
1792 r = r * 67 + c - 113;
1797 /* Find a slot in the mapped index INDEX for the object named NAME.
1798 If NAME is found, set *VEC_OUT to point to the CU vector in the
1799 constant pool and return 1. If NAME cannot be found, return 0. */
1801 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
1802 offset_type **vec_out)
1804 offset_type hash = mapped_index_string_hash (name);
1805 offset_type slot, step;
1807 slot = hash & (index->index_table_slots - 1);
1808 step = ((hash * 17) & (index->index_table_slots - 1)) | 1;
1812 /* Convert a slot number to an offset into the table. */
1813 offset_type i = 2 * slot;
1815 if (index->index_table[i] == 0 && index->index_table[i + 1] == 0)
1818 str = index->constant_pool + MAYBE_SWAP (index->index_table[i]);
1819 if (!strcmp (name, str))
1821 *vec_out = (offset_type *) (index->constant_pool
1822 + MAYBE_SWAP (index->index_table[i + 1]));
1826 slot = (slot + step) & (index->index_table_slots - 1);
1830 /* Read the index file. If everything went ok, initialize the "quick"
1831 elements of all the CUs and return 1. Otherwise, return 0. */
1833 dwarf2_read_index (struct objfile *objfile)
1836 struct mapped_index *map;
1837 offset_type *metadata;
1838 const gdb_byte *cu_list;
1839 const gdb_byte *types_list = NULL;
1840 offset_type version, cu_list_elements;
1841 offset_type types_list_elements = 0;
1844 if (dwarf2_per_objfile->gdb_index.asection == NULL
1845 || dwarf2_per_objfile->gdb_index.size == 0)
1847 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
1849 addr = dwarf2_per_objfile->gdb_index.buffer;
1850 /* Version check. */
1851 version = MAYBE_SWAP (*(offset_type *) addr);
1854 /* Index version 1 neglected to account for .debug_types. So,
1855 if we see .debug_types, we cannot use this index. */
1856 if (dwarf2_per_objfile->types.asection != NULL
1857 && dwarf2_per_objfile->types.size != 0)
1860 else if (version != 2)
1863 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
1864 map->total_size = dwarf2_per_objfile->gdb_index.size;
1866 metadata = (offset_type *) (addr + sizeof (offset_type));
1869 cu_list = addr + MAYBE_SWAP (metadata[i]);
1870 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
1876 types_list = addr + MAYBE_SWAP (metadata[i]);
1877 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
1878 - MAYBE_SWAP (metadata[i]))
1883 map->address_table = addr + MAYBE_SWAP (metadata[i]);
1884 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
1885 - MAYBE_SWAP (metadata[i]));
1888 map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
1889 map->index_table_slots = ((MAYBE_SWAP (metadata[i + 1])
1890 - MAYBE_SWAP (metadata[i]))
1891 / (2 * sizeof (offset_type)));
1894 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
1896 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
1900 && types_list_elements
1901 && !create_signatured_type_hash_from_index (objfile, types_list,
1902 types_list_elements))
1905 create_addrmap_from_index (objfile, map);
1907 dwarf2_per_objfile->index_table = map;
1908 dwarf2_per_objfile->using_index = 1;
1913 /* A helper for the "quick" functions which sets the global
1914 dwarf2_per_objfile according to OBJFILE. */
1916 dw2_setup (struct objfile *objfile)
1918 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1919 gdb_assert (dwarf2_per_objfile);
1922 /* A helper for the "quick" functions which attempts to read the line
1923 table for THIS_CU. */
1925 dw2_require_line_header (struct objfile *objfile,
1926 struct dwarf2_per_cu_data *this_cu)
1928 bfd *abfd = objfile->obfd;
1929 struct line_header *lh = NULL;
1930 struct attribute *attr;
1931 struct cleanup *cleanups;
1932 struct die_info *comp_unit_die;
1933 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
1934 int has_children, i;
1935 struct dwarf2_cu cu;
1936 unsigned int bytes_read, buffer_size;
1937 struct die_reader_specs reader_specs;
1938 char *name, *comp_dir;
1940 if (this_cu->v.quick->read_lines)
1942 this_cu->v.quick->read_lines = 1;
1944 memset (&cu, 0, sizeof (cu));
1945 cu.objfile = objfile;
1946 obstack_init (&cu.comp_unit_obstack);
1948 cleanups = make_cleanup (free_stack_comp_unit, &cu);
1950 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
1951 buffer_size = dwarf2_per_objfile->info.size;
1952 buffer = dwarf2_per_objfile->info.buffer;
1953 info_ptr = buffer + this_cu->offset;
1954 beg_of_comp_unit = info_ptr;
1956 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
1957 buffer, buffer_size,
1960 /* Complete the cu_header. */
1961 cu.header.offset = beg_of_comp_unit - buffer;
1962 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1965 cu.per_cu = this_cu;
1967 dwarf2_read_abbrevs (abfd, &cu);
1968 make_cleanup (dwarf2_free_abbrev_table, &cu);
1970 if (this_cu->from_debug_types)
1971 info_ptr += 8 /*signature*/ + cu.header.offset_size;
1972 init_cu_die_reader (&reader_specs, &cu);
1973 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
1976 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
1979 unsigned int line_offset = DW_UNSND (attr);
1980 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
1984 do_cleanups (cleanups);
1988 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
1990 this_cu->v.quick->lines = lh;
1992 this_cu->v.quick->file_names
1993 = obstack_alloc (&objfile->objfile_obstack,
1994 lh->num_file_names * sizeof (char *));
1995 for (i = 0; i < lh->num_file_names; ++i)
1996 this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
1998 do_cleanups (cleanups);
2001 /* A helper for the "quick" functions which computes and caches the
2002 real path for a given file name from the line table.
2003 dw2_require_line_header must have been called before this is
2006 dw2_require_full_path (struct objfile *objfile,
2007 struct dwarf2_per_cu_data *cu,
2010 if (!cu->v.quick->full_names)
2011 cu->v.quick->full_names
2012 = OBSTACK_CALLOC (&objfile->objfile_obstack,
2013 cu->v.quick->lines->num_file_names,
2016 if (!cu->v.quick->full_names[index])
2017 cu->v.quick->full_names[index]
2018 = gdb_realpath (cu->v.quick->file_names[index]);
2020 return cu->v.quick->full_names[index];
2023 static struct symtab *
2024 dw2_find_last_source_symtab (struct objfile *objfile)
2027 dw2_setup (objfile);
2028 index = dwarf2_per_objfile->n_comp_units - 1;
2029 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2033 dw2_forget_cached_source_info (struct objfile *objfile)
2037 dw2_setup (objfile);
2038 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2039 + dwarf2_per_objfile->n_type_comp_units); ++i)
2041 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2043 if (cu->v.quick->full_names)
2047 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2048 xfree ((void *) cu->v.quick->full_names[j]);
2054 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2055 const char *full_path, const char *real_path,
2056 struct symtab **result)
2059 int check_basename = lbasename (name) == name;
2060 struct dwarf2_per_cu_data *base_cu = NULL;
2062 dw2_setup (objfile);
2063 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2064 + dwarf2_per_objfile->n_type_comp_units); ++i)
2067 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2069 if (cu->v.quick->symtab)
2072 dw2_require_line_header (objfile, cu);
2073 if (!cu->v.quick->lines)
2076 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2078 const char *this_name = cu->v.quick->file_names[j];
2080 if (FILENAME_CMP (name, this_name) == 0)
2082 *result = dw2_instantiate_symtab (objfile, cu);
2086 if (check_basename && ! base_cu
2087 && FILENAME_CMP (lbasename (this_name), name) == 0)
2090 if (full_path != NULL)
2092 const char *this_full_name = dw2_require_full_path (objfile,
2096 && FILENAME_CMP (full_path, this_full_name) == 0)
2098 *result = dw2_instantiate_symtab (objfile, cu);
2103 if (real_path != NULL)
2105 const char *this_full_name = dw2_require_full_path (objfile,
2108 if (this_full_name != NULL)
2110 char *rp = gdb_realpath (this_full_name);
2111 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
2114 *result = dw2_instantiate_symtab (objfile, cu);
2125 *result = dw2_instantiate_symtab (objfile, base_cu);
2132 static struct symtab *
2133 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2134 const char *name, domain_enum domain)
2136 /* We do all the work in the pre_expand_symtabs_matching hook
2141 /* A helper function that expands all symtabs that hold an object
2144 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2146 dw2_setup (objfile);
2148 if (dwarf2_per_objfile->index_table)
2152 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2155 offset_type i, len = MAYBE_SWAP (*vec);
2156 for (i = 0; i < len; ++i)
2158 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2159 struct dwarf2_per_cu_data *cu = dw2_get_cu (cu_index);
2161 dw2_instantiate_symtab (objfile, cu);
2168 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2169 int kind, const char *name,
2172 dw2_do_expand_symtabs_matching (objfile, name);
2176 dw2_print_stats (struct objfile *objfile)
2180 dw2_setup (objfile);
2182 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2183 + dwarf2_per_objfile->n_type_comp_units); ++i)
2185 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2187 if (!cu->v.quick->symtab)
2190 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2194 dw2_dump (struct objfile *objfile)
2196 /* Nothing worth printing. */
2200 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2201 struct section_offsets *delta)
2203 /* There's nothing to relocate here. */
2207 dw2_expand_symtabs_for_function (struct objfile *objfile,
2208 const char *func_name)
2210 dw2_do_expand_symtabs_matching (objfile, func_name);
2214 dw2_expand_all_symtabs (struct objfile *objfile)
2218 dw2_setup (objfile);
2220 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2221 + dwarf2_per_objfile->n_type_comp_units); ++i)
2223 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2225 dw2_instantiate_symtab (objfile, cu);
2230 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2231 const char *filename)
2235 dw2_setup (objfile);
2236 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2237 + dwarf2_per_objfile->n_type_comp_units); ++i)
2240 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2242 if (cu->v.quick->symtab)
2245 dw2_require_line_header (objfile, cu);
2246 if (!cu->v.quick->lines)
2249 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2251 const char *this_name = cu->v.quick->file_names[j];
2252 if (strcmp (this_name, filename) == 0)
2254 dw2_instantiate_symtab (objfile, cu);
2262 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2264 struct dwarf2_per_cu_data *cu;
2267 dw2_setup (objfile);
2269 if (!dwarf2_per_objfile->index_table)
2272 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2276 /* Note that this just looks at the very first one named NAME -- but
2277 actually we are looking for a function. find_main_filename
2278 should be rewritten so that it doesn't require a custom hook. It
2279 could just use the ordinary symbol tables. */
2280 /* vec[0] is the length, which must always be >0. */
2281 cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2283 dw2_require_line_header (objfile, cu);
2284 if (!cu->v.quick->lines)
2287 return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1];
2291 dw2_map_ada_symtabs (struct objfile *objfile,
2292 int (*wild_match) (const char *, int, const char *),
2293 int (*is_name_suffix) (const char *),
2294 void (*callback) (struct objfile *,
2295 struct symtab *, void *),
2296 const char *name, int global,
2297 domain_enum namespace, int wild,
2300 /* For now, we don't support Ada, so this function can't be
2302 internal_error (__FILE__, __LINE__,
2303 _("map_ada_symtabs called via index method"));
2307 dw2_expand_symtabs_matching (struct objfile *objfile,
2308 int (*file_matcher) (const char *, void *),
2309 int (*name_matcher) (const char *, void *),
2316 dw2_setup (objfile);
2317 if (!dwarf2_per_objfile->index_table)
2320 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2321 + dwarf2_per_objfile->n_type_comp_units); ++i)
2324 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2326 cu->v.quick->mark = 0;
2327 if (cu->v.quick->symtab)
2330 dw2_require_line_header (objfile, cu);
2331 if (!cu->v.quick->lines)
2334 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2336 if (file_matcher (cu->v.quick->file_names[j], data))
2338 cu->v.quick->mark = 1;
2345 iter < dwarf2_per_objfile->index_table->index_table_slots;
2348 offset_type idx = 2 * iter;
2350 offset_type *vec, vec_len, vec_idx;
2352 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2353 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2356 name = (dwarf2_per_objfile->index_table->constant_pool
2357 + dwarf2_per_objfile->index_table->index_table[idx]);
2359 if (! (*name_matcher) (name, data))
2362 /* The name was matched, now expand corresponding CUs that were
2364 vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
2365 + dwarf2_per_objfile->index_table->index_table[idx + 1]);
2366 vec_len = MAYBE_SWAP (vec[0]);
2367 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2369 struct dwarf2_per_cu_data *cu;
2371 cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2372 if (cu->v.quick->mark)
2373 dw2_instantiate_symtab (objfile, cu);
2378 static struct symtab *
2379 dw2_find_pc_sect_symtab (struct objfile *objfile,
2380 struct minimal_symbol *msymbol,
2382 struct obj_section *section,
2385 struct dwarf2_per_cu_data *data;
2387 dw2_setup (objfile);
2389 if (!objfile->psymtabs_addrmap)
2392 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2396 if (warn_if_readin && data->v.quick->symtab)
2397 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2398 paddress (get_objfile_arch (objfile), pc));
2400 return dw2_instantiate_symtab (objfile, data);
2404 dw2_map_symbol_names (struct objfile *objfile,
2405 void (*fun) (const char *, void *),
2409 dw2_setup (objfile);
2411 if (!dwarf2_per_objfile->index_table)
2415 iter < dwarf2_per_objfile->index_table->index_table_slots;
2418 offset_type idx = 2 * iter;
2420 offset_type *vec, vec_len, vec_idx;
2422 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2423 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2426 name = (dwarf2_per_objfile->index_table->constant_pool
2427 + dwarf2_per_objfile->index_table->index_table[idx]);
2429 (*fun) (name, data);
2434 dw2_map_symbol_filenames (struct objfile *objfile,
2435 void (*fun) (const char *, const char *, void *),
2440 dw2_setup (objfile);
2441 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2442 + dwarf2_per_objfile->n_type_comp_units); ++i)
2445 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2447 if (cu->v.quick->symtab)
2450 dw2_require_line_header (objfile, cu);
2451 if (!cu->v.quick->lines)
2454 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2456 const char *this_full_name = dw2_require_full_path (objfile, cu, j);
2457 (*fun) (cu->v.quick->file_names[j], this_full_name, data);
2463 dw2_has_symbols (struct objfile *objfile)
2468 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2471 dw2_find_last_source_symtab,
2472 dw2_forget_cached_source_info,
2475 dw2_pre_expand_symtabs_matching,
2479 dw2_expand_symtabs_for_function,
2480 dw2_expand_all_symtabs,
2481 dw2_expand_symtabs_with_filename,
2482 dw2_find_symbol_file,
2483 dw2_map_ada_symtabs,
2484 dw2_expand_symtabs_matching,
2485 dw2_find_pc_sect_symtab,
2486 dw2_map_symbol_names,
2487 dw2_map_symbol_filenames
2490 /* Initialize for reading DWARF for this objfile. Return 0 if this
2491 file will use psymtabs, or 1 if using the GNU index. */
2494 dwarf2_initialize_objfile (struct objfile *objfile)
2496 /* If we're about to read full symbols, don't bother with the
2497 indices. In this case we also don't care if some other debug
2498 format is making psymtabs, because they are all about to be
2500 if ((objfile->flags & OBJF_READNOW))
2504 dwarf2_per_objfile->using_index = 1;
2505 create_all_comp_units (objfile);
2506 create_debug_types_hash_table (objfile);
2508 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2509 + dwarf2_per_objfile->n_type_comp_units); ++i)
2511 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2513 cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2514 struct dwarf2_per_cu_quick_data);
2517 /* Return 1 so that gdb sees the "quick" functions. However,
2518 these functions will be no-ops because we will have expanded
2523 if (dwarf2_read_index (objfile))
2526 dwarf2_build_psymtabs (objfile);
2532 /* Build a partial symbol table. */
2535 dwarf2_build_psymtabs (struct objfile *objfile)
2537 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2539 init_psymbol_list (objfile, 1024);
2542 dwarf2_build_psymtabs_hard (objfile);
2545 /* Return TRUE if OFFSET is within CU_HEADER. */
2548 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2550 unsigned int bottom = cu_header->offset;
2551 unsigned int top = (cu_header->offset
2553 + cu_header->initial_length_size);
2555 return (offset >= bottom && offset < top);
2558 /* Read in the comp unit header information from the debug_info at info_ptr.
2559 NOTE: This leaves members offset, first_die_offset to be filled in
2563 read_comp_unit_head (struct comp_unit_head *cu_header,
2564 gdb_byte *info_ptr, bfd *abfd)
2567 unsigned int bytes_read;
2569 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2570 cu_header->initial_length_size = bytes_read;
2571 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2572 info_ptr += bytes_read;
2573 cu_header->version = read_2_bytes (abfd, info_ptr);
2575 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2577 info_ptr += bytes_read;
2578 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2580 signed_addr = bfd_get_sign_extend_vma (abfd);
2581 if (signed_addr < 0)
2582 internal_error (__FILE__, __LINE__,
2583 _("read_comp_unit_head: dwarf from non elf file"));
2584 cu_header->signed_addr_p = signed_addr;
2590 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2591 gdb_byte *buffer, unsigned int buffer_size,
2594 gdb_byte *beg_of_comp_unit = info_ptr;
2596 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2598 if (header->version != 2 && header->version != 3 && header->version != 4)
2599 error (_("Dwarf Error: wrong version in compilation unit header "
2600 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2601 bfd_get_filename (abfd));
2603 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
2604 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2605 "(offset 0x%lx + 6) [in module %s]"),
2606 (long) header->abbrev_offset,
2607 (long) (beg_of_comp_unit - buffer),
2608 bfd_get_filename (abfd));
2610 if (beg_of_comp_unit + header->length + header->initial_length_size
2611 > buffer + buffer_size)
2612 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2613 "(offset 0x%lx + 0) [in module %s]"),
2614 (long) header->length,
2615 (long) (beg_of_comp_unit - buffer),
2616 bfd_get_filename (abfd));
2621 /* Read in the types comp unit header information from .debug_types entry at
2622 types_ptr. The result is a pointer to one past the end of the header. */
2625 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2626 ULONGEST *signature,
2627 gdb_byte *types_ptr, bfd *abfd)
2629 gdb_byte *initial_types_ptr = types_ptr;
2631 dwarf2_read_section (dwarf2_per_objfile->objfile,
2632 &dwarf2_per_objfile->types);
2633 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2635 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2637 *signature = read_8_bytes (abfd, types_ptr);
2639 types_ptr += cu_header->offset_size;
2640 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2645 /* Allocate a new partial symtab for file named NAME and mark this new
2646 partial symtab as being an include of PST. */
2649 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2650 struct objfile *objfile)
2652 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2654 subpst->section_offsets = pst->section_offsets;
2655 subpst->textlow = 0;
2656 subpst->texthigh = 0;
2658 subpst->dependencies = (struct partial_symtab **)
2659 obstack_alloc (&objfile->objfile_obstack,
2660 sizeof (struct partial_symtab *));
2661 subpst->dependencies[0] = pst;
2662 subpst->number_of_dependencies = 1;
2664 subpst->globals_offset = 0;
2665 subpst->n_global_syms = 0;
2666 subpst->statics_offset = 0;
2667 subpst->n_static_syms = 0;
2668 subpst->symtab = NULL;
2669 subpst->read_symtab = pst->read_symtab;
2672 /* No private part is necessary for include psymtabs. This property
2673 can be used to differentiate between such include psymtabs and
2674 the regular ones. */
2675 subpst->read_symtab_private = NULL;
2678 /* Read the Line Number Program data and extract the list of files
2679 included by the source file represented by PST. Build an include
2680 partial symtab for each of these included files. */
2683 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2684 struct die_info *die,
2685 struct partial_symtab *pst)
2687 struct objfile *objfile = cu->objfile;
2688 bfd *abfd = objfile->obfd;
2689 struct line_header *lh = NULL;
2690 struct attribute *attr;
2692 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2695 unsigned int line_offset = DW_UNSND (attr);
2697 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2700 return; /* No linetable, so no includes. */
2702 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
2704 free_line_header (lh);
2708 hash_type_signature (const void *item)
2710 const struct signatured_type *type_sig = item;
2712 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2713 return type_sig->signature;
2717 eq_type_signature (const void *item_lhs, const void *item_rhs)
2719 const struct signatured_type *lhs = item_lhs;
2720 const struct signatured_type *rhs = item_rhs;
2722 return lhs->signature == rhs->signature;
2725 /* Allocate a hash table for signatured types. */
2728 allocate_signatured_type_hash_table (struct objfile *objfile)
2730 return htab_create_alloc_ex (41,
2731 hash_type_signature,
2734 &objfile->objfile_obstack,
2735 hashtab_obstack_allocate,
2736 dummy_obstack_deallocate);
2739 /* A helper function to add a signatured type CU to a list. */
2742 add_signatured_type_cu_to_list (void **slot, void *datum)
2744 struct signatured_type *sigt = *slot;
2745 struct dwarf2_per_cu_data ***datap = datum;
2747 **datap = &sigt->per_cu;
2753 /* Create the hash table of all entries in the .debug_types section.
2754 The result is zero if there is an error (e.g. missing .debug_types section),
2755 otherwise non-zero. */
2758 create_debug_types_hash_table (struct objfile *objfile)
2762 struct dwarf2_per_cu_data **iter;
2764 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
2765 info_ptr = dwarf2_per_objfile->types.buffer;
2767 if (info_ptr == NULL)
2769 dwarf2_per_objfile->signatured_types = NULL;
2773 types_htab = allocate_signatured_type_hash_table (objfile);
2775 if (dwarf2_die_debug)
2776 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
2778 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2780 unsigned int offset;
2781 unsigned int offset_size;
2782 unsigned int type_offset;
2783 unsigned int length, initial_length_size;
2784 unsigned short version;
2786 struct signatured_type *type_sig;
2788 gdb_byte *ptr = info_ptr;
2790 offset = ptr - dwarf2_per_objfile->types.buffer;
2792 /* We need to read the type's signature in order to build the hash
2793 table, but we don't need to read anything else just yet. */
2795 /* Sanity check to ensure entire cu is present. */
2796 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
2797 if (ptr + length + initial_length_size
2798 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2800 complaint (&symfile_complaints,
2801 _("debug type entry runs off end of `.debug_types' section, ignored"));
2805 offset_size = initial_length_size == 4 ? 4 : 8;
2806 ptr += initial_length_size;
2807 version = bfd_get_16 (objfile->obfd, ptr);
2809 ptr += offset_size; /* abbrev offset */
2810 ptr += 1; /* address size */
2811 signature = bfd_get_64 (objfile->obfd, ptr);
2813 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
2815 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
2816 memset (type_sig, 0, sizeof (*type_sig));
2817 type_sig->signature = signature;
2818 type_sig->offset = offset;
2819 type_sig->type_offset = type_offset;
2820 type_sig->per_cu.objfile = objfile;
2821 type_sig->per_cu.from_debug_types = 1;
2823 slot = htab_find_slot (types_htab, type_sig, INSERT);
2824 gdb_assert (slot != NULL);
2827 if (dwarf2_die_debug)
2828 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
2829 offset, phex (signature, sizeof (signature)));
2831 info_ptr = info_ptr + initial_length_size + length;
2834 dwarf2_per_objfile->signatured_types = types_htab;
2836 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
2837 dwarf2_per_objfile->type_comp_units
2838 = obstack_alloc (&objfile->objfile_obstack,
2839 dwarf2_per_objfile->n_type_comp_units
2840 * sizeof (struct dwarf2_per_cu_data *));
2841 iter = &dwarf2_per_objfile->type_comp_units[0];
2842 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
2843 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
2844 == dwarf2_per_objfile->n_type_comp_units);
2849 /* Lookup a signature based type.
2850 Returns NULL if SIG is not present in the table. */
2852 static struct signatured_type *
2853 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
2855 struct signatured_type find_entry, *entry;
2857 if (dwarf2_per_objfile->signatured_types == NULL)
2859 complaint (&symfile_complaints,
2860 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2864 find_entry.signature = sig;
2865 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
2869 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2872 init_cu_die_reader (struct die_reader_specs *reader,
2873 struct dwarf2_cu *cu)
2875 reader->abfd = cu->objfile->obfd;
2877 if (cu->per_cu->from_debug_types)
2879 gdb_assert (dwarf2_per_objfile->types.readin);
2880 reader->buffer = dwarf2_per_objfile->types.buffer;
2884 gdb_assert (dwarf2_per_objfile->info.readin);
2885 reader->buffer = dwarf2_per_objfile->info.buffer;
2889 /* Find the base address of the compilation unit for range lists and
2890 location lists. It will normally be specified by DW_AT_low_pc.
2891 In DWARF-3 draft 4, the base address could be overridden by
2892 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2893 compilation units with discontinuous ranges. */
2896 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
2898 struct attribute *attr;
2901 cu->base_address = 0;
2903 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
2906 cu->base_address = DW_ADDR (attr);
2911 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2914 cu->base_address = DW_ADDR (attr);
2920 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2921 to combine the common parts.
2922 Process a compilation unit for a psymtab.
2923 BUFFER is a pointer to the beginning of the dwarf section buffer,
2924 either .debug_info or debug_types.
2925 INFO_PTR is a pointer to the start of the CU.
2926 Returns a pointer to the next CU. */
2929 process_psymtab_comp_unit (struct objfile *objfile,
2930 struct dwarf2_per_cu_data *this_cu,
2931 gdb_byte *buffer, gdb_byte *info_ptr,
2932 unsigned int buffer_size)
2934 bfd *abfd = objfile->obfd;
2935 gdb_byte *beg_of_comp_unit = info_ptr;
2936 struct die_info *comp_unit_die;
2937 struct partial_symtab *pst;
2939 struct cleanup *back_to_inner;
2940 struct dwarf2_cu cu;
2941 int has_children, has_pc_info;
2942 struct attribute *attr;
2943 CORE_ADDR best_lowpc = 0, best_highpc = 0;
2944 struct die_reader_specs reader_specs;
2946 memset (&cu, 0, sizeof (cu));
2947 cu.objfile = objfile;
2948 obstack_init (&cu.comp_unit_obstack);
2950 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
2952 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2953 buffer, buffer_size,
2956 /* Complete the cu_header. */
2957 cu.header.offset = beg_of_comp_unit - buffer;
2958 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2960 cu.list_in_scope = &file_symbols;
2962 /* If this compilation unit was already read in, free the
2963 cached copy in order to read it in again. This is
2964 necessary because we skipped some symbols when we first
2965 read in the compilation unit (see load_partial_dies).
2966 This problem could be avoided, but the benefit is
2968 if (this_cu->cu != NULL)
2969 free_one_cached_comp_unit (this_cu->cu);
2971 /* Note that this is a pointer to our stack frame, being
2972 added to a global data structure. It will be cleaned up
2973 in free_stack_comp_unit when we finish with this
2974 compilation unit. */
2976 cu.per_cu = this_cu;
2978 /* Read the abbrevs for this compilation unit into a table. */
2979 dwarf2_read_abbrevs (abfd, &cu);
2980 make_cleanup (dwarf2_free_abbrev_table, &cu);
2982 /* Read the compilation unit die. */
2983 if (this_cu->from_debug_types)
2984 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2985 init_cu_die_reader (&reader_specs, &cu);
2986 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2989 if (this_cu->from_debug_types)
2991 /* offset,length haven't been set yet for type units. */
2992 this_cu->offset = cu.header.offset;
2993 this_cu->length = cu.header.length + cu.header.initial_length_size;
2995 else if (comp_unit_die->tag == DW_TAG_partial_unit)
2997 info_ptr = (beg_of_comp_unit + cu.header.length
2998 + cu.header.initial_length_size);
2999 do_cleanups (back_to_inner);
3003 /* Set the language we're debugging. */
3004 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
3006 set_cu_language (DW_UNSND (attr), &cu);
3008 set_cu_language (language_minimal, &cu);
3010 /* Allocate a new partial symbol table structure. */
3011 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3012 pst = start_psymtab_common (objfile, objfile->section_offsets,
3013 (attr != NULL) ? DW_STRING (attr) : "",
3014 /* TEXTLOW and TEXTHIGH are set below. */
3016 objfile->global_psymbols.next,
3017 objfile->static_psymbols.next);
3019 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3021 pst->dirname = DW_STRING (attr);
3023 pst->read_symtab_private = this_cu;
3025 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3027 /* Store the function that reads in the rest of the symbol table */
3028 pst->read_symtab = dwarf2_psymtab_to_symtab;
3030 this_cu->v.psymtab = pst;
3032 dwarf2_find_base_address (comp_unit_die, &cu);
3034 /* Possibly set the default values of LOWPC and HIGHPC from
3036 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3037 &best_highpc, &cu, pst);
3038 if (has_pc_info == 1 && best_lowpc < best_highpc)
3039 /* Store the contiguous range if it is not empty; it can be empty for
3040 CUs with no code. */
3041 addrmap_set_empty (objfile->psymtabs_addrmap,
3042 best_lowpc + baseaddr,
3043 best_highpc + baseaddr - 1, pst);
3045 /* Check if comp unit has_children.
3046 If so, read the rest of the partial symbols from this comp unit.
3047 If not, there's no more debug_info for this comp unit. */
3050 struct partial_die_info *first_die;
3051 CORE_ADDR lowpc, highpc;
3053 lowpc = ((CORE_ADDR) -1);
3054 highpc = ((CORE_ADDR) 0);
3056 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3058 scan_partial_symbols (first_die, &lowpc, &highpc,
3059 ! has_pc_info, &cu);
3061 /* If we didn't find a lowpc, set it to highpc to avoid
3062 complaints from `maint check'. */
3063 if (lowpc == ((CORE_ADDR) -1))
3066 /* If the compilation unit didn't have an explicit address range,
3067 then use the information extracted from its child dies. */
3071 best_highpc = highpc;
3074 pst->textlow = best_lowpc + baseaddr;
3075 pst->texthigh = best_highpc + baseaddr;
3077 pst->n_global_syms = objfile->global_psymbols.next -
3078 (objfile->global_psymbols.list + pst->globals_offset);
3079 pst->n_static_syms = objfile->static_psymbols.next -
3080 (objfile->static_psymbols.list + pst->statics_offset);
3081 sort_pst_symbols (pst);
3083 info_ptr = (beg_of_comp_unit + cu.header.length
3084 + cu.header.initial_length_size);
3086 if (this_cu->from_debug_types)
3088 /* It's not clear we want to do anything with stmt lists here.
3089 Waiting to see what gcc ultimately does. */
3093 /* Get the list of files included in the current compilation unit,
3094 and build a psymtab for each of them. */
3095 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3098 do_cleanups (back_to_inner);
3103 /* Traversal function for htab_traverse_noresize.
3104 Process one .debug_types comp-unit. */
3107 process_type_comp_unit (void **slot, void *info)
3109 struct signatured_type *entry = (struct signatured_type *) *slot;
3110 struct objfile *objfile = (struct objfile *) info;
3111 struct dwarf2_per_cu_data *this_cu;
3113 this_cu = &entry->per_cu;
3115 gdb_assert (dwarf2_per_objfile->types.readin);
3116 process_psymtab_comp_unit (objfile, this_cu,
3117 dwarf2_per_objfile->types.buffer,
3118 dwarf2_per_objfile->types.buffer + entry->offset,
3119 dwarf2_per_objfile->types.size);
3124 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3125 Build partial symbol tables for the .debug_types comp-units. */
3128 build_type_psymtabs (struct objfile *objfile)
3130 if (! create_debug_types_hash_table (objfile))
3133 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3134 process_type_comp_unit, objfile);
3137 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3140 psymtabs_addrmap_cleanup (void *o)
3142 struct objfile *objfile = o;
3144 objfile->psymtabs_addrmap = NULL;
3147 /* Build the partial symbol table by doing a quick pass through the
3148 .debug_info and .debug_abbrev sections. */
3151 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3154 struct cleanup *back_to, *addrmap_cleanup;
3155 struct obstack temp_obstack;
3157 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3158 info_ptr = dwarf2_per_objfile->info.buffer;
3160 /* Any cached compilation units will be linked by the per-objfile
3161 read_in_chain. Make sure to free them when we're done. */
3162 back_to = make_cleanup (free_cached_comp_units, NULL);
3164 build_type_psymtabs (objfile);
3166 create_all_comp_units (objfile);
3168 /* Create a temporary address map on a temporary obstack. We later
3169 copy this to the final obstack. */
3170 obstack_init (&temp_obstack);
3171 make_cleanup_obstack_free (&temp_obstack);
3172 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3173 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3175 /* Since the objects we're extracting from .debug_info vary in
3176 length, only the individual functions to extract them (like
3177 read_comp_unit_head and load_partial_die) can really know whether
3178 the buffer is large enough to hold another complete object.
3180 At the moment, they don't actually check that. If .debug_info
3181 holds just one extra byte after the last compilation unit's dies,
3182 then read_comp_unit_head will happily read off the end of the
3183 buffer. read_partial_die is similarly casual. Those functions
3186 For this loop condition, simply checking whether there's any data
3187 left at all should be sufficient. */
3189 while (info_ptr < (dwarf2_per_objfile->info.buffer
3190 + dwarf2_per_objfile->info.size))
3192 struct dwarf2_per_cu_data *this_cu;
3194 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
3197 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3198 dwarf2_per_objfile->info.buffer,
3200 dwarf2_per_objfile->info.size);
3203 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3204 &objfile->objfile_obstack);
3205 discard_cleanups (addrmap_cleanup);
3207 do_cleanups (back_to);
3210 /* Load the partial DIEs for a secondary CU into memory. */
3213 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3214 struct objfile *objfile)
3216 bfd *abfd = objfile->obfd;
3217 gdb_byte *info_ptr, *beg_of_comp_unit;
3218 struct die_info *comp_unit_die;
3219 struct dwarf2_cu *cu;
3220 struct cleanup *back_to;
3221 struct attribute *attr;
3223 struct die_reader_specs reader_specs;
3225 gdb_assert (! this_cu->from_debug_types);
3227 gdb_assert (dwarf2_per_objfile->info.readin);
3228 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3229 beg_of_comp_unit = info_ptr;
3231 cu = alloc_one_comp_unit (objfile);
3233 /* ??? Missing cleanup for CU? */
3235 /* Link this compilation unit into the compilation unit tree. */
3237 cu->per_cu = this_cu;
3238 cu->type_hash = this_cu->type_hash;
3240 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3241 dwarf2_per_objfile->info.buffer,
3242 dwarf2_per_objfile->info.size,
3245 /* Complete the cu_header. */
3246 cu->header.offset = this_cu->offset;
3247 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3249 /* Read the abbrevs for this compilation unit into a table. */
3250 dwarf2_read_abbrevs (abfd, cu);
3251 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
3253 /* Read the compilation unit die. */
3254 init_cu_die_reader (&reader_specs, cu);
3255 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3258 /* Set the language we're debugging. */
3259 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
3261 set_cu_language (DW_UNSND (attr), cu);
3263 set_cu_language (language_minimal, cu);
3265 /* Check if comp unit has_children.
3266 If so, read the rest of the partial symbols from this comp unit.
3267 If not, there's no more debug_info for this comp unit. */
3269 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3271 do_cleanups (back_to);
3274 /* Create a list of all compilation units in OBJFILE. We do this only
3275 if an inter-comp-unit reference is found; presumably if there is one,
3276 there will be many, and one will occur early in the .debug_info section.
3277 So there's no point in building this list incrementally. */
3280 create_all_comp_units (struct objfile *objfile)
3284 struct dwarf2_per_cu_data **all_comp_units;
3287 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3288 info_ptr = dwarf2_per_objfile->info.buffer;
3292 all_comp_units = xmalloc (n_allocated
3293 * sizeof (struct dwarf2_per_cu_data *));
3295 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
3297 unsigned int length, initial_length_size;
3298 struct dwarf2_per_cu_data *this_cu;
3299 unsigned int offset;
3301 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3303 /* Read just enough information to find out where the next
3304 compilation unit is. */
3305 length = read_initial_length (objfile->obfd, info_ptr,
3306 &initial_length_size);
3308 /* Save the compilation unit for later lookup. */
3309 this_cu = obstack_alloc (&objfile->objfile_obstack,
3310 sizeof (struct dwarf2_per_cu_data));
3311 memset (this_cu, 0, sizeof (*this_cu));
3312 this_cu->offset = offset;
3313 this_cu->length = length + initial_length_size;
3314 this_cu->objfile = objfile;
3316 if (n_comp_units == n_allocated)
3319 all_comp_units = xrealloc (all_comp_units,
3321 * sizeof (struct dwarf2_per_cu_data *));
3323 all_comp_units[n_comp_units++] = this_cu;
3325 info_ptr = info_ptr + this_cu->length;
3328 dwarf2_per_objfile->all_comp_units
3329 = obstack_alloc (&objfile->objfile_obstack,
3330 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3331 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3332 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3333 xfree (all_comp_units);
3334 dwarf2_per_objfile->n_comp_units = n_comp_units;
3337 /* Process all loaded DIEs for compilation unit CU, starting at
3338 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3339 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3340 DW_AT_ranges). If NEED_PC is set, then this function will set
3341 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3342 and record the covered ranges in the addrmap. */
3345 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3346 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3348 struct partial_die_info *pdi;
3350 /* Now, march along the PDI's, descending into ones which have
3351 interesting children but skipping the children of the other ones,
3352 until we reach the end of the compilation unit. */
3358 fixup_partial_die (pdi, cu);
3360 /* Anonymous namespaces or modules have no name but have interesting
3361 children, so we need to look at them. Ditto for anonymous
3364 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3365 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3369 case DW_TAG_subprogram:
3370 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3372 case DW_TAG_variable:
3373 case DW_TAG_typedef:
3374 case DW_TAG_union_type:
3375 if (!pdi->is_declaration)
3377 add_partial_symbol (pdi, cu);
3380 case DW_TAG_class_type:
3381 case DW_TAG_interface_type:
3382 case DW_TAG_structure_type:
3383 if (!pdi->is_declaration)
3385 add_partial_symbol (pdi, cu);
3388 case DW_TAG_enumeration_type:
3389 if (!pdi->is_declaration)
3390 add_partial_enumeration (pdi, cu);
3392 case DW_TAG_base_type:
3393 case DW_TAG_subrange_type:
3394 /* File scope base type definitions are added to the partial
3396 add_partial_symbol (pdi, cu);
3398 case DW_TAG_namespace:
3399 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3402 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3409 /* If the die has a sibling, skip to the sibling. */
3411 pdi = pdi->die_sibling;
3415 /* Functions used to compute the fully scoped name of a partial DIE.
3417 Normally, this is simple. For C++, the parent DIE's fully scoped
3418 name is concatenated with "::" and the partial DIE's name. For
3419 Java, the same thing occurs except that "." is used instead of "::".
3420 Enumerators are an exception; they use the scope of their parent
3421 enumeration type, i.e. the name of the enumeration type is not
3422 prepended to the enumerator.
3424 There are two complexities. One is DW_AT_specification; in this
3425 case "parent" means the parent of the target of the specification,
3426 instead of the direct parent of the DIE. The other is compilers
3427 which do not emit DW_TAG_namespace; in this case we try to guess
3428 the fully qualified name of structure types from their members'
3429 linkage names. This must be done using the DIE's children rather
3430 than the children of any DW_AT_specification target. We only need
3431 to do this for structures at the top level, i.e. if the target of
3432 any DW_AT_specification (if any; otherwise the DIE itself) does not
3435 /* Compute the scope prefix associated with PDI's parent, in
3436 compilation unit CU. The result will be allocated on CU's
3437 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3438 field. NULL is returned if no prefix is necessary. */
3440 partial_die_parent_scope (struct partial_die_info *pdi,
3441 struct dwarf2_cu *cu)
3443 char *grandparent_scope;
3444 struct partial_die_info *parent, *real_pdi;
3446 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3447 then this means the parent of the specification DIE. */
3450 while (real_pdi->has_specification)
3451 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3453 parent = real_pdi->die_parent;
3457 if (parent->scope_set)
3458 return parent->scope;
3460 fixup_partial_die (parent, cu);
3462 grandparent_scope = partial_die_parent_scope (parent, cu);
3464 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3465 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3466 Work around this problem here. */
3467 if (cu->language == language_cplus
3468 && parent->tag == DW_TAG_namespace
3469 && strcmp (parent->name, "::") == 0
3470 && grandparent_scope == NULL)
3472 parent->scope = NULL;
3473 parent->scope_set = 1;
3477 if (parent->tag == DW_TAG_namespace
3478 || parent->tag == DW_TAG_module
3479 || parent->tag == DW_TAG_structure_type
3480 || parent->tag == DW_TAG_class_type
3481 || parent->tag == DW_TAG_interface_type
3482 || parent->tag == DW_TAG_union_type
3483 || parent->tag == DW_TAG_enumeration_type)
3485 if (grandparent_scope == NULL)
3486 parent->scope = parent->name;
3488 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
3489 parent->name, 0, cu);
3491 else if (parent->tag == DW_TAG_enumerator)
3492 /* Enumerators should not get the name of the enumeration as a prefix. */
3493 parent->scope = grandparent_scope;
3496 /* FIXME drow/2004-04-01: What should we be doing with
3497 function-local names? For partial symbols, we should probably be
3499 complaint (&symfile_complaints,
3500 _("unhandled containing DIE tag %d for DIE at %d"),
3501 parent->tag, pdi->offset);
3502 parent->scope = grandparent_scope;
3505 parent->scope_set = 1;
3506 return parent->scope;
3509 /* Return the fully scoped name associated with PDI, from compilation unit
3510 CU. The result will be allocated with malloc. */
3512 partial_die_full_name (struct partial_die_info *pdi,
3513 struct dwarf2_cu *cu)
3517 parent_scope = partial_die_parent_scope (pdi, cu);
3518 if (parent_scope == NULL)
3521 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3525 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3527 struct objfile *objfile = cu->objfile;
3529 char *actual_name = NULL;
3530 const struct partial_symbol *psym = NULL;
3532 int built_actual_name = 0;
3534 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3536 actual_name = partial_die_full_name (pdi, cu);
3538 built_actual_name = 1;
3540 if (actual_name == NULL)
3541 actual_name = pdi->name;
3545 case DW_TAG_subprogram:
3546 if (pdi->is_external || cu->language == language_ada)
3548 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3549 of the global scope. But in Ada, we want to be able to access
3550 nested procedures globally. So all Ada subprograms are stored
3551 in the global scope. */
3552 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3553 mst_text, objfile); */
3554 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3556 VAR_DOMAIN, LOC_BLOCK,
3557 &objfile->global_psymbols,
3558 0, pdi->lowpc + baseaddr,
3559 cu->language, objfile);
3563 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3564 mst_file_text, objfile); */
3565 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3567 VAR_DOMAIN, LOC_BLOCK,
3568 &objfile->static_psymbols,
3569 0, pdi->lowpc + baseaddr,
3570 cu->language, objfile);
3573 case DW_TAG_variable:
3575 addr = decode_locdesc (pdi->locdesc, cu);
3579 && !dwarf2_per_objfile->has_section_at_zero)
3581 /* A global or static variable may also have been stripped
3582 out by the linker if unused, in which case its address
3583 will be nullified; do not add such variables into partial
3584 symbol table then. */
3586 else if (pdi->is_external)
3589 Don't enter into the minimal symbol tables as there is
3590 a minimal symbol table entry from the ELF symbols already.
3591 Enter into partial symbol table if it has a location
3592 descriptor or a type.
3593 If the location descriptor is missing, new_symbol will create
3594 a LOC_UNRESOLVED symbol, the address of the variable will then
3595 be determined from the minimal symbol table whenever the variable
3597 The address for the partial symbol table entry is not
3598 used by GDB, but it comes in handy for debugging partial symbol
3601 if (pdi->locdesc || pdi->has_type)
3602 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3604 VAR_DOMAIN, LOC_STATIC,
3605 &objfile->global_psymbols,
3607 cu->language, objfile);
3611 /* Static Variable. Skip symbols without location descriptors. */
3612 if (pdi->locdesc == NULL)
3614 if (built_actual_name)
3615 xfree (actual_name);
3618 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3619 mst_file_data, objfile); */
3620 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3622 VAR_DOMAIN, LOC_STATIC,
3623 &objfile->static_psymbols,
3625 cu->language, objfile);
3628 case DW_TAG_typedef:
3629 case DW_TAG_base_type:
3630 case DW_TAG_subrange_type:
3631 add_psymbol_to_list (actual_name, strlen (actual_name),
3633 VAR_DOMAIN, LOC_TYPEDEF,
3634 &objfile->static_psymbols,
3635 0, (CORE_ADDR) 0, cu->language, objfile);
3637 case DW_TAG_namespace:
3638 add_psymbol_to_list (actual_name, strlen (actual_name),
3640 VAR_DOMAIN, LOC_TYPEDEF,
3641 &objfile->global_psymbols,
3642 0, (CORE_ADDR) 0, cu->language, objfile);
3644 case DW_TAG_class_type:
3645 case DW_TAG_interface_type:
3646 case DW_TAG_structure_type:
3647 case DW_TAG_union_type:
3648 case DW_TAG_enumeration_type:
3649 /* Skip external references. The DWARF standard says in the section
3650 about "Structure, Union, and Class Type Entries": "An incomplete
3651 structure, union or class type is represented by a structure,
3652 union or class entry that does not have a byte size attribute
3653 and that has a DW_AT_declaration attribute." */
3654 if (!pdi->has_byte_size && pdi->is_declaration)
3656 if (built_actual_name)
3657 xfree (actual_name);
3661 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3662 static vs. global. */
3663 add_psymbol_to_list (actual_name, strlen (actual_name),
3665 STRUCT_DOMAIN, LOC_TYPEDEF,
3666 (cu->language == language_cplus
3667 || cu->language == language_java)
3668 ? &objfile->global_psymbols
3669 : &objfile->static_psymbols,
3670 0, (CORE_ADDR) 0, cu->language, objfile);
3673 case DW_TAG_enumerator:
3674 add_psymbol_to_list (actual_name, strlen (actual_name),
3676 VAR_DOMAIN, LOC_CONST,
3677 (cu->language == language_cplus
3678 || cu->language == language_java)
3679 ? &objfile->global_psymbols
3680 : &objfile->static_psymbols,
3681 0, (CORE_ADDR) 0, cu->language, objfile);
3687 if (built_actual_name)
3688 xfree (actual_name);
3691 /* Read a partial die corresponding to a namespace; also, add a symbol
3692 corresponding to that namespace to the symbol table. NAMESPACE is
3693 the name of the enclosing namespace. */
3696 add_partial_namespace (struct partial_die_info *pdi,
3697 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3698 int need_pc, struct dwarf2_cu *cu)
3700 /* Add a symbol for the namespace. */
3702 add_partial_symbol (pdi, cu);
3704 /* Now scan partial symbols in that namespace. */
3706 if (pdi->has_children)
3707 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3710 /* Read a partial die corresponding to a Fortran module. */
3713 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
3714 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3716 /* Now scan partial symbols in that module. */
3718 if (pdi->has_children)
3719 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3722 /* Read a partial die corresponding to a subprogram and create a partial
3723 symbol for that subprogram. When the CU language allows it, this
3724 routine also defines a partial symbol for each nested subprogram
3725 that this subprogram contains.
3727 DIE my also be a lexical block, in which case we simply search
3728 recursively for suprograms defined inside that lexical block.
3729 Again, this is only performed when the CU language allows this
3730 type of definitions. */
3733 add_partial_subprogram (struct partial_die_info *pdi,
3734 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3735 int need_pc, struct dwarf2_cu *cu)
3737 if (pdi->tag == DW_TAG_subprogram)
3739 if (pdi->has_pc_info)
3741 if (pdi->lowpc < *lowpc)
3742 *lowpc = pdi->lowpc;
3743 if (pdi->highpc > *highpc)
3744 *highpc = pdi->highpc;
3748 struct objfile *objfile = cu->objfile;
3750 baseaddr = ANOFFSET (objfile->section_offsets,
3751 SECT_OFF_TEXT (objfile));
3752 addrmap_set_empty (objfile->psymtabs_addrmap,
3753 pdi->lowpc + baseaddr,
3754 pdi->highpc - 1 + baseaddr,
3755 cu->per_cu->v.psymtab);
3757 if (!pdi->is_declaration)
3758 /* Ignore subprogram DIEs that do not have a name, they are
3759 illegal. Do not emit a complaint at this point, we will
3760 do so when we convert this psymtab into a symtab. */
3762 add_partial_symbol (pdi, cu);
3766 if (! pdi->has_children)
3769 if (cu->language == language_ada)
3771 pdi = pdi->die_child;
3774 fixup_partial_die (pdi, cu);
3775 if (pdi->tag == DW_TAG_subprogram
3776 || pdi->tag == DW_TAG_lexical_block)
3777 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3778 pdi = pdi->die_sibling;
3783 /* See if we can figure out if the class lives in a namespace. We do
3784 this by looking for a member function; its demangled name will
3785 contain namespace info, if there is any. */
3788 guess_structure_name (struct partial_die_info *struct_pdi,
3789 struct dwarf2_cu *cu)
3791 if ((cu->language == language_cplus
3792 || cu->language == language_java)
3793 && cu->has_namespace_info == 0
3794 && struct_pdi->has_children)
3796 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3797 what template types look like, because the demangler
3798 frequently doesn't give the same name as the debug info. We
3799 could fix this by only using the demangled name to get the
3800 prefix (but see comment in read_structure_type). */
3802 struct partial_die_info *real_pdi;
3804 /* If this DIE (this DIE's specification, if any) has a parent, then
3805 we should not do this. We'll prepend the parent's fully qualified
3806 name when we create the partial symbol. */
3808 real_pdi = struct_pdi;
3809 while (real_pdi->has_specification)
3810 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3812 if (real_pdi->die_parent != NULL)
3817 /* Read a partial die corresponding to an enumeration type. */
3820 add_partial_enumeration (struct partial_die_info *enum_pdi,
3821 struct dwarf2_cu *cu)
3823 struct partial_die_info *pdi;
3825 if (enum_pdi->name != NULL)
3826 add_partial_symbol (enum_pdi, cu);
3828 pdi = enum_pdi->die_child;
3831 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
3832 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
3834 add_partial_symbol (pdi, cu);
3835 pdi = pdi->die_sibling;
3839 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3840 Return the corresponding abbrev, or NULL if the number is zero (indicating
3841 an empty DIE). In either case *BYTES_READ will be set to the length of
3842 the initial number. */
3844 static struct abbrev_info *
3845 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
3846 struct dwarf2_cu *cu)
3848 bfd *abfd = cu->objfile->obfd;
3849 unsigned int abbrev_number;
3850 struct abbrev_info *abbrev;
3852 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
3854 if (abbrev_number == 0)
3857 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
3860 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
3861 bfd_get_filename (abfd));
3867 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3868 Returns a pointer to the end of a series of DIEs, terminated by an empty
3869 DIE. Any children of the skipped DIEs will also be skipped. */
3872 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
3874 struct abbrev_info *abbrev;
3875 unsigned int bytes_read;
3879 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
3881 return info_ptr + bytes_read;
3883 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
3887 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3888 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3889 abbrev corresponding to that skipped uleb128 should be passed in
3890 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3894 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
3895 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
3897 unsigned int bytes_read;
3898 struct attribute attr;
3899 bfd *abfd = cu->objfile->obfd;
3900 unsigned int form, i;
3902 for (i = 0; i < abbrev->num_attrs; i++)
3904 /* The only abbrev we care about is DW_AT_sibling. */
3905 if (abbrev->attrs[i].name == DW_AT_sibling)
3907 read_attribute (&attr, &abbrev->attrs[i],
3908 abfd, info_ptr, cu);
3909 if (attr.form == DW_FORM_ref_addr)
3910 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
3912 return buffer + dwarf2_get_ref_die_offset (&attr);
3915 /* If it isn't DW_AT_sibling, skip this attribute. */
3916 form = abbrev->attrs[i].form;
3920 case DW_FORM_ref_addr:
3921 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
3922 and later it is offset sized. */
3923 if (cu->header.version == 2)
3924 info_ptr += cu->header.addr_size;
3926 info_ptr += cu->header.offset_size;
3929 info_ptr += cu->header.addr_size;
3936 case DW_FORM_flag_present:
3951 case DW_FORM_string:
3952 read_direct_string (abfd, info_ptr, &bytes_read);
3953 info_ptr += bytes_read;
3955 case DW_FORM_sec_offset:
3957 info_ptr += cu->header.offset_size;
3959 case DW_FORM_exprloc:
3961 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3962 info_ptr += bytes_read;
3964 case DW_FORM_block1:
3965 info_ptr += 1 + read_1_byte (abfd, info_ptr);
3967 case DW_FORM_block2:
3968 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
3970 case DW_FORM_block4:
3971 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
3975 case DW_FORM_ref_udata:
3976 info_ptr = skip_leb128 (abfd, info_ptr);
3978 case DW_FORM_indirect:
3979 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3980 info_ptr += bytes_read;
3981 /* We need to continue parsing from here, so just go back to
3983 goto skip_attribute;
3986 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
3987 dwarf_form_name (form),
3988 bfd_get_filename (abfd));
3992 if (abbrev->has_children)
3993 return skip_children (buffer, info_ptr, cu);
3998 /* Locate ORIG_PDI's sibling.
3999 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4003 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4004 gdb_byte *buffer, gdb_byte *info_ptr,
4005 bfd *abfd, struct dwarf2_cu *cu)
4007 /* Do we know the sibling already? */
4009 if (orig_pdi->sibling)
4010 return orig_pdi->sibling;
4012 /* Are there any children to deal with? */
4014 if (!orig_pdi->has_children)
4017 /* Skip the children the long way. */
4019 return skip_children (buffer, info_ptr, cu);
4022 /* Expand this partial symbol table into a full symbol table. */
4025 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4031 warning (_("bug: psymtab for %s is already read in."), pst->filename);
4037 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
4038 gdb_flush (gdb_stdout);
4041 /* Restore our global data. */
4042 dwarf2_per_objfile = objfile_data (pst->objfile,
4043 dwarf2_objfile_data_key);
4045 /* If this psymtab is constructed from a debug-only objfile, the
4046 has_section_at_zero flag will not necessarily be correct. We
4047 can get the correct value for this flag by looking at the data
4048 associated with the (presumably stripped) associated objfile. */
4049 if (pst->objfile->separate_debug_objfile_backlink)
4051 struct dwarf2_per_objfile *dpo_backlink
4052 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4053 dwarf2_objfile_data_key);
4055 dwarf2_per_objfile->has_section_at_zero
4056 = dpo_backlink->has_section_at_zero;
4059 psymtab_to_symtab_1 (pst);
4061 /* Finish up the debug error message. */
4063 printf_filtered (_("done.\n"));
4068 /* Add PER_CU to the queue. */
4071 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4073 struct dwarf2_queue_item *item;
4076 item = xmalloc (sizeof (*item));
4077 item->per_cu = per_cu;
4080 if (dwarf2_queue == NULL)
4081 dwarf2_queue = item;
4083 dwarf2_queue_tail->next = item;
4085 dwarf2_queue_tail = item;
4088 /* Process the queue. */
4091 process_queue (struct objfile *objfile)
4093 struct dwarf2_queue_item *item, *next_item;
4095 /* The queue starts out with one item, but following a DIE reference
4096 may load a new CU, adding it to the end of the queue. */
4097 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4099 if (dwarf2_per_objfile->using_index
4100 ? !item->per_cu->v.quick->symtab
4101 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4102 process_full_comp_unit (item->per_cu);
4104 item->per_cu->queued = 0;
4105 next_item = item->next;
4109 dwarf2_queue_tail = NULL;
4112 /* Free all allocated queue entries. This function only releases anything if
4113 an error was thrown; if the queue was processed then it would have been
4114 freed as we went along. */
4117 dwarf2_release_queue (void *dummy)
4119 struct dwarf2_queue_item *item, *last;
4121 item = dwarf2_queue;
4124 /* Anything still marked queued is likely to be in an
4125 inconsistent state, so discard it. */
4126 if (item->per_cu->queued)
4128 if (item->per_cu->cu != NULL)
4129 free_one_cached_comp_unit (item->per_cu->cu);
4130 item->per_cu->queued = 0;
4138 dwarf2_queue = dwarf2_queue_tail = NULL;
4141 /* Read in full symbols for PST, and anything it depends on. */
4144 psymtab_to_symtab_1 (struct partial_symtab *pst)
4146 struct dwarf2_per_cu_data *per_cu;
4147 struct cleanup *back_to;
4150 for (i = 0; i < pst->number_of_dependencies; i++)
4151 if (!pst->dependencies[i]->readin)
4153 /* Inform about additional files that need to be read in. */
4156 /* FIXME: i18n: Need to make this a single string. */
4157 fputs_filtered (" ", gdb_stdout);
4159 fputs_filtered ("and ", gdb_stdout);
4161 printf_filtered ("%s...", pst->dependencies[i]->filename);
4162 wrap_here (""); /* Flush output */
4163 gdb_flush (gdb_stdout);
4165 psymtab_to_symtab_1 (pst->dependencies[i]);
4168 per_cu = pst->read_symtab_private;
4172 /* It's an include file, no symbols to read for it.
4173 Everything is in the parent symtab. */
4178 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4181 /* Load the DIEs associated with PER_CU into memory. */
4184 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4186 bfd *abfd = objfile->obfd;
4187 struct dwarf2_cu *cu;
4188 unsigned int offset;
4189 gdb_byte *info_ptr, *beg_of_comp_unit;
4190 struct cleanup *back_to, *free_cu_cleanup;
4191 struct attribute *attr;
4193 gdb_assert (! per_cu->from_debug_types);
4195 /* Set local variables from the partial symbol table info. */
4196 offset = per_cu->offset;
4198 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4199 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4200 beg_of_comp_unit = info_ptr;
4202 cu = alloc_one_comp_unit (objfile);
4204 /* If an error occurs while loading, release our storage. */
4205 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4207 /* Read in the comp_unit header. */
4208 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4210 /* Complete the cu_header. */
4211 cu->header.offset = offset;
4212 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4214 /* Read the abbrevs for this compilation unit. */
4215 dwarf2_read_abbrevs (abfd, cu);
4216 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
4218 /* Link this compilation unit into the compilation unit tree. */
4220 cu->per_cu = per_cu;
4221 cu->type_hash = per_cu->type_hash;
4223 cu->dies = read_comp_unit (info_ptr, cu);
4225 /* We try not to read any attributes in this function, because not
4226 all objfiles needed for references have been loaded yet, and symbol
4227 table processing isn't initialized. But we have to set the CU language,
4228 or we won't be able to build types correctly. */
4229 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
4231 set_cu_language (DW_UNSND (attr), cu);
4233 set_cu_language (language_minimal, cu);
4235 /* Similarly, if we do not read the producer, we can not apply
4236 producer-specific interpretation. */
4237 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4239 cu->producer = DW_STRING (attr);
4241 /* Link this CU into read_in_chain. */
4242 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4243 dwarf2_per_objfile->read_in_chain = per_cu;
4245 do_cleanups (back_to);
4247 /* We've successfully allocated this compilation unit. Let our caller
4248 clean it up when finished with it. */
4249 discard_cleanups (free_cu_cleanup);
4252 /* Generate full symbol information for PST and CU, whose DIEs have
4253 already been loaded into memory. */
4256 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4258 struct dwarf2_cu *cu = per_cu->cu;
4259 struct objfile *objfile = per_cu->objfile;
4260 CORE_ADDR lowpc, highpc;
4261 struct symtab *symtab;
4262 struct cleanup *back_to;
4265 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4268 back_to = make_cleanup (really_free_pendings, NULL);
4270 cu->list_in_scope = &file_symbols;
4272 dwarf2_find_base_address (cu->dies, cu);
4274 /* Do line number decoding in read_file_scope () */
4275 process_die (cu->dies, cu);
4277 /* Some compilers don't define a DW_AT_high_pc attribute for the
4278 compilation unit. If the DW_AT_high_pc is missing, synthesize
4279 it, by scanning the DIE's below the compilation unit. */
4280 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4282 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4284 /* Set symtab language to language from DW_AT_language.
4285 If the compilation is from a C file generated by language preprocessors,
4286 do not set the language if it was already deduced by start_subfile. */
4288 && !(cu->language == language_c && symtab->language != language_c))
4290 symtab->language = cu->language;
4293 if (dwarf2_per_objfile->using_index)
4294 per_cu->v.quick->symtab = symtab;
4297 struct partial_symtab *pst = per_cu->v.psymtab;
4298 pst->symtab = symtab;
4302 do_cleanups (back_to);
4305 /* Process a die and its children. */
4308 process_die (struct die_info *die, struct dwarf2_cu *cu)
4312 case DW_TAG_padding:
4314 case DW_TAG_compile_unit:
4315 read_file_scope (die, cu);
4317 case DW_TAG_type_unit:
4318 read_type_unit_scope (die, cu);
4320 case DW_TAG_subprogram:
4321 case DW_TAG_inlined_subroutine:
4322 read_func_scope (die, cu);
4324 case DW_TAG_lexical_block:
4325 case DW_TAG_try_block:
4326 case DW_TAG_catch_block:
4327 read_lexical_block_scope (die, cu);
4329 case DW_TAG_class_type:
4330 case DW_TAG_interface_type:
4331 case DW_TAG_structure_type:
4332 case DW_TAG_union_type:
4333 process_structure_scope (die, cu);
4335 case DW_TAG_enumeration_type:
4336 process_enumeration_scope (die, cu);
4339 /* These dies have a type, but processing them does not create
4340 a symbol or recurse to process the children. Therefore we can
4341 read them on-demand through read_type_die. */
4342 case DW_TAG_subroutine_type:
4343 case DW_TAG_set_type:
4344 case DW_TAG_array_type:
4345 case DW_TAG_pointer_type:
4346 case DW_TAG_ptr_to_member_type:
4347 case DW_TAG_reference_type:
4348 case DW_TAG_string_type:
4351 case DW_TAG_base_type:
4352 case DW_TAG_subrange_type:
4353 case DW_TAG_typedef:
4354 /* Add a typedef symbol for the type definition, if it has a
4356 new_symbol (die, read_type_die (die, cu), cu);
4358 case DW_TAG_common_block:
4359 read_common_block (die, cu);
4361 case DW_TAG_common_inclusion:
4363 case DW_TAG_namespace:
4364 processing_has_namespace_info = 1;
4365 read_namespace (die, cu);
4368 processing_has_namespace_info = 1;
4369 read_module (die, cu);
4371 case DW_TAG_imported_declaration:
4372 case DW_TAG_imported_module:
4373 processing_has_namespace_info = 1;
4374 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4375 || cu->language != language_fortran))
4376 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4377 dwarf_tag_name (die->tag));
4378 read_import_statement (die, cu);
4381 new_symbol (die, NULL, cu);
4386 /* A helper function for dwarf2_compute_name which determines whether DIE
4387 needs to have the name of the scope prepended to the name listed in the
4391 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4393 struct attribute *attr;
4397 case DW_TAG_namespace:
4398 case DW_TAG_typedef:
4399 case DW_TAG_class_type:
4400 case DW_TAG_interface_type:
4401 case DW_TAG_structure_type:
4402 case DW_TAG_union_type:
4403 case DW_TAG_enumeration_type:
4404 case DW_TAG_enumerator:
4405 case DW_TAG_subprogram:
4409 case DW_TAG_variable:
4410 /* We only need to prefix "globally" visible variables. These include
4411 any variable marked with DW_AT_external or any variable that
4412 lives in a namespace. [Variables in anonymous namespaces
4413 require prefixing, but they are not DW_AT_external.] */
4415 if (dwarf2_attr (die, DW_AT_specification, cu))
4417 struct dwarf2_cu *spec_cu = cu;
4419 return die_needs_namespace (die_specification (die, &spec_cu),
4423 attr = dwarf2_attr (die, DW_AT_external, cu);
4424 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4425 && die->parent->tag != DW_TAG_module)
4427 /* A variable in a lexical block of some kind does not need a
4428 namespace, even though in C++ such variables may be external
4429 and have a mangled name. */
4430 if (die->parent->tag == DW_TAG_lexical_block
4431 || die->parent->tag == DW_TAG_try_block
4432 || die->parent->tag == DW_TAG_catch_block
4433 || die->parent->tag == DW_TAG_subprogram)
4442 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4443 compute the physname for the object, which include a method's
4444 formal parameters (C++/Java) and return type (Java).
4446 For Ada, return the DIE's linkage name rather than the fully qualified
4447 name. PHYSNAME is ignored..
4449 The result is allocated on the objfile_obstack and canonicalized. */
4452 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4456 name = dwarf2_name (die, cu);
4458 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4459 compute it by typename_concat inside GDB. */
4460 if (cu->language == language_ada
4461 || (cu->language == language_fortran && physname))
4463 /* For Ada unit, we prefer the linkage name over the name, as
4464 the former contains the exported name, which the user expects
4465 to be able to reference. Ideally, we want the user to be able
4466 to reference this entity using either natural or linkage name,
4467 but we haven't started looking at this enhancement yet. */
4468 struct attribute *attr;
4470 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4472 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4473 if (attr && DW_STRING (attr))
4474 return DW_STRING (attr);
4477 /* These are the only languages we know how to qualify names in. */
4479 && (cu->language == language_cplus || cu->language == language_java
4480 || cu->language == language_fortran))
4482 if (die_needs_namespace (die, cu))
4486 struct ui_file *buf;
4488 prefix = determine_prefix (die, cu);
4489 buf = mem_fileopen ();
4490 if (*prefix != '\0')
4492 char *prefixed_name = typename_concat (NULL, prefix, name,
4495 fputs_unfiltered (prefixed_name, buf);
4496 xfree (prefixed_name);
4499 fputs_unfiltered (name ? name : "", buf);
4501 /* For Java and C++ methods, append formal parameter type
4502 information, if PHYSNAME. */
4504 if (physname && die->tag == DW_TAG_subprogram
4505 && (cu->language == language_cplus
4506 || cu->language == language_java))
4508 struct type *type = read_type_die (die, cu);
4510 c_type_print_args (type, buf, 0, cu->language);
4512 if (cu->language == language_java)
4514 /* For java, we must append the return type to method
4516 if (die->tag == DW_TAG_subprogram)
4517 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
4520 else if (cu->language == language_cplus)
4522 if (TYPE_NFIELDS (type) > 0
4523 && TYPE_FIELD_ARTIFICIAL (type, 0)
4524 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
4525 fputs_unfiltered (" const", buf);
4529 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
4531 ui_file_delete (buf);
4533 if (cu->language == language_cplus)
4536 = dwarf2_canonicalize_name (name, cu,
4537 &cu->objfile->objfile_obstack);
4548 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4549 If scope qualifiers are appropriate they will be added. The result
4550 will be allocated on the objfile_obstack, or NULL if the DIE does
4551 not have a name. NAME may either be from a previous call to
4552 dwarf2_name or NULL.
4554 The output string will be canonicalized (if C++/Java). */
4557 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
4559 return dwarf2_compute_name (name, die, cu, 0);
4562 /* Construct a physname for the given DIE in CU. NAME may either be
4563 from a previous call to dwarf2_name or NULL. The result will be
4564 allocated on the objfile_objstack or NULL if the DIE does not have a
4567 The output string will be canonicalized (if C++/Java). */
4570 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
4572 return dwarf2_compute_name (name, die, cu, 1);
4575 /* Read the import statement specified by the given die and record it. */
4578 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
4580 struct attribute *import_attr;
4581 struct die_info *imported_die;
4582 struct dwarf2_cu *imported_cu;
4583 const char *imported_name;
4584 const char *imported_name_prefix;
4585 const char *canonical_name;
4586 const char *import_alias;
4587 const char *imported_declaration = NULL;
4588 const char *import_prefix;
4592 import_attr = dwarf2_attr (die, DW_AT_import, cu);
4593 if (import_attr == NULL)
4595 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
4596 dwarf_tag_name (die->tag));
4601 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
4602 imported_name = dwarf2_name (imported_die, imported_cu);
4603 if (imported_name == NULL)
4605 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4607 The import in the following code:
4621 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4622 <52> DW_AT_decl_file : 1
4623 <53> DW_AT_decl_line : 6
4624 <54> DW_AT_import : <0x75>
4625 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4627 <5b> DW_AT_decl_file : 1
4628 <5c> DW_AT_decl_line : 2
4629 <5d> DW_AT_type : <0x6e>
4631 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4632 <76> DW_AT_byte_size : 4
4633 <77> DW_AT_encoding : 5 (signed)
4635 imports the wrong die ( 0x75 instead of 0x58 ).
4636 This case will be ignored until the gcc bug is fixed. */
4640 /* Figure out the local name after import. */
4641 import_alias = dwarf2_name (die, cu);
4643 /* Figure out where the statement is being imported to. */
4644 import_prefix = determine_prefix (die, cu);
4646 /* Figure out what the scope of the imported die is and prepend it
4647 to the name of the imported die. */
4648 imported_name_prefix = determine_prefix (imported_die, imported_cu);
4650 if (imported_die->tag != DW_TAG_namespace
4651 && imported_die->tag != DW_TAG_module)
4653 imported_declaration = imported_name;
4654 canonical_name = imported_name_prefix;
4656 else if (strlen (imported_name_prefix) > 0)
4658 temp = alloca (strlen (imported_name_prefix)
4659 + 2 + strlen (imported_name) + 1);
4660 strcpy (temp, imported_name_prefix);
4661 strcat (temp, "::");
4662 strcat (temp, imported_name);
4663 canonical_name = temp;
4666 canonical_name = imported_name;
4668 cp_add_using_directive (import_prefix,
4671 imported_declaration,
4672 &cu->objfile->objfile_obstack);
4676 initialize_cu_func_list (struct dwarf2_cu *cu)
4678 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
4682 free_cu_line_header (void *arg)
4684 struct dwarf2_cu *cu = arg;
4686 free_line_header (cu->line_header);
4687 cu->line_header = NULL;
4691 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
4692 char **name, char **comp_dir)
4694 struct attribute *attr;
4699 /* Find the filename. Do not use dwarf2_name here, since the filename
4700 is not a source language identifier. */
4701 attr = dwarf2_attr (die, DW_AT_name, cu);
4704 *name = DW_STRING (attr);
4707 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
4709 *comp_dir = DW_STRING (attr);
4710 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
4712 *comp_dir = ldirname (*name);
4713 if (*comp_dir != NULL)
4714 make_cleanup (xfree, *comp_dir);
4716 if (*comp_dir != NULL)
4718 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4719 directory, get rid of it. */
4720 char *cp = strchr (*comp_dir, ':');
4722 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
4727 *name = "<unknown>";
4731 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
4733 struct objfile *objfile = cu->objfile;
4734 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4735 CORE_ADDR lowpc = ((CORE_ADDR) -1);
4736 CORE_ADDR highpc = ((CORE_ADDR) 0);
4737 struct attribute *attr;
4739 char *comp_dir = NULL;
4740 struct die_info *child_die;
4741 bfd *abfd = objfile->obfd;
4742 struct line_header *line_header = 0;
4745 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4747 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
4749 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4750 from finish_block. */
4751 if (lowpc == ((CORE_ADDR) -1))
4756 find_file_and_directory (die, cu, &name, &comp_dir);
4758 attr = dwarf2_attr (die, DW_AT_language, cu);
4761 set_cu_language (DW_UNSND (attr), cu);
4764 attr = dwarf2_attr (die, DW_AT_producer, cu);
4766 cu->producer = DW_STRING (attr);
4768 /* We assume that we're processing GCC output. */
4769 processing_gcc_compilation = 2;
4771 processing_has_namespace_info = 0;
4773 start_symtab (name, comp_dir, lowpc);
4774 record_debugformat ("DWARF 2");
4775 record_producer (cu->producer);
4777 initialize_cu_func_list (cu);
4779 /* Decode line number information if present. We do this before
4780 processing child DIEs, so that the line header table is available
4781 for DW_AT_decl_file. */
4782 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
4785 unsigned int line_offset = DW_UNSND (attr);
4786 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
4789 cu->line_header = line_header;
4790 make_cleanup (free_cu_line_header, cu);
4791 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
4795 /* Process all dies in compilation unit. */
4796 if (die->child != NULL)
4798 child_die = die->child;
4799 while (child_die && child_die->tag)
4801 process_die (child_die, cu);
4802 child_die = sibling_die (child_die);
4806 /* Decode macro information, if present. Dwarf 2 macro information
4807 refers to information in the line number info statement program
4808 header, so we can only read it if we've read the header
4810 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
4811 if (attr && line_header)
4813 unsigned int macro_offset = DW_UNSND (attr);
4815 dwarf_decode_macros (line_header, macro_offset,
4816 comp_dir, abfd, cu);
4818 do_cleanups (back_to);
4821 /* For TUs we want to skip the first top level sibling if it's not the
4822 actual type being defined by this TU. In this case the first top
4823 level sibling is there to provide context only. */
4826 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
4828 struct objfile *objfile = cu->objfile;
4829 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4831 struct attribute *attr;
4833 char *comp_dir = NULL;
4834 struct die_info *child_die;
4835 bfd *abfd = objfile->obfd;
4837 /* start_symtab needs a low pc, but we don't really have one.
4838 Do what read_file_scope would do in the absence of such info. */
4839 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4841 /* Find the filename. Do not use dwarf2_name here, since the filename
4842 is not a source language identifier. */
4843 attr = dwarf2_attr (die, DW_AT_name, cu);
4845 name = DW_STRING (attr);
4847 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
4849 comp_dir = DW_STRING (attr);
4850 else if (name != NULL && IS_ABSOLUTE_PATH (name))
4852 comp_dir = ldirname (name);
4853 if (comp_dir != NULL)
4854 make_cleanup (xfree, comp_dir);
4860 attr = dwarf2_attr (die, DW_AT_language, cu);
4862 set_cu_language (DW_UNSND (attr), cu);
4864 /* This isn't technically needed today. It is done for symmetry
4865 with read_file_scope. */
4866 attr = dwarf2_attr (die, DW_AT_producer, cu);
4868 cu->producer = DW_STRING (attr);
4870 /* We assume that we're processing GCC output. */
4871 processing_gcc_compilation = 2;
4873 processing_has_namespace_info = 0;
4875 start_symtab (name, comp_dir, lowpc);
4876 record_debugformat ("DWARF 2");
4877 record_producer (cu->producer);
4879 /* Process the dies in the type unit. */
4880 if (die->child == NULL)
4882 dump_die_for_error (die);
4883 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
4884 bfd_get_filename (abfd));
4887 child_die = die->child;
4889 while (child_die && child_die->tag)
4891 process_die (child_die, cu);
4893 child_die = sibling_die (child_die);
4896 do_cleanups (back_to);
4900 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
4901 struct dwarf2_cu *cu)
4903 struct function_range *thisfn;
4905 thisfn = (struct function_range *)
4906 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
4907 thisfn->name = name;
4908 thisfn->lowpc = lowpc;
4909 thisfn->highpc = highpc;
4910 thisfn->seen_line = 0;
4911 thisfn->next = NULL;
4913 if (cu->last_fn == NULL)
4914 cu->first_fn = thisfn;
4916 cu->last_fn->next = thisfn;
4918 cu->last_fn = thisfn;
4921 /* qsort helper for inherit_abstract_dies. */
4924 unsigned_int_compar (const void *ap, const void *bp)
4926 unsigned int a = *(unsigned int *) ap;
4927 unsigned int b = *(unsigned int *) bp;
4929 return (a > b) - (b > a);
4932 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
4933 Inherit only the children of the DW_AT_abstract_origin DIE not being already
4934 referenced by DW_AT_abstract_origin from the children of the current DIE. */
4937 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
4939 struct die_info *child_die;
4940 unsigned die_children_count;
4941 /* CU offsets which were referenced by children of the current DIE. */
4943 unsigned *offsets_end, *offsetp;
4944 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
4945 struct die_info *origin_die;
4946 /* Iterator of the ORIGIN_DIE children. */
4947 struct die_info *origin_child_die;
4948 struct cleanup *cleanups;
4949 struct attribute *attr;
4951 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
4955 origin_die = follow_die_ref (die, attr, &cu);
4956 if (die->tag != origin_die->tag
4957 && !(die->tag == DW_TAG_inlined_subroutine
4958 && origin_die->tag == DW_TAG_subprogram))
4959 complaint (&symfile_complaints,
4960 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
4961 die->offset, origin_die->offset);
4963 child_die = die->child;
4964 die_children_count = 0;
4965 while (child_die && child_die->tag)
4967 child_die = sibling_die (child_die);
4968 die_children_count++;
4970 offsets = xmalloc (sizeof (*offsets) * die_children_count);
4971 cleanups = make_cleanup (xfree, offsets);
4973 offsets_end = offsets;
4974 child_die = die->child;
4975 while (child_die && child_die->tag)
4977 /* For each CHILD_DIE, find the corresponding child of
4978 ORIGIN_DIE. If there is more than one layer of
4979 DW_AT_abstract_origin, follow them all; there shouldn't be,
4980 but GCC versions at least through 4.4 generate this (GCC PR
4982 struct die_info *child_origin_die = child_die;
4986 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
4989 child_origin_die = follow_die_ref (child_origin_die, attr, &cu);
4992 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
4993 counterpart may exist. */
4994 if (child_origin_die != child_die)
4996 if (child_die->tag != child_origin_die->tag
4997 && !(child_die->tag == DW_TAG_inlined_subroutine
4998 && child_origin_die->tag == DW_TAG_subprogram))
4999 complaint (&symfile_complaints,
5000 _("Child DIE 0x%x and its abstract origin 0x%x have "
5001 "different tags"), child_die->offset,
5002 child_origin_die->offset);
5003 if (child_origin_die->parent != origin_die)
5004 complaint (&symfile_complaints,
5005 _("Child DIE 0x%x and its abstract origin 0x%x have "
5006 "different parents"), child_die->offset,
5007 child_origin_die->offset);
5009 *offsets_end++ = child_origin_die->offset;
5011 child_die = sibling_die (child_die);
5013 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5014 unsigned_int_compar);
5015 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5016 if (offsetp[-1] == *offsetp)
5017 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
5018 "to DIE 0x%x as their abstract origin"),
5019 die->offset, *offsetp);
5022 origin_child_die = origin_die->child;
5023 while (origin_child_die && origin_child_die->tag)
5025 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5026 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5028 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5030 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5031 process_die (origin_child_die, cu);
5033 origin_child_die = sibling_die (origin_child_die);
5036 do_cleanups (cleanups);
5040 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5042 struct objfile *objfile = cu->objfile;
5043 struct context_stack *new;
5046 struct die_info *child_die;
5047 struct attribute *attr, *call_line, *call_file;
5050 struct block *block;
5051 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5055 /* If we do not have call site information, we can't show the
5056 caller of this inlined function. That's too confusing, so
5057 only use the scope for local variables. */
5058 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5059 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5060 if (call_line == NULL || call_file == NULL)
5062 read_lexical_block_scope (die, cu);
5067 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5069 name = dwarf2_name (die, cu);
5071 /* Ignore functions with missing or empty names. These are actually
5072 illegal according to the DWARF standard. */
5075 complaint (&symfile_complaints,
5076 _("missing name for subprogram DIE at %d"), die->offset);
5080 /* Ignore functions with missing or invalid low and high pc attributes. */
5081 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5083 attr = dwarf2_attr (die, DW_AT_external, cu);
5084 if (!attr || !DW_UNSND (attr))
5085 complaint (&symfile_complaints,
5086 _("cannot get low and high bounds for subprogram DIE at %d"),
5094 /* Record the function range for dwarf_decode_lines. */
5095 add_to_cu_func_list (name, lowpc, highpc, cu);
5097 new = push_context (0, lowpc);
5098 new->name = new_symbol (die, read_type_die (die, cu), cu);
5100 /* If there is a location expression for DW_AT_frame_base, record
5102 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5104 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5105 expression is being recorded directly in the function's symbol
5106 and not in a separate frame-base object. I guess this hack is
5107 to avoid adding some sort of frame-base adjunct/annex to the
5108 function's symbol :-(. The problem with doing this is that it
5109 results in a function symbol with a location expression that
5110 has nothing to do with the location of the function, ouch! The
5111 relationship should be: a function's symbol has-a frame base; a
5112 frame-base has-a location expression. */
5113 dwarf2_symbol_mark_computed (attr, new->name, cu);
5115 cu->list_in_scope = &local_symbols;
5117 if (die->child != NULL)
5119 child_die = die->child;
5120 while (child_die && child_die->tag)
5122 process_die (child_die, cu);
5123 child_die = sibling_die (child_die);
5127 inherit_abstract_dies (die, cu);
5129 /* If we have a DW_AT_specification, we might need to import using
5130 directives from the context of the specification DIE. See the
5131 comment in determine_prefix. */
5132 if (cu->language == language_cplus
5133 && dwarf2_attr (die, DW_AT_specification, cu))
5135 struct dwarf2_cu *spec_cu = cu;
5136 struct die_info *spec_die = die_specification (die, &spec_cu);
5140 child_die = spec_die->child;
5141 while (child_die && child_die->tag)
5143 if (child_die->tag == DW_TAG_imported_module)
5144 process_die (child_die, spec_cu);
5145 child_die = sibling_die (child_die);
5148 /* In some cases, GCC generates specification DIEs that
5149 themselves contain DW_AT_specification attributes. */
5150 spec_die = die_specification (spec_die, &spec_cu);
5154 new = pop_context ();
5155 /* Make a block for the local symbols within. */
5156 block = finish_block (new->name, &local_symbols, new->old_blocks,
5157 lowpc, highpc, objfile);
5159 /* For C++, set the block's scope. */
5160 if (cu->language == language_cplus || cu->language == language_fortran)
5161 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5162 determine_prefix (die, cu),
5163 processing_has_namespace_info);
5165 /* If we have address ranges, record them. */
5166 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5168 /* In C++, we can have functions nested inside functions (e.g., when
5169 a function declares a class that has methods). This means that
5170 when we finish processing a function scope, we may need to go
5171 back to building a containing block's symbol lists. */
5172 local_symbols = new->locals;
5173 param_symbols = new->params;
5174 using_directives = new->using_directives;
5176 /* If we've finished processing a top-level function, subsequent
5177 symbols go in the file symbol list. */
5178 if (outermost_context_p ())
5179 cu->list_in_scope = &file_symbols;
5182 /* Process all the DIES contained within a lexical block scope. Start
5183 a new scope, process the dies, and then close the scope. */
5186 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5188 struct objfile *objfile = cu->objfile;
5189 struct context_stack *new;
5190 CORE_ADDR lowpc, highpc;
5191 struct die_info *child_die;
5194 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5196 /* Ignore blocks with missing or invalid low and high pc attributes. */
5197 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5198 as multiple lexical blocks? Handling children in a sane way would
5199 be nasty. Might be easier to properly extend generic blocks to
5201 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5206 push_context (0, lowpc);
5207 if (die->child != NULL)
5209 child_die = die->child;
5210 while (child_die && child_die->tag)
5212 process_die (child_die, cu);
5213 child_die = sibling_die (child_die);
5216 new = pop_context ();
5218 if (local_symbols != NULL || using_directives != NULL)
5221 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5224 /* Note that recording ranges after traversing children, as we
5225 do here, means that recording a parent's ranges entails
5226 walking across all its children's ranges as they appear in
5227 the address map, which is quadratic behavior.
5229 It would be nicer to record the parent's ranges before
5230 traversing its children, simply overriding whatever you find
5231 there. But since we don't even decide whether to create a
5232 block until after we've traversed its children, that's hard
5234 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5236 local_symbols = new->locals;
5237 using_directives = new->using_directives;
5240 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5241 Return 1 if the attributes are present and valid, otherwise, return 0.
5242 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5245 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5246 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5247 struct partial_symtab *ranges_pst)
5249 struct objfile *objfile = cu->objfile;
5250 struct comp_unit_head *cu_header = &cu->header;
5251 bfd *obfd = objfile->obfd;
5252 unsigned int addr_size = cu_header->addr_size;
5253 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5254 /* Base address selection entry. */
5265 found_base = cu->base_known;
5266 base = cu->base_address;
5268 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5269 if (offset >= dwarf2_per_objfile->ranges.size)
5271 complaint (&symfile_complaints,
5272 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5276 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5278 /* Read in the largest possible address. */
5279 marker = read_address (obfd, buffer, cu, &dummy);
5280 if ((marker & mask) == mask)
5282 /* If we found the largest possible address, then
5283 read the base address. */
5284 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5285 buffer += 2 * addr_size;
5286 offset += 2 * addr_size;
5292 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5296 CORE_ADDR range_beginning, range_end;
5298 range_beginning = read_address (obfd, buffer, cu, &dummy);
5299 buffer += addr_size;
5300 range_end = read_address (obfd, buffer, cu, &dummy);
5301 buffer += addr_size;
5302 offset += 2 * addr_size;
5304 /* An end of list marker is a pair of zero addresses. */
5305 if (range_beginning == 0 && range_end == 0)
5306 /* Found the end of list entry. */
5309 /* Each base address selection entry is a pair of 2 values.
5310 The first is the largest possible address, the second is
5311 the base address. Check for a base address here. */
5312 if ((range_beginning & mask) == mask)
5314 /* If we found the largest possible address, then
5315 read the base address. */
5316 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5323 /* We have no valid base address for the ranges
5325 complaint (&symfile_complaints,
5326 _("Invalid .debug_ranges data (no base address)"));
5330 range_beginning += base;
5333 if (ranges_pst != NULL && range_beginning < range_end)
5334 addrmap_set_empty (objfile->psymtabs_addrmap,
5335 range_beginning + baseaddr, range_end - 1 + baseaddr,
5338 /* FIXME: This is recording everything as a low-high
5339 segment of consecutive addresses. We should have a
5340 data structure for discontiguous block ranges
5344 low = range_beginning;
5350 if (range_beginning < low)
5351 low = range_beginning;
5352 if (range_end > high)
5358 /* If the first entry is an end-of-list marker, the range
5359 describes an empty scope, i.e. no instructions. */
5365 *high_return = high;
5369 /* Get low and high pc attributes from a die. Return 1 if the attributes
5370 are present and valid, otherwise, return 0. Return -1 if the range is
5371 discontinuous, i.e. derived from DW_AT_ranges information. */
5373 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5374 CORE_ADDR *highpc, struct dwarf2_cu *cu,
5375 struct partial_symtab *pst)
5377 struct attribute *attr;
5382 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5385 high = DW_ADDR (attr);
5386 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5388 low = DW_ADDR (attr);
5390 /* Found high w/o low attribute. */
5393 /* Found consecutive range of addresses. */
5398 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5401 /* Value of the DW_AT_ranges attribute is the offset in the
5402 .debug_ranges section. */
5403 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
5405 /* Found discontinuous range of addresses. */
5413 /* When using the GNU linker, .gnu.linkonce. sections are used to
5414 eliminate duplicate copies of functions and vtables and such.
5415 The linker will arbitrarily choose one and discard the others.
5416 The AT_*_pc values for such functions refer to local labels in
5417 these sections. If the section from that file was discarded, the
5418 labels are not in the output, so the relocs get a value of 0.
5419 If this is a discarded function, mark the pc bounds as invalid,
5420 so that GDB will ignore it. */
5421 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
5429 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5430 its low and high PC addresses. Do nothing if these addresses could not
5431 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5432 and HIGHPC to the high address if greater than HIGHPC. */
5435 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
5436 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5437 struct dwarf2_cu *cu)
5439 CORE_ADDR low, high;
5440 struct die_info *child = die->child;
5442 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
5444 *lowpc = min (*lowpc, low);
5445 *highpc = max (*highpc, high);
5448 /* If the language does not allow nested subprograms (either inside
5449 subprograms or lexical blocks), we're done. */
5450 if (cu->language != language_ada)
5453 /* Check all the children of the given DIE. If it contains nested
5454 subprograms, then check their pc bounds. Likewise, we need to
5455 check lexical blocks as well, as they may also contain subprogram
5457 while (child && child->tag)
5459 if (child->tag == DW_TAG_subprogram
5460 || child->tag == DW_TAG_lexical_block)
5461 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
5462 child = sibling_die (child);
5466 /* Get the low and high pc's represented by the scope DIE, and store
5467 them in *LOWPC and *HIGHPC. If the correct values can't be
5468 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5471 get_scope_pc_bounds (struct die_info *die,
5472 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5473 struct dwarf2_cu *cu)
5475 CORE_ADDR best_low = (CORE_ADDR) -1;
5476 CORE_ADDR best_high = (CORE_ADDR) 0;
5477 CORE_ADDR current_low, current_high;
5479 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
5481 best_low = current_low;
5482 best_high = current_high;
5486 struct die_info *child = die->child;
5488 while (child && child->tag)
5490 switch (child->tag) {
5491 case DW_TAG_subprogram:
5492 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
5494 case DW_TAG_namespace:
5496 /* FIXME: carlton/2004-01-16: Should we do this for
5497 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5498 that current GCC's always emit the DIEs corresponding
5499 to definitions of methods of classes as children of a
5500 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5501 the DIEs giving the declarations, which could be
5502 anywhere). But I don't see any reason why the
5503 standards says that they have to be there. */
5504 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
5506 if (current_low != ((CORE_ADDR) -1))
5508 best_low = min (best_low, current_low);
5509 best_high = max (best_high, current_high);
5517 child = sibling_die (child);
5522 *highpc = best_high;
5525 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5528 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
5529 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
5531 struct attribute *attr;
5533 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5536 CORE_ADDR high = DW_ADDR (attr);
5538 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5541 CORE_ADDR low = DW_ADDR (attr);
5543 record_block_range (block, baseaddr + low, baseaddr + high - 1);
5547 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5550 bfd *obfd = cu->objfile->obfd;
5552 /* The value of the DW_AT_ranges attribute is the offset of the
5553 address range list in the .debug_ranges section. */
5554 unsigned long offset = DW_UNSND (attr);
5555 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
5557 /* For some target architectures, but not others, the
5558 read_address function sign-extends the addresses it returns.
5559 To recognize base address selection entries, we need a
5561 unsigned int addr_size = cu->header.addr_size;
5562 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5564 /* The base address, to which the next pair is relative. Note
5565 that this 'base' is a DWARF concept: most entries in a range
5566 list are relative, to reduce the number of relocs against the
5567 debugging information. This is separate from this function's
5568 'baseaddr' argument, which GDB uses to relocate debugging
5569 information from a shared library based on the address at
5570 which the library was loaded. */
5571 CORE_ADDR base = cu->base_address;
5572 int base_known = cu->base_known;
5574 gdb_assert (dwarf2_per_objfile->ranges.readin);
5575 if (offset >= dwarf2_per_objfile->ranges.size)
5577 complaint (&symfile_complaints,
5578 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5585 unsigned int bytes_read;
5586 CORE_ADDR start, end;
5588 start = read_address (obfd, buffer, cu, &bytes_read);
5589 buffer += bytes_read;
5590 end = read_address (obfd, buffer, cu, &bytes_read);
5591 buffer += bytes_read;
5593 /* Did we find the end of the range list? */
5594 if (start == 0 && end == 0)
5597 /* Did we find a base address selection entry? */
5598 else if ((start & base_select_mask) == base_select_mask)
5604 /* We found an ordinary address range. */
5609 complaint (&symfile_complaints,
5610 _("Invalid .debug_ranges data (no base address)"));
5614 record_block_range (block,
5615 baseaddr + base + start,
5616 baseaddr + base + end - 1);
5622 /* Add an aggregate field to the field list. */
5625 dwarf2_add_field (struct field_info *fip, struct die_info *die,
5626 struct dwarf2_cu *cu)
5628 struct objfile *objfile = cu->objfile;
5629 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5630 struct nextfield *new_field;
5631 struct attribute *attr;
5633 char *fieldname = "";
5635 /* Allocate a new field list entry and link it in. */
5636 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
5637 make_cleanup (xfree, new_field);
5638 memset (new_field, 0, sizeof (struct nextfield));
5640 if (die->tag == DW_TAG_inheritance)
5642 new_field->next = fip->baseclasses;
5643 fip->baseclasses = new_field;
5647 new_field->next = fip->fields;
5648 fip->fields = new_field;
5652 /* Handle accessibility and virtuality of field.
5653 The default accessibility for members is public, the default
5654 accessibility for inheritance is private. */
5655 if (die->tag != DW_TAG_inheritance)
5656 new_field->accessibility = DW_ACCESS_public;
5658 new_field->accessibility = DW_ACCESS_private;
5659 new_field->virtuality = DW_VIRTUALITY_none;
5661 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
5663 new_field->accessibility = DW_UNSND (attr);
5664 if (new_field->accessibility != DW_ACCESS_public)
5665 fip->non_public_fields = 1;
5666 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
5668 new_field->virtuality = DW_UNSND (attr);
5670 fp = &new_field->field;
5672 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
5674 /* Data member other than a C++ static data member. */
5676 /* Get type of field. */
5677 fp->type = die_type (die, cu);
5679 SET_FIELD_BITPOS (*fp, 0);
5681 /* Get bit size of field (zero if none). */
5682 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
5685 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
5689 FIELD_BITSIZE (*fp) = 0;
5692 /* Get bit offset of field. */
5693 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
5696 int byte_offset = 0;
5698 if (attr_form_is_section_offset (attr))
5699 dwarf2_complex_location_expr_complaint ();
5700 else if (attr_form_is_constant (attr))
5701 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5702 else if (attr_form_is_block (attr))
5703 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5705 dwarf2_complex_location_expr_complaint ();
5707 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
5709 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
5712 if (gdbarch_bits_big_endian (gdbarch))
5714 /* For big endian bits, the DW_AT_bit_offset gives the
5715 additional bit offset from the MSB of the containing
5716 anonymous object to the MSB of the field. We don't
5717 have to do anything special since we don't need to
5718 know the size of the anonymous object. */
5719 FIELD_BITPOS (*fp) += DW_UNSND (attr);
5723 /* For little endian bits, compute the bit offset to the
5724 MSB of the anonymous object, subtract off the number of
5725 bits from the MSB of the field to the MSB of the
5726 object, and then subtract off the number of bits of
5727 the field itself. The result is the bit offset of
5728 the LSB of the field. */
5730 int bit_offset = DW_UNSND (attr);
5732 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5735 /* The size of the anonymous object containing
5736 the bit field is explicit, so use the
5737 indicated size (in bytes). */
5738 anonymous_size = DW_UNSND (attr);
5742 /* The size of the anonymous object containing
5743 the bit field must be inferred from the type
5744 attribute of the data member containing the
5746 anonymous_size = TYPE_LENGTH (fp->type);
5748 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
5749 - bit_offset - FIELD_BITSIZE (*fp);
5753 /* Get name of field. */
5754 fieldname = dwarf2_name (die, cu);
5755 if (fieldname == NULL)
5758 /* The name is already allocated along with this objfile, so we don't
5759 need to duplicate it for the type. */
5760 fp->name = fieldname;
5762 /* Change accessibility for artificial fields (e.g. virtual table
5763 pointer or virtual base class pointer) to private. */
5764 if (dwarf2_attr (die, DW_AT_artificial, cu))
5766 FIELD_ARTIFICIAL (*fp) = 1;
5767 new_field->accessibility = DW_ACCESS_private;
5768 fip->non_public_fields = 1;
5771 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
5773 /* C++ static member. */
5775 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
5776 is a declaration, but all versions of G++ as of this writing
5777 (so through at least 3.2.1) incorrectly generate
5778 DW_TAG_variable tags. */
5782 /* Get name of field. */
5783 fieldname = dwarf2_name (die, cu);
5784 if (fieldname == NULL)
5787 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5789 /* Only create a symbol if this is an external value.
5790 new_symbol checks this and puts the value in the global symbol
5791 table, which we want. If it is not external, new_symbol
5792 will try to put the value in cu->list_in_scope which is wrong. */
5793 && dwarf2_flag_true_p (die, DW_AT_external, cu))
5795 /* A static const member, not much different than an enum as far as
5796 we're concerned, except that we can support more types. */
5797 new_symbol (die, NULL, cu);
5800 /* Get physical name. */
5801 physname = (char *) dwarf2_physname (fieldname, die, cu);
5803 /* The name is already allocated along with this objfile, so we don't
5804 need to duplicate it for the type. */
5805 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
5806 FIELD_TYPE (*fp) = die_type (die, cu);
5807 FIELD_NAME (*fp) = fieldname;
5809 else if (die->tag == DW_TAG_inheritance)
5811 /* C++ base class field. */
5812 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
5815 int byte_offset = 0;
5817 if (attr_form_is_section_offset (attr))
5818 dwarf2_complex_location_expr_complaint ();
5819 else if (attr_form_is_constant (attr))
5820 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5821 else if (attr_form_is_block (attr))
5822 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5824 dwarf2_complex_location_expr_complaint ();
5826 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
5828 FIELD_BITSIZE (*fp) = 0;
5829 FIELD_TYPE (*fp) = die_type (die, cu);
5830 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
5831 fip->nbaseclasses++;
5835 /* Add a typedef defined in the scope of the FIP's class. */
5838 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
5839 struct dwarf2_cu *cu)
5841 struct objfile *objfile = cu->objfile;
5842 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5843 struct typedef_field_list *new_field;
5844 struct attribute *attr;
5845 struct typedef_field *fp;
5846 char *fieldname = "";
5848 /* Allocate a new field list entry and link it in. */
5849 new_field = xzalloc (sizeof (*new_field));
5850 make_cleanup (xfree, new_field);
5852 gdb_assert (die->tag == DW_TAG_typedef);
5854 fp = &new_field->field;
5856 /* Get name of field. */
5857 fp->name = dwarf2_name (die, cu);
5858 if (fp->name == NULL)
5861 fp->type = read_type_die (die, cu);
5863 new_field->next = fip->typedef_field_list;
5864 fip->typedef_field_list = new_field;
5865 fip->typedef_field_list_count++;
5868 /* Create the vector of fields, and attach it to the type. */
5871 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
5872 struct dwarf2_cu *cu)
5874 int nfields = fip->nfields;
5876 /* Record the field count, allocate space for the array of fields,
5877 and create blank accessibility bitfields if necessary. */
5878 TYPE_NFIELDS (type) = nfields;
5879 TYPE_FIELDS (type) = (struct field *)
5880 TYPE_ALLOC (type, sizeof (struct field) * nfields);
5881 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
5883 if (fip->non_public_fields && cu->language != language_ada)
5885 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5887 TYPE_FIELD_PRIVATE_BITS (type) =
5888 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5889 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
5891 TYPE_FIELD_PROTECTED_BITS (type) =
5892 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5893 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
5895 TYPE_FIELD_IGNORE_BITS (type) =
5896 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5897 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
5900 /* If the type has baseclasses, allocate and clear a bit vector for
5901 TYPE_FIELD_VIRTUAL_BITS. */
5902 if (fip->nbaseclasses && cu->language != language_ada)
5904 int num_bytes = B_BYTES (fip->nbaseclasses);
5905 unsigned char *pointer;
5907 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5908 pointer = TYPE_ALLOC (type, num_bytes);
5909 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
5910 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
5911 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
5914 /* Copy the saved-up fields into the field vector. Start from the head
5915 of the list, adding to the tail of the field array, so that they end
5916 up in the same order in the array in which they were added to the list. */
5917 while (nfields-- > 0)
5919 struct nextfield *fieldp;
5923 fieldp = fip->fields;
5924 fip->fields = fieldp->next;
5928 fieldp = fip->baseclasses;
5929 fip->baseclasses = fieldp->next;
5932 TYPE_FIELD (type, nfields) = fieldp->field;
5933 switch (fieldp->accessibility)
5935 case DW_ACCESS_private:
5936 if (cu->language != language_ada)
5937 SET_TYPE_FIELD_PRIVATE (type, nfields);
5940 case DW_ACCESS_protected:
5941 if (cu->language != language_ada)
5942 SET_TYPE_FIELD_PROTECTED (type, nfields);
5945 case DW_ACCESS_public:
5949 /* Unknown accessibility. Complain and treat it as public. */
5951 complaint (&symfile_complaints, _("unsupported accessibility %d"),
5952 fieldp->accessibility);
5956 if (nfields < fip->nbaseclasses)
5958 switch (fieldp->virtuality)
5960 case DW_VIRTUALITY_virtual:
5961 case DW_VIRTUALITY_pure_virtual:
5962 if (cu->language == language_ada)
5963 error ("unexpected virtuality in component of Ada type");
5964 SET_TYPE_FIELD_VIRTUAL (type, nfields);
5971 /* Add a member function to the proper fieldlist. */
5974 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
5975 struct type *type, struct dwarf2_cu *cu)
5977 struct objfile *objfile = cu->objfile;
5978 struct attribute *attr;
5979 struct fnfieldlist *flp;
5981 struct fn_field *fnp;
5984 struct nextfnfield *new_fnfield;
5985 struct type *this_type;
5987 if (cu->language == language_ada)
5988 error ("unexpected member function in Ada type");
5990 /* Get name of member function. */
5991 fieldname = dwarf2_name (die, cu);
5992 if (fieldname == NULL)
5995 /* Get the mangled name. */
5996 physname = (char *) dwarf2_physname (fieldname, die, cu);
5998 /* Look up member function name in fieldlist. */
5999 for (i = 0; i < fip->nfnfields; i++)
6001 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6005 /* Create new list element if necessary. */
6006 if (i < fip->nfnfields)
6007 flp = &fip->fnfieldlists[i];
6010 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6012 fip->fnfieldlists = (struct fnfieldlist *)
6013 xrealloc (fip->fnfieldlists,
6014 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6015 * sizeof (struct fnfieldlist));
6016 if (fip->nfnfields == 0)
6017 make_cleanup (free_current_contents, &fip->fnfieldlists);
6019 flp = &fip->fnfieldlists[fip->nfnfields];
6020 flp->name = fieldname;
6026 /* Create a new member function field and chain it to the field list
6028 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6029 make_cleanup (xfree, new_fnfield);
6030 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6031 new_fnfield->next = flp->head;
6032 flp->head = new_fnfield;
6035 /* Fill in the member function field info. */
6036 fnp = &new_fnfield->fnfield;
6037 /* The name is already allocated along with this objfile, so we don't
6038 need to duplicate it for the type. */
6039 fnp->physname = physname ? physname : "";
6040 fnp->type = alloc_type (objfile);
6041 this_type = read_type_die (die, cu);
6042 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6044 int nparams = TYPE_NFIELDS (this_type);
6046 /* TYPE is the domain of this method, and THIS_TYPE is the type
6047 of the method itself (TYPE_CODE_METHOD). */
6048 smash_to_method_type (fnp->type, type,
6049 TYPE_TARGET_TYPE (this_type),
6050 TYPE_FIELDS (this_type),
6051 TYPE_NFIELDS (this_type),
6052 TYPE_VARARGS (this_type));
6054 /* Handle static member functions.
6055 Dwarf2 has no clean way to discern C++ static and non-static
6056 member functions. G++ helps GDB by marking the first
6057 parameter for non-static member functions (which is the
6058 this pointer) as artificial. We obtain this information
6059 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6060 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6061 fnp->voffset = VOFFSET_STATIC;
6064 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6067 /* Get fcontext from DW_AT_containing_type if present. */
6068 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6069 fnp->fcontext = die_containing_type (die, cu);
6071 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6072 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6074 /* Get accessibility. */
6075 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6078 switch (DW_UNSND (attr))
6080 case DW_ACCESS_private:
6081 fnp->is_private = 1;
6083 case DW_ACCESS_protected:
6084 fnp->is_protected = 1;
6089 /* Check for artificial methods. */
6090 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6091 if (attr && DW_UNSND (attr) != 0)
6092 fnp->is_artificial = 1;
6094 /* Get index in virtual function table if it is a virtual member
6095 function. For older versions of GCC, this is an offset in the
6096 appropriate virtual table, as specified by DW_AT_containing_type.
6097 For everyone else, it is an expression to be evaluated relative
6098 to the object address. */
6100 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6103 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6105 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6107 /* Old-style GCC. */
6108 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6110 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6111 || (DW_BLOCK (attr)->size > 1
6112 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6113 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6115 struct dwarf_block blk;
6118 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6120 blk.size = DW_BLOCK (attr)->size - offset;
6121 blk.data = DW_BLOCK (attr)->data + offset;
6122 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6123 if ((fnp->voffset % cu->header.addr_size) != 0)
6124 dwarf2_complex_location_expr_complaint ();
6126 fnp->voffset /= cu->header.addr_size;
6130 dwarf2_complex_location_expr_complaint ();
6133 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6135 else if (attr_form_is_section_offset (attr))
6137 dwarf2_complex_location_expr_complaint ();
6141 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6147 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6148 if (attr && DW_UNSND (attr))
6150 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6151 complaint (&symfile_complaints,
6152 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6153 fieldname, die->offset);
6154 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6155 TYPE_CPLUS_DYNAMIC (type) = 1;
6160 /* Create the vector of member function fields, and attach it to the type. */
6163 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6164 struct dwarf2_cu *cu)
6166 struct fnfieldlist *flp;
6167 int total_length = 0;
6170 if (cu->language == language_ada)
6171 error ("unexpected member functions in Ada type");
6173 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6174 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6175 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6177 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6179 struct nextfnfield *nfp = flp->head;
6180 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6183 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6184 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6185 fn_flp->fn_fields = (struct fn_field *)
6186 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6187 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6188 fn_flp->fn_fields[k] = nfp->fnfield;
6190 total_length += flp->length;
6193 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6194 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6197 /* Returns non-zero if NAME is the name of a vtable member in CU's
6198 language, zero otherwise. */
6200 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6202 static const char vptr[] = "_vptr";
6203 static const char vtable[] = "vtable";
6205 /* Look for the C++ and Java forms of the vtable. */
6206 if ((cu->language == language_java
6207 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6208 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
6209 && is_cplus_marker (name[sizeof (vptr) - 1])))
6215 /* GCC outputs unnamed structures that are really pointers to member
6216 functions, with the ABI-specified layout. If TYPE describes
6217 such a structure, smash it into a member function type.
6219 GCC shouldn't do this; it should just output pointer to member DIEs.
6220 This is GCC PR debug/28767. */
6223 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
6225 struct type *pfn_type, *domain_type, *new_type;
6227 /* Check for a structure with no name and two children. */
6228 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
6231 /* Check for __pfn and __delta members. */
6232 if (TYPE_FIELD_NAME (type, 0) == NULL
6233 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
6234 || TYPE_FIELD_NAME (type, 1) == NULL
6235 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
6238 /* Find the type of the method. */
6239 pfn_type = TYPE_FIELD_TYPE (type, 0);
6240 if (pfn_type == NULL
6241 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
6242 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
6245 /* Look for the "this" argument. */
6246 pfn_type = TYPE_TARGET_TYPE (pfn_type);
6247 if (TYPE_NFIELDS (pfn_type) == 0
6248 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6249 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
6252 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6253 new_type = alloc_type (objfile);
6254 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6255 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6256 TYPE_VARARGS (pfn_type));
6257 smash_to_methodptr_type (type, new_type);
6260 /* Called when we find the DIE that starts a structure or union scope
6261 (definition) to process all dies that define the members of the
6264 NOTE: we need to call struct_type regardless of whether or not the
6265 DIE has an at_name attribute, since it might be an anonymous
6266 structure or union. This gets the type entered into our set of
6269 However, if the structure is incomplete (an opaque struct/union)
6270 then suppress creating a symbol table entry for it since gdb only
6271 wants to find the one with the complete definition. Note that if
6272 it is complete, we just call new_symbol, which does it's own
6273 checking about whether the struct/union is anonymous or not (and
6274 suppresses creating a symbol table entry itself). */
6276 static struct type *
6277 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6279 struct objfile *objfile = cu->objfile;
6281 struct attribute *attr;
6283 struct cleanup *back_to;
6285 /* If the definition of this type lives in .debug_types, read that type.
6286 Don't follow DW_AT_specification though, that will take us back up
6287 the chain and we want to go down. */
6288 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6291 struct dwarf2_cu *type_cu = cu;
6292 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6294 /* We could just recurse on read_structure_type, but we need to call
6295 get_die_type to ensure only one type for this DIE is created.
6296 This is important, for example, because for c++ classes we need
6297 TYPE_NAME set which is only done by new_symbol. Blech. */
6298 type = read_type_die (type_die, type_cu);
6299 return set_die_type (die, type, cu);
6302 back_to = make_cleanup (null_cleanup, 0);
6304 type = alloc_type (objfile);
6305 INIT_CPLUS_SPECIFIC (type);
6307 name = dwarf2_name (die, cu);
6310 if (cu->language == language_cplus
6311 || cu->language == language_java)
6313 TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu);
6314 if (die->tag == DW_TAG_structure_type
6315 || die->tag == DW_TAG_class_type)
6316 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6320 /* The name is already allocated along with this objfile, so
6321 we don't need to duplicate it for the type. */
6322 TYPE_TAG_NAME (type) = (char *) name;
6323 if (die->tag == DW_TAG_class_type)
6324 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6328 if (die->tag == DW_TAG_structure_type)
6330 TYPE_CODE (type) = TYPE_CODE_STRUCT;
6332 else if (die->tag == DW_TAG_union_type)
6334 TYPE_CODE (type) = TYPE_CODE_UNION;
6338 TYPE_CODE (type) = TYPE_CODE_CLASS;
6341 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
6342 TYPE_DECLARED_CLASS (type) = 1;
6344 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6347 TYPE_LENGTH (type) = DW_UNSND (attr);
6351 TYPE_LENGTH (type) = 0;
6354 TYPE_STUB_SUPPORTED (type) = 1;
6355 if (die_is_declaration (die, cu))
6356 TYPE_STUB (type) = 1;
6357 else if (attr == NULL && die->child == NULL
6358 && producer_is_realview (cu->producer))
6359 /* RealView does not output the required DW_AT_declaration
6360 on incomplete types. */
6361 TYPE_STUB (type) = 1;
6363 /* We need to add the type field to the die immediately so we don't
6364 infinitely recurse when dealing with pointers to the structure
6365 type within the structure itself. */
6366 set_die_type (die, type, cu);
6368 /* set_die_type should be already done. */
6369 set_descriptive_type (type, die, cu);
6371 if (die->child != NULL && ! die_is_declaration (die, cu))
6373 struct field_info fi;
6374 struct die_info *child_die;
6376 memset (&fi, 0, sizeof (struct field_info));
6378 child_die = die->child;
6380 while (child_die && child_die->tag)
6382 if (child_die->tag == DW_TAG_member
6383 || child_die->tag == DW_TAG_variable)
6385 /* NOTE: carlton/2002-11-05: A C++ static data member
6386 should be a DW_TAG_member that is a declaration, but
6387 all versions of G++ as of this writing (so through at
6388 least 3.2.1) incorrectly generate DW_TAG_variable
6389 tags for them instead. */
6390 dwarf2_add_field (&fi, child_die, cu);
6392 else if (child_die->tag == DW_TAG_subprogram)
6394 /* C++ member function. */
6395 dwarf2_add_member_fn (&fi, child_die, type, cu);
6397 else if (child_die->tag == DW_TAG_inheritance)
6399 /* C++ base class field. */
6400 dwarf2_add_field (&fi, child_die, cu);
6402 else if (child_die->tag == DW_TAG_typedef)
6403 dwarf2_add_typedef (&fi, child_die, cu);
6404 child_die = sibling_die (child_die);
6407 /* Attach fields and member functions to the type. */
6409 dwarf2_attach_fields_to_type (&fi, type, cu);
6412 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
6414 /* Get the type which refers to the base class (possibly this
6415 class itself) which contains the vtable pointer for the current
6416 class from the DW_AT_containing_type attribute. This use of
6417 DW_AT_containing_type is a GNU extension. */
6419 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6421 struct type *t = die_containing_type (die, cu);
6423 TYPE_VPTR_BASETYPE (type) = t;
6428 /* Our own class provides vtbl ptr. */
6429 for (i = TYPE_NFIELDS (t) - 1;
6430 i >= TYPE_N_BASECLASSES (t);
6433 char *fieldname = TYPE_FIELD_NAME (t, i);
6435 if (is_vtable_name (fieldname, cu))
6437 TYPE_VPTR_FIELDNO (type) = i;
6442 /* Complain if virtual function table field not found. */
6443 if (i < TYPE_N_BASECLASSES (t))
6444 complaint (&symfile_complaints,
6445 _("virtual function table pointer not found when defining class '%s'"),
6446 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
6451 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
6454 else if (cu->producer
6455 && strncmp (cu->producer,
6456 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6458 /* The IBM XLC compiler does not provide direct indication
6459 of the containing type, but the vtable pointer is
6460 always named __vfp. */
6464 for (i = TYPE_NFIELDS (type) - 1;
6465 i >= TYPE_N_BASECLASSES (type);
6468 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
6470 TYPE_VPTR_FIELDNO (type) = i;
6471 TYPE_VPTR_BASETYPE (type) = type;
6478 /* Copy fi.typedef_field_list linked list elements content into the
6479 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6480 if (fi.typedef_field_list)
6482 int i = fi.typedef_field_list_count;
6484 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6485 TYPE_TYPEDEF_FIELD_ARRAY (type)
6486 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
6487 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
6489 /* Reverse the list order to keep the debug info elements order. */
6492 struct typedef_field *dest, *src;
6494 dest = &TYPE_TYPEDEF_FIELD (type, i);
6495 src = &fi.typedef_field_list->field;
6496 fi.typedef_field_list = fi.typedef_field_list->next;
6502 quirk_gcc_member_function_pointer (type, cu->objfile);
6504 do_cleanups (back_to);
6509 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
6511 struct die_info *child_die = die->child;
6512 struct type *this_type;
6514 this_type = get_die_type (die, cu);
6515 if (this_type == NULL)
6516 this_type = read_structure_type (die, cu);
6518 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6519 snapshots) has been known to create a die giving a declaration
6520 for a class that has, as a child, a die giving a definition for a
6521 nested class. So we have to process our children even if the
6522 current die is a declaration. Normally, of course, a declaration
6523 won't have any children at all. */
6525 while (child_die != NULL && child_die->tag)
6527 if (child_die->tag == DW_TAG_member
6528 || child_die->tag == DW_TAG_variable
6529 || child_die->tag == DW_TAG_inheritance)
6534 process_die (child_die, cu);
6536 child_die = sibling_die (child_die);
6539 /* Do not consider external references. According to the DWARF standard,
6540 these DIEs are identified by the fact that they have no byte_size
6541 attribute, and a declaration attribute. */
6542 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
6543 || !die_is_declaration (die, cu))
6544 new_symbol (die, this_type, cu);
6547 /* Given a DW_AT_enumeration_type die, set its type. We do not
6548 complete the type's fields yet, or create any symbols. */
6550 static struct type *
6551 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6553 struct objfile *objfile = cu->objfile;
6555 struct attribute *attr;
6558 /* If the definition of this type lives in .debug_types, read that type.
6559 Don't follow DW_AT_specification though, that will take us back up
6560 the chain and we want to go down. */
6561 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6564 struct dwarf2_cu *type_cu = cu;
6565 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6567 type = read_type_die (type_die, type_cu);
6568 return set_die_type (die, type, cu);
6571 type = alloc_type (objfile);
6573 TYPE_CODE (type) = TYPE_CODE_ENUM;
6574 name = dwarf2_full_name (NULL, die, cu);
6576 TYPE_TAG_NAME (type) = (char *) name;
6578 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6581 TYPE_LENGTH (type) = DW_UNSND (attr);
6585 TYPE_LENGTH (type) = 0;
6588 /* The enumeration DIE can be incomplete. In Ada, any type can be
6589 declared as private in the package spec, and then defined only
6590 inside the package body. Such types are known as Taft Amendment
6591 Types. When another package uses such a type, an incomplete DIE
6592 may be generated by the compiler. */
6593 if (die_is_declaration (die, cu))
6594 TYPE_STUB (type) = 1;
6596 return set_die_type (die, type, cu);
6599 /* Given a pointer to a die which begins an enumeration, process all
6600 the dies that define the members of the enumeration, and create the
6601 symbol for the enumeration type.
6603 NOTE: We reverse the order of the element list. */
6606 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
6608 struct die_info *child_die;
6609 struct field *fields;
6612 int unsigned_enum = 1;
6614 struct type *this_type;
6618 this_type = get_die_type (die, cu);
6619 if (this_type == NULL)
6620 this_type = read_enumeration_type (die, cu);
6621 if (die->child != NULL)
6623 child_die = die->child;
6624 while (child_die && child_die->tag)
6626 if (child_die->tag != DW_TAG_enumerator)
6628 process_die (child_die, cu);
6632 name = dwarf2_name (child_die, cu);
6635 sym = new_symbol (child_die, this_type, cu);
6636 if (SYMBOL_VALUE (sym) < 0)
6639 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
6641 fields = (struct field *)
6643 (num_fields + DW_FIELD_ALLOC_CHUNK)
6644 * sizeof (struct field));
6647 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
6648 FIELD_TYPE (fields[num_fields]) = NULL;
6649 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
6650 FIELD_BITSIZE (fields[num_fields]) = 0;
6656 child_die = sibling_die (child_die);
6661 TYPE_NFIELDS (this_type) = num_fields;
6662 TYPE_FIELDS (this_type) = (struct field *)
6663 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
6664 memcpy (TYPE_FIELDS (this_type), fields,
6665 sizeof (struct field) * num_fields);
6669 TYPE_UNSIGNED (this_type) = 1;
6672 new_symbol (die, this_type, cu);
6675 /* Extract all information from a DW_TAG_array_type DIE and put it in
6676 the DIE's type field. For now, this only handles one dimensional
6679 static struct type *
6680 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6682 struct objfile *objfile = cu->objfile;
6683 struct die_info *child_die;
6685 struct type *element_type, *range_type, *index_type;
6686 struct type **range_types = NULL;
6687 struct attribute *attr;
6689 struct cleanup *back_to;
6692 element_type = die_type (die, cu);
6694 /* The die_type call above may have already set the type for this DIE. */
6695 type = get_die_type (die, cu);
6699 /* Irix 6.2 native cc creates array types without children for
6700 arrays with unspecified length. */
6701 if (die->child == NULL)
6703 index_type = objfile_type (objfile)->builtin_int;
6704 range_type = create_range_type (NULL, index_type, 0, -1);
6705 type = create_array_type (NULL, element_type, range_type);
6706 return set_die_type (die, type, cu);
6709 back_to = make_cleanup (null_cleanup, NULL);
6710 child_die = die->child;
6711 while (child_die && child_die->tag)
6713 if (child_die->tag == DW_TAG_subrange_type)
6715 struct type *child_type = read_type_die (child_die, cu);
6717 if (child_type != NULL)
6719 /* The range type was succesfully read. Save it for
6720 the array type creation. */
6721 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
6723 range_types = (struct type **)
6724 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
6725 * sizeof (struct type *));
6727 make_cleanup (free_current_contents, &range_types);
6729 range_types[ndim++] = child_type;
6732 child_die = sibling_die (child_die);
6735 /* Dwarf2 dimensions are output from left to right, create the
6736 necessary array types in backwards order. */
6738 type = element_type;
6740 if (read_array_order (die, cu) == DW_ORD_col_major)
6745 type = create_array_type (NULL, type, range_types[i++]);
6750 type = create_array_type (NULL, type, range_types[ndim]);
6753 /* Understand Dwarf2 support for vector types (like they occur on
6754 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6755 array type. This is not part of the Dwarf2/3 standard yet, but a
6756 custom vendor extension. The main difference between a regular
6757 array and the vector variant is that vectors are passed by value
6759 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
6761 make_vector_type (type);
6763 name = dwarf2_name (die, cu);
6765 TYPE_NAME (type) = name;
6767 /* Install the type in the die. */
6768 set_die_type (die, type, cu);
6770 /* set_die_type should be already done. */
6771 set_descriptive_type (type, die, cu);
6773 do_cleanups (back_to);
6778 static enum dwarf_array_dim_ordering
6779 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
6781 struct attribute *attr;
6783 attr = dwarf2_attr (die, DW_AT_ordering, cu);
6785 if (attr) return DW_SND (attr);
6788 GNU F77 is a special case, as at 08/2004 array type info is the
6789 opposite order to the dwarf2 specification, but data is still
6790 laid out as per normal fortran.
6792 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
6796 if (cu->language == language_fortran
6797 && cu->producer && strstr (cu->producer, "GNU F77"))
6799 return DW_ORD_row_major;
6802 switch (cu->language_defn->la_array_ordering)
6804 case array_column_major:
6805 return DW_ORD_col_major;
6806 case array_row_major:
6808 return DW_ORD_row_major;
6812 /* Extract all information from a DW_TAG_set_type DIE and put it in
6813 the DIE's type field. */
6815 static struct type *
6816 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
6818 struct type *domain_type, *set_type;
6819 struct attribute *attr;
6821 domain_type = die_type (die, cu);
6823 /* The die_type call above may have already set the type for this DIE. */
6824 set_type = get_die_type (die, cu);
6828 set_type = create_set_type (NULL, domain_type);
6830 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6832 TYPE_LENGTH (set_type) = DW_UNSND (attr);
6834 return set_die_type (die, set_type, cu);
6837 /* First cut: install each common block member as a global variable. */
6840 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6842 struct die_info *child_die;
6843 struct attribute *attr;
6845 CORE_ADDR base = (CORE_ADDR) 0;
6847 attr = dwarf2_attr (die, DW_AT_location, cu);
6850 /* Support the .debug_loc offsets */
6851 if (attr_form_is_block (attr))
6853 base = decode_locdesc (DW_BLOCK (attr), cu);
6855 else if (attr_form_is_section_offset (attr))
6857 dwarf2_complex_location_expr_complaint ();
6861 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6862 "common block member");
6865 if (die->child != NULL)
6867 child_die = die->child;
6868 while (child_die && child_die->tag)
6870 sym = new_symbol (child_die, NULL, cu);
6871 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
6874 CORE_ADDR byte_offset = 0;
6876 if (attr_form_is_section_offset (attr))
6877 dwarf2_complex_location_expr_complaint ();
6878 else if (attr_form_is_constant (attr))
6879 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6880 else if (attr_form_is_block (attr))
6881 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6883 dwarf2_complex_location_expr_complaint ();
6885 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
6886 add_symbol_to_list (sym, &global_symbols);
6888 child_die = sibling_die (child_die);
6893 /* Create a type for a C++ namespace. */
6895 static struct type *
6896 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
6898 struct objfile *objfile = cu->objfile;
6899 const char *previous_prefix, *name;
6903 /* For extensions, reuse the type of the original namespace. */
6904 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
6906 struct die_info *ext_die;
6907 struct dwarf2_cu *ext_cu = cu;
6909 ext_die = dwarf2_extension (die, &ext_cu);
6910 type = read_type_die (ext_die, ext_cu);
6911 return set_die_type (die, type, cu);
6914 name = namespace_name (die, &is_anonymous, cu);
6916 /* Now build the name of the current namespace. */
6918 previous_prefix = determine_prefix (die, cu);
6919 if (previous_prefix[0] != '\0')
6920 name = typename_concat (&objfile->objfile_obstack,
6921 previous_prefix, name, 0, cu);
6923 /* Create the type. */
6924 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
6926 TYPE_NAME (type) = (char *) name;
6927 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6929 return set_die_type (die, type, cu);
6932 /* Read a C++ namespace. */
6935 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6937 struct objfile *objfile = cu->objfile;
6941 /* Add a symbol associated to this if we haven't seen the namespace
6942 before. Also, add a using directive if it's an anonymous
6945 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
6949 type = read_type_die (die, cu);
6950 new_symbol (die, type, cu);
6952 name = namespace_name (die, &is_anonymous, cu);
6955 const char *previous_prefix = determine_prefix (die, cu);
6957 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
6958 NULL, &objfile->objfile_obstack);
6962 if (die->child != NULL)
6964 struct die_info *child_die = die->child;
6966 while (child_die && child_die->tag)
6968 process_die (child_die, cu);
6969 child_die = sibling_die (child_die);
6974 /* Read a Fortran module as type. This DIE can be only a declaration used for
6975 imported module. Still we need that type as local Fortran "use ... only"
6976 declaration imports depend on the created type in determine_prefix. */
6978 static struct type *
6979 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
6981 struct objfile *objfile = cu->objfile;
6985 module_name = dwarf2_name (die, cu);
6987 complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
6989 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
6991 /* determine_prefix uses TYPE_TAG_NAME. */
6992 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6994 return set_die_type (die, type, cu);
6997 /* Read a Fortran module. */
7000 read_module (struct die_info *die, struct dwarf2_cu *cu)
7002 struct die_info *child_die = die->child;
7004 while (child_die && child_die->tag)
7006 process_die (child_die, cu);
7007 child_die = sibling_die (child_die);
7011 /* Return the name of the namespace represented by DIE. Set
7012 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7016 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7018 struct die_info *current_die;
7019 const char *name = NULL;
7021 /* Loop through the extensions until we find a name. */
7023 for (current_die = die;
7024 current_die != NULL;
7025 current_die = dwarf2_extension (die, &cu))
7027 name = dwarf2_name (current_die, cu);
7032 /* Is it an anonymous namespace? */
7034 *is_anonymous = (name == NULL);
7036 name = "(anonymous namespace)";
7041 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7042 the user defined type vector. */
7044 static struct type *
7045 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7047 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7048 struct comp_unit_head *cu_header = &cu->header;
7050 struct attribute *attr_byte_size;
7051 struct attribute *attr_address_class;
7052 int byte_size, addr_class;
7053 struct type *target_type;
7055 target_type = die_type (die, cu);
7057 /* The die_type call above may have already set the type for this DIE. */
7058 type = get_die_type (die, cu);
7062 type = lookup_pointer_type (target_type);
7064 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7066 byte_size = DW_UNSND (attr_byte_size);
7068 byte_size = cu_header->addr_size;
7070 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7071 if (attr_address_class)
7072 addr_class = DW_UNSND (attr_address_class);
7074 addr_class = DW_ADDR_none;
7076 /* If the pointer size or address class is different than the
7077 default, create a type variant marked as such and set the
7078 length accordingly. */
7079 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7081 if (gdbarch_address_class_type_flags_p (gdbarch))
7085 type_flags = gdbarch_address_class_type_flags
7086 (gdbarch, byte_size, addr_class);
7087 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7089 type = make_type_with_address_space (type, type_flags);
7091 else if (TYPE_LENGTH (type) != byte_size)
7093 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
7097 /* Should we also complain about unhandled address classes? */
7101 TYPE_LENGTH (type) = byte_size;
7102 return set_die_type (die, type, cu);
7105 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7106 the user defined type vector. */
7108 static struct type *
7109 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7112 struct type *to_type;
7113 struct type *domain;
7115 to_type = die_type (die, cu);
7116 domain = die_containing_type (die, cu);
7118 /* The calls above may have already set the type for this DIE. */
7119 type = get_die_type (die, cu);
7123 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7124 type = lookup_methodptr_type (to_type);
7126 type = lookup_memberptr_type (to_type, domain);
7128 return set_die_type (die, type, cu);
7131 /* Extract all information from a DW_TAG_reference_type DIE and add to
7132 the user defined type vector. */
7134 static struct type *
7135 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7137 struct comp_unit_head *cu_header = &cu->header;
7138 struct type *type, *target_type;
7139 struct attribute *attr;
7141 target_type = die_type (die, cu);
7143 /* The die_type call above may have already set the type for this DIE. */
7144 type = get_die_type (die, cu);
7148 type = lookup_reference_type (target_type);
7149 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7152 TYPE_LENGTH (type) = DW_UNSND (attr);
7156 TYPE_LENGTH (type) = cu_header->addr_size;
7158 return set_die_type (die, type, cu);
7161 static struct type *
7162 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
7164 struct type *base_type, *cv_type;
7166 base_type = die_type (die, cu);
7168 /* The die_type call above may have already set the type for this DIE. */
7169 cv_type = get_die_type (die, cu);
7173 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
7174 return set_die_type (die, cv_type, cu);
7177 static struct type *
7178 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
7180 struct type *base_type, *cv_type;
7182 base_type = die_type (die, cu);
7184 /* The die_type call above may have already set the type for this DIE. */
7185 cv_type = get_die_type (die, cu);
7189 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
7190 return set_die_type (die, cv_type, cu);
7193 /* Extract all information from a DW_TAG_string_type DIE and add to
7194 the user defined type vector. It isn't really a user defined type,
7195 but it behaves like one, with other DIE's using an AT_user_def_type
7196 attribute to reference it. */
7198 static struct type *
7199 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
7201 struct objfile *objfile = cu->objfile;
7202 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7203 struct type *type, *range_type, *index_type, *char_type;
7204 struct attribute *attr;
7205 unsigned int length;
7207 attr = dwarf2_attr (die, DW_AT_string_length, cu);
7210 length = DW_UNSND (attr);
7214 /* check for the DW_AT_byte_size attribute */
7215 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7218 length = DW_UNSND (attr);
7226 index_type = objfile_type (objfile)->builtin_int;
7227 range_type = create_range_type (NULL, index_type, 1, length);
7228 char_type = language_string_char_type (cu->language_defn, gdbarch);
7229 type = create_string_type (NULL, char_type, range_type);
7231 return set_die_type (die, type, cu);
7234 /* Handle DIES due to C code like:
7238 int (*funcp)(int a, long l);
7242 ('funcp' generates a DW_TAG_subroutine_type DIE)
7245 static struct type *
7246 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
7248 struct type *type; /* Type that this function returns */
7249 struct type *ftype; /* Function that returns above type */
7250 struct attribute *attr;
7252 type = die_type (die, cu);
7254 /* The die_type call above may have already set the type for this DIE. */
7255 ftype = get_die_type (die, cu);
7259 ftype = lookup_function_type (type);
7261 /* All functions in C++, Pascal and Java have prototypes. */
7262 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
7263 if ((attr && (DW_UNSND (attr) != 0))
7264 || cu->language == language_cplus
7265 || cu->language == language_java
7266 || cu->language == language_pascal)
7267 TYPE_PROTOTYPED (ftype) = 1;
7268 else if (producer_is_realview (cu->producer))
7269 /* RealView does not emit DW_AT_prototyped. We can not
7270 distinguish prototyped and unprototyped functions; default to
7271 prototyped, since that is more common in modern code (and
7272 RealView warns about unprototyped functions). */
7273 TYPE_PROTOTYPED (ftype) = 1;
7275 /* Store the calling convention in the type if it's available in
7276 the subroutine die. Otherwise set the calling convention to
7277 the default value DW_CC_normal. */
7278 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
7279 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
7281 /* We need to add the subroutine type to the die immediately so
7282 we don't infinitely recurse when dealing with parameters
7283 declared as the same subroutine type. */
7284 set_die_type (die, ftype, cu);
7286 if (die->child != NULL)
7288 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
7289 struct die_info *child_die;
7290 int nparams, iparams;
7292 /* Count the number of parameters.
7293 FIXME: GDB currently ignores vararg functions, but knows about
7294 vararg member functions. */
7296 child_die = die->child;
7297 while (child_die && child_die->tag)
7299 if (child_die->tag == DW_TAG_formal_parameter)
7301 else if (child_die->tag == DW_TAG_unspecified_parameters)
7302 TYPE_VARARGS (ftype) = 1;
7303 child_die = sibling_die (child_die);
7306 /* Allocate storage for parameters and fill them in. */
7307 TYPE_NFIELDS (ftype) = nparams;
7308 TYPE_FIELDS (ftype) = (struct field *)
7309 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
7311 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7312 even if we error out during the parameters reading below. */
7313 for (iparams = 0; iparams < nparams; iparams++)
7314 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
7317 child_die = die->child;
7318 while (child_die && child_die->tag)
7320 if (child_die->tag == DW_TAG_formal_parameter)
7322 /* Dwarf2 has no clean way to discern C++ static and non-static
7323 member functions. G++ helps GDB by marking the first
7324 parameter for non-static member functions (which is the
7325 this pointer) as artificial. We pass this information
7326 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
7327 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
7329 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
7332 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
7334 /* GCC/43521: In java, the formal parameter
7335 "this" is sometimes not marked with DW_AT_artificial. */
7336 if (cu->language == language_java)
7338 const char *name = dwarf2_name (child_die, cu);
7340 if (name && !strcmp (name, "this"))
7341 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
7344 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
7347 child_die = sibling_die (child_die);
7354 static struct type *
7355 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
7357 struct objfile *objfile = cu->objfile;
7358 const char *name = NULL;
7359 struct type *this_type;
7361 name = dwarf2_full_name (NULL, die, cu);
7362 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
7363 TYPE_FLAG_TARGET_STUB, NULL, objfile);
7364 TYPE_NAME (this_type) = (char *) name;
7365 set_die_type (die, this_type, cu);
7366 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
7370 /* Find a representation of a given base type and install
7371 it in the TYPE field of the die. */
7373 static struct type *
7374 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
7376 struct objfile *objfile = cu->objfile;
7378 struct attribute *attr;
7379 int encoding = 0, size = 0;
7381 enum type_code code = TYPE_CODE_INT;
7383 struct type *target_type = NULL;
7385 attr = dwarf2_attr (die, DW_AT_encoding, cu);
7388 encoding = DW_UNSND (attr);
7390 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7393 size = DW_UNSND (attr);
7395 name = dwarf2_name (die, cu);
7398 complaint (&symfile_complaints,
7399 _("DW_AT_name missing from DW_TAG_base_type"));
7404 case DW_ATE_address:
7405 /* Turn DW_ATE_address into a void * pointer. */
7406 code = TYPE_CODE_PTR;
7407 type_flags |= TYPE_FLAG_UNSIGNED;
7408 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
7410 case DW_ATE_boolean:
7411 code = TYPE_CODE_BOOL;
7412 type_flags |= TYPE_FLAG_UNSIGNED;
7414 case DW_ATE_complex_float:
7415 code = TYPE_CODE_COMPLEX;
7416 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
7418 case DW_ATE_decimal_float:
7419 code = TYPE_CODE_DECFLOAT;
7422 code = TYPE_CODE_FLT;
7426 case DW_ATE_unsigned:
7427 type_flags |= TYPE_FLAG_UNSIGNED;
7429 case DW_ATE_signed_char:
7430 if (cu->language == language_ada || cu->language == language_m2
7431 || cu->language == language_pascal)
7432 code = TYPE_CODE_CHAR;
7434 case DW_ATE_unsigned_char:
7435 if (cu->language == language_ada || cu->language == language_m2
7436 || cu->language == language_pascal)
7437 code = TYPE_CODE_CHAR;
7438 type_flags |= TYPE_FLAG_UNSIGNED;
7441 /* We just treat this as an integer and then recognize the
7442 type by name elsewhere. */
7446 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
7447 dwarf_type_encoding_name (encoding));
7451 type = init_type (code, size, type_flags, NULL, objfile);
7452 TYPE_NAME (type) = name;
7453 TYPE_TARGET_TYPE (type) = target_type;
7455 if (name && strcmp (name, "char") == 0)
7456 TYPE_NOSIGN (type) = 1;
7458 return set_die_type (die, type, cu);
7461 /* Read the given DW_AT_subrange DIE. */
7463 static struct type *
7464 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
7466 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7467 struct type *base_type;
7468 struct type *range_type;
7469 struct attribute *attr;
7473 LONGEST negative_mask;
7475 base_type = die_type (die, cu);
7476 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7477 check_typedef (base_type);
7479 /* The die_type call above may have already set the type for this DIE. */
7480 range_type = get_die_type (die, cu);
7484 if (cu->language == language_fortran)
7486 /* FORTRAN implies a lower bound of 1, if not given. */
7490 /* FIXME: For variable sized arrays either of these could be
7491 a variable rather than a constant value. We'll allow it,
7492 but we don't know how to handle it. */
7493 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
7495 low = dwarf2_get_attr_constant_value (attr, 0);
7497 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
7500 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
7502 /* GCC encodes arrays with unspecified or dynamic length
7503 with a DW_FORM_block1 attribute or a reference attribute.
7504 FIXME: GDB does not yet know how to handle dynamic
7505 arrays properly, treat them as arrays with unspecified
7508 FIXME: jimb/2003-09-22: GDB does not really know
7509 how to handle arrays of unspecified length
7510 either; we just represent them as zero-length
7511 arrays. Choose an appropriate upper bound given
7512 the lower bound we've computed above. */
7516 high = dwarf2_get_attr_constant_value (attr, 1);
7520 attr = dwarf2_attr (die, DW_AT_count, cu);
7523 int count = dwarf2_get_attr_constant_value (attr, 1);
7524 high = low + count - 1;
7528 /* Dwarf-2 specifications explicitly allows to create subrange types
7529 without specifying a base type.
7530 In that case, the base type must be set to the type of
7531 the lower bound, upper bound or count, in that order, if any of these
7532 three attributes references an object that has a type.
7533 If no base type is found, the Dwarf-2 specifications say that
7534 a signed integer type of size equal to the size of an address should
7536 For the following C code: `extern char gdb_int [];'
7537 GCC produces an empty range DIE.
7538 FIXME: muller/2010-05-28: Possible references to object for low bound,
7539 high bound or count are not yet handled by this code.
7541 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
7543 struct objfile *objfile = cu->objfile;
7544 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7545 int addr_size = gdbarch_addr_bit (gdbarch) /8;
7546 struct type *int_type = objfile_type (objfile)->builtin_int;
7548 /* Test "int", "long int", and "long long int" objfile types,
7549 and select the first one having a size above or equal to the
7550 architecture address size. */
7551 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7552 base_type = int_type;
7555 int_type = objfile_type (objfile)->builtin_long;
7556 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7557 base_type = int_type;
7560 int_type = objfile_type (objfile)->builtin_long_long;
7561 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7562 base_type = int_type;
7568 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
7569 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
7570 low |= negative_mask;
7571 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
7572 high |= negative_mask;
7574 range_type = create_range_type (NULL, base_type, low, high);
7576 /* Mark arrays with dynamic length at least as an array of unspecified
7577 length. GDB could check the boundary but before it gets implemented at
7578 least allow accessing the array elements. */
7579 if (attr && attr->form == DW_FORM_block1)
7580 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
7582 name = dwarf2_name (die, cu);
7584 TYPE_NAME (range_type) = name;
7586 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7588 TYPE_LENGTH (range_type) = DW_UNSND (attr);
7590 set_die_type (die, range_type, cu);
7592 /* set_die_type should be already done. */
7593 set_descriptive_type (range_type, die, cu);
7598 static struct type *
7599 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
7603 /* For now, we only support the C meaning of an unspecified type: void. */
7605 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
7606 TYPE_NAME (type) = dwarf2_name (die, cu);
7608 return set_die_type (die, type, cu);
7611 /* Trivial hash function for die_info: the hash value of a DIE
7612 is its offset in .debug_info for this objfile. */
7615 die_hash (const void *item)
7617 const struct die_info *die = item;
7622 /* Trivial comparison function for die_info structures: two DIEs
7623 are equal if they have the same offset. */
7626 die_eq (const void *item_lhs, const void *item_rhs)
7628 const struct die_info *die_lhs = item_lhs;
7629 const struct die_info *die_rhs = item_rhs;
7631 return die_lhs->offset == die_rhs->offset;
7634 /* Read a whole compilation unit into a linked list of dies. */
7636 static struct die_info *
7637 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
7639 struct die_reader_specs reader_specs;
7641 gdb_assert (cu->die_hash == NULL);
7643 = htab_create_alloc_ex (cu->header.length / 12,
7647 &cu->comp_unit_obstack,
7648 hashtab_obstack_allocate,
7649 dummy_obstack_deallocate);
7651 init_cu_die_reader (&reader_specs, cu);
7653 return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
7656 /* Main entry point for reading a DIE and all children.
7657 Read the DIE and dump it if requested. */
7659 static struct die_info *
7660 read_die_and_children (const struct die_reader_specs *reader,
7662 gdb_byte **new_info_ptr,
7663 struct die_info *parent)
7665 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
7666 new_info_ptr, parent);
7668 if (dwarf2_die_debug)
7670 fprintf_unfiltered (gdb_stdlog,
7671 "\nRead die from %s of %s:\n",
7672 reader->buffer == dwarf2_per_objfile->info.buffer
7674 : reader->buffer == dwarf2_per_objfile->types.buffer
7676 : "unknown section",
7677 reader->abfd->filename);
7678 dump_die (result, dwarf2_die_debug);
7684 /* Read a single die and all its descendents. Set the die's sibling
7685 field to NULL; set other fields in the die correctly, and set all
7686 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
7687 location of the info_ptr after reading all of those dies. PARENT
7688 is the parent of the die in question. */
7690 static struct die_info *
7691 read_die_and_children_1 (const struct die_reader_specs *reader,
7693 gdb_byte **new_info_ptr,
7694 struct die_info *parent)
7696 struct die_info *die;
7700 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
7703 *new_info_ptr = cur_ptr;
7706 store_in_ref_table (die, reader->cu);
7709 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
7713 *new_info_ptr = cur_ptr;
7716 die->sibling = NULL;
7717 die->parent = parent;
7721 /* Read a die, all of its descendents, and all of its siblings; set
7722 all of the fields of all of the dies correctly. Arguments are as
7723 in read_die_and_children. */
7725 static struct die_info *
7726 read_die_and_siblings (const struct die_reader_specs *reader,
7728 gdb_byte **new_info_ptr,
7729 struct die_info *parent)
7731 struct die_info *first_die, *last_sibling;
7735 first_die = last_sibling = NULL;
7739 struct die_info *die
7740 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
7744 *new_info_ptr = cur_ptr;
7751 last_sibling->sibling = die;
7757 /* Read the die from the .debug_info section buffer. Set DIEP to
7758 point to a newly allocated die with its information, except for its
7759 child, sibling, and parent fields. Set HAS_CHILDREN to tell
7760 whether the die has children or not. */
7763 read_full_die (const struct die_reader_specs *reader,
7764 struct die_info **diep, gdb_byte *info_ptr,
7767 unsigned int abbrev_number, bytes_read, i, offset;
7768 struct abbrev_info *abbrev;
7769 struct die_info *die;
7770 struct dwarf2_cu *cu = reader->cu;
7771 bfd *abfd = reader->abfd;
7773 offset = info_ptr - reader->buffer;
7774 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7775 info_ptr += bytes_read;
7783 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
7785 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
7787 bfd_get_filename (abfd));
7789 die = dwarf_alloc_die (cu, abbrev->num_attrs);
7790 die->offset = offset;
7791 die->tag = abbrev->tag;
7792 die->abbrev = abbrev_number;
7794 die->num_attrs = abbrev->num_attrs;
7796 for (i = 0; i < abbrev->num_attrs; ++i)
7797 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
7798 abfd, info_ptr, cu);
7801 *has_children = abbrev->has_children;
7805 /* In DWARF version 2, the description of the debugging information is
7806 stored in a separate .debug_abbrev section. Before we read any
7807 dies from a section we read in all abbreviations and install them
7808 in a hash table. This function also sets flags in CU describing
7809 the data found in the abbrev table. */
7812 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
7814 struct comp_unit_head *cu_header = &cu->header;
7815 gdb_byte *abbrev_ptr;
7816 struct abbrev_info *cur_abbrev;
7817 unsigned int abbrev_number, bytes_read, abbrev_name;
7818 unsigned int abbrev_form, hash_number;
7819 struct attr_abbrev *cur_attrs;
7820 unsigned int allocated_attrs;
7822 /* Initialize dwarf2 abbrevs */
7823 obstack_init (&cu->abbrev_obstack);
7824 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
7826 * sizeof (struct abbrev_info *)));
7827 memset (cu->dwarf2_abbrevs, 0,
7828 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
7830 dwarf2_read_section (dwarf2_per_objfile->objfile,
7831 &dwarf2_per_objfile->abbrev);
7832 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
7833 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7834 abbrev_ptr += bytes_read;
7836 allocated_attrs = ATTR_ALLOC_CHUNK;
7837 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
7839 /* loop until we reach an abbrev number of 0 */
7840 while (abbrev_number)
7842 cur_abbrev = dwarf_alloc_abbrev (cu);
7844 /* read in abbrev header */
7845 cur_abbrev->number = abbrev_number;
7846 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7847 abbrev_ptr += bytes_read;
7848 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
7851 if (cur_abbrev->tag == DW_TAG_namespace)
7852 cu->has_namespace_info = 1;
7854 /* now read in declarations */
7855 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7856 abbrev_ptr += bytes_read;
7857 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7858 abbrev_ptr += bytes_read;
7861 if (cur_abbrev->num_attrs == allocated_attrs)
7863 allocated_attrs += ATTR_ALLOC_CHUNK;
7865 = xrealloc (cur_attrs, (allocated_attrs
7866 * sizeof (struct attr_abbrev)));
7869 /* Record whether this compilation unit might have
7870 inter-compilation-unit references. If we don't know what form
7871 this attribute will have, then it might potentially be a
7872 DW_FORM_ref_addr, so we conservatively expect inter-CU
7875 if (abbrev_form == DW_FORM_ref_addr
7876 || abbrev_form == DW_FORM_indirect)
7877 cu->has_form_ref_addr = 1;
7879 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
7880 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
7881 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7882 abbrev_ptr += bytes_read;
7883 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7884 abbrev_ptr += bytes_read;
7887 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
7888 (cur_abbrev->num_attrs
7889 * sizeof (struct attr_abbrev)));
7890 memcpy (cur_abbrev->attrs, cur_attrs,
7891 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
7893 hash_number = abbrev_number % ABBREV_HASH_SIZE;
7894 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
7895 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
7897 /* Get next abbreviation.
7898 Under Irix6 the abbreviations for a compilation unit are not
7899 always properly terminated with an abbrev number of 0.
7900 Exit loop if we encounter an abbreviation which we have
7901 already read (which means we are about to read the abbreviations
7902 for the next compile unit) or if the end of the abbreviation
7903 table is reached. */
7904 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
7905 >= dwarf2_per_objfile->abbrev.size)
7907 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7908 abbrev_ptr += bytes_read;
7909 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
7916 /* Release the memory used by the abbrev table for a compilation unit. */
7919 dwarf2_free_abbrev_table (void *ptr_to_cu)
7921 struct dwarf2_cu *cu = ptr_to_cu;
7923 obstack_free (&cu->abbrev_obstack, NULL);
7924 cu->dwarf2_abbrevs = NULL;
7927 /* Lookup an abbrev_info structure in the abbrev hash table. */
7929 static struct abbrev_info *
7930 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
7932 unsigned int hash_number;
7933 struct abbrev_info *abbrev;
7935 hash_number = number % ABBREV_HASH_SIZE;
7936 abbrev = cu->dwarf2_abbrevs[hash_number];
7940 if (abbrev->number == number)
7943 abbrev = abbrev->next;
7948 /* Returns nonzero if TAG represents a type that we might generate a partial
7952 is_type_tag_for_partial (int tag)
7957 /* Some types that would be reasonable to generate partial symbols for,
7958 that we don't at present. */
7959 case DW_TAG_array_type:
7960 case DW_TAG_file_type:
7961 case DW_TAG_ptr_to_member_type:
7962 case DW_TAG_set_type:
7963 case DW_TAG_string_type:
7964 case DW_TAG_subroutine_type:
7966 case DW_TAG_base_type:
7967 case DW_TAG_class_type:
7968 case DW_TAG_interface_type:
7969 case DW_TAG_enumeration_type:
7970 case DW_TAG_structure_type:
7971 case DW_TAG_subrange_type:
7972 case DW_TAG_typedef:
7973 case DW_TAG_union_type:
7980 /* Load all DIEs that are interesting for partial symbols into memory. */
7982 static struct partial_die_info *
7983 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
7984 int building_psymtab, struct dwarf2_cu *cu)
7986 struct partial_die_info *part_die;
7987 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
7988 struct abbrev_info *abbrev;
7989 unsigned int bytes_read;
7990 unsigned int load_all = 0;
7992 int nesting_level = 1;
7997 if (cu->per_cu && cu->per_cu->load_all_dies)
8001 = htab_create_alloc_ex (cu->header.length / 12,
8005 &cu->comp_unit_obstack,
8006 hashtab_obstack_allocate,
8007 dummy_obstack_deallocate);
8009 part_die = obstack_alloc (&cu->comp_unit_obstack,
8010 sizeof (struct partial_die_info));
8014 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8016 /* A NULL abbrev means the end of a series of children. */
8019 if (--nesting_level == 0)
8021 /* PART_DIE was probably the last thing allocated on the
8022 comp_unit_obstack, so we could call obstack_free
8023 here. We don't do that because the waste is small,
8024 and will be cleaned up when we're done with this
8025 compilation unit. This way, we're also more robust
8026 against other users of the comp_unit_obstack. */
8029 info_ptr += bytes_read;
8030 last_die = parent_die;
8031 parent_die = parent_die->die_parent;
8035 /* Check whether this DIE is interesting enough to save. Normally
8036 we would not be interested in members here, but there may be
8037 later variables referencing them via DW_AT_specification (for
8040 && !is_type_tag_for_partial (abbrev->tag)
8041 && abbrev->tag != DW_TAG_enumerator
8042 && abbrev->tag != DW_TAG_subprogram
8043 && abbrev->tag != DW_TAG_lexical_block
8044 && abbrev->tag != DW_TAG_variable
8045 && abbrev->tag != DW_TAG_namespace
8046 && abbrev->tag != DW_TAG_module
8047 && abbrev->tag != DW_TAG_member)
8049 /* Otherwise we skip to the next sibling, if any. */
8050 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8054 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
8055 buffer, info_ptr, cu);
8057 /* This two-pass algorithm for processing partial symbols has a
8058 high cost in cache pressure. Thus, handle some simple cases
8059 here which cover the majority of C partial symbols. DIEs
8060 which neither have specification tags in them, nor could have
8061 specification tags elsewhere pointing at them, can simply be
8062 processed and discarded.
8064 This segment is also optional; scan_partial_symbols and
8065 add_partial_symbol will handle these DIEs if we chain
8066 them in normally. When compilers which do not emit large
8067 quantities of duplicate debug information are more common,
8068 this code can probably be removed. */
8070 /* Any complete simple types at the top level (pretty much all
8071 of them, for a language without namespaces), can be processed
8073 if (parent_die == NULL
8074 && part_die->has_specification == 0
8075 && part_die->is_declaration == 0
8076 && (part_die->tag == DW_TAG_typedef
8077 || part_die->tag == DW_TAG_base_type
8078 || part_die->tag == DW_TAG_subrange_type))
8080 if (building_psymtab && part_die->name != NULL)
8081 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8082 VAR_DOMAIN, LOC_TYPEDEF,
8083 &cu->objfile->static_psymbols,
8084 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8085 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8089 /* If we're at the second level, and we're an enumerator, and
8090 our parent has no specification (meaning possibly lives in a
8091 namespace elsewhere), then we can add the partial symbol now
8092 instead of queueing it. */
8093 if (part_die->tag == DW_TAG_enumerator
8094 && parent_die != NULL
8095 && parent_die->die_parent == NULL
8096 && parent_die->tag == DW_TAG_enumeration_type
8097 && parent_die->has_specification == 0)
8099 if (part_die->name == NULL)
8100 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
8101 else if (building_psymtab)
8102 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8103 VAR_DOMAIN, LOC_CONST,
8104 (cu->language == language_cplus
8105 || cu->language == language_java)
8106 ? &cu->objfile->global_psymbols
8107 : &cu->objfile->static_psymbols,
8108 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8110 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8114 /* We'll save this DIE so link it in. */
8115 part_die->die_parent = parent_die;
8116 part_die->die_sibling = NULL;
8117 part_die->die_child = NULL;
8119 if (last_die && last_die == parent_die)
8120 last_die->die_child = part_die;
8122 last_die->die_sibling = part_die;
8124 last_die = part_die;
8126 if (first_die == NULL)
8127 first_die = part_die;
8129 /* Maybe add the DIE to the hash table. Not all DIEs that we
8130 find interesting need to be in the hash table, because we
8131 also have the parent/sibling/child chains; only those that we
8132 might refer to by offset later during partial symbol reading.
8134 For now this means things that might have be the target of a
8135 DW_AT_specification, DW_AT_abstract_origin, or
8136 DW_AT_extension. DW_AT_extension will refer only to
8137 namespaces; DW_AT_abstract_origin refers to functions (and
8138 many things under the function DIE, but we do not recurse
8139 into function DIEs during partial symbol reading) and
8140 possibly variables as well; DW_AT_specification refers to
8141 declarations. Declarations ought to have the DW_AT_declaration
8142 flag. It happens that GCC forgets to put it in sometimes, but
8143 only for functions, not for types.
8145 Adding more things than necessary to the hash table is harmless
8146 except for the performance cost. Adding too few will result in
8147 wasted time in find_partial_die, when we reread the compilation
8148 unit with load_all_dies set. */
8151 || abbrev->tag == DW_TAG_subprogram
8152 || abbrev->tag == DW_TAG_variable
8153 || abbrev->tag == DW_TAG_namespace
8154 || part_die->is_declaration)
8158 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
8159 part_die->offset, INSERT);
8163 part_die = obstack_alloc (&cu->comp_unit_obstack,
8164 sizeof (struct partial_die_info));
8166 /* For some DIEs we want to follow their children (if any). For C
8167 we have no reason to follow the children of structures; for other
8168 languages we have to, both so that we can get at method physnames
8169 to infer fully qualified class names, and for DW_AT_specification.
8171 For Ada, we need to scan the children of subprograms and lexical
8172 blocks as well because Ada allows the definition of nested
8173 entities that could be interesting for the debugger, such as
8174 nested subprograms for instance. */
8175 if (last_die->has_children
8177 || last_die->tag == DW_TAG_namespace
8178 || last_die->tag == DW_TAG_module
8179 || last_die->tag == DW_TAG_enumeration_type
8180 || (cu->language != language_c
8181 && (last_die->tag == DW_TAG_class_type
8182 || last_die->tag == DW_TAG_interface_type
8183 || last_die->tag == DW_TAG_structure_type
8184 || last_die->tag == DW_TAG_union_type))
8185 || (cu->language == language_ada
8186 && (last_die->tag == DW_TAG_subprogram
8187 || last_die->tag == DW_TAG_lexical_block))))
8190 parent_die = last_die;
8194 /* Otherwise we skip to the next sibling, if any. */
8195 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
8197 /* Back to the top, do it again. */
8201 /* Read a minimal amount of information into the minimal die structure. */
8204 read_partial_die (struct partial_die_info *part_die,
8205 struct abbrev_info *abbrev,
8206 unsigned int abbrev_len, bfd *abfd,
8207 gdb_byte *buffer, gdb_byte *info_ptr,
8208 struct dwarf2_cu *cu)
8211 struct attribute attr;
8212 int has_low_pc_attr = 0;
8213 int has_high_pc_attr = 0;
8215 memset (part_die, 0, sizeof (struct partial_die_info));
8217 part_die->offset = info_ptr - buffer;
8219 info_ptr += abbrev_len;
8224 part_die->tag = abbrev->tag;
8225 part_die->has_children = abbrev->has_children;
8227 for (i = 0; i < abbrev->num_attrs; ++i)
8229 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
8231 /* Store the data if it is of an attribute we want to keep in a
8232 partial symbol table. */
8236 switch (part_die->tag)
8238 case DW_TAG_compile_unit:
8239 case DW_TAG_type_unit:
8240 /* Compilation units have a DW_AT_name that is a filename, not
8241 a source language identifier. */
8242 case DW_TAG_enumeration_type:
8243 case DW_TAG_enumerator:
8244 /* These tags always have simple identifiers already; no need
8245 to canonicalize them. */
8246 part_die->name = DW_STRING (&attr);
8250 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
8251 &cu->objfile->objfile_obstack);
8255 case DW_AT_linkage_name:
8256 case DW_AT_MIPS_linkage_name:
8257 /* Note that both forms of linkage name might appear. We
8258 assume they will be the same, and we only store the last
8260 if (cu->language == language_ada)
8261 part_die->name = DW_STRING (&attr);
8264 has_low_pc_attr = 1;
8265 part_die->lowpc = DW_ADDR (&attr);
8268 has_high_pc_attr = 1;
8269 part_die->highpc = DW_ADDR (&attr);
8271 case DW_AT_location:
8272 /* Support the .debug_loc offsets */
8273 if (attr_form_is_block (&attr))
8275 part_die->locdesc = DW_BLOCK (&attr);
8277 else if (attr_form_is_section_offset (&attr))
8279 dwarf2_complex_location_expr_complaint ();
8283 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8284 "partial symbol information");
8287 case DW_AT_external:
8288 part_die->is_external = DW_UNSND (&attr);
8290 case DW_AT_declaration:
8291 part_die->is_declaration = DW_UNSND (&attr);
8294 part_die->has_type = 1;
8296 case DW_AT_abstract_origin:
8297 case DW_AT_specification:
8298 case DW_AT_extension:
8299 part_die->has_specification = 1;
8300 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
8303 /* Ignore absolute siblings, they might point outside of
8304 the current compile unit. */
8305 if (attr.form == DW_FORM_ref_addr)
8306 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
8308 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
8310 case DW_AT_byte_size:
8311 part_die->has_byte_size = 1;
8313 case DW_AT_calling_convention:
8314 /* DWARF doesn't provide a way to identify a program's source-level
8315 entry point. DW_AT_calling_convention attributes are only meant
8316 to describe functions' calling conventions.
8318 However, because it's a necessary piece of information in
8319 Fortran, and because DW_CC_program is the only piece of debugging
8320 information whose definition refers to a 'main program' at all,
8321 several compilers have begun marking Fortran main programs with
8322 DW_CC_program --- even when those functions use the standard
8323 calling conventions.
8325 So until DWARF specifies a way to provide this information and
8326 compilers pick up the new representation, we'll support this
8328 if (DW_UNSND (&attr) == DW_CC_program
8329 && cu->language == language_fortran)
8330 set_main_name (part_die->name);
8337 /* When using the GNU linker, .gnu.linkonce. sections are used to
8338 eliminate duplicate copies of functions and vtables and such.
8339 The linker will arbitrarily choose one and discard the others.
8340 The AT_*_pc values for such functions refer to local labels in
8341 these sections. If the section from that file was discarded, the
8342 labels are not in the output, so the relocs get a value of 0.
8343 If this is a discarded function, mark the pc bounds as invalid,
8344 so that GDB will ignore it. */
8345 if (has_low_pc_attr && has_high_pc_attr
8346 && part_die->lowpc < part_die->highpc
8347 && (part_die->lowpc != 0
8348 || dwarf2_per_objfile->has_section_at_zero))
8349 part_die->has_pc_info = 1;
8354 /* Find a cached partial DIE at OFFSET in CU. */
8356 static struct partial_die_info *
8357 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
8359 struct partial_die_info *lookup_die = NULL;
8360 struct partial_die_info part_die;
8362 part_die.offset = offset;
8363 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
8368 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8369 except in the case of .debug_types DIEs which do not reference
8370 outside their CU (they do however referencing other types via
8373 static struct partial_die_info *
8374 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
8376 struct dwarf2_per_cu_data *per_cu = NULL;
8377 struct partial_die_info *pd = NULL;
8379 if (cu->per_cu->from_debug_types)
8381 pd = find_partial_die_in_comp_unit (offset, cu);
8387 if (offset_in_cu_p (&cu->header, offset))
8389 pd = find_partial_die_in_comp_unit (offset, cu);
8394 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
8396 if (per_cu->cu == NULL)
8398 load_partial_comp_unit (per_cu, cu->objfile);
8399 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
8400 dwarf2_per_objfile->read_in_chain = per_cu;
8403 per_cu->cu->last_used = 0;
8404 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8406 if (pd == NULL && per_cu->load_all_dies == 0)
8408 struct cleanup *back_to;
8409 struct partial_die_info comp_unit_die;
8410 struct abbrev_info *abbrev;
8411 unsigned int bytes_read;
8414 per_cu->load_all_dies = 1;
8416 /* Re-read the DIEs. */
8417 back_to = make_cleanup (null_cleanup, 0);
8418 if (per_cu->cu->dwarf2_abbrevs == NULL)
8420 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
8421 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
8423 info_ptr = (dwarf2_per_objfile->info.buffer
8424 + per_cu->cu->header.offset
8425 + per_cu->cu->header.first_die_offset);
8426 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
8427 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
8428 per_cu->cu->objfile->obfd,
8429 dwarf2_per_objfile->info.buffer, info_ptr,
8431 if (comp_unit_die.has_children)
8432 load_partial_dies (per_cu->cu->objfile->obfd,
8433 dwarf2_per_objfile->info.buffer, info_ptr,
8435 do_cleanups (back_to);
8437 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8443 internal_error (__FILE__, __LINE__,
8444 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8445 offset, bfd_get_filename (cu->objfile->obfd));
8449 /* Adjust PART_DIE before generating a symbol for it. This function
8450 may set the is_external flag or change the DIE's name. */
8453 fixup_partial_die (struct partial_die_info *part_die,
8454 struct dwarf2_cu *cu)
8456 /* If we found a reference attribute and the DIE has no name, try
8457 to find a name in the referred to DIE. */
8459 if (part_die->name == NULL && part_die->has_specification)
8461 struct partial_die_info *spec_die;
8463 spec_die = find_partial_die (part_die->spec_offset, cu);
8465 fixup_partial_die (spec_die, cu);
8469 part_die->name = spec_die->name;
8471 /* Copy DW_AT_external attribute if it is set. */
8472 if (spec_die->is_external)
8473 part_die->is_external = spec_die->is_external;
8477 /* Set default names for some unnamed DIEs. */
8478 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
8479 || part_die->tag == DW_TAG_class_type))
8480 part_die->name = "(anonymous class)";
8482 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
8483 part_die->name = "(anonymous namespace)";
8485 if (part_die->tag == DW_TAG_structure_type
8486 || part_die->tag == DW_TAG_class_type
8487 || part_die->tag == DW_TAG_union_type)
8488 guess_structure_name (part_die, cu);
8491 /* Read an attribute value described by an attribute form. */
8494 read_attribute_value (struct attribute *attr, unsigned form,
8495 bfd *abfd, gdb_byte *info_ptr,
8496 struct dwarf2_cu *cu)
8498 struct comp_unit_head *cu_header = &cu->header;
8499 unsigned int bytes_read;
8500 struct dwarf_block *blk;
8505 case DW_FORM_ref_addr:
8506 if (cu->header.version == 2)
8507 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
8509 DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
8510 info_ptr += bytes_read;
8513 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
8514 info_ptr += bytes_read;
8516 case DW_FORM_block2:
8517 blk = dwarf_alloc_block (cu);
8518 blk->size = read_2_bytes (abfd, info_ptr);
8520 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8521 info_ptr += blk->size;
8522 DW_BLOCK (attr) = blk;
8524 case DW_FORM_block4:
8525 blk = dwarf_alloc_block (cu);
8526 blk->size = read_4_bytes (abfd, info_ptr);
8528 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8529 info_ptr += blk->size;
8530 DW_BLOCK (attr) = blk;
8533 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
8537 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
8541 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
8544 case DW_FORM_sec_offset:
8545 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
8546 info_ptr += bytes_read;
8548 case DW_FORM_string:
8549 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
8550 DW_STRING_IS_CANONICAL (attr) = 0;
8551 info_ptr += bytes_read;
8554 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
8556 DW_STRING_IS_CANONICAL (attr) = 0;
8557 info_ptr += bytes_read;
8559 case DW_FORM_exprloc:
8561 blk = dwarf_alloc_block (cu);
8562 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8563 info_ptr += bytes_read;
8564 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8565 info_ptr += blk->size;
8566 DW_BLOCK (attr) = blk;
8568 case DW_FORM_block1:
8569 blk = dwarf_alloc_block (cu);
8570 blk->size = read_1_byte (abfd, info_ptr);
8572 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8573 info_ptr += blk->size;
8574 DW_BLOCK (attr) = blk;
8577 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
8581 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
8584 case DW_FORM_flag_present:
8585 DW_UNSND (attr) = 1;
8588 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
8589 info_ptr += bytes_read;
8592 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8593 info_ptr += bytes_read;
8596 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
8600 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
8604 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
8608 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
8612 /* Convert the signature to something we can record in DW_UNSND
8614 NOTE: This is NULL if the type wasn't found. */
8615 DW_SIGNATURED_TYPE (attr) =
8616 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
8619 case DW_FORM_ref_udata:
8620 DW_ADDR (attr) = (cu->header.offset
8621 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
8622 info_ptr += bytes_read;
8624 case DW_FORM_indirect:
8625 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8626 info_ptr += bytes_read;
8627 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
8630 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
8631 dwarf_form_name (form),
8632 bfd_get_filename (abfd));
8635 /* We have seen instances where the compiler tried to emit a byte
8636 size attribute of -1 which ended up being encoded as an unsigned
8637 0xffffffff. Although 0xffffffff is technically a valid size value,
8638 an object of this size seems pretty unlikely so we can relatively
8639 safely treat these cases as if the size attribute was invalid and
8640 treat them as zero by default. */
8641 if (attr->name == DW_AT_byte_size
8642 && form == DW_FORM_data4
8643 && DW_UNSND (attr) >= 0xffffffff)
8646 (&symfile_complaints,
8647 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
8648 hex_string (DW_UNSND (attr)));
8649 DW_UNSND (attr) = 0;
8655 /* Read an attribute described by an abbreviated attribute. */
8658 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
8659 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
8661 attr->name = abbrev->name;
8662 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
8665 /* read dwarf information from a buffer */
8668 read_1_byte (bfd *abfd, gdb_byte *buf)
8670 return bfd_get_8 (abfd, buf);
8674 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
8676 return bfd_get_signed_8 (abfd, buf);
8680 read_2_bytes (bfd *abfd, gdb_byte *buf)
8682 return bfd_get_16 (abfd, buf);
8686 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
8688 return bfd_get_signed_16 (abfd, buf);
8692 read_4_bytes (bfd *abfd, gdb_byte *buf)
8694 return bfd_get_32 (abfd, buf);
8698 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
8700 return bfd_get_signed_32 (abfd, buf);
8704 read_8_bytes (bfd *abfd, gdb_byte *buf)
8706 return bfd_get_64 (abfd, buf);
8710 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
8711 unsigned int *bytes_read)
8713 struct comp_unit_head *cu_header = &cu->header;
8714 CORE_ADDR retval = 0;
8716 if (cu_header->signed_addr_p)
8718 switch (cu_header->addr_size)
8721 retval = bfd_get_signed_16 (abfd, buf);
8724 retval = bfd_get_signed_32 (abfd, buf);
8727 retval = bfd_get_signed_64 (abfd, buf);
8730 internal_error (__FILE__, __LINE__,
8731 _("read_address: bad switch, signed [in module %s]"),
8732 bfd_get_filename (abfd));
8737 switch (cu_header->addr_size)
8740 retval = bfd_get_16 (abfd, buf);
8743 retval = bfd_get_32 (abfd, buf);
8746 retval = bfd_get_64 (abfd, buf);
8749 internal_error (__FILE__, __LINE__,
8750 _("read_address: bad switch, unsigned [in module %s]"),
8751 bfd_get_filename (abfd));
8755 *bytes_read = cu_header->addr_size;
8759 /* Read the initial length from a section. The (draft) DWARF 3
8760 specification allows the initial length to take up either 4 bytes
8761 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
8762 bytes describe the length and all offsets will be 8 bytes in length
8765 An older, non-standard 64-bit format is also handled by this
8766 function. The older format in question stores the initial length
8767 as an 8-byte quantity without an escape value. Lengths greater
8768 than 2^32 aren't very common which means that the initial 4 bytes
8769 is almost always zero. Since a length value of zero doesn't make
8770 sense for the 32-bit format, this initial zero can be considered to
8771 be an escape value which indicates the presence of the older 64-bit
8772 format. As written, the code can't detect (old format) lengths
8773 greater than 4GB. If it becomes necessary to handle lengths
8774 somewhat larger than 4GB, we could allow other small values (such
8775 as the non-sensical values of 1, 2, and 3) to also be used as
8776 escape values indicating the presence of the old format.
8778 The value returned via bytes_read should be used to increment the
8779 relevant pointer after calling read_initial_length().
8781 [ Note: read_initial_length() and read_offset() are based on the
8782 document entitled "DWARF Debugging Information Format", revision
8783 3, draft 8, dated November 19, 2001. This document was obtained
8786 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
8788 This document is only a draft and is subject to change. (So beware.)
8790 Details regarding the older, non-standard 64-bit format were
8791 determined empirically by examining 64-bit ELF files produced by
8792 the SGI toolchain on an IRIX 6.5 machine.
8794 - Kevin, July 16, 2002
8798 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
8800 LONGEST length = bfd_get_32 (abfd, buf);
8802 if (length == 0xffffffff)
8804 length = bfd_get_64 (abfd, buf + 4);
8807 else if (length == 0)
8809 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
8810 length = bfd_get_64 (abfd, buf);
8821 /* Cover function for read_initial_length.
8822 Returns the length of the object at BUF, and stores the size of the
8823 initial length in *BYTES_READ and stores the size that offsets will be in
8825 If the initial length size is not equivalent to that specified in
8826 CU_HEADER then issue a complaint.
8827 This is useful when reading non-comp-unit headers. */
8830 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
8831 const struct comp_unit_head *cu_header,
8832 unsigned int *bytes_read,
8833 unsigned int *offset_size)
8835 LONGEST length = read_initial_length (abfd, buf, bytes_read);
8837 gdb_assert (cu_header->initial_length_size == 4
8838 || cu_header->initial_length_size == 8
8839 || cu_header->initial_length_size == 12);
8841 if (cu_header->initial_length_size != *bytes_read)
8842 complaint (&symfile_complaints,
8843 _("intermixed 32-bit and 64-bit DWARF sections"));
8845 *offset_size = (*bytes_read == 4) ? 4 : 8;
8849 /* Read an offset from the data stream. The size of the offset is
8850 given by cu_header->offset_size. */
8853 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
8854 unsigned int *bytes_read)
8856 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
8858 *bytes_read = cu_header->offset_size;
8862 /* Read an offset from the data stream. */
8865 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
8869 switch (offset_size)
8872 retval = bfd_get_32 (abfd, buf);
8875 retval = bfd_get_64 (abfd, buf);
8878 internal_error (__FILE__, __LINE__,
8879 _("read_offset_1: bad switch [in module %s]"),
8880 bfd_get_filename (abfd));
8887 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
8889 /* If the size of a host char is 8 bits, we can return a pointer
8890 to the buffer, otherwise we have to copy the data to a buffer
8891 allocated on the temporary obstack. */
8892 gdb_assert (HOST_CHAR_BIT == 8);
8897 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8899 /* If the size of a host char is 8 bits, we can return a pointer
8900 to the string, otherwise we have to copy the string to a buffer
8901 allocated on the temporary obstack. */
8902 gdb_assert (HOST_CHAR_BIT == 8);
8905 *bytes_read_ptr = 1;
8908 *bytes_read_ptr = strlen ((char *) buf) + 1;
8909 return (char *) buf;
8913 read_indirect_string (bfd *abfd, gdb_byte *buf,
8914 const struct comp_unit_head *cu_header,
8915 unsigned int *bytes_read_ptr)
8917 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
8919 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
8920 if (dwarf2_per_objfile->str.buffer == NULL)
8922 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
8923 bfd_get_filename (abfd));
8926 if (str_offset >= dwarf2_per_objfile->str.size)
8928 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
8929 bfd_get_filename (abfd));
8932 gdb_assert (HOST_CHAR_BIT == 8);
8933 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
8935 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
8938 static unsigned long
8939 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8941 unsigned long result;
8942 unsigned int num_read;
8952 byte = bfd_get_8 (abfd, buf);
8955 result |= ((unsigned long)(byte & 127) << shift);
8956 if ((byte & 128) == 0)
8962 *bytes_read_ptr = num_read;
8967 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8970 int i, shift, num_read;
8979 byte = bfd_get_8 (abfd, buf);
8982 result |= ((long)(byte & 127) << shift);
8984 if ((byte & 128) == 0)
8989 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
8990 result |= -(((long)1) << shift);
8991 *bytes_read_ptr = num_read;
8995 /* Return a pointer to just past the end of an LEB128 number in BUF. */
8998 skip_leb128 (bfd *abfd, gdb_byte *buf)
9004 byte = bfd_get_8 (abfd, buf);
9006 if ((byte & 128) == 0)
9012 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
9019 cu->language = language_c;
9021 case DW_LANG_C_plus_plus:
9022 cu->language = language_cplus;
9025 cu->language = language_d;
9027 case DW_LANG_Fortran77:
9028 case DW_LANG_Fortran90:
9029 case DW_LANG_Fortran95:
9030 cu->language = language_fortran;
9032 case DW_LANG_Mips_Assembler:
9033 cu->language = language_asm;
9036 cu->language = language_java;
9040 cu->language = language_ada;
9042 case DW_LANG_Modula2:
9043 cu->language = language_m2;
9045 case DW_LANG_Pascal83:
9046 cu->language = language_pascal;
9049 cu->language = language_objc;
9051 case DW_LANG_Cobol74:
9052 case DW_LANG_Cobol85:
9054 cu->language = language_minimal;
9057 cu->language_defn = language_def (cu->language);
9060 /* Return the named attribute or NULL if not there. */
9062 static struct attribute *
9063 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
9066 struct attribute *spec = NULL;
9068 for (i = 0; i < die->num_attrs; ++i)
9070 if (die->attrs[i].name == name)
9071 return &die->attrs[i];
9072 if (die->attrs[i].name == DW_AT_specification
9073 || die->attrs[i].name == DW_AT_abstract_origin)
9074 spec = &die->attrs[i];
9079 die = follow_die_ref (die, spec, &cu);
9080 return dwarf2_attr (die, name, cu);
9086 /* Return the named attribute or NULL if not there,
9087 but do not follow DW_AT_specification, etc.
9088 This is for use in contexts where we're reading .debug_types dies.
9089 Following DW_AT_specification, DW_AT_abstract_origin will take us
9090 back up the chain, and we want to go down. */
9092 static struct attribute *
9093 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
9094 struct dwarf2_cu *cu)
9098 for (i = 0; i < die->num_attrs; ++i)
9099 if (die->attrs[i].name == name)
9100 return &die->attrs[i];
9105 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9106 and holds a non-zero value. This function should only be used for
9107 DW_FORM_flag or DW_FORM_flag_present attributes. */
9110 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
9112 struct attribute *attr = dwarf2_attr (die, name, cu);
9114 return (attr && DW_UNSND (attr));
9118 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
9120 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9121 which value is non-zero. However, we have to be careful with
9122 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9123 (via dwarf2_flag_true_p) follows this attribute. So we may
9124 end up accidently finding a declaration attribute that belongs
9125 to a different DIE referenced by the specification attribute,
9126 even though the given DIE does not have a declaration attribute. */
9127 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
9128 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
9131 /* Return the die giving the specification for DIE, if there is
9132 one. *SPEC_CU is the CU containing DIE on input, and the CU
9133 containing the return value on output. If there is no
9134 specification, but there is an abstract origin, that is
9137 static struct die_info *
9138 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
9140 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
9143 if (spec_attr == NULL)
9144 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
9146 if (spec_attr == NULL)
9149 return follow_die_ref (die, spec_attr, spec_cu);
9152 /* Free the line_header structure *LH, and any arrays and strings it
9155 free_line_header (struct line_header *lh)
9157 if (lh->standard_opcode_lengths)
9158 xfree (lh->standard_opcode_lengths);
9160 /* Remember that all the lh->file_names[i].name pointers are
9161 pointers into debug_line_buffer, and don't need to be freed. */
9163 xfree (lh->file_names);
9165 /* Similarly for the include directory names. */
9166 if (lh->include_dirs)
9167 xfree (lh->include_dirs);
9173 /* Add an entry to LH's include directory table. */
9175 add_include_dir (struct line_header *lh, char *include_dir)
9177 /* Grow the array if necessary. */
9178 if (lh->include_dirs_size == 0)
9180 lh->include_dirs_size = 1; /* for testing */
9181 lh->include_dirs = xmalloc (lh->include_dirs_size
9182 * sizeof (*lh->include_dirs));
9184 else if (lh->num_include_dirs >= lh->include_dirs_size)
9186 lh->include_dirs_size *= 2;
9187 lh->include_dirs = xrealloc (lh->include_dirs,
9188 (lh->include_dirs_size
9189 * sizeof (*lh->include_dirs)));
9192 lh->include_dirs[lh->num_include_dirs++] = include_dir;
9196 /* Add an entry to LH's file name table. */
9198 add_file_name (struct line_header *lh,
9200 unsigned int dir_index,
9201 unsigned int mod_time,
9202 unsigned int length)
9204 struct file_entry *fe;
9206 /* Grow the array if necessary. */
9207 if (lh->file_names_size == 0)
9209 lh->file_names_size = 1; /* for testing */
9210 lh->file_names = xmalloc (lh->file_names_size
9211 * sizeof (*lh->file_names));
9213 else if (lh->num_file_names >= lh->file_names_size)
9215 lh->file_names_size *= 2;
9216 lh->file_names = xrealloc (lh->file_names,
9217 (lh->file_names_size
9218 * sizeof (*lh->file_names)));
9221 fe = &lh->file_names[lh->num_file_names++];
9223 fe->dir_index = dir_index;
9224 fe->mod_time = mod_time;
9225 fe->length = length;
9231 /* Read the statement program header starting at OFFSET in
9232 .debug_line, according to the endianness of ABFD. Return a pointer
9233 to a struct line_header, allocated using xmalloc.
9235 NOTE: the strings in the include directory and file name tables of
9236 the returned object point into debug_line_buffer, and must not be
9238 static struct line_header *
9239 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
9240 struct dwarf2_cu *cu)
9242 struct cleanup *back_to;
9243 struct line_header *lh;
9245 unsigned int bytes_read, offset_size;
9247 char *cur_dir, *cur_file;
9249 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
9250 if (dwarf2_per_objfile->line.buffer == NULL)
9252 complaint (&symfile_complaints, _("missing .debug_line section"));
9256 /* Make sure that at least there's room for the total_length field.
9257 That could be 12 bytes long, but we're just going to fudge that. */
9258 if (offset + 4 >= dwarf2_per_objfile->line.size)
9260 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9264 lh = xmalloc (sizeof (*lh));
9265 memset (lh, 0, sizeof (*lh));
9266 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
9269 line_ptr = dwarf2_per_objfile->line.buffer + offset;
9271 /* Read in the header. */
9273 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
9274 &bytes_read, &offset_size);
9275 line_ptr += bytes_read;
9276 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
9277 + dwarf2_per_objfile->line.size))
9279 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9282 lh->statement_program_end = line_ptr + lh->total_length;
9283 lh->version = read_2_bytes (abfd, line_ptr);
9285 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
9286 line_ptr += offset_size;
9287 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
9289 if (lh->version >= 4)
9291 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
9295 lh->maximum_ops_per_instruction = 1;
9297 if (lh->maximum_ops_per_instruction == 0)
9299 lh->maximum_ops_per_instruction = 1;
9300 complaint (&symfile_complaints,
9301 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9304 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
9306 lh->line_base = read_1_signed_byte (abfd, line_ptr);
9308 lh->line_range = read_1_byte (abfd, line_ptr);
9310 lh->opcode_base = read_1_byte (abfd, line_ptr);
9312 lh->standard_opcode_lengths
9313 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
9315 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
9316 for (i = 1; i < lh->opcode_base; ++i)
9318 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
9322 /* Read directory table. */
9323 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
9325 line_ptr += bytes_read;
9326 add_include_dir (lh, cur_dir);
9328 line_ptr += bytes_read;
9330 /* Read file name table. */
9331 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
9333 unsigned int dir_index, mod_time, length;
9335 line_ptr += bytes_read;
9336 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9337 line_ptr += bytes_read;
9338 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9339 line_ptr += bytes_read;
9340 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9341 line_ptr += bytes_read;
9343 add_file_name (lh, cur_file, dir_index, mod_time, length);
9345 line_ptr += bytes_read;
9346 lh->statement_program_start = line_ptr;
9348 if (line_ptr > (dwarf2_per_objfile->line.buffer
9349 + dwarf2_per_objfile->line.size))
9350 complaint (&symfile_complaints,
9351 _("line number info header doesn't fit in `.debug_line' section"));
9353 discard_cleanups (back_to);
9357 /* This function exists to work around a bug in certain compilers
9358 (particularly GCC 2.95), in which the first line number marker of a
9359 function does not show up until after the prologue, right before
9360 the second line number marker. This function shifts ADDRESS down
9361 to the beginning of the function if necessary, and is called on
9362 addresses passed to record_line. */
9365 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
9367 struct function_range *fn;
9369 /* Find the function_range containing address. */
9374 cu->cached_fn = cu->first_fn;
9378 if (fn->lowpc <= address && fn->highpc > address)
9384 while (fn && fn != cu->cached_fn)
9385 if (fn->lowpc <= address && fn->highpc > address)
9395 if (address != fn->lowpc)
9396 complaint (&symfile_complaints,
9397 _("misplaced first line number at 0x%lx for '%s'"),
9398 (unsigned long) address, fn->name);
9403 /* Decode the Line Number Program (LNP) for the given line_header
9404 structure and CU. The actual information extracted and the type
9405 of structures created from the LNP depends on the value of PST.
9407 1. If PST is NULL, then this procedure uses the data from the program
9408 to create all necessary symbol tables, and their linetables.
9409 The compilation directory of the file is passed in COMP_DIR,
9410 and must not be NULL.
9412 2. If PST is not NULL, this procedure reads the program to determine
9413 the list of files included by the unit represented by PST, and
9414 builds all the associated partial symbol tables. In this case,
9415 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9416 is not used to compute the full name of the symtab, and therefore
9417 omitting it when building the partial symtab does not introduce
9418 the potential for inconsistency - a partial symtab and its associated
9419 symbtab having a different fullname -). */
9422 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
9423 struct dwarf2_cu *cu, struct partial_symtab *pst)
9425 gdb_byte *line_ptr, *extended_end;
9427 unsigned int bytes_read, extended_len;
9428 unsigned char op_code, extended_op, adj_opcode;
9430 struct objfile *objfile = cu->objfile;
9431 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9432 const int decode_for_pst_p = (pst != NULL);
9433 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
9435 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9437 line_ptr = lh->statement_program_start;
9438 line_end = lh->statement_program_end;
9440 /* Read the statement sequences until there's nothing left. */
9441 while (line_ptr < line_end)
9443 /* state machine registers */
9444 CORE_ADDR address = 0;
9445 unsigned int file = 1;
9446 unsigned int line = 1;
9447 unsigned int column = 0;
9448 int is_stmt = lh->default_is_stmt;
9449 int basic_block = 0;
9450 int end_sequence = 0;
9452 unsigned char op_index = 0;
9454 if (!decode_for_pst_p && lh->num_file_names >= file)
9456 /* Start a subfile for the current file of the state machine. */
9457 /* lh->include_dirs and lh->file_names are 0-based, but the
9458 directory and file name numbers in the statement program
9460 struct file_entry *fe = &lh->file_names[file - 1];
9464 dir = lh->include_dirs[fe->dir_index - 1];
9466 dwarf2_start_subfile (fe->name, dir, comp_dir);
9469 /* Decode the table. */
9470 while (!end_sequence)
9472 op_code = read_1_byte (abfd, line_ptr);
9474 if (line_ptr > line_end)
9476 dwarf2_debug_line_missing_end_sequence_complaint ();
9480 if (op_code >= lh->opcode_base)
9482 /* Special operand. */
9483 adj_opcode = op_code - lh->opcode_base;
9484 address += (((op_index + (adj_opcode / lh->line_range))
9485 / lh->maximum_ops_per_instruction)
9486 * lh->minimum_instruction_length);
9487 op_index = ((op_index + (adj_opcode / lh->line_range))
9488 % lh->maximum_ops_per_instruction);
9489 line += lh->line_base + (adj_opcode % lh->line_range);
9490 if (lh->num_file_names < file || file == 0)
9491 dwarf2_debug_line_missing_file_complaint ();
9492 /* For now we ignore lines not starting on an
9493 instruction boundary. */
9494 else if (op_index == 0)
9496 lh->file_names[file - 1].included_p = 1;
9497 if (!decode_for_pst_p && is_stmt)
9499 if (last_subfile != current_subfile)
9501 addr = gdbarch_addr_bits_remove (gdbarch, address);
9503 record_line (last_subfile, 0, addr);
9504 last_subfile = current_subfile;
9506 /* Append row to matrix using current values. */
9507 addr = check_cu_functions (address, cu);
9508 addr = gdbarch_addr_bits_remove (gdbarch, addr);
9509 record_line (current_subfile, line, addr);
9514 else switch (op_code)
9516 case DW_LNS_extended_op:
9517 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9518 line_ptr += bytes_read;
9519 extended_end = line_ptr + extended_len;
9520 extended_op = read_1_byte (abfd, line_ptr);
9522 switch (extended_op)
9524 case DW_LNE_end_sequence:
9527 case DW_LNE_set_address:
9528 address = read_address (abfd, line_ptr, cu, &bytes_read);
9530 line_ptr += bytes_read;
9531 address += baseaddr;
9533 case DW_LNE_define_file:
9536 unsigned int dir_index, mod_time, length;
9538 cur_file = read_direct_string (abfd, line_ptr, &bytes_read);
9539 line_ptr += bytes_read;
9541 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9542 line_ptr += bytes_read;
9544 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9545 line_ptr += bytes_read;
9547 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9548 line_ptr += bytes_read;
9549 add_file_name (lh, cur_file, dir_index, mod_time, length);
9552 case DW_LNE_set_discriminator:
9553 /* The discriminator is not interesting to the debugger;
9555 line_ptr = extended_end;
9558 complaint (&symfile_complaints,
9559 _("mangled .debug_line section"));
9562 /* Make sure that we parsed the extended op correctly. If e.g.
9563 we expected a different address size than the producer used,
9564 we may have read the wrong number of bytes. */
9565 if (line_ptr != extended_end)
9567 complaint (&symfile_complaints,
9568 _("mangled .debug_line section"));
9573 if (lh->num_file_names < file || file == 0)
9574 dwarf2_debug_line_missing_file_complaint ();
9577 lh->file_names[file - 1].included_p = 1;
9578 if (!decode_for_pst_p && is_stmt)
9580 if (last_subfile != current_subfile)
9582 addr = gdbarch_addr_bits_remove (gdbarch, address);
9584 record_line (last_subfile, 0, addr);
9585 last_subfile = current_subfile;
9587 addr = check_cu_functions (address, cu);
9588 addr = gdbarch_addr_bits_remove (gdbarch, addr);
9589 record_line (current_subfile, line, addr);
9594 case DW_LNS_advance_pc:
9597 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9599 address += (((op_index + adjust)
9600 / lh->maximum_ops_per_instruction)
9601 * lh->minimum_instruction_length);
9602 op_index = ((op_index + adjust)
9603 % lh->maximum_ops_per_instruction);
9604 line_ptr += bytes_read;
9607 case DW_LNS_advance_line:
9608 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
9609 line_ptr += bytes_read;
9611 case DW_LNS_set_file:
9613 /* The arrays lh->include_dirs and lh->file_names are
9614 0-based, but the directory and file name numbers in
9615 the statement program are 1-based. */
9616 struct file_entry *fe;
9619 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9620 line_ptr += bytes_read;
9621 if (lh->num_file_names < file || file == 0)
9622 dwarf2_debug_line_missing_file_complaint ();
9625 fe = &lh->file_names[file - 1];
9627 dir = lh->include_dirs[fe->dir_index - 1];
9628 if (!decode_for_pst_p)
9630 last_subfile = current_subfile;
9631 dwarf2_start_subfile (fe->name, dir, comp_dir);
9636 case DW_LNS_set_column:
9637 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9638 line_ptr += bytes_read;
9640 case DW_LNS_negate_stmt:
9641 is_stmt = (!is_stmt);
9643 case DW_LNS_set_basic_block:
9646 /* Add to the address register of the state machine the
9647 address increment value corresponding to special opcode
9648 255. I.e., this value is scaled by the minimum
9649 instruction length since special opcode 255 would have
9650 scaled the the increment. */
9651 case DW_LNS_const_add_pc:
9653 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
9655 address += (((op_index + adjust)
9656 / lh->maximum_ops_per_instruction)
9657 * lh->minimum_instruction_length);
9658 op_index = ((op_index + adjust)
9659 % lh->maximum_ops_per_instruction);
9662 case DW_LNS_fixed_advance_pc:
9663 address += read_2_bytes (abfd, line_ptr);
9669 /* Unknown standard opcode, ignore it. */
9672 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
9674 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9675 line_ptr += bytes_read;
9680 if (lh->num_file_names < file || file == 0)
9681 dwarf2_debug_line_missing_file_complaint ();
9684 lh->file_names[file - 1].included_p = 1;
9685 if (!decode_for_pst_p)
9687 addr = gdbarch_addr_bits_remove (gdbarch, address);
9688 record_line (current_subfile, 0, addr);
9693 if (decode_for_pst_p)
9697 /* Now that we're done scanning the Line Header Program, we can
9698 create the psymtab of each included file. */
9699 for (file_index = 0; file_index < lh->num_file_names; file_index++)
9700 if (lh->file_names[file_index].included_p == 1)
9702 const struct file_entry fe = lh->file_names [file_index];
9703 char *include_name = fe.name;
9704 char *dir_name = NULL;
9705 char *pst_filename = pst->filename;
9708 dir_name = lh->include_dirs[fe.dir_index - 1];
9710 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
9712 include_name = concat (dir_name, SLASH_STRING,
9713 include_name, (char *)NULL);
9714 make_cleanup (xfree, include_name);
9717 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
9719 pst_filename = concat (pst->dirname, SLASH_STRING,
9720 pst_filename, (char *)NULL);
9721 make_cleanup (xfree, pst_filename);
9724 if (strcmp (include_name, pst_filename) != 0)
9725 dwarf2_create_include_psymtab (include_name, pst, objfile);
9730 /* Make sure a symtab is created for every file, even files
9731 which contain only variables (i.e. no code with associated
9735 struct file_entry *fe;
9737 for (i = 0; i < lh->num_file_names; i++)
9741 fe = &lh->file_names[i];
9743 dir = lh->include_dirs[fe->dir_index - 1];
9744 dwarf2_start_subfile (fe->name, dir, comp_dir);
9746 /* Skip the main file; we don't need it, and it must be
9747 allocated last, so that it will show up before the
9748 non-primary symtabs in the objfile's symtab list. */
9749 if (current_subfile == first_subfile)
9752 if (current_subfile->symtab == NULL)
9753 current_subfile->symtab = allocate_symtab (current_subfile->name,
9755 fe->symtab = current_subfile->symtab;
9760 /* Start a subfile for DWARF. FILENAME is the name of the file and
9761 DIRNAME the name of the source directory which contains FILENAME
9762 or NULL if not known. COMP_DIR is the compilation directory for the
9763 linetable's compilation unit or NULL if not known.
9764 This routine tries to keep line numbers from identical absolute and
9765 relative file names in a common subfile.
9767 Using the `list' example from the GDB testsuite, which resides in
9768 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
9769 of /srcdir/list0.c yields the following debugging information for list0.c:
9771 DW_AT_name: /srcdir/list0.c
9772 DW_AT_comp_dir: /compdir
9773 files.files[0].name: list0.h
9774 files.files[0].dir: /srcdir
9775 files.files[1].name: list0.c
9776 files.files[1].dir: /srcdir
9778 The line number information for list0.c has to end up in a single
9779 subfile, so that `break /srcdir/list0.c:1' works as expected.
9780 start_subfile will ensure that this happens provided that we pass the
9781 concatenation of files.files[1].dir and files.files[1].name as the
9785 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
9789 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
9790 `start_symtab' will always pass the contents of DW_AT_comp_dir as
9791 second argument to start_subfile. To be consistent, we do the
9792 same here. In order not to lose the line information directory,
9793 we concatenate it to the filename when it makes sense.
9794 Note that the Dwarf3 standard says (speaking of filenames in line
9795 information): ``The directory index is ignored for file names
9796 that represent full path names''. Thus ignoring dirname in the
9797 `else' branch below isn't an issue. */
9799 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
9800 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
9802 fullname = filename;
9804 start_subfile (fullname, comp_dir);
9806 if (fullname != filename)
9811 var_decode_location (struct attribute *attr, struct symbol *sym,
9812 struct dwarf2_cu *cu)
9814 struct objfile *objfile = cu->objfile;
9815 struct comp_unit_head *cu_header = &cu->header;
9817 /* NOTE drow/2003-01-30: There used to be a comment and some special
9818 code here to turn a symbol with DW_AT_external and a
9819 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
9820 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
9821 with some versions of binutils) where shared libraries could have
9822 relocations against symbols in their debug information - the
9823 minimal symbol would have the right address, but the debug info
9824 would not. It's no longer necessary, because we will explicitly
9825 apply relocations when we read in the debug information now. */
9827 /* A DW_AT_location attribute with no contents indicates that a
9828 variable has been optimized away. */
9829 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
9831 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
9835 /* Handle one degenerate form of location expression specially, to
9836 preserve GDB's previous behavior when section offsets are
9837 specified. If this is just a DW_OP_addr then mark this symbol
9840 if (attr_form_is_block (attr)
9841 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
9842 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
9846 SYMBOL_VALUE_ADDRESS (sym) =
9847 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
9848 SYMBOL_CLASS (sym) = LOC_STATIC;
9849 fixup_symbol_section (sym, objfile);
9850 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
9851 SYMBOL_SECTION (sym));
9855 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
9856 expression evaluator, and use LOC_COMPUTED only when necessary
9857 (i.e. when the value of a register or memory location is
9858 referenced, or a thread-local block, etc.). Then again, it might
9859 not be worthwhile. I'm assuming that it isn't unless performance
9860 or memory numbers show me otherwise. */
9862 dwarf2_symbol_mark_computed (attr, sym, cu);
9863 SYMBOL_CLASS (sym) = LOC_COMPUTED;
9866 /* Given a pointer to a DWARF information entry, figure out if we need
9867 to make a symbol table entry for it, and if so, create a new entry
9868 and return a pointer to it.
9869 If TYPE is NULL, determine symbol type from the die, otherwise
9870 used the passed type. */
9872 static struct symbol *
9873 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
9875 struct objfile *objfile = cu->objfile;
9876 struct symbol *sym = NULL;
9878 struct attribute *attr = NULL;
9879 struct attribute *attr2 = NULL;
9881 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
9883 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9885 name = dwarf2_name (die, cu);
9888 const char *linkagename;
9890 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
9891 sizeof (struct symbol));
9892 OBJSTAT (objfile, n_syms++);
9893 memset (sym, 0, sizeof (struct symbol));
9895 /* Cache this symbol's name and the name's demangled form (if any). */
9896 SYMBOL_LANGUAGE (sym) = cu->language;
9897 linkagename = dwarf2_physname (name, die, cu);
9898 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
9900 /* Fortran does not have mangling standard and the mangling does differ
9901 between gfortran, iFort etc. */
9902 if (cu->language == language_fortran
9903 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
9904 symbol_set_demangled_name (&(sym->ginfo),
9905 (char *) dwarf2_full_name (name, die, cu),
9908 /* Default assumptions.
9909 Use the passed type or decode it from the die. */
9910 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9911 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
9913 SYMBOL_TYPE (sym) = type;
9915 SYMBOL_TYPE (sym) = die_type (die, cu);
9916 attr = dwarf2_attr (die,
9917 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
9921 SYMBOL_LINE (sym) = DW_UNSND (attr);
9924 attr = dwarf2_attr (die,
9925 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
9929 int file_index = DW_UNSND (attr);
9931 if (cu->line_header == NULL
9932 || file_index > cu->line_header->num_file_names)
9933 complaint (&symfile_complaints,
9934 _("file index out of range"));
9935 else if (file_index > 0)
9937 struct file_entry *fe;
9939 fe = &cu->line_header->file_names[file_index - 1];
9940 SYMBOL_SYMTAB (sym) = fe->symtab;
9947 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
9950 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
9952 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
9953 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
9954 SYMBOL_CLASS (sym) = LOC_LABEL;
9955 add_symbol_to_list (sym, cu->list_in_scope);
9957 case DW_TAG_subprogram:
9958 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9960 SYMBOL_CLASS (sym) = LOC_BLOCK;
9961 attr2 = dwarf2_attr (die, DW_AT_external, cu);
9962 if ((attr2 && (DW_UNSND (attr2) != 0))
9963 || cu->language == language_ada)
9965 /* Subprograms marked external are stored as a global symbol.
9966 Ada subprograms, whether marked external or not, are always
9967 stored as a global symbol, because we want to be able to
9968 access them globally. For instance, we want to be able
9969 to break on a nested subprogram without having to
9970 specify the context. */
9971 add_symbol_to_list (sym, &global_symbols);
9975 add_symbol_to_list (sym, cu->list_in_scope);
9978 case DW_TAG_inlined_subroutine:
9979 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9981 SYMBOL_CLASS (sym) = LOC_BLOCK;
9982 SYMBOL_INLINED (sym) = 1;
9983 /* Do not add the symbol to any lists. It will be found via
9984 BLOCK_FUNCTION from the blockvector. */
9986 case DW_TAG_variable:
9988 /* Compilation with minimal debug info may result in variables
9989 with missing type entries. Change the misleading `void' type
9990 to something sensible. */
9991 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
9993 = objfile_type (objfile)->nodebug_data_symbol;
9995 attr = dwarf2_attr (die, DW_AT_const_value, cu);
9996 /* In the case of DW_TAG_member, we should only be called for
9997 static const members. */
9998 if (die->tag == DW_TAG_member)
10000 /* dwarf2_add_field uses die_is_declaration,
10001 so we do the same. */
10002 gdb_assert (die_is_declaration (die, cu));
10007 dwarf2_const_value (attr, sym, cu);
10008 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10009 if (attr2 && (DW_UNSND (attr2) != 0))
10010 add_symbol_to_list (sym, &global_symbols);
10012 add_symbol_to_list (sym, cu->list_in_scope);
10015 attr = dwarf2_attr (die, DW_AT_location, cu);
10018 var_decode_location (attr, sym, cu);
10019 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10020 if (SYMBOL_CLASS (sym) == LOC_STATIC
10021 && SYMBOL_VALUE_ADDRESS (sym) == 0
10022 && !dwarf2_per_objfile->has_section_at_zero)
10024 /* When a static variable is eliminated by the linker,
10025 the corresponding debug information is not stripped
10026 out, but the variable address is set to null;
10027 do not add such variables into symbol table. */
10029 else if (attr2 && (DW_UNSND (attr2) != 0))
10031 struct pending **list_to_add;
10033 /* Workaround gfortran PR debug/40040 - it uses
10034 DW_AT_location for variables in -fPIC libraries which may
10035 get overriden by other libraries/executable and get
10036 a different address. Resolve it by the minimal symbol
10037 which may come from inferior's executable using copy
10038 relocation. Make this workaround only for gfortran as for
10039 other compilers GDB cannot guess the minimal symbol
10040 Fortran mangling kind. */
10041 if (cu->language == language_fortran && die->parent
10042 && die->parent->tag == DW_TAG_module
10044 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
10045 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10047 /* A variable with DW_AT_external is never static,
10048 but it may be block-scoped. */
10049 list_to_add = (cu->list_in_scope == &file_symbols
10050 ? &global_symbols : cu->list_in_scope);
10051 add_symbol_to_list (sym, list_to_add);
10054 add_symbol_to_list (sym, cu->list_in_scope);
10058 /* We do not know the address of this symbol.
10059 If it is an external symbol and we have type information
10060 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10061 The address of the variable will then be determined from
10062 the minimal symbol table whenever the variable is
10064 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10065 if (attr2 && (DW_UNSND (attr2) != 0)
10066 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
10068 struct pending **list_to_add;
10070 /* A variable with DW_AT_external is never static, but it
10071 may be block-scoped. */
10072 list_to_add = (cu->list_in_scope == &file_symbols
10073 ? &global_symbols : cu->list_in_scope);
10075 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10076 add_symbol_to_list (sym, list_to_add);
10078 else if (!die_is_declaration (die, cu))
10080 /* Use the default LOC_OPTIMIZED_OUT class. */
10081 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
10082 add_symbol_to_list (sym, cu->list_in_scope);
10086 case DW_TAG_formal_parameter:
10087 /* If we are inside a function, mark this as an argument. If
10088 not, we might be looking at an argument to an inlined function
10089 when we do not have enough information to show inlined frames;
10090 pretend it's a local variable in that case so that the user can
10092 if (context_stack_depth > 0
10093 && context_stack[context_stack_depth - 1].name != NULL)
10094 SYMBOL_IS_ARGUMENT (sym) = 1;
10095 attr = dwarf2_attr (die, DW_AT_location, cu);
10098 var_decode_location (attr, sym, cu);
10100 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10103 dwarf2_const_value (attr, sym, cu);
10105 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
10106 if (attr && DW_UNSND (attr))
10108 struct type *ref_type;
10110 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
10111 SYMBOL_TYPE (sym) = ref_type;
10114 add_symbol_to_list (sym, cu->list_in_scope);
10116 case DW_TAG_unspecified_parameters:
10117 /* From varargs functions; gdb doesn't seem to have any
10118 interest in this information, so just ignore it for now.
10121 case DW_TAG_class_type:
10122 case DW_TAG_interface_type:
10123 case DW_TAG_structure_type:
10124 case DW_TAG_union_type:
10125 case DW_TAG_set_type:
10126 case DW_TAG_enumeration_type:
10127 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10128 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
10131 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10132 really ever be static objects: otherwise, if you try
10133 to, say, break of a class's method and you're in a file
10134 which doesn't mention that class, it won't work unless
10135 the check for all static symbols in lookup_symbol_aux
10136 saves you. See the OtherFileClass tests in
10137 gdb.c++/namespace.exp. */
10139 struct pending **list_to_add;
10141 list_to_add = (cu->list_in_scope == &file_symbols
10142 && (cu->language == language_cplus
10143 || cu->language == language_java)
10144 ? &global_symbols : cu->list_in_scope);
10146 add_symbol_to_list (sym, list_to_add);
10148 /* The semantics of C++ state that "struct foo { ... }" also
10149 defines a typedef for "foo". A Java class declaration also
10150 defines a typedef for the class. */
10151 if (cu->language == language_cplus
10152 || cu->language == language_java
10153 || cu->language == language_ada)
10155 /* The symbol's name is already allocated along with
10156 this objfile, so we don't need to duplicate it for
10158 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
10159 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
10163 case DW_TAG_typedef:
10164 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10165 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10166 add_symbol_to_list (sym, cu->list_in_scope);
10168 case DW_TAG_base_type:
10169 case DW_TAG_subrange_type:
10170 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10171 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10172 add_symbol_to_list (sym, cu->list_in_scope);
10174 case DW_TAG_enumerator:
10175 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10178 dwarf2_const_value (attr, sym, cu);
10181 /* NOTE: carlton/2003-11-10: See comment above in the
10182 DW_TAG_class_type, etc. block. */
10184 struct pending **list_to_add;
10186 list_to_add = (cu->list_in_scope == &file_symbols
10187 && (cu->language == language_cplus
10188 || cu->language == language_java)
10189 ? &global_symbols : cu->list_in_scope);
10191 add_symbol_to_list (sym, list_to_add);
10194 case DW_TAG_namespace:
10195 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10196 add_symbol_to_list (sym, &global_symbols);
10199 /* Not a tag we recognize. Hopefully we aren't processing
10200 trash data, but since we must specifically ignore things
10201 we don't recognize, there is nothing else we should do at
10203 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
10204 dwarf_tag_name (die->tag));
10208 /* For the benefit of old versions of GCC, check for anonymous
10209 namespaces based on the demangled name. */
10210 if (!processing_has_namespace_info
10211 && cu->language == language_cplus)
10212 cp_scan_for_anonymous_namespaces (sym);
10217 /* Copy constant value from an attribute to a symbol. */
10220 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
10221 struct dwarf2_cu *cu)
10223 struct objfile *objfile = cu->objfile;
10224 struct comp_unit_head *cu_header = &cu->header;
10225 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
10226 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
10227 struct dwarf_block *blk;
10229 switch (attr->form)
10233 struct dwarf2_locexpr_baton *baton;
10236 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
10237 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
10238 cu_header->addr_size,
10239 TYPE_LENGTH (SYMBOL_TYPE
10241 /* Symbols of this form are reasonably rare, so we just
10242 piggyback on the existing location code rather than writing
10243 a new implementation of symbol_computed_ops. */
10244 baton = obstack_alloc (&objfile->objfile_obstack,
10245 sizeof (struct dwarf2_locexpr_baton));
10246 baton->per_cu = cu->per_cu;
10247 gdb_assert (baton->per_cu);
10249 baton->size = 2 + cu_header->addr_size;
10250 data = obstack_alloc (&objfile->objfile_obstack, baton->size);
10251 baton->data = data;
10253 data[0] = DW_OP_addr;
10254 store_unsigned_integer (&data[1], cu_header->addr_size,
10255 byte_order, DW_ADDR (attr));
10256 data[cu_header->addr_size + 1] = DW_OP_stack_value;
10258 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
10259 SYMBOL_LOCATION_BATON (sym) = baton;
10260 SYMBOL_CLASS (sym) = LOC_COMPUTED;
10263 case DW_FORM_string:
10265 /* DW_STRING is already allocated on the obstack, point directly
10267 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
10268 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
10270 case DW_FORM_block1:
10271 case DW_FORM_block2:
10272 case DW_FORM_block4:
10273 case DW_FORM_block:
10274 case DW_FORM_exprloc:
10275 blk = DW_BLOCK (attr);
10276 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
10277 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
10279 TYPE_LENGTH (SYMBOL_TYPE
10281 SYMBOL_VALUE_BYTES (sym) =
10282 obstack_alloc (&objfile->objfile_obstack, blk->size);
10283 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
10284 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
10287 /* The DW_AT_const_value attributes are supposed to carry the
10288 symbol's value "represented as it would be on the target
10289 architecture." By the time we get here, it's already been
10290 converted to host endianness, so we just need to sign- or
10291 zero-extend it as appropriate. */
10292 case DW_FORM_data1:
10293 dwarf2_const_value_data (attr, sym, 8);
10295 case DW_FORM_data2:
10296 dwarf2_const_value_data (attr, sym, 16);
10298 case DW_FORM_data4:
10299 dwarf2_const_value_data (attr, sym, 32);
10301 case DW_FORM_data8:
10302 dwarf2_const_value_data (attr, sym, 64);
10305 case DW_FORM_sdata:
10306 SYMBOL_VALUE (sym) = DW_SND (attr);
10307 SYMBOL_CLASS (sym) = LOC_CONST;
10310 case DW_FORM_udata:
10311 SYMBOL_VALUE (sym) = DW_UNSND (attr);
10312 SYMBOL_CLASS (sym) = LOC_CONST;
10316 complaint (&symfile_complaints,
10317 _("unsupported const value attribute form: '%s'"),
10318 dwarf_form_name (attr->form));
10319 SYMBOL_VALUE (sym) = 0;
10320 SYMBOL_CLASS (sym) = LOC_CONST;
10326 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
10327 or zero-extend it as appropriate for the symbol's type. */
10329 dwarf2_const_value_data (struct attribute *attr,
10330 struct symbol *sym,
10333 LONGEST l = DW_UNSND (attr);
10335 if (bits < sizeof (l) * 8)
10337 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
10338 l &= ((LONGEST) 1 << bits) - 1;
10340 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
10343 SYMBOL_VALUE (sym) = l;
10344 SYMBOL_CLASS (sym) = LOC_CONST;
10348 /* Return the type of the die in question using its DW_AT_type attribute. */
10350 static struct type *
10351 die_type (struct die_info *die, struct dwarf2_cu *cu)
10353 struct attribute *type_attr;
10354 struct die_info *type_die;
10356 type_attr = dwarf2_attr (die, DW_AT_type, cu);
10359 /* A missing DW_AT_type represents a void type. */
10360 return objfile_type (cu->objfile)->builtin_void;
10363 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
10365 return tag_type_to_type (type_die, cu);
10368 /* True iff CU's producer generates GNAT Ada auxiliary information
10369 that allows to find parallel types through that information instead
10370 of having to do expensive parallel lookups by type name. */
10373 need_gnat_info (struct dwarf2_cu *cu)
10375 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10376 of GNAT produces this auxiliary information, without any indication
10377 that it is produced. Part of enhancing the FSF version of GNAT
10378 to produce that information will be to put in place an indicator
10379 that we can use in order to determine whether the descriptive type
10380 info is available or not. One suggestion that has been made is
10381 to use a new attribute, attached to the CU die. For now, assume
10382 that the descriptive type info is not available. */
10387 /* Return the auxiliary type of the die in question using its
10388 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10389 attribute is not present. */
10391 static struct type *
10392 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
10394 struct attribute *type_attr;
10395 struct die_info *type_die;
10397 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
10401 type_die = follow_die_ref (die, type_attr, &cu);
10402 return tag_type_to_type (type_die, cu);
10405 /* If DIE has a descriptive_type attribute, then set the TYPE's
10406 descriptive type accordingly. */
10409 set_descriptive_type (struct type *type, struct die_info *die,
10410 struct dwarf2_cu *cu)
10412 struct type *descriptive_type = die_descriptive_type (die, cu);
10414 if (descriptive_type)
10416 ALLOCATE_GNAT_AUX_TYPE (type);
10417 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
10421 /* Return the containing type of the die in question using its
10422 DW_AT_containing_type attribute. */
10424 static struct type *
10425 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
10427 struct attribute *type_attr;
10428 struct die_info *type_die;
10430 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
10432 error (_("Dwarf Error: Problem turning containing type into gdb type "
10433 "[in module %s]"), cu->objfile->name);
10435 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
10436 return tag_type_to_type (type_die, cu);
10439 static struct type *
10440 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
10442 struct type *this_type;
10444 this_type = read_type_die (die, cu);
10447 char *message, *saved;
10449 /* read_type_die already issued a complaint. */
10450 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10454 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
10455 message, strlen (message));
10458 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
10463 static struct type *
10464 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
10466 struct type *this_type;
10468 this_type = get_die_type (die, cu);
10474 case DW_TAG_class_type:
10475 case DW_TAG_interface_type:
10476 case DW_TAG_structure_type:
10477 case DW_TAG_union_type:
10478 this_type = read_structure_type (die, cu);
10480 case DW_TAG_enumeration_type:
10481 this_type = read_enumeration_type (die, cu);
10483 case DW_TAG_subprogram:
10484 case DW_TAG_subroutine_type:
10485 case DW_TAG_inlined_subroutine:
10486 this_type = read_subroutine_type (die, cu);
10488 case DW_TAG_array_type:
10489 this_type = read_array_type (die, cu);
10491 case DW_TAG_set_type:
10492 this_type = read_set_type (die, cu);
10494 case DW_TAG_pointer_type:
10495 this_type = read_tag_pointer_type (die, cu);
10497 case DW_TAG_ptr_to_member_type:
10498 this_type = read_tag_ptr_to_member_type (die, cu);
10500 case DW_TAG_reference_type:
10501 this_type = read_tag_reference_type (die, cu);
10503 case DW_TAG_const_type:
10504 this_type = read_tag_const_type (die, cu);
10506 case DW_TAG_volatile_type:
10507 this_type = read_tag_volatile_type (die, cu);
10509 case DW_TAG_string_type:
10510 this_type = read_tag_string_type (die, cu);
10512 case DW_TAG_typedef:
10513 this_type = read_typedef (die, cu);
10515 case DW_TAG_subrange_type:
10516 this_type = read_subrange_type (die, cu);
10518 case DW_TAG_base_type:
10519 this_type = read_base_type (die, cu);
10521 case DW_TAG_unspecified_type:
10522 this_type = read_unspecified_type (die, cu);
10524 case DW_TAG_namespace:
10525 this_type = read_namespace_type (die, cu);
10527 case DW_TAG_module:
10528 this_type = read_module_type (die, cu);
10531 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
10532 dwarf_tag_name (die->tag));
10539 /* Return the name of the namespace/class that DIE is defined within,
10540 or "" if we can't tell. The caller should not xfree the result.
10542 For example, if we're within the method foo() in the following
10552 then determine_prefix on foo's die will return "N::C". */
10555 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
10557 struct die_info *parent, *spec_die;
10558 struct dwarf2_cu *spec_cu;
10559 struct type *parent_type;
10561 if (cu->language != language_cplus && cu->language != language_java
10562 && cu->language != language_fortran)
10565 /* We have to be careful in the presence of DW_AT_specification.
10566 For example, with GCC 3.4, given the code
10570 // Definition of N::foo.
10574 then we'll have a tree of DIEs like this:
10576 1: DW_TAG_compile_unit
10577 2: DW_TAG_namespace // N
10578 3: DW_TAG_subprogram // declaration of N::foo
10579 4: DW_TAG_subprogram // definition of N::foo
10580 DW_AT_specification // refers to die #3
10582 Thus, when processing die #4, we have to pretend that we're in
10583 the context of its DW_AT_specification, namely the contex of die
10586 spec_die = die_specification (die, &spec_cu);
10587 if (spec_die == NULL)
10588 parent = die->parent;
10591 parent = spec_die->parent;
10595 if (parent == NULL)
10598 switch (parent->tag)
10600 case DW_TAG_namespace:
10601 parent_type = read_type_die (parent, cu);
10602 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
10603 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
10604 Work around this problem here. */
10605 if (cu->language == language_cplus
10606 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
10608 /* We give a name to even anonymous namespaces. */
10609 return TYPE_TAG_NAME (parent_type);
10610 case DW_TAG_class_type:
10611 case DW_TAG_interface_type:
10612 case DW_TAG_structure_type:
10613 case DW_TAG_union_type:
10614 case DW_TAG_module:
10615 parent_type = read_type_die (parent, cu);
10616 if (TYPE_TAG_NAME (parent_type) != NULL)
10617 return TYPE_TAG_NAME (parent_type);
10619 /* An anonymous structure is only allowed non-static data
10620 members; no typedefs, no member functions, et cetera.
10621 So it does not need a prefix. */
10624 return determine_prefix (parent, cu);
10628 /* Return a newly-allocated string formed by concatenating PREFIX and
10629 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
10630 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
10631 perform an obconcat, otherwise allocate storage for the result. The CU argument
10632 is used to determine the language and hence, the appropriate separator. */
10634 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
10637 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
10638 int physname, struct dwarf2_cu *cu)
10640 const char *lead = "";
10643 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
10645 else if (cu->language == language_java)
10647 else if (cu->language == language_fortran && physname)
10649 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
10650 DW_AT_MIPS_linkage_name is preferred and used instead. */
10658 if (prefix == NULL)
10660 if (suffix == NULL)
10665 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
10667 strcpy (retval, lead);
10668 strcat (retval, prefix);
10669 strcat (retval, sep);
10670 strcat (retval, suffix);
10675 /* We have an obstack. */
10676 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
10680 /* Return sibling of die, NULL if no sibling. */
10682 static struct die_info *
10683 sibling_die (struct die_info *die)
10685 return die->sibling;
10688 /* Get name of a die, return NULL if not found. */
10691 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
10692 struct obstack *obstack)
10694 if (name && cu->language == language_cplus)
10696 char *canon_name = cp_canonicalize_string (name);
10698 if (canon_name != NULL)
10700 if (strcmp (canon_name, name) != 0)
10701 name = obsavestring (canon_name, strlen (canon_name),
10703 xfree (canon_name);
10710 /* Get name of a die, return NULL if not found. */
10713 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
10715 struct attribute *attr;
10717 attr = dwarf2_attr (die, DW_AT_name, cu);
10718 if (!attr || !DW_STRING (attr))
10723 case DW_TAG_compile_unit:
10724 /* Compilation units have a DW_AT_name that is a filename, not
10725 a source language identifier. */
10726 case DW_TAG_enumeration_type:
10727 case DW_TAG_enumerator:
10728 /* These tags always have simple identifiers already; no need
10729 to canonicalize them. */
10730 return DW_STRING (attr);
10732 case DW_TAG_subprogram:
10733 /* Java constructors will all be named "<init>", so return
10734 the class name when we see this special case. */
10735 if (cu->language == language_java
10736 && DW_STRING (attr) != NULL
10737 && strcmp (DW_STRING (attr), "<init>") == 0)
10739 struct dwarf2_cu *spec_cu = cu;
10740 struct die_info *spec_die;
10742 /* GCJ will output '<init>' for Java constructor names.
10743 For this special case, return the name of the parent class. */
10745 /* GCJ may output suprogram DIEs with AT_specification set.
10746 If so, use the name of the specified DIE. */
10747 spec_die = die_specification (die, &spec_cu);
10748 if (spec_die != NULL)
10749 return dwarf2_name (spec_die, spec_cu);
10754 if (die->tag == DW_TAG_class_type)
10755 return dwarf2_name (die, cu);
10757 while (die->tag != DW_TAG_compile_unit);
10761 case DW_TAG_class_type:
10762 case DW_TAG_interface_type:
10763 case DW_TAG_structure_type:
10764 case DW_TAG_union_type:
10765 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
10766 structures or unions. These were of the form "._%d" in GCC 4.1,
10767 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
10768 and GCC 4.4. We work around this problem by ignoring these. */
10769 if (strncmp (DW_STRING (attr), "._", 2) == 0
10770 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
10778 if (!DW_STRING_IS_CANONICAL (attr))
10781 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
10782 &cu->objfile->objfile_obstack);
10783 DW_STRING_IS_CANONICAL (attr) = 1;
10785 return DW_STRING (attr);
10788 /* Return the die that this die in an extension of, or NULL if there
10789 is none. *EXT_CU is the CU containing DIE on input, and the CU
10790 containing the return value on output. */
10792 static struct die_info *
10793 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
10795 struct attribute *attr;
10797 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
10801 return follow_die_ref (die, attr, ext_cu);
10804 /* Convert a DIE tag into its string name. */
10807 dwarf_tag_name (unsigned tag)
10811 case DW_TAG_padding:
10812 return "DW_TAG_padding";
10813 case DW_TAG_array_type:
10814 return "DW_TAG_array_type";
10815 case DW_TAG_class_type:
10816 return "DW_TAG_class_type";
10817 case DW_TAG_entry_point:
10818 return "DW_TAG_entry_point";
10819 case DW_TAG_enumeration_type:
10820 return "DW_TAG_enumeration_type";
10821 case DW_TAG_formal_parameter:
10822 return "DW_TAG_formal_parameter";
10823 case DW_TAG_imported_declaration:
10824 return "DW_TAG_imported_declaration";
10826 return "DW_TAG_label";
10827 case DW_TAG_lexical_block:
10828 return "DW_TAG_lexical_block";
10829 case DW_TAG_member:
10830 return "DW_TAG_member";
10831 case DW_TAG_pointer_type:
10832 return "DW_TAG_pointer_type";
10833 case DW_TAG_reference_type:
10834 return "DW_TAG_reference_type";
10835 case DW_TAG_compile_unit:
10836 return "DW_TAG_compile_unit";
10837 case DW_TAG_string_type:
10838 return "DW_TAG_string_type";
10839 case DW_TAG_structure_type:
10840 return "DW_TAG_structure_type";
10841 case DW_TAG_subroutine_type:
10842 return "DW_TAG_subroutine_type";
10843 case DW_TAG_typedef:
10844 return "DW_TAG_typedef";
10845 case DW_TAG_union_type:
10846 return "DW_TAG_union_type";
10847 case DW_TAG_unspecified_parameters:
10848 return "DW_TAG_unspecified_parameters";
10849 case DW_TAG_variant:
10850 return "DW_TAG_variant";
10851 case DW_TAG_common_block:
10852 return "DW_TAG_common_block";
10853 case DW_TAG_common_inclusion:
10854 return "DW_TAG_common_inclusion";
10855 case DW_TAG_inheritance:
10856 return "DW_TAG_inheritance";
10857 case DW_TAG_inlined_subroutine:
10858 return "DW_TAG_inlined_subroutine";
10859 case DW_TAG_module:
10860 return "DW_TAG_module";
10861 case DW_TAG_ptr_to_member_type:
10862 return "DW_TAG_ptr_to_member_type";
10863 case DW_TAG_set_type:
10864 return "DW_TAG_set_type";
10865 case DW_TAG_subrange_type:
10866 return "DW_TAG_subrange_type";
10867 case DW_TAG_with_stmt:
10868 return "DW_TAG_with_stmt";
10869 case DW_TAG_access_declaration:
10870 return "DW_TAG_access_declaration";
10871 case DW_TAG_base_type:
10872 return "DW_TAG_base_type";
10873 case DW_TAG_catch_block:
10874 return "DW_TAG_catch_block";
10875 case DW_TAG_const_type:
10876 return "DW_TAG_const_type";
10877 case DW_TAG_constant:
10878 return "DW_TAG_constant";
10879 case DW_TAG_enumerator:
10880 return "DW_TAG_enumerator";
10881 case DW_TAG_file_type:
10882 return "DW_TAG_file_type";
10883 case DW_TAG_friend:
10884 return "DW_TAG_friend";
10885 case DW_TAG_namelist:
10886 return "DW_TAG_namelist";
10887 case DW_TAG_namelist_item:
10888 return "DW_TAG_namelist_item";
10889 case DW_TAG_packed_type:
10890 return "DW_TAG_packed_type";
10891 case DW_TAG_subprogram:
10892 return "DW_TAG_subprogram";
10893 case DW_TAG_template_type_param:
10894 return "DW_TAG_template_type_param";
10895 case DW_TAG_template_value_param:
10896 return "DW_TAG_template_value_param";
10897 case DW_TAG_thrown_type:
10898 return "DW_TAG_thrown_type";
10899 case DW_TAG_try_block:
10900 return "DW_TAG_try_block";
10901 case DW_TAG_variant_part:
10902 return "DW_TAG_variant_part";
10903 case DW_TAG_variable:
10904 return "DW_TAG_variable";
10905 case DW_TAG_volatile_type:
10906 return "DW_TAG_volatile_type";
10907 case DW_TAG_dwarf_procedure:
10908 return "DW_TAG_dwarf_procedure";
10909 case DW_TAG_restrict_type:
10910 return "DW_TAG_restrict_type";
10911 case DW_TAG_interface_type:
10912 return "DW_TAG_interface_type";
10913 case DW_TAG_namespace:
10914 return "DW_TAG_namespace";
10915 case DW_TAG_imported_module:
10916 return "DW_TAG_imported_module";
10917 case DW_TAG_unspecified_type:
10918 return "DW_TAG_unspecified_type";
10919 case DW_TAG_partial_unit:
10920 return "DW_TAG_partial_unit";
10921 case DW_TAG_imported_unit:
10922 return "DW_TAG_imported_unit";
10923 case DW_TAG_condition:
10924 return "DW_TAG_condition";
10925 case DW_TAG_shared_type:
10926 return "DW_TAG_shared_type";
10927 case DW_TAG_type_unit:
10928 return "DW_TAG_type_unit";
10929 case DW_TAG_MIPS_loop:
10930 return "DW_TAG_MIPS_loop";
10931 case DW_TAG_HP_array_descriptor:
10932 return "DW_TAG_HP_array_descriptor";
10933 case DW_TAG_format_label:
10934 return "DW_TAG_format_label";
10935 case DW_TAG_function_template:
10936 return "DW_TAG_function_template";
10937 case DW_TAG_class_template:
10938 return "DW_TAG_class_template";
10939 case DW_TAG_GNU_BINCL:
10940 return "DW_TAG_GNU_BINCL";
10941 case DW_TAG_GNU_EINCL:
10942 return "DW_TAG_GNU_EINCL";
10943 case DW_TAG_upc_shared_type:
10944 return "DW_TAG_upc_shared_type";
10945 case DW_TAG_upc_strict_type:
10946 return "DW_TAG_upc_strict_type";
10947 case DW_TAG_upc_relaxed_type:
10948 return "DW_TAG_upc_relaxed_type";
10949 case DW_TAG_PGI_kanji_type:
10950 return "DW_TAG_PGI_kanji_type";
10951 case DW_TAG_PGI_interface_block:
10952 return "DW_TAG_PGI_interface_block";
10954 return "DW_TAG_<unknown>";
10958 /* Convert a DWARF attribute code into its string name. */
10961 dwarf_attr_name (unsigned attr)
10965 case DW_AT_sibling:
10966 return "DW_AT_sibling";
10967 case DW_AT_location:
10968 return "DW_AT_location";
10970 return "DW_AT_name";
10971 case DW_AT_ordering:
10972 return "DW_AT_ordering";
10973 case DW_AT_subscr_data:
10974 return "DW_AT_subscr_data";
10975 case DW_AT_byte_size:
10976 return "DW_AT_byte_size";
10977 case DW_AT_bit_offset:
10978 return "DW_AT_bit_offset";
10979 case DW_AT_bit_size:
10980 return "DW_AT_bit_size";
10981 case DW_AT_element_list:
10982 return "DW_AT_element_list";
10983 case DW_AT_stmt_list:
10984 return "DW_AT_stmt_list";
10986 return "DW_AT_low_pc";
10987 case DW_AT_high_pc:
10988 return "DW_AT_high_pc";
10989 case DW_AT_language:
10990 return "DW_AT_language";
10992 return "DW_AT_member";
10994 return "DW_AT_discr";
10995 case DW_AT_discr_value:
10996 return "DW_AT_discr_value";
10997 case DW_AT_visibility:
10998 return "DW_AT_visibility";
11000 return "DW_AT_import";
11001 case DW_AT_string_length:
11002 return "DW_AT_string_length";
11003 case DW_AT_common_reference:
11004 return "DW_AT_common_reference";
11005 case DW_AT_comp_dir:
11006 return "DW_AT_comp_dir";
11007 case DW_AT_const_value:
11008 return "DW_AT_const_value";
11009 case DW_AT_containing_type:
11010 return "DW_AT_containing_type";
11011 case DW_AT_default_value:
11012 return "DW_AT_default_value";
11014 return "DW_AT_inline";
11015 case DW_AT_is_optional:
11016 return "DW_AT_is_optional";
11017 case DW_AT_lower_bound:
11018 return "DW_AT_lower_bound";
11019 case DW_AT_producer:
11020 return "DW_AT_producer";
11021 case DW_AT_prototyped:
11022 return "DW_AT_prototyped";
11023 case DW_AT_return_addr:
11024 return "DW_AT_return_addr";
11025 case DW_AT_start_scope:
11026 return "DW_AT_start_scope";
11027 case DW_AT_bit_stride:
11028 return "DW_AT_bit_stride";
11029 case DW_AT_upper_bound:
11030 return "DW_AT_upper_bound";
11031 case DW_AT_abstract_origin:
11032 return "DW_AT_abstract_origin";
11033 case DW_AT_accessibility:
11034 return "DW_AT_accessibility";
11035 case DW_AT_address_class:
11036 return "DW_AT_address_class";
11037 case DW_AT_artificial:
11038 return "DW_AT_artificial";
11039 case DW_AT_base_types:
11040 return "DW_AT_base_types";
11041 case DW_AT_calling_convention:
11042 return "DW_AT_calling_convention";
11044 return "DW_AT_count";
11045 case DW_AT_data_member_location:
11046 return "DW_AT_data_member_location";
11047 case DW_AT_decl_column:
11048 return "DW_AT_decl_column";
11049 case DW_AT_decl_file:
11050 return "DW_AT_decl_file";
11051 case DW_AT_decl_line:
11052 return "DW_AT_decl_line";
11053 case DW_AT_declaration:
11054 return "DW_AT_declaration";
11055 case DW_AT_discr_list:
11056 return "DW_AT_discr_list";
11057 case DW_AT_encoding:
11058 return "DW_AT_encoding";
11059 case DW_AT_external:
11060 return "DW_AT_external";
11061 case DW_AT_frame_base:
11062 return "DW_AT_frame_base";
11064 return "DW_AT_friend";
11065 case DW_AT_identifier_case:
11066 return "DW_AT_identifier_case";
11067 case DW_AT_macro_info:
11068 return "DW_AT_macro_info";
11069 case DW_AT_namelist_items:
11070 return "DW_AT_namelist_items";
11071 case DW_AT_priority:
11072 return "DW_AT_priority";
11073 case DW_AT_segment:
11074 return "DW_AT_segment";
11075 case DW_AT_specification:
11076 return "DW_AT_specification";
11077 case DW_AT_static_link:
11078 return "DW_AT_static_link";
11080 return "DW_AT_type";
11081 case DW_AT_use_location:
11082 return "DW_AT_use_location";
11083 case DW_AT_variable_parameter:
11084 return "DW_AT_variable_parameter";
11085 case DW_AT_virtuality:
11086 return "DW_AT_virtuality";
11087 case DW_AT_vtable_elem_location:
11088 return "DW_AT_vtable_elem_location";
11089 /* DWARF 3 values. */
11090 case DW_AT_allocated:
11091 return "DW_AT_allocated";
11092 case DW_AT_associated:
11093 return "DW_AT_associated";
11094 case DW_AT_data_location:
11095 return "DW_AT_data_location";
11096 case DW_AT_byte_stride:
11097 return "DW_AT_byte_stride";
11098 case DW_AT_entry_pc:
11099 return "DW_AT_entry_pc";
11100 case DW_AT_use_UTF8:
11101 return "DW_AT_use_UTF8";
11102 case DW_AT_extension:
11103 return "DW_AT_extension";
11105 return "DW_AT_ranges";
11106 case DW_AT_trampoline:
11107 return "DW_AT_trampoline";
11108 case DW_AT_call_column:
11109 return "DW_AT_call_column";
11110 case DW_AT_call_file:
11111 return "DW_AT_call_file";
11112 case DW_AT_call_line:
11113 return "DW_AT_call_line";
11114 case DW_AT_description:
11115 return "DW_AT_description";
11116 case DW_AT_binary_scale:
11117 return "DW_AT_binary_scale";
11118 case DW_AT_decimal_scale:
11119 return "DW_AT_decimal_scale";
11121 return "DW_AT_small";
11122 case DW_AT_decimal_sign:
11123 return "DW_AT_decimal_sign";
11124 case DW_AT_digit_count:
11125 return "DW_AT_digit_count";
11126 case DW_AT_picture_string:
11127 return "DW_AT_picture_string";
11128 case DW_AT_mutable:
11129 return "DW_AT_mutable";
11130 case DW_AT_threads_scaled:
11131 return "DW_AT_threads_scaled";
11132 case DW_AT_explicit:
11133 return "DW_AT_explicit";
11134 case DW_AT_object_pointer:
11135 return "DW_AT_object_pointer";
11136 case DW_AT_endianity:
11137 return "DW_AT_endianity";
11138 case DW_AT_elemental:
11139 return "DW_AT_elemental";
11141 return "DW_AT_pure";
11142 case DW_AT_recursive:
11143 return "DW_AT_recursive";
11144 /* DWARF 4 values. */
11145 case DW_AT_signature:
11146 return "DW_AT_signature";
11147 case DW_AT_linkage_name:
11148 return "DW_AT_linkage_name";
11149 /* SGI/MIPS extensions. */
11150 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11151 case DW_AT_MIPS_fde:
11152 return "DW_AT_MIPS_fde";
11154 case DW_AT_MIPS_loop_begin:
11155 return "DW_AT_MIPS_loop_begin";
11156 case DW_AT_MIPS_tail_loop_begin:
11157 return "DW_AT_MIPS_tail_loop_begin";
11158 case DW_AT_MIPS_epilog_begin:
11159 return "DW_AT_MIPS_epilog_begin";
11160 case DW_AT_MIPS_loop_unroll_factor:
11161 return "DW_AT_MIPS_loop_unroll_factor";
11162 case DW_AT_MIPS_software_pipeline_depth:
11163 return "DW_AT_MIPS_software_pipeline_depth";
11164 case DW_AT_MIPS_linkage_name:
11165 return "DW_AT_MIPS_linkage_name";
11166 case DW_AT_MIPS_stride:
11167 return "DW_AT_MIPS_stride";
11168 case DW_AT_MIPS_abstract_name:
11169 return "DW_AT_MIPS_abstract_name";
11170 case DW_AT_MIPS_clone_origin:
11171 return "DW_AT_MIPS_clone_origin";
11172 case DW_AT_MIPS_has_inlines:
11173 return "DW_AT_MIPS_has_inlines";
11174 /* HP extensions. */
11175 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11176 case DW_AT_HP_block_index:
11177 return "DW_AT_HP_block_index";
11179 case DW_AT_HP_unmodifiable:
11180 return "DW_AT_HP_unmodifiable";
11181 case DW_AT_HP_actuals_stmt_list:
11182 return "DW_AT_HP_actuals_stmt_list";
11183 case DW_AT_HP_proc_per_section:
11184 return "DW_AT_HP_proc_per_section";
11185 case DW_AT_HP_raw_data_ptr:
11186 return "DW_AT_HP_raw_data_ptr";
11187 case DW_AT_HP_pass_by_reference:
11188 return "DW_AT_HP_pass_by_reference";
11189 case DW_AT_HP_opt_level:
11190 return "DW_AT_HP_opt_level";
11191 case DW_AT_HP_prof_version_id:
11192 return "DW_AT_HP_prof_version_id";
11193 case DW_AT_HP_opt_flags:
11194 return "DW_AT_HP_opt_flags";
11195 case DW_AT_HP_cold_region_low_pc:
11196 return "DW_AT_HP_cold_region_low_pc";
11197 case DW_AT_HP_cold_region_high_pc:
11198 return "DW_AT_HP_cold_region_high_pc";
11199 case DW_AT_HP_all_variables_modifiable:
11200 return "DW_AT_HP_all_variables_modifiable";
11201 case DW_AT_HP_linkage_name:
11202 return "DW_AT_HP_linkage_name";
11203 case DW_AT_HP_prof_flags:
11204 return "DW_AT_HP_prof_flags";
11205 /* GNU extensions. */
11206 case DW_AT_sf_names:
11207 return "DW_AT_sf_names";
11208 case DW_AT_src_info:
11209 return "DW_AT_src_info";
11210 case DW_AT_mac_info:
11211 return "DW_AT_mac_info";
11212 case DW_AT_src_coords:
11213 return "DW_AT_src_coords";
11214 case DW_AT_body_begin:
11215 return "DW_AT_body_begin";
11216 case DW_AT_body_end:
11217 return "DW_AT_body_end";
11218 case DW_AT_GNU_vector:
11219 return "DW_AT_GNU_vector";
11220 /* VMS extensions. */
11221 case DW_AT_VMS_rtnbeg_pd_address:
11222 return "DW_AT_VMS_rtnbeg_pd_address";
11223 /* UPC extension. */
11224 case DW_AT_upc_threads_scaled:
11225 return "DW_AT_upc_threads_scaled";
11226 /* PGI (STMicroelectronics) extensions. */
11227 case DW_AT_PGI_lbase:
11228 return "DW_AT_PGI_lbase";
11229 case DW_AT_PGI_soffset:
11230 return "DW_AT_PGI_soffset";
11231 case DW_AT_PGI_lstride:
11232 return "DW_AT_PGI_lstride";
11234 return "DW_AT_<unknown>";
11238 /* Convert a DWARF value form code into its string name. */
11241 dwarf_form_name (unsigned form)
11246 return "DW_FORM_addr";
11247 case DW_FORM_block2:
11248 return "DW_FORM_block2";
11249 case DW_FORM_block4:
11250 return "DW_FORM_block4";
11251 case DW_FORM_data2:
11252 return "DW_FORM_data2";
11253 case DW_FORM_data4:
11254 return "DW_FORM_data4";
11255 case DW_FORM_data8:
11256 return "DW_FORM_data8";
11257 case DW_FORM_string:
11258 return "DW_FORM_string";
11259 case DW_FORM_block:
11260 return "DW_FORM_block";
11261 case DW_FORM_block1:
11262 return "DW_FORM_block1";
11263 case DW_FORM_data1:
11264 return "DW_FORM_data1";
11266 return "DW_FORM_flag";
11267 case DW_FORM_sdata:
11268 return "DW_FORM_sdata";
11270 return "DW_FORM_strp";
11271 case DW_FORM_udata:
11272 return "DW_FORM_udata";
11273 case DW_FORM_ref_addr:
11274 return "DW_FORM_ref_addr";
11276 return "DW_FORM_ref1";
11278 return "DW_FORM_ref2";
11280 return "DW_FORM_ref4";
11282 return "DW_FORM_ref8";
11283 case DW_FORM_ref_udata:
11284 return "DW_FORM_ref_udata";
11285 case DW_FORM_indirect:
11286 return "DW_FORM_indirect";
11287 case DW_FORM_sec_offset:
11288 return "DW_FORM_sec_offset";
11289 case DW_FORM_exprloc:
11290 return "DW_FORM_exprloc";
11291 case DW_FORM_flag_present:
11292 return "DW_FORM_flag_present";
11294 return "DW_FORM_sig8";
11296 return "DW_FORM_<unknown>";
11300 /* Convert a DWARF stack opcode into its string name. */
11303 dwarf_stack_op_name (unsigned op, int def)
11308 return "DW_OP_addr";
11310 return "DW_OP_deref";
11311 case DW_OP_const1u:
11312 return "DW_OP_const1u";
11313 case DW_OP_const1s:
11314 return "DW_OP_const1s";
11315 case DW_OP_const2u:
11316 return "DW_OP_const2u";
11317 case DW_OP_const2s:
11318 return "DW_OP_const2s";
11319 case DW_OP_const4u:
11320 return "DW_OP_const4u";
11321 case DW_OP_const4s:
11322 return "DW_OP_const4s";
11323 case DW_OP_const8u:
11324 return "DW_OP_const8u";
11325 case DW_OP_const8s:
11326 return "DW_OP_const8s";
11328 return "DW_OP_constu";
11330 return "DW_OP_consts";
11332 return "DW_OP_dup";
11334 return "DW_OP_drop";
11336 return "DW_OP_over";
11338 return "DW_OP_pick";
11340 return "DW_OP_swap";
11342 return "DW_OP_rot";
11344 return "DW_OP_xderef";
11346 return "DW_OP_abs";
11348 return "DW_OP_and";
11350 return "DW_OP_div";
11352 return "DW_OP_minus";
11354 return "DW_OP_mod";
11356 return "DW_OP_mul";
11358 return "DW_OP_neg";
11360 return "DW_OP_not";
11364 return "DW_OP_plus";
11365 case DW_OP_plus_uconst:
11366 return "DW_OP_plus_uconst";
11368 return "DW_OP_shl";
11370 return "DW_OP_shr";
11372 return "DW_OP_shra";
11374 return "DW_OP_xor";
11376 return "DW_OP_bra";
11390 return "DW_OP_skip";
11392 return "DW_OP_lit0";
11394 return "DW_OP_lit1";
11396 return "DW_OP_lit2";
11398 return "DW_OP_lit3";
11400 return "DW_OP_lit4";
11402 return "DW_OP_lit5";
11404 return "DW_OP_lit6";
11406 return "DW_OP_lit7";
11408 return "DW_OP_lit8";
11410 return "DW_OP_lit9";
11412 return "DW_OP_lit10";
11414 return "DW_OP_lit11";
11416 return "DW_OP_lit12";
11418 return "DW_OP_lit13";
11420 return "DW_OP_lit14";
11422 return "DW_OP_lit15";
11424 return "DW_OP_lit16";
11426 return "DW_OP_lit17";
11428 return "DW_OP_lit18";
11430 return "DW_OP_lit19";
11432 return "DW_OP_lit20";
11434 return "DW_OP_lit21";
11436 return "DW_OP_lit22";
11438 return "DW_OP_lit23";
11440 return "DW_OP_lit24";
11442 return "DW_OP_lit25";
11444 return "DW_OP_lit26";
11446 return "DW_OP_lit27";
11448 return "DW_OP_lit28";
11450 return "DW_OP_lit29";
11452 return "DW_OP_lit30";
11454 return "DW_OP_lit31";
11456 return "DW_OP_reg0";
11458 return "DW_OP_reg1";
11460 return "DW_OP_reg2";
11462 return "DW_OP_reg3";
11464 return "DW_OP_reg4";
11466 return "DW_OP_reg5";
11468 return "DW_OP_reg6";
11470 return "DW_OP_reg7";
11472 return "DW_OP_reg8";
11474 return "DW_OP_reg9";
11476 return "DW_OP_reg10";
11478 return "DW_OP_reg11";
11480 return "DW_OP_reg12";
11482 return "DW_OP_reg13";
11484 return "DW_OP_reg14";
11486 return "DW_OP_reg15";
11488 return "DW_OP_reg16";
11490 return "DW_OP_reg17";
11492 return "DW_OP_reg18";
11494 return "DW_OP_reg19";
11496 return "DW_OP_reg20";
11498 return "DW_OP_reg21";
11500 return "DW_OP_reg22";
11502 return "DW_OP_reg23";
11504 return "DW_OP_reg24";
11506 return "DW_OP_reg25";
11508 return "DW_OP_reg26";
11510 return "DW_OP_reg27";
11512 return "DW_OP_reg28";
11514 return "DW_OP_reg29";
11516 return "DW_OP_reg30";
11518 return "DW_OP_reg31";
11520 return "DW_OP_breg0";
11522 return "DW_OP_breg1";
11524 return "DW_OP_breg2";
11526 return "DW_OP_breg3";
11528 return "DW_OP_breg4";
11530 return "DW_OP_breg5";
11532 return "DW_OP_breg6";
11534 return "DW_OP_breg7";
11536 return "DW_OP_breg8";
11538 return "DW_OP_breg9";
11540 return "DW_OP_breg10";
11542 return "DW_OP_breg11";
11544 return "DW_OP_breg12";
11546 return "DW_OP_breg13";
11548 return "DW_OP_breg14";
11550 return "DW_OP_breg15";
11552 return "DW_OP_breg16";
11554 return "DW_OP_breg17";
11556 return "DW_OP_breg18";
11558 return "DW_OP_breg19";
11560 return "DW_OP_breg20";
11562 return "DW_OP_breg21";
11564 return "DW_OP_breg22";
11566 return "DW_OP_breg23";
11568 return "DW_OP_breg24";
11570 return "DW_OP_breg25";
11572 return "DW_OP_breg26";
11574 return "DW_OP_breg27";
11576 return "DW_OP_breg28";
11578 return "DW_OP_breg29";
11580 return "DW_OP_breg30";
11582 return "DW_OP_breg31";
11584 return "DW_OP_regx";
11586 return "DW_OP_fbreg";
11588 return "DW_OP_bregx";
11590 return "DW_OP_piece";
11591 case DW_OP_deref_size:
11592 return "DW_OP_deref_size";
11593 case DW_OP_xderef_size:
11594 return "DW_OP_xderef_size";
11596 return "DW_OP_nop";
11597 /* DWARF 3 extensions. */
11598 case DW_OP_push_object_address:
11599 return "DW_OP_push_object_address";
11601 return "DW_OP_call2";
11603 return "DW_OP_call4";
11604 case DW_OP_call_ref:
11605 return "DW_OP_call_ref";
11606 case DW_OP_form_tls_address:
11607 return "DW_OP_form_tls_address";
11608 case DW_OP_call_frame_cfa:
11609 return "DW_OP_call_frame_cfa";
11610 case DW_OP_bit_piece:
11611 return "DW_OP_bit_piece";
11612 /* DWARF 4 extensions. */
11613 case DW_OP_implicit_value:
11614 return "DW_OP_implicit_value";
11615 case DW_OP_stack_value:
11616 return "DW_OP_stack_value";
11617 /* GNU extensions. */
11618 case DW_OP_GNU_push_tls_address:
11619 return "DW_OP_GNU_push_tls_address";
11620 case DW_OP_GNU_uninit:
11621 return "DW_OP_GNU_uninit";
11623 return def ? "OP_<unknown>" : NULL;
11628 dwarf_bool_name (unsigned mybool)
11636 /* Convert a DWARF type code into its string name. */
11639 dwarf_type_encoding_name (unsigned enc)
11644 return "DW_ATE_void";
11645 case DW_ATE_address:
11646 return "DW_ATE_address";
11647 case DW_ATE_boolean:
11648 return "DW_ATE_boolean";
11649 case DW_ATE_complex_float:
11650 return "DW_ATE_complex_float";
11652 return "DW_ATE_float";
11653 case DW_ATE_signed:
11654 return "DW_ATE_signed";
11655 case DW_ATE_signed_char:
11656 return "DW_ATE_signed_char";
11657 case DW_ATE_unsigned:
11658 return "DW_ATE_unsigned";
11659 case DW_ATE_unsigned_char:
11660 return "DW_ATE_unsigned_char";
11662 case DW_ATE_imaginary_float:
11663 return "DW_ATE_imaginary_float";
11664 case DW_ATE_packed_decimal:
11665 return "DW_ATE_packed_decimal";
11666 case DW_ATE_numeric_string:
11667 return "DW_ATE_numeric_string";
11668 case DW_ATE_edited:
11669 return "DW_ATE_edited";
11670 case DW_ATE_signed_fixed:
11671 return "DW_ATE_signed_fixed";
11672 case DW_ATE_unsigned_fixed:
11673 return "DW_ATE_unsigned_fixed";
11674 case DW_ATE_decimal_float:
11675 return "DW_ATE_decimal_float";
11678 return "DW_ATE_UTF";
11679 /* HP extensions. */
11680 case DW_ATE_HP_float80:
11681 return "DW_ATE_HP_float80";
11682 case DW_ATE_HP_complex_float80:
11683 return "DW_ATE_HP_complex_float80";
11684 case DW_ATE_HP_float128:
11685 return "DW_ATE_HP_float128";
11686 case DW_ATE_HP_complex_float128:
11687 return "DW_ATE_HP_complex_float128";
11688 case DW_ATE_HP_floathpintel:
11689 return "DW_ATE_HP_floathpintel";
11690 case DW_ATE_HP_imaginary_float80:
11691 return "DW_ATE_HP_imaginary_float80";
11692 case DW_ATE_HP_imaginary_float128:
11693 return "DW_ATE_HP_imaginary_float128";
11695 return "DW_ATE_<unknown>";
11699 /* Convert a DWARF call frame info operation to its string name. */
11703 dwarf_cfi_name (unsigned cfi_opc)
11707 case DW_CFA_advance_loc:
11708 return "DW_CFA_advance_loc";
11709 case DW_CFA_offset:
11710 return "DW_CFA_offset";
11711 case DW_CFA_restore:
11712 return "DW_CFA_restore";
11714 return "DW_CFA_nop";
11715 case DW_CFA_set_loc:
11716 return "DW_CFA_set_loc";
11717 case DW_CFA_advance_loc1:
11718 return "DW_CFA_advance_loc1";
11719 case DW_CFA_advance_loc2:
11720 return "DW_CFA_advance_loc2";
11721 case DW_CFA_advance_loc4:
11722 return "DW_CFA_advance_loc4";
11723 case DW_CFA_offset_extended:
11724 return "DW_CFA_offset_extended";
11725 case DW_CFA_restore_extended:
11726 return "DW_CFA_restore_extended";
11727 case DW_CFA_undefined:
11728 return "DW_CFA_undefined";
11729 case DW_CFA_same_value:
11730 return "DW_CFA_same_value";
11731 case DW_CFA_register:
11732 return "DW_CFA_register";
11733 case DW_CFA_remember_state:
11734 return "DW_CFA_remember_state";
11735 case DW_CFA_restore_state:
11736 return "DW_CFA_restore_state";
11737 case DW_CFA_def_cfa:
11738 return "DW_CFA_def_cfa";
11739 case DW_CFA_def_cfa_register:
11740 return "DW_CFA_def_cfa_register";
11741 case DW_CFA_def_cfa_offset:
11742 return "DW_CFA_def_cfa_offset";
11744 case DW_CFA_def_cfa_expression:
11745 return "DW_CFA_def_cfa_expression";
11746 case DW_CFA_expression:
11747 return "DW_CFA_expression";
11748 case DW_CFA_offset_extended_sf:
11749 return "DW_CFA_offset_extended_sf";
11750 case DW_CFA_def_cfa_sf:
11751 return "DW_CFA_def_cfa_sf";
11752 case DW_CFA_def_cfa_offset_sf:
11753 return "DW_CFA_def_cfa_offset_sf";
11754 case DW_CFA_val_offset:
11755 return "DW_CFA_val_offset";
11756 case DW_CFA_val_offset_sf:
11757 return "DW_CFA_val_offset_sf";
11758 case DW_CFA_val_expression:
11759 return "DW_CFA_val_expression";
11760 /* SGI/MIPS specific. */
11761 case DW_CFA_MIPS_advance_loc8:
11762 return "DW_CFA_MIPS_advance_loc8";
11763 /* GNU extensions. */
11764 case DW_CFA_GNU_window_save:
11765 return "DW_CFA_GNU_window_save";
11766 case DW_CFA_GNU_args_size:
11767 return "DW_CFA_GNU_args_size";
11768 case DW_CFA_GNU_negative_offset_extended:
11769 return "DW_CFA_GNU_negative_offset_extended";
11771 return "DW_CFA_<unknown>";
11777 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
11781 print_spaces (indent, f);
11782 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
11783 dwarf_tag_name (die->tag), die->abbrev, die->offset);
11785 if (die->parent != NULL)
11787 print_spaces (indent, f);
11788 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
11789 die->parent->offset);
11792 print_spaces (indent, f);
11793 fprintf_unfiltered (f, " has children: %s\n",
11794 dwarf_bool_name (die->child != NULL));
11796 print_spaces (indent, f);
11797 fprintf_unfiltered (f, " attributes:\n");
11799 for (i = 0; i < die->num_attrs; ++i)
11801 print_spaces (indent, f);
11802 fprintf_unfiltered (f, " %s (%s) ",
11803 dwarf_attr_name (die->attrs[i].name),
11804 dwarf_form_name (die->attrs[i].form));
11806 switch (die->attrs[i].form)
11808 case DW_FORM_ref_addr:
11810 fprintf_unfiltered (f, "address: ");
11811 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
11813 case DW_FORM_block2:
11814 case DW_FORM_block4:
11815 case DW_FORM_block:
11816 case DW_FORM_block1:
11817 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
11819 case DW_FORM_exprloc:
11820 fprintf_unfiltered (f, "expression: size %u",
11821 DW_BLOCK (&die->attrs[i])->size);
11826 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
11827 (long) (DW_ADDR (&die->attrs[i])));
11829 case DW_FORM_data1:
11830 case DW_FORM_data2:
11831 case DW_FORM_data4:
11832 case DW_FORM_data8:
11833 case DW_FORM_udata:
11834 case DW_FORM_sdata:
11835 fprintf_unfiltered (f, "constant: %s",
11836 pulongest (DW_UNSND (&die->attrs[i])));
11838 case DW_FORM_sec_offset:
11839 fprintf_unfiltered (f, "section offset: %s",
11840 pulongest (DW_UNSND (&die->attrs[i])));
11843 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
11844 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
11845 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
11847 fprintf_unfiltered (f, "signatured type, offset: unknown");
11849 case DW_FORM_string:
11851 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
11852 DW_STRING (&die->attrs[i])
11853 ? DW_STRING (&die->attrs[i]) : "",
11854 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
11857 if (DW_UNSND (&die->attrs[i]))
11858 fprintf_unfiltered (f, "flag: TRUE");
11860 fprintf_unfiltered (f, "flag: FALSE");
11862 case DW_FORM_flag_present:
11863 fprintf_unfiltered (f, "flag: TRUE");
11865 case DW_FORM_indirect:
11866 /* the reader will have reduced the indirect form to
11867 the "base form" so this form should not occur */
11868 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
11871 fprintf_unfiltered (f, "unsupported attribute form: %d.",
11872 die->attrs[i].form);
11875 fprintf_unfiltered (f, "\n");
11880 dump_die_for_error (struct die_info *die)
11882 dump_die_shallow (gdb_stderr, 0, die);
11886 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
11888 int indent = level * 4;
11890 gdb_assert (die != NULL);
11892 if (level >= max_level)
11895 dump_die_shallow (f, indent, die);
11897 if (die->child != NULL)
11899 print_spaces (indent, f);
11900 fprintf_unfiltered (f, " Children:");
11901 if (level + 1 < max_level)
11903 fprintf_unfiltered (f, "\n");
11904 dump_die_1 (f, level + 1, max_level, die->child);
11908 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
11912 if (die->sibling != NULL && level > 0)
11914 dump_die_1 (f, level, max_level, die->sibling);
11918 /* This is called from the pdie macro in gdbinit.in.
11919 It's not static so gcc will keep a copy callable from gdb. */
11922 dump_die (struct die_info *die, int max_level)
11924 dump_die_1 (gdb_stdlog, 0, max_level, die);
11928 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
11932 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
11938 is_ref_attr (struct attribute *attr)
11940 switch (attr->form)
11942 case DW_FORM_ref_addr:
11947 case DW_FORM_ref_udata:
11954 static unsigned int
11955 dwarf2_get_ref_die_offset (struct attribute *attr)
11957 if (is_ref_attr (attr))
11958 return DW_ADDR (attr);
11960 complaint (&symfile_complaints,
11961 _("unsupported die ref attribute form: '%s'"),
11962 dwarf_form_name (attr->form));
11966 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
11967 * the value held by the attribute is not constant. */
11970 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
11972 if (attr->form == DW_FORM_sdata)
11973 return DW_SND (attr);
11974 else if (attr->form == DW_FORM_udata
11975 || attr->form == DW_FORM_data1
11976 || attr->form == DW_FORM_data2
11977 || attr->form == DW_FORM_data4
11978 || attr->form == DW_FORM_data8)
11979 return DW_UNSND (attr);
11982 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
11983 dwarf_form_name (attr->form));
11984 return default_value;
11988 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
11989 unit and add it to our queue.
11990 The result is non-zero if PER_CU was queued, otherwise the result is zero
11991 meaning either PER_CU is already queued or it is already loaded. */
11994 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
11995 struct dwarf2_per_cu_data *per_cu)
11997 /* Mark the dependence relation so that we don't flush PER_CU
11999 dwarf2_add_dependence (this_cu, per_cu);
12001 /* If it's already on the queue, we have nothing to do. */
12002 if (per_cu->queued)
12005 /* If the compilation unit is already loaded, just mark it as
12007 if (per_cu->cu != NULL)
12009 per_cu->cu->last_used = 0;
12013 /* Add it to the queue. */
12014 queue_comp_unit (per_cu, this_cu->objfile);
12019 /* Follow reference or signature attribute ATTR of SRC_DIE.
12020 On entry *REF_CU is the CU of SRC_DIE.
12021 On exit *REF_CU is the CU of the result. */
12023 static struct die_info *
12024 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
12025 struct dwarf2_cu **ref_cu)
12027 struct die_info *die;
12029 if (is_ref_attr (attr))
12030 die = follow_die_ref (src_die, attr, ref_cu);
12031 else if (attr->form == DW_FORM_sig8)
12032 die = follow_die_sig (src_die, attr, ref_cu);
12035 dump_die_for_error (src_die);
12036 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12037 (*ref_cu)->objfile->name);
12043 /* Follow reference OFFSET.
12044 On entry *REF_CU is the CU of source DIE referencing OFFSET.
12045 On exit *REF_CU is the CU of the result. */
12047 static struct die_info *
12048 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
12050 struct die_info temp_die;
12051 struct dwarf2_cu *target_cu, *cu = *ref_cu;
12053 gdb_assert (cu->per_cu != NULL);
12055 if (cu->per_cu->from_debug_types)
12057 /* .debug_types CUs cannot reference anything outside their CU.
12058 If they need to, they have to reference a signatured type via
12060 if (! offset_in_cu_p (&cu->header, offset))
12064 else if (! offset_in_cu_p (&cu->header, offset))
12066 struct dwarf2_per_cu_data *per_cu;
12068 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
12070 /* If necessary, add it to the queue and load its DIEs. */
12071 if (maybe_queue_comp_unit (cu, per_cu))
12072 load_full_comp_unit (per_cu, cu->objfile);
12074 target_cu = per_cu->cu;
12079 *ref_cu = target_cu;
12080 temp_die.offset = offset;
12081 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
12084 /* Follow reference attribute ATTR of SRC_DIE.
12085 On entry *REF_CU is the CU of SRC_DIE.
12086 On exit *REF_CU is the CU of the result. */
12088 static struct die_info *
12089 follow_die_ref (struct die_info *src_die, struct attribute *attr,
12090 struct dwarf2_cu **ref_cu)
12092 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12093 struct dwarf2_cu *cu = *ref_cu;
12094 struct die_info *die;
12096 die = follow_die_offset (offset, ref_cu);
12098 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12099 "at 0x%x [in module %s]"),
12100 offset, src_die->offset, cu->objfile->name);
12105 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12106 value is intended for DW_OP_call*. */
12108 struct dwarf2_locexpr_baton
12109 dwarf2_fetch_die_location_block (unsigned int offset,
12110 struct dwarf2_per_cu_data *per_cu)
12112 struct dwarf2_cu *cu = per_cu->cu;
12113 struct die_info *die;
12114 struct attribute *attr;
12115 struct dwarf2_locexpr_baton retval;
12117 die = follow_die_offset (offset, &cu);
12119 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12120 offset, per_cu->cu->objfile->name);
12122 attr = dwarf2_attr (die, DW_AT_location, cu);
12125 /* DWARF: "If there is no such attribute, then there is no effect.". */
12127 retval.data = NULL;
12132 if (!attr_form_is_block (attr))
12133 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12134 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12135 offset, per_cu->cu->objfile->name);
12137 retval.data = DW_BLOCK (attr)->data;
12138 retval.size = DW_BLOCK (attr)->size;
12140 retval.per_cu = cu->per_cu;
12144 /* Follow the signature attribute ATTR in SRC_DIE.
12145 On entry *REF_CU is the CU of SRC_DIE.
12146 On exit *REF_CU is the CU of the result. */
12148 static struct die_info *
12149 follow_die_sig (struct die_info *src_die, struct attribute *attr,
12150 struct dwarf2_cu **ref_cu)
12152 struct objfile *objfile = (*ref_cu)->objfile;
12153 struct die_info temp_die;
12154 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12155 struct dwarf2_cu *sig_cu;
12156 struct die_info *die;
12158 /* sig_type will be NULL if the signatured type is missing from
12160 if (sig_type == NULL)
12161 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12162 "at 0x%x [in module %s]"),
12163 src_die->offset, objfile->name);
12165 /* If necessary, add it to the queue and load its DIEs. */
12167 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
12168 read_signatured_type (objfile, sig_type);
12170 gdb_assert (sig_type->per_cu.cu != NULL);
12172 sig_cu = sig_type->per_cu.cu;
12173 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
12174 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
12181 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12182 "at 0x%x [in module %s]"),
12183 sig_type->type_offset, src_die->offset, objfile->name);
12186 /* Given an offset of a signatured type, return its signatured_type. */
12188 static struct signatured_type *
12189 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
12191 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
12192 unsigned int length, initial_length_size;
12193 unsigned int sig_offset;
12194 struct signatured_type find_entry, *type_sig;
12196 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
12197 sig_offset = (initial_length_size
12199 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
12200 + 1 /*address_size*/);
12201 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
12202 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
12204 /* This is only used to lookup previously recorded types.
12205 If we didn't find it, it's our bug. */
12206 gdb_assert (type_sig != NULL);
12207 gdb_assert (offset == type_sig->offset);
12212 /* Read in signatured type at OFFSET and build its CU and die(s). */
12215 read_signatured_type_at_offset (struct objfile *objfile,
12216 unsigned int offset)
12218 struct signatured_type *type_sig;
12220 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
12222 /* We have the section offset, but we need the signature to do the
12223 hash table lookup. */
12224 type_sig = lookup_signatured_type_at_offset (objfile, offset);
12226 gdb_assert (type_sig->per_cu.cu == NULL);
12228 read_signatured_type (objfile, type_sig);
12230 gdb_assert (type_sig->per_cu.cu != NULL);
12233 /* Read in a signatured type and build its CU and DIEs. */
12236 read_signatured_type (struct objfile *objfile,
12237 struct signatured_type *type_sig)
12239 gdb_byte *types_ptr;
12240 struct die_reader_specs reader_specs;
12241 struct dwarf2_cu *cu;
12242 ULONGEST signature;
12243 struct cleanup *back_to, *free_cu_cleanup;
12244 struct attribute *attr;
12246 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
12247 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
12249 gdb_assert (type_sig->per_cu.cu == NULL);
12251 cu = xmalloc (sizeof (struct dwarf2_cu));
12252 memset (cu, 0, sizeof (struct dwarf2_cu));
12253 obstack_init (&cu->comp_unit_obstack);
12254 cu->objfile = objfile;
12255 type_sig->per_cu.cu = cu;
12256 cu->per_cu = &type_sig->per_cu;
12258 /* If an error occurs while loading, release our storage. */
12259 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
12261 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
12262 types_ptr, objfile->obfd);
12263 gdb_assert (signature == type_sig->signature);
12266 = htab_create_alloc_ex (cu->header.length / 12,
12270 &cu->comp_unit_obstack,
12271 hashtab_obstack_allocate,
12272 dummy_obstack_deallocate);
12274 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
12275 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
12277 init_cu_die_reader (&reader_specs, cu);
12279 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
12282 /* We try not to read any attributes in this function, because not
12283 all objfiles needed for references have been loaded yet, and symbol
12284 table processing isn't initialized. But we have to set the CU language,
12285 or we won't be able to build types correctly. */
12286 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
12288 set_cu_language (DW_UNSND (attr), cu);
12290 set_cu_language (language_minimal, cu);
12292 do_cleanups (back_to);
12294 /* We've successfully allocated this compilation unit. Let our caller
12295 clean it up when finished with it. */
12296 discard_cleanups (free_cu_cleanup);
12298 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
12299 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
12302 /* Decode simple location descriptions.
12303 Given a pointer to a dwarf block that defines a location, compute
12304 the location and return the value.
12306 NOTE drow/2003-11-18: This function is called in two situations
12307 now: for the address of static or global variables (partial symbols
12308 only) and for offsets into structures which are expected to be
12309 (more or less) constant. The partial symbol case should go away,
12310 and only the constant case should remain. That will let this
12311 function complain more accurately. A few special modes are allowed
12312 without complaint for global variables (for instance, global
12313 register values and thread-local values).
12315 A location description containing no operations indicates that the
12316 object is optimized out. The return value is 0 for that case.
12317 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12318 callers will only want a very basic result and this can become a
12321 Note that stack[0] is unused except as a default error return.
12322 Note that stack overflow is not yet handled. */
12325 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
12327 struct objfile *objfile = cu->objfile;
12329 int size = blk->size;
12330 gdb_byte *data = blk->data;
12331 CORE_ADDR stack[64];
12333 unsigned int bytes_read, unsnd;
12377 stack[++stacki] = op - DW_OP_lit0;
12412 stack[++stacki] = op - DW_OP_reg0;
12414 dwarf2_complex_location_expr_complaint ();
12418 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
12420 stack[++stacki] = unsnd;
12422 dwarf2_complex_location_expr_complaint ();
12426 stack[++stacki] = read_address (objfile->obfd, &data[i],
12431 case DW_OP_const1u:
12432 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
12436 case DW_OP_const1s:
12437 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
12441 case DW_OP_const2u:
12442 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
12446 case DW_OP_const2s:
12447 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
12451 case DW_OP_const4u:
12452 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
12456 case DW_OP_const4s:
12457 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
12462 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
12468 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
12473 stack[stacki + 1] = stack[stacki];
12478 stack[stacki - 1] += stack[stacki];
12482 case DW_OP_plus_uconst:
12483 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
12488 stack[stacki - 1] -= stack[stacki];
12493 /* If we're not the last op, then we definitely can't encode
12494 this using GDB's address_class enum. This is valid for partial
12495 global symbols, although the variable's address will be bogus
12498 dwarf2_complex_location_expr_complaint ();
12501 case DW_OP_GNU_push_tls_address:
12502 /* The top of the stack has the offset from the beginning
12503 of the thread control block at which the variable is located. */
12504 /* Nothing should follow this operator, so the top of stack would
12506 /* This is valid for partial global symbols, but the variable's
12507 address will be bogus in the psymtab. */
12509 dwarf2_complex_location_expr_complaint ();
12512 case DW_OP_GNU_uninit:
12516 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
12517 dwarf_stack_op_name (op, 1));
12518 return (stack[stacki]);
12521 return (stack[stacki]);
12524 /* memory allocation interface */
12526 static struct dwarf_block *
12527 dwarf_alloc_block (struct dwarf2_cu *cu)
12529 struct dwarf_block *blk;
12531 blk = (struct dwarf_block *)
12532 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
12536 static struct abbrev_info *
12537 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
12539 struct abbrev_info *abbrev;
12541 abbrev = (struct abbrev_info *)
12542 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
12543 memset (abbrev, 0, sizeof (struct abbrev_info));
12547 static struct die_info *
12548 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
12550 struct die_info *die;
12551 size_t size = sizeof (struct die_info);
12554 size += (num_attrs - 1) * sizeof (struct attribute);
12556 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
12557 memset (die, 0, sizeof (struct die_info));
12562 /* Macro support. */
12565 /* Return the full name of file number I in *LH's file name table.
12566 Use COMP_DIR as the name of the current directory of the
12567 compilation. The result is allocated using xmalloc; the caller is
12568 responsible for freeing it. */
12570 file_full_name (int file, struct line_header *lh, const char *comp_dir)
12572 /* Is the file number a valid index into the line header's file name
12573 table? Remember that file numbers start with one, not zero. */
12574 if (1 <= file && file <= lh->num_file_names)
12576 struct file_entry *fe = &lh->file_names[file - 1];
12578 if (IS_ABSOLUTE_PATH (fe->name))
12579 return xstrdup (fe->name);
12587 dir = lh->include_dirs[fe->dir_index - 1];
12593 dir_len = strlen (dir);
12594 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
12595 strcpy (full_name, dir);
12596 full_name[dir_len] = '/';
12597 strcpy (full_name + dir_len + 1, fe->name);
12601 return xstrdup (fe->name);
12606 /* The compiler produced a bogus file number. We can at least
12607 record the macro definitions made in the file, even if we
12608 won't be able to find the file by name. */
12609 char fake_name[80];
12611 sprintf (fake_name, "<bad macro file number %d>", file);
12613 complaint (&symfile_complaints,
12614 _("bad file number in macro information (%d)"),
12617 return xstrdup (fake_name);
12622 static struct macro_source_file *
12623 macro_start_file (int file, int line,
12624 struct macro_source_file *current_file,
12625 const char *comp_dir,
12626 struct line_header *lh, struct objfile *objfile)
12628 /* The full name of this source file. */
12629 char *full_name = file_full_name (file, lh, comp_dir);
12631 /* We don't create a macro table for this compilation unit
12632 at all until we actually get a filename. */
12633 if (! pending_macros)
12634 pending_macros = new_macro_table (&objfile->objfile_obstack,
12635 objfile->macro_cache);
12637 if (! current_file)
12638 /* If we have no current file, then this must be the start_file
12639 directive for the compilation unit's main source file. */
12640 current_file = macro_set_main (pending_macros, full_name);
12642 current_file = macro_include (current_file, line, full_name);
12646 return current_file;
12650 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
12651 followed by a null byte. */
12653 copy_string (const char *buf, int len)
12655 char *s = xmalloc (len + 1);
12657 memcpy (s, buf, len);
12663 static const char *
12664 consume_improper_spaces (const char *p, const char *body)
12668 complaint (&symfile_complaints,
12669 _("macro definition contains spaces in formal argument list:\n`%s'"),
12681 parse_macro_definition (struct macro_source_file *file, int line,
12686 /* The body string takes one of two forms. For object-like macro
12687 definitions, it should be:
12689 <macro name> " " <definition>
12691 For function-like macro definitions, it should be:
12693 <macro name> "() " <definition>
12695 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
12697 Spaces may appear only where explicitly indicated, and in the
12700 The Dwarf 2 spec says that an object-like macro's name is always
12701 followed by a space, but versions of GCC around March 2002 omit
12702 the space when the macro's definition is the empty string.
12704 The Dwarf 2 spec says that there should be no spaces between the
12705 formal arguments in a function-like macro's formal argument list,
12706 but versions of GCC around March 2002 include spaces after the
12710 /* Find the extent of the macro name. The macro name is terminated
12711 by either a space or null character (for an object-like macro) or
12712 an opening paren (for a function-like macro). */
12713 for (p = body; *p; p++)
12714 if (*p == ' ' || *p == '(')
12717 if (*p == ' ' || *p == '\0')
12719 /* It's an object-like macro. */
12720 int name_len = p - body;
12721 char *name = copy_string (body, name_len);
12722 const char *replacement;
12725 replacement = body + name_len + 1;
12728 dwarf2_macro_malformed_definition_complaint (body);
12729 replacement = body + name_len;
12732 macro_define_object (file, line, name, replacement);
12736 else if (*p == '(')
12738 /* It's a function-like macro. */
12739 char *name = copy_string (body, p - body);
12742 char **argv = xmalloc (argv_size * sizeof (*argv));
12746 p = consume_improper_spaces (p, body);
12748 /* Parse the formal argument list. */
12749 while (*p && *p != ')')
12751 /* Find the extent of the current argument name. */
12752 const char *arg_start = p;
12754 while (*p && *p != ',' && *p != ')' && *p != ' ')
12757 if (! *p || p == arg_start)
12758 dwarf2_macro_malformed_definition_complaint (body);
12761 /* Make sure argv has room for the new argument. */
12762 if (argc >= argv_size)
12765 argv = xrealloc (argv, argv_size * sizeof (*argv));
12768 argv[argc++] = copy_string (arg_start, p - arg_start);
12771 p = consume_improper_spaces (p, body);
12773 /* Consume the comma, if present. */
12778 p = consume_improper_spaces (p, body);
12787 /* Perfectly formed definition, no complaints. */
12788 macro_define_function (file, line, name,
12789 argc, (const char **) argv,
12791 else if (*p == '\0')
12793 /* Complain, but do define it. */
12794 dwarf2_macro_malformed_definition_complaint (body);
12795 macro_define_function (file, line, name,
12796 argc, (const char **) argv,
12800 /* Just complain. */
12801 dwarf2_macro_malformed_definition_complaint (body);
12804 /* Just complain. */
12805 dwarf2_macro_malformed_definition_complaint (body);
12811 for (i = 0; i < argc; i++)
12817 dwarf2_macro_malformed_definition_complaint (body);
12822 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
12823 char *comp_dir, bfd *abfd,
12824 struct dwarf2_cu *cu)
12826 gdb_byte *mac_ptr, *mac_end;
12827 struct macro_source_file *current_file = 0;
12828 enum dwarf_macinfo_record_type macinfo_type;
12829 int at_commandline;
12831 dwarf2_read_section (dwarf2_per_objfile->objfile,
12832 &dwarf2_per_objfile->macinfo);
12833 if (dwarf2_per_objfile->macinfo.buffer == NULL)
12835 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
12839 /* First pass: Find the name of the base filename.
12840 This filename is needed in order to process all macros whose definition
12841 (or undefinition) comes from the command line. These macros are defined
12842 before the first DW_MACINFO_start_file entry, and yet still need to be
12843 associated to the base file.
12845 To determine the base file name, we scan the macro definitions until we
12846 reach the first DW_MACINFO_start_file entry. We then initialize
12847 CURRENT_FILE accordingly so that any macro definition found before the
12848 first DW_MACINFO_start_file can still be associated to the base file. */
12850 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
12851 mac_end = dwarf2_per_objfile->macinfo.buffer
12852 + dwarf2_per_objfile->macinfo.size;
12856 /* Do we at least have room for a macinfo type byte? */
12857 if (mac_ptr >= mac_end)
12859 /* Complaint is printed during the second pass as GDB will probably
12860 stop the first pass earlier upon finding DW_MACINFO_start_file. */
12864 macinfo_type = read_1_byte (abfd, mac_ptr);
12867 switch (macinfo_type)
12869 /* A zero macinfo type indicates the end of the macro
12874 case DW_MACINFO_define:
12875 case DW_MACINFO_undef:
12876 /* Only skip the data by MAC_PTR. */
12878 unsigned int bytes_read;
12880 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12881 mac_ptr += bytes_read;
12882 read_direct_string (abfd, mac_ptr, &bytes_read);
12883 mac_ptr += bytes_read;
12887 case DW_MACINFO_start_file:
12889 unsigned int bytes_read;
12892 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12893 mac_ptr += bytes_read;
12894 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12895 mac_ptr += bytes_read;
12897 current_file = macro_start_file (file, line, current_file, comp_dir,
12902 case DW_MACINFO_end_file:
12903 /* No data to skip by MAC_PTR. */
12906 case DW_MACINFO_vendor_ext:
12907 /* Only skip the data by MAC_PTR. */
12909 unsigned int bytes_read;
12911 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12912 mac_ptr += bytes_read;
12913 read_direct_string (abfd, mac_ptr, &bytes_read);
12914 mac_ptr += bytes_read;
12921 } while (macinfo_type != 0 && current_file == NULL);
12923 /* Second pass: Process all entries.
12925 Use the AT_COMMAND_LINE flag to determine whether we are still processing
12926 command-line macro definitions/undefinitions. This flag is unset when we
12927 reach the first DW_MACINFO_start_file entry. */
12929 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
12931 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
12932 GDB is still reading the definitions from command line. First
12933 DW_MACINFO_start_file will need to be ignored as it was already executed
12934 to create CURRENT_FILE for the main source holding also the command line
12935 definitions. On first met DW_MACINFO_start_file this flag is reset to
12936 normally execute all the remaining DW_MACINFO_start_file macinfos. */
12938 at_commandline = 1;
12942 /* Do we at least have room for a macinfo type byte? */
12943 if (mac_ptr >= mac_end)
12945 dwarf2_macros_too_long_complaint ();
12949 macinfo_type = read_1_byte (abfd, mac_ptr);
12952 switch (macinfo_type)
12954 /* A zero macinfo type indicates the end of the macro
12959 case DW_MACINFO_define:
12960 case DW_MACINFO_undef:
12962 unsigned int bytes_read;
12966 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12967 mac_ptr += bytes_read;
12968 body = read_direct_string (abfd, mac_ptr, &bytes_read);
12969 mac_ptr += bytes_read;
12971 if (! current_file)
12973 /* DWARF violation as no main source is present. */
12974 complaint (&symfile_complaints,
12975 _("debug info with no main source gives macro %s "
12977 macinfo_type == DW_MACINFO_define ?
12979 macinfo_type == DW_MACINFO_undef ?
12980 _("undefinition") :
12981 _("something-or-other"), line, body);
12984 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
12985 complaint (&symfile_complaints,
12986 _("debug info gives %s macro %s with %s line %d: %s"),
12987 at_commandline ? _("command-line") : _("in-file"),
12988 macinfo_type == DW_MACINFO_define ?
12990 macinfo_type == DW_MACINFO_undef ?
12991 _("undefinition") :
12992 _("something-or-other"),
12993 line == 0 ? _("zero") : _("non-zero"), line, body);
12995 if (macinfo_type == DW_MACINFO_define)
12996 parse_macro_definition (current_file, line, body);
12997 else if (macinfo_type == DW_MACINFO_undef)
12998 macro_undef (current_file, line, body);
13002 case DW_MACINFO_start_file:
13004 unsigned int bytes_read;
13007 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13008 mac_ptr += bytes_read;
13009 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13010 mac_ptr += bytes_read;
13012 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
13013 complaint (&symfile_complaints,
13014 _("debug info gives source %d included "
13015 "from %s at %s line %d"),
13016 file, at_commandline ? _("command-line") : _("file"),
13017 line == 0 ? _("zero") : _("non-zero"), line);
13019 if (at_commandline)
13021 /* This DW_MACINFO_start_file was executed in the pass one. */
13022 at_commandline = 0;
13025 current_file = macro_start_file (file, line,
13026 current_file, comp_dir,
13031 case DW_MACINFO_end_file:
13032 if (! current_file)
13033 complaint (&symfile_complaints,
13034 _("macro debug info has an unmatched `close_file' directive"));
13037 current_file = current_file->included_by;
13038 if (! current_file)
13040 enum dwarf_macinfo_record_type next_type;
13042 /* GCC circa March 2002 doesn't produce the zero
13043 type byte marking the end of the compilation
13044 unit. Complain if it's not there, but exit no
13047 /* Do we at least have room for a macinfo type byte? */
13048 if (mac_ptr >= mac_end)
13050 dwarf2_macros_too_long_complaint ();
13054 /* We don't increment mac_ptr here, so this is just
13056 next_type = read_1_byte (abfd, mac_ptr);
13057 if (next_type != 0)
13058 complaint (&symfile_complaints,
13059 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13066 case DW_MACINFO_vendor_ext:
13068 unsigned int bytes_read;
13072 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13073 mac_ptr += bytes_read;
13074 string = read_direct_string (abfd, mac_ptr, &bytes_read);
13075 mac_ptr += bytes_read;
13077 /* We don't recognize any vendor extensions. */
13081 } while (macinfo_type != 0);
13084 /* Check if the attribute's form is a DW_FORM_block*
13085 if so return true else false. */
13087 attr_form_is_block (struct attribute *attr)
13089 return (attr == NULL ? 0 :
13090 attr->form == DW_FORM_block1
13091 || attr->form == DW_FORM_block2
13092 || attr->form == DW_FORM_block4
13093 || attr->form == DW_FORM_block
13094 || attr->form == DW_FORM_exprloc);
13097 /* Return non-zero if ATTR's value is a section offset --- classes
13098 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13099 You may use DW_UNSND (attr) to retrieve such offsets.
13101 Section 7.5.4, "Attribute Encodings", explains that no attribute
13102 may have a value that belongs to more than one of these classes; it
13103 would be ambiguous if we did, because we use the same forms for all
13106 attr_form_is_section_offset (struct attribute *attr)
13108 return (attr->form == DW_FORM_data4
13109 || attr->form == DW_FORM_data8
13110 || attr->form == DW_FORM_sec_offset);
13114 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13115 zero otherwise. When this function returns true, you can apply
13116 dwarf2_get_attr_constant_value to it.
13118 However, note that for some attributes you must check
13119 attr_form_is_section_offset before using this test. DW_FORM_data4
13120 and DW_FORM_data8 are members of both the constant class, and of
13121 the classes that contain offsets into other debug sections
13122 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13123 that, if an attribute's can be either a constant or one of the
13124 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13125 taken as section offsets, not constants. */
13127 attr_form_is_constant (struct attribute *attr)
13129 switch (attr->form)
13131 case DW_FORM_sdata:
13132 case DW_FORM_udata:
13133 case DW_FORM_data1:
13134 case DW_FORM_data2:
13135 case DW_FORM_data4:
13136 case DW_FORM_data8:
13144 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
13145 struct dwarf2_cu *cu)
13147 if (attr_form_is_section_offset (attr)
13148 /* ".debug_loc" may not exist at all, or the offset may be outside
13149 the section. If so, fall through to the complaint in the
13151 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
13153 struct dwarf2_loclist_baton *baton;
13155 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13156 sizeof (struct dwarf2_loclist_baton));
13157 baton->per_cu = cu->per_cu;
13158 gdb_assert (baton->per_cu);
13160 dwarf2_read_section (dwarf2_per_objfile->objfile,
13161 &dwarf2_per_objfile->loc);
13163 /* We don't know how long the location list is, but make sure we
13164 don't run off the edge of the section. */
13165 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
13166 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
13167 baton->base_address = cu->base_address;
13168 if (cu->base_known == 0)
13169 complaint (&symfile_complaints,
13170 _("Location list used without specifying the CU base address."));
13172 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
13173 SYMBOL_LOCATION_BATON (sym) = baton;
13177 struct dwarf2_locexpr_baton *baton;
13179 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13180 sizeof (struct dwarf2_locexpr_baton));
13181 baton->per_cu = cu->per_cu;
13182 gdb_assert (baton->per_cu);
13184 if (attr_form_is_block (attr))
13186 /* Note that we're just copying the block's data pointer
13187 here, not the actual data. We're still pointing into the
13188 info_buffer for SYM's objfile; right now we never release
13189 that buffer, but when we do clean up properly this may
13191 baton->size = DW_BLOCK (attr)->size;
13192 baton->data = DW_BLOCK (attr)->data;
13196 dwarf2_invalid_attrib_class_complaint ("location description",
13197 SYMBOL_NATURAL_NAME (sym));
13199 baton->data = NULL;
13202 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
13203 SYMBOL_LOCATION_BATON (sym) = baton;
13207 /* Return the OBJFILE associated with the compilation unit CU. If CU
13208 came from a separate debuginfo file, then the master objfile is
13212 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
13214 struct objfile *objfile = per_cu->objfile;
13216 /* Return the master objfile, so that we can report and look up the
13217 correct file containing this variable. */
13218 if (objfile->separate_debug_objfile_backlink)
13219 objfile = objfile->separate_debug_objfile_backlink;
13224 /* Return the address size given in the compilation unit header for CU. */
13227 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
13230 return per_cu->cu->header.addr_size;
13233 /* If the CU is not currently read in, we re-read its header. */
13234 struct objfile *objfile = per_cu->objfile;
13235 struct dwarf2_per_objfile *per_objfile
13236 = objfile_data (objfile, dwarf2_objfile_data_key);
13237 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
13238 struct comp_unit_head cu_header;
13240 memset (&cu_header, 0, sizeof cu_header);
13241 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
13242 return cu_header.addr_size;
13246 /* Return the offset size given in the compilation unit header for CU. */
13249 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
13252 return per_cu->cu->header.offset_size;
13255 /* If the CU is not currently read in, we re-read its header. */
13256 struct objfile *objfile = per_cu->objfile;
13257 struct dwarf2_per_objfile *per_objfile
13258 = objfile_data (objfile, dwarf2_objfile_data_key);
13259 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
13260 struct comp_unit_head cu_header;
13262 memset (&cu_header, 0, sizeof cu_header);
13263 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
13264 return cu_header.offset_size;
13268 /* Return the text offset of the CU. The returned offset comes from
13269 this CU's objfile. If this objfile came from a separate debuginfo
13270 file, then the offset may be different from the corresponding
13271 offset in the parent objfile. */
13274 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
13276 struct objfile *objfile = per_cu->objfile;
13278 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
13281 /* Locate the .debug_info compilation unit from CU's objfile which contains
13282 the DIE at OFFSET. Raises an error on failure. */
13284 static struct dwarf2_per_cu_data *
13285 dwarf2_find_containing_comp_unit (unsigned int offset,
13286 struct objfile *objfile)
13288 struct dwarf2_per_cu_data *this_cu;
13292 high = dwarf2_per_objfile->n_comp_units - 1;
13295 int mid = low + (high - low) / 2;
13297 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
13302 gdb_assert (low == high);
13303 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
13306 error (_("Dwarf Error: could not find partial DIE containing "
13307 "offset 0x%lx [in module %s]"),
13308 (long) offset, bfd_get_filename (objfile->obfd));
13310 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
13311 return dwarf2_per_objfile->all_comp_units[low-1];
13315 this_cu = dwarf2_per_objfile->all_comp_units[low];
13316 if (low == dwarf2_per_objfile->n_comp_units - 1
13317 && offset >= this_cu->offset + this_cu->length)
13318 error (_("invalid dwarf2 offset %u"), offset);
13319 gdb_assert (offset < this_cu->offset + this_cu->length);
13324 /* Locate the compilation unit from OBJFILE which is located at exactly
13325 OFFSET. Raises an error on failure. */
13327 static struct dwarf2_per_cu_data *
13328 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
13330 struct dwarf2_per_cu_data *this_cu;
13332 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
13333 if (this_cu->offset != offset)
13334 error (_("no compilation unit with offset %u."), offset);
13338 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13340 static struct dwarf2_cu *
13341 alloc_one_comp_unit (struct objfile *objfile)
13343 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
13344 cu->objfile = objfile;
13345 obstack_init (&cu->comp_unit_obstack);
13349 /* Release one cached compilation unit, CU. We unlink it from the tree
13350 of compilation units, but we don't remove it from the read_in_chain;
13351 the caller is responsible for that.
13352 NOTE: DATA is a void * because this function is also used as a
13353 cleanup routine. */
13356 free_one_comp_unit (void *data)
13358 struct dwarf2_cu *cu = data;
13360 if (cu->per_cu != NULL)
13361 cu->per_cu->cu = NULL;
13364 obstack_free (&cu->comp_unit_obstack, NULL);
13369 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13370 when we're finished with it. We can't free the pointer itself, but be
13371 sure to unlink it from the cache. Also release any associated storage
13372 and perform cache maintenance.
13374 Only used during partial symbol parsing. */
13377 free_stack_comp_unit (void *data)
13379 struct dwarf2_cu *cu = data;
13381 obstack_free (&cu->comp_unit_obstack, NULL);
13382 cu->partial_dies = NULL;
13384 if (cu->per_cu != NULL)
13386 /* This compilation unit is on the stack in our caller, so we
13387 should not xfree it. Just unlink it. */
13388 cu->per_cu->cu = NULL;
13391 /* If we had a per-cu pointer, then we may have other compilation
13392 units loaded, so age them now. */
13393 age_cached_comp_units ();
13397 /* Free all cached compilation units. */
13400 free_cached_comp_units (void *data)
13402 struct dwarf2_per_cu_data *per_cu, **last_chain;
13404 per_cu = dwarf2_per_objfile->read_in_chain;
13405 last_chain = &dwarf2_per_objfile->read_in_chain;
13406 while (per_cu != NULL)
13408 struct dwarf2_per_cu_data *next_cu;
13410 next_cu = per_cu->cu->read_in_chain;
13412 free_one_comp_unit (per_cu->cu);
13413 *last_chain = next_cu;
13419 /* Increase the age counter on each cached compilation unit, and free
13420 any that are too old. */
13423 age_cached_comp_units (void)
13425 struct dwarf2_per_cu_data *per_cu, **last_chain;
13427 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
13428 per_cu = dwarf2_per_objfile->read_in_chain;
13429 while (per_cu != NULL)
13431 per_cu->cu->last_used ++;
13432 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
13433 dwarf2_mark (per_cu->cu);
13434 per_cu = per_cu->cu->read_in_chain;
13437 per_cu = dwarf2_per_objfile->read_in_chain;
13438 last_chain = &dwarf2_per_objfile->read_in_chain;
13439 while (per_cu != NULL)
13441 struct dwarf2_per_cu_data *next_cu;
13443 next_cu = per_cu->cu->read_in_chain;
13445 if (!per_cu->cu->mark)
13447 free_one_comp_unit (per_cu->cu);
13448 *last_chain = next_cu;
13451 last_chain = &per_cu->cu->read_in_chain;
13457 /* Remove a single compilation unit from the cache. */
13460 free_one_cached_comp_unit (void *target_cu)
13462 struct dwarf2_per_cu_data *per_cu, **last_chain;
13464 per_cu = dwarf2_per_objfile->read_in_chain;
13465 last_chain = &dwarf2_per_objfile->read_in_chain;
13466 while (per_cu != NULL)
13468 struct dwarf2_per_cu_data *next_cu;
13470 next_cu = per_cu->cu->read_in_chain;
13472 if (per_cu->cu == target_cu)
13474 free_one_comp_unit (per_cu->cu);
13475 *last_chain = next_cu;
13479 last_chain = &per_cu->cu->read_in_chain;
13485 /* Release all extra memory associated with OBJFILE. */
13488 dwarf2_free_objfile (struct objfile *objfile)
13490 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
13492 if (dwarf2_per_objfile == NULL)
13495 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
13496 free_cached_comp_units (NULL);
13498 if (dwarf2_per_objfile->using_index)
13502 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
13505 struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
13507 if (!cu->v.quick->lines)
13510 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
13512 if (cu->v.quick->file_names)
13513 xfree ((void *) cu->v.quick->file_names[j]);
13514 if (cu->v.quick->full_names)
13515 xfree ((void *) cu->v.quick->full_names[j]);
13518 free_line_header (cu->v.quick->lines);
13522 /* Everything else should be on the objfile obstack. */
13525 /* A pair of DIE offset and GDB type pointer. We store these
13526 in a hash table separate from the DIEs, and preserve them
13527 when the DIEs are flushed out of cache. */
13529 struct dwarf2_offset_and_type
13531 unsigned int offset;
13535 /* Hash function for a dwarf2_offset_and_type. */
13538 offset_and_type_hash (const void *item)
13540 const struct dwarf2_offset_and_type *ofs = item;
13542 return ofs->offset;
13545 /* Equality function for a dwarf2_offset_and_type. */
13548 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
13550 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
13551 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
13553 return ofs_lhs->offset == ofs_rhs->offset;
13556 /* Set the type associated with DIE to TYPE. Save it in CU's hash
13557 table if necessary. For convenience, return TYPE.
13559 The DIEs reading must have careful ordering to:
13560 * Not cause infite loops trying to read in DIEs as a prerequisite for
13561 reading current DIE.
13562 * Not trying to dereference contents of still incompletely read in types
13563 while reading in other DIEs.
13564 * Enable referencing still incompletely read in types just by a pointer to
13565 the type without accessing its fields.
13567 Therefore caller should follow these rules:
13568 * Try to fetch any prerequisite types we may need to build this DIE type
13569 before building the type and calling set_die_type.
13570 * After building typer call set_die_type for current DIE as soon as
13571 possible before fetching more types to complete the current type.
13572 * Make the type as complete as possible before fetching more types. */
13574 static struct type *
13575 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
13577 struct dwarf2_offset_and_type **slot, ofs;
13579 /* For Ada types, make sure that the gnat-specific data is always
13580 initialized (if not already set). There are a few types where
13581 we should not be doing so, because the type-specific area is
13582 already used to hold some other piece of info (eg: TYPE_CODE_FLT
13583 where the type-specific area is used to store the floatformat).
13584 But this is not a problem, because the gnat-specific information
13585 is actually not needed for these types. */
13586 if (need_gnat_info (cu)
13587 && TYPE_CODE (type) != TYPE_CODE_FUNC
13588 && TYPE_CODE (type) != TYPE_CODE_FLT
13589 && !HAVE_GNAT_AUX_INFO (type))
13590 INIT_GNAT_SPECIFIC (type);
13592 if (cu->type_hash == NULL)
13594 gdb_assert (cu->per_cu != NULL);
13595 cu->per_cu->type_hash
13596 = htab_create_alloc_ex (cu->header.length / 24,
13597 offset_and_type_hash,
13598 offset_and_type_eq,
13600 &cu->objfile->objfile_obstack,
13601 hashtab_obstack_allocate,
13602 dummy_obstack_deallocate);
13603 cu->type_hash = cu->per_cu->type_hash;
13606 ofs.offset = die->offset;
13608 slot = (struct dwarf2_offset_and_type **)
13609 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
13611 complaint (&symfile_complaints,
13612 _("A problem internal to GDB: DIE 0x%x has type already set"),
13614 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
13619 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
13620 not have a saved type. */
13622 static struct type *
13623 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
13625 struct dwarf2_offset_and_type *slot, ofs;
13626 htab_t type_hash = cu->type_hash;
13628 if (type_hash == NULL)
13631 ofs.offset = die->offset;
13632 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
13639 /* Add a dependence relationship from CU to REF_PER_CU. */
13642 dwarf2_add_dependence (struct dwarf2_cu *cu,
13643 struct dwarf2_per_cu_data *ref_per_cu)
13647 if (cu->dependencies == NULL)
13649 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
13650 NULL, &cu->comp_unit_obstack,
13651 hashtab_obstack_allocate,
13652 dummy_obstack_deallocate);
13654 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
13656 *slot = ref_per_cu;
13659 /* Subroutine of dwarf2_mark to pass to htab_traverse.
13660 Set the mark field in every compilation unit in the
13661 cache that we must keep because we are keeping CU. */
13664 dwarf2_mark_helper (void **slot, void *data)
13666 struct dwarf2_per_cu_data *per_cu;
13668 per_cu = (struct dwarf2_per_cu_data *) *slot;
13669 if (per_cu->cu->mark)
13671 per_cu->cu->mark = 1;
13673 if (per_cu->cu->dependencies != NULL)
13674 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
13679 /* Set the mark field in CU and in every other compilation unit in the
13680 cache that we must keep because we are keeping CU. */
13683 dwarf2_mark (struct dwarf2_cu *cu)
13688 if (cu->dependencies != NULL)
13689 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
13693 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
13697 per_cu->cu->mark = 0;
13698 per_cu = per_cu->cu->read_in_chain;
13702 /* Trivial hash function for partial_die_info: the hash value of a DIE
13703 is its offset in .debug_info for this objfile. */
13706 partial_die_hash (const void *item)
13708 const struct partial_die_info *part_die = item;
13710 return part_die->offset;
13713 /* Trivial comparison function for partial_die_info structures: two DIEs
13714 are equal if they have the same offset. */
13717 partial_die_eq (const void *item_lhs, const void *item_rhs)
13719 const struct partial_die_info *part_die_lhs = item_lhs;
13720 const struct partial_die_info *part_die_rhs = item_rhs;
13722 return part_die_lhs->offset == part_die_rhs->offset;
13725 static struct cmd_list_element *set_dwarf2_cmdlist;
13726 static struct cmd_list_element *show_dwarf2_cmdlist;
13729 set_dwarf2_cmd (char *args, int from_tty)
13731 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
13735 show_dwarf2_cmd (char *args, int from_tty)
13737 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
13740 /* If section described by INFO was mmapped, munmap it now. */
13743 munmap_section_buffer (struct dwarf2_section_info *info)
13745 if (info->was_mmapped)
13748 intptr_t begin = (intptr_t) info->buffer;
13749 intptr_t map_begin = begin & ~(pagesize - 1);
13750 size_t map_length = info->size + begin - map_begin;
13752 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
13754 /* Without HAVE_MMAP, we should never be here to begin with. */
13760 /* munmap debug sections for OBJFILE, if necessary. */
13763 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
13765 struct dwarf2_per_objfile *data = d;
13767 munmap_section_buffer (&data->info);
13768 munmap_section_buffer (&data->abbrev);
13769 munmap_section_buffer (&data->line);
13770 munmap_section_buffer (&data->str);
13771 munmap_section_buffer (&data->macinfo);
13772 munmap_section_buffer (&data->ranges);
13773 munmap_section_buffer (&data->loc);
13774 munmap_section_buffer (&data->frame);
13775 munmap_section_buffer (&data->eh_frame);
13776 munmap_section_buffer (&data->gdb_index);
13781 /* The contents of the hash table we create when building the string
13783 struct strtab_entry
13785 offset_type offset;
13789 /* Hash function for a strtab_entry. */
13791 hash_strtab_entry (const void *e)
13793 const struct strtab_entry *entry = e;
13794 return mapped_index_string_hash (entry->str);
13797 /* Equality function for a strtab_entry. */
13799 eq_strtab_entry (const void *a, const void *b)
13801 const struct strtab_entry *ea = a;
13802 const struct strtab_entry *eb = b;
13803 return !strcmp (ea->str, eb->str);
13806 /* Create a strtab_entry hash table. */
13808 create_strtab (void)
13810 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
13811 xfree, xcalloc, xfree);
13814 /* Add a string to the constant pool. Return the string's offset in
13817 add_string (htab_t table, struct obstack *cpool, const char *str)
13820 struct strtab_entry entry;
13821 struct strtab_entry *result;
13824 slot = htab_find_slot (table, &entry, INSERT);
13829 result = XNEW (struct strtab_entry);
13830 result->offset = obstack_object_size (cpool);
13832 obstack_grow_str0 (cpool, str);
13835 return result->offset;
13838 /* An entry in the symbol table. */
13839 struct symtab_index_entry
13841 /* The name of the symbol. */
13843 /* The offset of the name in the constant pool. */
13844 offset_type index_offset;
13845 /* A sorted vector of the indices of all the CUs that hold an object
13847 VEC (offset_type) *cu_indices;
13850 /* The symbol table. This is a power-of-2-sized hash table. */
13851 struct mapped_symtab
13853 offset_type n_elements;
13855 struct symtab_index_entry **data;
13858 /* Hash function for a symtab_index_entry. */
13860 hash_symtab_entry (const void *e)
13862 const struct symtab_index_entry *entry = e;
13863 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
13864 sizeof (offset_type) * VEC_length (offset_type,
13865 entry->cu_indices),
13869 /* Equality function for a symtab_index_entry. */
13871 eq_symtab_entry (const void *a, const void *b)
13873 const struct symtab_index_entry *ea = a;
13874 const struct symtab_index_entry *eb = b;
13875 int len = VEC_length (offset_type, ea->cu_indices);
13876 if (len != VEC_length (offset_type, eb->cu_indices))
13878 return !memcmp (VEC_address (offset_type, ea->cu_indices),
13879 VEC_address (offset_type, eb->cu_indices),
13880 sizeof (offset_type) * len);
13883 /* Destroy a symtab_index_entry. */
13885 delete_symtab_entry (void *p)
13887 struct symtab_index_entry *entry = p;
13888 VEC_free (offset_type, entry->cu_indices);
13892 /* Create a hash table holding symtab_index_entry objects. */
13894 create_index_table (void)
13896 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
13897 delete_symtab_entry, xcalloc, xfree);
13900 /* Create a new mapped symtab object. */
13901 static struct mapped_symtab *
13902 create_mapped_symtab (void)
13904 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
13905 symtab->n_elements = 0;
13906 symtab->size = 1024;
13907 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
13911 /* Destroy a mapped_symtab. */
13913 cleanup_mapped_symtab (void *p)
13915 struct mapped_symtab *symtab = p;
13916 /* The contents of the array are freed when the other hash table is
13918 xfree (symtab->data);
13922 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
13924 static struct symtab_index_entry **
13925 find_slot (struct mapped_symtab *symtab, const char *name)
13927 offset_type index, step, hash = mapped_index_string_hash (name);
13929 index = hash & (symtab->size - 1);
13930 step = ((hash * 17) & (symtab->size - 1)) | 1;
13934 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
13935 return &symtab->data[index];
13936 index = (index + step) & (symtab->size - 1);
13940 /* Expand SYMTAB's hash table. */
13942 hash_expand (struct mapped_symtab *symtab)
13944 offset_type old_size = symtab->size;
13946 struct symtab_index_entry **old_entries = symtab->data;
13949 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
13951 for (i = 0; i < old_size; ++i)
13953 if (old_entries[i])
13955 struct symtab_index_entry **slot = find_slot (symtab,
13956 old_entries[i]->name);
13957 *slot = old_entries[i];
13961 xfree (old_entries);
13964 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
13965 is the index of the CU in which the symbol appears. */
13967 add_index_entry (struct mapped_symtab *symtab, const char *name,
13968 offset_type cu_index)
13970 struct symtab_index_entry **slot;
13972 ++symtab->n_elements;
13973 if (4 * symtab->n_elements / 3 >= symtab->size)
13974 hash_expand (symtab);
13976 slot = find_slot (symtab, name);
13979 *slot = XNEW (struct symtab_index_entry);
13980 (*slot)->name = name;
13981 (*slot)->cu_indices = NULL;
13983 /* Don't push an index twice. Due to how we add entries we only
13984 have to check the last one. */
13985 if (VEC_empty (offset_type, (*slot)->cu_indices)
13986 || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
13987 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
13990 /* Add a vector of indices to the constant pool. */
13992 add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
13993 struct symtab_index_entry *entry)
13997 slot = htab_find_slot (index_table, entry, INSERT);
14000 offset_type len = VEC_length (offset_type, entry->cu_indices);
14001 offset_type val = MAYBE_SWAP (len);
14006 entry->index_offset = obstack_object_size (cpool);
14008 obstack_grow (cpool, &val, sizeof (val));
14010 VEC_iterate (offset_type, entry->cu_indices, i, iter);
14013 val = MAYBE_SWAP (iter);
14014 obstack_grow (cpool, &val, sizeof (val));
14019 struct symtab_index_entry *old_entry = *slot;
14020 entry->index_offset = old_entry->index_offset;
14023 return entry->index_offset;
14026 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14027 constant pool entries going into the obstack CPOOL. */
14029 write_hash_table (struct mapped_symtab *symtab,
14030 struct obstack *output, struct obstack *cpool)
14033 htab_t index_table;
14036 index_table = create_index_table ();
14037 str_table = create_strtab ();
14038 /* We add all the index vectors to the constant pool first, to
14039 ensure alignment is ok. */
14040 for (i = 0; i < symtab->size; ++i)
14042 if (symtab->data[i])
14043 add_indices_to_cpool (index_table, cpool, symtab->data[i]);
14046 /* Now write out the hash table. */
14047 for (i = 0; i < symtab->size; ++i)
14049 offset_type str_off, vec_off;
14051 if (symtab->data[i])
14053 str_off = add_string (str_table, cpool, symtab->data[i]->name);
14054 vec_off = symtab->data[i]->index_offset;
14058 /* While 0 is a valid constant pool index, it is not valid
14059 to have 0 for both offsets. */
14064 str_off = MAYBE_SWAP (str_off);
14065 vec_off = MAYBE_SWAP (vec_off);
14067 obstack_grow (output, &str_off, sizeof (str_off));
14068 obstack_grow (output, &vec_off, sizeof (vec_off));
14071 htab_delete (str_table);
14072 htab_delete (index_table);
14075 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14076 from PST; CU_INDEX is the index of the CU in the vector of all
14079 add_address_entry (struct objfile *objfile,
14080 struct obstack *addr_obstack, struct partial_symtab *pst,
14081 unsigned int cu_index)
14083 offset_type offset;
14085 CORE_ADDR baseaddr;
14087 /* Don't bother recording empty ranges. */
14088 if (pst->textlow == pst->texthigh)
14091 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14093 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
14094 obstack_grow (addr_obstack, addr, 8);
14095 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
14096 obstack_grow (addr_obstack, addr, 8);
14097 offset = MAYBE_SWAP (cu_index);
14098 obstack_grow (addr_obstack, &offset, sizeof (offset_type));
14101 /* Add a list of partial symbols to SYMTAB. */
14103 write_psymbols (struct mapped_symtab *symtab,
14104 struct partial_symbol **psymp,
14106 offset_type cu_index)
14108 for (; count-- > 0; ++psymp)
14110 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
14111 error (_("Ada is not currently supported by the index"));
14112 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
14116 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14117 exception if there is an error. */
14119 write_obstack (FILE *file, struct obstack *obstack)
14121 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
14123 != obstack_object_size (obstack))
14124 error (_("couldn't data write to file"));
14127 /* Unlink a file if the argument is not NULL. */
14129 unlink_if_set (void *p)
14131 char **filename = p;
14133 unlink (*filename);
14136 /* A helper struct used when iterating over debug_types. */
14137 struct signatured_type_index_data
14139 struct objfile *objfile;
14140 struct mapped_symtab *symtab;
14141 struct obstack *types_list;
14145 /* A helper function that writes a single signatured_type to an
14148 write_one_signatured_type (void **slot, void *d)
14150 struct signatured_type_index_data *info = d;
14151 struct signatured_type *entry = (struct signatured_type *) *slot;
14152 struct dwarf2_per_cu_data *cu = &entry->per_cu;
14153 struct partial_symtab *psymtab = cu->v.psymtab;
14156 write_psymbols (info->symtab,
14157 info->objfile->global_psymbols.list + psymtab->globals_offset,
14158 psymtab->n_global_syms, info->cu_index);
14159 write_psymbols (info->symtab,
14160 info->objfile->static_psymbols.list + psymtab->statics_offset,
14161 psymtab->n_static_syms, info->cu_index);
14163 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
14164 obstack_grow (info->types_list, val, 8);
14165 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
14166 obstack_grow (info->types_list, val, 8);
14167 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
14168 obstack_grow (info->types_list, val, 8);
14175 /* Create an index file for OBJFILE in the directory DIR. */
14177 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
14179 struct cleanup *cleanup;
14180 char *filename, *cleanup_filename;
14181 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
14182 struct obstack cu_list, types_cu_list;
14185 struct mapped_symtab *symtab;
14186 offset_type val, size_of_contents, total_len;
14190 if (!objfile->psymtabs)
14192 if (dwarf2_per_objfile->using_index)
14193 error (_("Cannot use an index to create the index"));
14195 if (stat (objfile->name, &st) < 0)
14196 perror_with_name (_("Could not stat"));
14198 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
14199 INDEX_SUFFIX, (char *) NULL);
14200 cleanup = make_cleanup (xfree, filename);
14202 out_file = fopen (filename, "wb");
14204 error (_("Can't open `%s' for writing"), filename);
14206 cleanup_filename = filename;
14207 make_cleanup (unlink_if_set, &cleanup_filename);
14209 symtab = create_mapped_symtab ();
14210 make_cleanup (cleanup_mapped_symtab, symtab);
14212 obstack_init (&addr_obstack);
14213 make_cleanup_obstack_free (&addr_obstack);
14215 obstack_init (&cu_list);
14216 make_cleanup_obstack_free (&cu_list);
14218 obstack_init (&types_cu_list);
14219 make_cleanup_obstack_free (&types_cu_list);
14221 /* The list is already sorted, so we don't need to do additional
14222 work here. Also, the debug_types entries do not appear in
14223 all_comp_units, but only in their own hash table. */
14224 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
14226 struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
14227 struct partial_symtab *psymtab = cu->v.psymtab;
14230 write_psymbols (symtab,
14231 objfile->global_psymbols.list + psymtab->globals_offset,
14232 psymtab->n_global_syms, i);
14233 write_psymbols (symtab,
14234 objfile->static_psymbols.list + psymtab->statics_offset,
14235 psymtab->n_static_syms, i);
14237 add_address_entry (objfile, &addr_obstack, psymtab, i);
14239 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset);
14240 obstack_grow (&cu_list, val, 8);
14241 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length);
14242 obstack_grow (&cu_list, val, 8);
14245 /* Write out the .debug_type entries, if any. */
14246 if (dwarf2_per_objfile->signatured_types)
14248 struct signatured_type_index_data sig_data;
14250 sig_data.objfile = objfile;
14251 sig_data.symtab = symtab;
14252 sig_data.types_list = &types_cu_list;
14253 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
14254 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
14255 write_one_signatured_type, &sig_data);
14258 obstack_init (&constant_pool);
14259 make_cleanup_obstack_free (&constant_pool);
14260 obstack_init (&symtab_obstack);
14261 make_cleanup_obstack_free (&symtab_obstack);
14262 write_hash_table (symtab, &symtab_obstack, &constant_pool);
14264 obstack_init (&contents);
14265 make_cleanup_obstack_free (&contents);
14266 size_of_contents = 6 * sizeof (offset_type);
14267 total_len = size_of_contents;
14269 /* The version number. */
14270 val = MAYBE_SWAP (2);
14271 obstack_grow (&contents, &val, sizeof (val));
14273 /* The offset of the CU list from the start of the file. */
14274 val = MAYBE_SWAP (total_len);
14275 obstack_grow (&contents, &val, sizeof (val));
14276 total_len += obstack_object_size (&cu_list);
14278 /* The offset of the types CU list from the start of the file. */
14279 val = MAYBE_SWAP (total_len);
14280 obstack_grow (&contents, &val, sizeof (val));
14281 total_len += obstack_object_size (&types_cu_list);
14283 /* The offset of the address table from the start of the file. */
14284 val = MAYBE_SWAP (total_len);
14285 obstack_grow (&contents, &val, sizeof (val));
14286 total_len += obstack_object_size (&addr_obstack);
14288 /* The offset of the symbol table from the start of the file. */
14289 val = MAYBE_SWAP (total_len);
14290 obstack_grow (&contents, &val, sizeof (val));
14291 total_len += obstack_object_size (&symtab_obstack);
14293 /* The offset of the constant pool from the start of the file. */
14294 val = MAYBE_SWAP (total_len);
14295 obstack_grow (&contents, &val, sizeof (val));
14296 total_len += obstack_object_size (&constant_pool);
14298 gdb_assert (obstack_object_size (&contents) == size_of_contents);
14300 write_obstack (out_file, &contents);
14301 write_obstack (out_file, &cu_list);
14302 write_obstack (out_file, &types_cu_list);
14303 write_obstack (out_file, &addr_obstack);
14304 write_obstack (out_file, &symtab_obstack);
14305 write_obstack (out_file, &constant_pool);
14309 /* We want to keep the file, so we set cleanup_filename to NULL
14310 here. See unlink_if_set. */
14311 cleanup_filename = NULL;
14313 do_cleanups (cleanup);
14316 /* The mapped index file format is designed to be directly mmap()able
14317 on any architecture. In most cases, a datum is represented using a
14318 little-endian 32-bit integer value, called an offset_type. Big
14319 endian machines must byte-swap the values before using them.
14320 Exceptions to this rule are noted. The data is laid out such that
14321 alignment is always respected.
14323 A mapped index consists of several sections.
14325 1. The file header. This is a sequence of values, of offset_type
14326 unless otherwise noted:
14327 [0] The version number. Currently 1 or 2. The differences are
14328 noted below. Version 1 did not account for .debug_types sections;
14329 the presence of a .debug_types section invalidates any version 1
14330 index that may exist.
14331 [1] The offset, from the start of the file, of the CU list.
14332 [1.5] In version 2, the offset, from the start of the file, of the
14333 types CU list. This offset does not appear in version 1. Note
14334 that this can be empty, in which case this offset will be equal to
14336 [2] The offset, from the start of the file, of the address section.
14337 [3] The offset, from the start of the file, of the symbol table.
14338 [4] The offset, from the start of the file, of the constant pool.
14340 2. The CU list. This is a sequence of pairs of 64-bit
14341 little-endian values, sorted by the CU offset. The first element
14342 in each pair is the offset of a CU in the .debug_info section. The
14343 second element in each pair is the length of that CU. References
14344 to a CU elsewhere in the map are done using a CU index, which is
14345 just the 0-based index into this table. Note that if there are
14346 type CUs, then conceptually CUs and type CUs form a single list for
14347 the purposes of CU indices.
14349 2.5 The types CU list. This does not appear in a version 1 index.
14350 This is a sequence of triplets of 64-bit little-endian values. In
14351 a triplet, the first value is the CU offset, the second value is
14352 the type offset in the CU, and the third value is the type
14353 signature. The types CU list is not sorted.
14355 3. The address section. The address section consists of a sequence
14356 of address entries. Each address entry has three elements.
14357 [0] The low address. This is a 64-bit little-endian value.
14358 [1] The high address. This is a 64-bit little-endian value.
14359 [2] The CU index. This is an offset_type value.
14361 4. The symbol table. This is a hash table. The size of the hash
14362 table is always a power of 2. The initial hash and the step are
14363 currently defined by the `find_slot' function.
14365 Each slot in the hash table consists of a pair of offset_type
14366 values. The first value is the offset of the symbol's name in the
14367 constant pool. The second value is the offset of the CU vector in
14370 If both values are 0, then this slot in the hash table is empty.
14371 This is ok because while 0 is a valid constant pool index, it
14372 cannot be a valid index for both a string and a CU vector.
14374 A string in the constant pool is stored as a \0-terminated string,
14377 A CU vector in the constant pool is a sequence of offset_type
14378 values. The first value is the number of CU indices in the vector.
14379 Each subsequent value is the index of a CU in the CU list. This
14380 element in the hash table is used to indicate which CUs define the
14383 5. The constant pool. This is simply a bunch of bytes. It is
14384 organized so that alignment is correct: CU vectors are stored
14385 first, followed by strings. */
14387 save_gdb_index_command (char *arg, int from_tty)
14389 struct objfile *objfile;
14392 error (_("usage: save gdb-index DIRECTORY"));
14394 ALL_OBJFILES (objfile)
14398 /* If the objfile does not correspond to an actual file, skip it. */
14399 if (stat (objfile->name, &st) < 0)
14402 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
14403 if (dwarf2_per_objfile)
14405 volatile struct gdb_exception except;
14407 TRY_CATCH (except, RETURN_MASK_ERROR)
14409 write_psymtabs_to_index (objfile, arg);
14411 if (except.reason < 0)
14412 exception_fprintf (gdb_stderr, except,
14413 _("Error while writing index for `%s': "),
14421 int dwarf2_always_disassemble;
14424 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
14425 struct cmd_list_element *c, const char *value)
14427 fprintf_filtered (file, _("\
14428 Whether to always disassemble DWARF expressions is %s.\n"),
14432 void _initialize_dwarf2_read (void);
14435 _initialize_dwarf2_read (void)
14437 struct cmd_list_element *c;
14439 dwarf2_objfile_data_key
14440 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
14442 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
14443 Set DWARF 2 specific variables.\n\
14444 Configure DWARF 2 variables such as the cache size"),
14445 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
14446 0/*allow-unknown*/, &maintenance_set_cmdlist);
14448 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
14449 Show DWARF 2 specific variables\n\
14450 Show DWARF 2 variables such as the cache size"),
14451 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
14452 0/*allow-unknown*/, &maintenance_show_cmdlist);
14454 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
14455 &dwarf2_max_cache_age, _("\
14456 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14457 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14458 A higher limit means that cached compilation units will be stored\n\
14459 in memory longer, and more total memory will be used. Zero disables\n\
14460 caching, which can slow down startup."),
14462 show_dwarf2_max_cache_age,
14463 &set_dwarf2_cmdlist,
14464 &show_dwarf2_cmdlist);
14466 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
14467 &dwarf2_always_disassemble, _("\
14468 Set whether `info address' always disassembles DWARF expressions."), _("\
14469 Show whether `info address' always disassembles DWARF expressions."), _("\
14470 When enabled, DWARF expressions are always printed in an assembly-like\n\
14471 syntax. When disabled, expressions will be printed in a more\n\
14472 conversational style, when possible."),
14474 show_dwarf2_always_disassemble,
14475 &set_dwarf2_cmdlist,
14476 &show_dwarf2_cmdlist);
14478 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
14479 Set debugging of the dwarf2 DIE reader."), _("\
14480 Show debugging of the dwarf2 DIE reader."), _("\
14481 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14482 The value is the maximum depth to print."),
14485 &setdebuglist, &showdebuglist);
14487 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
14488 _("Save a .gdb-index file"),
14490 set_cmd_completer (c, filename_completer);