1 /* DWARF 2 debugging format support for GDB.
3 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 support in dwarfread.c
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or (at
19 your option) any later version.
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
53 #include "gdb_string.h"
54 #include "gdb_assert.h"
55 #include <sys/types.h>
57 /* A note on memory usage for this file.
59 At the present time, this code reads the debug info sections into
60 the objfile's objfile_obstack. A definite improvement for startup
61 time, on platforms which do not emit relocations for debug
62 sections, would be to use mmap instead. The object's complete
63 debug information is loaded into memory, partly to simplify
64 absolute DIE references.
66 Whether using obstacks or mmap, the sections should remain loaded
67 until the objfile is released, and pointers into the section data
68 can be used for any other data associated to the objfile (symbol
69 names, type names, location expressions to name a few). */
71 #ifndef DWARF2_REG_TO_REGNUM
72 #define DWARF2_REG_TO_REGNUM(REG) (REG)
76 /* .debug_info header for a compilation unit
77 Because of alignment constraints, this structure has padding and cannot
78 be mapped directly onto the beginning of the .debug_info section. */
79 typedef struct comp_unit_header
81 unsigned int length; /* length of the .debug_info
83 unsigned short version; /* version number -- 2 for DWARF
85 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
86 unsigned char addr_size; /* byte size of an address -- 4 */
89 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
92 /* .debug_pubnames header
93 Because of alignment constraints, this structure has padding and cannot
94 be mapped directly onto the beginning of the .debug_info section. */
95 typedef struct pubnames_header
97 unsigned int length; /* length of the .debug_pubnames
99 unsigned char version; /* version number -- 2 for DWARF
101 unsigned int info_offset; /* offset into .debug_info section */
102 unsigned int info_size; /* byte size of .debug_info section
106 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
108 /* .debug_pubnames header
109 Because of alignment constraints, this structure has padding and cannot
110 be mapped directly onto the beginning of the .debug_info section. */
111 typedef struct aranges_header
113 unsigned int length; /* byte len of the .debug_aranges
115 unsigned short version; /* version number -- 2 for DWARF
117 unsigned int info_offset; /* offset into .debug_info section */
118 unsigned char addr_size; /* byte size of an address */
119 unsigned char seg_size; /* byte size of segment descriptor */
122 #define _ACTUAL_ARANGES_HEADER_SIZE 12
124 /* .debug_line statement program prologue
125 Because of alignment constraints, this structure has padding and cannot
126 be mapped directly onto the beginning of the .debug_info section. */
127 typedef struct statement_prologue
129 unsigned int total_length; /* byte length of the statement
131 unsigned short version; /* version number -- 2 for DWARF
133 unsigned int prologue_length; /* # bytes between prologue &
135 unsigned char minimum_instruction_length; /* byte size of
137 unsigned char default_is_stmt; /* initial value of is_stmt
140 unsigned char line_range;
141 unsigned char opcode_base; /* number assigned to first special
143 unsigned char *standard_opcode_lengths;
147 static const struct objfile_data *dwarf2_objfile_data_key;
149 struct dwarf2_per_objfile
151 /* Sizes of debugging sections. */
152 unsigned int info_size;
153 unsigned int abbrev_size;
154 unsigned int line_size;
155 unsigned int pubnames_size;
156 unsigned int aranges_size;
157 unsigned int loc_size;
158 unsigned int macinfo_size;
159 unsigned int str_size;
160 unsigned int ranges_size;
161 unsigned int frame_size;
162 unsigned int eh_frame_size;
164 /* Loaded data from the sections. */
169 char *macinfo_buffer;
173 /* A list of all the compilation units. This is used to locate
174 the target compilation unit of a particular reference. */
175 struct dwarf2_per_cu_data **all_comp_units;
177 /* The number of compilation units in ALL_COMP_UNITS. */
180 /* A chain of compilation units that are currently read in, so that
181 they can be freed later. */
182 struct dwarf2_per_cu_data *read_in_chain;
185 static struct dwarf2_per_objfile *dwarf2_per_objfile;
187 static asection *dwarf_info_section;
188 static asection *dwarf_abbrev_section;
189 static asection *dwarf_line_section;
190 static asection *dwarf_pubnames_section;
191 static asection *dwarf_aranges_section;
192 static asection *dwarf_loc_section;
193 static asection *dwarf_macinfo_section;
194 static asection *dwarf_str_section;
195 static asection *dwarf_ranges_section;
196 asection *dwarf_frame_section;
197 asection *dwarf_eh_frame_section;
199 /* names of the debugging sections */
201 #define INFO_SECTION ".debug_info"
202 #define ABBREV_SECTION ".debug_abbrev"
203 #define LINE_SECTION ".debug_line"
204 #define PUBNAMES_SECTION ".debug_pubnames"
205 #define ARANGES_SECTION ".debug_aranges"
206 #define LOC_SECTION ".debug_loc"
207 #define MACINFO_SECTION ".debug_macinfo"
208 #define STR_SECTION ".debug_str"
209 #define RANGES_SECTION ".debug_ranges"
210 #define FRAME_SECTION ".debug_frame"
211 #define EH_FRAME_SECTION ".eh_frame"
213 /* local data types */
215 /* We hold several abbreviation tables in memory at the same time. */
216 #ifndef ABBREV_HASH_SIZE
217 #define ABBREV_HASH_SIZE 121
220 /* The data in a compilation unit header, after target2host
221 translation, looks like this. */
222 struct comp_unit_head
224 unsigned long length;
226 unsigned int abbrev_offset;
227 unsigned char addr_size;
228 unsigned char signed_addr_p;
230 /* Size of file offsets; either 4 or 8. */
231 unsigned int offset_size;
233 /* Size of the length field; either 4 or 12. */
234 unsigned int initial_length_size;
236 /* Offset to the first byte of this compilation unit header in the
237 .debug_info section, for resolving relative reference dies. */
240 /* Pointer to this compilation unit header in the .debug_info
244 /* Pointer to the first die of this compilation unit. This will be
245 the first byte following the compilation unit header. */
248 /* Pointer to the next compilation unit header in the program. */
249 struct comp_unit_head *next;
251 /* Base address of this compilation unit. */
252 CORE_ADDR base_address;
254 /* Non-zero if base_address has been set. */
258 /* Fixed size for the DIE hash table. */
259 #ifndef REF_HASH_SIZE
260 #define REF_HASH_SIZE 1021
263 /* Internal state when decoding a particular compilation unit. */
266 /* The objfile containing this compilation unit. */
267 struct objfile *objfile;
269 /* The header of the compilation unit.
271 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
272 should logically be moved to the dwarf2_cu structure. */
273 struct comp_unit_head header;
275 struct function_range *first_fn, *last_fn, *cached_fn;
277 /* The language we are debugging. */
278 enum language language;
279 const struct language_defn *language_defn;
281 const char *producer;
283 /* The generic symbol table building routines have separate lists for
284 file scope symbols and all all other scopes (local scopes). So
285 we need to select the right one to pass to add_symbol_to_list().
286 We do it by keeping a pointer to the correct list in list_in_scope.
288 FIXME: The original dwarf code just treated the file scope as the
289 first local scope, and all other local scopes as nested local
290 scopes, and worked fine. Check to see if we really need to
291 distinguish these in buildsym.c. */
292 struct pending **list_in_scope;
294 /* Maintain an array of referenced fundamental types for the current
295 compilation unit being read. For DWARF version 1, we have to construct
296 the fundamental types on the fly, since no information about the
297 fundamental types is supplied. Each such fundamental type is created by
298 calling a language dependent routine to create the type, and then a
299 pointer to that type is then placed in the array at the index specified
300 by it's FT_<TYPENAME> value. The array has a fixed size set by the
301 FT_NUM_MEMBERS compile time constant, which is the number of predefined
302 fundamental types gdb knows how to construct. */
303 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
305 /* DWARF abbreviation table associated with this compilation unit. */
306 struct abbrev_info **dwarf2_abbrevs;
308 /* Storage for the abbrev table. */
309 struct obstack abbrev_obstack;
311 /* Hash table holding all the loaded partial DIEs. */
314 /* Storage for things with the same lifetime as this read-in compilation
315 unit, including partial DIEs. */
316 struct obstack comp_unit_obstack;
318 /* When multiple dwarf2_cu structures are living in memory, this field
319 chains them all together, so that they can be released efficiently.
320 We will probably also want a generation counter so that most-recently-used
321 compilation units are cached... */
322 struct dwarf2_per_cu_data *read_in_chain;
324 /* Backchain to our per_cu entry if the tree has been built. */
325 struct dwarf2_per_cu_data *per_cu;
327 /* How many compilation units ago was this CU last referenced? */
330 /* A hash table of die offsets for following references. */
331 struct die_info *die_ref_table[REF_HASH_SIZE];
333 /* Full DIEs if read in. */
334 struct die_info *dies;
336 /* A set of pointers to dwarf2_per_cu_data objects for compilation
337 units referenced by this one. Only set during full symbol processing;
338 partial symbol tables do not have dependencies. */
341 /* Mark used when releasing cached dies. */
342 unsigned int mark : 1;
344 /* This flag will be set if this compilation unit might include
345 inter-compilation-unit references. */
346 unsigned int has_form_ref_addr : 1;
348 /* This flag will be set if this compilation unit includes any
349 DW_TAG_namespace DIEs. If we know that there are explicit
350 DIEs for namespaces, we don't need to try to infer them
351 from mangled names. */
352 unsigned int has_namespace_info : 1;
355 /* Persistent data held for a compilation unit, even when not
356 processing it. We put a pointer to this structure in the
357 read_symtab_private field of the psymtab. If we encounter
358 inter-compilation-unit references, we also maintain a sorted
359 list of all compilation units. */
361 struct dwarf2_per_cu_data
363 /* The start offset and length of this compilation unit. 2**31-1
364 bytes should suffice to store the length of any compilation unit
365 - if it doesn't, GDB will fall over anyway. */
366 unsigned long offset;
367 unsigned long length : 31;
369 /* Flag indicating this compilation unit will be read in before
370 any of the current compilation units are processed. */
371 unsigned long queued : 1;
373 /* Set iff currently read in. */
374 struct dwarf2_cu *cu;
376 /* If full symbols for this CU have been read in, then this field
377 holds a map of DIE offsets to types. It isn't always possible
378 to reconstruct this information later, so we have to preserve
382 /* The partial symbol table associated with this compilation unit. */
383 struct partial_symtab *psymtab;
386 /* The line number information for a compilation unit (found in the
387 .debug_line section) begins with a "statement program header",
388 which contains the following information. */
391 unsigned int total_length;
392 unsigned short version;
393 unsigned int header_length;
394 unsigned char minimum_instruction_length;
395 unsigned char default_is_stmt;
397 unsigned char line_range;
398 unsigned char opcode_base;
400 /* standard_opcode_lengths[i] is the number of operands for the
401 standard opcode whose value is i. This means that
402 standard_opcode_lengths[0] is unused, and the last meaningful
403 element is standard_opcode_lengths[opcode_base - 1]. */
404 unsigned char *standard_opcode_lengths;
406 /* The include_directories table. NOTE! These strings are not
407 allocated with xmalloc; instead, they are pointers into
408 debug_line_buffer. If you try to free them, `free' will get
410 unsigned int num_include_dirs, include_dirs_size;
413 /* The file_names table. NOTE! These strings are not allocated
414 with xmalloc; instead, they are pointers into debug_line_buffer.
415 Don't try to free them directly. */
416 unsigned int num_file_names, file_names_size;
420 unsigned int dir_index;
421 unsigned int mod_time;
423 int included_p; /* Non-zero if referenced by the Line Number Program. */
426 /* The start and end of the statement program following this
427 header. These point into dwarf2_per_objfile->line_buffer. */
428 char *statement_program_start, *statement_program_end;
431 /* When we construct a partial symbol table entry we only
432 need this much information. */
433 struct partial_die_info
435 /* Offset of this DIE. */
438 /* DWARF-2 tag for this DIE. */
439 ENUM_BITFIELD(dwarf_tag) tag : 16;
441 /* Language code associated with this DIE. This is only used
442 for the compilation unit DIE. */
443 unsigned int language : 8;
445 /* Assorted flags describing the data found in this DIE. */
446 unsigned int has_children : 1;
447 unsigned int is_external : 1;
448 unsigned int is_declaration : 1;
449 unsigned int has_type : 1;
450 unsigned int has_specification : 1;
451 unsigned int has_stmt_list : 1;
452 unsigned int has_pc_info : 1;
454 /* Flag set if the SCOPE field of this structure has been
456 unsigned int scope_set : 1;
458 /* The name of this DIE. Normally the value of DW_AT_name, but
459 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
464 /* The scope to prepend to our children. This is generally
465 allocated on the comp_unit_obstack, so will disappear
466 when this compilation unit leaves the cache. */
469 /* The location description associated with this DIE, if any. */
470 struct dwarf_block *locdesc;
472 /* If HAS_PC_INFO, the PC range associated with this DIE. */
476 /* Pointer into the info_buffer pointing at the target of
477 DW_AT_sibling, if any. */
480 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
481 DW_AT_specification (or DW_AT_abstract_origin or
483 unsigned int spec_offset;
485 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
486 unsigned int line_offset;
488 /* Pointers to this DIE's parent, first child, and next sibling,
490 struct partial_die_info *die_parent, *die_child, *die_sibling;
493 /* This data structure holds the information of an abbrev. */
496 unsigned int number; /* number identifying abbrev */
497 enum dwarf_tag tag; /* dwarf tag */
498 unsigned short has_children; /* boolean */
499 unsigned short num_attrs; /* number of attributes */
500 struct attr_abbrev *attrs; /* an array of attribute descriptions */
501 struct abbrev_info *next; /* next in chain */
506 enum dwarf_attribute name;
507 enum dwarf_form form;
510 /* This data structure holds a complete die structure. */
513 enum dwarf_tag tag; /* Tag indicating type of die */
514 unsigned int abbrev; /* Abbrev number */
515 unsigned int offset; /* Offset in .debug_info section */
516 unsigned int num_attrs; /* Number of attributes */
517 struct attribute *attrs; /* An array of attributes */
518 struct die_info *next_ref; /* Next die in ref hash table */
520 /* The dies in a compilation unit form an n-ary tree. PARENT
521 points to this die's parent; CHILD points to the first child of
522 this node; and all the children of a given node are chained
523 together via their SIBLING fields, terminated by a die whose
525 struct die_info *child; /* Its first child, if any. */
526 struct die_info *sibling; /* Its next sibling, if any. */
527 struct die_info *parent; /* Its parent, if any. */
529 struct type *type; /* Cached type information */
532 /* Attributes have a name and a value */
535 enum dwarf_attribute name;
536 enum dwarf_form form;
540 struct dwarf_block *blk;
548 struct function_range
551 CORE_ADDR lowpc, highpc;
553 struct function_range *next;
556 /* Get at parts of an attribute structure */
558 #define DW_STRING(attr) ((attr)->u.str)
559 #define DW_UNSND(attr) ((attr)->u.unsnd)
560 #define DW_BLOCK(attr) ((attr)->u.blk)
561 #define DW_SND(attr) ((attr)->u.snd)
562 #define DW_ADDR(attr) ((attr)->u.addr)
564 /* Blocks are a bunch of untyped bytes. */
571 #ifndef ATTR_ALLOC_CHUNK
572 #define ATTR_ALLOC_CHUNK 4
575 /* Allocate fields for structs, unions and enums in this size. */
576 #ifndef DW_FIELD_ALLOC_CHUNK
577 #define DW_FIELD_ALLOC_CHUNK 4
580 /* A zeroed version of a partial die for initialization purposes. */
581 static struct partial_die_info zeroed_partial_die;
583 /* FIXME: decode_locdesc sets these variables to describe the location
584 to the caller. These ought to be a structure or something. If
585 none of the flags are set, the object lives at the address returned
586 by decode_locdesc. */
588 static int isreg; /* Object lives in register.
589 decode_locdesc's return value is
590 the register number. */
592 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
593 but this would require a corresponding change in unpack_field_as_long
595 static int bits_per_byte = 8;
597 /* The routines that read and process dies for a C struct or C++ class
598 pass lists of data member fields and lists of member function fields
599 in an instance of a field_info structure, as defined below. */
602 /* List of data member and baseclasses fields. */
605 struct nextfield *next;
612 /* Number of fields. */
615 /* Number of baseclasses. */
618 /* Set if the accesibility of one of the fields is not public. */
619 int non_public_fields;
621 /* Member function fields array, entries are allocated in the order they
622 are encountered in the object file. */
625 struct nextfnfield *next;
626 struct fn_field fnfield;
630 /* Member function fieldlist array, contains name of possibly overloaded
631 member function, number of overloaded member functions and a pointer
632 to the head of the member function field chain. */
637 struct nextfnfield *head;
641 /* Number of entries in the fnfieldlists array. */
645 /* One item on the queue of compilation units to read in full symbols
647 struct dwarf2_queue_item
649 struct dwarf2_per_cu_data *per_cu;
650 struct dwarf2_queue_item *next;
653 /* The current queue. */
654 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
656 /* Loaded secondary compilation units are kept in memory until they
657 have not been referenced for the processing of this many
658 compilation units. Set this to zero to disable caching. Cache
659 sizes of up to at least twenty will improve startup time for
660 typical inter-CU-reference binaries, at an obvious memory cost. */
661 static int dwarf2_max_cache_age = 5;
663 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
664 struct cmd_list_element *c, const char *value)
666 fprintf_filtered (file, _("\
667 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
672 /* Various complaints about symbol reading that don't abort the process */
675 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
677 complaint (&symfile_complaints,
678 _("statement list doesn't fit in .debug_line section"));
682 dwarf2_complex_location_expr_complaint (void)
684 complaint (&symfile_complaints, _("location expression too complex"));
688 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
691 complaint (&symfile_complaints,
692 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
697 dwarf2_macros_too_long_complaint (void)
699 complaint (&symfile_complaints,
700 _("macro info runs off end of `.debug_macinfo' section"));
704 dwarf2_macro_malformed_definition_complaint (const char *arg1)
706 complaint (&symfile_complaints,
707 _("macro debug info contains a malformed macro definition:\n`%s'"),
712 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
714 complaint (&symfile_complaints,
715 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
718 /* local function prototypes */
720 static void dwarf2_locate_sections (bfd *, asection *, void *);
723 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
726 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
729 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
730 struct partial_die_info *,
731 struct partial_symtab *);
733 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
735 static void scan_partial_symbols (struct partial_die_info *,
736 CORE_ADDR *, CORE_ADDR *,
739 static void add_partial_symbol (struct partial_die_info *,
742 static int pdi_needs_namespace (enum dwarf_tag tag);
744 static void add_partial_namespace (struct partial_die_info *pdi,
745 CORE_ADDR *lowpc, CORE_ADDR *highpc,
746 struct dwarf2_cu *cu);
748 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
749 struct dwarf2_cu *cu);
751 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
754 struct dwarf2_cu *cu);
756 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
758 static void psymtab_to_symtab_1 (struct partial_symtab *);
760 char *dwarf2_read_section (struct objfile *, asection *);
762 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
764 static void dwarf2_free_abbrev_table (void *);
766 static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *);
768 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
771 static struct partial_die_info *load_partial_dies (bfd *, char *, int,
774 static char *read_partial_die (struct partial_die_info *,
775 struct abbrev_info *abbrev, unsigned int,
776 bfd *, char *, struct dwarf2_cu *);
778 static struct partial_die_info *find_partial_die (unsigned long,
781 static void fixup_partial_die (struct partial_die_info *,
784 static char *read_full_die (struct die_info **, bfd *, char *,
785 struct dwarf2_cu *, int *);
787 static char *read_attribute (struct attribute *, struct attr_abbrev *,
788 bfd *, char *, struct dwarf2_cu *);
790 static char *read_attribute_value (struct attribute *, unsigned,
791 bfd *, char *, struct dwarf2_cu *);
793 static unsigned int read_1_byte (bfd *, char *);
795 static int read_1_signed_byte (bfd *, char *);
797 static unsigned int read_2_bytes (bfd *, char *);
799 static unsigned int read_4_bytes (bfd *, char *);
801 static unsigned long read_8_bytes (bfd *, char *);
803 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
806 static LONGEST read_initial_length (bfd *, char *,
807 struct comp_unit_head *, int *bytes_read);
809 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
812 static char *read_n_bytes (bfd *, char *, unsigned int);
814 static char *read_string (bfd *, char *, unsigned int *);
816 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
819 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
821 static long read_signed_leb128 (bfd *, char *, unsigned int *);
823 static char *skip_leb128 (bfd *, char *);
825 static void set_cu_language (unsigned int, struct dwarf2_cu *);
827 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
830 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
831 struct dwarf2_cu *cu);
833 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
835 static struct die_info *die_specification (struct die_info *die,
838 static void free_line_header (struct line_header *lh);
840 static void add_file_name (struct line_header *, char *, unsigned int,
841 unsigned int, unsigned int);
843 static struct line_header *(dwarf_decode_line_header
844 (unsigned int offset,
845 bfd *abfd, struct dwarf2_cu *cu));
847 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
848 struct dwarf2_cu *, struct partial_symtab *);
850 static void dwarf2_start_subfile (char *, char *);
852 static struct symbol *new_symbol (struct die_info *, struct type *,
855 static void dwarf2_const_value (struct attribute *, struct symbol *,
858 static void dwarf2_const_value_data (struct attribute *attr,
862 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
864 static struct type *die_containing_type (struct die_info *,
867 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
869 static void read_type_die (struct die_info *, struct dwarf2_cu *);
871 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
873 static char *typename_concat (struct obstack *, const char *prefix, const char *suffix,
876 static void read_typedef (struct die_info *, struct dwarf2_cu *);
878 static void read_base_type (struct die_info *, struct dwarf2_cu *);
880 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
882 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
884 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
886 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
888 static int dwarf2_get_pc_bounds (struct die_info *,
889 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
891 static void get_scope_pc_bounds (struct die_info *,
892 CORE_ADDR *, CORE_ADDR *,
895 static void dwarf2_add_field (struct field_info *, struct die_info *,
898 static void dwarf2_attach_fields_to_type (struct field_info *,
899 struct type *, struct dwarf2_cu *);
901 static void dwarf2_add_member_fn (struct field_info *,
902 struct die_info *, struct type *,
905 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
906 struct type *, struct dwarf2_cu *);
908 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
910 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
912 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
914 static void read_common_block (struct die_info *, struct dwarf2_cu *);
916 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
918 static const char *namespace_name (struct die_info *die,
919 int *is_anonymous, struct dwarf2_cu *);
921 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
923 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
925 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
927 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
929 static void read_array_type (struct die_info *, struct dwarf2_cu *);
931 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
934 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
936 static void read_tag_ptr_to_member_type (struct die_info *,
939 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
941 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
943 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
945 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
947 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
949 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
951 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
954 struct die_info *parent);
956 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
959 struct die_info *parent);
961 static void free_die_list (struct die_info *);
963 static void process_die (struct die_info *, struct dwarf2_cu *);
965 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
967 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
969 static struct die_info *dwarf2_extension (struct die_info *die,
972 static char *dwarf_tag_name (unsigned int);
974 static char *dwarf_attr_name (unsigned int);
976 static char *dwarf_form_name (unsigned int);
978 static char *dwarf_stack_op_name (unsigned int);
980 static char *dwarf_bool_name (unsigned int);
982 static char *dwarf_type_encoding_name (unsigned int);
985 static char *dwarf_cfi_name (unsigned int);
987 struct die_info *copy_die (struct die_info *);
990 static struct die_info *sibling_die (struct die_info *);
992 static void dump_die (struct die_info *);
994 static void dump_die_list (struct die_info *);
996 static void store_in_ref_table (unsigned int, struct die_info *,
999 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
1000 struct dwarf2_cu *);
1002 static int dwarf2_get_attr_constant_value (struct attribute *, int);
1004 static struct die_info *follow_die_ref (struct die_info *,
1006 struct dwarf2_cu *);
1008 static struct type *dwarf2_fundamental_type (struct objfile *, int,
1009 struct dwarf2_cu *);
1011 /* memory allocation interface */
1013 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1015 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1017 static struct die_info *dwarf_alloc_die (void);
1019 static void initialize_cu_func_list (struct dwarf2_cu *);
1021 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1022 struct dwarf2_cu *);
1024 static void dwarf_decode_macros (struct line_header *, unsigned int,
1025 char *, bfd *, struct dwarf2_cu *);
1027 static int attr_form_is_block (struct attribute *);
1030 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
1031 struct dwarf2_cu *cu);
1033 static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
1034 struct dwarf2_cu *cu);
1036 static void free_stack_comp_unit (void *);
1038 static void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
1040 static void dummy_obstack_deallocate (void *object, void *data);
1042 static hashval_t partial_die_hash (const void *item);
1044 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1046 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1047 (unsigned long offset, struct objfile *objfile);
1049 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1050 (unsigned long offset, struct objfile *objfile);
1052 static void free_one_comp_unit (void *);
1054 static void free_cached_comp_units (void *);
1056 static void age_cached_comp_units (void);
1058 static void free_one_cached_comp_unit (void *);
1060 static void set_die_type (struct die_info *, struct type *,
1061 struct dwarf2_cu *);
1063 static void reset_die_and_siblings_types (struct die_info *,
1064 struct dwarf2_cu *);
1066 static void create_all_comp_units (struct objfile *);
1068 static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *);
1070 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1072 static void dwarf2_add_dependence (struct dwarf2_cu *,
1073 struct dwarf2_per_cu_data *);
1075 static void dwarf2_mark (struct dwarf2_cu *);
1077 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1079 /* Try to locate the sections we need for DWARF 2 debugging
1080 information and return true if we have enough to do something. */
1083 dwarf2_has_info (struct objfile *objfile)
1085 struct dwarf2_per_objfile *data;
1087 /* Initialize per-objfile state. */
1088 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1089 memset (data, 0, sizeof (*data));
1090 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1091 dwarf2_per_objfile = data;
1093 dwarf_info_section = 0;
1094 dwarf_abbrev_section = 0;
1095 dwarf_line_section = 0;
1096 dwarf_str_section = 0;
1097 dwarf_macinfo_section = 0;
1098 dwarf_frame_section = 0;
1099 dwarf_eh_frame_section = 0;
1100 dwarf_ranges_section = 0;
1101 dwarf_loc_section = 0;
1103 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1104 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
1107 /* This function is mapped across the sections and remembers the
1108 offset and size of each of the debugging sections we are interested
1112 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
1114 if (strcmp (sectp->name, INFO_SECTION) == 0)
1116 dwarf2_per_objfile->info_size = bfd_get_section_size (sectp);
1117 dwarf_info_section = sectp;
1119 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
1121 dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp);
1122 dwarf_abbrev_section = sectp;
1124 else if (strcmp (sectp->name, LINE_SECTION) == 0)
1126 dwarf2_per_objfile->line_size = bfd_get_section_size (sectp);
1127 dwarf_line_section = sectp;
1129 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
1131 dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp);
1132 dwarf_pubnames_section = sectp;
1134 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
1136 dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp);
1137 dwarf_aranges_section = sectp;
1139 else if (strcmp (sectp->name, LOC_SECTION) == 0)
1141 dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp);
1142 dwarf_loc_section = sectp;
1144 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
1146 dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp);
1147 dwarf_macinfo_section = sectp;
1149 else if (strcmp (sectp->name, STR_SECTION) == 0)
1151 dwarf2_per_objfile->str_size = bfd_get_section_size (sectp);
1152 dwarf_str_section = sectp;
1154 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1156 dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp);
1157 dwarf_frame_section = sectp;
1159 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1161 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1162 if (aflag & SEC_HAS_CONTENTS)
1164 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp);
1165 dwarf_eh_frame_section = sectp;
1168 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1170 dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
1171 dwarf_ranges_section = sectp;
1175 /* Build a partial symbol table. */
1178 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1180 /* We definitely need the .debug_info and .debug_abbrev sections */
1182 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1183 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1185 if (dwarf_line_section)
1186 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1188 dwarf2_per_objfile->line_buffer = NULL;
1190 if (dwarf_str_section)
1191 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1193 dwarf2_per_objfile->str_buffer = NULL;
1195 if (dwarf_macinfo_section)
1196 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1197 dwarf_macinfo_section);
1199 dwarf2_per_objfile->macinfo_buffer = NULL;
1201 if (dwarf_ranges_section)
1202 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1204 dwarf2_per_objfile->ranges_buffer = NULL;
1206 if (dwarf_loc_section)
1207 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1209 dwarf2_per_objfile->loc_buffer = NULL;
1212 || (objfile->global_psymbols.size == 0
1213 && objfile->static_psymbols.size == 0))
1215 init_psymbol_list (objfile, 1024);
1219 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1221 /* Things are significantly easier if we have .debug_aranges and
1222 .debug_pubnames sections */
1224 dwarf2_build_psymtabs_easy (objfile, mainline);
1228 /* only test this case for now */
1230 /* In this case we have to work a bit harder */
1231 dwarf2_build_psymtabs_hard (objfile, mainline);
1236 /* Build the partial symbol table from the information in the
1237 .debug_pubnames and .debug_aranges sections. */
1240 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1242 bfd *abfd = objfile->obfd;
1243 char *aranges_buffer, *pubnames_buffer;
1244 char *aranges_ptr, *pubnames_ptr;
1245 unsigned int entry_length, version, info_offset, info_size;
1247 pubnames_buffer = dwarf2_read_section (objfile,
1248 dwarf_pubnames_section);
1249 pubnames_ptr = pubnames_buffer;
1250 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1252 struct comp_unit_head cu_header;
1255 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1257 pubnames_ptr += bytes_read;
1258 version = read_1_byte (abfd, pubnames_ptr);
1260 info_offset = read_4_bytes (abfd, pubnames_ptr);
1262 info_size = read_4_bytes (abfd, pubnames_ptr);
1266 aranges_buffer = dwarf2_read_section (objfile,
1267 dwarf_aranges_section);
1272 /* Read in the comp unit header information from the debug_info at
1276 read_comp_unit_head (struct comp_unit_head *cu_header,
1277 char *info_ptr, bfd *abfd)
1281 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1283 info_ptr += bytes_read;
1284 cu_header->version = read_2_bytes (abfd, info_ptr);
1286 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1288 info_ptr += bytes_read;
1289 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1291 signed_addr = bfd_get_sign_extend_vma (abfd);
1292 if (signed_addr < 0)
1293 internal_error (__FILE__, __LINE__,
1294 _("read_comp_unit_head: dwarf from non elf file"));
1295 cu_header->signed_addr_p = signed_addr;
1300 partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr,
1303 char *beg_of_comp_unit = info_ptr;
1305 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1307 if (header->version != 2)
1308 error (_("Dwarf Error: wrong version in compilation unit header "
1309 "(is %d, should be %d) [in module %s]"), header->version,
1310 2, bfd_get_filename (abfd));
1312 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1313 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1314 "(offset 0x%lx + 6) [in module %s]"),
1315 (long) header->abbrev_offset,
1316 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1317 bfd_get_filename (abfd));
1319 if (beg_of_comp_unit + header->length + header->initial_length_size
1320 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1321 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1322 "(offset 0x%lx + 0) [in module %s]"),
1323 (long) header->length,
1324 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1325 bfd_get_filename (abfd));
1330 /* Allocate a new partial symtab for file named NAME and mark this new
1331 partial symtab as being an include of PST. */
1334 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1335 struct objfile *objfile)
1337 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1339 subpst->section_offsets = pst->section_offsets;
1340 subpst->textlow = 0;
1341 subpst->texthigh = 0;
1343 subpst->dependencies = (struct partial_symtab **)
1344 obstack_alloc (&objfile->objfile_obstack,
1345 sizeof (struct partial_symtab *));
1346 subpst->dependencies[0] = pst;
1347 subpst->number_of_dependencies = 1;
1349 subpst->globals_offset = 0;
1350 subpst->n_global_syms = 0;
1351 subpst->statics_offset = 0;
1352 subpst->n_static_syms = 0;
1353 subpst->symtab = NULL;
1354 subpst->read_symtab = pst->read_symtab;
1357 /* No private part is necessary for include psymtabs. This property
1358 can be used to differentiate between such include psymtabs and
1359 the regular ones. */
1360 subpst->read_symtab_private = NULL;
1363 /* Read the Line Number Program data and extract the list of files
1364 included by the source file represented by PST. Build an include
1365 partial symtab for each of these included files.
1367 This procedure assumes that there *is* a Line Number Program in
1368 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1369 before calling this procedure. */
1372 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1373 struct partial_die_info *pdi,
1374 struct partial_symtab *pst)
1376 struct objfile *objfile = cu->objfile;
1377 bfd *abfd = objfile->obfd;
1378 struct line_header *lh;
1380 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1382 return; /* No linetable, so no includes. */
1384 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1386 free_line_header (lh);
1390 /* Build the partial symbol table by doing a quick pass through the
1391 .debug_info and .debug_abbrev sections. */
1394 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1396 /* Instead of reading this into a big buffer, we should probably use
1397 mmap() on architectures that support it. (FIXME) */
1398 bfd *abfd = objfile->obfd;
1400 char *beg_of_comp_unit;
1401 struct partial_die_info comp_unit_die;
1402 struct partial_symtab *pst;
1403 struct cleanup *back_to;
1404 CORE_ADDR lowpc, highpc, baseaddr;
1406 info_ptr = dwarf2_per_objfile->info_buffer;
1408 /* Any cached compilation units will be linked by the per-objfile
1409 read_in_chain. Make sure to free them when we're done. */
1410 back_to = make_cleanup (free_cached_comp_units, NULL);
1412 create_all_comp_units (objfile);
1414 /* Since the objects we're extracting from .debug_info vary in
1415 length, only the individual functions to extract them (like
1416 read_comp_unit_head and load_partial_die) can really know whether
1417 the buffer is large enough to hold another complete object.
1419 At the moment, they don't actually check that. If .debug_info
1420 holds just one extra byte after the last compilation unit's dies,
1421 then read_comp_unit_head will happily read off the end of the
1422 buffer. read_partial_die is similarly casual. Those functions
1425 For this loop condition, simply checking whether there's any data
1426 left at all should be sufficient. */
1427 while (info_ptr < (dwarf2_per_objfile->info_buffer
1428 + dwarf2_per_objfile->info_size))
1430 struct cleanup *back_to_inner;
1431 struct dwarf2_cu cu;
1432 struct abbrev_info *abbrev;
1433 unsigned int bytes_read;
1434 struct dwarf2_per_cu_data *this_cu;
1436 beg_of_comp_unit = info_ptr;
1438 memset (&cu, 0, sizeof (cu));
1440 obstack_init (&cu.comp_unit_obstack);
1442 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1444 cu.objfile = objfile;
1445 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1447 /* Complete the cu_header */
1448 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1449 cu.header.first_die_ptr = info_ptr;
1450 cu.header.cu_head_ptr = beg_of_comp_unit;
1452 cu.list_in_scope = &file_symbols;
1454 /* Read the abbrevs for this compilation unit into a table */
1455 dwarf2_read_abbrevs (abfd, &cu);
1456 make_cleanup (dwarf2_free_abbrev_table, &cu);
1458 this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile);
1460 /* Read the compilation unit die */
1461 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1462 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1463 abfd, info_ptr, &cu);
1465 /* Set the language we're debugging */
1466 set_cu_language (comp_unit_die.language, &cu);
1468 /* Allocate a new partial symbol table structure */
1469 pst = start_psymtab_common (objfile, objfile->section_offsets,
1470 comp_unit_die.name ? comp_unit_die.name : "",
1471 comp_unit_die.lowpc,
1472 objfile->global_psymbols.next,
1473 objfile->static_psymbols.next);
1475 if (comp_unit_die.dirname)
1476 pst->dirname = xstrdup (comp_unit_die.dirname);
1478 pst->read_symtab_private = (char *) this_cu;
1480 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1482 /* Store the function that reads in the rest of the symbol table */
1483 pst->read_symtab = dwarf2_psymtab_to_symtab;
1485 /* If this compilation unit was already read in, free the
1486 cached copy in order to read it in again. This is
1487 necessary because we skipped some symbols when we first
1488 read in the compilation unit (see load_partial_dies).
1489 This problem could be avoided, but the benefit is
1491 if (this_cu->cu != NULL)
1492 free_one_cached_comp_unit (this_cu->cu);
1494 cu.per_cu = this_cu;
1496 /* Note that this is a pointer to our stack frame, being
1497 added to a global data structure. It will be cleaned up
1498 in free_stack_comp_unit when we finish with this
1499 compilation unit. */
1502 this_cu->psymtab = pst;
1504 /* Check if comp unit has_children.
1505 If so, read the rest of the partial symbols from this comp unit.
1506 If not, there's no more debug_info for this comp unit. */
1507 if (comp_unit_die.has_children)
1509 struct partial_die_info *first_die;
1511 lowpc = ((CORE_ADDR) -1);
1512 highpc = ((CORE_ADDR) 0);
1514 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1516 scan_partial_symbols (first_die, &lowpc, &highpc, &cu);
1518 /* If we didn't find a lowpc, set it to highpc to avoid
1519 complaints from `maint check'. */
1520 if (lowpc == ((CORE_ADDR) -1))
1523 /* If the compilation unit didn't have an explicit address range,
1524 then use the information extracted from its child dies. */
1525 if (! comp_unit_die.has_pc_info)
1527 comp_unit_die.lowpc = lowpc;
1528 comp_unit_die.highpc = highpc;
1531 pst->textlow = comp_unit_die.lowpc + baseaddr;
1532 pst->texthigh = comp_unit_die.highpc + baseaddr;
1534 pst->n_global_syms = objfile->global_psymbols.next -
1535 (objfile->global_psymbols.list + pst->globals_offset);
1536 pst->n_static_syms = objfile->static_psymbols.next -
1537 (objfile->static_psymbols.list + pst->statics_offset);
1538 sort_pst_symbols (pst);
1540 /* If there is already a psymtab or symtab for a file of this
1541 name, remove it. (If there is a symtab, more drastic things
1542 also happen.) This happens in VxWorks. */
1543 free_named_symtabs (pst->filename);
1545 if (comp_unit_die.has_stmt_list)
1547 /* Get the list of files included in the current compilation unit,
1548 and build a psymtab for each of them. */
1549 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1552 info_ptr = beg_of_comp_unit + cu.header.length
1553 + cu.header.initial_length_size;
1555 do_cleanups (back_to_inner);
1557 do_cleanups (back_to);
1560 /* Load the DIEs for a secondary CU into memory. */
1563 load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile)
1565 bfd *abfd = objfile->obfd;
1566 char *info_ptr, *beg_of_comp_unit;
1567 struct partial_die_info comp_unit_die;
1568 struct dwarf2_cu *cu;
1569 struct abbrev_info *abbrev;
1570 unsigned int bytes_read;
1571 struct cleanup *back_to;
1573 info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset;
1574 beg_of_comp_unit = info_ptr;
1576 cu = xmalloc (sizeof (struct dwarf2_cu));
1577 memset (cu, 0, sizeof (struct dwarf2_cu));
1579 obstack_init (&cu->comp_unit_obstack);
1581 cu->objfile = objfile;
1582 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd);
1584 /* Complete the cu_header. */
1585 cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1586 cu->header.first_die_ptr = info_ptr;
1587 cu->header.cu_head_ptr = beg_of_comp_unit;
1589 /* Read the abbrevs for this compilation unit into a table. */
1590 dwarf2_read_abbrevs (abfd, cu);
1591 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
1593 /* Read the compilation unit die. */
1594 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1595 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1596 abfd, info_ptr, cu);
1598 /* Set the language we're debugging. */
1599 set_cu_language (comp_unit_die.language, cu);
1601 /* Link this compilation unit into the compilation unit tree. */
1603 cu->per_cu = this_cu;
1605 /* Check if comp unit has_children.
1606 If so, read the rest of the partial symbols from this comp unit.
1607 If not, there's no more debug_info for this comp unit. */
1608 if (comp_unit_die.has_children)
1609 load_partial_dies (abfd, info_ptr, 0, cu);
1611 do_cleanups (back_to);
1614 /* Create a list of all compilation units in OBJFILE. We do this only
1615 if an inter-comp-unit reference is found; presumably if there is one,
1616 there will be many, and one will occur early in the .debug_info section.
1617 So there's no point in building this list incrementally. */
1620 create_all_comp_units (struct objfile *objfile)
1624 struct dwarf2_per_cu_data **all_comp_units;
1625 char *info_ptr = dwarf2_per_objfile->info_buffer;
1629 all_comp_units = xmalloc (n_allocated
1630 * sizeof (struct dwarf2_per_cu_data *));
1632 while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1634 struct comp_unit_head cu_header;
1635 char *beg_of_comp_unit;
1636 struct dwarf2_per_cu_data *this_cu;
1637 unsigned long offset;
1640 offset = info_ptr - dwarf2_per_objfile->info_buffer;
1642 /* Read just enough information to find out where the next
1643 compilation unit is. */
1644 cu_header.length = read_initial_length (objfile->obfd, info_ptr,
1645 &cu_header, &bytes_read);
1647 /* Save the compilation unit for later lookup. */
1648 this_cu = obstack_alloc (&objfile->objfile_obstack,
1649 sizeof (struct dwarf2_per_cu_data));
1650 memset (this_cu, 0, sizeof (*this_cu));
1651 this_cu->offset = offset;
1652 this_cu->length = cu_header.length + cu_header.initial_length_size;
1654 if (n_comp_units == n_allocated)
1657 all_comp_units = xrealloc (all_comp_units,
1659 * sizeof (struct dwarf2_per_cu_data *));
1661 all_comp_units[n_comp_units++] = this_cu;
1663 info_ptr = info_ptr + this_cu->length;
1666 dwarf2_per_objfile->all_comp_units
1667 = obstack_alloc (&objfile->objfile_obstack,
1668 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1669 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
1670 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1671 xfree (all_comp_units);
1672 dwarf2_per_objfile->n_comp_units = n_comp_units;
1675 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1676 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1680 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1681 CORE_ADDR *highpc, struct dwarf2_cu *cu)
1683 struct objfile *objfile = cu->objfile;
1684 bfd *abfd = objfile->obfd;
1685 struct partial_die_info *pdi;
1687 /* Now, march along the PDI's, descending into ones which have
1688 interesting children but skipping the children of the other ones,
1689 until we reach the end of the compilation unit. */
1695 fixup_partial_die (pdi, cu);
1697 /* Anonymous namespaces have no name but have interesting
1698 children, so we need to look at them. Ditto for anonymous
1701 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1702 || pdi->tag == DW_TAG_enumeration_type)
1706 case DW_TAG_subprogram:
1707 if (pdi->has_pc_info)
1709 if (pdi->lowpc < *lowpc)
1711 *lowpc = pdi->lowpc;
1713 if (pdi->highpc > *highpc)
1715 *highpc = pdi->highpc;
1717 if (!pdi->is_declaration)
1719 add_partial_symbol (pdi, cu);
1723 case DW_TAG_variable:
1724 case DW_TAG_typedef:
1725 case DW_TAG_union_type:
1726 if (!pdi->is_declaration)
1728 add_partial_symbol (pdi, cu);
1731 case DW_TAG_class_type:
1732 case DW_TAG_structure_type:
1733 if (!pdi->is_declaration)
1735 add_partial_symbol (pdi, cu);
1738 case DW_TAG_enumeration_type:
1739 if (!pdi->is_declaration)
1740 add_partial_enumeration (pdi, cu);
1742 case DW_TAG_base_type:
1743 case DW_TAG_subrange_type:
1744 /* File scope base type definitions are added to the partial
1746 add_partial_symbol (pdi, cu);
1748 case DW_TAG_namespace:
1749 add_partial_namespace (pdi, lowpc, highpc, cu);
1756 /* If the die has a sibling, skip to the sibling. */
1758 pdi = pdi->die_sibling;
1762 /* Functions used to compute the fully scoped name of a partial DIE.
1764 Normally, this is simple. For C++, the parent DIE's fully scoped
1765 name is concatenated with "::" and the partial DIE's name. For
1766 Java, the same thing occurs except that "." is used instead of "::".
1767 Enumerators are an exception; they use the scope of their parent
1768 enumeration type, i.e. the name of the enumeration type is not
1769 prepended to the enumerator.
1771 There are two complexities. One is DW_AT_specification; in this
1772 case "parent" means the parent of the target of the specification,
1773 instead of the direct parent of the DIE. The other is compilers
1774 which do not emit DW_TAG_namespace; in this case we try to guess
1775 the fully qualified name of structure types from their members'
1776 linkage names. This must be done using the DIE's children rather
1777 than the children of any DW_AT_specification target. We only need
1778 to do this for structures at the top level, i.e. if the target of
1779 any DW_AT_specification (if any; otherwise the DIE itself) does not
1782 /* Compute the scope prefix associated with PDI's parent, in
1783 compilation unit CU. The result will be allocated on CU's
1784 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1785 field. NULL is returned if no prefix is necessary. */
1787 partial_die_parent_scope (struct partial_die_info *pdi,
1788 struct dwarf2_cu *cu)
1790 char *grandparent_scope;
1791 struct partial_die_info *parent, *real_pdi;
1793 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1794 then this means the parent of the specification DIE. */
1797 while (real_pdi->has_specification)
1798 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
1800 parent = real_pdi->die_parent;
1804 if (parent->scope_set)
1805 return parent->scope;
1807 fixup_partial_die (parent, cu);
1809 grandparent_scope = partial_die_parent_scope (parent, cu);
1811 if (parent->tag == DW_TAG_namespace
1812 || parent->tag == DW_TAG_structure_type
1813 || parent->tag == DW_TAG_class_type
1814 || parent->tag == DW_TAG_union_type)
1816 if (grandparent_scope == NULL)
1817 parent->scope = parent->name;
1819 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
1822 else if (parent->tag == DW_TAG_enumeration_type)
1823 /* Enumerators should not get the name of the enumeration as a prefix. */
1824 parent->scope = grandparent_scope;
1827 /* FIXME drow/2004-04-01: What should we be doing with
1828 function-local names? For partial symbols, we should probably be
1830 complaint (&symfile_complaints,
1831 _("unhandled containing DIE tag %d for DIE at %d"),
1832 parent->tag, pdi->offset);
1833 parent->scope = grandparent_scope;
1836 parent->scope_set = 1;
1837 return parent->scope;
1840 /* Return the fully scoped name associated with PDI, from compilation unit
1841 CU. The result will be allocated with malloc. */
1843 partial_die_full_name (struct partial_die_info *pdi,
1844 struct dwarf2_cu *cu)
1848 parent_scope = partial_die_parent_scope (pdi, cu);
1849 if (parent_scope == NULL)
1852 return typename_concat (NULL, parent_scope, pdi->name, cu);
1856 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1858 struct objfile *objfile = cu->objfile;
1861 const char *my_prefix;
1862 const struct partial_symbol *psym = NULL;
1864 int built_actual_name = 0;
1866 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1870 if (pdi_needs_namespace (pdi->tag))
1872 actual_name = partial_die_full_name (pdi, cu);
1874 built_actual_name = 1;
1877 if (actual_name == NULL)
1878 actual_name = pdi->name;
1882 case DW_TAG_subprogram:
1883 if (pdi->is_external)
1885 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1886 mst_text, objfile); */
1887 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1888 VAR_DOMAIN, LOC_BLOCK,
1889 &objfile->global_psymbols,
1890 0, pdi->lowpc + baseaddr,
1891 cu->language, objfile);
1895 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1896 mst_file_text, objfile); */
1897 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1898 VAR_DOMAIN, LOC_BLOCK,
1899 &objfile->static_psymbols,
1900 0, pdi->lowpc + baseaddr,
1901 cu->language, objfile);
1904 case DW_TAG_variable:
1905 if (pdi->is_external)
1908 Don't enter into the minimal symbol tables as there is
1909 a minimal symbol table entry from the ELF symbols already.
1910 Enter into partial symbol table if it has a location
1911 descriptor or a type.
1912 If the location descriptor is missing, new_symbol will create
1913 a LOC_UNRESOLVED symbol, the address of the variable will then
1914 be determined from the minimal symbol table whenever the variable
1916 The address for the partial symbol table entry is not
1917 used by GDB, but it comes in handy for debugging partial symbol
1921 addr = decode_locdesc (pdi->locdesc, cu);
1922 if (pdi->locdesc || pdi->has_type)
1923 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1924 VAR_DOMAIN, LOC_STATIC,
1925 &objfile->global_psymbols,
1927 cu->language, objfile);
1931 /* Static Variable. Skip symbols without location descriptors. */
1932 if (pdi->locdesc == NULL)
1934 addr = decode_locdesc (pdi->locdesc, cu);
1935 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1936 mst_file_data, objfile); */
1937 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1938 VAR_DOMAIN, LOC_STATIC,
1939 &objfile->static_psymbols,
1941 cu->language, objfile);
1944 case DW_TAG_typedef:
1945 case DW_TAG_base_type:
1946 case DW_TAG_subrange_type:
1947 add_psymbol_to_list (actual_name, strlen (actual_name),
1948 VAR_DOMAIN, LOC_TYPEDEF,
1949 &objfile->static_psymbols,
1950 0, (CORE_ADDR) 0, cu->language, objfile);
1952 case DW_TAG_namespace:
1953 add_psymbol_to_list (actual_name, strlen (actual_name),
1954 VAR_DOMAIN, LOC_TYPEDEF,
1955 &objfile->global_psymbols,
1956 0, (CORE_ADDR) 0, cu->language, objfile);
1958 case DW_TAG_class_type:
1959 case DW_TAG_structure_type:
1960 case DW_TAG_union_type:
1961 case DW_TAG_enumeration_type:
1962 /* Skip aggregate types without children, these are external
1964 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1965 static vs. global. */
1966 if (pdi->has_children == 0)
1968 add_psymbol_to_list (actual_name, strlen (actual_name),
1969 STRUCT_DOMAIN, LOC_TYPEDEF,
1970 (cu->language == language_cplus
1971 || cu->language == language_java)
1972 ? &objfile->global_psymbols
1973 : &objfile->static_psymbols,
1974 0, (CORE_ADDR) 0, cu->language, objfile);
1976 if (cu->language == language_cplus
1977 || cu->language == language_java)
1979 /* For C++ and Java, these implicitly act as typedefs as well. */
1980 add_psymbol_to_list (actual_name, strlen (actual_name),
1981 VAR_DOMAIN, LOC_TYPEDEF,
1982 &objfile->global_psymbols,
1983 0, (CORE_ADDR) 0, cu->language, objfile);
1986 case DW_TAG_enumerator:
1987 add_psymbol_to_list (actual_name, strlen (actual_name),
1988 VAR_DOMAIN, LOC_CONST,
1989 (cu->language == language_cplus
1990 || cu->language == language_java)
1991 ? &objfile->global_psymbols
1992 : &objfile->static_psymbols,
1993 0, (CORE_ADDR) 0, cu->language, objfile);
1999 /* Check to see if we should scan the name for possible namespace
2000 info. Only do this if this is C++, if we don't have namespace
2001 debugging info in the file, if the psym is of an appropriate type
2002 (otherwise we'll have psym == NULL), and if we actually had a
2003 mangled name to begin with. */
2005 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2006 cases which do not set PSYM above? */
2008 if (cu->language == language_cplus
2009 && cu->has_namespace_info == 0
2011 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
2012 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
2015 if (built_actual_name)
2016 xfree (actual_name);
2019 /* Determine whether a die of type TAG living in a C++ class or
2020 namespace needs to have the name of the scope prepended to the
2021 name listed in the die. */
2024 pdi_needs_namespace (enum dwarf_tag tag)
2028 case DW_TAG_namespace:
2029 case DW_TAG_typedef:
2030 case DW_TAG_class_type:
2031 case DW_TAG_structure_type:
2032 case DW_TAG_union_type:
2033 case DW_TAG_enumeration_type:
2034 case DW_TAG_enumerator:
2041 /* Read a partial die corresponding to a namespace; also, add a symbol
2042 corresponding to that namespace to the symbol table. NAMESPACE is
2043 the name of the enclosing namespace. */
2046 add_partial_namespace (struct partial_die_info *pdi,
2047 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2048 struct dwarf2_cu *cu)
2050 struct objfile *objfile = cu->objfile;
2052 /* Add a symbol for the namespace. */
2054 add_partial_symbol (pdi, cu);
2056 /* Now scan partial symbols in that namespace. */
2058 if (pdi->has_children)
2059 scan_partial_symbols (pdi->die_child, lowpc, highpc, cu);
2062 /* See if we can figure out if the class lives in a namespace. We do
2063 this by looking for a member function; its demangled name will
2064 contain namespace info, if there is any. */
2067 guess_structure_name (struct partial_die_info *struct_pdi,
2068 struct dwarf2_cu *cu)
2070 if ((cu->language == language_cplus
2071 || cu->language == language_java)
2072 && cu->has_namespace_info == 0
2073 && struct_pdi->has_children)
2075 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2076 what template types look like, because the demangler
2077 frequently doesn't give the same name as the debug info. We
2078 could fix this by only using the demangled name to get the
2079 prefix (but see comment in read_structure_type). */
2081 struct partial_die_info *child_pdi = struct_pdi->die_child;
2082 struct partial_die_info *real_pdi;
2084 /* If this DIE (this DIE's specification, if any) has a parent, then
2085 we should not do this. We'll prepend the parent's fully qualified
2086 name when we create the partial symbol. */
2088 real_pdi = struct_pdi;
2089 while (real_pdi->has_specification)
2090 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2092 if (real_pdi->die_parent != NULL)
2095 while (child_pdi != NULL)
2097 if (child_pdi->tag == DW_TAG_subprogram)
2099 char *actual_class_name
2100 = language_class_name_from_physname (cu->language_defn,
2102 if (actual_class_name != NULL)
2105 = obsavestring (actual_class_name,
2106 strlen (actual_class_name),
2107 &cu->comp_unit_obstack);
2108 xfree (actual_class_name);
2113 child_pdi = child_pdi->die_sibling;
2118 /* Read a partial die corresponding to an enumeration type. */
2121 add_partial_enumeration (struct partial_die_info *enum_pdi,
2122 struct dwarf2_cu *cu)
2124 struct objfile *objfile = cu->objfile;
2125 bfd *abfd = objfile->obfd;
2126 struct partial_die_info *pdi;
2128 if (enum_pdi->name != NULL)
2129 add_partial_symbol (enum_pdi, cu);
2131 pdi = enum_pdi->die_child;
2134 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2135 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2137 add_partial_symbol (pdi, cu);
2138 pdi = pdi->die_sibling;
2142 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2143 Return the corresponding abbrev, or NULL if the number is zero (indicating
2144 an empty DIE). In either case *BYTES_READ will be set to the length of
2145 the initial number. */
2147 static struct abbrev_info *
2148 peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu)
2150 bfd *abfd = cu->objfile->obfd;
2151 unsigned int abbrev_number;
2152 struct abbrev_info *abbrev;
2154 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2156 if (abbrev_number == 0)
2159 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2162 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2163 bfd_get_filename (abfd));
2169 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2170 pointer to the end of a series of DIEs, terminated by an empty
2171 DIE. Any children of the skipped DIEs will also be skipped. */
2174 skip_children (char *info_ptr, struct dwarf2_cu *cu)
2176 struct abbrev_info *abbrev;
2177 unsigned int bytes_read;
2181 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2183 return info_ptr + bytes_read;
2185 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
2189 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2190 should point just after the initial uleb128 of a DIE, and the
2191 abbrev corresponding to that skipped uleb128 should be passed in
2192 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2196 skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
2197 struct dwarf2_cu *cu)
2199 unsigned int bytes_read;
2200 struct attribute attr;
2201 bfd *abfd = cu->objfile->obfd;
2202 unsigned int form, i;
2204 for (i = 0; i < abbrev->num_attrs; i++)
2206 /* The only abbrev we care about is DW_AT_sibling. */
2207 if (abbrev->attrs[i].name == DW_AT_sibling)
2209 read_attribute (&attr, &abbrev->attrs[i],
2210 abfd, info_ptr, cu);
2211 if (attr.form == DW_FORM_ref_addr)
2212 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2214 return dwarf2_per_objfile->info_buffer
2215 + dwarf2_get_ref_die_offset (&attr, cu);
2218 /* If it isn't DW_AT_sibling, skip this attribute. */
2219 form = abbrev->attrs[i].form;
2224 case DW_FORM_ref_addr:
2225 info_ptr += cu->header.addr_size;
2244 case DW_FORM_string:
2245 read_string (abfd, info_ptr, &bytes_read);
2246 info_ptr += bytes_read;
2249 info_ptr += cu->header.offset_size;
2252 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2253 info_ptr += bytes_read;
2255 case DW_FORM_block1:
2256 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2258 case DW_FORM_block2:
2259 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2261 case DW_FORM_block4:
2262 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2266 case DW_FORM_ref_udata:
2267 info_ptr = skip_leb128 (abfd, info_ptr);
2269 case DW_FORM_indirect:
2270 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2271 info_ptr += bytes_read;
2272 /* We need to continue parsing from here, so just go back to
2274 goto skip_attribute;
2277 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2278 dwarf_form_name (form),
2279 bfd_get_filename (abfd));
2283 if (abbrev->has_children)
2284 return skip_children (info_ptr, cu);
2289 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2290 the next DIE after ORIG_PDI. */
2293 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
2294 bfd *abfd, struct dwarf2_cu *cu)
2296 /* Do we know the sibling already? */
2298 if (orig_pdi->sibling)
2299 return orig_pdi->sibling;
2301 /* Are there any children to deal with? */
2303 if (!orig_pdi->has_children)
2306 /* Skip the children the long way. */
2308 return skip_children (info_ptr, cu);
2311 /* Expand this partial symbol table into a full symbol table. */
2314 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2316 /* FIXME: This is barely more than a stub. */
2321 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2327 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2328 gdb_flush (gdb_stdout);
2331 /* Restore our global data. */
2332 dwarf2_per_objfile = objfile_data (pst->objfile,
2333 dwarf2_objfile_data_key);
2335 psymtab_to_symtab_1 (pst);
2337 /* Finish up the debug error message. */
2339 printf_filtered (_("done.\n"));
2344 /* Add PER_CU to the queue. */
2347 queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
2349 struct dwarf2_queue_item *item;
2352 item = xmalloc (sizeof (*item));
2353 item->per_cu = per_cu;
2356 if (dwarf2_queue == NULL)
2357 dwarf2_queue = item;
2359 dwarf2_queue_tail->next = item;
2361 dwarf2_queue_tail = item;
2364 /* Process the queue. */
2367 process_queue (struct objfile *objfile)
2369 struct dwarf2_queue_item *item, *next_item;
2371 /* Initially, there is just one item on the queue. Load its DIEs,
2372 and the DIEs of any other compilation units it requires,
2375 for (item = dwarf2_queue; item != NULL; item = item->next)
2377 /* Read in this compilation unit. This may add new items to
2378 the end of the queue. */
2379 load_full_comp_unit (item->per_cu);
2381 item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
2382 dwarf2_per_objfile->read_in_chain = item->per_cu;
2384 /* If this compilation unit has already had full symbols created,
2385 reset the TYPE fields in each DIE. */
2386 if (item->per_cu->psymtab->readin)
2387 reset_die_and_siblings_types (item->per_cu->cu->dies,
2391 /* Now everything left on the queue needs to be read in. Process
2392 them, one at a time, removing from the queue as we finish. */
2393 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
2395 if (!item->per_cu->psymtab->readin)
2396 process_full_comp_unit (item->per_cu);
2398 item->per_cu->queued = 0;
2399 next_item = item->next;
2403 dwarf2_queue_tail = NULL;
2406 /* Free all allocated queue entries. This function only releases anything if
2407 an error was thrown; if the queue was processed then it would have been
2408 freed as we went along. */
2411 dwarf2_release_queue (void *dummy)
2413 struct dwarf2_queue_item *item, *last;
2415 item = dwarf2_queue;
2418 /* Anything still marked queued is likely to be in an
2419 inconsistent state, so discard it. */
2420 if (item->per_cu->queued)
2422 if (item->per_cu->cu != NULL)
2423 free_one_cached_comp_unit (item->per_cu->cu);
2424 item->per_cu->queued = 0;
2432 dwarf2_queue = dwarf2_queue_tail = NULL;
2435 /* Read in full symbols for PST, and anything it depends on. */
2438 psymtab_to_symtab_1 (struct partial_symtab *pst)
2440 struct dwarf2_per_cu_data *per_cu;
2441 struct cleanup *back_to;
2444 for (i = 0; i < pst->number_of_dependencies; i++)
2445 if (!pst->dependencies[i]->readin)
2447 /* Inform about additional files that need to be read in. */
2450 /* FIXME: i18n: Need to make this a single string. */
2451 fputs_filtered (" ", gdb_stdout);
2453 fputs_filtered ("and ", gdb_stdout);
2455 printf_filtered ("%s...", pst->dependencies[i]->filename);
2456 wrap_here (""); /* Flush output */
2457 gdb_flush (gdb_stdout);
2459 psymtab_to_symtab_1 (pst->dependencies[i]);
2462 per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private;
2466 /* It's an include file, no symbols to read for it.
2467 Everything is in the parent symtab. */
2472 back_to = make_cleanup (dwarf2_release_queue, NULL);
2474 queue_comp_unit (per_cu);
2476 process_queue (pst->objfile);
2478 /* Age the cache, releasing compilation units that have not
2479 been used recently. */
2480 age_cached_comp_units ();
2482 do_cleanups (back_to);
2485 /* Load the DIEs associated with PST and PER_CU into memory. */
2487 static struct dwarf2_cu *
2488 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
2490 struct partial_symtab *pst = per_cu->psymtab;
2491 bfd *abfd = pst->objfile->obfd;
2492 struct dwarf2_cu *cu;
2493 unsigned long offset;
2495 struct cleanup *back_to, *free_cu_cleanup;
2496 struct attribute *attr;
2499 /* Set local variables from the partial symbol table info. */
2500 offset = per_cu->offset;
2502 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2504 cu = xmalloc (sizeof (struct dwarf2_cu));
2505 memset (cu, 0, sizeof (struct dwarf2_cu));
2507 /* If an error occurs while loading, release our storage. */
2508 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
2510 cu->objfile = pst->objfile;
2512 /* read in the comp_unit header */
2513 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
2515 /* Read the abbrevs for this compilation unit */
2516 dwarf2_read_abbrevs (abfd, cu);
2517 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2519 cu->header.offset = offset;
2521 cu->per_cu = per_cu;
2524 /* We use this obstack for block values in dwarf_alloc_block. */
2525 obstack_init (&cu->comp_unit_obstack);
2527 cu->dies = read_comp_unit (info_ptr, abfd, cu);
2529 /* We try not to read any attributes in this function, because not
2530 all objfiles needed for references have been loaded yet, and symbol
2531 table processing isn't initialized. But we have to set the CU language,
2532 or we won't be able to build types correctly. */
2533 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
2535 set_cu_language (DW_UNSND (attr), cu);
2537 set_cu_language (language_minimal, cu);
2539 do_cleanups (back_to);
2541 /* We've successfully allocated this compilation unit. Let our caller
2542 clean it up when finished with it. */
2543 discard_cleanups (free_cu_cleanup);
2548 /* Generate full symbol information for PST and CU, whose DIEs have
2549 already been loaded into memory. */
2552 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
2554 struct partial_symtab *pst = per_cu->psymtab;
2555 struct dwarf2_cu *cu = per_cu->cu;
2556 struct objfile *objfile = pst->objfile;
2557 bfd *abfd = objfile->obfd;
2558 CORE_ADDR lowpc, highpc;
2559 struct symtab *symtab;
2560 struct cleanup *back_to;
2561 struct attribute *attr;
2564 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2566 /* We're in the global namespace. */
2567 processing_current_prefix = "";
2570 back_to = make_cleanup (really_free_pendings, NULL);
2572 cu->list_in_scope = &file_symbols;
2574 /* Find the base address of the compilation unit for range lists and
2575 location lists. It will normally be specified by DW_AT_low_pc.
2576 In DWARF-3 draft 4, the base address could be overridden by
2577 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2578 compilation units with discontinuous ranges. */
2580 cu->header.base_known = 0;
2581 cu->header.base_address = 0;
2583 attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu);
2586 cu->header.base_address = DW_ADDR (attr);
2587 cu->header.base_known = 1;
2591 attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu);
2594 cu->header.base_address = DW_ADDR (attr);
2595 cu->header.base_known = 1;
2599 /* Do line number decoding in read_file_scope () */
2600 process_die (cu->dies, cu);
2602 /* Some compilers don't define a DW_AT_high_pc attribute for the
2603 compilation unit. If the DW_AT_high_pc is missing, synthesize
2604 it, by scanning the DIE's below the compilation unit. */
2605 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
2607 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2609 /* Set symtab language to language from DW_AT_language.
2610 If the compilation is from a C file generated by language preprocessors,
2611 do not set the language if it was already deduced by start_subfile. */
2613 && !(cu->language == language_c && symtab->language != language_c))
2615 symtab->language = cu->language;
2617 pst->symtab = symtab;
2620 do_cleanups (back_to);
2623 /* Process a die and its children. */
2626 process_die (struct die_info *die, struct dwarf2_cu *cu)
2630 case DW_TAG_padding:
2632 case DW_TAG_compile_unit:
2633 read_file_scope (die, cu);
2635 case DW_TAG_subprogram:
2636 read_subroutine_type (die, cu);
2637 read_func_scope (die, cu);
2639 case DW_TAG_inlined_subroutine:
2640 /* FIXME: These are ignored for now.
2641 They could be used to set breakpoints on all inlined instances
2642 of a function and make GDB `next' properly over inlined functions. */
2644 case DW_TAG_lexical_block:
2645 case DW_TAG_try_block:
2646 case DW_TAG_catch_block:
2647 read_lexical_block_scope (die, cu);
2649 case DW_TAG_class_type:
2650 case DW_TAG_structure_type:
2651 case DW_TAG_union_type:
2652 read_structure_type (die, cu);
2653 process_structure_scope (die, cu);
2655 case DW_TAG_enumeration_type:
2656 read_enumeration_type (die, cu);
2657 process_enumeration_scope (die, cu);
2660 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2661 a symbol or process any children. Therefore it doesn't do anything
2662 that won't be done on-demand by read_type_die. */
2663 case DW_TAG_subroutine_type:
2664 read_subroutine_type (die, cu);
2666 case DW_TAG_array_type:
2667 read_array_type (die, cu);
2669 case DW_TAG_pointer_type:
2670 read_tag_pointer_type (die, cu);
2672 case DW_TAG_ptr_to_member_type:
2673 read_tag_ptr_to_member_type (die, cu);
2675 case DW_TAG_reference_type:
2676 read_tag_reference_type (die, cu);
2678 case DW_TAG_string_type:
2679 read_tag_string_type (die, cu);
2683 case DW_TAG_base_type:
2684 read_base_type (die, cu);
2685 /* Add a typedef symbol for the type definition, if it has a
2687 new_symbol (die, die->type, cu);
2689 case DW_TAG_subrange_type:
2690 read_subrange_type (die, cu);
2691 /* Add a typedef symbol for the type definition, if it has a
2693 new_symbol (die, die->type, cu);
2695 case DW_TAG_common_block:
2696 read_common_block (die, cu);
2698 case DW_TAG_common_inclusion:
2700 case DW_TAG_namespace:
2701 processing_has_namespace_info = 1;
2702 read_namespace (die, cu);
2704 case DW_TAG_imported_declaration:
2705 case DW_TAG_imported_module:
2706 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2707 information contained in these. DW_TAG_imported_declaration
2708 dies shouldn't have children; DW_TAG_imported_module dies
2709 shouldn't in the C++ case, but conceivably could in the
2710 Fortran case, so we'll have to replace this gdb_assert if
2711 Fortran compilers start generating that info. */
2712 processing_has_namespace_info = 1;
2713 gdb_assert (die->child == NULL);
2716 new_symbol (die, NULL, cu);
2722 initialize_cu_func_list (struct dwarf2_cu *cu)
2724 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2728 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2730 struct objfile *objfile = cu->objfile;
2731 struct comp_unit_head *cu_header = &cu->header;
2732 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2733 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2734 CORE_ADDR highpc = ((CORE_ADDR) 0);
2735 struct attribute *attr;
2736 char *name = "<unknown>";
2737 char *comp_dir = NULL;
2738 struct die_info *child_die;
2739 bfd *abfd = objfile->obfd;
2740 struct line_header *line_header = 0;
2743 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2745 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2747 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2748 from finish_block. */
2749 if (lowpc == ((CORE_ADDR) -1))
2754 attr = dwarf2_attr (die, DW_AT_name, cu);
2757 name = DW_STRING (attr);
2759 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2762 comp_dir = DW_STRING (attr);
2765 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2766 directory, get rid of it. */
2767 char *cp = strchr (comp_dir, ':');
2769 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2774 attr = dwarf2_attr (die, DW_AT_language, cu);
2777 set_cu_language (DW_UNSND (attr), cu);
2780 attr = dwarf2_attr (die, DW_AT_producer, cu);
2782 cu->producer = DW_STRING (attr);
2784 /* We assume that we're processing GCC output. */
2785 processing_gcc_compilation = 2;
2787 /* FIXME:Do something here. */
2788 if (dip->at_producer != NULL)
2790 handle_producer (dip->at_producer);
2794 /* The compilation unit may be in a different language or objfile,
2795 zero out all remembered fundamental types. */
2796 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2798 start_symtab (name, comp_dir, lowpc);
2799 record_debugformat ("DWARF 2");
2801 initialize_cu_func_list (cu);
2803 /* Process all dies in compilation unit. */
2804 if (die->child != NULL)
2806 child_die = die->child;
2807 while (child_die && child_die->tag)
2809 process_die (child_die, cu);
2810 child_die = sibling_die (child_die);
2814 /* Decode line number information if present. */
2815 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2818 unsigned int line_offset = DW_UNSND (attr);
2819 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2822 make_cleanup ((make_cleanup_ftype *) free_line_header,
2823 (void *) line_header);
2824 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
2828 /* Decode macro information, if present. Dwarf 2 macro information
2829 refers to information in the line number info statement program
2830 header, so we can only read it if we've read the header
2832 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2833 if (attr && line_header)
2835 unsigned int macro_offset = DW_UNSND (attr);
2836 dwarf_decode_macros (line_header, macro_offset,
2837 comp_dir, abfd, cu);
2839 do_cleanups (back_to);
2843 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2844 struct dwarf2_cu *cu)
2846 struct function_range *thisfn;
2848 thisfn = (struct function_range *)
2849 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
2850 thisfn->name = name;
2851 thisfn->lowpc = lowpc;
2852 thisfn->highpc = highpc;
2853 thisfn->seen_line = 0;
2854 thisfn->next = NULL;
2856 if (cu->last_fn == NULL)
2857 cu->first_fn = thisfn;
2859 cu->last_fn->next = thisfn;
2861 cu->last_fn = thisfn;
2865 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2867 struct objfile *objfile = cu->objfile;
2868 struct context_stack *new;
2871 struct die_info *child_die;
2872 struct attribute *attr;
2874 const char *previous_prefix = processing_current_prefix;
2875 struct cleanup *back_to = NULL;
2878 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2880 name = dwarf2_linkage_name (die, cu);
2882 /* Ignore functions with missing or empty names and functions with
2883 missing or invalid low and high pc attributes. */
2884 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2887 if (cu->language == language_cplus
2888 || cu->language == language_java)
2890 struct die_info *spec_die = die_specification (die, cu);
2892 /* NOTE: carlton/2004-01-23: We have to be careful in the
2893 presence of DW_AT_specification. For example, with GCC 3.4,
2898 // Definition of N::foo.
2902 then we'll have a tree of DIEs like this:
2904 1: DW_TAG_compile_unit
2905 2: DW_TAG_namespace // N
2906 3: DW_TAG_subprogram // declaration of N::foo
2907 4: DW_TAG_subprogram // definition of N::foo
2908 DW_AT_specification // refers to die #3
2910 Thus, when processing die #4, we have to pretend that we're
2911 in the context of its DW_AT_specification, namely the contex
2914 if (spec_die != NULL)
2916 char *specification_prefix = determine_prefix (spec_die, cu);
2917 processing_current_prefix = specification_prefix;
2918 back_to = make_cleanup (xfree, specification_prefix);
2925 /* Record the function range for dwarf_decode_lines. */
2926 add_to_cu_func_list (name, lowpc, highpc, cu);
2928 new = push_context (0, lowpc);
2929 new->name = new_symbol (die, die->type, cu);
2931 /* If there is a location expression for DW_AT_frame_base, record
2933 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2935 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2936 expression is being recorded directly in the function's symbol
2937 and not in a separate frame-base object. I guess this hack is
2938 to avoid adding some sort of frame-base adjunct/annex to the
2939 function's symbol :-(. The problem with doing this is that it
2940 results in a function symbol with a location expression that
2941 has nothing to do with the location of the function, ouch! The
2942 relationship should be: a function's symbol has-a frame base; a
2943 frame-base has-a location expression. */
2944 dwarf2_symbol_mark_computed (attr, new->name, cu);
2946 cu->list_in_scope = &local_symbols;
2948 if (die->child != NULL)
2950 child_die = die->child;
2951 while (child_die && child_die->tag)
2953 process_die (child_die, cu);
2954 child_die = sibling_die (child_die);
2958 new = pop_context ();
2959 /* Make a block for the local symbols within. */
2960 finish_block (new->name, &local_symbols, new->old_blocks,
2961 lowpc, highpc, objfile);
2963 /* In C++, we can have functions nested inside functions (e.g., when
2964 a function declares a class that has methods). This means that
2965 when we finish processing a function scope, we may need to go
2966 back to building a containing block's symbol lists. */
2967 local_symbols = new->locals;
2968 param_symbols = new->params;
2970 /* If we've finished processing a top-level function, subsequent
2971 symbols go in the file symbol list. */
2972 if (outermost_context_p ())
2973 cu->list_in_scope = &file_symbols;
2975 processing_current_prefix = previous_prefix;
2976 if (back_to != NULL)
2977 do_cleanups (back_to);
2980 /* Process all the DIES contained within a lexical block scope. Start
2981 a new scope, process the dies, and then close the scope. */
2984 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2986 struct objfile *objfile = cu->objfile;
2987 struct context_stack *new;
2988 CORE_ADDR lowpc, highpc;
2989 struct die_info *child_die;
2992 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2994 /* Ignore blocks with missing or invalid low and high pc attributes. */
2995 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2996 as multiple lexical blocks? Handling children in a sane way would
2997 be nasty. Might be easier to properly extend generic blocks to
2999 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
3004 push_context (0, lowpc);
3005 if (die->child != NULL)
3007 child_die = die->child;
3008 while (child_die && child_die->tag)
3010 process_die (child_die, cu);
3011 child_die = sibling_die (child_die);
3014 new = pop_context ();
3016 if (local_symbols != NULL)
3018 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
3021 local_symbols = new->locals;
3024 /* Get low and high pc attributes from a die. Return 1 if the attributes
3025 are present and valid, otherwise, return 0. Return -1 if the range is
3026 discontinuous, i.e. derived from DW_AT_ranges information. */
3028 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
3029 CORE_ADDR *highpc, struct dwarf2_cu *cu)
3031 struct objfile *objfile = cu->objfile;
3032 struct comp_unit_head *cu_header = &cu->header;
3033 struct attribute *attr;
3034 bfd *obfd = objfile->obfd;
3039 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
3042 high = DW_ADDR (attr);
3043 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3045 low = DW_ADDR (attr);
3047 /* Found high w/o low attribute. */
3050 /* Found consecutive range of addresses. */
3055 attr = dwarf2_attr (die, DW_AT_ranges, cu);
3058 unsigned int addr_size = cu_header->addr_size;
3059 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3060 /* Value of the DW_AT_ranges attribute is the offset in the
3061 .debug_ranges section. */
3062 unsigned int offset = DW_UNSND (attr);
3063 /* Base address selection entry. */
3071 found_base = cu_header->base_known;
3072 base = cu_header->base_address;
3074 if (offset >= dwarf2_per_objfile->ranges_size)
3076 complaint (&symfile_complaints,
3077 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3081 buffer = dwarf2_per_objfile->ranges_buffer + offset;
3083 /* Read in the largest possible address. */
3084 marker = read_address (obfd, buffer, cu, &dummy);
3085 if ((marker & mask) == mask)
3087 /* If we found the largest possible address, then
3088 read the base address. */
3089 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3090 buffer += 2 * addr_size;
3091 offset += 2 * addr_size;
3099 CORE_ADDR range_beginning, range_end;
3101 range_beginning = read_address (obfd, buffer, cu, &dummy);
3102 buffer += addr_size;
3103 range_end = read_address (obfd, buffer, cu, &dummy);
3104 buffer += addr_size;
3105 offset += 2 * addr_size;
3107 /* An end of list marker is a pair of zero addresses. */
3108 if (range_beginning == 0 && range_end == 0)
3109 /* Found the end of list entry. */
3112 /* Each base address selection entry is a pair of 2 values.
3113 The first is the largest possible address, the second is
3114 the base address. Check for a base address here. */
3115 if ((range_beginning & mask) == mask)
3117 /* If we found the largest possible address, then
3118 read the base address. */
3119 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3126 /* We have no valid base address for the ranges
3128 complaint (&symfile_complaints,
3129 _("Invalid .debug_ranges data (no base address)"));
3133 range_beginning += base;
3136 /* FIXME: This is recording everything as a low-high
3137 segment of consecutive addresses. We should have a
3138 data structure for discontiguous block ranges
3142 low = range_beginning;
3148 if (range_beginning < low)
3149 low = range_beginning;
3150 if (range_end > high)
3156 /* If the first entry is an end-of-list marker, the range
3157 describes an empty scope, i.e. no instructions. */
3167 /* When using the GNU linker, .gnu.linkonce. sections are used to
3168 eliminate duplicate copies of functions and vtables and such.
3169 The linker will arbitrarily choose one and discard the others.
3170 The AT_*_pc values for such functions refer to local labels in
3171 these sections. If the section from that file was discarded, the
3172 labels are not in the output, so the relocs get a value of 0.
3173 If this is a discarded function, mark the pc bounds as invalid,
3174 so that GDB will ignore it. */
3175 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
3183 /* Get the low and high pc's represented by the scope DIE, and store
3184 them in *LOWPC and *HIGHPC. If the correct values can't be
3185 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3188 get_scope_pc_bounds (struct die_info *die,
3189 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3190 struct dwarf2_cu *cu)
3192 CORE_ADDR best_low = (CORE_ADDR) -1;
3193 CORE_ADDR best_high = (CORE_ADDR) 0;
3194 CORE_ADDR current_low, current_high;
3196 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
3198 best_low = current_low;
3199 best_high = current_high;
3203 struct die_info *child = die->child;
3205 while (child && child->tag)
3207 switch (child->tag) {
3208 case DW_TAG_subprogram:
3209 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
3211 best_low = min (best_low, current_low);
3212 best_high = max (best_high, current_high);
3215 case DW_TAG_namespace:
3216 /* FIXME: carlton/2004-01-16: Should we do this for
3217 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3218 that current GCC's always emit the DIEs corresponding
3219 to definitions of methods of classes as children of a
3220 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3221 the DIEs giving the declarations, which could be
3222 anywhere). But I don't see any reason why the
3223 standards says that they have to be there. */
3224 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
3226 if (current_low != ((CORE_ADDR) -1))
3228 best_low = min (best_low, current_low);
3229 best_high = max (best_high, current_high);
3237 child = sibling_die (child);
3242 *highpc = best_high;
3245 /* Add an aggregate field to the field list. */
3248 dwarf2_add_field (struct field_info *fip, struct die_info *die,
3249 struct dwarf2_cu *cu)
3251 struct objfile *objfile = cu->objfile;
3252 struct nextfield *new_field;
3253 struct attribute *attr;
3255 char *fieldname = "";
3257 /* Allocate a new field list entry and link it in. */
3258 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3259 make_cleanup (xfree, new_field);
3260 memset (new_field, 0, sizeof (struct nextfield));
3261 new_field->next = fip->fields;
3262 fip->fields = new_field;
3265 /* Handle accessibility and virtuality of field.
3266 The default accessibility for members is public, the default
3267 accessibility for inheritance is private. */
3268 if (die->tag != DW_TAG_inheritance)
3269 new_field->accessibility = DW_ACCESS_public;
3271 new_field->accessibility = DW_ACCESS_private;
3272 new_field->virtuality = DW_VIRTUALITY_none;
3274 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3276 new_field->accessibility = DW_UNSND (attr);
3277 if (new_field->accessibility != DW_ACCESS_public)
3278 fip->non_public_fields = 1;
3279 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
3281 new_field->virtuality = DW_UNSND (attr);
3283 fp = &new_field->field;
3285 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
3287 /* Data member other than a C++ static data member. */
3289 /* Get type of field. */
3290 fp->type = die_type (die, cu);
3292 FIELD_STATIC_KIND (*fp) = 0;
3294 /* Get bit size of field (zero if none). */
3295 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
3298 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
3302 FIELD_BITSIZE (*fp) = 0;
3305 /* Get bit offset of field. */
3306 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3309 FIELD_BITPOS (*fp) =
3310 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
3313 FIELD_BITPOS (*fp) = 0;
3314 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
3317 if (BITS_BIG_ENDIAN)
3319 /* For big endian bits, the DW_AT_bit_offset gives the
3320 additional bit offset from the MSB of the containing
3321 anonymous object to the MSB of the field. We don't
3322 have to do anything special since we don't need to
3323 know the size of the anonymous object. */
3324 FIELD_BITPOS (*fp) += DW_UNSND (attr);
3328 /* For little endian bits, compute the bit offset to the
3329 MSB of the anonymous object, subtract off the number of
3330 bits from the MSB of the field to the MSB of the
3331 object, and then subtract off the number of bits of
3332 the field itself. The result is the bit offset of
3333 the LSB of the field. */
3335 int bit_offset = DW_UNSND (attr);
3337 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3340 /* The size of the anonymous object containing
3341 the bit field is explicit, so use the
3342 indicated size (in bytes). */
3343 anonymous_size = DW_UNSND (attr);
3347 /* The size of the anonymous object containing
3348 the bit field must be inferred from the type
3349 attribute of the data member containing the
3351 anonymous_size = TYPE_LENGTH (fp->type);
3353 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
3354 - bit_offset - FIELD_BITSIZE (*fp);
3358 /* Get name of field. */
3359 attr = dwarf2_attr (die, DW_AT_name, cu);
3360 if (attr && DW_STRING (attr))
3361 fieldname = DW_STRING (attr);
3363 /* The name is already allocated along with this objfile, so we don't
3364 need to duplicate it for the type. */
3365 fp->name = fieldname;
3367 /* Change accessibility for artificial fields (e.g. virtual table
3368 pointer or virtual base class pointer) to private. */
3369 if (dwarf2_attr (die, DW_AT_artificial, cu))
3371 new_field->accessibility = DW_ACCESS_private;
3372 fip->non_public_fields = 1;
3375 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
3377 /* C++ static member. */
3379 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3380 is a declaration, but all versions of G++ as of this writing
3381 (so through at least 3.2.1) incorrectly generate
3382 DW_TAG_variable tags. */
3386 /* Get name of field. */
3387 attr = dwarf2_attr (die, DW_AT_name, cu);
3388 if (attr && DW_STRING (attr))
3389 fieldname = DW_STRING (attr);
3393 /* Get physical name. */
3394 physname = dwarf2_linkage_name (die, cu);
3396 /* The name is already allocated along with this objfile, so we don't
3397 need to duplicate it for the type. */
3398 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
3399 FIELD_TYPE (*fp) = die_type (die, cu);
3400 FIELD_NAME (*fp) = fieldname;
3402 else if (die->tag == DW_TAG_inheritance)
3404 /* C++ base class field. */
3405 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3407 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
3409 FIELD_BITSIZE (*fp) = 0;
3410 FIELD_STATIC_KIND (*fp) = 0;
3411 FIELD_TYPE (*fp) = die_type (die, cu);
3412 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3413 fip->nbaseclasses++;
3417 /* Create the vector of fields, and attach it to the type. */
3420 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3421 struct dwarf2_cu *cu)
3423 int nfields = fip->nfields;
3425 /* Record the field count, allocate space for the array of fields,
3426 and create blank accessibility bitfields if necessary. */
3427 TYPE_NFIELDS (type) = nfields;
3428 TYPE_FIELDS (type) = (struct field *)
3429 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3430 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3432 if (fip->non_public_fields)
3434 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3436 TYPE_FIELD_PRIVATE_BITS (type) =
3437 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3438 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3440 TYPE_FIELD_PROTECTED_BITS (type) =
3441 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3442 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3444 TYPE_FIELD_IGNORE_BITS (type) =
3445 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3446 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3449 /* If the type has baseclasses, allocate and clear a bit vector for
3450 TYPE_FIELD_VIRTUAL_BITS. */
3451 if (fip->nbaseclasses)
3453 int num_bytes = B_BYTES (fip->nbaseclasses);
3456 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3457 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3458 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3459 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
3460 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
3463 /* Copy the saved-up fields into the field vector. Start from the head
3464 of the list, adding to the tail of the field array, so that they end
3465 up in the same order in the array in which they were added to the list. */
3466 while (nfields-- > 0)
3468 TYPE_FIELD (type, nfields) = fip->fields->field;
3469 switch (fip->fields->accessibility)
3471 case DW_ACCESS_private:
3472 SET_TYPE_FIELD_PRIVATE (type, nfields);
3475 case DW_ACCESS_protected:
3476 SET_TYPE_FIELD_PROTECTED (type, nfields);
3479 case DW_ACCESS_public:
3483 /* Unknown accessibility. Complain and treat it as public. */
3485 complaint (&symfile_complaints, _("unsupported accessibility %d"),
3486 fip->fields->accessibility);
3490 if (nfields < fip->nbaseclasses)
3492 switch (fip->fields->virtuality)
3494 case DW_VIRTUALITY_virtual:
3495 case DW_VIRTUALITY_pure_virtual:
3496 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3500 fip->fields = fip->fields->next;
3504 /* Add a member function to the proper fieldlist. */
3507 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3508 struct type *type, struct dwarf2_cu *cu)
3510 struct objfile *objfile = cu->objfile;
3511 struct attribute *attr;
3512 struct fnfieldlist *flp;
3514 struct fn_field *fnp;
3517 struct nextfnfield *new_fnfield;
3519 /* Get name of member function. */
3520 attr = dwarf2_attr (die, DW_AT_name, cu);
3521 if (attr && DW_STRING (attr))
3522 fieldname = DW_STRING (attr);
3526 /* Get the mangled name. */
3527 physname = dwarf2_linkage_name (die, cu);
3529 /* Look up member function name in fieldlist. */
3530 for (i = 0; i < fip->nfnfields; i++)
3532 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3536 /* Create new list element if necessary. */
3537 if (i < fip->nfnfields)
3538 flp = &fip->fnfieldlists[i];
3541 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3543 fip->fnfieldlists = (struct fnfieldlist *)
3544 xrealloc (fip->fnfieldlists,
3545 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3546 * sizeof (struct fnfieldlist));
3547 if (fip->nfnfields == 0)
3548 make_cleanup (free_current_contents, &fip->fnfieldlists);
3550 flp = &fip->fnfieldlists[fip->nfnfields];
3551 flp->name = fieldname;
3557 /* Create a new member function field and chain it to the field list
3559 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3560 make_cleanup (xfree, new_fnfield);
3561 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3562 new_fnfield->next = flp->head;
3563 flp->head = new_fnfield;
3566 /* Fill in the member function field info. */
3567 fnp = &new_fnfield->fnfield;
3568 /* The name is already allocated along with this objfile, so we don't
3569 need to duplicate it for the type. */
3570 fnp->physname = physname ? physname : "";
3571 fnp->type = alloc_type (objfile);
3572 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
3574 int nparams = TYPE_NFIELDS (die->type);
3576 /* TYPE is the domain of this method, and DIE->TYPE is the type
3577 of the method itself (TYPE_CODE_METHOD). */
3578 smash_to_method_type (fnp->type, type,
3579 TYPE_TARGET_TYPE (die->type),
3580 TYPE_FIELDS (die->type),
3581 TYPE_NFIELDS (die->type),
3582 TYPE_VARARGS (die->type));
3584 /* Handle static member functions.
3585 Dwarf2 has no clean way to discern C++ static and non-static
3586 member functions. G++ helps GDB by marking the first
3587 parameter for non-static member functions (which is the
3588 this pointer) as artificial. We obtain this information
3589 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3590 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
3591 fnp->voffset = VOFFSET_STATIC;
3594 complaint (&symfile_complaints, _("member function type missing for '%s'"),
3597 /* Get fcontext from DW_AT_containing_type if present. */
3598 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3599 fnp->fcontext = die_containing_type (die, cu);
3601 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3602 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3604 /* Get accessibility. */
3605 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3608 switch (DW_UNSND (attr))
3610 case DW_ACCESS_private:
3611 fnp->is_private = 1;
3613 case DW_ACCESS_protected:
3614 fnp->is_protected = 1;
3619 /* Check for artificial methods. */
3620 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3621 if (attr && DW_UNSND (attr) != 0)
3622 fnp->is_artificial = 1;
3624 /* Get index in virtual function table if it is a virtual member function. */
3625 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3628 /* Support the .debug_loc offsets */
3629 if (attr_form_is_block (attr))
3631 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3633 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3635 dwarf2_complex_location_expr_complaint ();
3639 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3645 /* Create the vector of member function fields, and attach it to the type. */
3648 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
3649 struct dwarf2_cu *cu)
3651 struct fnfieldlist *flp;
3652 int total_length = 0;
3655 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3656 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3657 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
3659 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
3661 struct nextfnfield *nfp = flp->head;
3662 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
3665 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
3666 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
3667 fn_flp->fn_fields = (struct fn_field *)
3668 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
3669 for (k = flp->length; (k--, nfp); nfp = nfp->next)
3670 fn_flp->fn_fields[k] = nfp->fnfield;
3672 total_length += flp->length;
3675 TYPE_NFN_FIELDS (type) = fip->nfnfields;
3676 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3680 /* Returns non-zero if NAME is the name of a vtable member in CU's
3681 language, zero otherwise. */
3683 is_vtable_name (const char *name, struct dwarf2_cu *cu)
3685 static const char vptr[] = "_vptr";
3686 static const char vtable[] = "vtable";
3688 /* Look for the C++ and Java forms of the vtable. */
3689 if ((cu->language == language_java
3690 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
3691 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
3692 && is_cplus_marker (name[sizeof (vptr) - 1])))
3699 /* Called when we find the DIE that starts a structure or union scope
3700 (definition) to process all dies that define the members of the
3703 NOTE: we need to call struct_type regardless of whether or not the
3704 DIE has an at_name attribute, since it might be an anonymous
3705 structure or union. This gets the type entered into our set of
3708 However, if the structure is incomplete (an opaque struct/union)
3709 then suppress creating a symbol table entry for it since gdb only
3710 wants to find the one with the complete definition. Note that if
3711 it is complete, we just call new_symbol, which does it's own
3712 checking about whether the struct/union is anonymous or not (and
3713 suppresses creating a symbol table entry itself). */
3716 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3718 struct objfile *objfile = cu->objfile;
3720 struct attribute *attr;
3721 const char *previous_prefix = processing_current_prefix;
3722 struct cleanup *back_to = NULL;
3727 type = alloc_type (objfile);
3729 INIT_CPLUS_SPECIFIC (type);
3730 attr = dwarf2_attr (die, DW_AT_name, cu);
3731 if (attr && DW_STRING (attr))
3733 if (cu->language == language_cplus
3734 || cu->language == language_java)
3736 char *new_prefix = determine_class_name (die, cu);
3737 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3738 strlen (new_prefix),
3739 &objfile->objfile_obstack);
3740 back_to = make_cleanup (xfree, new_prefix);
3741 processing_current_prefix = new_prefix;
3745 /* The name is already allocated along with this objfile, so
3746 we don't need to duplicate it for the type. */
3747 TYPE_TAG_NAME (type) = DW_STRING (attr);
3751 if (die->tag == DW_TAG_structure_type)
3753 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3755 else if (die->tag == DW_TAG_union_type)
3757 TYPE_CODE (type) = TYPE_CODE_UNION;
3761 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3763 TYPE_CODE (type) = TYPE_CODE_CLASS;
3766 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3769 TYPE_LENGTH (type) = DW_UNSND (attr);
3773 TYPE_LENGTH (type) = 0;
3776 if (die_is_declaration (die, cu))
3777 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3779 /* We need to add the type field to the die immediately so we don't
3780 infinitely recurse when dealing with pointers to the structure
3781 type within the structure itself. */
3782 set_die_type (die, type, cu);
3784 if (die->child != NULL && ! die_is_declaration (die, cu))
3786 struct field_info fi;
3787 struct die_info *child_die;
3788 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3790 memset (&fi, 0, sizeof (struct field_info));
3792 child_die = die->child;
3794 while (child_die && child_die->tag)
3796 if (child_die->tag == DW_TAG_member
3797 || child_die->tag == DW_TAG_variable)
3799 /* NOTE: carlton/2002-11-05: A C++ static data member
3800 should be a DW_TAG_member that is a declaration, but
3801 all versions of G++ as of this writing (so through at
3802 least 3.2.1) incorrectly generate DW_TAG_variable
3803 tags for them instead. */
3804 dwarf2_add_field (&fi, child_die, cu);
3806 else if (child_die->tag == DW_TAG_subprogram)
3808 /* C++ member function. */
3809 read_type_die (child_die, cu);
3810 dwarf2_add_member_fn (&fi, child_die, type, cu);
3812 else if (child_die->tag == DW_TAG_inheritance)
3814 /* C++ base class field. */
3815 dwarf2_add_field (&fi, child_die, cu);
3817 child_die = sibling_die (child_die);
3820 /* Attach fields and member functions to the type. */
3822 dwarf2_attach_fields_to_type (&fi, type, cu);
3825 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3827 /* Get the type which refers to the base class (possibly this
3828 class itself) which contains the vtable pointer for the current
3829 class from the DW_AT_containing_type attribute. */
3831 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3833 struct type *t = die_containing_type (die, cu);
3835 TYPE_VPTR_BASETYPE (type) = t;
3840 /* Our own class provides vtbl ptr. */
3841 for (i = TYPE_NFIELDS (t) - 1;
3842 i >= TYPE_N_BASECLASSES (t);
3845 char *fieldname = TYPE_FIELD_NAME (t, i);
3847 if (is_vtable_name (fieldname, cu))
3849 TYPE_VPTR_FIELDNO (type) = i;
3854 /* Complain if virtual function table field not found. */
3855 if (i < TYPE_N_BASECLASSES (t))
3856 complaint (&symfile_complaints,
3857 _("virtual function table pointer not found when defining class '%s'"),
3858 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3863 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3868 do_cleanups (back_to);
3871 processing_current_prefix = previous_prefix;
3872 if (back_to != NULL)
3873 do_cleanups (back_to);
3877 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3879 struct objfile *objfile = cu->objfile;
3880 const char *previous_prefix = processing_current_prefix;
3881 struct die_info *child_die = die->child;
3883 if (TYPE_TAG_NAME (die->type) != NULL)
3884 processing_current_prefix = TYPE_TAG_NAME (die->type);
3886 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3887 snapshots) has been known to create a die giving a declaration
3888 for a class that has, as a child, a die giving a definition for a
3889 nested class. So we have to process our children even if the
3890 current die is a declaration. Normally, of course, a declaration
3891 won't have any children at all. */
3893 while (child_die != NULL && child_die->tag)
3895 if (child_die->tag == DW_TAG_member
3896 || child_die->tag == DW_TAG_variable
3897 || child_die->tag == DW_TAG_inheritance)
3902 process_die (child_die, cu);
3904 child_die = sibling_die (child_die);
3907 if (die->child != NULL && ! die_is_declaration (die, cu))
3908 new_symbol (die, die->type, cu);
3910 processing_current_prefix = previous_prefix;
3913 /* Given a DW_AT_enumeration_type die, set its type. We do not
3914 complete the type's fields yet, or create any symbols. */
3917 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3919 struct objfile *objfile = cu->objfile;
3921 struct attribute *attr;
3926 type = alloc_type (objfile);
3928 TYPE_CODE (type) = TYPE_CODE_ENUM;
3929 attr = dwarf2_attr (die, DW_AT_name, cu);
3930 if (attr && DW_STRING (attr))
3932 char *name = DW_STRING (attr);
3934 if (processing_has_namespace_info)
3936 TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack,
3937 processing_current_prefix,
3942 /* The name is already allocated along with this objfile, so
3943 we don't need to duplicate it for the type. */
3944 TYPE_TAG_NAME (type) = name;
3948 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3951 TYPE_LENGTH (type) = DW_UNSND (attr);
3955 TYPE_LENGTH (type) = 0;
3958 set_die_type (die, type, cu);
3961 /* Determine the name of the type represented by DIE, which should be
3962 a named C++ or Java compound type. Return the name in question; the caller
3963 is responsible for xfree()'ing it. */
3966 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3968 struct cleanup *back_to = NULL;
3969 struct die_info *spec_die = die_specification (die, cu);
3970 char *new_prefix = NULL;
3972 /* If this is the definition of a class that is declared by another
3973 die, then processing_current_prefix may not be accurate; see
3974 read_func_scope for a similar example. */
3975 if (spec_die != NULL)
3977 char *specification_prefix = determine_prefix (spec_die, cu);
3978 processing_current_prefix = specification_prefix;
3979 back_to = make_cleanup (xfree, specification_prefix);
3982 /* If we don't have namespace debug info, guess the name by trying
3983 to demangle the names of members, just like we did in
3984 guess_structure_name. */
3985 if (!processing_has_namespace_info)
3987 struct die_info *child;
3989 for (child = die->child;
3990 child != NULL && child->tag != 0;
3991 child = sibling_die (child))
3993 if (child->tag == DW_TAG_subprogram)
3996 = language_class_name_from_physname (cu->language_defn,
4000 if (new_prefix != NULL)
4006 if (new_prefix == NULL)
4008 const char *name = dwarf2_name (die, cu);
4009 new_prefix = typename_concat (NULL, processing_current_prefix,
4010 name ? name : "<<anonymous>>",
4014 if (back_to != NULL)
4015 do_cleanups (back_to);
4020 /* Given a pointer to a die which begins an enumeration, process all
4021 the dies that define the members of the enumeration, and create the
4022 symbol for the enumeration type.
4024 NOTE: We reverse the order of the element list. */
4027 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
4029 struct objfile *objfile = cu->objfile;
4030 struct die_info *child_die;
4031 struct field *fields;
4032 struct attribute *attr;
4035 int unsigned_enum = 1;
4039 if (die->child != NULL)
4041 child_die = die->child;
4042 while (child_die && child_die->tag)
4044 if (child_die->tag != DW_TAG_enumerator)
4046 process_die (child_die, cu);
4050 attr = dwarf2_attr (child_die, DW_AT_name, cu);
4053 sym = new_symbol (child_die, die->type, cu);
4054 if (SYMBOL_VALUE (sym) < 0)
4057 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
4059 fields = (struct field *)
4061 (num_fields + DW_FIELD_ALLOC_CHUNK)
4062 * sizeof (struct field));
4065 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
4066 FIELD_TYPE (fields[num_fields]) = NULL;
4067 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
4068 FIELD_BITSIZE (fields[num_fields]) = 0;
4069 FIELD_STATIC_KIND (fields[num_fields]) = 0;
4075 child_die = sibling_die (child_die);
4080 TYPE_NFIELDS (die->type) = num_fields;
4081 TYPE_FIELDS (die->type) = (struct field *)
4082 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
4083 memcpy (TYPE_FIELDS (die->type), fields,
4084 sizeof (struct field) * num_fields);
4088 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
4091 new_symbol (die, die->type, cu);
4094 /* Extract all information from a DW_TAG_array_type DIE and put it in
4095 the DIE's type field. For now, this only handles one dimensional
4099 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
4101 struct objfile *objfile = cu->objfile;
4102 struct die_info *child_die;
4103 struct type *type = NULL;
4104 struct type *element_type, *range_type, *index_type;
4105 struct type **range_types = NULL;
4106 struct attribute *attr;
4108 struct cleanup *back_to;
4110 /* Return if we've already decoded this type. */
4116 element_type = die_type (die, cu);
4118 /* Irix 6.2 native cc creates array types without children for
4119 arrays with unspecified length. */
4120 if (die->child == NULL)
4122 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
4123 range_type = create_range_type (NULL, index_type, 0, -1);
4124 set_die_type (die, create_array_type (NULL, element_type, range_type),
4129 back_to = make_cleanup (null_cleanup, NULL);
4130 child_die = die->child;
4131 while (child_die && child_die->tag)
4133 if (child_die->tag == DW_TAG_subrange_type)
4135 read_subrange_type (child_die, cu);
4137 if (child_die->type != NULL)
4139 /* The range type was succesfully read. Save it for
4140 the array type creation. */
4141 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
4143 range_types = (struct type **)
4144 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
4145 * sizeof (struct type *));
4147 make_cleanup (free_current_contents, &range_types);
4149 range_types[ndim++] = child_die->type;
4152 child_die = sibling_die (child_die);
4155 /* Dwarf2 dimensions are output from left to right, create the
4156 necessary array types in backwards order. */
4158 type = element_type;
4160 if (read_array_order (die, cu) == DW_ORD_col_major)
4164 type = create_array_type (NULL, type, range_types[i++]);
4169 type = create_array_type (NULL, type, range_types[ndim]);
4172 /* Understand Dwarf2 support for vector types (like they occur on
4173 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4174 array type. This is not part of the Dwarf2/3 standard yet, but a
4175 custom vendor extension. The main difference between a regular
4176 array and the vector variant is that vectors are passed by value
4178 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
4180 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
4182 do_cleanups (back_to);
4184 /* Install the type in the die. */
4185 set_die_type (die, type, cu);
4188 static enum dwarf_array_dim_ordering
4189 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
4191 struct attribute *attr;
4193 attr = dwarf2_attr (die, DW_AT_ordering, cu);
4195 if (attr) return DW_SND (attr);
4198 GNU F77 is a special case, as at 08/2004 array type info is the
4199 opposite order to the dwarf2 specification, but data is still
4200 laid out as per normal fortran.
4202 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4206 if (cu->language == language_fortran &&
4207 cu->producer && strstr (cu->producer, "GNU F77"))
4209 return DW_ORD_row_major;
4212 switch (cu->language_defn->la_array_ordering)
4214 case array_column_major:
4215 return DW_ORD_col_major;
4216 case array_row_major:
4218 return DW_ORD_row_major;
4223 /* First cut: install each common block member as a global variable. */
4226 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
4228 struct die_info *child_die;
4229 struct attribute *attr;
4231 CORE_ADDR base = (CORE_ADDR) 0;
4233 attr = dwarf2_attr (die, DW_AT_location, cu);
4236 /* Support the .debug_loc offsets */
4237 if (attr_form_is_block (attr))
4239 base = decode_locdesc (DW_BLOCK (attr), cu);
4241 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
4243 dwarf2_complex_location_expr_complaint ();
4247 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4248 "common block member");
4251 if (die->child != NULL)
4253 child_die = die->child;
4254 while (child_die && child_die->tag)
4256 sym = new_symbol (child_die, NULL, cu);
4257 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
4260 SYMBOL_VALUE_ADDRESS (sym) =
4261 base + decode_locdesc (DW_BLOCK (attr), cu);
4262 add_symbol_to_list (sym, &global_symbols);
4264 child_die = sibling_die (child_die);
4269 /* Read a C++ namespace. */
4272 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
4274 struct objfile *objfile = cu->objfile;
4275 const char *previous_prefix = processing_current_prefix;
4278 struct die_info *current_die;
4279 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4281 name = namespace_name (die, &is_anonymous, cu);
4283 /* Now build the name of the current namespace. */
4285 if (previous_prefix[0] == '\0')
4287 processing_current_prefix = name;
4291 char *temp_name = typename_concat (NULL, previous_prefix, name, cu);
4292 make_cleanup (xfree, temp_name);
4293 processing_current_prefix = temp_name;
4296 /* Add a symbol associated to this if we haven't seen the namespace
4297 before. Also, add a using directive if it's an anonymous
4300 if (dwarf2_extension (die, cu) == NULL)
4304 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4305 this cast will hopefully become unnecessary. */
4306 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
4307 (char *) processing_current_prefix,
4309 TYPE_TAG_NAME (type) = TYPE_NAME (type);
4311 new_symbol (die, type, cu);
4312 set_die_type (die, type, cu);
4315 cp_add_using_directive (processing_current_prefix,
4316 strlen (previous_prefix),
4317 strlen (processing_current_prefix));
4320 if (die->child != NULL)
4322 struct die_info *child_die = die->child;
4324 while (child_die && child_die->tag)
4326 process_die (child_die, cu);
4327 child_die = sibling_die (child_die);
4331 processing_current_prefix = previous_prefix;
4332 do_cleanups (back_to);
4335 /* Return the name of the namespace represented by DIE. Set
4336 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4340 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
4342 struct die_info *current_die;
4343 const char *name = NULL;
4345 /* Loop through the extensions until we find a name. */
4347 for (current_die = die;
4348 current_die != NULL;
4349 current_die = dwarf2_extension (die, cu))
4351 name = dwarf2_name (current_die, cu);
4356 /* Is it an anonymous namespace? */
4358 *is_anonymous = (name == NULL);
4360 name = "(anonymous namespace)";
4365 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4366 the user defined type vector. */
4369 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
4371 struct comp_unit_head *cu_header = &cu->header;
4373 struct attribute *attr_byte_size;
4374 struct attribute *attr_address_class;
4375 int byte_size, addr_class;
4382 type = lookup_pointer_type (die_type (die, cu));
4384 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
4386 byte_size = DW_UNSND (attr_byte_size);
4388 byte_size = cu_header->addr_size;
4390 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
4391 if (attr_address_class)
4392 addr_class = DW_UNSND (attr_address_class);
4394 addr_class = DW_ADDR_none;
4396 /* If the pointer size or address class is different than the
4397 default, create a type variant marked as such and set the
4398 length accordingly. */
4399 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
4401 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4405 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
4406 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
4407 type = make_type_with_address_space (type, type_flags);
4409 else if (TYPE_LENGTH (type) != byte_size)
4411 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
4414 /* Should we also complain about unhandled address classes? */
4418 TYPE_LENGTH (type) = byte_size;
4419 set_die_type (die, type, cu);
4422 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4423 the user defined type vector. */
4426 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
4428 struct objfile *objfile = cu->objfile;
4430 struct type *to_type;
4431 struct type *domain;
4438 type = alloc_type (objfile);
4439 to_type = die_type (die, cu);
4440 domain = die_containing_type (die, cu);
4441 smash_to_member_type (type, domain, to_type);
4443 set_die_type (die, type, cu);
4446 /* Extract all information from a DW_TAG_reference_type DIE and add to
4447 the user defined type vector. */
4450 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
4452 struct comp_unit_head *cu_header = &cu->header;
4454 struct attribute *attr;
4461 type = lookup_reference_type (die_type (die, cu));
4462 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4465 TYPE_LENGTH (type) = DW_UNSND (attr);
4469 TYPE_LENGTH (type) = cu_header->addr_size;
4471 set_die_type (die, type, cu);
4475 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
4477 struct type *base_type;
4484 base_type = die_type (die, cu);
4485 set_die_type (die, make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0),
4490 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
4492 struct type *base_type;
4499 base_type = die_type (die, cu);
4500 set_die_type (die, make_cv_type (TYPE_CONST (base_type), 1, base_type, 0),
4504 /* Extract all information from a DW_TAG_string_type DIE and add to
4505 the user defined type vector. It isn't really a user defined type,
4506 but it behaves like one, with other DIE's using an AT_user_def_type
4507 attribute to reference it. */
4510 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
4512 struct objfile *objfile = cu->objfile;
4513 struct type *type, *range_type, *index_type, *char_type;
4514 struct attribute *attr;
4515 unsigned int length;
4522 attr = dwarf2_attr (die, DW_AT_string_length, cu);
4525 length = DW_UNSND (attr);
4529 /* check for the DW_AT_byte_size attribute */
4530 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4533 length = DW_UNSND (attr);
4540 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
4541 range_type = create_range_type (NULL, index_type, 1, length);
4542 if (cu->language == language_fortran)
4544 /* Need to create a unique string type for bounds
4546 type = create_string_type (0, range_type);
4550 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
4551 type = create_string_type (char_type, range_type);
4553 set_die_type (die, type, cu);
4556 /* Handle DIES due to C code like:
4560 int (*funcp)(int a, long l);
4564 ('funcp' generates a DW_TAG_subroutine_type DIE)
4568 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4570 struct type *type; /* Type that this function returns */
4571 struct type *ftype; /* Function that returns above type */
4572 struct attribute *attr;
4574 /* Decode the type that this subroutine returns */
4579 type = die_type (die, cu);
4580 ftype = make_function_type (type, (struct type **) 0);
4582 /* All functions in C++ and Java have prototypes. */
4583 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
4584 if ((attr && (DW_UNSND (attr) != 0))
4585 || cu->language == language_cplus
4586 || cu->language == language_java)
4587 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
4589 if (die->child != NULL)
4591 struct die_info *child_die;
4595 /* Count the number of parameters.
4596 FIXME: GDB currently ignores vararg functions, but knows about
4597 vararg member functions. */
4598 child_die = die->child;
4599 while (child_die && child_die->tag)
4601 if (child_die->tag == DW_TAG_formal_parameter)
4603 else if (child_die->tag == DW_TAG_unspecified_parameters)
4604 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
4605 child_die = sibling_die (child_die);
4608 /* Allocate storage for parameters and fill them in. */
4609 TYPE_NFIELDS (ftype) = nparams;
4610 TYPE_FIELDS (ftype) = (struct field *)
4611 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
4613 child_die = die->child;
4614 while (child_die && child_die->tag)
4616 if (child_die->tag == DW_TAG_formal_parameter)
4618 /* Dwarf2 has no clean way to discern C++ static and non-static
4619 member functions. G++ helps GDB by marking the first
4620 parameter for non-static member functions (which is the
4621 this pointer) as artificial. We pass this information
4622 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4623 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
4625 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
4627 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
4628 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
4631 child_die = sibling_die (child_die);
4635 set_die_type (die, ftype, cu);
4639 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
4641 struct objfile *objfile = cu->objfile;
4642 struct attribute *attr;
4647 attr = dwarf2_attr (die, DW_AT_name, cu);
4648 if (attr && DW_STRING (attr))
4650 name = DW_STRING (attr);
4652 set_die_type (die, init_type (TYPE_CODE_TYPEDEF, 0,
4653 TYPE_FLAG_TARGET_STUB, name, objfile),
4655 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
4659 /* Find a representation of a given base type and install
4660 it in the TYPE field of the die. */
4663 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
4665 struct objfile *objfile = cu->objfile;
4667 struct attribute *attr;
4668 int encoding = 0, size = 0;
4670 /* If we've already decoded this die, this is a no-op. */
4676 attr = dwarf2_attr (die, DW_AT_encoding, cu);
4679 encoding = DW_UNSND (attr);
4681 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4684 size = DW_UNSND (attr);
4686 attr = dwarf2_attr (die, DW_AT_name, cu);
4687 if (attr && DW_STRING (attr))
4689 enum type_code code = TYPE_CODE_INT;
4694 case DW_ATE_address:
4695 /* Turn DW_ATE_address into a void * pointer. */
4696 code = TYPE_CODE_PTR;
4697 type_flags |= TYPE_FLAG_UNSIGNED;
4699 case DW_ATE_boolean:
4700 code = TYPE_CODE_BOOL;
4701 type_flags |= TYPE_FLAG_UNSIGNED;
4703 case DW_ATE_complex_float:
4704 code = TYPE_CODE_COMPLEX;
4707 code = TYPE_CODE_FLT;
4710 case DW_ATE_signed_char:
4712 case DW_ATE_unsigned:
4713 case DW_ATE_unsigned_char:
4714 type_flags |= TYPE_FLAG_UNSIGNED;
4717 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
4718 dwarf_type_encoding_name (encoding));
4721 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4722 if (encoding == DW_ATE_address)
4723 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4725 else if (encoding == DW_ATE_complex_float)
4728 TYPE_TARGET_TYPE (type)
4729 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4730 else if (size == 16)
4731 TYPE_TARGET_TYPE (type)
4732 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4734 TYPE_TARGET_TYPE (type)
4735 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4740 type = dwarf_base_type (encoding, size, cu);
4742 set_die_type (die, type, cu);
4745 /* Read the given DW_AT_subrange DIE. */
4748 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4750 struct type *base_type;
4751 struct type *range_type;
4752 struct attribute *attr;
4756 /* If we have already decoded this die, then nothing more to do. */
4760 base_type = die_type (die, cu);
4761 if (base_type == NULL)
4763 complaint (&symfile_complaints,
4764 _("DW_AT_type missing from DW_TAG_subrange_type"));
4768 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4769 base_type = alloc_type (NULL);
4771 if (cu->language == language_fortran)
4773 /* FORTRAN implies a lower bound of 1, if not given. */
4777 /* FIXME: For variable sized arrays either of these could be
4778 a variable rather than a constant value. We'll allow it,
4779 but we don't know how to handle it. */
4780 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4782 low = dwarf2_get_attr_constant_value (attr, 0);
4784 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4787 if (attr->form == DW_FORM_block1)
4789 /* GCC encodes arrays with unspecified or dynamic length
4790 with a DW_FORM_block1 attribute.
4791 FIXME: GDB does not yet know how to handle dynamic
4792 arrays properly, treat them as arrays with unspecified
4795 FIXME: jimb/2003-09-22: GDB does not really know
4796 how to handle arrays of unspecified length
4797 either; we just represent them as zero-length
4798 arrays. Choose an appropriate upper bound given
4799 the lower bound we've computed above. */
4803 high = dwarf2_get_attr_constant_value (attr, 1);
4806 range_type = create_range_type (NULL, base_type, low, high);
4808 attr = dwarf2_attr (die, DW_AT_name, cu);
4809 if (attr && DW_STRING (attr))
4810 TYPE_NAME (range_type) = DW_STRING (attr);
4812 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4814 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4816 set_die_type (die, range_type, cu);
4820 /* Read a whole compilation unit into a linked list of dies. */
4822 static struct die_info *
4823 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4825 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4828 /* Read a single die and all its descendents. Set the die's sibling
4829 field to NULL; set other fields in the die correctly, and set all
4830 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4831 location of the info_ptr after reading all of those dies. PARENT
4832 is the parent of the die in question. */
4834 static struct die_info *
4835 read_die_and_children (char *info_ptr, bfd *abfd,
4836 struct dwarf2_cu *cu,
4837 char **new_info_ptr,
4838 struct die_info *parent)
4840 struct die_info *die;
4844 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4845 store_in_ref_table (die->offset, die, cu);
4849 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4855 *new_info_ptr = cur_ptr;
4858 die->sibling = NULL;
4859 die->parent = parent;
4863 /* Read a die, all of its descendents, and all of its siblings; set
4864 all of the fields of all of the dies correctly. Arguments are as
4865 in read_die_and_children. */
4867 static struct die_info *
4868 read_die_and_siblings (char *info_ptr, bfd *abfd,
4869 struct dwarf2_cu *cu,
4870 char **new_info_ptr,
4871 struct die_info *parent)
4873 struct die_info *first_die, *last_sibling;
4877 first_die = last_sibling = NULL;
4881 struct die_info *die
4882 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4890 last_sibling->sibling = die;
4895 *new_info_ptr = cur_ptr;
4905 /* Free a linked list of dies. */
4908 free_die_list (struct die_info *dies)
4910 struct die_info *die, *next;
4915 if (die->child != NULL)
4916 free_die_list (die->child);
4917 next = die->sibling;
4924 /* Read the contents of the section at OFFSET and of size SIZE from the
4925 object file specified by OBJFILE into the objfile_obstack and return it. */
4928 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4930 bfd *abfd = objfile->obfd;
4932 bfd_size_type size = bfd_get_section_size (sectp);
4937 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4939 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4943 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4944 || bfd_bread (buf, size, abfd) != size)
4945 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
4946 bfd_get_filename (abfd));
4951 /* In DWARF version 2, the description of the debugging information is
4952 stored in a separate .debug_abbrev section. Before we read any
4953 dies from a section we read in all abbreviations and install them
4954 in a hash table. This function also sets flags in CU describing
4955 the data found in the abbrev table. */
4958 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4960 struct comp_unit_head *cu_header = &cu->header;
4962 struct abbrev_info *cur_abbrev;
4963 unsigned int abbrev_number, bytes_read, abbrev_name;
4964 unsigned int abbrev_form, hash_number;
4965 struct attr_abbrev *cur_attrs;
4966 unsigned int allocated_attrs;
4968 /* Initialize dwarf2 abbrevs */
4969 obstack_init (&cu->abbrev_obstack);
4970 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
4972 * sizeof (struct abbrev_info *)));
4973 memset (cu->dwarf2_abbrevs, 0,
4974 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
4976 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
4977 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4978 abbrev_ptr += bytes_read;
4980 allocated_attrs = ATTR_ALLOC_CHUNK;
4981 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
4983 /* loop until we reach an abbrev number of 0 */
4984 while (abbrev_number)
4986 cur_abbrev = dwarf_alloc_abbrev (cu);
4988 /* read in abbrev header */
4989 cur_abbrev->number = abbrev_number;
4990 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4991 abbrev_ptr += bytes_read;
4992 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4995 if (cur_abbrev->tag == DW_TAG_namespace)
4996 cu->has_namespace_info = 1;
4998 /* now read in declarations */
4999 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5000 abbrev_ptr += bytes_read;
5001 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5002 abbrev_ptr += bytes_read;
5005 if (cur_abbrev->num_attrs == allocated_attrs)
5007 allocated_attrs += ATTR_ALLOC_CHUNK;
5009 = xrealloc (cur_attrs, (allocated_attrs
5010 * sizeof (struct attr_abbrev)));
5013 /* Record whether this compilation unit might have
5014 inter-compilation-unit references. If we don't know what form
5015 this attribute will have, then it might potentially be a
5016 DW_FORM_ref_addr, so we conservatively expect inter-CU
5019 if (abbrev_form == DW_FORM_ref_addr
5020 || abbrev_form == DW_FORM_indirect)
5021 cu->has_form_ref_addr = 1;
5023 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
5024 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
5025 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5026 abbrev_ptr += bytes_read;
5027 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5028 abbrev_ptr += bytes_read;
5031 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
5032 (cur_abbrev->num_attrs
5033 * sizeof (struct attr_abbrev)));
5034 memcpy (cur_abbrev->attrs, cur_attrs,
5035 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
5037 hash_number = abbrev_number % ABBREV_HASH_SIZE;
5038 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
5039 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
5041 /* Get next abbreviation.
5042 Under Irix6 the abbreviations for a compilation unit are not
5043 always properly terminated with an abbrev number of 0.
5044 Exit loop if we encounter an abbreviation which we have
5045 already read (which means we are about to read the abbreviations
5046 for the next compile unit) or if the end of the abbreviation
5047 table is reached. */
5048 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
5049 >= dwarf2_per_objfile->abbrev_size)
5051 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5052 abbrev_ptr += bytes_read;
5053 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
5060 /* Release the memory used by the abbrev table for a compilation unit. */
5063 dwarf2_free_abbrev_table (void *ptr_to_cu)
5065 struct dwarf2_cu *cu = ptr_to_cu;
5067 obstack_free (&cu->abbrev_obstack, NULL);
5068 cu->dwarf2_abbrevs = NULL;
5071 /* Lookup an abbrev_info structure in the abbrev hash table. */
5073 static struct abbrev_info *
5074 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
5076 unsigned int hash_number;
5077 struct abbrev_info *abbrev;
5079 hash_number = number % ABBREV_HASH_SIZE;
5080 abbrev = cu->dwarf2_abbrevs[hash_number];
5084 if (abbrev->number == number)
5087 abbrev = abbrev->next;
5092 /* Returns nonzero if TAG represents a type that we might generate a partial
5096 is_type_tag_for_partial (int tag)
5101 /* Some types that would be reasonable to generate partial symbols for,
5102 that we don't at present. */
5103 case DW_TAG_array_type:
5104 case DW_TAG_file_type:
5105 case DW_TAG_ptr_to_member_type:
5106 case DW_TAG_set_type:
5107 case DW_TAG_string_type:
5108 case DW_TAG_subroutine_type:
5110 case DW_TAG_base_type:
5111 case DW_TAG_class_type:
5112 case DW_TAG_enumeration_type:
5113 case DW_TAG_structure_type:
5114 case DW_TAG_subrange_type:
5115 case DW_TAG_typedef:
5116 case DW_TAG_union_type:
5123 /* Load all DIEs that are interesting for partial symbols into memory. */
5125 static struct partial_die_info *
5126 load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab,
5127 struct dwarf2_cu *cu)
5129 struct partial_die_info *part_die;
5130 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
5131 struct abbrev_info *abbrev;
5132 unsigned int bytes_read;
5134 int nesting_level = 1;
5140 = htab_create_alloc_ex (cu->header.length / 12,
5144 &cu->comp_unit_obstack,
5145 hashtab_obstack_allocate,
5146 dummy_obstack_deallocate);
5148 part_die = obstack_alloc (&cu->comp_unit_obstack,
5149 sizeof (struct partial_die_info));
5153 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
5155 /* A NULL abbrev means the end of a series of children. */
5158 if (--nesting_level == 0)
5160 /* PART_DIE was probably the last thing allocated on the
5161 comp_unit_obstack, so we could call obstack_free
5162 here. We don't do that because the waste is small,
5163 and will be cleaned up when we're done with this
5164 compilation unit. This way, we're also more robust
5165 against other users of the comp_unit_obstack. */
5168 info_ptr += bytes_read;
5169 last_die = parent_die;
5170 parent_die = parent_die->die_parent;
5174 /* Check whether this DIE is interesting enough to save. */
5175 if (!is_type_tag_for_partial (abbrev->tag)
5176 && abbrev->tag != DW_TAG_enumerator
5177 && abbrev->tag != DW_TAG_subprogram
5178 && abbrev->tag != DW_TAG_variable
5179 && abbrev->tag != DW_TAG_namespace)
5181 /* Otherwise we skip to the next sibling, if any. */
5182 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
5186 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
5187 abfd, info_ptr, cu);
5189 /* This two-pass algorithm for processing partial symbols has a
5190 high cost in cache pressure. Thus, handle some simple cases
5191 here which cover the majority of C partial symbols. DIEs
5192 which neither have specification tags in them, nor could have
5193 specification tags elsewhere pointing at them, can simply be
5194 processed and discarded.
5196 This segment is also optional; scan_partial_symbols and
5197 add_partial_symbol will handle these DIEs if we chain
5198 them in normally. When compilers which do not emit large
5199 quantities of duplicate debug information are more common,
5200 this code can probably be removed. */
5202 /* Any complete simple types at the top level (pretty much all
5203 of them, for a language without namespaces), can be processed
5205 if (parent_die == NULL
5206 && part_die->has_specification == 0
5207 && part_die->is_declaration == 0
5208 && (part_die->tag == DW_TAG_typedef
5209 || part_die->tag == DW_TAG_base_type
5210 || part_die->tag == DW_TAG_subrange_type))
5212 if (building_psymtab && part_die->name != NULL)
5213 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5214 VAR_DOMAIN, LOC_TYPEDEF,
5215 &cu->objfile->static_psymbols,
5216 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5217 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5221 /* If we're at the second level, and we're an enumerator, and
5222 our parent has no specification (meaning possibly lives in a
5223 namespace elsewhere), then we can add the partial symbol now
5224 instead of queueing it. */
5225 if (part_die->tag == DW_TAG_enumerator
5226 && parent_die != NULL
5227 && parent_die->die_parent == NULL
5228 && parent_die->tag == DW_TAG_enumeration_type
5229 && parent_die->has_specification == 0)
5231 if (part_die->name == NULL)
5232 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
5233 else if (building_psymtab)
5234 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5235 VAR_DOMAIN, LOC_CONST,
5236 (cu->language == language_cplus
5237 || cu->language == language_java)
5238 ? &cu->objfile->global_psymbols
5239 : &cu->objfile->static_psymbols,
5240 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5242 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5246 /* We'll save this DIE so link it in. */
5247 part_die->die_parent = parent_die;
5248 part_die->die_sibling = NULL;
5249 part_die->die_child = NULL;
5251 if (last_die && last_die == parent_die)
5252 last_die->die_child = part_die;
5254 last_die->die_sibling = part_die;
5256 last_die = part_die;
5258 if (first_die == NULL)
5259 first_die = part_die;
5261 /* Maybe add the DIE to the hash table. Not all DIEs that we
5262 find interesting need to be in the hash table, because we
5263 also have the parent/sibling/child chains; only those that we
5264 might refer to by offset later during partial symbol reading.
5266 For now this means things that might have be the target of a
5267 DW_AT_specification, DW_AT_abstract_origin, or
5268 DW_AT_extension. DW_AT_extension will refer only to
5269 namespaces; DW_AT_abstract_origin refers to functions (and
5270 many things under the function DIE, but we do not recurse
5271 into function DIEs during partial symbol reading) and
5272 possibly variables as well; DW_AT_specification refers to
5273 declarations. Declarations ought to have the DW_AT_declaration
5274 flag. It happens that GCC forgets to put it in sometimes, but
5275 only for functions, not for types.
5277 Adding more things than necessary to the hash table is harmless
5278 except for the performance cost. Adding too few will result in
5279 internal errors in find_partial_die. */
5281 if (abbrev->tag == DW_TAG_subprogram
5282 || abbrev->tag == DW_TAG_variable
5283 || abbrev->tag == DW_TAG_namespace
5284 || part_die->is_declaration)
5288 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
5289 part_die->offset, INSERT);
5293 part_die = obstack_alloc (&cu->comp_unit_obstack,
5294 sizeof (struct partial_die_info));
5296 /* For some DIEs we want to follow their children (if any). For C
5297 we have no reason to follow the children of structures; for other
5298 languages we have to, both so that we can get at method physnames
5299 to infer fully qualified class names, and for DW_AT_specification. */
5300 if (last_die->has_children
5301 && (last_die->tag == DW_TAG_namespace
5302 || last_die->tag == DW_TAG_enumeration_type
5303 || (cu->language != language_c
5304 && (last_die->tag == DW_TAG_class_type
5305 || last_die->tag == DW_TAG_structure_type
5306 || last_die->tag == DW_TAG_union_type))))
5309 parent_die = last_die;
5313 /* Otherwise we skip to the next sibling, if any. */
5314 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
5316 /* Back to the top, do it again. */
5320 /* Read a minimal amount of information into the minimal die structure. */
5323 read_partial_die (struct partial_die_info *part_die,
5324 struct abbrev_info *abbrev,
5325 unsigned int abbrev_len, bfd *abfd,
5326 char *info_ptr, struct dwarf2_cu *cu)
5328 unsigned int bytes_read, i;
5329 struct attribute attr;
5330 int has_low_pc_attr = 0;
5331 int has_high_pc_attr = 0;
5333 memset (part_die, 0, sizeof (struct partial_die_info));
5335 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
5337 info_ptr += abbrev_len;
5342 part_die->tag = abbrev->tag;
5343 part_die->has_children = abbrev->has_children;
5345 for (i = 0; i < abbrev->num_attrs; ++i)
5347 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
5349 /* Store the data if it is of an attribute we want to keep in a
5350 partial symbol table. */
5355 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5356 if (part_die->name == NULL)
5357 part_die->name = DW_STRING (&attr);
5359 case DW_AT_comp_dir:
5360 if (part_die->dirname == NULL)
5361 part_die->dirname = DW_STRING (&attr);
5363 case DW_AT_MIPS_linkage_name:
5364 part_die->name = DW_STRING (&attr);
5367 has_low_pc_attr = 1;
5368 part_die->lowpc = DW_ADDR (&attr);
5371 has_high_pc_attr = 1;
5372 part_die->highpc = DW_ADDR (&attr);
5374 case DW_AT_location:
5375 /* Support the .debug_loc offsets */
5376 if (attr_form_is_block (&attr))
5378 part_die->locdesc = DW_BLOCK (&attr);
5380 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
5382 dwarf2_complex_location_expr_complaint ();
5386 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5387 "partial symbol information");
5390 case DW_AT_language:
5391 part_die->language = DW_UNSND (&attr);
5393 case DW_AT_external:
5394 part_die->is_external = DW_UNSND (&attr);
5396 case DW_AT_declaration:
5397 part_die->is_declaration = DW_UNSND (&attr);
5400 part_die->has_type = 1;
5402 case DW_AT_abstract_origin:
5403 case DW_AT_specification:
5404 case DW_AT_extension:
5405 part_die->has_specification = 1;
5406 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
5409 /* Ignore absolute siblings, they might point outside of
5410 the current compile unit. */
5411 if (attr.form == DW_FORM_ref_addr)
5412 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
5414 part_die->sibling = dwarf2_per_objfile->info_buffer
5415 + dwarf2_get_ref_die_offset (&attr, cu);
5417 case DW_AT_stmt_list:
5418 part_die->has_stmt_list = 1;
5419 part_die->line_offset = DW_UNSND (&attr);
5426 /* When using the GNU linker, .gnu.linkonce. sections are used to
5427 eliminate duplicate copies of functions and vtables and such.
5428 The linker will arbitrarily choose one and discard the others.
5429 The AT_*_pc values for such functions refer to local labels in
5430 these sections. If the section from that file was discarded, the
5431 labels are not in the output, so the relocs get a value of 0.
5432 If this is a discarded function, mark the pc bounds as invalid,
5433 so that GDB will ignore it. */
5434 if (has_low_pc_attr && has_high_pc_attr
5435 && part_die->lowpc < part_die->highpc
5436 && (part_die->lowpc != 0
5437 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
5438 part_die->has_pc_info = 1;
5442 /* Find a cached partial DIE at OFFSET in CU. */
5444 static struct partial_die_info *
5445 find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu)
5447 struct partial_die_info *lookup_die = NULL;
5448 struct partial_die_info part_die;
5450 part_die.offset = offset;
5451 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
5453 if (lookup_die == NULL)
5454 internal_error (__FILE__, __LINE__,
5455 _("could not find partial DIE in cache\n"));
5460 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5462 static struct partial_die_info *
5463 find_partial_die (unsigned long offset, struct dwarf2_cu *cu)
5465 struct dwarf2_per_cu_data *per_cu;
5467 if (offset >= cu->header.offset
5468 && offset < cu->header.offset + cu->header.length)
5469 return find_partial_die_in_comp_unit (offset, cu);
5471 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
5473 if (per_cu->cu == NULL)
5475 load_comp_unit (per_cu, cu->objfile);
5476 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
5477 dwarf2_per_objfile->read_in_chain = per_cu;
5480 per_cu->cu->last_used = 0;
5481 return find_partial_die_in_comp_unit (offset, per_cu->cu);
5484 /* Adjust PART_DIE before generating a symbol for it. This function
5485 may set the is_external flag or change the DIE's name. */
5488 fixup_partial_die (struct partial_die_info *part_die,
5489 struct dwarf2_cu *cu)
5491 /* If we found a reference attribute and the DIE has no name, try
5492 to find a name in the referred to DIE. */
5494 if (part_die->name == NULL && part_die->has_specification)
5496 struct partial_die_info *spec_die;
5498 spec_die = find_partial_die (part_die->spec_offset, cu);
5500 fixup_partial_die (spec_die, cu);
5504 part_die->name = spec_die->name;
5506 /* Copy DW_AT_external attribute if it is set. */
5507 if (spec_die->is_external)
5508 part_die->is_external = spec_die->is_external;
5512 /* Set default names for some unnamed DIEs. */
5513 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
5514 || part_die->tag == DW_TAG_class_type))
5515 part_die->name = "(anonymous class)";
5517 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
5518 part_die->name = "(anonymous namespace)";
5520 if (part_die->tag == DW_TAG_structure_type
5521 || part_die->tag == DW_TAG_class_type
5522 || part_die->tag == DW_TAG_union_type)
5523 guess_structure_name (part_die, cu);
5526 /* Read the die from the .debug_info section buffer. Set DIEP to
5527 point to a newly allocated die with its information, except for its
5528 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5529 whether the die has children or not. */
5532 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
5533 struct dwarf2_cu *cu, int *has_children)
5535 unsigned int abbrev_number, bytes_read, i, offset;
5536 struct abbrev_info *abbrev;
5537 struct die_info *die;
5539 offset = info_ptr - dwarf2_per_objfile->info_buffer;
5540 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5541 info_ptr += bytes_read;
5544 die = dwarf_alloc_die ();
5546 die->abbrev = abbrev_number;
5553 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
5556 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
5558 bfd_get_filename (abfd));
5560 die = dwarf_alloc_die ();
5561 die->offset = offset;
5562 die->tag = abbrev->tag;
5563 die->abbrev = abbrev_number;
5566 die->num_attrs = abbrev->num_attrs;
5567 die->attrs = (struct attribute *)
5568 xmalloc (die->num_attrs * sizeof (struct attribute));
5570 for (i = 0; i < abbrev->num_attrs; ++i)
5572 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
5573 abfd, info_ptr, cu);
5575 /* If this attribute is an absolute reference to a different
5576 compilation unit, make sure that compilation unit is loaded
5578 if (die->attrs[i].form == DW_FORM_ref_addr
5579 && (DW_ADDR (&die->attrs[i]) < cu->header.offset
5580 || (DW_ADDR (&die->attrs[i])
5581 >= cu->header.offset + cu->header.length)))
5583 struct dwarf2_per_cu_data *per_cu;
5584 per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (&die->attrs[i]),
5587 /* Mark the dependence relation so that we don't flush PER_CU
5589 dwarf2_add_dependence (cu, per_cu);
5591 /* If it's already on the queue, we have nothing to do. */
5595 /* If the compilation unit is already loaded, just mark it as
5597 if (per_cu->cu != NULL)
5599 per_cu->cu->last_used = 0;
5603 /* Add it to the queue. */
5604 queue_comp_unit (per_cu);
5609 *has_children = abbrev->has_children;
5613 /* Read an attribute value described by an attribute form. */
5616 read_attribute_value (struct attribute *attr, unsigned form,
5617 bfd *abfd, char *info_ptr,
5618 struct dwarf2_cu *cu)
5620 struct comp_unit_head *cu_header = &cu->header;
5621 unsigned int bytes_read;
5622 struct dwarf_block *blk;
5628 case DW_FORM_ref_addr:
5629 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
5630 info_ptr += bytes_read;
5632 case DW_FORM_block2:
5633 blk = dwarf_alloc_block (cu);
5634 blk->size = read_2_bytes (abfd, info_ptr);
5636 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5637 info_ptr += blk->size;
5638 DW_BLOCK (attr) = blk;
5640 case DW_FORM_block4:
5641 blk = dwarf_alloc_block (cu);
5642 blk->size = read_4_bytes (abfd, info_ptr);
5644 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5645 info_ptr += blk->size;
5646 DW_BLOCK (attr) = blk;
5649 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5653 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5657 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5660 case DW_FORM_string:
5661 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
5662 info_ptr += bytes_read;
5665 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
5667 info_ptr += bytes_read;
5670 blk = dwarf_alloc_block (cu);
5671 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5672 info_ptr += bytes_read;
5673 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5674 info_ptr += blk->size;
5675 DW_BLOCK (attr) = blk;
5677 case DW_FORM_block1:
5678 blk = dwarf_alloc_block (cu);
5679 blk->size = read_1_byte (abfd, info_ptr);
5681 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5682 info_ptr += blk->size;
5683 DW_BLOCK (attr) = blk;
5686 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5690 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5694 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
5695 info_ptr += bytes_read;
5698 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5699 info_ptr += bytes_read;
5702 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
5706 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
5710 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
5714 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
5717 case DW_FORM_ref_udata:
5718 DW_ADDR (attr) = (cu->header.offset
5719 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
5720 info_ptr += bytes_read;
5722 case DW_FORM_indirect:
5723 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5724 info_ptr += bytes_read;
5725 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
5728 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
5729 dwarf_form_name (form),
5730 bfd_get_filename (abfd));
5735 /* Read an attribute described by an abbreviated attribute. */
5738 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
5739 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
5741 attr->name = abbrev->name;
5742 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
5745 /* read dwarf information from a buffer */
5748 read_1_byte (bfd *abfd, char *buf)
5750 return bfd_get_8 (abfd, (bfd_byte *) buf);
5754 read_1_signed_byte (bfd *abfd, char *buf)
5756 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
5760 read_2_bytes (bfd *abfd, char *buf)
5762 return bfd_get_16 (abfd, (bfd_byte *) buf);
5766 read_2_signed_bytes (bfd *abfd, char *buf)
5768 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5772 read_4_bytes (bfd *abfd, char *buf)
5774 return bfd_get_32 (abfd, (bfd_byte *) buf);
5778 read_4_signed_bytes (bfd *abfd, char *buf)
5780 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5783 static unsigned long
5784 read_8_bytes (bfd *abfd, char *buf)
5786 return bfd_get_64 (abfd, (bfd_byte *) buf);
5790 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
5792 struct comp_unit_head *cu_header = &cu->header;
5793 CORE_ADDR retval = 0;
5795 if (cu_header->signed_addr_p)
5797 switch (cu_header->addr_size)
5800 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5803 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5806 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
5809 internal_error (__FILE__, __LINE__,
5810 _("read_address: bad switch, signed [in module %s]"),
5811 bfd_get_filename (abfd));
5816 switch (cu_header->addr_size)
5819 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
5822 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5825 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5828 internal_error (__FILE__, __LINE__,
5829 _("read_address: bad switch, unsigned [in module %s]"),
5830 bfd_get_filename (abfd));
5834 *bytes_read = cu_header->addr_size;
5838 /* Read the initial length from a section. The (draft) DWARF 3
5839 specification allows the initial length to take up either 4 bytes
5840 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5841 bytes describe the length and all offsets will be 8 bytes in length
5844 An older, non-standard 64-bit format is also handled by this
5845 function. The older format in question stores the initial length
5846 as an 8-byte quantity without an escape value. Lengths greater
5847 than 2^32 aren't very common which means that the initial 4 bytes
5848 is almost always zero. Since a length value of zero doesn't make
5849 sense for the 32-bit format, this initial zero can be considered to
5850 be an escape value which indicates the presence of the older 64-bit
5851 format. As written, the code can't detect (old format) lengths
5852 greater than 4GB. If it becomes necessary to handle lengths
5853 somewhat larger than 4GB, we could allow other small values (such
5854 as the non-sensical values of 1, 2, and 3) to also be used as
5855 escape values indicating the presence of the old format.
5857 The value returned via bytes_read should be used to increment the
5858 relevant pointer after calling read_initial_length().
5860 As a side effect, this function sets the fields initial_length_size
5861 and offset_size in cu_header to the values appropriate for the
5862 length field. (The format of the initial length field determines
5863 the width of file offsets to be fetched later with fetch_offset().)
5865 [ Note: read_initial_length() and read_offset() are based on the
5866 document entitled "DWARF Debugging Information Format", revision
5867 3, draft 8, dated November 19, 2001. This document was obtained
5870 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5872 This document is only a draft and is subject to change. (So beware.)
5874 Details regarding the older, non-standard 64-bit format were
5875 determined empirically by examining 64-bit ELF files produced by
5876 the SGI toolchain on an IRIX 6.5 machine.
5878 - Kevin, July 16, 2002
5882 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
5887 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5889 if (retval == 0xffffffff)
5891 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
5893 if (cu_header != NULL)
5895 cu_header->initial_length_size = 12;
5896 cu_header->offset_size = 8;
5899 else if (retval == 0)
5901 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5903 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5905 if (cu_header != NULL)
5907 cu_header->initial_length_size = 8;
5908 cu_header->offset_size = 8;
5914 if (cu_header != NULL)
5916 cu_header->initial_length_size = 4;
5917 cu_header->offset_size = 4;
5924 /* Read an offset from the data stream. The size of the offset is
5925 given by cu_header->offset_size. */
5928 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
5933 switch (cu_header->offset_size)
5936 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5940 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5944 internal_error (__FILE__, __LINE__,
5945 _("read_offset: bad switch [in module %s]"),
5946 bfd_get_filename (abfd));
5953 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
5955 /* If the size of a host char is 8 bits, we can return a pointer
5956 to the buffer, otherwise we have to copy the data to a buffer
5957 allocated on the temporary obstack. */
5958 gdb_assert (HOST_CHAR_BIT == 8);
5963 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5965 /* If the size of a host char is 8 bits, we can return a pointer
5966 to the string, otherwise we have to copy the string to a buffer
5967 allocated on the temporary obstack. */
5968 gdb_assert (HOST_CHAR_BIT == 8);
5971 *bytes_read_ptr = 1;
5974 *bytes_read_ptr = strlen (buf) + 1;
5979 read_indirect_string (bfd *abfd, char *buf,
5980 const struct comp_unit_head *cu_header,
5981 unsigned int *bytes_read_ptr)
5983 LONGEST str_offset = read_offset (abfd, buf, cu_header,
5984 (int *) bytes_read_ptr);
5986 if (dwarf2_per_objfile->str_buffer == NULL)
5988 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
5989 bfd_get_filename (abfd));
5992 if (str_offset >= dwarf2_per_objfile->str_size)
5994 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
5995 bfd_get_filename (abfd));
5998 gdb_assert (HOST_CHAR_BIT == 8);
5999 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
6001 return dwarf2_per_objfile->str_buffer + str_offset;
6004 static unsigned long
6005 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
6007 unsigned long result;
6008 unsigned int num_read;
6018 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
6021 result |= ((unsigned long)(byte & 127) << shift);
6022 if ((byte & 128) == 0)
6028 *bytes_read_ptr = num_read;
6033 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
6036 int i, shift, size, num_read;
6046 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
6049 result |= ((long)(byte & 127) << shift);
6051 if ((byte & 128) == 0)
6056 if ((shift < size) && (byte & 0x40))
6058 result |= -(1 << shift);
6060 *bytes_read_ptr = num_read;
6064 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6067 skip_leb128 (bfd *abfd, char *buf)
6073 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
6075 if ((byte & 128) == 0)
6081 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
6087 cu->language = language_c;
6089 case DW_LANG_C_plus_plus:
6090 cu->language = language_cplus;
6092 case DW_LANG_Fortran77:
6093 case DW_LANG_Fortran90:
6094 case DW_LANG_Fortran95:
6095 cu->language = language_fortran;
6097 case DW_LANG_Mips_Assembler:
6098 cu->language = language_asm;
6101 cu->language = language_java;
6105 cu->language = language_ada;
6107 case DW_LANG_Cobol74:
6108 case DW_LANG_Cobol85:
6109 case DW_LANG_Pascal83:
6110 case DW_LANG_Modula2:
6112 cu->language = language_minimal;
6115 cu->language_defn = language_def (cu->language);
6118 /* Return the named attribute or NULL if not there. */
6120 static struct attribute *
6121 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
6124 struct attribute *spec = NULL;
6126 for (i = 0; i < die->num_attrs; ++i)
6128 if (die->attrs[i].name == name)
6129 return &die->attrs[i];
6130 if (die->attrs[i].name == DW_AT_specification
6131 || die->attrs[i].name == DW_AT_abstract_origin)
6132 spec = &die->attrs[i];
6136 return dwarf2_attr (follow_die_ref (die, spec, cu), name, cu);
6141 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6142 and holds a non-zero value. This function should only be used for
6143 DW_FORM_flag attributes. */
6146 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
6148 struct attribute *attr = dwarf2_attr (die, name, cu);
6150 return (attr && DW_UNSND (attr));
6154 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
6156 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6157 which value is non-zero. However, we have to be careful with
6158 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6159 (via dwarf2_flag_true_p) follows this attribute. So we may
6160 end up accidently finding a declaration attribute that belongs
6161 to a different DIE referenced by the specification attribute,
6162 even though the given DIE does not have a declaration attribute. */
6163 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
6164 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
6167 /* Return the die giving the specification for DIE, if there is
6170 static struct die_info *
6171 die_specification (struct die_info *die, struct dwarf2_cu *cu)
6173 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
6175 if (spec_attr == NULL)
6178 return follow_die_ref (die, spec_attr, cu);
6181 /* Free the line_header structure *LH, and any arrays and strings it
6184 free_line_header (struct line_header *lh)
6186 if (lh->standard_opcode_lengths)
6187 xfree (lh->standard_opcode_lengths);
6189 /* Remember that all the lh->file_names[i].name pointers are
6190 pointers into debug_line_buffer, and don't need to be freed. */
6192 xfree (lh->file_names);
6194 /* Similarly for the include directory names. */
6195 if (lh->include_dirs)
6196 xfree (lh->include_dirs);
6202 /* Add an entry to LH's include directory table. */
6204 add_include_dir (struct line_header *lh, char *include_dir)
6206 /* Grow the array if necessary. */
6207 if (lh->include_dirs_size == 0)
6209 lh->include_dirs_size = 1; /* for testing */
6210 lh->include_dirs = xmalloc (lh->include_dirs_size
6211 * sizeof (*lh->include_dirs));
6213 else if (lh->num_include_dirs >= lh->include_dirs_size)
6215 lh->include_dirs_size *= 2;
6216 lh->include_dirs = xrealloc (lh->include_dirs,
6217 (lh->include_dirs_size
6218 * sizeof (*lh->include_dirs)));
6221 lh->include_dirs[lh->num_include_dirs++] = include_dir;
6225 /* Add an entry to LH's file name table. */
6227 add_file_name (struct line_header *lh,
6229 unsigned int dir_index,
6230 unsigned int mod_time,
6231 unsigned int length)
6233 struct file_entry *fe;
6235 /* Grow the array if necessary. */
6236 if (lh->file_names_size == 0)
6238 lh->file_names_size = 1; /* for testing */
6239 lh->file_names = xmalloc (lh->file_names_size
6240 * sizeof (*lh->file_names));
6242 else if (lh->num_file_names >= lh->file_names_size)
6244 lh->file_names_size *= 2;
6245 lh->file_names = xrealloc (lh->file_names,
6246 (lh->file_names_size
6247 * sizeof (*lh->file_names)));
6250 fe = &lh->file_names[lh->num_file_names++];
6252 fe->dir_index = dir_index;
6253 fe->mod_time = mod_time;
6254 fe->length = length;
6259 /* Read the statement program header starting at OFFSET in
6260 .debug_line, according to the endianness of ABFD. Return a pointer
6261 to a struct line_header, allocated using xmalloc.
6263 NOTE: the strings in the include directory and file name tables of
6264 the returned object point into debug_line_buffer, and must not be
6266 static struct line_header *
6267 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
6268 struct dwarf2_cu *cu)
6270 struct cleanup *back_to;
6271 struct line_header *lh;
6275 char *cur_dir, *cur_file;
6277 if (dwarf2_per_objfile->line_buffer == NULL)
6279 complaint (&symfile_complaints, _("missing .debug_line section"));
6283 /* Make sure that at least there's room for the total_length field.
6284 That could be 12 bytes long, but we're just going to fudge that. */
6285 if (offset + 4 >= dwarf2_per_objfile->line_size)
6287 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6291 lh = xmalloc (sizeof (*lh));
6292 memset (lh, 0, sizeof (*lh));
6293 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
6296 line_ptr = dwarf2_per_objfile->line_buffer + offset;
6298 /* Read in the header. */
6299 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
6300 line_ptr += bytes_read;
6301 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
6302 + dwarf2_per_objfile->line_size))
6304 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6307 lh->statement_program_end = line_ptr + lh->total_length;
6308 lh->version = read_2_bytes (abfd, line_ptr);
6310 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
6311 line_ptr += bytes_read;
6312 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
6314 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
6316 lh->line_base = read_1_signed_byte (abfd, line_ptr);
6318 lh->line_range = read_1_byte (abfd, line_ptr);
6320 lh->opcode_base = read_1_byte (abfd, line_ptr);
6322 lh->standard_opcode_lengths
6323 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
6325 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
6326 for (i = 1; i < lh->opcode_base; ++i)
6328 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
6332 /* Read directory table. */
6333 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
6335 line_ptr += bytes_read;
6336 add_include_dir (lh, cur_dir);
6338 line_ptr += bytes_read;
6340 /* Read file name table. */
6341 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
6343 unsigned int dir_index, mod_time, length;
6345 line_ptr += bytes_read;
6346 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6347 line_ptr += bytes_read;
6348 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6349 line_ptr += bytes_read;
6350 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6351 line_ptr += bytes_read;
6353 add_file_name (lh, cur_file, dir_index, mod_time, length);
6355 line_ptr += bytes_read;
6356 lh->statement_program_start = line_ptr;
6358 if (line_ptr > (dwarf2_per_objfile->line_buffer
6359 + dwarf2_per_objfile->line_size))
6360 complaint (&symfile_complaints,
6361 _("line number info header doesn't fit in `.debug_line' section"));
6363 discard_cleanups (back_to);
6367 /* This function exists to work around a bug in certain compilers
6368 (particularly GCC 2.95), in which the first line number marker of a
6369 function does not show up until after the prologue, right before
6370 the second line number marker. This function shifts ADDRESS down
6371 to the beginning of the function if necessary, and is called on
6372 addresses passed to record_line. */
6375 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
6377 struct function_range *fn;
6379 /* Find the function_range containing address. */
6384 cu->cached_fn = cu->first_fn;
6388 if (fn->lowpc <= address && fn->highpc > address)
6394 while (fn && fn != cu->cached_fn)
6395 if (fn->lowpc <= address && fn->highpc > address)
6405 if (address != fn->lowpc)
6406 complaint (&symfile_complaints,
6407 _("misplaced first line number at 0x%lx for '%s'"),
6408 (unsigned long) address, fn->name);
6413 /* Decode the Line Number Program (LNP) for the given line_header
6414 structure and CU. The actual information extracted and the type
6415 of structures created from the LNP depends on the value of PST.
6417 1. If PST is NULL, then this procedure uses the data from the program
6418 to create all necessary symbol tables, and their linetables.
6419 The compilation directory of the file is passed in COMP_DIR,
6420 and must not be NULL.
6422 2. If PST is not NULL, this procedure reads the program to determine
6423 the list of files included by the unit represented by PST, and
6424 builds all the associated partial symbol tables. In this case,
6425 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6426 is not used to compute the full name of the symtab, and therefore
6427 omitting it when building the partial symtab does not introduce
6428 the potential for inconsistency - a partial symtab and its associated
6429 symbtab having a different fullname -). */
6432 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
6433 struct dwarf2_cu *cu, struct partial_symtab *pst)
6437 unsigned int bytes_read;
6438 unsigned char op_code, extended_op, adj_opcode;
6440 struct objfile *objfile = cu->objfile;
6441 const int decode_for_pst_p = (pst != NULL);
6443 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6445 line_ptr = lh->statement_program_start;
6446 line_end = lh->statement_program_end;
6448 /* Read the statement sequences until there's nothing left. */
6449 while (line_ptr < line_end)
6451 /* state machine registers */
6452 CORE_ADDR address = 0;
6453 unsigned int file = 1;
6454 unsigned int line = 1;
6455 unsigned int column = 0;
6456 int is_stmt = lh->default_is_stmt;
6457 int basic_block = 0;
6458 int end_sequence = 0;
6460 if (!decode_for_pst_p && lh->num_file_names >= file)
6462 /* Start a subfile for the current file of the state machine. */
6463 /* lh->include_dirs and lh->file_names are 0-based, but the
6464 directory and file name numbers in the statement program
6466 struct file_entry *fe = &lh->file_names[file - 1];
6470 dir = lh->include_dirs[fe->dir_index - 1];
6473 dwarf2_start_subfile (fe->name, dir);
6476 /* Decode the table. */
6477 while (!end_sequence)
6479 op_code = read_1_byte (abfd, line_ptr);
6482 if (op_code >= lh->opcode_base)
6484 /* Special operand. */
6485 adj_opcode = op_code - lh->opcode_base;
6486 address += (adj_opcode / lh->line_range)
6487 * lh->minimum_instruction_length;
6488 line += lh->line_base + (adj_opcode % lh->line_range);
6489 lh->file_names[file - 1].included_p = 1;
6490 if (!decode_for_pst_p)
6492 /* Append row to matrix using current values. */
6493 record_line (current_subfile, line,
6494 check_cu_functions (address, cu));
6498 else switch (op_code)
6500 case DW_LNS_extended_op:
6501 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6502 line_ptr += bytes_read;
6503 extended_op = read_1_byte (abfd, line_ptr);
6505 switch (extended_op)
6507 case DW_LNE_end_sequence:
6509 lh->file_names[file - 1].included_p = 1;
6510 if (!decode_for_pst_p)
6511 record_line (current_subfile, 0, address);
6513 case DW_LNE_set_address:
6514 address = read_address (abfd, line_ptr, cu, &bytes_read);
6515 line_ptr += bytes_read;
6516 address += baseaddr;
6518 case DW_LNE_define_file:
6521 unsigned int dir_index, mod_time, length;
6523 cur_file = read_string (abfd, line_ptr, &bytes_read);
6524 line_ptr += bytes_read;
6526 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6527 line_ptr += bytes_read;
6529 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6530 line_ptr += bytes_read;
6532 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6533 line_ptr += bytes_read;
6534 add_file_name (lh, cur_file, dir_index, mod_time, length);
6538 complaint (&symfile_complaints,
6539 _("mangled .debug_line section"));
6544 lh->file_names[file - 1].included_p = 1;
6545 if (!decode_for_pst_p)
6546 record_line (current_subfile, line,
6547 check_cu_functions (address, cu));
6550 case DW_LNS_advance_pc:
6551 address += lh->minimum_instruction_length
6552 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6553 line_ptr += bytes_read;
6555 case DW_LNS_advance_line:
6556 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
6557 line_ptr += bytes_read;
6559 case DW_LNS_set_file:
6561 /* The arrays lh->include_dirs and lh->file_names are
6562 0-based, but the directory and file name numbers in
6563 the statement program are 1-based. */
6564 struct file_entry *fe;
6567 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6568 line_ptr += bytes_read;
6569 fe = &lh->file_names[file - 1];
6571 dir = lh->include_dirs[fe->dir_index - 1];
6574 if (!decode_for_pst_p)
6575 dwarf2_start_subfile (fe->name, dir);
6578 case DW_LNS_set_column:
6579 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6580 line_ptr += bytes_read;
6582 case DW_LNS_negate_stmt:
6583 is_stmt = (!is_stmt);
6585 case DW_LNS_set_basic_block:
6588 /* Add to the address register of the state machine the
6589 address increment value corresponding to special opcode
6590 255. I.e., this value is scaled by the minimum
6591 instruction length since special opcode 255 would have
6592 scaled the the increment. */
6593 case DW_LNS_const_add_pc:
6594 address += (lh->minimum_instruction_length
6595 * ((255 - lh->opcode_base) / lh->line_range));
6597 case DW_LNS_fixed_advance_pc:
6598 address += read_2_bytes (abfd, line_ptr);
6603 /* Unknown standard opcode, ignore it. */
6606 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
6608 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6609 line_ptr += bytes_read;
6616 if (decode_for_pst_p)
6620 /* Now that we're done scanning the Line Header Program, we can
6621 create the psymtab of each included file. */
6622 for (file_index = 0; file_index < lh->num_file_names; file_index++)
6623 if (lh->file_names[file_index].included_p == 1)
6625 char *include_name = lh->file_names [file_index].name;
6627 if (strcmp (include_name, pst->filename) != 0)
6628 dwarf2_create_include_psymtab (include_name, pst, objfile);
6633 /* Start a subfile for DWARF. FILENAME is the name of the file and
6634 DIRNAME the name of the source directory which contains FILENAME
6635 or NULL if not known.
6636 This routine tries to keep line numbers from identical absolute and
6637 relative file names in a common subfile.
6639 Using the `list' example from the GDB testsuite, which resides in
6640 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6641 of /srcdir/list0.c yields the following debugging information for list0.c:
6643 DW_AT_name: /srcdir/list0.c
6644 DW_AT_comp_dir: /compdir
6645 files.files[0].name: list0.h
6646 files.files[0].dir: /srcdir
6647 files.files[1].name: list0.c
6648 files.files[1].dir: /srcdir
6650 The line number information for list0.c has to end up in a single
6651 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6654 dwarf2_start_subfile (char *filename, char *dirname)
6656 /* If the filename isn't absolute, try to match an existing subfile
6657 with the full pathname. */
6659 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
6661 struct subfile *subfile;
6662 char *fullname = concat (dirname, "/", filename, NULL);
6664 for (subfile = subfiles; subfile; subfile = subfile->next)
6666 if (FILENAME_CMP (subfile->name, fullname) == 0)
6668 current_subfile = subfile;
6675 start_subfile (filename, dirname);
6679 var_decode_location (struct attribute *attr, struct symbol *sym,
6680 struct dwarf2_cu *cu)
6682 struct objfile *objfile = cu->objfile;
6683 struct comp_unit_head *cu_header = &cu->header;
6685 /* NOTE drow/2003-01-30: There used to be a comment and some special
6686 code here to turn a symbol with DW_AT_external and a
6687 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6688 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6689 with some versions of binutils) where shared libraries could have
6690 relocations against symbols in their debug information - the
6691 minimal symbol would have the right address, but the debug info
6692 would not. It's no longer necessary, because we will explicitly
6693 apply relocations when we read in the debug information now. */
6695 /* A DW_AT_location attribute with no contents indicates that a
6696 variable has been optimized away. */
6697 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
6699 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
6703 /* Handle one degenerate form of location expression specially, to
6704 preserve GDB's previous behavior when section offsets are
6705 specified. If this is just a DW_OP_addr then mark this symbol
6708 if (attr_form_is_block (attr)
6709 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
6710 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
6714 SYMBOL_VALUE_ADDRESS (sym) =
6715 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
6716 fixup_symbol_section (sym, objfile);
6717 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
6718 SYMBOL_SECTION (sym));
6719 SYMBOL_CLASS (sym) = LOC_STATIC;
6723 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6724 expression evaluator, and use LOC_COMPUTED only when necessary
6725 (i.e. when the value of a register or memory location is
6726 referenced, or a thread-local block, etc.). Then again, it might
6727 not be worthwhile. I'm assuming that it isn't unless performance
6728 or memory numbers show me otherwise. */
6730 dwarf2_symbol_mark_computed (attr, sym, cu);
6731 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6734 /* Given a pointer to a DWARF information entry, figure out if we need
6735 to make a symbol table entry for it, and if so, create a new entry
6736 and return a pointer to it.
6737 If TYPE is NULL, determine symbol type from the die, otherwise
6738 used the passed type. */
6740 static struct symbol *
6741 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6743 struct objfile *objfile = cu->objfile;
6744 struct symbol *sym = NULL;
6746 struct attribute *attr = NULL;
6747 struct attribute *attr2 = NULL;
6750 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6752 if (die->tag != DW_TAG_namespace)
6753 name = dwarf2_linkage_name (die, cu);
6755 name = TYPE_NAME (type);
6759 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6760 sizeof (struct symbol));
6761 OBJSTAT (objfile, n_syms++);
6762 memset (sym, 0, sizeof (struct symbol));
6764 /* Cache this symbol's name and the name's demangled form (if any). */
6765 SYMBOL_LANGUAGE (sym) = cu->language;
6766 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6768 /* Default assumptions.
6769 Use the passed type or decode it from the die. */
6770 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6771 SYMBOL_CLASS (sym) = LOC_STATIC;
6773 SYMBOL_TYPE (sym) = type;
6775 SYMBOL_TYPE (sym) = die_type (die, cu);
6776 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
6779 SYMBOL_LINE (sym) = DW_UNSND (attr);
6784 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6787 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
6789 SYMBOL_CLASS (sym) = LOC_LABEL;
6791 case DW_TAG_subprogram:
6792 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6794 SYMBOL_CLASS (sym) = LOC_BLOCK;
6795 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6796 if (attr2 && (DW_UNSND (attr2) != 0))
6798 add_symbol_to_list (sym, &global_symbols);
6802 add_symbol_to_list (sym, cu->list_in_scope);
6805 case DW_TAG_variable:
6806 /* Compilation with minimal debug info may result in variables
6807 with missing type entries. Change the misleading `void' type
6808 to something sensible. */
6809 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
6810 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
6811 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
6812 "<variable, no debug info>",
6814 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6817 dwarf2_const_value (attr, sym, cu);
6818 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6819 if (attr2 && (DW_UNSND (attr2) != 0))
6820 add_symbol_to_list (sym, &global_symbols);
6822 add_symbol_to_list (sym, cu->list_in_scope);
6825 attr = dwarf2_attr (die, DW_AT_location, cu);
6828 var_decode_location (attr, sym, cu);
6829 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6830 if (attr2 && (DW_UNSND (attr2) != 0))
6831 add_symbol_to_list (sym, &global_symbols);
6833 add_symbol_to_list (sym, cu->list_in_scope);
6837 /* We do not know the address of this symbol.
6838 If it is an external symbol and we have type information
6839 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6840 The address of the variable will then be determined from
6841 the minimal symbol table whenever the variable is
6843 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6844 if (attr2 && (DW_UNSND (attr2) != 0)
6845 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
6847 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6848 add_symbol_to_list (sym, &global_symbols);
6852 case DW_TAG_formal_parameter:
6853 attr = dwarf2_attr (die, DW_AT_location, cu);
6856 var_decode_location (attr, sym, cu);
6857 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6858 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
6859 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
6861 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6864 dwarf2_const_value (attr, sym, cu);
6866 add_symbol_to_list (sym, cu->list_in_scope);
6868 case DW_TAG_unspecified_parameters:
6869 /* From varargs functions; gdb doesn't seem to have any
6870 interest in this information, so just ignore it for now.
6873 case DW_TAG_class_type:
6874 case DW_TAG_structure_type:
6875 case DW_TAG_union_type:
6876 case DW_TAG_enumeration_type:
6877 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6878 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6880 /* Make sure that the symbol includes appropriate enclosing
6881 classes/namespaces in its name. These are calculated in
6882 read_structure_type, and the correct name is saved in
6885 if (cu->language == language_cplus
6886 || cu->language == language_java)
6888 struct type *type = SYMBOL_TYPE (sym);
6890 if (TYPE_TAG_NAME (type) != NULL)
6892 /* FIXME: carlton/2003-11-10: Should this use
6893 SYMBOL_SET_NAMES instead? (The same problem also
6894 arises further down in this function.) */
6895 /* The type's name is already allocated along with
6896 this objfile, so we don't need to duplicate it
6898 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
6903 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6904 really ever be static objects: otherwise, if you try
6905 to, say, break of a class's method and you're in a file
6906 which doesn't mention that class, it won't work unless
6907 the check for all static symbols in lookup_symbol_aux
6908 saves you. See the OtherFileClass tests in
6909 gdb.c++/namespace.exp. */
6911 struct pending **list_to_add;
6913 list_to_add = (cu->list_in_scope == &file_symbols
6914 && (cu->language == language_cplus
6915 || cu->language == language_java)
6916 ? &global_symbols : cu->list_in_scope);
6918 add_symbol_to_list (sym, list_to_add);
6920 /* The semantics of C++ state that "struct foo { ... }" also
6921 defines a typedef for "foo". A Java class declaration also
6922 defines a typedef for the class. Synthesize a typedef symbol
6923 so that "ptype foo" works as expected. */
6924 if (cu->language == language_cplus
6925 || cu->language == language_java)
6927 struct symbol *typedef_sym = (struct symbol *)
6928 obstack_alloc (&objfile->objfile_obstack,
6929 sizeof (struct symbol));
6930 *typedef_sym = *sym;
6931 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
6932 /* The symbol's name is already allocated along with
6933 this objfile, so we don't need to duplicate it for
6935 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
6936 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
6937 add_symbol_to_list (typedef_sym, list_to_add);
6941 case DW_TAG_typedef:
6942 if (processing_has_namespace_info
6943 && processing_current_prefix[0] != '\0')
6945 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6946 processing_current_prefix,
6949 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6950 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6951 add_symbol_to_list (sym, cu->list_in_scope);
6953 case DW_TAG_base_type:
6954 case DW_TAG_subrange_type:
6955 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6956 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6957 add_symbol_to_list (sym, cu->list_in_scope);
6959 case DW_TAG_enumerator:
6960 if (processing_has_namespace_info
6961 && processing_current_prefix[0] != '\0')
6963 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6964 processing_current_prefix,
6967 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6970 dwarf2_const_value (attr, sym, cu);
6973 /* NOTE: carlton/2003-11-10: See comment above in the
6974 DW_TAG_class_type, etc. block. */
6976 struct pending **list_to_add;
6978 list_to_add = (cu->list_in_scope == &file_symbols
6979 && (cu->language == language_cplus
6980 || cu->language == language_java)
6981 ? &global_symbols : cu->list_in_scope);
6983 add_symbol_to_list (sym, list_to_add);
6986 case DW_TAG_namespace:
6987 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6988 add_symbol_to_list (sym, &global_symbols);
6991 /* Not a tag we recognize. Hopefully we aren't processing
6992 trash data, but since we must specifically ignore things
6993 we don't recognize, there is nothing else we should do at
6995 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
6996 dwarf_tag_name (die->tag));
7003 /* Copy constant value from an attribute to a symbol. */
7006 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
7007 struct dwarf2_cu *cu)
7009 struct objfile *objfile = cu->objfile;
7010 struct comp_unit_head *cu_header = &cu->header;
7011 struct dwarf_block *blk;
7016 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
7017 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
7018 cu_header->addr_size,
7019 TYPE_LENGTH (SYMBOL_TYPE
7021 SYMBOL_VALUE_BYTES (sym) = (char *)
7022 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
7023 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7024 it's body - store_unsigned_integer. */
7025 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
7027 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7029 case DW_FORM_block1:
7030 case DW_FORM_block2:
7031 case DW_FORM_block4:
7033 blk = DW_BLOCK (attr);
7034 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
7035 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
7037 TYPE_LENGTH (SYMBOL_TYPE
7039 SYMBOL_VALUE_BYTES (sym) = (char *)
7040 obstack_alloc (&objfile->objfile_obstack, blk->size);
7041 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
7042 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7045 /* The DW_AT_const_value attributes are supposed to carry the
7046 symbol's value "represented as it would be on the target
7047 architecture." By the time we get here, it's already been
7048 converted to host endianness, so we just need to sign- or
7049 zero-extend it as appropriate. */
7051 dwarf2_const_value_data (attr, sym, 8);
7054 dwarf2_const_value_data (attr, sym, 16);
7057 dwarf2_const_value_data (attr, sym, 32);
7060 dwarf2_const_value_data (attr, sym, 64);
7064 SYMBOL_VALUE (sym) = DW_SND (attr);
7065 SYMBOL_CLASS (sym) = LOC_CONST;
7069 SYMBOL_VALUE (sym) = DW_UNSND (attr);
7070 SYMBOL_CLASS (sym) = LOC_CONST;
7074 complaint (&symfile_complaints,
7075 _("unsupported const value attribute form: '%s'"),
7076 dwarf_form_name (attr->form));
7077 SYMBOL_VALUE (sym) = 0;
7078 SYMBOL_CLASS (sym) = LOC_CONST;
7084 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7085 or zero-extend it as appropriate for the symbol's type. */
7087 dwarf2_const_value_data (struct attribute *attr,
7091 LONGEST l = DW_UNSND (attr);
7093 if (bits < sizeof (l) * 8)
7095 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
7096 l &= ((LONGEST) 1 << bits) - 1;
7098 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
7101 SYMBOL_VALUE (sym) = l;
7102 SYMBOL_CLASS (sym) = LOC_CONST;
7106 /* Return the type of the die in question using its DW_AT_type attribute. */
7108 static struct type *
7109 die_type (struct die_info *die, struct dwarf2_cu *cu)
7112 struct attribute *type_attr;
7113 struct die_info *type_die;
7115 type_attr = dwarf2_attr (die, DW_AT_type, cu);
7118 /* A missing DW_AT_type represents a void type. */
7119 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
7122 type_die = follow_die_ref (die, type_attr, cu);
7124 type = tag_type_to_type (type_die, cu);
7127 dump_die (type_die);
7128 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7134 /* Return the containing type of the die in question using its
7135 DW_AT_containing_type attribute. */
7137 static struct type *
7138 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
7140 struct type *type = NULL;
7141 struct attribute *type_attr;
7142 struct die_info *type_die = NULL;
7144 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
7147 type_die = follow_die_ref (die, type_attr, cu);
7148 type = tag_type_to_type (type_die, cu);
7153 dump_die (type_die);
7154 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7160 static struct type *
7161 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
7169 read_type_die (die, cu);
7173 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7181 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
7183 char *prefix = determine_prefix (die, cu);
7184 const char *old_prefix = processing_current_prefix;
7185 struct cleanup *back_to = make_cleanup (xfree, prefix);
7186 processing_current_prefix = prefix;
7190 case DW_TAG_class_type:
7191 case DW_TAG_structure_type:
7192 case DW_TAG_union_type:
7193 read_structure_type (die, cu);
7195 case DW_TAG_enumeration_type:
7196 read_enumeration_type (die, cu);
7198 case DW_TAG_subprogram:
7199 case DW_TAG_subroutine_type:
7200 read_subroutine_type (die, cu);
7202 case DW_TAG_array_type:
7203 read_array_type (die, cu);
7205 case DW_TAG_pointer_type:
7206 read_tag_pointer_type (die, cu);
7208 case DW_TAG_ptr_to_member_type:
7209 read_tag_ptr_to_member_type (die, cu);
7211 case DW_TAG_reference_type:
7212 read_tag_reference_type (die, cu);
7214 case DW_TAG_const_type:
7215 read_tag_const_type (die, cu);
7217 case DW_TAG_volatile_type:
7218 read_tag_volatile_type (die, cu);
7220 case DW_TAG_string_type:
7221 read_tag_string_type (die, cu);
7223 case DW_TAG_typedef:
7224 read_typedef (die, cu);
7226 case DW_TAG_subrange_type:
7227 read_subrange_type (die, cu);
7229 case DW_TAG_base_type:
7230 read_base_type (die, cu);
7233 complaint (&symfile_complaints, _("unexepected tag in read_type_die: '%s'"),
7234 dwarf_tag_name (die->tag));
7238 processing_current_prefix = old_prefix;
7239 do_cleanups (back_to);
7242 /* Return the name of the namespace/class that DIE is defined within,
7243 or "" if we can't tell. The caller should xfree the result. */
7245 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7246 therein) for an example of how to use this function to deal with
7247 DW_AT_specification. */
7250 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
7252 struct die_info *parent;
7254 if (cu->language != language_cplus
7255 && cu->language != language_java)
7258 parent = die->parent;
7262 return xstrdup ("");
7266 switch (parent->tag) {
7267 case DW_TAG_namespace:
7269 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7270 before doing this check? */
7271 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
7273 return xstrdup (TYPE_TAG_NAME (parent->type));
7278 char *parent_prefix = determine_prefix (parent, cu);
7279 char *retval = typename_concat (NULL, parent_prefix,
7280 namespace_name (parent, &dummy,
7283 xfree (parent_prefix);
7288 case DW_TAG_class_type:
7289 case DW_TAG_structure_type:
7291 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
7293 return xstrdup (TYPE_TAG_NAME (parent->type));
7297 const char *old_prefix = processing_current_prefix;
7298 char *new_prefix = determine_prefix (parent, cu);
7301 processing_current_prefix = new_prefix;
7302 retval = determine_class_name (parent, cu);
7303 processing_current_prefix = old_prefix;
7310 return determine_prefix (parent, cu);
7315 /* Return a newly-allocated string formed by concatenating PREFIX and
7316 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7317 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7318 perform an obconcat, otherwise allocate storage for the result. The CU argument
7319 is used to determine the language and hence, the appropriate separator. */
7321 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7324 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
7325 struct dwarf2_cu *cu)
7329 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
7331 else if (cu->language == language_java)
7338 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
7343 strcpy (retval, prefix);
7344 strcat (retval, sep);
7347 strcat (retval, suffix);
7353 /* We have an obstack. */
7354 return obconcat (obs, prefix, sep, suffix);
7358 static struct type *
7359 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
7361 struct objfile *objfile = cu->objfile;
7363 /* FIXME - this should not produce a new (struct type *)
7364 every time. It should cache base types. */
7368 case DW_ATE_address:
7369 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
7371 case DW_ATE_boolean:
7372 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
7374 case DW_ATE_complex_float:
7377 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
7381 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
7387 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
7391 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
7398 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7401 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
7405 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7409 case DW_ATE_signed_char:
7410 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7412 case DW_ATE_unsigned:
7416 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7419 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
7423 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
7427 case DW_ATE_unsigned_char:
7428 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7431 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7438 copy_die (struct die_info *old_die)
7440 struct die_info *new_die;
7443 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
7444 memset (new_die, 0, sizeof (struct die_info));
7446 new_die->tag = old_die->tag;
7447 new_die->has_children = old_die->has_children;
7448 new_die->abbrev = old_die->abbrev;
7449 new_die->offset = old_die->offset;
7450 new_die->type = NULL;
7452 num_attrs = old_die->num_attrs;
7453 new_die->num_attrs = num_attrs;
7454 new_die->attrs = (struct attribute *)
7455 xmalloc (num_attrs * sizeof (struct attribute));
7457 for (i = 0; i < old_die->num_attrs; ++i)
7459 new_die->attrs[i].name = old_die->attrs[i].name;
7460 new_die->attrs[i].form = old_die->attrs[i].form;
7461 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
7464 new_die->next = NULL;
7469 /* Return sibling of die, NULL if no sibling. */
7471 static struct die_info *
7472 sibling_die (struct die_info *die)
7474 return die->sibling;
7477 /* Get linkage name of a die, return NULL if not found. */
7480 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7482 struct attribute *attr;
7484 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7485 if (attr && DW_STRING (attr))
7486 return DW_STRING (attr);
7487 attr = dwarf2_attr (die, DW_AT_name, cu);
7488 if (attr && DW_STRING (attr))
7489 return DW_STRING (attr);
7493 /* Get name of a die, return NULL if not found. */
7496 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
7498 struct attribute *attr;
7500 attr = dwarf2_attr (die, DW_AT_name, cu);
7501 if (attr && DW_STRING (attr))
7502 return DW_STRING (attr);
7506 /* Return the die that this die in an extension of, or NULL if there
7509 static struct die_info *
7510 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
7512 struct attribute *attr;
7514 attr = dwarf2_attr (die, DW_AT_extension, cu);
7518 return follow_die_ref (die, attr, cu);
7521 /* Convert a DIE tag into its string name. */
7524 dwarf_tag_name (unsigned tag)
7528 case DW_TAG_padding:
7529 return "DW_TAG_padding";
7530 case DW_TAG_array_type:
7531 return "DW_TAG_array_type";
7532 case DW_TAG_class_type:
7533 return "DW_TAG_class_type";
7534 case DW_TAG_entry_point:
7535 return "DW_TAG_entry_point";
7536 case DW_TAG_enumeration_type:
7537 return "DW_TAG_enumeration_type";
7538 case DW_TAG_formal_parameter:
7539 return "DW_TAG_formal_parameter";
7540 case DW_TAG_imported_declaration:
7541 return "DW_TAG_imported_declaration";
7543 return "DW_TAG_label";
7544 case DW_TAG_lexical_block:
7545 return "DW_TAG_lexical_block";
7547 return "DW_TAG_member";
7548 case DW_TAG_pointer_type:
7549 return "DW_TAG_pointer_type";
7550 case DW_TAG_reference_type:
7551 return "DW_TAG_reference_type";
7552 case DW_TAG_compile_unit:
7553 return "DW_TAG_compile_unit";
7554 case DW_TAG_string_type:
7555 return "DW_TAG_string_type";
7556 case DW_TAG_structure_type:
7557 return "DW_TAG_structure_type";
7558 case DW_TAG_subroutine_type:
7559 return "DW_TAG_subroutine_type";
7560 case DW_TAG_typedef:
7561 return "DW_TAG_typedef";
7562 case DW_TAG_union_type:
7563 return "DW_TAG_union_type";
7564 case DW_TAG_unspecified_parameters:
7565 return "DW_TAG_unspecified_parameters";
7566 case DW_TAG_variant:
7567 return "DW_TAG_variant";
7568 case DW_TAG_common_block:
7569 return "DW_TAG_common_block";
7570 case DW_TAG_common_inclusion:
7571 return "DW_TAG_common_inclusion";
7572 case DW_TAG_inheritance:
7573 return "DW_TAG_inheritance";
7574 case DW_TAG_inlined_subroutine:
7575 return "DW_TAG_inlined_subroutine";
7577 return "DW_TAG_module";
7578 case DW_TAG_ptr_to_member_type:
7579 return "DW_TAG_ptr_to_member_type";
7580 case DW_TAG_set_type:
7581 return "DW_TAG_set_type";
7582 case DW_TAG_subrange_type:
7583 return "DW_TAG_subrange_type";
7584 case DW_TAG_with_stmt:
7585 return "DW_TAG_with_stmt";
7586 case DW_TAG_access_declaration:
7587 return "DW_TAG_access_declaration";
7588 case DW_TAG_base_type:
7589 return "DW_TAG_base_type";
7590 case DW_TAG_catch_block:
7591 return "DW_TAG_catch_block";
7592 case DW_TAG_const_type:
7593 return "DW_TAG_const_type";
7594 case DW_TAG_constant:
7595 return "DW_TAG_constant";
7596 case DW_TAG_enumerator:
7597 return "DW_TAG_enumerator";
7598 case DW_TAG_file_type:
7599 return "DW_TAG_file_type";
7601 return "DW_TAG_friend";
7602 case DW_TAG_namelist:
7603 return "DW_TAG_namelist";
7604 case DW_TAG_namelist_item:
7605 return "DW_TAG_namelist_item";
7606 case DW_TAG_packed_type:
7607 return "DW_TAG_packed_type";
7608 case DW_TAG_subprogram:
7609 return "DW_TAG_subprogram";
7610 case DW_TAG_template_type_param:
7611 return "DW_TAG_template_type_param";
7612 case DW_TAG_template_value_param:
7613 return "DW_TAG_template_value_param";
7614 case DW_TAG_thrown_type:
7615 return "DW_TAG_thrown_type";
7616 case DW_TAG_try_block:
7617 return "DW_TAG_try_block";
7618 case DW_TAG_variant_part:
7619 return "DW_TAG_variant_part";
7620 case DW_TAG_variable:
7621 return "DW_TAG_variable";
7622 case DW_TAG_volatile_type:
7623 return "DW_TAG_volatile_type";
7624 case DW_TAG_dwarf_procedure:
7625 return "DW_TAG_dwarf_procedure";
7626 case DW_TAG_restrict_type:
7627 return "DW_TAG_restrict_type";
7628 case DW_TAG_interface_type:
7629 return "DW_TAG_interface_type";
7630 case DW_TAG_namespace:
7631 return "DW_TAG_namespace";
7632 case DW_TAG_imported_module:
7633 return "DW_TAG_imported_module";
7634 case DW_TAG_unspecified_type:
7635 return "DW_TAG_unspecified_type";
7636 case DW_TAG_partial_unit:
7637 return "DW_TAG_partial_unit";
7638 case DW_TAG_imported_unit:
7639 return "DW_TAG_imported_unit";
7640 case DW_TAG_MIPS_loop:
7641 return "DW_TAG_MIPS_loop";
7642 case DW_TAG_format_label:
7643 return "DW_TAG_format_label";
7644 case DW_TAG_function_template:
7645 return "DW_TAG_function_template";
7646 case DW_TAG_class_template:
7647 return "DW_TAG_class_template";
7649 return "DW_TAG_<unknown>";
7653 /* Convert a DWARF attribute code into its string name. */
7656 dwarf_attr_name (unsigned attr)
7661 return "DW_AT_sibling";
7662 case DW_AT_location:
7663 return "DW_AT_location";
7665 return "DW_AT_name";
7666 case DW_AT_ordering:
7667 return "DW_AT_ordering";
7668 case DW_AT_subscr_data:
7669 return "DW_AT_subscr_data";
7670 case DW_AT_byte_size:
7671 return "DW_AT_byte_size";
7672 case DW_AT_bit_offset:
7673 return "DW_AT_bit_offset";
7674 case DW_AT_bit_size:
7675 return "DW_AT_bit_size";
7676 case DW_AT_element_list:
7677 return "DW_AT_element_list";
7678 case DW_AT_stmt_list:
7679 return "DW_AT_stmt_list";
7681 return "DW_AT_low_pc";
7683 return "DW_AT_high_pc";
7684 case DW_AT_language:
7685 return "DW_AT_language";
7687 return "DW_AT_member";
7689 return "DW_AT_discr";
7690 case DW_AT_discr_value:
7691 return "DW_AT_discr_value";
7692 case DW_AT_visibility:
7693 return "DW_AT_visibility";
7695 return "DW_AT_import";
7696 case DW_AT_string_length:
7697 return "DW_AT_string_length";
7698 case DW_AT_common_reference:
7699 return "DW_AT_common_reference";
7700 case DW_AT_comp_dir:
7701 return "DW_AT_comp_dir";
7702 case DW_AT_const_value:
7703 return "DW_AT_const_value";
7704 case DW_AT_containing_type:
7705 return "DW_AT_containing_type";
7706 case DW_AT_default_value:
7707 return "DW_AT_default_value";
7709 return "DW_AT_inline";
7710 case DW_AT_is_optional:
7711 return "DW_AT_is_optional";
7712 case DW_AT_lower_bound:
7713 return "DW_AT_lower_bound";
7714 case DW_AT_producer:
7715 return "DW_AT_producer";
7716 case DW_AT_prototyped:
7717 return "DW_AT_prototyped";
7718 case DW_AT_return_addr:
7719 return "DW_AT_return_addr";
7720 case DW_AT_start_scope:
7721 return "DW_AT_start_scope";
7722 case DW_AT_stride_size:
7723 return "DW_AT_stride_size";
7724 case DW_AT_upper_bound:
7725 return "DW_AT_upper_bound";
7726 case DW_AT_abstract_origin:
7727 return "DW_AT_abstract_origin";
7728 case DW_AT_accessibility:
7729 return "DW_AT_accessibility";
7730 case DW_AT_address_class:
7731 return "DW_AT_address_class";
7732 case DW_AT_artificial:
7733 return "DW_AT_artificial";
7734 case DW_AT_base_types:
7735 return "DW_AT_base_types";
7736 case DW_AT_calling_convention:
7737 return "DW_AT_calling_convention";
7739 return "DW_AT_count";
7740 case DW_AT_data_member_location:
7741 return "DW_AT_data_member_location";
7742 case DW_AT_decl_column:
7743 return "DW_AT_decl_column";
7744 case DW_AT_decl_file:
7745 return "DW_AT_decl_file";
7746 case DW_AT_decl_line:
7747 return "DW_AT_decl_line";
7748 case DW_AT_declaration:
7749 return "DW_AT_declaration";
7750 case DW_AT_discr_list:
7751 return "DW_AT_discr_list";
7752 case DW_AT_encoding:
7753 return "DW_AT_encoding";
7754 case DW_AT_external:
7755 return "DW_AT_external";
7756 case DW_AT_frame_base:
7757 return "DW_AT_frame_base";
7759 return "DW_AT_friend";
7760 case DW_AT_identifier_case:
7761 return "DW_AT_identifier_case";
7762 case DW_AT_macro_info:
7763 return "DW_AT_macro_info";
7764 case DW_AT_namelist_items:
7765 return "DW_AT_namelist_items";
7766 case DW_AT_priority:
7767 return "DW_AT_priority";
7769 return "DW_AT_segment";
7770 case DW_AT_specification:
7771 return "DW_AT_specification";
7772 case DW_AT_static_link:
7773 return "DW_AT_static_link";
7775 return "DW_AT_type";
7776 case DW_AT_use_location:
7777 return "DW_AT_use_location";
7778 case DW_AT_variable_parameter:
7779 return "DW_AT_variable_parameter";
7780 case DW_AT_virtuality:
7781 return "DW_AT_virtuality";
7782 case DW_AT_vtable_elem_location:
7783 return "DW_AT_vtable_elem_location";
7784 case DW_AT_allocated:
7785 return "DW_AT_allocated";
7786 case DW_AT_associated:
7787 return "DW_AT_associated";
7788 case DW_AT_data_location:
7789 return "DW_AT_data_location";
7791 return "DW_AT_stride";
7792 case DW_AT_entry_pc:
7793 return "DW_AT_entry_pc";
7794 case DW_AT_use_UTF8:
7795 return "DW_AT_use_UTF8";
7796 case DW_AT_extension:
7797 return "DW_AT_extension";
7799 return "DW_AT_ranges";
7800 case DW_AT_trampoline:
7801 return "DW_AT_trampoline";
7802 case DW_AT_call_column:
7803 return "DW_AT_call_column";
7804 case DW_AT_call_file:
7805 return "DW_AT_call_file";
7806 case DW_AT_call_line:
7807 return "DW_AT_call_line";
7809 case DW_AT_MIPS_fde:
7810 return "DW_AT_MIPS_fde";
7811 case DW_AT_MIPS_loop_begin:
7812 return "DW_AT_MIPS_loop_begin";
7813 case DW_AT_MIPS_tail_loop_begin:
7814 return "DW_AT_MIPS_tail_loop_begin";
7815 case DW_AT_MIPS_epilog_begin:
7816 return "DW_AT_MIPS_epilog_begin";
7817 case DW_AT_MIPS_loop_unroll_factor:
7818 return "DW_AT_MIPS_loop_unroll_factor";
7819 case DW_AT_MIPS_software_pipeline_depth:
7820 return "DW_AT_MIPS_software_pipeline_depth";
7822 case DW_AT_MIPS_linkage_name:
7823 return "DW_AT_MIPS_linkage_name";
7825 case DW_AT_sf_names:
7826 return "DW_AT_sf_names";
7827 case DW_AT_src_info:
7828 return "DW_AT_src_info";
7829 case DW_AT_mac_info:
7830 return "DW_AT_mac_info";
7831 case DW_AT_src_coords:
7832 return "DW_AT_src_coords";
7833 case DW_AT_body_begin:
7834 return "DW_AT_body_begin";
7835 case DW_AT_body_end:
7836 return "DW_AT_body_end";
7837 case DW_AT_GNU_vector:
7838 return "DW_AT_GNU_vector";
7840 return "DW_AT_<unknown>";
7844 /* Convert a DWARF value form code into its string name. */
7847 dwarf_form_name (unsigned form)
7852 return "DW_FORM_addr";
7853 case DW_FORM_block2:
7854 return "DW_FORM_block2";
7855 case DW_FORM_block4:
7856 return "DW_FORM_block4";
7858 return "DW_FORM_data2";
7860 return "DW_FORM_data4";
7862 return "DW_FORM_data8";
7863 case DW_FORM_string:
7864 return "DW_FORM_string";
7866 return "DW_FORM_block";
7867 case DW_FORM_block1:
7868 return "DW_FORM_block1";
7870 return "DW_FORM_data1";
7872 return "DW_FORM_flag";
7874 return "DW_FORM_sdata";
7876 return "DW_FORM_strp";
7878 return "DW_FORM_udata";
7879 case DW_FORM_ref_addr:
7880 return "DW_FORM_ref_addr";
7882 return "DW_FORM_ref1";
7884 return "DW_FORM_ref2";
7886 return "DW_FORM_ref4";
7888 return "DW_FORM_ref8";
7889 case DW_FORM_ref_udata:
7890 return "DW_FORM_ref_udata";
7891 case DW_FORM_indirect:
7892 return "DW_FORM_indirect";
7894 return "DW_FORM_<unknown>";
7898 /* Convert a DWARF stack opcode into its string name. */
7901 dwarf_stack_op_name (unsigned op)
7906 return "DW_OP_addr";
7908 return "DW_OP_deref";
7910 return "DW_OP_const1u";
7912 return "DW_OP_const1s";
7914 return "DW_OP_const2u";
7916 return "DW_OP_const2s";
7918 return "DW_OP_const4u";
7920 return "DW_OP_const4s";
7922 return "DW_OP_const8u";
7924 return "DW_OP_const8s";
7926 return "DW_OP_constu";
7928 return "DW_OP_consts";
7932 return "DW_OP_drop";
7934 return "DW_OP_over";
7936 return "DW_OP_pick";
7938 return "DW_OP_swap";
7942 return "DW_OP_xderef";
7950 return "DW_OP_minus";
7962 return "DW_OP_plus";
7963 case DW_OP_plus_uconst:
7964 return "DW_OP_plus_uconst";
7970 return "DW_OP_shra";
7988 return "DW_OP_skip";
7990 return "DW_OP_lit0";
7992 return "DW_OP_lit1";
7994 return "DW_OP_lit2";
7996 return "DW_OP_lit3";
7998 return "DW_OP_lit4";
8000 return "DW_OP_lit5";
8002 return "DW_OP_lit6";
8004 return "DW_OP_lit7";
8006 return "DW_OP_lit8";
8008 return "DW_OP_lit9";
8010 return "DW_OP_lit10";
8012 return "DW_OP_lit11";
8014 return "DW_OP_lit12";
8016 return "DW_OP_lit13";
8018 return "DW_OP_lit14";
8020 return "DW_OP_lit15";
8022 return "DW_OP_lit16";
8024 return "DW_OP_lit17";
8026 return "DW_OP_lit18";
8028 return "DW_OP_lit19";
8030 return "DW_OP_lit20";
8032 return "DW_OP_lit21";
8034 return "DW_OP_lit22";
8036 return "DW_OP_lit23";
8038 return "DW_OP_lit24";
8040 return "DW_OP_lit25";
8042 return "DW_OP_lit26";
8044 return "DW_OP_lit27";
8046 return "DW_OP_lit28";
8048 return "DW_OP_lit29";
8050 return "DW_OP_lit30";
8052 return "DW_OP_lit31";
8054 return "DW_OP_reg0";
8056 return "DW_OP_reg1";
8058 return "DW_OP_reg2";
8060 return "DW_OP_reg3";
8062 return "DW_OP_reg4";
8064 return "DW_OP_reg5";
8066 return "DW_OP_reg6";
8068 return "DW_OP_reg7";
8070 return "DW_OP_reg8";
8072 return "DW_OP_reg9";
8074 return "DW_OP_reg10";
8076 return "DW_OP_reg11";
8078 return "DW_OP_reg12";
8080 return "DW_OP_reg13";
8082 return "DW_OP_reg14";
8084 return "DW_OP_reg15";
8086 return "DW_OP_reg16";
8088 return "DW_OP_reg17";
8090 return "DW_OP_reg18";
8092 return "DW_OP_reg19";
8094 return "DW_OP_reg20";
8096 return "DW_OP_reg21";
8098 return "DW_OP_reg22";
8100 return "DW_OP_reg23";
8102 return "DW_OP_reg24";
8104 return "DW_OP_reg25";
8106 return "DW_OP_reg26";
8108 return "DW_OP_reg27";
8110 return "DW_OP_reg28";
8112 return "DW_OP_reg29";
8114 return "DW_OP_reg30";
8116 return "DW_OP_reg31";
8118 return "DW_OP_breg0";
8120 return "DW_OP_breg1";
8122 return "DW_OP_breg2";
8124 return "DW_OP_breg3";
8126 return "DW_OP_breg4";
8128 return "DW_OP_breg5";
8130 return "DW_OP_breg6";
8132 return "DW_OP_breg7";
8134 return "DW_OP_breg8";
8136 return "DW_OP_breg9";
8138 return "DW_OP_breg10";
8140 return "DW_OP_breg11";
8142 return "DW_OP_breg12";
8144 return "DW_OP_breg13";
8146 return "DW_OP_breg14";
8148 return "DW_OP_breg15";
8150 return "DW_OP_breg16";
8152 return "DW_OP_breg17";
8154 return "DW_OP_breg18";
8156 return "DW_OP_breg19";
8158 return "DW_OP_breg20";
8160 return "DW_OP_breg21";
8162 return "DW_OP_breg22";
8164 return "DW_OP_breg23";
8166 return "DW_OP_breg24";
8168 return "DW_OP_breg25";
8170 return "DW_OP_breg26";
8172 return "DW_OP_breg27";
8174 return "DW_OP_breg28";
8176 return "DW_OP_breg29";
8178 return "DW_OP_breg30";
8180 return "DW_OP_breg31";
8182 return "DW_OP_regx";
8184 return "DW_OP_fbreg";
8186 return "DW_OP_bregx";
8188 return "DW_OP_piece";
8189 case DW_OP_deref_size:
8190 return "DW_OP_deref_size";
8191 case DW_OP_xderef_size:
8192 return "DW_OP_xderef_size";
8195 /* DWARF 3 extensions. */
8196 case DW_OP_push_object_address:
8197 return "DW_OP_push_object_address";
8199 return "DW_OP_call2";
8201 return "DW_OP_call4";
8202 case DW_OP_call_ref:
8203 return "DW_OP_call_ref";
8204 /* GNU extensions. */
8205 case DW_OP_GNU_push_tls_address:
8206 return "DW_OP_GNU_push_tls_address";
8208 return "OP_<unknown>";
8213 dwarf_bool_name (unsigned mybool)
8221 /* Convert a DWARF type code into its string name. */
8224 dwarf_type_encoding_name (unsigned enc)
8228 case DW_ATE_address:
8229 return "DW_ATE_address";
8230 case DW_ATE_boolean:
8231 return "DW_ATE_boolean";
8232 case DW_ATE_complex_float:
8233 return "DW_ATE_complex_float";
8235 return "DW_ATE_float";
8237 return "DW_ATE_signed";
8238 case DW_ATE_signed_char:
8239 return "DW_ATE_signed_char";
8240 case DW_ATE_unsigned:
8241 return "DW_ATE_unsigned";
8242 case DW_ATE_unsigned_char:
8243 return "DW_ATE_unsigned_char";
8244 case DW_ATE_imaginary_float:
8245 return "DW_ATE_imaginary_float";
8247 return "DW_ATE_<unknown>";
8251 /* Convert a DWARF call frame info operation to its string name. */
8255 dwarf_cfi_name (unsigned cfi_opc)
8259 case DW_CFA_advance_loc:
8260 return "DW_CFA_advance_loc";
8262 return "DW_CFA_offset";
8263 case DW_CFA_restore:
8264 return "DW_CFA_restore";
8266 return "DW_CFA_nop";
8267 case DW_CFA_set_loc:
8268 return "DW_CFA_set_loc";
8269 case DW_CFA_advance_loc1:
8270 return "DW_CFA_advance_loc1";
8271 case DW_CFA_advance_loc2:
8272 return "DW_CFA_advance_loc2";
8273 case DW_CFA_advance_loc4:
8274 return "DW_CFA_advance_loc4";
8275 case DW_CFA_offset_extended:
8276 return "DW_CFA_offset_extended";
8277 case DW_CFA_restore_extended:
8278 return "DW_CFA_restore_extended";
8279 case DW_CFA_undefined:
8280 return "DW_CFA_undefined";
8281 case DW_CFA_same_value:
8282 return "DW_CFA_same_value";
8283 case DW_CFA_register:
8284 return "DW_CFA_register";
8285 case DW_CFA_remember_state:
8286 return "DW_CFA_remember_state";
8287 case DW_CFA_restore_state:
8288 return "DW_CFA_restore_state";
8289 case DW_CFA_def_cfa:
8290 return "DW_CFA_def_cfa";
8291 case DW_CFA_def_cfa_register:
8292 return "DW_CFA_def_cfa_register";
8293 case DW_CFA_def_cfa_offset:
8294 return "DW_CFA_def_cfa_offset";
8297 case DW_CFA_def_cfa_expression:
8298 return "DW_CFA_def_cfa_expression";
8299 case DW_CFA_expression:
8300 return "DW_CFA_expression";
8301 case DW_CFA_offset_extended_sf:
8302 return "DW_CFA_offset_extended_sf";
8303 case DW_CFA_def_cfa_sf:
8304 return "DW_CFA_def_cfa_sf";
8305 case DW_CFA_def_cfa_offset_sf:
8306 return "DW_CFA_def_cfa_offset_sf";
8308 /* SGI/MIPS specific */
8309 case DW_CFA_MIPS_advance_loc8:
8310 return "DW_CFA_MIPS_advance_loc8";
8312 /* GNU extensions */
8313 case DW_CFA_GNU_window_save:
8314 return "DW_CFA_GNU_window_save";
8315 case DW_CFA_GNU_args_size:
8316 return "DW_CFA_GNU_args_size";
8317 case DW_CFA_GNU_negative_offset_extended:
8318 return "DW_CFA_GNU_negative_offset_extended";
8321 return "DW_CFA_<unknown>";
8327 dump_die (struct die_info *die)
8331 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
8332 dwarf_tag_name (die->tag), die->abbrev, die->offset);
8333 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
8334 dwarf_bool_name (die->child != NULL));
8336 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
8337 for (i = 0; i < die->num_attrs; ++i)
8339 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
8340 dwarf_attr_name (die->attrs[i].name),
8341 dwarf_form_name (die->attrs[i].form));
8342 switch (die->attrs[i].form)
8344 case DW_FORM_ref_addr:
8346 fprintf_unfiltered (gdb_stderr, "address: ");
8347 deprecated_print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
8349 case DW_FORM_block2:
8350 case DW_FORM_block4:
8352 case DW_FORM_block1:
8353 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
8358 fprintf_unfiltered (gdb_stderr, "constant ref: %ld (adjusted)",
8359 (long) (DW_ADDR (&die->attrs[i])));
8367 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
8369 case DW_FORM_string:
8371 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
8372 DW_STRING (&die->attrs[i])
8373 ? DW_STRING (&die->attrs[i]) : "");
8376 if (DW_UNSND (&die->attrs[i]))
8377 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
8379 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
8381 case DW_FORM_indirect:
8382 /* the reader will have reduced the indirect form to
8383 the "base form" so this form should not occur */
8384 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
8387 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
8388 die->attrs[i].form);
8390 fprintf_unfiltered (gdb_stderr, "\n");
8395 dump_die_list (struct die_info *die)
8400 if (die->child != NULL)
8401 dump_die_list (die->child);
8402 if (die->sibling != NULL)
8403 dump_die_list (die->sibling);
8408 store_in_ref_table (unsigned int offset, struct die_info *die,
8409 struct dwarf2_cu *cu)
8412 struct die_info *old;
8414 h = (offset % REF_HASH_SIZE);
8415 old = cu->die_ref_table[h];
8416 die->next_ref = old;
8417 cu->die_ref_table[h] = die;
8421 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
8423 unsigned int result = 0;
8427 case DW_FORM_ref_addr:
8432 case DW_FORM_ref_udata:
8433 result = DW_ADDR (attr);
8436 complaint (&symfile_complaints,
8437 _("unsupported die ref attribute form: '%s'"),
8438 dwarf_form_name (attr->form));
8443 /* Return the constant value held by the given attribute. Return -1
8444 if the value held by the attribute is not constant. */
8447 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
8449 if (attr->form == DW_FORM_sdata)
8450 return DW_SND (attr);
8451 else if (attr->form == DW_FORM_udata
8452 || attr->form == DW_FORM_data1
8453 || attr->form == DW_FORM_data2
8454 || attr->form == DW_FORM_data4
8455 || attr->form == DW_FORM_data8)
8456 return DW_UNSND (attr);
8459 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
8460 dwarf_form_name (attr->form));
8461 return default_value;
8465 static struct die_info *
8466 follow_die_ref (struct die_info *src_die, struct attribute *attr,
8467 struct dwarf2_cu *cu)
8469 struct die_info *die;
8470 unsigned int offset;
8472 struct die_info temp_die;
8473 struct dwarf2_cu *target_cu;
8475 offset = dwarf2_get_ref_die_offset (attr, cu);
8477 if (DW_ADDR (attr) < cu->header.offset
8478 || DW_ADDR (attr) >= cu->header.offset + cu->header.length)
8480 struct dwarf2_per_cu_data *per_cu;
8481 per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (attr),
8483 target_cu = per_cu->cu;
8488 h = (offset % REF_HASH_SIZE);
8489 die = target_cu->die_ref_table[h];
8492 if (die->offset == offset)
8494 die = die->next_ref;
8497 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
8498 "at 0x%lx [in module %s]"),
8499 (long) src_die->offset, (long) offset, cu->objfile->name);
8504 static struct type *
8505 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
8506 struct dwarf2_cu *cu)
8508 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
8510 error (_("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]"),
8511 typeid, objfile->name);
8514 /* Look for this particular type in the fundamental type vector. If
8515 one is not found, create and install one appropriate for the
8516 current language and the current target machine. */
8518 if (cu->ftypes[typeid] == NULL)
8520 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
8523 return (cu->ftypes[typeid]);
8526 /* Decode simple location descriptions.
8527 Given a pointer to a dwarf block that defines a location, compute
8528 the location and return the value.
8530 NOTE drow/2003-11-18: This function is called in two situations
8531 now: for the address of static or global variables (partial symbols
8532 only) and for offsets into structures which are expected to be
8533 (more or less) constant. The partial symbol case should go away,
8534 and only the constant case should remain. That will let this
8535 function complain more accurately. A few special modes are allowed
8536 without complaint for global variables (for instance, global
8537 register values and thread-local values).
8539 A location description containing no operations indicates that the
8540 object is optimized out. The return value is 0 for that case.
8541 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8542 callers will only want a very basic result and this can become a
8545 When the result is a register number, the global isreg flag is set,
8546 otherwise it is cleared.
8548 Note that stack[0] is unused except as a default error return.
8549 Note that stack overflow is not yet handled. */
8552 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
8554 struct objfile *objfile = cu->objfile;
8555 struct comp_unit_head *cu_header = &cu->header;
8557 int size = blk->size;
8558 char *data = blk->data;
8559 CORE_ADDR stack[64];
8561 unsigned int bytes_read, unsnd;
8606 stack[++stacki] = op - DW_OP_lit0;
8642 stack[++stacki] = op - DW_OP_reg0;
8644 dwarf2_complex_location_expr_complaint ();
8649 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8651 stack[++stacki] = unsnd;
8653 dwarf2_complex_location_expr_complaint ();
8657 stack[++stacki] = read_address (objfile->obfd, &data[i],
8663 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
8668 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
8673 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
8678 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
8683 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
8688 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
8693 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
8699 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
8704 stack[stacki + 1] = stack[stacki];
8709 stack[stacki - 1] += stack[stacki];
8713 case DW_OP_plus_uconst:
8714 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8719 stack[stacki - 1] -= stack[stacki];
8724 /* If we're not the last op, then we definitely can't encode
8725 this using GDB's address_class enum. This is valid for partial
8726 global symbols, although the variable's address will be bogus
8729 dwarf2_complex_location_expr_complaint ();
8732 case DW_OP_GNU_push_tls_address:
8733 /* The top of the stack has the offset from the beginning
8734 of the thread control block at which the variable is located. */
8735 /* Nothing should follow this operator, so the top of stack would
8737 /* This is valid for partial global symbols, but the variable's
8738 address will be bogus in the psymtab. */
8740 dwarf2_complex_location_expr_complaint ();
8744 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
8745 dwarf_stack_op_name (op));
8746 return (stack[stacki]);
8749 return (stack[stacki]);
8752 /* memory allocation interface */
8754 static struct dwarf_block *
8755 dwarf_alloc_block (struct dwarf2_cu *cu)
8757 struct dwarf_block *blk;
8759 blk = (struct dwarf_block *)
8760 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
8764 static struct abbrev_info *
8765 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
8767 struct abbrev_info *abbrev;
8769 abbrev = (struct abbrev_info *)
8770 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
8771 memset (abbrev, 0, sizeof (struct abbrev_info));
8775 static struct die_info *
8776 dwarf_alloc_die (void)
8778 struct die_info *die;
8780 die = (struct die_info *) xmalloc (sizeof (struct die_info));
8781 memset (die, 0, sizeof (struct die_info));
8786 /* Macro support. */
8789 /* Return the full name of file number I in *LH's file name table.
8790 Use COMP_DIR as the name of the current directory of the
8791 compilation. The result is allocated using xmalloc; the caller is
8792 responsible for freeing it. */
8794 file_full_name (int file, struct line_header *lh, const char *comp_dir)
8796 struct file_entry *fe = &lh->file_names[file - 1];
8798 if (IS_ABSOLUTE_PATH (fe->name))
8799 return xstrdup (fe->name);
8807 dir = lh->include_dirs[fe->dir_index - 1];
8813 dir_len = strlen (dir);
8814 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
8815 strcpy (full_name, dir);
8816 full_name[dir_len] = '/';
8817 strcpy (full_name + dir_len + 1, fe->name);
8821 return xstrdup (fe->name);
8826 static struct macro_source_file *
8827 macro_start_file (int file, int line,
8828 struct macro_source_file *current_file,
8829 const char *comp_dir,
8830 struct line_header *lh, struct objfile *objfile)
8832 /* The full name of this source file. */
8833 char *full_name = file_full_name (file, lh, comp_dir);
8835 /* We don't create a macro table for this compilation unit
8836 at all until we actually get a filename. */
8837 if (! pending_macros)
8838 pending_macros = new_macro_table (&objfile->objfile_obstack,
8839 objfile->macro_cache);
8842 /* If we have no current file, then this must be the start_file
8843 directive for the compilation unit's main source file. */
8844 current_file = macro_set_main (pending_macros, full_name);
8846 current_file = macro_include (current_file, line, full_name);
8850 return current_file;
8854 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8855 followed by a null byte. */
8857 copy_string (const char *buf, int len)
8859 char *s = xmalloc (len + 1);
8860 memcpy (s, buf, len);
8868 consume_improper_spaces (const char *p, const char *body)
8872 complaint (&symfile_complaints,
8873 _("macro definition contains spaces in formal argument list:\n`%s'"),
8885 parse_macro_definition (struct macro_source_file *file, int line,
8890 /* The body string takes one of two forms. For object-like macro
8891 definitions, it should be:
8893 <macro name> " " <definition>
8895 For function-like macro definitions, it should be:
8897 <macro name> "() " <definition>
8899 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8901 Spaces may appear only where explicitly indicated, and in the
8904 The Dwarf 2 spec says that an object-like macro's name is always
8905 followed by a space, but versions of GCC around March 2002 omit
8906 the space when the macro's definition is the empty string.
8908 The Dwarf 2 spec says that there should be no spaces between the
8909 formal arguments in a function-like macro's formal argument list,
8910 but versions of GCC around March 2002 include spaces after the
8914 /* Find the extent of the macro name. The macro name is terminated
8915 by either a space or null character (for an object-like macro) or
8916 an opening paren (for a function-like macro). */
8917 for (p = body; *p; p++)
8918 if (*p == ' ' || *p == '(')
8921 if (*p == ' ' || *p == '\0')
8923 /* It's an object-like macro. */
8924 int name_len = p - body;
8925 char *name = copy_string (body, name_len);
8926 const char *replacement;
8929 replacement = body + name_len + 1;
8932 dwarf2_macro_malformed_definition_complaint (body);
8933 replacement = body + name_len;
8936 macro_define_object (file, line, name, replacement);
8942 /* It's a function-like macro. */
8943 char *name = copy_string (body, p - body);
8946 char **argv = xmalloc (argv_size * sizeof (*argv));
8950 p = consume_improper_spaces (p, body);
8952 /* Parse the formal argument list. */
8953 while (*p && *p != ')')
8955 /* Find the extent of the current argument name. */
8956 const char *arg_start = p;
8958 while (*p && *p != ',' && *p != ')' && *p != ' ')
8961 if (! *p || p == arg_start)
8962 dwarf2_macro_malformed_definition_complaint (body);
8965 /* Make sure argv has room for the new argument. */
8966 if (argc >= argv_size)
8969 argv = xrealloc (argv, argv_size * sizeof (*argv));
8972 argv[argc++] = copy_string (arg_start, p - arg_start);
8975 p = consume_improper_spaces (p, body);
8977 /* Consume the comma, if present. */
8982 p = consume_improper_spaces (p, body);
8991 /* Perfectly formed definition, no complaints. */
8992 macro_define_function (file, line, name,
8993 argc, (const char **) argv,
8995 else if (*p == '\0')
8997 /* Complain, but do define it. */
8998 dwarf2_macro_malformed_definition_complaint (body);
8999 macro_define_function (file, line, name,
9000 argc, (const char **) argv,
9004 /* Just complain. */
9005 dwarf2_macro_malformed_definition_complaint (body);
9008 /* Just complain. */
9009 dwarf2_macro_malformed_definition_complaint (body);
9015 for (i = 0; i < argc; i++)
9021 dwarf2_macro_malformed_definition_complaint (body);
9026 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
9027 char *comp_dir, bfd *abfd,
9028 struct dwarf2_cu *cu)
9030 char *mac_ptr, *mac_end;
9031 struct macro_source_file *current_file = 0;
9033 if (dwarf2_per_objfile->macinfo_buffer == NULL)
9035 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
9039 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
9040 mac_end = dwarf2_per_objfile->macinfo_buffer
9041 + dwarf2_per_objfile->macinfo_size;
9045 enum dwarf_macinfo_record_type macinfo_type;
9047 /* Do we at least have room for a macinfo type byte? */
9048 if (mac_ptr >= mac_end)
9050 dwarf2_macros_too_long_complaint ();
9054 macinfo_type = read_1_byte (abfd, mac_ptr);
9057 switch (macinfo_type)
9059 /* A zero macinfo type indicates the end of the macro
9064 case DW_MACINFO_define:
9065 case DW_MACINFO_undef:
9071 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
9072 mac_ptr += bytes_read;
9073 body = read_string (abfd, mac_ptr, &bytes_read);
9074 mac_ptr += bytes_read;
9077 complaint (&symfile_complaints,
9078 _("debug info gives macro %s outside of any file: %s"),
9080 DW_MACINFO_define ? "definition" : macinfo_type ==
9081 DW_MACINFO_undef ? "undefinition" :
9082 "something-or-other", body);
9085 if (macinfo_type == DW_MACINFO_define)
9086 parse_macro_definition (current_file, line, body);
9087 else if (macinfo_type == DW_MACINFO_undef)
9088 macro_undef (current_file, line, body);
9093 case DW_MACINFO_start_file:
9098 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
9099 mac_ptr += bytes_read;
9100 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
9101 mac_ptr += bytes_read;
9103 current_file = macro_start_file (file, line,
9104 current_file, comp_dir,
9109 case DW_MACINFO_end_file:
9111 complaint (&symfile_complaints,
9112 _("macro debug info has an unmatched `close_file' directive"));
9115 current_file = current_file->included_by;
9118 enum dwarf_macinfo_record_type next_type;
9120 /* GCC circa March 2002 doesn't produce the zero
9121 type byte marking the end of the compilation
9122 unit. Complain if it's not there, but exit no
9125 /* Do we at least have room for a macinfo type byte? */
9126 if (mac_ptr >= mac_end)
9128 dwarf2_macros_too_long_complaint ();
9132 /* We don't increment mac_ptr here, so this is just
9134 next_type = read_1_byte (abfd, mac_ptr);
9136 complaint (&symfile_complaints,
9137 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9144 case DW_MACINFO_vendor_ext:
9150 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
9151 mac_ptr += bytes_read;
9152 string = read_string (abfd, mac_ptr, &bytes_read);
9153 mac_ptr += bytes_read;
9155 /* We don't recognize any vendor extensions. */
9162 /* Check if the attribute's form is a DW_FORM_block*
9163 if so return true else false. */
9165 attr_form_is_block (struct attribute *attr)
9167 return (attr == NULL ? 0 :
9168 attr->form == DW_FORM_block1
9169 || attr->form == DW_FORM_block2
9170 || attr->form == DW_FORM_block4
9171 || attr->form == DW_FORM_block);
9175 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
9176 struct dwarf2_cu *cu)
9178 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
9180 struct dwarf2_loclist_baton *baton;
9182 baton = obstack_alloc (&cu->objfile->objfile_obstack,
9183 sizeof (struct dwarf2_loclist_baton));
9184 baton->objfile = cu->objfile;
9186 /* We don't know how long the location list is, but make sure we
9187 don't run off the edge of the section. */
9188 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
9189 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
9190 baton->base_address = cu->header.base_address;
9191 if (cu->header.base_known == 0)
9192 complaint (&symfile_complaints,
9193 _("Location list used without specifying the CU base address."));
9195 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
9196 SYMBOL_LOCATION_BATON (sym) = baton;
9200 struct dwarf2_locexpr_baton *baton;
9202 baton = obstack_alloc (&cu->objfile->objfile_obstack,
9203 sizeof (struct dwarf2_locexpr_baton));
9204 baton->objfile = cu->objfile;
9206 if (attr_form_is_block (attr))
9208 /* Note that we're just copying the block's data pointer
9209 here, not the actual data. We're still pointing into the
9210 info_buffer for SYM's objfile; right now we never release
9211 that buffer, but when we do clean up properly this may
9213 baton->size = DW_BLOCK (attr)->size;
9214 baton->data = DW_BLOCK (attr)->data;
9218 dwarf2_invalid_attrib_class_complaint ("location description",
9219 SYMBOL_NATURAL_NAME (sym));
9224 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
9225 SYMBOL_LOCATION_BATON (sym) = baton;
9229 /* Locate the compilation unit from CU's objfile which contains the
9230 DIE at OFFSET. Raises an error on failure. */
9232 static struct dwarf2_per_cu_data *
9233 dwarf2_find_containing_comp_unit (unsigned long offset,
9234 struct objfile *objfile)
9236 struct dwarf2_per_cu_data *this_cu;
9240 high = dwarf2_per_objfile->n_comp_units - 1;
9243 int mid = low + (high - low) / 2;
9244 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
9249 gdb_assert (low == high);
9250 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
9253 error (_("Dwarf Error: could not find partial DIE containing "
9254 "offset 0x%lx [in module %s]"),
9255 (long) offset, bfd_get_filename (objfile->obfd));
9257 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
9258 return dwarf2_per_objfile->all_comp_units[low-1];
9262 this_cu = dwarf2_per_objfile->all_comp_units[low];
9263 if (low == dwarf2_per_objfile->n_comp_units - 1
9264 && offset >= this_cu->offset + this_cu->length)
9265 error (_("invalid dwarf2 offset %ld"), offset);
9266 gdb_assert (offset < this_cu->offset + this_cu->length);
9271 /* Locate the compilation unit from OBJFILE which is located at exactly
9272 OFFSET. Raises an error on failure. */
9274 static struct dwarf2_per_cu_data *
9275 dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile)
9277 struct dwarf2_per_cu_data *this_cu;
9278 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
9279 if (this_cu->offset != offset)
9280 error (_("no compilation unit with offset %ld."), offset);
9284 /* Release one cached compilation unit, CU. We unlink it from the tree
9285 of compilation units, but we don't remove it from the read_in_chain;
9286 the caller is responsible for that. */
9289 free_one_comp_unit (void *data)
9291 struct dwarf2_cu *cu = data;
9293 if (cu->per_cu != NULL)
9294 cu->per_cu->cu = NULL;
9297 obstack_free (&cu->comp_unit_obstack, NULL);
9299 free_die_list (cu->dies);
9304 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9305 when we're finished with it. We can't free the pointer itself, but be
9306 sure to unlink it from the cache. Also release any associated storage
9307 and perform cache maintenance.
9309 Only used during partial symbol parsing. */
9312 free_stack_comp_unit (void *data)
9314 struct dwarf2_cu *cu = data;
9316 obstack_free (&cu->comp_unit_obstack, NULL);
9317 cu->partial_dies = NULL;
9319 if (cu->per_cu != NULL)
9321 /* This compilation unit is on the stack in our caller, so we
9322 should not xfree it. Just unlink it. */
9323 cu->per_cu->cu = NULL;
9326 /* If we had a per-cu pointer, then we may have other compilation
9327 units loaded, so age them now. */
9328 age_cached_comp_units ();
9332 /* Free all cached compilation units. */
9335 free_cached_comp_units (void *data)
9337 struct dwarf2_per_cu_data *per_cu, **last_chain;
9339 per_cu = dwarf2_per_objfile->read_in_chain;
9340 last_chain = &dwarf2_per_objfile->read_in_chain;
9341 while (per_cu != NULL)
9343 struct dwarf2_per_cu_data *next_cu;
9345 next_cu = per_cu->cu->read_in_chain;
9347 free_one_comp_unit (per_cu->cu);
9348 *last_chain = next_cu;
9354 /* Increase the age counter on each cached compilation unit, and free
9355 any that are too old. */
9358 age_cached_comp_units (void)
9360 struct dwarf2_per_cu_data *per_cu, **last_chain;
9362 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
9363 per_cu = dwarf2_per_objfile->read_in_chain;
9364 while (per_cu != NULL)
9366 per_cu->cu->last_used ++;
9367 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
9368 dwarf2_mark (per_cu->cu);
9369 per_cu = per_cu->cu->read_in_chain;
9372 per_cu = dwarf2_per_objfile->read_in_chain;
9373 last_chain = &dwarf2_per_objfile->read_in_chain;
9374 while (per_cu != NULL)
9376 struct dwarf2_per_cu_data *next_cu;
9378 next_cu = per_cu->cu->read_in_chain;
9380 if (!per_cu->cu->mark)
9382 free_one_comp_unit (per_cu->cu);
9383 *last_chain = next_cu;
9386 last_chain = &per_cu->cu->read_in_chain;
9392 /* Remove a single compilation unit from the cache. */
9395 free_one_cached_comp_unit (void *target_cu)
9397 struct dwarf2_per_cu_data *per_cu, **last_chain;
9399 per_cu = dwarf2_per_objfile->read_in_chain;
9400 last_chain = &dwarf2_per_objfile->read_in_chain;
9401 while (per_cu != NULL)
9403 struct dwarf2_per_cu_data *next_cu;
9405 next_cu = per_cu->cu->read_in_chain;
9407 if (per_cu->cu == target_cu)
9409 free_one_comp_unit (per_cu->cu);
9410 *last_chain = next_cu;
9414 last_chain = &per_cu->cu->read_in_chain;
9420 /* A pair of DIE offset and GDB type pointer. We store these
9421 in a hash table separate from the DIEs, and preserve them
9422 when the DIEs are flushed out of cache. */
9424 struct dwarf2_offset_and_type
9426 unsigned int offset;
9430 /* Hash function for a dwarf2_offset_and_type. */
9433 offset_and_type_hash (const void *item)
9435 const struct dwarf2_offset_and_type *ofs = item;
9439 /* Equality function for a dwarf2_offset_and_type. */
9442 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
9444 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
9445 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
9446 return ofs_lhs->offset == ofs_rhs->offset;
9449 /* Set the type associated with DIE to TYPE. Save it in CU's hash
9450 table if necessary. */
9453 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
9455 struct dwarf2_offset_and_type **slot, ofs;
9459 if (cu->per_cu == NULL)
9462 if (cu->per_cu->type_hash == NULL)
9463 cu->per_cu->type_hash
9464 = htab_create_alloc_ex (cu->header.length / 24,
9465 offset_and_type_hash,
9468 &cu->objfile->objfile_obstack,
9469 hashtab_obstack_allocate,
9470 dummy_obstack_deallocate);
9472 ofs.offset = die->offset;
9474 slot = (struct dwarf2_offset_and_type **)
9475 htab_find_slot_with_hash (cu->per_cu->type_hash, &ofs, ofs.offset, INSERT);
9476 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
9480 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
9481 have a saved type. */
9483 static struct type *
9484 get_die_type (struct die_info *die, htab_t type_hash)
9486 struct dwarf2_offset_and_type *slot, ofs;
9488 ofs.offset = die->offset;
9489 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
9496 /* Restore the types of the DIE tree starting at START_DIE from the hash
9497 table saved in CU. */
9500 reset_die_and_siblings_types (struct die_info *start_die, struct dwarf2_cu *cu)
9502 struct die_info *die;
9504 if (cu->per_cu->type_hash == NULL)
9507 for (die = start_die; die != NULL; die = die->sibling)
9509 die->type = get_die_type (die, cu->per_cu->type_hash);
9510 if (die->child != NULL)
9511 reset_die_and_siblings_types (die->child, cu);
9515 /* Set the mark field in CU and in every other compilation unit in the
9516 cache that we must keep because we are keeping CU. */
9518 /* Add a dependence relationship from CU to REF_PER_CU. */
9521 dwarf2_add_dependence (struct dwarf2_cu *cu,
9522 struct dwarf2_per_cu_data *ref_per_cu)
9526 if (cu->dependencies == NULL)
9528 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
9529 NULL, &cu->comp_unit_obstack,
9530 hashtab_obstack_allocate,
9531 dummy_obstack_deallocate);
9533 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
9538 /* Set the mark field in CU and in every other compilation unit in the
9539 cache that we must keep because we are keeping CU. */
9542 dwarf2_mark_helper (void **slot, void *data)
9544 struct dwarf2_per_cu_data *per_cu;
9546 per_cu = (struct dwarf2_per_cu_data *) *slot;
9547 if (per_cu->cu->mark)
9549 per_cu->cu->mark = 1;
9551 if (per_cu->cu->dependencies != NULL)
9552 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
9558 dwarf2_mark (struct dwarf2_cu *cu)
9563 if (cu->dependencies != NULL)
9564 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
9568 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
9572 per_cu->cu->mark = 0;
9573 per_cu = per_cu->cu->read_in_chain;
9577 /* Allocation function for the libiberty hash table which uses an
9581 hashtab_obstack_allocate (void *data, size_t size, size_t count)
9583 unsigned int total = size * count;
9584 void *ptr = obstack_alloc ((struct obstack *) data, total);
9585 memset (ptr, 0, total);
9589 /* Trivial deallocation function for the libiberty splay tree and hash
9590 table - don't deallocate anything. Rely on later deletion of the
9594 dummy_obstack_deallocate (void *object, void *data)
9599 /* Trivial hash function for partial_die_info: the hash value of a DIE
9600 is its offset in .debug_info for this objfile. */
9603 partial_die_hash (const void *item)
9605 const struct partial_die_info *part_die = item;
9606 return part_die->offset;
9609 /* Trivial comparison function for partial_die_info structures: two DIEs
9610 are equal if they have the same offset. */
9613 partial_die_eq (const void *item_lhs, const void *item_rhs)
9615 const struct partial_die_info *part_die_lhs = item_lhs;
9616 const struct partial_die_info *part_die_rhs = item_rhs;
9617 return part_die_lhs->offset == part_die_rhs->offset;
9620 static struct cmd_list_element *set_dwarf2_cmdlist;
9621 static struct cmd_list_element *show_dwarf2_cmdlist;
9624 set_dwarf2_cmd (char *args, int from_tty)
9626 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
9630 show_dwarf2_cmd (char *args, int from_tty)
9632 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
9635 void _initialize_dwarf2_read (void);
9638 _initialize_dwarf2_read (void)
9640 dwarf2_objfile_data_key = register_objfile_data ();
9642 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
9643 Set DWARF 2 specific variables.\n\
9644 Configure DWARF 2 variables such as the cache size"),
9645 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
9646 0/*allow-unknown*/, &maintenance_set_cmdlist);
9648 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
9649 Show DWARF 2 specific variables\n\
9650 Show DWARF 2 variables such as the cache size"),
9651 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
9652 0/*allow-unknown*/, &maintenance_show_cmdlist);
9654 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
9655 &dwarf2_max_cache_age, _("\
9656 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
9657 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
9658 A higher limit means that cached compilation units will be stored\n\
9659 in memory longer, and more total memory will be used. Zero disables\n\
9660 caching, which can slow down startup."),
9662 show_dwarf2_max_cache_age,
9663 &set_dwarf2_cmdlist,
9664 &show_dwarf2_cmdlist);