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.
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"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 /* A note on memory usage for this file.
56 At the present time, this code reads the debug info sections into
57 the objfile's objfile_obstack. A definite improvement for startup
58 time, on platforms which do not emit relocations for debug
59 sections, would be to use mmap instead. The object's complete
60 debug information is loaded into memory, partly to simplify
61 absolute DIE references.
63 Whether using obstacks or mmap, the sections should remain loaded
64 until the objfile is released, and pointers into the section data
65 can be used for any other data associated to the objfile (symbol
66 names, type names, location expressions to name a few). */
68 #ifndef DWARF2_REG_TO_REGNUM
69 #define DWARF2_REG_TO_REGNUM(REG) (REG)
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length; /* length of the .debug_info
80 unsigned short version; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
83 unsigned char addr_size; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length; /* length of the .debug_pubnames
96 unsigned char version; /* version number -- 2 for DWARF
98 unsigned int info_offset; /* offset into .debug_info section */
99 unsigned int info_size; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length; /* byte len of the .debug_aranges
112 unsigned short version; /* version number -- 2 for DWARF
114 unsigned int info_offset; /* offset into .debug_info section */
115 unsigned char addr_size; /* byte size of an address */
116 unsigned char seg_size; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length; /* byte length of the statement
128 unsigned short version; /* version number -- 2 for DWARF
130 unsigned int prologue_length; /* # bytes between prologue &
132 unsigned char minimum_instruction_length; /* byte size of
134 unsigned char default_is_stmt; /* initial value of is_stmt
137 unsigned char line_range;
138 unsigned char opcode_base; /* number assigned to first special
140 unsigned char *standard_opcode_lengths;
144 static const struct objfile_data *dwarf2_objfile_data_key;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size;
150 unsigned int abbrev_size;
151 unsigned int line_size;
152 unsigned int pubnames_size;
153 unsigned int aranges_size;
154 unsigned int loc_size;
155 unsigned int macinfo_size;
156 unsigned int str_size;
157 unsigned int ranges_size;
158 unsigned int frame_size;
159 unsigned int eh_frame_size;
161 /* Loaded data from the sections. */
166 char *macinfo_buffer;
171 static struct dwarf2_per_objfile *dwarf2_per_objfile;
173 static asection *dwarf_info_section;
174 static asection *dwarf_abbrev_section;
175 static asection *dwarf_line_section;
176 static asection *dwarf_pubnames_section;
177 static asection *dwarf_aranges_section;
178 static asection *dwarf_loc_section;
179 static asection *dwarf_macinfo_section;
180 static asection *dwarf_str_section;
181 static asection *dwarf_ranges_section;
182 asection *dwarf_frame_section;
183 asection *dwarf_eh_frame_section;
185 /* names of the debugging sections */
187 #define INFO_SECTION ".debug_info"
188 #define ABBREV_SECTION ".debug_abbrev"
189 #define LINE_SECTION ".debug_line"
190 #define PUBNAMES_SECTION ".debug_pubnames"
191 #define ARANGES_SECTION ".debug_aranges"
192 #define LOC_SECTION ".debug_loc"
193 #define MACINFO_SECTION ".debug_macinfo"
194 #define STR_SECTION ".debug_str"
195 #define RANGES_SECTION ".debug_ranges"
196 #define FRAME_SECTION ".debug_frame"
197 #define EH_FRAME_SECTION ".eh_frame"
199 /* local data types */
201 /* We hold several abbreviation tables in memory at the same time. */
202 #ifndef ABBREV_HASH_SIZE
203 #define ABBREV_HASH_SIZE 121
206 /* The data in a compilation unit header, after target2host
207 translation, looks like this. */
208 struct comp_unit_head
210 unsigned long length;
212 unsigned int abbrev_offset;
213 unsigned char addr_size;
214 unsigned char signed_addr_p;
215 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
216 unsigned int initial_length_size; /* size of the length field; either
219 /* Offset to the first byte of this compilation unit header in the
220 * .debug_info section, for resolving relative reference dies. */
224 /* Pointer to this compilation unit header in the .debug_info
229 /* Pointer to the first die of this compilatio unit. This will
230 * be the first byte following the compilation unit header. */
234 /* Pointer to the next compilation unit header in the program. */
236 struct comp_unit_head *next;
238 /* Base address of this compilation unit. */
240 CORE_ADDR base_address;
242 /* Non-zero if base_address has been set. */
247 /* Internal state when decoding a particular compilation unit. */
250 /* The objfile containing this compilation unit. */
251 struct objfile *objfile;
253 /* The header of the compilation unit.
255 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
256 should logically be moved to the dwarf2_cu structure. */
257 struct comp_unit_head header;
259 struct function_range *first_fn, *last_fn, *cached_fn;
261 /* The language we are debugging. */
262 enum language language;
263 const struct language_defn *language_defn;
265 /* The generic symbol table building routines have separate lists for
266 file scope symbols and all all other scopes (local scopes). So
267 we need to select the right one to pass to add_symbol_to_list().
268 We do it by keeping a pointer to the correct list in list_in_scope.
270 FIXME: The original dwarf code just treated the file scope as the
271 first local scope, and all other local scopes as nested local
272 scopes, and worked fine. Check to see if we really need to
273 distinguish these in buildsym.c. */
274 struct pending **list_in_scope;
276 /* Maintain an array of referenced fundamental types for the current
277 compilation unit being read. For DWARF version 1, we have to construct
278 the fundamental types on the fly, since no information about the
279 fundamental types is supplied. Each such fundamental type is created by
280 calling a language dependent routine to create the type, and then a
281 pointer to that type is then placed in the array at the index specified
282 by it's FT_<TYPENAME> value. The array has a fixed size set by the
283 FT_NUM_MEMBERS compile time constant, which is the number of predefined
284 fundamental types gdb knows how to construct. */
285 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
287 /* DWARF abbreviation table associated with this compilation unit. */
288 struct abbrev_info **dwarf2_abbrevs;
290 /* Storage for the abbrev table. */
291 struct obstack abbrev_obstack;
293 /* Hash table holding all the loaded partial DIEs. */
296 /* Storage for things with the same lifetime as this read-in compilation
297 unit, including partial DIEs. */
298 struct obstack comp_unit_obstack;
300 /* This flag will be set if this compilation unit includes any
301 DW_TAG_namespace DIEs. If we know that there are explicit
302 DIEs for namespaces, we don't need to try to infer them
303 from mangled names. */
304 unsigned int has_namespace_info : 1;
307 /* The line number information for a compilation unit (found in the
308 .debug_line section) begins with a "statement program header",
309 which contains the following information. */
312 unsigned int total_length;
313 unsigned short version;
314 unsigned int header_length;
315 unsigned char minimum_instruction_length;
316 unsigned char default_is_stmt;
318 unsigned char line_range;
319 unsigned char opcode_base;
321 /* standard_opcode_lengths[i] is the number of operands for the
322 standard opcode whose value is i. This means that
323 standard_opcode_lengths[0] is unused, and the last meaningful
324 element is standard_opcode_lengths[opcode_base - 1]. */
325 unsigned char *standard_opcode_lengths;
327 /* The include_directories table. NOTE! These strings are not
328 allocated with xmalloc; instead, they are pointers into
329 debug_line_buffer. If you try to free them, `free' will get
331 unsigned int num_include_dirs, include_dirs_size;
334 /* The file_names table. NOTE! These strings are not allocated
335 with xmalloc; instead, they are pointers into debug_line_buffer.
336 Don't try to free them directly. */
337 unsigned int num_file_names, file_names_size;
341 unsigned int dir_index;
342 unsigned int mod_time;
346 /* The start and end of the statement program following this
347 header. These point into dwarf2_per_objfile->line_buffer. */
348 char *statement_program_start, *statement_program_end;
351 /* When we construct a partial symbol table entry we only
352 need this much information. */
353 struct partial_die_info
355 /* Offset of this DIE. */
358 /* DWARF-2 tag for this DIE. */
359 ENUM_BITFIELD(dwarf_tag) tag : 16;
361 /* Language code associated with this DIE. This is only used
362 for the compilation unit DIE. */
363 unsigned int language : 8;
365 /* Assorted flags describing the data found in this DIE. */
366 unsigned int has_children : 1;
367 unsigned int is_external : 1;
368 unsigned int is_declaration : 1;
369 unsigned int has_type : 1;
370 unsigned int has_specification : 1;
371 unsigned int has_pc_info : 1;
373 /* Flag set if the SCOPE field of this structure has been
375 unsigned int scope_set : 1;
377 /* The name of this DIE. Normally the value of DW_AT_name, but
378 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
382 /* The scope to prepend to our children. This is generally
383 allocated on the comp_unit_obstack, so will disappear
384 when this compilation unit leaves the cache. */
387 /* The location description associated with this DIE, if any. */
388 struct dwarf_block *locdesc;
390 /* If HAS_PC_INFO, the PC range associated with this DIE. */
394 /* Pointer into the info_buffer pointing at the target of
395 DW_AT_sibling, if any. */
398 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
399 DW_AT_specification (or DW_AT_abstract_origin or
401 unsigned int spec_offset;
403 /* Pointers to this DIE's parent, first child, and next sibling,
405 struct partial_die_info *die_parent, *die_child, *die_sibling;
408 /* This data structure holds the information of an abbrev. */
411 unsigned int number; /* number identifying abbrev */
412 enum dwarf_tag tag; /* dwarf tag */
413 unsigned short has_children; /* boolean */
414 unsigned short num_attrs; /* number of attributes */
415 struct attr_abbrev *attrs; /* an array of attribute descriptions */
416 struct abbrev_info *next; /* next in chain */
421 enum dwarf_attribute name;
422 enum dwarf_form form;
425 /* This data structure holds a complete die structure. */
428 enum dwarf_tag tag; /* Tag indicating type of die */
429 unsigned int abbrev; /* Abbrev number */
430 unsigned int offset; /* Offset in .debug_info section */
431 unsigned int num_attrs; /* Number of attributes */
432 struct attribute *attrs; /* An array of attributes */
433 struct die_info *next_ref; /* Next die in ref hash table */
435 /* The dies in a compilation unit form an n-ary tree. PARENT
436 points to this die's parent; CHILD points to the first child of
437 this node; and all the children of a given node are chained
438 together via their SIBLING fields, terminated by a die whose
440 struct die_info *child; /* Its first child, if any. */
441 struct die_info *sibling; /* Its next sibling, if any. */
442 struct die_info *parent; /* Its parent, if any. */
444 struct type *type; /* Cached type information */
447 /* Attributes have a name and a value */
450 enum dwarf_attribute name;
451 enum dwarf_form form;
455 struct dwarf_block *blk;
463 struct function_range
466 CORE_ADDR lowpc, highpc;
468 struct function_range *next;
471 /* Get at parts of an attribute structure */
473 #define DW_STRING(attr) ((attr)->u.str)
474 #define DW_UNSND(attr) ((attr)->u.unsnd)
475 #define DW_BLOCK(attr) ((attr)->u.blk)
476 #define DW_SND(attr) ((attr)->u.snd)
477 #define DW_ADDR(attr) ((attr)->u.addr)
479 /* Blocks are a bunch of untyped bytes. */
486 #ifndef ATTR_ALLOC_CHUNK
487 #define ATTR_ALLOC_CHUNK 4
490 /* A hash table of die offsets for following references. */
491 #ifndef REF_HASH_SIZE
492 #define REF_HASH_SIZE 1021
495 static struct die_info *die_ref_table[REF_HASH_SIZE];
497 /* Obstack for allocating temporary storage used during symbol reading. */
498 static struct obstack dwarf2_tmp_obstack;
500 /* Allocate fields for structs, unions and enums in this size. */
501 #ifndef DW_FIELD_ALLOC_CHUNK
502 #define DW_FIELD_ALLOC_CHUNK 4
505 /* A zeroed version of a partial die for initialization purposes. */
506 static struct partial_die_info zeroed_partial_die;
508 /* FIXME: decode_locdesc sets these variables to describe the location
509 to the caller. These ought to be a structure or something. If
510 none of the flags are set, the object lives at the address returned
511 by decode_locdesc. */
513 static int isreg; /* Object lives in register.
514 decode_locdesc's return value is
515 the register number. */
517 /* We put a pointer to this structure in the read_symtab_private field
522 /* Offset in .debug_info for this compilation unit. */
524 unsigned long dwarf_info_offset;
527 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
528 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
530 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
531 but this would require a corresponding change in unpack_field_as_long
533 static int bits_per_byte = 8;
535 /* The routines that read and process dies for a C struct or C++ class
536 pass lists of data member fields and lists of member function fields
537 in an instance of a field_info structure, as defined below. */
540 /* List of data member and baseclasses fields. */
543 struct nextfield *next;
550 /* Number of fields. */
553 /* Number of baseclasses. */
556 /* Set if the accesibility of one of the fields is not public. */
557 int non_public_fields;
559 /* Member function fields array, entries are allocated in the order they
560 are encountered in the object file. */
563 struct nextfnfield *next;
564 struct fn_field fnfield;
568 /* Member function fieldlist array, contains name of possibly overloaded
569 member function, number of overloaded member functions and a pointer
570 to the head of the member function field chain. */
575 struct nextfnfield *head;
579 /* Number of entries in the fnfieldlists array. */
583 /* Various complaints about symbol reading that don't abort the process */
586 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
588 complaint (&symfile_complaints,
589 "statement list doesn't fit in .debug_line section");
593 dwarf2_complex_location_expr_complaint (void)
595 complaint (&symfile_complaints, "location expression too complex");
599 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
602 complaint (&symfile_complaints,
603 "const value length mismatch for '%s', got %d, expected %d", arg1,
608 dwarf2_macros_too_long_complaint (void)
610 complaint (&symfile_complaints,
611 "macro info runs off end of `.debug_macinfo' section");
615 dwarf2_macro_malformed_definition_complaint (const char *arg1)
617 complaint (&symfile_complaints,
618 "macro debug info contains a malformed macro definition:\n`%s'",
623 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
625 complaint (&symfile_complaints,
626 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
629 /* local function prototypes */
631 static void dwarf2_locate_sections (bfd *, asection *, void *);
634 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
637 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
639 static void scan_partial_symbols (struct partial_die_info *,
640 CORE_ADDR *, CORE_ADDR *,
643 static void add_partial_symbol (struct partial_die_info *,
646 static int pdi_needs_namespace (enum dwarf_tag tag);
648 static void add_partial_namespace (struct partial_die_info *pdi,
649 CORE_ADDR *lowpc, CORE_ADDR *highpc,
650 struct dwarf2_cu *cu);
652 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
653 struct dwarf2_cu *cu);
655 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
658 struct dwarf2_cu *cu);
660 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
662 static void psymtab_to_symtab_1 (struct partial_symtab *);
664 char *dwarf2_read_section (struct objfile *, asection *);
666 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
668 static void dwarf2_free_abbrev_table (void *);
670 static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *);
672 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
675 static struct partial_die_info *load_partial_dies (bfd *, char *, int,
678 static char *read_partial_die (struct partial_die_info *,
679 struct abbrev_info *abbrev, unsigned int,
680 bfd *, char *, struct dwarf2_cu *);
682 static struct partial_die_info *find_partial_die (unsigned long,
684 struct dwarf2_cu **);
686 static void fixup_partial_die (struct partial_die_info *,
689 static char *read_full_die (struct die_info **, bfd *, char *,
690 struct dwarf2_cu *, int *);
692 static char *read_attribute (struct attribute *, struct attr_abbrev *,
693 bfd *, char *, struct dwarf2_cu *);
695 static char *read_attribute_value (struct attribute *, unsigned,
696 bfd *, char *, struct dwarf2_cu *);
698 static unsigned int read_1_byte (bfd *, char *);
700 static int read_1_signed_byte (bfd *, char *);
702 static unsigned int read_2_bytes (bfd *, char *);
704 static unsigned int read_4_bytes (bfd *, char *);
706 static unsigned long read_8_bytes (bfd *, char *);
708 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
711 static LONGEST read_initial_length (bfd *, char *,
712 struct comp_unit_head *, int *bytes_read);
714 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
717 static char *read_n_bytes (bfd *, char *, unsigned int);
719 static char *read_string (bfd *, char *, unsigned int *);
721 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
724 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
726 static long read_signed_leb128 (bfd *, char *, unsigned int *);
728 static char *skip_leb128 (bfd *, char *);
730 static void set_cu_language (unsigned int, struct dwarf2_cu *);
732 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
735 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
737 static struct die_info *die_specification (struct die_info *die,
740 static void free_line_header (struct line_header *lh);
742 static struct line_header *(dwarf_decode_line_header
743 (unsigned int offset,
744 bfd *abfd, struct dwarf2_cu *cu));
746 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
749 static void dwarf2_start_subfile (char *, char *);
751 static struct symbol *new_symbol (struct die_info *, struct type *,
754 static void dwarf2_const_value (struct attribute *, struct symbol *,
757 static void dwarf2_const_value_data (struct attribute *attr,
761 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
763 static struct type *die_containing_type (struct die_info *,
767 static struct type *type_at_offset (unsigned int, struct objfile *);
770 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
772 static void read_type_die (struct die_info *, struct dwarf2_cu *);
774 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
776 static char *typename_concat (const char *prefix, const char *suffix);
778 static void read_typedef (struct die_info *, struct dwarf2_cu *);
780 static void read_base_type (struct die_info *, struct dwarf2_cu *);
782 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
784 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
786 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
788 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
790 static int dwarf2_get_pc_bounds (struct die_info *,
791 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
793 static void get_scope_pc_bounds (struct die_info *,
794 CORE_ADDR *, CORE_ADDR *,
797 static void dwarf2_add_field (struct field_info *, struct die_info *,
800 static void dwarf2_attach_fields_to_type (struct field_info *,
801 struct type *, struct dwarf2_cu *);
803 static void dwarf2_add_member_fn (struct field_info *,
804 struct die_info *, struct type *,
807 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
808 struct type *, struct dwarf2_cu *);
810 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
812 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
814 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
816 static void read_common_block (struct die_info *, struct dwarf2_cu *);
818 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
820 static const char *namespace_name (struct die_info *die,
821 int *is_anonymous, struct dwarf2_cu *);
823 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
825 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
827 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
829 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
831 static void read_array_type (struct die_info *, struct dwarf2_cu *);
833 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
835 static void read_tag_ptr_to_member_type (struct die_info *,
838 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
840 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
842 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
844 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
846 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
848 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
850 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
853 struct die_info *parent);
855 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
858 struct die_info *parent);
860 static void free_die_list (struct die_info *);
862 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
864 static void process_die (struct die_info *, struct dwarf2_cu *);
866 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
868 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
870 static struct die_info *dwarf2_extension (struct die_info *die,
873 static char *dwarf_tag_name (unsigned int);
875 static char *dwarf_attr_name (unsigned int);
877 static char *dwarf_form_name (unsigned int);
879 static char *dwarf_stack_op_name (unsigned int);
881 static char *dwarf_bool_name (unsigned int);
883 static char *dwarf_type_encoding_name (unsigned int);
886 static char *dwarf_cfi_name (unsigned int);
888 struct die_info *copy_die (struct die_info *);
891 static struct die_info *sibling_die (struct die_info *);
893 static void dump_die (struct die_info *);
895 static void dump_die_list (struct die_info *);
897 static void store_in_ref_table (unsigned int, struct die_info *);
899 static void dwarf2_empty_hash_tables (void);
901 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
904 static int dwarf2_get_attr_constant_value (struct attribute *, int);
906 static struct die_info *follow_die_ref (unsigned int);
908 static struct type *dwarf2_fundamental_type (struct objfile *, int,
911 /* memory allocation interface */
913 static void dwarf2_free_tmp_obstack (void *);
915 static struct dwarf_block *dwarf_alloc_block (void);
917 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
919 static struct die_info *dwarf_alloc_die (void);
921 static void initialize_cu_func_list (struct dwarf2_cu *);
923 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
926 static void dwarf_decode_macros (struct line_header *, unsigned int,
927 char *, bfd *, struct dwarf2_cu *);
929 static int attr_form_is_block (struct attribute *);
932 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
933 struct dwarf2_cu *cu);
935 static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
936 struct dwarf2_cu *cu);
938 static void free_stack_comp_unit (void *);
940 static void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
942 static void dummy_obstack_deallocate (void *object, void *data);
944 static hashval_t partial_die_hash (const void *item);
946 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
948 /* Try to locate the sections we need for DWARF 2 debugging
949 information and return true if we have enough to do something. */
952 dwarf2_has_info (struct objfile *objfile)
954 struct dwarf2_per_objfile *data;
956 /* Initialize per-objfile state. */
957 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
958 memset (data, 0, sizeof (*data));
959 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
960 dwarf2_per_objfile = data;
962 dwarf_info_section = 0;
963 dwarf_abbrev_section = 0;
964 dwarf_line_section = 0;
965 dwarf_str_section = 0;
966 dwarf_macinfo_section = 0;
967 dwarf_frame_section = 0;
968 dwarf_eh_frame_section = 0;
969 dwarf_ranges_section = 0;
970 dwarf_loc_section = 0;
972 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
973 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
976 /* This function is mapped across the sections and remembers the
977 offset and size of each of the debugging sections we are interested
981 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
983 if (strcmp (sectp->name, INFO_SECTION) == 0)
985 dwarf2_per_objfile->info_size = bfd_get_section_size_before_reloc (sectp);
986 dwarf_info_section = sectp;
988 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
990 dwarf2_per_objfile->abbrev_size = bfd_get_section_size_before_reloc (sectp);
991 dwarf_abbrev_section = sectp;
993 else if (strcmp (sectp->name, LINE_SECTION) == 0)
995 dwarf2_per_objfile->line_size = bfd_get_section_size_before_reloc (sectp);
996 dwarf_line_section = sectp;
998 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
1000 dwarf2_per_objfile->pubnames_size = bfd_get_section_size_before_reloc (sectp);
1001 dwarf_pubnames_section = sectp;
1003 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
1005 dwarf2_per_objfile->aranges_size = bfd_get_section_size_before_reloc (sectp);
1006 dwarf_aranges_section = sectp;
1008 else if (strcmp (sectp->name, LOC_SECTION) == 0)
1010 dwarf2_per_objfile->loc_size = bfd_get_section_size_before_reloc (sectp);
1011 dwarf_loc_section = sectp;
1013 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
1015 dwarf2_per_objfile->macinfo_size = bfd_get_section_size_before_reloc (sectp);
1016 dwarf_macinfo_section = sectp;
1018 else if (strcmp (sectp->name, STR_SECTION) == 0)
1020 dwarf2_per_objfile->str_size = bfd_get_section_size_before_reloc (sectp);
1021 dwarf_str_section = sectp;
1023 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1025 dwarf2_per_objfile->frame_size = bfd_get_section_size_before_reloc (sectp);
1026 dwarf_frame_section = sectp;
1028 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1030 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1031 if (aflag & SEC_HAS_CONTENTS)
1033 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size_before_reloc (sectp);
1034 dwarf_eh_frame_section = sectp;
1037 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1039 dwarf2_per_objfile->ranges_size = bfd_get_section_size_before_reloc (sectp);
1040 dwarf_ranges_section = sectp;
1044 /* Build a partial symbol table. */
1047 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1049 /* We definitely need the .debug_info and .debug_abbrev sections */
1051 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1052 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1054 if (dwarf_line_section)
1055 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1057 dwarf2_per_objfile->line_buffer = NULL;
1059 if (dwarf_str_section)
1060 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1062 dwarf2_per_objfile->str_buffer = NULL;
1064 if (dwarf_macinfo_section)
1065 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1066 dwarf_macinfo_section);
1068 dwarf2_per_objfile->macinfo_buffer = NULL;
1070 if (dwarf_ranges_section)
1071 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1073 dwarf2_per_objfile->ranges_buffer = NULL;
1075 if (dwarf_loc_section)
1076 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1078 dwarf2_per_objfile->loc_buffer = NULL;
1081 || (objfile->global_psymbols.size == 0
1082 && objfile->static_psymbols.size == 0))
1084 init_psymbol_list (objfile, 1024);
1088 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1090 /* Things are significantly easier if we have .debug_aranges and
1091 .debug_pubnames sections */
1093 dwarf2_build_psymtabs_easy (objfile, mainline);
1097 /* only test this case for now */
1099 /* In this case we have to work a bit harder */
1100 dwarf2_build_psymtabs_hard (objfile, mainline);
1105 /* Build the partial symbol table from the information in the
1106 .debug_pubnames and .debug_aranges sections. */
1109 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1111 bfd *abfd = objfile->obfd;
1112 char *aranges_buffer, *pubnames_buffer;
1113 char *aranges_ptr, *pubnames_ptr;
1114 unsigned int entry_length, version, info_offset, info_size;
1116 pubnames_buffer = dwarf2_read_section (objfile,
1117 dwarf_pubnames_section);
1118 pubnames_ptr = pubnames_buffer;
1119 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1121 struct comp_unit_head cu_header;
1124 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1126 pubnames_ptr += bytes_read;
1127 version = read_1_byte (abfd, pubnames_ptr);
1129 info_offset = read_4_bytes (abfd, pubnames_ptr);
1131 info_size = read_4_bytes (abfd, pubnames_ptr);
1135 aranges_buffer = dwarf2_read_section (objfile,
1136 dwarf_aranges_section);
1141 /* Read in the comp unit header information from the debug_info at
1145 read_comp_unit_head (struct comp_unit_head *cu_header,
1146 char *info_ptr, bfd *abfd)
1150 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1152 info_ptr += bytes_read;
1153 cu_header->version = read_2_bytes (abfd, info_ptr);
1155 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1157 info_ptr += bytes_read;
1158 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1160 signed_addr = bfd_get_sign_extend_vma (abfd);
1161 if (signed_addr < 0)
1162 internal_error (__FILE__, __LINE__,
1163 "read_comp_unit_head: dwarf from non elf file");
1164 cu_header->signed_addr_p = signed_addr;
1169 partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr,
1172 char *beg_of_comp_unit = info_ptr;
1174 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1176 if (header->version != 2)
1177 error ("Dwarf Error: wrong version in compilation unit header "
1178 "(is %d, should be %d) [in module %s]", header->version,
1179 2, bfd_get_filename (abfd));
1181 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1182 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1183 "(offset 0x%lx + 6) [in module %s]",
1184 (long) header->abbrev_offset,
1185 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1186 bfd_get_filename (abfd));
1188 if (beg_of_comp_unit + header->length + header->initial_length_size
1189 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1190 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1191 "(offset 0x%lx + 0) [in module %s]",
1192 (long) header->length,
1193 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1194 bfd_get_filename (abfd));
1199 /* Build the partial symbol table by doing a quick pass through the
1200 .debug_info and .debug_abbrev sections. */
1203 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1205 /* Instead of reading this into a big buffer, we should probably use
1206 mmap() on architectures that support it. (FIXME) */
1207 bfd *abfd = objfile->obfd;
1209 char *beg_of_comp_unit;
1210 struct partial_die_info comp_unit_die;
1211 struct partial_symtab *pst;
1212 struct cleanup *back_to;
1213 CORE_ADDR lowpc, highpc, baseaddr;
1215 info_ptr = dwarf2_per_objfile->info_buffer;
1217 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1218 the partial symbol scan, like attribute values.
1220 We could reduce our peak memory consumption during partial symbol
1221 table construction by freeing stuff from this obstack more often
1222 --- say, after processing each compilation unit, or each die ---
1223 but it turns out that this saves almost nothing. For an
1224 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1225 on dwarf2_tmp_obstack. Some investigation showed:
1227 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1228 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1229 all fixed-length values not requiring dynamic allocation.
1231 2) 30% of the attributes used the form DW_FORM_string. For
1232 DW_FORM_string, read_attribute simply hands back a pointer to
1233 the null-terminated string in info_buffer, so no dynamic
1234 allocation is needed there either.
1236 3) The remaining 1% of the attributes all used DW_FORM_block1.
1237 75% of those were DW_AT_frame_base location lists for
1238 functions; the rest were DW_AT_location attributes, probably
1239 for the global variables.
1241 Anyway, what this all means is that the memory the dwarf2
1242 reader uses as temporary space reading partial symbols is about
1243 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1245 obstack_init (&dwarf2_tmp_obstack);
1246 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1248 /* Since the objects we're extracting from .debug_info vary in
1249 length, only the individual functions to extract them (like
1250 read_comp_unit_head and load_partial_die) can really know whether
1251 the buffer is large enough to hold another complete object.
1253 At the moment, they don't actually check that. If .debug_info
1254 holds just one extra byte after the last compilation unit's dies,
1255 then read_comp_unit_head will happily read off the end of the
1256 buffer. read_partial_die is similarly casual. Those functions
1259 For this loop condition, simply checking whether there's any data
1260 left at all should be sufficient. */
1261 while (info_ptr < (dwarf2_per_objfile->info_buffer
1262 + dwarf2_per_objfile->info_size))
1264 struct cleanup *back_to_inner;
1265 struct dwarf2_cu cu;
1266 struct abbrev_info *abbrev;
1267 unsigned int bytes_read;
1268 struct dwarf2_per_cu_data *this_cu;
1270 beg_of_comp_unit = info_ptr;
1272 memset (&cu, 0, sizeof (cu));
1274 obstack_init (&cu.comp_unit_obstack);
1276 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1278 cu.objfile = objfile;
1279 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1281 /* Complete the cu_header */
1282 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1283 cu.header.first_die_ptr = info_ptr;
1284 cu.header.cu_head_ptr = beg_of_comp_unit;
1286 cu.list_in_scope = &file_symbols;
1288 cu.partial_dies = NULL;
1290 /* Read the abbrevs for this compilation unit into a table */
1291 dwarf2_read_abbrevs (abfd, &cu);
1292 make_cleanup (dwarf2_free_abbrev_table, &cu);
1294 /* Read the compilation unit die */
1295 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1296 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1297 abfd, info_ptr, &cu);
1299 /* Set the language we're debugging */
1300 set_cu_language (comp_unit_die.language, &cu);
1302 /* Allocate a new partial symbol table structure */
1303 pst = start_psymtab_common (objfile, objfile->section_offsets,
1304 comp_unit_die.name ? comp_unit_die.name : "",
1305 comp_unit_die.lowpc,
1306 objfile->global_psymbols.next,
1307 objfile->static_psymbols.next);
1309 pst->read_symtab_private = (char *)
1310 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1311 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1312 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1314 /* Store the function that reads in the rest of the symbol table */
1315 pst->read_symtab = dwarf2_psymtab_to_symtab;
1317 /* Check if comp unit has_children.
1318 If so, read the rest of the partial symbols from this comp unit.
1319 If not, there's no more debug_info for this comp unit. */
1320 if (comp_unit_die.has_children)
1322 struct partial_die_info *first_die;
1324 lowpc = ((CORE_ADDR) -1);
1325 highpc = ((CORE_ADDR) 0);
1327 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1329 scan_partial_symbols (first_die, &lowpc, &highpc, &cu);
1331 /* If we didn't find a lowpc, set it to highpc to avoid
1332 complaints from `maint check'. */
1333 if (lowpc == ((CORE_ADDR) -1))
1336 /* If the compilation unit didn't have an explicit address range,
1337 then use the information extracted from its child dies. */
1338 if (! comp_unit_die.has_pc_info)
1340 comp_unit_die.lowpc = lowpc;
1341 comp_unit_die.highpc = highpc;
1344 pst->textlow = comp_unit_die.lowpc + baseaddr;
1345 pst->texthigh = comp_unit_die.highpc + baseaddr;
1347 pst->n_global_syms = objfile->global_psymbols.next -
1348 (objfile->global_psymbols.list + pst->globals_offset);
1349 pst->n_static_syms = objfile->static_psymbols.next -
1350 (objfile->static_psymbols.list + pst->statics_offset);
1351 sort_pst_symbols (pst);
1353 /* If there is already a psymtab or symtab for a file of this
1354 name, remove it. (If there is a symtab, more drastic things
1355 also happen.) This happens in VxWorks. */
1356 free_named_symtabs (pst->filename);
1358 info_ptr = beg_of_comp_unit + cu.header.length
1359 + cu.header.initial_length_size;
1361 do_cleanups (back_to_inner);
1363 do_cleanups (back_to);
1366 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1367 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1371 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1372 CORE_ADDR *highpc, struct dwarf2_cu *cu)
1374 struct objfile *objfile = cu->objfile;
1375 bfd *abfd = objfile->obfd;
1376 struct partial_die_info *pdi;
1378 /* Now, march along the PDI's, descending into ones which have
1379 interesting children but skipping the children of the other ones,
1380 until we reach the end of the compilation unit. */
1386 fixup_partial_die (pdi, cu);
1388 /* Anonymous namespaces have no name but have interesting
1389 children, so we need to look at them. Ditto for anonymous
1392 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1393 || pdi->tag == DW_TAG_enumeration_type)
1397 case DW_TAG_subprogram:
1398 if (pdi->has_pc_info)
1400 if (pdi->lowpc < *lowpc)
1402 *lowpc = pdi->lowpc;
1404 if (pdi->highpc > *highpc)
1406 *highpc = pdi->highpc;
1408 if (!pdi->is_declaration)
1410 add_partial_symbol (pdi, cu);
1414 case DW_TAG_variable:
1415 case DW_TAG_typedef:
1416 case DW_TAG_union_type:
1417 if (!pdi->is_declaration)
1419 add_partial_symbol (pdi, cu);
1422 case DW_TAG_class_type:
1423 case DW_TAG_structure_type:
1424 if (!pdi->is_declaration)
1426 add_partial_symbol (pdi, cu);
1429 case DW_TAG_enumeration_type:
1430 if (!pdi->is_declaration)
1431 add_partial_enumeration (pdi, cu);
1433 case DW_TAG_base_type:
1434 case DW_TAG_subrange_type:
1435 /* File scope base type definitions are added to the partial
1437 add_partial_symbol (pdi, cu);
1439 case DW_TAG_namespace:
1440 add_partial_namespace (pdi, lowpc, highpc, cu);
1447 /* If the die has a sibling, skip to the sibling. */
1449 pdi = pdi->die_sibling;
1453 /* Functions used to compute the fully scoped name of a partial DIE.
1455 Normally, this is simple. For C++, the parent DIE's fully scoped
1456 name is concatenated with "::" and the partial DIE's name.
1457 Enumerators are an exception; they use the scope of their parent
1458 enumeration type, i.e. the name of the enumeration type is not
1459 prepended to the enumerator.
1461 There are two complexities. One is DW_AT_specification; in this
1462 case "parent" means the parent of the target of the specification,
1463 instead of the direct parent of the DIE. The other is compilers
1464 which do not emit DW_TAG_namespace; in this case we try to guess
1465 the fully qualified name of structure types from their members'
1466 linkage names. This must be done using the DIE's children rather
1467 than the children of any DW_AT_specification target. We only need
1468 to do this for structures at the top level, i.e. if the target of
1469 any DW_AT_specification (if any; otherwise the DIE itself) does not
1472 /* Compute the scope prefix associated with PDI's parent, in
1473 compilation unit CU. The result will be allocated on CU's
1474 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1475 field. NULL is returned if no prefix is necessary. */
1477 partial_die_parent_scope (struct partial_die_info *pdi,
1478 struct dwarf2_cu *cu)
1480 char *grandparent_scope;
1481 struct partial_die_info *parent, *real_pdi;
1482 struct dwarf2_cu *spec_cu;
1484 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1485 then this means the parent of the specification DIE. */
1489 while (real_pdi->has_specification)
1490 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1492 parent = real_pdi->die_parent;
1496 if (parent->scope_set)
1497 return parent->scope;
1499 fixup_partial_die (parent, cu);
1501 grandparent_scope = partial_die_parent_scope (parent, spec_cu);
1503 if (parent->tag == DW_TAG_namespace
1504 || parent->tag == DW_TAG_structure_type
1505 || parent->tag == DW_TAG_class_type
1506 || parent->tag == DW_TAG_union_type)
1508 if (grandparent_scope == NULL)
1509 parent->scope = parent->name;
1511 parent->scope = obconcat (&cu->comp_unit_obstack, grandparent_scope,
1512 "::", parent->name);
1514 else if (parent->tag == DW_TAG_enumeration_type)
1515 /* Enumerators should not get the name of the enumeration as a prefix. */
1516 parent->scope = grandparent_scope;
1519 /* FIXME drow/2004-04-01: What should we be doing with
1520 function-local names? For partial symbols, we should probably be
1522 complaint (&symfile_complaints,
1523 "unhandled containing DIE tag %d for DIE at %d",
1524 parent->tag, pdi->offset);
1525 parent->scope = grandparent_scope;
1528 parent->scope_set = 1;
1529 return parent->scope;
1532 /* Return the fully scoped name associated with PDI, from compilation unit
1533 CU. The result will be allocated with malloc. */
1535 partial_die_full_name (struct partial_die_info *pdi,
1536 struct dwarf2_cu *cu)
1540 parent_scope = partial_die_parent_scope (pdi, cu);
1541 if (parent_scope == NULL)
1544 return concat (parent_scope, "::", pdi->name, NULL);
1548 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1550 struct objfile *objfile = cu->objfile;
1553 const char *my_prefix;
1554 const struct partial_symbol *psym = NULL;
1556 int built_actual_name = 0;
1558 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1562 if (pdi_needs_namespace (pdi->tag))
1564 actual_name = partial_die_full_name (pdi, cu);
1566 built_actual_name = 1;
1569 if (actual_name == NULL)
1570 actual_name = pdi->name;
1574 case DW_TAG_subprogram:
1575 if (pdi->is_external)
1577 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1578 mst_text, objfile); */
1579 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1580 VAR_DOMAIN, LOC_BLOCK,
1581 &objfile->global_psymbols,
1582 0, pdi->lowpc + baseaddr,
1583 cu->language, objfile);
1587 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1588 mst_file_text, objfile); */
1589 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1590 VAR_DOMAIN, LOC_BLOCK,
1591 &objfile->static_psymbols,
1592 0, pdi->lowpc + baseaddr,
1593 cu->language, objfile);
1596 case DW_TAG_variable:
1597 if (pdi->is_external)
1600 Don't enter into the minimal symbol tables as there is
1601 a minimal symbol table entry from the ELF symbols already.
1602 Enter into partial symbol table if it has a location
1603 descriptor or a type.
1604 If the location descriptor is missing, new_symbol will create
1605 a LOC_UNRESOLVED symbol, the address of the variable will then
1606 be determined from the minimal symbol table whenever the variable
1608 The address for the partial symbol table entry is not
1609 used by GDB, but it comes in handy for debugging partial symbol
1613 addr = decode_locdesc (pdi->locdesc, cu);
1614 if (pdi->locdesc || pdi->has_type)
1615 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1616 VAR_DOMAIN, LOC_STATIC,
1617 &objfile->global_psymbols,
1619 cu->language, objfile);
1623 /* Static Variable. Skip symbols without location descriptors. */
1624 if (pdi->locdesc == NULL)
1626 addr = decode_locdesc (pdi->locdesc, cu);
1627 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1628 mst_file_data, objfile); */
1629 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1630 VAR_DOMAIN, LOC_STATIC,
1631 &objfile->static_psymbols,
1633 cu->language, objfile);
1636 case DW_TAG_typedef:
1637 case DW_TAG_base_type:
1638 case DW_TAG_subrange_type:
1639 add_psymbol_to_list (actual_name, strlen (actual_name),
1640 VAR_DOMAIN, LOC_TYPEDEF,
1641 &objfile->static_psymbols,
1642 0, (CORE_ADDR) 0, cu->language, objfile);
1644 case DW_TAG_namespace:
1645 add_psymbol_to_list (actual_name, strlen (actual_name),
1646 VAR_DOMAIN, LOC_TYPEDEF,
1647 &objfile->global_psymbols,
1648 0, (CORE_ADDR) 0, cu->language, objfile);
1650 case DW_TAG_class_type:
1651 case DW_TAG_structure_type:
1652 case DW_TAG_union_type:
1653 case DW_TAG_enumeration_type:
1654 /* Skip aggregate types without children, these are external
1656 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1657 static vs. global. */
1658 if (pdi->has_children == 0)
1660 add_psymbol_to_list (actual_name, strlen (actual_name),
1661 STRUCT_DOMAIN, LOC_TYPEDEF,
1662 cu->language == language_cplus
1663 ? &objfile->global_psymbols
1664 : &objfile->static_psymbols,
1665 0, (CORE_ADDR) 0, cu->language, objfile);
1667 if (cu->language == language_cplus)
1669 /* For C++, these implicitly act as typedefs as well. */
1670 add_psymbol_to_list (actual_name, strlen (actual_name),
1671 VAR_DOMAIN, LOC_TYPEDEF,
1672 &objfile->global_psymbols,
1673 0, (CORE_ADDR) 0, cu->language, objfile);
1676 case DW_TAG_enumerator:
1677 add_psymbol_to_list (actual_name, strlen (actual_name),
1678 VAR_DOMAIN, LOC_CONST,
1679 cu->language == language_cplus
1680 ? &objfile->global_psymbols
1681 : &objfile->static_psymbols,
1682 0, (CORE_ADDR) 0, cu->language, objfile);
1688 /* Check to see if we should scan the name for possible namespace
1689 info. Only do this if this is C++, if we don't have namespace
1690 debugging info in the file, if the psym is of an appropriate type
1691 (otherwise we'll have psym == NULL), and if we actually had a
1692 mangled name to begin with. */
1694 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1695 cases which do not set PSYM above? */
1697 if (cu->language == language_cplus
1698 && cu->has_namespace_info == 0
1700 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1701 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1704 if (built_actual_name)
1705 xfree (actual_name);
1708 /* Determine whether a die of type TAG living in a C++ class or
1709 namespace needs to have the name of the scope prepended to the
1710 name listed in the die. */
1713 pdi_needs_namespace (enum dwarf_tag tag)
1717 case DW_TAG_namespace:
1718 case DW_TAG_typedef:
1719 case DW_TAG_class_type:
1720 case DW_TAG_structure_type:
1721 case DW_TAG_union_type:
1722 case DW_TAG_enumeration_type:
1723 case DW_TAG_enumerator:
1730 /* Read a partial die corresponding to a namespace; also, add a symbol
1731 corresponding to that namespace to the symbol table. NAMESPACE is
1732 the name of the enclosing namespace. */
1735 add_partial_namespace (struct partial_die_info *pdi,
1736 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1737 struct dwarf2_cu *cu)
1739 struct objfile *objfile = cu->objfile;
1741 /* Add a symbol for the namespace. */
1743 add_partial_symbol (pdi, cu);
1745 /* Now scan partial symbols in that namespace. */
1747 if (pdi->has_children)
1748 scan_partial_symbols (pdi->die_child, lowpc, highpc, cu);
1751 /* See if we can figure out if the class lives in a namespace. We do
1752 this by looking for a member function; its demangled name will
1753 contain namespace info, if there is any. */
1756 guess_structure_name (struct partial_die_info *struct_pdi,
1757 struct dwarf2_cu *cu)
1759 if (cu->language == language_cplus
1760 && cu->has_namespace_info == 0
1761 && struct_pdi->has_children)
1763 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1764 what template types look like, because the demangler
1765 frequently doesn't give the same name as the debug info. We
1766 could fix this by only using the demangled name to get the
1767 prefix (but see comment in read_structure_type). */
1769 struct partial_die_info *child_pdi = struct_pdi->die_child;
1770 struct partial_die_info *real_pdi;
1771 struct dwarf2_cu *spec_cu;
1773 /* If this DIE (this DIE's specification, if any) has a parent, then
1774 we should not do this. We'll prepend the parent's fully qualified
1775 name when we create the partial symbol. */
1777 real_pdi = struct_pdi;
1779 while (real_pdi->has_specification)
1780 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1782 if (real_pdi->die_parent != NULL)
1785 while (child_pdi != NULL)
1787 if (child_pdi->tag == DW_TAG_subprogram)
1789 char *actual_class_name
1790 = class_name_from_physname (child_pdi->name);
1791 if (actual_class_name != NULL)
1794 = obsavestring (actual_class_name,
1795 strlen (actual_class_name),
1796 &cu->comp_unit_obstack);
1797 xfree (actual_class_name);
1802 child_pdi = child_pdi->die_sibling;
1807 /* Read a partial die corresponding to an enumeration type. */
1810 add_partial_enumeration (struct partial_die_info *enum_pdi,
1811 struct dwarf2_cu *cu)
1813 struct objfile *objfile = cu->objfile;
1814 bfd *abfd = objfile->obfd;
1815 struct partial_die_info *pdi;
1817 if (enum_pdi->name != NULL)
1818 add_partial_symbol (enum_pdi, cu);
1820 pdi = enum_pdi->die_child;
1823 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
1824 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1826 add_partial_symbol (pdi, cu);
1827 pdi = pdi->die_sibling;
1831 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1832 Return the corresponding abbrev, or NULL if the number is zero (indicating
1833 an empty DIE). In either case *BYTES_READ will be set to the length of
1834 the initial number. */
1836 static struct abbrev_info *
1837 peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu)
1839 bfd *abfd = cu->objfile->obfd;
1840 unsigned int abbrev_number;
1841 struct abbrev_info *abbrev;
1843 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
1845 if (abbrev_number == 0)
1848 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
1851 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
1852 bfd_get_filename (abfd));
1858 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1859 pointer to the end of a series of DIEs, terminated by an empty
1860 DIE. Any children of the skipped DIEs will also be skipped. */
1863 skip_children (char *info_ptr, struct dwarf2_cu *cu)
1865 struct abbrev_info *abbrev;
1866 unsigned int bytes_read;
1870 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1872 return info_ptr + bytes_read;
1874 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
1878 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1879 should point just after the initial uleb128 of a DIE, and the
1880 abbrev corresponding to that skipped uleb128 should be passed in
1881 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1885 skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
1886 struct dwarf2_cu *cu)
1888 unsigned int bytes_read;
1889 struct attribute attr;
1890 bfd *abfd = cu->objfile->obfd;
1891 unsigned int form, i;
1893 for (i = 0; i < abbrev->num_attrs; i++)
1895 /* The only abbrev we care about is DW_AT_sibling. */
1896 if (abbrev->attrs[i].name == DW_AT_sibling)
1898 read_attribute (&attr, &abbrev->attrs[i],
1899 abfd, info_ptr, cu);
1900 if (attr.form == DW_FORM_ref_addr)
1901 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
1903 return dwarf2_per_objfile->info_buffer
1904 + dwarf2_get_ref_die_offset (&attr, cu);
1907 /* If it isn't DW_AT_sibling, skip this attribute. */
1908 form = abbrev->attrs[i].form;
1913 case DW_FORM_ref_addr:
1914 info_ptr += cu->header.addr_size;
1933 case DW_FORM_string:
1934 read_string (abfd, info_ptr, &bytes_read);
1935 info_ptr += bytes_read;
1938 info_ptr += cu->header.offset_size;
1941 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1942 info_ptr += bytes_read;
1944 case DW_FORM_block1:
1945 info_ptr += 1 + read_1_byte (abfd, info_ptr);
1947 case DW_FORM_block2:
1948 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
1950 case DW_FORM_block4:
1951 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
1955 case DW_FORM_ref_udata:
1956 info_ptr = skip_leb128 (abfd, info_ptr);
1958 case DW_FORM_indirect:
1959 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
1960 info_ptr += bytes_read;
1961 /* We need to continue parsing from here, so just go back to
1963 goto skip_attribute;
1966 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
1967 dwarf_form_name (form),
1968 bfd_get_filename (abfd));
1972 if (abbrev->has_children)
1973 return skip_children (info_ptr, cu);
1978 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
1979 the next DIE after ORIG_PDI. */
1982 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1983 bfd *abfd, struct dwarf2_cu *cu)
1985 /* Do we know the sibling already? */
1987 if (orig_pdi->sibling)
1988 return orig_pdi->sibling;
1990 /* Are there any children to deal with? */
1992 if (!orig_pdi->has_children)
1995 /* Skip the children the long way. */
1997 return skip_children (info_ptr, cu);
2000 /* Expand this partial symbol table into a full symbol table. */
2003 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2005 /* FIXME: This is barely more than a stub. */
2010 warning ("bug: psymtab for %s is already read in.", pst->filename);
2016 printf_filtered ("Reading in symbols for %s...", pst->filename);
2017 gdb_flush (gdb_stdout);
2020 psymtab_to_symtab_1 (pst);
2022 /* Finish up the debug error message. */
2024 printf_filtered ("done.\n");
2030 psymtab_to_symtab_1 (struct partial_symtab *pst)
2032 struct objfile *objfile = pst->objfile;
2033 bfd *abfd = objfile->obfd;
2034 struct dwarf2_cu cu;
2035 struct die_info *dies;
2036 unsigned long offset;
2037 CORE_ADDR lowpc, highpc;
2038 struct die_info *child_die;
2040 struct symtab *symtab;
2041 struct cleanup *back_to;
2042 struct attribute *attr;
2045 dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key);
2047 /* Set local variables from the partial symbol table info. */
2048 offset = DWARF_INFO_OFFSET (pst);
2050 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2051 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2053 /* We're in the global namespace. */
2054 processing_current_prefix = "";
2056 obstack_init (&dwarf2_tmp_obstack);
2057 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
2060 make_cleanup (really_free_pendings, NULL);
2062 cu.objfile = objfile;
2064 /* read in the comp_unit header */
2065 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
2067 /* Read the abbrevs for this compilation unit */
2068 dwarf2_read_abbrevs (abfd, &cu);
2069 make_cleanup (dwarf2_free_abbrev_table, &cu);
2071 cu.header.offset = offset;
2073 cu.list_in_scope = &file_symbols;
2075 dies = read_comp_unit (info_ptr, abfd, &cu);
2077 make_cleanup_free_die_list (dies);
2079 /* Find the base address of the compilation unit for range lists and
2080 location lists. It will normally be specified by DW_AT_low_pc.
2081 In DWARF-3 draft 4, the base address could be overridden by
2082 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2083 compilation units with discontinuous ranges. */
2085 cu.header.base_known = 0;
2086 cu.header.base_address = 0;
2088 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
2091 cu.header.base_address = DW_ADDR (attr);
2092 cu.header.base_known = 1;
2096 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
2099 cu.header.base_address = DW_ADDR (attr);
2100 cu.header.base_known = 1;
2104 /* Do line number decoding in read_file_scope () */
2105 process_die (dies, &cu);
2107 /* Some compilers don't define a DW_AT_high_pc attribute for the
2108 compilation unit. If the DW_AT_high_pc is missing, synthesize
2109 it, by scanning the DIE's below the compilation unit. */
2110 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
2112 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2114 /* Set symtab language to language from DW_AT_language.
2115 If the compilation is from a C file generated by language preprocessors,
2116 do not set the language if it was already deduced by start_subfile. */
2118 && !(cu.language == language_c && symtab->language != language_c))
2120 symtab->language = cu.language;
2122 pst->symtab = symtab;
2125 do_cleanups (back_to);
2128 /* Process a die and its children. */
2131 process_die (struct die_info *die, struct dwarf2_cu *cu)
2135 case DW_TAG_padding:
2137 case DW_TAG_compile_unit:
2138 read_file_scope (die, cu);
2140 case DW_TAG_subprogram:
2141 read_subroutine_type (die, cu);
2142 read_func_scope (die, cu);
2144 case DW_TAG_inlined_subroutine:
2145 /* FIXME: These are ignored for now.
2146 They could be used to set breakpoints on all inlined instances
2147 of a function and make GDB `next' properly over inlined functions. */
2149 case DW_TAG_lexical_block:
2150 case DW_TAG_try_block:
2151 case DW_TAG_catch_block:
2152 read_lexical_block_scope (die, cu);
2154 case DW_TAG_class_type:
2155 case DW_TAG_structure_type:
2156 case DW_TAG_union_type:
2157 read_structure_type (die, cu);
2158 process_structure_scope (die, cu);
2160 case DW_TAG_enumeration_type:
2161 read_enumeration_type (die, cu);
2162 process_enumeration_scope (die, cu);
2165 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2166 a symbol or process any children. Therefore it doesn't do anything
2167 that won't be done on-demand by read_type_die. */
2168 case DW_TAG_subroutine_type:
2169 read_subroutine_type (die, cu);
2171 case DW_TAG_array_type:
2172 read_array_type (die, cu);
2174 case DW_TAG_pointer_type:
2175 read_tag_pointer_type (die, cu);
2177 case DW_TAG_ptr_to_member_type:
2178 read_tag_ptr_to_member_type (die, cu);
2180 case DW_TAG_reference_type:
2181 read_tag_reference_type (die, cu);
2183 case DW_TAG_string_type:
2184 read_tag_string_type (die, cu);
2188 case DW_TAG_base_type:
2189 read_base_type (die, cu);
2190 /* Add a typedef symbol for the type definition, if it has a
2192 new_symbol (die, die->type, cu);
2194 case DW_TAG_subrange_type:
2195 read_subrange_type (die, cu);
2196 /* Add a typedef symbol for the type definition, if it has a
2198 new_symbol (die, die->type, cu);
2200 case DW_TAG_common_block:
2201 read_common_block (die, cu);
2203 case DW_TAG_common_inclusion:
2205 case DW_TAG_namespace:
2206 processing_has_namespace_info = 1;
2207 read_namespace (die, cu);
2209 case DW_TAG_imported_declaration:
2210 case DW_TAG_imported_module:
2211 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2212 information contained in these. DW_TAG_imported_declaration
2213 dies shouldn't have children; DW_TAG_imported_module dies
2214 shouldn't in the C++ case, but conceivably could in the
2215 Fortran case, so we'll have to replace this gdb_assert if
2216 Fortran compilers start generating that info. */
2217 processing_has_namespace_info = 1;
2218 gdb_assert (die->child == NULL);
2221 new_symbol (die, NULL, cu);
2227 initialize_cu_func_list (struct dwarf2_cu *cu)
2229 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2233 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2235 struct objfile *objfile = cu->objfile;
2236 struct comp_unit_head *cu_header = &cu->header;
2237 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2238 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2239 CORE_ADDR highpc = ((CORE_ADDR) 0);
2240 struct attribute *attr;
2241 char *name = "<unknown>";
2242 char *comp_dir = NULL;
2243 struct die_info *child_die;
2244 bfd *abfd = objfile->obfd;
2245 struct line_header *line_header = 0;
2248 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2250 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2252 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2253 from finish_block. */
2254 if (lowpc == ((CORE_ADDR) -1))
2259 attr = dwarf2_attr (die, DW_AT_name, cu);
2262 name = DW_STRING (attr);
2264 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2267 comp_dir = DW_STRING (attr);
2270 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2271 directory, get rid of it. */
2272 char *cp = strchr (comp_dir, ':');
2274 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2279 if (objfile->ei.entry_point >= lowpc &&
2280 objfile->ei.entry_point < highpc)
2282 objfile->ei.deprecated_entry_file_lowpc = lowpc;
2283 objfile->ei.deprecated_entry_file_highpc = highpc;
2286 attr = dwarf2_attr (die, DW_AT_language, cu);
2289 set_cu_language (DW_UNSND (attr), cu);
2292 /* We assume that we're processing GCC output. */
2293 processing_gcc_compilation = 2;
2295 /* FIXME:Do something here. */
2296 if (dip->at_producer != NULL)
2298 handle_producer (dip->at_producer);
2302 /* The compilation unit may be in a different language or objfile,
2303 zero out all remembered fundamental types. */
2304 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2306 start_symtab (name, comp_dir, lowpc);
2307 record_debugformat ("DWARF 2");
2309 initialize_cu_func_list (cu);
2311 /* Process all dies in compilation unit. */
2312 if (die->child != NULL)
2314 child_die = die->child;
2315 while (child_die && child_die->tag)
2317 process_die (child_die, cu);
2318 child_die = sibling_die (child_die);
2322 /* Decode line number information if present. */
2323 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2326 unsigned int line_offset = DW_UNSND (attr);
2327 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2330 make_cleanup ((make_cleanup_ftype *) free_line_header,
2331 (void *) line_header);
2332 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2336 /* Decode macro information, if present. Dwarf 2 macro information
2337 refers to information in the line number info statement program
2338 header, so we can only read it if we've read the header
2340 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2341 if (attr && line_header)
2343 unsigned int macro_offset = DW_UNSND (attr);
2344 dwarf_decode_macros (line_header, macro_offset,
2345 comp_dir, abfd, cu);
2347 do_cleanups (back_to);
2351 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2352 struct dwarf2_cu *cu)
2354 struct function_range *thisfn;
2356 thisfn = (struct function_range *)
2357 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2358 thisfn->name = name;
2359 thisfn->lowpc = lowpc;
2360 thisfn->highpc = highpc;
2361 thisfn->seen_line = 0;
2362 thisfn->next = NULL;
2364 if (cu->last_fn == NULL)
2365 cu->first_fn = thisfn;
2367 cu->last_fn->next = thisfn;
2369 cu->last_fn = thisfn;
2373 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2375 struct objfile *objfile = cu->objfile;
2376 struct context_stack *new;
2379 struct die_info *child_die;
2380 struct attribute *attr;
2382 const char *previous_prefix = processing_current_prefix;
2383 struct cleanup *back_to = NULL;
2386 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2388 name = dwarf2_linkage_name (die, cu);
2390 /* Ignore functions with missing or empty names and functions with
2391 missing or invalid low and high pc attributes. */
2392 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2395 if (cu->language == language_cplus)
2397 struct die_info *spec_die = die_specification (die, cu);
2399 /* NOTE: carlton/2004-01-23: We have to be careful in the
2400 presence of DW_AT_specification. For example, with GCC 3.4,
2405 // Definition of N::foo.
2409 then we'll have a tree of DIEs like this:
2411 1: DW_TAG_compile_unit
2412 2: DW_TAG_namespace // N
2413 3: DW_TAG_subprogram // declaration of N::foo
2414 4: DW_TAG_subprogram // definition of N::foo
2415 DW_AT_specification // refers to die #3
2417 Thus, when processing die #4, we have to pretend that we're
2418 in the context of its DW_AT_specification, namely the contex
2421 if (spec_die != NULL)
2423 char *specification_prefix = determine_prefix (spec_die, cu);
2424 processing_current_prefix = specification_prefix;
2425 back_to = make_cleanup (xfree, specification_prefix);
2432 /* Record the function range for dwarf_decode_lines. */
2433 add_to_cu_func_list (name, lowpc, highpc, cu);
2435 if (objfile->ei.entry_point >= lowpc &&
2436 objfile->ei.entry_point < highpc)
2438 objfile->ei.entry_func_lowpc = lowpc;
2439 objfile->ei.entry_func_highpc = highpc;
2442 new = push_context (0, lowpc);
2443 new->name = new_symbol (die, die->type, cu);
2445 /* If there is a location expression for DW_AT_frame_base, record
2447 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2449 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2450 expression is being recorded directly in the function's symbol
2451 and not in a separate frame-base object. I guess this hack is
2452 to avoid adding some sort of frame-base adjunct/annex to the
2453 function's symbol :-(. The problem with doing this is that it
2454 results in a function symbol with a location expression that
2455 has nothing to do with the location of the function, ouch! The
2456 relationship should be: a function's symbol has-a frame base; a
2457 frame-base has-a location expression. */
2458 dwarf2_symbol_mark_computed (attr, new->name, cu);
2460 cu->list_in_scope = &local_symbols;
2462 if (die->child != NULL)
2464 child_die = die->child;
2465 while (child_die && child_die->tag)
2467 process_die (child_die, cu);
2468 child_die = sibling_die (child_die);
2472 new = pop_context ();
2473 /* Make a block for the local symbols within. */
2474 finish_block (new->name, &local_symbols, new->old_blocks,
2475 lowpc, highpc, objfile);
2477 /* In C++, we can have functions nested inside functions (e.g., when
2478 a function declares a class that has methods). This means that
2479 when we finish processing a function scope, we may need to go
2480 back to building a containing block's symbol lists. */
2481 local_symbols = new->locals;
2482 param_symbols = new->params;
2484 /* If we've finished processing a top-level function, subsequent
2485 symbols go in the file symbol list. */
2486 if (outermost_context_p ())
2487 cu->list_in_scope = &file_symbols;
2489 processing_current_prefix = previous_prefix;
2490 if (back_to != NULL)
2491 do_cleanups (back_to);
2494 /* Process all the DIES contained within a lexical block scope. Start
2495 a new scope, process the dies, and then close the scope. */
2498 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2500 struct objfile *objfile = cu->objfile;
2501 struct context_stack *new;
2502 CORE_ADDR lowpc, highpc;
2503 struct die_info *child_die;
2506 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2508 /* Ignore blocks with missing or invalid low and high pc attributes. */
2509 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2510 as multiple lexical blocks? Handling children in a sane way would
2511 be nasty. Might be easier to properly extend generic blocks to
2513 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2518 push_context (0, lowpc);
2519 if (die->child != NULL)
2521 child_die = die->child;
2522 while (child_die && child_die->tag)
2524 process_die (child_die, cu);
2525 child_die = sibling_die (child_die);
2528 new = pop_context ();
2530 if (local_symbols != NULL)
2532 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2535 local_symbols = new->locals;
2538 /* Get low and high pc attributes from a die. Return 1 if the attributes
2539 are present and valid, otherwise, return 0. Return -1 if the range is
2540 discontinuous, i.e. derived from DW_AT_ranges information. */
2542 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2543 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2545 struct objfile *objfile = cu->objfile;
2546 struct comp_unit_head *cu_header = &cu->header;
2547 struct attribute *attr;
2548 bfd *obfd = objfile->obfd;
2553 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2556 high = DW_ADDR (attr);
2557 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2559 low = DW_ADDR (attr);
2561 /* Found high w/o low attribute. */
2564 /* Found consecutive range of addresses. */
2569 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2572 unsigned int addr_size = cu_header->addr_size;
2573 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2574 /* Value of the DW_AT_ranges attribute is the offset in the
2575 .debug_ranges section. */
2576 unsigned int offset = DW_UNSND (attr);
2577 /* Base address selection entry. */
2585 found_base = cu_header->base_known;
2586 base = cu_header->base_address;
2588 if (offset >= dwarf2_per_objfile->ranges_size)
2590 complaint (&symfile_complaints,
2591 "Offset %d out of bounds for DW_AT_ranges attribute",
2595 buffer = dwarf2_per_objfile->ranges_buffer + offset;
2597 /* Read in the largest possible address. */
2598 marker = read_address (obfd, buffer, cu, &dummy);
2599 if ((marker & mask) == mask)
2601 /* If we found the largest possible address, then
2602 read the base address. */
2603 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2604 buffer += 2 * addr_size;
2605 offset += 2 * addr_size;
2613 CORE_ADDR range_beginning, range_end;
2615 range_beginning = read_address (obfd, buffer, cu, &dummy);
2616 buffer += addr_size;
2617 range_end = read_address (obfd, buffer, cu, &dummy);
2618 buffer += addr_size;
2619 offset += 2 * addr_size;
2621 /* An end of list marker is a pair of zero addresses. */
2622 if (range_beginning == 0 && range_end == 0)
2623 /* Found the end of list entry. */
2626 /* Each base address selection entry is a pair of 2 values.
2627 The first is the largest possible address, the second is
2628 the base address. Check for a base address here. */
2629 if ((range_beginning & mask) == mask)
2631 /* If we found the largest possible address, then
2632 read the base address. */
2633 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2640 /* We have no valid base address for the ranges
2642 complaint (&symfile_complaints,
2643 "Invalid .debug_ranges data (no base address)");
2647 range_beginning += base;
2650 /* FIXME: This is recording everything as a low-high
2651 segment of consecutive addresses. We should have a
2652 data structure for discontiguous block ranges
2656 low = range_beginning;
2662 if (range_beginning < low)
2663 low = range_beginning;
2664 if (range_end > high)
2670 /* If the first entry is an end-of-list marker, the range
2671 describes an empty scope, i.e. no instructions. */
2681 /* When using the GNU linker, .gnu.linkonce. sections are used to
2682 eliminate duplicate copies of functions and vtables and such.
2683 The linker will arbitrarily choose one and discard the others.
2684 The AT_*_pc values for such functions refer to local labels in
2685 these sections. If the section from that file was discarded, the
2686 labels are not in the output, so the relocs get a value of 0.
2687 If this is a discarded function, mark the pc bounds as invalid,
2688 so that GDB will ignore it. */
2689 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2697 /* Get the low and high pc's represented by the scope DIE, and store
2698 them in *LOWPC and *HIGHPC. If the correct values can't be
2699 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2702 get_scope_pc_bounds (struct die_info *die,
2703 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2704 struct dwarf2_cu *cu)
2706 CORE_ADDR best_low = (CORE_ADDR) -1;
2707 CORE_ADDR best_high = (CORE_ADDR) 0;
2708 CORE_ADDR current_low, current_high;
2710 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2712 best_low = current_low;
2713 best_high = current_high;
2717 struct die_info *child = die->child;
2719 while (child && child->tag)
2721 switch (child->tag) {
2722 case DW_TAG_subprogram:
2723 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2725 best_low = min (best_low, current_low);
2726 best_high = max (best_high, current_high);
2729 case DW_TAG_namespace:
2730 /* FIXME: carlton/2004-01-16: Should we do this for
2731 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2732 that current GCC's always emit the DIEs corresponding
2733 to definitions of methods of classes as children of a
2734 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2735 the DIEs giving the declarations, which could be
2736 anywhere). But I don't see any reason why the
2737 standards says that they have to be there. */
2738 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2740 if (current_low != ((CORE_ADDR) -1))
2742 best_low = min (best_low, current_low);
2743 best_high = max (best_high, current_high);
2751 child = sibling_die (child);
2756 *highpc = best_high;
2759 /* Add an aggregate field to the field list. */
2762 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2763 struct dwarf2_cu *cu)
2765 struct objfile *objfile = cu->objfile;
2766 struct nextfield *new_field;
2767 struct attribute *attr;
2769 char *fieldname = "";
2771 /* Allocate a new field list entry and link it in. */
2772 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2773 make_cleanup (xfree, new_field);
2774 memset (new_field, 0, sizeof (struct nextfield));
2775 new_field->next = fip->fields;
2776 fip->fields = new_field;
2779 /* Handle accessibility and virtuality of field.
2780 The default accessibility for members is public, the default
2781 accessibility for inheritance is private. */
2782 if (die->tag != DW_TAG_inheritance)
2783 new_field->accessibility = DW_ACCESS_public;
2785 new_field->accessibility = DW_ACCESS_private;
2786 new_field->virtuality = DW_VIRTUALITY_none;
2788 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2790 new_field->accessibility = DW_UNSND (attr);
2791 if (new_field->accessibility != DW_ACCESS_public)
2792 fip->non_public_fields = 1;
2793 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2795 new_field->virtuality = DW_UNSND (attr);
2797 fp = &new_field->field;
2799 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2801 /* Data member other than a C++ static data member. */
2803 /* Get type of field. */
2804 fp->type = die_type (die, cu);
2806 FIELD_STATIC_KIND (*fp) = 0;
2808 /* Get bit size of field (zero if none). */
2809 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2812 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2816 FIELD_BITSIZE (*fp) = 0;
2819 /* Get bit offset of field. */
2820 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2823 FIELD_BITPOS (*fp) =
2824 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2827 FIELD_BITPOS (*fp) = 0;
2828 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2831 if (BITS_BIG_ENDIAN)
2833 /* For big endian bits, the DW_AT_bit_offset gives the
2834 additional bit offset from the MSB of the containing
2835 anonymous object to the MSB of the field. We don't
2836 have to do anything special since we don't need to
2837 know the size of the anonymous object. */
2838 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2842 /* For little endian bits, compute the bit offset to the
2843 MSB of the anonymous object, subtract off the number of
2844 bits from the MSB of the field to the MSB of the
2845 object, and then subtract off the number of bits of
2846 the field itself. The result is the bit offset of
2847 the LSB of the field. */
2849 int bit_offset = DW_UNSND (attr);
2851 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2854 /* The size of the anonymous object containing
2855 the bit field is explicit, so use the
2856 indicated size (in bytes). */
2857 anonymous_size = DW_UNSND (attr);
2861 /* The size of the anonymous object containing
2862 the bit field must be inferred from the type
2863 attribute of the data member containing the
2865 anonymous_size = TYPE_LENGTH (fp->type);
2867 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2868 - bit_offset - FIELD_BITSIZE (*fp);
2872 /* Get name of field. */
2873 attr = dwarf2_attr (die, DW_AT_name, cu);
2874 if (attr && DW_STRING (attr))
2875 fieldname = DW_STRING (attr);
2877 /* The name is already allocated along with this objfile, so we don't
2878 need to duplicate it for the type. */
2879 fp->name = fieldname;
2881 /* Change accessibility for artificial fields (e.g. virtual table
2882 pointer or virtual base class pointer) to private. */
2883 if (dwarf2_attr (die, DW_AT_artificial, cu))
2885 new_field->accessibility = DW_ACCESS_private;
2886 fip->non_public_fields = 1;
2889 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2891 /* C++ static member. */
2893 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2894 is a declaration, but all versions of G++ as of this writing
2895 (so through at least 3.2.1) incorrectly generate
2896 DW_TAG_variable tags. */
2900 /* Get name of field. */
2901 attr = dwarf2_attr (die, DW_AT_name, cu);
2902 if (attr && DW_STRING (attr))
2903 fieldname = DW_STRING (attr);
2907 /* Get physical name. */
2908 physname = dwarf2_linkage_name (die, cu);
2910 /* The name is already allocated along with this objfile, so we don't
2911 need to duplicate it for the type. */
2912 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
2913 FIELD_TYPE (*fp) = die_type (die, cu);
2914 FIELD_NAME (*fp) = fieldname;
2916 else if (die->tag == DW_TAG_inheritance)
2918 /* C++ base class field. */
2919 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2921 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2923 FIELD_BITSIZE (*fp) = 0;
2924 FIELD_STATIC_KIND (*fp) = 0;
2925 FIELD_TYPE (*fp) = die_type (die, cu);
2926 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2927 fip->nbaseclasses++;
2931 /* Create the vector of fields, and attach it to the type. */
2934 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2935 struct dwarf2_cu *cu)
2937 int nfields = fip->nfields;
2939 /* Record the field count, allocate space for the array of fields,
2940 and create blank accessibility bitfields if necessary. */
2941 TYPE_NFIELDS (type) = nfields;
2942 TYPE_FIELDS (type) = (struct field *)
2943 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2944 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2946 if (fip->non_public_fields)
2948 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2950 TYPE_FIELD_PRIVATE_BITS (type) =
2951 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2952 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2954 TYPE_FIELD_PROTECTED_BITS (type) =
2955 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2956 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2958 TYPE_FIELD_IGNORE_BITS (type) =
2959 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2960 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2963 /* If the type has baseclasses, allocate and clear a bit vector for
2964 TYPE_FIELD_VIRTUAL_BITS. */
2965 if (fip->nbaseclasses)
2967 int num_bytes = B_BYTES (fip->nbaseclasses);
2970 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2971 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2972 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2973 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2974 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2977 /* Copy the saved-up fields into the field vector. Start from the head
2978 of the list, adding to the tail of the field array, so that they end
2979 up in the same order in the array in which they were added to the list. */
2980 while (nfields-- > 0)
2982 TYPE_FIELD (type, nfields) = fip->fields->field;
2983 switch (fip->fields->accessibility)
2985 case DW_ACCESS_private:
2986 SET_TYPE_FIELD_PRIVATE (type, nfields);
2989 case DW_ACCESS_protected:
2990 SET_TYPE_FIELD_PROTECTED (type, nfields);
2993 case DW_ACCESS_public:
2997 /* Unknown accessibility. Complain and treat it as public. */
2999 complaint (&symfile_complaints, "unsupported accessibility %d",
3000 fip->fields->accessibility);
3004 if (nfields < fip->nbaseclasses)
3006 switch (fip->fields->virtuality)
3008 case DW_VIRTUALITY_virtual:
3009 case DW_VIRTUALITY_pure_virtual:
3010 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3014 fip->fields = fip->fields->next;
3018 /* Add a member function to the proper fieldlist. */
3021 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3022 struct type *type, struct dwarf2_cu *cu)
3024 struct objfile *objfile = cu->objfile;
3025 struct attribute *attr;
3026 struct fnfieldlist *flp;
3028 struct fn_field *fnp;
3031 struct nextfnfield *new_fnfield;
3033 /* Get name of member function. */
3034 attr = dwarf2_attr (die, DW_AT_name, cu);
3035 if (attr && DW_STRING (attr))
3036 fieldname = DW_STRING (attr);
3040 /* Get the mangled name. */
3041 physname = dwarf2_linkage_name (die, cu);
3043 /* Look up member function name in fieldlist. */
3044 for (i = 0; i < fip->nfnfields; i++)
3046 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3050 /* Create new list element if necessary. */
3051 if (i < fip->nfnfields)
3052 flp = &fip->fnfieldlists[i];
3055 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3057 fip->fnfieldlists = (struct fnfieldlist *)
3058 xrealloc (fip->fnfieldlists,
3059 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3060 * sizeof (struct fnfieldlist));
3061 if (fip->nfnfields == 0)
3062 make_cleanup (free_current_contents, &fip->fnfieldlists);
3064 flp = &fip->fnfieldlists[fip->nfnfields];
3065 flp->name = fieldname;
3071 /* Create a new member function field and chain it to the field list
3073 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3074 make_cleanup (xfree, new_fnfield);
3075 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3076 new_fnfield->next = flp->head;
3077 flp->head = new_fnfield;
3080 /* Fill in the member function field info. */
3081 fnp = &new_fnfield->fnfield;
3082 /* The name is already allocated along with this objfile, so we don't
3083 need to duplicate it for the type. */
3084 fnp->physname = physname ? physname : "";
3085 fnp->type = alloc_type (objfile);
3086 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
3088 int nparams = TYPE_NFIELDS (die->type);
3090 /* TYPE is the domain of this method, and DIE->TYPE is the type
3091 of the method itself (TYPE_CODE_METHOD). */
3092 smash_to_method_type (fnp->type, type,
3093 TYPE_TARGET_TYPE (die->type),
3094 TYPE_FIELDS (die->type),
3095 TYPE_NFIELDS (die->type),
3096 TYPE_VARARGS (die->type));
3098 /* Handle static member functions.
3099 Dwarf2 has no clean way to discern C++ static and non-static
3100 member functions. G++ helps GDB by marking the first
3101 parameter for non-static member functions (which is the
3102 this pointer) as artificial. We obtain this information
3103 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3104 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
3105 fnp->voffset = VOFFSET_STATIC;
3108 complaint (&symfile_complaints, "member function type missing for '%s'",
3111 /* Get fcontext from DW_AT_containing_type if present. */
3112 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3113 fnp->fcontext = die_containing_type (die, cu);
3115 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3116 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3118 /* Get accessibility. */
3119 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3122 switch (DW_UNSND (attr))
3124 case DW_ACCESS_private:
3125 fnp->is_private = 1;
3127 case DW_ACCESS_protected:
3128 fnp->is_protected = 1;
3133 /* Check for artificial methods. */
3134 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3135 if (attr && DW_UNSND (attr) != 0)
3136 fnp->is_artificial = 1;
3138 /* Get index in virtual function table if it is a virtual member function. */
3139 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3142 /* Support the .debug_loc offsets */
3143 if (attr_form_is_block (attr))
3145 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3147 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3149 dwarf2_complex_location_expr_complaint ();
3153 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3159 /* Create the vector of member function fields, and attach it to the type. */
3162 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
3163 struct dwarf2_cu *cu)
3165 struct fnfieldlist *flp;
3166 int total_length = 0;
3169 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3170 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3171 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
3173 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
3175 struct nextfnfield *nfp = flp->head;
3176 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
3179 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
3180 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
3181 fn_flp->fn_fields = (struct fn_field *)
3182 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
3183 for (k = flp->length; (k--, nfp); nfp = nfp->next)
3184 fn_flp->fn_fields[k] = nfp->fnfield;
3186 total_length += flp->length;
3189 TYPE_NFN_FIELDS (type) = fip->nfnfields;
3190 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3193 /* Called when we find the DIE that starts a structure or union scope
3194 (definition) to process all dies that define the members of the
3197 NOTE: we need to call struct_type regardless of whether or not the
3198 DIE has an at_name attribute, since it might be an anonymous
3199 structure or union. This gets the type entered into our set of
3202 However, if the structure is incomplete (an opaque struct/union)
3203 then suppress creating a symbol table entry for it since gdb only
3204 wants to find the one with the complete definition. Note that if
3205 it is complete, we just call new_symbol, which does it's own
3206 checking about whether the struct/union is anonymous or not (and
3207 suppresses creating a symbol table entry itself). */
3210 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3212 struct objfile *objfile = cu->objfile;
3214 struct attribute *attr;
3215 const char *previous_prefix = processing_current_prefix;
3216 struct cleanup *back_to = NULL;
3221 type = alloc_type (objfile);
3223 INIT_CPLUS_SPECIFIC (type);
3224 attr = dwarf2_attr (die, DW_AT_name, cu);
3225 if (attr && DW_STRING (attr))
3227 if (cu->language == language_cplus)
3229 char *new_prefix = determine_class_name (die, cu);
3230 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3231 strlen (new_prefix),
3232 &objfile->objfile_obstack);
3233 back_to = make_cleanup (xfree, new_prefix);
3234 processing_current_prefix = new_prefix;
3238 /* The name is already allocated along with this objfile, so
3239 we don't need to duplicate it for the type. */
3240 TYPE_TAG_NAME (type) = DW_STRING (attr);
3244 if (die->tag == DW_TAG_structure_type)
3246 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3248 else if (die->tag == DW_TAG_union_type)
3250 TYPE_CODE (type) = TYPE_CODE_UNION;
3254 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3256 TYPE_CODE (type) = TYPE_CODE_CLASS;
3259 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3262 TYPE_LENGTH (type) = DW_UNSND (attr);
3266 TYPE_LENGTH (type) = 0;
3269 if (die_is_declaration (die, cu))
3270 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3272 /* We need to add the type field to the die immediately so we don't
3273 infinitely recurse when dealing with pointers to the structure
3274 type within the structure itself. */
3277 if (die->child != NULL && ! die_is_declaration (die, cu))
3279 struct field_info fi;
3280 struct die_info *child_die;
3281 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3283 memset (&fi, 0, sizeof (struct field_info));
3285 child_die = die->child;
3287 while (child_die && child_die->tag)
3289 if (child_die->tag == DW_TAG_member
3290 || child_die->tag == DW_TAG_variable)
3292 /* NOTE: carlton/2002-11-05: A C++ static data member
3293 should be a DW_TAG_member that is a declaration, but
3294 all versions of G++ as of this writing (so through at
3295 least 3.2.1) incorrectly generate DW_TAG_variable
3296 tags for them instead. */
3297 dwarf2_add_field (&fi, child_die, cu);
3299 else if (child_die->tag == DW_TAG_subprogram)
3301 /* C++ member function. */
3302 read_type_die (child_die, cu);
3303 dwarf2_add_member_fn (&fi, child_die, type, cu);
3305 else if (child_die->tag == DW_TAG_inheritance)
3307 /* C++ base class field. */
3308 dwarf2_add_field (&fi, child_die, cu);
3310 child_die = sibling_die (child_die);
3313 /* Attach fields and member functions to the type. */
3315 dwarf2_attach_fields_to_type (&fi, type, cu);
3318 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3320 /* Get the type which refers to the base class (possibly this
3321 class itself) which contains the vtable pointer for the current
3322 class from the DW_AT_containing_type attribute. */
3324 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3326 struct type *t = die_containing_type (die, cu);
3328 TYPE_VPTR_BASETYPE (type) = t;
3331 static const char vptr_name[] =
3332 {'_', 'v', 'p', 't', 'r', '\0'};
3335 /* Our own class provides vtbl ptr. */
3336 for (i = TYPE_NFIELDS (t) - 1;
3337 i >= TYPE_N_BASECLASSES (t);
3340 char *fieldname = TYPE_FIELD_NAME (t, i);
3342 if ((strncmp (fieldname, vptr_name,
3343 strlen (vptr_name) - 1)
3345 && is_cplus_marker (fieldname[strlen (vptr_name)]))
3347 TYPE_VPTR_FIELDNO (type) = i;
3352 /* Complain if virtual function table field not found. */
3353 if (i < TYPE_N_BASECLASSES (t))
3354 complaint (&symfile_complaints,
3355 "virtual function table pointer not found when defining class '%s'",
3356 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3361 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3366 do_cleanups (back_to);
3369 processing_current_prefix = previous_prefix;
3370 if (back_to != NULL)
3371 do_cleanups (back_to);
3375 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3377 struct objfile *objfile = cu->objfile;
3378 const char *previous_prefix = processing_current_prefix;
3379 struct die_info *child_die = die->child;
3381 if (TYPE_TAG_NAME (die->type) != NULL)
3382 processing_current_prefix = TYPE_TAG_NAME (die->type);
3384 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3385 snapshots) has been known to create a die giving a declaration
3386 for a class that has, as a child, a die giving a definition for a
3387 nested class. So we have to process our children even if the
3388 current die is a declaration. Normally, of course, a declaration
3389 won't have any children at all. */
3391 while (child_die != NULL && child_die->tag)
3393 if (child_die->tag == DW_TAG_member
3394 || child_die->tag == DW_TAG_variable
3395 || child_die->tag == DW_TAG_inheritance)
3400 process_die (child_die, cu);
3402 child_die = sibling_die (child_die);
3405 if (die->child != NULL && ! die_is_declaration (die, cu))
3406 new_symbol (die, die->type, cu);
3408 processing_current_prefix = previous_prefix;
3411 /* Given a DW_AT_enumeration_type die, set its type. We do not
3412 complete the type's fields yet, or create any symbols. */
3415 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3417 struct objfile *objfile = cu->objfile;
3419 struct attribute *attr;
3424 type = alloc_type (objfile);
3426 TYPE_CODE (type) = TYPE_CODE_ENUM;
3427 attr = dwarf2_attr (die, DW_AT_name, cu);
3428 if (attr && DW_STRING (attr))
3430 char *name = DW_STRING (attr);
3432 if (processing_has_namespace_info)
3434 TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack,
3435 processing_current_prefix,
3436 processing_current_prefix[0] == '\0'
3442 /* The name is already allocated along with this objfile, so
3443 we don't need to duplicate it for the type. */
3444 TYPE_TAG_NAME (type) = name;
3448 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3451 TYPE_LENGTH (type) = DW_UNSND (attr);
3455 TYPE_LENGTH (type) = 0;
3461 /* Determine the name of the type represented by DIE, which should be
3462 a named C++ compound type. Return the name in question; the caller
3463 is responsible for xfree()'ing it. */
3466 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3468 struct cleanup *back_to = NULL;
3469 struct die_info *spec_die = die_specification (die, cu);
3470 char *new_prefix = NULL;
3472 /* If this is the definition of a class that is declared by another
3473 die, then processing_current_prefix may not be accurate; see
3474 read_func_scope for a similar example. */
3475 if (spec_die != NULL)
3477 char *specification_prefix = determine_prefix (spec_die, cu);
3478 processing_current_prefix = specification_prefix;
3479 back_to = make_cleanup (xfree, specification_prefix);
3482 /* If we don't have namespace debug info, guess the name by trying
3483 to demangle the names of members, just like we did in
3484 guess_structure_name. */
3485 if (!processing_has_namespace_info)
3487 struct die_info *child;
3489 for (child = die->child;
3490 child != NULL && child->tag != 0;
3491 child = sibling_die (child))
3493 if (child->tag == DW_TAG_subprogram)
3495 new_prefix = class_name_from_physname (dwarf2_linkage_name
3498 if (new_prefix != NULL)
3504 if (new_prefix == NULL)
3506 const char *name = dwarf2_name (die, cu);
3507 new_prefix = typename_concat (processing_current_prefix,
3508 name ? name : "<<anonymous>>");
3511 if (back_to != NULL)
3512 do_cleanups (back_to);
3517 /* Given a pointer to a die which begins an enumeration, process all
3518 the dies that define the members of the enumeration, and create the
3519 symbol for the enumeration type.
3521 NOTE: We reverse the order of the element list. */
3524 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3526 struct objfile *objfile = cu->objfile;
3527 struct die_info *child_die;
3528 struct field *fields;
3529 struct attribute *attr;
3532 int unsigned_enum = 1;
3536 if (die->child != NULL)
3538 child_die = die->child;
3539 while (child_die && child_die->tag)
3541 if (child_die->tag != DW_TAG_enumerator)
3543 process_die (child_die, cu);
3547 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3550 sym = new_symbol (child_die, die->type, cu);
3551 if (SYMBOL_VALUE (sym) < 0)
3554 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3556 fields = (struct field *)
3558 (num_fields + DW_FIELD_ALLOC_CHUNK)
3559 * sizeof (struct field));
3562 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3563 FIELD_TYPE (fields[num_fields]) = NULL;
3564 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3565 FIELD_BITSIZE (fields[num_fields]) = 0;
3566 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3572 child_die = sibling_die (child_die);
3577 TYPE_NFIELDS (die->type) = num_fields;
3578 TYPE_FIELDS (die->type) = (struct field *)
3579 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3580 memcpy (TYPE_FIELDS (die->type), fields,
3581 sizeof (struct field) * num_fields);
3585 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3588 new_symbol (die, die->type, cu);
3591 /* Extract all information from a DW_TAG_array_type DIE and put it in
3592 the DIE's type field. For now, this only handles one dimensional
3596 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3598 struct objfile *objfile = cu->objfile;
3599 struct die_info *child_die;
3600 struct type *type = NULL;
3601 struct type *element_type, *range_type, *index_type;
3602 struct type **range_types = NULL;
3603 struct attribute *attr;
3605 struct cleanup *back_to;
3607 /* Return if we've already decoded this type. */
3613 element_type = die_type (die, cu);
3615 /* Irix 6.2 native cc creates array types without children for
3616 arrays with unspecified length. */
3617 if (die->child == NULL)
3619 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3620 range_type = create_range_type (NULL, index_type, 0, -1);
3621 die->type = create_array_type (NULL, element_type, range_type);
3625 back_to = make_cleanup (null_cleanup, NULL);
3626 child_die = die->child;
3627 while (child_die && child_die->tag)
3629 if (child_die->tag == DW_TAG_subrange_type)
3631 read_subrange_type (child_die, cu);
3633 if (child_die->type != NULL)
3635 /* The range type was succesfully read. Save it for
3636 the array type creation. */
3637 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3639 range_types = (struct type **)
3640 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3641 * sizeof (struct type *));
3643 make_cleanup (free_current_contents, &range_types);
3645 range_types[ndim++] = child_die->type;
3648 child_die = sibling_die (child_die);
3651 /* Dwarf2 dimensions are output from left to right, create the
3652 necessary array types in backwards order. */
3653 type = element_type;
3655 type = create_array_type (NULL, type, range_types[ndim]);
3657 /* Understand Dwarf2 support for vector types (like they occur on
3658 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3659 array type. This is not part of the Dwarf2/3 standard yet, but a
3660 custom vendor extension. The main difference between a regular
3661 array and the vector variant is that vectors are passed by value
3663 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3665 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3667 do_cleanups (back_to);
3669 /* Install the type in the die. */
3673 /* First cut: install each common block member as a global variable. */
3676 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3678 struct die_info *child_die;
3679 struct attribute *attr;
3681 CORE_ADDR base = (CORE_ADDR) 0;
3683 attr = dwarf2_attr (die, DW_AT_location, cu);
3686 /* Support the .debug_loc offsets */
3687 if (attr_form_is_block (attr))
3689 base = decode_locdesc (DW_BLOCK (attr), cu);
3691 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3693 dwarf2_complex_location_expr_complaint ();
3697 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3698 "common block member");
3701 if (die->child != NULL)
3703 child_die = die->child;
3704 while (child_die && child_die->tag)
3706 sym = new_symbol (child_die, NULL, cu);
3707 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3710 SYMBOL_VALUE_ADDRESS (sym) =
3711 base + decode_locdesc (DW_BLOCK (attr), cu);
3712 add_symbol_to_list (sym, &global_symbols);
3714 child_die = sibling_die (child_die);
3719 /* Read a C++ namespace. */
3722 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3724 struct objfile *objfile = cu->objfile;
3725 const char *previous_prefix = processing_current_prefix;
3728 struct die_info *current_die;
3730 name = namespace_name (die, &is_anonymous, cu);
3732 /* Now build the name of the current namespace. */
3734 if (previous_prefix[0] == '\0')
3736 processing_current_prefix = name;
3740 /* We need temp_name around because processing_current_prefix
3741 is a const char *. */
3742 char *temp_name = alloca (strlen (previous_prefix)
3743 + 2 + strlen(name) + 1);
3744 strcpy (temp_name, previous_prefix);
3745 strcat (temp_name, "::");
3746 strcat (temp_name, name);
3748 processing_current_prefix = temp_name;
3751 /* Add a symbol associated to this if we haven't seen the namespace
3752 before. Also, add a using directive if it's an anonymous
3755 if (dwarf2_extension (die, cu) == NULL)
3759 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3760 this cast will hopefully become unnecessary. */
3761 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3762 (char *) processing_current_prefix,
3764 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3766 new_symbol (die, type, cu);
3770 cp_add_using_directive (processing_current_prefix,
3771 strlen (previous_prefix),
3772 strlen (processing_current_prefix));
3775 if (die->child != NULL)
3777 struct die_info *child_die = die->child;
3779 while (child_die && child_die->tag)
3781 process_die (child_die, cu);
3782 child_die = sibling_die (child_die);
3786 processing_current_prefix = previous_prefix;
3789 /* Return the name of the namespace represented by DIE. Set
3790 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3794 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3796 struct die_info *current_die;
3797 const char *name = NULL;
3799 /* Loop through the extensions until we find a name. */
3801 for (current_die = die;
3802 current_die != NULL;
3803 current_die = dwarf2_extension (die, cu))
3805 name = dwarf2_name (current_die, cu);
3810 /* Is it an anonymous namespace? */
3812 *is_anonymous = (name == NULL);
3814 name = "(anonymous namespace)";
3819 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3820 the user defined type vector. */
3823 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3825 struct comp_unit_head *cu_header = &cu->header;
3827 struct attribute *attr_byte_size;
3828 struct attribute *attr_address_class;
3829 int byte_size, addr_class;
3836 type = lookup_pointer_type (die_type (die, cu));
3838 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3840 byte_size = DW_UNSND (attr_byte_size);
3842 byte_size = cu_header->addr_size;
3844 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3845 if (attr_address_class)
3846 addr_class = DW_UNSND (attr_address_class);
3848 addr_class = DW_ADDR_none;
3850 /* If the pointer size or address class is different than the
3851 default, create a type variant marked as such and set the
3852 length accordingly. */
3853 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3855 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3859 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3860 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3861 type = make_type_with_address_space (type, type_flags);
3863 else if (TYPE_LENGTH (type) != byte_size)
3865 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3868 /* Should we also complain about unhandled address classes? */
3872 TYPE_LENGTH (type) = byte_size;
3876 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3877 the user defined type vector. */
3880 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3882 struct objfile *objfile = cu->objfile;
3884 struct type *to_type;
3885 struct type *domain;
3892 type = alloc_type (objfile);
3893 to_type = die_type (die, cu);
3894 domain = die_containing_type (die, cu);
3895 smash_to_member_type (type, domain, to_type);
3900 /* Extract all information from a DW_TAG_reference_type DIE and add to
3901 the user defined type vector. */
3904 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3906 struct comp_unit_head *cu_header = &cu->header;
3908 struct attribute *attr;
3915 type = lookup_reference_type (die_type (die, cu));
3916 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3919 TYPE_LENGTH (type) = DW_UNSND (attr);
3923 TYPE_LENGTH (type) = cu_header->addr_size;
3929 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3931 struct type *base_type;
3938 base_type = die_type (die, cu);
3939 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
3943 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3945 struct type *base_type;
3952 base_type = die_type (die, cu);
3953 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
3956 /* Extract all information from a DW_TAG_string_type DIE and add to
3957 the user defined type vector. It isn't really a user defined type,
3958 but it behaves like one, with other DIE's using an AT_user_def_type
3959 attribute to reference it. */
3962 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3964 struct objfile *objfile = cu->objfile;
3965 struct type *type, *range_type, *index_type, *char_type;
3966 struct attribute *attr;
3967 unsigned int length;
3974 attr = dwarf2_attr (die, DW_AT_string_length, cu);
3977 length = DW_UNSND (attr);
3981 /* check for the DW_AT_byte_size attribute */
3982 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3985 length = DW_UNSND (attr);
3992 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3993 range_type = create_range_type (NULL, index_type, 1, length);
3994 if (cu->language == language_fortran)
3996 /* Need to create a unique string type for bounds
3998 type = create_string_type (0, range_type);
4002 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
4003 type = create_string_type (char_type, range_type);
4008 /* Handle DIES due to C code like:
4012 int (*funcp)(int a, long l);
4016 ('funcp' generates a DW_TAG_subroutine_type DIE)
4020 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4022 struct type *type; /* Type that this function returns */
4023 struct type *ftype; /* Function that returns above type */
4024 struct attribute *attr;
4026 /* Decode the type that this subroutine returns */
4031 type = die_type (die, cu);
4032 ftype = lookup_function_type (type);
4034 /* All functions in C++ have prototypes. */
4035 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
4036 if ((attr && (DW_UNSND (attr) != 0))
4037 || cu->language == language_cplus)
4038 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
4040 if (die->child != NULL)
4042 struct die_info *child_die;
4046 /* Count the number of parameters.
4047 FIXME: GDB currently ignores vararg functions, but knows about
4048 vararg member functions. */
4049 child_die = die->child;
4050 while (child_die && child_die->tag)
4052 if (child_die->tag == DW_TAG_formal_parameter)
4054 else if (child_die->tag == DW_TAG_unspecified_parameters)
4055 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
4056 child_die = sibling_die (child_die);
4059 /* Allocate storage for parameters and fill them in. */
4060 TYPE_NFIELDS (ftype) = nparams;
4061 TYPE_FIELDS (ftype) = (struct field *)
4062 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
4064 child_die = die->child;
4065 while (child_die && child_die->tag)
4067 if (child_die->tag == DW_TAG_formal_parameter)
4069 /* Dwarf2 has no clean way to discern C++ static and non-static
4070 member functions. G++ helps GDB by marking the first
4071 parameter for non-static member functions (which is the
4072 this pointer) as artificial. We pass this information
4073 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4074 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
4076 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
4078 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
4079 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
4082 child_die = sibling_die (child_die);
4090 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
4092 struct objfile *objfile = cu->objfile;
4093 struct attribute *attr;
4098 attr = dwarf2_attr (die, DW_AT_name, cu);
4099 if (attr && DW_STRING (attr))
4101 name = DW_STRING (attr);
4103 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
4104 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
4108 /* Find a representation of a given base type and install
4109 it in the TYPE field of the die. */
4112 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
4114 struct objfile *objfile = cu->objfile;
4116 struct attribute *attr;
4117 int encoding = 0, size = 0;
4119 /* If we've already decoded this die, this is a no-op. */
4125 attr = dwarf2_attr (die, DW_AT_encoding, cu);
4128 encoding = DW_UNSND (attr);
4130 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4133 size = DW_UNSND (attr);
4135 attr = dwarf2_attr (die, DW_AT_name, cu);
4136 if (attr && DW_STRING (attr))
4138 enum type_code code = TYPE_CODE_INT;
4143 case DW_ATE_address:
4144 /* Turn DW_ATE_address into a void * pointer. */
4145 code = TYPE_CODE_PTR;
4146 type_flags |= TYPE_FLAG_UNSIGNED;
4148 case DW_ATE_boolean:
4149 code = TYPE_CODE_BOOL;
4150 type_flags |= TYPE_FLAG_UNSIGNED;
4152 case DW_ATE_complex_float:
4153 code = TYPE_CODE_COMPLEX;
4156 code = TYPE_CODE_FLT;
4159 case DW_ATE_signed_char:
4161 case DW_ATE_unsigned:
4162 case DW_ATE_unsigned_char:
4163 type_flags |= TYPE_FLAG_UNSIGNED;
4166 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
4167 dwarf_type_encoding_name (encoding));
4170 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4171 if (encoding == DW_ATE_address)
4172 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4174 else if (encoding == DW_ATE_complex_float)
4177 TYPE_TARGET_TYPE (type)
4178 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4179 else if (size == 16)
4180 TYPE_TARGET_TYPE (type)
4181 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4183 TYPE_TARGET_TYPE (type)
4184 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4189 type = dwarf_base_type (encoding, size, cu);
4194 /* Read the given DW_AT_subrange DIE. */
4197 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4199 struct type *base_type;
4200 struct type *range_type;
4201 struct attribute *attr;
4205 /* If we have already decoded this die, then nothing more to do. */
4209 base_type = die_type (die, cu);
4210 if (base_type == NULL)
4212 complaint (&symfile_complaints,
4213 "DW_AT_type missing from DW_TAG_subrange_type");
4217 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4218 base_type = alloc_type (NULL);
4220 if (cu->language == language_fortran)
4222 /* FORTRAN implies a lower bound of 1, if not given. */
4226 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4228 low = dwarf2_get_attr_constant_value (attr, 0);
4230 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4233 if (attr->form == DW_FORM_block1)
4235 /* GCC encodes arrays with unspecified or dynamic length
4236 with a DW_FORM_block1 attribute.
4237 FIXME: GDB does not yet know how to handle dynamic
4238 arrays properly, treat them as arrays with unspecified
4241 FIXME: jimb/2003-09-22: GDB does not really know
4242 how to handle arrays of unspecified length
4243 either; we just represent them as zero-length
4244 arrays. Choose an appropriate upper bound given
4245 the lower bound we've computed above. */
4249 high = dwarf2_get_attr_constant_value (attr, 1);
4252 range_type = create_range_type (NULL, base_type, low, high);
4254 attr = dwarf2_attr (die, DW_AT_name, cu);
4255 if (attr && DW_STRING (attr))
4256 TYPE_NAME (range_type) = DW_STRING (attr);
4258 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4260 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4262 die->type = range_type;
4266 /* Read a whole compilation unit into a linked list of dies. */
4268 static struct die_info *
4269 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4271 /* Reset die reference table; we are
4272 building new ones now. */
4273 dwarf2_empty_hash_tables ();
4275 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4278 /* Read a single die and all its descendents. Set the die's sibling
4279 field to NULL; set other fields in the die correctly, and set all
4280 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4281 location of the info_ptr after reading all of those dies. PARENT
4282 is the parent of the die in question. */
4284 static struct die_info *
4285 read_die_and_children (char *info_ptr, bfd *abfd,
4286 struct dwarf2_cu *cu,
4287 char **new_info_ptr,
4288 struct die_info *parent)
4290 struct die_info *die;
4294 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4295 store_in_ref_table (die->offset, die);
4299 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4305 *new_info_ptr = cur_ptr;
4308 die->sibling = NULL;
4309 die->parent = parent;
4313 /* Read a die, all of its descendents, and all of its siblings; set
4314 all of the fields of all of the dies correctly. Arguments are as
4315 in read_die_and_children. */
4317 static struct die_info *
4318 read_die_and_siblings (char *info_ptr, bfd *abfd,
4319 struct dwarf2_cu *cu,
4320 char **new_info_ptr,
4321 struct die_info *parent)
4323 struct die_info *first_die, *last_sibling;
4327 first_die = last_sibling = NULL;
4331 struct die_info *die
4332 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4340 last_sibling->sibling = die;
4345 *new_info_ptr = cur_ptr;
4355 /* Free a linked list of dies. */
4358 free_die_list (struct die_info *dies)
4360 struct die_info *die, *next;
4365 if (die->child != NULL)
4366 free_die_list (die->child);
4367 next = die->sibling;
4375 do_free_die_list_cleanup (void *dies)
4377 free_die_list (dies);
4380 static struct cleanup *
4381 make_cleanup_free_die_list (struct die_info *dies)
4383 return make_cleanup (do_free_die_list_cleanup, dies);
4387 /* Read the contents of the section at OFFSET and of size SIZE from the
4388 object file specified by OBJFILE into the objfile_obstack and return it. */
4391 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4393 bfd *abfd = objfile->obfd;
4395 bfd_size_type size = bfd_get_section_size_before_reloc (sectp);
4400 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4402 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4406 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4407 || bfd_bread (buf, size, abfd) != size)
4408 error ("Dwarf Error: Can't read DWARF data from '%s'",
4409 bfd_get_filename (abfd));
4414 /* In DWARF version 2, the description of the debugging information is
4415 stored in a separate .debug_abbrev section. Before we read any
4416 dies from a section we read in all abbreviations and install them
4417 in a hash table. This function also sets flags in CU describing
4418 the data found in the abbrev table. */
4421 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4423 struct comp_unit_head *cu_header = &cu->header;
4425 struct abbrev_info *cur_abbrev;
4426 unsigned int abbrev_number, bytes_read, abbrev_name;
4427 unsigned int abbrev_form, hash_number;
4428 struct attr_abbrev *cur_attrs;
4429 unsigned int allocated_attrs;
4431 /* Initialize dwarf2 abbrevs */
4432 obstack_init (&cu->abbrev_obstack);
4433 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
4435 * sizeof (struct abbrev_info *)));
4436 memset (cu->dwarf2_abbrevs, 0,
4437 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
4439 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
4440 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4441 abbrev_ptr += bytes_read;
4443 allocated_attrs = ATTR_ALLOC_CHUNK;
4444 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
4446 /* loop until we reach an abbrev number of 0 */
4447 while (abbrev_number)
4449 cur_abbrev = dwarf_alloc_abbrev (cu);
4451 /* read in abbrev header */
4452 cur_abbrev->number = abbrev_number;
4453 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4454 abbrev_ptr += bytes_read;
4455 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4458 if (cur_abbrev->tag == DW_TAG_namespace)
4459 cu->has_namespace_info = 1;
4461 /* now read in declarations */
4462 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4463 abbrev_ptr += bytes_read;
4464 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4465 abbrev_ptr += bytes_read;
4468 if (cur_abbrev->num_attrs == allocated_attrs)
4470 allocated_attrs += ATTR_ALLOC_CHUNK;
4472 = xrealloc (cur_attrs, (allocated_attrs
4473 * sizeof (struct attr_abbrev)));
4475 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
4476 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4477 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4478 abbrev_ptr += bytes_read;
4479 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4480 abbrev_ptr += bytes_read;
4483 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
4484 (cur_abbrev->num_attrs
4485 * sizeof (struct attr_abbrev)));
4486 memcpy (cur_abbrev->attrs, cur_attrs,
4487 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
4489 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4490 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
4491 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
4493 /* Get next abbreviation.
4494 Under Irix6 the abbreviations for a compilation unit are not
4495 always properly terminated with an abbrev number of 0.
4496 Exit loop if we encounter an abbreviation which we have
4497 already read (which means we are about to read the abbreviations
4498 for the next compile unit) or if the end of the abbreviation
4499 table is reached. */
4500 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
4501 >= dwarf2_per_objfile->abbrev_size)
4503 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4504 abbrev_ptr += bytes_read;
4505 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4512 /* Release the memory used by the abbrev table for a compilation unit. */
4515 dwarf2_free_abbrev_table (void *ptr_to_cu)
4517 struct dwarf2_cu *cu = ptr_to_cu;
4519 obstack_free (&cu->abbrev_obstack, NULL);
4520 cu->dwarf2_abbrevs = NULL;
4523 /* Lookup an abbrev_info structure in the abbrev hash table. */
4525 static struct abbrev_info *
4526 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4528 unsigned int hash_number;
4529 struct abbrev_info *abbrev;
4531 hash_number = number % ABBREV_HASH_SIZE;
4532 abbrev = cu->dwarf2_abbrevs[hash_number];
4536 if (abbrev->number == number)
4539 abbrev = abbrev->next;
4544 /* Returns nonzero if TAG represents a type that we might generate a partial
4548 is_type_tag_for_partial (int tag)
4553 /* Some types that would be reasonable to generate partial symbols for,
4554 that we don't at present. */
4555 case DW_TAG_array_type:
4556 case DW_TAG_file_type:
4557 case DW_TAG_ptr_to_member_type:
4558 case DW_TAG_set_type:
4559 case DW_TAG_string_type:
4560 case DW_TAG_subroutine_type:
4562 case DW_TAG_base_type:
4563 case DW_TAG_class_type:
4564 case DW_TAG_enumeration_type:
4565 case DW_TAG_structure_type:
4566 case DW_TAG_subrange_type:
4567 case DW_TAG_typedef:
4568 case DW_TAG_union_type:
4575 /* Load all DIEs that are interesting for partial symbols into memory. */
4577 static struct partial_die_info *
4578 load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab,
4579 struct dwarf2_cu *cu)
4581 struct partial_die_info *part_die;
4582 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
4583 struct abbrev_info *abbrev;
4584 unsigned int bytes_read;
4586 int nesting_level = 1;
4592 = htab_create_alloc_ex (cu->header.length / 12,
4596 &cu->comp_unit_obstack,
4597 hashtab_obstack_allocate,
4598 dummy_obstack_deallocate);
4600 part_die = obstack_alloc (&cu->comp_unit_obstack,
4601 sizeof (struct partial_die_info));
4605 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4607 /* A NULL abbrev means the end of a series of children. */
4610 if (--nesting_level == 0)
4612 /* PART_DIE was probably the last thing allocated on the
4613 comp_unit_obstack, so we could call obstack_free
4614 here. We don't do that because the waste is small,
4615 and will be cleaned up when we're done with this
4616 compilation unit. This way, we're also more robust
4617 against other users of the comp_unit_obstack. */
4620 info_ptr += bytes_read;
4621 last_die = parent_die;
4622 parent_die = parent_die->die_parent;
4626 /* Check whether this DIE is interesting enough to save. */
4627 if (!is_type_tag_for_partial (abbrev->tag)
4628 && abbrev->tag != DW_TAG_enumerator
4629 && abbrev->tag != DW_TAG_subprogram
4630 && abbrev->tag != DW_TAG_variable
4631 && abbrev->tag != DW_TAG_namespace)
4633 /* Otherwise we skip to the next sibling, if any. */
4634 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
4638 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
4639 abfd, info_ptr, cu);
4641 /* This two-pass algorithm for processing partial symbols has a
4642 high cost in cache pressure. Thus, handle some simple cases
4643 here which cover the majority of C partial symbols. DIEs
4644 which neither have specification tags in them, nor could have
4645 specification tags elsewhere pointing at them, can simply be
4646 processed and discarded.
4648 This segment is also optional; scan_partial_symbols and
4649 add_partial_symbol will handle these DIEs if we chain
4650 them in normally. When compilers which do not emit large
4651 quantities of duplicate debug information are more common,
4652 this code can probably be removed. */
4654 /* Any complete simple types at the top level (pretty much all
4655 of them, for a language without namespaces), can be processed
4657 if (parent_die == NULL
4658 && part_die->has_specification == 0
4659 && part_die->is_declaration == 0
4660 && (part_die->tag == DW_TAG_typedef
4661 || part_die->tag == DW_TAG_base_type
4662 || part_die->tag == DW_TAG_subrange_type))
4664 if (building_psymtab && part_die->name != NULL)
4665 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4666 VAR_DOMAIN, LOC_TYPEDEF,
4667 &cu->objfile->static_psymbols,
4668 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4669 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4673 /* If we're at the second level, and we're an enumerator, and
4674 our parent has no specification (meaning possibly lives in a
4675 namespace elsewhere), then we can add the partial symbol now
4676 instead of queueing it. */
4677 if (part_die->tag == DW_TAG_enumerator
4678 && parent_die != NULL
4679 && parent_die->die_parent == NULL
4680 && parent_die->tag == DW_TAG_enumeration_type
4681 && parent_die->has_specification == 0)
4683 if (part_die->name == NULL)
4684 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
4685 else if (building_psymtab)
4686 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4687 VAR_DOMAIN, LOC_CONST,
4688 cu->language == language_cplus
4689 ? &cu->objfile->global_psymbols
4690 : &cu->objfile->static_psymbols,
4691 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4693 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4697 /* We'll save this DIE so link it in. */
4698 part_die->die_parent = parent_die;
4699 part_die->die_sibling = NULL;
4700 part_die->die_child = NULL;
4702 if (last_die && last_die == parent_die)
4703 last_die->die_child = part_die;
4705 last_die->die_sibling = part_die;
4707 last_die = part_die;
4709 if (first_die == NULL)
4710 first_die = part_die;
4712 /* Maybe add the DIE to the hash table. Not all DIEs that we
4713 find interesting need to be in the hash table, because we
4714 also have the parent/sibling/child chains; only those that we
4715 might refer to by offset later during partial symbol reading.
4717 For now this means things that might have be the target of a
4718 DW_AT_specification, DW_AT_abstract_origin, or
4719 DW_AT_extension. DW_AT_extension will refer only to
4720 namespaces; DW_AT_abstract_origin refers to functions (and
4721 many things under the function DIE, but we do not recurse
4722 into function DIEs during partial symbol reading) and
4723 possibly variables as well; DW_AT_specification refers to
4724 declarations. Declarations ought to have the DW_AT_declaration
4725 flag. It happens that GCC forgets to put it in sometimes, but
4726 only for functions, not for types.
4728 Adding more things than necessary to the hash table is harmless
4729 except for the performance cost. Adding too few will result in
4730 internal errors in find_partial_die. */
4732 if (abbrev->tag == DW_TAG_subprogram
4733 || abbrev->tag == DW_TAG_variable
4734 || abbrev->tag == DW_TAG_namespace
4735 || part_die->is_declaration)
4739 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
4740 part_die->offset, INSERT);
4744 part_die = obstack_alloc (&cu->comp_unit_obstack,
4745 sizeof (struct partial_die_info));
4747 /* For some DIEs we want to follow their children (if any). For C
4748 we have no reason to follow the children of structures; for other
4749 languages we have to, both so that we can get at method physnames
4750 to infer fully qualified class names, and for DW_AT_specification. */
4751 if (last_die->has_children
4752 && (last_die->tag == DW_TAG_namespace
4753 || last_die->tag == DW_TAG_enumeration_type
4754 || (cu->language != language_c
4755 && (last_die->tag == DW_TAG_class_type
4756 || last_die->tag == DW_TAG_structure_type
4757 || last_die->tag == DW_TAG_union_type))))
4760 parent_die = last_die;
4764 /* Otherwise we skip to the next sibling, if any. */
4765 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
4767 /* Back to the top, do it again. */
4771 /* Read a minimal amount of information into the minimal die structure. */
4774 read_partial_die (struct partial_die_info *part_die,
4775 struct abbrev_info *abbrev,
4776 unsigned int abbrev_len, bfd *abfd,
4777 char *info_ptr, struct dwarf2_cu *cu)
4779 unsigned int bytes_read, i;
4780 struct attribute attr;
4781 int has_low_pc_attr = 0;
4782 int has_high_pc_attr = 0;
4784 memset (part_die, 0, sizeof (struct partial_die_info));
4786 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
4788 info_ptr += abbrev_len;
4793 part_die->tag = abbrev->tag;
4794 part_die->has_children = abbrev->has_children;
4796 for (i = 0; i < abbrev->num_attrs; ++i)
4798 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4800 /* Store the data if it is of an attribute we want to keep in a
4801 partial symbol table. */
4806 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4807 if (part_die->name == NULL)
4808 part_die->name = DW_STRING (&attr);
4810 case DW_AT_MIPS_linkage_name:
4811 part_die->name = DW_STRING (&attr);
4814 has_low_pc_attr = 1;
4815 part_die->lowpc = DW_ADDR (&attr);
4818 has_high_pc_attr = 1;
4819 part_die->highpc = DW_ADDR (&attr);
4821 case DW_AT_location:
4822 /* Support the .debug_loc offsets */
4823 if (attr_form_is_block (&attr))
4825 part_die->locdesc = DW_BLOCK (&attr);
4827 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4829 dwarf2_complex_location_expr_complaint ();
4833 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4834 "partial symbol information");
4837 case DW_AT_language:
4838 part_die->language = DW_UNSND (&attr);
4840 case DW_AT_external:
4841 part_die->is_external = DW_UNSND (&attr);
4843 case DW_AT_declaration:
4844 part_die->is_declaration = DW_UNSND (&attr);
4847 part_die->has_type = 1;
4849 case DW_AT_abstract_origin:
4850 case DW_AT_specification:
4851 case DW_AT_extension:
4852 part_die->has_specification = 1;
4853 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
4856 /* Ignore absolute siblings, they might point outside of
4857 the current compile unit. */
4858 if (attr.form == DW_FORM_ref_addr)
4859 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4861 part_die->sibling = dwarf2_per_objfile->info_buffer
4862 + dwarf2_get_ref_die_offset (&attr, cu);
4869 /* When using the GNU linker, .gnu.linkonce. sections are used to
4870 eliminate duplicate copies of functions and vtables and such.
4871 The linker will arbitrarily choose one and discard the others.
4872 The AT_*_pc values for such functions refer to local labels in
4873 these sections. If the section from that file was discarded, the
4874 labels are not in the output, so the relocs get a value of 0.
4875 If this is a discarded function, mark the pc bounds as invalid,
4876 so that GDB will ignore it. */
4877 if (has_low_pc_attr && has_high_pc_attr
4878 && part_die->lowpc < part_die->highpc
4879 && (part_die->lowpc != 0
4880 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4881 part_die->has_pc_info = 1;
4885 /* Find a cached partial DIE at OFFSET in CU. */
4887 static struct partial_die_info *
4888 find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu)
4890 struct partial_die_info *lookup_die = NULL;
4891 struct partial_die_info part_die;
4893 part_die.offset = offset;
4894 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
4896 if (lookup_die == NULL)
4897 internal_error (__FILE__, __LINE__,
4898 "could not find partial DIE in cache\n");
4903 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
4905 static struct partial_die_info *
4906 find_partial_die (unsigned long offset, struct dwarf2_cu *cu,
4907 struct dwarf2_cu **target_cu)
4909 struct dwarf2_per_cu_data *per_cu;
4911 if (offset >= cu->header.offset
4912 && offset < cu->header.offset + cu->header.length)
4915 return find_partial_die_in_comp_unit (offset, cu);
4918 internal_error (__FILE__, __LINE__,
4919 "unsupported inter-compilation-unit reference");
4922 /* Adjust PART_DIE before generating a symbol for it. This function
4923 may set the is_external flag or change the DIE's name. */
4926 fixup_partial_die (struct partial_die_info *part_die,
4927 struct dwarf2_cu *cu)
4929 /* If we found a reference attribute and the DIE has no name, try
4930 to find a name in the referred to DIE. */
4932 if (part_die->name == NULL && part_die->has_specification)
4934 struct partial_die_info *spec_die;
4935 struct dwarf2_cu *spec_cu;
4937 spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu);
4939 fixup_partial_die (spec_die, spec_cu);
4943 part_die->name = spec_die->name;
4945 /* Copy DW_AT_external attribute if it is set. */
4946 if (spec_die->is_external)
4947 part_die->is_external = spec_die->is_external;
4951 /* Set default names for some unnamed DIEs. */
4952 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
4953 || part_die->tag == DW_TAG_class_type))
4954 part_die->name = "(anonymous class)";
4956 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
4957 part_die->name = "(anonymous namespace)";
4959 if (part_die->tag == DW_TAG_structure_type
4960 || part_die->tag == DW_TAG_class_type
4961 || part_die->tag == DW_TAG_union_type)
4962 guess_structure_name (part_die, cu);
4965 /* Read the die from the .debug_info section buffer. Set DIEP to
4966 point to a newly allocated die with its information, except for its
4967 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4968 whether the die has children or not. */
4971 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4972 struct dwarf2_cu *cu, int *has_children)
4974 unsigned int abbrev_number, bytes_read, i, offset;
4975 struct abbrev_info *abbrev;
4976 struct die_info *die;
4978 offset = info_ptr - dwarf2_per_objfile->info_buffer;
4979 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4980 info_ptr += bytes_read;
4983 die = dwarf_alloc_die ();
4985 die->abbrev = abbrev_number;
4992 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4995 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4997 bfd_get_filename (abfd));
4999 die = dwarf_alloc_die ();
5000 die->offset = offset;
5001 die->tag = abbrev->tag;
5002 die->abbrev = abbrev_number;
5005 die->num_attrs = abbrev->num_attrs;
5006 die->attrs = (struct attribute *)
5007 xmalloc (die->num_attrs * sizeof (struct attribute));
5009 for (i = 0; i < abbrev->num_attrs; ++i)
5011 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
5012 abfd, info_ptr, cu);
5016 *has_children = abbrev->has_children;
5020 /* Read an attribute value described by an attribute form. */
5023 read_attribute_value (struct attribute *attr, unsigned form,
5024 bfd *abfd, char *info_ptr,
5025 struct dwarf2_cu *cu)
5027 struct comp_unit_head *cu_header = &cu->header;
5028 unsigned int bytes_read;
5029 struct dwarf_block *blk;
5035 case DW_FORM_ref_addr:
5036 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
5037 info_ptr += bytes_read;
5039 case DW_FORM_block2:
5040 blk = dwarf_alloc_block ();
5041 blk->size = read_2_bytes (abfd, info_ptr);
5043 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5044 info_ptr += blk->size;
5045 DW_BLOCK (attr) = blk;
5047 case DW_FORM_block4:
5048 blk = dwarf_alloc_block ();
5049 blk->size = read_4_bytes (abfd, info_ptr);
5051 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5052 info_ptr += blk->size;
5053 DW_BLOCK (attr) = blk;
5056 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5060 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5064 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5067 case DW_FORM_string:
5068 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
5069 info_ptr += bytes_read;
5072 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
5074 info_ptr += bytes_read;
5077 blk = dwarf_alloc_block ();
5078 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5079 info_ptr += bytes_read;
5080 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5081 info_ptr += blk->size;
5082 DW_BLOCK (attr) = blk;
5084 case DW_FORM_block1:
5085 blk = dwarf_alloc_block ();
5086 blk->size = read_1_byte (abfd, info_ptr);
5088 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5089 info_ptr += blk->size;
5090 DW_BLOCK (attr) = blk;
5093 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5097 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5101 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
5102 info_ptr += bytes_read;
5105 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5106 info_ptr += bytes_read;
5109 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5113 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5117 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5121 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5124 case DW_FORM_ref_udata:
5125 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5126 info_ptr += bytes_read;
5128 case DW_FORM_indirect:
5129 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5130 info_ptr += bytes_read;
5131 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
5134 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5135 dwarf_form_name (form),
5136 bfd_get_filename (abfd));
5141 /* Read an attribute described by an abbreviated attribute. */
5144 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
5145 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
5147 attr->name = abbrev->name;
5148 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
5151 /* read dwarf information from a buffer */
5154 read_1_byte (bfd *abfd, char *buf)
5156 return bfd_get_8 (abfd, (bfd_byte *) buf);
5160 read_1_signed_byte (bfd *abfd, char *buf)
5162 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
5166 read_2_bytes (bfd *abfd, char *buf)
5168 return bfd_get_16 (abfd, (bfd_byte *) buf);
5172 read_2_signed_bytes (bfd *abfd, char *buf)
5174 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5178 read_4_bytes (bfd *abfd, char *buf)
5180 return bfd_get_32 (abfd, (bfd_byte *) buf);
5184 read_4_signed_bytes (bfd *abfd, char *buf)
5186 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5189 static unsigned long
5190 read_8_bytes (bfd *abfd, char *buf)
5192 return bfd_get_64 (abfd, (bfd_byte *) buf);
5196 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
5198 struct comp_unit_head *cu_header = &cu->header;
5199 CORE_ADDR retval = 0;
5201 if (cu_header->signed_addr_p)
5203 switch (cu_header->addr_size)
5206 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5209 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5212 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
5215 internal_error (__FILE__, __LINE__,
5216 "read_address: bad switch, signed [in module %s]",
5217 bfd_get_filename (abfd));
5222 switch (cu_header->addr_size)
5225 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
5228 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5231 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5234 internal_error (__FILE__, __LINE__,
5235 "read_address: bad switch, unsigned [in module %s]",
5236 bfd_get_filename (abfd));
5240 *bytes_read = cu_header->addr_size;
5244 /* Read the initial length from a section. The (draft) DWARF 3
5245 specification allows the initial length to take up either 4 bytes
5246 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5247 bytes describe the length and all offsets will be 8 bytes in length
5250 An older, non-standard 64-bit format is also handled by this
5251 function. The older format in question stores the initial length
5252 as an 8-byte quantity without an escape value. Lengths greater
5253 than 2^32 aren't very common which means that the initial 4 bytes
5254 is almost always zero. Since a length value of zero doesn't make
5255 sense for the 32-bit format, this initial zero can be considered to
5256 be an escape value which indicates the presence of the older 64-bit
5257 format. As written, the code can't detect (old format) lengths
5258 greater than 4GB. If it becomes necessary to handle lengths somewhat
5259 larger than 4GB, we could allow other small values (such as the
5260 non-sensical values of 1, 2, and 3) to also be used as escape values
5261 indicating the presence of the old format.
5263 The value returned via bytes_read should be used to increment
5264 the relevant pointer after calling read_initial_length().
5266 As a side effect, this function sets the fields initial_length_size
5267 and offset_size in cu_header to the values appropriate for the
5268 length field. (The format of the initial length field determines
5269 the width of file offsets to be fetched later with fetch_offset().)
5271 [ Note: read_initial_length() and read_offset() are based on the
5272 document entitled "DWARF Debugging Information Format", revision
5273 3, draft 8, dated November 19, 2001. This document was obtained
5276 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5278 This document is only a draft and is subject to change. (So beware.)
5280 Details regarding the older, non-standard 64-bit format were
5281 determined empirically by examining 64-bit ELF files produced
5282 by the SGI toolchain on an IRIX 6.5 machine.
5284 - Kevin, July 16, 2002
5288 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
5293 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5295 if (retval == 0xffffffff)
5297 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
5299 if (cu_header != NULL)
5301 cu_header->initial_length_size = 12;
5302 cu_header->offset_size = 8;
5305 else if (retval == 0)
5307 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5309 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5311 if (cu_header != NULL)
5313 cu_header->initial_length_size = 8;
5314 cu_header->offset_size = 8;
5320 if (cu_header != NULL)
5322 cu_header->initial_length_size = 4;
5323 cu_header->offset_size = 4;
5330 /* Read an offset from the data stream. The size of the offset is
5331 given by cu_header->offset_size. */
5334 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
5339 switch (cu_header->offset_size)
5342 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5346 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5350 internal_error (__FILE__, __LINE__,
5351 "read_offset: bad switch [in module %s]",
5352 bfd_get_filename (abfd));
5359 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
5361 /* If the size of a host char is 8 bits, we can return a pointer
5362 to the buffer, otherwise we have to copy the data to a buffer
5363 allocated on the temporary obstack. */
5364 gdb_assert (HOST_CHAR_BIT == 8);
5369 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5371 /* If the size of a host char is 8 bits, we can return a pointer
5372 to the string, otherwise we have to copy the string to a buffer
5373 allocated on the temporary obstack. */
5374 gdb_assert (HOST_CHAR_BIT == 8);
5377 *bytes_read_ptr = 1;
5380 *bytes_read_ptr = strlen (buf) + 1;
5385 read_indirect_string (bfd *abfd, char *buf,
5386 const struct comp_unit_head *cu_header,
5387 unsigned int *bytes_read_ptr)
5389 LONGEST str_offset = read_offset (abfd, buf, cu_header,
5390 (int *) bytes_read_ptr);
5392 if (dwarf2_per_objfile->str_buffer == NULL)
5394 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5395 bfd_get_filename (abfd));
5398 if (str_offset >= dwarf2_per_objfile->str_size)
5400 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5401 bfd_get_filename (abfd));
5404 gdb_assert (HOST_CHAR_BIT == 8);
5405 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
5407 return dwarf2_per_objfile->str_buffer + str_offset;
5410 static unsigned long
5411 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5413 unsigned long result;
5414 unsigned int num_read;
5424 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5427 result |= ((unsigned long)(byte & 127) << shift);
5428 if ((byte & 128) == 0)
5434 *bytes_read_ptr = num_read;
5439 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5442 int i, shift, size, num_read;
5452 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5455 result |= ((long)(byte & 127) << shift);
5457 if ((byte & 128) == 0)
5462 if ((shift < size) && (byte & 0x40))
5464 result |= -(1 << shift);
5466 *bytes_read_ptr = num_read;
5470 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5473 skip_leb128 (bfd *abfd, char *buf)
5479 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5481 if ((byte & 128) == 0)
5487 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5493 cu->language = language_c;
5495 case DW_LANG_C_plus_plus:
5496 cu->language = language_cplus;
5498 case DW_LANG_Fortran77:
5499 case DW_LANG_Fortran90:
5500 case DW_LANG_Fortran95:
5501 cu->language = language_fortran;
5503 case DW_LANG_Mips_Assembler:
5504 cu->language = language_asm;
5507 cu->language = language_java;
5511 case DW_LANG_Cobol74:
5512 case DW_LANG_Cobol85:
5513 case DW_LANG_Pascal83:
5514 case DW_LANG_Modula2:
5516 cu->language = language_minimal;
5519 cu->language_defn = language_def (cu->language);
5522 /* Return the named attribute or NULL if not there. */
5524 static struct attribute *
5525 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5528 struct attribute *spec = NULL;
5530 for (i = 0; i < die->num_attrs; ++i)
5532 if (die->attrs[i].name == name)
5534 return &die->attrs[i];
5536 if (die->attrs[i].name == DW_AT_specification
5537 || die->attrs[i].name == DW_AT_abstract_origin)
5538 spec = &die->attrs[i];
5542 struct die_info *ref_die =
5543 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5546 return dwarf2_attr (ref_die, name, cu);
5553 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5555 return (dwarf2_attr (die, DW_AT_declaration, cu)
5556 && ! dwarf2_attr (die, DW_AT_specification, cu));
5559 /* Return the die giving the specification for DIE, if there is
5562 static struct die_info *
5563 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5565 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5567 if (spec_attr == NULL)
5570 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5573 /* Free the line_header structure *LH, and any arrays and strings it
5576 free_line_header (struct line_header *lh)
5578 if (lh->standard_opcode_lengths)
5579 xfree (lh->standard_opcode_lengths);
5581 /* Remember that all the lh->file_names[i].name pointers are
5582 pointers into debug_line_buffer, and don't need to be freed. */
5584 xfree (lh->file_names);
5586 /* Similarly for the include directory names. */
5587 if (lh->include_dirs)
5588 xfree (lh->include_dirs);
5594 /* Add an entry to LH's include directory table. */
5596 add_include_dir (struct line_header *lh, char *include_dir)
5598 /* Grow the array if necessary. */
5599 if (lh->include_dirs_size == 0)
5601 lh->include_dirs_size = 1; /* for testing */
5602 lh->include_dirs = xmalloc (lh->include_dirs_size
5603 * sizeof (*lh->include_dirs));
5605 else if (lh->num_include_dirs >= lh->include_dirs_size)
5607 lh->include_dirs_size *= 2;
5608 lh->include_dirs = xrealloc (lh->include_dirs,
5609 (lh->include_dirs_size
5610 * sizeof (*lh->include_dirs)));
5613 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5617 /* Add an entry to LH's file name table. */
5619 add_file_name (struct line_header *lh,
5621 unsigned int dir_index,
5622 unsigned int mod_time,
5623 unsigned int length)
5625 struct file_entry *fe;
5627 /* Grow the array if necessary. */
5628 if (lh->file_names_size == 0)
5630 lh->file_names_size = 1; /* for testing */
5631 lh->file_names = xmalloc (lh->file_names_size
5632 * sizeof (*lh->file_names));
5634 else if (lh->num_file_names >= lh->file_names_size)
5636 lh->file_names_size *= 2;
5637 lh->file_names = xrealloc (lh->file_names,
5638 (lh->file_names_size
5639 * sizeof (*lh->file_names)));
5642 fe = &lh->file_names[lh->num_file_names++];
5644 fe->dir_index = dir_index;
5645 fe->mod_time = mod_time;
5646 fe->length = length;
5650 /* Read the statement program header starting at OFFSET in
5651 .debug_line, according to the endianness of ABFD. Return a pointer
5652 to a struct line_header, allocated using xmalloc.
5654 NOTE: the strings in the include directory and file name tables of
5655 the returned object point into debug_line_buffer, and must not be
5657 static struct line_header *
5658 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5659 struct dwarf2_cu *cu)
5661 struct cleanup *back_to;
5662 struct line_header *lh;
5666 char *cur_dir, *cur_file;
5668 if (dwarf2_per_objfile->line_buffer == NULL)
5670 complaint (&symfile_complaints, "missing .debug_line section");
5674 /* Make sure that at least there's room for the total_length field. That
5675 could be 12 bytes long, but we're just going to fudge that. */
5676 if (offset + 4 >= dwarf2_per_objfile->line_size)
5678 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5682 lh = xmalloc (sizeof (*lh));
5683 memset (lh, 0, sizeof (*lh));
5684 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5687 line_ptr = dwarf2_per_objfile->line_buffer + offset;
5689 /* read in the header */
5690 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
5691 line_ptr += bytes_read;
5692 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
5693 + dwarf2_per_objfile->line_size))
5695 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5698 lh->statement_program_end = line_ptr + lh->total_length;
5699 lh->version = read_2_bytes (abfd, line_ptr);
5701 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5702 line_ptr += bytes_read;
5703 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5705 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5707 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5709 lh->line_range = read_1_byte (abfd, line_ptr);
5711 lh->opcode_base = read_1_byte (abfd, line_ptr);
5713 lh->standard_opcode_lengths
5714 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5716 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5717 for (i = 1; i < lh->opcode_base; ++i)
5719 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5723 /* Read directory table */
5724 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5726 line_ptr += bytes_read;
5727 add_include_dir (lh, cur_dir);
5729 line_ptr += bytes_read;
5731 /* Read file name table */
5732 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5734 unsigned int dir_index, mod_time, length;
5736 line_ptr += bytes_read;
5737 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5738 line_ptr += bytes_read;
5739 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5740 line_ptr += bytes_read;
5741 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5742 line_ptr += bytes_read;
5744 add_file_name (lh, cur_file, dir_index, mod_time, length);
5746 line_ptr += bytes_read;
5747 lh->statement_program_start = line_ptr;
5749 if (line_ptr > (dwarf2_per_objfile->line_buffer
5750 + dwarf2_per_objfile->line_size))
5751 complaint (&symfile_complaints,
5752 "line number info header doesn't fit in `.debug_line' section");
5754 discard_cleanups (back_to);
5758 /* This function exists to work around a bug in certain compilers
5759 (particularly GCC 2.95), in which the first line number marker of a
5760 function does not show up until after the prologue, right before
5761 the second line number marker. This function shifts ADDRESS down
5762 to the beginning of the function if necessary, and is called on
5763 addresses passed to record_line. */
5766 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5768 struct function_range *fn;
5770 /* Find the function_range containing address. */
5775 cu->cached_fn = cu->first_fn;
5779 if (fn->lowpc <= address && fn->highpc > address)
5785 while (fn && fn != cu->cached_fn)
5786 if (fn->lowpc <= address && fn->highpc > address)
5796 if (address != fn->lowpc)
5797 complaint (&symfile_complaints,
5798 "misplaced first line number at 0x%lx for '%s'",
5799 (unsigned long) address, fn->name);
5804 /* Decode the line number information for the compilation unit whose
5805 line number info is at OFFSET in the .debug_line section.
5806 The compilation directory of the file is passed in COMP_DIR. */
5809 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5810 struct dwarf2_cu *cu)
5814 unsigned int bytes_read;
5815 unsigned char op_code, extended_op, adj_opcode;
5817 struct objfile *objfile = cu->objfile;
5819 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5821 line_ptr = lh->statement_program_start;
5822 line_end = lh->statement_program_end;
5824 /* Read the statement sequences until there's nothing left. */
5825 while (line_ptr < line_end)
5827 /* state machine registers */
5828 CORE_ADDR address = 0;
5829 unsigned int file = 1;
5830 unsigned int line = 1;
5831 unsigned int column = 0;
5832 int is_stmt = lh->default_is_stmt;
5833 int basic_block = 0;
5834 int end_sequence = 0;
5836 /* Start a subfile for the current file of the state machine. */
5837 if (lh->num_file_names >= file)
5839 /* lh->include_dirs and lh->file_names are 0-based, but the
5840 directory and file name numbers in the statement program
5842 struct file_entry *fe = &lh->file_names[file - 1];
5845 dir = lh->include_dirs[fe->dir_index - 1];
5848 dwarf2_start_subfile (fe->name, dir);
5851 /* Decode the table. */
5852 while (!end_sequence)
5854 op_code = read_1_byte (abfd, line_ptr);
5857 if (op_code >= lh->opcode_base)
5858 { /* Special operand. */
5859 adj_opcode = op_code - lh->opcode_base;
5860 address += (adj_opcode / lh->line_range)
5861 * lh->minimum_instruction_length;
5862 line += lh->line_base + (adj_opcode % lh->line_range);
5863 /* append row to matrix using current values */
5864 record_line (current_subfile, line,
5865 check_cu_functions (address, cu));
5868 else switch (op_code)
5870 case DW_LNS_extended_op:
5871 line_ptr += 1; /* ignore length */
5872 extended_op = read_1_byte (abfd, line_ptr);
5874 switch (extended_op)
5876 case DW_LNE_end_sequence:
5878 record_line (current_subfile, 0, address);
5880 case DW_LNE_set_address:
5881 address = read_address (abfd, line_ptr, cu, &bytes_read);
5882 line_ptr += bytes_read;
5883 address += baseaddr;
5885 case DW_LNE_define_file:
5888 unsigned int dir_index, mod_time, length;
5890 cur_file = read_string (abfd, line_ptr, &bytes_read);
5891 line_ptr += bytes_read;
5893 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5894 line_ptr += bytes_read;
5896 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5897 line_ptr += bytes_read;
5899 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5900 line_ptr += bytes_read;
5901 add_file_name (lh, cur_file, dir_index, mod_time, length);
5905 complaint (&symfile_complaints,
5906 "mangled .debug_line section");
5911 record_line (current_subfile, line,
5912 check_cu_functions (address, cu));
5915 case DW_LNS_advance_pc:
5916 address += lh->minimum_instruction_length
5917 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5918 line_ptr += bytes_read;
5920 case DW_LNS_advance_line:
5921 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5922 line_ptr += bytes_read;
5924 case DW_LNS_set_file:
5926 /* lh->include_dirs and lh->file_names are 0-based,
5927 but the directory and file name numbers in the
5928 statement program are 1-based. */
5929 struct file_entry *fe;
5931 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5932 line_ptr += bytes_read;
5933 fe = &lh->file_names[file - 1];
5935 dir = lh->include_dirs[fe->dir_index - 1];
5938 dwarf2_start_subfile (fe->name, dir);
5941 case DW_LNS_set_column:
5942 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5943 line_ptr += bytes_read;
5945 case DW_LNS_negate_stmt:
5946 is_stmt = (!is_stmt);
5948 case DW_LNS_set_basic_block:
5951 /* Add to the address register of the state machine the
5952 address increment value corresponding to special opcode
5953 255. Ie, this value is scaled by the minimum instruction
5954 length since special opcode 255 would have scaled the
5956 case DW_LNS_const_add_pc:
5957 address += (lh->minimum_instruction_length
5958 * ((255 - lh->opcode_base) / lh->line_range));
5960 case DW_LNS_fixed_advance_pc:
5961 address += read_2_bytes (abfd, line_ptr);
5965 { /* Unknown standard opcode, ignore it. */
5967 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5969 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5970 line_ptr += bytes_read;
5978 /* Start a subfile for DWARF. FILENAME is the name of the file and
5979 DIRNAME the name of the source directory which contains FILENAME
5980 or NULL if not known.
5981 This routine tries to keep line numbers from identical absolute and
5982 relative file names in a common subfile.
5984 Using the `list' example from the GDB testsuite, which resides in
5985 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5986 of /srcdir/list0.c yields the following debugging information for list0.c:
5988 DW_AT_name: /srcdir/list0.c
5989 DW_AT_comp_dir: /compdir
5990 files.files[0].name: list0.h
5991 files.files[0].dir: /srcdir
5992 files.files[1].name: list0.c
5993 files.files[1].dir: /srcdir
5995 The line number information for list0.c has to end up in a single
5996 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5999 dwarf2_start_subfile (char *filename, char *dirname)
6001 /* If the filename isn't absolute, try to match an existing subfile
6002 with the full pathname. */
6004 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
6006 struct subfile *subfile;
6007 char *fullname = concat (dirname, "/", filename, NULL);
6009 for (subfile = subfiles; subfile; subfile = subfile->next)
6011 if (FILENAME_CMP (subfile->name, fullname) == 0)
6013 current_subfile = subfile;
6020 start_subfile (filename, dirname);
6024 var_decode_location (struct attribute *attr, struct symbol *sym,
6025 struct dwarf2_cu *cu)
6027 struct objfile *objfile = cu->objfile;
6028 struct comp_unit_head *cu_header = &cu->header;
6030 /* NOTE drow/2003-01-30: There used to be a comment and some special
6031 code here to turn a symbol with DW_AT_external and a
6032 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6033 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6034 with some versions of binutils) where shared libraries could have
6035 relocations against symbols in their debug information - the
6036 minimal symbol would have the right address, but the debug info
6037 would not. It's no longer necessary, because we will explicitly
6038 apply relocations when we read in the debug information now. */
6040 /* A DW_AT_location attribute with no contents indicates that a
6041 variable has been optimized away. */
6042 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
6044 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
6048 /* Handle one degenerate form of location expression specially, to
6049 preserve GDB's previous behavior when section offsets are
6050 specified. If this is just a DW_OP_addr then mark this symbol
6053 if (attr_form_is_block (attr)
6054 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
6055 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
6059 SYMBOL_VALUE_ADDRESS (sym) =
6060 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
6061 fixup_symbol_section (sym, objfile);
6062 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
6063 SYMBOL_SECTION (sym));
6064 SYMBOL_CLASS (sym) = LOC_STATIC;
6068 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6069 expression evaluator, and use LOC_COMPUTED only when necessary
6070 (i.e. when the value of a register or memory location is
6071 referenced, or a thread-local block, etc.). Then again, it might
6072 not be worthwhile. I'm assuming that it isn't unless performance
6073 or memory numbers show me otherwise. */
6075 dwarf2_symbol_mark_computed (attr, sym, cu);
6076 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6079 /* Given a pointer to a DWARF information entry, figure out if we need
6080 to make a symbol table entry for it, and if so, create a new entry
6081 and return a pointer to it.
6082 If TYPE is NULL, determine symbol type from the die, otherwise
6083 used the passed type. */
6085 static struct symbol *
6086 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6088 struct objfile *objfile = cu->objfile;
6089 struct symbol *sym = NULL;
6091 struct attribute *attr = NULL;
6092 struct attribute *attr2 = NULL;
6095 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6097 if (die->tag != DW_TAG_namespace)
6098 name = dwarf2_linkage_name (die, cu);
6100 name = TYPE_NAME (type);
6104 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6105 sizeof (struct symbol));
6106 OBJSTAT (objfile, n_syms++);
6107 memset (sym, 0, sizeof (struct symbol));
6109 /* Cache this symbol's name and the name's demangled form (if any). */
6110 SYMBOL_LANGUAGE (sym) = cu->language;
6111 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6113 /* Default assumptions.
6114 Use the passed type or decode it from the die. */
6115 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6116 SYMBOL_CLASS (sym) = LOC_STATIC;
6118 SYMBOL_TYPE (sym) = type;
6120 SYMBOL_TYPE (sym) = die_type (die, cu);
6121 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
6124 SYMBOL_LINE (sym) = DW_UNSND (attr);
6129 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6132 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
6134 SYMBOL_CLASS (sym) = LOC_LABEL;
6136 case DW_TAG_subprogram:
6137 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6139 SYMBOL_CLASS (sym) = LOC_BLOCK;
6140 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6141 if (attr2 && (DW_UNSND (attr2) != 0))
6143 add_symbol_to_list (sym, &global_symbols);
6147 add_symbol_to_list (sym, cu->list_in_scope);
6150 case DW_TAG_variable:
6151 /* Compilation with minimal debug info may result in variables
6152 with missing type entries. Change the misleading `void' type
6153 to something sensible. */
6154 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
6155 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
6156 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
6157 "<variable, no debug info>",
6159 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6162 dwarf2_const_value (attr, sym, cu);
6163 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6164 if (attr2 && (DW_UNSND (attr2) != 0))
6165 add_symbol_to_list (sym, &global_symbols);
6167 add_symbol_to_list (sym, cu->list_in_scope);
6170 attr = dwarf2_attr (die, DW_AT_location, cu);
6173 var_decode_location (attr, sym, cu);
6174 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6175 if (attr2 && (DW_UNSND (attr2) != 0))
6176 add_symbol_to_list (sym, &global_symbols);
6178 add_symbol_to_list (sym, cu->list_in_scope);
6182 /* We do not know the address of this symbol.
6183 If it is an external symbol and we have type information
6184 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6185 The address of the variable will then be determined from
6186 the minimal symbol table whenever the variable is
6188 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6189 if (attr2 && (DW_UNSND (attr2) != 0)
6190 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
6192 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6193 add_symbol_to_list (sym, &global_symbols);
6197 case DW_TAG_formal_parameter:
6198 attr = dwarf2_attr (die, DW_AT_location, cu);
6201 var_decode_location (attr, sym, cu);
6202 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6203 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
6204 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
6206 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6209 dwarf2_const_value (attr, sym, cu);
6211 add_symbol_to_list (sym, cu->list_in_scope);
6213 case DW_TAG_unspecified_parameters:
6214 /* From varargs functions; gdb doesn't seem to have any
6215 interest in this information, so just ignore it for now.
6218 case DW_TAG_class_type:
6219 case DW_TAG_structure_type:
6220 case DW_TAG_union_type:
6221 case DW_TAG_enumeration_type:
6222 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6223 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6225 /* Make sure that the symbol includes appropriate enclosing
6226 classes/namespaces in its name. These are calculated in
6227 read_structure_type, and the correct name is saved in
6230 if (cu->language == language_cplus)
6232 struct type *type = SYMBOL_TYPE (sym);
6234 if (TYPE_TAG_NAME (type) != NULL)
6236 /* FIXME: carlton/2003-11-10: Should this use
6237 SYMBOL_SET_NAMES instead? (The same problem also
6238 arises further down in this function.) */
6239 /* The type's name is already allocated along with
6240 this objfile, so we don't need to duplicate it
6242 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
6247 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
6248 really ever be static objects: otherwise, if you try
6249 to, say, break of a class's method and you're in a file
6250 which doesn't mention that class, it won't work unless
6251 the check for all static symbols in lookup_symbol_aux
6252 saves you. See the OtherFileClass tests in
6253 gdb.c++/namespace.exp. */
6255 struct pending **list_to_add;
6257 list_to_add = (cu->list_in_scope == &file_symbols
6258 && cu->language == language_cplus
6259 ? &global_symbols : cu->list_in_scope);
6261 add_symbol_to_list (sym, list_to_add);
6263 /* The semantics of C++ state that "struct foo { ... }" also
6264 defines a typedef for "foo". Synthesize a typedef symbol so
6265 that "ptype foo" works as expected. */
6266 if (cu->language == language_cplus)
6268 struct symbol *typedef_sym = (struct symbol *)
6269 obstack_alloc (&objfile->objfile_obstack,
6270 sizeof (struct symbol));
6271 *typedef_sym = *sym;
6272 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
6273 /* The symbol's name is already allocated along with
6274 this objfile, so we don't need to duplicate it for
6276 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
6277 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym);
6278 add_symbol_to_list (typedef_sym, list_to_add);
6282 case DW_TAG_typedef:
6283 if (processing_has_namespace_info
6284 && processing_current_prefix[0] != '\0')
6286 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
6287 processing_current_prefix,
6291 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6292 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6293 add_symbol_to_list (sym, cu->list_in_scope);
6295 case DW_TAG_base_type:
6296 case DW_TAG_subrange_type:
6297 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6298 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6299 add_symbol_to_list (sym, cu->list_in_scope);
6301 case DW_TAG_enumerator:
6302 if (processing_has_namespace_info
6303 && processing_current_prefix[0] != '\0')
6305 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
6306 processing_current_prefix,
6310 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6313 dwarf2_const_value (attr, sym, cu);
6316 /* NOTE: carlton/2003-11-10: See comment above in the
6317 DW_TAG_class_type, etc. block. */
6319 struct pending **list_to_add;
6321 list_to_add = (cu->list_in_scope == &file_symbols
6322 && cu->language == language_cplus
6323 ? &global_symbols : cu->list_in_scope);
6325 add_symbol_to_list (sym, list_to_add);
6328 case DW_TAG_namespace:
6329 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6330 add_symbol_to_list (sym, &global_symbols);
6333 /* Not a tag we recognize. Hopefully we aren't processing
6334 trash data, but since we must specifically ignore things
6335 we don't recognize, there is nothing else we should do at
6337 complaint (&symfile_complaints, "unsupported tag: '%s'",
6338 dwarf_tag_name (die->tag));
6345 /* Copy constant value from an attribute to a symbol. */
6348 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
6349 struct dwarf2_cu *cu)
6351 struct objfile *objfile = cu->objfile;
6352 struct comp_unit_head *cu_header = &cu->header;
6353 struct dwarf_block *blk;
6358 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
6359 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6360 cu_header->addr_size,
6361 TYPE_LENGTH (SYMBOL_TYPE
6363 SYMBOL_VALUE_BYTES (sym) = (char *)
6364 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
6365 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6366 it's body - store_unsigned_integer. */
6367 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
6369 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6371 case DW_FORM_block1:
6372 case DW_FORM_block2:
6373 case DW_FORM_block4:
6375 blk = DW_BLOCK (attr);
6376 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
6377 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6379 TYPE_LENGTH (SYMBOL_TYPE
6381 SYMBOL_VALUE_BYTES (sym) = (char *)
6382 obstack_alloc (&objfile->objfile_obstack, blk->size);
6383 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
6384 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6387 /* The DW_AT_const_value attributes are supposed to carry the
6388 symbol's value "represented as it would be on the target
6389 architecture." By the time we get here, it's already been
6390 converted to host endianness, so we just need to sign- or
6391 zero-extend it as appropriate. */
6393 dwarf2_const_value_data (attr, sym, 8);
6396 dwarf2_const_value_data (attr, sym, 16);
6399 dwarf2_const_value_data (attr, sym, 32);
6402 dwarf2_const_value_data (attr, sym, 64);
6406 SYMBOL_VALUE (sym) = DW_SND (attr);
6407 SYMBOL_CLASS (sym) = LOC_CONST;
6411 SYMBOL_VALUE (sym) = DW_UNSND (attr);
6412 SYMBOL_CLASS (sym) = LOC_CONST;
6416 complaint (&symfile_complaints,
6417 "unsupported const value attribute form: '%s'",
6418 dwarf_form_name (attr->form));
6419 SYMBOL_VALUE (sym) = 0;
6420 SYMBOL_CLASS (sym) = LOC_CONST;
6426 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6427 or zero-extend it as appropriate for the symbol's type. */
6429 dwarf2_const_value_data (struct attribute *attr,
6433 LONGEST l = DW_UNSND (attr);
6435 if (bits < sizeof (l) * 8)
6437 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
6438 l &= ((LONGEST) 1 << bits) - 1;
6440 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
6443 SYMBOL_VALUE (sym) = l;
6444 SYMBOL_CLASS (sym) = LOC_CONST;
6448 /* Return the type of the die in question using its DW_AT_type attribute. */
6450 static struct type *
6451 die_type (struct die_info *die, struct dwarf2_cu *cu)
6454 struct attribute *type_attr;
6455 struct die_info *type_die;
6458 type_attr = dwarf2_attr (die, DW_AT_type, cu);
6461 /* A missing DW_AT_type represents a void type. */
6462 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
6466 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6467 type_die = follow_die_ref (ref);
6470 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6471 ref, cu->objfile->name);
6475 type = tag_type_to_type (type_die, cu);
6478 dump_die (type_die);
6479 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6485 /* Return the containing type of the die in question using its
6486 DW_AT_containing_type attribute. */
6488 static struct type *
6489 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6491 struct type *type = NULL;
6492 struct attribute *type_attr;
6493 struct die_info *type_die = NULL;
6496 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6499 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6500 type_die = follow_die_ref (ref);
6503 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6507 type = tag_type_to_type (type_die, cu);
6512 dump_die (type_die);
6513 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6520 static struct type *
6521 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
6523 struct die_info *die;
6526 die = follow_die_ref (offset);
6529 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
6532 type = tag_type_to_type (die, cu);
6537 static struct type *
6538 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
6546 read_type_die (die, cu);
6550 error ("Dwarf Error: Cannot find type of die [in module %s]",
6558 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6560 char *prefix = determine_prefix (die, cu);
6561 const char *old_prefix = processing_current_prefix;
6562 struct cleanup *back_to = make_cleanup (xfree, prefix);
6563 processing_current_prefix = prefix;
6567 case DW_TAG_class_type:
6568 case DW_TAG_structure_type:
6569 case DW_TAG_union_type:
6570 read_structure_type (die, cu);
6572 case DW_TAG_enumeration_type:
6573 read_enumeration_type (die, cu);
6575 case DW_TAG_subprogram:
6576 case DW_TAG_subroutine_type:
6577 read_subroutine_type (die, cu);
6579 case DW_TAG_array_type:
6580 read_array_type (die, cu);
6582 case DW_TAG_pointer_type:
6583 read_tag_pointer_type (die, cu);
6585 case DW_TAG_ptr_to_member_type:
6586 read_tag_ptr_to_member_type (die, cu);
6588 case DW_TAG_reference_type:
6589 read_tag_reference_type (die, cu);
6591 case DW_TAG_const_type:
6592 read_tag_const_type (die, cu);
6594 case DW_TAG_volatile_type:
6595 read_tag_volatile_type (die, cu);
6597 case DW_TAG_string_type:
6598 read_tag_string_type (die, cu);
6600 case DW_TAG_typedef:
6601 read_typedef (die, cu);
6603 case DW_TAG_subrange_type:
6604 read_subrange_type (die, cu);
6606 case DW_TAG_base_type:
6607 read_base_type (die, cu);
6610 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6611 dwarf_tag_name (die->tag));
6615 processing_current_prefix = old_prefix;
6616 do_cleanups (back_to);
6619 /* Return the name of the namespace/class that DIE is defined within,
6620 or "" if we can't tell. The caller should xfree the result. */
6622 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6623 therein) for an example of how to use this function to deal with
6624 DW_AT_specification. */
6627 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6629 struct die_info *parent;
6631 if (cu->language != language_cplus)
6634 parent = die->parent;
6638 return xstrdup ("");
6642 switch (parent->tag) {
6643 case DW_TAG_namespace:
6645 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6646 before doing this check? */
6647 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6649 return xstrdup (TYPE_TAG_NAME (parent->type));
6654 char *parent_prefix = determine_prefix (parent, cu);
6655 char *retval = typename_concat (parent_prefix,
6656 namespace_name (parent, &dummy,
6658 xfree (parent_prefix);
6663 case DW_TAG_class_type:
6664 case DW_TAG_structure_type:
6666 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6668 return xstrdup (TYPE_TAG_NAME (parent->type));
6672 const char *old_prefix = processing_current_prefix;
6673 char *new_prefix = determine_prefix (parent, cu);
6676 processing_current_prefix = new_prefix;
6677 retval = determine_class_name (parent, cu);
6678 processing_current_prefix = old_prefix;
6685 return determine_prefix (parent, cu);
6690 /* Return a newly-allocated string formed by concatenating PREFIX,
6691 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6692 string, just return a copy of SUFFIX. */
6695 typename_concat (const char *prefix, const char *suffix)
6697 if (prefix == NULL || prefix[0] == '\0')
6698 return xstrdup (suffix);
6701 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1);
6703 strcpy (retval, prefix);
6704 strcat (retval, "::");
6705 strcat (retval, suffix);
6711 static struct type *
6712 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6714 struct objfile *objfile = cu->objfile;
6716 /* FIXME - this should not produce a new (struct type *)
6717 every time. It should cache base types. */
6721 case DW_ATE_address:
6722 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6724 case DW_ATE_boolean:
6725 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6727 case DW_ATE_complex_float:
6730 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6734 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6740 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6744 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6751 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6754 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6758 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6762 case DW_ATE_signed_char:
6763 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6765 case DW_ATE_unsigned:
6769 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6772 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
6776 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
6780 case DW_ATE_unsigned_char:
6781 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6784 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6791 copy_die (struct die_info *old_die)
6793 struct die_info *new_die;
6796 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
6797 memset (new_die, 0, sizeof (struct die_info));
6799 new_die->tag = old_die->tag;
6800 new_die->has_children = old_die->has_children;
6801 new_die->abbrev = old_die->abbrev;
6802 new_die->offset = old_die->offset;
6803 new_die->type = NULL;
6805 num_attrs = old_die->num_attrs;
6806 new_die->num_attrs = num_attrs;
6807 new_die->attrs = (struct attribute *)
6808 xmalloc (num_attrs * sizeof (struct attribute));
6810 for (i = 0; i < old_die->num_attrs; ++i)
6812 new_die->attrs[i].name = old_die->attrs[i].name;
6813 new_die->attrs[i].form = old_die->attrs[i].form;
6814 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
6817 new_die->next = NULL;
6822 /* Return sibling of die, NULL if no sibling. */
6824 static struct die_info *
6825 sibling_die (struct die_info *die)
6827 return die->sibling;
6830 /* Get linkage name of a die, return NULL if not found. */
6833 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
6835 struct attribute *attr;
6837 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
6838 if (attr && DW_STRING (attr))
6839 return DW_STRING (attr);
6840 attr = dwarf2_attr (die, DW_AT_name, cu);
6841 if (attr && DW_STRING (attr))
6842 return DW_STRING (attr);
6846 /* Get name of a die, return NULL if not found. */
6849 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
6851 struct attribute *attr;
6853 attr = dwarf2_attr (die, DW_AT_name, cu);
6854 if (attr && DW_STRING (attr))
6855 return DW_STRING (attr);
6859 /* Return the die that this die in an extension of, or NULL if there
6862 static struct die_info *
6863 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
6865 struct attribute *attr;
6866 struct die_info *extension_die;
6869 attr = dwarf2_attr (die, DW_AT_extension, cu);
6873 ref = dwarf2_get_ref_die_offset (attr, cu);
6874 extension_die = follow_die_ref (ref);
6877 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
6880 return extension_die;
6883 /* Convert a DIE tag into its string name. */
6886 dwarf_tag_name (unsigned tag)
6890 case DW_TAG_padding:
6891 return "DW_TAG_padding";
6892 case DW_TAG_array_type:
6893 return "DW_TAG_array_type";
6894 case DW_TAG_class_type:
6895 return "DW_TAG_class_type";
6896 case DW_TAG_entry_point:
6897 return "DW_TAG_entry_point";
6898 case DW_TAG_enumeration_type:
6899 return "DW_TAG_enumeration_type";
6900 case DW_TAG_formal_parameter:
6901 return "DW_TAG_formal_parameter";
6902 case DW_TAG_imported_declaration:
6903 return "DW_TAG_imported_declaration";
6905 return "DW_TAG_label";
6906 case DW_TAG_lexical_block:
6907 return "DW_TAG_lexical_block";
6909 return "DW_TAG_member";
6910 case DW_TAG_pointer_type:
6911 return "DW_TAG_pointer_type";
6912 case DW_TAG_reference_type:
6913 return "DW_TAG_reference_type";
6914 case DW_TAG_compile_unit:
6915 return "DW_TAG_compile_unit";
6916 case DW_TAG_string_type:
6917 return "DW_TAG_string_type";
6918 case DW_TAG_structure_type:
6919 return "DW_TAG_structure_type";
6920 case DW_TAG_subroutine_type:
6921 return "DW_TAG_subroutine_type";
6922 case DW_TAG_typedef:
6923 return "DW_TAG_typedef";
6924 case DW_TAG_union_type:
6925 return "DW_TAG_union_type";
6926 case DW_TAG_unspecified_parameters:
6927 return "DW_TAG_unspecified_parameters";
6928 case DW_TAG_variant:
6929 return "DW_TAG_variant";
6930 case DW_TAG_common_block:
6931 return "DW_TAG_common_block";
6932 case DW_TAG_common_inclusion:
6933 return "DW_TAG_common_inclusion";
6934 case DW_TAG_inheritance:
6935 return "DW_TAG_inheritance";
6936 case DW_TAG_inlined_subroutine:
6937 return "DW_TAG_inlined_subroutine";
6939 return "DW_TAG_module";
6940 case DW_TAG_ptr_to_member_type:
6941 return "DW_TAG_ptr_to_member_type";
6942 case DW_TAG_set_type:
6943 return "DW_TAG_set_type";
6944 case DW_TAG_subrange_type:
6945 return "DW_TAG_subrange_type";
6946 case DW_TAG_with_stmt:
6947 return "DW_TAG_with_stmt";
6948 case DW_TAG_access_declaration:
6949 return "DW_TAG_access_declaration";
6950 case DW_TAG_base_type:
6951 return "DW_TAG_base_type";
6952 case DW_TAG_catch_block:
6953 return "DW_TAG_catch_block";
6954 case DW_TAG_const_type:
6955 return "DW_TAG_const_type";
6956 case DW_TAG_constant:
6957 return "DW_TAG_constant";
6958 case DW_TAG_enumerator:
6959 return "DW_TAG_enumerator";
6960 case DW_TAG_file_type:
6961 return "DW_TAG_file_type";
6963 return "DW_TAG_friend";
6964 case DW_TAG_namelist:
6965 return "DW_TAG_namelist";
6966 case DW_TAG_namelist_item:
6967 return "DW_TAG_namelist_item";
6968 case DW_TAG_packed_type:
6969 return "DW_TAG_packed_type";
6970 case DW_TAG_subprogram:
6971 return "DW_TAG_subprogram";
6972 case DW_TAG_template_type_param:
6973 return "DW_TAG_template_type_param";
6974 case DW_TAG_template_value_param:
6975 return "DW_TAG_template_value_param";
6976 case DW_TAG_thrown_type:
6977 return "DW_TAG_thrown_type";
6978 case DW_TAG_try_block:
6979 return "DW_TAG_try_block";
6980 case DW_TAG_variant_part:
6981 return "DW_TAG_variant_part";
6982 case DW_TAG_variable:
6983 return "DW_TAG_variable";
6984 case DW_TAG_volatile_type:
6985 return "DW_TAG_volatile_type";
6986 case DW_TAG_dwarf_procedure:
6987 return "DW_TAG_dwarf_procedure";
6988 case DW_TAG_restrict_type:
6989 return "DW_TAG_restrict_type";
6990 case DW_TAG_interface_type:
6991 return "DW_TAG_interface_type";
6992 case DW_TAG_namespace:
6993 return "DW_TAG_namespace";
6994 case DW_TAG_imported_module:
6995 return "DW_TAG_imported_module";
6996 case DW_TAG_unspecified_type:
6997 return "DW_TAG_unspecified_type";
6998 case DW_TAG_partial_unit:
6999 return "DW_TAG_partial_unit";
7000 case DW_TAG_imported_unit:
7001 return "DW_TAG_imported_unit";
7002 case DW_TAG_MIPS_loop:
7003 return "DW_TAG_MIPS_loop";
7004 case DW_TAG_format_label:
7005 return "DW_TAG_format_label";
7006 case DW_TAG_function_template:
7007 return "DW_TAG_function_template";
7008 case DW_TAG_class_template:
7009 return "DW_TAG_class_template";
7011 return "DW_TAG_<unknown>";
7015 /* Convert a DWARF attribute code into its string name. */
7018 dwarf_attr_name (unsigned attr)
7023 return "DW_AT_sibling";
7024 case DW_AT_location:
7025 return "DW_AT_location";
7027 return "DW_AT_name";
7028 case DW_AT_ordering:
7029 return "DW_AT_ordering";
7030 case DW_AT_subscr_data:
7031 return "DW_AT_subscr_data";
7032 case DW_AT_byte_size:
7033 return "DW_AT_byte_size";
7034 case DW_AT_bit_offset:
7035 return "DW_AT_bit_offset";
7036 case DW_AT_bit_size:
7037 return "DW_AT_bit_size";
7038 case DW_AT_element_list:
7039 return "DW_AT_element_list";
7040 case DW_AT_stmt_list:
7041 return "DW_AT_stmt_list";
7043 return "DW_AT_low_pc";
7045 return "DW_AT_high_pc";
7046 case DW_AT_language:
7047 return "DW_AT_language";
7049 return "DW_AT_member";
7051 return "DW_AT_discr";
7052 case DW_AT_discr_value:
7053 return "DW_AT_discr_value";
7054 case DW_AT_visibility:
7055 return "DW_AT_visibility";
7057 return "DW_AT_import";
7058 case DW_AT_string_length:
7059 return "DW_AT_string_length";
7060 case DW_AT_common_reference:
7061 return "DW_AT_common_reference";
7062 case DW_AT_comp_dir:
7063 return "DW_AT_comp_dir";
7064 case DW_AT_const_value:
7065 return "DW_AT_const_value";
7066 case DW_AT_containing_type:
7067 return "DW_AT_containing_type";
7068 case DW_AT_default_value:
7069 return "DW_AT_default_value";
7071 return "DW_AT_inline";
7072 case DW_AT_is_optional:
7073 return "DW_AT_is_optional";
7074 case DW_AT_lower_bound:
7075 return "DW_AT_lower_bound";
7076 case DW_AT_producer:
7077 return "DW_AT_producer";
7078 case DW_AT_prototyped:
7079 return "DW_AT_prototyped";
7080 case DW_AT_return_addr:
7081 return "DW_AT_return_addr";
7082 case DW_AT_start_scope:
7083 return "DW_AT_start_scope";
7084 case DW_AT_stride_size:
7085 return "DW_AT_stride_size";
7086 case DW_AT_upper_bound:
7087 return "DW_AT_upper_bound";
7088 case DW_AT_abstract_origin:
7089 return "DW_AT_abstract_origin";
7090 case DW_AT_accessibility:
7091 return "DW_AT_accessibility";
7092 case DW_AT_address_class:
7093 return "DW_AT_address_class";
7094 case DW_AT_artificial:
7095 return "DW_AT_artificial";
7096 case DW_AT_base_types:
7097 return "DW_AT_base_types";
7098 case DW_AT_calling_convention:
7099 return "DW_AT_calling_convention";
7101 return "DW_AT_count";
7102 case DW_AT_data_member_location:
7103 return "DW_AT_data_member_location";
7104 case DW_AT_decl_column:
7105 return "DW_AT_decl_column";
7106 case DW_AT_decl_file:
7107 return "DW_AT_decl_file";
7108 case DW_AT_decl_line:
7109 return "DW_AT_decl_line";
7110 case DW_AT_declaration:
7111 return "DW_AT_declaration";
7112 case DW_AT_discr_list:
7113 return "DW_AT_discr_list";
7114 case DW_AT_encoding:
7115 return "DW_AT_encoding";
7116 case DW_AT_external:
7117 return "DW_AT_external";
7118 case DW_AT_frame_base:
7119 return "DW_AT_frame_base";
7121 return "DW_AT_friend";
7122 case DW_AT_identifier_case:
7123 return "DW_AT_identifier_case";
7124 case DW_AT_macro_info:
7125 return "DW_AT_macro_info";
7126 case DW_AT_namelist_items:
7127 return "DW_AT_namelist_items";
7128 case DW_AT_priority:
7129 return "DW_AT_priority";
7131 return "DW_AT_segment";
7132 case DW_AT_specification:
7133 return "DW_AT_specification";
7134 case DW_AT_static_link:
7135 return "DW_AT_static_link";
7137 return "DW_AT_type";
7138 case DW_AT_use_location:
7139 return "DW_AT_use_location";
7140 case DW_AT_variable_parameter:
7141 return "DW_AT_variable_parameter";
7142 case DW_AT_virtuality:
7143 return "DW_AT_virtuality";
7144 case DW_AT_vtable_elem_location:
7145 return "DW_AT_vtable_elem_location";
7146 case DW_AT_allocated:
7147 return "DW_AT_allocated";
7148 case DW_AT_associated:
7149 return "DW_AT_associated";
7150 case DW_AT_data_location:
7151 return "DW_AT_data_location";
7153 return "DW_AT_stride";
7154 case DW_AT_entry_pc:
7155 return "DW_AT_entry_pc";
7156 case DW_AT_use_UTF8:
7157 return "DW_AT_use_UTF8";
7158 case DW_AT_extension:
7159 return "DW_AT_extension";
7161 return "DW_AT_ranges";
7162 case DW_AT_trampoline:
7163 return "DW_AT_trampoline";
7164 case DW_AT_call_column:
7165 return "DW_AT_call_column";
7166 case DW_AT_call_file:
7167 return "DW_AT_call_file";
7168 case DW_AT_call_line:
7169 return "DW_AT_call_line";
7171 case DW_AT_MIPS_fde:
7172 return "DW_AT_MIPS_fde";
7173 case DW_AT_MIPS_loop_begin:
7174 return "DW_AT_MIPS_loop_begin";
7175 case DW_AT_MIPS_tail_loop_begin:
7176 return "DW_AT_MIPS_tail_loop_begin";
7177 case DW_AT_MIPS_epilog_begin:
7178 return "DW_AT_MIPS_epilog_begin";
7179 case DW_AT_MIPS_loop_unroll_factor:
7180 return "DW_AT_MIPS_loop_unroll_factor";
7181 case DW_AT_MIPS_software_pipeline_depth:
7182 return "DW_AT_MIPS_software_pipeline_depth";
7184 case DW_AT_MIPS_linkage_name:
7185 return "DW_AT_MIPS_linkage_name";
7187 case DW_AT_sf_names:
7188 return "DW_AT_sf_names";
7189 case DW_AT_src_info:
7190 return "DW_AT_src_info";
7191 case DW_AT_mac_info:
7192 return "DW_AT_mac_info";
7193 case DW_AT_src_coords:
7194 return "DW_AT_src_coords";
7195 case DW_AT_body_begin:
7196 return "DW_AT_body_begin";
7197 case DW_AT_body_end:
7198 return "DW_AT_body_end";
7199 case DW_AT_GNU_vector:
7200 return "DW_AT_GNU_vector";
7202 return "DW_AT_<unknown>";
7206 /* Convert a DWARF value form code into its string name. */
7209 dwarf_form_name (unsigned form)
7214 return "DW_FORM_addr";
7215 case DW_FORM_block2:
7216 return "DW_FORM_block2";
7217 case DW_FORM_block4:
7218 return "DW_FORM_block4";
7220 return "DW_FORM_data2";
7222 return "DW_FORM_data4";
7224 return "DW_FORM_data8";
7225 case DW_FORM_string:
7226 return "DW_FORM_string";
7228 return "DW_FORM_block";
7229 case DW_FORM_block1:
7230 return "DW_FORM_block1";
7232 return "DW_FORM_data1";
7234 return "DW_FORM_flag";
7236 return "DW_FORM_sdata";
7238 return "DW_FORM_strp";
7240 return "DW_FORM_udata";
7241 case DW_FORM_ref_addr:
7242 return "DW_FORM_ref_addr";
7244 return "DW_FORM_ref1";
7246 return "DW_FORM_ref2";
7248 return "DW_FORM_ref4";
7250 return "DW_FORM_ref8";
7251 case DW_FORM_ref_udata:
7252 return "DW_FORM_ref_udata";
7253 case DW_FORM_indirect:
7254 return "DW_FORM_indirect";
7256 return "DW_FORM_<unknown>";
7260 /* Convert a DWARF stack opcode into its string name. */
7263 dwarf_stack_op_name (unsigned op)
7268 return "DW_OP_addr";
7270 return "DW_OP_deref";
7272 return "DW_OP_const1u";
7274 return "DW_OP_const1s";
7276 return "DW_OP_const2u";
7278 return "DW_OP_const2s";
7280 return "DW_OP_const4u";
7282 return "DW_OP_const4s";
7284 return "DW_OP_const8u";
7286 return "DW_OP_const8s";
7288 return "DW_OP_constu";
7290 return "DW_OP_consts";
7294 return "DW_OP_drop";
7296 return "DW_OP_over";
7298 return "DW_OP_pick";
7300 return "DW_OP_swap";
7304 return "DW_OP_xderef";
7312 return "DW_OP_minus";
7324 return "DW_OP_plus";
7325 case DW_OP_plus_uconst:
7326 return "DW_OP_plus_uconst";
7332 return "DW_OP_shra";
7350 return "DW_OP_skip";
7352 return "DW_OP_lit0";
7354 return "DW_OP_lit1";
7356 return "DW_OP_lit2";
7358 return "DW_OP_lit3";
7360 return "DW_OP_lit4";
7362 return "DW_OP_lit5";
7364 return "DW_OP_lit6";
7366 return "DW_OP_lit7";
7368 return "DW_OP_lit8";
7370 return "DW_OP_lit9";
7372 return "DW_OP_lit10";
7374 return "DW_OP_lit11";
7376 return "DW_OP_lit12";
7378 return "DW_OP_lit13";
7380 return "DW_OP_lit14";
7382 return "DW_OP_lit15";
7384 return "DW_OP_lit16";
7386 return "DW_OP_lit17";
7388 return "DW_OP_lit18";
7390 return "DW_OP_lit19";
7392 return "DW_OP_lit20";
7394 return "DW_OP_lit21";
7396 return "DW_OP_lit22";
7398 return "DW_OP_lit23";
7400 return "DW_OP_lit24";
7402 return "DW_OP_lit25";
7404 return "DW_OP_lit26";
7406 return "DW_OP_lit27";
7408 return "DW_OP_lit28";
7410 return "DW_OP_lit29";
7412 return "DW_OP_lit30";
7414 return "DW_OP_lit31";
7416 return "DW_OP_reg0";
7418 return "DW_OP_reg1";
7420 return "DW_OP_reg2";
7422 return "DW_OP_reg3";
7424 return "DW_OP_reg4";
7426 return "DW_OP_reg5";
7428 return "DW_OP_reg6";
7430 return "DW_OP_reg7";
7432 return "DW_OP_reg8";
7434 return "DW_OP_reg9";
7436 return "DW_OP_reg10";
7438 return "DW_OP_reg11";
7440 return "DW_OP_reg12";
7442 return "DW_OP_reg13";
7444 return "DW_OP_reg14";
7446 return "DW_OP_reg15";
7448 return "DW_OP_reg16";
7450 return "DW_OP_reg17";
7452 return "DW_OP_reg18";
7454 return "DW_OP_reg19";
7456 return "DW_OP_reg20";
7458 return "DW_OP_reg21";
7460 return "DW_OP_reg22";
7462 return "DW_OP_reg23";
7464 return "DW_OP_reg24";
7466 return "DW_OP_reg25";
7468 return "DW_OP_reg26";
7470 return "DW_OP_reg27";
7472 return "DW_OP_reg28";
7474 return "DW_OP_reg29";
7476 return "DW_OP_reg30";
7478 return "DW_OP_reg31";
7480 return "DW_OP_breg0";
7482 return "DW_OP_breg1";
7484 return "DW_OP_breg2";
7486 return "DW_OP_breg3";
7488 return "DW_OP_breg4";
7490 return "DW_OP_breg5";
7492 return "DW_OP_breg6";
7494 return "DW_OP_breg7";
7496 return "DW_OP_breg8";
7498 return "DW_OP_breg9";
7500 return "DW_OP_breg10";
7502 return "DW_OP_breg11";
7504 return "DW_OP_breg12";
7506 return "DW_OP_breg13";
7508 return "DW_OP_breg14";
7510 return "DW_OP_breg15";
7512 return "DW_OP_breg16";
7514 return "DW_OP_breg17";
7516 return "DW_OP_breg18";
7518 return "DW_OP_breg19";
7520 return "DW_OP_breg20";
7522 return "DW_OP_breg21";
7524 return "DW_OP_breg22";
7526 return "DW_OP_breg23";
7528 return "DW_OP_breg24";
7530 return "DW_OP_breg25";
7532 return "DW_OP_breg26";
7534 return "DW_OP_breg27";
7536 return "DW_OP_breg28";
7538 return "DW_OP_breg29";
7540 return "DW_OP_breg30";
7542 return "DW_OP_breg31";
7544 return "DW_OP_regx";
7546 return "DW_OP_fbreg";
7548 return "DW_OP_bregx";
7550 return "DW_OP_piece";
7551 case DW_OP_deref_size:
7552 return "DW_OP_deref_size";
7553 case DW_OP_xderef_size:
7554 return "DW_OP_xderef_size";
7557 /* DWARF 3 extensions. */
7558 case DW_OP_push_object_address:
7559 return "DW_OP_push_object_address";
7561 return "DW_OP_call2";
7563 return "DW_OP_call4";
7564 case DW_OP_call_ref:
7565 return "DW_OP_call_ref";
7566 /* GNU extensions. */
7567 case DW_OP_GNU_push_tls_address:
7568 return "DW_OP_GNU_push_tls_address";
7570 return "OP_<unknown>";
7575 dwarf_bool_name (unsigned mybool)
7583 /* Convert a DWARF type code into its string name. */
7586 dwarf_type_encoding_name (unsigned enc)
7590 case DW_ATE_address:
7591 return "DW_ATE_address";
7592 case DW_ATE_boolean:
7593 return "DW_ATE_boolean";
7594 case DW_ATE_complex_float:
7595 return "DW_ATE_complex_float";
7597 return "DW_ATE_float";
7599 return "DW_ATE_signed";
7600 case DW_ATE_signed_char:
7601 return "DW_ATE_signed_char";
7602 case DW_ATE_unsigned:
7603 return "DW_ATE_unsigned";
7604 case DW_ATE_unsigned_char:
7605 return "DW_ATE_unsigned_char";
7606 case DW_ATE_imaginary_float:
7607 return "DW_ATE_imaginary_float";
7609 return "DW_ATE_<unknown>";
7613 /* Convert a DWARF call frame info operation to its string name. */
7617 dwarf_cfi_name (unsigned cfi_opc)
7621 case DW_CFA_advance_loc:
7622 return "DW_CFA_advance_loc";
7624 return "DW_CFA_offset";
7625 case DW_CFA_restore:
7626 return "DW_CFA_restore";
7628 return "DW_CFA_nop";
7629 case DW_CFA_set_loc:
7630 return "DW_CFA_set_loc";
7631 case DW_CFA_advance_loc1:
7632 return "DW_CFA_advance_loc1";
7633 case DW_CFA_advance_loc2:
7634 return "DW_CFA_advance_loc2";
7635 case DW_CFA_advance_loc4:
7636 return "DW_CFA_advance_loc4";
7637 case DW_CFA_offset_extended:
7638 return "DW_CFA_offset_extended";
7639 case DW_CFA_restore_extended:
7640 return "DW_CFA_restore_extended";
7641 case DW_CFA_undefined:
7642 return "DW_CFA_undefined";
7643 case DW_CFA_same_value:
7644 return "DW_CFA_same_value";
7645 case DW_CFA_register:
7646 return "DW_CFA_register";
7647 case DW_CFA_remember_state:
7648 return "DW_CFA_remember_state";
7649 case DW_CFA_restore_state:
7650 return "DW_CFA_restore_state";
7651 case DW_CFA_def_cfa:
7652 return "DW_CFA_def_cfa";
7653 case DW_CFA_def_cfa_register:
7654 return "DW_CFA_def_cfa_register";
7655 case DW_CFA_def_cfa_offset:
7656 return "DW_CFA_def_cfa_offset";
7659 case DW_CFA_def_cfa_expression:
7660 return "DW_CFA_def_cfa_expression";
7661 case DW_CFA_expression:
7662 return "DW_CFA_expression";
7663 case DW_CFA_offset_extended_sf:
7664 return "DW_CFA_offset_extended_sf";
7665 case DW_CFA_def_cfa_sf:
7666 return "DW_CFA_def_cfa_sf";
7667 case DW_CFA_def_cfa_offset_sf:
7668 return "DW_CFA_def_cfa_offset_sf";
7670 /* SGI/MIPS specific */
7671 case DW_CFA_MIPS_advance_loc8:
7672 return "DW_CFA_MIPS_advance_loc8";
7674 /* GNU extensions */
7675 case DW_CFA_GNU_window_save:
7676 return "DW_CFA_GNU_window_save";
7677 case DW_CFA_GNU_args_size:
7678 return "DW_CFA_GNU_args_size";
7679 case DW_CFA_GNU_negative_offset_extended:
7680 return "DW_CFA_GNU_negative_offset_extended";
7683 return "DW_CFA_<unknown>";
7689 dump_die (struct die_info *die)
7693 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7694 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7695 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7696 dwarf_bool_name (die->child != NULL));
7698 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7699 for (i = 0; i < die->num_attrs; ++i)
7701 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7702 dwarf_attr_name (die->attrs[i].name),
7703 dwarf_form_name (die->attrs[i].form));
7704 switch (die->attrs[i].form)
7706 case DW_FORM_ref_addr:
7708 fprintf_unfiltered (gdb_stderr, "address: ");
7709 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7711 case DW_FORM_block2:
7712 case DW_FORM_block4:
7714 case DW_FORM_block1:
7715 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7726 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7728 case DW_FORM_string:
7730 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7731 DW_STRING (&die->attrs[i])
7732 ? DW_STRING (&die->attrs[i]) : "");
7735 if (DW_UNSND (&die->attrs[i]))
7736 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7738 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7740 case DW_FORM_indirect:
7741 /* the reader will have reduced the indirect form to
7742 the "base form" so this form should not occur */
7743 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7746 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7747 die->attrs[i].form);
7749 fprintf_unfiltered (gdb_stderr, "\n");
7754 dump_die_list (struct die_info *die)
7759 if (die->child != NULL)
7760 dump_die_list (die->child);
7761 if (die->sibling != NULL)
7762 dump_die_list (die->sibling);
7767 store_in_ref_table (unsigned int offset, struct die_info *die)
7770 struct die_info *old;
7772 h = (offset % REF_HASH_SIZE);
7773 old = die_ref_table[h];
7774 die->next_ref = old;
7775 die_ref_table[h] = die;
7780 dwarf2_empty_hash_tables (void)
7782 memset (die_ref_table, 0, sizeof (die_ref_table));
7786 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
7788 unsigned int result = 0;
7792 case DW_FORM_ref_addr:
7793 result = DW_ADDR (attr);
7799 case DW_FORM_ref_udata:
7800 result = cu->header.offset + DW_UNSND (attr);
7803 complaint (&symfile_complaints,
7804 "unsupported die ref attribute form: '%s'",
7805 dwarf_form_name (attr->form));
7810 /* Return the constant value held by the given attribute. Return -1
7811 if the value held by the attribute is not constant. */
7814 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7816 if (attr->form == DW_FORM_sdata)
7817 return DW_SND (attr);
7818 else if (attr->form == DW_FORM_udata
7819 || attr->form == DW_FORM_data1
7820 || attr->form == DW_FORM_data2
7821 || attr->form == DW_FORM_data4
7822 || attr->form == DW_FORM_data8)
7823 return DW_UNSND (attr);
7826 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
7827 dwarf_form_name (attr->form));
7828 return default_value;
7832 static struct die_info *
7833 follow_die_ref (unsigned int offset)
7835 struct die_info *die;
7838 h = (offset % REF_HASH_SIZE);
7839 die = die_ref_table[h];
7842 if (die->offset == offset)
7846 die = die->next_ref;
7851 static struct type *
7852 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
7853 struct dwarf2_cu *cu)
7855 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
7857 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7858 typeid, objfile->name);
7861 /* Look for this particular type in the fundamental type vector. If
7862 one is not found, create and install one appropriate for the
7863 current language and the current target machine. */
7865 if (cu->ftypes[typeid] == NULL)
7867 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
7870 return (cu->ftypes[typeid]);
7873 /* Decode simple location descriptions.
7874 Given a pointer to a dwarf block that defines a location, compute
7875 the location and return the value.
7877 NOTE drow/2003-11-18: This function is called in two situations
7878 now: for the address of static or global variables (partial symbols
7879 only) and for offsets into structures which are expected to be
7880 (more or less) constant. The partial symbol case should go away,
7881 and only the constant case should remain. That will let this
7882 function complain more accurately. A few special modes are allowed
7883 without complaint for global variables (for instance, global
7884 register values and thread-local values).
7886 A location description containing no operations indicates that the
7887 object is optimized out. The return value is 0 for that case.
7888 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7889 callers will only want a very basic result and this can become a
7892 When the result is a register number, the global isreg flag is set,
7893 otherwise it is cleared.
7895 Note that stack[0] is unused except as a default error return.
7896 Note that stack overflow is not yet handled. */
7899 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
7901 struct objfile *objfile = cu->objfile;
7902 struct comp_unit_head *cu_header = &cu->header;
7904 int size = blk->size;
7905 char *data = blk->data;
7906 CORE_ADDR stack[64];
7908 unsigned int bytes_read, unsnd;
7953 stack[++stacki] = op - DW_OP_lit0;
7989 stack[++stacki] = op - DW_OP_reg0;
7991 dwarf2_complex_location_expr_complaint ();
7996 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7998 stack[++stacki] = unsnd;
8000 dwarf2_complex_location_expr_complaint ();
8004 stack[++stacki] = read_address (objfile->obfd, &data[i],
8010 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
8015 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
8020 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
8025 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
8030 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
8035 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
8040 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
8046 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
8051 stack[stacki + 1] = stack[stacki];
8056 stack[stacki - 1] += stack[stacki];
8060 case DW_OP_plus_uconst:
8061 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8066 stack[stacki - 1] -= stack[stacki];
8071 /* If we're not the last op, then we definitely can't encode
8072 this using GDB's address_class enum. This is valid for partial
8073 global symbols, although the variable's address will be bogus
8076 dwarf2_complex_location_expr_complaint ();
8079 case DW_OP_GNU_push_tls_address:
8080 /* The top of the stack has the offset from the beginning
8081 of the thread control block at which the variable is located. */
8082 /* Nothing should follow this operator, so the top of stack would
8084 /* This is valid for partial global symbols, but the variable's
8085 address will be bogus in the psymtab. */
8087 dwarf2_complex_location_expr_complaint ();
8091 complaint (&symfile_complaints, "unsupported stack op: '%s'",
8092 dwarf_stack_op_name (op));
8093 return (stack[stacki]);
8096 return (stack[stacki]);
8099 /* memory allocation interface */
8102 dwarf2_free_tmp_obstack (void *ignore)
8104 obstack_free (&dwarf2_tmp_obstack, NULL);
8107 static struct dwarf_block *
8108 dwarf_alloc_block (void)
8110 struct dwarf_block *blk;
8112 blk = (struct dwarf_block *)
8113 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
8117 static struct abbrev_info *
8118 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
8120 struct abbrev_info *abbrev;
8122 abbrev = (struct abbrev_info *)
8123 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
8124 memset (abbrev, 0, sizeof (struct abbrev_info));
8128 static struct die_info *
8129 dwarf_alloc_die (void)
8131 struct die_info *die;
8133 die = (struct die_info *) xmalloc (sizeof (struct die_info));
8134 memset (die, 0, sizeof (struct die_info));
8139 /* Macro support. */
8142 /* Return the full name of file number I in *LH's file name table.
8143 Use COMP_DIR as the name of the current directory of the
8144 compilation. The result is allocated using xmalloc; the caller is
8145 responsible for freeing it. */
8147 file_full_name (int file, struct line_header *lh, const char *comp_dir)
8149 struct file_entry *fe = &lh->file_names[file - 1];
8151 if (IS_ABSOLUTE_PATH (fe->name))
8152 return xstrdup (fe->name);
8160 dir = lh->include_dirs[fe->dir_index - 1];
8166 dir_len = strlen (dir);
8167 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
8168 strcpy (full_name, dir);
8169 full_name[dir_len] = '/';
8170 strcpy (full_name + dir_len + 1, fe->name);
8174 return xstrdup (fe->name);
8179 static struct macro_source_file *
8180 macro_start_file (int file, int line,
8181 struct macro_source_file *current_file,
8182 const char *comp_dir,
8183 struct line_header *lh, struct objfile *objfile)
8185 /* The full name of this source file. */
8186 char *full_name = file_full_name (file, lh, comp_dir);
8188 /* We don't create a macro table for this compilation unit
8189 at all until we actually get a filename. */
8190 if (! pending_macros)
8191 pending_macros = new_macro_table (&objfile->objfile_obstack,
8192 objfile->macro_cache);
8195 /* If we have no current file, then this must be the start_file
8196 directive for the compilation unit's main source file. */
8197 current_file = macro_set_main (pending_macros, full_name);
8199 current_file = macro_include (current_file, line, full_name);
8203 return current_file;
8207 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8208 followed by a null byte. */
8210 copy_string (const char *buf, int len)
8212 char *s = xmalloc (len + 1);
8213 memcpy (s, buf, len);
8221 consume_improper_spaces (const char *p, const char *body)
8225 complaint (&symfile_complaints,
8226 "macro definition contains spaces in formal argument list:\n`%s'",
8238 parse_macro_definition (struct macro_source_file *file, int line,
8243 /* The body string takes one of two forms. For object-like macro
8244 definitions, it should be:
8246 <macro name> " " <definition>
8248 For function-like macro definitions, it should be:
8250 <macro name> "() " <definition>
8252 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8254 Spaces may appear only where explicitly indicated, and in the
8257 The Dwarf 2 spec says that an object-like macro's name is always
8258 followed by a space, but versions of GCC around March 2002 omit
8259 the space when the macro's definition is the empty string.
8261 The Dwarf 2 spec says that there should be no spaces between the
8262 formal arguments in a function-like macro's formal argument list,
8263 but versions of GCC around March 2002 include spaces after the
8267 /* Find the extent of the macro name. The macro name is terminated
8268 by either a space or null character (for an object-like macro) or
8269 an opening paren (for a function-like macro). */
8270 for (p = body; *p; p++)
8271 if (*p == ' ' || *p == '(')
8274 if (*p == ' ' || *p == '\0')
8276 /* It's an object-like macro. */
8277 int name_len = p - body;
8278 char *name = copy_string (body, name_len);
8279 const char *replacement;
8282 replacement = body + name_len + 1;
8285 dwarf2_macro_malformed_definition_complaint (body);
8286 replacement = body + name_len;
8289 macro_define_object (file, line, name, replacement);
8295 /* It's a function-like macro. */
8296 char *name = copy_string (body, p - body);
8299 char **argv = xmalloc (argv_size * sizeof (*argv));
8303 p = consume_improper_spaces (p, body);
8305 /* Parse the formal argument list. */
8306 while (*p && *p != ')')
8308 /* Find the extent of the current argument name. */
8309 const char *arg_start = p;
8311 while (*p && *p != ',' && *p != ')' && *p != ' ')
8314 if (! *p || p == arg_start)
8315 dwarf2_macro_malformed_definition_complaint (body);
8318 /* Make sure argv has room for the new argument. */
8319 if (argc >= argv_size)
8322 argv = xrealloc (argv, argv_size * sizeof (*argv));
8325 argv[argc++] = copy_string (arg_start, p - arg_start);
8328 p = consume_improper_spaces (p, body);
8330 /* Consume the comma, if present. */
8335 p = consume_improper_spaces (p, body);
8344 /* Perfectly formed definition, no complaints. */
8345 macro_define_function (file, line, name,
8346 argc, (const char **) argv,
8348 else if (*p == '\0')
8350 /* Complain, but do define it. */
8351 dwarf2_macro_malformed_definition_complaint (body);
8352 macro_define_function (file, line, name,
8353 argc, (const char **) argv,
8357 /* Just complain. */
8358 dwarf2_macro_malformed_definition_complaint (body);
8361 /* Just complain. */
8362 dwarf2_macro_malformed_definition_complaint (body);
8368 for (i = 0; i < argc; i++)
8374 dwarf2_macro_malformed_definition_complaint (body);
8379 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
8380 char *comp_dir, bfd *abfd,
8381 struct dwarf2_cu *cu)
8383 char *mac_ptr, *mac_end;
8384 struct macro_source_file *current_file = 0;
8386 if (dwarf2_per_objfile->macinfo_buffer == NULL)
8388 complaint (&symfile_complaints, "missing .debug_macinfo section");
8392 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
8393 mac_end = dwarf2_per_objfile->macinfo_buffer
8394 + dwarf2_per_objfile->macinfo_size;
8398 enum dwarf_macinfo_record_type macinfo_type;
8400 /* Do we at least have room for a macinfo type byte? */
8401 if (mac_ptr >= mac_end)
8403 dwarf2_macros_too_long_complaint ();
8407 macinfo_type = read_1_byte (abfd, mac_ptr);
8410 switch (macinfo_type)
8412 /* A zero macinfo type indicates the end of the macro
8417 case DW_MACINFO_define:
8418 case DW_MACINFO_undef:
8424 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8425 mac_ptr += bytes_read;
8426 body = read_string (abfd, mac_ptr, &bytes_read);
8427 mac_ptr += bytes_read;
8430 complaint (&symfile_complaints,
8431 "debug info gives macro %s outside of any file: %s",
8433 DW_MACINFO_define ? "definition" : macinfo_type ==
8434 DW_MACINFO_undef ? "undefinition" :
8435 "something-or-other", body);
8438 if (macinfo_type == DW_MACINFO_define)
8439 parse_macro_definition (current_file, line, body);
8440 else if (macinfo_type == DW_MACINFO_undef)
8441 macro_undef (current_file, line, body);
8446 case DW_MACINFO_start_file:
8451 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8452 mac_ptr += bytes_read;
8453 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8454 mac_ptr += bytes_read;
8456 current_file = macro_start_file (file, line,
8457 current_file, comp_dir,
8462 case DW_MACINFO_end_file:
8464 complaint (&symfile_complaints,
8465 "macro debug info has an unmatched `close_file' directive");
8468 current_file = current_file->included_by;
8471 enum dwarf_macinfo_record_type next_type;
8473 /* GCC circa March 2002 doesn't produce the zero
8474 type byte marking the end of the compilation
8475 unit. Complain if it's not there, but exit no
8478 /* Do we at least have room for a macinfo type byte? */
8479 if (mac_ptr >= mac_end)
8481 dwarf2_macros_too_long_complaint ();
8485 /* We don't increment mac_ptr here, so this is just
8487 next_type = read_1_byte (abfd, mac_ptr);
8489 complaint (&symfile_complaints,
8490 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8497 case DW_MACINFO_vendor_ext:
8503 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8504 mac_ptr += bytes_read;
8505 string = read_string (abfd, mac_ptr, &bytes_read);
8506 mac_ptr += bytes_read;
8508 /* We don't recognize any vendor extensions. */
8515 /* Check if the attribute's form is a DW_FORM_block*
8516 if so return true else false. */
8518 attr_form_is_block (struct attribute *attr)
8520 return (attr == NULL ? 0 :
8521 attr->form == DW_FORM_block1
8522 || attr->form == DW_FORM_block2
8523 || attr->form == DW_FORM_block4
8524 || attr->form == DW_FORM_block);
8528 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
8529 struct dwarf2_cu *cu)
8531 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8533 struct dwarf2_loclist_baton *baton;
8535 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8536 sizeof (struct dwarf2_loclist_baton));
8537 baton->objfile = cu->objfile;
8539 /* We don't know how long the location list is, but make sure we
8540 don't run off the edge of the section. */
8541 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
8542 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
8543 baton->base_address = cu->header.base_address;
8544 if (cu->header.base_known == 0)
8545 complaint (&symfile_complaints,
8546 "Location list used without specifying the CU base address.");
8548 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8549 SYMBOL_LOCATION_BATON (sym) = baton;
8553 struct dwarf2_locexpr_baton *baton;
8555 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8556 sizeof (struct dwarf2_locexpr_baton));
8557 baton->objfile = cu->objfile;
8559 if (attr_form_is_block (attr))
8561 /* Note that we're just copying the block's data pointer
8562 here, not the actual data. We're still pointing into the
8563 info_buffer for SYM's objfile; right now we never release
8564 that buffer, but when we do clean up properly this may
8566 baton->size = DW_BLOCK (attr)->size;
8567 baton->data = DW_BLOCK (attr)->data;
8571 dwarf2_invalid_attrib_class_complaint ("location description",
8572 SYMBOL_NATURAL_NAME (sym));
8577 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8578 SYMBOL_LOCATION_BATON (sym) = baton;
8582 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8583 when we're finished with it. We can't free the pointer itself, but
8584 release any associated storage.
8586 Only used during partial symbol parsing. */
8589 free_stack_comp_unit (void *data)
8591 struct dwarf2_cu *cu = data;
8593 obstack_free (&cu->comp_unit_obstack, NULL);
8594 cu->partial_dies = NULL;
8597 /* Allocation function for the libiberty hash table which uses an
8601 hashtab_obstack_allocate (void *data, size_t size, size_t count)
8603 unsigned int total = size * count;
8604 void *ptr = obstack_alloc ((struct obstack *) data, total);
8605 memset (ptr, 0, total);
8609 /* Trivial deallocation function for the libiberty splay tree and hash
8610 table - don't deallocate anything. Rely on later deletion of the
8614 dummy_obstack_deallocate (void *object, void *data)
8619 /* Trivial hash function for partial_die_info: the hash value of a DIE
8620 is its offset in .debug_info for this objfile. */
8623 partial_die_hash (const void *item)
8625 const struct partial_die_info *part_die = item;
8626 return part_die->offset;
8629 /* Trivial comparison function for partial_die_info structures: two DIEs
8630 are equal if they have the same offset. */
8633 partial_die_eq (const void *item_lhs, const void *item_rhs)
8635 const struct partial_die_info *part_die_lhs = item_lhs;
8636 const struct partial_die_info *part_die_rhs = item_rhs;
8637 return part_die_lhs->offset == part_die_rhs->offset;
8640 void _initialize_dwarf2_read (void);
8643 _initialize_dwarf2_read (void)
8645 dwarf2_objfile_data_key = register_objfile_data ();