1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
56 /* A note on memory usage for this file.
58 At the present time, this code reads the debug info sections into
59 the objfile's objfile_obstack. A definite improvement for startup
60 time, on platforms which do not emit relocations for debug
61 sections, would be to use mmap instead. The object's complete
62 debug information is loaded into memory, partly to simplify
63 absolute DIE references.
65 Whether using obstacks or mmap, the sections should remain loaded
66 until the objfile is released, and pointers into the section data
67 can be used for any other data associated to the objfile (symbol
68 names, type names, location expressions to name a few). */
70 #ifndef DWARF2_REG_TO_REGNUM
71 #define DWARF2_REG_TO_REGNUM(REG) (REG)
75 /* .debug_info header for a compilation unit
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct comp_unit_header
80 unsigned int length; /* length of the .debug_info
82 unsigned short version; /* version number -- 2 for DWARF
84 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
85 unsigned char addr_size; /* byte size of an address -- 4 */
88 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct pubnames_header
96 unsigned int length; /* length of the .debug_pubnames
98 unsigned char version; /* version number -- 2 for DWARF
100 unsigned int info_offset; /* offset into .debug_info section */
101 unsigned int info_size; /* byte size of .debug_info section
105 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
107 /* .debug_pubnames header
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct aranges_header
112 unsigned int length; /* byte len of the .debug_aranges
114 unsigned short version; /* version number -- 2 for DWARF
116 unsigned int info_offset; /* offset into .debug_info section */
117 unsigned char addr_size; /* byte size of an address */
118 unsigned char seg_size; /* byte size of segment descriptor */
121 #define _ACTUAL_ARANGES_HEADER_SIZE 12
123 /* .debug_line statement program prologue
124 Because of alignment constraints, this structure has padding and cannot
125 be mapped directly onto the beginning of the .debug_info section. */
126 typedef struct statement_prologue
128 unsigned int total_length; /* byte length of the statement
130 unsigned short version; /* version number -- 2 for DWARF
132 unsigned int prologue_length; /* # bytes between prologue &
134 unsigned char minimum_instruction_length; /* byte size of
136 unsigned char default_is_stmt; /* initial value of is_stmt
139 unsigned char line_range;
140 unsigned char opcode_base; /* number assigned to first special
142 unsigned char *standard_opcode_lengths;
146 static const struct objfile_data *dwarf2_objfile_data_key;
148 struct dwarf2_per_objfile
150 /* Sizes of debugging sections. */
151 unsigned int info_size;
152 unsigned int abbrev_size;
153 unsigned int line_size;
154 unsigned int pubnames_size;
155 unsigned int aranges_size;
156 unsigned int loc_size;
157 unsigned int macinfo_size;
158 unsigned int str_size;
159 unsigned int ranges_size;
160 unsigned int frame_size;
161 unsigned int eh_frame_size;
163 /* Loaded data from the sections. */
168 char *macinfo_buffer;
172 /* A list of all the compilation units. This will be set if and
173 only if we have encountered a compilation unit with inter-CU
175 struct dwarf2_per_cu_data **all_comp_units;
177 /* The number of compilation units in ALL_COMP_UNITS. */
180 /* A chain of compilation units that are currently read in, so that
181 they can be freed later. */
182 struct dwarf2_per_cu_data *read_in_chain;
185 static struct dwarf2_per_objfile *dwarf2_per_objfile;
187 static asection *dwarf_info_section;
188 static asection *dwarf_abbrev_section;
189 static asection *dwarf_line_section;
190 static asection *dwarf_pubnames_section;
191 static asection *dwarf_aranges_section;
192 static asection *dwarf_loc_section;
193 static asection *dwarf_macinfo_section;
194 static asection *dwarf_str_section;
195 static asection *dwarf_ranges_section;
196 asection *dwarf_frame_section;
197 asection *dwarf_eh_frame_section;
199 /* names of the debugging sections */
201 #define INFO_SECTION ".debug_info"
202 #define ABBREV_SECTION ".debug_abbrev"
203 #define LINE_SECTION ".debug_line"
204 #define PUBNAMES_SECTION ".debug_pubnames"
205 #define ARANGES_SECTION ".debug_aranges"
206 #define LOC_SECTION ".debug_loc"
207 #define MACINFO_SECTION ".debug_macinfo"
208 #define STR_SECTION ".debug_str"
209 #define RANGES_SECTION ".debug_ranges"
210 #define FRAME_SECTION ".debug_frame"
211 #define EH_FRAME_SECTION ".eh_frame"
213 /* local data types */
215 /* We hold several abbreviation tables in memory at the same time. */
216 #ifndef ABBREV_HASH_SIZE
217 #define ABBREV_HASH_SIZE 121
220 /* The data in a compilation unit header, after target2host
221 translation, looks like this. */
222 struct comp_unit_head
224 unsigned long length;
226 unsigned int abbrev_offset;
227 unsigned char addr_size;
228 unsigned char signed_addr_p;
229 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
230 unsigned int initial_length_size; /* size of the length field; either
233 /* Offset to the first byte of this compilation unit header in the
234 * .debug_info section, for resolving relative reference dies. */
238 /* Pointer to this compilation unit header in the .debug_info
243 /* Pointer to the first die of this compilatio unit. This will
244 * be the first byte following the compilation unit header. */
248 /* Pointer to the next compilation unit header in the program. */
250 struct comp_unit_head *next;
252 /* Base address of this compilation unit. */
254 CORE_ADDR base_address;
256 /* Non-zero if base_address has been set. */
261 /* Internal state when decoding a particular compilation unit. */
264 /* The objfile containing this compilation unit. */
265 struct objfile *objfile;
267 /* The header of the compilation unit.
269 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
270 should logically be moved to the dwarf2_cu structure. */
271 struct comp_unit_head header;
273 struct function_range *first_fn, *last_fn, *cached_fn;
275 /* The language we are debugging. */
276 enum language language;
277 const struct language_defn *language_defn;
279 const char *producer;
281 /* The generic symbol table building routines have separate lists for
282 file scope symbols and all all other scopes (local scopes). So
283 we need to select the right one to pass to add_symbol_to_list().
284 We do it by keeping a pointer to the correct list in list_in_scope.
286 FIXME: The original dwarf code just treated the file scope as the
287 first local scope, and all other local scopes as nested local
288 scopes, and worked fine. Check to see if we really need to
289 distinguish these in buildsym.c. */
290 struct pending **list_in_scope;
292 /* Maintain an array of referenced fundamental types for the current
293 compilation unit being read. For DWARF version 1, we have to construct
294 the fundamental types on the fly, since no information about the
295 fundamental types is supplied. Each such fundamental type is created by
296 calling a language dependent routine to create the type, and then a
297 pointer to that type is then placed in the array at the index specified
298 by it's FT_<TYPENAME> value. The array has a fixed size set by the
299 FT_NUM_MEMBERS compile time constant, which is the number of predefined
300 fundamental types gdb knows how to construct. */
301 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
303 /* DWARF abbreviation table associated with this compilation unit. */
304 struct abbrev_info **dwarf2_abbrevs;
306 /* Storage for the abbrev table. */
307 struct obstack abbrev_obstack;
309 /* Hash table holding all the loaded partial DIEs. */
312 /* Storage for things with the same lifetime as this read-in compilation
313 unit, including partial DIEs. */
314 struct obstack comp_unit_obstack;
316 /* When multiple dwarf2_cu structures are living in memory, this field
317 chains them all together, so that they can be released efficiently.
318 We will probably also want a generation counter so that most-recently-used
319 compilation units are cached... */
320 struct dwarf2_per_cu_data *read_in_chain;
322 /* Backchain to our per_cu entry if the tree has been built. */
323 struct dwarf2_per_cu_data *per_cu;
325 /* How many compilation units ago was this CU last referenced? */
328 /* Mark used when releasing cached dies. */
329 unsigned int mark : 1;
331 /* This flag will be set if this compilation unit might include
332 inter-compilation-unit references. */
333 unsigned int has_form_ref_addr : 1;
335 /* This flag will be set if this compilation unit includes any
336 DW_TAG_namespace DIEs. If we know that there are explicit
337 DIEs for namespaces, we don't need to try to infer them
338 from mangled names. */
339 unsigned int has_namespace_info : 1;
342 struct dwarf2_per_cu_data
344 /* The start offset and length of this compilation unit. 2**31-1
345 bytes should suffice to store the length of any compilation unit
346 - if it doesn't, GDB will fall over anyway. */
347 unsigned long offset;
348 unsigned long length : 31;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned long queued : 1;
354 /* Set iff currently read in. */
355 struct dwarf2_cu *cu;
357 /* If full symbols for this CU have been read in, then this field
358 holds a map of DIE offsets to types. It isn't always possible
359 to reconstruct this information later, so we have to preserve
365 /* The line number information for a compilation unit (found in the
366 .debug_line section) begins with a "statement program header",
367 which contains the following information. */
370 unsigned int total_length;
371 unsigned short version;
372 unsigned int header_length;
373 unsigned char minimum_instruction_length;
374 unsigned char default_is_stmt;
376 unsigned char line_range;
377 unsigned char opcode_base;
379 /* standard_opcode_lengths[i] is the number of operands for the
380 standard opcode whose value is i. This means that
381 standard_opcode_lengths[0] is unused, and the last meaningful
382 element is standard_opcode_lengths[opcode_base - 1]. */
383 unsigned char *standard_opcode_lengths;
385 /* The include_directories table. NOTE! These strings are not
386 allocated with xmalloc; instead, they are pointers into
387 debug_line_buffer. If you try to free them, `free' will get
389 unsigned int num_include_dirs, include_dirs_size;
392 /* The file_names table. NOTE! These strings are not allocated
393 with xmalloc; instead, they are pointers into debug_line_buffer.
394 Don't try to free them directly. */
395 unsigned int num_file_names, file_names_size;
399 unsigned int dir_index;
400 unsigned int mod_time;
402 int included_p; /* Non-zero if referenced by the Line Number Program. */
405 /* The start and end of the statement program following this
406 header. These point into dwarf2_per_objfile->line_buffer. */
407 char *statement_program_start, *statement_program_end;
410 /* When we construct a partial symbol table entry we only
411 need this much information. */
412 struct partial_die_info
414 /* Offset of this DIE. */
417 /* DWARF-2 tag for this DIE. */
418 ENUM_BITFIELD(dwarf_tag) tag : 16;
420 /* Language code associated with this DIE. This is only used
421 for the compilation unit DIE. */
422 unsigned int language : 8;
424 /* Assorted flags describing the data found in this DIE. */
425 unsigned int has_children : 1;
426 unsigned int is_external : 1;
427 unsigned int is_declaration : 1;
428 unsigned int has_type : 1;
429 unsigned int has_specification : 1;
430 unsigned int has_stmt_list : 1;
431 unsigned int has_pc_info : 1;
433 /* Flag set if the SCOPE field of this structure has been
435 unsigned int scope_set : 1;
437 /* The name of this DIE. Normally the value of DW_AT_name, but
438 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
443 /* The scope to prepend to our children. This is generally
444 allocated on the comp_unit_obstack, so will disappear
445 when this compilation unit leaves the cache. */
448 /* The location description associated with this DIE, if any. */
449 struct dwarf_block *locdesc;
451 /* If HAS_PC_INFO, the PC range associated with this DIE. */
455 /* Pointer into the info_buffer pointing at the target of
456 DW_AT_sibling, if any. */
459 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
460 DW_AT_specification (or DW_AT_abstract_origin or
462 unsigned int spec_offset;
464 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
465 unsigned int line_offset;
467 /* Pointers to this DIE's parent, first child, and next sibling,
469 struct partial_die_info *die_parent, *die_child, *die_sibling;
472 /* This data structure holds the information of an abbrev. */
475 unsigned int number; /* number identifying abbrev */
476 enum dwarf_tag tag; /* dwarf tag */
477 unsigned short has_children; /* boolean */
478 unsigned short num_attrs; /* number of attributes */
479 struct attr_abbrev *attrs; /* an array of attribute descriptions */
480 struct abbrev_info *next; /* next in chain */
485 enum dwarf_attribute name;
486 enum dwarf_form form;
489 /* This data structure holds a complete die structure. */
492 enum dwarf_tag tag; /* Tag indicating type of die */
493 unsigned int abbrev; /* Abbrev number */
494 unsigned int offset; /* Offset in .debug_info section */
495 unsigned int num_attrs; /* Number of attributes */
496 struct attribute *attrs; /* An array of attributes */
497 struct die_info *next_ref; /* Next die in ref hash table */
499 /* The dies in a compilation unit form an n-ary tree. PARENT
500 points to this die's parent; CHILD points to the first child of
501 this node; and all the children of a given node are chained
502 together via their SIBLING fields, terminated by a die whose
504 struct die_info *child; /* Its first child, if any. */
505 struct die_info *sibling; /* Its next sibling, if any. */
506 struct die_info *parent; /* Its parent, if any. */
508 struct type *type; /* Cached type information */
511 /* Attributes have a name and a value */
514 enum dwarf_attribute name;
515 enum dwarf_form form;
519 struct dwarf_block *blk;
527 struct function_range
530 CORE_ADDR lowpc, highpc;
532 struct function_range *next;
535 /* Get at parts of an attribute structure */
537 #define DW_STRING(attr) ((attr)->u.str)
538 #define DW_UNSND(attr) ((attr)->u.unsnd)
539 #define DW_BLOCK(attr) ((attr)->u.blk)
540 #define DW_SND(attr) ((attr)->u.snd)
541 #define DW_ADDR(attr) ((attr)->u.addr)
543 /* Blocks are a bunch of untyped bytes. */
550 #ifndef ATTR_ALLOC_CHUNK
551 #define ATTR_ALLOC_CHUNK 4
554 /* A hash table of die offsets for following references. */
555 #ifndef REF_HASH_SIZE
556 #define REF_HASH_SIZE 1021
559 static struct die_info *die_ref_table[REF_HASH_SIZE];
561 /* Allocate fields for structs, unions and enums in this size. */
562 #ifndef DW_FIELD_ALLOC_CHUNK
563 #define DW_FIELD_ALLOC_CHUNK 4
566 /* A zeroed version of a partial die for initialization purposes. */
567 static struct partial_die_info zeroed_partial_die;
569 /* FIXME: decode_locdesc sets these variables to describe the location
570 to the caller. These ought to be a structure or something. If
571 none of the flags are set, the object lives at the address returned
572 by decode_locdesc. */
574 static int isreg; /* Object lives in register.
575 decode_locdesc's return value is
576 the register number. */
578 /* We put a pointer to this structure in the read_symtab_private field
583 /* Offset in .debug_info for this compilation unit. */
585 unsigned long dwarf_info_offset;
588 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
589 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
591 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
592 but this would require a corresponding change in unpack_field_as_long
594 static int bits_per_byte = 8;
596 /* The routines that read and process dies for a C struct or C++ class
597 pass lists of data member fields and lists of member function fields
598 in an instance of a field_info structure, as defined below. */
601 /* List of data member and baseclasses fields. */
604 struct nextfield *next;
611 /* Number of fields. */
614 /* Number of baseclasses. */
617 /* Set if the accesibility of one of the fields is not public. */
618 int non_public_fields;
620 /* Member function fields array, entries are allocated in the order they
621 are encountered in the object file. */
624 struct nextfnfield *next;
625 struct fn_field fnfield;
629 /* Member function fieldlist array, contains name of possibly overloaded
630 member function, number of overloaded member functions and a pointer
631 to the head of the member function field chain. */
636 struct nextfnfield *head;
640 /* Number of entries in the fnfieldlists array. */
644 /* Loaded secondary compilation units are kept in memory until they
645 have not been referenced for the processing of this many
646 compilation units. Set this to zero to disable caching. Cache
647 sizes of up to at least twenty will improve startup time for
648 typical inter-CU-reference binaries, at an obvious memory cost. */
649 static int dwarf2_max_cache_age = 5;
651 /* Various complaints about symbol reading that don't abort the process */
654 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
656 complaint (&symfile_complaints,
657 "statement list doesn't fit in .debug_line section");
661 dwarf2_complex_location_expr_complaint (void)
663 complaint (&symfile_complaints, "location expression too complex");
667 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
670 complaint (&symfile_complaints,
671 "const value length mismatch for '%s', got %d, expected %d", arg1,
676 dwarf2_macros_too_long_complaint (void)
678 complaint (&symfile_complaints,
679 "macro info runs off end of `.debug_macinfo' section");
683 dwarf2_macro_malformed_definition_complaint (const char *arg1)
685 complaint (&symfile_complaints,
686 "macro debug info contains a malformed macro definition:\n`%s'",
691 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
693 complaint (&symfile_complaints,
694 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
697 /* local function prototypes */
699 static void dwarf2_locate_sections (bfd *, asection *, void *);
702 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
705 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
708 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
709 struct partial_die_info *,
710 struct partial_symtab *);
712 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
714 static void scan_partial_symbols (struct partial_die_info *,
715 CORE_ADDR *, CORE_ADDR *,
718 static void add_partial_symbol (struct partial_die_info *,
721 static int pdi_needs_namespace (enum dwarf_tag tag);
723 static void add_partial_namespace (struct partial_die_info *pdi,
724 CORE_ADDR *lowpc, CORE_ADDR *highpc,
725 struct dwarf2_cu *cu);
727 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
728 struct dwarf2_cu *cu);
730 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
733 struct dwarf2_cu *cu);
735 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
737 static void psymtab_to_symtab_1 (struct partial_symtab *);
739 char *dwarf2_read_section (struct objfile *, asection *);
741 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
743 static void dwarf2_free_abbrev_table (void *);
745 static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *);
747 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
750 static struct partial_die_info *load_partial_dies (bfd *, char *, int,
753 static char *read_partial_die (struct partial_die_info *,
754 struct abbrev_info *abbrev, unsigned int,
755 bfd *, char *, struct dwarf2_cu *);
757 static struct partial_die_info *find_partial_die (unsigned long,
759 struct dwarf2_cu **);
761 static void fixup_partial_die (struct partial_die_info *,
764 static char *read_full_die (struct die_info **, bfd *, char *,
765 struct dwarf2_cu *, int *);
767 static char *read_attribute (struct attribute *, struct attr_abbrev *,
768 bfd *, char *, struct dwarf2_cu *);
770 static char *read_attribute_value (struct attribute *, unsigned,
771 bfd *, char *, struct dwarf2_cu *);
773 static unsigned int read_1_byte (bfd *, char *);
775 static int read_1_signed_byte (bfd *, char *);
777 static unsigned int read_2_bytes (bfd *, char *);
779 static unsigned int read_4_bytes (bfd *, char *);
781 static unsigned long read_8_bytes (bfd *, char *);
783 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
786 static LONGEST read_initial_length (bfd *, char *,
787 struct comp_unit_head *, int *bytes_read);
789 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
792 static char *read_n_bytes (bfd *, char *, unsigned int);
794 static char *read_string (bfd *, char *, unsigned int *);
796 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
799 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
801 static long read_signed_leb128 (bfd *, char *, unsigned int *);
803 static char *skip_leb128 (bfd *, char *);
805 static void set_cu_language (unsigned int, struct dwarf2_cu *);
807 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
810 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
811 struct dwarf2_cu *cu);
813 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
815 static struct die_info *die_specification (struct die_info *die,
818 static void free_line_header (struct line_header *lh);
820 static void add_file_name (struct line_header *, char *, unsigned int,
821 unsigned int, unsigned int);
823 static struct line_header *(dwarf_decode_line_header
824 (unsigned int offset,
825 bfd *abfd, struct dwarf2_cu *cu));
827 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
828 struct dwarf2_cu *, struct partial_symtab *);
830 static void dwarf2_start_subfile (char *, char *);
832 static struct symbol *new_symbol (struct die_info *, struct type *,
835 static void dwarf2_const_value (struct attribute *, struct symbol *,
838 static void dwarf2_const_value_data (struct attribute *attr,
842 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
844 static struct type *die_containing_type (struct die_info *,
848 static struct type *type_at_offset (unsigned int, struct objfile *);
851 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
853 static void read_type_die (struct die_info *, struct dwarf2_cu *);
855 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
857 static char *typename_concat (struct obstack *, const char *prefix, const char *suffix,
860 static void read_typedef (struct die_info *, struct dwarf2_cu *);
862 static void read_base_type (struct die_info *, struct dwarf2_cu *);
864 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
866 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
868 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
870 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
872 static int dwarf2_get_pc_bounds (struct die_info *,
873 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
875 static void get_scope_pc_bounds (struct die_info *,
876 CORE_ADDR *, CORE_ADDR *,
879 static void dwarf2_add_field (struct field_info *, struct die_info *,
882 static void dwarf2_attach_fields_to_type (struct field_info *,
883 struct type *, struct dwarf2_cu *);
885 static void dwarf2_add_member_fn (struct field_info *,
886 struct die_info *, struct type *,
889 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
890 struct type *, struct dwarf2_cu *);
892 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
894 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
896 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
898 static void read_common_block (struct die_info *, struct dwarf2_cu *);
900 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
902 static const char *namespace_name (struct die_info *die,
903 int *is_anonymous, struct dwarf2_cu *);
905 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
907 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
909 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
911 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
913 static void read_array_type (struct die_info *, struct dwarf2_cu *);
915 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
918 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
920 static void read_tag_ptr_to_member_type (struct die_info *,
923 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
925 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
927 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
929 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
931 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
933 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
935 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
938 struct die_info *parent);
940 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
943 struct die_info *parent);
945 static void free_die_list (struct die_info *);
947 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
949 static void process_die (struct die_info *, struct dwarf2_cu *);
951 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
953 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
955 static struct die_info *dwarf2_extension (struct die_info *die,
958 static char *dwarf_tag_name (unsigned int);
960 static char *dwarf_attr_name (unsigned int);
962 static char *dwarf_form_name (unsigned int);
964 static char *dwarf_stack_op_name (unsigned int);
966 static char *dwarf_bool_name (unsigned int);
968 static char *dwarf_type_encoding_name (unsigned int);
971 static char *dwarf_cfi_name (unsigned int);
973 struct die_info *copy_die (struct die_info *);
976 static struct die_info *sibling_die (struct die_info *);
978 static void dump_die (struct die_info *);
980 static void dump_die_list (struct die_info *);
982 static void store_in_ref_table (unsigned int, struct die_info *);
984 static void dwarf2_empty_hash_tables (void);
986 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
989 static int dwarf2_get_attr_constant_value (struct attribute *, int);
991 static struct die_info *follow_die_ref (unsigned int);
993 static struct type *dwarf2_fundamental_type (struct objfile *, int,
996 /* memory allocation interface */
998 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1000 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1002 static struct die_info *dwarf_alloc_die (void);
1004 static void initialize_cu_func_list (struct dwarf2_cu *);
1006 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1007 struct dwarf2_cu *);
1009 static void dwarf_decode_macros (struct line_header *, unsigned int,
1010 char *, bfd *, struct dwarf2_cu *);
1012 static int attr_form_is_block (struct attribute *);
1015 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
1016 struct dwarf2_cu *cu);
1018 static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
1019 struct dwarf2_cu *cu);
1021 static void free_stack_comp_unit (void *);
1023 static void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
1025 static void dummy_obstack_deallocate (void *object, void *data);
1027 static hashval_t partial_die_hash (const void *item);
1029 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1031 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1032 (unsigned long offset, struct objfile *objfile);
1034 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1035 (unsigned long offset, struct objfile *objfile);
1037 static void free_one_comp_unit (void *);
1039 static void free_cached_comp_units (void *);
1041 static void age_cached_comp_units (void);
1043 static void free_one_cached_comp_unit (void *);
1045 static void set_die_type (struct die_info *, struct type *,
1046 struct dwarf2_cu *);
1049 static void reset_die_and_siblings_types (struct die_info *,
1050 struct dwarf2_cu *);
1053 static void create_all_comp_units (struct objfile *);
1055 static void dwarf2_mark (struct dwarf2_cu *);
1057 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1059 /* Try to locate the sections we need for DWARF 2 debugging
1060 information and return true if we have enough to do something. */
1063 dwarf2_has_info (struct objfile *objfile)
1065 struct dwarf2_per_objfile *data;
1067 /* Initialize per-objfile state. */
1068 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1069 memset (data, 0, sizeof (*data));
1070 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1071 dwarf2_per_objfile = data;
1073 dwarf_info_section = 0;
1074 dwarf_abbrev_section = 0;
1075 dwarf_line_section = 0;
1076 dwarf_str_section = 0;
1077 dwarf_macinfo_section = 0;
1078 dwarf_frame_section = 0;
1079 dwarf_eh_frame_section = 0;
1080 dwarf_ranges_section = 0;
1081 dwarf_loc_section = 0;
1083 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1084 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
1087 /* This function is mapped across the sections and remembers the
1088 offset and size of each of the debugging sections we are interested
1092 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
1094 if (strcmp (sectp->name, INFO_SECTION) == 0)
1096 dwarf2_per_objfile->info_size = bfd_get_section_size (sectp);
1097 dwarf_info_section = sectp;
1099 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
1101 dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp);
1102 dwarf_abbrev_section = sectp;
1104 else if (strcmp (sectp->name, LINE_SECTION) == 0)
1106 dwarf2_per_objfile->line_size = bfd_get_section_size (sectp);
1107 dwarf_line_section = sectp;
1109 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
1111 dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp);
1112 dwarf_pubnames_section = sectp;
1114 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
1116 dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp);
1117 dwarf_aranges_section = sectp;
1119 else if (strcmp (sectp->name, LOC_SECTION) == 0)
1121 dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp);
1122 dwarf_loc_section = sectp;
1124 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
1126 dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp);
1127 dwarf_macinfo_section = sectp;
1129 else if (strcmp (sectp->name, STR_SECTION) == 0)
1131 dwarf2_per_objfile->str_size = bfd_get_section_size (sectp);
1132 dwarf_str_section = sectp;
1134 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1136 dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp);
1137 dwarf_frame_section = sectp;
1139 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1141 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1142 if (aflag & SEC_HAS_CONTENTS)
1144 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp);
1145 dwarf_eh_frame_section = sectp;
1148 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1150 dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
1151 dwarf_ranges_section = sectp;
1155 /* Build a partial symbol table. */
1158 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1160 /* We definitely need the .debug_info and .debug_abbrev sections */
1162 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1163 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1165 if (dwarf_line_section)
1166 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1168 dwarf2_per_objfile->line_buffer = NULL;
1170 if (dwarf_str_section)
1171 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1173 dwarf2_per_objfile->str_buffer = NULL;
1175 if (dwarf_macinfo_section)
1176 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1177 dwarf_macinfo_section);
1179 dwarf2_per_objfile->macinfo_buffer = NULL;
1181 if (dwarf_ranges_section)
1182 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1184 dwarf2_per_objfile->ranges_buffer = NULL;
1186 if (dwarf_loc_section)
1187 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1189 dwarf2_per_objfile->loc_buffer = NULL;
1192 || (objfile->global_psymbols.size == 0
1193 && objfile->static_psymbols.size == 0))
1195 init_psymbol_list (objfile, 1024);
1199 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1201 /* Things are significantly easier if we have .debug_aranges and
1202 .debug_pubnames sections */
1204 dwarf2_build_psymtabs_easy (objfile, mainline);
1208 /* only test this case for now */
1210 /* In this case we have to work a bit harder */
1211 dwarf2_build_psymtabs_hard (objfile, mainline);
1216 /* Build the partial symbol table from the information in the
1217 .debug_pubnames and .debug_aranges sections. */
1220 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1222 bfd *abfd = objfile->obfd;
1223 char *aranges_buffer, *pubnames_buffer;
1224 char *aranges_ptr, *pubnames_ptr;
1225 unsigned int entry_length, version, info_offset, info_size;
1227 pubnames_buffer = dwarf2_read_section (objfile,
1228 dwarf_pubnames_section);
1229 pubnames_ptr = pubnames_buffer;
1230 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1232 struct comp_unit_head cu_header;
1235 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1237 pubnames_ptr += bytes_read;
1238 version = read_1_byte (abfd, pubnames_ptr);
1240 info_offset = read_4_bytes (abfd, pubnames_ptr);
1242 info_size = read_4_bytes (abfd, pubnames_ptr);
1246 aranges_buffer = dwarf2_read_section (objfile,
1247 dwarf_aranges_section);
1252 /* Read in the comp unit header information from the debug_info at
1256 read_comp_unit_head (struct comp_unit_head *cu_header,
1257 char *info_ptr, bfd *abfd)
1261 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1263 info_ptr += bytes_read;
1264 cu_header->version = read_2_bytes (abfd, info_ptr);
1266 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1268 info_ptr += bytes_read;
1269 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1271 signed_addr = bfd_get_sign_extend_vma (abfd);
1272 if (signed_addr < 0)
1273 internal_error (__FILE__, __LINE__,
1274 "read_comp_unit_head: dwarf from non elf file");
1275 cu_header->signed_addr_p = signed_addr;
1280 partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr,
1283 char *beg_of_comp_unit = info_ptr;
1285 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1287 if (header->version != 2)
1288 error ("Dwarf Error: wrong version in compilation unit header "
1289 "(is %d, should be %d) [in module %s]", header->version,
1290 2, bfd_get_filename (abfd));
1292 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1293 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1294 "(offset 0x%lx + 6) [in module %s]",
1295 (long) header->abbrev_offset,
1296 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1297 bfd_get_filename (abfd));
1299 if (beg_of_comp_unit + header->length + header->initial_length_size
1300 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1301 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1302 "(offset 0x%lx + 0) [in module %s]",
1303 (long) header->length,
1304 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1305 bfd_get_filename (abfd));
1310 /* Allocate a new partial symtab for file named NAME and mark this new
1311 partial symtab as being an include of PST. */
1314 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1315 struct objfile *objfile)
1317 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1319 subpst->section_offsets = pst->section_offsets;
1320 subpst->textlow = 0;
1321 subpst->texthigh = 0;
1323 subpst->dependencies = (struct partial_symtab **)
1324 obstack_alloc (&objfile->objfile_obstack,
1325 sizeof (struct partial_symtab *));
1326 subpst->dependencies[0] = pst;
1327 subpst->number_of_dependencies = 1;
1329 subpst->globals_offset = 0;
1330 subpst->n_global_syms = 0;
1331 subpst->statics_offset = 0;
1332 subpst->n_static_syms = 0;
1333 subpst->symtab = NULL;
1334 subpst->read_symtab = pst->read_symtab;
1337 /* No private part is necessary for include psymtabs. This property
1338 can be used to differentiate between such include psymtabs and
1339 the regular ones. If it ever happens that a regular psymtab can
1340 legitimally have a NULL private part, then we'll have to add a
1341 dedicated field for that in the dwarf2_pinfo structure. */
1342 subpst->read_symtab_private = NULL;
1345 /* Read the Line Number Program data and extract the list of files
1346 included by the source file represented by PST. Build an include
1347 partial symtab for each of these included files.
1349 This procedure assumes that there *is* a Line Number Program in
1350 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1351 before calling this procedure. */
1354 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1355 struct partial_die_info *pdi,
1356 struct partial_symtab *pst)
1358 struct objfile *objfile = cu->objfile;
1359 bfd *abfd = objfile->obfd;
1360 struct line_header *lh;
1362 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1364 return; /* No linetable, so no includes. */
1366 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1368 free_line_header (lh);
1372 /* Build the partial symbol table by doing a quick pass through the
1373 .debug_info and .debug_abbrev sections. */
1376 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1378 /* Instead of reading this into a big buffer, we should probably use
1379 mmap() on architectures that support it. (FIXME) */
1380 bfd *abfd = objfile->obfd;
1382 char *beg_of_comp_unit;
1383 struct partial_die_info comp_unit_die;
1384 struct partial_symtab *pst;
1385 struct cleanup *back_to;
1386 CORE_ADDR lowpc, highpc, baseaddr;
1388 info_ptr = dwarf2_per_objfile->info_buffer;
1390 /* Any cached compilation units will be linked by the per-objfile
1391 read_in_chain. Make sure to free them when we're done. */
1392 back_to = make_cleanup (free_cached_comp_units, NULL);
1394 /* Since the objects we're extracting from .debug_info vary in
1395 length, only the individual functions to extract them (like
1396 read_comp_unit_head and load_partial_die) can really know whether
1397 the buffer is large enough to hold another complete object.
1399 At the moment, they don't actually check that. If .debug_info
1400 holds just one extra byte after the last compilation unit's dies,
1401 then read_comp_unit_head will happily read off the end of the
1402 buffer. read_partial_die is similarly casual. Those functions
1405 For this loop condition, simply checking whether there's any data
1406 left at all should be sufficient. */
1407 while (info_ptr < (dwarf2_per_objfile->info_buffer
1408 + dwarf2_per_objfile->info_size))
1410 struct cleanup *back_to_inner;
1411 struct dwarf2_cu cu;
1412 struct abbrev_info *abbrev;
1413 unsigned int bytes_read;
1414 struct dwarf2_per_cu_data *this_cu;
1416 beg_of_comp_unit = info_ptr;
1418 memset (&cu, 0, sizeof (cu));
1420 obstack_init (&cu.comp_unit_obstack);
1422 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1424 cu.objfile = objfile;
1425 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1427 /* Complete the cu_header */
1428 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1429 cu.header.first_die_ptr = info_ptr;
1430 cu.header.cu_head_ptr = beg_of_comp_unit;
1432 cu.list_in_scope = &file_symbols;
1434 /* Read the abbrevs for this compilation unit into a table */
1435 dwarf2_read_abbrevs (abfd, &cu);
1436 make_cleanup (dwarf2_free_abbrev_table, &cu);
1438 if (cu.has_form_ref_addr && dwarf2_per_objfile->all_comp_units == NULL)
1439 create_all_comp_units (objfile);
1441 /* Read the compilation unit die */
1442 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1443 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1444 abfd, info_ptr, &cu);
1446 /* Set the language we're debugging */
1447 set_cu_language (comp_unit_die.language, &cu);
1449 /* Allocate a new partial symbol table structure */
1450 pst = start_psymtab_common (objfile, objfile->section_offsets,
1451 comp_unit_die.name ? comp_unit_die.name : "",
1452 comp_unit_die.lowpc,
1453 objfile->global_psymbols.next,
1454 objfile->static_psymbols.next);
1456 if (comp_unit_die.dirname)
1457 pst->dirname = xstrdup (comp_unit_die.dirname);
1459 pst->read_symtab_private = (char *)
1460 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1461 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1462 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1464 /* Store the function that reads in the rest of the symbol table */
1465 pst->read_symtab = dwarf2_psymtab_to_symtab;
1467 if (dwarf2_per_objfile->all_comp_units != NULL)
1469 struct dwarf2_per_cu_data *per_cu;
1471 per_cu = dwarf2_find_comp_unit (cu.header.offset, objfile);
1473 /* If this compilation unit was already read in, free the
1474 cached copy in order to read it in again. This is
1475 necessary because we skipped some symbols when we first
1476 read in the compilation unit (see load_partial_dies).
1477 This problem could be avoided, but the benefit is
1479 if (per_cu->cu != NULL)
1480 free_one_cached_comp_unit (per_cu->cu);
1484 /* Note that this is a pointer to our stack frame, being
1485 added to a global data structure. It will be cleaned up
1486 in free_stack_comp_unit when we finish with this
1487 compilation unit. */
1493 /* Check if comp unit has_children.
1494 If so, read the rest of the partial symbols from this comp unit.
1495 If not, there's no more debug_info for this comp unit. */
1496 if (comp_unit_die.has_children)
1498 struct partial_die_info *first_die;
1500 lowpc = ((CORE_ADDR) -1);
1501 highpc = ((CORE_ADDR) 0);
1503 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1505 scan_partial_symbols (first_die, &lowpc, &highpc, &cu);
1507 /* If we didn't find a lowpc, set it to highpc to avoid
1508 complaints from `maint check'. */
1509 if (lowpc == ((CORE_ADDR) -1))
1512 /* If the compilation unit didn't have an explicit address range,
1513 then use the information extracted from its child dies. */
1514 if (! comp_unit_die.has_pc_info)
1516 comp_unit_die.lowpc = lowpc;
1517 comp_unit_die.highpc = highpc;
1520 pst->textlow = comp_unit_die.lowpc + baseaddr;
1521 pst->texthigh = comp_unit_die.highpc + baseaddr;
1523 pst->n_global_syms = objfile->global_psymbols.next -
1524 (objfile->global_psymbols.list + pst->globals_offset);
1525 pst->n_static_syms = objfile->static_psymbols.next -
1526 (objfile->static_psymbols.list + pst->statics_offset);
1527 sort_pst_symbols (pst);
1529 /* If there is already a psymtab or symtab for a file of this
1530 name, remove it. (If there is a symtab, more drastic things
1531 also happen.) This happens in VxWorks. */
1532 free_named_symtabs (pst->filename);
1534 if (comp_unit_die.has_stmt_list)
1536 /* Get the list of files included in the current compilation unit,
1537 and build a psymtab for each of them. */
1538 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1541 info_ptr = beg_of_comp_unit + cu.header.length
1542 + cu.header.initial_length_size;
1544 do_cleanups (back_to_inner);
1546 do_cleanups (back_to);
1549 /* Load the DIEs for a secondary CU into memory. */
1552 load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile)
1554 bfd *abfd = objfile->obfd;
1555 char *info_ptr, *beg_of_comp_unit;
1556 struct partial_die_info comp_unit_die;
1557 struct dwarf2_cu *cu;
1558 struct abbrev_info *abbrev;
1559 unsigned int bytes_read;
1560 struct cleanup *back_to;
1562 info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset;
1563 beg_of_comp_unit = info_ptr;
1565 cu = xmalloc (sizeof (struct dwarf2_cu));
1566 memset (cu, 0, sizeof (struct dwarf2_cu));
1568 obstack_init (&cu->comp_unit_obstack);
1570 cu->objfile = objfile;
1571 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd);
1573 /* Complete the cu_header. */
1574 cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1575 cu->header.first_die_ptr = info_ptr;
1576 cu->header.cu_head_ptr = beg_of_comp_unit;
1578 /* Read the abbrevs for this compilation unit into a table. */
1579 dwarf2_read_abbrevs (abfd, cu);
1580 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
1582 /* Read the compilation unit die. */
1583 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1584 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1585 abfd, info_ptr, cu);
1587 /* Set the language we're debugging. */
1588 set_cu_language (comp_unit_die.language, cu);
1590 /* Link this compilation unit into the compilation unit tree. */
1592 cu->per_cu = this_cu;
1594 /* Check if comp unit has_children.
1595 If so, read the rest of the partial symbols from this comp unit.
1596 If not, there's no more debug_info for this comp unit. */
1597 if (comp_unit_die.has_children)
1598 load_partial_dies (abfd, info_ptr, 0, cu);
1600 do_cleanups (back_to);
1603 /* Create a list of all compilation units in OBJFILE. We do this only
1604 if an inter-comp-unit reference is found; presumably if there is one,
1605 there will be many, and one will occur early in the .debug_info section.
1606 So there's no point in building this list incrementally. */
1609 create_all_comp_units (struct objfile *objfile)
1613 struct dwarf2_per_cu_data **all_comp_units;
1614 char *info_ptr = dwarf2_per_objfile->info_buffer;
1618 all_comp_units = xmalloc (n_allocated
1619 * sizeof (struct dwarf2_per_cu_data *));
1621 while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1623 struct comp_unit_head cu_header;
1624 char *beg_of_comp_unit;
1625 struct dwarf2_per_cu_data *this_cu;
1626 unsigned long offset;
1629 offset = info_ptr - dwarf2_per_objfile->info_buffer;
1631 /* Read just enough information to find out where the next
1632 compilation unit is. */
1633 cu_header.length = read_initial_length (objfile->obfd, info_ptr,
1634 &cu_header, &bytes_read);
1636 /* Save the compilation unit for later lookup. */
1637 this_cu = obstack_alloc (&objfile->objfile_obstack,
1638 sizeof (struct dwarf2_per_cu_data));
1639 memset (this_cu, 0, sizeof (*this_cu));
1640 this_cu->offset = offset;
1641 this_cu->length = cu_header.length + cu_header.initial_length_size;
1643 if (n_comp_units == n_allocated)
1646 all_comp_units = xrealloc (all_comp_units,
1648 * sizeof (struct dwarf2_per_cu_data *));
1650 all_comp_units[n_comp_units++] = this_cu;
1652 info_ptr = info_ptr + this_cu->length;
1655 dwarf2_per_objfile->all_comp_units
1656 = obstack_alloc (&objfile->objfile_obstack,
1657 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1658 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
1659 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1660 xfree (all_comp_units);
1661 dwarf2_per_objfile->n_comp_units = n_comp_units;
1664 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1665 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1669 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1670 CORE_ADDR *highpc, struct dwarf2_cu *cu)
1672 struct objfile *objfile = cu->objfile;
1673 bfd *abfd = objfile->obfd;
1674 struct partial_die_info *pdi;
1676 /* Now, march along the PDI's, descending into ones which have
1677 interesting children but skipping the children of the other ones,
1678 until we reach the end of the compilation unit. */
1684 fixup_partial_die (pdi, cu);
1686 /* Anonymous namespaces have no name but have interesting
1687 children, so we need to look at them. Ditto for anonymous
1690 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1691 || pdi->tag == DW_TAG_enumeration_type)
1695 case DW_TAG_subprogram:
1696 if (pdi->has_pc_info)
1698 if (pdi->lowpc < *lowpc)
1700 *lowpc = pdi->lowpc;
1702 if (pdi->highpc > *highpc)
1704 *highpc = pdi->highpc;
1706 if (!pdi->is_declaration)
1708 add_partial_symbol (pdi, cu);
1712 case DW_TAG_variable:
1713 case DW_TAG_typedef:
1714 case DW_TAG_union_type:
1715 if (!pdi->is_declaration)
1717 add_partial_symbol (pdi, cu);
1720 case DW_TAG_class_type:
1721 case DW_TAG_structure_type:
1722 if (!pdi->is_declaration)
1724 add_partial_symbol (pdi, cu);
1727 case DW_TAG_enumeration_type:
1728 if (!pdi->is_declaration)
1729 add_partial_enumeration (pdi, cu);
1731 case DW_TAG_base_type:
1732 case DW_TAG_subrange_type:
1733 /* File scope base type definitions are added to the partial
1735 add_partial_symbol (pdi, cu);
1737 case DW_TAG_namespace:
1738 add_partial_namespace (pdi, lowpc, highpc, cu);
1745 /* If the die has a sibling, skip to the sibling. */
1747 pdi = pdi->die_sibling;
1751 /* Functions used to compute the fully scoped name of a partial DIE.
1753 Normally, this is simple. For C++, the parent DIE's fully scoped
1754 name is concatenated with "::" and the partial DIE's name. For
1755 Java, the same thing occurs except that "." is used instead of "::".
1756 Enumerators are an exception; they use the scope of their parent
1757 enumeration type, i.e. the name of the enumeration type is not
1758 prepended to the enumerator.
1760 There are two complexities. One is DW_AT_specification; in this
1761 case "parent" means the parent of the target of the specification,
1762 instead of the direct parent of the DIE. The other is compilers
1763 which do not emit DW_TAG_namespace; in this case we try to guess
1764 the fully qualified name of structure types from their members'
1765 linkage names. This must be done using the DIE's children rather
1766 than the children of any DW_AT_specification target. We only need
1767 to do this for structures at the top level, i.e. if the target of
1768 any DW_AT_specification (if any; otherwise the DIE itself) does not
1771 /* Compute the scope prefix associated with PDI's parent, in
1772 compilation unit CU. The result will be allocated on CU's
1773 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1774 field. NULL is returned if no prefix is necessary. */
1776 partial_die_parent_scope (struct partial_die_info *pdi,
1777 struct dwarf2_cu *cu)
1779 char *grandparent_scope;
1780 struct partial_die_info *parent, *real_pdi;
1781 struct dwarf2_cu *spec_cu;
1783 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1784 then this means the parent of the specification DIE. */
1788 while (real_pdi->has_specification)
1789 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1791 parent = real_pdi->die_parent;
1795 if (parent->scope_set)
1796 return parent->scope;
1798 fixup_partial_die (parent, cu);
1800 grandparent_scope = partial_die_parent_scope (parent, spec_cu);
1802 if (parent->tag == DW_TAG_namespace
1803 || parent->tag == DW_TAG_structure_type
1804 || parent->tag == DW_TAG_class_type
1805 || parent->tag == DW_TAG_union_type)
1807 if (grandparent_scope == NULL)
1808 parent->scope = parent->name;
1810 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
1813 else if (parent->tag == DW_TAG_enumeration_type)
1814 /* Enumerators should not get the name of the enumeration as a prefix. */
1815 parent->scope = grandparent_scope;
1818 /* FIXME drow/2004-04-01: What should we be doing with
1819 function-local names? For partial symbols, we should probably be
1821 complaint (&symfile_complaints,
1822 "unhandled containing DIE tag %d for DIE at %d",
1823 parent->tag, pdi->offset);
1824 parent->scope = grandparent_scope;
1827 parent->scope_set = 1;
1828 return parent->scope;
1831 /* Return the fully scoped name associated with PDI, from compilation unit
1832 CU. The result will be allocated with malloc. */
1834 partial_die_full_name (struct partial_die_info *pdi,
1835 struct dwarf2_cu *cu)
1839 parent_scope = partial_die_parent_scope (pdi, cu);
1840 if (parent_scope == NULL)
1843 return typename_concat (NULL, parent_scope, pdi->name, cu);
1847 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1849 struct objfile *objfile = cu->objfile;
1852 const char *my_prefix;
1853 const struct partial_symbol *psym = NULL;
1855 int built_actual_name = 0;
1857 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1861 if (pdi_needs_namespace (pdi->tag))
1863 actual_name = partial_die_full_name (pdi, cu);
1865 built_actual_name = 1;
1868 if (actual_name == NULL)
1869 actual_name = pdi->name;
1873 case DW_TAG_subprogram:
1874 if (pdi->is_external)
1876 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1877 mst_text, objfile); */
1878 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1879 VAR_DOMAIN, LOC_BLOCK,
1880 &objfile->global_psymbols,
1881 0, pdi->lowpc + baseaddr,
1882 cu->language, objfile);
1886 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1887 mst_file_text, objfile); */
1888 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1889 VAR_DOMAIN, LOC_BLOCK,
1890 &objfile->static_psymbols,
1891 0, pdi->lowpc + baseaddr,
1892 cu->language, objfile);
1895 case DW_TAG_variable:
1896 if (pdi->is_external)
1899 Don't enter into the minimal symbol tables as there is
1900 a minimal symbol table entry from the ELF symbols already.
1901 Enter into partial symbol table if it has a location
1902 descriptor or a type.
1903 If the location descriptor is missing, new_symbol will create
1904 a LOC_UNRESOLVED symbol, the address of the variable will then
1905 be determined from the minimal symbol table whenever the variable
1907 The address for the partial symbol table entry is not
1908 used by GDB, but it comes in handy for debugging partial symbol
1912 addr = decode_locdesc (pdi->locdesc, cu);
1913 if (pdi->locdesc || pdi->has_type)
1914 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1915 VAR_DOMAIN, LOC_STATIC,
1916 &objfile->global_psymbols,
1918 cu->language, objfile);
1922 /* Static Variable. Skip symbols without location descriptors. */
1923 if (pdi->locdesc == NULL)
1925 addr = decode_locdesc (pdi->locdesc, cu);
1926 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1927 mst_file_data, objfile); */
1928 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1929 VAR_DOMAIN, LOC_STATIC,
1930 &objfile->static_psymbols,
1932 cu->language, objfile);
1935 case DW_TAG_typedef:
1936 case DW_TAG_base_type:
1937 case DW_TAG_subrange_type:
1938 add_psymbol_to_list (actual_name, strlen (actual_name),
1939 VAR_DOMAIN, LOC_TYPEDEF,
1940 &objfile->static_psymbols,
1941 0, (CORE_ADDR) 0, cu->language, objfile);
1943 case DW_TAG_namespace:
1944 add_psymbol_to_list (actual_name, strlen (actual_name),
1945 VAR_DOMAIN, LOC_TYPEDEF,
1946 &objfile->global_psymbols,
1947 0, (CORE_ADDR) 0, cu->language, objfile);
1949 case DW_TAG_class_type:
1950 case DW_TAG_structure_type:
1951 case DW_TAG_union_type:
1952 case DW_TAG_enumeration_type:
1953 /* Skip aggregate types without children, these are external
1955 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1956 static vs. global. */
1957 if (pdi->has_children == 0)
1959 add_psymbol_to_list (actual_name, strlen (actual_name),
1960 STRUCT_DOMAIN, LOC_TYPEDEF,
1961 (cu->language == language_cplus
1962 || cu->language == language_java)
1963 ? &objfile->global_psymbols
1964 : &objfile->static_psymbols,
1965 0, (CORE_ADDR) 0, cu->language, objfile);
1967 if (cu->language == language_cplus
1968 || cu->language == language_java)
1970 /* For C++ and Java, these implicitly act as typedefs as well. */
1971 add_psymbol_to_list (actual_name, strlen (actual_name),
1972 VAR_DOMAIN, LOC_TYPEDEF,
1973 &objfile->global_psymbols,
1974 0, (CORE_ADDR) 0, cu->language, objfile);
1977 case DW_TAG_enumerator:
1978 add_psymbol_to_list (actual_name, strlen (actual_name),
1979 VAR_DOMAIN, LOC_CONST,
1980 (cu->language == language_cplus
1981 || cu->language == language_java)
1982 ? &objfile->global_psymbols
1983 : &objfile->static_psymbols,
1984 0, (CORE_ADDR) 0, cu->language, objfile);
1990 /* Check to see if we should scan the name for possible namespace
1991 info. Only do this if this is C++, if we don't have namespace
1992 debugging info in the file, if the psym is of an appropriate type
1993 (otherwise we'll have psym == NULL), and if we actually had a
1994 mangled name to begin with. */
1996 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1997 cases which do not set PSYM above? */
1999 if (cu->language == language_cplus
2000 && cu->has_namespace_info == 0
2002 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
2003 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
2006 if (built_actual_name)
2007 xfree (actual_name);
2010 /* Determine whether a die of type TAG living in a C++ class or
2011 namespace needs to have the name of the scope prepended to the
2012 name listed in the die. */
2015 pdi_needs_namespace (enum dwarf_tag tag)
2019 case DW_TAG_namespace:
2020 case DW_TAG_typedef:
2021 case DW_TAG_class_type:
2022 case DW_TAG_structure_type:
2023 case DW_TAG_union_type:
2024 case DW_TAG_enumeration_type:
2025 case DW_TAG_enumerator:
2032 /* Read a partial die corresponding to a namespace; also, add a symbol
2033 corresponding to that namespace to the symbol table. NAMESPACE is
2034 the name of the enclosing namespace. */
2037 add_partial_namespace (struct partial_die_info *pdi,
2038 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2039 struct dwarf2_cu *cu)
2041 struct objfile *objfile = cu->objfile;
2043 /* Add a symbol for the namespace. */
2045 add_partial_symbol (pdi, cu);
2047 /* Now scan partial symbols in that namespace. */
2049 if (pdi->has_children)
2050 scan_partial_symbols (pdi->die_child, lowpc, highpc, cu);
2053 /* See if we can figure out if the class lives in a namespace. We do
2054 this by looking for a member function; its demangled name will
2055 contain namespace info, if there is any. */
2058 guess_structure_name (struct partial_die_info *struct_pdi,
2059 struct dwarf2_cu *cu)
2061 if ((cu->language == language_cplus
2062 || cu->language == language_java)
2063 && cu->has_namespace_info == 0
2064 && struct_pdi->has_children)
2066 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2067 what template types look like, because the demangler
2068 frequently doesn't give the same name as the debug info. We
2069 could fix this by only using the demangled name to get the
2070 prefix (but see comment in read_structure_type). */
2072 struct partial_die_info *child_pdi = struct_pdi->die_child;
2073 struct partial_die_info *real_pdi;
2074 struct dwarf2_cu *spec_cu;
2076 /* If this DIE (this DIE's specification, if any) has a parent, then
2077 we should not do this. We'll prepend the parent's fully qualified
2078 name when we create the partial symbol. */
2080 real_pdi = struct_pdi;
2082 while (real_pdi->has_specification)
2083 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
2085 if (real_pdi->die_parent != NULL)
2088 while (child_pdi != NULL)
2090 if (child_pdi->tag == DW_TAG_subprogram)
2092 char *actual_class_name
2093 = language_class_name_from_physname (cu->language_defn,
2095 if (actual_class_name != NULL)
2098 = obsavestring (actual_class_name,
2099 strlen (actual_class_name),
2100 &cu->comp_unit_obstack);
2101 xfree (actual_class_name);
2106 child_pdi = child_pdi->die_sibling;
2111 /* Read a partial die corresponding to an enumeration type. */
2114 add_partial_enumeration (struct partial_die_info *enum_pdi,
2115 struct dwarf2_cu *cu)
2117 struct objfile *objfile = cu->objfile;
2118 bfd *abfd = objfile->obfd;
2119 struct partial_die_info *pdi;
2121 if (enum_pdi->name != NULL)
2122 add_partial_symbol (enum_pdi, cu);
2124 pdi = enum_pdi->die_child;
2127 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2128 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
2130 add_partial_symbol (pdi, cu);
2131 pdi = pdi->die_sibling;
2135 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2136 Return the corresponding abbrev, or NULL if the number is zero (indicating
2137 an empty DIE). In either case *BYTES_READ will be set to the length of
2138 the initial number. */
2140 static struct abbrev_info *
2141 peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu)
2143 bfd *abfd = cu->objfile->obfd;
2144 unsigned int abbrev_number;
2145 struct abbrev_info *abbrev;
2147 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2149 if (abbrev_number == 0)
2152 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2155 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
2156 bfd_get_filename (abfd));
2162 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2163 pointer to the end of a series of DIEs, terminated by an empty
2164 DIE. Any children of the skipped DIEs will also be skipped. */
2167 skip_children (char *info_ptr, struct dwarf2_cu *cu)
2169 struct abbrev_info *abbrev;
2170 unsigned int bytes_read;
2174 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2176 return info_ptr + bytes_read;
2178 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
2182 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2183 should point just after the initial uleb128 of a DIE, and the
2184 abbrev corresponding to that skipped uleb128 should be passed in
2185 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2189 skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
2190 struct dwarf2_cu *cu)
2192 unsigned int bytes_read;
2193 struct attribute attr;
2194 bfd *abfd = cu->objfile->obfd;
2195 unsigned int form, i;
2197 for (i = 0; i < abbrev->num_attrs; i++)
2199 /* The only abbrev we care about is DW_AT_sibling. */
2200 if (abbrev->attrs[i].name == DW_AT_sibling)
2202 read_attribute (&attr, &abbrev->attrs[i],
2203 abfd, info_ptr, cu);
2204 if (attr.form == DW_FORM_ref_addr)
2205 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
2207 return dwarf2_per_objfile->info_buffer
2208 + dwarf2_get_ref_die_offset (&attr, cu);
2211 /* If it isn't DW_AT_sibling, skip this attribute. */
2212 form = abbrev->attrs[i].form;
2217 case DW_FORM_ref_addr:
2218 info_ptr += cu->header.addr_size;
2237 case DW_FORM_string:
2238 read_string (abfd, info_ptr, &bytes_read);
2239 info_ptr += bytes_read;
2242 info_ptr += cu->header.offset_size;
2245 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2246 info_ptr += bytes_read;
2248 case DW_FORM_block1:
2249 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2251 case DW_FORM_block2:
2252 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2254 case DW_FORM_block4:
2255 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2259 case DW_FORM_ref_udata:
2260 info_ptr = skip_leb128 (abfd, info_ptr);
2262 case DW_FORM_indirect:
2263 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2264 info_ptr += bytes_read;
2265 /* We need to continue parsing from here, so just go back to
2267 goto skip_attribute;
2270 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2271 dwarf_form_name (form),
2272 bfd_get_filename (abfd));
2276 if (abbrev->has_children)
2277 return skip_children (info_ptr, cu);
2282 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2283 the next DIE after ORIG_PDI. */
2286 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
2287 bfd *abfd, struct dwarf2_cu *cu)
2289 /* Do we know the sibling already? */
2291 if (orig_pdi->sibling)
2292 return orig_pdi->sibling;
2294 /* Are there any children to deal with? */
2296 if (!orig_pdi->has_children)
2299 /* Skip the children the long way. */
2301 return skip_children (info_ptr, cu);
2304 /* Expand this partial symbol table into a full symbol table. */
2307 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2309 /* FIXME: This is barely more than a stub. */
2314 warning ("bug: psymtab for %s is already read in.", pst->filename);
2320 printf_filtered ("Reading in symbols for %s...", pst->filename);
2321 gdb_flush (gdb_stdout);
2324 psymtab_to_symtab_1 (pst);
2326 /* Finish up the debug error message. */
2328 printf_filtered ("done.\n");
2334 psymtab_to_symtab_1 (struct partial_symtab *pst)
2336 struct objfile *objfile = pst->objfile;
2337 bfd *abfd = objfile->obfd;
2338 struct dwarf2_cu cu;
2339 struct die_info *dies;
2340 unsigned long offset;
2341 CORE_ADDR lowpc, highpc;
2342 struct die_info *child_die;
2344 struct symtab *symtab;
2345 struct cleanup *back_to;
2346 struct attribute *attr;
2350 for (i = 0; i < pst->number_of_dependencies; i++)
2351 if (!pst->dependencies[i]->readin)
2353 /* Inform about additional files that need to be read in. */
2356 fputs_filtered (" ", gdb_stdout);
2358 fputs_filtered ("and ", gdb_stdout);
2360 printf_filtered ("%s...", pst->dependencies[i]->filename);
2361 wrap_here (""); /* Flush output */
2362 gdb_flush (gdb_stdout);
2364 psymtab_to_symtab_1 (pst->dependencies[i]);
2367 if (pst->read_symtab_private == NULL)
2369 /* It's an include file, no symbols to read for it.
2370 Everything is in the parent symtab. */
2375 dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key);
2377 /* Set local variables from the partial symbol table info. */
2378 offset = DWARF_INFO_OFFSET (pst);
2380 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2381 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2383 /* We're in the global namespace. */
2384 processing_current_prefix = "";
2386 memset (&cu, 0, sizeof (struct dwarf2_cu));
2387 obstack_init (&cu.comp_unit_obstack);
2388 back_to = make_cleanup (free_stack_comp_unit, &cu);
2391 make_cleanup (really_free_pendings, NULL);
2393 cu.objfile = objfile;
2395 /* read in the comp_unit header */
2396 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
2398 /* Read the abbrevs for this compilation unit */
2399 dwarf2_read_abbrevs (abfd, &cu);
2400 make_cleanup (dwarf2_free_abbrev_table, &cu);
2402 cu.header.offset = offset;
2404 cu.list_in_scope = &file_symbols;
2406 dies = read_comp_unit (info_ptr, abfd, &cu);
2408 make_cleanup_free_die_list (dies);
2410 /* Find the base address of the compilation unit for range lists and
2411 location lists. It will normally be specified by DW_AT_low_pc.
2412 In DWARF-3 draft 4, the base address could be overridden by
2413 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2414 compilation units with discontinuous ranges. */
2416 cu.header.base_known = 0;
2417 cu.header.base_address = 0;
2419 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
2422 cu.header.base_address = DW_ADDR (attr);
2423 cu.header.base_known = 1;
2427 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
2430 cu.header.base_address = DW_ADDR (attr);
2431 cu.header.base_known = 1;
2435 /* Do line number decoding in read_file_scope () */
2436 process_die (dies, &cu);
2438 /* Some compilers don't define a DW_AT_high_pc attribute for the
2439 compilation unit. If the DW_AT_high_pc is missing, synthesize
2440 it, by scanning the DIE's below the compilation unit. */
2441 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
2443 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2445 /* Set symtab language to language from DW_AT_language.
2446 If the compilation is from a C file generated by language preprocessors,
2447 do not set the language if it was already deduced by start_subfile. */
2449 && !(cu.language == language_c && symtab->language != language_c))
2451 symtab->language = cu.language;
2453 pst->symtab = symtab;
2456 do_cleanups (back_to);
2459 /* Process a die and its children. */
2462 process_die (struct die_info *die, struct dwarf2_cu *cu)
2466 case DW_TAG_padding:
2468 case DW_TAG_compile_unit:
2469 read_file_scope (die, cu);
2471 case DW_TAG_subprogram:
2472 read_subroutine_type (die, cu);
2473 read_func_scope (die, cu);
2475 case DW_TAG_inlined_subroutine:
2476 /* FIXME: These are ignored for now.
2477 They could be used to set breakpoints on all inlined instances
2478 of a function and make GDB `next' properly over inlined functions. */
2480 case DW_TAG_lexical_block:
2481 case DW_TAG_try_block:
2482 case DW_TAG_catch_block:
2483 read_lexical_block_scope (die, cu);
2485 case DW_TAG_class_type:
2486 case DW_TAG_structure_type:
2487 case DW_TAG_union_type:
2488 read_structure_type (die, cu);
2489 process_structure_scope (die, cu);
2491 case DW_TAG_enumeration_type:
2492 read_enumeration_type (die, cu);
2493 process_enumeration_scope (die, cu);
2496 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2497 a symbol or process any children. Therefore it doesn't do anything
2498 that won't be done on-demand by read_type_die. */
2499 case DW_TAG_subroutine_type:
2500 read_subroutine_type (die, cu);
2502 case DW_TAG_array_type:
2503 read_array_type (die, cu);
2505 case DW_TAG_pointer_type:
2506 read_tag_pointer_type (die, cu);
2508 case DW_TAG_ptr_to_member_type:
2509 read_tag_ptr_to_member_type (die, cu);
2511 case DW_TAG_reference_type:
2512 read_tag_reference_type (die, cu);
2514 case DW_TAG_string_type:
2515 read_tag_string_type (die, cu);
2519 case DW_TAG_base_type:
2520 read_base_type (die, cu);
2521 /* Add a typedef symbol for the type definition, if it has a
2523 new_symbol (die, die->type, cu);
2525 case DW_TAG_subrange_type:
2526 read_subrange_type (die, cu);
2527 /* Add a typedef symbol for the type definition, if it has a
2529 new_symbol (die, die->type, cu);
2531 case DW_TAG_common_block:
2532 read_common_block (die, cu);
2534 case DW_TAG_common_inclusion:
2536 case DW_TAG_namespace:
2537 processing_has_namespace_info = 1;
2538 read_namespace (die, cu);
2540 case DW_TAG_imported_declaration:
2541 case DW_TAG_imported_module:
2542 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2543 information contained in these. DW_TAG_imported_declaration
2544 dies shouldn't have children; DW_TAG_imported_module dies
2545 shouldn't in the C++ case, but conceivably could in the
2546 Fortran case, so we'll have to replace this gdb_assert if
2547 Fortran compilers start generating that info. */
2548 processing_has_namespace_info = 1;
2549 gdb_assert (die->child == NULL);
2552 new_symbol (die, NULL, cu);
2558 initialize_cu_func_list (struct dwarf2_cu *cu)
2560 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2564 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2566 struct objfile *objfile = cu->objfile;
2567 struct comp_unit_head *cu_header = &cu->header;
2568 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2569 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2570 CORE_ADDR highpc = ((CORE_ADDR) 0);
2571 struct attribute *attr;
2572 char *name = "<unknown>";
2573 char *comp_dir = NULL;
2574 struct die_info *child_die;
2575 bfd *abfd = objfile->obfd;
2576 struct line_header *line_header = 0;
2579 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2581 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2583 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2584 from finish_block. */
2585 if (lowpc == ((CORE_ADDR) -1))
2590 attr = dwarf2_attr (die, DW_AT_name, cu);
2593 name = DW_STRING (attr);
2595 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2598 comp_dir = DW_STRING (attr);
2601 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2602 directory, get rid of it. */
2603 char *cp = strchr (comp_dir, ':');
2605 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2610 attr = dwarf2_attr (die, DW_AT_language, cu);
2613 set_cu_language (DW_UNSND (attr), cu);
2616 attr = dwarf2_attr (die, DW_AT_producer, cu);
2618 cu->producer = DW_STRING (attr);
2620 /* We assume that we're processing GCC output. */
2621 processing_gcc_compilation = 2;
2623 /* FIXME:Do something here. */
2624 if (dip->at_producer != NULL)
2626 handle_producer (dip->at_producer);
2630 /* The compilation unit may be in a different language or objfile,
2631 zero out all remembered fundamental types. */
2632 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2634 start_symtab (name, comp_dir, lowpc);
2635 record_debugformat ("DWARF 2");
2637 initialize_cu_func_list (cu);
2639 /* Process all dies in compilation unit. */
2640 if (die->child != NULL)
2642 child_die = die->child;
2643 while (child_die && child_die->tag)
2645 process_die (child_die, cu);
2646 child_die = sibling_die (child_die);
2650 /* Decode line number information if present. */
2651 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2654 unsigned int line_offset = DW_UNSND (attr);
2655 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2658 make_cleanup ((make_cleanup_ftype *) free_line_header,
2659 (void *) line_header);
2660 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
2664 /* Decode macro information, if present. Dwarf 2 macro information
2665 refers to information in the line number info statement program
2666 header, so we can only read it if we've read the header
2668 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2669 if (attr && line_header)
2671 unsigned int macro_offset = DW_UNSND (attr);
2672 dwarf_decode_macros (line_header, macro_offset,
2673 comp_dir, abfd, cu);
2675 do_cleanups (back_to);
2679 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2680 struct dwarf2_cu *cu)
2682 struct function_range *thisfn;
2684 thisfn = (struct function_range *)
2685 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
2686 thisfn->name = name;
2687 thisfn->lowpc = lowpc;
2688 thisfn->highpc = highpc;
2689 thisfn->seen_line = 0;
2690 thisfn->next = NULL;
2692 if (cu->last_fn == NULL)
2693 cu->first_fn = thisfn;
2695 cu->last_fn->next = thisfn;
2697 cu->last_fn = thisfn;
2701 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2703 struct objfile *objfile = cu->objfile;
2704 struct context_stack *new;
2707 struct die_info *child_die;
2708 struct attribute *attr;
2710 const char *previous_prefix = processing_current_prefix;
2711 struct cleanup *back_to = NULL;
2714 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2716 name = dwarf2_linkage_name (die, cu);
2718 /* Ignore functions with missing or empty names and functions with
2719 missing or invalid low and high pc attributes. */
2720 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2723 if (cu->language == language_cplus
2724 || cu->language == language_java)
2726 struct die_info *spec_die = die_specification (die, cu);
2728 /* NOTE: carlton/2004-01-23: We have to be careful in the
2729 presence of DW_AT_specification. For example, with GCC 3.4,
2734 // Definition of N::foo.
2738 then we'll have a tree of DIEs like this:
2740 1: DW_TAG_compile_unit
2741 2: DW_TAG_namespace // N
2742 3: DW_TAG_subprogram // declaration of N::foo
2743 4: DW_TAG_subprogram // definition of N::foo
2744 DW_AT_specification // refers to die #3
2746 Thus, when processing die #4, we have to pretend that we're
2747 in the context of its DW_AT_specification, namely the contex
2750 if (spec_die != NULL)
2752 char *specification_prefix = determine_prefix (spec_die, cu);
2753 processing_current_prefix = specification_prefix;
2754 back_to = make_cleanup (xfree, specification_prefix);
2761 /* Record the function range for dwarf_decode_lines. */
2762 add_to_cu_func_list (name, lowpc, highpc, cu);
2764 new = push_context (0, lowpc);
2765 new->name = new_symbol (die, die->type, cu);
2767 /* If there is a location expression for DW_AT_frame_base, record
2769 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2771 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2772 expression is being recorded directly in the function's symbol
2773 and not in a separate frame-base object. I guess this hack is
2774 to avoid adding some sort of frame-base adjunct/annex to the
2775 function's symbol :-(. The problem with doing this is that it
2776 results in a function symbol with a location expression that
2777 has nothing to do with the location of the function, ouch! The
2778 relationship should be: a function's symbol has-a frame base; a
2779 frame-base has-a location expression. */
2780 dwarf2_symbol_mark_computed (attr, new->name, cu);
2782 cu->list_in_scope = &local_symbols;
2784 if (die->child != NULL)
2786 child_die = die->child;
2787 while (child_die && child_die->tag)
2789 process_die (child_die, cu);
2790 child_die = sibling_die (child_die);
2794 new = pop_context ();
2795 /* Make a block for the local symbols within. */
2796 finish_block (new->name, &local_symbols, new->old_blocks,
2797 lowpc, highpc, objfile);
2799 /* In C++, we can have functions nested inside functions (e.g., when
2800 a function declares a class that has methods). This means that
2801 when we finish processing a function scope, we may need to go
2802 back to building a containing block's symbol lists. */
2803 local_symbols = new->locals;
2804 param_symbols = new->params;
2806 /* If we've finished processing a top-level function, subsequent
2807 symbols go in the file symbol list. */
2808 if (outermost_context_p ())
2809 cu->list_in_scope = &file_symbols;
2811 processing_current_prefix = previous_prefix;
2812 if (back_to != NULL)
2813 do_cleanups (back_to);
2816 /* Process all the DIES contained within a lexical block scope. Start
2817 a new scope, process the dies, and then close the scope. */
2820 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2822 struct objfile *objfile = cu->objfile;
2823 struct context_stack *new;
2824 CORE_ADDR lowpc, highpc;
2825 struct die_info *child_die;
2828 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2830 /* Ignore blocks with missing or invalid low and high pc attributes. */
2831 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2832 as multiple lexical blocks? Handling children in a sane way would
2833 be nasty. Might be easier to properly extend generic blocks to
2835 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2840 push_context (0, lowpc);
2841 if (die->child != NULL)
2843 child_die = die->child;
2844 while (child_die && child_die->tag)
2846 process_die (child_die, cu);
2847 child_die = sibling_die (child_die);
2850 new = pop_context ();
2852 if (local_symbols != NULL)
2854 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2857 local_symbols = new->locals;
2860 /* Get low and high pc attributes from a die. Return 1 if the attributes
2861 are present and valid, otherwise, return 0. Return -1 if the range is
2862 discontinuous, i.e. derived from DW_AT_ranges information. */
2864 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2865 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2867 struct objfile *objfile = cu->objfile;
2868 struct comp_unit_head *cu_header = &cu->header;
2869 struct attribute *attr;
2870 bfd *obfd = objfile->obfd;
2875 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2878 high = DW_ADDR (attr);
2879 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2881 low = DW_ADDR (attr);
2883 /* Found high w/o low attribute. */
2886 /* Found consecutive range of addresses. */
2891 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2894 unsigned int addr_size = cu_header->addr_size;
2895 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2896 /* Value of the DW_AT_ranges attribute is the offset in the
2897 .debug_ranges section. */
2898 unsigned int offset = DW_UNSND (attr);
2899 /* Base address selection entry. */
2907 found_base = cu_header->base_known;
2908 base = cu_header->base_address;
2910 if (offset >= dwarf2_per_objfile->ranges_size)
2912 complaint (&symfile_complaints,
2913 "Offset %d out of bounds for DW_AT_ranges attribute",
2917 buffer = dwarf2_per_objfile->ranges_buffer + offset;
2919 /* Read in the largest possible address. */
2920 marker = read_address (obfd, buffer, cu, &dummy);
2921 if ((marker & mask) == mask)
2923 /* If we found the largest possible address, then
2924 read the base address. */
2925 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2926 buffer += 2 * addr_size;
2927 offset += 2 * addr_size;
2935 CORE_ADDR range_beginning, range_end;
2937 range_beginning = read_address (obfd, buffer, cu, &dummy);
2938 buffer += addr_size;
2939 range_end = read_address (obfd, buffer, cu, &dummy);
2940 buffer += addr_size;
2941 offset += 2 * addr_size;
2943 /* An end of list marker is a pair of zero addresses. */
2944 if (range_beginning == 0 && range_end == 0)
2945 /* Found the end of list entry. */
2948 /* Each base address selection entry is a pair of 2 values.
2949 The first is the largest possible address, the second is
2950 the base address. Check for a base address here. */
2951 if ((range_beginning & mask) == mask)
2953 /* If we found the largest possible address, then
2954 read the base address. */
2955 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2962 /* We have no valid base address for the ranges
2964 complaint (&symfile_complaints,
2965 "Invalid .debug_ranges data (no base address)");
2969 range_beginning += base;
2972 /* FIXME: This is recording everything as a low-high
2973 segment of consecutive addresses. We should have a
2974 data structure for discontiguous block ranges
2978 low = range_beginning;
2984 if (range_beginning < low)
2985 low = range_beginning;
2986 if (range_end > high)
2992 /* If the first entry is an end-of-list marker, the range
2993 describes an empty scope, i.e. no instructions. */
3003 /* When using the GNU linker, .gnu.linkonce. sections are used to
3004 eliminate duplicate copies of functions and vtables and such.
3005 The linker will arbitrarily choose one and discard the others.
3006 The AT_*_pc values for such functions refer to local labels in
3007 these sections. If the section from that file was discarded, the
3008 labels are not in the output, so the relocs get a value of 0.
3009 If this is a discarded function, mark the pc bounds as invalid,
3010 so that GDB will ignore it. */
3011 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
3019 /* Get the low and high pc's represented by the scope DIE, and store
3020 them in *LOWPC and *HIGHPC. If the correct values can't be
3021 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3024 get_scope_pc_bounds (struct die_info *die,
3025 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3026 struct dwarf2_cu *cu)
3028 CORE_ADDR best_low = (CORE_ADDR) -1;
3029 CORE_ADDR best_high = (CORE_ADDR) 0;
3030 CORE_ADDR current_low, current_high;
3032 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
3034 best_low = current_low;
3035 best_high = current_high;
3039 struct die_info *child = die->child;
3041 while (child && child->tag)
3043 switch (child->tag) {
3044 case DW_TAG_subprogram:
3045 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
3047 best_low = min (best_low, current_low);
3048 best_high = max (best_high, current_high);
3051 case DW_TAG_namespace:
3052 /* FIXME: carlton/2004-01-16: Should we do this for
3053 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3054 that current GCC's always emit the DIEs corresponding
3055 to definitions of methods of classes as children of a
3056 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3057 the DIEs giving the declarations, which could be
3058 anywhere). But I don't see any reason why the
3059 standards says that they have to be there. */
3060 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
3062 if (current_low != ((CORE_ADDR) -1))
3064 best_low = min (best_low, current_low);
3065 best_high = max (best_high, current_high);
3073 child = sibling_die (child);
3078 *highpc = best_high;
3081 /* Add an aggregate field to the field list. */
3084 dwarf2_add_field (struct field_info *fip, struct die_info *die,
3085 struct dwarf2_cu *cu)
3087 struct objfile *objfile = cu->objfile;
3088 struct nextfield *new_field;
3089 struct attribute *attr;
3091 char *fieldname = "";
3093 /* Allocate a new field list entry and link it in. */
3094 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3095 make_cleanup (xfree, new_field);
3096 memset (new_field, 0, sizeof (struct nextfield));
3097 new_field->next = fip->fields;
3098 fip->fields = new_field;
3101 /* Handle accessibility and virtuality of field.
3102 The default accessibility for members is public, the default
3103 accessibility for inheritance is private. */
3104 if (die->tag != DW_TAG_inheritance)
3105 new_field->accessibility = DW_ACCESS_public;
3107 new_field->accessibility = DW_ACCESS_private;
3108 new_field->virtuality = DW_VIRTUALITY_none;
3110 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3112 new_field->accessibility = DW_UNSND (attr);
3113 if (new_field->accessibility != DW_ACCESS_public)
3114 fip->non_public_fields = 1;
3115 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
3117 new_field->virtuality = DW_UNSND (attr);
3119 fp = &new_field->field;
3121 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
3123 /* Data member other than a C++ static data member. */
3125 /* Get type of field. */
3126 fp->type = die_type (die, cu);
3128 FIELD_STATIC_KIND (*fp) = 0;
3130 /* Get bit size of field (zero if none). */
3131 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
3134 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
3138 FIELD_BITSIZE (*fp) = 0;
3141 /* Get bit offset of field. */
3142 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3145 FIELD_BITPOS (*fp) =
3146 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
3149 FIELD_BITPOS (*fp) = 0;
3150 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
3153 if (BITS_BIG_ENDIAN)
3155 /* For big endian bits, the DW_AT_bit_offset gives the
3156 additional bit offset from the MSB of the containing
3157 anonymous object to the MSB of the field. We don't
3158 have to do anything special since we don't need to
3159 know the size of the anonymous object. */
3160 FIELD_BITPOS (*fp) += DW_UNSND (attr);
3164 /* For little endian bits, compute the bit offset to the
3165 MSB of the anonymous object, subtract off the number of
3166 bits from the MSB of the field to the MSB of the
3167 object, and then subtract off the number of bits of
3168 the field itself. The result is the bit offset of
3169 the LSB of the field. */
3171 int bit_offset = DW_UNSND (attr);
3173 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3176 /* The size of the anonymous object containing
3177 the bit field is explicit, so use the
3178 indicated size (in bytes). */
3179 anonymous_size = DW_UNSND (attr);
3183 /* The size of the anonymous object containing
3184 the bit field must be inferred from the type
3185 attribute of the data member containing the
3187 anonymous_size = TYPE_LENGTH (fp->type);
3189 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
3190 - bit_offset - FIELD_BITSIZE (*fp);
3194 /* Get name of field. */
3195 attr = dwarf2_attr (die, DW_AT_name, cu);
3196 if (attr && DW_STRING (attr))
3197 fieldname = DW_STRING (attr);
3199 /* The name is already allocated along with this objfile, so we don't
3200 need to duplicate it for the type. */
3201 fp->name = fieldname;
3203 /* Change accessibility for artificial fields (e.g. virtual table
3204 pointer or virtual base class pointer) to private. */
3205 if (dwarf2_attr (die, DW_AT_artificial, cu))
3207 new_field->accessibility = DW_ACCESS_private;
3208 fip->non_public_fields = 1;
3211 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
3213 /* C++ static member. */
3215 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3216 is a declaration, but all versions of G++ as of this writing
3217 (so through at least 3.2.1) incorrectly generate
3218 DW_TAG_variable tags. */
3222 /* Get name of field. */
3223 attr = dwarf2_attr (die, DW_AT_name, cu);
3224 if (attr && DW_STRING (attr))
3225 fieldname = DW_STRING (attr);
3229 /* Get physical name. */
3230 physname = dwarf2_linkage_name (die, cu);
3232 /* The name is already allocated along with this objfile, so we don't
3233 need to duplicate it for the type. */
3234 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
3235 FIELD_TYPE (*fp) = die_type (die, cu);
3236 FIELD_NAME (*fp) = fieldname;
3238 else if (die->tag == DW_TAG_inheritance)
3240 /* C++ base class field. */
3241 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3243 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
3245 FIELD_BITSIZE (*fp) = 0;
3246 FIELD_STATIC_KIND (*fp) = 0;
3247 FIELD_TYPE (*fp) = die_type (die, cu);
3248 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3249 fip->nbaseclasses++;
3253 /* Create the vector of fields, and attach it to the type. */
3256 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3257 struct dwarf2_cu *cu)
3259 int nfields = fip->nfields;
3261 /* Record the field count, allocate space for the array of fields,
3262 and create blank accessibility bitfields if necessary. */
3263 TYPE_NFIELDS (type) = nfields;
3264 TYPE_FIELDS (type) = (struct field *)
3265 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3266 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3268 if (fip->non_public_fields)
3270 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3272 TYPE_FIELD_PRIVATE_BITS (type) =
3273 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3274 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3276 TYPE_FIELD_PROTECTED_BITS (type) =
3277 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3278 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3280 TYPE_FIELD_IGNORE_BITS (type) =
3281 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3282 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3285 /* If the type has baseclasses, allocate and clear a bit vector for
3286 TYPE_FIELD_VIRTUAL_BITS. */
3287 if (fip->nbaseclasses)
3289 int num_bytes = B_BYTES (fip->nbaseclasses);
3292 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3293 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3294 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3295 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
3296 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
3299 /* Copy the saved-up fields into the field vector. Start from the head
3300 of the list, adding to the tail of the field array, so that they end
3301 up in the same order in the array in which they were added to the list. */
3302 while (nfields-- > 0)
3304 TYPE_FIELD (type, nfields) = fip->fields->field;
3305 switch (fip->fields->accessibility)
3307 case DW_ACCESS_private:
3308 SET_TYPE_FIELD_PRIVATE (type, nfields);
3311 case DW_ACCESS_protected:
3312 SET_TYPE_FIELD_PROTECTED (type, nfields);
3315 case DW_ACCESS_public:
3319 /* Unknown accessibility. Complain and treat it as public. */
3321 complaint (&symfile_complaints, "unsupported accessibility %d",
3322 fip->fields->accessibility);
3326 if (nfields < fip->nbaseclasses)
3328 switch (fip->fields->virtuality)
3330 case DW_VIRTUALITY_virtual:
3331 case DW_VIRTUALITY_pure_virtual:
3332 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3336 fip->fields = fip->fields->next;
3340 /* Add a member function to the proper fieldlist. */
3343 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3344 struct type *type, struct dwarf2_cu *cu)
3346 struct objfile *objfile = cu->objfile;
3347 struct attribute *attr;
3348 struct fnfieldlist *flp;
3350 struct fn_field *fnp;
3353 struct nextfnfield *new_fnfield;
3355 /* Get name of member function. */
3356 attr = dwarf2_attr (die, DW_AT_name, cu);
3357 if (attr && DW_STRING (attr))
3358 fieldname = DW_STRING (attr);
3362 /* Get the mangled name. */
3363 physname = dwarf2_linkage_name (die, cu);
3365 /* Look up member function name in fieldlist. */
3366 for (i = 0; i < fip->nfnfields; i++)
3368 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3372 /* Create new list element if necessary. */
3373 if (i < fip->nfnfields)
3374 flp = &fip->fnfieldlists[i];
3377 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3379 fip->fnfieldlists = (struct fnfieldlist *)
3380 xrealloc (fip->fnfieldlists,
3381 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3382 * sizeof (struct fnfieldlist));
3383 if (fip->nfnfields == 0)
3384 make_cleanup (free_current_contents, &fip->fnfieldlists);
3386 flp = &fip->fnfieldlists[fip->nfnfields];
3387 flp->name = fieldname;
3393 /* Create a new member function field and chain it to the field list
3395 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3396 make_cleanup (xfree, new_fnfield);
3397 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3398 new_fnfield->next = flp->head;
3399 flp->head = new_fnfield;
3402 /* Fill in the member function field info. */
3403 fnp = &new_fnfield->fnfield;
3404 /* The name is already allocated along with this objfile, so we don't
3405 need to duplicate it for the type. */
3406 fnp->physname = physname ? physname : "";
3407 fnp->type = alloc_type (objfile);
3408 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
3410 int nparams = TYPE_NFIELDS (die->type);
3412 /* TYPE is the domain of this method, and DIE->TYPE is the type
3413 of the method itself (TYPE_CODE_METHOD). */
3414 smash_to_method_type (fnp->type, type,
3415 TYPE_TARGET_TYPE (die->type),
3416 TYPE_FIELDS (die->type),
3417 TYPE_NFIELDS (die->type),
3418 TYPE_VARARGS (die->type));
3420 /* Handle static member functions.
3421 Dwarf2 has no clean way to discern C++ static and non-static
3422 member functions. G++ helps GDB by marking the first
3423 parameter for non-static member functions (which is the
3424 this pointer) as artificial. We obtain this information
3425 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3426 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
3427 fnp->voffset = VOFFSET_STATIC;
3430 complaint (&symfile_complaints, "member function type missing for '%s'",
3433 /* Get fcontext from DW_AT_containing_type if present. */
3434 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3435 fnp->fcontext = die_containing_type (die, cu);
3437 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3438 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3440 /* Get accessibility. */
3441 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3444 switch (DW_UNSND (attr))
3446 case DW_ACCESS_private:
3447 fnp->is_private = 1;
3449 case DW_ACCESS_protected:
3450 fnp->is_protected = 1;
3455 /* Check for artificial methods. */
3456 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3457 if (attr && DW_UNSND (attr) != 0)
3458 fnp->is_artificial = 1;
3460 /* Get index in virtual function table if it is a virtual member function. */
3461 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3464 /* Support the .debug_loc offsets */
3465 if (attr_form_is_block (attr))
3467 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3469 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3471 dwarf2_complex_location_expr_complaint ();
3475 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3481 /* Create the vector of member function fields, and attach it to the type. */
3484 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
3485 struct dwarf2_cu *cu)
3487 struct fnfieldlist *flp;
3488 int total_length = 0;
3491 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3492 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3493 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
3495 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
3497 struct nextfnfield *nfp = flp->head;
3498 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
3501 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
3502 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
3503 fn_flp->fn_fields = (struct fn_field *)
3504 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
3505 for (k = flp->length; (k--, nfp); nfp = nfp->next)
3506 fn_flp->fn_fields[k] = nfp->fnfield;
3508 total_length += flp->length;
3511 TYPE_NFN_FIELDS (type) = fip->nfnfields;
3512 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3516 /* Returns non-zero if NAME is the name of a vtable member in CU's
3517 language, zero otherwise. */
3519 is_vtable_name (const char *name, struct dwarf2_cu *cu)
3521 static const char vptr[] = "_vptr";
3522 static const char vtable[] = "vtable";
3524 /* Look for the C++ and Java forms of the vtable. */
3525 if ((cu->language == language_java
3526 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
3527 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
3528 && is_cplus_marker (name[sizeof (vptr) - 1])))
3535 /* Called when we find the DIE that starts a structure or union scope
3536 (definition) to process all dies that define the members of the
3539 NOTE: we need to call struct_type regardless of whether or not the
3540 DIE has an at_name attribute, since it might be an anonymous
3541 structure or union. This gets the type entered into our set of
3544 However, if the structure is incomplete (an opaque struct/union)
3545 then suppress creating a symbol table entry for it since gdb only
3546 wants to find the one with the complete definition. Note that if
3547 it is complete, we just call new_symbol, which does it's own
3548 checking about whether the struct/union is anonymous or not (and
3549 suppresses creating a symbol table entry itself). */
3552 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3554 struct objfile *objfile = cu->objfile;
3556 struct attribute *attr;
3557 const char *previous_prefix = processing_current_prefix;
3558 struct cleanup *back_to = NULL;
3563 type = alloc_type (objfile);
3565 INIT_CPLUS_SPECIFIC (type);
3566 attr = dwarf2_attr (die, DW_AT_name, cu);
3567 if (attr && DW_STRING (attr))
3569 if (cu->language == language_cplus
3570 || cu->language == language_java)
3572 char *new_prefix = determine_class_name (die, cu);
3573 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3574 strlen (new_prefix),
3575 &objfile->objfile_obstack);
3576 back_to = make_cleanup (xfree, new_prefix);
3577 processing_current_prefix = new_prefix;
3581 /* The name is already allocated along with this objfile, so
3582 we don't need to duplicate it for the type. */
3583 TYPE_TAG_NAME (type) = DW_STRING (attr);
3587 if (die->tag == DW_TAG_structure_type)
3589 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3591 else if (die->tag == DW_TAG_union_type)
3593 TYPE_CODE (type) = TYPE_CODE_UNION;
3597 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3599 TYPE_CODE (type) = TYPE_CODE_CLASS;
3602 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3605 TYPE_LENGTH (type) = DW_UNSND (attr);
3609 TYPE_LENGTH (type) = 0;
3612 if (die_is_declaration (die, cu))
3613 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3615 /* We need to add the type field to the die immediately so we don't
3616 infinitely recurse when dealing with pointers to the structure
3617 type within the structure itself. */
3618 set_die_type (die, type, cu);
3620 if (die->child != NULL && ! die_is_declaration (die, cu))
3622 struct field_info fi;
3623 struct die_info *child_die;
3624 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3626 memset (&fi, 0, sizeof (struct field_info));
3628 child_die = die->child;
3630 while (child_die && child_die->tag)
3632 if (child_die->tag == DW_TAG_member
3633 || child_die->tag == DW_TAG_variable)
3635 /* NOTE: carlton/2002-11-05: A C++ static data member
3636 should be a DW_TAG_member that is a declaration, but
3637 all versions of G++ as of this writing (so through at
3638 least 3.2.1) incorrectly generate DW_TAG_variable
3639 tags for them instead. */
3640 dwarf2_add_field (&fi, child_die, cu);
3642 else if (child_die->tag == DW_TAG_subprogram)
3644 /* C++ member function. */
3645 read_type_die (child_die, cu);
3646 dwarf2_add_member_fn (&fi, child_die, type, cu);
3648 else if (child_die->tag == DW_TAG_inheritance)
3650 /* C++ base class field. */
3651 dwarf2_add_field (&fi, child_die, cu);
3653 child_die = sibling_die (child_die);
3656 /* Attach fields and member functions to the type. */
3658 dwarf2_attach_fields_to_type (&fi, type, cu);
3661 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3663 /* Get the type which refers to the base class (possibly this
3664 class itself) which contains the vtable pointer for the current
3665 class from the DW_AT_containing_type attribute. */
3667 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3669 struct type *t = die_containing_type (die, cu);
3671 TYPE_VPTR_BASETYPE (type) = t;
3676 /* Our own class provides vtbl ptr. */
3677 for (i = TYPE_NFIELDS (t) - 1;
3678 i >= TYPE_N_BASECLASSES (t);
3681 char *fieldname = TYPE_FIELD_NAME (t, i);
3683 if (is_vtable_name (fieldname, cu))
3685 TYPE_VPTR_FIELDNO (type) = i;
3690 /* Complain if virtual function table field not found. */
3691 if (i < TYPE_N_BASECLASSES (t))
3692 complaint (&symfile_complaints,
3693 "virtual function table pointer not found when defining class '%s'",
3694 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3699 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3704 do_cleanups (back_to);
3707 processing_current_prefix = previous_prefix;
3708 if (back_to != NULL)
3709 do_cleanups (back_to);
3713 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3715 struct objfile *objfile = cu->objfile;
3716 const char *previous_prefix = processing_current_prefix;
3717 struct die_info *child_die = die->child;
3719 if (TYPE_TAG_NAME (die->type) != NULL)
3720 processing_current_prefix = TYPE_TAG_NAME (die->type);
3722 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3723 snapshots) has been known to create a die giving a declaration
3724 for a class that has, as a child, a die giving a definition for a
3725 nested class. So we have to process our children even if the
3726 current die is a declaration. Normally, of course, a declaration
3727 won't have any children at all. */
3729 while (child_die != NULL && child_die->tag)
3731 if (child_die->tag == DW_TAG_member
3732 || child_die->tag == DW_TAG_variable
3733 || child_die->tag == DW_TAG_inheritance)
3738 process_die (child_die, cu);
3740 child_die = sibling_die (child_die);
3743 if (die->child != NULL && ! die_is_declaration (die, cu))
3744 new_symbol (die, die->type, cu);
3746 processing_current_prefix = previous_prefix;
3749 /* Given a DW_AT_enumeration_type die, set its type. We do not
3750 complete the type's fields yet, or create any symbols. */
3753 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3755 struct objfile *objfile = cu->objfile;
3757 struct attribute *attr;
3762 type = alloc_type (objfile);
3764 TYPE_CODE (type) = TYPE_CODE_ENUM;
3765 attr = dwarf2_attr (die, DW_AT_name, cu);
3766 if (attr && DW_STRING (attr))
3768 char *name = DW_STRING (attr);
3770 if (processing_has_namespace_info)
3772 TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack,
3773 processing_current_prefix,
3778 /* The name is already allocated along with this objfile, so
3779 we don't need to duplicate it for the type. */
3780 TYPE_TAG_NAME (type) = name;
3784 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3787 TYPE_LENGTH (type) = DW_UNSND (attr);
3791 TYPE_LENGTH (type) = 0;
3794 set_die_type (die, type, cu);
3797 /* Determine the name of the type represented by DIE, which should be
3798 a named C++ or Java compound type. Return the name in question; the caller
3799 is responsible for xfree()'ing it. */
3802 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3804 struct cleanup *back_to = NULL;
3805 struct die_info *spec_die = die_specification (die, cu);
3806 char *new_prefix = NULL;
3808 /* If this is the definition of a class that is declared by another
3809 die, then processing_current_prefix may not be accurate; see
3810 read_func_scope for a similar example. */
3811 if (spec_die != NULL)
3813 char *specification_prefix = determine_prefix (spec_die, cu);
3814 processing_current_prefix = specification_prefix;
3815 back_to = make_cleanup (xfree, specification_prefix);
3818 /* If we don't have namespace debug info, guess the name by trying
3819 to demangle the names of members, just like we did in
3820 guess_structure_name. */
3821 if (!processing_has_namespace_info)
3823 struct die_info *child;
3825 for (child = die->child;
3826 child != NULL && child->tag != 0;
3827 child = sibling_die (child))
3829 if (child->tag == DW_TAG_subprogram)
3832 = language_class_name_from_physname (cu->language_defn,
3836 if (new_prefix != NULL)
3842 if (new_prefix == NULL)
3844 const char *name = dwarf2_name (die, cu);
3845 new_prefix = typename_concat (NULL, processing_current_prefix,
3846 name ? name : "<<anonymous>>",
3850 if (back_to != NULL)
3851 do_cleanups (back_to);
3856 /* Given a pointer to a die which begins an enumeration, process all
3857 the dies that define the members of the enumeration, and create the
3858 symbol for the enumeration type.
3860 NOTE: We reverse the order of the element list. */
3863 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3865 struct objfile *objfile = cu->objfile;
3866 struct die_info *child_die;
3867 struct field *fields;
3868 struct attribute *attr;
3871 int unsigned_enum = 1;
3875 if (die->child != NULL)
3877 child_die = die->child;
3878 while (child_die && child_die->tag)
3880 if (child_die->tag != DW_TAG_enumerator)
3882 process_die (child_die, cu);
3886 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3889 sym = new_symbol (child_die, die->type, cu);
3890 if (SYMBOL_VALUE (sym) < 0)
3893 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3895 fields = (struct field *)
3897 (num_fields + DW_FIELD_ALLOC_CHUNK)
3898 * sizeof (struct field));
3901 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3902 FIELD_TYPE (fields[num_fields]) = NULL;
3903 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3904 FIELD_BITSIZE (fields[num_fields]) = 0;
3905 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3911 child_die = sibling_die (child_die);
3916 TYPE_NFIELDS (die->type) = num_fields;
3917 TYPE_FIELDS (die->type) = (struct field *)
3918 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3919 memcpy (TYPE_FIELDS (die->type), fields,
3920 sizeof (struct field) * num_fields);
3924 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3927 new_symbol (die, die->type, cu);
3930 /* Extract all information from a DW_TAG_array_type DIE and put it in
3931 the DIE's type field. For now, this only handles one dimensional
3935 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3937 struct objfile *objfile = cu->objfile;
3938 struct die_info *child_die;
3939 struct type *type = NULL;
3940 struct type *element_type, *range_type, *index_type;
3941 struct type **range_types = NULL;
3942 struct attribute *attr;
3944 struct cleanup *back_to;
3946 /* Return if we've already decoded this type. */
3952 element_type = die_type (die, cu);
3954 /* Irix 6.2 native cc creates array types without children for
3955 arrays with unspecified length. */
3956 if (die->child == NULL)
3958 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3959 range_type = create_range_type (NULL, index_type, 0, -1);
3960 set_die_type (die, create_array_type (NULL, element_type, range_type),
3965 back_to = make_cleanup (null_cleanup, NULL);
3966 child_die = die->child;
3967 while (child_die && child_die->tag)
3969 if (child_die->tag == DW_TAG_subrange_type)
3971 read_subrange_type (child_die, cu);
3973 if (child_die->type != NULL)
3975 /* The range type was succesfully read. Save it for
3976 the array type creation. */
3977 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3979 range_types = (struct type **)
3980 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3981 * sizeof (struct type *));
3983 make_cleanup (free_current_contents, &range_types);
3985 range_types[ndim++] = child_die->type;
3988 child_die = sibling_die (child_die);
3991 /* Dwarf2 dimensions are output from left to right, create the
3992 necessary array types in backwards order. */
3994 type = element_type;
3996 if (read_array_order (die, cu) == DW_ORD_col_major)
4000 type = create_array_type (NULL, type, range_types[i++]);
4005 type = create_array_type (NULL, type, range_types[ndim]);
4008 /* Understand Dwarf2 support for vector types (like they occur on
4009 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4010 array type. This is not part of the Dwarf2/3 standard yet, but a
4011 custom vendor extension. The main difference between a regular
4012 array and the vector variant is that vectors are passed by value
4014 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
4016 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
4018 do_cleanups (back_to);
4020 /* Install the type in the die. */
4021 set_die_type (die, type, cu);
4024 static enum dwarf_array_dim_ordering
4025 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
4027 struct attribute *attr;
4029 attr = dwarf2_attr (die, DW_AT_ordering, cu);
4031 if (attr) return DW_SND (attr);
4034 GNU F77 is a special case, as at 08/2004 array type info is the
4035 opposite order to the dwarf2 specification, but data is still
4036 laid out as per normal fortran.
4038 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4042 if (cu->language == language_fortran &&
4043 cu->producer && strstr (cu->producer, "GNU F77"))
4045 return DW_ORD_row_major;
4048 switch (cu->language_defn->la_array_ordering)
4050 case array_column_major:
4051 return DW_ORD_col_major;
4052 case array_row_major:
4054 return DW_ORD_row_major;
4059 /* First cut: install each common block member as a global variable. */
4062 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
4064 struct die_info *child_die;
4065 struct attribute *attr;
4067 CORE_ADDR base = (CORE_ADDR) 0;
4069 attr = dwarf2_attr (die, DW_AT_location, cu);
4072 /* Support the .debug_loc offsets */
4073 if (attr_form_is_block (attr))
4075 base = decode_locdesc (DW_BLOCK (attr), cu);
4077 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
4079 dwarf2_complex_location_expr_complaint ();
4083 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4084 "common block member");
4087 if (die->child != NULL)
4089 child_die = die->child;
4090 while (child_die && child_die->tag)
4092 sym = new_symbol (child_die, NULL, cu);
4093 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
4096 SYMBOL_VALUE_ADDRESS (sym) =
4097 base + decode_locdesc (DW_BLOCK (attr), cu);
4098 add_symbol_to_list (sym, &global_symbols);
4100 child_die = sibling_die (child_die);
4105 /* Read a C++ namespace. */
4108 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
4110 struct objfile *objfile = cu->objfile;
4111 const char *previous_prefix = processing_current_prefix;
4114 struct die_info *current_die;
4115 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4117 name = namespace_name (die, &is_anonymous, cu);
4119 /* Now build the name of the current namespace. */
4121 if (previous_prefix[0] == '\0')
4123 processing_current_prefix = name;
4127 char *temp_name = typename_concat (NULL, previous_prefix, name, cu);
4128 make_cleanup (xfree, temp_name);
4129 processing_current_prefix = temp_name;
4132 /* Add a symbol associated to this if we haven't seen the namespace
4133 before. Also, add a using directive if it's an anonymous
4136 if (dwarf2_extension (die, cu) == NULL)
4140 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4141 this cast will hopefully become unnecessary. */
4142 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
4143 (char *) processing_current_prefix,
4145 TYPE_TAG_NAME (type) = TYPE_NAME (type);
4147 new_symbol (die, type, cu);
4148 set_die_type (die, type, cu);
4151 cp_add_using_directive (processing_current_prefix,
4152 strlen (previous_prefix),
4153 strlen (processing_current_prefix));
4156 if (die->child != NULL)
4158 struct die_info *child_die = die->child;
4160 while (child_die && child_die->tag)
4162 process_die (child_die, cu);
4163 child_die = sibling_die (child_die);
4167 processing_current_prefix = previous_prefix;
4168 do_cleanups (back_to);
4171 /* Return the name of the namespace represented by DIE. Set
4172 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4176 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
4178 struct die_info *current_die;
4179 const char *name = NULL;
4181 /* Loop through the extensions until we find a name. */
4183 for (current_die = die;
4184 current_die != NULL;
4185 current_die = dwarf2_extension (die, cu))
4187 name = dwarf2_name (current_die, cu);
4192 /* Is it an anonymous namespace? */
4194 *is_anonymous = (name == NULL);
4196 name = "(anonymous namespace)";
4201 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4202 the user defined type vector. */
4205 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
4207 struct comp_unit_head *cu_header = &cu->header;
4209 struct attribute *attr_byte_size;
4210 struct attribute *attr_address_class;
4211 int byte_size, addr_class;
4218 type = lookup_pointer_type (die_type (die, cu));
4220 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
4222 byte_size = DW_UNSND (attr_byte_size);
4224 byte_size = cu_header->addr_size;
4226 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
4227 if (attr_address_class)
4228 addr_class = DW_UNSND (attr_address_class);
4230 addr_class = DW_ADDR_none;
4232 /* If the pointer size or address class is different than the
4233 default, create a type variant marked as such and set the
4234 length accordingly. */
4235 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
4237 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4241 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
4242 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
4243 type = make_type_with_address_space (type, type_flags);
4245 else if (TYPE_LENGTH (type) != byte_size)
4247 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
4250 /* Should we also complain about unhandled address classes? */
4254 TYPE_LENGTH (type) = byte_size;
4255 set_die_type (die, type, cu);
4258 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4259 the user defined type vector. */
4262 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
4264 struct objfile *objfile = cu->objfile;
4266 struct type *to_type;
4267 struct type *domain;
4274 type = alloc_type (objfile);
4275 to_type = die_type (die, cu);
4276 domain = die_containing_type (die, cu);
4277 smash_to_member_type (type, domain, to_type);
4279 set_die_type (die, type, cu);
4282 /* Extract all information from a DW_TAG_reference_type DIE and add to
4283 the user defined type vector. */
4286 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
4288 struct comp_unit_head *cu_header = &cu->header;
4290 struct attribute *attr;
4297 type = lookup_reference_type (die_type (die, cu));
4298 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4301 TYPE_LENGTH (type) = DW_UNSND (attr);
4305 TYPE_LENGTH (type) = cu_header->addr_size;
4307 set_die_type (die, type, cu);
4311 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
4313 struct type *base_type;
4320 base_type = die_type (die, cu);
4321 set_die_type (die, make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0),
4326 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
4328 struct type *base_type;
4335 base_type = die_type (die, cu);
4336 set_die_type (die, make_cv_type (TYPE_CONST (base_type), 1, base_type, 0),
4340 /* Extract all information from a DW_TAG_string_type DIE and add to
4341 the user defined type vector. It isn't really a user defined type,
4342 but it behaves like one, with other DIE's using an AT_user_def_type
4343 attribute to reference it. */
4346 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
4348 struct objfile *objfile = cu->objfile;
4349 struct type *type, *range_type, *index_type, *char_type;
4350 struct attribute *attr;
4351 unsigned int length;
4358 attr = dwarf2_attr (die, DW_AT_string_length, cu);
4361 length = DW_UNSND (attr);
4365 /* check for the DW_AT_byte_size attribute */
4366 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4369 length = DW_UNSND (attr);
4376 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
4377 range_type = create_range_type (NULL, index_type, 1, length);
4378 if (cu->language == language_fortran)
4380 /* Need to create a unique string type for bounds
4382 type = create_string_type (0, range_type);
4386 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
4387 type = create_string_type (char_type, range_type);
4389 set_die_type (die, type, cu);
4392 /* Handle DIES due to C code like:
4396 int (*funcp)(int a, long l);
4400 ('funcp' generates a DW_TAG_subroutine_type DIE)
4404 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4406 struct type *type; /* Type that this function returns */
4407 struct type *ftype; /* Function that returns above type */
4408 struct attribute *attr;
4410 /* Decode the type that this subroutine returns */
4415 type = die_type (die, cu);
4416 ftype = lookup_function_type (type);
4418 /* All functions in C++ and Java have prototypes. */
4419 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
4420 if ((attr && (DW_UNSND (attr) != 0))
4421 || cu->language == language_cplus
4422 || cu->language == language_java)
4423 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
4425 if (die->child != NULL)
4427 struct die_info *child_die;
4431 /* Count the number of parameters.
4432 FIXME: GDB currently ignores vararg functions, but knows about
4433 vararg member functions. */
4434 child_die = die->child;
4435 while (child_die && child_die->tag)
4437 if (child_die->tag == DW_TAG_formal_parameter)
4439 else if (child_die->tag == DW_TAG_unspecified_parameters)
4440 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
4441 child_die = sibling_die (child_die);
4444 /* Allocate storage for parameters and fill them in. */
4445 TYPE_NFIELDS (ftype) = nparams;
4446 TYPE_FIELDS (ftype) = (struct field *)
4447 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
4449 child_die = die->child;
4450 while (child_die && child_die->tag)
4452 if (child_die->tag == DW_TAG_formal_parameter)
4454 /* Dwarf2 has no clean way to discern C++ static and non-static
4455 member functions. G++ helps GDB by marking the first
4456 parameter for non-static member functions (which is the
4457 this pointer) as artificial. We pass this information
4458 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4459 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
4461 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
4463 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
4464 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
4467 child_die = sibling_die (child_die);
4471 set_die_type (die, ftype, cu);
4475 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
4477 struct objfile *objfile = cu->objfile;
4478 struct attribute *attr;
4483 attr = dwarf2_attr (die, DW_AT_name, cu);
4484 if (attr && DW_STRING (attr))
4486 name = DW_STRING (attr);
4488 set_die_type (die, init_type (TYPE_CODE_TYPEDEF, 0,
4489 TYPE_FLAG_TARGET_STUB, name, objfile),
4491 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
4495 /* Find a representation of a given base type and install
4496 it in the TYPE field of the die. */
4499 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
4501 struct objfile *objfile = cu->objfile;
4503 struct attribute *attr;
4504 int encoding = 0, size = 0;
4506 /* If we've already decoded this die, this is a no-op. */
4512 attr = dwarf2_attr (die, DW_AT_encoding, cu);
4515 encoding = DW_UNSND (attr);
4517 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4520 size = DW_UNSND (attr);
4522 attr = dwarf2_attr (die, DW_AT_name, cu);
4523 if (attr && DW_STRING (attr))
4525 enum type_code code = TYPE_CODE_INT;
4530 case DW_ATE_address:
4531 /* Turn DW_ATE_address into a void * pointer. */
4532 code = TYPE_CODE_PTR;
4533 type_flags |= TYPE_FLAG_UNSIGNED;
4535 case DW_ATE_boolean:
4536 code = TYPE_CODE_BOOL;
4537 type_flags |= TYPE_FLAG_UNSIGNED;
4539 case DW_ATE_complex_float:
4540 code = TYPE_CODE_COMPLEX;
4543 code = TYPE_CODE_FLT;
4546 case DW_ATE_signed_char:
4548 case DW_ATE_unsigned:
4549 case DW_ATE_unsigned_char:
4550 type_flags |= TYPE_FLAG_UNSIGNED;
4553 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
4554 dwarf_type_encoding_name (encoding));
4557 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4558 if (encoding == DW_ATE_address)
4559 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4561 else if (encoding == DW_ATE_complex_float)
4564 TYPE_TARGET_TYPE (type)
4565 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4566 else if (size == 16)
4567 TYPE_TARGET_TYPE (type)
4568 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4570 TYPE_TARGET_TYPE (type)
4571 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4576 type = dwarf_base_type (encoding, size, cu);
4578 set_die_type (die, type, cu);
4581 /* Read the given DW_AT_subrange DIE. */
4584 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4586 struct type *base_type;
4587 struct type *range_type;
4588 struct attribute *attr;
4592 /* If we have already decoded this die, then nothing more to do. */
4596 base_type = die_type (die, cu);
4597 if (base_type == NULL)
4599 complaint (&symfile_complaints,
4600 "DW_AT_type missing from DW_TAG_subrange_type");
4604 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4605 base_type = alloc_type (NULL);
4607 if (cu->language == language_fortran)
4609 /* FORTRAN implies a lower bound of 1, if not given. */
4613 /* FIXME: For variable sized arrays either of these could be
4614 a variable rather than a constant value. We'll allow it,
4615 but we don't know how to handle it. */
4616 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4618 low = dwarf2_get_attr_constant_value (attr, 0);
4620 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4623 if (attr->form == DW_FORM_block1)
4625 /* GCC encodes arrays with unspecified or dynamic length
4626 with a DW_FORM_block1 attribute.
4627 FIXME: GDB does not yet know how to handle dynamic
4628 arrays properly, treat them as arrays with unspecified
4631 FIXME: jimb/2003-09-22: GDB does not really know
4632 how to handle arrays of unspecified length
4633 either; we just represent them as zero-length
4634 arrays. Choose an appropriate upper bound given
4635 the lower bound we've computed above. */
4639 high = dwarf2_get_attr_constant_value (attr, 1);
4642 range_type = create_range_type (NULL, base_type, low, high);
4644 attr = dwarf2_attr (die, DW_AT_name, cu);
4645 if (attr && DW_STRING (attr))
4646 TYPE_NAME (range_type) = DW_STRING (attr);
4648 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4650 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4652 set_die_type (die, range_type, cu);
4656 /* Read a whole compilation unit into a linked list of dies. */
4658 static struct die_info *
4659 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4661 /* Reset die reference table; we are
4662 building new ones now. */
4663 dwarf2_empty_hash_tables ();
4665 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4668 /* Read a single die and all its descendents. Set the die's sibling
4669 field to NULL; set other fields in the die correctly, and set all
4670 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4671 location of the info_ptr after reading all of those dies. PARENT
4672 is the parent of the die in question. */
4674 static struct die_info *
4675 read_die_and_children (char *info_ptr, bfd *abfd,
4676 struct dwarf2_cu *cu,
4677 char **new_info_ptr,
4678 struct die_info *parent)
4680 struct die_info *die;
4684 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4685 store_in_ref_table (die->offset, die);
4689 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4695 *new_info_ptr = cur_ptr;
4698 die->sibling = NULL;
4699 die->parent = parent;
4703 /* Read a die, all of its descendents, and all of its siblings; set
4704 all of the fields of all of the dies correctly. Arguments are as
4705 in read_die_and_children. */
4707 static struct die_info *
4708 read_die_and_siblings (char *info_ptr, bfd *abfd,
4709 struct dwarf2_cu *cu,
4710 char **new_info_ptr,
4711 struct die_info *parent)
4713 struct die_info *first_die, *last_sibling;
4717 first_die = last_sibling = NULL;
4721 struct die_info *die
4722 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4730 last_sibling->sibling = die;
4735 *new_info_ptr = cur_ptr;
4745 /* Free a linked list of dies. */
4748 free_die_list (struct die_info *dies)
4750 struct die_info *die, *next;
4755 if (die->child != NULL)
4756 free_die_list (die->child);
4757 next = die->sibling;
4765 do_free_die_list_cleanup (void *dies)
4767 free_die_list (dies);
4770 static struct cleanup *
4771 make_cleanup_free_die_list (struct die_info *dies)
4773 return make_cleanup (do_free_die_list_cleanup, dies);
4777 /* Read the contents of the section at OFFSET and of size SIZE from the
4778 object file specified by OBJFILE into the objfile_obstack and return it. */
4781 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4783 bfd *abfd = objfile->obfd;
4785 bfd_size_type size = bfd_get_section_size (sectp);
4790 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4792 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4796 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4797 || bfd_bread (buf, size, abfd) != size)
4798 error ("Dwarf Error: Can't read DWARF data from '%s'",
4799 bfd_get_filename (abfd));
4804 /* In DWARF version 2, the description of the debugging information is
4805 stored in a separate .debug_abbrev section. Before we read any
4806 dies from a section we read in all abbreviations and install them
4807 in a hash table. This function also sets flags in CU describing
4808 the data found in the abbrev table. */
4811 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4813 struct comp_unit_head *cu_header = &cu->header;
4815 struct abbrev_info *cur_abbrev;
4816 unsigned int abbrev_number, bytes_read, abbrev_name;
4817 unsigned int abbrev_form, hash_number;
4818 struct attr_abbrev *cur_attrs;
4819 unsigned int allocated_attrs;
4821 /* Initialize dwarf2 abbrevs */
4822 obstack_init (&cu->abbrev_obstack);
4823 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
4825 * sizeof (struct abbrev_info *)));
4826 memset (cu->dwarf2_abbrevs, 0,
4827 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
4829 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
4830 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4831 abbrev_ptr += bytes_read;
4833 allocated_attrs = ATTR_ALLOC_CHUNK;
4834 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
4836 /* loop until we reach an abbrev number of 0 */
4837 while (abbrev_number)
4839 cur_abbrev = dwarf_alloc_abbrev (cu);
4841 /* read in abbrev header */
4842 cur_abbrev->number = abbrev_number;
4843 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4844 abbrev_ptr += bytes_read;
4845 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4848 if (cur_abbrev->tag == DW_TAG_namespace)
4849 cu->has_namespace_info = 1;
4851 /* now read in declarations */
4852 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4853 abbrev_ptr += bytes_read;
4854 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4855 abbrev_ptr += bytes_read;
4858 if (cur_abbrev->num_attrs == allocated_attrs)
4860 allocated_attrs += ATTR_ALLOC_CHUNK;
4862 = xrealloc (cur_attrs, (allocated_attrs
4863 * sizeof (struct attr_abbrev)));
4866 /* Record whether this compilation unit might have
4867 inter-compilation-unit references. If we don't know what form
4868 this attribute will have, then it might potentially be a
4869 DW_FORM_ref_addr, so we conservatively expect inter-CU
4872 if (abbrev_form == DW_FORM_ref_addr
4873 || abbrev_form == DW_FORM_indirect)
4874 cu->has_form_ref_addr = 1;
4876 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
4877 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4878 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4879 abbrev_ptr += bytes_read;
4880 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4881 abbrev_ptr += bytes_read;
4884 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
4885 (cur_abbrev->num_attrs
4886 * sizeof (struct attr_abbrev)));
4887 memcpy (cur_abbrev->attrs, cur_attrs,
4888 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
4890 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4891 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
4892 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
4894 /* Get next abbreviation.
4895 Under Irix6 the abbreviations for a compilation unit are not
4896 always properly terminated with an abbrev number of 0.
4897 Exit loop if we encounter an abbreviation which we have
4898 already read (which means we are about to read the abbreviations
4899 for the next compile unit) or if the end of the abbreviation
4900 table is reached. */
4901 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
4902 >= dwarf2_per_objfile->abbrev_size)
4904 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4905 abbrev_ptr += bytes_read;
4906 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4913 /* Release the memory used by the abbrev table for a compilation unit. */
4916 dwarf2_free_abbrev_table (void *ptr_to_cu)
4918 struct dwarf2_cu *cu = ptr_to_cu;
4920 obstack_free (&cu->abbrev_obstack, NULL);
4921 cu->dwarf2_abbrevs = NULL;
4924 /* Lookup an abbrev_info structure in the abbrev hash table. */
4926 static struct abbrev_info *
4927 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4929 unsigned int hash_number;
4930 struct abbrev_info *abbrev;
4932 hash_number = number % ABBREV_HASH_SIZE;
4933 abbrev = cu->dwarf2_abbrevs[hash_number];
4937 if (abbrev->number == number)
4940 abbrev = abbrev->next;
4945 /* Returns nonzero if TAG represents a type that we might generate a partial
4949 is_type_tag_for_partial (int tag)
4954 /* Some types that would be reasonable to generate partial symbols for,
4955 that we don't at present. */
4956 case DW_TAG_array_type:
4957 case DW_TAG_file_type:
4958 case DW_TAG_ptr_to_member_type:
4959 case DW_TAG_set_type:
4960 case DW_TAG_string_type:
4961 case DW_TAG_subroutine_type:
4963 case DW_TAG_base_type:
4964 case DW_TAG_class_type:
4965 case DW_TAG_enumeration_type:
4966 case DW_TAG_structure_type:
4967 case DW_TAG_subrange_type:
4968 case DW_TAG_typedef:
4969 case DW_TAG_union_type:
4976 /* Load all DIEs that are interesting for partial symbols into memory. */
4978 static struct partial_die_info *
4979 load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab,
4980 struct dwarf2_cu *cu)
4982 struct partial_die_info *part_die;
4983 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
4984 struct abbrev_info *abbrev;
4985 unsigned int bytes_read;
4987 int nesting_level = 1;
4993 = htab_create_alloc_ex (cu->header.length / 12,
4997 &cu->comp_unit_obstack,
4998 hashtab_obstack_allocate,
4999 dummy_obstack_deallocate);
5001 part_die = obstack_alloc (&cu->comp_unit_obstack,
5002 sizeof (struct partial_die_info));
5006 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
5008 /* A NULL abbrev means the end of a series of children. */
5011 if (--nesting_level == 0)
5013 /* PART_DIE was probably the last thing allocated on the
5014 comp_unit_obstack, so we could call obstack_free
5015 here. We don't do that because the waste is small,
5016 and will be cleaned up when we're done with this
5017 compilation unit. This way, we're also more robust
5018 against other users of the comp_unit_obstack. */
5021 info_ptr += bytes_read;
5022 last_die = parent_die;
5023 parent_die = parent_die->die_parent;
5027 /* Check whether this DIE is interesting enough to save. */
5028 if (!is_type_tag_for_partial (abbrev->tag)
5029 && abbrev->tag != DW_TAG_enumerator
5030 && abbrev->tag != DW_TAG_subprogram
5031 && abbrev->tag != DW_TAG_variable
5032 && abbrev->tag != DW_TAG_namespace)
5034 /* Otherwise we skip to the next sibling, if any. */
5035 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
5039 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
5040 abfd, info_ptr, cu);
5042 /* This two-pass algorithm for processing partial symbols has a
5043 high cost in cache pressure. Thus, handle some simple cases
5044 here which cover the majority of C partial symbols. DIEs
5045 which neither have specification tags in them, nor could have
5046 specification tags elsewhere pointing at them, can simply be
5047 processed and discarded.
5049 This segment is also optional; scan_partial_symbols and
5050 add_partial_symbol will handle these DIEs if we chain
5051 them in normally. When compilers which do not emit large
5052 quantities of duplicate debug information are more common,
5053 this code can probably be removed. */
5055 /* Any complete simple types at the top level (pretty much all
5056 of them, for a language without namespaces), can be processed
5058 if (parent_die == NULL
5059 && part_die->has_specification == 0
5060 && part_die->is_declaration == 0
5061 && (part_die->tag == DW_TAG_typedef
5062 || part_die->tag == DW_TAG_base_type
5063 || part_die->tag == DW_TAG_subrange_type))
5065 if (building_psymtab && part_die->name != NULL)
5066 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5067 VAR_DOMAIN, LOC_TYPEDEF,
5068 &cu->objfile->static_psymbols,
5069 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5070 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5074 /* If we're at the second level, and we're an enumerator, and
5075 our parent has no specification (meaning possibly lives in a
5076 namespace elsewhere), then we can add the partial symbol now
5077 instead of queueing it. */
5078 if (part_die->tag == DW_TAG_enumerator
5079 && parent_die != NULL
5080 && parent_die->die_parent == NULL
5081 && parent_die->tag == DW_TAG_enumeration_type
5082 && parent_die->has_specification == 0)
5084 if (part_die->name == NULL)
5085 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
5086 else if (building_psymtab)
5087 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5088 VAR_DOMAIN, LOC_CONST,
5089 (cu->language == language_cplus
5090 || cu->language == language_java)
5091 ? &cu->objfile->global_psymbols
5092 : &cu->objfile->static_psymbols,
5093 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5095 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5099 /* We'll save this DIE so link it in. */
5100 part_die->die_parent = parent_die;
5101 part_die->die_sibling = NULL;
5102 part_die->die_child = NULL;
5104 if (last_die && last_die == parent_die)
5105 last_die->die_child = part_die;
5107 last_die->die_sibling = part_die;
5109 last_die = part_die;
5111 if (first_die == NULL)
5112 first_die = part_die;
5114 /* Maybe add the DIE to the hash table. Not all DIEs that we
5115 find interesting need to be in the hash table, because we
5116 also have the parent/sibling/child chains; only those that we
5117 might refer to by offset later during partial symbol reading.
5119 For now this means things that might have be the target of a
5120 DW_AT_specification, DW_AT_abstract_origin, or
5121 DW_AT_extension. DW_AT_extension will refer only to
5122 namespaces; DW_AT_abstract_origin refers to functions (and
5123 many things under the function DIE, but we do not recurse
5124 into function DIEs during partial symbol reading) and
5125 possibly variables as well; DW_AT_specification refers to
5126 declarations. Declarations ought to have the DW_AT_declaration
5127 flag. It happens that GCC forgets to put it in sometimes, but
5128 only for functions, not for types.
5130 Adding more things than necessary to the hash table is harmless
5131 except for the performance cost. Adding too few will result in
5132 internal errors in find_partial_die. */
5134 if (abbrev->tag == DW_TAG_subprogram
5135 || abbrev->tag == DW_TAG_variable
5136 || abbrev->tag == DW_TAG_namespace
5137 || part_die->is_declaration)
5141 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
5142 part_die->offset, INSERT);
5146 part_die = obstack_alloc (&cu->comp_unit_obstack,
5147 sizeof (struct partial_die_info));
5149 /* For some DIEs we want to follow their children (if any). For C
5150 we have no reason to follow the children of structures; for other
5151 languages we have to, both so that we can get at method physnames
5152 to infer fully qualified class names, and for DW_AT_specification. */
5153 if (last_die->has_children
5154 && (last_die->tag == DW_TAG_namespace
5155 || last_die->tag == DW_TAG_enumeration_type
5156 || (cu->language != language_c
5157 && (last_die->tag == DW_TAG_class_type
5158 || last_die->tag == DW_TAG_structure_type
5159 || last_die->tag == DW_TAG_union_type))))
5162 parent_die = last_die;
5166 /* Otherwise we skip to the next sibling, if any. */
5167 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
5169 /* Back to the top, do it again. */
5173 /* Read a minimal amount of information into the minimal die structure. */
5176 read_partial_die (struct partial_die_info *part_die,
5177 struct abbrev_info *abbrev,
5178 unsigned int abbrev_len, bfd *abfd,
5179 char *info_ptr, struct dwarf2_cu *cu)
5181 unsigned int bytes_read, i;
5182 struct attribute attr;
5183 int has_low_pc_attr = 0;
5184 int has_high_pc_attr = 0;
5186 memset (part_die, 0, sizeof (struct partial_die_info));
5188 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
5190 info_ptr += abbrev_len;
5195 part_die->tag = abbrev->tag;
5196 part_die->has_children = abbrev->has_children;
5198 for (i = 0; i < abbrev->num_attrs; ++i)
5200 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
5202 /* Store the data if it is of an attribute we want to keep in a
5203 partial symbol table. */
5208 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5209 if (part_die->name == NULL)
5210 part_die->name = DW_STRING (&attr);
5212 case DW_AT_comp_dir:
5213 if (part_die->dirname == NULL)
5214 part_die->dirname = DW_STRING (&attr);
5216 case DW_AT_MIPS_linkage_name:
5217 part_die->name = DW_STRING (&attr);
5220 has_low_pc_attr = 1;
5221 part_die->lowpc = DW_ADDR (&attr);
5224 has_high_pc_attr = 1;
5225 part_die->highpc = DW_ADDR (&attr);
5227 case DW_AT_location:
5228 /* Support the .debug_loc offsets */
5229 if (attr_form_is_block (&attr))
5231 part_die->locdesc = DW_BLOCK (&attr);
5233 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
5235 dwarf2_complex_location_expr_complaint ();
5239 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5240 "partial symbol information");
5243 case DW_AT_language:
5244 part_die->language = DW_UNSND (&attr);
5246 case DW_AT_external:
5247 part_die->is_external = DW_UNSND (&attr);
5249 case DW_AT_declaration:
5250 part_die->is_declaration = DW_UNSND (&attr);
5253 part_die->has_type = 1;
5255 case DW_AT_abstract_origin:
5256 case DW_AT_specification:
5257 case DW_AT_extension:
5258 part_die->has_specification = 1;
5259 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
5262 /* Ignore absolute siblings, they might point outside of
5263 the current compile unit. */
5264 if (attr.form == DW_FORM_ref_addr)
5265 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
5267 part_die->sibling = dwarf2_per_objfile->info_buffer
5268 + dwarf2_get_ref_die_offset (&attr, cu);
5270 case DW_AT_stmt_list:
5271 part_die->has_stmt_list = 1;
5272 part_die->line_offset = DW_UNSND (&attr);
5279 /* When using the GNU linker, .gnu.linkonce. sections are used to
5280 eliminate duplicate copies of functions and vtables and such.
5281 The linker will arbitrarily choose one and discard the others.
5282 The AT_*_pc values for such functions refer to local labels in
5283 these sections. If the section from that file was discarded, the
5284 labels are not in the output, so the relocs get a value of 0.
5285 If this is a discarded function, mark the pc bounds as invalid,
5286 so that GDB will ignore it. */
5287 if (has_low_pc_attr && has_high_pc_attr
5288 && part_die->lowpc < part_die->highpc
5289 && (part_die->lowpc != 0
5290 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
5291 part_die->has_pc_info = 1;
5295 /* Find a cached partial DIE at OFFSET in CU. */
5297 static struct partial_die_info *
5298 find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu)
5300 struct partial_die_info *lookup_die = NULL;
5301 struct partial_die_info part_die;
5303 part_die.offset = offset;
5304 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
5306 if (lookup_die == NULL)
5307 internal_error (__FILE__, __LINE__,
5308 "could not find partial DIE in cache\n");
5313 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5315 static struct partial_die_info *
5316 find_partial_die (unsigned long offset, struct dwarf2_cu *cu,
5317 struct dwarf2_cu **target_cu)
5319 struct dwarf2_per_cu_data *per_cu;
5321 if (offset >= cu->header.offset
5322 && offset < cu->header.offset + cu->header.length)
5325 return find_partial_die_in_comp_unit (offset, cu);
5328 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
5330 /* If this offset isn't pointing into a known compilation unit,
5331 the debug information is probably corrupted. */
5333 error ("Dwarf Error: could not find partial DIE containing "
5334 "offset 0x%lx [in module %s]",
5335 (long) offset, bfd_get_filename (cu->objfile->obfd));
5337 if (per_cu->cu == NULL)
5339 load_comp_unit (per_cu, cu->objfile);
5340 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
5341 dwarf2_per_objfile->read_in_chain = per_cu;
5344 per_cu->cu->last_used = 0;
5345 *target_cu = per_cu->cu;
5346 return find_partial_die_in_comp_unit (offset, per_cu->cu);
5349 /* Adjust PART_DIE before generating a symbol for it. This function
5350 may set the is_external flag or change the DIE's name. */
5353 fixup_partial_die (struct partial_die_info *part_die,
5354 struct dwarf2_cu *cu)
5356 /* If we found a reference attribute and the DIE has no name, try
5357 to find a name in the referred to DIE. */
5359 if (part_die->name == NULL && part_die->has_specification)
5361 struct partial_die_info *spec_die;
5362 struct dwarf2_cu *spec_cu;
5364 spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu);
5366 fixup_partial_die (spec_die, spec_cu);
5370 part_die->name = spec_die->name;
5372 /* Copy DW_AT_external attribute if it is set. */
5373 if (spec_die->is_external)
5374 part_die->is_external = spec_die->is_external;
5378 /* Set default names for some unnamed DIEs. */
5379 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
5380 || part_die->tag == DW_TAG_class_type))
5381 part_die->name = "(anonymous class)";
5383 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
5384 part_die->name = "(anonymous namespace)";
5386 if (part_die->tag == DW_TAG_structure_type
5387 || part_die->tag == DW_TAG_class_type
5388 || part_die->tag == DW_TAG_union_type)
5389 guess_structure_name (part_die, cu);
5392 /* Read the die from the .debug_info section buffer. Set DIEP to
5393 point to a newly allocated die with its information, except for its
5394 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5395 whether the die has children or not. */
5398 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
5399 struct dwarf2_cu *cu, int *has_children)
5401 unsigned int abbrev_number, bytes_read, i, offset;
5402 struct abbrev_info *abbrev;
5403 struct die_info *die;
5405 offset = info_ptr - dwarf2_per_objfile->info_buffer;
5406 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5407 info_ptr += bytes_read;
5410 die = dwarf_alloc_die ();
5412 die->abbrev = abbrev_number;
5419 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
5422 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5424 bfd_get_filename (abfd));
5426 die = dwarf_alloc_die ();
5427 die->offset = offset;
5428 die->tag = abbrev->tag;
5429 die->abbrev = abbrev_number;
5432 die->num_attrs = abbrev->num_attrs;
5433 die->attrs = (struct attribute *)
5434 xmalloc (die->num_attrs * sizeof (struct attribute));
5436 for (i = 0; i < abbrev->num_attrs; ++i)
5438 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
5439 abfd, info_ptr, cu);
5443 *has_children = abbrev->has_children;
5447 /* Read an attribute value described by an attribute form. */
5450 read_attribute_value (struct attribute *attr, unsigned form,
5451 bfd *abfd, char *info_ptr,
5452 struct dwarf2_cu *cu)
5454 struct comp_unit_head *cu_header = &cu->header;
5455 unsigned int bytes_read;
5456 struct dwarf_block *blk;
5462 case DW_FORM_ref_addr:
5463 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
5464 info_ptr += bytes_read;
5466 case DW_FORM_block2:
5467 blk = dwarf_alloc_block (cu);
5468 blk->size = read_2_bytes (abfd, info_ptr);
5470 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5471 info_ptr += blk->size;
5472 DW_BLOCK (attr) = blk;
5474 case DW_FORM_block4:
5475 blk = dwarf_alloc_block (cu);
5476 blk->size = read_4_bytes (abfd, info_ptr);
5478 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5479 info_ptr += blk->size;
5480 DW_BLOCK (attr) = blk;
5483 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5487 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5491 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5494 case DW_FORM_string:
5495 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
5496 info_ptr += bytes_read;
5499 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
5501 info_ptr += bytes_read;
5504 blk = dwarf_alloc_block (cu);
5505 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5506 info_ptr += bytes_read;
5507 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5508 info_ptr += blk->size;
5509 DW_BLOCK (attr) = blk;
5511 case DW_FORM_block1:
5512 blk = dwarf_alloc_block (cu);
5513 blk->size = read_1_byte (abfd, info_ptr);
5515 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5516 info_ptr += blk->size;
5517 DW_BLOCK (attr) = blk;
5520 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5524 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5528 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
5529 info_ptr += bytes_read;
5532 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5533 info_ptr += bytes_read;
5536 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5540 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5544 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5548 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5551 case DW_FORM_ref_udata:
5552 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5553 info_ptr += bytes_read;
5555 case DW_FORM_indirect:
5556 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5557 info_ptr += bytes_read;
5558 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
5561 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5562 dwarf_form_name (form),
5563 bfd_get_filename (abfd));
5568 /* Read an attribute described by an abbreviated attribute. */
5571 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
5572 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
5574 attr->name = abbrev->name;
5575 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
5578 /* read dwarf information from a buffer */
5581 read_1_byte (bfd *abfd, char *buf)
5583 return bfd_get_8 (abfd, (bfd_byte *) buf);
5587 read_1_signed_byte (bfd *abfd, char *buf)
5589 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
5593 read_2_bytes (bfd *abfd, char *buf)
5595 return bfd_get_16 (abfd, (bfd_byte *) buf);
5599 read_2_signed_bytes (bfd *abfd, char *buf)
5601 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5605 read_4_bytes (bfd *abfd, char *buf)
5607 return bfd_get_32 (abfd, (bfd_byte *) buf);
5611 read_4_signed_bytes (bfd *abfd, char *buf)
5613 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5616 static unsigned long
5617 read_8_bytes (bfd *abfd, char *buf)
5619 return bfd_get_64 (abfd, (bfd_byte *) buf);
5623 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
5625 struct comp_unit_head *cu_header = &cu->header;
5626 CORE_ADDR retval = 0;
5628 if (cu_header->signed_addr_p)
5630 switch (cu_header->addr_size)
5633 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5636 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5639 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
5642 internal_error (__FILE__, __LINE__,
5643 "read_address: bad switch, signed [in module %s]",
5644 bfd_get_filename (abfd));
5649 switch (cu_header->addr_size)
5652 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
5655 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5658 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5661 internal_error (__FILE__, __LINE__,
5662 "read_address: bad switch, unsigned [in module %s]",
5663 bfd_get_filename (abfd));
5667 *bytes_read = cu_header->addr_size;
5671 /* Read the initial length from a section. The (draft) DWARF 3
5672 specification allows the initial length to take up either 4 bytes
5673 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5674 bytes describe the length and all offsets will be 8 bytes in length
5677 An older, non-standard 64-bit format is also handled by this
5678 function. The older format in question stores the initial length
5679 as an 8-byte quantity without an escape value. Lengths greater
5680 than 2^32 aren't very common which means that the initial 4 bytes
5681 is almost always zero. Since a length value of zero doesn't make
5682 sense for the 32-bit format, this initial zero can be considered to
5683 be an escape value which indicates the presence of the older 64-bit
5684 format. As written, the code can't detect (old format) lengths
5685 greater than 4GB. If it becomes necessary to handle lengths somewhat
5686 larger than 4GB, we could allow other small values (such as the
5687 non-sensical values of 1, 2, and 3) to also be used as escape values
5688 indicating the presence of the old format.
5690 The value returned via bytes_read should be used to increment
5691 the relevant pointer after calling read_initial_length().
5693 As a side effect, this function sets the fields initial_length_size
5694 and offset_size in cu_header to the values appropriate for the
5695 length field. (The format of the initial length field determines
5696 the width of file offsets to be fetched later with fetch_offset().)
5698 [ Note: read_initial_length() and read_offset() are based on the
5699 document entitled "DWARF Debugging Information Format", revision
5700 3, draft 8, dated November 19, 2001. This document was obtained
5703 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5705 This document is only a draft and is subject to change. (So beware.)
5707 Details regarding the older, non-standard 64-bit format were
5708 determined empirically by examining 64-bit ELF files produced
5709 by the SGI toolchain on an IRIX 6.5 machine.
5711 - Kevin, July 16, 2002
5715 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
5720 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5722 if (retval == 0xffffffff)
5724 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
5726 if (cu_header != NULL)
5728 cu_header->initial_length_size = 12;
5729 cu_header->offset_size = 8;
5732 else if (retval == 0)
5734 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5736 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5738 if (cu_header != NULL)
5740 cu_header->initial_length_size = 8;
5741 cu_header->offset_size = 8;
5747 if (cu_header != NULL)
5749 cu_header->initial_length_size = 4;
5750 cu_header->offset_size = 4;
5757 /* Read an offset from the data stream. The size of the offset is
5758 given by cu_header->offset_size. */
5761 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
5766 switch (cu_header->offset_size)
5769 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5773 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5777 internal_error (__FILE__, __LINE__,
5778 "read_offset: bad switch [in module %s]",
5779 bfd_get_filename (abfd));
5786 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
5788 /* If the size of a host char is 8 bits, we can return a pointer
5789 to the buffer, otherwise we have to copy the data to a buffer
5790 allocated on the temporary obstack. */
5791 gdb_assert (HOST_CHAR_BIT == 8);
5796 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5798 /* If the size of a host char is 8 bits, we can return a pointer
5799 to the string, otherwise we have to copy the string to a buffer
5800 allocated on the temporary obstack. */
5801 gdb_assert (HOST_CHAR_BIT == 8);
5804 *bytes_read_ptr = 1;
5807 *bytes_read_ptr = strlen (buf) + 1;
5812 read_indirect_string (bfd *abfd, char *buf,
5813 const struct comp_unit_head *cu_header,
5814 unsigned int *bytes_read_ptr)
5816 LONGEST str_offset = read_offset (abfd, buf, cu_header,
5817 (int *) bytes_read_ptr);
5819 if (dwarf2_per_objfile->str_buffer == NULL)
5821 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5822 bfd_get_filename (abfd));
5825 if (str_offset >= dwarf2_per_objfile->str_size)
5827 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5828 bfd_get_filename (abfd));
5831 gdb_assert (HOST_CHAR_BIT == 8);
5832 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
5834 return dwarf2_per_objfile->str_buffer + str_offset;
5837 static unsigned long
5838 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5840 unsigned long result;
5841 unsigned int num_read;
5851 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5854 result |= ((unsigned long)(byte & 127) << shift);
5855 if ((byte & 128) == 0)
5861 *bytes_read_ptr = num_read;
5866 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5869 int i, shift, size, num_read;
5879 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5882 result |= ((long)(byte & 127) << shift);
5884 if ((byte & 128) == 0)
5889 if ((shift < size) && (byte & 0x40))
5891 result |= -(1 << shift);
5893 *bytes_read_ptr = num_read;
5897 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5900 skip_leb128 (bfd *abfd, char *buf)
5906 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5908 if ((byte & 128) == 0)
5914 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5920 cu->language = language_c;
5922 case DW_LANG_C_plus_plus:
5923 cu->language = language_cplus;
5925 case DW_LANG_Fortran77:
5926 case DW_LANG_Fortran90:
5927 case DW_LANG_Fortran95:
5928 cu->language = language_fortran;
5930 case DW_LANG_Mips_Assembler:
5931 cu->language = language_asm;
5934 cu->language = language_java;
5938 case DW_LANG_Cobol74:
5939 case DW_LANG_Cobol85:
5940 case DW_LANG_Pascal83:
5941 case DW_LANG_Modula2:
5943 cu->language = language_minimal;
5946 cu->language_defn = language_def (cu->language);
5949 /* Return the named attribute or NULL if not there. */
5951 static struct attribute *
5952 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5955 struct attribute *spec = NULL;
5957 for (i = 0; i < die->num_attrs; ++i)
5959 if (die->attrs[i].name == name)
5961 return &die->attrs[i];
5963 if (die->attrs[i].name == DW_AT_specification
5964 || die->attrs[i].name == DW_AT_abstract_origin)
5965 spec = &die->attrs[i];
5969 struct die_info *ref_die =
5970 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5973 return dwarf2_attr (ref_die, name, cu);
5979 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5980 and holds a non-zero value. This function should only be used for
5981 DW_FORM_flag attributes. */
5984 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
5986 struct attribute *attr = dwarf2_attr (die, name, cu);
5988 return (attr && DW_UNSND (attr));
5992 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5994 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5995 which value is non-zero. However, we have to be careful with
5996 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5997 (via dwarf2_flag_true_p) follows this attribute. So we may
5998 end up accidently finding a declaration attribute that belongs
5999 to a different DIE referenced by the specification attribute,
6000 even though the given DIE does not have a declaration attribute. */
6001 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
6002 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
6005 /* Return the die giving the specification for DIE, if there is
6008 static struct die_info *
6009 die_specification (struct die_info *die, struct dwarf2_cu *cu)
6011 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
6013 if (spec_attr == NULL)
6016 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
6019 /* Free the line_header structure *LH, and any arrays and strings it
6022 free_line_header (struct line_header *lh)
6024 if (lh->standard_opcode_lengths)
6025 xfree (lh->standard_opcode_lengths);
6027 /* Remember that all the lh->file_names[i].name pointers are
6028 pointers into debug_line_buffer, and don't need to be freed. */
6030 xfree (lh->file_names);
6032 /* Similarly for the include directory names. */
6033 if (lh->include_dirs)
6034 xfree (lh->include_dirs);
6040 /* Add an entry to LH's include directory table. */
6042 add_include_dir (struct line_header *lh, char *include_dir)
6044 /* Grow the array if necessary. */
6045 if (lh->include_dirs_size == 0)
6047 lh->include_dirs_size = 1; /* for testing */
6048 lh->include_dirs = xmalloc (lh->include_dirs_size
6049 * sizeof (*lh->include_dirs));
6051 else if (lh->num_include_dirs >= lh->include_dirs_size)
6053 lh->include_dirs_size *= 2;
6054 lh->include_dirs = xrealloc (lh->include_dirs,
6055 (lh->include_dirs_size
6056 * sizeof (*lh->include_dirs)));
6059 lh->include_dirs[lh->num_include_dirs++] = include_dir;
6063 /* Add an entry to LH's file name table. */
6065 add_file_name (struct line_header *lh,
6067 unsigned int dir_index,
6068 unsigned int mod_time,
6069 unsigned int length)
6071 struct file_entry *fe;
6073 /* Grow the array if necessary. */
6074 if (lh->file_names_size == 0)
6076 lh->file_names_size = 1; /* for testing */
6077 lh->file_names = xmalloc (lh->file_names_size
6078 * sizeof (*lh->file_names));
6080 else if (lh->num_file_names >= lh->file_names_size)
6082 lh->file_names_size *= 2;
6083 lh->file_names = xrealloc (lh->file_names,
6084 (lh->file_names_size
6085 * sizeof (*lh->file_names)));
6088 fe = &lh->file_names[lh->num_file_names++];
6090 fe->dir_index = dir_index;
6091 fe->mod_time = mod_time;
6092 fe->length = length;
6097 /* Read the statement program header starting at OFFSET in
6098 .debug_line, according to the endianness of ABFD. Return a pointer
6099 to a struct line_header, allocated using xmalloc.
6101 NOTE: the strings in the include directory and file name tables of
6102 the returned object point into debug_line_buffer, and must not be
6104 static struct line_header *
6105 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
6106 struct dwarf2_cu *cu)
6108 struct cleanup *back_to;
6109 struct line_header *lh;
6113 char *cur_dir, *cur_file;
6115 if (dwarf2_per_objfile->line_buffer == NULL)
6117 complaint (&symfile_complaints, "missing .debug_line section");
6121 /* Make sure that at least there's room for the total_length field. That
6122 could be 12 bytes long, but we're just going to fudge that. */
6123 if (offset + 4 >= dwarf2_per_objfile->line_size)
6125 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6129 lh = xmalloc (sizeof (*lh));
6130 memset (lh, 0, sizeof (*lh));
6131 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
6134 line_ptr = dwarf2_per_objfile->line_buffer + offset;
6136 /* read in the header */
6137 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
6138 line_ptr += bytes_read;
6139 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
6140 + dwarf2_per_objfile->line_size))
6142 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6145 lh->statement_program_end = line_ptr + lh->total_length;
6146 lh->version = read_2_bytes (abfd, line_ptr);
6148 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
6149 line_ptr += bytes_read;
6150 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
6152 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
6154 lh->line_base = read_1_signed_byte (abfd, line_ptr);
6156 lh->line_range = read_1_byte (abfd, line_ptr);
6158 lh->opcode_base = read_1_byte (abfd, line_ptr);
6160 lh->standard_opcode_lengths
6161 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
6163 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
6164 for (i = 1; i < lh->opcode_base; ++i)
6166 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
6170 /* Read directory table */
6171 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
6173 line_ptr += bytes_read;
6174 add_include_dir (lh, cur_dir);
6176 line_ptr += bytes_read;
6178 /* Read file name table */
6179 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
6181 unsigned int dir_index, mod_time, length;
6183 line_ptr += bytes_read;
6184 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6185 line_ptr += bytes_read;
6186 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6187 line_ptr += bytes_read;
6188 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6189 line_ptr += bytes_read;
6191 add_file_name (lh, cur_file, dir_index, mod_time, length);
6193 line_ptr += bytes_read;
6194 lh->statement_program_start = line_ptr;
6196 if (line_ptr > (dwarf2_per_objfile->line_buffer
6197 + dwarf2_per_objfile->line_size))
6198 complaint (&symfile_complaints,
6199 "line number info header doesn't fit in `.debug_line' section");
6201 discard_cleanups (back_to);
6205 /* This function exists to work around a bug in certain compilers
6206 (particularly GCC 2.95), in which the first line number marker of a
6207 function does not show up until after the prologue, right before
6208 the second line number marker. This function shifts ADDRESS down
6209 to the beginning of the function if necessary, and is called on
6210 addresses passed to record_line. */
6213 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
6215 struct function_range *fn;
6217 /* Find the function_range containing address. */
6222 cu->cached_fn = cu->first_fn;
6226 if (fn->lowpc <= address && fn->highpc > address)
6232 while (fn && fn != cu->cached_fn)
6233 if (fn->lowpc <= address && fn->highpc > address)
6243 if (address != fn->lowpc)
6244 complaint (&symfile_complaints,
6245 "misplaced first line number at 0x%lx for '%s'",
6246 (unsigned long) address, fn->name);
6251 /* Decode the Line Number Program (LNP) for the given line_header
6252 structure and CU. The actual information extracted and the type
6253 of structures created from the LNP depends on the value of PST.
6255 1. If PST is NULL, then this procedure uses the data from the program
6256 to create all necessary symbol tables, and their linetables.
6257 The compilation directory of the file is passed in COMP_DIR,
6258 and must not be NULL.
6260 2. If PST is not NULL, this procedure reads the program to determine
6261 the list of files included by the unit represented by PST, and
6262 builds all the associated partial symbol tables. In this case,
6263 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6264 is not used to compute the full name of the symtab, and therefore
6265 omitting it when building the partial symtab does not introduce
6266 the potential for inconsistency - a partial symtab and its associated
6267 symbtab having a different fullname -). */
6270 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
6271 struct dwarf2_cu *cu, struct partial_symtab *pst)
6275 unsigned int bytes_read;
6276 unsigned char op_code, extended_op, adj_opcode;
6278 struct objfile *objfile = cu->objfile;
6279 const int decode_for_pst_p = (pst != NULL);
6281 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6283 line_ptr = lh->statement_program_start;
6284 line_end = lh->statement_program_end;
6286 /* Read the statement sequences until there's nothing left. */
6287 while (line_ptr < line_end)
6289 /* state machine registers */
6290 CORE_ADDR address = 0;
6291 unsigned int file = 1;
6292 unsigned int line = 1;
6293 unsigned int column = 0;
6294 int is_stmt = lh->default_is_stmt;
6295 int basic_block = 0;
6296 int end_sequence = 0;
6298 if (!decode_for_pst_p && lh->num_file_names >= file)
6300 /* Start a subfile for the current file of the state machine. */
6301 /* lh->include_dirs and lh->file_names are 0-based, but the
6302 directory and file name numbers in the statement program
6304 struct file_entry *fe = &lh->file_names[file - 1];
6307 dir = lh->include_dirs[fe->dir_index - 1];
6310 dwarf2_start_subfile (fe->name, dir);
6313 /* Decode the table. */
6314 while (!end_sequence)
6316 op_code = read_1_byte (abfd, line_ptr);
6319 if (op_code >= lh->opcode_base)
6320 { /* Special operand. */
6321 adj_opcode = op_code - lh->opcode_base;
6322 address += (adj_opcode / lh->line_range)
6323 * lh->minimum_instruction_length;
6324 line += lh->line_base + (adj_opcode % lh->line_range);
6325 lh->file_names[file - 1].included_p = 1;
6326 if (!decode_for_pst_p)
6328 /* append row to matrix using current values */
6329 record_line (current_subfile, line,
6330 check_cu_functions (address, cu));
6334 else switch (op_code)
6336 case DW_LNS_extended_op:
6337 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6338 line_ptr += bytes_read;
6339 extended_op = read_1_byte (abfd, line_ptr);
6341 switch (extended_op)
6343 case DW_LNE_end_sequence:
6345 lh->file_names[file - 1].included_p = 1;
6346 if (!decode_for_pst_p)
6347 record_line (current_subfile, 0, address);
6349 case DW_LNE_set_address:
6350 address = read_address (abfd, line_ptr, cu, &bytes_read);
6351 line_ptr += bytes_read;
6352 address += baseaddr;
6354 case DW_LNE_define_file:
6357 unsigned int dir_index, mod_time, length;
6359 cur_file = read_string (abfd, line_ptr, &bytes_read);
6360 line_ptr += bytes_read;
6362 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6363 line_ptr += bytes_read;
6365 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6366 line_ptr += bytes_read;
6368 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6369 line_ptr += bytes_read;
6370 add_file_name (lh, cur_file, dir_index, mod_time, length);
6374 complaint (&symfile_complaints,
6375 "mangled .debug_line section");
6380 lh->file_names[file - 1].included_p = 1;
6381 if (!decode_for_pst_p)
6382 record_line (current_subfile, line,
6383 check_cu_functions (address, cu));
6386 case DW_LNS_advance_pc:
6387 address += lh->minimum_instruction_length
6388 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6389 line_ptr += bytes_read;
6391 case DW_LNS_advance_line:
6392 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
6393 line_ptr += bytes_read;
6395 case DW_LNS_set_file:
6397 /* lh->include_dirs and lh->file_names are 0-based,
6398 but the directory and file name numbers in the
6399 statement program are 1-based. */
6400 struct file_entry *fe;
6402 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6403 line_ptr += bytes_read;
6404 fe = &lh->file_names[file - 1];
6406 dir = lh->include_dirs[fe->dir_index - 1];
6409 if (!decode_for_pst_p)
6410 dwarf2_start_subfile (fe->name, dir);
6413 case DW_LNS_set_column:
6414 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6415 line_ptr += bytes_read;
6417 case DW_LNS_negate_stmt:
6418 is_stmt = (!is_stmt);
6420 case DW_LNS_set_basic_block:
6423 /* Add to the address register of the state machine the
6424 address increment value corresponding to special opcode
6425 255. Ie, this value is scaled by the minimum instruction
6426 length since special opcode 255 would have scaled the
6428 case DW_LNS_const_add_pc:
6429 address += (lh->minimum_instruction_length
6430 * ((255 - lh->opcode_base) / lh->line_range));
6432 case DW_LNS_fixed_advance_pc:
6433 address += read_2_bytes (abfd, line_ptr);
6437 { /* Unknown standard opcode, ignore it. */
6439 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
6441 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6442 line_ptr += bytes_read;
6449 if (decode_for_pst_p)
6453 /* Now that we're done scanning the Line Header Program, we can
6454 create the psymtab of each included file. */
6455 for (file_index = 0; file_index < lh->num_file_names; file_index++)
6456 if (lh->file_names[file_index].included_p == 1)
6458 char *include_name = lh->file_names [file_index].name;
6460 if (strcmp (include_name, pst->filename) != 0)
6461 dwarf2_create_include_psymtab (include_name, pst, objfile);
6466 /* Start a subfile for DWARF. FILENAME is the name of the file and
6467 DIRNAME the name of the source directory which contains FILENAME
6468 or NULL if not known.
6469 This routine tries to keep line numbers from identical absolute and
6470 relative file names in a common subfile.
6472 Using the `list' example from the GDB testsuite, which resides in
6473 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6474 of /srcdir/list0.c yields the following debugging information for list0.c:
6476 DW_AT_name: /srcdir/list0.c
6477 DW_AT_comp_dir: /compdir
6478 files.files[0].name: list0.h
6479 files.files[0].dir: /srcdir
6480 files.files[1].name: list0.c
6481 files.files[1].dir: /srcdir
6483 The line number information for list0.c has to end up in a single
6484 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6487 dwarf2_start_subfile (char *filename, char *dirname)
6489 /* If the filename isn't absolute, try to match an existing subfile
6490 with the full pathname. */
6492 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
6494 struct subfile *subfile;
6495 char *fullname = concat (dirname, "/", filename, NULL);
6497 for (subfile = subfiles; subfile; subfile = subfile->next)
6499 if (FILENAME_CMP (subfile->name, fullname) == 0)
6501 current_subfile = subfile;
6508 start_subfile (filename, dirname);
6512 var_decode_location (struct attribute *attr, struct symbol *sym,
6513 struct dwarf2_cu *cu)
6515 struct objfile *objfile = cu->objfile;
6516 struct comp_unit_head *cu_header = &cu->header;
6518 /* NOTE drow/2003-01-30: There used to be a comment and some special
6519 code here to turn a symbol with DW_AT_external and a
6520 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6521 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6522 with some versions of binutils) where shared libraries could have
6523 relocations against symbols in their debug information - the
6524 minimal symbol would have the right address, but the debug info
6525 would not. It's no longer necessary, because we will explicitly
6526 apply relocations when we read in the debug information now. */
6528 /* A DW_AT_location attribute with no contents indicates that a
6529 variable has been optimized away. */
6530 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
6532 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
6536 /* Handle one degenerate form of location expression specially, to
6537 preserve GDB's previous behavior when section offsets are
6538 specified. If this is just a DW_OP_addr then mark this symbol
6541 if (attr_form_is_block (attr)
6542 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
6543 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
6547 SYMBOL_VALUE_ADDRESS (sym) =
6548 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
6549 fixup_symbol_section (sym, objfile);
6550 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
6551 SYMBOL_SECTION (sym));
6552 SYMBOL_CLASS (sym) = LOC_STATIC;
6556 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6557 expression evaluator, and use LOC_COMPUTED only when necessary
6558 (i.e. when the value of a register or memory location is
6559 referenced, or a thread-local block, etc.). Then again, it might
6560 not be worthwhile. I'm assuming that it isn't unless performance
6561 or memory numbers show me otherwise. */
6563 dwarf2_symbol_mark_computed (attr, sym, cu);
6564 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6567 /* Given a pointer to a DWARF information entry, figure out if we need
6568 to make a symbol table entry for it, and if so, create a new entry
6569 and return a pointer to it.
6570 If TYPE is NULL, determine symbol type from the die, otherwise
6571 used the passed type. */
6573 static struct symbol *
6574 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6576 struct objfile *objfile = cu->objfile;
6577 struct symbol *sym = NULL;
6579 struct attribute *attr = NULL;
6580 struct attribute *attr2 = NULL;
6583 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6585 if (die->tag != DW_TAG_namespace)
6586 name = dwarf2_linkage_name (die, cu);
6588 name = TYPE_NAME (type);
6592 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6593 sizeof (struct symbol));
6594 OBJSTAT (objfile, n_syms++);
6595 memset (sym, 0, sizeof (struct symbol));
6597 /* Cache this symbol's name and the name's demangled form (if any). */
6598 SYMBOL_LANGUAGE (sym) = cu->language;
6599 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6601 /* Default assumptions.
6602 Use the passed type or decode it from the die. */
6603 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6604 SYMBOL_CLASS (sym) = LOC_STATIC;
6606 SYMBOL_TYPE (sym) = type;
6608 SYMBOL_TYPE (sym) = die_type (die, cu);
6609 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
6612 SYMBOL_LINE (sym) = DW_UNSND (attr);
6617 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6620 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
6622 SYMBOL_CLASS (sym) = LOC_LABEL;
6624 case DW_TAG_subprogram:
6625 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6627 SYMBOL_CLASS (sym) = LOC_BLOCK;
6628 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6629 if (attr2 && (DW_UNSND (attr2) != 0))
6631 add_symbol_to_list (sym, &global_symbols);
6635 add_symbol_to_list (sym, cu->list_in_scope);
6638 case DW_TAG_variable:
6639 /* Compilation with minimal debug info may result in variables
6640 with missing type entries. Change the misleading `void' type
6641 to something sensible. */
6642 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
6643 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
6644 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
6645 "<variable, no debug info>",
6647 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6650 dwarf2_const_value (attr, sym, cu);
6651 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6652 if (attr2 && (DW_UNSND (attr2) != 0))
6653 add_symbol_to_list (sym, &global_symbols);
6655 add_symbol_to_list (sym, cu->list_in_scope);
6658 attr = dwarf2_attr (die, DW_AT_location, cu);
6661 var_decode_location (attr, sym, cu);
6662 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6663 if (attr2 && (DW_UNSND (attr2) != 0))
6664 add_symbol_to_list (sym, &global_symbols);
6666 add_symbol_to_list (sym, cu->list_in_scope);
6670 /* We do not know the address of this symbol.
6671 If it is an external symbol and we have type information
6672 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6673 The address of the variable will then be determined from
6674 the minimal symbol table whenever the variable is
6676 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6677 if (attr2 && (DW_UNSND (attr2) != 0)
6678 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
6680 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6681 add_symbol_to_list (sym, &global_symbols);
6685 case DW_TAG_formal_parameter:
6686 attr = dwarf2_attr (die, DW_AT_location, cu);
6689 var_decode_location (attr, sym, cu);
6690 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6691 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
6692 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
6694 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6697 dwarf2_const_value (attr, sym, cu);
6699 add_symbol_to_list (sym, cu->list_in_scope);
6701 case DW_TAG_unspecified_parameters:
6702 /* From varargs functions; gdb doesn't seem to have any
6703 interest in this information, so just ignore it for now.
6706 case DW_TAG_class_type:
6707 case DW_TAG_structure_type:
6708 case DW_TAG_union_type:
6709 case DW_TAG_enumeration_type:
6710 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6711 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6713 /* Make sure that the symbol includes appropriate enclosing
6714 classes/namespaces in its name. These are calculated in
6715 read_structure_type, and the correct name is saved in
6718 if (cu->language == language_cplus
6719 || cu->language == language_java)
6721 struct type *type = SYMBOL_TYPE (sym);
6723 if (TYPE_TAG_NAME (type) != NULL)
6725 /* FIXME: carlton/2003-11-10: Should this use
6726 SYMBOL_SET_NAMES instead? (The same problem also
6727 arises further down in this function.) */
6728 /* The type's name is already allocated along with
6729 this objfile, so we don't need to duplicate it
6731 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
6736 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6737 really ever be static objects: otherwise, if you try
6738 to, say, break of a class's method and you're in a file
6739 which doesn't mention that class, it won't work unless
6740 the check for all static symbols in lookup_symbol_aux
6741 saves you. See the OtherFileClass tests in
6742 gdb.c++/namespace.exp. */
6744 struct pending **list_to_add;
6746 list_to_add = (cu->list_in_scope == &file_symbols
6747 && (cu->language == language_cplus
6748 || cu->language == language_java)
6749 ? &global_symbols : cu->list_in_scope);
6751 add_symbol_to_list (sym, list_to_add);
6753 /* The semantics of C++ state that "struct foo { ... }" also
6754 defines a typedef for "foo". A Java class declaration also
6755 defines a typedef for the class. Synthesize a typedef symbol
6756 so that "ptype foo" works as expected. */
6757 if (cu->language == language_cplus
6758 || cu->language == language_java)
6760 struct symbol *typedef_sym = (struct symbol *)
6761 obstack_alloc (&objfile->objfile_obstack,
6762 sizeof (struct symbol));
6763 *typedef_sym = *sym;
6764 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
6765 /* The symbol's name is already allocated along with
6766 this objfile, so we don't need to duplicate it for
6768 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
6769 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym);
6770 add_symbol_to_list (typedef_sym, list_to_add);
6774 case DW_TAG_typedef:
6775 if (processing_has_namespace_info
6776 && processing_current_prefix[0] != '\0')
6778 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6779 processing_current_prefix,
6782 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6783 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6784 add_symbol_to_list (sym, cu->list_in_scope);
6786 case DW_TAG_base_type:
6787 case DW_TAG_subrange_type:
6788 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6789 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6790 add_symbol_to_list (sym, cu->list_in_scope);
6792 case DW_TAG_enumerator:
6793 if (processing_has_namespace_info
6794 && processing_current_prefix[0] != '\0')
6796 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6797 processing_current_prefix,
6800 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6803 dwarf2_const_value (attr, sym, cu);
6806 /* NOTE: carlton/2003-11-10: See comment above in the
6807 DW_TAG_class_type, etc. block. */
6809 struct pending **list_to_add;
6811 list_to_add = (cu->list_in_scope == &file_symbols
6812 && (cu->language == language_cplus
6813 || cu->language == language_java)
6814 ? &global_symbols : cu->list_in_scope);
6816 add_symbol_to_list (sym, list_to_add);
6819 case DW_TAG_namespace:
6820 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6821 add_symbol_to_list (sym, &global_symbols);
6824 /* Not a tag we recognize. Hopefully we aren't processing
6825 trash data, but since we must specifically ignore things
6826 we don't recognize, there is nothing else we should do at
6828 complaint (&symfile_complaints, "unsupported tag: '%s'",
6829 dwarf_tag_name (die->tag));
6836 /* Copy constant value from an attribute to a symbol. */
6839 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
6840 struct dwarf2_cu *cu)
6842 struct objfile *objfile = cu->objfile;
6843 struct comp_unit_head *cu_header = &cu->header;
6844 struct dwarf_block *blk;
6849 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
6850 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6851 cu_header->addr_size,
6852 TYPE_LENGTH (SYMBOL_TYPE
6854 SYMBOL_VALUE_BYTES (sym) = (char *)
6855 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
6856 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6857 it's body - store_unsigned_integer. */
6858 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
6860 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6862 case DW_FORM_block1:
6863 case DW_FORM_block2:
6864 case DW_FORM_block4:
6866 blk = DW_BLOCK (attr);
6867 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
6868 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6870 TYPE_LENGTH (SYMBOL_TYPE
6872 SYMBOL_VALUE_BYTES (sym) = (char *)
6873 obstack_alloc (&objfile->objfile_obstack, blk->size);
6874 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
6875 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6878 /* The DW_AT_const_value attributes are supposed to carry the
6879 symbol's value "represented as it would be on the target
6880 architecture." By the time we get here, it's already been
6881 converted to host endianness, so we just need to sign- or
6882 zero-extend it as appropriate. */
6884 dwarf2_const_value_data (attr, sym, 8);
6887 dwarf2_const_value_data (attr, sym, 16);
6890 dwarf2_const_value_data (attr, sym, 32);
6893 dwarf2_const_value_data (attr, sym, 64);
6897 SYMBOL_VALUE (sym) = DW_SND (attr);
6898 SYMBOL_CLASS (sym) = LOC_CONST;
6902 SYMBOL_VALUE (sym) = DW_UNSND (attr);
6903 SYMBOL_CLASS (sym) = LOC_CONST;
6907 complaint (&symfile_complaints,
6908 "unsupported const value attribute form: '%s'",
6909 dwarf_form_name (attr->form));
6910 SYMBOL_VALUE (sym) = 0;
6911 SYMBOL_CLASS (sym) = LOC_CONST;
6917 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6918 or zero-extend it as appropriate for the symbol's type. */
6920 dwarf2_const_value_data (struct attribute *attr,
6924 LONGEST l = DW_UNSND (attr);
6926 if (bits < sizeof (l) * 8)
6928 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
6929 l &= ((LONGEST) 1 << bits) - 1;
6931 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
6934 SYMBOL_VALUE (sym) = l;
6935 SYMBOL_CLASS (sym) = LOC_CONST;
6939 /* Return the type of the die in question using its DW_AT_type attribute. */
6941 static struct type *
6942 die_type (struct die_info *die, struct dwarf2_cu *cu)
6945 struct attribute *type_attr;
6946 struct die_info *type_die;
6949 type_attr = dwarf2_attr (die, DW_AT_type, cu);
6952 /* A missing DW_AT_type represents a void type. */
6953 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
6957 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6958 type_die = follow_die_ref (ref);
6961 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6962 ref, cu->objfile->name);
6966 type = tag_type_to_type (type_die, cu);
6969 dump_die (type_die);
6970 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6976 /* Return the containing type of the die in question using its
6977 DW_AT_containing_type attribute. */
6979 static struct type *
6980 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6982 struct type *type = NULL;
6983 struct attribute *type_attr;
6984 struct die_info *type_die = NULL;
6987 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6990 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6991 type_die = follow_die_ref (ref);
6994 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6998 type = tag_type_to_type (type_die, cu);
7003 dump_die (type_die);
7004 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
7011 static struct type *
7012 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
7014 struct die_info *die;
7017 die = follow_die_ref (offset);
7020 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
7023 type = tag_type_to_type (die, cu);
7028 static struct type *
7029 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
7037 read_type_die (die, cu);
7041 error ("Dwarf Error: Cannot find type of die [in module %s]",
7049 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
7051 char *prefix = determine_prefix (die, cu);
7052 const char *old_prefix = processing_current_prefix;
7053 struct cleanup *back_to = make_cleanup (xfree, prefix);
7054 processing_current_prefix = prefix;
7058 case DW_TAG_class_type:
7059 case DW_TAG_structure_type:
7060 case DW_TAG_union_type:
7061 read_structure_type (die, cu);
7063 case DW_TAG_enumeration_type:
7064 read_enumeration_type (die, cu);
7066 case DW_TAG_subprogram:
7067 case DW_TAG_subroutine_type:
7068 read_subroutine_type (die, cu);
7070 case DW_TAG_array_type:
7071 read_array_type (die, cu);
7073 case DW_TAG_pointer_type:
7074 read_tag_pointer_type (die, cu);
7076 case DW_TAG_ptr_to_member_type:
7077 read_tag_ptr_to_member_type (die, cu);
7079 case DW_TAG_reference_type:
7080 read_tag_reference_type (die, cu);
7082 case DW_TAG_const_type:
7083 read_tag_const_type (die, cu);
7085 case DW_TAG_volatile_type:
7086 read_tag_volatile_type (die, cu);
7088 case DW_TAG_string_type:
7089 read_tag_string_type (die, cu);
7091 case DW_TAG_typedef:
7092 read_typedef (die, cu);
7094 case DW_TAG_subrange_type:
7095 read_subrange_type (die, cu);
7097 case DW_TAG_base_type:
7098 read_base_type (die, cu);
7101 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
7102 dwarf_tag_name (die->tag));
7106 processing_current_prefix = old_prefix;
7107 do_cleanups (back_to);
7110 /* Return the name of the namespace/class that DIE is defined within,
7111 or "" if we can't tell. The caller should xfree the result. */
7113 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7114 therein) for an example of how to use this function to deal with
7115 DW_AT_specification. */
7118 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
7120 struct die_info *parent;
7122 if (cu->language != language_cplus
7123 && cu->language != language_java)
7126 parent = die->parent;
7130 return xstrdup ("");
7134 switch (parent->tag) {
7135 case DW_TAG_namespace:
7137 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7138 before doing this check? */
7139 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
7141 return xstrdup (TYPE_TAG_NAME (parent->type));
7146 char *parent_prefix = determine_prefix (parent, cu);
7147 char *retval = typename_concat (NULL, parent_prefix,
7148 namespace_name (parent, &dummy,
7151 xfree (parent_prefix);
7156 case DW_TAG_class_type:
7157 case DW_TAG_structure_type:
7159 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
7161 return xstrdup (TYPE_TAG_NAME (parent->type));
7165 const char *old_prefix = processing_current_prefix;
7166 char *new_prefix = determine_prefix (parent, cu);
7169 processing_current_prefix = new_prefix;
7170 retval = determine_class_name (parent, cu);
7171 processing_current_prefix = old_prefix;
7178 return determine_prefix (parent, cu);
7183 /* Return a newly-allocated string formed by concatenating PREFIX and
7184 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7185 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7186 perform an obconcat, otherwise allocate storage for the result. The CU argument
7187 is used to determine the language and hence, the appropriate separator. */
7189 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7192 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
7193 struct dwarf2_cu *cu)
7197 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
7199 else if (cu->language == language_java)
7206 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
7211 strcpy (retval, prefix);
7212 strcat (retval, sep);
7215 strcat (retval, suffix);
7221 /* We have an obstack. */
7222 return obconcat (obs, prefix, sep, suffix);
7226 static struct type *
7227 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
7229 struct objfile *objfile = cu->objfile;
7231 /* FIXME - this should not produce a new (struct type *)
7232 every time. It should cache base types. */
7236 case DW_ATE_address:
7237 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
7239 case DW_ATE_boolean:
7240 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
7242 case DW_ATE_complex_float:
7245 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
7249 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
7255 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
7259 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
7266 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7269 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
7273 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7277 case DW_ATE_signed_char:
7278 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7280 case DW_ATE_unsigned:
7284 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7287 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
7291 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
7295 case DW_ATE_unsigned_char:
7296 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7299 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7306 copy_die (struct die_info *old_die)
7308 struct die_info *new_die;
7311 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
7312 memset (new_die, 0, sizeof (struct die_info));
7314 new_die->tag = old_die->tag;
7315 new_die->has_children = old_die->has_children;
7316 new_die->abbrev = old_die->abbrev;
7317 new_die->offset = old_die->offset;
7318 new_die->type = NULL;
7320 num_attrs = old_die->num_attrs;
7321 new_die->num_attrs = num_attrs;
7322 new_die->attrs = (struct attribute *)
7323 xmalloc (num_attrs * sizeof (struct attribute));
7325 for (i = 0; i < old_die->num_attrs; ++i)
7327 new_die->attrs[i].name = old_die->attrs[i].name;
7328 new_die->attrs[i].form = old_die->attrs[i].form;
7329 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
7332 new_die->next = NULL;
7337 /* Return sibling of die, NULL if no sibling. */
7339 static struct die_info *
7340 sibling_die (struct die_info *die)
7342 return die->sibling;
7345 /* Get linkage name of a die, return NULL if not found. */
7348 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7350 struct attribute *attr;
7352 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7353 if (attr && DW_STRING (attr))
7354 return DW_STRING (attr);
7355 attr = dwarf2_attr (die, DW_AT_name, cu);
7356 if (attr && DW_STRING (attr))
7357 return DW_STRING (attr);
7361 /* Get name of a die, return NULL if not found. */
7364 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
7366 struct attribute *attr;
7368 attr = dwarf2_attr (die, DW_AT_name, cu);
7369 if (attr && DW_STRING (attr))
7370 return DW_STRING (attr);
7374 /* Return the die that this die in an extension of, or NULL if there
7377 static struct die_info *
7378 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
7380 struct attribute *attr;
7381 struct die_info *extension_die;
7384 attr = dwarf2_attr (die, DW_AT_extension, cu);
7388 ref = dwarf2_get_ref_die_offset (attr, cu);
7389 extension_die = follow_die_ref (ref);
7392 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
7395 return extension_die;
7398 /* Convert a DIE tag into its string name. */
7401 dwarf_tag_name (unsigned tag)
7405 case DW_TAG_padding:
7406 return "DW_TAG_padding";
7407 case DW_TAG_array_type:
7408 return "DW_TAG_array_type";
7409 case DW_TAG_class_type:
7410 return "DW_TAG_class_type";
7411 case DW_TAG_entry_point:
7412 return "DW_TAG_entry_point";
7413 case DW_TAG_enumeration_type:
7414 return "DW_TAG_enumeration_type";
7415 case DW_TAG_formal_parameter:
7416 return "DW_TAG_formal_parameter";
7417 case DW_TAG_imported_declaration:
7418 return "DW_TAG_imported_declaration";
7420 return "DW_TAG_label";
7421 case DW_TAG_lexical_block:
7422 return "DW_TAG_lexical_block";
7424 return "DW_TAG_member";
7425 case DW_TAG_pointer_type:
7426 return "DW_TAG_pointer_type";
7427 case DW_TAG_reference_type:
7428 return "DW_TAG_reference_type";
7429 case DW_TAG_compile_unit:
7430 return "DW_TAG_compile_unit";
7431 case DW_TAG_string_type:
7432 return "DW_TAG_string_type";
7433 case DW_TAG_structure_type:
7434 return "DW_TAG_structure_type";
7435 case DW_TAG_subroutine_type:
7436 return "DW_TAG_subroutine_type";
7437 case DW_TAG_typedef:
7438 return "DW_TAG_typedef";
7439 case DW_TAG_union_type:
7440 return "DW_TAG_union_type";
7441 case DW_TAG_unspecified_parameters:
7442 return "DW_TAG_unspecified_parameters";
7443 case DW_TAG_variant:
7444 return "DW_TAG_variant";
7445 case DW_TAG_common_block:
7446 return "DW_TAG_common_block";
7447 case DW_TAG_common_inclusion:
7448 return "DW_TAG_common_inclusion";
7449 case DW_TAG_inheritance:
7450 return "DW_TAG_inheritance";
7451 case DW_TAG_inlined_subroutine:
7452 return "DW_TAG_inlined_subroutine";
7454 return "DW_TAG_module";
7455 case DW_TAG_ptr_to_member_type:
7456 return "DW_TAG_ptr_to_member_type";
7457 case DW_TAG_set_type:
7458 return "DW_TAG_set_type";
7459 case DW_TAG_subrange_type:
7460 return "DW_TAG_subrange_type";
7461 case DW_TAG_with_stmt:
7462 return "DW_TAG_with_stmt";
7463 case DW_TAG_access_declaration:
7464 return "DW_TAG_access_declaration";
7465 case DW_TAG_base_type:
7466 return "DW_TAG_base_type";
7467 case DW_TAG_catch_block:
7468 return "DW_TAG_catch_block";
7469 case DW_TAG_const_type:
7470 return "DW_TAG_const_type";
7471 case DW_TAG_constant:
7472 return "DW_TAG_constant";
7473 case DW_TAG_enumerator:
7474 return "DW_TAG_enumerator";
7475 case DW_TAG_file_type:
7476 return "DW_TAG_file_type";
7478 return "DW_TAG_friend";
7479 case DW_TAG_namelist:
7480 return "DW_TAG_namelist";
7481 case DW_TAG_namelist_item:
7482 return "DW_TAG_namelist_item";
7483 case DW_TAG_packed_type:
7484 return "DW_TAG_packed_type";
7485 case DW_TAG_subprogram:
7486 return "DW_TAG_subprogram";
7487 case DW_TAG_template_type_param:
7488 return "DW_TAG_template_type_param";
7489 case DW_TAG_template_value_param:
7490 return "DW_TAG_template_value_param";
7491 case DW_TAG_thrown_type:
7492 return "DW_TAG_thrown_type";
7493 case DW_TAG_try_block:
7494 return "DW_TAG_try_block";
7495 case DW_TAG_variant_part:
7496 return "DW_TAG_variant_part";
7497 case DW_TAG_variable:
7498 return "DW_TAG_variable";
7499 case DW_TAG_volatile_type:
7500 return "DW_TAG_volatile_type";
7501 case DW_TAG_dwarf_procedure:
7502 return "DW_TAG_dwarf_procedure";
7503 case DW_TAG_restrict_type:
7504 return "DW_TAG_restrict_type";
7505 case DW_TAG_interface_type:
7506 return "DW_TAG_interface_type";
7507 case DW_TAG_namespace:
7508 return "DW_TAG_namespace";
7509 case DW_TAG_imported_module:
7510 return "DW_TAG_imported_module";
7511 case DW_TAG_unspecified_type:
7512 return "DW_TAG_unspecified_type";
7513 case DW_TAG_partial_unit:
7514 return "DW_TAG_partial_unit";
7515 case DW_TAG_imported_unit:
7516 return "DW_TAG_imported_unit";
7517 case DW_TAG_MIPS_loop:
7518 return "DW_TAG_MIPS_loop";
7519 case DW_TAG_format_label:
7520 return "DW_TAG_format_label";
7521 case DW_TAG_function_template:
7522 return "DW_TAG_function_template";
7523 case DW_TAG_class_template:
7524 return "DW_TAG_class_template";
7526 return "DW_TAG_<unknown>";
7530 /* Convert a DWARF attribute code into its string name. */
7533 dwarf_attr_name (unsigned attr)
7538 return "DW_AT_sibling";
7539 case DW_AT_location:
7540 return "DW_AT_location";
7542 return "DW_AT_name";
7543 case DW_AT_ordering:
7544 return "DW_AT_ordering";
7545 case DW_AT_subscr_data:
7546 return "DW_AT_subscr_data";
7547 case DW_AT_byte_size:
7548 return "DW_AT_byte_size";
7549 case DW_AT_bit_offset:
7550 return "DW_AT_bit_offset";
7551 case DW_AT_bit_size:
7552 return "DW_AT_bit_size";
7553 case DW_AT_element_list:
7554 return "DW_AT_element_list";
7555 case DW_AT_stmt_list:
7556 return "DW_AT_stmt_list";
7558 return "DW_AT_low_pc";
7560 return "DW_AT_high_pc";
7561 case DW_AT_language:
7562 return "DW_AT_language";
7564 return "DW_AT_member";
7566 return "DW_AT_discr";
7567 case DW_AT_discr_value:
7568 return "DW_AT_discr_value";
7569 case DW_AT_visibility:
7570 return "DW_AT_visibility";
7572 return "DW_AT_import";
7573 case DW_AT_string_length:
7574 return "DW_AT_string_length";
7575 case DW_AT_common_reference:
7576 return "DW_AT_common_reference";
7577 case DW_AT_comp_dir:
7578 return "DW_AT_comp_dir";
7579 case DW_AT_const_value:
7580 return "DW_AT_const_value";
7581 case DW_AT_containing_type:
7582 return "DW_AT_containing_type";
7583 case DW_AT_default_value:
7584 return "DW_AT_default_value";
7586 return "DW_AT_inline";
7587 case DW_AT_is_optional:
7588 return "DW_AT_is_optional";
7589 case DW_AT_lower_bound:
7590 return "DW_AT_lower_bound";
7591 case DW_AT_producer:
7592 return "DW_AT_producer";
7593 case DW_AT_prototyped:
7594 return "DW_AT_prototyped";
7595 case DW_AT_return_addr:
7596 return "DW_AT_return_addr";
7597 case DW_AT_start_scope:
7598 return "DW_AT_start_scope";
7599 case DW_AT_stride_size:
7600 return "DW_AT_stride_size";
7601 case DW_AT_upper_bound:
7602 return "DW_AT_upper_bound";
7603 case DW_AT_abstract_origin:
7604 return "DW_AT_abstract_origin";
7605 case DW_AT_accessibility:
7606 return "DW_AT_accessibility";
7607 case DW_AT_address_class:
7608 return "DW_AT_address_class";
7609 case DW_AT_artificial:
7610 return "DW_AT_artificial";
7611 case DW_AT_base_types:
7612 return "DW_AT_base_types";
7613 case DW_AT_calling_convention:
7614 return "DW_AT_calling_convention";
7616 return "DW_AT_count";
7617 case DW_AT_data_member_location:
7618 return "DW_AT_data_member_location";
7619 case DW_AT_decl_column:
7620 return "DW_AT_decl_column";
7621 case DW_AT_decl_file:
7622 return "DW_AT_decl_file";
7623 case DW_AT_decl_line:
7624 return "DW_AT_decl_line";
7625 case DW_AT_declaration:
7626 return "DW_AT_declaration";
7627 case DW_AT_discr_list:
7628 return "DW_AT_discr_list";
7629 case DW_AT_encoding:
7630 return "DW_AT_encoding";
7631 case DW_AT_external:
7632 return "DW_AT_external";
7633 case DW_AT_frame_base:
7634 return "DW_AT_frame_base";
7636 return "DW_AT_friend";
7637 case DW_AT_identifier_case:
7638 return "DW_AT_identifier_case";
7639 case DW_AT_macro_info:
7640 return "DW_AT_macro_info";
7641 case DW_AT_namelist_items:
7642 return "DW_AT_namelist_items";
7643 case DW_AT_priority:
7644 return "DW_AT_priority";
7646 return "DW_AT_segment";
7647 case DW_AT_specification:
7648 return "DW_AT_specification";
7649 case DW_AT_static_link:
7650 return "DW_AT_static_link";
7652 return "DW_AT_type";
7653 case DW_AT_use_location:
7654 return "DW_AT_use_location";
7655 case DW_AT_variable_parameter:
7656 return "DW_AT_variable_parameter";
7657 case DW_AT_virtuality:
7658 return "DW_AT_virtuality";
7659 case DW_AT_vtable_elem_location:
7660 return "DW_AT_vtable_elem_location";
7661 case DW_AT_allocated:
7662 return "DW_AT_allocated";
7663 case DW_AT_associated:
7664 return "DW_AT_associated";
7665 case DW_AT_data_location:
7666 return "DW_AT_data_location";
7668 return "DW_AT_stride";
7669 case DW_AT_entry_pc:
7670 return "DW_AT_entry_pc";
7671 case DW_AT_use_UTF8:
7672 return "DW_AT_use_UTF8";
7673 case DW_AT_extension:
7674 return "DW_AT_extension";
7676 return "DW_AT_ranges";
7677 case DW_AT_trampoline:
7678 return "DW_AT_trampoline";
7679 case DW_AT_call_column:
7680 return "DW_AT_call_column";
7681 case DW_AT_call_file:
7682 return "DW_AT_call_file";
7683 case DW_AT_call_line:
7684 return "DW_AT_call_line";
7686 case DW_AT_MIPS_fde:
7687 return "DW_AT_MIPS_fde";
7688 case DW_AT_MIPS_loop_begin:
7689 return "DW_AT_MIPS_loop_begin";
7690 case DW_AT_MIPS_tail_loop_begin:
7691 return "DW_AT_MIPS_tail_loop_begin";
7692 case DW_AT_MIPS_epilog_begin:
7693 return "DW_AT_MIPS_epilog_begin";
7694 case DW_AT_MIPS_loop_unroll_factor:
7695 return "DW_AT_MIPS_loop_unroll_factor";
7696 case DW_AT_MIPS_software_pipeline_depth:
7697 return "DW_AT_MIPS_software_pipeline_depth";
7699 case DW_AT_MIPS_linkage_name:
7700 return "DW_AT_MIPS_linkage_name";
7702 case DW_AT_sf_names:
7703 return "DW_AT_sf_names";
7704 case DW_AT_src_info:
7705 return "DW_AT_src_info";
7706 case DW_AT_mac_info:
7707 return "DW_AT_mac_info";
7708 case DW_AT_src_coords:
7709 return "DW_AT_src_coords";
7710 case DW_AT_body_begin:
7711 return "DW_AT_body_begin";
7712 case DW_AT_body_end:
7713 return "DW_AT_body_end";
7714 case DW_AT_GNU_vector:
7715 return "DW_AT_GNU_vector";
7717 return "DW_AT_<unknown>";
7721 /* Convert a DWARF value form code into its string name. */
7724 dwarf_form_name (unsigned form)
7729 return "DW_FORM_addr";
7730 case DW_FORM_block2:
7731 return "DW_FORM_block2";
7732 case DW_FORM_block4:
7733 return "DW_FORM_block4";
7735 return "DW_FORM_data2";
7737 return "DW_FORM_data4";
7739 return "DW_FORM_data8";
7740 case DW_FORM_string:
7741 return "DW_FORM_string";
7743 return "DW_FORM_block";
7744 case DW_FORM_block1:
7745 return "DW_FORM_block1";
7747 return "DW_FORM_data1";
7749 return "DW_FORM_flag";
7751 return "DW_FORM_sdata";
7753 return "DW_FORM_strp";
7755 return "DW_FORM_udata";
7756 case DW_FORM_ref_addr:
7757 return "DW_FORM_ref_addr";
7759 return "DW_FORM_ref1";
7761 return "DW_FORM_ref2";
7763 return "DW_FORM_ref4";
7765 return "DW_FORM_ref8";
7766 case DW_FORM_ref_udata:
7767 return "DW_FORM_ref_udata";
7768 case DW_FORM_indirect:
7769 return "DW_FORM_indirect";
7771 return "DW_FORM_<unknown>";
7775 /* Convert a DWARF stack opcode into its string name. */
7778 dwarf_stack_op_name (unsigned op)
7783 return "DW_OP_addr";
7785 return "DW_OP_deref";
7787 return "DW_OP_const1u";
7789 return "DW_OP_const1s";
7791 return "DW_OP_const2u";
7793 return "DW_OP_const2s";
7795 return "DW_OP_const4u";
7797 return "DW_OP_const4s";
7799 return "DW_OP_const8u";
7801 return "DW_OP_const8s";
7803 return "DW_OP_constu";
7805 return "DW_OP_consts";
7809 return "DW_OP_drop";
7811 return "DW_OP_over";
7813 return "DW_OP_pick";
7815 return "DW_OP_swap";
7819 return "DW_OP_xderef";
7827 return "DW_OP_minus";
7839 return "DW_OP_plus";
7840 case DW_OP_plus_uconst:
7841 return "DW_OP_plus_uconst";
7847 return "DW_OP_shra";
7865 return "DW_OP_skip";
7867 return "DW_OP_lit0";
7869 return "DW_OP_lit1";
7871 return "DW_OP_lit2";
7873 return "DW_OP_lit3";
7875 return "DW_OP_lit4";
7877 return "DW_OP_lit5";
7879 return "DW_OP_lit6";
7881 return "DW_OP_lit7";
7883 return "DW_OP_lit8";
7885 return "DW_OP_lit9";
7887 return "DW_OP_lit10";
7889 return "DW_OP_lit11";
7891 return "DW_OP_lit12";
7893 return "DW_OP_lit13";
7895 return "DW_OP_lit14";
7897 return "DW_OP_lit15";
7899 return "DW_OP_lit16";
7901 return "DW_OP_lit17";
7903 return "DW_OP_lit18";
7905 return "DW_OP_lit19";
7907 return "DW_OP_lit20";
7909 return "DW_OP_lit21";
7911 return "DW_OP_lit22";
7913 return "DW_OP_lit23";
7915 return "DW_OP_lit24";
7917 return "DW_OP_lit25";
7919 return "DW_OP_lit26";
7921 return "DW_OP_lit27";
7923 return "DW_OP_lit28";
7925 return "DW_OP_lit29";
7927 return "DW_OP_lit30";
7929 return "DW_OP_lit31";
7931 return "DW_OP_reg0";
7933 return "DW_OP_reg1";
7935 return "DW_OP_reg2";
7937 return "DW_OP_reg3";
7939 return "DW_OP_reg4";
7941 return "DW_OP_reg5";
7943 return "DW_OP_reg6";
7945 return "DW_OP_reg7";
7947 return "DW_OP_reg8";
7949 return "DW_OP_reg9";
7951 return "DW_OP_reg10";
7953 return "DW_OP_reg11";
7955 return "DW_OP_reg12";
7957 return "DW_OP_reg13";
7959 return "DW_OP_reg14";
7961 return "DW_OP_reg15";
7963 return "DW_OP_reg16";
7965 return "DW_OP_reg17";
7967 return "DW_OP_reg18";
7969 return "DW_OP_reg19";
7971 return "DW_OP_reg20";
7973 return "DW_OP_reg21";
7975 return "DW_OP_reg22";
7977 return "DW_OP_reg23";
7979 return "DW_OP_reg24";
7981 return "DW_OP_reg25";
7983 return "DW_OP_reg26";
7985 return "DW_OP_reg27";
7987 return "DW_OP_reg28";
7989 return "DW_OP_reg29";
7991 return "DW_OP_reg30";
7993 return "DW_OP_reg31";
7995 return "DW_OP_breg0";
7997 return "DW_OP_breg1";
7999 return "DW_OP_breg2";
8001 return "DW_OP_breg3";
8003 return "DW_OP_breg4";
8005 return "DW_OP_breg5";
8007 return "DW_OP_breg6";
8009 return "DW_OP_breg7";
8011 return "DW_OP_breg8";
8013 return "DW_OP_breg9";
8015 return "DW_OP_breg10";
8017 return "DW_OP_breg11";
8019 return "DW_OP_breg12";
8021 return "DW_OP_breg13";
8023 return "DW_OP_breg14";
8025 return "DW_OP_breg15";
8027 return "DW_OP_breg16";
8029 return "DW_OP_breg17";
8031 return "DW_OP_breg18";
8033 return "DW_OP_breg19";
8035 return "DW_OP_breg20";
8037 return "DW_OP_breg21";
8039 return "DW_OP_breg22";
8041 return "DW_OP_breg23";
8043 return "DW_OP_breg24";
8045 return "DW_OP_breg25";
8047 return "DW_OP_breg26";
8049 return "DW_OP_breg27";
8051 return "DW_OP_breg28";
8053 return "DW_OP_breg29";
8055 return "DW_OP_breg30";
8057 return "DW_OP_breg31";
8059 return "DW_OP_regx";
8061 return "DW_OP_fbreg";
8063 return "DW_OP_bregx";
8065 return "DW_OP_piece";
8066 case DW_OP_deref_size:
8067 return "DW_OP_deref_size";
8068 case DW_OP_xderef_size:
8069 return "DW_OP_xderef_size";
8072 /* DWARF 3 extensions. */
8073 case DW_OP_push_object_address:
8074 return "DW_OP_push_object_address";
8076 return "DW_OP_call2";
8078 return "DW_OP_call4";
8079 case DW_OP_call_ref:
8080 return "DW_OP_call_ref";
8081 /* GNU extensions. */
8082 case DW_OP_GNU_push_tls_address:
8083 return "DW_OP_GNU_push_tls_address";
8085 return "OP_<unknown>";
8090 dwarf_bool_name (unsigned mybool)
8098 /* Convert a DWARF type code into its string name. */
8101 dwarf_type_encoding_name (unsigned enc)
8105 case DW_ATE_address:
8106 return "DW_ATE_address";
8107 case DW_ATE_boolean:
8108 return "DW_ATE_boolean";
8109 case DW_ATE_complex_float:
8110 return "DW_ATE_complex_float";
8112 return "DW_ATE_float";
8114 return "DW_ATE_signed";
8115 case DW_ATE_signed_char:
8116 return "DW_ATE_signed_char";
8117 case DW_ATE_unsigned:
8118 return "DW_ATE_unsigned";
8119 case DW_ATE_unsigned_char:
8120 return "DW_ATE_unsigned_char";
8121 case DW_ATE_imaginary_float:
8122 return "DW_ATE_imaginary_float";
8124 return "DW_ATE_<unknown>";
8128 /* Convert a DWARF call frame info operation to its string name. */
8132 dwarf_cfi_name (unsigned cfi_opc)
8136 case DW_CFA_advance_loc:
8137 return "DW_CFA_advance_loc";
8139 return "DW_CFA_offset";
8140 case DW_CFA_restore:
8141 return "DW_CFA_restore";
8143 return "DW_CFA_nop";
8144 case DW_CFA_set_loc:
8145 return "DW_CFA_set_loc";
8146 case DW_CFA_advance_loc1:
8147 return "DW_CFA_advance_loc1";
8148 case DW_CFA_advance_loc2:
8149 return "DW_CFA_advance_loc2";
8150 case DW_CFA_advance_loc4:
8151 return "DW_CFA_advance_loc4";
8152 case DW_CFA_offset_extended:
8153 return "DW_CFA_offset_extended";
8154 case DW_CFA_restore_extended:
8155 return "DW_CFA_restore_extended";
8156 case DW_CFA_undefined:
8157 return "DW_CFA_undefined";
8158 case DW_CFA_same_value:
8159 return "DW_CFA_same_value";
8160 case DW_CFA_register:
8161 return "DW_CFA_register";
8162 case DW_CFA_remember_state:
8163 return "DW_CFA_remember_state";
8164 case DW_CFA_restore_state:
8165 return "DW_CFA_restore_state";
8166 case DW_CFA_def_cfa:
8167 return "DW_CFA_def_cfa";
8168 case DW_CFA_def_cfa_register:
8169 return "DW_CFA_def_cfa_register";
8170 case DW_CFA_def_cfa_offset:
8171 return "DW_CFA_def_cfa_offset";
8174 case DW_CFA_def_cfa_expression:
8175 return "DW_CFA_def_cfa_expression";
8176 case DW_CFA_expression:
8177 return "DW_CFA_expression";
8178 case DW_CFA_offset_extended_sf:
8179 return "DW_CFA_offset_extended_sf";
8180 case DW_CFA_def_cfa_sf:
8181 return "DW_CFA_def_cfa_sf";
8182 case DW_CFA_def_cfa_offset_sf:
8183 return "DW_CFA_def_cfa_offset_sf";
8185 /* SGI/MIPS specific */
8186 case DW_CFA_MIPS_advance_loc8:
8187 return "DW_CFA_MIPS_advance_loc8";
8189 /* GNU extensions */
8190 case DW_CFA_GNU_window_save:
8191 return "DW_CFA_GNU_window_save";
8192 case DW_CFA_GNU_args_size:
8193 return "DW_CFA_GNU_args_size";
8194 case DW_CFA_GNU_negative_offset_extended:
8195 return "DW_CFA_GNU_negative_offset_extended";
8198 return "DW_CFA_<unknown>";
8204 dump_die (struct die_info *die)
8208 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
8209 dwarf_tag_name (die->tag), die->abbrev, die->offset);
8210 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
8211 dwarf_bool_name (die->child != NULL));
8213 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
8214 for (i = 0; i < die->num_attrs; ++i)
8216 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
8217 dwarf_attr_name (die->attrs[i].name),
8218 dwarf_form_name (die->attrs[i].form));
8219 switch (die->attrs[i].form)
8221 case DW_FORM_ref_addr:
8223 fprintf_unfiltered (gdb_stderr, "address: ");
8224 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
8226 case DW_FORM_block2:
8227 case DW_FORM_block4:
8229 case DW_FORM_block1:
8230 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
8241 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
8243 case DW_FORM_string:
8245 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
8246 DW_STRING (&die->attrs[i])
8247 ? DW_STRING (&die->attrs[i]) : "");
8250 if (DW_UNSND (&die->attrs[i]))
8251 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
8253 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
8255 case DW_FORM_indirect:
8256 /* the reader will have reduced the indirect form to
8257 the "base form" so this form should not occur */
8258 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
8261 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
8262 die->attrs[i].form);
8264 fprintf_unfiltered (gdb_stderr, "\n");
8269 dump_die_list (struct die_info *die)
8274 if (die->child != NULL)
8275 dump_die_list (die->child);
8276 if (die->sibling != NULL)
8277 dump_die_list (die->sibling);
8282 store_in_ref_table (unsigned int offset, struct die_info *die)
8285 struct die_info *old;
8287 h = (offset % REF_HASH_SIZE);
8288 old = die_ref_table[h];
8289 die->next_ref = old;
8290 die_ref_table[h] = die;
8295 dwarf2_empty_hash_tables (void)
8297 memset (die_ref_table, 0, sizeof (die_ref_table));
8301 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
8303 unsigned int result = 0;
8307 case DW_FORM_ref_addr:
8308 result = DW_ADDR (attr);
8314 case DW_FORM_ref_udata:
8315 result = cu->header.offset + DW_UNSND (attr);
8318 complaint (&symfile_complaints,
8319 "unsupported die ref attribute form: '%s'",
8320 dwarf_form_name (attr->form));
8325 /* Return the constant value held by the given attribute. Return -1
8326 if the value held by the attribute is not constant. */
8329 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
8331 if (attr->form == DW_FORM_sdata)
8332 return DW_SND (attr);
8333 else if (attr->form == DW_FORM_udata
8334 || attr->form == DW_FORM_data1
8335 || attr->form == DW_FORM_data2
8336 || attr->form == DW_FORM_data4
8337 || attr->form == DW_FORM_data8)
8338 return DW_UNSND (attr);
8341 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
8342 dwarf_form_name (attr->form));
8343 return default_value;
8347 static struct die_info *
8348 follow_die_ref (unsigned int offset)
8350 struct die_info *die;
8353 h = (offset % REF_HASH_SIZE);
8354 die = die_ref_table[h];
8357 if (die->offset == offset)
8361 die = die->next_ref;
8366 static struct type *
8367 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
8368 struct dwarf2_cu *cu)
8370 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
8372 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8373 typeid, objfile->name);
8376 /* Look for this particular type in the fundamental type vector. If
8377 one is not found, create and install one appropriate for the
8378 current language and the current target machine. */
8380 if (cu->ftypes[typeid] == NULL)
8382 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
8385 return (cu->ftypes[typeid]);
8388 /* Decode simple location descriptions.
8389 Given a pointer to a dwarf block that defines a location, compute
8390 the location and return the value.
8392 NOTE drow/2003-11-18: This function is called in two situations
8393 now: for the address of static or global variables (partial symbols
8394 only) and for offsets into structures which are expected to be
8395 (more or less) constant. The partial symbol case should go away,
8396 and only the constant case should remain. That will let this
8397 function complain more accurately. A few special modes are allowed
8398 without complaint for global variables (for instance, global
8399 register values and thread-local values).
8401 A location description containing no operations indicates that the
8402 object is optimized out. The return value is 0 for that case.
8403 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8404 callers will only want a very basic result and this can become a
8407 When the result is a register number, the global isreg flag is set,
8408 otherwise it is cleared.
8410 Note that stack[0] is unused except as a default error return.
8411 Note that stack overflow is not yet handled. */
8414 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
8416 struct objfile *objfile = cu->objfile;
8417 struct comp_unit_head *cu_header = &cu->header;
8419 int size = blk->size;
8420 char *data = blk->data;
8421 CORE_ADDR stack[64];
8423 unsigned int bytes_read, unsnd;
8468 stack[++stacki] = op - DW_OP_lit0;
8504 stack[++stacki] = op - DW_OP_reg0;
8506 dwarf2_complex_location_expr_complaint ();
8511 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8513 stack[++stacki] = unsnd;
8515 dwarf2_complex_location_expr_complaint ();
8519 stack[++stacki] = read_address (objfile->obfd, &data[i],
8525 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
8530 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
8535 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
8540 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
8545 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
8550 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
8555 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
8561 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
8566 stack[stacki + 1] = stack[stacki];
8571 stack[stacki - 1] += stack[stacki];
8575 case DW_OP_plus_uconst:
8576 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8581 stack[stacki - 1] -= stack[stacki];
8586 /* If we're not the last op, then we definitely can't encode
8587 this using GDB's address_class enum. This is valid for partial
8588 global symbols, although the variable's address will be bogus
8591 dwarf2_complex_location_expr_complaint ();
8594 case DW_OP_GNU_push_tls_address:
8595 /* The top of the stack has the offset from the beginning
8596 of the thread control block at which the variable is located. */
8597 /* Nothing should follow this operator, so the top of stack would
8599 /* This is valid for partial global symbols, but the variable's
8600 address will be bogus in the psymtab. */
8602 dwarf2_complex_location_expr_complaint ();
8606 complaint (&symfile_complaints, "unsupported stack op: '%s'",
8607 dwarf_stack_op_name (op));
8608 return (stack[stacki]);
8611 return (stack[stacki]);
8614 /* memory allocation interface */
8616 static struct dwarf_block *
8617 dwarf_alloc_block (struct dwarf2_cu *cu)
8619 struct dwarf_block *blk;
8621 blk = (struct dwarf_block *)
8622 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
8626 static struct abbrev_info *
8627 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
8629 struct abbrev_info *abbrev;
8631 abbrev = (struct abbrev_info *)
8632 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
8633 memset (abbrev, 0, sizeof (struct abbrev_info));
8637 static struct die_info *
8638 dwarf_alloc_die (void)
8640 struct die_info *die;
8642 die = (struct die_info *) xmalloc (sizeof (struct die_info));
8643 memset (die, 0, sizeof (struct die_info));
8648 /* Macro support. */
8651 /* Return the full name of file number I in *LH's file name table.
8652 Use COMP_DIR as the name of the current directory of the
8653 compilation. The result is allocated using xmalloc; the caller is
8654 responsible for freeing it. */
8656 file_full_name (int file, struct line_header *lh, const char *comp_dir)
8658 struct file_entry *fe = &lh->file_names[file - 1];
8660 if (IS_ABSOLUTE_PATH (fe->name))
8661 return xstrdup (fe->name);
8669 dir = lh->include_dirs[fe->dir_index - 1];
8675 dir_len = strlen (dir);
8676 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
8677 strcpy (full_name, dir);
8678 full_name[dir_len] = '/';
8679 strcpy (full_name + dir_len + 1, fe->name);
8683 return xstrdup (fe->name);
8688 static struct macro_source_file *
8689 macro_start_file (int file, int line,
8690 struct macro_source_file *current_file,
8691 const char *comp_dir,
8692 struct line_header *lh, struct objfile *objfile)
8694 /* The full name of this source file. */
8695 char *full_name = file_full_name (file, lh, comp_dir);
8697 /* We don't create a macro table for this compilation unit
8698 at all until we actually get a filename. */
8699 if (! pending_macros)
8700 pending_macros = new_macro_table (&objfile->objfile_obstack,
8701 objfile->macro_cache);
8704 /* If we have no current file, then this must be the start_file
8705 directive for the compilation unit's main source file. */
8706 current_file = macro_set_main (pending_macros, full_name);
8708 current_file = macro_include (current_file, line, full_name);
8712 return current_file;
8716 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8717 followed by a null byte. */
8719 copy_string (const char *buf, int len)
8721 char *s = xmalloc (len + 1);
8722 memcpy (s, buf, len);
8730 consume_improper_spaces (const char *p, const char *body)
8734 complaint (&symfile_complaints,
8735 "macro definition contains spaces in formal argument list:\n`%s'",
8747 parse_macro_definition (struct macro_source_file *file, int line,
8752 /* The body string takes one of two forms. For object-like macro
8753 definitions, it should be:
8755 <macro name> " " <definition>
8757 For function-like macro definitions, it should be:
8759 <macro name> "() " <definition>
8761 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8763 Spaces may appear only where explicitly indicated, and in the
8766 The Dwarf 2 spec says that an object-like macro's name is always
8767 followed by a space, but versions of GCC around March 2002 omit
8768 the space when the macro's definition is the empty string.
8770 The Dwarf 2 spec says that there should be no spaces between the
8771 formal arguments in a function-like macro's formal argument list,
8772 but versions of GCC around March 2002 include spaces after the
8776 /* Find the extent of the macro name. The macro name is terminated
8777 by either a space or null character (for an object-like macro) or
8778 an opening paren (for a function-like macro). */
8779 for (p = body; *p; p++)
8780 if (*p == ' ' || *p == '(')
8783 if (*p == ' ' || *p == '\0')
8785 /* It's an object-like macro. */
8786 int name_len = p - body;
8787 char *name = copy_string (body, name_len);
8788 const char *replacement;
8791 replacement = body + name_len + 1;
8794 dwarf2_macro_malformed_definition_complaint (body);
8795 replacement = body + name_len;
8798 macro_define_object (file, line, name, replacement);
8804 /* It's a function-like macro. */
8805 char *name = copy_string (body, p - body);
8808 char **argv = xmalloc (argv_size * sizeof (*argv));
8812 p = consume_improper_spaces (p, body);
8814 /* Parse the formal argument list. */
8815 while (*p && *p != ')')
8817 /* Find the extent of the current argument name. */
8818 const char *arg_start = p;
8820 while (*p && *p != ',' && *p != ')' && *p != ' ')
8823 if (! *p || p == arg_start)
8824 dwarf2_macro_malformed_definition_complaint (body);
8827 /* Make sure argv has room for the new argument. */
8828 if (argc >= argv_size)
8831 argv = xrealloc (argv, argv_size * sizeof (*argv));
8834 argv[argc++] = copy_string (arg_start, p - arg_start);
8837 p = consume_improper_spaces (p, body);
8839 /* Consume the comma, if present. */
8844 p = consume_improper_spaces (p, body);
8853 /* Perfectly formed definition, no complaints. */
8854 macro_define_function (file, line, name,
8855 argc, (const char **) argv,
8857 else if (*p == '\0')
8859 /* Complain, but do define it. */
8860 dwarf2_macro_malformed_definition_complaint (body);
8861 macro_define_function (file, line, name,
8862 argc, (const char **) argv,
8866 /* Just complain. */
8867 dwarf2_macro_malformed_definition_complaint (body);
8870 /* Just complain. */
8871 dwarf2_macro_malformed_definition_complaint (body);
8877 for (i = 0; i < argc; i++)
8883 dwarf2_macro_malformed_definition_complaint (body);
8888 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
8889 char *comp_dir, bfd *abfd,
8890 struct dwarf2_cu *cu)
8892 char *mac_ptr, *mac_end;
8893 struct macro_source_file *current_file = 0;
8895 if (dwarf2_per_objfile->macinfo_buffer == NULL)
8897 complaint (&symfile_complaints, "missing .debug_macinfo section");
8901 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
8902 mac_end = dwarf2_per_objfile->macinfo_buffer
8903 + dwarf2_per_objfile->macinfo_size;
8907 enum dwarf_macinfo_record_type macinfo_type;
8909 /* Do we at least have room for a macinfo type byte? */
8910 if (mac_ptr >= mac_end)
8912 dwarf2_macros_too_long_complaint ();
8916 macinfo_type = read_1_byte (abfd, mac_ptr);
8919 switch (macinfo_type)
8921 /* A zero macinfo type indicates the end of the macro
8926 case DW_MACINFO_define:
8927 case DW_MACINFO_undef:
8933 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8934 mac_ptr += bytes_read;
8935 body = read_string (abfd, mac_ptr, &bytes_read);
8936 mac_ptr += bytes_read;
8939 complaint (&symfile_complaints,
8940 "debug info gives macro %s outside of any file: %s",
8942 DW_MACINFO_define ? "definition" : macinfo_type ==
8943 DW_MACINFO_undef ? "undefinition" :
8944 "something-or-other", body);
8947 if (macinfo_type == DW_MACINFO_define)
8948 parse_macro_definition (current_file, line, body);
8949 else if (macinfo_type == DW_MACINFO_undef)
8950 macro_undef (current_file, line, body);
8955 case DW_MACINFO_start_file:
8960 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8961 mac_ptr += bytes_read;
8962 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8963 mac_ptr += bytes_read;
8965 current_file = macro_start_file (file, line,
8966 current_file, comp_dir,
8971 case DW_MACINFO_end_file:
8973 complaint (&symfile_complaints,
8974 "macro debug info has an unmatched `close_file' directive");
8977 current_file = current_file->included_by;
8980 enum dwarf_macinfo_record_type next_type;
8982 /* GCC circa March 2002 doesn't produce the zero
8983 type byte marking the end of the compilation
8984 unit. Complain if it's not there, but exit no
8987 /* Do we at least have room for a macinfo type byte? */
8988 if (mac_ptr >= mac_end)
8990 dwarf2_macros_too_long_complaint ();
8994 /* We don't increment mac_ptr here, so this is just
8996 next_type = read_1_byte (abfd, mac_ptr);
8998 complaint (&symfile_complaints,
8999 "no terminating 0-type entry for macros in `.debug_macinfo' section");
9006 case DW_MACINFO_vendor_ext:
9012 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
9013 mac_ptr += bytes_read;
9014 string = read_string (abfd, mac_ptr, &bytes_read);
9015 mac_ptr += bytes_read;
9017 /* We don't recognize any vendor extensions. */
9024 /* Check if the attribute's form is a DW_FORM_block*
9025 if so return true else false. */
9027 attr_form_is_block (struct attribute *attr)
9029 return (attr == NULL ? 0 :
9030 attr->form == DW_FORM_block1
9031 || attr->form == DW_FORM_block2
9032 || attr->form == DW_FORM_block4
9033 || attr->form == DW_FORM_block);
9037 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
9038 struct dwarf2_cu *cu)
9040 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
9042 struct dwarf2_loclist_baton *baton;
9044 baton = obstack_alloc (&cu->objfile->objfile_obstack,
9045 sizeof (struct dwarf2_loclist_baton));
9046 baton->objfile = cu->objfile;
9048 /* We don't know how long the location list is, but make sure we
9049 don't run off the edge of the section. */
9050 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
9051 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
9052 baton->base_address = cu->header.base_address;
9053 if (cu->header.base_known == 0)
9054 complaint (&symfile_complaints,
9055 "Location list used without specifying the CU base address.");
9057 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
9058 SYMBOL_LOCATION_BATON (sym) = baton;
9062 struct dwarf2_locexpr_baton *baton;
9064 baton = obstack_alloc (&cu->objfile->objfile_obstack,
9065 sizeof (struct dwarf2_locexpr_baton));
9066 baton->objfile = cu->objfile;
9068 if (attr_form_is_block (attr))
9070 /* Note that we're just copying the block's data pointer
9071 here, not the actual data. We're still pointing into the
9072 info_buffer for SYM's objfile; right now we never release
9073 that buffer, but when we do clean up properly this may
9075 baton->size = DW_BLOCK (attr)->size;
9076 baton->data = DW_BLOCK (attr)->data;
9080 dwarf2_invalid_attrib_class_complaint ("location description",
9081 SYMBOL_NATURAL_NAME (sym));
9086 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
9087 SYMBOL_LOCATION_BATON (sym) = baton;
9091 /* Locate the compilation unit from CU's objfile which contains the
9092 DIE at OFFSET. Returns NULL on failure. */
9094 static struct dwarf2_per_cu_data *
9095 dwarf2_find_containing_comp_unit (unsigned long offset,
9096 struct objfile *objfile)
9098 struct dwarf2_per_cu_data *this_cu;
9101 if (dwarf2_per_objfile->all_comp_units == NULL)
9102 error ("Dwarf Error: offset 0x%lx points outside this "
9103 "compilation unit [in module %s]",
9104 offset, bfd_get_filename (objfile->obfd));
9107 high = dwarf2_per_objfile->n_comp_units - 1;
9110 int mid = low + (high - low) / 2;
9111 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
9116 gdb_assert (low == high);
9117 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
9119 gdb_assert (low > 0);
9120 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
9121 return dwarf2_per_objfile->all_comp_units[low-1];
9125 this_cu = dwarf2_per_objfile->all_comp_units[low];
9126 if (low == dwarf2_per_objfile->n_comp_units - 1
9127 && offset >= this_cu->offset + this_cu->length)
9128 error ("invalid dwarf2 offset %ld", offset);
9129 gdb_assert (offset < this_cu->offset + this_cu->length);
9134 static struct dwarf2_per_cu_data *
9135 dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile)
9137 struct dwarf2_per_cu_data *this_cu;
9138 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
9139 if (this_cu->offset != offset)
9140 error ("no compilation unit with offset %ld\n", offset);
9144 /* Release one cached compilation unit, CU. We unlink it from the tree
9145 of compilation units, but we don't remove it from the read_in_chain;
9146 the caller is responsible for that. */
9149 free_one_comp_unit (void *data)
9151 struct dwarf2_cu *cu = data;
9153 if (cu->per_cu != NULL)
9154 cu->per_cu->cu = NULL;
9157 obstack_free (&cu->comp_unit_obstack, NULL);
9162 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9163 when we're finished with it. We can't free the pointer itself, but be
9164 sure to unlink it from the cache. Also release any associated storage
9165 and perform cache maintenance.
9167 Only used during partial symbol parsing. */
9170 free_stack_comp_unit (void *data)
9172 struct dwarf2_cu *cu = data;
9174 obstack_free (&cu->comp_unit_obstack, NULL);
9175 cu->partial_dies = NULL;
9177 if (cu->per_cu != NULL)
9179 /* This compilation unit is on the stack in our caller, so we
9180 should not xfree it. Just unlink it. */
9181 cu->per_cu->cu = NULL;
9184 /* If we had a per-cu pointer, then we may have other compilation
9185 units loaded, so age them now. */
9186 age_cached_comp_units ();
9190 /* Free all cached compilation units. */
9193 free_cached_comp_units (void *data)
9195 struct dwarf2_per_cu_data *per_cu, **last_chain;
9197 per_cu = dwarf2_per_objfile->read_in_chain;
9198 last_chain = &dwarf2_per_objfile->read_in_chain;
9199 while (per_cu != NULL)
9201 struct dwarf2_per_cu_data *next_cu;
9203 next_cu = per_cu->cu->read_in_chain;
9205 free_one_comp_unit (per_cu->cu);
9206 *last_chain = next_cu;
9212 /* Increase the age counter on each cached compilation unit, and free
9213 any that are too old. */
9216 age_cached_comp_units (void)
9218 struct dwarf2_per_cu_data *per_cu, **last_chain;
9220 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
9221 per_cu = dwarf2_per_objfile->read_in_chain;
9222 while (per_cu != NULL)
9224 per_cu->cu->last_used ++;
9225 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
9226 dwarf2_mark (per_cu->cu);
9227 per_cu = per_cu->cu->read_in_chain;
9230 per_cu = dwarf2_per_objfile->read_in_chain;
9231 last_chain = &dwarf2_per_objfile->read_in_chain;
9232 while (per_cu != NULL)
9234 struct dwarf2_per_cu_data *next_cu;
9236 next_cu = per_cu->cu->read_in_chain;
9238 if (!per_cu->cu->mark)
9240 free_one_comp_unit (per_cu->cu);
9241 *last_chain = next_cu;
9244 last_chain = &per_cu->cu->read_in_chain;
9250 /* Remove a single compilation unit from the cache. */
9253 free_one_cached_comp_unit (void *target_cu)
9255 struct dwarf2_per_cu_data *per_cu, **last_chain;
9257 per_cu = dwarf2_per_objfile->read_in_chain;
9258 last_chain = &dwarf2_per_objfile->read_in_chain;
9259 while (per_cu != NULL)
9261 struct dwarf2_per_cu_data *next_cu;
9263 next_cu = per_cu->cu->read_in_chain;
9265 if (per_cu->cu == target_cu)
9267 free_one_comp_unit (per_cu->cu);
9268 *last_chain = next_cu;
9272 last_chain = &per_cu->cu->read_in_chain;
9278 /* A pair of DIE offset and GDB type pointer. We store these
9279 in a hash table separate from the DIEs, and preserve them
9280 when the DIEs are flushed out of cache. */
9282 struct dwarf2_offset_and_type
9284 unsigned int offset;
9288 /* Hash function for a dwarf2_offset_and_type. */
9291 offset_and_type_hash (const void *item)
9293 const struct dwarf2_offset_and_type *ofs = item;
9297 /* Equality function for a dwarf2_offset_and_type. */
9300 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
9302 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
9303 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
9304 return ofs_lhs->offset == ofs_rhs->offset;
9307 /* Set the type associated with DIE to TYPE. Save it in CU's hash
9308 table if necessary. */
9311 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
9313 struct dwarf2_offset_and_type **slot, ofs;
9317 if (cu->per_cu == NULL)
9320 if (cu->per_cu->type_hash == NULL)
9321 cu->per_cu->type_hash
9322 = htab_create_alloc_ex (cu->header.length / 24,
9323 offset_and_type_hash,
9326 &cu->objfile->objfile_obstack,
9327 hashtab_obstack_allocate,
9328 dummy_obstack_deallocate);
9330 ofs.offset = die->offset;
9332 slot = (struct dwarf2_offset_and_type **)
9333 htab_find_slot_with_hash (cu->per_cu->type_hash, &ofs, ofs.offset, INSERT);
9334 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
9340 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
9341 have a saved type. */
9343 static struct type *
9344 get_die_type (struct die_info *die, htab_t type_hash)
9346 struct dwarf2_offset_and_type *slot, ofs;
9348 ofs.offset = die->offset;
9349 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
9356 /* Restore the types of the DIE tree starting at START_DIE from the hash
9357 table saved in CU. */
9360 reset_die_and_siblings_types (struct die_info *start_die, struct dwarf2_cu *cu)
9362 struct die_info *die;
9364 if (cu->per_cu->type_hash == NULL)
9367 for (die = start_die; die != NULL; die = die->sibling)
9369 die->type = get_die_type (die, cu->per_cu->type_hash);
9370 if (die->child != NULL)
9371 reset_die_and_siblings_types (die->child, cu);
9377 /* Set the mark field in CU and in every other compilation unit in the
9378 cache that we must keep because we are keeping CU. */
9381 dwarf2_mark (struct dwarf2_cu *cu)
9389 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
9393 per_cu->cu->mark = 0;
9394 per_cu = per_cu->cu->read_in_chain;
9398 /* Allocation function for the libiberty hash table which uses an
9402 hashtab_obstack_allocate (void *data, size_t size, size_t count)
9404 unsigned int total = size * count;
9405 void *ptr = obstack_alloc ((struct obstack *) data, total);
9406 memset (ptr, 0, total);
9410 /* Trivial deallocation function for the libiberty splay tree and hash
9411 table - don't deallocate anything. Rely on later deletion of the
9415 dummy_obstack_deallocate (void *object, void *data)
9420 /* Trivial hash function for partial_die_info: the hash value of a DIE
9421 is its offset in .debug_info for this objfile. */
9424 partial_die_hash (const void *item)
9426 const struct partial_die_info *part_die = item;
9427 return part_die->offset;
9430 /* Trivial comparison function for partial_die_info structures: two DIEs
9431 are equal if they have the same offset. */
9434 partial_die_eq (const void *item_lhs, const void *item_rhs)
9436 const struct partial_die_info *part_die_lhs = item_lhs;
9437 const struct partial_die_info *part_die_rhs = item_rhs;
9438 return part_die_lhs->offset == part_die_rhs->offset;
9441 static struct cmd_list_element *set_dwarf2_cmdlist;
9442 static struct cmd_list_element *show_dwarf2_cmdlist;
9445 set_dwarf2_cmd (char *args, int from_tty)
9447 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
9451 show_dwarf2_cmd (char *args, int from_tty)
9453 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
9456 void _initialize_dwarf2_read (void);
9459 _initialize_dwarf2_read (void)
9461 dwarf2_objfile_data_key = register_objfile_data ();
9463 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd,
9464 "Set DWARF 2 specific variables.\n"
9465 "Configure DWARF 2 variables such as the cache size",
9466 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
9467 0/*allow-unknown*/, &maintenance_set_cmdlist);
9469 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd,
9470 "Show DWARF 2 specific variables\n"
9471 "Show DWARF 2 variables such as the cache size",
9472 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
9473 0/*allow-unknown*/, &maintenance_show_cmdlist);
9475 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
9476 &dwarf2_max_cache_age,
9477 "Set the upper bound on the age of cached "
9478 "dwarf2 compilation units.",
9479 "Show the upper bound on the age of cached "
9480 "dwarf2 compilation units.",
9481 "A higher limit means that cached "
9482 "compilation units will be stored\n"
9483 "in memory longer, and more total memory will "
9484 "be used. Zero disables\n"
9485 "caching, which can slow down startup.",
9486 "The upper bound on the age of cached "
9487 "dwarf2 compilation units is %d.",
9488 NULL, NULL, &set_dwarf2_cmdlist,
9489 &show_dwarf2_cmdlist);