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.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
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_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, *types_list;
1839 offset_type version, cu_list_elements, types_list_elements;
1842 if (dwarf2_per_objfile->gdb_index.asection == NULL
1843 || dwarf2_per_objfile->gdb_index.size == 0)
1845 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
1847 addr = dwarf2_per_objfile->gdb_index.buffer;
1848 /* Version check. */
1849 version = MAYBE_SWAP (*(offset_type *) addr);
1852 /* Index version 1 neglected to account for .debug_types. So,
1853 if we see .debug_types, we cannot use this index. */
1854 if (dwarf2_per_objfile->types.asection != NULL
1855 && dwarf2_per_objfile->types.size != 0)
1858 else if (version != 2)
1861 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
1862 map->total_size = dwarf2_per_objfile->gdb_index.size;
1864 metadata = (offset_type *) (addr + sizeof (offset_type));
1867 cu_list = addr + MAYBE_SWAP (metadata[i]);
1868 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
1874 types_list = addr + MAYBE_SWAP (metadata[i]);
1875 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
1876 - MAYBE_SWAP (metadata[i]))
1881 map->address_table = addr + MAYBE_SWAP (metadata[i]);
1882 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
1883 - MAYBE_SWAP (metadata[i]));
1886 map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
1887 map->index_table_slots = ((MAYBE_SWAP (metadata[i + 1])
1888 - MAYBE_SWAP (metadata[i]))
1889 / (2 * sizeof (offset_type)));
1892 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
1894 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
1898 && types_list_elements
1899 && !create_signatured_type_hash_from_index (objfile, types_list,
1900 types_list_elements))
1903 create_addrmap_from_index (objfile, map);
1905 dwarf2_per_objfile->index_table = map;
1906 dwarf2_per_objfile->using_index = 1;
1911 /* A helper for the "quick" functions which sets the global
1912 dwarf2_per_objfile according to OBJFILE. */
1914 dw2_setup (struct objfile *objfile)
1916 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1917 gdb_assert (dwarf2_per_objfile);
1920 /* A helper for the "quick" functions which attempts to read the line
1921 table for THIS_CU. */
1923 dw2_require_line_header (struct objfile *objfile,
1924 struct dwarf2_per_cu_data *this_cu)
1926 bfd *abfd = objfile->obfd;
1927 struct line_header *lh = NULL;
1928 struct attribute *attr;
1929 struct cleanup *cleanups;
1930 struct die_info *comp_unit_die;
1931 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
1932 int has_children, i;
1933 struct dwarf2_cu cu;
1934 unsigned int bytes_read, buffer_size;
1935 struct die_reader_specs reader_specs;
1936 char *name, *comp_dir;
1938 if (this_cu->v.quick->read_lines)
1940 this_cu->v.quick->read_lines = 1;
1942 memset (&cu, 0, sizeof (cu));
1943 cu.objfile = objfile;
1944 obstack_init (&cu.comp_unit_obstack);
1946 cleanups = make_cleanup (free_stack_comp_unit, &cu);
1948 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
1949 buffer_size = dwarf2_per_objfile->info.size;
1950 buffer = dwarf2_per_objfile->info.buffer;
1951 info_ptr = buffer + this_cu->offset;
1952 beg_of_comp_unit = info_ptr;
1954 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
1955 buffer, buffer_size,
1958 /* Complete the cu_header. */
1959 cu.header.offset = beg_of_comp_unit - buffer;
1960 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1963 cu.per_cu = this_cu;
1965 dwarf2_read_abbrevs (abfd, &cu);
1966 make_cleanup (dwarf2_free_abbrev_table, &cu);
1968 if (this_cu->from_debug_types)
1969 info_ptr += 8 /*signature*/ + cu.header.offset_size;
1970 init_cu_die_reader (&reader_specs, &cu);
1971 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
1974 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
1977 unsigned int line_offset = DW_UNSND (attr);
1978 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
1982 do_cleanups (cleanups);
1986 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
1988 this_cu->v.quick->lines = lh;
1990 this_cu->v.quick->file_names
1991 = obstack_alloc (&objfile->objfile_obstack,
1992 lh->num_file_names * sizeof (char *));
1993 for (i = 0; i < lh->num_file_names; ++i)
1994 this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
1996 do_cleanups (cleanups);
1999 /* A helper for the "quick" functions which computes and caches the
2000 real path for a given file name from the line table.
2001 dw2_require_line_header must have been called before this is
2004 dw2_require_full_path (struct objfile *objfile,
2005 struct dwarf2_per_cu_data *cu,
2008 if (!cu->v.quick->full_names)
2009 cu->v.quick->full_names
2010 = OBSTACK_CALLOC (&objfile->objfile_obstack,
2011 cu->v.quick->lines->num_file_names,
2014 if (!cu->v.quick->full_names[index])
2015 cu->v.quick->full_names[index]
2016 = gdb_realpath (cu->v.quick->file_names[index]);
2018 return cu->v.quick->full_names[index];
2021 static struct symtab *
2022 dw2_find_last_source_symtab (struct objfile *objfile)
2025 dw2_setup (objfile);
2026 index = dwarf2_per_objfile->n_comp_units - 1;
2027 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2031 dw2_forget_cached_source_info (struct objfile *objfile)
2035 dw2_setup (objfile);
2036 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2037 + dwarf2_per_objfile->n_type_comp_units); ++i)
2039 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2041 if (cu->v.quick->full_names)
2045 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2046 xfree ((void *) cu->v.quick->full_names[j]);
2052 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2053 const char *full_path, const char *real_path,
2054 struct symtab **result)
2057 int check_basename = lbasename (name) == name;
2058 struct dwarf2_per_cu_data *base_cu = NULL;
2060 dw2_setup (objfile);
2061 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2062 + dwarf2_per_objfile->n_type_comp_units); ++i)
2065 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2067 if (cu->v.quick->symtab)
2070 dw2_require_line_header (objfile, cu);
2071 if (!cu->v.quick->lines)
2074 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2076 const char *this_name = cu->v.quick->file_names[j];
2078 if (FILENAME_CMP (name, this_name) == 0)
2080 *result = dw2_instantiate_symtab (objfile, cu);
2084 if (check_basename && ! base_cu
2085 && FILENAME_CMP (lbasename (this_name), name) == 0)
2088 if (full_path != NULL)
2090 const char *this_full_name = dw2_require_full_path (objfile,
2094 && FILENAME_CMP (full_path, this_full_name) == 0)
2096 *result = dw2_instantiate_symtab (objfile, cu);
2101 if (real_path != NULL)
2103 const char *this_full_name = dw2_require_full_path (objfile,
2106 if (this_full_name != NULL)
2108 char *rp = gdb_realpath (this_full_name);
2109 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
2112 *result = dw2_instantiate_symtab (objfile, cu);
2123 *result = dw2_instantiate_symtab (objfile, base_cu);
2130 static struct symtab *
2131 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2132 const char *name, domain_enum domain)
2134 /* We do all the work in the pre_expand_symtabs_matching hook
2139 /* A helper function that expands all symtabs that hold an object
2142 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2144 dw2_setup (objfile);
2146 if (dwarf2_per_objfile->index_table)
2150 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2153 offset_type i, len = MAYBE_SWAP (*vec);
2154 for (i = 0; i < len; ++i)
2156 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2157 struct dwarf2_per_cu_data *cu = dw2_get_cu (cu_index);
2159 dw2_instantiate_symtab (objfile, cu);
2166 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2167 int kind, const char *name,
2170 dw2_do_expand_symtabs_matching (objfile, name);
2174 dw2_print_stats (struct objfile *objfile)
2178 dw2_setup (objfile);
2180 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2181 + dwarf2_per_objfile->n_type_comp_units); ++i)
2183 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2185 if (!cu->v.quick->symtab)
2188 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2192 dw2_dump (struct objfile *objfile)
2194 /* Nothing worth printing. */
2198 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2199 struct section_offsets *delta)
2201 /* There's nothing to relocate here. */
2205 dw2_expand_symtabs_for_function (struct objfile *objfile,
2206 const char *func_name)
2208 dw2_do_expand_symtabs_matching (objfile, func_name);
2212 dw2_expand_all_symtabs (struct objfile *objfile)
2216 dw2_setup (objfile);
2218 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2219 + dwarf2_per_objfile->n_type_comp_units); ++i)
2221 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2223 dw2_instantiate_symtab (objfile, cu);
2228 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2229 const char *filename)
2233 dw2_setup (objfile);
2234 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2235 + dwarf2_per_objfile->n_type_comp_units); ++i)
2238 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2240 if (cu->v.quick->symtab)
2243 dw2_require_line_header (objfile, cu);
2244 if (!cu->v.quick->lines)
2247 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2249 const char *this_name = cu->v.quick->file_names[j];
2250 if (strcmp (this_name, filename) == 0)
2252 dw2_instantiate_symtab (objfile, cu);
2260 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2262 struct dwarf2_per_cu_data *cu;
2265 dw2_setup (objfile);
2267 if (!dwarf2_per_objfile->index_table)
2270 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2274 /* Note that this just looks at the very first one named NAME -- but
2275 actually we are looking for a function. find_main_filename
2276 should be rewritten so that it doesn't require a custom hook. It
2277 could just use the ordinary symbol tables. */
2278 /* vec[0] is the length, which must always be >0. */
2279 cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2281 dw2_require_line_header (objfile, cu);
2282 if (!cu->v.quick->lines)
2285 return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1];
2289 dw2_map_ada_symtabs (struct objfile *objfile,
2290 int (*wild_match) (const char *, int, const char *),
2291 int (*is_name_suffix) (const char *),
2292 void (*callback) (struct objfile *,
2293 struct symtab *, void *),
2294 const char *name, int global,
2295 domain_enum namespace, int wild,
2298 /* For now, we don't support Ada, so this function can't be
2300 internal_error (__FILE__, __LINE__,
2301 _("map_ada_symtabs called via index method"));
2305 dw2_expand_symtabs_matching (struct objfile *objfile,
2306 int (*file_matcher) (const char *, void *),
2307 int (*name_matcher) (const char *, void *),
2314 dw2_setup (objfile);
2315 if (!dwarf2_per_objfile->index_table)
2318 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2319 + dwarf2_per_objfile->n_type_comp_units); ++i)
2322 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2324 cu->v.quick->mark = 0;
2325 if (cu->v.quick->symtab)
2328 dw2_require_line_header (objfile, cu);
2329 if (!cu->v.quick->lines)
2332 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2334 if (file_matcher (cu->v.quick->file_names[j], data))
2336 cu->v.quick->mark = 1;
2343 iter < dwarf2_per_objfile->index_table->index_table_slots;
2346 offset_type idx = 2 * iter;
2348 offset_type *vec, vec_len, vec_idx;
2350 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2351 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2354 name = (dwarf2_per_objfile->index_table->constant_pool
2355 + dwarf2_per_objfile->index_table->index_table[idx]);
2357 if (! (*name_matcher) (name, data))
2360 /* The name was matched, now expand corresponding CUs that were
2362 vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
2363 + dwarf2_per_objfile->index_table->index_table[idx + 1]);
2364 vec_len = MAYBE_SWAP (vec[0]);
2365 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2367 struct dwarf2_per_cu_data *cu;
2369 cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2370 if (cu->v.quick->mark)
2371 dw2_instantiate_symtab (objfile, cu);
2376 static struct symtab *
2377 dw2_find_pc_sect_symtab (struct objfile *objfile,
2378 struct minimal_symbol *msymbol,
2380 struct obj_section *section,
2383 struct dwarf2_per_cu_data *data;
2385 dw2_setup (objfile);
2387 if (!objfile->psymtabs_addrmap)
2390 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2394 if (warn_if_readin && data->v.quick->symtab)
2395 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
2396 paddress (get_objfile_arch (objfile), pc));
2398 return dw2_instantiate_symtab (objfile, data);
2402 dw2_map_symbol_names (struct objfile *objfile,
2403 void (*fun) (const char *, void *),
2407 dw2_setup (objfile);
2409 if (!dwarf2_per_objfile->index_table)
2413 iter < dwarf2_per_objfile->index_table->index_table_slots;
2416 offset_type idx = 2 * iter;
2418 offset_type *vec, vec_len, vec_idx;
2420 if (dwarf2_per_objfile->index_table->index_table[idx] == 0
2421 && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
2424 name = (dwarf2_per_objfile->index_table->constant_pool
2425 + dwarf2_per_objfile->index_table->index_table[idx]);
2427 (*fun) (name, data);
2432 dw2_map_symbol_filenames (struct objfile *objfile,
2433 void (*fun) (const char *, const char *, void *),
2438 dw2_setup (objfile);
2439 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2440 + dwarf2_per_objfile->n_type_comp_units); ++i)
2443 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2445 if (cu->v.quick->symtab)
2448 dw2_require_line_header (objfile, cu);
2449 if (!cu->v.quick->lines)
2452 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2454 const char *this_full_name = dw2_require_full_path (objfile, cu, j);
2455 (*fun) (cu->v.quick->file_names[j], this_full_name, data);
2461 dw2_has_symbols (struct objfile *objfile)
2466 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2469 dw2_find_last_source_symtab,
2470 dw2_forget_cached_source_info,
2473 dw2_pre_expand_symtabs_matching,
2477 dw2_expand_symtabs_for_function,
2478 dw2_expand_all_symtabs,
2479 dw2_expand_symtabs_with_filename,
2480 dw2_find_symbol_file,
2481 dw2_map_ada_symtabs,
2482 dw2_expand_symtabs_matching,
2483 dw2_find_pc_sect_symtab,
2484 dw2_map_symbol_names,
2485 dw2_map_symbol_filenames
2488 /* Initialize for reading DWARF for this objfile. Return 0 if this
2489 file will use psymtabs, or 1 if using the GNU index. */
2492 dwarf2_initialize_objfile (struct objfile *objfile)
2494 /* If we're about to read full symbols, don't bother with the
2495 indices. In this case we also don't care if some other debug
2496 format is making psymtabs, because they are all about to be
2498 if ((objfile->flags & OBJF_READNOW))
2502 dwarf2_per_objfile->using_index = 1;
2503 create_all_comp_units (objfile);
2504 create_debug_types_hash_table (objfile);
2506 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2507 + dwarf2_per_objfile->n_type_comp_units); ++i)
2509 struct dwarf2_per_cu_data *cu = dw2_get_cu (i);
2511 cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2512 struct dwarf2_per_cu_quick_data);
2515 /* Return 1 so that gdb sees the "quick" functions. However,
2516 these functions will be no-ops because we will have expanded
2521 if (dwarf2_read_index (objfile))
2524 dwarf2_build_psymtabs (objfile);
2530 /* Build a partial symbol table. */
2533 dwarf2_build_psymtabs (struct objfile *objfile)
2535 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2537 init_psymbol_list (objfile, 1024);
2540 dwarf2_build_psymtabs_hard (objfile);
2543 /* Return TRUE if OFFSET is within CU_HEADER. */
2546 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2548 unsigned int bottom = cu_header->offset;
2549 unsigned int top = (cu_header->offset
2551 + cu_header->initial_length_size);
2553 return (offset >= bottom && offset < top);
2556 /* Read in the comp unit header information from the debug_info at info_ptr.
2557 NOTE: This leaves members offset, first_die_offset to be filled in
2561 read_comp_unit_head (struct comp_unit_head *cu_header,
2562 gdb_byte *info_ptr, bfd *abfd)
2565 unsigned int bytes_read;
2567 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2568 cu_header->initial_length_size = bytes_read;
2569 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2570 info_ptr += bytes_read;
2571 cu_header->version = read_2_bytes (abfd, info_ptr);
2573 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2575 info_ptr += bytes_read;
2576 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2578 signed_addr = bfd_get_sign_extend_vma (abfd);
2579 if (signed_addr < 0)
2580 internal_error (__FILE__, __LINE__,
2581 _("read_comp_unit_head: dwarf from non elf file"));
2582 cu_header->signed_addr_p = signed_addr;
2588 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2589 gdb_byte *buffer, unsigned int buffer_size,
2592 gdb_byte *beg_of_comp_unit = info_ptr;
2594 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2596 if (header->version != 2 && header->version != 3 && header->version != 4)
2597 error (_("Dwarf Error: wrong version in compilation unit header "
2598 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2599 bfd_get_filename (abfd));
2601 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
2602 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2603 "(offset 0x%lx + 6) [in module %s]"),
2604 (long) header->abbrev_offset,
2605 (long) (beg_of_comp_unit - buffer),
2606 bfd_get_filename (abfd));
2608 if (beg_of_comp_unit + header->length + header->initial_length_size
2609 > buffer + buffer_size)
2610 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2611 "(offset 0x%lx + 0) [in module %s]"),
2612 (long) header->length,
2613 (long) (beg_of_comp_unit - buffer),
2614 bfd_get_filename (abfd));
2619 /* Read in the types comp unit header information from .debug_types entry at
2620 types_ptr. The result is a pointer to one past the end of the header. */
2623 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2624 ULONGEST *signature,
2625 gdb_byte *types_ptr, bfd *abfd)
2627 gdb_byte *initial_types_ptr = types_ptr;
2629 dwarf2_read_section (dwarf2_per_objfile->objfile,
2630 &dwarf2_per_objfile->types);
2631 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2633 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2635 *signature = read_8_bytes (abfd, types_ptr);
2637 types_ptr += cu_header->offset_size;
2638 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2643 /* Allocate a new partial symtab for file named NAME and mark this new
2644 partial symtab as being an include of PST. */
2647 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2648 struct objfile *objfile)
2650 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2652 subpst->section_offsets = pst->section_offsets;
2653 subpst->textlow = 0;
2654 subpst->texthigh = 0;
2656 subpst->dependencies = (struct partial_symtab **)
2657 obstack_alloc (&objfile->objfile_obstack,
2658 sizeof (struct partial_symtab *));
2659 subpst->dependencies[0] = pst;
2660 subpst->number_of_dependencies = 1;
2662 subpst->globals_offset = 0;
2663 subpst->n_global_syms = 0;
2664 subpst->statics_offset = 0;
2665 subpst->n_static_syms = 0;
2666 subpst->symtab = NULL;
2667 subpst->read_symtab = pst->read_symtab;
2670 /* No private part is necessary for include psymtabs. This property
2671 can be used to differentiate between such include psymtabs and
2672 the regular ones. */
2673 subpst->read_symtab_private = NULL;
2676 /* Read the Line Number Program data and extract the list of files
2677 included by the source file represented by PST. Build an include
2678 partial symtab for each of these included files. */
2681 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2682 struct die_info *die,
2683 struct partial_symtab *pst)
2685 struct objfile *objfile = cu->objfile;
2686 bfd *abfd = objfile->obfd;
2687 struct line_header *lh = NULL;
2688 struct attribute *attr;
2690 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2693 unsigned int line_offset = DW_UNSND (attr);
2695 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2698 return; /* No linetable, so no includes. */
2700 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
2702 free_line_header (lh);
2706 hash_type_signature (const void *item)
2708 const struct signatured_type *type_sig = item;
2710 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2711 return type_sig->signature;
2715 eq_type_signature (const void *item_lhs, const void *item_rhs)
2717 const struct signatured_type *lhs = item_lhs;
2718 const struct signatured_type *rhs = item_rhs;
2720 return lhs->signature == rhs->signature;
2723 /* Allocate a hash table for signatured types. */
2726 allocate_signatured_type_hash_table (struct objfile *objfile)
2728 return htab_create_alloc_ex (41,
2729 hash_type_signature,
2732 &objfile->objfile_obstack,
2733 hashtab_obstack_allocate,
2734 dummy_obstack_deallocate);
2737 /* A helper function to add a signatured type CU to a list. */
2740 add_signatured_type_cu_to_list (void **slot, void *datum)
2742 struct signatured_type *sigt = *slot;
2743 struct dwarf2_per_cu_data ***datap = datum;
2745 **datap = &sigt->per_cu;
2751 /* Create the hash table of all entries in the .debug_types section.
2752 The result is zero if there is an error (e.g. missing .debug_types section),
2753 otherwise non-zero. */
2756 create_debug_types_hash_table (struct objfile *objfile)
2760 struct dwarf2_per_cu_data **iter;
2762 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
2763 info_ptr = dwarf2_per_objfile->types.buffer;
2765 if (info_ptr == NULL)
2767 dwarf2_per_objfile->signatured_types = NULL;
2771 types_htab = allocate_signatured_type_hash_table (objfile);
2773 if (dwarf2_die_debug)
2774 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
2776 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2778 unsigned int offset;
2779 unsigned int offset_size;
2780 unsigned int type_offset;
2781 unsigned int length, initial_length_size;
2782 unsigned short version;
2784 struct signatured_type *type_sig;
2786 gdb_byte *ptr = info_ptr;
2788 offset = ptr - dwarf2_per_objfile->types.buffer;
2790 /* We need to read the type's signature in order to build the hash
2791 table, but we don't need to read anything else just yet. */
2793 /* Sanity check to ensure entire cu is present. */
2794 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
2795 if (ptr + length + initial_length_size
2796 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
2798 complaint (&symfile_complaints,
2799 _("debug type entry runs off end of `.debug_types' section, ignored"));
2803 offset_size = initial_length_size == 4 ? 4 : 8;
2804 ptr += initial_length_size;
2805 version = bfd_get_16 (objfile->obfd, ptr);
2807 ptr += offset_size; /* abbrev offset */
2808 ptr += 1; /* address size */
2809 signature = bfd_get_64 (objfile->obfd, ptr);
2811 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
2813 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
2814 memset (type_sig, 0, sizeof (*type_sig));
2815 type_sig->signature = signature;
2816 type_sig->offset = offset;
2817 type_sig->type_offset = type_offset;
2818 type_sig->per_cu.objfile = objfile;
2819 type_sig->per_cu.from_debug_types = 1;
2821 slot = htab_find_slot (types_htab, type_sig, INSERT);
2822 gdb_assert (slot != NULL);
2825 if (dwarf2_die_debug)
2826 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
2827 offset, phex (signature, sizeof (signature)));
2829 info_ptr = info_ptr + initial_length_size + length;
2832 dwarf2_per_objfile->signatured_types = types_htab;
2834 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
2835 dwarf2_per_objfile->type_comp_units
2836 = obstack_alloc (&objfile->objfile_obstack,
2837 dwarf2_per_objfile->n_type_comp_units
2838 * sizeof (struct dwarf2_per_cu_data *));
2839 iter = &dwarf2_per_objfile->type_comp_units[0];
2840 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
2841 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
2842 == dwarf2_per_objfile->n_type_comp_units);
2847 /* Lookup a signature based type.
2848 Returns NULL if SIG is not present in the table. */
2850 static struct signatured_type *
2851 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
2853 struct signatured_type find_entry, *entry;
2855 if (dwarf2_per_objfile->signatured_types == NULL)
2857 complaint (&symfile_complaints,
2858 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2862 find_entry.signature = sig;
2863 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
2867 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2870 init_cu_die_reader (struct die_reader_specs *reader,
2871 struct dwarf2_cu *cu)
2873 reader->abfd = cu->objfile->obfd;
2875 if (cu->per_cu->from_debug_types)
2877 gdb_assert (dwarf2_per_objfile->types.readin);
2878 reader->buffer = dwarf2_per_objfile->types.buffer;
2882 gdb_assert (dwarf2_per_objfile->info.readin);
2883 reader->buffer = dwarf2_per_objfile->info.buffer;
2887 /* Find the base address of the compilation unit for range lists and
2888 location lists. It will normally be specified by DW_AT_low_pc.
2889 In DWARF-3 draft 4, the base address could be overridden by
2890 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2891 compilation units with discontinuous ranges. */
2894 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
2896 struct attribute *attr;
2899 cu->base_address = 0;
2901 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
2904 cu->base_address = DW_ADDR (attr);
2909 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2912 cu->base_address = DW_ADDR (attr);
2918 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2919 to combine the common parts.
2920 Process a compilation unit for a psymtab.
2921 BUFFER is a pointer to the beginning of the dwarf section buffer,
2922 either .debug_info or debug_types.
2923 INFO_PTR is a pointer to the start of the CU.
2924 Returns a pointer to the next CU. */
2927 process_psymtab_comp_unit (struct objfile *objfile,
2928 struct dwarf2_per_cu_data *this_cu,
2929 gdb_byte *buffer, gdb_byte *info_ptr,
2930 unsigned int buffer_size)
2932 bfd *abfd = objfile->obfd;
2933 gdb_byte *beg_of_comp_unit = info_ptr;
2934 struct die_info *comp_unit_die;
2935 struct partial_symtab *pst;
2937 struct cleanup *back_to_inner;
2938 struct dwarf2_cu cu;
2939 int has_children, has_pc_info;
2940 struct attribute *attr;
2941 CORE_ADDR best_lowpc = 0, best_highpc = 0;
2942 struct die_reader_specs reader_specs;
2944 memset (&cu, 0, sizeof (cu));
2945 cu.objfile = objfile;
2946 obstack_init (&cu.comp_unit_obstack);
2948 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
2950 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2951 buffer, buffer_size,
2954 /* Complete the cu_header. */
2955 cu.header.offset = beg_of_comp_unit - buffer;
2956 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2958 cu.list_in_scope = &file_symbols;
2960 /* If this compilation unit was already read in, free the
2961 cached copy in order to read it in again. This is
2962 necessary because we skipped some symbols when we first
2963 read in the compilation unit (see load_partial_dies).
2964 This problem could be avoided, but the benefit is
2966 if (this_cu->cu != NULL)
2967 free_one_cached_comp_unit (this_cu->cu);
2969 /* Note that this is a pointer to our stack frame, being
2970 added to a global data structure. It will be cleaned up
2971 in free_stack_comp_unit when we finish with this
2972 compilation unit. */
2974 cu.per_cu = this_cu;
2976 /* Read the abbrevs for this compilation unit into a table. */
2977 dwarf2_read_abbrevs (abfd, &cu);
2978 make_cleanup (dwarf2_free_abbrev_table, &cu);
2980 /* Read the compilation unit die. */
2981 if (this_cu->from_debug_types)
2982 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2983 init_cu_die_reader (&reader_specs, &cu);
2984 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2987 if (this_cu->from_debug_types)
2989 /* offset,length haven't been set yet for type units. */
2990 this_cu->offset = cu.header.offset;
2991 this_cu->length = cu.header.length + cu.header.initial_length_size;
2993 else if (comp_unit_die->tag == DW_TAG_partial_unit)
2995 info_ptr = (beg_of_comp_unit + cu.header.length
2996 + cu.header.initial_length_size);
2997 do_cleanups (back_to_inner);
3001 /* Set the language we're debugging. */
3002 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
3004 set_cu_language (DW_UNSND (attr), &cu);
3006 set_cu_language (language_minimal, &cu);
3008 /* Allocate a new partial symbol table structure. */
3009 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3010 pst = start_psymtab_common (objfile, objfile->section_offsets,
3011 (attr != NULL) ? DW_STRING (attr) : "",
3012 /* TEXTLOW and TEXTHIGH are set below. */
3014 objfile->global_psymbols.next,
3015 objfile->static_psymbols.next);
3017 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3019 pst->dirname = DW_STRING (attr);
3021 pst->read_symtab_private = this_cu;
3023 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3025 /* Store the function that reads in the rest of the symbol table */
3026 pst->read_symtab = dwarf2_psymtab_to_symtab;
3028 this_cu->v.psymtab = pst;
3030 dwarf2_find_base_address (comp_unit_die, &cu);
3032 /* Possibly set the default values of LOWPC and HIGHPC from
3034 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3035 &best_highpc, &cu, pst);
3036 if (has_pc_info == 1 && best_lowpc < best_highpc)
3037 /* Store the contiguous range if it is not empty; it can be empty for
3038 CUs with no code. */
3039 addrmap_set_empty (objfile->psymtabs_addrmap,
3040 best_lowpc + baseaddr,
3041 best_highpc + baseaddr - 1, pst);
3043 /* Check if comp unit has_children.
3044 If so, read the rest of the partial symbols from this comp unit.
3045 If not, there's no more debug_info for this comp unit. */
3048 struct partial_die_info *first_die;
3049 CORE_ADDR lowpc, highpc;
3051 lowpc = ((CORE_ADDR) -1);
3052 highpc = ((CORE_ADDR) 0);
3054 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3056 scan_partial_symbols (first_die, &lowpc, &highpc,
3057 ! has_pc_info, &cu);
3059 /* If we didn't find a lowpc, set it to highpc to avoid
3060 complaints from `maint check'. */
3061 if (lowpc == ((CORE_ADDR) -1))
3064 /* If the compilation unit didn't have an explicit address range,
3065 then use the information extracted from its child dies. */
3069 best_highpc = highpc;
3072 pst->textlow = best_lowpc + baseaddr;
3073 pst->texthigh = best_highpc + baseaddr;
3075 pst->n_global_syms = objfile->global_psymbols.next -
3076 (objfile->global_psymbols.list + pst->globals_offset);
3077 pst->n_static_syms = objfile->static_psymbols.next -
3078 (objfile->static_psymbols.list + pst->statics_offset);
3079 sort_pst_symbols (pst);
3081 info_ptr = (beg_of_comp_unit + cu.header.length
3082 + cu.header.initial_length_size);
3084 if (this_cu->from_debug_types)
3086 /* It's not clear we want to do anything with stmt lists here.
3087 Waiting to see what gcc ultimately does. */
3091 /* Get the list of files included in the current compilation unit,
3092 and build a psymtab for each of them. */
3093 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3096 do_cleanups (back_to_inner);
3101 /* Traversal function for htab_traverse_noresize.
3102 Process one .debug_types comp-unit. */
3105 process_type_comp_unit (void **slot, void *info)
3107 struct signatured_type *entry = (struct signatured_type *) *slot;
3108 struct objfile *objfile = (struct objfile *) info;
3109 struct dwarf2_per_cu_data *this_cu;
3111 this_cu = &entry->per_cu;
3113 gdb_assert (dwarf2_per_objfile->types.readin);
3114 process_psymtab_comp_unit (objfile, this_cu,
3115 dwarf2_per_objfile->types.buffer,
3116 dwarf2_per_objfile->types.buffer + entry->offset,
3117 dwarf2_per_objfile->types.size);
3122 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3123 Build partial symbol tables for the .debug_types comp-units. */
3126 build_type_psymtabs (struct objfile *objfile)
3128 if (! create_debug_types_hash_table (objfile))
3131 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3132 process_type_comp_unit, objfile);
3135 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3138 psymtabs_addrmap_cleanup (void *o)
3140 struct objfile *objfile = o;
3142 objfile->psymtabs_addrmap = NULL;
3145 /* Build the partial symbol table by doing a quick pass through the
3146 .debug_info and .debug_abbrev sections. */
3149 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3152 struct cleanup *back_to, *addrmap_cleanup;
3153 struct obstack temp_obstack;
3155 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3156 info_ptr = dwarf2_per_objfile->info.buffer;
3158 /* Any cached compilation units will be linked by the per-objfile
3159 read_in_chain. Make sure to free them when we're done. */
3160 back_to = make_cleanup (free_cached_comp_units, NULL);
3162 build_type_psymtabs (objfile);
3164 create_all_comp_units (objfile);
3166 /* Create a temporary address map on a temporary obstack. We later
3167 copy this to the final obstack. */
3168 obstack_init (&temp_obstack);
3169 make_cleanup_obstack_free (&temp_obstack);
3170 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3171 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3173 /* Since the objects we're extracting from .debug_info vary in
3174 length, only the individual functions to extract them (like
3175 read_comp_unit_head and load_partial_die) can really know whether
3176 the buffer is large enough to hold another complete object.
3178 At the moment, they don't actually check that. If .debug_info
3179 holds just one extra byte after the last compilation unit's dies,
3180 then read_comp_unit_head will happily read off the end of the
3181 buffer. read_partial_die is similarly casual. Those functions
3184 For this loop condition, simply checking whether there's any data
3185 left at all should be sufficient. */
3187 while (info_ptr < (dwarf2_per_objfile->info.buffer
3188 + dwarf2_per_objfile->info.size))
3190 struct dwarf2_per_cu_data *this_cu;
3192 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
3195 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3196 dwarf2_per_objfile->info.buffer,
3198 dwarf2_per_objfile->info.size);
3201 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3202 &objfile->objfile_obstack);
3203 discard_cleanups (addrmap_cleanup);
3205 do_cleanups (back_to);
3208 /* Load the partial DIEs for a secondary CU into memory. */
3211 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3212 struct objfile *objfile)
3214 bfd *abfd = objfile->obfd;
3215 gdb_byte *info_ptr, *beg_of_comp_unit;
3216 struct die_info *comp_unit_die;
3217 struct dwarf2_cu *cu;
3218 struct cleanup *back_to;
3219 struct attribute *attr;
3221 struct die_reader_specs reader_specs;
3223 gdb_assert (! this_cu->from_debug_types);
3225 gdb_assert (dwarf2_per_objfile->info.readin);
3226 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3227 beg_of_comp_unit = info_ptr;
3229 cu = alloc_one_comp_unit (objfile);
3231 /* ??? Missing cleanup for CU? */
3233 /* Link this compilation unit into the compilation unit tree. */
3235 cu->per_cu = this_cu;
3236 cu->type_hash = this_cu->type_hash;
3238 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3239 dwarf2_per_objfile->info.buffer,
3240 dwarf2_per_objfile->info.size,
3243 /* Complete the cu_header. */
3244 cu->header.offset = this_cu->offset;
3245 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3247 /* Read the abbrevs for this compilation unit into a table. */
3248 dwarf2_read_abbrevs (abfd, cu);
3249 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
3251 /* Read the compilation unit die. */
3252 init_cu_die_reader (&reader_specs, cu);
3253 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3256 /* Set the language we're debugging. */
3257 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
3259 set_cu_language (DW_UNSND (attr), cu);
3261 set_cu_language (language_minimal, cu);
3263 /* Check if comp unit has_children.
3264 If so, read the rest of the partial symbols from this comp unit.
3265 If not, there's no more debug_info for this comp unit. */
3267 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3269 do_cleanups (back_to);
3272 /* Create a list of all compilation units in OBJFILE. We do this only
3273 if an inter-comp-unit reference is found; presumably if there is one,
3274 there will be many, and one will occur early in the .debug_info section.
3275 So there's no point in building this list incrementally. */
3278 create_all_comp_units (struct objfile *objfile)
3282 struct dwarf2_per_cu_data **all_comp_units;
3285 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3286 info_ptr = dwarf2_per_objfile->info.buffer;
3290 all_comp_units = xmalloc (n_allocated
3291 * sizeof (struct dwarf2_per_cu_data *));
3293 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
3295 unsigned int length, initial_length_size;
3296 struct dwarf2_per_cu_data *this_cu;
3297 unsigned int offset;
3299 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3301 /* Read just enough information to find out where the next
3302 compilation unit is. */
3303 length = read_initial_length (objfile->obfd, info_ptr,
3304 &initial_length_size);
3306 /* Save the compilation unit for later lookup. */
3307 this_cu = obstack_alloc (&objfile->objfile_obstack,
3308 sizeof (struct dwarf2_per_cu_data));
3309 memset (this_cu, 0, sizeof (*this_cu));
3310 this_cu->offset = offset;
3311 this_cu->length = length + initial_length_size;
3312 this_cu->objfile = objfile;
3314 if (n_comp_units == n_allocated)
3317 all_comp_units = xrealloc (all_comp_units,
3319 * sizeof (struct dwarf2_per_cu_data *));
3321 all_comp_units[n_comp_units++] = this_cu;
3323 info_ptr = info_ptr + this_cu->length;
3326 dwarf2_per_objfile->all_comp_units
3327 = obstack_alloc (&objfile->objfile_obstack,
3328 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3329 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3330 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3331 xfree (all_comp_units);
3332 dwarf2_per_objfile->n_comp_units = n_comp_units;
3335 /* Process all loaded DIEs for compilation unit CU, starting at
3336 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3337 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3338 DW_AT_ranges). If NEED_PC is set, then this function will set
3339 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3340 and record the covered ranges in the addrmap. */
3343 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3344 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3346 struct partial_die_info *pdi;
3348 /* Now, march along the PDI's, descending into ones which have
3349 interesting children but skipping the children of the other ones,
3350 until we reach the end of the compilation unit. */
3356 fixup_partial_die (pdi, cu);
3358 /* Anonymous namespaces or modules have no name but have interesting
3359 children, so we need to look at them. Ditto for anonymous
3362 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3363 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3367 case DW_TAG_subprogram:
3368 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3370 case DW_TAG_variable:
3371 case DW_TAG_typedef:
3372 case DW_TAG_union_type:
3373 if (!pdi->is_declaration)
3375 add_partial_symbol (pdi, cu);
3378 case DW_TAG_class_type:
3379 case DW_TAG_interface_type:
3380 case DW_TAG_structure_type:
3381 if (!pdi->is_declaration)
3383 add_partial_symbol (pdi, cu);
3386 case DW_TAG_enumeration_type:
3387 if (!pdi->is_declaration)
3388 add_partial_enumeration (pdi, cu);
3390 case DW_TAG_base_type:
3391 case DW_TAG_subrange_type:
3392 /* File scope base type definitions are added to the partial
3394 add_partial_symbol (pdi, cu);
3396 case DW_TAG_namespace:
3397 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3400 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3407 /* If the die has a sibling, skip to the sibling. */
3409 pdi = pdi->die_sibling;
3413 /* Functions used to compute the fully scoped name of a partial DIE.
3415 Normally, this is simple. For C++, the parent DIE's fully scoped
3416 name is concatenated with "::" and the partial DIE's name. For
3417 Java, the same thing occurs except that "." is used instead of "::".
3418 Enumerators are an exception; they use the scope of their parent
3419 enumeration type, i.e. the name of the enumeration type is not
3420 prepended to the enumerator.
3422 There are two complexities. One is DW_AT_specification; in this
3423 case "parent" means the parent of the target of the specification,
3424 instead of the direct parent of the DIE. The other is compilers
3425 which do not emit DW_TAG_namespace; in this case we try to guess
3426 the fully qualified name of structure types from their members'
3427 linkage names. This must be done using the DIE's children rather
3428 than the children of any DW_AT_specification target. We only need
3429 to do this for structures at the top level, i.e. if the target of
3430 any DW_AT_specification (if any; otherwise the DIE itself) does not
3433 /* Compute the scope prefix associated with PDI's parent, in
3434 compilation unit CU. The result will be allocated on CU's
3435 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3436 field. NULL is returned if no prefix is necessary. */
3438 partial_die_parent_scope (struct partial_die_info *pdi,
3439 struct dwarf2_cu *cu)
3441 char *grandparent_scope;
3442 struct partial_die_info *parent, *real_pdi;
3444 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3445 then this means the parent of the specification DIE. */
3448 while (real_pdi->has_specification)
3449 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3451 parent = real_pdi->die_parent;
3455 if (parent->scope_set)
3456 return parent->scope;
3458 fixup_partial_die (parent, cu);
3460 grandparent_scope = partial_die_parent_scope (parent, cu);
3462 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3463 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3464 Work around this problem here. */
3465 if (cu->language == language_cplus
3466 && parent->tag == DW_TAG_namespace
3467 && strcmp (parent->name, "::") == 0
3468 && grandparent_scope == NULL)
3470 parent->scope = NULL;
3471 parent->scope_set = 1;
3475 if (parent->tag == DW_TAG_namespace
3476 || parent->tag == DW_TAG_module
3477 || parent->tag == DW_TAG_structure_type
3478 || parent->tag == DW_TAG_class_type
3479 || parent->tag == DW_TAG_interface_type
3480 || parent->tag == DW_TAG_union_type
3481 || parent->tag == DW_TAG_enumeration_type)
3483 if (grandparent_scope == NULL)
3484 parent->scope = parent->name;
3486 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
3487 parent->name, 0, cu);
3489 else if (parent->tag == DW_TAG_enumerator)
3490 /* Enumerators should not get the name of the enumeration as a prefix. */
3491 parent->scope = grandparent_scope;
3494 /* FIXME drow/2004-04-01: What should we be doing with
3495 function-local names? For partial symbols, we should probably be
3497 complaint (&symfile_complaints,
3498 _("unhandled containing DIE tag %d for DIE at %d"),
3499 parent->tag, pdi->offset);
3500 parent->scope = grandparent_scope;
3503 parent->scope_set = 1;
3504 return parent->scope;
3507 /* Return the fully scoped name associated with PDI, from compilation unit
3508 CU. The result will be allocated with malloc. */
3510 partial_die_full_name (struct partial_die_info *pdi,
3511 struct dwarf2_cu *cu)
3515 parent_scope = partial_die_parent_scope (pdi, cu);
3516 if (parent_scope == NULL)
3519 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3523 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3525 struct objfile *objfile = cu->objfile;
3527 char *actual_name = NULL;
3528 const struct partial_symbol *psym = NULL;
3530 int built_actual_name = 0;
3532 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3534 actual_name = partial_die_full_name (pdi, cu);
3536 built_actual_name = 1;
3538 if (actual_name == NULL)
3539 actual_name = pdi->name;
3543 case DW_TAG_subprogram:
3544 if (pdi->is_external || cu->language == language_ada)
3546 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3547 of the global scope. But in Ada, we want to be able to access
3548 nested procedures globally. So all Ada subprograms are stored
3549 in the global scope. */
3550 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3551 mst_text, objfile); */
3552 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3554 VAR_DOMAIN, LOC_BLOCK,
3555 &objfile->global_psymbols,
3556 0, pdi->lowpc + baseaddr,
3557 cu->language, objfile);
3561 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3562 mst_file_text, objfile); */
3563 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3565 VAR_DOMAIN, LOC_BLOCK,
3566 &objfile->static_psymbols,
3567 0, pdi->lowpc + baseaddr,
3568 cu->language, objfile);
3571 case DW_TAG_variable:
3572 if (pdi->is_external)
3575 Don't enter into the minimal symbol tables as there is
3576 a minimal symbol table entry from the ELF symbols already.
3577 Enter into partial symbol table if it has a location
3578 descriptor or a type.
3579 If the location descriptor is missing, new_symbol will create
3580 a LOC_UNRESOLVED symbol, the address of the variable will then
3581 be determined from the minimal symbol table whenever the variable
3583 The address for the partial symbol table entry is not
3584 used by GDB, but it comes in handy for debugging partial symbol
3588 addr = decode_locdesc (pdi->locdesc, cu);
3589 if (pdi->locdesc || pdi->has_type)
3590 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3592 VAR_DOMAIN, LOC_STATIC,
3593 &objfile->global_psymbols,
3595 cu->language, objfile);
3599 /* Static Variable. Skip symbols without location descriptors. */
3600 if (pdi->locdesc == NULL)
3602 if (built_actual_name)
3603 xfree (actual_name);
3606 addr = decode_locdesc (pdi->locdesc, cu);
3607 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3608 mst_file_data, objfile); */
3609 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
3611 VAR_DOMAIN, LOC_STATIC,
3612 &objfile->static_psymbols,
3614 cu->language, objfile);
3617 case DW_TAG_typedef:
3618 case DW_TAG_base_type:
3619 case DW_TAG_subrange_type:
3620 add_psymbol_to_list (actual_name, strlen (actual_name),
3622 VAR_DOMAIN, LOC_TYPEDEF,
3623 &objfile->static_psymbols,
3624 0, (CORE_ADDR) 0, cu->language, objfile);
3626 case DW_TAG_namespace:
3627 add_psymbol_to_list (actual_name, strlen (actual_name),
3629 VAR_DOMAIN, LOC_TYPEDEF,
3630 &objfile->global_psymbols,
3631 0, (CORE_ADDR) 0, cu->language, objfile);
3633 case DW_TAG_class_type:
3634 case DW_TAG_interface_type:
3635 case DW_TAG_structure_type:
3636 case DW_TAG_union_type:
3637 case DW_TAG_enumeration_type:
3638 /* Skip external references. The DWARF standard says in the section
3639 about "Structure, Union, and Class Type Entries": "An incomplete
3640 structure, union or class type is represented by a structure,
3641 union or class entry that does not have a byte size attribute
3642 and that has a DW_AT_declaration attribute." */
3643 if (!pdi->has_byte_size && pdi->is_declaration)
3645 if (built_actual_name)
3646 xfree (actual_name);
3650 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3651 static vs. global. */
3652 add_psymbol_to_list (actual_name, strlen (actual_name),
3654 STRUCT_DOMAIN, LOC_TYPEDEF,
3655 (cu->language == language_cplus
3656 || cu->language == language_java)
3657 ? &objfile->global_psymbols
3658 : &objfile->static_psymbols,
3659 0, (CORE_ADDR) 0, cu->language, objfile);
3662 case DW_TAG_enumerator:
3663 add_psymbol_to_list (actual_name, strlen (actual_name),
3665 VAR_DOMAIN, LOC_CONST,
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);
3676 if (built_actual_name)
3677 xfree (actual_name);
3680 /* Read a partial die corresponding to a namespace; also, add a symbol
3681 corresponding to that namespace to the symbol table. NAMESPACE is
3682 the name of the enclosing namespace. */
3685 add_partial_namespace (struct partial_die_info *pdi,
3686 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3687 int need_pc, struct dwarf2_cu *cu)
3689 /* Add a symbol for the namespace. */
3691 add_partial_symbol (pdi, cu);
3693 /* Now scan partial symbols in that namespace. */
3695 if (pdi->has_children)
3696 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3699 /* Read a partial die corresponding to a Fortran module. */
3702 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
3703 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3705 /* Now scan partial symbols in that module. */
3707 if (pdi->has_children)
3708 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
3711 /* Read a partial die corresponding to a subprogram and create a partial
3712 symbol for that subprogram. When the CU language allows it, this
3713 routine also defines a partial symbol for each nested subprogram
3714 that this subprogram contains.
3716 DIE my also be a lexical block, in which case we simply search
3717 recursively for suprograms defined inside that lexical block.
3718 Again, this is only performed when the CU language allows this
3719 type of definitions. */
3722 add_partial_subprogram (struct partial_die_info *pdi,
3723 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3724 int need_pc, struct dwarf2_cu *cu)
3726 if (pdi->tag == DW_TAG_subprogram)
3728 if (pdi->has_pc_info)
3730 if (pdi->lowpc < *lowpc)
3731 *lowpc = pdi->lowpc;
3732 if (pdi->highpc > *highpc)
3733 *highpc = pdi->highpc;
3737 struct objfile *objfile = cu->objfile;
3739 baseaddr = ANOFFSET (objfile->section_offsets,
3740 SECT_OFF_TEXT (objfile));
3741 addrmap_set_empty (objfile->psymtabs_addrmap,
3742 pdi->lowpc + baseaddr,
3743 pdi->highpc - 1 + baseaddr,
3744 cu->per_cu->v.psymtab);
3746 if (!pdi->is_declaration)
3747 /* Ignore subprogram DIEs that do not have a name, they are
3748 illegal. Do not emit a complaint at this point, we will
3749 do so when we convert this psymtab into a symtab. */
3751 add_partial_symbol (pdi, cu);
3755 if (! pdi->has_children)
3758 if (cu->language == language_ada)
3760 pdi = pdi->die_child;
3763 fixup_partial_die (pdi, cu);
3764 if (pdi->tag == DW_TAG_subprogram
3765 || pdi->tag == DW_TAG_lexical_block)
3766 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3767 pdi = pdi->die_sibling;
3772 /* See if we can figure out if the class lives in a namespace. We do
3773 this by looking for a member function; its demangled name will
3774 contain namespace info, if there is any. */
3777 guess_structure_name (struct partial_die_info *struct_pdi,
3778 struct dwarf2_cu *cu)
3780 if ((cu->language == language_cplus
3781 || cu->language == language_java)
3782 && cu->has_namespace_info == 0
3783 && struct_pdi->has_children)
3785 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3786 what template types look like, because the demangler
3787 frequently doesn't give the same name as the debug info. We
3788 could fix this by only using the demangled name to get the
3789 prefix (but see comment in read_structure_type). */
3791 struct partial_die_info *real_pdi;
3793 /* If this DIE (this DIE's specification, if any) has a parent, then
3794 we should not do this. We'll prepend the parent's fully qualified
3795 name when we create the partial symbol. */
3797 real_pdi = struct_pdi;
3798 while (real_pdi->has_specification)
3799 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3801 if (real_pdi->die_parent != NULL)
3806 /* Read a partial die corresponding to an enumeration type. */
3809 add_partial_enumeration (struct partial_die_info *enum_pdi,
3810 struct dwarf2_cu *cu)
3812 struct partial_die_info *pdi;
3814 if (enum_pdi->name != NULL)
3815 add_partial_symbol (enum_pdi, cu);
3817 pdi = enum_pdi->die_child;
3820 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
3821 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
3823 add_partial_symbol (pdi, cu);
3824 pdi = pdi->die_sibling;
3828 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3829 Return the corresponding abbrev, or NULL if the number is zero (indicating
3830 an empty DIE). In either case *BYTES_READ will be set to the length of
3831 the initial number. */
3833 static struct abbrev_info *
3834 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
3835 struct dwarf2_cu *cu)
3837 bfd *abfd = cu->objfile->obfd;
3838 unsigned int abbrev_number;
3839 struct abbrev_info *abbrev;
3841 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
3843 if (abbrev_number == 0)
3846 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
3849 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
3850 bfd_get_filename (abfd));
3856 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3857 Returns a pointer to the end of a series of DIEs, terminated by an empty
3858 DIE. Any children of the skipped DIEs will also be skipped. */
3861 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
3863 struct abbrev_info *abbrev;
3864 unsigned int bytes_read;
3868 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
3870 return info_ptr + bytes_read;
3872 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
3876 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3877 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3878 abbrev corresponding to that skipped uleb128 should be passed in
3879 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3883 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
3884 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
3886 unsigned int bytes_read;
3887 struct attribute attr;
3888 bfd *abfd = cu->objfile->obfd;
3889 unsigned int form, i;
3891 for (i = 0; i < abbrev->num_attrs; i++)
3893 /* The only abbrev we care about is DW_AT_sibling. */
3894 if (abbrev->attrs[i].name == DW_AT_sibling)
3896 read_attribute (&attr, &abbrev->attrs[i],
3897 abfd, info_ptr, cu);
3898 if (attr.form == DW_FORM_ref_addr)
3899 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
3901 return buffer + dwarf2_get_ref_die_offset (&attr);
3904 /* If it isn't DW_AT_sibling, skip this attribute. */
3905 form = abbrev->attrs[i].form;
3909 case DW_FORM_ref_addr:
3910 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
3911 and later it is offset sized. */
3912 if (cu->header.version == 2)
3913 info_ptr += cu->header.addr_size;
3915 info_ptr += cu->header.offset_size;
3918 info_ptr += cu->header.addr_size;
3925 case DW_FORM_flag_present:
3940 case DW_FORM_string:
3941 read_string (abfd, info_ptr, &bytes_read);
3942 info_ptr += bytes_read;
3944 case DW_FORM_sec_offset:
3946 info_ptr += cu->header.offset_size;
3948 case DW_FORM_exprloc:
3950 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3951 info_ptr += bytes_read;
3953 case DW_FORM_block1:
3954 info_ptr += 1 + read_1_byte (abfd, info_ptr);
3956 case DW_FORM_block2:
3957 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
3959 case DW_FORM_block4:
3960 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
3964 case DW_FORM_ref_udata:
3965 info_ptr = skip_leb128 (abfd, info_ptr);
3967 case DW_FORM_indirect:
3968 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3969 info_ptr += bytes_read;
3970 /* We need to continue parsing from here, so just go back to
3972 goto skip_attribute;
3975 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
3976 dwarf_form_name (form),
3977 bfd_get_filename (abfd));
3981 if (abbrev->has_children)
3982 return skip_children (buffer, info_ptr, cu);
3987 /* Locate ORIG_PDI's sibling.
3988 INFO_PTR should point to the start of the next DIE after ORIG_PDI
3992 locate_pdi_sibling (struct partial_die_info *orig_pdi,
3993 gdb_byte *buffer, gdb_byte *info_ptr,
3994 bfd *abfd, struct dwarf2_cu *cu)
3996 /* Do we know the sibling already? */
3998 if (orig_pdi->sibling)
3999 return orig_pdi->sibling;
4001 /* Are there any children to deal with? */
4003 if (!orig_pdi->has_children)
4006 /* Skip the children the long way. */
4008 return skip_children (buffer, info_ptr, cu);
4011 /* Expand this partial symbol table into a full symbol table. */
4014 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4020 warning (_("bug: psymtab for %s is already read in."), pst->filename);
4026 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
4027 gdb_flush (gdb_stdout);
4030 /* Restore our global data. */
4031 dwarf2_per_objfile = objfile_data (pst->objfile,
4032 dwarf2_objfile_data_key);
4034 /* If this psymtab is constructed from a debug-only objfile, the
4035 has_section_at_zero flag will not necessarily be correct. We
4036 can get the correct value for this flag by looking at the data
4037 associated with the (presumably stripped) associated objfile. */
4038 if (pst->objfile->separate_debug_objfile_backlink)
4040 struct dwarf2_per_objfile *dpo_backlink
4041 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4042 dwarf2_objfile_data_key);
4044 dwarf2_per_objfile->has_section_at_zero
4045 = dpo_backlink->has_section_at_zero;
4048 psymtab_to_symtab_1 (pst);
4050 /* Finish up the debug error message. */
4052 printf_filtered (_("done.\n"));
4057 /* Add PER_CU to the queue. */
4060 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4062 struct dwarf2_queue_item *item;
4065 item = xmalloc (sizeof (*item));
4066 item->per_cu = per_cu;
4069 if (dwarf2_queue == NULL)
4070 dwarf2_queue = item;
4072 dwarf2_queue_tail->next = item;
4074 dwarf2_queue_tail = item;
4077 /* Process the queue. */
4080 process_queue (struct objfile *objfile)
4082 struct dwarf2_queue_item *item, *next_item;
4084 /* The queue starts out with one item, but following a DIE reference
4085 may load a new CU, adding it to the end of the queue. */
4086 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4088 if (dwarf2_per_objfile->using_index
4089 ? !item->per_cu->v.quick->symtab
4090 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4091 process_full_comp_unit (item->per_cu);
4093 item->per_cu->queued = 0;
4094 next_item = item->next;
4098 dwarf2_queue_tail = NULL;
4101 /* Free all allocated queue entries. This function only releases anything if
4102 an error was thrown; if the queue was processed then it would have been
4103 freed as we went along. */
4106 dwarf2_release_queue (void *dummy)
4108 struct dwarf2_queue_item *item, *last;
4110 item = dwarf2_queue;
4113 /* Anything still marked queued is likely to be in an
4114 inconsistent state, so discard it. */
4115 if (item->per_cu->queued)
4117 if (item->per_cu->cu != NULL)
4118 free_one_cached_comp_unit (item->per_cu->cu);
4119 item->per_cu->queued = 0;
4127 dwarf2_queue = dwarf2_queue_tail = NULL;
4130 /* Read in full symbols for PST, and anything it depends on. */
4133 psymtab_to_symtab_1 (struct partial_symtab *pst)
4135 struct dwarf2_per_cu_data *per_cu;
4136 struct cleanup *back_to;
4139 for (i = 0; i < pst->number_of_dependencies; i++)
4140 if (!pst->dependencies[i]->readin)
4142 /* Inform about additional files that need to be read in. */
4145 /* FIXME: i18n: Need to make this a single string. */
4146 fputs_filtered (" ", gdb_stdout);
4148 fputs_filtered ("and ", gdb_stdout);
4150 printf_filtered ("%s...", pst->dependencies[i]->filename);
4151 wrap_here (""); /* Flush output */
4152 gdb_flush (gdb_stdout);
4154 psymtab_to_symtab_1 (pst->dependencies[i]);
4157 per_cu = pst->read_symtab_private;
4161 /* It's an include file, no symbols to read for it.
4162 Everything is in the parent symtab. */
4167 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4170 /* Load the DIEs associated with PER_CU into memory. */
4173 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4175 bfd *abfd = objfile->obfd;
4176 struct dwarf2_cu *cu;
4177 unsigned int offset;
4178 gdb_byte *info_ptr, *beg_of_comp_unit;
4179 struct cleanup *back_to, *free_cu_cleanup;
4180 struct attribute *attr;
4182 gdb_assert (! per_cu->from_debug_types);
4184 /* Set local variables from the partial symbol table info. */
4185 offset = per_cu->offset;
4187 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4188 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4189 beg_of_comp_unit = info_ptr;
4191 cu = alloc_one_comp_unit (objfile);
4193 /* If an error occurs while loading, release our storage. */
4194 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4196 /* Read in the comp_unit header. */
4197 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4199 /* Complete the cu_header. */
4200 cu->header.offset = offset;
4201 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4203 /* Read the abbrevs for this compilation unit. */
4204 dwarf2_read_abbrevs (abfd, cu);
4205 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
4207 /* Link this compilation unit into the compilation unit tree. */
4209 cu->per_cu = per_cu;
4210 cu->type_hash = per_cu->type_hash;
4212 cu->dies = read_comp_unit (info_ptr, cu);
4214 /* We try not to read any attributes in this function, because not
4215 all objfiles needed for references have been loaded yet, and symbol
4216 table processing isn't initialized. But we have to set the CU language,
4217 or we won't be able to build types correctly. */
4218 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
4220 set_cu_language (DW_UNSND (attr), cu);
4222 set_cu_language (language_minimal, cu);
4224 /* Similarly, if we do not read the producer, we can not apply
4225 producer-specific interpretation. */
4226 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4228 cu->producer = DW_STRING (attr);
4230 /* Link this CU into read_in_chain. */
4231 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4232 dwarf2_per_objfile->read_in_chain = per_cu;
4234 do_cleanups (back_to);
4236 /* We've successfully allocated this compilation unit. Let our caller
4237 clean it up when finished with it. */
4238 discard_cleanups (free_cu_cleanup);
4241 /* Generate full symbol information for PST and CU, whose DIEs have
4242 already been loaded into memory. */
4245 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4247 struct dwarf2_cu *cu = per_cu->cu;
4248 struct objfile *objfile = per_cu->objfile;
4249 CORE_ADDR lowpc, highpc;
4250 struct symtab *symtab;
4251 struct cleanup *back_to;
4254 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4257 back_to = make_cleanup (really_free_pendings, NULL);
4259 cu->list_in_scope = &file_symbols;
4261 dwarf2_find_base_address (cu->dies, cu);
4263 /* Do line number decoding in read_file_scope () */
4264 process_die (cu->dies, cu);
4266 /* Some compilers don't define a DW_AT_high_pc attribute for the
4267 compilation unit. If the DW_AT_high_pc is missing, synthesize
4268 it, by scanning the DIE's below the compilation unit. */
4269 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4271 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4273 /* Set symtab language to language from DW_AT_language.
4274 If the compilation is from a C file generated by language preprocessors,
4275 do not set the language if it was already deduced by start_subfile. */
4277 && !(cu->language == language_c && symtab->language != language_c))
4279 symtab->language = cu->language;
4282 if (dwarf2_per_objfile->using_index)
4283 per_cu->v.quick->symtab = symtab;
4286 struct partial_symtab *pst = per_cu->v.psymtab;
4287 pst->symtab = symtab;
4291 do_cleanups (back_to);
4294 /* Process a die and its children. */
4297 process_die (struct die_info *die, struct dwarf2_cu *cu)
4301 case DW_TAG_padding:
4303 case DW_TAG_compile_unit:
4304 read_file_scope (die, cu);
4306 case DW_TAG_type_unit:
4307 read_type_unit_scope (die, cu);
4309 case DW_TAG_subprogram:
4310 case DW_TAG_inlined_subroutine:
4311 read_func_scope (die, cu);
4313 case DW_TAG_lexical_block:
4314 case DW_TAG_try_block:
4315 case DW_TAG_catch_block:
4316 read_lexical_block_scope (die, cu);
4318 case DW_TAG_class_type:
4319 case DW_TAG_interface_type:
4320 case DW_TAG_structure_type:
4321 case DW_TAG_union_type:
4322 process_structure_scope (die, cu);
4324 case DW_TAG_enumeration_type:
4325 process_enumeration_scope (die, cu);
4328 /* These dies have a type, but processing them does not create
4329 a symbol or recurse to process the children. Therefore we can
4330 read them on-demand through read_type_die. */
4331 case DW_TAG_subroutine_type:
4332 case DW_TAG_set_type:
4333 case DW_TAG_array_type:
4334 case DW_TAG_pointer_type:
4335 case DW_TAG_ptr_to_member_type:
4336 case DW_TAG_reference_type:
4337 case DW_TAG_string_type:
4340 case DW_TAG_base_type:
4341 case DW_TAG_subrange_type:
4342 case DW_TAG_typedef:
4343 /* Add a typedef symbol for the type definition, if it has a
4345 new_symbol (die, read_type_die (die, cu), cu);
4347 case DW_TAG_common_block:
4348 read_common_block (die, cu);
4350 case DW_TAG_common_inclusion:
4352 case DW_TAG_namespace:
4353 processing_has_namespace_info = 1;
4354 read_namespace (die, cu);
4357 processing_has_namespace_info = 1;
4358 read_module (die, cu);
4360 case DW_TAG_imported_declaration:
4361 case DW_TAG_imported_module:
4362 processing_has_namespace_info = 1;
4363 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4364 || cu->language != language_fortran))
4365 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4366 dwarf_tag_name (die->tag));
4367 read_import_statement (die, cu);
4370 new_symbol (die, NULL, cu);
4375 /* A helper function for dwarf2_compute_name which determines whether DIE
4376 needs to have the name of the scope prepended to the name listed in the
4380 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4382 struct attribute *attr;
4386 case DW_TAG_namespace:
4387 case DW_TAG_typedef:
4388 case DW_TAG_class_type:
4389 case DW_TAG_interface_type:
4390 case DW_TAG_structure_type:
4391 case DW_TAG_union_type:
4392 case DW_TAG_enumeration_type:
4393 case DW_TAG_enumerator:
4394 case DW_TAG_subprogram:
4398 case DW_TAG_variable:
4399 /* We only need to prefix "globally" visible variables. These include
4400 any variable marked with DW_AT_external or any variable that
4401 lives in a namespace. [Variables in anonymous namespaces
4402 require prefixing, but they are not DW_AT_external.] */
4404 if (dwarf2_attr (die, DW_AT_specification, cu))
4406 struct dwarf2_cu *spec_cu = cu;
4408 return die_needs_namespace (die_specification (die, &spec_cu),
4412 attr = dwarf2_attr (die, DW_AT_external, cu);
4413 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4414 && die->parent->tag != DW_TAG_module)
4416 /* A variable in a lexical block of some kind does not need a
4417 namespace, even though in C++ such variables may be external
4418 and have a mangled name. */
4419 if (die->parent->tag == DW_TAG_lexical_block
4420 || die->parent->tag == DW_TAG_try_block
4421 || die->parent->tag == DW_TAG_catch_block
4422 || die->parent->tag == DW_TAG_subprogram)
4431 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4432 compute the physname for the object, which include a method's
4433 formal parameters (C++/Java) and return type (Java).
4435 For Ada, return the DIE's linkage name rather than the fully qualified
4436 name. PHYSNAME is ignored..
4438 The result is allocated on the objfile_obstack and canonicalized. */
4441 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4445 name = dwarf2_name (die, cu);
4447 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4448 compute it by typename_concat inside GDB. */
4449 if (cu->language == language_ada
4450 || (cu->language == language_fortran && physname))
4452 /* For Ada unit, we prefer the linkage name over the name, as
4453 the former contains the exported name, which the user expects
4454 to be able to reference. Ideally, we want the user to be able
4455 to reference this entity using either natural or linkage name,
4456 but we haven't started looking at this enhancement yet. */
4457 struct attribute *attr;
4459 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4461 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4462 if (attr && DW_STRING (attr))
4463 return DW_STRING (attr);
4466 /* These are the only languages we know how to qualify names in. */
4468 && (cu->language == language_cplus || cu->language == language_java
4469 || cu->language == language_fortran))
4471 if (die_needs_namespace (die, cu))
4475 struct ui_file *buf;
4477 prefix = determine_prefix (die, cu);
4478 buf = mem_fileopen ();
4479 if (*prefix != '\0')
4481 char *prefixed_name = typename_concat (NULL, prefix, name,
4484 fputs_unfiltered (prefixed_name, buf);
4485 xfree (prefixed_name);
4488 fputs_unfiltered (name ? name : "", buf);
4490 /* For Java and C++ methods, append formal parameter type
4491 information, if PHYSNAME. */
4493 if (physname && die->tag == DW_TAG_subprogram
4494 && (cu->language == language_cplus
4495 || cu->language == language_java))
4497 struct type *type = read_type_die (die, cu);
4499 c_type_print_args (type, buf, 0, cu->language);
4501 if (cu->language == language_java)
4503 /* For java, we must append the return type to method
4505 if (die->tag == DW_TAG_subprogram)
4506 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
4509 else if (cu->language == language_cplus)
4511 if (TYPE_NFIELDS (type) > 0
4512 && TYPE_FIELD_ARTIFICIAL (type, 0)
4513 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
4514 fputs_unfiltered (" const", buf);
4518 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
4520 ui_file_delete (buf);
4522 if (cu->language == language_cplus)
4525 = dwarf2_canonicalize_name (name, cu,
4526 &cu->objfile->objfile_obstack);
4537 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4538 If scope qualifiers are appropriate they will be added. The result
4539 will be allocated on the objfile_obstack, or NULL if the DIE does
4540 not have a name. NAME may either be from a previous call to
4541 dwarf2_name or NULL.
4543 The output string will be canonicalized (if C++/Java). */
4546 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
4548 return dwarf2_compute_name (name, die, cu, 0);
4551 /* Construct a physname for the given DIE in CU. NAME may either be
4552 from a previous call to dwarf2_name or NULL. The result will be
4553 allocated on the objfile_objstack or NULL if the DIE does not have a
4556 The output string will be canonicalized (if C++/Java). */
4559 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
4561 return dwarf2_compute_name (name, die, cu, 1);
4564 /* Read the import statement specified by the given die and record it. */
4567 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
4569 struct attribute *import_attr;
4570 struct die_info *imported_die;
4571 struct dwarf2_cu *imported_cu;
4572 const char *imported_name;
4573 const char *imported_name_prefix;
4574 const char *canonical_name;
4575 const char *import_alias;
4576 const char *imported_declaration = NULL;
4577 const char *import_prefix;
4581 import_attr = dwarf2_attr (die, DW_AT_import, cu);
4582 if (import_attr == NULL)
4584 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
4585 dwarf_tag_name (die->tag));
4590 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
4591 imported_name = dwarf2_name (imported_die, imported_cu);
4592 if (imported_name == NULL)
4594 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4596 The import in the following code:
4610 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4611 <52> DW_AT_decl_file : 1
4612 <53> DW_AT_decl_line : 6
4613 <54> DW_AT_import : <0x75>
4614 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4616 <5b> DW_AT_decl_file : 1
4617 <5c> DW_AT_decl_line : 2
4618 <5d> DW_AT_type : <0x6e>
4620 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4621 <76> DW_AT_byte_size : 4
4622 <77> DW_AT_encoding : 5 (signed)
4624 imports the wrong die ( 0x75 instead of 0x58 ).
4625 This case will be ignored until the gcc bug is fixed. */
4629 /* Figure out the local name after import. */
4630 import_alias = dwarf2_name (die, cu);
4632 /* Figure out where the statement is being imported to. */
4633 import_prefix = determine_prefix (die, cu);
4635 /* Figure out what the scope of the imported die is and prepend it
4636 to the name of the imported die. */
4637 imported_name_prefix = determine_prefix (imported_die, imported_cu);
4639 if (imported_die->tag != DW_TAG_namespace
4640 && imported_die->tag != DW_TAG_module)
4642 imported_declaration = imported_name;
4643 canonical_name = imported_name_prefix;
4645 else if (strlen (imported_name_prefix) > 0)
4647 temp = alloca (strlen (imported_name_prefix)
4648 + 2 + strlen (imported_name) + 1);
4649 strcpy (temp, imported_name_prefix);
4650 strcat (temp, "::");
4651 strcat (temp, imported_name);
4652 canonical_name = temp;
4655 canonical_name = imported_name;
4657 cp_add_using_directive (import_prefix,
4660 imported_declaration,
4661 &cu->objfile->objfile_obstack);
4665 initialize_cu_func_list (struct dwarf2_cu *cu)
4667 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
4671 free_cu_line_header (void *arg)
4673 struct dwarf2_cu *cu = arg;
4675 free_line_header (cu->line_header);
4676 cu->line_header = NULL;
4680 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
4681 char **name, char **comp_dir)
4683 struct attribute *attr;
4688 /* Find the filename. Do not use dwarf2_name here, since the filename
4689 is not a source language identifier. */
4690 attr = dwarf2_attr (die, DW_AT_name, cu);
4693 *name = DW_STRING (attr);
4696 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
4698 *comp_dir = DW_STRING (attr);
4699 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
4701 *comp_dir = ldirname (*name);
4702 if (*comp_dir != NULL)
4703 make_cleanup (xfree, *comp_dir);
4705 if (*comp_dir != NULL)
4707 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4708 directory, get rid of it. */
4709 char *cp = strchr (*comp_dir, ':');
4711 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
4716 *name = "<unknown>";
4720 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
4722 struct objfile *objfile = cu->objfile;
4723 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4724 CORE_ADDR lowpc = ((CORE_ADDR) -1);
4725 CORE_ADDR highpc = ((CORE_ADDR) 0);
4726 struct attribute *attr;
4728 char *comp_dir = NULL;
4729 struct die_info *child_die;
4730 bfd *abfd = objfile->obfd;
4731 struct line_header *line_header = 0;
4734 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4736 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
4738 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4739 from finish_block. */
4740 if (lowpc == ((CORE_ADDR) -1))
4745 find_file_and_directory (die, cu, &name, &comp_dir);
4747 attr = dwarf2_attr (die, DW_AT_language, cu);
4750 set_cu_language (DW_UNSND (attr), cu);
4753 attr = dwarf2_attr (die, DW_AT_producer, cu);
4755 cu->producer = DW_STRING (attr);
4757 /* We assume that we're processing GCC output. */
4758 processing_gcc_compilation = 2;
4760 processing_has_namespace_info = 0;
4762 start_symtab (name, comp_dir, lowpc);
4763 record_debugformat ("DWARF 2");
4764 record_producer (cu->producer);
4766 initialize_cu_func_list (cu);
4768 /* Decode line number information if present. We do this before
4769 processing child DIEs, so that the line header table is available
4770 for DW_AT_decl_file. */
4771 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
4774 unsigned int line_offset = DW_UNSND (attr);
4775 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
4778 cu->line_header = line_header;
4779 make_cleanup (free_cu_line_header, cu);
4780 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
4784 /* Process all dies in compilation unit. */
4785 if (die->child != NULL)
4787 child_die = die->child;
4788 while (child_die && child_die->tag)
4790 process_die (child_die, cu);
4791 child_die = sibling_die (child_die);
4795 /* Decode macro information, if present. Dwarf 2 macro information
4796 refers to information in the line number info statement program
4797 header, so we can only read it if we've read the header
4799 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
4800 if (attr && line_header)
4802 unsigned int macro_offset = DW_UNSND (attr);
4804 dwarf_decode_macros (line_header, macro_offset,
4805 comp_dir, abfd, cu);
4807 do_cleanups (back_to);
4810 /* For TUs we want to skip the first top level sibling if it's not the
4811 actual type being defined by this TU. In this case the first top
4812 level sibling is there to provide context only. */
4815 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
4817 struct objfile *objfile = cu->objfile;
4818 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4820 struct attribute *attr;
4822 char *comp_dir = NULL;
4823 struct die_info *child_die;
4824 bfd *abfd = objfile->obfd;
4826 /* start_symtab needs a low pc, but we don't really have one.
4827 Do what read_file_scope would do in the absence of such info. */
4828 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4830 /* Find the filename. Do not use dwarf2_name here, since the filename
4831 is not a source language identifier. */
4832 attr = dwarf2_attr (die, DW_AT_name, cu);
4834 name = DW_STRING (attr);
4836 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
4838 comp_dir = DW_STRING (attr);
4839 else if (name != NULL && IS_ABSOLUTE_PATH (name))
4841 comp_dir = ldirname (name);
4842 if (comp_dir != NULL)
4843 make_cleanup (xfree, comp_dir);
4849 attr = dwarf2_attr (die, DW_AT_language, cu);
4851 set_cu_language (DW_UNSND (attr), cu);
4853 /* This isn't technically needed today. It is done for symmetry
4854 with read_file_scope. */
4855 attr = dwarf2_attr (die, DW_AT_producer, cu);
4857 cu->producer = DW_STRING (attr);
4859 /* We assume that we're processing GCC output. */
4860 processing_gcc_compilation = 2;
4862 processing_has_namespace_info = 0;
4864 start_symtab (name, comp_dir, lowpc);
4865 record_debugformat ("DWARF 2");
4866 record_producer (cu->producer);
4868 /* Process the dies in the type unit. */
4869 if (die->child == NULL)
4871 dump_die_for_error (die);
4872 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
4873 bfd_get_filename (abfd));
4876 child_die = die->child;
4878 while (child_die && child_die->tag)
4880 process_die (child_die, cu);
4882 child_die = sibling_die (child_die);
4885 do_cleanups (back_to);
4889 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
4890 struct dwarf2_cu *cu)
4892 struct function_range *thisfn;
4894 thisfn = (struct function_range *)
4895 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
4896 thisfn->name = name;
4897 thisfn->lowpc = lowpc;
4898 thisfn->highpc = highpc;
4899 thisfn->seen_line = 0;
4900 thisfn->next = NULL;
4902 if (cu->last_fn == NULL)
4903 cu->first_fn = thisfn;
4905 cu->last_fn->next = thisfn;
4907 cu->last_fn = thisfn;
4910 /* qsort helper for inherit_abstract_dies. */
4913 unsigned_int_compar (const void *ap, const void *bp)
4915 unsigned int a = *(unsigned int *) ap;
4916 unsigned int b = *(unsigned int *) bp;
4918 return (a > b) - (b > a);
4921 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
4922 Inherit only the children of the DW_AT_abstract_origin DIE not being already
4923 referenced by DW_AT_abstract_origin from the children of the current DIE. */
4926 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
4928 struct die_info *child_die;
4929 unsigned die_children_count;
4930 /* CU offsets which were referenced by children of the current DIE. */
4932 unsigned *offsets_end, *offsetp;
4933 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
4934 struct die_info *origin_die;
4935 /* Iterator of the ORIGIN_DIE children. */
4936 struct die_info *origin_child_die;
4937 struct cleanup *cleanups;
4938 struct attribute *attr;
4940 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
4944 origin_die = follow_die_ref (die, attr, &cu);
4945 if (die->tag != origin_die->tag
4946 && !(die->tag == DW_TAG_inlined_subroutine
4947 && origin_die->tag == DW_TAG_subprogram))
4948 complaint (&symfile_complaints,
4949 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
4950 die->offset, origin_die->offset);
4952 child_die = die->child;
4953 die_children_count = 0;
4954 while (child_die && child_die->tag)
4956 child_die = sibling_die (child_die);
4957 die_children_count++;
4959 offsets = xmalloc (sizeof (*offsets) * die_children_count);
4960 cleanups = make_cleanup (xfree, offsets);
4962 offsets_end = offsets;
4963 child_die = die->child;
4964 while (child_die && child_die->tag)
4966 /* For each CHILD_DIE, find the corresponding child of
4967 ORIGIN_DIE. If there is more than one layer of
4968 DW_AT_abstract_origin, follow them all; there shouldn't be,
4969 but GCC versions at least through 4.4 generate this (GCC PR
4971 struct die_info *child_origin_die = child_die;
4975 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
4978 child_origin_die = follow_die_ref (child_origin_die, attr, &cu);
4981 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
4982 counterpart may exist. */
4983 if (child_origin_die != child_die)
4985 if (child_die->tag != child_origin_die->tag
4986 && !(child_die->tag == DW_TAG_inlined_subroutine
4987 && child_origin_die->tag == DW_TAG_subprogram))
4988 complaint (&symfile_complaints,
4989 _("Child DIE 0x%x and its abstract origin 0x%x have "
4990 "different tags"), child_die->offset,
4991 child_origin_die->offset);
4992 if (child_origin_die->parent != origin_die)
4993 complaint (&symfile_complaints,
4994 _("Child DIE 0x%x and its abstract origin 0x%x have "
4995 "different parents"), child_die->offset,
4996 child_origin_die->offset);
4998 *offsets_end++ = child_origin_die->offset;
5000 child_die = sibling_die (child_die);
5002 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5003 unsigned_int_compar);
5004 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5005 if (offsetp[-1] == *offsetp)
5006 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
5007 "to DIE 0x%x as their abstract origin"),
5008 die->offset, *offsetp);
5011 origin_child_die = origin_die->child;
5012 while (origin_child_die && origin_child_die->tag)
5014 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5015 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5017 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5019 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5020 process_die (origin_child_die, cu);
5022 origin_child_die = sibling_die (origin_child_die);
5025 do_cleanups (cleanups);
5029 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5031 struct objfile *objfile = cu->objfile;
5032 struct context_stack *new;
5035 struct die_info *child_die;
5036 struct attribute *attr, *call_line, *call_file;
5039 struct block *block;
5040 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5044 /* If we do not have call site information, we can't show the
5045 caller of this inlined function. That's too confusing, so
5046 only use the scope for local variables. */
5047 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5048 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5049 if (call_line == NULL || call_file == NULL)
5051 read_lexical_block_scope (die, cu);
5056 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5058 name = dwarf2_name (die, cu);
5060 /* Ignore functions with missing or empty names. These are actually
5061 illegal according to the DWARF standard. */
5064 complaint (&symfile_complaints,
5065 _("missing name for subprogram DIE at %d"), die->offset);
5069 /* Ignore functions with missing or invalid low and high pc attributes. */
5070 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5072 attr = dwarf2_attr (die, DW_AT_external, cu);
5073 if (!attr || !DW_UNSND (attr))
5074 complaint (&symfile_complaints,
5075 _("cannot get low and high bounds for subprogram DIE at %d"),
5083 /* Record the function range for dwarf_decode_lines. */
5084 add_to_cu_func_list (name, lowpc, highpc, cu);
5086 new = push_context (0, lowpc);
5087 new->name = new_symbol (die, read_type_die (die, cu), cu);
5089 /* If there is a location expression for DW_AT_frame_base, record
5091 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5093 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5094 expression is being recorded directly in the function's symbol
5095 and not in a separate frame-base object. I guess this hack is
5096 to avoid adding some sort of frame-base adjunct/annex to the
5097 function's symbol :-(. The problem with doing this is that it
5098 results in a function symbol with a location expression that
5099 has nothing to do with the location of the function, ouch! The
5100 relationship should be: a function's symbol has-a frame base; a
5101 frame-base has-a location expression. */
5102 dwarf2_symbol_mark_computed (attr, new->name, cu);
5104 cu->list_in_scope = &local_symbols;
5106 if (die->child != NULL)
5108 child_die = die->child;
5109 while (child_die && child_die->tag)
5111 process_die (child_die, cu);
5112 child_die = sibling_die (child_die);
5116 inherit_abstract_dies (die, cu);
5118 /* If we have a DW_AT_specification, we might need to import using
5119 directives from the context of the specification DIE. See the
5120 comment in determine_prefix. */
5121 if (cu->language == language_cplus
5122 && dwarf2_attr (die, DW_AT_specification, cu))
5124 struct dwarf2_cu *spec_cu = cu;
5125 struct die_info *spec_die = die_specification (die, &spec_cu);
5129 child_die = spec_die->child;
5130 while (child_die && child_die->tag)
5132 if (child_die->tag == DW_TAG_imported_module)
5133 process_die (child_die, spec_cu);
5134 child_die = sibling_die (child_die);
5137 /* In some cases, GCC generates specification DIEs that
5138 themselves contain DW_AT_specification attributes. */
5139 spec_die = die_specification (spec_die, &spec_cu);
5143 new = pop_context ();
5144 /* Make a block for the local symbols within. */
5145 block = finish_block (new->name, &local_symbols, new->old_blocks,
5146 lowpc, highpc, objfile);
5148 /* For C++, set the block's scope. */
5149 if (cu->language == language_cplus || cu->language == language_fortran)
5150 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5151 determine_prefix (die, cu),
5152 processing_has_namespace_info);
5154 /* If we have address ranges, record them. */
5155 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5157 /* In C++, we can have functions nested inside functions (e.g., when
5158 a function declares a class that has methods). This means that
5159 when we finish processing a function scope, we may need to go
5160 back to building a containing block's symbol lists. */
5161 local_symbols = new->locals;
5162 param_symbols = new->params;
5163 using_directives = new->using_directives;
5165 /* If we've finished processing a top-level function, subsequent
5166 symbols go in the file symbol list. */
5167 if (outermost_context_p ())
5168 cu->list_in_scope = &file_symbols;
5171 /* Process all the DIES contained within a lexical block scope. Start
5172 a new scope, process the dies, and then close the scope. */
5175 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5177 struct objfile *objfile = cu->objfile;
5178 struct context_stack *new;
5179 CORE_ADDR lowpc, highpc;
5180 struct die_info *child_die;
5183 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5185 /* Ignore blocks with missing or invalid low and high pc attributes. */
5186 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5187 as multiple lexical blocks? Handling children in a sane way would
5188 be nasty. Might be easier to properly extend generic blocks to
5190 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5195 push_context (0, lowpc);
5196 if (die->child != NULL)
5198 child_die = die->child;
5199 while (child_die && child_die->tag)
5201 process_die (child_die, cu);
5202 child_die = sibling_die (child_die);
5205 new = pop_context ();
5207 if (local_symbols != NULL || using_directives != NULL)
5210 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5213 /* Note that recording ranges after traversing children, as we
5214 do here, means that recording a parent's ranges entails
5215 walking across all its children's ranges as they appear in
5216 the address map, which is quadratic behavior.
5218 It would be nicer to record the parent's ranges before
5219 traversing its children, simply overriding whatever you find
5220 there. But since we don't even decide whether to create a
5221 block until after we've traversed its children, that's hard
5223 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5225 local_symbols = new->locals;
5226 using_directives = new->using_directives;
5229 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5230 Return 1 if the attributes are present and valid, otherwise, return 0.
5231 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5234 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5235 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5236 struct partial_symtab *ranges_pst)
5238 struct objfile *objfile = cu->objfile;
5239 struct comp_unit_head *cu_header = &cu->header;
5240 bfd *obfd = objfile->obfd;
5241 unsigned int addr_size = cu_header->addr_size;
5242 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5243 /* Base address selection entry. */
5254 found_base = cu->base_known;
5255 base = cu->base_address;
5257 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5258 if (offset >= dwarf2_per_objfile->ranges.size)
5260 complaint (&symfile_complaints,
5261 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5265 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5267 /* Read in the largest possible address. */
5268 marker = read_address (obfd, buffer, cu, &dummy);
5269 if ((marker & mask) == mask)
5271 /* If we found the largest possible address, then
5272 read the base address. */
5273 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5274 buffer += 2 * addr_size;
5275 offset += 2 * addr_size;
5281 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5285 CORE_ADDR range_beginning, range_end;
5287 range_beginning = read_address (obfd, buffer, cu, &dummy);
5288 buffer += addr_size;
5289 range_end = read_address (obfd, buffer, cu, &dummy);
5290 buffer += addr_size;
5291 offset += 2 * addr_size;
5293 /* An end of list marker is a pair of zero addresses. */
5294 if (range_beginning == 0 && range_end == 0)
5295 /* Found the end of list entry. */
5298 /* Each base address selection entry is a pair of 2 values.
5299 The first is the largest possible address, the second is
5300 the base address. Check for a base address here. */
5301 if ((range_beginning & mask) == mask)
5303 /* If we found the largest possible address, then
5304 read the base address. */
5305 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5312 /* We have no valid base address for the ranges
5314 complaint (&symfile_complaints,
5315 _("Invalid .debug_ranges data (no base address)"));
5319 range_beginning += base;
5322 if (ranges_pst != NULL && range_beginning < range_end)
5323 addrmap_set_empty (objfile->psymtabs_addrmap,
5324 range_beginning + baseaddr, range_end - 1 + baseaddr,
5327 /* FIXME: This is recording everything as a low-high
5328 segment of consecutive addresses. We should have a
5329 data structure for discontiguous block ranges
5333 low = range_beginning;
5339 if (range_beginning < low)
5340 low = range_beginning;
5341 if (range_end > high)
5347 /* If the first entry is an end-of-list marker, the range
5348 describes an empty scope, i.e. no instructions. */
5354 *high_return = high;
5358 /* Get low and high pc attributes from a die. Return 1 if the attributes
5359 are present and valid, otherwise, return 0. Return -1 if the range is
5360 discontinuous, i.e. derived from DW_AT_ranges information. */
5362 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5363 CORE_ADDR *highpc, struct dwarf2_cu *cu,
5364 struct partial_symtab *pst)
5366 struct attribute *attr;
5371 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5374 high = DW_ADDR (attr);
5375 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5377 low = DW_ADDR (attr);
5379 /* Found high w/o low attribute. */
5382 /* Found consecutive range of addresses. */
5387 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5390 /* Value of the DW_AT_ranges attribute is the offset in the
5391 .debug_ranges section. */
5392 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
5394 /* Found discontinuous range of addresses. */
5402 /* When using the GNU linker, .gnu.linkonce. sections are used to
5403 eliminate duplicate copies of functions and vtables and such.
5404 The linker will arbitrarily choose one and discard the others.
5405 The AT_*_pc values for such functions refer to local labels in
5406 these sections. If the section from that file was discarded, the
5407 labels are not in the output, so the relocs get a value of 0.
5408 If this is a discarded function, mark the pc bounds as invalid,
5409 so that GDB will ignore it. */
5410 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
5418 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5419 its low and high PC addresses. Do nothing if these addresses could not
5420 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5421 and HIGHPC to the high address if greater than HIGHPC. */
5424 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
5425 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5426 struct dwarf2_cu *cu)
5428 CORE_ADDR low, high;
5429 struct die_info *child = die->child;
5431 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
5433 *lowpc = min (*lowpc, low);
5434 *highpc = max (*highpc, high);
5437 /* If the language does not allow nested subprograms (either inside
5438 subprograms or lexical blocks), we're done. */
5439 if (cu->language != language_ada)
5442 /* Check all the children of the given DIE. If it contains nested
5443 subprograms, then check their pc bounds. Likewise, we need to
5444 check lexical blocks as well, as they may also contain subprogram
5446 while (child && child->tag)
5448 if (child->tag == DW_TAG_subprogram
5449 || child->tag == DW_TAG_lexical_block)
5450 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
5451 child = sibling_die (child);
5455 /* Get the low and high pc's represented by the scope DIE, and store
5456 them in *LOWPC and *HIGHPC. If the correct values can't be
5457 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5460 get_scope_pc_bounds (struct die_info *die,
5461 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5462 struct dwarf2_cu *cu)
5464 CORE_ADDR best_low = (CORE_ADDR) -1;
5465 CORE_ADDR best_high = (CORE_ADDR) 0;
5466 CORE_ADDR current_low, current_high;
5468 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
5470 best_low = current_low;
5471 best_high = current_high;
5475 struct die_info *child = die->child;
5477 while (child && child->tag)
5479 switch (child->tag) {
5480 case DW_TAG_subprogram:
5481 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
5483 case DW_TAG_namespace:
5485 /* FIXME: carlton/2004-01-16: Should we do this for
5486 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5487 that current GCC's always emit the DIEs corresponding
5488 to definitions of methods of classes as children of a
5489 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5490 the DIEs giving the declarations, which could be
5491 anywhere). But I don't see any reason why the
5492 standards says that they have to be there. */
5493 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
5495 if (current_low != ((CORE_ADDR) -1))
5497 best_low = min (best_low, current_low);
5498 best_high = max (best_high, current_high);
5506 child = sibling_die (child);
5511 *highpc = best_high;
5514 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5517 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
5518 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
5520 struct attribute *attr;
5522 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5525 CORE_ADDR high = DW_ADDR (attr);
5527 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5530 CORE_ADDR low = DW_ADDR (attr);
5532 record_block_range (block, baseaddr + low, baseaddr + high - 1);
5536 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5539 bfd *obfd = cu->objfile->obfd;
5541 /* The value of the DW_AT_ranges attribute is the offset of the
5542 address range list in the .debug_ranges section. */
5543 unsigned long offset = DW_UNSND (attr);
5544 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
5546 /* For some target architectures, but not others, the
5547 read_address function sign-extends the addresses it returns.
5548 To recognize base address selection entries, we need a
5550 unsigned int addr_size = cu->header.addr_size;
5551 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5553 /* The base address, to which the next pair is relative. Note
5554 that this 'base' is a DWARF concept: most entries in a range
5555 list are relative, to reduce the number of relocs against the
5556 debugging information. This is separate from this function's
5557 'baseaddr' argument, which GDB uses to relocate debugging
5558 information from a shared library based on the address at
5559 which the library was loaded. */
5560 CORE_ADDR base = cu->base_address;
5561 int base_known = cu->base_known;
5563 gdb_assert (dwarf2_per_objfile->ranges.readin);
5564 if (offset >= dwarf2_per_objfile->ranges.size)
5566 complaint (&symfile_complaints,
5567 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5574 unsigned int bytes_read;
5575 CORE_ADDR start, end;
5577 start = read_address (obfd, buffer, cu, &bytes_read);
5578 buffer += bytes_read;
5579 end = read_address (obfd, buffer, cu, &bytes_read);
5580 buffer += bytes_read;
5582 /* Did we find the end of the range list? */
5583 if (start == 0 && end == 0)
5586 /* Did we find a base address selection entry? */
5587 else if ((start & base_select_mask) == base_select_mask)
5593 /* We found an ordinary address range. */
5598 complaint (&symfile_complaints,
5599 _("Invalid .debug_ranges data (no base address)"));
5603 record_block_range (block,
5604 baseaddr + base + start,
5605 baseaddr + base + end - 1);
5611 /* Add an aggregate field to the field list. */
5614 dwarf2_add_field (struct field_info *fip, struct die_info *die,
5615 struct dwarf2_cu *cu)
5617 struct objfile *objfile = cu->objfile;
5618 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5619 struct nextfield *new_field;
5620 struct attribute *attr;
5622 char *fieldname = "";
5624 /* Allocate a new field list entry and link it in. */
5625 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
5626 make_cleanup (xfree, new_field);
5627 memset (new_field, 0, sizeof (struct nextfield));
5629 if (die->tag == DW_TAG_inheritance)
5631 new_field->next = fip->baseclasses;
5632 fip->baseclasses = new_field;
5636 new_field->next = fip->fields;
5637 fip->fields = new_field;
5641 /* Handle accessibility and virtuality of field.
5642 The default accessibility for members is public, the default
5643 accessibility for inheritance is private. */
5644 if (die->tag != DW_TAG_inheritance)
5645 new_field->accessibility = DW_ACCESS_public;
5647 new_field->accessibility = DW_ACCESS_private;
5648 new_field->virtuality = DW_VIRTUALITY_none;
5650 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
5652 new_field->accessibility = DW_UNSND (attr);
5653 if (new_field->accessibility != DW_ACCESS_public)
5654 fip->non_public_fields = 1;
5655 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
5657 new_field->virtuality = DW_UNSND (attr);
5659 fp = &new_field->field;
5661 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
5663 /* Data member other than a C++ static data member. */
5665 /* Get type of field. */
5666 fp->type = die_type (die, cu);
5668 SET_FIELD_BITPOS (*fp, 0);
5670 /* Get bit size of field (zero if none). */
5671 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
5674 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
5678 FIELD_BITSIZE (*fp) = 0;
5681 /* Get bit offset of field. */
5682 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
5685 int byte_offset = 0;
5687 if (attr_form_is_section_offset (attr))
5688 dwarf2_complex_location_expr_complaint ();
5689 else if (attr_form_is_constant (attr))
5690 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5691 else if (attr_form_is_block (attr))
5692 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5694 dwarf2_complex_location_expr_complaint ();
5696 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
5698 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
5701 if (gdbarch_bits_big_endian (gdbarch))
5703 /* For big endian bits, the DW_AT_bit_offset gives the
5704 additional bit offset from the MSB of the containing
5705 anonymous object to the MSB of the field. We don't
5706 have to do anything special since we don't need to
5707 know the size of the anonymous object. */
5708 FIELD_BITPOS (*fp) += DW_UNSND (attr);
5712 /* For little endian bits, compute the bit offset to the
5713 MSB of the anonymous object, subtract off the number of
5714 bits from the MSB of the field to the MSB of the
5715 object, and then subtract off the number of bits of
5716 the field itself. The result is the bit offset of
5717 the LSB of the field. */
5719 int bit_offset = DW_UNSND (attr);
5721 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5724 /* The size of the anonymous object containing
5725 the bit field is explicit, so use the
5726 indicated size (in bytes). */
5727 anonymous_size = DW_UNSND (attr);
5731 /* The size of the anonymous object containing
5732 the bit field must be inferred from the type
5733 attribute of the data member containing the
5735 anonymous_size = TYPE_LENGTH (fp->type);
5737 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
5738 - bit_offset - FIELD_BITSIZE (*fp);
5742 /* Get name of field. */
5743 fieldname = dwarf2_name (die, cu);
5744 if (fieldname == NULL)
5747 /* The name is already allocated along with this objfile, so we don't
5748 need to duplicate it for the type. */
5749 fp->name = fieldname;
5751 /* Change accessibility for artificial fields (e.g. virtual table
5752 pointer or virtual base class pointer) to private. */
5753 if (dwarf2_attr (die, DW_AT_artificial, cu))
5755 FIELD_ARTIFICIAL (*fp) = 1;
5756 new_field->accessibility = DW_ACCESS_private;
5757 fip->non_public_fields = 1;
5760 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
5762 /* C++ static member. */
5764 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
5765 is a declaration, but all versions of G++ as of this writing
5766 (so through at least 3.2.1) incorrectly generate
5767 DW_TAG_variable tags. */
5771 /* Get name of field. */
5772 fieldname = dwarf2_name (die, cu);
5773 if (fieldname == NULL)
5776 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5778 /* Only create a symbol if this is an external value.
5779 new_symbol checks this and puts the value in the global symbol
5780 table, which we want. If it is not external, new_symbol
5781 will try to put the value in cu->list_in_scope which is wrong. */
5782 && dwarf2_flag_true_p (die, DW_AT_external, cu))
5784 /* A static const member, not much different than an enum as far as
5785 we're concerned, except that we can support more types. */
5786 new_symbol (die, NULL, cu);
5789 /* Get physical name. */
5790 physname = (char *) dwarf2_physname (fieldname, die, cu);
5792 /* The name is already allocated along with this objfile, so we don't
5793 need to duplicate it for the type. */
5794 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
5795 FIELD_TYPE (*fp) = die_type (die, cu);
5796 FIELD_NAME (*fp) = fieldname;
5798 else if (die->tag == DW_TAG_inheritance)
5800 /* C++ base class field. */
5801 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
5804 int byte_offset = 0;
5806 if (attr_form_is_section_offset (attr))
5807 dwarf2_complex_location_expr_complaint ();
5808 else if (attr_form_is_constant (attr))
5809 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5810 else if (attr_form_is_block (attr))
5811 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5813 dwarf2_complex_location_expr_complaint ();
5815 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
5817 FIELD_BITSIZE (*fp) = 0;
5818 FIELD_TYPE (*fp) = die_type (die, cu);
5819 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
5820 fip->nbaseclasses++;
5824 /* Add a typedef defined in the scope of the FIP's class. */
5827 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
5828 struct dwarf2_cu *cu)
5830 struct objfile *objfile = cu->objfile;
5831 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5832 struct typedef_field_list *new_field;
5833 struct attribute *attr;
5834 struct typedef_field *fp;
5835 char *fieldname = "";
5837 /* Allocate a new field list entry and link it in. */
5838 new_field = xzalloc (sizeof (*new_field));
5839 make_cleanup (xfree, new_field);
5841 gdb_assert (die->tag == DW_TAG_typedef);
5843 fp = &new_field->field;
5845 /* Get name of field. */
5846 fp->name = dwarf2_name (die, cu);
5847 if (fp->name == NULL)
5850 fp->type = read_type_die (die, cu);
5852 new_field->next = fip->typedef_field_list;
5853 fip->typedef_field_list = new_field;
5854 fip->typedef_field_list_count++;
5857 /* Create the vector of fields, and attach it to the type. */
5860 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
5861 struct dwarf2_cu *cu)
5863 int nfields = fip->nfields;
5865 /* Record the field count, allocate space for the array of fields,
5866 and create blank accessibility bitfields if necessary. */
5867 TYPE_NFIELDS (type) = nfields;
5868 TYPE_FIELDS (type) = (struct field *)
5869 TYPE_ALLOC (type, sizeof (struct field) * nfields);
5870 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
5872 if (fip->non_public_fields && cu->language != language_ada)
5874 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5876 TYPE_FIELD_PRIVATE_BITS (type) =
5877 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5878 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
5880 TYPE_FIELD_PROTECTED_BITS (type) =
5881 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5882 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
5884 TYPE_FIELD_IGNORE_BITS (type) =
5885 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
5886 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
5889 /* If the type has baseclasses, allocate and clear a bit vector for
5890 TYPE_FIELD_VIRTUAL_BITS. */
5891 if (fip->nbaseclasses && cu->language != language_ada)
5893 int num_bytes = B_BYTES (fip->nbaseclasses);
5894 unsigned char *pointer;
5896 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5897 pointer = TYPE_ALLOC (type, num_bytes);
5898 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
5899 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
5900 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
5903 /* Copy the saved-up fields into the field vector. Start from the head
5904 of the list, adding to the tail of the field array, so that they end
5905 up in the same order in the array in which they were added to the list. */
5906 while (nfields-- > 0)
5908 struct nextfield *fieldp;
5912 fieldp = fip->fields;
5913 fip->fields = fieldp->next;
5917 fieldp = fip->baseclasses;
5918 fip->baseclasses = fieldp->next;
5921 TYPE_FIELD (type, nfields) = fieldp->field;
5922 switch (fieldp->accessibility)
5924 case DW_ACCESS_private:
5925 if (cu->language != language_ada)
5926 SET_TYPE_FIELD_PRIVATE (type, nfields);
5929 case DW_ACCESS_protected:
5930 if (cu->language != language_ada)
5931 SET_TYPE_FIELD_PROTECTED (type, nfields);
5934 case DW_ACCESS_public:
5938 /* Unknown accessibility. Complain and treat it as public. */
5940 complaint (&symfile_complaints, _("unsupported accessibility %d"),
5941 fieldp->accessibility);
5945 if (nfields < fip->nbaseclasses)
5947 switch (fieldp->virtuality)
5949 case DW_VIRTUALITY_virtual:
5950 case DW_VIRTUALITY_pure_virtual:
5951 if (cu->language == language_ada)
5952 error ("unexpected virtuality in component of Ada type");
5953 SET_TYPE_FIELD_VIRTUAL (type, nfields);
5960 /* Add a member function to the proper fieldlist. */
5963 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
5964 struct type *type, struct dwarf2_cu *cu)
5966 struct objfile *objfile = cu->objfile;
5967 struct attribute *attr;
5968 struct fnfieldlist *flp;
5970 struct fn_field *fnp;
5973 struct nextfnfield *new_fnfield;
5974 struct type *this_type;
5976 if (cu->language == language_ada)
5977 error ("unexpected member function in Ada type");
5979 /* Get name of member function. */
5980 fieldname = dwarf2_name (die, cu);
5981 if (fieldname == NULL)
5984 /* Get the mangled name. */
5985 physname = (char *) dwarf2_physname (fieldname, die, cu);
5987 /* Look up member function name in fieldlist. */
5988 for (i = 0; i < fip->nfnfields; i++)
5990 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
5994 /* Create new list element if necessary. */
5995 if (i < fip->nfnfields)
5996 flp = &fip->fnfieldlists[i];
5999 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6001 fip->fnfieldlists = (struct fnfieldlist *)
6002 xrealloc (fip->fnfieldlists,
6003 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6004 * sizeof (struct fnfieldlist));
6005 if (fip->nfnfields == 0)
6006 make_cleanup (free_current_contents, &fip->fnfieldlists);
6008 flp = &fip->fnfieldlists[fip->nfnfields];
6009 flp->name = fieldname;
6015 /* Create a new member function field and chain it to the field list
6017 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6018 make_cleanup (xfree, new_fnfield);
6019 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6020 new_fnfield->next = flp->head;
6021 flp->head = new_fnfield;
6024 /* Fill in the member function field info. */
6025 fnp = &new_fnfield->fnfield;
6026 /* The name is already allocated along with this objfile, so we don't
6027 need to duplicate it for the type. */
6028 fnp->physname = physname ? physname : "";
6029 fnp->type = alloc_type (objfile);
6030 this_type = read_type_die (die, cu);
6031 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6033 int nparams = TYPE_NFIELDS (this_type);
6035 /* TYPE is the domain of this method, and THIS_TYPE is the type
6036 of the method itself (TYPE_CODE_METHOD). */
6037 smash_to_method_type (fnp->type, type,
6038 TYPE_TARGET_TYPE (this_type),
6039 TYPE_FIELDS (this_type),
6040 TYPE_NFIELDS (this_type),
6041 TYPE_VARARGS (this_type));
6043 /* Handle static member functions.
6044 Dwarf2 has no clean way to discern C++ static and non-static
6045 member functions. G++ helps GDB by marking the first
6046 parameter for non-static member functions (which is the
6047 this pointer) as artificial. We obtain this information
6048 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6049 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6050 fnp->voffset = VOFFSET_STATIC;
6053 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6056 /* Get fcontext from DW_AT_containing_type if present. */
6057 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6058 fnp->fcontext = die_containing_type (die, cu);
6060 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6061 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6063 /* Get accessibility. */
6064 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6067 switch (DW_UNSND (attr))
6069 case DW_ACCESS_private:
6070 fnp->is_private = 1;
6072 case DW_ACCESS_protected:
6073 fnp->is_protected = 1;
6078 /* Check for artificial methods. */
6079 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6080 if (attr && DW_UNSND (attr) != 0)
6081 fnp->is_artificial = 1;
6083 /* Get index in virtual function table if it is a virtual member
6084 function. For older versions of GCC, this is an offset in the
6085 appropriate virtual table, as specified by DW_AT_containing_type.
6086 For everyone else, it is an expression to be evaluated relative
6087 to the object address. */
6089 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6092 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6094 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6096 /* Old-style GCC. */
6097 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6099 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6100 || (DW_BLOCK (attr)->size > 1
6101 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6102 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6104 struct dwarf_block blk;
6107 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6109 blk.size = DW_BLOCK (attr)->size - offset;
6110 blk.data = DW_BLOCK (attr)->data + offset;
6111 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6112 if ((fnp->voffset % cu->header.addr_size) != 0)
6113 dwarf2_complex_location_expr_complaint ();
6115 fnp->voffset /= cu->header.addr_size;
6119 dwarf2_complex_location_expr_complaint ();
6122 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6124 else if (attr_form_is_section_offset (attr))
6126 dwarf2_complex_location_expr_complaint ();
6130 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6136 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6137 if (attr && DW_UNSND (attr))
6139 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6140 complaint (&symfile_complaints,
6141 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6142 fieldname, die->offset);
6143 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6144 TYPE_CPLUS_DYNAMIC (type) = 1;
6149 /* Create the vector of member function fields, and attach it to the type. */
6152 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6153 struct dwarf2_cu *cu)
6155 struct fnfieldlist *flp;
6156 int total_length = 0;
6159 if (cu->language == language_ada)
6160 error ("unexpected member functions in Ada type");
6162 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6163 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6164 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6166 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6168 struct nextfnfield *nfp = flp->head;
6169 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6172 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6173 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6174 fn_flp->fn_fields = (struct fn_field *)
6175 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6176 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6177 fn_flp->fn_fields[k] = nfp->fnfield;
6179 total_length += flp->length;
6182 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6183 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6186 /* Returns non-zero if NAME is the name of a vtable member in CU's
6187 language, zero otherwise. */
6189 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6191 static const char vptr[] = "_vptr";
6192 static const char vtable[] = "vtable";
6194 /* Look for the C++ and Java forms of the vtable. */
6195 if ((cu->language == language_java
6196 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6197 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
6198 && is_cplus_marker (name[sizeof (vptr) - 1])))
6204 /* GCC outputs unnamed structures that are really pointers to member
6205 functions, with the ABI-specified layout. If TYPE describes
6206 such a structure, smash it into a member function type.
6208 GCC shouldn't do this; it should just output pointer to member DIEs.
6209 This is GCC PR debug/28767. */
6212 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
6214 struct type *pfn_type, *domain_type, *new_type;
6216 /* Check for a structure with no name and two children. */
6217 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
6220 /* Check for __pfn and __delta members. */
6221 if (TYPE_FIELD_NAME (type, 0) == NULL
6222 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
6223 || TYPE_FIELD_NAME (type, 1) == NULL
6224 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
6227 /* Find the type of the method. */
6228 pfn_type = TYPE_FIELD_TYPE (type, 0);
6229 if (pfn_type == NULL
6230 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
6231 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
6234 /* Look for the "this" argument. */
6235 pfn_type = TYPE_TARGET_TYPE (pfn_type);
6236 if (TYPE_NFIELDS (pfn_type) == 0
6237 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6238 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
6241 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6242 new_type = alloc_type (objfile);
6243 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6244 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6245 TYPE_VARARGS (pfn_type));
6246 smash_to_methodptr_type (type, new_type);
6249 /* Called when we find the DIE that starts a structure or union scope
6250 (definition) to process all dies that define the members of the
6253 NOTE: we need to call struct_type regardless of whether or not the
6254 DIE has an at_name attribute, since it might be an anonymous
6255 structure or union. This gets the type entered into our set of
6258 However, if the structure is incomplete (an opaque struct/union)
6259 then suppress creating a symbol table entry for it since gdb only
6260 wants to find the one with the complete definition. Note that if
6261 it is complete, we just call new_symbol, which does it's own
6262 checking about whether the struct/union is anonymous or not (and
6263 suppresses creating a symbol table entry itself). */
6265 static struct type *
6266 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6268 struct objfile *objfile = cu->objfile;
6270 struct attribute *attr;
6272 struct cleanup *back_to;
6274 /* If the definition of this type lives in .debug_types, read that type.
6275 Don't follow DW_AT_specification though, that will take us back up
6276 the chain and we want to go down. */
6277 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6280 struct dwarf2_cu *type_cu = cu;
6281 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6283 /* We could just recurse on read_structure_type, but we need to call
6284 get_die_type to ensure only one type for this DIE is created.
6285 This is important, for example, because for c++ classes we need
6286 TYPE_NAME set which is only done by new_symbol. Blech. */
6287 type = read_type_die (type_die, type_cu);
6288 return set_die_type (die, type, cu);
6291 back_to = make_cleanup (null_cleanup, 0);
6293 type = alloc_type (objfile);
6294 INIT_CPLUS_SPECIFIC (type);
6296 name = dwarf2_name (die, cu);
6299 if (cu->language == language_cplus
6300 || cu->language == language_java)
6302 TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu);
6303 if (die->tag == DW_TAG_structure_type
6304 || die->tag == DW_TAG_class_type)
6305 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6309 /* The name is already allocated along with this objfile, so
6310 we don't need to duplicate it for the type. */
6311 TYPE_TAG_NAME (type) = (char *) name;
6312 if (die->tag == DW_TAG_class_type)
6313 TYPE_NAME (type) = TYPE_TAG_NAME (type);
6317 if (die->tag == DW_TAG_structure_type)
6319 TYPE_CODE (type) = TYPE_CODE_STRUCT;
6321 else if (die->tag == DW_TAG_union_type)
6323 TYPE_CODE (type) = TYPE_CODE_UNION;
6327 TYPE_CODE (type) = TYPE_CODE_CLASS;
6330 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
6331 TYPE_DECLARED_CLASS (type) = 1;
6333 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6336 TYPE_LENGTH (type) = DW_UNSND (attr);
6340 TYPE_LENGTH (type) = 0;
6343 TYPE_STUB_SUPPORTED (type) = 1;
6344 if (die_is_declaration (die, cu))
6345 TYPE_STUB (type) = 1;
6346 else if (attr == NULL && die->child == NULL
6347 && producer_is_realview (cu->producer))
6348 /* RealView does not output the required DW_AT_declaration
6349 on incomplete types. */
6350 TYPE_STUB (type) = 1;
6352 /* We need to add the type field to the die immediately so we don't
6353 infinitely recurse when dealing with pointers to the structure
6354 type within the structure itself. */
6355 set_die_type (die, type, cu);
6357 /* set_die_type should be already done. */
6358 set_descriptive_type (type, die, cu);
6360 if (die->child != NULL && ! die_is_declaration (die, cu))
6362 struct field_info fi;
6363 struct die_info *child_die;
6365 memset (&fi, 0, sizeof (struct field_info));
6367 child_die = die->child;
6369 while (child_die && child_die->tag)
6371 if (child_die->tag == DW_TAG_member
6372 || child_die->tag == DW_TAG_variable)
6374 /* NOTE: carlton/2002-11-05: A C++ static data member
6375 should be a DW_TAG_member that is a declaration, but
6376 all versions of G++ as of this writing (so through at
6377 least 3.2.1) incorrectly generate DW_TAG_variable
6378 tags for them instead. */
6379 dwarf2_add_field (&fi, child_die, cu);
6381 else if (child_die->tag == DW_TAG_subprogram)
6383 /* C++ member function. */
6384 dwarf2_add_member_fn (&fi, child_die, type, cu);
6386 else if (child_die->tag == DW_TAG_inheritance)
6388 /* C++ base class field. */
6389 dwarf2_add_field (&fi, child_die, cu);
6391 else if (child_die->tag == DW_TAG_typedef)
6392 dwarf2_add_typedef (&fi, child_die, cu);
6393 child_die = sibling_die (child_die);
6396 /* Attach fields and member functions to the type. */
6398 dwarf2_attach_fields_to_type (&fi, type, cu);
6401 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
6403 /* Get the type which refers to the base class (possibly this
6404 class itself) which contains the vtable pointer for the current
6405 class from the DW_AT_containing_type attribute. This use of
6406 DW_AT_containing_type is a GNU extension. */
6408 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6410 struct type *t = die_containing_type (die, cu);
6412 TYPE_VPTR_BASETYPE (type) = t;
6417 /* Our own class provides vtbl ptr. */
6418 for (i = TYPE_NFIELDS (t) - 1;
6419 i >= TYPE_N_BASECLASSES (t);
6422 char *fieldname = TYPE_FIELD_NAME (t, i);
6424 if (is_vtable_name (fieldname, cu))
6426 TYPE_VPTR_FIELDNO (type) = i;
6431 /* Complain if virtual function table field not found. */
6432 if (i < TYPE_N_BASECLASSES (t))
6433 complaint (&symfile_complaints,
6434 _("virtual function table pointer not found when defining class '%s'"),
6435 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
6440 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
6443 else if (cu->producer
6444 && strncmp (cu->producer,
6445 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6447 /* The IBM XLC compiler does not provide direct indication
6448 of the containing type, but the vtable pointer is
6449 always named __vfp. */
6453 for (i = TYPE_NFIELDS (type) - 1;
6454 i >= TYPE_N_BASECLASSES (type);
6457 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
6459 TYPE_VPTR_FIELDNO (type) = i;
6460 TYPE_VPTR_BASETYPE (type) = type;
6467 /* Copy fi.typedef_field_list linked list elements content into the
6468 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6469 if (fi.typedef_field_list)
6471 int i = fi.typedef_field_list_count;
6473 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6474 TYPE_TYPEDEF_FIELD_ARRAY (type)
6475 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
6476 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
6478 /* Reverse the list order to keep the debug info elements order. */
6481 struct typedef_field *dest, *src;
6483 dest = &TYPE_TYPEDEF_FIELD (type, i);
6484 src = &fi.typedef_field_list->field;
6485 fi.typedef_field_list = fi.typedef_field_list->next;
6491 quirk_gcc_member_function_pointer (type, cu->objfile);
6493 do_cleanups (back_to);
6498 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
6500 struct die_info *child_die = die->child;
6501 struct type *this_type;
6503 this_type = get_die_type (die, cu);
6504 if (this_type == NULL)
6505 this_type = read_structure_type (die, cu);
6507 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6508 snapshots) has been known to create a die giving a declaration
6509 for a class that has, as a child, a die giving a definition for a
6510 nested class. So we have to process our children even if the
6511 current die is a declaration. Normally, of course, a declaration
6512 won't have any children at all. */
6514 while (child_die != NULL && child_die->tag)
6516 if (child_die->tag == DW_TAG_member
6517 || child_die->tag == DW_TAG_variable
6518 || child_die->tag == DW_TAG_inheritance)
6523 process_die (child_die, cu);
6525 child_die = sibling_die (child_die);
6528 /* Do not consider external references. According to the DWARF standard,
6529 these DIEs are identified by the fact that they have no byte_size
6530 attribute, and a declaration attribute. */
6531 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
6532 || !die_is_declaration (die, cu))
6533 new_symbol (die, this_type, cu);
6536 /* Given a DW_AT_enumeration_type die, set its type. We do not
6537 complete the type's fields yet, or create any symbols. */
6539 static struct type *
6540 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6542 struct objfile *objfile = cu->objfile;
6544 struct attribute *attr;
6547 /* If the definition of this type lives in .debug_types, read that type.
6548 Don't follow DW_AT_specification though, that will take us back up
6549 the chain and we want to go down. */
6550 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6553 struct dwarf2_cu *type_cu = cu;
6554 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6556 type = read_type_die (type_die, type_cu);
6557 return set_die_type (die, type, cu);
6560 type = alloc_type (objfile);
6562 TYPE_CODE (type) = TYPE_CODE_ENUM;
6563 name = dwarf2_full_name (NULL, die, cu);
6565 TYPE_TAG_NAME (type) = (char *) name;
6567 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6570 TYPE_LENGTH (type) = DW_UNSND (attr);
6574 TYPE_LENGTH (type) = 0;
6577 /* The enumeration DIE can be incomplete. In Ada, any type can be
6578 declared as private in the package spec, and then defined only
6579 inside the package body. Such types are known as Taft Amendment
6580 Types. When another package uses such a type, an incomplete DIE
6581 may be generated by the compiler. */
6582 if (die_is_declaration (die, cu))
6583 TYPE_STUB (type) = 1;
6585 return set_die_type (die, type, cu);
6588 /* Given a pointer to a die which begins an enumeration, process all
6589 the dies that define the members of the enumeration, and create the
6590 symbol for the enumeration type.
6592 NOTE: We reverse the order of the element list. */
6595 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
6597 struct die_info *child_die;
6598 struct field *fields;
6601 int unsigned_enum = 1;
6603 struct type *this_type;
6607 this_type = get_die_type (die, cu);
6608 if (this_type == NULL)
6609 this_type = read_enumeration_type (die, cu);
6610 if (die->child != NULL)
6612 child_die = die->child;
6613 while (child_die && child_die->tag)
6615 if (child_die->tag != DW_TAG_enumerator)
6617 process_die (child_die, cu);
6621 name = dwarf2_name (child_die, cu);
6624 sym = new_symbol (child_die, this_type, cu);
6625 if (SYMBOL_VALUE (sym) < 0)
6628 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
6630 fields = (struct field *)
6632 (num_fields + DW_FIELD_ALLOC_CHUNK)
6633 * sizeof (struct field));
6636 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
6637 FIELD_TYPE (fields[num_fields]) = NULL;
6638 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
6639 FIELD_BITSIZE (fields[num_fields]) = 0;
6645 child_die = sibling_die (child_die);
6650 TYPE_NFIELDS (this_type) = num_fields;
6651 TYPE_FIELDS (this_type) = (struct field *)
6652 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
6653 memcpy (TYPE_FIELDS (this_type), fields,
6654 sizeof (struct field) * num_fields);
6658 TYPE_UNSIGNED (this_type) = 1;
6661 new_symbol (die, this_type, cu);
6664 /* Extract all information from a DW_TAG_array_type DIE and put it in
6665 the DIE's type field. For now, this only handles one dimensional
6668 static struct type *
6669 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6671 struct objfile *objfile = cu->objfile;
6672 struct die_info *child_die;
6674 struct type *element_type, *range_type, *index_type;
6675 struct type **range_types = NULL;
6676 struct attribute *attr;
6678 struct cleanup *back_to;
6681 element_type = die_type (die, cu);
6683 /* The die_type call above may have already set the type for this DIE. */
6684 type = get_die_type (die, cu);
6688 /* Irix 6.2 native cc creates array types without children for
6689 arrays with unspecified length. */
6690 if (die->child == NULL)
6692 index_type = objfile_type (objfile)->builtin_int;
6693 range_type = create_range_type (NULL, index_type, 0, -1);
6694 type = create_array_type (NULL, element_type, range_type);
6695 return set_die_type (die, type, cu);
6698 back_to = make_cleanup (null_cleanup, NULL);
6699 child_die = die->child;
6700 while (child_die && child_die->tag)
6702 if (child_die->tag == DW_TAG_subrange_type)
6704 struct type *child_type = read_type_die (child_die, cu);
6706 if (child_type != NULL)
6708 /* The range type was succesfully read. Save it for
6709 the array type creation. */
6710 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
6712 range_types = (struct type **)
6713 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
6714 * sizeof (struct type *));
6716 make_cleanup (free_current_contents, &range_types);
6718 range_types[ndim++] = child_type;
6721 child_die = sibling_die (child_die);
6724 /* Dwarf2 dimensions are output from left to right, create the
6725 necessary array types in backwards order. */
6727 type = element_type;
6729 if (read_array_order (die, cu) == DW_ORD_col_major)
6734 type = create_array_type (NULL, type, range_types[i++]);
6739 type = create_array_type (NULL, type, range_types[ndim]);
6742 /* Understand Dwarf2 support for vector types (like they occur on
6743 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6744 array type. This is not part of the Dwarf2/3 standard yet, but a
6745 custom vendor extension. The main difference between a regular
6746 array and the vector variant is that vectors are passed by value
6748 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
6750 make_vector_type (type);
6752 name = dwarf2_name (die, cu);
6754 TYPE_NAME (type) = name;
6756 /* Install the type in the die. */
6757 set_die_type (die, type, cu);
6759 /* set_die_type should be already done. */
6760 set_descriptive_type (type, die, cu);
6762 do_cleanups (back_to);
6767 static enum dwarf_array_dim_ordering
6768 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
6770 struct attribute *attr;
6772 attr = dwarf2_attr (die, DW_AT_ordering, cu);
6774 if (attr) return DW_SND (attr);
6777 GNU F77 is a special case, as at 08/2004 array type info is the
6778 opposite order to the dwarf2 specification, but data is still
6779 laid out as per normal fortran.
6781 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
6785 if (cu->language == language_fortran
6786 && cu->producer && strstr (cu->producer, "GNU F77"))
6788 return DW_ORD_row_major;
6791 switch (cu->language_defn->la_array_ordering)
6793 case array_column_major:
6794 return DW_ORD_col_major;
6795 case array_row_major:
6797 return DW_ORD_row_major;
6801 /* Extract all information from a DW_TAG_set_type DIE and put it in
6802 the DIE's type field. */
6804 static struct type *
6805 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
6807 struct type *domain_type, *set_type;
6808 struct attribute *attr;
6810 domain_type = die_type (die, cu);
6812 /* The die_type call above may have already set the type for this DIE. */
6813 set_type = get_die_type (die, cu);
6817 set_type = create_set_type (NULL, domain_type);
6819 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6821 TYPE_LENGTH (set_type) = DW_UNSND (attr);
6823 return set_die_type (die, set_type, cu);
6826 /* First cut: install each common block member as a global variable. */
6829 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6831 struct die_info *child_die;
6832 struct attribute *attr;
6834 CORE_ADDR base = (CORE_ADDR) 0;
6836 attr = dwarf2_attr (die, DW_AT_location, cu);
6839 /* Support the .debug_loc offsets */
6840 if (attr_form_is_block (attr))
6842 base = decode_locdesc (DW_BLOCK (attr), cu);
6844 else if (attr_form_is_section_offset (attr))
6846 dwarf2_complex_location_expr_complaint ();
6850 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6851 "common block member");
6854 if (die->child != NULL)
6856 child_die = die->child;
6857 while (child_die && child_die->tag)
6859 sym = new_symbol (child_die, NULL, cu);
6860 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
6863 CORE_ADDR byte_offset = 0;
6865 if (attr_form_is_section_offset (attr))
6866 dwarf2_complex_location_expr_complaint ();
6867 else if (attr_form_is_constant (attr))
6868 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6869 else if (attr_form_is_block (attr))
6870 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6872 dwarf2_complex_location_expr_complaint ();
6874 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
6875 add_symbol_to_list (sym, &global_symbols);
6877 child_die = sibling_die (child_die);
6882 /* Create a type for a C++ namespace. */
6884 static struct type *
6885 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
6887 struct objfile *objfile = cu->objfile;
6888 const char *previous_prefix, *name;
6892 /* For extensions, reuse the type of the original namespace. */
6893 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
6895 struct die_info *ext_die;
6896 struct dwarf2_cu *ext_cu = cu;
6898 ext_die = dwarf2_extension (die, &ext_cu);
6899 type = read_type_die (ext_die, ext_cu);
6900 return set_die_type (die, type, cu);
6903 name = namespace_name (die, &is_anonymous, cu);
6905 /* Now build the name of the current namespace. */
6907 previous_prefix = determine_prefix (die, cu);
6908 if (previous_prefix[0] != '\0')
6909 name = typename_concat (&objfile->objfile_obstack,
6910 previous_prefix, name, 0, cu);
6912 /* Create the type. */
6913 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
6915 TYPE_NAME (type) = (char *) name;
6916 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6918 return set_die_type (die, type, cu);
6921 /* Read a C++ namespace. */
6924 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6926 struct objfile *objfile = cu->objfile;
6930 /* Add a symbol associated to this if we haven't seen the namespace
6931 before. Also, add a using directive if it's an anonymous
6934 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
6938 type = read_type_die (die, cu);
6939 new_symbol (die, type, cu);
6941 name = namespace_name (die, &is_anonymous, cu);
6944 const char *previous_prefix = determine_prefix (die, cu);
6946 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
6947 NULL, &objfile->objfile_obstack);
6951 if (die->child != NULL)
6953 struct die_info *child_die = die->child;
6955 while (child_die && child_die->tag)
6957 process_die (child_die, cu);
6958 child_die = sibling_die (child_die);
6963 /* Read a Fortran module as type. This DIE can be only a declaration used for
6964 imported module. Still we need that type as local Fortran "use ... only"
6965 declaration imports depend on the created type in determine_prefix. */
6967 static struct type *
6968 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
6970 struct objfile *objfile = cu->objfile;
6974 module_name = dwarf2_name (die, cu);
6976 complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
6978 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
6980 /* determine_prefix uses TYPE_TAG_NAME. */
6981 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6983 return set_die_type (die, type, cu);
6986 /* Read a Fortran module. */
6989 read_module (struct die_info *die, struct dwarf2_cu *cu)
6991 struct die_info *child_die = die->child;
6993 while (child_die && child_die->tag)
6995 process_die (child_die, cu);
6996 child_die = sibling_die (child_die);
7000 /* Return the name of the namespace represented by DIE. Set
7001 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7005 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7007 struct die_info *current_die;
7008 const char *name = NULL;
7010 /* Loop through the extensions until we find a name. */
7012 for (current_die = die;
7013 current_die != NULL;
7014 current_die = dwarf2_extension (die, &cu))
7016 name = dwarf2_name (current_die, cu);
7021 /* Is it an anonymous namespace? */
7023 *is_anonymous = (name == NULL);
7025 name = "(anonymous namespace)";
7030 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7031 the user defined type vector. */
7033 static struct type *
7034 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7036 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7037 struct comp_unit_head *cu_header = &cu->header;
7039 struct attribute *attr_byte_size;
7040 struct attribute *attr_address_class;
7041 int byte_size, addr_class;
7042 struct type *target_type;
7044 target_type = die_type (die, cu);
7046 /* The die_type call above may have already set the type for this DIE. */
7047 type = get_die_type (die, cu);
7051 type = lookup_pointer_type (target_type);
7053 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7055 byte_size = DW_UNSND (attr_byte_size);
7057 byte_size = cu_header->addr_size;
7059 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7060 if (attr_address_class)
7061 addr_class = DW_UNSND (attr_address_class);
7063 addr_class = DW_ADDR_none;
7065 /* If the pointer size or address class is different than the
7066 default, create a type variant marked as such and set the
7067 length accordingly. */
7068 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7070 if (gdbarch_address_class_type_flags_p (gdbarch))
7074 type_flags = gdbarch_address_class_type_flags
7075 (gdbarch, byte_size, addr_class);
7076 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7078 type = make_type_with_address_space (type, type_flags);
7080 else if (TYPE_LENGTH (type) != byte_size)
7082 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
7086 /* Should we also complain about unhandled address classes? */
7090 TYPE_LENGTH (type) = byte_size;
7091 return set_die_type (die, type, cu);
7094 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7095 the user defined type vector. */
7097 static struct type *
7098 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7101 struct type *to_type;
7102 struct type *domain;
7104 to_type = die_type (die, cu);
7105 domain = die_containing_type (die, cu);
7107 /* The calls above may have already set the type for this DIE. */
7108 type = get_die_type (die, cu);
7112 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7113 type = lookup_methodptr_type (to_type);
7115 type = lookup_memberptr_type (to_type, domain);
7117 return set_die_type (die, type, cu);
7120 /* Extract all information from a DW_TAG_reference_type DIE and add to
7121 the user defined type vector. */
7123 static struct type *
7124 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7126 struct comp_unit_head *cu_header = &cu->header;
7127 struct type *type, *target_type;
7128 struct attribute *attr;
7130 target_type = die_type (die, cu);
7132 /* The die_type call above may have already set the type for this DIE. */
7133 type = get_die_type (die, cu);
7137 type = lookup_reference_type (target_type);
7138 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7141 TYPE_LENGTH (type) = DW_UNSND (attr);
7145 TYPE_LENGTH (type) = cu_header->addr_size;
7147 return set_die_type (die, type, cu);
7150 static struct type *
7151 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
7153 struct type *base_type, *cv_type;
7155 base_type = die_type (die, cu);
7157 /* The die_type call above may have already set the type for this DIE. */
7158 cv_type = get_die_type (die, cu);
7162 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
7163 return set_die_type (die, cv_type, cu);
7166 static struct type *
7167 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
7169 struct type *base_type, *cv_type;
7171 base_type = die_type (die, cu);
7173 /* The die_type call above may have already set the type for this DIE. */
7174 cv_type = get_die_type (die, cu);
7178 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
7179 return set_die_type (die, cv_type, cu);
7182 /* Extract all information from a DW_TAG_string_type DIE and add to
7183 the user defined type vector. It isn't really a user defined type,
7184 but it behaves like one, with other DIE's using an AT_user_def_type
7185 attribute to reference it. */
7187 static struct type *
7188 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
7190 struct objfile *objfile = cu->objfile;
7191 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7192 struct type *type, *range_type, *index_type, *char_type;
7193 struct attribute *attr;
7194 unsigned int length;
7196 attr = dwarf2_attr (die, DW_AT_string_length, cu);
7199 length = DW_UNSND (attr);
7203 /* check for the DW_AT_byte_size attribute */
7204 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7207 length = DW_UNSND (attr);
7215 index_type = objfile_type (objfile)->builtin_int;
7216 range_type = create_range_type (NULL, index_type, 1, length);
7217 char_type = language_string_char_type (cu->language_defn, gdbarch);
7218 type = create_string_type (NULL, char_type, range_type);
7220 return set_die_type (die, type, cu);
7223 /* Handle DIES due to C code like:
7227 int (*funcp)(int a, long l);
7231 ('funcp' generates a DW_TAG_subroutine_type DIE)
7234 static struct type *
7235 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
7237 struct type *type; /* Type that this function returns */
7238 struct type *ftype; /* Function that returns above type */
7239 struct attribute *attr;
7241 type = die_type (die, cu);
7243 /* The die_type call above may have already set the type for this DIE. */
7244 ftype = get_die_type (die, cu);
7248 ftype = lookup_function_type (type);
7250 /* All functions in C++, Pascal and Java have prototypes. */
7251 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
7252 if ((attr && (DW_UNSND (attr) != 0))
7253 || cu->language == language_cplus
7254 || cu->language == language_java
7255 || cu->language == language_pascal)
7256 TYPE_PROTOTYPED (ftype) = 1;
7257 else if (producer_is_realview (cu->producer))
7258 /* RealView does not emit DW_AT_prototyped. We can not
7259 distinguish prototyped and unprototyped functions; default to
7260 prototyped, since that is more common in modern code (and
7261 RealView warns about unprototyped functions). */
7262 TYPE_PROTOTYPED (ftype) = 1;
7264 /* Store the calling convention in the type if it's available in
7265 the subroutine die. Otherwise set the calling convention to
7266 the default value DW_CC_normal. */
7267 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
7268 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
7270 /* We need to add the subroutine type to the die immediately so
7271 we don't infinitely recurse when dealing with parameters
7272 declared as the same subroutine type. */
7273 set_die_type (die, ftype, cu);
7275 if (die->child != NULL)
7277 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
7278 struct die_info *child_die;
7279 int nparams, iparams;
7281 /* Count the number of parameters.
7282 FIXME: GDB currently ignores vararg functions, but knows about
7283 vararg member functions. */
7285 child_die = die->child;
7286 while (child_die && child_die->tag)
7288 if (child_die->tag == DW_TAG_formal_parameter)
7290 else if (child_die->tag == DW_TAG_unspecified_parameters)
7291 TYPE_VARARGS (ftype) = 1;
7292 child_die = sibling_die (child_die);
7295 /* Allocate storage for parameters and fill them in. */
7296 TYPE_NFIELDS (ftype) = nparams;
7297 TYPE_FIELDS (ftype) = (struct field *)
7298 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
7300 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7301 even if we error out during the parameters reading below. */
7302 for (iparams = 0; iparams < nparams; iparams++)
7303 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
7306 child_die = die->child;
7307 while (child_die && child_die->tag)
7309 if (child_die->tag == DW_TAG_formal_parameter)
7311 /* Dwarf2 has no clean way to discern C++ static and non-static
7312 member functions. G++ helps GDB by marking the first
7313 parameter for non-static member functions (which is the
7314 this pointer) as artificial. We pass this information
7315 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
7316 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
7318 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
7321 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
7323 /* GCC/43521: In java, the formal parameter
7324 "this" is sometimes not marked with DW_AT_artificial. */
7325 if (cu->language == language_java)
7327 const char *name = dwarf2_name (child_die, cu);
7329 if (name && !strcmp (name, "this"))
7330 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
7333 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
7336 child_die = sibling_die (child_die);
7343 static struct type *
7344 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
7346 struct objfile *objfile = cu->objfile;
7347 const char *name = NULL;
7348 struct type *this_type;
7350 name = dwarf2_full_name (NULL, die, cu);
7351 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
7352 TYPE_FLAG_TARGET_STUB, NULL, objfile);
7353 TYPE_NAME (this_type) = (char *) name;
7354 set_die_type (die, this_type, cu);
7355 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
7359 /* Find a representation of a given base type and install
7360 it in the TYPE field of the die. */
7362 static struct type *
7363 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
7365 struct objfile *objfile = cu->objfile;
7367 struct attribute *attr;
7368 int encoding = 0, size = 0;
7370 enum type_code code = TYPE_CODE_INT;
7372 struct type *target_type = NULL;
7374 attr = dwarf2_attr (die, DW_AT_encoding, cu);
7377 encoding = DW_UNSND (attr);
7379 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7382 size = DW_UNSND (attr);
7384 name = dwarf2_name (die, cu);
7387 complaint (&symfile_complaints,
7388 _("DW_AT_name missing from DW_TAG_base_type"));
7393 case DW_ATE_address:
7394 /* Turn DW_ATE_address into a void * pointer. */
7395 code = TYPE_CODE_PTR;
7396 type_flags |= TYPE_FLAG_UNSIGNED;
7397 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
7399 case DW_ATE_boolean:
7400 code = TYPE_CODE_BOOL;
7401 type_flags |= TYPE_FLAG_UNSIGNED;
7403 case DW_ATE_complex_float:
7404 code = TYPE_CODE_COMPLEX;
7405 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
7407 case DW_ATE_decimal_float:
7408 code = TYPE_CODE_DECFLOAT;
7411 code = TYPE_CODE_FLT;
7415 case DW_ATE_unsigned:
7416 type_flags |= TYPE_FLAG_UNSIGNED;
7418 case DW_ATE_signed_char:
7419 if (cu->language == language_ada || cu->language == language_m2
7420 || cu->language == language_pascal)
7421 code = TYPE_CODE_CHAR;
7423 case DW_ATE_unsigned_char:
7424 if (cu->language == language_ada || cu->language == language_m2
7425 || cu->language == language_pascal)
7426 code = TYPE_CODE_CHAR;
7427 type_flags |= TYPE_FLAG_UNSIGNED;
7430 /* We just treat this as an integer and then recognize the
7431 type by name elsewhere. */
7435 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
7436 dwarf_type_encoding_name (encoding));
7440 type = init_type (code, size, type_flags, NULL, objfile);
7441 TYPE_NAME (type) = name;
7442 TYPE_TARGET_TYPE (type) = target_type;
7444 if (name && strcmp (name, "char") == 0)
7445 TYPE_NOSIGN (type) = 1;
7447 return set_die_type (die, type, cu);
7450 /* Read the given DW_AT_subrange DIE. */
7452 static struct type *
7453 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
7455 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7456 struct type *base_type;
7457 struct type *range_type;
7458 struct attribute *attr;
7462 LONGEST negative_mask;
7464 base_type = die_type (die, cu);
7465 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7466 check_typedef (base_type);
7468 /* The die_type call above may have already set the type for this DIE. */
7469 range_type = get_die_type (die, cu);
7473 if (cu->language == language_fortran)
7475 /* FORTRAN implies a lower bound of 1, if not given. */
7479 /* FIXME: For variable sized arrays either of these could be
7480 a variable rather than a constant value. We'll allow it,
7481 but we don't know how to handle it. */
7482 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
7484 low = dwarf2_get_attr_constant_value (attr, 0);
7486 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
7489 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
7491 /* GCC encodes arrays with unspecified or dynamic length
7492 with a DW_FORM_block1 attribute or a reference attribute.
7493 FIXME: GDB does not yet know how to handle dynamic
7494 arrays properly, treat them as arrays with unspecified
7497 FIXME: jimb/2003-09-22: GDB does not really know
7498 how to handle arrays of unspecified length
7499 either; we just represent them as zero-length
7500 arrays. Choose an appropriate upper bound given
7501 the lower bound we've computed above. */
7505 high = dwarf2_get_attr_constant_value (attr, 1);
7509 attr = dwarf2_attr (die, DW_AT_count, cu);
7512 int count = dwarf2_get_attr_constant_value (attr, 1);
7513 high = low + count - 1;
7517 /* Dwarf-2 specifications explicitly allows to create subrange types
7518 without specifying a base type.
7519 In that case, the base type must be set to the type of
7520 the lower bound, upper bound or count, in that order, if any of these
7521 three attributes references an object that has a type.
7522 If no base type is found, the Dwarf-2 specifications say that
7523 a signed integer type of size equal to the size of an address should
7525 For the following C code: `extern char gdb_int [];'
7526 GCC produces an empty range DIE.
7527 FIXME: muller/2010-05-28: Possible references to object for low bound,
7528 high bound or count are not yet handled by this code.
7530 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
7532 struct objfile *objfile = cu->objfile;
7533 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7534 int addr_size = gdbarch_addr_bit (gdbarch) /8;
7535 struct type *int_type = objfile_type (objfile)->builtin_int;
7537 /* Test "int", "long int", and "long long int" objfile types,
7538 and select the first one having a size above or equal to the
7539 architecture address size. */
7540 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7541 base_type = int_type;
7544 int_type = objfile_type (objfile)->builtin_long;
7545 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7546 base_type = int_type;
7549 int_type = objfile_type (objfile)->builtin_long_long;
7550 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
7551 base_type = int_type;
7557 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
7558 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
7559 low |= negative_mask;
7560 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
7561 high |= negative_mask;
7563 range_type = create_range_type (NULL, base_type, low, high);
7565 /* Mark arrays with dynamic length at least as an array of unspecified
7566 length. GDB could check the boundary but before it gets implemented at
7567 least allow accessing the array elements. */
7568 if (attr && attr->form == DW_FORM_block1)
7569 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
7571 name = dwarf2_name (die, cu);
7573 TYPE_NAME (range_type) = name;
7575 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7577 TYPE_LENGTH (range_type) = DW_UNSND (attr);
7579 set_die_type (die, range_type, cu);
7581 /* set_die_type should be already done. */
7582 set_descriptive_type (range_type, die, cu);
7587 static struct type *
7588 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
7592 /* For now, we only support the C meaning of an unspecified type: void. */
7594 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
7595 TYPE_NAME (type) = dwarf2_name (die, cu);
7597 return set_die_type (die, type, cu);
7600 /* Trivial hash function for die_info: the hash value of a DIE
7601 is its offset in .debug_info for this objfile. */
7604 die_hash (const void *item)
7606 const struct die_info *die = item;
7611 /* Trivial comparison function for die_info structures: two DIEs
7612 are equal if they have the same offset. */
7615 die_eq (const void *item_lhs, const void *item_rhs)
7617 const struct die_info *die_lhs = item_lhs;
7618 const struct die_info *die_rhs = item_rhs;
7620 return die_lhs->offset == die_rhs->offset;
7623 /* Read a whole compilation unit into a linked list of dies. */
7625 static struct die_info *
7626 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
7628 struct die_reader_specs reader_specs;
7630 gdb_assert (cu->die_hash == NULL);
7632 = htab_create_alloc_ex (cu->header.length / 12,
7636 &cu->comp_unit_obstack,
7637 hashtab_obstack_allocate,
7638 dummy_obstack_deallocate);
7640 init_cu_die_reader (&reader_specs, cu);
7642 return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
7645 /* Main entry point for reading a DIE and all children.
7646 Read the DIE and dump it if requested. */
7648 static struct die_info *
7649 read_die_and_children (const struct die_reader_specs *reader,
7651 gdb_byte **new_info_ptr,
7652 struct die_info *parent)
7654 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
7655 new_info_ptr, parent);
7657 if (dwarf2_die_debug)
7659 fprintf_unfiltered (gdb_stdlog,
7660 "\nRead die from %s of %s:\n",
7661 reader->buffer == dwarf2_per_objfile->info.buffer
7663 : reader->buffer == dwarf2_per_objfile->types.buffer
7665 : "unknown section",
7666 reader->abfd->filename);
7667 dump_die (result, dwarf2_die_debug);
7673 /* Read a single die and all its descendents. Set the die's sibling
7674 field to NULL; set other fields in the die correctly, and set all
7675 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
7676 location of the info_ptr after reading all of those dies. PARENT
7677 is the parent of the die in question. */
7679 static struct die_info *
7680 read_die_and_children_1 (const struct die_reader_specs *reader,
7682 gdb_byte **new_info_ptr,
7683 struct die_info *parent)
7685 struct die_info *die;
7689 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
7692 *new_info_ptr = cur_ptr;
7695 store_in_ref_table (die, reader->cu);
7698 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
7702 *new_info_ptr = cur_ptr;
7705 die->sibling = NULL;
7706 die->parent = parent;
7710 /* Read a die, all of its descendents, and all of its siblings; set
7711 all of the fields of all of the dies correctly. Arguments are as
7712 in read_die_and_children. */
7714 static struct die_info *
7715 read_die_and_siblings (const struct die_reader_specs *reader,
7717 gdb_byte **new_info_ptr,
7718 struct die_info *parent)
7720 struct die_info *first_die, *last_sibling;
7724 first_die = last_sibling = NULL;
7728 struct die_info *die
7729 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
7733 *new_info_ptr = cur_ptr;
7740 last_sibling->sibling = die;
7746 /* Read the die from the .debug_info section buffer. Set DIEP to
7747 point to a newly allocated die with its information, except for its
7748 child, sibling, and parent fields. Set HAS_CHILDREN to tell
7749 whether the die has children or not. */
7752 read_full_die (const struct die_reader_specs *reader,
7753 struct die_info **diep, gdb_byte *info_ptr,
7756 unsigned int abbrev_number, bytes_read, i, offset;
7757 struct abbrev_info *abbrev;
7758 struct die_info *die;
7759 struct dwarf2_cu *cu = reader->cu;
7760 bfd *abfd = reader->abfd;
7762 offset = info_ptr - reader->buffer;
7763 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7764 info_ptr += bytes_read;
7772 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
7774 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
7776 bfd_get_filename (abfd));
7778 die = dwarf_alloc_die (cu, abbrev->num_attrs);
7779 die->offset = offset;
7780 die->tag = abbrev->tag;
7781 die->abbrev = abbrev_number;
7783 die->num_attrs = abbrev->num_attrs;
7785 for (i = 0; i < abbrev->num_attrs; ++i)
7786 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
7787 abfd, info_ptr, cu);
7790 *has_children = abbrev->has_children;
7794 /* In DWARF version 2, the description of the debugging information is
7795 stored in a separate .debug_abbrev section. Before we read any
7796 dies from a section we read in all abbreviations and install them
7797 in a hash table. This function also sets flags in CU describing
7798 the data found in the abbrev table. */
7801 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
7803 struct comp_unit_head *cu_header = &cu->header;
7804 gdb_byte *abbrev_ptr;
7805 struct abbrev_info *cur_abbrev;
7806 unsigned int abbrev_number, bytes_read, abbrev_name;
7807 unsigned int abbrev_form, hash_number;
7808 struct attr_abbrev *cur_attrs;
7809 unsigned int allocated_attrs;
7811 /* Initialize dwarf2 abbrevs */
7812 obstack_init (&cu->abbrev_obstack);
7813 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
7815 * sizeof (struct abbrev_info *)));
7816 memset (cu->dwarf2_abbrevs, 0,
7817 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
7819 dwarf2_read_section (dwarf2_per_objfile->objfile,
7820 &dwarf2_per_objfile->abbrev);
7821 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
7822 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7823 abbrev_ptr += bytes_read;
7825 allocated_attrs = ATTR_ALLOC_CHUNK;
7826 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
7828 /* loop until we reach an abbrev number of 0 */
7829 while (abbrev_number)
7831 cur_abbrev = dwarf_alloc_abbrev (cu);
7833 /* read in abbrev header */
7834 cur_abbrev->number = abbrev_number;
7835 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7836 abbrev_ptr += bytes_read;
7837 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
7840 if (cur_abbrev->tag == DW_TAG_namespace)
7841 cu->has_namespace_info = 1;
7843 /* now read in declarations */
7844 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7845 abbrev_ptr += bytes_read;
7846 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7847 abbrev_ptr += bytes_read;
7850 if (cur_abbrev->num_attrs == allocated_attrs)
7852 allocated_attrs += ATTR_ALLOC_CHUNK;
7854 = xrealloc (cur_attrs, (allocated_attrs
7855 * sizeof (struct attr_abbrev)));
7858 /* Record whether this compilation unit might have
7859 inter-compilation-unit references. If we don't know what form
7860 this attribute will have, then it might potentially be a
7861 DW_FORM_ref_addr, so we conservatively expect inter-CU
7864 if (abbrev_form == DW_FORM_ref_addr
7865 || abbrev_form == DW_FORM_indirect)
7866 cu->has_form_ref_addr = 1;
7868 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
7869 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
7870 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7871 abbrev_ptr += bytes_read;
7872 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7873 abbrev_ptr += bytes_read;
7876 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
7877 (cur_abbrev->num_attrs
7878 * sizeof (struct attr_abbrev)));
7879 memcpy (cur_abbrev->attrs, cur_attrs,
7880 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
7882 hash_number = abbrev_number % ABBREV_HASH_SIZE;
7883 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
7884 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
7886 /* Get next abbreviation.
7887 Under Irix6 the abbreviations for a compilation unit are not
7888 always properly terminated with an abbrev number of 0.
7889 Exit loop if we encounter an abbreviation which we have
7890 already read (which means we are about to read the abbreviations
7891 for the next compile unit) or if the end of the abbreviation
7892 table is reached. */
7893 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
7894 >= dwarf2_per_objfile->abbrev.size)
7896 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
7897 abbrev_ptr += bytes_read;
7898 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
7905 /* Release the memory used by the abbrev table for a compilation unit. */
7908 dwarf2_free_abbrev_table (void *ptr_to_cu)
7910 struct dwarf2_cu *cu = ptr_to_cu;
7912 obstack_free (&cu->abbrev_obstack, NULL);
7913 cu->dwarf2_abbrevs = NULL;
7916 /* Lookup an abbrev_info structure in the abbrev hash table. */
7918 static struct abbrev_info *
7919 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
7921 unsigned int hash_number;
7922 struct abbrev_info *abbrev;
7924 hash_number = number % ABBREV_HASH_SIZE;
7925 abbrev = cu->dwarf2_abbrevs[hash_number];
7929 if (abbrev->number == number)
7932 abbrev = abbrev->next;
7937 /* Returns nonzero if TAG represents a type that we might generate a partial
7941 is_type_tag_for_partial (int tag)
7946 /* Some types that would be reasonable to generate partial symbols for,
7947 that we don't at present. */
7948 case DW_TAG_array_type:
7949 case DW_TAG_file_type:
7950 case DW_TAG_ptr_to_member_type:
7951 case DW_TAG_set_type:
7952 case DW_TAG_string_type:
7953 case DW_TAG_subroutine_type:
7955 case DW_TAG_base_type:
7956 case DW_TAG_class_type:
7957 case DW_TAG_interface_type:
7958 case DW_TAG_enumeration_type:
7959 case DW_TAG_structure_type:
7960 case DW_TAG_subrange_type:
7961 case DW_TAG_typedef:
7962 case DW_TAG_union_type:
7969 /* Load all DIEs that are interesting for partial symbols into memory. */
7971 static struct partial_die_info *
7972 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
7973 int building_psymtab, struct dwarf2_cu *cu)
7975 struct partial_die_info *part_die;
7976 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
7977 struct abbrev_info *abbrev;
7978 unsigned int bytes_read;
7979 unsigned int load_all = 0;
7981 int nesting_level = 1;
7986 if (cu->per_cu && cu->per_cu->load_all_dies)
7990 = htab_create_alloc_ex (cu->header.length / 12,
7994 &cu->comp_unit_obstack,
7995 hashtab_obstack_allocate,
7996 dummy_obstack_deallocate);
7998 part_die = obstack_alloc (&cu->comp_unit_obstack,
7999 sizeof (struct partial_die_info));
8003 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8005 /* A NULL abbrev means the end of a series of children. */
8008 if (--nesting_level == 0)
8010 /* PART_DIE was probably the last thing allocated on the
8011 comp_unit_obstack, so we could call obstack_free
8012 here. We don't do that because the waste is small,
8013 and will be cleaned up when we're done with this
8014 compilation unit. This way, we're also more robust
8015 against other users of the comp_unit_obstack. */
8018 info_ptr += bytes_read;
8019 last_die = parent_die;
8020 parent_die = parent_die->die_parent;
8024 /* Check whether this DIE is interesting enough to save. Normally
8025 we would not be interested in members here, but there may be
8026 later variables referencing them via DW_AT_specification (for
8029 && !is_type_tag_for_partial (abbrev->tag)
8030 && abbrev->tag != DW_TAG_enumerator
8031 && abbrev->tag != DW_TAG_subprogram
8032 && abbrev->tag != DW_TAG_lexical_block
8033 && abbrev->tag != DW_TAG_variable
8034 && abbrev->tag != DW_TAG_namespace
8035 && abbrev->tag != DW_TAG_module
8036 && abbrev->tag != DW_TAG_member)
8038 /* Otherwise we skip to the next sibling, if any. */
8039 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8043 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
8044 buffer, info_ptr, cu);
8046 /* This two-pass algorithm for processing partial symbols has a
8047 high cost in cache pressure. Thus, handle some simple cases
8048 here which cover the majority of C partial symbols. DIEs
8049 which neither have specification tags in them, nor could have
8050 specification tags elsewhere pointing at them, can simply be
8051 processed and discarded.
8053 This segment is also optional; scan_partial_symbols and
8054 add_partial_symbol will handle these DIEs if we chain
8055 them in normally. When compilers which do not emit large
8056 quantities of duplicate debug information are more common,
8057 this code can probably be removed. */
8059 /* Any complete simple types at the top level (pretty much all
8060 of them, for a language without namespaces), can be processed
8062 if (parent_die == NULL
8063 && part_die->has_specification == 0
8064 && part_die->is_declaration == 0
8065 && (part_die->tag == DW_TAG_typedef
8066 || part_die->tag == DW_TAG_base_type
8067 || part_die->tag == DW_TAG_subrange_type))
8069 if (building_psymtab && part_die->name != NULL)
8070 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8071 VAR_DOMAIN, LOC_TYPEDEF,
8072 &cu->objfile->static_psymbols,
8073 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8074 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8078 /* If we're at the second level, and we're an enumerator, and
8079 our parent has no specification (meaning possibly lives in a
8080 namespace elsewhere), then we can add the partial symbol now
8081 instead of queueing it. */
8082 if (part_die->tag == DW_TAG_enumerator
8083 && parent_die != NULL
8084 && parent_die->die_parent == NULL
8085 && parent_die->tag == DW_TAG_enumeration_type
8086 && parent_die->has_specification == 0)
8088 if (part_die->name == NULL)
8089 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
8090 else if (building_psymtab)
8091 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8092 VAR_DOMAIN, LOC_CONST,
8093 (cu->language == language_cplus
8094 || cu->language == language_java)
8095 ? &cu->objfile->global_psymbols
8096 : &cu->objfile->static_psymbols,
8097 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8099 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8103 /* We'll save this DIE so link it in. */
8104 part_die->die_parent = parent_die;
8105 part_die->die_sibling = NULL;
8106 part_die->die_child = NULL;
8108 if (last_die && last_die == parent_die)
8109 last_die->die_child = part_die;
8111 last_die->die_sibling = part_die;
8113 last_die = part_die;
8115 if (first_die == NULL)
8116 first_die = part_die;
8118 /* Maybe add the DIE to the hash table. Not all DIEs that we
8119 find interesting need to be in the hash table, because we
8120 also have the parent/sibling/child chains; only those that we
8121 might refer to by offset later during partial symbol reading.
8123 For now this means things that might have be the target of a
8124 DW_AT_specification, DW_AT_abstract_origin, or
8125 DW_AT_extension. DW_AT_extension will refer only to
8126 namespaces; DW_AT_abstract_origin refers to functions (and
8127 many things under the function DIE, but we do not recurse
8128 into function DIEs during partial symbol reading) and
8129 possibly variables as well; DW_AT_specification refers to
8130 declarations. Declarations ought to have the DW_AT_declaration
8131 flag. It happens that GCC forgets to put it in sometimes, but
8132 only for functions, not for types.
8134 Adding more things than necessary to the hash table is harmless
8135 except for the performance cost. Adding too few will result in
8136 wasted time in find_partial_die, when we reread the compilation
8137 unit with load_all_dies set. */
8140 || abbrev->tag == DW_TAG_subprogram
8141 || abbrev->tag == DW_TAG_variable
8142 || abbrev->tag == DW_TAG_namespace
8143 || part_die->is_declaration)
8147 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
8148 part_die->offset, INSERT);
8152 part_die = obstack_alloc (&cu->comp_unit_obstack,
8153 sizeof (struct partial_die_info));
8155 /* For some DIEs we want to follow their children (if any). For C
8156 we have no reason to follow the children of structures; for other
8157 languages we have to, both so that we can get at method physnames
8158 to infer fully qualified class names, and for DW_AT_specification.
8160 For Ada, we need to scan the children of subprograms and lexical
8161 blocks as well because Ada allows the definition of nested
8162 entities that could be interesting for the debugger, such as
8163 nested subprograms for instance. */
8164 if (last_die->has_children
8166 || last_die->tag == DW_TAG_namespace
8167 || last_die->tag == DW_TAG_module
8168 || last_die->tag == DW_TAG_enumeration_type
8169 || (cu->language != language_c
8170 && (last_die->tag == DW_TAG_class_type
8171 || last_die->tag == DW_TAG_interface_type
8172 || last_die->tag == DW_TAG_structure_type
8173 || last_die->tag == DW_TAG_union_type))
8174 || (cu->language == language_ada
8175 && (last_die->tag == DW_TAG_subprogram
8176 || last_die->tag == DW_TAG_lexical_block))))
8179 parent_die = last_die;
8183 /* Otherwise we skip to the next sibling, if any. */
8184 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
8186 /* Back to the top, do it again. */
8190 /* Read a minimal amount of information into the minimal die structure. */
8193 read_partial_die (struct partial_die_info *part_die,
8194 struct abbrev_info *abbrev,
8195 unsigned int abbrev_len, bfd *abfd,
8196 gdb_byte *buffer, gdb_byte *info_ptr,
8197 struct dwarf2_cu *cu)
8200 struct attribute attr;
8201 int has_low_pc_attr = 0;
8202 int has_high_pc_attr = 0;
8204 memset (part_die, 0, sizeof (struct partial_die_info));
8206 part_die->offset = info_ptr - buffer;
8208 info_ptr += abbrev_len;
8213 part_die->tag = abbrev->tag;
8214 part_die->has_children = abbrev->has_children;
8216 for (i = 0; i < abbrev->num_attrs; ++i)
8218 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
8220 /* Store the data if it is of an attribute we want to keep in a
8221 partial symbol table. */
8225 switch (part_die->tag)
8227 case DW_TAG_compile_unit:
8228 case DW_TAG_type_unit:
8229 /* Compilation units have a DW_AT_name that is a filename, not
8230 a source language identifier. */
8231 case DW_TAG_enumeration_type:
8232 case DW_TAG_enumerator:
8233 /* These tags always have simple identifiers already; no need
8234 to canonicalize them. */
8235 part_die->name = DW_STRING (&attr);
8239 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
8240 &cu->objfile->objfile_obstack);
8244 case DW_AT_linkage_name:
8245 case DW_AT_MIPS_linkage_name:
8246 /* Note that both forms of linkage name might appear. We
8247 assume they will be the same, and we only store the last
8249 if (cu->language == language_ada)
8250 part_die->name = DW_STRING (&attr);
8253 has_low_pc_attr = 1;
8254 part_die->lowpc = DW_ADDR (&attr);
8257 has_high_pc_attr = 1;
8258 part_die->highpc = DW_ADDR (&attr);
8260 case DW_AT_location:
8261 /* Support the .debug_loc offsets */
8262 if (attr_form_is_block (&attr))
8264 part_die->locdesc = DW_BLOCK (&attr);
8266 else if (attr_form_is_section_offset (&attr))
8268 dwarf2_complex_location_expr_complaint ();
8272 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8273 "partial symbol information");
8276 case DW_AT_external:
8277 part_die->is_external = DW_UNSND (&attr);
8279 case DW_AT_declaration:
8280 part_die->is_declaration = DW_UNSND (&attr);
8283 part_die->has_type = 1;
8285 case DW_AT_abstract_origin:
8286 case DW_AT_specification:
8287 case DW_AT_extension:
8288 part_die->has_specification = 1;
8289 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
8292 /* Ignore absolute siblings, they might point outside of
8293 the current compile unit. */
8294 if (attr.form == DW_FORM_ref_addr)
8295 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
8297 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
8299 case DW_AT_byte_size:
8300 part_die->has_byte_size = 1;
8302 case DW_AT_calling_convention:
8303 /* DWARF doesn't provide a way to identify a program's source-level
8304 entry point. DW_AT_calling_convention attributes are only meant
8305 to describe functions' calling conventions.
8307 However, because it's a necessary piece of information in
8308 Fortran, and because DW_CC_program is the only piece of debugging
8309 information whose definition refers to a 'main program' at all,
8310 several compilers have begun marking Fortran main programs with
8311 DW_CC_program --- even when those functions use the standard
8312 calling conventions.
8314 So until DWARF specifies a way to provide this information and
8315 compilers pick up the new representation, we'll support this
8317 if (DW_UNSND (&attr) == DW_CC_program
8318 && cu->language == language_fortran)
8319 set_main_name (part_die->name);
8326 /* When using the GNU linker, .gnu.linkonce. sections are used to
8327 eliminate duplicate copies of functions and vtables and such.
8328 The linker will arbitrarily choose one and discard the others.
8329 The AT_*_pc values for such functions refer to local labels in
8330 these sections. If the section from that file was discarded, the
8331 labels are not in the output, so the relocs get a value of 0.
8332 If this is a discarded function, mark the pc bounds as invalid,
8333 so that GDB will ignore it. */
8334 if (has_low_pc_attr && has_high_pc_attr
8335 && part_die->lowpc < part_die->highpc
8336 && (part_die->lowpc != 0
8337 || dwarf2_per_objfile->has_section_at_zero))
8338 part_die->has_pc_info = 1;
8343 /* Find a cached partial DIE at OFFSET in CU. */
8345 static struct partial_die_info *
8346 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
8348 struct partial_die_info *lookup_die = NULL;
8349 struct partial_die_info part_die;
8351 part_die.offset = offset;
8352 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
8357 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8358 except in the case of .debug_types DIEs which do not reference
8359 outside their CU (they do however referencing other types via
8362 static struct partial_die_info *
8363 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
8365 struct dwarf2_per_cu_data *per_cu = NULL;
8366 struct partial_die_info *pd = NULL;
8368 if (cu->per_cu->from_debug_types)
8370 pd = find_partial_die_in_comp_unit (offset, cu);
8376 if (offset_in_cu_p (&cu->header, offset))
8378 pd = find_partial_die_in_comp_unit (offset, cu);
8383 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
8385 if (per_cu->cu == NULL)
8387 load_partial_comp_unit (per_cu, cu->objfile);
8388 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
8389 dwarf2_per_objfile->read_in_chain = per_cu;
8392 per_cu->cu->last_used = 0;
8393 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8395 if (pd == NULL && per_cu->load_all_dies == 0)
8397 struct cleanup *back_to;
8398 struct partial_die_info comp_unit_die;
8399 struct abbrev_info *abbrev;
8400 unsigned int bytes_read;
8403 per_cu->load_all_dies = 1;
8405 /* Re-read the DIEs. */
8406 back_to = make_cleanup (null_cleanup, 0);
8407 if (per_cu->cu->dwarf2_abbrevs == NULL)
8409 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
8410 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
8412 info_ptr = (dwarf2_per_objfile->info.buffer
8413 + per_cu->cu->header.offset
8414 + per_cu->cu->header.first_die_offset);
8415 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
8416 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
8417 per_cu->cu->objfile->obfd,
8418 dwarf2_per_objfile->info.buffer, info_ptr,
8420 if (comp_unit_die.has_children)
8421 load_partial_dies (per_cu->cu->objfile->obfd,
8422 dwarf2_per_objfile->info.buffer, info_ptr,
8424 do_cleanups (back_to);
8426 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
8432 internal_error (__FILE__, __LINE__,
8433 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8434 offset, bfd_get_filename (cu->objfile->obfd));
8438 /* Adjust PART_DIE before generating a symbol for it. This function
8439 may set the is_external flag or change the DIE's name. */
8442 fixup_partial_die (struct partial_die_info *part_die,
8443 struct dwarf2_cu *cu)
8445 /* If we found a reference attribute and the DIE has no name, try
8446 to find a name in the referred to DIE. */
8448 if (part_die->name == NULL && part_die->has_specification)
8450 struct partial_die_info *spec_die;
8452 spec_die = find_partial_die (part_die->spec_offset, cu);
8454 fixup_partial_die (spec_die, cu);
8458 part_die->name = spec_die->name;
8460 /* Copy DW_AT_external attribute if it is set. */
8461 if (spec_die->is_external)
8462 part_die->is_external = spec_die->is_external;
8466 /* Set default names for some unnamed DIEs. */
8467 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
8468 || part_die->tag == DW_TAG_class_type))
8469 part_die->name = "(anonymous class)";
8471 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
8472 part_die->name = "(anonymous namespace)";
8474 if (part_die->tag == DW_TAG_structure_type
8475 || part_die->tag == DW_TAG_class_type
8476 || part_die->tag == DW_TAG_union_type)
8477 guess_structure_name (part_die, cu);
8480 /* Read an attribute value described by an attribute form. */
8483 read_attribute_value (struct attribute *attr, unsigned form,
8484 bfd *abfd, gdb_byte *info_ptr,
8485 struct dwarf2_cu *cu)
8487 struct comp_unit_head *cu_header = &cu->header;
8488 unsigned int bytes_read;
8489 struct dwarf_block *blk;
8494 case DW_FORM_ref_addr:
8495 if (cu->header.version == 2)
8496 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
8498 DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
8499 info_ptr += bytes_read;
8502 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
8503 info_ptr += bytes_read;
8505 case DW_FORM_block2:
8506 blk = dwarf_alloc_block (cu);
8507 blk->size = read_2_bytes (abfd, info_ptr);
8509 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8510 info_ptr += blk->size;
8511 DW_BLOCK (attr) = blk;
8513 case DW_FORM_block4:
8514 blk = dwarf_alloc_block (cu);
8515 blk->size = read_4_bytes (abfd, info_ptr);
8517 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8518 info_ptr += blk->size;
8519 DW_BLOCK (attr) = blk;
8522 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
8526 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
8530 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
8533 case DW_FORM_sec_offset:
8534 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
8535 info_ptr += bytes_read;
8537 case DW_FORM_string:
8538 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
8539 DW_STRING_IS_CANONICAL (attr) = 0;
8540 info_ptr += bytes_read;
8543 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
8545 DW_STRING_IS_CANONICAL (attr) = 0;
8546 info_ptr += bytes_read;
8548 case DW_FORM_exprloc:
8550 blk = dwarf_alloc_block (cu);
8551 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8552 info_ptr += bytes_read;
8553 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8554 info_ptr += blk->size;
8555 DW_BLOCK (attr) = blk;
8557 case DW_FORM_block1:
8558 blk = dwarf_alloc_block (cu);
8559 blk->size = read_1_byte (abfd, info_ptr);
8561 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
8562 info_ptr += blk->size;
8563 DW_BLOCK (attr) = blk;
8566 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
8570 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
8573 case DW_FORM_flag_present:
8574 DW_UNSND (attr) = 1;
8577 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
8578 info_ptr += bytes_read;
8581 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8582 info_ptr += bytes_read;
8585 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
8589 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
8593 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
8597 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
8601 /* Convert the signature to something we can record in DW_UNSND
8603 NOTE: This is NULL if the type wasn't found. */
8604 DW_SIGNATURED_TYPE (attr) =
8605 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
8608 case DW_FORM_ref_udata:
8609 DW_ADDR (attr) = (cu->header.offset
8610 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
8611 info_ptr += bytes_read;
8613 case DW_FORM_indirect:
8614 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8615 info_ptr += bytes_read;
8616 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
8619 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
8620 dwarf_form_name (form),
8621 bfd_get_filename (abfd));
8624 /* We have seen instances where the compiler tried to emit a byte
8625 size attribute of -1 which ended up being encoded as an unsigned
8626 0xffffffff. Although 0xffffffff is technically a valid size value,
8627 an object of this size seems pretty unlikely so we can relatively
8628 safely treat these cases as if the size attribute was invalid and
8629 treat them as zero by default. */
8630 if (attr->name == DW_AT_byte_size
8631 && form == DW_FORM_data4
8632 && DW_UNSND (attr) >= 0xffffffff)
8635 (&symfile_complaints,
8636 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
8637 hex_string (DW_UNSND (attr)));
8638 DW_UNSND (attr) = 0;
8644 /* Read an attribute described by an abbreviated attribute. */
8647 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
8648 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
8650 attr->name = abbrev->name;
8651 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
8654 /* read dwarf information from a buffer */
8657 read_1_byte (bfd *abfd, gdb_byte *buf)
8659 return bfd_get_8 (abfd, buf);
8663 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
8665 return bfd_get_signed_8 (abfd, buf);
8669 read_2_bytes (bfd *abfd, gdb_byte *buf)
8671 return bfd_get_16 (abfd, buf);
8675 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
8677 return bfd_get_signed_16 (abfd, buf);
8681 read_4_bytes (bfd *abfd, gdb_byte *buf)
8683 return bfd_get_32 (abfd, buf);
8687 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
8689 return bfd_get_signed_32 (abfd, buf);
8693 read_8_bytes (bfd *abfd, gdb_byte *buf)
8695 return bfd_get_64 (abfd, buf);
8699 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
8700 unsigned int *bytes_read)
8702 struct comp_unit_head *cu_header = &cu->header;
8703 CORE_ADDR retval = 0;
8705 if (cu_header->signed_addr_p)
8707 switch (cu_header->addr_size)
8710 retval = bfd_get_signed_16 (abfd, buf);
8713 retval = bfd_get_signed_32 (abfd, buf);
8716 retval = bfd_get_signed_64 (abfd, buf);
8719 internal_error (__FILE__, __LINE__,
8720 _("read_address: bad switch, signed [in module %s]"),
8721 bfd_get_filename (abfd));
8726 switch (cu_header->addr_size)
8729 retval = bfd_get_16 (abfd, buf);
8732 retval = bfd_get_32 (abfd, buf);
8735 retval = bfd_get_64 (abfd, buf);
8738 internal_error (__FILE__, __LINE__,
8739 _("read_address: bad switch, unsigned [in module %s]"),
8740 bfd_get_filename (abfd));
8744 *bytes_read = cu_header->addr_size;
8748 /* Read the initial length from a section. The (draft) DWARF 3
8749 specification allows the initial length to take up either 4 bytes
8750 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
8751 bytes describe the length and all offsets will be 8 bytes in length
8754 An older, non-standard 64-bit format is also handled by this
8755 function. The older format in question stores the initial length
8756 as an 8-byte quantity without an escape value. Lengths greater
8757 than 2^32 aren't very common which means that the initial 4 bytes
8758 is almost always zero. Since a length value of zero doesn't make
8759 sense for the 32-bit format, this initial zero can be considered to
8760 be an escape value which indicates the presence of the older 64-bit
8761 format. As written, the code can't detect (old format) lengths
8762 greater than 4GB. If it becomes necessary to handle lengths
8763 somewhat larger than 4GB, we could allow other small values (such
8764 as the non-sensical values of 1, 2, and 3) to also be used as
8765 escape values indicating the presence of the old format.
8767 The value returned via bytes_read should be used to increment the
8768 relevant pointer after calling read_initial_length().
8770 [ Note: read_initial_length() and read_offset() are based on the
8771 document entitled "DWARF Debugging Information Format", revision
8772 3, draft 8, dated November 19, 2001. This document was obtained
8775 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
8777 This document is only a draft and is subject to change. (So beware.)
8779 Details regarding the older, non-standard 64-bit format were
8780 determined empirically by examining 64-bit ELF files produced by
8781 the SGI toolchain on an IRIX 6.5 machine.
8783 - Kevin, July 16, 2002
8787 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
8789 LONGEST length = bfd_get_32 (abfd, buf);
8791 if (length == 0xffffffff)
8793 length = bfd_get_64 (abfd, buf + 4);
8796 else if (length == 0)
8798 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
8799 length = bfd_get_64 (abfd, buf);
8810 /* Cover function for read_initial_length.
8811 Returns the length of the object at BUF, and stores the size of the
8812 initial length in *BYTES_READ and stores the size that offsets will be in
8814 If the initial length size is not equivalent to that specified in
8815 CU_HEADER then issue a complaint.
8816 This is useful when reading non-comp-unit headers. */
8819 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
8820 const struct comp_unit_head *cu_header,
8821 unsigned int *bytes_read,
8822 unsigned int *offset_size)
8824 LONGEST length = read_initial_length (abfd, buf, bytes_read);
8826 gdb_assert (cu_header->initial_length_size == 4
8827 || cu_header->initial_length_size == 8
8828 || cu_header->initial_length_size == 12);
8830 if (cu_header->initial_length_size != *bytes_read)
8831 complaint (&symfile_complaints,
8832 _("intermixed 32-bit and 64-bit DWARF sections"));
8834 *offset_size = (*bytes_read == 4) ? 4 : 8;
8838 /* Read an offset from the data stream. The size of the offset is
8839 given by cu_header->offset_size. */
8842 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
8843 unsigned int *bytes_read)
8845 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
8847 *bytes_read = cu_header->offset_size;
8851 /* Read an offset from the data stream. */
8854 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
8858 switch (offset_size)
8861 retval = bfd_get_32 (abfd, buf);
8864 retval = bfd_get_64 (abfd, buf);
8867 internal_error (__FILE__, __LINE__,
8868 _("read_offset_1: bad switch [in module %s]"),
8869 bfd_get_filename (abfd));
8876 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
8878 /* If the size of a host char is 8 bits, we can return a pointer
8879 to the buffer, otherwise we have to copy the data to a buffer
8880 allocated on the temporary obstack. */
8881 gdb_assert (HOST_CHAR_BIT == 8);
8886 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8888 /* If the size of a host char is 8 bits, we can return a pointer
8889 to the string, otherwise we have to copy the string to a buffer
8890 allocated on the temporary obstack. */
8891 gdb_assert (HOST_CHAR_BIT == 8);
8894 *bytes_read_ptr = 1;
8897 *bytes_read_ptr = strlen ((char *) buf) + 1;
8898 return (char *) buf;
8902 read_indirect_string (bfd *abfd, gdb_byte *buf,
8903 const struct comp_unit_head *cu_header,
8904 unsigned int *bytes_read_ptr)
8906 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
8908 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
8909 if (dwarf2_per_objfile->str.buffer == NULL)
8911 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
8912 bfd_get_filename (abfd));
8915 if (str_offset >= dwarf2_per_objfile->str.size)
8917 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
8918 bfd_get_filename (abfd));
8921 gdb_assert (HOST_CHAR_BIT == 8);
8922 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
8924 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
8927 static unsigned long
8928 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8930 unsigned long result;
8931 unsigned int num_read;
8941 byte = bfd_get_8 (abfd, buf);
8944 result |= ((unsigned long)(byte & 127) << shift);
8945 if ((byte & 128) == 0)
8951 *bytes_read_ptr = num_read;
8956 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
8959 int i, shift, num_read;
8968 byte = bfd_get_8 (abfd, buf);
8971 result |= ((long)(byte & 127) << shift);
8973 if ((byte & 128) == 0)
8978 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
8979 result |= -(((long)1) << shift);
8980 *bytes_read_ptr = num_read;
8984 /* Return a pointer to just past the end of an LEB128 number in BUF. */
8987 skip_leb128 (bfd *abfd, gdb_byte *buf)
8993 byte = bfd_get_8 (abfd, buf);
8995 if ((byte & 128) == 0)
9001 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
9008 cu->language = language_c;
9010 case DW_LANG_C_plus_plus:
9011 cu->language = language_cplus;
9014 cu->language = language_d;
9016 case DW_LANG_Fortran77:
9017 case DW_LANG_Fortran90:
9018 case DW_LANG_Fortran95:
9019 cu->language = language_fortran;
9021 case DW_LANG_Mips_Assembler:
9022 cu->language = language_asm;
9025 cu->language = language_java;
9029 cu->language = language_ada;
9031 case DW_LANG_Modula2:
9032 cu->language = language_m2;
9034 case DW_LANG_Pascal83:
9035 cu->language = language_pascal;
9038 cu->language = language_objc;
9040 case DW_LANG_Cobol74:
9041 case DW_LANG_Cobol85:
9043 cu->language = language_minimal;
9046 cu->language_defn = language_def (cu->language);
9049 /* Return the named attribute or NULL if not there. */
9051 static struct attribute *
9052 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
9055 struct attribute *spec = NULL;
9057 for (i = 0; i < die->num_attrs; ++i)
9059 if (die->attrs[i].name == name)
9060 return &die->attrs[i];
9061 if (die->attrs[i].name == DW_AT_specification
9062 || die->attrs[i].name == DW_AT_abstract_origin)
9063 spec = &die->attrs[i];
9068 die = follow_die_ref (die, spec, &cu);
9069 return dwarf2_attr (die, name, cu);
9075 /* Return the named attribute or NULL if not there,
9076 but do not follow DW_AT_specification, etc.
9077 This is for use in contexts where we're reading .debug_types dies.
9078 Following DW_AT_specification, DW_AT_abstract_origin will take us
9079 back up the chain, and we want to go down. */
9081 static struct attribute *
9082 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
9083 struct dwarf2_cu *cu)
9087 for (i = 0; i < die->num_attrs; ++i)
9088 if (die->attrs[i].name == name)
9089 return &die->attrs[i];
9094 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9095 and holds a non-zero value. This function should only be used for
9096 DW_FORM_flag or DW_FORM_flag_present attributes. */
9099 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
9101 struct attribute *attr = dwarf2_attr (die, name, cu);
9103 return (attr && DW_UNSND (attr));
9107 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
9109 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9110 which value is non-zero. However, we have to be careful with
9111 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9112 (via dwarf2_flag_true_p) follows this attribute. So we may
9113 end up accidently finding a declaration attribute that belongs
9114 to a different DIE referenced by the specification attribute,
9115 even though the given DIE does not have a declaration attribute. */
9116 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
9117 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
9120 /* Return the die giving the specification for DIE, if there is
9121 one. *SPEC_CU is the CU containing DIE on input, and the CU
9122 containing the return value on output. If there is no
9123 specification, but there is an abstract origin, that is
9126 static struct die_info *
9127 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
9129 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
9132 if (spec_attr == NULL)
9133 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
9135 if (spec_attr == NULL)
9138 return follow_die_ref (die, spec_attr, spec_cu);
9141 /* Free the line_header structure *LH, and any arrays and strings it
9144 free_line_header (struct line_header *lh)
9146 if (lh->standard_opcode_lengths)
9147 xfree (lh->standard_opcode_lengths);
9149 /* Remember that all the lh->file_names[i].name pointers are
9150 pointers into debug_line_buffer, and don't need to be freed. */
9152 xfree (lh->file_names);
9154 /* Similarly for the include directory names. */
9155 if (lh->include_dirs)
9156 xfree (lh->include_dirs);
9162 /* Add an entry to LH's include directory table. */
9164 add_include_dir (struct line_header *lh, char *include_dir)
9166 /* Grow the array if necessary. */
9167 if (lh->include_dirs_size == 0)
9169 lh->include_dirs_size = 1; /* for testing */
9170 lh->include_dirs = xmalloc (lh->include_dirs_size
9171 * sizeof (*lh->include_dirs));
9173 else if (lh->num_include_dirs >= lh->include_dirs_size)
9175 lh->include_dirs_size *= 2;
9176 lh->include_dirs = xrealloc (lh->include_dirs,
9177 (lh->include_dirs_size
9178 * sizeof (*lh->include_dirs)));
9181 lh->include_dirs[lh->num_include_dirs++] = include_dir;
9185 /* Add an entry to LH's file name table. */
9187 add_file_name (struct line_header *lh,
9189 unsigned int dir_index,
9190 unsigned int mod_time,
9191 unsigned int length)
9193 struct file_entry *fe;
9195 /* Grow the array if necessary. */
9196 if (lh->file_names_size == 0)
9198 lh->file_names_size = 1; /* for testing */
9199 lh->file_names = xmalloc (lh->file_names_size
9200 * sizeof (*lh->file_names));
9202 else if (lh->num_file_names >= lh->file_names_size)
9204 lh->file_names_size *= 2;
9205 lh->file_names = xrealloc (lh->file_names,
9206 (lh->file_names_size
9207 * sizeof (*lh->file_names)));
9210 fe = &lh->file_names[lh->num_file_names++];
9212 fe->dir_index = dir_index;
9213 fe->mod_time = mod_time;
9214 fe->length = length;
9220 /* Read the statement program header starting at OFFSET in
9221 .debug_line, according to the endianness of ABFD. Return a pointer
9222 to a struct line_header, allocated using xmalloc.
9224 NOTE: the strings in the include directory and file name tables of
9225 the returned object point into debug_line_buffer, and must not be
9227 static struct line_header *
9228 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
9229 struct dwarf2_cu *cu)
9231 struct cleanup *back_to;
9232 struct line_header *lh;
9234 unsigned int bytes_read, offset_size;
9236 char *cur_dir, *cur_file;
9238 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
9239 if (dwarf2_per_objfile->line.buffer == NULL)
9241 complaint (&symfile_complaints, _("missing .debug_line section"));
9245 /* Make sure that at least there's room for the total_length field.
9246 That could be 12 bytes long, but we're just going to fudge that. */
9247 if (offset + 4 >= dwarf2_per_objfile->line.size)
9249 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9253 lh = xmalloc (sizeof (*lh));
9254 memset (lh, 0, sizeof (*lh));
9255 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
9258 line_ptr = dwarf2_per_objfile->line.buffer + offset;
9260 /* Read in the header. */
9262 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
9263 &bytes_read, &offset_size);
9264 line_ptr += bytes_read;
9265 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
9266 + dwarf2_per_objfile->line.size))
9268 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9271 lh->statement_program_end = line_ptr + lh->total_length;
9272 lh->version = read_2_bytes (abfd, line_ptr);
9274 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
9275 line_ptr += offset_size;
9276 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
9278 if (lh->version >= 4)
9280 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
9284 lh->maximum_ops_per_instruction = 1;
9286 if (lh->maximum_ops_per_instruction == 0)
9288 lh->maximum_ops_per_instruction = 1;
9289 complaint (&symfile_complaints,
9290 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9293 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
9295 lh->line_base = read_1_signed_byte (abfd, line_ptr);
9297 lh->line_range = read_1_byte (abfd, line_ptr);
9299 lh->opcode_base = read_1_byte (abfd, line_ptr);
9301 lh->standard_opcode_lengths
9302 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
9304 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
9305 for (i = 1; i < lh->opcode_base; ++i)
9307 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
9311 /* Read directory table. */
9312 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
9314 line_ptr += bytes_read;
9315 add_include_dir (lh, cur_dir);
9317 line_ptr += bytes_read;
9319 /* Read file name table. */
9320 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
9322 unsigned int dir_index, mod_time, length;
9324 line_ptr += bytes_read;
9325 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9326 line_ptr += bytes_read;
9327 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9328 line_ptr += bytes_read;
9329 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9330 line_ptr += bytes_read;
9332 add_file_name (lh, cur_file, dir_index, mod_time, length);
9334 line_ptr += bytes_read;
9335 lh->statement_program_start = line_ptr;
9337 if (line_ptr > (dwarf2_per_objfile->line.buffer
9338 + dwarf2_per_objfile->line.size))
9339 complaint (&symfile_complaints,
9340 _("line number info header doesn't fit in `.debug_line' section"));
9342 discard_cleanups (back_to);
9346 /* This function exists to work around a bug in certain compilers
9347 (particularly GCC 2.95), in which the first line number marker of a
9348 function does not show up until after the prologue, right before
9349 the second line number marker. This function shifts ADDRESS down
9350 to the beginning of the function if necessary, and is called on
9351 addresses passed to record_line. */
9354 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
9356 struct function_range *fn;
9358 /* Find the function_range containing address. */
9363 cu->cached_fn = cu->first_fn;
9367 if (fn->lowpc <= address && fn->highpc > address)
9373 while (fn && fn != cu->cached_fn)
9374 if (fn->lowpc <= address && fn->highpc > address)
9384 if (address != fn->lowpc)
9385 complaint (&symfile_complaints,
9386 _("misplaced first line number at 0x%lx for '%s'"),
9387 (unsigned long) address, fn->name);
9392 /* Decode the Line Number Program (LNP) for the given line_header
9393 structure and CU. The actual information extracted and the type
9394 of structures created from the LNP depends on the value of PST.
9396 1. If PST is NULL, then this procedure uses the data from the program
9397 to create all necessary symbol tables, and their linetables.
9398 The compilation directory of the file is passed in COMP_DIR,
9399 and must not be NULL.
9401 2. If PST is not NULL, this procedure reads the program to determine
9402 the list of files included by the unit represented by PST, and
9403 builds all the associated partial symbol tables. In this case,
9404 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9405 is not used to compute the full name of the symtab, and therefore
9406 omitting it when building the partial symtab does not introduce
9407 the potential for inconsistency - a partial symtab and its associated
9408 symbtab having a different fullname -). */
9411 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
9412 struct dwarf2_cu *cu, struct partial_symtab *pst)
9414 gdb_byte *line_ptr, *extended_end;
9416 unsigned int bytes_read, extended_len;
9417 unsigned char op_code, extended_op, adj_opcode;
9419 struct objfile *objfile = cu->objfile;
9420 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9421 const int decode_for_pst_p = (pst != NULL);
9422 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
9424 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9426 line_ptr = lh->statement_program_start;
9427 line_end = lh->statement_program_end;
9429 /* Read the statement sequences until there's nothing left. */
9430 while (line_ptr < line_end)
9432 /* state machine registers */
9433 CORE_ADDR address = 0;
9434 unsigned int file = 1;
9435 unsigned int line = 1;
9436 unsigned int column = 0;
9437 int is_stmt = lh->default_is_stmt;
9438 int basic_block = 0;
9439 int end_sequence = 0;
9441 unsigned char op_index = 0;
9443 if (!decode_for_pst_p && lh->num_file_names >= file)
9445 /* Start a subfile for the current file of the state machine. */
9446 /* lh->include_dirs and lh->file_names are 0-based, but the
9447 directory and file name numbers in the statement program
9449 struct file_entry *fe = &lh->file_names[file - 1];
9453 dir = lh->include_dirs[fe->dir_index - 1];
9455 dwarf2_start_subfile (fe->name, dir, comp_dir);
9458 /* Decode the table. */
9459 while (!end_sequence)
9461 op_code = read_1_byte (abfd, line_ptr);
9463 if (line_ptr > line_end)
9465 dwarf2_debug_line_missing_end_sequence_complaint ();
9469 if (op_code >= lh->opcode_base)
9471 /* Special operand. */
9472 adj_opcode = op_code - lh->opcode_base;
9473 address += (((op_index + (adj_opcode / lh->line_range))
9474 / lh->maximum_ops_per_instruction)
9475 * lh->minimum_instruction_length);
9476 op_index = ((op_index + (adj_opcode / lh->line_range))
9477 % lh->maximum_ops_per_instruction);
9478 line += lh->line_base + (adj_opcode % lh->line_range);
9479 if (lh->num_file_names < file || file == 0)
9480 dwarf2_debug_line_missing_file_complaint ();
9481 /* For now we ignore lines not starting on an
9482 instruction boundary. */
9483 else if (op_index == 0)
9485 lh->file_names[file - 1].included_p = 1;
9486 if (!decode_for_pst_p && is_stmt)
9488 if (last_subfile != current_subfile)
9490 addr = gdbarch_addr_bits_remove (gdbarch, address);
9492 record_line (last_subfile, 0, addr);
9493 last_subfile = current_subfile;
9495 /* Append row to matrix using current values. */
9496 addr = check_cu_functions (address, cu);
9497 addr = gdbarch_addr_bits_remove (gdbarch, addr);
9498 record_line (current_subfile, line, addr);
9503 else switch (op_code)
9505 case DW_LNS_extended_op:
9506 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9507 line_ptr += bytes_read;
9508 extended_end = line_ptr + extended_len;
9509 extended_op = read_1_byte (abfd, line_ptr);
9511 switch (extended_op)
9513 case DW_LNE_end_sequence:
9516 case DW_LNE_set_address:
9517 address = read_address (abfd, line_ptr, cu, &bytes_read);
9519 line_ptr += bytes_read;
9520 address += baseaddr;
9522 case DW_LNE_define_file:
9525 unsigned int dir_index, mod_time, length;
9527 cur_file = read_string (abfd, line_ptr, &bytes_read);
9528 line_ptr += bytes_read;
9530 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9531 line_ptr += bytes_read;
9533 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9534 line_ptr += bytes_read;
9536 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9537 line_ptr += bytes_read;
9538 add_file_name (lh, cur_file, dir_index, mod_time, length);
9541 case DW_LNE_set_discriminator:
9542 /* The discriminator is not interesting to the debugger;
9544 line_ptr = extended_end;
9547 complaint (&symfile_complaints,
9548 _("mangled .debug_line section"));
9551 /* Make sure that we parsed the extended op correctly. If e.g.
9552 we expected a different address size than the producer used,
9553 we may have read the wrong number of bytes. */
9554 if (line_ptr != extended_end)
9556 complaint (&symfile_complaints,
9557 _("mangled .debug_line section"));
9562 if (lh->num_file_names < file || file == 0)
9563 dwarf2_debug_line_missing_file_complaint ();
9566 lh->file_names[file - 1].included_p = 1;
9567 if (!decode_for_pst_p && is_stmt)
9569 if (last_subfile != current_subfile)
9571 addr = gdbarch_addr_bits_remove (gdbarch, address);
9573 record_line (last_subfile, 0, addr);
9574 last_subfile = current_subfile;
9576 addr = check_cu_functions (address, cu);
9577 addr = gdbarch_addr_bits_remove (gdbarch, addr);
9578 record_line (current_subfile, line, addr);
9583 case DW_LNS_advance_pc:
9586 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9588 address += (((op_index + adjust)
9589 / lh->maximum_ops_per_instruction)
9590 * lh->minimum_instruction_length);
9591 op_index = ((op_index + adjust)
9592 % lh->maximum_ops_per_instruction);
9593 line_ptr += bytes_read;
9596 case DW_LNS_advance_line:
9597 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
9598 line_ptr += bytes_read;
9600 case DW_LNS_set_file:
9602 /* The arrays lh->include_dirs and lh->file_names are
9603 0-based, but the directory and file name numbers in
9604 the statement program are 1-based. */
9605 struct file_entry *fe;
9608 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9609 line_ptr += bytes_read;
9610 if (lh->num_file_names < file || file == 0)
9611 dwarf2_debug_line_missing_file_complaint ();
9614 fe = &lh->file_names[file - 1];
9616 dir = lh->include_dirs[fe->dir_index - 1];
9617 if (!decode_for_pst_p)
9619 last_subfile = current_subfile;
9620 dwarf2_start_subfile (fe->name, dir, comp_dir);
9625 case DW_LNS_set_column:
9626 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9627 line_ptr += bytes_read;
9629 case DW_LNS_negate_stmt:
9630 is_stmt = (!is_stmt);
9632 case DW_LNS_set_basic_block:
9635 /* Add to the address register of the state machine the
9636 address increment value corresponding to special opcode
9637 255. I.e., this value is scaled by the minimum
9638 instruction length since special opcode 255 would have
9639 scaled the the increment. */
9640 case DW_LNS_const_add_pc:
9642 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
9644 address += (((op_index + adjust)
9645 / lh->maximum_ops_per_instruction)
9646 * lh->minimum_instruction_length);
9647 op_index = ((op_index + adjust)
9648 % lh->maximum_ops_per_instruction);
9651 case DW_LNS_fixed_advance_pc:
9652 address += read_2_bytes (abfd, line_ptr);
9658 /* Unknown standard opcode, ignore it. */
9661 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
9663 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
9664 line_ptr += bytes_read;
9669 if (lh->num_file_names < file || file == 0)
9670 dwarf2_debug_line_missing_file_complaint ();
9673 lh->file_names[file - 1].included_p = 1;
9674 if (!decode_for_pst_p)
9676 addr = gdbarch_addr_bits_remove (gdbarch, address);
9677 record_line (current_subfile, 0, addr);
9682 if (decode_for_pst_p)
9686 /* Now that we're done scanning the Line Header Program, we can
9687 create the psymtab of each included file. */
9688 for (file_index = 0; file_index < lh->num_file_names; file_index++)
9689 if (lh->file_names[file_index].included_p == 1)
9691 const struct file_entry fe = lh->file_names [file_index];
9692 char *include_name = fe.name;
9693 char *dir_name = NULL;
9694 char *pst_filename = pst->filename;
9697 dir_name = lh->include_dirs[fe.dir_index - 1];
9699 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
9701 include_name = concat (dir_name, SLASH_STRING,
9702 include_name, (char *)NULL);
9703 make_cleanup (xfree, include_name);
9706 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
9708 pst_filename = concat (pst->dirname, SLASH_STRING,
9709 pst_filename, (char *)NULL);
9710 make_cleanup (xfree, pst_filename);
9713 if (strcmp (include_name, pst_filename) != 0)
9714 dwarf2_create_include_psymtab (include_name, pst, objfile);
9719 /* Make sure a symtab is created for every file, even files
9720 which contain only variables (i.e. no code with associated
9724 struct file_entry *fe;
9726 for (i = 0; i < lh->num_file_names; i++)
9730 fe = &lh->file_names[i];
9732 dir = lh->include_dirs[fe->dir_index - 1];
9733 dwarf2_start_subfile (fe->name, dir, comp_dir);
9735 /* Skip the main file; we don't need it, and it must be
9736 allocated last, so that it will show up before the
9737 non-primary symtabs in the objfile's symtab list. */
9738 if (current_subfile == first_subfile)
9741 if (current_subfile->symtab == NULL)
9742 current_subfile->symtab = allocate_symtab (current_subfile->name,
9744 fe->symtab = current_subfile->symtab;
9749 /* Start a subfile for DWARF. FILENAME is the name of the file and
9750 DIRNAME the name of the source directory which contains FILENAME
9751 or NULL if not known. COMP_DIR is the compilation directory for the
9752 linetable's compilation unit or NULL if not known.
9753 This routine tries to keep line numbers from identical absolute and
9754 relative file names in a common subfile.
9756 Using the `list' example from the GDB testsuite, which resides in
9757 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
9758 of /srcdir/list0.c yields the following debugging information for list0.c:
9760 DW_AT_name: /srcdir/list0.c
9761 DW_AT_comp_dir: /compdir
9762 files.files[0].name: list0.h
9763 files.files[0].dir: /srcdir
9764 files.files[1].name: list0.c
9765 files.files[1].dir: /srcdir
9767 The line number information for list0.c has to end up in a single
9768 subfile, so that `break /srcdir/list0.c:1' works as expected.
9769 start_subfile will ensure that this happens provided that we pass the
9770 concatenation of files.files[1].dir and files.files[1].name as the
9774 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
9778 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
9779 `start_symtab' will always pass the contents of DW_AT_comp_dir as
9780 second argument to start_subfile. To be consistent, we do the
9781 same here. In order not to lose the line information directory,
9782 we concatenate it to the filename when it makes sense.
9783 Note that the Dwarf3 standard says (speaking of filenames in line
9784 information): ``The directory index is ignored for file names
9785 that represent full path names''. Thus ignoring dirname in the
9786 `else' branch below isn't an issue. */
9788 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
9789 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
9791 fullname = filename;
9793 start_subfile (fullname, comp_dir);
9795 if (fullname != filename)
9800 var_decode_location (struct attribute *attr, struct symbol *sym,
9801 struct dwarf2_cu *cu)
9803 struct objfile *objfile = cu->objfile;
9804 struct comp_unit_head *cu_header = &cu->header;
9806 /* NOTE drow/2003-01-30: There used to be a comment and some special
9807 code here to turn a symbol with DW_AT_external and a
9808 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
9809 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
9810 with some versions of binutils) where shared libraries could have
9811 relocations against symbols in their debug information - the
9812 minimal symbol would have the right address, but the debug info
9813 would not. It's no longer necessary, because we will explicitly
9814 apply relocations when we read in the debug information now. */
9816 /* A DW_AT_location attribute with no contents indicates that a
9817 variable has been optimized away. */
9818 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
9820 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
9824 /* Handle one degenerate form of location expression specially, to
9825 preserve GDB's previous behavior when section offsets are
9826 specified. If this is just a DW_OP_addr then mark this symbol
9829 if (attr_form_is_block (attr)
9830 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
9831 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
9835 SYMBOL_VALUE_ADDRESS (sym) =
9836 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
9837 SYMBOL_CLASS (sym) = LOC_STATIC;
9838 fixup_symbol_section (sym, objfile);
9839 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
9840 SYMBOL_SECTION (sym));
9844 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
9845 expression evaluator, and use LOC_COMPUTED only when necessary
9846 (i.e. when the value of a register or memory location is
9847 referenced, or a thread-local block, etc.). Then again, it might
9848 not be worthwhile. I'm assuming that it isn't unless performance
9849 or memory numbers show me otherwise. */
9851 dwarf2_symbol_mark_computed (attr, sym, cu);
9852 SYMBOL_CLASS (sym) = LOC_COMPUTED;
9855 /* Given a pointer to a DWARF information entry, figure out if we need
9856 to make a symbol table entry for it, and if so, create a new entry
9857 and return a pointer to it.
9858 If TYPE is NULL, determine symbol type from the die, otherwise
9859 used the passed type. */
9861 static struct symbol *
9862 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
9864 struct objfile *objfile = cu->objfile;
9865 struct symbol *sym = NULL;
9867 struct attribute *attr = NULL;
9868 struct attribute *attr2 = NULL;
9870 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
9872 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9874 name = dwarf2_name (die, cu);
9877 const char *linkagename;
9879 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
9880 sizeof (struct symbol));
9881 OBJSTAT (objfile, n_syms++);
9882 memset (sym, 0, sizeof (struct symbol));
9884 /* Cache this symbol's name and the name's demangled form (if any). */
9885 SYMBOL_LANGUAGE (sym) = cu->language;
9886 linkagename = dwarf2_physname (name, die, cu);
9887 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
9889 /* Fortran does not have mangling standard and the mangling does differ
9890 between gfortran, iFort etc. */
9891 if (cu->language == language_fortran
9892 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
9893 symbol_set_demangled_name (&(sym->ginfo),
9894 (char *) dwarf2_full_name (name, die, cu),
9897 /* Default assumptions.
9898 Use the passed type or decode it from the die. */
9899 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9900 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
9902 SYMBOL_TYPE (sym) = type;
9904 SYMBOL_TYPE (sym) = die_type (die, cu);
9905 attr = dwarf2_attr (die,
9906 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
9910 SYMBOL_LINE (sym) = DW_UNSND (attr);
9913 attr = dwarf2_attr (die,
9914 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
9918 int file_index = DW_UNSND (attr);
9920 if (cu->line_header == NULL
9921 || file_index > cu->line_header->num_file_names)
9922 complaint (&symfile_complaints,
9923 _("file index out of range"));
9924 else if (file_index > 0)
9926 struct file_entry *fe;
9928 fe = &cu->line_header->file_names[file_index - 1];
9929 SYMBOL_SYMTAB (sym) = fe->symtab;
9936 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
9939 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
9941 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
9942 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
9943 SYMBOL_CLASS (sym) = LOC_LABEL;
9944 add_symbol_to_list (sym, cu->list_in_scope);
9946 case DW_TAG_subprogram:
9947 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9949 SYMBOL_CLASS (sym) = LOC_BLOCK;
9950 attr2 = dwarf2_attr (die, DW_AT_external, cu);
9951 if ((attr2 && (DW_UNSND (attr2) != 0))
9952 || cu->language == language_ada)
9954 /* Subprograms marked external are stored as a global symbol.
9955 Ada subprograms, whether marked external or not, are always
9956 stored as a global symbol, because we want to be able to
9957 access them globally. For instance, we want to be able
9958 to break on a nested subprogram without having to
9959 specify the context. */
9960 add_symbol_to_list (sym, &global_symbols);
9964 add_symbol_to_list (sym, cu->list_in_scope);
9967 case DW_TAG_inlined_subroutine:
9968 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9970 SYMBOL_CLASS (sym) = LOC_BLOCK;
9971 SYMBOL_INLINED (sym) = 1;
9972 /* Do not add the symbol to any lists. It will be found via
9973 BLOCK_FUNCTION from the blockvector. */
9975 case DW_TAG_variable:
9977 /* Compilation with minimal debug info may result in variables
9978 with missing type entries. Change the misleading `void' type
9979 to something sensible. */
9980 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
9982 = objfile_type (objfile)->nodebug_data_symbol;
9984 attr = dwarf2_attr (die, DW_AT_const_value, cu);
9985 /* In the case of DW_TAG_member, we should only be called for
9986 static const members. */
9987 if (die->tag == DW_TAG_member)
9989 /* dwarf2_add_field uses die_is_declaration,
9990 so we do the same. */
9991 gdb_assert (die_is_declaration (die, cu));
9996 dwarf2_const_value (attr, sym, cu);
9997 attr2 = dwarf2_attr (die, DW_AT_external, cu);
9998 if (attr2 && (DW_UNSND (attr2) != 0))
9999 add_symbol_to_list (sym, &global_symbols);
10001 add_symbol_to_list (sym, cu->list_in_scope);
10004 attr = dwarf2_attr (die, DW_AT_location, cu);
10007 var_decode_location (attr, sym, cu);
10008 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10009 if (attr2 && (DW_UNSND (attr2) != 0))
10011 struct pending **list_to_add;
10013 /* Workaround gfortran PR debug/40040 - it uses
10014 DW_AT_location for variables in -fPIC libraries which may
10015 get overriden by other libraries/executable and get
10016 a different address. Resolve it by the minimal symbol
10017 which may come from inferior's executable using copy
10018 relocation. Make this workaround only for gfortran as for
10019 other compilers GDB cannot guess the minimal symbol
10020 Fortran mangling kind. */
10021 if (cu->language == language_fortran && die->parent
10022 && die->parent->tag == DW_TAG_module
10024 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
10025 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10027 /* A variable with DW_AT_external is never static,
10028 but it may be block-scoped. */
10029 list_to_add = (cu->list_in_scope == &file_symbols
10030 ? &global_symbols : cu->list_in_scope);
10031 add_symbol_to_list (sym, list_to_add);
10034 add_symbol_to_list (sym, cu->list_in_scope);
10038 /* We do not know the address of this symbol.
10039 If it is an external symbol and we have type information
10040 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10041 The address of the variable will then be determined from
10042 the minimal symbol table whenever the variable is
10044 attr2 = dwarf2_attr (die, DW_AT_external, cu);
10045 if (attr2 && (DW_UNSND (attr2) != 0)
10046 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
10048 struct pending **list_to_add;
10050 /* A variable with DW_AT_external is never static, but it
10051 may be block-scoped. */
10052 list_to_add = (cu->list_in_scope == &file_symbols
10053 ? &global_symbols : cu->list_in_scope);
10055 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
10056 add_symbol_to_list (sym, list_to_add);
10058 else if (!die_is_declaration (die, cu))
10060 /* Use the default LOC_OPTIMIZED_OUT class. */
10061 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
10062 add_symbol_to_list (sym, cu->list_in_scope);
10066 case DW_TAG_formal_parameter:
10067 /* If we are inside a function, mark this as an argument. If
10068 not, we might be looking at an argument to an inlined function
10069 when we do not have enough information to show inlined frames;
10070 pretend it's a local variable in that case so that the user can
10072 if (context_stack_depth > 0
10073 && context_stack[context_stack_depth - 1].name != NULL)
10074 SYMBOL_IS_ARGUMENT (sym) = 1;
10075 attr = dwarf2_attr (die, DW_AT_location, cu);
10078 var_decode_location (attr, sym, cu);
10080 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10083 dwarf2_const_value (attr, sym, cu);
10085 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
10086 if (attr && DW_UNSND (attr))
10088 struct type *ref_type;
10090 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
10091 SYMBOL_TYPE (sym) = ref_type;
10094 add_symbol_to_list (sym, cu->list_in_scope);
10096 case DW_TAG_unspecified_parameters:
10097 /* From varargs functions; gdb doesn't seem to have any
10098 interest in this information, so just ignore it for now.
10101 case DW_TAG_class_type:
10102 case DW_TAG_interface_type:
10103 case DW_TAG_structure_type:
10104 case DW_TAG_union_type:
10105 case DW_TAG_set_type:
10106 case DW_TAG_enumeration_type:
10107 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10108 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
10111 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10112 really ever be static objects: otherwise, if you try
10113 to, say, break of a class's method and you're in a file
10114 which doesn't mention that class, it won't work unless
10115 the check for all static symbols in lookup_symbol_aux
10116 saves you. See the OtherFileClass tests in
10117 gdb.c++/namespace.exp. */
10119 struct pending **list_to_add;
10121 list_to_add = (cu->list_in_scope == &file_symbols
10122 && (cu->language == language_cplus
10123 || cu->language == language_java)
10124 ? &global_symbols : cu->list_in_scope);
10126 add_symbol_to_list (sym, list_to_add);
10128 /* The semantics of C++ state that "struct foo { ... }" also
10129 defines a typedef for "foo". A Java class declaration also
10130 defines a typedef for the class. */
10131 if (cu->language == language_cplus
10132 || cu->language == language_java
10133 || cu->language == language_ada)
10135 /* The symbol's name is already allocated along with
10136 this objfile, so we don't need to duplicate it for
10138 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
10139 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
10143 case DW_TAG_typedef:
10144 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10145 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10146 add_symbol_to_list (sym, cu->list_in_scope);
10148 case DW_TAG_base_type:
10149 case DW_TAG_subrange_type:
10150 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10151 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10152 add_symbol_to_list (sym, cu->list_in_scope);
10154 case DW_TAG_enumerator:
10155 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10158 dwarf2_const_value (attr, sym, cu);
10161 /* NOTE: carlton/2003-11-10: See comment above in the
10162 DW_TAG_class_type, etc. block. */
10164 struct pending **list_to_add;
10166 list_to_add = (cu->list_in_scope == &file_symbols
10167 && (cu->language == language_cplus
10168 || cu->language == language_java)
10169 ? &global_symbols : cu->list_in_scope);
10171 add_symbol_to_list (sym, list_to_add);
10174 case DW_TAG_namespace:
10175 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
10176 add_symbol_to_list (sym, &global_symbols);
10179 /* Not a tag we recognize. Hopefully we aren't processing
10180 trash data, but since we must specifically ignore things
10181 we don't recognize, there is nothing else we should do at
10183 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
10184 dwarf_tag_name (die->tag));
10188 /* For the benefit of old versions of GCC, check for anonymous
10189 namespaces based on the demangled name. */
10190 if (!processing_has_namespace_info
10191 && cu->language == language_cplus)
10192 cp_scan_for_anonymous_namespaces (sym);
10197 /* Copy constant value from an attribute to a symbol. */
10200 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
10201 struct dwarf2_cu *cu)
10203 struct objfile *objfile = cu->objfile;
10204 struct comp_unit_head *cu_header = &cu->header;
10205 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
10206 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
10207 struct dwarf_block *blk;
10209 switch (attr->form)
10213 struct dwarf2_locexpr_baton *baton;
10216 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
10217 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
10218 cu_header->addr_size,
10219 TYPE_LENGTH (SYMBOL_TYPE
10221 /* Symbols of this form are reasonably rare, so we just
10222 piggyback on the existing location code rather than writing
10223 a new implementation of symbol_computed_ops. */
10224 baton = obstack_alloc (&objfile->objfile_obstack,
10225 sizeof (struct dwarf2_locexpr_baton));
10226 baton->per_cu = cu->per_cu;
10227 gdb_assert (baton->per_cu);
10229 baton->size = 2 + cu_header->addr_size;
10230 data = obstack_alloc (&objfile->objfile_obstack, baton->size);
10231 baton->data = data;
10233 data[0] = DW_OP_addr;
10234 store_unsigned_integer (&data[1], cu_header->addr_size,
10235 byte_order, DW_ADDR (attr));
10236 data[cu_header->addr_size + 1] = DW_OP_stack_value;
10238 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
10239 SYMBOL_LOCATION_BATON (sym) = baton;
10240 SYMBOL_CLASS (sym) = LOC_COMPUTED;
10243 case DW_FORM_string:
10245 /* DW_STRING is already allocated on the obstack, point directly
10247 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
10248 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
10250 case DW_FORM_block1:
10251 case DW_FORM_block2:
10252 case DW_FORM_block4:
10253 case DW_FORM_block:
10254 case DW_FORM_exprloc:
10255 blk = DW_BLOCK (attr);
10256 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
10257 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
10259 TYPE_LENGTH (SYMBOL_TYPE
10261 SYMBOL_VALUE_BYTES (sym) =
10262 obstack_alloc (&objfile->objfile_obstack, blk->size);
10263 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
10264 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
10267 /* The DW_AT_const_value attributes are supposed to carry the
10268 symbol's value "represented as it would be on the target
10269 architecture." By the time we get here, it's already been
10270 converted to host endianness, so we just need to sign- or
10271 zero-extend it as appropriate. */
10272 case DW_FORM_data1:
10273 dwarf2_const_value_data (attr, sym, 8);
10275 case DW_FORM_data2:
10276 dwarf2_const_value_data (attr, sym, 16);
10278 case DW_FORM_data4:
10279 dwarf2_const_value_data (attr, sym, 32);
10281 case DW_FORM_data8:
10282 dwarf2_const_value_data (attr, sym, 64);
10285 case DW_FORM_sdata:
10286 SYMBOL_VALUE (sym) = DW_SND (attr);
10287 SYMBOL_CLASS (sym) = LOC_CONST;
10290 case DW_FORM_udata:
10291 SYMBOL_VALUE (sym) = DW_UNSND (attr);
10292 SYMBOL_CLASS (sym) = LOC_CONST;
10296 complaint (&symfile_complaints,
10297 _("unsupported const value attribute form: '%s'"),
10298 dwarf_form_name (attr->form));
10299 SYMBOL_VALUE (sym) = 0;
10300 SYMBOL_CLASS (sym) = LOC_CONST;
10306 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
10307 or zero-extend it as appropriate for the symbol's type. */
10309 dwarf2_const_value_data (struct attribute *attr,
10310 struct symbol *sym,
10313 LONGEST l = DW_UNSND (attr);
10315 if (bits < sizeof (l) * 8)
10317 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
10318 l &= ((LONGEST) 1 << bits) - 1;
10320 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
10323 SYMBOL_VALUE (sym) = l;
10324 SYMBOL_CLASS (sym) = LOC_CONST;
10328 /* Return the type of the die in question using its DW_AT_type attribute. */
10330 static struct type *
10331 die_type (struct die_info *die, struct dwarf2_cu *cu)
10333 struct attribute *type_attr;
10334 struct die_info *type_die;
10336 type_attr = dwarf2_attr (die, DW_AT_type, cu);
10339 /* A missing DW_AT_type represents a void type. */
10340 return objfile_type (cu->objfile)->builtin_void;
10343 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
10345 return tag_type_to_type (type_die, cu);
10348 /* True iff CU's producer generates GNAT Ada auxiliary information
10349 that allows to find parallel types through that information instead
10350 of having to do expensive parallel lookups by type name. */
10353 need_gnat_info (struct dwarf2_cu *cu)
10355 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10356 of GNAT produces this auxiliary information, without any indication
10357 that it is produced. Part of enhancing the FSF version of GNAT
10358 to produce that information will be to put in place an indicator
10359 that we can use in order to determine whether the descriptive type
10360 info is available or not. One suggestion that has been made is
10361 to use a new attribute, attached to the CU die. For now, assume
10362 that the descriptive type info is not available. */
10367 /* Return the auxiliary type of the die in question using its
10368 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10369 attribute is not present. */
10371 static struct type *
10372 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
10374 struct attribute *type_attr;
10375 struct die_info *type_die;
10377 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
10381 type_die = follow_die_ref (die, type_attr, &cu);
10382 return tag_type_to_type (type_die, cu);
10385 /* If DIE has a descriptive_type attribute, then set the TYPE's
10386 descriptive type accordingly. */
10389 set_descriptive_type (struct type *type, struct die_info *die,
10390 struct dwarf2_cu *cu)
10392 struct type *descriptive_type = die_descriptive_type (die, cu);
10394 if (descriptive_type)
10396 ALLOCATE_GNAT_AUX_TYPE (type);
10397 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
10401 /* Return the containing type of the die in question using its
10402 DW_AT_containing_type attribute. */
10404 static struct type *
10405 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
10407 struct attribute *type_attr;
10408 struct die_info *type_die;
10410 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
10412 error (_("Dwarf Error: Problem turning containing type into gdb type "
10413 "[in module %s]"), cu->objfile->name);
10415 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
10416 return tag_type_to_type (type_die, cu);
10419 static struct type *
10420 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
10422 struct type *this_type;
10424 this_type = read_type_die (die, cu);
10427 char *message, *saved;
10429 /* read_type_die already issued a complaint. */
10430 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10434 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
10435 message, strlen (message));
10438 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
10443 static struct type *
10444 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
10446 struct type *this_type;
10448 this_type = get_die_type (die, cu);
10454 case DW_TAG_class_type:
10455 case DW_TAG_interface_type:
10456 case DW_TAG_structure_type:
10457 case DW_TAG_union_type:
10458 this_type = read_structure_type (die, cu);
10460 case DW_TAG_enumeration_type:
10461 this_type = read_enumeration_type (die, cu);
10463 case DW_TAG_subprogram:
10464 case DW_TAG_subroutine_type:
10465 case DW_TAG_inlined_subroutine:
10466 this_type = read_subroutine_type (die, cu);
10468 case DW_TAG_array_type:
10469 this_type = read_array_type (die, cu);
10471 case DW_TAG_set_type:
10472 this_type = read_set_type (die, cu);
10474 case DW_TAG_pointer_type:
10475 this_type = read_tag_pointer_type (die, cu);
10477 case DW_TAG_ptr_to_member_type:
10478 this_type = read_tag_ptr_to_member_type (die, cu);
10480 case DW_TAG_reference_type:
10481 this_type = read_tag_reference_type (die, cu);
10483 case DW_TAG_const_type:
10484 this_type = read_tag_const_type (die, cu);
10486 case DW_TAG_volatile_type:
10487 this_type = read_tag_volatile_type (die, cu);
10489 case DW_TAG_string_type:
10490 this_type = read_tag_string_type (die, cu);
10492 case DW_TAG_typedef:
10493 this_type = read_typedef (die, cu);
10495 case DW_TAG_subrange_type:
10496 this_type = read_subrange_type (die, cu);
10498 case DW_TAG_base_type:
10499 this_type = read_base_type (die, cu);
10501 case DW_TAG_unspecified_type:
10502 this_type = read_unspecified_type (die, cu);
10504 case DW_TAG_namespace:
10505 this_type = read_namespace_type (die, cu);
10507 case DW_TAG_module:
10508 this_type = read_module_type (die, cu);
10511 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
10512 dwarf_tag_name (die->tag));
10519 /* Return the name of the namespace/class that DIE is defined within,
10520 or "" if we can't tell. The caller should not xfree the result.
10522 For example, if we're within the method foo() in the following
10532 then determine_prefix on foo's die will return "N::C". */
10535 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
10537 struct die_info *parent, *spec_die;
10538 struct dwarf2_cu *spec_cu;
10539 struct type *parent_type;
10541 if (cu->language != language_cplus && cu->language != language_java
10542 && cu->language != language_fortran)
10545 /* We have to be careful in the presence of DW_AT_specification.
10546 For example, with GCC 3.4, given the code
10550 // Definition of N::foo.
10554 then we'll have a tree of DIEs like this:
10556 1: DW_TAG_compile_unit
10557 2: DW_TAG_namespace // N
10558 3: DW_TAG_subprogram // declaration of N::foo
10559 4: DW_TAG_subprogram // definition of N::foo
10560 DW_AT_specification // refers to die #3
10562 Thus, when processing die #4, we have to pretend that we're in
10563 the context of its DW_AT_specification, namely the contex of die
10566 spec_die = die_specification (die, &spec_cu);
10567 if (spec_die == NULL)
10568 parent = die->parent;
10571 parent = spec_die->parent;
10575 if (parent == NULL)
10578 switch (parent->tag)
10580 case DW_TAG_namespace:
10581 parent_type = read_type_die (parent, cu);
10582 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
10583 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
10584 Work around this problem here. */
10585 if (cu->language == language_cplus
10586 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
10588 /* We give a name to even anonymous namespaces. */
10589 return TYPE_TAG_NAME (parent_type);
10590 case DW_TAG_class_type:
10591 case DW_TAG_interface_type:
10592 case DW_TAG_structure_type:
10593 case DW_TAG_union_type:
10594 case DW_TAG_module:
10595 parent_type = read_type_die (parent, cu);
10596 if (TYPE_TAG_NAME (parent_type) != NULL)
10597 return TYPE_TAG_NAME (parent_type);
10599 /* An anonymous structure is only allowed non-static data
10600 members; no typedefs, no member functions, et cetera.
10601 So it does not need a prefix. */
10604 return determine_prefix (parent, cu);
10608 /* Return a newly-allocated string formed by concatenating PREFIX and
10609 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
10610 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
10611 perform an obconcat, otherwise allocate storage for the result. The CU argument
10612 is used to determine the language and hence, the appropriate separator. */
10614 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
10617 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
10618 int physname, struct dwarf2_cu *cu)
10620 const char *lead = "";
10623 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
10625 else if (cu->language == language_java)
10627 else if (cu->language == language_fortran && physname)
10629 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
10630 DW_AT_MIPS_linkage_name is preferred and used instead. */
10638 if (prefix == NULL)
10640 if (suffix == NULL)
10645 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
10647 strcpy (retval, lead);
10648 strcat (retval, prefix);
10649 strcat (retval, sep);
10650 strcat (retval, suffix);
10655 /* We have an obstack. */
10656 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
10660 /* Return sibling of die, NULL if no sibling. */
10662 static struct die_info *
10663 sibling_die (struct die_info *die)
10665 return die->sibling;
10668 /* Get name of a die, return NULL if not found. */
10671 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
10672 struct obstack *obstack)
10674 if (name && cu->language == language_cplus)
10676 char *canon_name = cp_canonicalize_string (name);
10678 if (canon_name != NULL)
10680 if (strcmp (canon_name, name) != 0)
10681 name = obsavestring (canon_name, strlen (canon_name),
10683 xfree (canon_name);
10690 /* Get name of a die, return NULL if not found. */
10693 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
10695 struct attribute *attr;
10697 attr = dwarf2_attr (die, DW_AT_name, cu);
10698 if (!attr || !DW_STRING (attr))
10703 case DW_TAG_compile_unit:
10704 /* Compilation units have a DW_AT_name that is a filename, not
10705 a source language identifier. */
10706 case DW_TAG_enumeration_type:
10707 case DW_TAG_enumerator:
10708 /* These tags always have simple identifiers already; no need
10709 to canonicalize them. */
10710 return DW_STRING (attr);
10712 case DW_TAG_subprogram:
10713 /* Java constructors will all be named "<init>", so return
10714 the class name when we see this special case. */
10715 if (cu->language == language_java
10716 && DW_STRING (attr) != NULL
10717 && strcmp (DW_STRING (attr), "<init>") == 0)
10719 struct dwarf2_cu *spec_cu = cu;
10720 struct die_info *spec_die;
10722 /* GCJ will output '<init>' for Java constructor names.
10723 For this special case, return the name of the parent class. */
10725 /* GCJ may output suprogram DIEs with AT_specification set.
10726 If so, use the name of the specified DIE. */
10727 spec_die = die_specification (die, &spec_cu);
10728 if (spec_die != NULL)
10729 return dwarf2_name (spec_die, spec_cu);
10734 if (die->tag == DW_TAG_class_type)
10735 return dwarf2_name (die, cu);
10737 while (die->tag != DW_TAG_compile_unit);
10741 case DW_TAG_class_type:
10742 case DW_TAG_interface_type:
10743 case DW_TAG_structure_type:
10744 case DW_TAG_union_type:
10745 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
10746 structures or unions. These were of the form "._%d" in GCC 4.1,
10747 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
10748 and GCC 4.4. We work around this problem by ignoring these. */
10749 if (strncmp (DW_STRING (attr), "._", 2) == 0
10750 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
10758 if (!DW_STRING_IS_CANONICAL (attr))
10761 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
10762 &cu->objfile->objfile_obstack);
10763 DW_STRING_IS_CANONICAL (attr) = 1;
10765 return DW_STRING (attr);
10768 /* Return the die that this die in an extension of, or NULL if there
10769 is none. *EXT_CU is the CU containing DIE on input, and the CU
10770 containing the return value on output. */
10772 static struct die_info *
10773 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
10775 struct attribute *attr;
10777 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
10781 return follow_die_ref (die, attr, ext_cu);
10784 /* Convert a DIE tag into its string name. */
10787 dwarf_tag_name (unsigned tag)
10791 case DW_TAG_padding:
10792 return "DW_TAG_padding";
10793 case DW_TAG_array_type:
10794 return "DW_TAG_array_type";
10795 case DW_TAG_class_type:
10796 return "DW_TAG_class_type";
10797 case DW_TAG_entry_point:
10798 return "DW_TAG_entry_point";
10799 case DW_TAG_enumeration_type:
10800 return "DW_TAG_enumeration_type";
10801 case DW_TAG_formal_parameter:
10802 return "DW_TAG_formal_parameter";
10803 case DW_TAG_imported_declaration:
10804 return "DW_TAG_imported_declaration";
10806 return "DW_TAG_label";
10807 case DW_TAG_lexical_block:
10808 return "DW_TAG_lexical_block";
10809 case DW_TAG_member:
10810 return "DW_TAG_member";
10811 case DW_TAG_pointer_type:
10812 return "DW_TAG_pointer_type";
10813 case DW_TAG_reference_type:
10814 return "DW_TAG_reference_type";
10815 case DW_TAG_compile_unit:
10816 return "DW_TAG_compile_unit";
10817 case DW_TAG_string_type:
10818 return "DW_TAG_string_type";
10819 case DW_TAG_structure_type:
10820 return "DW_TAG_structure_type";
10821 case DW_TAG_subroutine_type:
10822 return "DW_TAG_subroutine_type";
10823 case DW_TAG_typedef:
10824 return "DW_TAG_typedef";
10825 case DW_TAG_union_type:
10826 return "DW_TAG_union_type";
10827 case DW_TAG_unspecified_parameters:
10828 return "DW_TAG_unspecified_parameters";
10829 case DW_TAG_variant:
10830 return "DW_TAG_variant";
10831 case DW_TAG_common_block:
10832 return "DW_TAG_common_block";
10833 case DW_TAG_common_inclusion:
10834 return "DW_TAG_common_inclusion";
10835 case DW_TAG_inheritance:
10836 return "DW_TAG_inheritance";
10837 case DW_TAG_inlined_subroutine:
10838 return "DW_TAG_inlined_subroutine";
10839 case DW_TAG_module:
10840 return "DW_TAG_module";
10841 case DW_TAG_ptr_to_member_type:
10842 return "DW_TAG_ptr_to_member_type";
10843 case DW_TAG_set_type:
10844 return "DW_TAG_set_type";
10845 case DW_TAG_subrange_type:
10846 return "DW_TAG_subrange_type";
10847 case DW_TAG_with_stmt:
10848 return "DW_TAG_with_stmt";
10849 case DW_TAG_access_declaration:
10850 return "DW_TAG_access_declaration";
10851 case DW_TAG_base_type:
10852 return "DW_TAG_base_type";
10853 case DW_TAG_catch_block:
10854 return "DW_TAG_catch_block";
10855 case DW_TAG_const_type:
10856 return "DW_TAG_const_type";
10857 case DW_TAG_constant:
10858 return "DW_TAG_constant";
10859 case DW_TAG_enumerator:
10860 return "DW_TAG_enumerator";
10861 case DW_TAG_file_type:
10862 return "DW_TAG_file_type";
10863 case DW_TAG_friend:
10864 return "DW_TAG_friend";
10865 case DW_TAG_namelist:
10866 return "DW_TAG_namelist";
10867 case DW_TAG_namelist_item:
10868 return "DW_TAG_namelist_item";
10869 case DW_TAG_packed_type:
10870 return "DW_TAG_packed_type";
10871 case DW_TAG_subprogram:
10872 return "DW_TAG_subprogram";
10873 case DW_TAG_template_type_param:
10874 return "DW_TAG_template_type_param";
10875 case DW_TAG_template_value_param:
10876 return "DW_TAG_template_value_param";
10877 case DW_TAG_thrown_type:
10878 return "DW_TAG_thrown_type";
10879 case DW_TAG_try_block:
10880 return "DW_TAG_try_block";
10881 case DW_TAG_variant_part:
10882 return "DW_TAG_variant_part";
10883 case DW_TAG_variable:
10884 return "DW_TAG_variable";
10885 case DW_TAG_volatile_type:
10886 return "DW_TAG_volatile_type";
10887 case DW_TAG_dwarf_procedure:
10888 return "DW_TAG_dwarf_procedure";
10889 case DW_TAG_restrict_type:
10890 return "DW_TAG_restrict_type";
10891 case DW_TAG_interface_type:
10892 return "DW_TAG_interface_type";
10893 case DW_TAG_namespace:
10894 return "DW_TAG_namespace";
10895 case DW_TAG_imported_module:
10896 return "DW_TAG_imported_module";
10897 case DW_TAG_unspecified_type:
10898 return "DW_TAG_unspecified_type";
10899 case DW_TAG_partial_unit:
10900 return "DW_TAG_partial_unit";
10901 case DW_TAG_imported_unit:
10902 return "DW_TAG_imported_unit";
10903 case DW_TAG_condition:
10904 return "DW_TAG_condition";
10905 case DW_TAG_shared_type:
10906 return "DW_TAG_shared_type";
10907 case DW_TAG_type_unit:
10908 return "DW_TAG_type_unit";
10909 case DW_TAG_MIPS_loop:
10910 return "DW_TAG_MIPS_loop";
10911 case DW_TAG_HP_array_descriptor:
10912 return "DW_TAG_HP_array_descriptor";
10913 case DW_TAG_format_label:
10914 return "DW_TAG_format_label";
10915 case DW_TAG_function_template:
10916 return "DW_TAG_function_template";
10917 case DW_TAG_class_template:
10918 return "DW_TAG_class_template";
10919 case DW_TAG_GNU_BINCL:
10920 return "DW_TAG_GNU_BINCL";
10921 case DW_TAG_GNU_EINCL:
10922 return "DW_TAG_GNU_EINCL";
10923 case DW_TAG_upc_shared_type:
10924 return "DW_TAG_upc_shared_type";
10925 case DW_TAG_upc_strict_type:
10926 return "DW_TAG_upc_strict_type";
10927 case DW_TAG_upc_relaxed_type:
10928 return "DW_TAG_upc_relaxed_type";
10929 case DW_TAG_PGI_kanji_type:
10930 return "DW_TAG_PGI_kanji_type";
10931 case DW_TAG_PGI_interface_block:
10932 return "DW_TAG_PGI_interface_block";
10934 return "DW_TAG_<unknown>";
10938 /* Convert a DWARF attribute code into its string name. */
10941 dwarf_attr_name (unsigned attr)
10945 case DW_AT_sibling:
10946 return "DW_AT_sibling";
10947 case DW_AT_location:
10948 return "DW_AT_location";
10950 return "DW_AT_name";
10951 case DW_AT_ordering:
10952 return "DW_AT_ordering";
10953 case DW_AT_subscr_data:
10954 return "DW_AT_subscr_data";
10955 case DW_AT_byte_size:
10956 return "DW_AT_byte_size";
10957 case DW_AT_bit_offset:
10958 return "DW_AT_bit_offset";
10959 case DW_AT_bit_size:
10960 return "DW_AT_bit_size";
10961 case DW_AT_element_list:
10962 return "DW_AT_element_list";
10963 case DW_AT_stmt_list:
10964 return "DW_AT_stmt_list";
10966 return "DW_AT_low_pc";
10967 case DW_AT_high_pc:
10968 return "DW_AT_high_pc";
10969 case DW_AT_language:
10970 return "DW_AT_language";
10972 return "DW_AT_member";
10974 return "DW_AT_discr";
10975 case DW_AT_discr_value:
10976 return "DW_AT_discr_value";
10977 case DW_AT_visibility:
10978 return "DW_AT_visibility";
10980 return "DW_AT_import";
10981 case DW_AT_string_length:
10982 return "DW_AT_string_length";
10983 case DW_AT_common_reference:
10984 return "DW_AT_common_reference";
10985 case DW_AT_comp_dir:
10986 return "DW_AT_comp_dir";
10987 case DW_AT_const_value:
10988 return "DW_AT_const_value";
10989 case DW_AT_containing_type:
10990 return "DW_AT_containing_type";
10991 case DW_AT_default_value:
10992 return "DW_AT_default_value";
10994 return "DW_AT_inline";
10995 case DW_AT_is_optional:
10996 return "DW_AT_is_optional";
10997 case DW_AT_lower_bound:
10998 return "DW_AT_lower_bound";
10999 case DW_AT_producer:
11000 return "DW_AT_producer";
11001 case DW_AT_prototyped:
11002 return "DW_AT_prototyped";
11003 case DW_AT_return_addr:
11004 return "DW_AT_return_addr";
11005 case DW_AT_start_scope:
11006 return "DW_AT_start_scope";
11007 case DW_AT_bit_stride:
11008 return "DW_AT_bit_stride";
11009 case DW_AT_upper_bound:
11010 return "DW_AT_upper_bound";
11011 case DW_AT_abstract_origin:
11012 return "DW_AT_abstract_origin";
11013 case DW_AT_accessibility:
11014 return "DW_AT_accessibility";
11015 case DW_AT_address_class:
11016 return "DW_AT_address_class";
11017 case DW_AT_artificial:
11018 return "DW_AT_artificial";
11019 case DW_AT_base_types:
11020 return "DW_AT_base_types";
11021 case DW_AT_calling_convention:
11022 return "DW_AT_calling_convention";
11024 return "DW_AT_count";
11025 case DW_AT_data_member_location:
11026 return "DW_AT_data_member_location";
11027 case DW_AT_decl_column:
11028 return "DW_AT_decl_column";
11029 case DW_AT_decl_file:
11030 return "DW_AT_decl_file";
11031 case DW_AT_decl_line:
11032 return "DW_AT_decl_line";
11033 case DW_AT_declaration:
11034 return "DW_AT_declaration";
11035 case DW_AT_discr_list:
11036 return "DW_AT_discr_list";
11037 case DW_AT_encoding:
11038 return "DW_AT_encoding";
11039 case DW_AT_external:
11040 return "DW_AT_external";
11041 case DW_AT_frame_base:
11042 return "DW_AT_frame_base";
11044 return "DW_AT_friend";
11045 case DW_AT_identifier_case:
11046 return "DW_AT_identifier_case";
11047 case DW_AT_macro_info:
11048 return "DW_AT_macro_info";
11049 case DW_AT_namelist_items:
11050 return "DW_AT_namelist_items";
11051 case DW_AT_priority:
11052 return "DW_AT_priority";
11053 case DW_AT_segment:
11054 return "DW_AT_segment";
11055 case DW_AT_specification:
11056 return "DW_AT_specification";
11057 case DW_AT_static_link:
11058 return "DW_AT_static_link";
11060 return "DW_AT_type";
11061 case DW_AT_use_location:
11062 return "DW_AT_use_location";
11063 case DW_AT_variable_parameter:
11064 return "DW_AT_variable_parameter";
11065 case DW_AT_virtuality:
11066 return "DW_AT_virtuality";
11067 case DW_AT_vtable_elem_location:
11068 return "DW_AT_vtable_elem_location";
11069 /* DWARF 3 values. */
11070 case DW_AT_allocated:
11071 return "DW_AT_allocated";
11072 case DW_AT_associated:
11073 return "DW_AT_associated";
11074 case DW_AT_data_location:
11075 return "DW_AT_data_location";
11076 case DW_AT_byte_stride:
11077 return "DW_AT_byte_stride";
11078 case DW_AT_entry_pc:
11079 return "DW_AT_entry_pc";
11080 case DW_AT_use_UTF8:
11081 return "DW_AT_use_UTF8";
11082 case DW_AT_extension:
11083 return "DW_AT_extension";
11085 return "DW_AT_ranges";
11086 case DW_AT_trampoline:
11087 return "DW_AT_trampoline";
11088 case DW_AT_call_column:
11089 return "DW_AT_call_column";
11090 case DW_AT_call_file:
11091 return "DW_AT_call_file";
11092 case DW_AT_call_line:
11093 return "DW_AT_call_line";
11094 case DW_AT_description:
11095 return "DW_AT_description";
11096 case DW_AT_binary_scale:
11097 return "DW_AT_binary_scale";
11098 case DW_AT_decimal_scale:
11099 return "DW_AT_decimal_scale";
11101 return "DW_AT_small";
11102 case DW_AT_decimal_sign:
11103 return "DW_AT_decimal_sign";
11104 case DW_AT_digit_count:
11105 return "DW_AT_digit_count";
11106 case DW_AT_picture_string:
11107 return "DW_AT_picture_string";
11108 case DW_AT_mutable:
11109 return "DW_AT_mutable";
11110 case DW_AT_threads_scaled:
11111 return "DW_AT_threads_scaled";
11112 case DW_AT_explicit:
11113 return "DW_AT_explicit";
11114 case DW_AT_object_pointer:
11115 return "DW_AT_object_pointer";
11116 case DW_AT_endianity:
11117 return "DW_AT_endianity";
11118 case DW_AT_elemental:
11119 return "DW_AT_elemental";
11121 return "DW_AT_pure";
11122 case DW_AT_recursive:
11123 return "DW_AT_recursive";
11124 /* DWARF 4 values. */
11125 case DW_AT_signature:
11126 return "DW_AT_signature";
11127 case DW_AT_linkage_name:
11128 return "DW_AT_linkage_name";
11129 /* SGI/MIPS extensions. */
11130 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11131 case DW_AT_MIPS_fde:
11132 return "DW_AT_MIPS_fde";
11134 case DW_AT_MIPS_loop_begin:
11135 return "DW_AT_MIPS_loop_begin";
11136 case DW_AT_MIPS_tail_loop_begin:
11137 return "DW_AT_MIPS_tail_loop_begin";
11138 case DW_AT_MIPS_epilog_begin:
11139 return "DW_AT_MIPS_epilog_begin";
11140 case DW_AT_MIPS_loop_unroll_factor:
11141 return "DW_AT_MIPS_loop_unroll_factor";
11142 case DW_AT_MIPS_software_pipeline_depth:
11143 return "DW_AT_MIPS_software_pipeline_depth";
11144 case DW_AT_MIPS_linkage_name:
11145 return "DW_AT_MIPS_linkage_name";
11146 case DW_AT_MIPS_stride:
11147 return "DW_AT_MIPS_stride";
11148 case DW_AT_MIPS_abstract_name:
11149 return "DW_AT_MIPS_abstract_name";
11150 case DW_AT_MIPS_clone_origin:
11151 return "DW_AT_MIPS_clone_origin";
11152 case DW_AT_MIPS_has_inlines:
11153 return "DW_AT_MIPS_has_inlines";
11154 /* HP extensions. */
11155 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11156 case DW_AT_HP_block_index:
11157 return "DW_AT_HP_block_index";
11159 case DW_AT_HP_unmodifiable:
11160 return "DW_AT_HP_unmodifiable";
11161 case DW_AT_HP_actuals_stmt_list:
11162 return "DW_AT_HP_actuals_stmt_list";
11163 case DW_AT_HP_proc_per_section:
11164 return "DW_AT_HP_proc_per_section";
11165 case DW_AT_HP_raw_data_ptr:
11166 return "DW_AT_HP_raw_data_ptr";
11167 case DW_AT_HP_pass_by_reference:
11168 return "DW_AT_HP_pass_by_reference";
11169 case DW_AT_HP_opt_level:
11170 return "DW_AT_HP_opt_level";
11171 case DW_AT_HP_prof_version_id:
11172 return "DW_AT_HP_prof_version_id";
11173 case DW_AT_HP_opt_flags:
11174 return "DW_AT_HP_opt_flags";
11175 case DW_AT_HP_cold_region_low_pc:
11176 return "DW_AT_HP_cold_region_low_pc";
11177 case DW_AT_HP_cold_region_high_pc:
11178 return "DW_AT_HP_cold_region_high_pc";
11179 case DW_AT_HP_all_variables_modifiable:
11180 return "DW_AT_HP_all_variables_modifiable";
11181 case DW_AT_HP_linkage_name:
11182 return "DW_AT_HP_linkage_name";
11183 case DW_AT_HP_prof_flags:
11184 return "DW_AT_HP_prof_flags";
11185 /* GNU extensions. */
11186 case DW_AT_sf_names:
11187 return "DW_AT_sf_names";
11188 case DW_AT_src_info:
11189 return "DW_AT_src_info";
11190 case DW_AT_mac_info:
11191 return "DW_AT_mac_info";
11192 case DW_AT_src_coords:
11193 return "DW_AT_src_coords";
11194 case DW_AT_body_begin:
11195 return "DW_AT_body_begin";
11196 case DW_AT_body_end:
11197 return "DW_AT_body_end";
11198 case DW_AT_GNU_vector:
11199 return "DW_AT_GNU_vector";
11200 /* VMS extensions. */
11201 case DW_AT_VMS_rtnbeg_pd_address:
11202 return "DW_AT_VMS_rtnbeg_pd_address";
11203 /* UPC extension. */
11204 case DW_AT_upc_threads_scaled:
11205 return "DW_AT_upc_threads_scaled";
11206 /* PGI (STMicroelectronics) extensions. */
11207 case DW_AT_PGI_lbase:
11208 return "DW_AT_PGI_lbase";
11209 case DW_AT_PGI_soffset:
11210 return "DW_AT_PGI_soffset";
11211 case DW_AT_PGI_lstride:
11212 return "DW_AT_PGI_lstride";
11214 return "DW_AT_<unknown>";
11218 /* Convert a DWARF value form code into its string name. */
11221 dwarf_form_name (unsigned form)
11226 return "DW_FORM_addr";
11227 case DW_FORM_block2:
11228 return "DW_FORM_block2";
11229 case DW_FORM_block4:
11230 return "DW_FORM_block4";
11231 case DW_FORM_data2:
11232 return "DW_FORM_data2";
11233 case DW_FORM_data4:
11234 return "DW_FORM_data4";
11235 case DW_FORM_data8:
11236 return "DW_FORM_data8";
11237 case DW_FORM_string:
11238 return "DW_FORM_string";
11239 case DW_FORM_block:
11240 return "DW_FORM_block";
11241 case DW_FORM_block1:
11242 return "DW_FORM_block1";
11243 case DW_FORM_data1:
11244 return "DW_FORM_data1";
11246 return "DW_FORM_flag";
11247 case DW_FORM_sdata:
11248 return "DW_FORM_sdata";
11250 return "DW_FORM_strp";
11251 case DW_FORM_udata:
11252 return "DW_FORM_udata";
11253 case DW_FORM_ref_addr:
11254 return "DW_FORM_ref_addr";
11256 return "DW_FORM_ref1";
11258 return "DW_FORM_ref2";
11260 return "DW_FORM_ref4";
11262 return "DW_FORM_ref8";
11263 case DW_FORM_ref_udata:
11264 return "DW_FORM_ref_udata";
11265 case DW_FORM_indirect:
11266 return "DW_FORM_indirect";
11267 case DW_FORM_sec_offset:
11268 return "DW_FORM_sec_offset";
11269 case DW_FORM_exprloc:
11270 return "DW_FORM_exprloc";
11271 case DW_FORM_flag_present:
11272 return "DW_FORM_flag_present";
11274 return "DW_FORM_sig8";
11276 return "DW_FORM_<unknown>";
11280 /* Convert a DWARF stack opcode into its string name. */
11283 dwarf_stack_op_name (unsigned op, int def)
11288 return "DW_OP_addr";
11290 return "DW_OP_deref";
11291 case DW_OP_const1u:
11292 return "DW_OP_const1u";
11293 case DW_OP_const1s:
11294 return "DW_OP_const1s";
11295 case DW_OP_const2u:
11296 return "DW_OP_const2u";
11297 case DW_OP_const2s:
11298 return "DW_OP_const2s";
11299 case DW_OP_const4u:
11300 return "DW_OP_const4u";
11301 case DW_OP_const4s:
11302 return "DW_OP_const4s";
11303 case DW_OP_const8u:
11304 return "DW_OP_const8u";
11305 case DW_OP_const8s:
11306 return "DW_OP_const8s";
11308 return "DW_OP_constu";
11310 return "DW_OP_consts";
11312 return "DW_OP_dup";
11314 return "DW_OP_drop";
11316 return "DW_OP_over";
11318 return "DW_OP_pick";
11320 return "DW_OP_swap";
11322 return "DW_OP_rot";
11324 return "DW_OP_xderef";
11326 return "DW_OP_abs";
11328 return "DW_OP_and";
11330 return "DW_OP_div";
11332 return "DW_OP_minus";
11334 return "DW_OP_mod";
11336 return "DW_OP_mul";
11338 return "DW_OP_neg";
11340 return "DW_OP_not";
11344 return "DW_OP_plus";
11345 case DW_OP_plus_uconst:
11346 return "DW_OP_plus_uconst";
11348 return "DW_OP_shl";
11350 return "DW_OP_shr";
11352 return "DW_OP_shra";
11354 return "DW_OP_xor";
11356 return "DW_OP_bra";
11370 return "DW_OP_skip";
11372 return "DW_OP_lit0";
11374 return "DW_OP_lit1";
11376 return "DW_OP_lit2";
11378 return "DW_OP_lit3";
11380 return "DW_OP_lit4";
11382 return "DW_OP_lit5";
11384 return "DW_OP_lit6";
11386 return "DW_OP_lit7";
11388 return "DW_OP_lit8";
11390 return "DW_OP_lit9";
11392 return "DW_OP_lit10";
11394 return "DW_OP_lit11";
11396 return "DW_OP_lit12";
11398 return "DW_OP_lit13";
11400 return "DW_OP_lit14";
11402 return "DW_OP_lit15";
11404 return "DW_OP_lit16";
11406 return "DW_OP_lit17";
11408 return "DW_OP_lit18";
11410 return "DW_OP_lit19";
11412 return "DW_OP_lit20";
11414 return "DW_OP_lit21";
11416 return "DW_OP_lit22";
11418 return "DW_OP_lit23";
11420 return "DW_OP_lit24";
11422 return "DW_OP_lit25";
11424 return "DW_OP_lit26";
11426 return "DW_OP_lit27";
11428 return "DW_OP_lit28";
11430 return "DW_OP_lit29";
11432 return "DW_OP_lit30";
11434 return "DW_OP_lit31";
11436 return "DW_OP_reg0";
11438 return "DW_OP_reg1";
11440 return "DW_OP_reg2";
11442 return "DW_OP_reg3";
11444 return "DW_OP_reg4";
11446 return "DW_OP_reg5";
11448 return "DW_OP_reg6";
11450 return "DW_OP_reg7";
11452 return "DW_OP_reg8";
11454 return "DW_OP_reg9";
11456 return "DW_OP_reg10";
11458 return "DW_OP_reg11";
11460 return "DW_OP_reg12";
11462 return "DW_OP_reg13";
11464 return "DW_OP_reg14";
11466 return "DW_OP_reg15";
11468 return "DW_OP_reg16";
11470 return "DW_OP_reg17";
11472 return "DW_OP_reg18";
11474 return "DW_OP_reg19";
11476 return "DW_OP_reg20";
11478 return "DW_OP_reg21";
11480 return "DW_OP_reg22";
11482 return "DW_OP_reg23";
11484 return "DW_OP_reg24";
11486 return "DW_OP_reg25";
11488 return "DW_OP_reg26";
11490 return "DW_OP_reg27";
11492 return "DW_OP_reg28";
11494 return "DW_OP_reg29";
11496 return "DW_OP_reg30";
11498 return "DW_OP_reg31";
11500 return "DW_OP_breg0";
11502 return "DW_OP_breg1";
11504 return "DW_OP_breg2";
11506 return "DW_OP_breg3";
11508 return "DW_OP_breg4";
11510 return "DW_OP_breg5";
11512 return "DW_OP_breg6";
11514 return "DW_OP_breg7";
11516 return "DW_OP_breg8";
11518 return "DW_OP_breg9";
11520 return "DW_OP_breg10";
11522 return "DW_OP_breg11";
11524 return "DW_OP_breg12";
11526 return "DW_OP_breg13";
11528 return "DW_OP_breg14";
11530 return "DW_OP_breg15";
11532 return "DW_OP_breg16";
11534 return "DW_OP_breg17";
11536 return "DW_OP_breg18";
11538 return "DW_OP_breg19";
11540 return "DW_OP_breg20";
11542 return "DW_OP_breg21";
11544 return "DW_OP_breg22";
11546 return "DW_OP_breg23";
11548 return "DW_OP_breg24";
11550 return "DW_OP_breg25";
11552 return "DW_OP_breg26";
11554 return "DW_OP_breg27";
11556 return "DW_OP_breg28";
11558 return "DW_OP_breg29";
11560 return "DW_OP_breg30";
11562 return "DW_OP_breg31";
11564 return "DW_OP_regx";
11566 return "DW_OP_fbreg";
11568 return "DW_OP_bregx";
11570 return "DW_OP_piece";
11571 case DW_OP_deref_size:
11572 return "DW_OP_deref_size";
11573 case DW_OP_xderef_size:
11574 return "DW_OP_xderef_size";
11576 return "DW_OP_nop";
11577 /* DWARF 3 extensions. */
11578 case DW_OP_push_object_address:
11579 return "DW_OP_push_object_address";
11581 return "DW_OP_call2";
11583 return "DW_OP_call4";
11584 case DW_OP_call_ref:
11585 return "DW_OP_call_ref";
11586 case DW_OP_form_tls_address:
11587 return "DW_OP_form_tls_address";
11588 case DW_OP_call_frame_cfa:
11589 return "DW_OP_call_frame_cfa";
11590 case DW_OP_bit_piece:
11591 return "DW_OP_bit_piece";
11592 /* DWARF 4 extensions. */
11593 case DW_OP_implicit_value:
11594 return "DW_OP_implicit_value";
11595 case DW_OP_stack_value:
11596 return "DW_OP_stack_value";
11597 /* GNU extensions. */
11598 case DW_OP_GNU_push_tls_address:
11599 return "DW_OP_GNU_push_tls_address";
11600 case DW_OP_GNU_uninit:
11601 return "DW_OP_GNU_uninit";
11603 return def ? "OP_<unknown>" : NULL;
11608 dwarf_bool_name (unsigned mybool)
11616 /* Convert a DWARF type code into its string name. */
11619 dwarf_type_encoding_name (unsigned enc)
11624 return "DW_ATE_void";
11625 case DW_ATE_address:
11626 return "DW_ATE_address";
11627 case DW_ATE_boolean:
11628 return "DW_ATE_boolean";
11629 case DW_ATE_complex_float:
11630 return "DW_ATE_complex_float";
11632 return "DW_ATE_float";
11633 case DW_ATE_signed:
11634 return "DW_ATE_signed";
11635 case DW_ATE_signed_char:
11636 return "DW_ATE_signed_char";
11637 case DW_ATE_unsigned:
11638 return "DW_ATE_unsigned";
11639 case DW_ATE_unsigned_char:
11640 return "DW_ATE_unsigned_char";
11642 case DW_ATE_imaginary_float:
11643 return "DW_ATE_imaginary_float";
11644 case DW_ATE_packed_decimal:
11645 return "DW_ATE_packed_decimal";
11646 case DW_ATE_numeric_string:
11647 return "DW_ATE_numeric_string";
11648 case DW_ATE_edited:
11649 return "DW_ATE_edited";
11650 case DW_ATE_signed_fixed:
11651 return "DW_ATE_signed_fixed";
11652 case DW_ATE_unsigned_fixed:
11653 return "DW_ATE_unsigned_fixed";
11654 case DW_ATE_decimal_float:
11655 return "DW_ATE_decimal_float";
11658 return "DW_ATE_UTF";
11659 /* HP extensions. */
11660 case DW_ATE_HP_float80:
11661 return "DW_ATE_HP_float80";
11662 case DW_ATE_HP_complex_float80:
11663 return "DW_ATE_HP_complex_float80";
11664 case DW_ATE_HP_float128:
11665 return "DW_ATE_HP_float128";
11666 case DW_ATE_HP_complex_float128:
11667 return "DW_ATE_HP_complex_float128";
11668 case DW_ATE_HP_floathpintel:
11669 return "DW_ATE_HP_floathpintel";
11670 case DW_ATE_HP_imaginary_float80:
11671 return "DW_ATE_HP_imaginary_float80";
11672 case DW_ATE_HP_imaginary_float128:
11673 return "DW_ATE_HP_imaginary_float128";
11675 return "DW_ATE_<unknown>";
11679 /* Convert a DWARF call frame info operation to its string name. */
11683 dwarf_cfi_name (unsigned cfi_opc)
11687 case DW_CFA_advance_loc:
11688 return "DW_CFA_advance_loc";
11689 case DW_CFA_offset:
11690 return "DW_CFA_offset";
11691 case DW_CFA_restore:
11692 return "DW_CFA_restore";
11694 return "DW_CFA_nop";
11695 case DW_CFA_set_loc:
11696 return "DW_CFA_set_loc";
11697 case DW_CFA_advance_loc1:
11698 return "DW_CFA_advance_loc1";
11699 case DW_CFA_advance_loc2:
11700 return "DW_CFA_advance_loc2";
11701 case DW_CFA_advance_loc4:
11702 return "DW_CFA_advance_loc4";
11703 case DW_CFA_offset_extended:
11704 return "DW_CFA_offset_extended";
11705 case DW_CFA_restore_extended:
11706 return "DW_CFA_restore_extended";
11707 case DW_CFA_undefined:
11708 return "DW_CFA_undefined";
11709 case DW_CFA_same_value:
11710 return "DW_CFA_same_value";
11711 case DW_CFA_register:
11712 return "DW_CFA_register";
11713 case DW_CFA_remember_state:
11714 return "DW_CFA_remember_state";
11715 case DW_CFA_restore_state:
11716 return "DW_CFA_restore_state";
11717 case DW_CFA_def_cfa:
11718 return "DW_CFA_def_cfa";
11719 case DW_CFA_def_cfa_register:
11720 return "DW_CFA_def_cfa_register";
11721 case DW_CFA_def_cfa_offset:
11722 return "DW_CFA_def_cfa_offset";
11724 case DW_CFA_def_cfa_expression:
11725 return "DW_CFA_def_cfa_expression";
11726 case DW_CFA_expression:
11727 return "DW_CFA_expression";
11728 case DW_CFA_offset_extended_sf:
11729 return "DW_CFA_offset_extended_sf";
11730 case DW_CFA_def_cfa_sf:
11731 return "DW_CFA_def_cfa_sf";
11732 case DW_CFA_def_cfa_offset_sf:
11733 return "DW_CFA_def_cfa_offset_sf";
11734 case DW_CFA_val_offset:
11735 return "DW_CFA_val_offset";
11736 case DW_CFA_val_offset_sf:
11737 return "DW_CFA_val_offset_sf";
11738 case DW_CFA_val_expression:
11739 return "DW_CFA_val_expression";
11740 /* SGI/MIPS specific. */
11741 case DW_CFA_MIPS_advance_loc8:
11742 return "DW_CFA_MIPS_advance_loc8";
11743 /* GNU extensions. */
11744 case DW_CFA_GNU_window_save:
11745 return "DW_CFA_GNU_window_save";
11746 case DW_CFA_GNU_args_size:
11747 return "DW_CFA_GNU_args_size";
11748 case DW_CFA_GNU_negative_offset_extended:
11749 return "DW_CFA_GNU_negative_offset_extended";
11751 return "DW_CFA_<unknown>";
11757 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
11761 print_spaces (indent, f);
11762 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
11763 dwarf_tag_name (die->tag), die->abbrev, die->offset);
11765 if (die->parent != NULL)
11767 print_spaces (indent, f);
11768 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
11769 die->parent->offset);
11772 print_spaces (indent, f);
11773 fprintf_unfiltered (f, " has children: %s\n",
11774 dwarf_bool_name (die->child != NULL));
11776 print_spaces (indent, f);
11777 fprintf_unfiltered (f, " attributes:\n");
11779 for (i = 0; i < die->num_attrs; ++i)
11781 print_spaces (indent, f);
11782 fprintf_unfiltered (f, " %s (%s) ",
11783 dwarf_attr_name (die->attrs[i].name),
11784 dwarf_form_name (die->attrs[i].form));
11786 switch (die->attrs[i].form)
11788 case DW_FORM_ref_addr:
11790 fprintf_unfiltered (f, "address: ");
11791 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
11793 case DW_FORM_block2:
11794 case DW_FORM_block4:
11795 case DW_FORM_block:
11796 case DW_FORM_block1:
11797 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
11799 case DW_FORM_exprloc:
11800 fprintf_unfiltered (f, "expression: size %u",
11801 DW_BLOCK (&die->attrs[i])->size);
11806 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
11807 (long) (DW_ADDR (&die->attrs[i])));
11809 case DW_FORM_data1:
11810 case DW_FORM_data2:
11811 case DW_FORM_data4:
11812 case DW_FORM_data8:
11813 case DW_FORM_udata:
11814 case DW_FORM_sdata:
11815 fprintf_unfiltered (f, "constant: %s",
11816 pulongest (DW_UNSND (&die->attrs[i])));
11818 case DW_FORM_sec_offset:
11819 fprintf_unfiltered (f, "section offset: %s",
11820 pulongest (DW_UNSND (&die->attrs[i])));
11823 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
11824 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
11825 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
11827 fprintf_unfiltered (f, "signatured type, offset: unknown");
11829 case DW_FORM_string:
11831 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
11832 DW_STRING (&die->attrs[i])
11833 ? DW_STRING (&die->attrs[i]) : "",
11834 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
11837 if (DW_UNSND (&die->attrs[i]))
11838 fprintf_unfiltered (f, "flag: TRUE");
11840 fprintf_unfiltered (f, "flag: FALSE");
11842 case DW_FORM_flag_present:
11843 fprintf_unfiltered (f, "flag: TRUE");
11845 case DW_FORM_indirect:
11846 /* the reader will have reduced the indirect form to
11847 the "base form" so this form should not occur */
11848 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
11851 fprintf_unfiltered (f, "unsupported attribute form: %d.",
11852 die->attrs[i].form);
11855 fprintf_unfiltered (f, "\n");
11860 dump_die_for_error (struct die_info *die)
11862 dump_die_shallow (gdb_stderr, 0, die);
11866 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
11868 int indent = level * 4;
11870 gdb_assert (die != NULL);
11872 if (level >= max_level)
11875 dump_die_shallow (f, indent, die);
11877 if (die->child != NULL)
11879 print_spaces (indent, f);
11880 fprintf_unfiltered (f, " Children:");
11881 if (level + 1 < max_level)
11883 fprintf_unfiltered (f, "\n");
11884 dump_die_1 (f, level + 1, max_level, die->child);
11888 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
11892 if (die->sibling != NULL && level > 0)
11894 dump_die_1 (f, level, max_level, die->sibling);
11898 /* This is called from the pdie macro in gdbinit.in.
11899 It's not static so gcc will keep a copy callable from gdb. */
11902 dump_die (struct die_info *die, int max_level)
11904 dump_die_1 (gdb_stdlog, 0, max_level, die);
11908 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
11912 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
11918 is_ref_attr (struct attribute *attr)
11920 switch (attr->form)
11922 case DW_FORM_ref_addr:
11927 case DW_FORM_ref_udata:
11934 static unsigned int
11935 dwarf2_get_ref_die_offset (struct attribute *attr)
11937 if (is_ref_attr (attr))
11938 return DW_ADDR (attr);
11940 complaint (&symfile_complaints,
11941 _("unsupported die ref attribute form: '%s'"),
11942 dwarf_form_name (attr->form));
11946 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
11947 * the value held by the attribute is not constant. */
11950 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
11952 if (attr->form == DW_FORM_sdata)
11953 return DW_SND (attr);
11954 else if (attr->form == DW_FORM_udata
11955 || attr->form == DW_FORM_data1
11956 || attr->form == DW_FORM_data2
11957 || attr->form == DW_FORM_data4
11958 || attr->form == DW_FORM_data8)
11959 return DW_UNSND (attr);
11962 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
11963 dwarf_form_name (attr->form));
11964 return default_value;
11968 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
11969 unit and add it to our queue.
11970 The result is non-zero if PER_CU was queued, otherwise the result is zero
11971 meaning either PER_CU is already queued or it is already loaded. */
11974 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
11975 struct dwarf2_per_cu_data *per_cu)
11977 /* Mark the dependence relation so that we don't flush PER_CU
11979 dwarf2_add_dependence (this_cu, per_cu);
11981 /* If it's already on the queue, we have nothing to do. */
11982 if (per_cu->queued)
11985 /* If the compilation unit is already loaded, just mark it as
11987 if (per_cu->cu != NULL)
11989 per_cu->cu->last_used = 0;
11993 /* Add it to the queue. */
11994 queue_comp_unit (per_cu, this_cu->objfile);
11999 /* Follow reference or signature attribute ATTR of SRC_DIE.
12000 On entry *REF_CU is the CU of SRC_DIE.
12001 On exit *REF_CU is the CU of the result. */
12003 static struct die_info *
12004 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
12005 struct dwarf2_cu **ref_cu)
12007 struct die_info *die;
12009 if (is_ref_attr (attr))
12010 die = follow_die_ref (src_die, attr, ref_cu);
12011 else if (attr->form == DW_FORM_sig8)
12012 die = follow_die_sig (src_die, attr, ref_cu);
12015 dump_die_for_error (src_die);
12016 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12017 (*ref_cu)->objfile->name);
12023 /* Follow reference OFFSET.
12024 On entry *REF_CU is the CU of source DIE referencing OFFSET.
12025 On exit *REF_CU is the CU of the result. */
12027 static struct die_info *
12028 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
12030 struct die_info temp_die;
12031 struct dwarf2_cu *target_cu, *cu = *ref_cu;
12033 gdb_assert (cu->per_cu != NULL);
12035 if (cu->per_cu->from_debug_types)
12037 /* .debug_types CUs cannot reference anything outside their CU.
12038 If they need to, they have to reference a signatured type via
12040 if (! offset_in_cu_p (&cu->header, offset))
12044 else if (! offset_in_cu_p (&cu->header, offset))
12046 struct dwarf2_per_cu_data *per_cu;
12048 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
12050 /* If necessary, add it to the queue and load its DIEs. */
12051 if (maybe_queue_comp_unit (cu, per_cu))
12052 load_full_comp_unit (per_cu, cu->objfile);
12054 target_cu = per_cu->cu;
12059 *ref_cu = target_cu;
12060 temp_die.offset = offset;
12061 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
12064 /* Follow reference attribute ATTR of SRC_DIE.
12065 On entry *REF_CU is the CU of SRC_DIE.
12066 On exit *REF_CU is the CU of the result. */
12068 static struct die_info *
12069 follow_die_ref (struct die_info *src_die, struct attribute *attr,
12070 struct dwarf2_cu **ref_cu)
12072 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12073 struct dwarf2_cu *cu = *ref_cu;
12074 struct die_info *die;
12076 die = follow_die_offset (offset, ref_cu);
12078 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12079 "at 0x%x [in module %s]"),
12080 offset, src_die->offset, cu->objfile->name);
12085 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12086 value is intended for DW_OP_call*. */
12088 struct dwarf2_locexpr_baton
12089 dwarf2_fetch_die_location_block (unsigned int offset,
12090 struct dwarf2_per_cu_data *per_cu)
12092 struct dwarf2_cu *cu = per_cu->cu;
12093 struct die_info *die;
12094 struct attribute *attr;
12095 struct dwarf2_locexpr_baton retval;
12097 die = follow_die_offset (offset, &cu);
12099 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12100 offset, per_cu->cu->objfile->name);
12102 attr = dwarf2_attr (die, DW_AT_location, cu);
12105 /* DWARF: "If there is no such attribute, then there is no effect.". */
12107 retval.data = NULL;
12112 if (!attr_form_is_block (attr))
12113 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12114 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12115 offset, per_cu->cu->objfile->name);
12117 retval.data = DW_BLOCK (attr)->data;
12118 retval.size = DW_BLOCK (attr)->size;
12120 retval.per_cu = cu->per_cu;
12124 /* Follow the signature attribute ATTR in SRC_DIE.
12125 On entry *REF_CU is the CU of SRC_DIE.
12126 On exit *REF_CU is the CU of the result. */
12128 static struct die_info *
12129 follow_die_sig (struct die_info *src_die, struct attribute *attr,
12130 struct dwarf2_cu **ref_cu)
12132 struct objfile *objfile = (*ref_cu)->objfile;
12133 struct die_info temp_die;
12134 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12135 struct dwarf2_cu *sig_cu;
12136 struct die_info *die;
12138 /* sig_type will be NULL if the signatured type is missing from
12140 if (sig_type == NULL)
12141 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12142 "at 0x%x [in module %s]"),
12143 src_die->offset, objfile->name);
12145 /* If necessary, add it to the queue and load its DIEs. */
12147 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
12148 read_signatured_type (objfile, sig_type);
12150 gdb_assert (sig_type->per_cu.cu != NULL);
12152 sig_cu = sig_type->per_cu.cu;
12153 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
12154 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
12161 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12162 "at 0x%x [in module %s]"),
12163 sig_type->type_offset, src_die->offset, objfile->name);
12166 /* Given an offset of a signatured type, return its signatured_type. */
12168 static struct signatured_type *
12169 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
12171 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
12172 unsigned int length, initial_length_size;
12173 unsigned int sig_offset;
12174 struct signatured_type find_entry, *type_sig;
12176 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
12177 sig_offset = (initial_length_size
12179 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
12180 + 1 /*address_size*/);
12181 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
12182 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
12184 /* This is only used to lookup previously recorded types.
12185 If we didn't find it, it's our bug. */
12186 gdb_assert (type_sig != NULL);
12187 gdb_assert (offset == type_sig->offset);
12192 /* Read in signatured type at OFFSET and build its CU and die(s). */
12195 read_signatured_type_at_offset (struct objfile *objfile,
12196 unsigned int offset)
12198 struct signatured_type *type_sig;
12200 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
12202 /* We have the section offset, but we need the signature to do the
12203 hash table lookup. */
12204 type_sig = lookup_signatured_type_at_offset (objfile, offset);
12206 gdb_assert (type_sig->per_cu.cu == NULL);
12208 read_signatured_type (objfile, type_sig);
12210 gdb_assert (type_sig->per_cu.cu != NULL);
12213 /* Read in a signatured type and build its CU and DIEs. */
12216 read_signatured_type (struct objfile *objfile,
12217 struct signatured_type *type_sig)
12219 gdb_byte *types_ptr;
12220 struct die_reader_specs reader_specs;
12221 struct dwarf2_cu *cu;
12222 ULONGEST signature;
12223 struct cleanup *back_to, *free_cu_cleanup;
12224 struct attribute *attr;
12226 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
12227 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
12229 gdb_assert (type_sig->per_cu.cu == NULL);
12231 cu = xmalloc (sizeof (struct dwarf2_cu));
12232 memset (cu, 0, sizeof (struct dwarf2_cu));
12233 obstack_init (&cu->comp_unit_obstack);
12234 cu->objfile = objfile;
12235 type_sig->per_cu.cu = cu;
12236 cu->per_cu = &type_sig->per_cu;
12238 /* If an error occurs while loading, release our storage. */
12239 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
12241 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
12242 types_ptr, objfile->obfd);
12243 gdb_assert (signature == type_sig->signature);
12246 = htab_create_alloc_ex (cu->header.length / 12,
12250 &cu->comp_unit_obstack,
12251 hashtab_obstack_allocate,
12252 dummy_obstack_deallocate);
12254 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
12255 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
12257 init_cu_die_reader (&reader_specs, cu);
12259 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
12262 /* We try not to read any attributes in this function, because not
12263 all objfiles needed for references have been loaded yet, and symbol
12264 table processing isn't initialized. But we have to set the CU language,
12265 or we won't be able to build types correctly. */
12266 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
12268 set_cu_language (DW_UNSND (attr), cu);
12270 set_cu_language (language_minimal, cu);
12272 do_cleanups (back_to);
12274 /* We've successfully allocated this compilation unit. Let our caller
12275 clean it up when finished with it. */
12276 discard_cleanups (free_cu_cleanup);
12278 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
12279 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
12282 /* Decode simple location descriptions.
12283 Given a pointer to a dwarf block that defines a location, compute
12284 the location and return the value.
12286 NOTE drow/2003-11-18: This function is called in two situations
12287 now: for the address of static or global variables (partial symbols
12288 only) and for offsets into structures which are expected to be
12289 (more or less) constant. The partial symbol case should go away,
12290 and only the constant case should remain. That will let this
12291 function complain more accurately. A few special modes are allowed
12292 without complaint for global variables (for instance, global
12293 register values and thread-local values).
12295 A location description containing no operations indicates that the
12296 object is optimized out. The return value is 0 for that case.
12297 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12298 callers will only want a very basic result and this can become a
12301 Note that stack[0] is unused except as a default error return.
12302 Note that stack overflow is not yet handled. */
12305 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
12307 struct objfile *objfile = cu->objfile;
12309 int size = blk->size;
12310 gdb_byte *data = blk->data;
12311 CORE_ADDR stack[64];
12313 unsigned int bytes_read, unsnd;
12357 stack[++stacki] = op - DW_OP_lit0;
12392 stack[++stacki] = op - DW_OP_reg0;
12394 dwarf2_complex_location_expr_complaint ();
12398 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
12400 stack[++stacki] = unsnd;
12402 dwarf2_complex_location_expr_complaint ();
12406 stack[++stacki] = read_address (objfile->obfd, &data[i],
12411 case DW_OP_const1u:
12412 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
12416 case DW_OP_const1s:
12417 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
12421 case DW_OP_const2u:
12422 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
12426 case DW_OP_const2s:
12427 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
12431 case DW_OP_const4u:
12432 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
12436 case DW_OP_const4s:
12437 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
12442 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
12448 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
12453 stack[stacki + 1] = stack[stacki];
12458 stack[stacki - 1] += stack[stacki];
12462 case DW_OP_plus_uconst:
12463 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
12468 stack[stacki - 1] -= stack[stacki];
12473 /* If we're not the last op, then we definitely can't encode
12474 this using GDB's address_class enum. This is valid for partial
12475 global symbols, although the variable's address will be bogus
12478 dwarf2_complex_location_expr_complaint ();
12481 case DW_OP_GNU_push_tls_address:
12482 /* The top of the stack has the offset from the beginning
12483 of the thread control block at which the variable is located. */
12484 /* Nothing should follow this operator, so the top of stack would
12486 /* This is valid for partial global symbols, but the variable's
12487 address will be bogus in the psymtab. */
12489 dwarf2_complex_location_expr_complaint ();
12492 case DW_OP_GNU_uninit:
12496 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
12497 dwarf_stack_op_name (op, 1));
12498 return (stack[stacki]);
12501 return (stack[stacki]);
12504 /* memory allocation interface */
12506 static struct dwarf_block *
12507 dwarf_alloc_block (struct dwarf2_cu *cu)
12509 struct dwarf_block *blk;
12511 blk = (struct dwarf_block *)
12512 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
12516 static struct abbrev_info *
12517 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
12519 struct abbrev_info *abbrev;
12521 abbrev = (struct abbrev_info *)
12522 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
12523 memset (abbrev, 0, sizeof (struct abbrev_info));
12527 static struct die_info *
12528 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
12530 struct die_info *die;
12531 size_t size = sizeof (struct die_info);
12534 size += (num_attrs - 1) * sizeof (struct attribute);
12536 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
12537 memset (die, 0, sizeof (struct die_info));
12542 /* Macro support. */
12545 /* Return the full name of file number I in *LH's file name table.
12546 Use COMP_DIR as the name of the current directory of the
12547 compilation. The result is allocated using xmalloc; the caller is
12548 responsible for freeing it. */
12550 file_full_name (int file, struct line_header *lh, const char *comp_dir)
12552 /* Is the file number a valid index into the line header's file name
12553 table? Remember that file numbers start with one, not zero. */
12554 if (1 <= file && file <= lh->num_file_names)
12556 struct file_entry *fe = &lh->file_names[file - 1];
12558 if (IS_ABSOLUTE_PATH (fe->name))
12559 return xstrdup (fe->name);
12567 dir = lh->include_dirs[fe->dir_index - 1];
12573 dir_len = strlen (dir);
12574 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
12575 strcpy (full_name, dir);
12576 full_name[dir_len] = '/';
12577 strcpy (full_name + dir_len + 1, fe->name);
12581 return xstrdup (fe->name);
12586 /* The compiler produced a bogus file number. We can at least
12587 record the macro definitions made in the file, even if we
12588 won't be able to find the file by name. */
12589 char fake_name[80];
12591 sprintf (fake_name, "<bad macro file number %d>", file);
12593 complaint (&symfile_complaints,
12594 _("bad file number in macro information (%d)"),
12597 return xstrdup (fake_name);
12602 static struct macro_source_file *
12603 macro_start_file (int file, int line,
12604 struct macro_source_file *current_file,
12605 const char *comp_dir,
12606 struct line_header *lh, struct objfile *objfile)
12608 /* The full name of this source file. */
12609 char *full_name = file_full_name (file, lh, comp_dir);
12611 /* We don't create a macro table for this compilation unit
12612 at all until we actually get a filename. */
12613 if (! pending_macros)
12614 pending_macros = new_macro_table (&objfile->objfile_obstack,
12615 objfile->macro_cache);
12617 if (! current_file)
12618 /* If we have no current file, then this must be the start_file
12619 directive for the compilation unit's main source file. */
12620 current_file = macro_set_main (pending_macros, full_name);
12622 current_file = macro_include (current_file, line, full_name);
12626 return current_file;
12630 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
12631 followed by a null byte. */
12633 copy_string (const char *buf, int len)
12635 char *s = xmalloc (len + 1);
12637 memcpy (s, buf, len);
12643 static const char *
12644 consume_improper_spaces (const char *p, const char *body)
12648 complaint (&symfile_complaints,
12649 _("macro definition contains spaces in formal argument list:\n`%s'"),
12661 parse_macro_definition (struct macro_source_file *file, int line,
12666 /* The body string takes one of two forms. For object-like macro
12667 definitions, it should be:
12669 <macro name> " " <definition>
12671 For function-like macro definitions, it should be:
12673 <macro name> "() " <definition>
12675 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
12677 Spaces may appear only where explicitly indicated, and in the
12680 The Dwarf 2 spec says that an object-like macro's name is always
12681 followed by a space, but versions of GCC around March 2002 omit
12682 the space when the macro's definition is the empty string.
12684 The Dwarf 2 spec says that there should be no spaces between the
12685 formal arguments in a function-like macro's formal argument list,
12686 but versions of GCC around March 2002 include spaces after the
12690 /* Find the extent of the macro name. The macro name is terminated
12691 by either a space or null character (for an object-like macro) or
12692 an opening paren (for a function-like macro). */
12693 for (p = body; *p; p++)
12694 if (*p == ' ' || *p == '(')
12697 if (*p == ' ' || *p == '\0')
12699 /* It's an object-like macro. */
12700 int name_len = p - body;
12701 char *name = copy_string (body, name_len);
12702 const char *replacement;
12705 replacement = body + name_len + 1;
12708 dwarf2_macro_malformed_definition_complaint (body);
12709 replacement = body + name_len;
12712 macro_define_object (file, line, name, replacement);
12716 else if (*p == '(')
12718 /* It's a function-like macro. */
12719 char *name = copy_string (body, p - body);
12722 char **argv = xmalloc (argv_size * sizeof (*argv));
12726 p = consume_improper_spaces (p, body);
12728 /* Parse the formal argument list. */
12729 while (*p && *p != ')')
12731 /* Find the extent of the current argument name. */
12732 const char *arg_start = p;
12734 while (*p && *p != ',' && *p != ')' && *p != ' ')
12737 if (! *p || p == arg_start)
12738 dwarf2_macro_malformed_definition_complaint (body);
12741 /* Make sure argv has room for the new argument. */
12742 if (argc >= argv_size)
12745 argv = xrealloc (argv, argv_size * sizeof (*argv));
12748 argv[argc++] = copy_string (arg_start, p - arg_start);
12751 p = consume_improper_spaces (p, body);
12753 /* Consume the comma, if present. */
12758 p = consume_improper_spaces (p, body);
12767 /* Perfectly formed definition, no complaints. */
12768 macro_define_function (file, line, name,
12769 argc, (const char **) argv,
12771 else if (*p == '\0')
12773 /* Complain, but do define it. */
12774 dwarf2_macro_malformed_definition_complaint (body);
12775 macro_define_function (file, line, name,
12776 argc, (const char **) argv,
12780 /* Just complain. */
12781 dwarf2_macro_malformed_definition_complaint (body);
12784 /* Just complain. */
12785 dwarf2_macro_malformed_definition_complaint (body);
12791 for (i = 0; i < argc; i++)
12797 dwarf2_macro_malformed_definition_complaint (body);
12802 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
12803 char *comp_dir, bfd *abfd,
12804 struct dwarf2_cu *cu)
12806 gdb_byte *mac_ptr, *mac_end;
12807 struct macro_source_file *current_file = 0;
12808 enum dwarf_macinfo_record_type macinfo_type;
12809 int at_commandline;
12811 dwarf2_read_section (dwarf2_per_objfile->objfile,
12812 &dwarf2_per_objfile->macinfo);
12813 if (dwarf2_per_objfile->macinfo.buffer == NULL)
12815 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
12819 /* First pass: Find the name of the base filename.
12820 This filename is needed in order to process all macros whose definition
12821 (or undefinition) comes from the command line. These macros are defined
12822 before the first DW_MACINFO_start_file entry, and yet still need to be
12823 associated to the base file.
12825 To determine the base file name, we scan the macro definitions until we
12826 reach the first DW_MACINFO_start_file entry. We then initialize
12827 CURRENT_FILE accordingly so that any macro definition found before the
12828 first DW_MACINFO_start_file can still be associated to the base file. */
12830 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
12831 mac_end = dwarf2_per_objfile->macinfo.buffer
12832 + dwarf2_per_objfile->macinfo.size;
12836 /* Do we at least have room for a macinfo type byte? */
12837 if (mac_ptr >= mac_end)
12839 /* Complaint is printed during the second pass as GDB will probably
12840 stop the first pass earlier upon finding DW_MACINFO_start_file. */
12844 macinfo_type = read_1_byte (abfd, mac_ptr);
12847 switch (macinfo_type)
12849 /* A zero macinfo type indicates the end of the macro
12854 case DW_MACINFO_define:
12855 case DW_MACINFO_undef:
12856 /* Only skip the data by MAC_PTR. */
12858 unsigned int bytes_read;
12860 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12861 mac_ptr += bytes_read;
12862 read_string (abfd, mac_ptr, &bytes_read);
12863 mac_ptr += bytes_read;
12867 case DW_MACINFO_start_file:
12869 unsigned int bytes_read;
12872 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12873 mac_ptr += bytes_read;
12874 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12875 mac_ptr += bytes_read;
12877 current_file = macro_start_file (file, line, current_file, comp_dir,
12882 case DW_MACINFO_end_file:
12883 /* No data to skip by MAC_PTR. */
12886 case DW_MACINFO_vendor_ext:
12887 /* Only skip the data by MAC_PTR. */
12889 unsigned int bytes_read;
12891 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12892 mac_ptr += bytes_read;
12893 read_string (abfd, mac_ptr, &bytes_read);
12894 mac_ptr += bytes_read;
12901 } while (macinfo_type != 0 && current_file == NULL);
12903 /* Second pass: Process all entries.
12905 Use the AT_COMMAND_LINE flag to determine whether we are still processing
12906 command-line macro definitions/undefinitions. This flag is unset when we
12907 reach the first DW_MACINFO_start_file entry. */
12909 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
12911 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
12912 GDB is still reading the definitions from command line. First
12913 DW_MACINFO_start_file will need to be ignored as it was already executed
12914 to create CURRENT_FILE for the main source holding also the command line
12915 definitions. On first met DW_MACINFO_start_file this flag is reset to
12916 normally execute all the remaining DW_MACINFO_start_file macinfos. */
12918 at_commandline = 1;
12922 /* Do we at least have room for a macinfo type byte? */
12923 if (mac_ptr >= mac_end)
12925 dwarf2_macros_too_long_complaint ();
12929 macinfo_type = read_1_byte (abfd, mac_ptr);
12932 switch (macinfo_type)
12934 /* A zero macinfo type indicates the end of the macro
12939 case DW_MACINFO_define:
12940 case DW_MACINFO_undef:
12942 unsigned int bytes_read;
12946 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12947 mac_ptr += bytes_read;
12948 body = read_string (abfd, mac_ptr, &bytes_read);
12949 mac_ptr += bytes_read;
12951 if (! current_file)
12953 /* DWARF violation as no main source is present. */
12954 complaint (&symfile_complaints,
12955 _("debug info with no main source gives macro %s "
12957 macinfo_type == DW_MACINFO_define ?
12959 macinfo_type == DW_MACINFO_undef ?
12960 _("undefinition") :
12961 _("something-or-other"), line, body);
12964 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
12965 complaint (&symfile_complaints,
12966 _("debug info gives %s macro %s with %s line %d: %s"),
12967 at_commandline ? _("command-line") : _("in-file"),
12968 macinfo_type == DW_MACINFO_define ?
12970 macinfo_type == DW_MACINFO_undef ?
12971 _("undefinition") :
12972 _("something-or-other"),
12973 line == 0 ? _("zero") : _("non-zero"), line, body);
12975 if (macinfo_type == DW_MACINFO_define)
12976 parse_macro_definition (current_file, line, body);
12977 else if (macinfo_type == DW_MACINFO_undef)
12978 macro_undef (current_file, line, body);
12982 case DW_MACINFO_start_file:
12984 unsigned int bytes_read;
12987 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12988 mac_ptr += bytes_read;
12989 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
12990 mac_ptr += bytes_read;
12992 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
12993 complaint (&symfile_complaints,
12994 _("debug info gives source %d included "
12995 "from %s at %s line %d"),
12996 file, at_commandline ? _("command-line") : _("file"),
12997 line == 0 ? _("zero") : _("non-zero"), line);
12999 if (at_commandline)
13001 /* This DW_MACINFO_start_file was executed in the pass one. */
13002 at_commandline = 0;
13005 current_file = macro_start_file (file, line,
13006 current_file, comp_dir,
13011 case DW_MACINFO_end_file:
13012 if (! current_file)
13013 complaint (&symfile_complaints,
13014 _("macro debug info has an unmatched `close_file' directive"));
13017 current_file = current_file->included_by;
13018 if (! current_file)
13020 enum dwarf_macinfo_record_type next_type;
13022 /* GCC circa March 2002 doesn't produce the zero
13023 type byte marking the end of the compilation
13024 unit. Complain if it's not there, but exit no
13027 /* Do we at least have room for a macinfo type byte? */
13028 if (mac_ptr >= mac_end)
13030 dwarf2_macros_too_long_complaint ();
13034 /* We don't increment mac_ptr here, so this is just
13036 next_type = read_1_byte (abfd, mac_ptr);
13037 if (next_type != 0)
13038 complaint (&symfile_complaints,
13039 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13046 case DW_MACINFO_vendor_ext:
13048 unsigned int bytes_read;
13052 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
13053 mac_ptr += bytes_read;
13054 string = read_string (abfd, mac_ptr, &bytes_read);
13055 mac_ptr += bytes_read;
13057 /* We don't recognize any vendor extensions. */
13061 } while (macinfo_type != 0);
13064 /* Check if the attribute's form is a DW_FORM_block*
13065 if so return true else false. */
13067 attr_form_is_block (struct attribute *attr)
13069 return (attr == NULL ? 0 :
13070 attr->form == DW_FORM_block1
13071 || attr->form == DW_FORM_block2
13072 || attr->form == DW_FORM_block4
13073 || attr->form == DW_FORM_block
13074 || attr->form == DW_FORM_exprloc);
13077 /* Return non-zero if ATTR's value is a section offset --- classes
13078 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13079 You may use DW_UNSND (attr) to retrieve such offsets.
13081 Section 7.5.4, "Attribute Encodings", explains that no attribute
13082 may have a value that belongs to more than one of these classes; it
13083 would be ambiguous if we did, because we use the same forms for all
13086 attr_form_is_section_offset (struct attribute *attr)
13088 return (attr->form == DW_FORM_data4
13089 || attr->form == DW_FORM_data8
13090 || attr->form == DW_FORM_sec_offset);
13094 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13095 zero otherwise. When this function returns true, you can apply
13096 dwarf2_get_attr_constant_value to it.
13098 However, note that for some attributes you must check
13099 attr_form_is_section_offset before using this test. DW_FORM_data4
13100 and DW_FORM_data8 are members of both the constant class, and of
13101 the classes that contain offsets into other debug sections
13102 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13103 that, if an attribute's can be either a constant or one of the
13104 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13105 taken as section offsets, not constants. */
13107 attr_form_is_constant (struct attribute *attr)
13109 switch (attr->form)
13111 case DW_FORM_sdata:
13112 case DW_FORM_udata:
13113 case DW_FORM_data1:
13114 case DW_FORM_data2:
13115 case DW_FORM_data4:
13116 case DW_FORM_data8:
13124 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
13125 struct dwarf2_cu *cu)
13127 if (attr_form_is_section_offset (attr)
13128 /* ".debug_loc" may not exist at all, or the offset may be outside
13129 the section. If so, fall through to the complaint in the
13131 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
13133 struct dwarf2_loclist_baton *baton;
13135 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13136 sizeof (struct dwarf2_loclist_baton));
13137 baton->per_cu = cu->per_cu;
13138 gdb_assert (baton->per_cu);
13140 dwarf2_read_section (dwarf2_per_objfile->objfile,
13141 &dwarf2_per_objfile->loc);
13143 /* We don't know how long the location list is, but make sure we
13144 don't run off the edge of the section. */
13145 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
13146 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
13147 baton->base_address = cu->base_address;
13148 if (cu->base_known == 0)
13149 complaint (&symfile_complaints,
13150 _("Location list used without specifying the CU base address."));
13152 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
13153 SYMBOL_LOCATION_BATON (sym) = baton;
13157 struct dwarf2_locexpr_baton *baton;
13159 baton = obstack_alloc (&cu->objfile->objfile_obstack,
13160 sizeof (struct dwarf2_locexpr_baton));
13161 baton->per_cu = cu->per_cu;
13162 gdb_assert (baton->per_cu);
13164 if (attr_form_is_block (attr))
13166 /* Note that we're just copying the block's data pointer
13167 here, not the actual data. We're still pointing into the
13168 info_buffer for SYM's objfile; right now we never release
13169 that buffer, but when we do clean up properly this may
13171 baton->size = DW_BLOCK (attr)->size;
13172 baton->data = DW_BLOCK (attr)->data;
13176 dwarf2_invalid_attrib_class_complaint ("location description",
13177 SYMBOL_NATURAL_NAME (sym));
13179 baton->data = NULL;
13182 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
13183 SYMBOL_LOCATION_BATON (sym) = baton;
13187 /* Return the OBJFILE associated with the compilation unit CU. If CU
13188 came from a separate debuginfo file, then the master objfile is
13192 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
13194 struct objfile *objfile = per_cu->objfile;
13196 /* Return the master objfile, so that we can report and look up the
13197 correct file containing this variable. */
13198 if (objfile->separate_debug_objfile_backlink)
13199 objfile = objfile->separate_debug_objfile_backlink;
13204 /* Return the address size given in the compilation unit header for CU. */
13207 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
13210 return per_cu->cu->header.addr_size;
13213 /* If the CU is not currently read in, we re-read its header. */
13214 struct objfile *objfile = per_cu->objfile;
13215 struct dwarf2_per_objfile *per_objfile
13216 = objfile_data (objfile, dwarf2_objfile_data_key);
13217 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
13218 struct comp_unit_head cu_header;
13220 memset (&cu_header, 0, sizeof cu_header);
13221 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
13222 return cu_header.addr_size;
13226 /* Return the offset size given in the compilation unit header for CU. */
13229 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
13232 return per_cu->cu->header.offset_size;
13235 /* If the CU is not currently read in, we re-read its header. */
13236 struct objfile *objfile = per_cu->objfile;
13237 struct dwarf2_per_objfile *per_objfile
13238 = objfile_data (objfile, dwarf2_objfile_data_key);
13239 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
13240 struct comp_unit_head cu_header;
13242 memset (&cu_header, 0, sizeof cu_header);
13243 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
13244 return cu_header.offset_size;
13248 /* Return the text offset of the CU. The returned offset comes from
13249 this CU's objfile. If this objfile came from a separate debuginfo
13250 file, then the offset may be different from the corresponding
13251 offset in the parent objfile. */
13254 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
13256 struct objfile *objfile = per_cu->objfile;
13258 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
13261 /* Locate the .debug_info compilation unit from CU's objfile which contains
13262 the DIE at OFFSET. Raises an error on failure. */
13264 static struct dwarf2_per_cu_data *
13265 dwarf2_find_containing_comp_unit (unsigned int offset,
13266 struct objfile *objfile)
13268 struct dwarf2_per_cu_data *this_cu;
13272 high = dwarf2_per_objfile->n_comp_units - 1;
13275 int mid = low + (high - low) / 2;
13277 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
13282 gdb_assert (low == high);
13283 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
13286 error (_("Dwarf Error: could not find partial DIE containing "
13287 "offset 0x%lx [in module %s]"),
13288 (long) offset, bfd_get_filename (objfile->obfd));
13290 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
13291 return dwarf2_per_objfile->all_comp_units[low-1];
13295 this_cu = dwarf2_per_objfile->all_comp_units[low];
13296 if (low == dwarf2_per_objfile->n_comp_units - 1
13297 && offset >= this_cu->offset + this_cu->length)
13298 error (_("invalid dwarf2 offset %u"), offset);
13299 gdb_assert (offset < this_cu->offset + this_cu->length);
13304 /* Locate the compilation unit from OBJFILE which is located at exactly
13305 OFFSET. Raises an error on failure. */
13307 static struct dwarf2_per_cu_data *
13308 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
13310 struct dwarf2_per_cu_data *this_cu;
13312 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
13313 if (this_cu->offset != offset)
13314 error (_("no compilation unit with offset %u."), offset);
13318 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13320 static struct dwarf2_cu *
13321 alloc_one_comp_unit (struct objfile *objfile)
13323 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
13324 cu->objfile = objfile;
13325 obstack_init (&cu->comp_unit_obstack);
13329 /* Release one cached compilation unit, CU. We unlink it from the tree
13330 of compilation units, but we don't remove it from the read_in_chain;
13331 the caller is responsible for that.
13332 NOTE: DATA is a void * because this function is also used as a
13333 cleanup routine. */
13336 free_one_comp_unit (void *data)
13338 struct dwarf2_cu *cu = data;
13340 if (cu->per_cu != NULL)
13341 cu->per_cu->cu = NULL;
13344 obstack_free (&cu->comp_unit_obstack, NULL);
13349 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13350 when we're finished with it. We can't free the pointer itself, but be
13351 sure to unlink it from the cache. Also release any associated storage
13352 and perform cache maintenance.
13354 Only used during partial symbol parsing. */
13357 free_stack_comp_unit (void *data)
13359 struct dwarf2_cu *cu = data;
13361 obstack_free (&cu->comp_unit_obstack, NULL);
13362 cu->partial_dies = NULL;
13364 if (cu->per_cu != NULL)
13366 /* This compilation unit is on the stack in our caller, so we
13367 should not xfree it. Just unlink it. */
13368 cu->per_cu->cu = NULL;
13371 /* If we had a per-cu pointer, then we may have other compilation
13372 units loaded, so age them now. */
13373 age_cached_comp_units ();
13377 /* Free all cached compilation units. */
13380 free_cached_comp_units (void *data)
13382 struct dwarf2_per_cu_data *per_cu, **last_chain;
13384 per_cu = dwarf2_per_objfile->read_in_chain;
13385 last_chain = &dwarf2_per_objfile->read_in_chain;
13386 while (per_cu != NULL)
13388 struct dwarf2_per_cu_data *next_cu;
13390 next_cu = per_cu->cu->read_in_chain;
13392 free_one_comp_unit (per_cu->cu);
13393 *last_chain = next_cu;
13399 /* Increase the age counter on each cached compilation unit, and free
13400 any that are too old. */
13403 age_cached_comp_units (void)
13405 struct dwarf2_per_cu_data *per_cu, **last_chain;
13407 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
13408 per_cu = dwarf2_per_objfile->read_in_chain;
13409 while (per_cu != NULL)
13411 per_cu->cu->last_used ++;
13412 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
13413 dwarf2_mark (per_cu->cu);
13414 per_cu = per_cu->cu->read_in_chain;
13417 per_cu = dwarf2_per_objfile->read_in_chain;
13418 last_chain = &dwarf2_per_objfile->read_in_chain;
13419 while (per_cu != NULL)
13421 struct dwarf2_per_cu_data *next_cu;
13423 next_cu = per_cu->cu->read_in_chain;
13425 if (!per_cu->cu->mark)
13427 free_one_comp_unit (per_cu->cu);
13428 *last_chain = next_cu;
13431 last_chain = &per_cu->cu->read_in_chain;
13437 /* Remove a single compilation unit from the cache. */
13440 free_one_cached_comp_unit (void *target_cu)
13442 struct dwarf2_per_cu_data *per_cu, **last_chain;
13444 per_cu = dwarf2_per_objfile->read_in_chain;
13445 last_chain = &dwarf2_per_objfile->read_in_chain;
13446 while (per_cu != NULL)
13448 struct dwarf2_per_cu_data *next_cu;
13450 next_cu = per_cu->cu->read_in_chain;
13452 if (per_cu->cu == target_cu)
13454 free_one_comp_unit (per_cu->cu);
13455 *last_chain = next_cu;
13459 last_chain = &per_cu->cu->read_in_chain;
13465 /* Release all extra memory associated with OBJFILE. */
13468 dwarf2_free_objfile (struct objfile *objfile)
13470 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
13472 if (dwarf2_per_objfile == NULL)
13475 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
13476 free_cached_comp_units (NULL);
13478 if (dwarf2_per_objfile->using_index)
13482 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
13485 struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
13487 if (!cu->v.quick->lines)
13490 for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
13492 if (cu->v.quick->file_names)
13493 xfree ((void *) cu->v.quick->file_names[j]);
13494 if (cu->v.quick->full_names)
13495 xfree ((void *) cu->v.quick->full_names[j]);
13498 free_line_header (cu->v.quick->lines);
13502 /* Everything else should be on the objfile obstack. */
13505 /* A pair of DIE offset and GDB type pointer. We store these
13506 in a hash table separate from the DIEs, and preserve them
13507 when the DIEs are flushed out of cache. */
13509 struct dwarf2_offset_and_type
13511 unsigned int offset;
13515 /* Hash function for a dwarf2_offset_and_type. */
13518 offset_and_type_hash (const void *item)
13520 const struct dwarf2_offset_and_type *ofs = item;
13522 return ofs->offset;
13525 /* Equality function for a dwarf2_offset_and_type. */
13528 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
13530 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
13531 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
13533 return ofs_lhs->offset == ofs_rhs->offset;
13536 /* Set the type associated with DIE to TYPE. Save it in CU's hash
13537 table if necessary. For convenience, return TYPE.
13539 The DIEs reading must have careful ordering to:
13540 * Not cause infite loops trying to read in DIEs as a prerequisite for
13541 reading current DIE.
13542 * Not trying to dereference contents of still incompletely read in types
13543 while reading in other DIEs.
13544 * Enable referencing still incompletely read in types just by a pointer to
13545 the type without accessing its fields.
13547 Therefore caller should follow these rules:
13548 * Try to fetch any prerequisite types we may need to build this DIE type
13549 before building the type and calling set_die_type.
13550 * After building typer call set_die_type for current DIE as soon as
13551 possible before fetching more types to complete the current type.
13552 * Make the type as complete as possible before fetching more types. */
13554 static struct type *
13555 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
13557 struct dwarf2_offset_and_type **slot, ofs;
13559 /* For Ada types, make sure that the gnat-specific data is always
13560 initialized (if not already set). There are a few types where
13561 we should not be doing so, because the type-specific area is
13562 already used to hold some other piece of info (eg: TYPE_CODE_FLT
13563 where the type-specific area is used to store the floatformat).
13564 But this is not a problem, because the gnat-specific information
13565 is actually not needed for these types. */
13566 if (need_gnat_info (cu)
13567 && TYPE_CODE (type) != TYPE_CODE_FUNC
13568 && TYPE_CODE (type) != TYPE_CODE_FLT
13569 && !HAVE_GNAT_AUX_INFO (type))
13570 INIT_GNAT_SPECIFIC (type);
13572 if (cu->type_hash == NULL)
13574 gdb_assert (cu->per_cu != NULL);
13575 cu->per_cu->type_hash
13576 = htab_create_alloc_ex (cu->header.length / 24,
13577 offset_and_type_hash,
13578 offset_and_type_eq,
13580 &cu->objfile->objfile_obstack,
13581 hashtab_obstack_allocate,
13582 dummy_obstack_deallocate);
13583 cu->type_hash = cu->per_cu->type_hash;
13586 ofs.offset = die->offset;
13588 slot = (struct dwarf2_offset_and_type **)
13589 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
13591 complaint (&symfile_complaints,
13592 _("A problem internal to GDB: DIE 0x%x has type already set"),
13594 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
13599 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
13600 not have a saved type. */
13602 static struct type *
13603 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
13605 struct dwarf2_offset_and_type *slot, ofs;
13606 htab_t type_hash = cu->type_hash;
13608 if (type_hash == NULL)
13611 ofs.offset = die->offset;
13612 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
13619 /* Add a dependence relationship from CU to REF_PER_CU. */
13622 dwarf2_add_dependence (struct dwarf2_cu *cu,
13623 struct dwarf2_per_cu_data *ref_per_cu)
13627 if (cu->dependencies == NULL)
13629 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
13630 NULL, &cu->comp_unit_obstack,
13631 hashtab_obstack_allocate,
13632 dummy_obstack_deallocate);
13634 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
13636 *slot = ref_per_cu;
13639 /* Subroutine of dwarf2_mark to pass to htab_traverse.
13640 Set the mark field in every compilation unit in the
13641 cache that we must keep because we are keeping CU. */
13644 dwarf2_mark_helper (void **slot, void *data)
13646 struct dwarf2_per_cu_data *per_cu;
13648 per_cu = (struct dwarf2_per_cu_data *) *slot;
13649 if (per_cu->cu->mark)
13651 per_cu->cu->mark = 1;
13653 if (per_cu->cu->dependencies != NULL)
13654 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
13659 /* Set the mark field in CU and in every other compilation unit in the
13660 cache that we must keep because we are keeping CU. */
13663 dwarf2_mark (struct dwarf2_cu *cu)
13668 if (cu->dependencies != NULL)
13669 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
13673 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
13677 per_cu->cu->mark = 0;
13678 per_cu = per_cu->cu->read_in_chain;
13682 /* Trivial hash function for partial_die_info: the hash value of a DIE
13683 is its offset in .debug_info for this objfile. */
13686 partial_die_hash (const void *item)
13688 const struct partial_die_info *part_die = item;
13690 return part_die->offset;
13693 /* Trivial comparison function for partial_die_info structures: two DIEs
13694 are equal if they have the same offset. */
13697 partial_die_eq (const void *item_lhs, const void *item_rhs)
13699 const struct partial_die_info *part_die_lhs = item_lhs;
13700 const struct partial_die_info *part_die_rhs = item_rhs;
13702 return part_die_lhs->offset == part_die_rhs->offset;
13705 static struct cmd_list_element *set_dwarf2_cmdlist;
13706 static struct cmd_list_element *show_dwarf2_cmdlist;
13709 set_dwarf2_cmd (char *args, int from_tty)
13711 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
13715 show_dwarf2_cmd (char *args, int from_tty)
13717 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
13720 /* If section described by INFO was mmapped, munmap it now. */
13723 munmap_section_buffer (struct dwarf2_section_info *info)
13725 if (info->was_mmapped)
13728 intptr_t begin = (intptr_t) info->buffer;
13729 intptr_t map_begin = begin & ~(pagesize - 1);
13730 size_t map_length = info->size + begin - map_begin;
13732 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
13734 /* Without HAVE_MMAP, we should never be here to begin with. */
13740 /* munmap debug sections for OBJFILE, if necessary. */
13743 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
13745 struct dwarf2_per_objfile *data = d;
13747 munmap_section_buffer (&data->info);
13748 munmap_section_buffer (&data->abbrev);
13749 munmap_section_buffer (&data->line);
13750 munmap_section_buffer (&data->str);
13751 munmap_section_buffer (&data->macinfo);
13752 munmap_section_buffer (&data->ranges);
13753 munmap_section_buffer (&data->loc);
13754 munmap_section_buffer (&data->frame);
13755 munmap_section_buffer (&data->eh_frame);
13756 munmap_section_buffer (&data->gdb_index);
13761 /* The contents of the hash table we create when building the string
13763 struct strtab_entry
13765 offset_type offset;
13769 /* Hash function for a strtab_entry. */
13771 hash_strtab_entry (const void *e)
13773 const struct strtab_entry *entry = e;
13774 return mapped_index_string_hash (entry->str);
13777 /* Equality function for a strtab_entry. */
13779 eq_strtab_entry (const void *a, const void *b)
13781 const struct strtab_entry *ea = a;
13782 const struct strtab_entry *eb = b;
13783 return !strcmp (ea->str, eb->str);
13786 /* Create a strtab_entry hash table. */
13788 create_strtab (void)
13790 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
13791 xfree, xcalloc, xfree);
13794 /* Add a string to the constant pool. Return the string's offset in
13797 add_string (htab_t table, struct obstack *cpool, const char *str)
13800 struct strtab_entry entry;
13801 struct strtab_entry *result;
13804 slot = htab_find_slot (table, &entry, INSERT);
13809 result = XNEW (struct strtab_entry);
13810 result->offset = obstack_object_size (cpool);
13812 obstack_grow_str0 (cpool, str);
13815 return result->offset;
13818 /* An entry in the symbol table. */
13819 struct symtab_index_entry
13821 /* The name of the symbol. */
13823 /* The offset of the name in the constant pool. */
13824 offset_type index_offset;
13825 /* A sorted vector of the indices of all the CUs that hold an object
13827 VEC (offset_type) *cu_indices;
13830 /* The symbol table. This is a power-of-2-sized hash table. */
13831 struct mapped_symtab
13833 offset_type n_elements;
13835 struct symtab_index_entry **data;
13838 /* Hash function for a symtab_index_entry. */
13840 hash_symtab_entry (const void *e)
13842 const struct symtab_index_entry *entry = e;
13843 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
13844 sizeof (offset_type) * VEC_length (offset_type,
13845 entry->cu_indices),
13849 /* Equality function for a symtab_index_entry. */
13851 eq_symtab_entry (const void *a, const void *b)
13853 const struct symtab_index_entry *ea = a;
13854 const struct symtab_index_entry *eb = b;
13855 int len = VEC_length (offset_type, ea->cu_indices);
13856 if (len != VEC_length (offset_type, eb->cu_indices))
13858 return !memcmp (VEC_address (offset_type, ea->cu_indices),
13859 VEC_address (offset_type, eb->cu_indices),
13860 sizeof (offset_type) * len);
13863 /* Destroy a symtab_index_entry. */
13865 delete_symtab_entry (void *p)
13867 struct symtab_index_entry *entry = p;
13868 VEC_free (offset_type, entry->cu_indices);
13872 /* Create a hash table holding symtab_index_entry objects. */
13874 create_index_table (void)
13876 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
13877 delete_symtab_entry, xcalloc, xfree);
13880 /* Create a new mapped symtab object. */
13881 static struct mapped_symtab *
13882 create_mapped_symtab (void)
13884 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
13885 symtab->n_elements = 0;
13886 symtab->size = 1024;
13887 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
13891 /* Destroy a mapped_symtab. */
13893 cleanup_mapped_symtab (void *p)
13895 struct mapped_symtab *symtab = p;
13896 /* The contents of the array are freed when the other hash table is
13898 xfree (symtab->data);
13902 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
13904 static struct symtab_index_entry **
13905 find_slot (struct mapped_symtab *symtab, const char *name)
13907 offset_type index, step, hash = mapped_index_string_hash (name);
13909 index = hash & (symtab->size - 1);
13910 step = ((hash * 17) & (symtab->size - 1)) | 1;
13914 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
13915 return &symtab->data[index];
13916 index = (index + step) & (symtab->size - 1);
13920 /* Expand SYMTAB's hash table. */
13922 hash_expand (struct mapped_symtab *symtab)
13924 offset_type old_size = symtab->size;
13926 struct symtab_index_entry **old_entries = symtab->data;
13929 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
13931 for (i = 0; i < old_size; ++i)
13933 if (old_entries[i])
13935 struct symtab_index_entry **slot = find_slot (symtab,
13936 old_entries[i]->name);
13937 *slot = old_entries[i];
13941 xfree (old_entries);
13944 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
13945 is the index of the CU in which the symbol appears. */
13947 add_index_entry (struct mapped_symtab *symtab, const char *name,
13948 offset_type cu_index)
13950 struct symtab_index_entry **slot;
13952 ++symtab->n_elements;
13953 if (4 * symtab->n_elements / 3 >= symtab->size)
13954 hash_expand (symtab);
13956 slot = find_slot (symtab, name);
13959 *slot = XNEW (struct symtab_index_entry);
13960 (*slot)->name = name;
13961 (*slot)->cu_indices = NULL;
13963 /* Don't push an index twice. Due to how we add entries we only
13964 have to check the last one. */
13965 if (VEC_empty (offset_type, (*slot)->cu_indices)
13966 || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
13967 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
13970 /* Add a vector of indices to the constant pool. */
13972 add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
13973 struct symtab_index_entry *entry)
13977 slot = htab_find_slot (index_table, entry, INSERT);
13980 offset_type len = VEC_length (offset_type, entry->cu_indices);
13981 offset_type val = MAYBE_SWAP (len);
13986 entry->index_offset = obstack_object_size (cpool);
13988 obstack_grow (cpool, &val, sizeof (val));
13990 VEC_iterate (offset_type, entry->cu_indices, i, iter);
13993 val = MAYBE_SWAP (iter);
13994 obstack_grow (cpool, &val, sizeof (val));
13999 struct symtab_index_entry *old_entry = *slot;
14000 entry->index_offset = old_entry->index_offset;
14003 return entry->index_offset;
14006 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14007 constant pool entries going into the obstack CPOOL. */
14009 write_hash_table (struct mapped_symtab *symtab,
14010 struct obstack *output, struct obstack *cpool)
14013 htab_t index_table;
14016 index_table = create_index_table ();
14017 str_table = create_strtab ();
14018 /* We add all the index vectors to the constant pool first, to
14019 ensure alignment is ok. */
14020 for (i = 0; i < symtab->size; ++i)
14022 if (symtab->data[i])
14023 add_indices_to_cpool (index_table, cpool, symtab->data[i]);
14026 /* Now write out the hash table. */
14027 for (i = 0; i < symtab->size; ++i)
14029 offset_type str_off, vec_off;
14031 if (symtab->data[i])
14033 str_off = add_string (str_table, cpool, symtab->data[i]->name);
14034 vec_off = symtab->data[i]->index_offset;
14038 /* While 0 is a valid constant pool index, it is not valid
14039 to have 0 for both offsets. */
14044 str_off = MAYBE_SWAP (str_off);
14045 vec_off = MAYBE_SWAP (vec_off);
14047 obstack_grow (output, &str_off, sizeof (str_off));
14048 obstack_grow (output, &vec_off, sizeof (vec_off));
14051 htab_delete (str_table);
14052 htab_delete (index_table);
14055 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14056 from PST; CU_INDEX is the index of the CU in the vector of all
14059 add_address_entry (struct objfile *objfile,
14060 struct obstack *addr_obstack, struct partial_symtab *pst,
14061 unsigned int cu_index)
14063 offset_type offset;
14065 CORE_ADDR baseaddr;
14067 /* Don't bother recording empty ranges. */
14068 if (pst->textlow == pst->texthigh)
14071 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14073 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
14074 obstack_grow (addr_obstack, addr, 8);
14075 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
14076 obstack_grow (addr_obstack, addr, 8);
14077 offset = MAYBE_SWAP (cu_index);
14078 obstack_grow (addr_obstack, &offset, sizeof (offset_type));
14081 /* Add a list of partial symbols to SYMTAB. */
14083 write_psymbols (struct mapped_symtab *symtab,
14084 struct partial_symbol **psymp,
14086 offset_type cu_index)
14088 for (; count-- > 0; ++psymp)
14090 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
14091 error (_("Ada is not currently supported by the index"));
14092 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
14096 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14097 exception if there is an error. */
14099 write_obstack (FILE *file, struct obstack *obstack)
14101 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
14103 != obstack_object_size (obstack))
14104 error (_("couldn't data write to file"));
14107 /* Unlink a file if the argument is not NULL. */
14109 unlink_if_set (void *p)
14111 char **filename = p;
14113 unlink (*filename);
14116 /* A helper struct used when iterating over debug_types. */
14117 struct signatured_type_index_data
14119 struct objfile *objfile;
14120 struct mapped_symtab *symtab;
14121 struct obstack *types_list;
14125 /* A helper function that writes a single signatured_type to an
14128 write_one_signatured_type (void **slot, void *d)
14130 struct signatured_type_index_data *info = d;
14131 struct signatured_type *entry = (struct signatured_type *) *slot;
14132 struct dwarf2_per_cu_data *cu = &entry->per_cu;
14133 struct partial_symtab *psymtab = cu->v.psymtab;
14136 write_psymbols (info->symtab,
14137 info->objfile->global_psymbols.list + psymtab->globals_offset,
14138 psymtab->n_global_syms, info->cu_index);
14139 write_psymbols (info->symtab,
14140 info->objfile->static_psymbols.list + psymtab->statics_offset,
14141 psymtab->n_static_syms, info->cu_index);
14143 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
14144 obstack_grow (info->types_list, val, 8);
14145 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
14146 obstack_grow (info->types_list, val, 8);
14147 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
14148 obstack_grow (info->types_list, val, 8);
14155 /* Create an index file for OBJFILE in the directory DIR. */
14157 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
14159 struct cleanup *cleanup;
14160 char *filename, *cleanup_filename;
14161 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
14162 struct obstack cu_list, types_cu_list;
14165 struct mapped_symtab *symtab;
14166 offset_type val, size_of_contents, total_len;
14170 if (!objfile->psymtabs)
14172 if (dwarf2_per_objfile->using_index)
14173 error (_("Cannot use an index to create the index"));
14175 if (stat (objfile->name, &st) < 0)
14176 perror_with_name (_("Could not stat"));
14178 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
14179 INDEX_SUFFIX, (char *) NULL);
14180 cleanup = make_cleanup (xfree, filename);
14182 out_file = fopen (filename, "wb");
14184 error (_("Can't open `%s' for writing"), filename);
14186 cleanup_filename = filename;
14187 make_cleanup (unlink_if_set, &cleanup_filename);
14189 symtab = create_mapped_symtab ();
14190 make_cleanup (cleanup_mapped_symtab, symtab);
14192 obstack_init (&addr_obstack);
14193 make_cleanup_obstack_free (&addr_obstack);
14195 obstack_init (&cu_list);
14196 make_cleanup_obstack_free (&cu_list);
14198 obstack_init (&types_cu_list);
14199 make_cleanup_obstack_free (&types_cu_list);
14201 /* The list is already sorted, so we don't need to do additional
14202 work here. Also, the debug_types entries do not appear in
14203 all_comp_units, but only in their own hash table. */
14204 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
14206 struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
14207 struct partial_symtab *psymtab = cu->v.psymtab;
14210 write_psymbols (symtab,
14211 objfile->global_psymbols.list + psymtab->globals_offset,
14212 psymtab->n_global_syms, i);
14213 write_psymbols (symtab,
14214 objfile->static_psymbols.list + psymtab->statics_offset,
14215 psymtab->n_static_syms, i);
14217 add_address_entry (objfile, &addr_obstack, psymtab, i);
14219 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset);
14220 obstack_grow (&cu_list, val, 8);
14221 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length);
14222 obstack_grow (&cu_list, val, 8);
14225 /* Write out the .debug_type entries, if any. */
14226 if (dwarf2_per_objfile->signatured_types)
14228 struct signatured_type_index_data sig_data;
14230 sig_data.objfile = objfile;
14231 sig_data.symtab = symtab;
14232 sig_data.types_list = &types_cu_list;
14233 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
14234 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
14235 write_one_signatured_type, &sig_data);
14238 obstack_init (&constant_pool);
14239 make_cleanup_obstack_free (&constant_pool);
14240 obstack_init (&symtab_obstack);
14241 make_cleanup_obstack_free (&symtab_obstack);
14242 write_hash_table (symtab, &symtab_obstack, &constant_pool);
14244 obstack_init (&contents);
14245 make_cleanup_obstack_free (&contents);
14246 size_of_contents = 6 * sizeof (offset_type);
14247 total_len = size_of_contents;
14249 /* The version number. */
14250 val = MAYBE_SWAP (2);
14251 obstack_grow (&contents, &val, sizeof (val));
14253 /* The offset of the CU list from the start of the file. */
14254 val = MAYBE_SWAP (total_len);
14255 obstack_grow (&contents, &val, sizeof (val));
14256 total_len += obstack_object_size (&cu_list);
14258 /* The offset of the types CU list from the start of the file. */
14259 val = MAYBE_SWAP (total_len);
14260 obstack_grow (&contents, &val, sizeof (val));
14261 total_len += obstack_object_size (&types_cu_list);
14263 /* The offset of the address table from the start of the file. */
14264 val = MAYBE_SWAP (total_len);
14265 obstack_grow (&contents, &val, sizeof (val));
14266 total_len += obstack_object_size (&addr_obstack);
14268 /* The offset of the symbol table from the start of the file. */
14269 val = MAYBE_SWAP (total_len);
14270 obstack_grow (&contents, &val, sizeof (val));
14271 total_len += obstack_object_size (&symtab_obstack);
14273 /* The offset of the constant pool 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 (&constant_pool);
14278 gdb_assert (obstack_object_size (&contents) == size_of_contents);
14280 write_obstack (out_file, &contents);
14281 write_obstack (out_file, &cu_list);
14282 write_obstack (out_file, &types_cu_list);
14283 write_obstack (out_file, &addr_obstack);
14284 write_obstack (out_file, &symtab_obstack);
14285 write_obstack (out_file, &constant_pool);
14289 /* We want to keep the file, so we set cleanup_filename to NULL
14290 here. See unlink_if_set. */
14291 cleanup_filename = NULL;
14293 do_cleanups (cleanup);
14296 /* The mapped index file format is designed to be directly mmap()able
14297 on any architecture. In most cases, a datum is represented using a
14298 little-endian 32-bit integer value, called an offset_type. Big
14299 endian machines must byte-swap the values before using them.
14300 Exceptions to this rule are noted. The data is laid out such that
14301 alignment is always respected.
14303 A mapped index consists of several sections.
14305 1. The file header. This is a sequence of values, of offset_type
14306 unless otherwise noted:
14307 [0] The version number. Currently 1 or 2. The differences are
14308 noted below. Version 1 did not account for .debug_types sections;
14309 the presence of a .debug_types section invalidates any version 1
14310 index that may exist.
14311 [1] The offset, from the start of the file, of the CU list.
14312 [1.5] In version 2, the offset, from the start of the file, of the
14313 types CU list. This offset does not appear in version 1. Note
14314 that this can be empty, in which case this offset will be equal to
14316 [2] The offset, from the start of the file, of the address section.
14317 [3] The offset, from the start of the file, of the symbol table.
14318 [4] The offset, from the start of the file, of the constant pool.
14320 2. The CU list. This is a sequence of pairs of 64-bit
14321 little-endian values, sorted by the CU offset. The first element
14322 in each pair is the offset of a CU in the .debug_info section. The
14323 second element in each pair is the length of that CU. References
14324 to a CU elsewhere in the map are done using a CU index, which is
14325 just the 0-based index into this table. Note that if there are
14326 type CUs, then conceptually CUs and type CUs form a single list for
14327 the purposes of CU indices.
14329 2.5 The types CU list. This does not appear in a version 1 index.
14330 This is a sequence of triplets of 64-bit little-endian values. In
14331 a triplet, the first value is the CU offset, the second value is
14332 the type offset in the CU, and the third value is the type
14333 signature. The types CU list is not sorted.
14335 3. The address section. The address section consists of a sequence
14336 of address entries. Each address entry has three elements.
14337 [0] The low address. This is a 64-bit little-endian value.
14338 [1] The high address. This is a 64-bit little-endian value.
14339 [2] The CU index. This is an offset_type value.
14341 4. The symbol table. This is a hash table. The size of the hash
14342 table is always a power of 2. The initial hash and the step are
14343 currently defined by the `find_slot' function.
14345 Each slot in the hash table consists of a pair of offset_type
14346 values. The first value is the offset of the symbol's name in the
14347 constant pool. The second value is the offset of the CU vector in
14350 If both values are 0, then this slot in the hash table is empty.
14351 This is ok because while 0 is a valid constant pool index, it
14352 cannot be a valid index for both a string and a CU vector.
14354 A string in the constant pool is stored as a \0-terminated string,
14357 A CU vector in the constant pool is a sequence of offset_type
14358 values. The first value is the number of CU indices in the vector.
14359 Each subsequent value is the index of a CU in the CU list. This
14360 element in the hash table is used to indicate which CUs define the
14363 5. The constant pool. This is simply a bunch of bytes. It is
14364 organized so that alignment is correct: CU vectors are stored
14365 first, followed by strings. */
14367 save_gdb_index_command (char *arg, int from_tty)
14369 struct objfile *objfile;
14372 error (_("usage: save gdb-index DIRECTORY"));
14374 ALL_OBJFILES (objfile)
14378 /* If the objfile does not correspond to an actual file, skip it. */
14379 if (stat (objfile->name, &st) < 0)
14382 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
14383 if (dwarf2_per_objfile)
14385 volatile struct gdb_exception except;
14387 TRY_CATCH (except, RETURN_MASK_ERROR)
14389 write_psymtabs_to_index (objfile, arg);
14391 if (except.reason < 0)
14392 exception_fprintf (gdb_stderr, except,
14393 _("Error while writing index for `%s': "),
14401 int dwarf2_always_disassemble;
14404 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
14405 struct cmd_list_element *c, const char *value)
14407 fprintf_filtered (file, _("\
14408 Whether to always disassemble DWARF expressions is %s.\n"),
14412 void _initialize_dwarf2_read (void);
14415 _initialize_dwarf2_read (void)
14417 struct cmd_list_element *c;
14419 dwarf2_objfile_data_key
14420 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
14422 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
14423 Set DWARF 2 specific variables.\n\
14424 Configure DWARF 2 variables such as the cache size"),
14425 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
14426 0/*allow-unknown*/, &maintenance_set_cmdlist);
14428 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
14429 Show DWARF 2 specific variables\n\
14430 Show DWARF 2 variables such as the cache size"),
14431 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
14432 0/*allow-unknown*/, &maintenance_show_cmdlist);
14434 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
14435 &dwarf2_max_cache_age, _("\
14436 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14437 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14438 A higher limit means that cached compilation units will be stored\n\
14439 in memory longer, and more total memory will be used. Zero disables\n\
14440 caching, which can slow down startup."),
14442 show_dwarf2_max_cache_age,
14443 &set_dwarf2_cmdlist,
14444 &show_dwarf2_cmdlist);
14446 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
14447 &dwarf2_always_disassemble, _("\
14448 Set whether `info address' always disassembles DWARF expressions."), _("\
14449 Show whether `info address' always disassembles DWARF expressions."), _("\
14450 When enabled, DWARF expressions are always printed in an assembly-like\n\
14451 syntax. When disabled, expressions will be printed in a more\n\
14452 conversational style, when possible."),
14454 show_dwarf2_always_disassemble,
14455 &set_dwarf2_cmdlist,
14456 &show_dwarf2_cmdlist);
14458 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
14459 Set debugging of the dwarf2 DIE reader."), _("\
14460 Show debugging of the dwarf2 DIE reader."), _("\
14461 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14462 The value is the maximum depth to print."),
14465 &setdebuglist, &showdebuglist);
14467 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
14468 _("Save a .gdb-index file"),
14470 set_cmd_completer (c, filename_completer);