1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
63 /* .debug_info header for a compilation unit
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct comp_unit_header
68 unsigned int length; /* length of the .debug_info
70 unsigned short version; /* version number -- 2 for DWARF
72 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
73 unsigned char addr_size; /* byte size of an address -- 4 */
76 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
79 /* .debug_pubnames header
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct pubnames_header
84 unsigned int length; /* length of the .debug_pubnames
86 unsigned char version; /* version number -- 2 for DWARF
88 unsigned int info_offset; /* offset into .debug_info section */
89 unsigned int info_size; /* byte size of .debug_info section
93 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
95 /* .debug_pubnames header
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct aranges_header
100 unsigned int length; /* byte len of the .debug_aranges
102 unsigned short version; /* version number -- 2 for DWARF
104 unsigned int info_offset; /* offset into .debug_info section */
105 unsigned char addr_size; /* byte size of an address */
106 unsigned char seg_size; /* byte size of segment descriptor */
109 #define _ACTUAL_ARANGES_HEADER_SIZE 12
111 /* .debug_line statement program prologue
112 Because of alignment constraints, this structure has padding and cannot
113 be mapped directly onto the beginning of the .debug_info section. */
114 typedef struct statement_prologue
116 unsigned int total_length; /* byte length of the statement
118 unsigned short version; /* version number -- 2 for DWARF
120 unsigned int prologue_length; /* # bytes between prologue &
122 unsigned char minimum_instruction_length; /* byte size of
124 unsigned char default_is_stmt; /* initial value of is_stmt
127 unsigned char line_range;
128 unsigned char opcode_base; /* number assigned to first special
130 unsigned char *standard_opcode_lengths;
134 /* When non-zero, dump DIEs after they are read in. */
135 static int dwarf2_die_debug = 0;
139 /* When set, the file that we're processing is known to have debugging
140 info for C++ namespaces. GCC 3.3.x did not produce this information,
141 but later versions do. */
143 static int processing_has_namespace_info;
145 static const struct objfile_data *dwarf2_objfile_data_key;
147 struct dwarf2_section_info
155 struct dwarf2_per_objfile
157 struct dwarf2_section_info info;
158 struct dwarf2_section_info abbrev;
159 struct dwarf2_section_info line;
160 struct dwarf2_section_info pubnames;
161 struct dwarf2_section_info aranges;
162 struct dwarf2_section_info loc;
163 struct dwarf2_section_info macinfo;
164 struct dwarf2_section_info str;
165 struct dwarf2_section_info ranges;
166 struct dwarf2_section_info frame;
167 struct dwarf2_section_info eh_frame;
169 /* A list of all the compilation units. This is used to locate
170 the target compilation unit of a particular reference. */
171 struct dwarf2_per_cu_data **all_comp_units;
173 /* The number of compilation units in ALL_COMP_UNITS. */
176 /* A chain of compilation units that are currently read in, so that
177 they can be freed later. */
178 struct dwarf2_per_cu_data *read_in_chain;
180 /* A flag indicating wether this objfile has a section loaded at a
182 int has_section_at_zero;
185 static struct dwarf2_per_objfile *dwarf2_per_objfile;
187 /* names of the debugging sections */
189 /* Note that if the debugging section has been compressed, it might
190 have a name like .zdebug_info. */
192 #define INFO_SECTION "debug_info"
193 #define ABBREV_SECTION "debug_abbrev"
194 #define LINE_SECTION "debug_line"
195 #define PUBNAMES_SECTION "debug_pubnames"
196 #define ARANGES_SECTION "debug_aranges"
197 #define LOC_SECTION "debug_loc"
198 #define MACINFO_SECTION "debug_macinfo"
199 #define STR_SECTION "debug_str"
200 #define RANGES_SECTION "debug_ranges"
201 #define FRAME_SECTION "debug_frame"
202 #define EH_FRAME_SECTION "eh_frame"
204 /* local data types */
206 /* We hold several abbreviation tables in memory at the same time. */
207 #ifndef ABBREV_HASH_SIZE
208 #define ABBREV_HASH_SIZE 121
211 /* The data in a compilation unit header, after target2host
212 translation, looks like this. */
213 struct comp_unit_head
217 unsigned char addr_size;
218 unsigned char signed_addr_p;
219 unsigned int abbrev_offset;
221 /* Size of file offsets; either 4 or 8. */
222 unsigned int offset_size;
224 /* Size of the length field; either 4 or 12. */
225 unsigned int initial_length_size;
227 /* Offset to the first byte of this compilation unit header in the
228 .debug_info section, for resolving relative reference dies. */
231 /* Offset to first die in this cu from the start of the cu.
232 This will be the first byte following the compilation unit header. */
233 unsigned int first_die_offset;
236 /* Internal state when decoding a particular compilation unit. */
239 /* The objfile containing this compilation unit. */
240 struct objfile *objfile;
242 /* The header of the compilation unit. */
243 struct comp_unit_head header;
245 /* Base address of this compilation unit. */
246 CORE_ADDR base_address;
248 /* Non-zero if base_address has been set. */
251 struct function_range *first_fn, *last_fn, *cached_fn;
253 /* The language we are debugging. */
254 enum language language;
255 const struct language_defn *language_defn;
257 const char *producer;
259 /* The generic symbol table building routines have separate lists for
260 file scope symbols and all all other scopes (local scopes). So
261 we need to select the right one to pass to add_symbol_to_list().
262 We do it by keeping a pointer to the correct list in list_in_scope.
264 FIXME: The original dwarf code just treated the file scope as the
265 first local scope, and all other local scopes as nested local
266 scopes, and worked fine. Check to see if we really need to
267 distinguish these in buildsym.c. */
268 struct pending **list_in_scope;
270 /* DWARF abbreviation table associated with this compilation unit. */
271 struct abbrev_info **dwarf2_abbrevs;
273 /* Storage for the abbrev table. */
274 struct obstack abbrev_obstack;
276 /* Hash table holding all the loaded partial DIEs. */
279 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
280 unsigned int ranges_offset;
282 /* Storage for things with the same lifetime as this read-in compilation
283 unit, including partial DIEs. */
284 struct obstack comp_unit_obstack;
286 /* When multiple dwarf2_cu structures are living in memory, this field
287 chains them all together, so that they can be released efficiently.
288 We will probably also want a generation counter so that most-recently-used
289 compilation units are cached... */
290 struct dwarf2_per_cu_data *read_in_chain;
292 /* Backchain to our per_cu entry if the tree has been built. */
293 struct dwarf2_per_cu_data *per_cu;
295 /* Pointer to the die -> type map. Although it is stored
296 permanently in per_cu, we copy it here to avoid double
300 /* How many compilation units ago was this CU last referenced? */
303 /* A hash table of die offsets for following references. */
306 /* Full DIEs if read in. */
307 struct die_info *dies;
309 /* A set of pointers to dwarf2_per_cu_data objects for compilation
310 units referenced by this one. Only set during full symbol processing;
311 partial symbol tables do not have dependencies. */
314 /* Header data from the line table, during full symbol processing. */
315 struct line_header *line_header;
317 /* Mark used when releasing cached dies. */
318 unsigned int mark : 1;
320 /* This flag will be set if this compilation unit might include
321 inter-compilation-unit references. */
322 unsigned int has_form_ref_addr : 1;
324 /* This flag will be set if this compilation unit includes any
325 DW_TAG_namespace DIEs. If we know that there are explicit
326 DIEs for namespaces, we don't need to try to infer them
327 from mangled names. */
328 unsigned int has_namespace_info : 1;
330 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
331 unsigned int has_ranges_offset : 1;
334 /* Persistent data held for a compilation unit, even when not
335 processing it. We put a pointer to this structure in the
336 read_symtab_private field of the psymtab. If we encounter
337 inter-compilation-unit references, we also maintain a sorted
338 list of all compilation units. */
340 struct dwarf2_per_cu_data
342 /* The start offset and length of this compilation unit. 2**30-1
343 bytes should suffice to store the length of any compilation unit
344 - if it doesn't, GDB will fall over anyway.
345 NOTE: Unlike comp_unit_head.length, this length includes
346 initial_length_size. */
348 unsigned int length : 30;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned int queued : 1;
354 /* This flag will be set if we need to load absolutely all DIEs
355 for this compilation unit, instead of just the ones we think
356 are interesting. It gets set if we look for a DIE in the
357 hash table and don't find it. */
358 unsigned int load_all_dies : 1;
360 /* Set iff currently read in. */
361 struct dwarf2_cu *cu;
363 /* If full symbols for this CU have been read in, then this field
364 holds a map of DIE offsets to types. It isn't always possible
365 to reconstruct this information later, so we have to preserve
369 /* The partial symbol table associated with this compilation unit,
370 or NULL for partial units (which do not have an associated
372 struct partial_symtab *psymtab;
375 /* The line number information for a compilation unit (found in the
376 .debug_line section) begins with a "statement program header",
377 which contains the following information. */
380 unsigned int total_length;
381 unsigned short version;
382 unsigned int header_length;
383 unsigned char minimum_instruction_length;
384 unsigned char default_is_stmt;
386 unsigned char line_range;
387 unsigned char opcode_base;
389 /* standard_opcode_lengths[i] is the number of operands for the
390 standard opcode whose value is i. This means that
391 standard_opcode_lengths[0] is unused, and the last meaningful
392 element is standard_opcode_lengths[opcode_base - 1]. */
393 unsigned char *standard_opcode_lengths;
395 /* The include_directories table. NOTE! These strings are not
396 allocated with xmalloc; instead, they are pointers into
397 debug_line_buffer. If you try to free them, `free' will get
399 unsigned int num_include_dirs, include_dirs_size;
402 /* The file_names table. NOTE! These strings are not allocated
403 with xmalloc; instead, they are pointers into debug_line_buffer.
404 Don't try to free them directly. */
405 unsigned int num_file_names, file_names_size;
409 unsigned int dir_index;
410 unsigned int mod_time;
412 int included_p; /* Non-zero if referenced by the Line Number Program. */
413 struct symtab *symtab; /* The associated symbol table, if any. */
416 /* The start and end of the statement program following this
417 header. These point into dwarf2_per_objfile->line_buffer. */
418 gdb_byte *statement_program_start, *statement_program_end;
421 /* When we construct a partial symbol table entry we only
422 need this much information. */
423 struct partial_die_info
425 /* Offset of this DIE. */
428 /* DWARF-2 tag for this DIE. */
429 ENUM_BITFIELD(dwarf_tag) tag : 16;
431 /* Language code associated with this DIE. This is only used
432 for the compilation unit DIE. */
433 unsigned int language : 8;
435 /* Assorted flags describing the data found in this DIE. */
436 unsigned int has_children : 1;
437 unsigned int is_external : 1;
438 unsigned int is_declaration : 1;
439 unsigned int has_type : 1;
440 unsigned int has_specification : 1;
441 unsigned int has_stmt_list : 1;
442 unsigned int has_pc_info : 1;
444 /* Flag set if the SCOPE field of this structure has been
446 unsigned int scope_set : 1;
448 /* Flag set if the DIE has a byte_size attribute. */
449 unsigned int has_byte_size : 1;
451 /* The name of this DIE. Normally the value of DW_AT_name, but
452 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
457 /* The scope to prepend to our children. This is generally
458 allocated on the comp_unit_obstack, so will disappear
459 when this compilation unit leaves the cache. */
462 /* The location description associated with this DIE, if any. */
463 struct dwarf_block *locdesc;
465 /* If HAS_PC_INFO, the PC range associated with this DIE. */
469 /* Pointer into the info_buffer pointing at the target of
470 DW_AT_sibling, if any. */
473 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
474 DW_AT_specification (or DW_AT_abstract_origin or
476 unsigned int spec_offset;
478 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
479 unsigned int line_offset;
481 /* Pointers to this DIE's parent, first child, and next sibling,
483 struct partial_die_info *die_parent, *die_child, *die_sibling;
486 /* This data structure holds the information of an abbrev. */
489 unsigned int number; /* number identifying abbrev */
490 enum dwarf_tag tag; /* dwarf tag */
491 unsigned short has_children; /* boolean */
492 unsigned short num_attrs; /* number of attributes */
493 struct attr_abbrev *attrs; /* an array of attribute descriptions */
494 struct abbrev_info *next; /* next in chain */
499 ENUM_BITFIELD(dwarf_attribute) name : 16;
500 ENUM_BITFIELD(dwarf_form) form : 16;
503 /* Additional GDB-specific attribute forms. */
506 /* A string which has been updated to GDB's internal
507 representation (e.g. converted to canonical form) and does not
508 need to be updated again. */
509 GDB_FORM_cached_string = 0xff
512 /* Attributes have a name and a value */
515 ENUM_BITFIELD(dwarf_attribute) name : 16;
516 ENUM_BITFIELD(dwarf_form) form : 16;
520 struct dwarf_block *blk;
528 /* This data structure holds a complete die structure. */
531 /* DWARF-2 tag for this DIE. */
532 ENUM_BITFIELD(dwarf_tag) tag : 16;
534 /* Number of attributes */
535 unsigned short num_attrs;
540 /* Offset in .debug_info section */
543 /* The dies in a compilation unit form an n-ary tree. PARENT
544 points to this die's parent; CHILD points to the first child of
545 this node; and all the children of a given node are chained
546 together via their SIBLING fields, terminated by a die whose
548 struct die_info *child; /* Its first child, if any. */
549 struct die_info *sibling; /* Its next sibling, if any. */
550 struct die_info *parent; /* Its parent, if any. */
552 /* An array of attributes, with NUM_ATTRS elements. There may be
553 zero, but it's not common and zero-sized arrays are not
554 sufficiently portable C. */
555 struct attribute attrs[1];
558 struct function_range
561 CORE_ADDR lowpc, highpc;
563 struct function_range *next;
566 /* Get at parts of an attribute structure */
568 #define DW_STRING(attr) ((attr)->u.str)
569 #define DW_UNSND(attr) ((attr)->u.unsnd)
570 #define DW_BLOCK(attr) ((attr)->u.blk)
571 #define DW_SND(attr) ((attr)->u.snd)
572 #define DW_ADDR(attr) ((attr)->u.addr)
574 /* Blocks are a bunch of untyped bytes. */
581 #ifndef ATTR_ALLOC_CHUNK
582 #define ATTR_ALLOC_CHUNK 4
585 /* Allocate fields for structs, unions and enums in this size. */
586 #ifndef DW_FIELD_ALLOC_CHUNK
587 #define DW_FIELD_ALLOC_CHUNK 4
590 /* A zeroed version of a partial die for initialization purposes. */
591 static struct partial_die_info zeroed_partial_die;
593 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
594 but this would require a corresponding change in unpack_field_as_long
596 static int bits_per_byte = 8;
598 /* The routines that read and process dies for a C struct or C++ class
599 pass lists of data member fields and lists of member function fields
600 in an instance of a field_info structure, as defined below. */
603 /* List of data member and baseclasses fields. */
606 struct nextfield *next;
613 /* Number of fields. */
616 /* Number of baseclasses. */
619 /* Set if the accesibility of one of the fields is not public. */
620 int non_public_fields;
622 /* Member function fields array, entries are allocated in the order they
623 are encountered in the object file. */
626 struct nextfnfield *next;
627 struct fn_field fnfield;
631 /* Member function fieldlist array, contains name of possibly overloaded
632 member function, number of overloaded member functions and a pointer
633 to the head of the member function field chain. */
638 struct nextfnfield *head;
642 /* Number of entries in the fnfieldlists array. */
646 /* One item on the queue of compilation units to read in full symbols
648 struct dwarf2_queue_item
650 struct dwarf2_per_cu_data *per_cu;
651 struct dwarf2_queue_item *next;
654 /* The current queue. */
655 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
657 /* Loaded secondary compilation units are kept in memory until they
658 have not been referenced for the processing of this many
659 compilation units. Set this to zero to disable caching. Cache
660 sizes of up to at least twenty will improve startup time for
661 typical inter-CU-reference binaries, at an obvious memory cost. */
662 static int dwarf2_max_cache_age = 5;
664 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
665 struct cmd_list_element *c, const char *value)
667 fprintf_filtered (file, _("\
668 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
673 /* Various complaints about symbol reading that don't abort the process */
676 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
678 complaint (&symfile_complaints,
679 _("statement list doesn't fit in .debug_line section"));
683 dwarf2_debug_line_missing_file_complaint (void)
685 complaint (&symfile_complaints,
686 _(".debug_line section has line data without a file"));
690 dwarf2_debug_line_missing_end_sequence_complaint (void)
692 complaint (&symfile_complaints,
693 _(".debug_line section has line program sequence without an end"));
697 dwarf2_complex_location_expr_complaint (void)
699 complaint (&symfile_complaints, _("location expression too complex"));
703 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
706 complaint (&symfile_complaints,
707 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
712 dwarf2_macros_too_long_complaint (void)
714 complaint (&symfile_complaints,
715 _("macro info runs off end of `.debug_macinfo' section"));
719 dwarf2_macro_malformed_definition_complaint (const char *arg1)
721 complaint (&symfile_complaints,
722 _("macro debug info contains a malformed macro definition:\n`%s'"),
727 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
729 complaint (&symfile_complaints,
730 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
733 /* local function prototypes */
735 static void dwarf2_locate_sections (bfd *, asection *, void *);
738 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
741 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
744 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
745 struct partial_die_info *,
746 struct partial_symtab *);
748 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
750 static void scan_partial_symbols (struct partial_die_info *,
751 CORE_ADDR *, CORE_ADDR *,
752 int, struct dwarf2_cu *);
754 static void add_partial_symbol (struct partial_die_info *,
757 static int pdi_needs_namespace (enum dwarf_tag tag);
759 static void add_partial_namespace (struct partial_die_info *pdi,
760 CORE_ADDR *lowpc, CORE_ADDR *highpc,
761 int need_pc, struct dwarf2_cu *cu);
763 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
764 CORE_ADDR *highpc, int need_pc,
765 struct dwarf2_cu *cu);
767 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
768 struct dwarf2_cu *cu);
770 static void add_partial_subprogram (struct partial_die_info *pdi,
771 CORE_ADDR *lowpc, CORE_ADDR *highpc,
772 int need_pc, struct dwarf2_cu *cu);
774 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
777 struct dwarf2_cu *cu);
779 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
781 static void psymtab_to_symtab_1 (struct partial_symtab *);
783 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
785 static void dwarf2_free_abbrev_table (void *);
787 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
790 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
793 static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int,
796 static gdb_byte *read_partial_die (struct partial_die_info *,
797 struct abbrev_info *abbrev, unsigned int,
798 bfd *, gdb_byte *, struct dwarf2_cu *);
800 static struct partial_die_info *find_partial_die (unsigned int,
803 static void fixup_partial_die (struct partial_die_info *,
806 static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *,
807 struct dwarf2_cu *, int *);
809 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
810 bfd *, gdb_byte *, struct dwarf2_cu *);
812 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
813 bfd *, gdb_byte *, struct dwarf2_cu *);
815 static unsigned int read_1_byte (bfd *, gdb_byte *);
817 static int read_1_signed_byte (bfd *, gdb_byte *);
819 static unsigned int read_2_bytes (bfd *, gdb_byte *);
821 static unsigned int read_4_bytes (bfd *, gdb_byte *);
823 static unsigned long read_8_bytes (bfd *, gdb_byte *);
825 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
828 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
830 static LONGEST read_checked_initial_length_and_offset
831 (bfd *, gdb_byte *, const struct comp_unit_head *,
832 unsigned int *, unsigned int *);
834 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
837 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
839 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
841 static char *read_string (bfd *, gdb_byte *, unsigned int *);
843 static char *read_indirect_string (bfd *, gdb_byte *,
844 const struct comp_unit_head *,
847 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
849 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
851 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
853 static void set_cu_language (unsigned int, struct dwarf2_cu *);
855 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
858 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
859 struct dwarf2_cu *cu);
861 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
863 static struct die_info *die_specification (struct die_info *die,
864 struct dwarf2_cu **);
866 static void free_line_header (struct line_header *lh);
868 static void add_file_name (struct line_header *, char *, unsigned int,
869 unsigned int, unsigned int);
871 static struct line_header *(dwarf_decode_line_header
872 (unsigned int offset,
873 bfd *abfd, struct dwarf2_cu *cu));
875 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
876 struct dwarf2_cu *, struct partial_symtab *);
878 static void dwarf2_start_subfile (char *, char *, char *);
880 static struct symbol *new_symbol (struct die_info *, struct type *,
883 static void dwarf2_const_value (struct attribute *, struct symbol *,
886 static void dwarf2_const_value_data (struct attribute *attr,
890 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
892 static struct type *die_containing_type (struct die_info *,
895 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
897 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
899 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
901 static char *typename_concat (struct obstack *,
906 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
908 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
910 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
912 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
913 struct dwarf2_cu *, struct partial_symtab *);
915 static int dwarf2_get_pc_bounds (struct die_info *,
916 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
918 static void get_scope_pc_bounds (struct die_info *,
919 CORE_ADDR *, CORE_ADDR *,
922 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
923 CORE_ADDR, struct dwarf2_cu *);
925 static void dwarf2_add_field (struct field_info *, struct die_info *,
928 static void dwarf2_attach_fields_to_type (struct field_info *,
929 struct type *, struct dwarf2_cu *);
931 static void dwarf2_add_member_fn (struct field_info *,
932 struct die_info *, struct type *,
935 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
936 struct type *, struct dwarf2_cu *);
938 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
940 static const char *determine_class_name (struct die_info *die,
941 struct dwarf2_cu *cu);
943 static void read_common_block (struct die_info *, struct dwarf2_cu *);
945 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
947 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
949 static const char *namespace_name (struct die_info *die,
950 int *is_anonymous, struct dwarf2_cu *);
952 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
954 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
956 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
959 static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *);
961 static struct die_info *read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd,
963 gdb_byte **new_info_ptr,
964 struct die_info *parent);
966 static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd,
968 gdb_byte **new_info_ptr,
969 struct die_info *parent);
971 static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd,
973 gdb_byte **new_info_ptr,
974 struct die_info *parent);
976 static void process_die (struct die_info *, struct dwarf2_cu *);
978 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
980 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
983 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
985 static struct die_info *dwarf2_extension (struct die_info *die,
986 struct dwarf2_cu **);
988 static char *dwarf_tag_name (unsigned int);
990 static char *dwarf_attr_name (unsigned int);
992 static char *dwarf_form_name (unsigned int);
994 static char *dwarf_stack_op_name (unsigned int);
996 static char *dwarf_bool_name (unsigned int);
998 static char *dwarf_type_encoding_name (unsigned int);
1001 static char *dwarf_cfi_name (unsigned int);
1004 static struct die_info *sibling_die (struct die_info *);
1006 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1008 static void dump_die_for_error (struct die_info *);
1010 static void dump_die_1 (struct ui_file *, int level, int max_level,
1013 /*static*/ void dump_die (struct die_info *, int max_level);
1015 static void store_in_ref_table (struct die_info *,
1016 struct dwarf2_cu *);
1018 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1020 static int dwarf2_get_attr_constant_value (struct attribute *, int);
1022 static struct die_info *follow_die_ref (struct die_info *,
1024 struct dwarf2_cu **);
1026 /* memory allocation interface */
1028 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1030 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1032 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1034 static void initialize_cu_func_list (struct dwarf2_cu *);
1036 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1037 struct dwarf2_cu *);
1039 static void dwarf_decode_macros (struct line_header *, unsigned int,
1040 char *, bfd *, struct dwarf2_cu *);
1042 static int attr_form_is_block (struct attribute *);
1044 static int attr_form_is_section_offset (struct attribute *);
1046 static int attr_form_is_constant (struct attribute *);
1048 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1050 struct dwarf2_cu *cu);
1052 static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev,
1053 struct dwarf2_cu *cu);
1055 static void free_stack_comp_unit (void *);
1057 static hashval_t partial_die_hash (const void *item);
1059 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1061 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1062 (unsigned int offset, struct objfile *objfile);
1064 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1065 (unsigned int offset, struct objfile *objfile);
1067 static void free_one_comp_unit (void *);
1069 static void free_cached_comp_units (void *);
1071 static void age_cached_comp_units (void);
1073 static void free_one_cached_comp_unit (void *);
1075 static struct type *set_die_type (struct die_info *, struct type *,
1076 struct dwarf2_cu *);
1078 static void create_all_comp_units (struct objfile *);
1080 static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *,
1083 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1085 static void dwarf2_add_dependence (struct dwarf2_cu *,
1086 struct dwarf2_per_cu_data *);
1088 static void dwarf2_mark (struct dwarf2_cu *);
1090 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1092 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1094 /* Try to locate the sections we need for DWARF 2 debugging
1095 information and return true if we have enough to do something. */
1098 dwarf2_has_info (struct objfile *objfile)
1100 struct dwarf2_per_objfile *data;
1102 /* Initialize per-objfile state. */
1103 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1104 memset (data, 0, sizeof (*data));
1105 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1106 dwarf2_per_objfile = data;
1108 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1109 return (data->info.asection != NULL && data->abbrev.asection != NULL);
1112 /* When loading sections, we can either look for ".<name>", or for
1113 * ".z<name>", which indicates a compressed section. */
1116 section_is_p (const char *section_name, const char *name)
1118 return (section_name[0] == '.'
1119 && (strcmp (section_name + 1, name) == 0
1120 || (section_name[1] == 'z'
1121 && strcmp (section_name + 2, name) == 0)));
1124 /* This function is mapped across the sections and remembers the
1125 offset and size of each of the debugging sections we are interested
1129 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1131 if (section_is_p (sectp->name, INFO_SECTION))
1133 dwarf2_per_objfile->info.asection = sectp;
1134 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1136 else if (section_is_p (sectp->name, ABBREV_SECTION))
1138 dwarf2_per_objfile->abbrev.asection = sectp;
1139 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1141 else if (section_is_p (sectp->name, LINE_SECTION))
1143 dwarf2_per_objfile->line.asection = sectp;
1144 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1146 else if (section_is_p (sectp->name, PUBNAMES_SECTION))
1148 dwarf2_per_objfile->pubnames.asection = sectp;
1149 dwarf2_per_objfile->pubnames.size = bfd_get_section_size (sectp);
1151 else if (section_is_p (sectp->name, ARANGES_SECTION))
1153 dwarf2_per_objfile->aranges.asection = sectp;
1154 dwarf2_per_objfile->aranges.size = bfd_get_section_size (sectp);
1156 else if (section_is_p (sectp->name, LOC_SECTION))
1158 dwarf2_per_objfile->loc.asection = sectp;
1159 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1161 else if (section_is_p (sectp->name, MACINFO_SECTION))
1163 dwarf2_per_objfile->macinfo.asection = sectp;
1164 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1166 else if (section_is_p (sectp->name, STR_SECTION))
1168 dwarf2_per_objfile->str.asection = sectp;
1169 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1171 else if (section_is_p (sectp->name, FRAME_SECTION))
1173 dwarf2_per_objfile->frame.asection = sectp;
1174 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1176 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1178 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1179 if (aflag & SEC_HAS_CONTENTS)
1181 dwarf2_per_objfile->eh_frame.asection = sectp;
1182 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1185 else if (section_is_p (sectp->name, RANGES_SECTION))
1187 dwarf2_per_objfile->ranges.asection = sectp;
1188 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1191 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1192 && bfd_section_vma (abfd, sectp) == 0)
1193 dwarf2_per_objfile->has_section_at_zero = 1;
1196 /* Decompress a section that was compressed using zlib. Store the
1197 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1200 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1201 gdb_byte **outbuf, bfd_size_type *outsize)
1203 bfd *abfd = objfile->obfd;
1205 error (_("Support for zlib-compressed DWARF data (from '%s') "
1206 "is disabled in this copy of GDB"),
1207 bfd_get_filename (abfd));
1209 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1210 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1211 bfd_size_type uncompressed_size;
1212 gdb_byte *uncompressed_buffer;
1215 int header_size = 12;
1217 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1218 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1219 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1220 bfd_get_filename (abfd));
1222 /* Read the zlib header. In this case, it should be "ZLIB" followed
1223 by the uncompressed section size, 8 bytes in big-endian order. */
1224 if (compressed_size < header_size
1225 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1226 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1227 bfd_get_filename (abfd));
1228 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1229 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1230 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1231 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1232 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1233 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1234 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1235 uncompressed_size += compressed_buffer[11];
1237 /* It is possible the section consists of several compressed
1238 buffers concatenated together, so we uncompress in a loop. */
1242 strm.avail_in = compressed_size - header_size;
1243 strm.next_in = (Bytef*) compressed_buffer + header_size;
1244 strm.avail_out = uncompressed_size;
1245 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1247 rc = inflateInit (&strm);
1248 while (strm.avail_in > 0)
1251 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1252 bfd_get_filename (abfd), rc);
1253 strm.next_out = ((Bytef*) uncompressed_buffer
1254 + (uncompressed_size - strm.avail_out));
1255 rc = inflate (&strm, Z_FINISH);
1256 if (rc != Z_STREAM_END)
1257 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1258 bfd_get_filename (abfd), rc);
1259 rc = inflateReset (&strm);
1261 rc = inflateEnd (&strm);
1263 || strm.avail_out != 0)
1264 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1265 bfd_get_filename (abfd), rc);
1267 xfree (compressed_buffer);
1268 *outbuf = uncompressed_buffer;
1269 *outsize = uncompressed_size;
1273 /* Read the contents of the section SECTP from object file specified by
1274 OBJFILE, store info about the section into INFO.
1275 If the section is compressed, uncompress it before returning. */
1278 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1280 bfd *abfd = objfile->obfd;
1281 asection *sectp = info->asection;
1282 gdb_byte *buf, *retbuf;
1283 unsigned char header[4];
1285 info->buffer = NULL;
1286 info->was_mmapped = 0;
1288 if (info->asection == NULL || info->size == 0)
1291 /* Check if the file has a 4-byte header indicating compression. */
1292 if (info->size > sizeof (header)
1293 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1294 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1296 /* Upon decompression, update the buffer and its size. */
1297 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1299 zlib_decompress_section (objfile, sectp, &info->buffer,
1307 pagesize = getpagesize ();
1309 /* Only try to mmap sections which are large enough: we don't want to
1310 waste space due to fragmentation. Also, only try mmap for sections
1311 without relocations. */
1313 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1315 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1316 size_t map_length = info->size + sectp->filepos - pg_offset;
1317 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1318 MAP_PRIVATE, pg_offset);
1320 if (retbuf != MAP_FAILED)
1322 info->was_mmapped = 1;
1323 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1329 /* If we get here, we are a normal, not-compressed section. */
1331 = obstack_alloc (&objfile->objfile_obstack, info->size);
1333 /* When debugging .o files, we may need to apply relocations; see
1334 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1335 We never compress sections in .o files, so we only need to
1336 try this when the section is not compressed. */
1337 retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
1340 info->buffer = retbuf;
1344 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1345 || bfd_bread (buf, info->size, abfd) != info->size)
1346 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1347 bfd_get_filename (abfd));
1350 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1354 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1355 asection **sectp, gdb_byte **bufp,
1356 bfd_size_type *sizep)
1358 struct dwarf2_per_objfile *data
1359 = objfile_data (objfile, dwarf2_objfile_data_key);
1360 struct dwarf2_section_info *info;
1361 if (section_is_p (section_name, EH_FRAME_SECTION))
1362 info = &data->eh_frame;
1363 else if (section_is_p (section_name, FRAME_SECTION))
1364 info = &data->frame;
1368 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1369 /* We haven't read this section in yet. Do it now. */
1370 dwarf2_read_section (objfile, info);
1372 *sectp = info->asection;
1373 *bufp = info->buffer;
1374 *sizep = info->size;
1377 /* Build a partial symbol table. */
1380 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1382 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
1383 dwarf2_read_section (objfile, &dwarf2_per_objfile->abbrev);
1384 dwarf2_read_section (objfile, &dwarf2_per_objfile->line);
1385 dwarf2_read_section (objfile, &dwarf2_per_objfile->str);
1386 dwarf2_read_section (objfile, &dwarf2_per_objfile->macinfo);
1387 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
1388 dwarf2_read_section (objfile, &dwarf2_per_objfile->loc);
1389 dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame);
1390 dwarf2_read_section (objfile, &dwarf2_per_objfile->frame);
1393 || (objfile->global_psymbols.size == 0
1394 && objfile->static_psymbols.size == 0))
1396 init_psymbol_list (objfile, 1024);
1400 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1402 /* Things are significantly easier if we have .debug_aranges and
1403 .debug_pubnames sections */
1405 dwarf2_build_psymtabs_easy (objfile, mainline);
1409 /* only test this case for now */
1411 /* In this case we have to work a bit harder */
1412 dwarf2_build_psymtabs_hard (objfile, mainline);
1417 /* Build the partial symbol table from the information in the
1418 .debug_pubnames and .debug_aranges sections. */
1421 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1423 bfd *abfd = objfile->obfd;
1424 char *aranges_buffer, *pubnames_buffer;
1425 char *aranges_ptr, *pubnames_ptr;
1426 unsigned int entry_length, version, info_offset, info_size;
1428 pubnames_buffer = dwarf2_read_section (objfile,
1429 dwarf_pubnames_section);
1430 pubnames_ptr = pubnames_buffer;
1431 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames.size)
1433 unsigned int bytes_read;
1435 entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read);
1436 pubnames_ptr += bytes_read;
1437 version = read_1_byte (abfd, pubnames_ptr);
1439 info_offset = read_4_bytes (abfd, pubnames_ptr);
1441 info_size = read_4_bytes (abfd, pubnames_ptr);
1445 aranges_buffer = dwarf2_read_section (objfile,
1446 dwarf_aranges_section);
1451 /* Return TRUE if OFFSET is within CU_HEADER. */
1454 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
1456 unsigned int bottom = cu_header->offset;
1457 unsigned int top = (cu_header->offset
1459 + cu_header->initial_length_size);
1460 return (offset >= bottom && offset < top);
1463 /* Read in the comp unit header information from the debug_info at
1467 read_comp_unit_head (struct comp_unit_head *cu_header,
1468 gdb_byte *info_ptr, bfd *abfd)
1471 unsigned int bytes_read;
1473 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
1474 cu_header->initial_length_size = bytes_read;
1475 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
1476 info_ptr += bytes_read;
1477 cu_header->version = read_2_bytes (abfd, info_ptr);
1479 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1481 info_ptr += bytes_read;
1482 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1484 signed_addr = bfd_get_sign_extend_vma (abfd);
1485 if (signed_addr < 0)
1486 internal_error (__FILE__, __LINE__,
1487 _("read_comp_unit_head: dwarf from non elf file"));
1488 cu_header->signed_addr_p = signed_addr;
1494 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
1497 gdb_byte *beg_of_comp_unit = info_ptr;
1499 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1501 if (header->version != 2 && header->version != 3)
1502 error (_("Dwarf Error: wrong version in compilation unit header "
1503 "(is %d, should be %d) [in module %s]"), header->version,
1504 2, bfd_get_filename (abfd));
1506 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
1507 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1508 "(offset 0x%lx + 6) [in module %s]"),
1509 (long) header->abbrev_offset,
1510 (long) (beg_of_comp_unit - dwarf2_per_objfile->info.buffer),
1511 bfd_get_filename (abfd));
1513 if (beg_of_comp_unit + header->length + header->initial_length_size
1514 > dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
1515 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1516 "(offset 0x%lx + 0) [in module %s]"),
1517 (long) header->length,
1518 (long) (beg_of_comp_unit - dwarf2_per_objfile->info.buffer),
1519 bfd_get_filename (abfd));
1524 /* Allocate a new partial symtab for file named NAME and mark this new
1525 partial symtab as being an include of PST. */
1528 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1529 struct objfile *objfile)
1531 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1533 subpst->section_offsets = pst->section_offsets;
1534 subpst->textlow = 0;
1535 subpst->texthigh = 0;
1537 subpst->dependencies = (struct partial_symtab **)
1538 obstack_alloc (&objfile->objfile_obstack,
1539 sizeof (struct partial_symtab *));
1540 subpst->dependencies[0] = pst;
1541 subpst->number_of_dependencies = 1;
1543 subpst->globals_offset = 0;
1544 subpst->n_global_syms = 0;
1545 subpst->statics_offset = 0;
1546 subpst->n_static_syms = 0;
1547 subpst->symtab = NULL;
1548 subpst->read_symtab = pst->read_symtab;
1551 /* No private part is necessary for include psymtabs. This property
1552 can be used to differentiate between such include psymtabs and
1553 the regular ones. */
1554 subpst->read_symtab_private = NULL;
1557 /* Read the Line Number Program data and extract the list of files
1558 included by the source file represented by PST. Build an include
1559 partial symtab for each of these included files.
1561 This procedure assumes that there *is* a Line Number Program in
1562 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1563 before calling this procedure. */
1566 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1567 struct partial_die_info *pdi,
1568 struct partial_symtab *pst)
1570 struct objfile *objfile = cu->objfile;
1571 bfd *abfd = objfile->obfd;
1572 struct line_header *lh;
1574 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1576 return; /* No linetable, so no includes. */
1578 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1580 free_line_header (lh);
1584 /* Build the partial symbol table by doing a quick pass through the
1585 .debug_info and .debug_abbrev sections. */
1588 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1590 /* Instead of reading this into a big buffer, we should probably use
1591 mmap() on architectures that support it. (FIXME) */
1592 bfd *abfd = objfile->obfd;
1594 gdb_byte *beg_of_comp_unit;
1595 struct partial_die_info comp_unit_die;
1596 struct partial_symtab *pst;
1597 struct cleanup *back_to;
1600 info_ptr = dwarf2_per_objfile->info.buffer;
1602 /* Any cached compilation units will be linked by the per-objfile
1603 read_in_chain. Make sure to free them when we're done. */
1604 back_to = make_cleanup (free_cached_comp_units, NULL);
1606 create_all_comp_units (objfile);
1608 objfile->psymtabs_addrmap = addrmap_create_mutable
1609 (&objfile->objfile_obstack);
1611 /* Since the objects we're extracting from .debug_info vary in
1612 length, only the individual functions to extract them (like
1613 read_comp_unit_head and load_partial_die) can really know whether
1614 the buffer is large enough to hold another complete object.
1616 At the moment, they don't actually check that. If .debug_info
1617 holds just one extra byte after the last compilation unit's dies,
1618 then read_comp_unit_head will happily read off the end of the
1619 buffer. read_partial_die is similarly casual. Those functions
1622 For this loop condition, simply checking whether there's any data
1623 left at all should be sufficient. */
1624 while (info_ptr < (dwarf2_per_objfile->info.buffer
1625 + dwarf2_per_objfile->info.size))
1627 struct cleanup *back_to_inner;
1628 struct dwarf2_cu cu;
1629 struct abbrev_info *abbrev;
1630 unsigned int bytes_read;
1631 struct dwarf2_per_cu_data *this_cu;
1633 beg_of_comp_unit = info_ptr;
1635 memset (&cu, 0, sizeof (cu));
1637 obstack_init (&cu.comp_unit_obstack);
1639 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1641 cu.objfile = objfile;
1642 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1644 /* Complete the cu_header */
1645 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info.buffer;
1646 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1648 cu.list_in_scope = &file_symbols;
1650 /* Read the abbrevs for this compilation unit into a table */
1651 dwarf2_read_abbrevs (abfd, &cu);
1652 make_cleanup (dwarf2_free_abbrev_table, &cu);
1654 this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile);
1656 /* Read the compilation unit die */
1657 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1658 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1659 abfd, info_ptr, &cu);
1661 if (comp_unit_die.tag == DW_TAG_partial_unit)
1663 info_ptr = (beg_of_comp_unit + cu.header.length
1664 + cu.header.initial_length_size);
1665 do_cleanups (back_to_inner);
1669 /* Set the language we're debugging */
1670 set_cu_language (comp_unit_die.language, &cu);
1672 /* Allocate a new partial symbol table structure */
1673 pst = start_psymtab_common (objfile, objfile->section_offsets,
1674 comp_unit_die.name ? comp_unit_die.name : "",
1675 /* TEXTLOW and TEXTHIGH are set below. */
1677 objfile->global_psymbols.next,
1678 objfile->static_psymbols.next);
1680 if (comp_unit_die.dirname)
1681 pst->dirname = obsavestring (comp_unit_die.dirname,
1682 strlen (comp_unit_die.dirname),
1683 &objfile->objfile_obstack);
1685 pst->read_symtab_private = (char *) this_cu;
1687 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1689 /* Store the function that reads in the rest of the symbol table */
1690 pst->read_symtab = dwarf2_psymtab_to_symtab;
1692 /* If this compilation unit was already read in, free the
1693 cached copy in order to read it in again. This is
1694 necessary because we skipped some symbols when we first
1695 read in the compilation unit (see load_partial_dies).
1696 This problem could be avoided, but the benefit is
1698 if (this_cu->cu != NULL)
1699 free_one_cached_comp_unit (this_cu->cu);
1701 cu.per_cu = this_cu;
1703 /* Note that this is a pointer to our stack frame, being
1704 added to a global data structure. It will be cleaned up
1705 in free_stack_comp_unit when we finish with this
1706 compilation unit. */
1709 this_cu->psymtab = pst;
1711 /* Possibly set the default values of LOWPC and HIGHPC from
1713 if (cu.has_ranges_offset)
1715 if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc,
1716 &comp_unit_die.highpc, &cu, pst))
1717 comp_unit_die.has_pc_info = 1;
1719 else if (comp_unit_die.has_pc_info
1720 && comp_unit_die.lowpc < comp_unit_die.highpc)
1721 /* Store the contiguous range if it is not empty; it can be empty for
1722 CUs with no code. */
1723 addrmap_set_empty (objfile->psymtabs_addrmap,
1724 comp_unit_die.lowpc + baseaddr,
1725 comp_unit_die.highpc + baseaddr - 1, pst);
1727 /* Check if comp unit has_children.
1728 If so, read the rest of the partial symbols from this comp unit.
1729 If not, there's no more debug_info for this comp unit. */
1730 if (comp_unit_die.has_children)
1732 struct partial_die_info *first_die;
1733 CORE_ADDR lowpc, highpc;
1735 lowpc = ((CORE_ADDR) -1);
1736 highpc = ((CORE_ADDR) 0);
1738 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1740 scan_partial_symbols (first_die, &lowpc, &highpc,
1741 ! comp_unit_die.has_pc_info, &cu);
1743 /* If we didn't find a lowpc, set it to highpc to avoid
1744 complaints from `maint check'. */
1745 if (lowpc == ((CORE_ADDR) -1))
1748 /* If the compilation unit didn't have an explicit address range,
1749 then use the information extracted from its child dies. */
1750 if (! comp_unit_die.has_pc_info)
1752 comp_unit_die.lowpc = lowpc;
1753 comp_unit_die.highpc = highpc;
1756 pst->textlow = comp_unit_die.lowpc + baseaddr;
1757 pst->texthigh = comp_unit_die.highpc + baseaddr;
1759 pst->n_global_syms = objfile->global_psymbols.next -
1760 (objfile->global_psymbols.list + pst->globals_offset);
1761 pst->n_static_syms = objfile->static_psymbols.next -
1762 (objfile->static_psymbols.list + pst->statics_offset);
1763 sort_pst_symbols (pst);
1765 /* If there is already a psymtab or symtab for a file of this
1766 name, remove it. (If there is a symtab, more drastic things
1767 also happen.) This happens in VxWorks. */
1768 free_named_symtabs (pst->filename);
1770 info_ptr = beg_of_comp_unit + cu.header.length
1771 + cu.header.initial_length_size;
1773 if (comp_unit_die.has_stmt_list)
1775 /* Get the list of files included in the current compilation unit,
1776 and build a psymtab for each of them. */
1777 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1780 do_cleanups (back_to_inner);
1783 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
1784 &objfile->objfile_obstack);
1786 do_cleanups (back_to);
1789 /* Load the DIEs for a secondary CU into memory. */
1792 load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile)
1794 bfd *abfd = objfile->obfd;
1795 gdb_byte *info_ptr, *beg_of_comp_unit;
1796 struct partial_die_info comp_unit_die;
1797 struct dwarf2_cu *cu;
1798 struct abbrev_info *abbrev;
1799 unsigned int bytes_read;
1800 struct cleanup *back_to;
1802 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
1803 beg_of_comp_unit = info_ptr;
1805 cu = xmalloc (sizeof (struct dwarf2_cu));
1806 memset (cu, 0, sizeof (struct dwarf2_cu));
1808 obstack_init (&cu->comp_unit_obstack);
1810 cu->objfile = objfile;
1811 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd);
1813 /* Complete the cu_header. */
1814 cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info.buffer;
1815 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
1817 /* Read the abbrevs for this compilation unit into a table. */
1818 dwarf2_read_abbrevs (abfd, cu);
1819 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
1821 /* Read the compilation unit die. */
1822 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1823 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1824 abfd, info_ptr, cu);
1826 /* Set the language we're debugging. */
1827 set_cu_language (comp_unit_die.language, cu);
1829 /* Link this compilation unit into the compilation unit tree. */
1831 cu->per_cu = this_cu;
1832 cu->type_hash = cu->per_cu->type_hash;
1834 /* Check if comp unit has_children.
1835 If so, read the rest of the partial symbols from this comp unit.
1836 If not, there's no more debug_info for this comp unit. */
1837 if (comp_unit_die.has_children)
1838 load_partial_dies (abfd, info_ptr, 0, cu);
1840 do_cleanups (back_to);
1843 /* Create a list of all compilation units in OBJFILE. We do this only
1844 if an inter-comp-unit reference is found; presumably if there is one,
1845 there will be many, and one will occur early in the .debug_info section.
1846 So there's no point in building this list incrementally. */
1849 create_all_comp_units (struct objfile *objfile)
1853 struct dwarf2_per_cu_data **all_comp_units;
1854 gdb_byte *info_ptr = dwarf2_per_objfile->info.buffer;
1858 all_comp_units = xmalloc (n_allocated
1859 * sizeof (struct dwarf2_per_cu_data *));
1861 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
1863 unsigned int length, initial_length_size;
1864 gdb_byte *beg_of_comp_unit;
1865 struct dwarf2_per_cu_data *this_cu;
1866 unsigned int offset;
1868 offset = info_ptr - dwarf2_per_objfile->info.buffer;
1870 /* Read just enough information to find out where the next
1871 compilation unit is. */
1872 length = read_initial_length (objfile->obfd, info_ptr,
1873 &initial_length_size);
1875 /* Save the compilation unit for later lookup. */
1876 this_cu = obstack_alloc (&objfile->objfile_obstack,
1877 sizeof (struct dwarf2_per_cu_data));
1878 memset (this_cu, 0, sizeof (*this_cu));
1879 this_cu->offset = offset;
1880 this_cu->length = length + initial_length_size;
1882 if (n_comp_units == n_allocated)
1885 all_comp_units = xrealloc (all_comp_units,
1887 * sizeof (struct dwarf2_per_cu_data *));
1889 all_comp_units[n_comp_units++] = this_cu;
1891 info_ptr = info_ptr + this_cu->length;
1894 dwarf2_per_objfile->all_comp_units
1895 = obstack_alloc (&objfile->objfile_obstack,
1896 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1897 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
1898 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1899 xfree (all_comp_units);
1900 dwarf2_per_objfile->n_comp_units = n_comp_units;
1903 /* Process all loaded DIEs for compilation unit CU, starting at
1904 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1905 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1906 DW_AT_ranges). If NEED_PC is set, then this function will set
1907 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1908 and record the covered ranges in the addrmap. */
1911 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1912 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
1914 struct objfile *objfile = cu->objfile;
1915 bfd *abfd = objfile->obfd;
1916 struct partial_die_info *pdi;
1918 /* Now, march along the PDI's, descending into ones which have
1919 interesting children but skipping the children of the other ones,
1920 until we reach the end of the compilation unit. */
1926 fixup_partial_die (pdi, cu);
1928 /* Anonymous namespaces have no name but have interesting
1929 children, so we need to look at them. Ditto for anonymous
1932 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1933 || pdi->tag == DW_TAG_enumeration_type)
1937 case DW_TAG_subprogram:
1938 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
1940 case DW_TAG_variable:
1941 case DW_TAG_typedef:
1942 case DW_TAG_union_type:
1943 if (!pdi->is_declaration)
1945 add_partial_symbol (pdi, cu);
1948 case DW_TAG_class_type:
1949 case DW_TAG_interface_type:
1950 case DW_TAG_structure_type:
1951 if (!pdi->is_declaration)
1953 add_partial_symbol (pdi, cu);
1956 case DW_TAG_enumeration_type:
1957 if (!pdi->is_declaration)
1958 add_partial_enumeration (pdi, cu);
1960 case DW_TAG_base_type:
1961 case DW_TAG_subrange_type:
1962 /* File scope base type definitions are added to the partial
1964 add_partial_symbol (pdi, cu);
1966 case DW_TAG_namespace:
1967 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
1970 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
1977 /* If the die has a sibling, skip to the sibling. */
1979 pdi = pdi->die_sibling;
1983 /* Functions used to compute the fully scoped name of a partial DIE.
1985 Normally, this is simple. For C++, the parent DIE's fully scoped
1986 name is concatenated with "::" and the partial DIE's name. For
1987 Java, the same thing occurs except that "." is used instead of "::".
1988 Enumerators are an exception; they use the scope of their parent
1989 enumeration type, i.e. the name of the enumeration type is not
1990 prepended to the enumerator.
1992 There are two complexities. One is DW_AT_specification; in this
1993 case "parent" means the parent of the target of the specification,
1994 instead of the direct parent of the DIE. The other is compilers
1995 which do not emit DW_TAG_namespace; in this case we try to guess
1996 the fully qualified name of structure types from their members'
1997 linkage names. This must be done using the DIE's children rather
1998 than the children of any DW_AT_specification target. We only need
1999 to do this for structures at the top level, i.e. if the target of
2000 any DW_AT_specification (if any; otherwise the DIE itself) does not
2003 /* Compute the scope prefix associated with PDI's parent, in
2004 compilation unit CU. The result will be allocated on CU's
2005 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2006 field. NULL is returned if no prefix is necessary. */
2008 partial_die_parent_scope (struct partial_die_info *pdi,
2009 struct dwarf2_cu *cu)
2011 char *grandparent_scope;
2012 struct partial_die_info *parent, *real_pdi;
2014 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2015 then this means the parent of the specification DIE. */
2018 while (real_pdi->has_specification)
2019 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2021 parent = real_pdi->die_parent;
2025 if (parent->scope_set)
2026 return parent->scope;
2028 fixup_partial_die (parent, cu);
2030 grandparent_scope = partial_die_parent_scope (parent, cu);
2032 if (parent->tag == DW_TAG_namespace
2033 || parent->tag == DW_TAG_structure_type
2034 || parent->tag == DW_TAG_class_type
2035 || parent->tag == DW_TAG_interface_type
2036 || parent->tag == DW_TAG_union_type)
2038 if (grandparent_scope == NULL)
2039 parent->scope = parent->name;
2041 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
2044 else if (parent->tag == DW_TAG_enumeration_type)
2045 /* Enumerators should not get the name of the enumeration as a prefix. */
2046 parent->scope = grandparent_scope;
2049 /* FIXME drow/2004-04-01: What should we be doing with
2050 function-local names? For partial symbols, we should probably be
2052 complaint (&symfile_complaints,
2053 _("unhandled containing DIE tag %d for DIE at %d"),
2054 parent->tag, pdi->offset);
2055 parent->scope = grandparent_scope;
2058 parent->scope_set = 1;
2059 return parent->scope;
2062 /* Return the fully scoped name associated with PDI, from compilation unit
2063 CU. The result will be allocated with malloc. */
2065 partial_die_full_name (struct partial_die_info *pdi,
2066 struct dwarf2_cu *cu)
2070 parent_scope = partial_die_parent_scope (pdi, cu);
2071 if (parent_scope == NULL)
2074 return typename_concat (NULL, parent_scope, pdi->name, cu);
2078 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
2080 struct objfile *objfile = cu->objfile;
2082 char *actual_name = NULL;
2083 const char *my_prefix;
2084 const struct partial_symbol *psym = NULL;
2086 int built_actual_name = 0;
2088 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2090 if (pdi_needs_namespace (pdi->tag))
2092 actual_name = partial_die_full_name (pdi, cu);
2094 built_actual_name = 1;
2097 if (actual_name == NULL)
2098 actual_name = pdi->name;
2102 case DW_TAG_subprogram:
2103 if (pdi->is_external || cu->language == language_ada)
2105 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2106 of the global scope. But in Ada, we want to be able to access
2107 nested procedures globally. So all Ada subprograms are stored
2108 in the global scope. */
2109 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2110 mst_text, objfile); */
2111 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2112 VAR_DOMAIN, LOC_BLOCK,
2113 &objfile->global_psymbols,
2114 0, pdi->lowpc + baseaddr,
2115 cu->language, objfile);
2119 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2120 mst_file_text, objfile); */
2121 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2122 VAR_DOMAIN, LOC_BLOCK,
2123 &objfile->static_psymbols,
2124 0, pdi->lowpc + baseaddr,
2125 cu->language, objfile);
2128 case DW_TAG_variable:
2129 if (pdi->is_external)
2132 Don't enter into the minimal symbol tables as there is
2133 a minimal symbol table entry from the ELF symbols already.
2134 Enter into partial symbol table if it has a location
2135 descriptor or a type.
2136 If the location descriptor is missing, new_symbol will create
2137 a LOC_UNRESOLVED symbol, the address of the variable will then
2138 be determined from the minimal symbol table whenever the variable
2140 The address for the partial symbol table entry is not
2141 used by GDB, but it comes in handy for debugging partial symbol
2145 addr = decode_locdesc (pdi->locdesc, cu);
2146 if (pdi->locdesc || pdi->has_type)
2147 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2148 VAR_DOMAIN, LOC_STATIC,
2149 &objfile->global_psymbols,
2151 cu->language, objfile);
2155 /* Static Variable. Skip symbols without location descriptors. */
2156 if (pdi->locdesc == NULL)
2158 if (built_actual_name)
2159 xfree (actual_name);
2162 addr = decode_locdesc (pdi->locdesc, cu);
2163 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2164 mst_file_data, objfile); */
2165 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2166 VAR_DOMAIN, LOC_STATIC,
2167 &objfile->static_psymbols,
2169 cu->language, objfile);
2172 case DW_TAG_typedef:
2173 case DW_TAG_base_type:
2174 case DW_TAG_subrange_type:
2175 add_psymbol_to_list (actual_name, strlen (actual_name),
2176 VAR_DOMAIN, LOC_TYPEDEF,
2177 &objfile->static_psymbols,
2178 0, (CORE_ADDR) 0, cu->language, objfile);
2180 case DW_TAG_namespace:
2181 add_psymbol_to_list (actual_name, strlen (actual_name),
2182 VAR_DOMAIN, LOC_TYPEDEF,
2183 &objfile->global_psymbols,
2184 0, (CORE_ADDR) 0, cu->language, objfile);
2186 case DW_TAG_class_type:
2187 case DW_TAG_interface_type:
2188 case DW_TAG_structure_type:
2189 case DW_TAG_union_type:
2190 case DW_TAG_enumeration_type:
2191 /* Skip external references. The DWARF standard says in the section
2192 about "Structure, Union, and Class Type Entries": "An incomplete
2193 structure, union or class type is represented by a structure,
2194 union or class entry that does not have a byte size attribute
2195 and that has a DW_AT_declaration attribute." */
2196 if (!pdi->has_byte_size && pdi->is_declaration)
2198 if (built_actual_name)
2199 xfree (actual_name);
2203 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2204 static vs. global. */
2205 add_psymbol_to_list (actual_name, strlen (actual_name),
2206 STRUCT_DOMAIN, LOC_TYPEDEF,
2207 (cu->language == language_cplus
2208 || cu->language == language_java)
2209 ? &objfile->global_psymbols
2210 : &objfile->static_psymbols,
2211 0, (CORE_ADDR) 0, cu->language, objfile);
2214 case DW_TAG_enumerator:
2215 add_psymbol_to_list (actual_name, strlen (actual_name),
2216 VAR_DOMAIN, LOC_CONST,
2217 (cu->language == language_cplus
2218 || cu->language == language_java)
2219 ? &objfile->global_psymbols
2220 : &objfile->static_psymbols,
2221 0, (CORE_ADDR) 0, cu->language, objfile);
2227 /* Check to see if we should scan the name for possible namespace
2228 info. Only do this if this is C++, if we don't have namespace
2229 debugging info in the file, if the psym is of an appropriate type
2230 (otherwise we'll have psym == NULL), and if we actually had a
2231 mangled name to begin with. */
2233 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2234 cases which do not set PSYM above? */
2236 if (cu->language == language_cplus
2237 && cu->has_namespace_info == 0
2239 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
2240 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
2243 if (built_actual_name)
2244 xfree (actual_name);
2247 /* Determine whether a die of type TAG living in a C++ class or
2248 namespace needs to have the name of the scope prepended to the
2249 name listed in the die. */
2252 pdi_needs_namespace (enum dwarf_tag tag)
2256 case DW_TAG_namespace:
2257 case DW_TAG_typedef:
2258 case DW_TAG_class_type:
2259 case DW_TAG_interface_type:
2260 case DW_TAG_structure_type:
2261 case DW_TAG_union_type:
2262 case DW_TAG_enumeration_type:
2263 case DW_TAG_enumerator:
2270 /* Read a partial die corresponding to a namespace; also, add a symbol
2271 corresponding to that namespace to the symbol table. NAMESPACE is
2272 the name of the enclosing namespace. */
2275 add_partial_namespace (struct partial_die_info *pdi,
2276 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2277 int need_pc, struct dwarf2_cu *cu)
2279 struct objfile *objfile = cu->objfile;
2281 /* Add a symbol for the namespace. */
2283 add_partial_symbol (pdi, cu);
2285 /* Now scan partial symbols in that namespace. */
2287 if (pdi->has_children)
2288 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2291 /* Read a partial die corresponding to a Fortran module. */
2294 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
2295 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2297 /* Now scan partial symbols in that module.
2299 FIXME: Support the separate Fortran module namespaces. */
2301 if (pdi->has_children)
2302 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2305 /* Read a partial die corresponding to a subprogram and create a partial
2306 symbol for that subprogram. When the CU language allows it, this
2307 routine also defines a partial symbol for each nested subprogram
2308 that this subprogram contains.
2310 DIE my also be a lexical block, in which case we simply search
2311 recursively for suprograms defined inside that lexical block.
2312 Again, this is only performed when the CU language allows this
2313 type of definitions. */
2316 add_partial_subprogram (struct partial_die_info *pdi,
2317 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2318 int need_pc, struct dwarf2_cu *cu)
2320 if (pdi->tag == DW_TAG_subprogram)
2322 if (pdi->has_pc_info)
2324 if (pdi->lowpc < *lowpc)
2325 *lowpc = pdi->lowpc;
2326 if (pdi->highpc > *highpc)
2327 *highpc = pdi->highpc;
2331 struct objfile *objfile = cu->objfile;
2333 baseaddr = ANOFFSET (objfile->section_offsets,
2334 SECT_OFF_TEXT (objfile));
2335 addrmap_set_empty (objfile->psymtabs_addrmap,
2336 pdi->lowpc, pdi->highpc - 1,
2337 cu->per_cu->psymtab);
2339 if (!pdi->is_declaration)
2340 add_partial_symbol (pdi, cu);
2344 if (! pdi->has_children)
2347 if (cu->language == language_ada)
2349 pdi = pdi->die_child;
2352 fixup_partial_die (pdi, cu);
2353 if (pdi->tag == DW_TAG_subprogram
2354 || pdi->tag == DW_TAG_lexical_block)
2355 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2356 pdi = pdi->die_sibling;
2361 /* See if we can figure out if the class lives in a namespace. We do
2362 this by looking for a member function; its demangled name will
2363 contain namespace info, if there is any. */
2366 guess_structure_name (struct partial_die_info *struct_pdi,
2367 struct dwarf2_cu *cu)
2369 if ((cu->language == language_cplus
2370 || cu->language == language_java)
2371 && cu->has_namespace_info == 0
2372 && struct_pdi->has_children)
2374 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2375 what template types look like, because the demangler
2376 frequently doesn't give the same name as the debug info. We
2377 could fix this by only using the demangled name to get the
2378 prefix (but see comment in read_structure_type). */
2380 struct partial_die_info *child_pdi = struct_pdi->die_child;
2381 struct partial_die_info *real_pdi;
2383 /* If this DIE (this DIE's specification, if any) has a parent, then
2384 we should not do this. We'll prepend the parent's fully qualified
2385 name when we create the partial symbol. */
2387 real_pdi = struct_pdi;
2388 while (real_pdi->has_specification)
2389 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2391 if (real_pdi->die_parent != NULL)
2394 while (child_pdi != NULL)
2396 if (child_pdi->tag == DW_TAG_subprogram)
2398 char *actual_class_name
2399 = language_class_name_from_physname (cu->language_defn,
2401 if (actual_class_name != NULL)
2404 = obsavestring (actual_class_name,
2405 strlen (actual_class_name),
2406 &cu->comp_unit_obstack);
2407 xfree (actual_class_name);
2412 child_pdi = child_pdi->die_sibling;
2417 /* Read a partial die corresponding to an enumeration type. */
2420 add_partial_enumeration (struct partial_die_info *enum_pdi,
2421 struct dwarf2_cu *cu)
2423 struct objfile *objfile = cu->objfile;
2424 bfd *abfd = objfile->obfd;
2425 struct partial_die_info *pdi;
2427 if (enum_pdi->name != NULL)
2428 add_partial_symbol (enum_pdi, cu);
2430 pdi = enum_pdi->die_child;
2433 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2434 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2436 add_partial_symbol (pdi, cu);
2437 pdi = pdi->die_sibling;
2441 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2442 Return the corresponding abbrev, or NULL if the number is zero (indicating
2443 an empty DIE). In either case *BYTES_READ will be set to the length of
2444 the initial number. */
2446 static struct abbrev_info *
2447 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
2448 struct dwarf2_cu *cu)
2450 bfd *abfd = cu->objfile->obfd;
2451 unsigned int abbrev_number;
2452 struct abbrev_info *abbrev;
2454 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2456 if (abbrev_number == 0)
2459 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2462 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2463 bfd_get_filename (abfd));
2469 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2470 pointer to the end of a series of DIEs, terminated by an empty
2471 DIE. Any children of the skipped DIEs will also be skipped. */
2474 skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu)
2476 struct abbrev_info *abbrev;
2477 unsigned int bytes_read;
2481 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2483 return info_ptr + bytes_read;
2485 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
2489 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2490 should point just after the initial uleb128 of a DIE, and the
2491 abbrev corresponding to that skipped uleb128 should be passed in
2492 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2496 skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev,
2497 struct dwarf2_cu *cu)
2499 unsigned int bytes_read;
2500 struct attribute attr;
2501 bfd *abfd = cu->objfile->obfd;
2502 unsigned int form, i;
2504 for (i = 0; i < abbrev->num_attrs; i++)
2506 /* The only abbrev we care about is DW_AT_sibling. */
2507 if (abbrev->attrs[i].name == DW_AT_sibling)
2509 read_attribute (&attr, &abbrev->attrs[i],
2510 abfd, info_ptr, cu);
2511 if (attr.form == DW_FORM_ref_addr)
2512 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2514 return dwarf2_per_objfile->info.buffer
2515 + dwarf2_get_ref_die_offset (&attr);
2518 /* If it isn't DW_AT_sibling, skip this attribute. */
2519 form = abbrev->attrs[i].form;
2524 case DW_FORM_ref_addr:
2525 info_ptr += cu->header.addr_size;
2544 case DW_FORM_string:
2545 read_string (abfd, info_ptr, &bytes_read);
2546 info_ptr += bytes_read;
2549 info_ptr += cu->header.offset_size;
2552 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2553 info_ptr += bytes_read;
2555 case DW_FORM_block1:
2556 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2558 case DW_FORM_block2:
2559 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2561 case DW_FORM_block4:
2562 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2566 case DW_FORM_ref_udata:
2567 info_ptr = skip_leb128 (abfd, info_ptr);
2569 case DW_FORM_indirect:
2570 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2571 info_ptr += bytes_read;
2572 /* We need to continue parsing from here, so just go back to
2574 goto skip_attribute;
2577 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2578 dwarf_form_name (form),
2579 bfd_get_filename (abfd));
2583 if (abbrev->has_children)
2584 return skip_children (info_ptr, cu);
2589 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2590 the next DIE after ORIG_PDI. */
2593 locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr,
2594 bfd *abfd, struct dwarf2_cu *cu)
2596 /* Do we know the sibling already? */
2598 if (orig_pdi->sibling)
2599 return orig_pdi->sibling;
2601 /* Are there any children to deal with? */
2603 if (!orig_pdi->has_children)
2606 /* Skip the children the long way. */
2608 return skip_children (info_ptr, cu);
2611 /* Expand this partial symbol table into a full symbol table. */
2614 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2616 /* FIXME: This is barely more than a stub. */
2621 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2627 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2628 gdb_flush (gdb_stdout);
2631 /* Restore our global data. */
2632 dwarf2_per_objfile = objfile_data (pst->objfile,
2633 dwarf2_objfile_data_key);
2635 /* If this psymtab is constructed from a debug-only objfile, the
2636 has_section_at_zero flag will not necessarily be correct. We
2637 can get the correct value for this flag by looking at the data
2638 associated with the (presumably stripped) associated objfile. */
2639 if (pst->objfile->separate_debug_objfile_backlink)
2641 struct dwarf2_per_objfile *dpo_backlink
2642 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
2643 dwarf2_objfile_data_key);
2644 dwarf2_per_objfile->has_section_at_zero
2645 = dpo_backlink->has_section_at_zero;
2648 psymtab_to_symtab_1 (pst);
2650 /* Finish up the debug error message. */
2652 printf_filtered (_("done.\n"));
2657 /* Add PER_CU to the queue. */
2660 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2662 struct dwarf2_queue_item *item;
2665 item = xmalloc (sizeof (*item));
2666 item->per_cu = per_cu;
2669 if (dwarf2_queue == NULL)
2670 dwarf2_queue = item;
2672 dwarf2_queue_tail->next = item;
2674 dwarf2_queue_tail = item;
2676 /* Either PER_CU is the CU we want to process, or we're following a reference
2677 pointing into PER_CU. Either way, we need its DIEs now. */
2678 load_full_comp_unit (item->per_cu, objfile);
2679 item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
2680 dwarf2_per_objfile->read_in_chain = item->per_cu;
2683 /* Process the queue. */
2686 process_queue (struct objfile *objfile)
2688 struct dwarf2_queue_item *item, *next_item;
2690 /* The queue starts out with one item, but following a DIE reference
2691 may load a new CU, adding it to the end of the queue. */
2692 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
2694 if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
2695 process_full_comp_unit (item->per_cu);
2697 item->per_cu->queued = 0;
2698 next_item = item->next;
2702 dwarf2_queue_tail = NULL;
2705 /* Free all allocated queue entries. This function only releases anything if
2706 an error was thrown; if the queue was processed then it would have been
2707 freed as we went along. */
2710 dwarf2_release_queue (void *dummy)
2712 struct dwarf2_queue_item *item, *last;
2714 item = dwarf2_queue;
2717 /* Anything still marked queued is likely to be in an
2718 inconsistent state, so discard it. */
2719 if (item->per_cu->queued)
2721 if (item->per_cu->cu != NULL)
2722 free_one_cached_comp_unit (item->per_cu->cu);
2723 item->per_cu->queued = 0;
2731 dwarf2_queue = dwarf2_queue_tail = NULL;
2734 /* Read in full symbols for PST, and anything it depends on. */
2737 psymtab_to_symtab_1 (struct partial_symtab *pst)
2739 struct dwarf2_per_cu_data *per_cu;
2740 struct cleanup *back_to;
2743 for (i = 0; i < pst->number_of_dependencies; i++)
2744 if (!pst->dependencies[i]->readin)
2746 /* Inform about additional files that need to be read in. */
2749 /* FIXME: i18n: Need to make this a single string. */
2750 fputs_filtered (" ", gdb_stdout);
2752 fputs_filtered ("and ", gdb_stdout);
2754 printf_filtered ("%s...", pst->dependencies[i]->filename);
2755 wrap_here (""); /* Flush output */
2756 gdb_flush (gdb_stdout);
2758 psymtab_to_symtab_1 (pst->dependencies[i]);
2761 per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private;
2765 /* It's an include file, no symbols to read for it.
2766 Everything is in the parent symtab. */
2771 back_to = make_cleanup (dwarf2_release_queue, NULL);
2773 queue_comp_unit (per_cu, pst->objfile);
2775 process_queue (pst->objfile);
2777 /* Age the cache, releasing compilation units that have not
2778 been used recently. */
2779 age_cached_comp_units ();
2781 do_cleanups (back_to);
2784 /* Load the DIEs associated with PST and PER_CU into memory. */
2786 static struct dwarf2_cu *
2787 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2789 bfd *abfd = objfile->obfd;
2790 struct dwarf2_cu *cu;
2791 unsigned int offset;
2793 struct cleanup *back_to, *free_cu_cleanup;
2794 struct attribute *attr;
2797 /* Set local variables from the partial symbol table info. */
2798 offset = per_cu->offset;
2800 info_ptr = dwarf2_per_objfile->info.buffer + offset;
2802 cu = xmalloc (sizeof (struct dwarf2_cu));
2803 memset (cu, 0, sizeof (struct dwarf2_cu));
2805 /* If an error occurs while loading, release our storage. */
2806 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
2808 cu->objfile = objfile;
2810 /* read in the comp_unit header */
2811 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
2813 /* Read the abbrevs for this compilation unit */
2814 dwarf2_read_abbrevs (abfd, cu);
2815 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2817 cu->header.offset = offset;
2819 cu->per_cu = per_cu;
2821 cu->type_hash = per_cu->type_hash;
2823 /* We use this obstack for block values in dwarf_alloc_block. */
2824 obstack_init (&cu->comp_unit_obstack);
2826 cu->dies = read_comp_unit (info_ptr, abfd, cu);
2828 /* We try not to read any attributes in this function, because not
2829 all objfiles needed for references have been loaded yet, and symbol
2830 table processing isn't initialized. But we have to set the CU language,
2831 or we won't be able to build types correctly. */
2832 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
2834 set_cu_language (DW_UNSND (attr), cu);
2836 set_cu_language (language_minimal, cu);
2838 do_cleanups (back_to);
2840 /* We've successfully allocated this compilation unit. Let our caller
2841 clean it up when finished with it. */
2842 discard_cleanups (free_cu_cleanup);
2847 /* Generate full symbol information for PST and CU, whose DIEs have
2848 already been loaded into memory. */
2851 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
2853 struct partial_symtab *pst = per_cu->psymtab;
2854 struct dwarf2_cu *cu = per_cu->cu;
2855 struct objfile *objfile = pst->objfile;
2856 bfd *abfd = objfile->obfd;
2857 CORE_ADDR lowpc, highpc;
2858 struct symtab *symtab;
2859 struct cleanup *back_to;
2860 struct attribute *attr;
2863 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2866 back_to = make_cleanup (really_free_pendings, NULL);
2868 cu->list_in_scope = &file_symbols;
2870 /* Find the base address of the compilation unit for range lists and
2871 location lists. It will normally be specified by DW_AT_low_pc.
2872 In DWARF-3 draft 4, the base address could be overridden by
2873 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2874 compilation units with discontinuous ranges. */
2877 cu->base_address = 0;
2879 attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu);
2882 cu->base_address = DW_ADDR (attr);
2887 attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu);
2890 cu->base_address = DW_ADDR (attr);
2895 /* Do line number decoding in read_file_scope () */
2896 process_die (cu->dies, cu);
2898 /* Some compilers don't define a DW_AT_high_pc attribute for the
2899 compilation unit. If the DW_AT_high_pc is missing, synthesize
2900 it, by scanning the DIE's below the compilation unit. */
2901 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
2903 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2905 /* Set symtab language to language from DW_AT_language.
2906 If the compilation is from a C file generated by language preprocessors,
2907 do not set the language if it was already deduced by start_subfile. */
2909 && !(cu->language == language_c && symtab->language != language_c))
2911 symtab->language = cu->language;
2913 pst->symtab = symtab;
2916 do_cleanups (back_to);
2919 /* Process a die and its children. */
2922 process_die (struct die_info *die, struct dwarf2_cu *cu)
2926 case DW_TAG_padding:
2928 case DW_TAG_compile_unit:
2929 read_file_scope (die, cu);
2931 case DW_TAG_subprogram:
2932 read_func_scope (die, cu);
2934 case DW_TAG_inlined_subroutine:
2935 /* FIXME: These are ignored for now.
2936 They could be used to set breakpoints on all inlined instances
2937 of a function and make GDB `next' properly over inlined functions. */
2939 case DW_TAG_lexical_block:
2940 case DW_TAG_try_block:
2941 case DW_TAG_catch_block:
2942 read_lexical_block_scope (die, cu);
2944 case DW_TAG_class_type:
2945 case DW_TAG_interface_type:
2946 case DW_TAG_structure_type:
2947 case DW_TAG_union_type:
2948 process_structure_scope (die, cu);
2950 case DW_TAG_enumeration_type:
2951 process_enumeration_scope (die, cu);
2954 /* These dies have a type, but processing them does not create
2955 a symbol or recurse to process the children. Therefore we can
2956 read them on-demand through read_type_die. */
2957 case DW_TAG_subroutine_type:
2958 case DW_TAG_set_type:
2959 case DW_TAG_array_type:
2960 case DW_TAG_pointer_type:
2961 case DW_TAG_ptr_to_member_type:
2962 case DW_TAG_reference_type:
2963 case DW_TAG_string_type:
2966 case DW_TAG_base_type:
2967 case DW_TAG_subrange_type:
2968 case DW_TAG_typedef:
2969 /* Add a typedef symbol for the type definition, if it has a
2971 new_symbol (die, read_type_die (die, cu), cu);
2973 case DW_TAG_common_block:
2974 read_common_block (die, cu);
2976 case DW_TAG_common_inclusion:
2978 case DW_TAG_namespace:
2979 processing_has_namespace_info = 1;
2980 read_namespace (die, cu);
2983 read_module (die, cu);
2985 case DW_TAG_imported_declaration:
2986 case DW_TAG_imported_module:
2987 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2988 information contained in these. DW_TAG_imported_declaration
2989 dies shouldn't have children; DW_TAG_imported_module dies
2990 shouldn't in the C++ case, but conceivably could in the
2992 processing_has_namespace_info = 1;
2993 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
2994 dwarf_tag_name (die->tag));
2997 new_symbol (die, NULL, cu);
3002 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3003 If scope qualifiers are appropriate they will be added. The result
3004 will be allocated on the objfile_obstack, or NULL if the DIE does
3008 dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
3010 struct attribute *attr;
3011 char *prefix, *name;
3012 struct ui_file *buf = NULL;
3014 name = dwarf2_name (die, cu);
3018 /* These are the only languages we know how to qualify names in. */
3019 if (cu->language != language_cplus
3020 && cu->language != language_java)
3023 /* If no prefix is necessary for this type of DIE, return the
3024 unqualified name. The other three tags listed could be handled
3025 in pdi_needs_namespace, but that requires broader changes. */
3026 if (!pdi_needs_namespace (die->tag)
3027 && die->tag != DW_TAG_subprogram
3028 && die->tag != DW_TAG_variable
3029 && die->tag != DW_TAG_member)
3032 prefix = determine_prefix (die, cu);
3033 if (*prefix != '\0')
3034 name = typename_concat (&cu->objfile->objfile_obstack, prefix,
3041 initialize_cu_func_list (struct dwarf2_cu *cu)
3043 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
3047 free_cu_line_header (void *arg)
3049 struct dwarf2_cu *cu = arg;
3051 free_line_header (cu->line_header);
3052 cu->line_header = NULL;
3056 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3058 struct objfile *objfile = cu->objfile;
3059 struct comp_unit_head *cu_header = &cu->header;
3060 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3061 CORE_ADDR lowpc = ((CORE_ADDR) -1);
3062 CORE_ADDR highpc = ((CORE_ADDR) 0);
3063 struct attribute *attr;
3065 char *comp_dir = NULL;
3066 struct die_info *child_die;
3067 bfd *abfd = objfile->obfd;
3068 struct line_header *line_header = 0;
3071 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3073 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
3075 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3076 from finish_block. */
3077 if (lowpc == ((CORE_ADDR) -1))
3082 /* Find the filename. Do not use dwarf2_name here, since the filename
3083 is not a source language identifier. */
3084 attr = dwarf2_attr (die, DW_AT_name, cu);
3087 name = DW_STRING (attr);
3090 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3092 comp_dir = DW_STRING (attr);
3093 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3095 comp_dir = ldirname (name);
3096 if (comp_dir != NULL)
3097 make_cleanup (xfree, comp_dir);
3099 if (comp_dir != NULL)
3101 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3102 directory, get rid of it. */
3103 char *cp = strchr (comp_dir, ':');
3105 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3112 attr = dwarf2_attr (die, DW_AT_language, cu);
3115 set_cu_language (DW_UNSND (attr), cu);
3118 attr = dwarf2_attr (die, DW_AT_producer, cu);
3120 cu->producer = DW_STRING (attr);
3122 /* We assume that we're processing GCC output. */
3123 processing_gcc_compilation = 2;
3125 processing_has_namespace_info = 0;
3127 start_symtab (name, comp_dir, lowpc);
3128 record_debugformat ("DWARF 2");
3129 record_producer (cu->producer);
3131 initialize_cu_func_list (cu);
3133 /* Decode line number information if present. We do this before
3134 processing child DIEs, so that the line header table is available
3135 for DW_AT_decl_file. */
3136 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3139 unsigned int line_offset = DW_UNSND (attr);
3140 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
3143 cu->line_header = line_header;
3144 make_cleanup (free_cu_line_header, cu);
3145 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
3149 /* Process all dies in compilation unit. */
3150 if (die->child != NULL)
3152 child_die = die->child;
3153 while (child_die && child_die->tag)
3155 process_die (child_die, cu);
3156 child_die = sibling_die (child_die);
3160 /* Decode macro information, if present. Dwarf 2 macro information
3161 refers to information in the line number info statement program
3162 header, so we can only read it if we've read the header
3164 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
3165 if (attr && line_header)
3167 unsigned int macro_offset = DW_UNSND (attr);
3168 dwarf_decode_macros (line_header, macro_offset,
3169 comp_dir, abfd, cu);
3171 do_cleanups (back_to);
3175 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
3176 struct dwarf2_cu *cu)
3178 struct function_range *thisfn;
3180 thisfn = (struct function_range *)
3181 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
3182 thisfn->name = name;
3183 thisfn->lowpc = lowpc;
3184 thisfn->highpc = highpc;
3185 thisfn->seen_line = 0;
3186 thisfn->next = NULL;
3188 if (cu->last_fn == NULL)
3189 cu->first_fn = thisfn;
3191 cu->last_fn->next = thisfn;
3193 cu->last_fn = thisfn;
3196 /* qsort helper for inherit_abstract_dies. */
3199 unsigned_int_compar (const void *ap, const void *bp)
3201 unsigned int a = *(unsigned int *) ap;
3202 unsigned int b = *(unsigned int *) bp;
3204 return (a > b) - (b > a);
3207 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3208 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3209 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3212 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
3214 struct die_info *child_die;
3215 unsigned die_children_count;
3216 /* CU offsets which were referenced by children of the current DIE. */
3218 unsigned *offsets_end, *offsetp;
3219 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3220 struct die_info *origin_die;
3221 /* Iterator of the ORIGIN_DIE children. */
3222 struct die_info *origin_child_die;
3223 struct cleanup *cleanups;
3224 struct attribute *attr;
3226 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
3230 origin_die = follow_die_ref (die, attr, &cu);
3231 if (die->tag != origin_die->tag)
3232 complaint (&symfile_complaints,
3233 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3234 die->offset, origin_die->offset);
3236 child_die = die->child;
3237 die_children_count = 0;
3238 while (child_die && child_die->tag)
3240 child_die = sibling_die (child_die);
3241 die_children_count++;
3243 offsets = xmalloc (sizeof (*offsets) * die_children_count);
3244 cleanups = make_cleanup (xfree, offsets);
3246 offsets_end = offsets;
3247 child_die = die->child;
3248 while (child_die && child_die->tag)
3250 attr = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
3251 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3252 counterpart may exist. */
3255 struct die_info *child_origin_die;
3257 child_origin_die = follow_die_ref (child_die, attr, &cu);
3258 if (child_die->tag != child_origin_die->tag)
3259 complaint (&symfile_complaints,
3260 _("Child DIE 0x%x and its abstract origin 0x%x have "
3261 "different tags"), child_die->offset,
3262 child_origin_die->offset);
3263 *offsets_end++ = child_origin_die->offset;
3265 child_die = sibling_die (child_die);
3267 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
3268 unsigned_int_compar);
3269 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
3270 if (offsetp[-1] == *offsetp)
3271 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
3272 "to DIE 0x%x as their abstract origin"),
3273 die->offset, *offsetp);
3276 origin_child_die = origin_die->child;
3277 while (origin_child_die && origin_child_die->tag)
3279 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3280 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
3282 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
3284 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3285 process_die (origin_child_die, cu);
3287 origin_child_die = sibling_die (origin_child_die);
3290 do_cleanups (cleanups);
3294 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
3296 struct objfile *objfile = cu->objfile;
3297 struct context_stack *new;
3300 struct die_info *child_die;
3301 struct attribute *attr;
3304 struct block *block;
3306 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3308 name = dwarf2_linkage_name (die, cu);
3310 /* Ignore functions with missing or empty names and functions with
3311 missing or invalid low and high pc attributes. */
3312 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
3318 /* Record the function range for dwarf_decode_lines. */
3319 add_to_cu_func_list (name, lowpc, highpc, cu);
3321 new = push_context (0, lowpc);
3322 new->name = new_symbol (die, read_type_die (die, cu), cu);
3324 /* If there is a location expression for DW_AT_frame_base, record
3326 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
3328 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3329 expression is being recorded directly in the function's symbol
3330 and not in a separate frame-base object. I guess this hack is
3331 to avoid adding some sort of frame-base adjunct/annex to the
3332 function's symbol :-(. The problem with doing this is that it
3333 results in a function symbol with a location expression that
3334 has nothing to do with the location of the function, ouch! The
3335 relationship should be: a function's symbol has-a frame base; a
3336 frame-base has-a location expression. */
3337 dwarf2_symbol_mark_computed (attr, new->name, cu);
3339 cu->list_in_scope = &local_symbols;
3341 if (die->child != NULL)
3343 child_die = die->child;
3344 while (child_die && child_die->tag)
3346 process_die (child_die, cu);
3347 child_die = sibling_die (child_die);
3351 inherit_abstract_dies (die, cu);
3353 new = pop_context ();
3354 /* Make a block for the local symbols within. */
3355 block = finish_block (new->name, &local_symbols, new->old_blocks,
3356 lowpc, highpc, objfile);
3358 /* For C++, set the block's scope. */
3359 if (cu->language == language_cplus)
3360 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
3361 determine_prefix (die, cu),
3362 processing_has_namespace_info);
3364 /* If we have address ranges, record them. */
3365 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3367 /* In C++, we can have functions nested inside functions (e.g., when
3368 a function declares a class that has methods). This means that
3369 when we finish processing a function scope, we may need to go
3370 back to building a containing block's symbol lists. */
3371 local_symbols = new->locals;
3372 param_symbols = new->params;
3374 /* If we've finished processing a top-level function, subsequent
3375 symbols go in the file symbol list. */
3376 if (outermost_context_p ())
3377 cu->list_in_scope = &file_symbols;
3380 /* Process all the DIES contained within a lexical block scope. Start
3381 a new scope, process the dies, and then close the scope. */
3384 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
3386 struct objfile *objfile = cu->objfile;
3387 struct context_stack *new;
3388 CORE_ADDR lowpc, highpc;
3389 struct die_info *child_die;
3392 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3394 /* Ignore blocks with missing or invalid low and high pc attributes. */
3395 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3396 as multiple lexical blocks? Handling children in a sane way would
3397 be nasty. Might be easier to properly extend generic blocks to
3399 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
3404 push_context (0, lowpc);
3405 if (die->child != NULL)
3407 child_die = die->child;
3408 while (child_die && child_die->tag)
3410 process_die (child_die, cu);
3411 child_die = sibling_die (child_die);
3414 new = pop_context ();
3416 if (local_symbols != NULL)
3419 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
3422 /* Note that recording ranges after traversing children, as we
3423 do here, means that recording a parent's ranges entails
3424 walking across all its children's ranges as they appear in
3425 the address map, which is quadratic behavior.
3427 It would be nicer to record the parent's ranges before
3428 traversing its children, simply overriding whatever you find
3429 there. But since we don't even decide whether to create a
3430 block until after we've traversed its children, that's hard
3432 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3434 local_symbols = new->locals;
3437 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3438 Return 1 if the attributes are present and valid, otherwise, return 0.
3439 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3442 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
3443 CORE_ADDR *high_return, struct dwarf2_cu *cu,
3444 struct partial_symtab *ranges_pst)
3446 struct objfile *objfile = cu->objfile;
3447 struct comp_unit_head *cu_header = &cu->header;
3448 bfd *obfd = objfile->obfd;
3449 unsigned int addr_size = cu_header->addr_size;
3450 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3451 /* Base address selection entry. */
3462 found_base = cu->base_known;
3463 base = cu->base_address;
3465 if (offset >= dwarf2_per_objfile->ranges.size)
3467 complaint (&symfile_complaints,
3468 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3472 buffer = dwarf2_per_objfile->ranges.buffer + offset;
3474 /* Read in the largest possible address. */
3475 marker = read_address (obfd, buffer, cu, &dummy);
3476 if ((marker & mask) == mask)
3478 /* If we found the largest possible address, then
3479 read the base address. */
3480 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3481 buffer += 2 * addr_size;
3482 offset += 2 * addr_size;
3488 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3492 CORE_ADDR range_beginning, range_end;
3494 range_beginning = read_address (obfd, buffer, cu, &dummy);
3495 buffer += addr_size;
3496 range_end = read_address (obfd, buffer, cu, &dummy);
3497 buffer += addr_size;
3498 offset += 2 * addr_size;
3500 /* An end of list marker is a pair of zero addresses. */
3501 if (range_beginning == 0 && range_end == 0)
3502 /* Found the end of list entry. */
3505 /* Each base address selection entry is a pair of 2 values.
3506 The first is the largest possible address, the second is
3507 the base address. Check for a base address here. */
3508 if ((range_beginning & mask) == mask)
3510 /* If we found the largest possible address, then
3511 read the base address. */
3512 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3519 /* We have no valid base address for the ranges
3521 complaint (&symfile_complaints,
3522 _("Invalid .debug_ranges data (no base address)"));
3526 range_beginning += base;
3529 if (ranges_pst != NULL && range_beginning < range_end)
3530 addrmap_set_empty (objfile->psymtabs_addrmap,
3531 range_beginning + baseaddr, range_end - 1 + baseaddr,
3534 /* FIXME: This is recording everything as a low-high
3535 segment of consecutive addresses. We should have a
3536 data structure for discontiguous block ranges
3540 low = range_beginning;
3546 if (range_beginning < low)
3547 low = range_beginning;
3548 if (range_end > high)
3554 /* If the first entry is an end-of-list marker, the range
3555 describes an empty scope, i.e. no instructions. */
3561 *high_return = high;
3565 /* Get low and high pc attributes from a die. Return 1 if the attributes
3566 are present and valid, otherwise, return 0. Return -1 if the range is
3567 discontinuous, i.e. derived from DW_AT_ranges information. */
3569 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
3570 CORE_ADDR *highpc, struct dwarf2_cu *cu)
3572 struct attribute *attr;
3577 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
3580 high = DW_ADDR (attr);
3581 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3583 low = DW_ADDR (attr);
3585 /* Found high w/o low attribute. */
3588 /* Found consecutive range of addresses. */
3593 attr = dwarf2_attr (die, DW_AT_ranges, cu);
3596 /* Value of the DW_AT_ranges attribute is the offset in the
3597 .debug_ranges section. */
3598 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL))
3600 /* Found discontinuous range of addresses. */
3608 /* When using the GNU linker, .gnu.linkonce. sections are used to
3609 eliminate duplicate copies of functions and vtables and such.
3610 The linker will arbitrarily choose one and discard the others.
3611 The AT_*_pc values for such functions refer to local labels in
3612 these sections. If the section from that file was discarded, the
3613 labels are not in the output, so the relocs get a value of 0.
3614 If this is a discarded function, mark the pc bounds as invalid,
3615 so that GDB will ignore it. */
3616 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
3624 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3625 its low and high PC addresses. Do nothing if these addresses could not
3626 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3627 and HIGHPC to the high address if greater than HIGHPC. */
3630 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
3631 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3632 struct dwarf2_cu *cu)
3634 CORE_ADDR low, high;
3635 struct die_info *child = die->child;
3637 if (dwarf2_get_pc_bounds (die, &low, &high, cu))
3639 *lowpc = min (*lowpc, low);
3640 *highpc = max (*highpc, high);
3643 /* If the language does not allow nested subprograms (either inside
3644 subprograms or lexical blocks), we're done. */
3645 if (cu->language != language_ada)
3648 /* Check all the children of the given DIE. If it contains nested
3649 subprograms, then check their pc bounds. Likewise, we need to
3650 check lexical blocks as well, as they may also contain subprogram
3652 while (child && child->tag)
3654 if (child->tag == DW_TAG_subprogram
3655 || child->tag == DW_TAG_lexical_block)
3656 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
3657 child = sibling_die (child);
3661 /* Get the low and high pc's represented by the scope DIE, and store
3662 them in *LOWPC and *HIGHPC. If the correct values can't be
3663 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3666 get_scope_pc_bounds (struct die_info *die,
3667 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3668 struct dwarf2_cu *cu)
3670 CORE_ADDR best_low = (CORE_ADDR) -1;
3671 CORE_ADDR best_high = (CORE_ADDR) 0;
3672 CORE_ADDR current_low, current_high;
3674 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
3676 best_low = current_low;
3677 best_high = current_high;
3681 struct die_info *child = die->child;
3683 while (child && child->tag)
3685 switch (child->tag) {
3686 case DW_TAG_subprogram:
3687 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
3689 case DW_TAG_namespace:
3690 /* FIXME: carlton/2004-01-16: Should we do this for
3691 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3692 that current GCC's always emit the DIEs corresponding
3693 to definitions of methods of classes as children of a
3694 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3695 the DIEs giving the declarations, which could be
3696 anywhere). But I don't see any reason why the
3697 standards says that they have to be there. */
3698 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
3700 if (current_low != ((CORE_ADDR) -1))
3702 best_low = min (best_low, current_low);
3703 best_high = max (best_high, current_high);
3711 child = sibling_die (child);
3716 *highpc = best_high;
3719 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3722 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
3723 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
3725 struct attribute *attr;
3727 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
3730 CORE_ADDR high = DW_ADDR (attr);
3731 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3734 CORE_ADDR low = DW_ADDR (attr);
3735 record_block_range (block, baseaddr + low, baseaddr + high - 1);
3739 attr = dwarf2_attr (die, DW_AT_ranges, cu);
3742 bfd *obfd = cu->objfile->obfd;
3744 /* The value of the DW_AT_ranges attribute is the offset of the
3745 address range list in the .debug_ranges section. */
3746 unsigned long offset = DW_UNSND (attr);
3747 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
3749 /* For some target architectures, but not others, the
3750 read_address function sign-extends the addresses it returns.
3751 To recognize base address selection entries, we need a
3753 unsigned int addr_size = cu->header.addr_size;
3754 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3756 /* The base address, to which the next pair is relative. Note
3757 that this 'base' is a DWARF concept: most entries in a range
3758 list are relative, to reduce the number of relocs against the
3759 debugging information. This is separate from this function's
3760 'baseaddr' argument, which GDB uses to relocate debugging
3761 information from a shared library based on the address at
3762 which the library was loaded. */
3763 CORE_ADDR base = cu->base_address;
3764 int base_known = cu->base_known;
3766 if (offset >= dwarf2_per_objfile->ranges.size)
3768 complaint (&symfile_complaints,
3769 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3776 unsigned int bytes_read;
3777 CORE_ADDR start, end;
3779 start = read_address (obfd, buffer, cu, &bytes_read);
3780 buffer += bytes_read;
3781 end = read_address (obfd, buffer, cu, &bytes_read);
3782 buffer += bytes_read;
3784 /* Did we find the end of the range list? */
3785 if (start == 0 && end == 0)
3788 /* Did we find a base address selection entry? */
3789 else if ((start & base_select_mask) == base_select_mask)
3795 /* We found an ordinary address range. */
3800 complaint (&symfile_complaints,
3801 _("Invalid .debug_ranges data (no base address)"));
3805 record_block_range (block,
3806 baseaddr + base + start,
3807 baseaddr + base + end - 1);
3813 /* Add an aggregate field to the field list. */
3816 dwarf2_add_field (struct field_info *fip, struct die_info *die,
3817 struct dwarf2_cu *cu)
3819 struct objfile *objfile = cu->objfile;
3820 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3821 struct nextfield *new_field;
3822 struct attribute *attr;
3824 char *fieldname = "";
3826 /* Allocate a new field list entry and link it in. */
3827 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3828 make_cleanup (xfree, new_field);
3829 memset (new_field, 0, sizeof (struct nextfield));
3830 new_field->next = fip->fields;
3831 fip->fields = new_field;
3834 /* Handle accessibility and virtuality of field.
3835 The default accessibility for members is public, the default
3836 accessibility for inheritance is private. */
3837 if (die->tag != DW_TAG_inheritance)
3838 new_field->accessibility = DW_ACCESS_public;
3840 new_field->accessibility = DW_ACCESS_private;
3841 new_field->virtuality = DW_VIRTUALITY_none;
3843 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3845 new_field->accessibility = DW_UNSND (attr);
3846 if (new_field->accessibility != DW_ACCESS_public)
3847 fip->non_public_fields = 1;
3848 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
3850 new_field->virtuality = DW_UNSND (attr);
3852 fp = &new_field->field;
3854 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
3856 /* Data member other than a C++ static data member. */
3858 /* Get type of field. */
3859 fp->type = die_type (die, cu);
3861 SET_FIELD_BITPOS (*fp, 0);
3863 /* Get bit size of field (zero if none). */
3864 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
3867 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
3871 FIELD_BITSIZE (*fp) = 0;
3874 /* Get bit offset of field. */
3875 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3880 if (attr_form_is_section_offset (attr))
3882 dwarf2_complex_location_expr_complaint ();
3885 else if (attr_form_is_constant (attr))
3886 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
3888 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
3890 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
3892 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
3895 if (gdbarch_bits_big_endian (gdbarch))
3897 /* For big endian bits, the DW_AT_bit_offset gives the
3898 additional bit offset from the MSB of the containing
3899 anonymous object to the MSB of the field. We don't
3900 have to do anything special since we don't need to
3901 know the size of the anonymous object. */
3902 FIELD_BITPOS (*fp) += DW_UNSND (attr);
3906 /* For little endian bits, compute the bit offset to the
3907 MSB of the anonymous object, subtract off the number of
3908 bits from the MSB of the field to the MSB of the
3909 object, and then subtract off the number of bits of
3910 the field itself. The result is the bit offset of
3911 the LSB of the field. */
3913 int bit_offset = DW_UNSND (attr);
3915 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3918 /* The size of the anonymous object containing
3919 the bit field is explicit, so use the
3920 indicated size (in bytes). */
3921 anonymous_size = DW_UNSND (attr);
3925 /* The size of the anonymous object containing
3926 the bit field must be inferred from the type
3927 attribute of the data member containing the
3929 anonymous_size = TYPE_LENGTH (fp->type);
3931 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
3932 - bit_offset - FIELD_BITSIZE (*fp);
3936 /* Get name of field. */
3937 fieldname = dwarf2_name (die, cu);
3938 if (fieldname == NULL)
3941 /* The name is already allocated along with this objfile, so we don't
3942 need to duplicate it for the type. */
3943 fp->name = fieldname;
3945 /* Change accessibility for artificial fields (e.g. virtual table
3946 pointer or virtual base class pointer) to private. */
3947 if (dwarf2_attr (die, DW_AT_artificial, cu))
3949 new_field->accessibility = DW_ACCESS_private;
3950 fip->non_public_fields = 1;
3953 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
3955 /* C++ static member. */
3957 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3958 is a declaration, but all versions of G++ as of this writing
3959 (so through at least 3.2.1) incorrectly generate
3960 DW_TAG_variable tags. */
3964 /* Get name of field. */
3965 fieldname = dwarf2_name (die, cu);
3966 if (fieldname == NULL)
3969 /* Get physical name. */
3970 physname = dwarf2_linkage_name (die, cu);
3972 /* The name is already allocated along with this objfile, so we don't
3973 need to duplicate it for the type. */
3974 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
3975 FIELD_TYPE (*fp) = die_type (die, cu);
3976 FIELD_NAME (*fp) = fieldname;
3978 else if (die->tag == DW_TAG_inheritance)
3980 /* C++ base class field. */
3981 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3983 SET_FIELD_BITPOS (*fp, decode_locdesc (DW_BLOCK (attr), cu)
3985 FIELD_BITSIZE (*fp) = 0;
3986 FIELD_TYPE (*fp) = die_type (die, cu);
3987 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3988 fip->nbaseclasses++;
3992 /* Create the vector of fields, and attach it to the type. */
3995 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3996 struct dwarf2_cu *cu)
3998 int nfields = fip->nfields;
4000 /* Record the field count, allocate space for the array of fields,
4001 and create blank accessibility bitfields if necessary. */
4002 TYPE_NFIELDS (type) = nfields;
4003 TYPE_FIELDS (type) = (struct field *)
4004 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4005 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4007 if (fip->non_public_fields)
4009 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4011 TYPE_FIELD_PRIVATE_BITS (type) =
4012 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4013 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4015 TYPE_FIELD_PROTECTED_BITS (type) =
4016 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4017 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4019 TYPE_FIELD_IGNORE_BITS (type) =
4020 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4021 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4024 /* If the type has baseclasses, allocate and clear a bit vector for
4025 TYPE_FIELD_VIRTUAL_BITS. */
4026 if (fip->nbaseclasses)
4028 int num_bytes = B_BYTES (fip->nbaseclasses);
4029 unsigned char *pointer;
4031 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4032 pointer = TYPE_ALLOC (type, num_bytes);
4033 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
4034 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
4035 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
4038 /* Copy the saved-up fields into the field vector. Start from the head
4039 of the list, adding to the tail of the field array, so that they end
4040 up in the same order in the array in which they were added to the list. */
4041 while (nfields-- > 0)
4043 TYPE_FIELD (type, nfields) = fip->fields->field;
4044 switch (fip->fields->accessibility)
4046 case DW_ACCESS_private:
4047 SET_TYPE_FIELD_PRIVATE (type, nfields);
4050 case DW_ACCESS_protected:
4051 SET_TYPE_FIELD_PROTECTED (type, nfields);
4054 case DW_ACCESS_public:
4058 /* Unknown accessibility. Complain and treat it as public. */
4060 complaint (&symfile_complaints, _("unsupported accessibility %d"),
4061 fip->fields->accessibility);
4065 if (nfields < fip->nbaseclasses)
4067 switch (fip->fields->virtuality)
4069 case DW_VIRTUALITY_virtual:
4070 case DW_VIRTUALITY_pure_virtual:
4071 SET_TYPE_FIELD_VIRTUAL (type, nfields);
4075 fip->fields = fip->fields->next;
4079 /* Add a member function to the proper fieldlist. */
4082 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
4083 struct type *type, struct dwarf2_cu *cu)
4085 struct objfile *objfile = cu->objfile;
4086 struct attribute *attr;
4087 struct fnfieldlist *flp;
4089 struct fn_field *fnp;
4092 struct nextfnfield *new_fnfield;
4093 struct type *this_type;
4095 /* Get name of member function. */
4096 fieldname = dwarf2_name (die, cu);
4097 if (fieldname == NULL)
4100 /* Get the mangled name. */
4101 physname = dwarf2_linkage_name (die, cu);
4103 /* Look up member function name in fieldlist. */
4104 for (i = 0; i < fip->nfnfields; i++)
4106 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
4110 /* Create new list element if necessary. */
4111 if (i < fip->nfnfields)
4112 flp = &fip->fnfieldlists[i];
4115 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
4117 fip->fnfieldlists = (struct fnfieldlist *)
4118 xrealloc (fip->fnfieldlists,
4119 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
4120 * sizeof (struct fnfieldlist));
4121 if (fip->nfnfields == 0)
4122 make_cleanup (free_current_contents, &fip->fnfieldlists);
4124 flp = &fip->fnfieldlists[fip->nfnfields];
4125 flp->name = fieldname;
4131 /* Create a new member function field and chain it to the field list
4133 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
4134 make_cleanup (xfree, new_fnfield);
4135 memset (new_fnfield, 0, sizeof (struct nextfnfield));
4136 new_fnfield->next = flp->head;
4137 flp->head = new_fnfield;
4140 /* Fill in the member function field info. */
4141 fnp = &new_fnfield->fnfield;
4142 /* The name is already allocated along with this objfile, so we don't
4143 need to duplicate it for the type. */
4144 fnp->physname = physname ? physname : "";
4145 fnp->type = alloc_type (objfile);
4146 this_type = read_type_die (die, cu);
4147 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
4149 int nparams = TYPE_NFIELDS (this_type);
4151 /* TYPE is the domain of this method, and THIS_TYPE is the type
4152 of the method itself (TYPE_CODE_METHOD). */
4153 smash_to_method_type (fnp->type, type,
4154 TYPE_TARGET_TYPE (this_type),
4155 TYPE_FIELDS (this_type),
4156 TYPE_NFIELDS (this_type),
4157 TYPE_VARARGS (this_type));
4159 /* Handle static member functions.
4160 Dwarf2 has no clean way to discern C++ static and non-static
4161 member functions. G++ helps GDB by marking the first
4162 parameter for non-static member functions (which is the
4163 this pointer) as artificial. We obtain this information
4164 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4165 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
4166 fnp->voffset = VOFFSET_STATIC;
4169 complaint (&symfile_complaints, _("member function type missing for '%s'"),
4172 /* Get fcontext from DW_AT_containing_type if present. */
4173 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4174 fnp->fcontext = die_containing_type (die, cu);
4176 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4177 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4179 /* Get accessibility. */
4180 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4183 switch (DW_UNSND (attr))
4185 case DW_ACCESS_private:
4186 fnp->is_private = 1;
4188 case DW_ACCESS_protected:
4189 fnp->is_protected = 1;
4194 /* Check for artificial methods. */
4195 attr = dwarf2_attr (die, DW_AT_artificial, cu);
4196 if (attr && DW_UNSND (attr) != 0)
4197 fnp->is_artificial = 1;
4199 /* Get index in virtual function table if it is a virtual member function. */
4200 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
4203 /* Support the .debug_loc offsets */
4204 if (attr_form_is_block (attr))
4206 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
4208 else if (attr_form_is_section_offset (attr))
4210 dwarf2_complex_location_expr_complaint ();
4214 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4220 /* Create the vector of member function fields, and attach it to the type. */
4223 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
4224 struct dwarf2_cu *cu)
4226 struct fnfieldlist *flp;
4227 int total_length = 0;
4230 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4231 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4232 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
4234 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
4236 struct nextfnfield *nfp = flp->head;
4237 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
4240 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
4241 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
4242 fn_flp->fn_fields = (struct fn_field *)
4243 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
4244 for (k = flp->length; (k--, nfp); nfp = nfp->next)
4245 fn_flp->fn_fields[k] = nfp->fnfield;
4247 total_length += flp->length;
4250 TYPE_NFN_FIELDS (type) = fip->nfnfields;
4251 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
4254 /* Returns non-zero if NAME is the name of a vtable member in CU's
4255 language, zero otherwise. */
4257 is_vtable_name (const char *name, struct dwarf2_cu *cu)
4259 static const char vptr[] = "_vptr";
4260 static const char vtable[] = "vtable";
4262 /* Look for the C++ and Java forms of the vtable. */
4263 if ((cu->language == language_java
4264 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
4265 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
4266 && is_cplus_marker (name[sizeof (vptr) - 1])))
4272 /* GCC outputs unnamed structures that are really pointers to member
4273 functions, with the ABI-specified layout. If DIE (from CU) describes
4274 such a structure, set its type, and return nonzero. Otherwise return
4277 GCC shouldn't do this; it should just output pointer to member DIEs.
4278 This is GCC PR debug/28767. */
4280 static struct type *
4281 quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
4283 struct objfile *objfile = cu->objfile;
4285 struct die_info *pfn_die, *delta_die;
4286 struct attribute *pfn_name, *delta_name;
4287 struct type *pfn_type, *domain_type;
4289 /* Check for a structure with no name and two children. */
4290 if (die->tag != DW_TAG_structure_type
4291 || dwarf2_attr (die, DW_AT_name, cu) != NULL
4292 || die->child == NULL
4293 || die->child->sibling == NULL
4294 || (die->child->sibling->sibling != NULL
4295 && die->child->sibling->sibling->tag != DW_TAG_padding))
4298 /* Check for __pfn and __delta members. */
4299 pfn_die = die->child;
4300 pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu);
4301 if (pfn_die->tag != DW_TAG_member
4303 || DW_STRING (pfn_name) == NULL
4304 || strcmp ("__pfn", DW_STRING (pfn_name)) != 0)
4307 delta_die = pfn_die->sibling;
4308 delta_name = dwarf2_attr (delta_die, DW_AT_name, cu);
4309 if (delta_die->tag != DW_TAG_member
4310 || delta_name == NULL
4311 || DW_STRING (delta_name) == NULL
4312 || strcmp ("__delta", DW_STRING (delta_name)) != 0)
4315 /* Find the type of the method. */
4316 pfn_type = die_type (pfn_die, cu);
4317 if (pfn_type == NULL
4318 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
4319 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
4322 /* Look for the "this" argument. */
4323 pfn_type = TYPE_TARGET_TYPE (pfn_type);
4324 if (TYPE_NFIELDS (pfn_type) == 0
4325 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
4328 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
4329 type = alloc_type (objfile);
4330 smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
4331 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
4332 TYPE_VARARGS (pfn_type));
4333 type = lookup_methodptr_type (type);
4334 return set_die_type (die, type, cu);
4337 /* Called when we find the DIE that starts a structure or union scope
4338 (definition) to process all dies that define the members of the
4341 NOTE: we need to call struct_type regardless of whether or not the
4342 DIE has an at_name attribute, since it might be an anonymous
4343 structure or union. This gets the type entered into our set of
4346 However, if the structure is incomplete (an opaque struct/union)
4347 then suppress creating a symbol table entry for it since gdb only
4348 wants to find the one with the complete definition. Note that if
4349 it is complete, we just call new_symbol, which does it's own
4350 checking about whether the struct/union is anonymous or not (and
4351 suppresses creating a symbol table entry itself). */
4353 static struct type *
4354 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
4356 struct objfile *objfile = cu->objfile;
4358 struct attribute *attr;
4360 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4362 type = quirk_gcc_member_function_pointer (die, cu);
4366 type = alloc_type (objfile);
4367 INIT_CPLUS_SPECIFIC (type);
4368 name = dwarf2_name (die, cu);
4371 if (cu->language == language_cplus
4372 || cu->language == language_java)
4374 const char *new_prefix = determine_class_name (die, cu);
4375 TYPE_TAG_NAME (type) = (char *) new_prefix;
4379 /* The name is already allocated along with this objfile, so
4380 we don't need to duplicate it for the type. */
4381 TYPE_TAG_NAME (type) = name;
4385 if (die->tag == DW_TAG_structure_type)
4387 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4389 else if (die->tag == DW_TAG_union_type)
4391 TYPE_CODE (type) = TYPE_CODE_UNION;
4395 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4397 TYPE_CODE (type) = TYPE_CODE_CLASS;
4400 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4403 TYPE_LENGTH (type) = DW_UNSND (attr);
4407 TYPE_LENGTH (type) = 0;
4410 TYPE_STUB_SUPPORTED (type) = 1;
4411 if (die_is_declaration (die, cu))
4412 TYPE_STUB (type) = 1;
4414 /* We need to add the type field to the die immediately so we don't
4415 infinitely recurse when dealing with pointers to the structure
4416 type within the structure itself. */
4417 set_die_type (die, type, cu);
4419 if (die->child != NULL && ! die_is_declaration (die, cu))
4421 struct field_info fi;
4422 struct die_info *child_die;
4424 memset (&fi, 0, sizeof (struct field_info));
4426 child_die = die->child;
4428 while (child_die && child_die->tag)
4430 if (child_die->tag == DW_TAG_member
4431 || child_die->tag == DW_TAG_variable)
4433 /* NOTE: carlton/2002-11-05: A C++ static data member
4434 should be a DW_TAG_member that is a declaration, but
4435 all versions of G++ as of this writing (so through at
4436 least 3.2.1) incorrectly generate DW_TAG_variable
4437 tags for them instead. */
4438 dwarf2_add_field (&fi, child_die, cu);
4440 else if (child_die->tag == DW_TAG_subprogram)
4442 /* C++ member function. */
4443 dwarf2_add_member_fn (&fi, child_die, type, cu);
4445 else if (child_die->tag == DW_TAG_inheritance)
4447 /* C++ base class field. */
4448 dwarf2_add_field (&fi, child_die, cu);
4450 child_die = sibling_die (child_die);
4453 /* Attach fields and member functions to the type. */
4455 dwarf2_attach_fields_to_type (&fi, type, cu);
4458 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
4460 /* Get the type which refers to the base class (possibly this
4461 class itself) which contains the vtable pointer for the current
4462 class from the DW_AT_containing_type attribute. */
4464 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4466 struct type *t = die_containing_type (die, cu);
4468 TYPE_VPTR_BASETYPE (type) = t;
4473 /* Our own class provides vtbl ptr. */
4474 for (i = TYPE_NFIELDS (t) - 1;
4475 i >= TYPE_N_BASECLASSES (t);
4478 char *fieldname = TYPE_FIELD_NAME (t, i);
4480 if (is_vtable_name (fieldname, cu))
4482 TYPE_VPTR_FIELDNO (type) = i;
4487 /* Complain if virtual function table field not found. */
4488 if (i < TYPE_N_BASECLASSES (t))
4489 complaint (&symfile_complaints,
4490 _("virtual function table pointer not found when defining class '%s'"),
4491 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
4496 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4499 else if (cu->producer
4500 && strncmp (cu->producer,
4501 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4503 /* The IBM XLC compiler does not provide direct indication
4504 of the containing type, but the vtable pointer is
4505 always named __vfp. */
4509 for (i = TYPE_NFIELDS (type) - 1;
4510 i >= TYPE_N_BASECLASSES (type);
4513 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
4515 TYPE_VPTR_FIELDNO (type) = i;
4516 TYPE_VPTR_BASETYPE (type) = type;
4524 do_cleanups (back_to);
4529 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
4531 struct objfile *objfile = cu->objfile;
4532 struct die_info *child_die = die->child;
4533 struct type *this_type;
4535 this_type = get_die_type (die, cu);
4536 if (this_type == NULL)
4537 this_type = read_structure_type (die, cu);
4539 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4540 snapshots) has been known to create a die giving a declaration
4541 for a class that has, as a child, a die giving a definition for a
4542 nested class. So we have to process our children even if the
4543 current die is a declaration. Normally, of course, a declaration
4544 won't have any children at all. */
4546 while (child_die != NULL && child_die->tag)
4548 if (child_die->tag == DW_TAG_member
4549 || child_die->tag == DW_TAG_variable
4550 || child_die->tag == DW_TAG_inheritance)
4555 process_die (child_die, cu);
4557 child_die = sibling_die (child_die);
4560 /* Do not consider external references. According to the DWARF standard,
4561 these DIEs are identified by the fact that they have no byte_size
4562 attribute, and a declaration attribute. */
4563 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
4564 || !die_is_declaration (die, cu))
4565 new_symbol (die, this_type, cu);
4568 /* Given a DW_AT_enumeration_type die, set its type. We do not
4569 complete the type's fields yet, or create any symbols. */
4571 static struct type *
4572 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
4574 struct objfile *objfile = cu->objfile;
4576 struct attribute *attr;
4579 type = alloc_type (objfile);
4581 TYPE_CODE (type) = TYPE_CODE_ENUM;
4582 name = dwarf2_full_name (die, cu);
4584 TYPE_TAG_NAME (type) = (char *) name;
4586 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4589 TYPE_LENGTH (type) = DW_UNSND (attr);
4593 TYPE_LENGTH (type) = 0;
4596 /* The enumeration DIE can be incomplete. In Ada, any type can be
4597 declared as private in the package spec, and then defined only
4598 inside the package body. Such types are known as Taft Amendment
4599 Types. When another package uses such a type, an incomplete DIE
4600 may be generated by the compiler. */
4601 if (die_is_declaration (die, cu))
4602 TYPE_STUB (type) = 1;
4604 return set_die_type (die, type, cu);
4607 /* Determine the name of the type represented by DIE, which should be
4608 a named C++ or Java compound type. Return the name in question,
4609 allocated on the objfile obstack. */
4612 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
4614 const char *new_prefix = NULL;
4616 /* If we don't have namespace debug info, guess the name by trying
4617 to demangle the names of members, just like we did in
4618 guess_structure_name. */
4619 if (!processing_has_namespace_info)
4621 struct die_info *child;
4623 for (child = die->child;
4624 child != NULL && child->tag != 0;
4625 child = sibling_die (child))
4627 if (child->tag == DW_TAG_subprogram)
4630 = language_class_name_from_physname (cu->language_defn,
4634 if (phys_prefix != NULL)
4637 = obsavestring (phys_prefix, strlen (phys_prefix),
4638 &cu->objfile->objfile_obstack);
4639 xfree (phys_prefix);
4646 if (new_prefix == NULL)
4647 new_prefix = dwarf2_full_name (die, cu);
4652 /* Given a pointer to a die which begins an enumeration, process all
4653 the dies that define the members of the enumeration, and create the
4654 symbol for the enumeration type.
4656 NOTE: We reverse the order of the element list. */
4659 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
4661 struct objfile *objfile = cu->objfile;
4662 struct die_info *child_die;
4663 struct field *fields;
4666 int unsigned_enum = 1;
4668 struct type *this_type;
4672 this_type = get_die_type (die, cu);
4673 if (this_type == NULL)
4674 this_type = read_enumeration_type (die, cu);
4675 if (die->child != NULL)
4677 child_die = die->child;
4678 while (child_die && child_die->tag)
4680 if (child_die->tag != DW_TAG_enumerator)
4682 process_die (child_die, cu);
4686 name = dwarf2_name (child_die, cu);
4689 sym = new_symbol (child_die, this_type, cu);
4690 if (SYMBOL_VALUE (sym) < 0)
4693 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
4695 fields = (struct field *)
4697 (num_fields + DW_FIELD_ALLOC_CHUNK)
4698 * sizeof (struct field));
4701 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
4702 FIELD_TYPE (fields[num_fields]) = NULL;
4703 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
4704 FIELD_BITSIZE (fields[num_fields]) = 0;
4710 child_die = sibling_die (child_die);
4715 TYPE_NFIELDS (this_type) = num_fields;
4716 TYPE_FIELDS (this_type) = (struct field *)
4717 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
4718 memcpy (TYPE_FIELDS (this_type), fields,
4719 sizeof (struct field) * num_fields);
4723 TYPE_UNSIGNED (this_type) = 1;
4726 new_symbol (die, this_type, cu);
4729 /* Extract all information from a DW_TAG_array_type DIE and put it in
4730 the DIE's type field. For now, this only handles one dimensional
4733 static struct type *
4734 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
4736 struct objfile *objfile = cu->objfile;
4737 struct die_info *child_die;
4738 struct type *type = NULL;
4739 struct type *element_type, *range_type, *index_type;
4740 struct type **range_types = NULL;
4741 struct attribute *attr;
4743 struct cleanup *back_to;
4746 element_type = die_type (die, cu);
4748 /* Irix 6.2 native cc creates array types without children for
4749 arrays with unspecified length. */
4750 if (die->child == NULL)
4752 index_type = builtin_type_int32;
4753 range_type = create_range_type (NULL, index_type, 0, -1);
4754 type = create_array_type (NULL, element_type, range_type);
4755 return set_die_type (die, type, cu);
4758 back_to = make_cleanup (null_cleanup, NULL);
4759 child_die = die->child;
4760 while (child_die && child_die->tag)
4762 if (child_die->tag == DW_TAG_subrange_type)
4764 struct type *child_type = read_type_die (child_die, cu);
4765 if (child_type != NULL)
4767 /* The range type was succesfully read. Save it for
4768 the array type creation. */
4769 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
4771 range_types = (struct type **)
4772 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
4773 * sizeof (struct type *));
4775 make_cleanup (free_current_contents, &range_types);
4777 range_types[ndim++] = child_type;
4780 child_die = sibling_die (child_die);
4783 /* Dwarf2 dimensions are output from left to right, create the
4784 necessary array types in backwards order. */
4786 type = element_type;
4788 if (read_array_order (die, cu) == DW_ORD_col_major)
4792 type = create_array_type (NULL, type, range_types[i++]);
4797 type = create_array_type (NULL, type, range_types[ndim]);
4800 /* Understand Dwarf2 support for vector types (like they occur on
4801 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4802 array type. This is not part of the Dwarf2/3 standard yet, but a
4803 custom vendor extension. The main difference between a regular
4804 array and the vector variant is that vectors are passed by value
4806 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
4808 make_vector_type (type);
4810 name = dwarf2_name (die, cu);
4812 TYPE_NAME (type) = name;
4814 do_cleanups (back_to);
4816 /* Install the type in the die. */
4817 return set_die_type (die, type, cu);
4820 static enum dwarf_array_dim_ordering
4821 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
4823 struct attribute *attr;
4825 attr = dwarf2_attr (die, DW_AT_ordering, cu);
4827 if (attr) return DW_SND (attr);
4830 GNU F77 is a special case, as at 08/2004 array type info is the
4831 opposite order to the dwarf2 specification, but data is still
4832 laid out as per normal fortran.
4834 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4838 if (cu->language == language_fortran &&
4839 cu->producer && strstr (cu->producer, "GNU F77"))
4841 return DW_ORD_row_major;
4844 switch (cu->language_defn->la_array_ordering)
4846 case array_column_major:
4847 return DW_ORD_col_major;
4848 case array_row_major:
4850 return DW_ORD_row_major;
4854 /* Extract all information from a DW_TAG_set_type DIE and put it in
4855 the DIE's type field. */
4857 static struct type *
4858 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
4860 struct type *set_type = create_set_type (NULL, die_type (die, cu));
4862 return set_die_type (die, set_type, cu);
4865 /* First cut: install each common block member as a global variable. */
4868 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
4870 struct die_info *child_die;
4871 struct attribute *attr;
4873 CORE_ADDR base = (CORE_ADDR) 0;
4875 attr = dwarf2_attr (die, DW_AT_location, cu);
4878 /* Support the .debug_loc offsets */
4879 if (attr_form_is_block (attr))
4881 base = decode_locdesc (DW_BLOCK (attr), cu);
4883 else if (attr_form_is_section_offset (attr))
4885 dwarf2_complex_location_expr_complaint ();
4889 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4890 "common block member");
4893 if (die->child != NULL)
4895 child_die = die->child;
4896 while (child_die && child_die->tag)
4898 sym = new_symbol (child_die, NULL, cu);
4899 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
4902 SYMBOL_VALUE_ADDRESS (sym) =
4903 base + decode_locdesc (DW_BLOCK (attr), cu);
4904 add_symbol_to_list (sym, &global_symbols);
4906 child_die = sibling_die (child_die);
4911 /* Create a type for a C++ namespace. */
4913 static struct type *
4914 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
4916 struct objfile *objfile = cu->objfile;
4917 const char *previous_prefix, *name;
4921 /* For extensions, reuse the type of the original namespace. */
4922 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
4924 struct die_info *ext_die;
4925 struct dwarf2_cu *ext_cu = cu;
4926 ext_die = dwarf2_extension (die, &ext_cu);
4927 type = read_type_die (ext_die, ext_cu);
4928 return set_die_type (die, type, cu);
4931 name = namespace_name (die, &is_anonymous, cu);
4933 /* Now build the name of the current namespace. */
4935 previous_prefix = determine_prefix (die, cu);
4936 if (previous_prefix[0] != '\0')
4937 name = typename_concat (&objfile->objfile_obstack,
4938 previous_prefix, name, cu);
4940 /* Create the type. */
4941 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
4943 TYPE_NAME (type) = (char *) name;
4944 TYPE_TAG_NAME (type) = TYPE_NAME (type);
4946 set_die_type (die, type, cu);
4951 /* Read a C++ namespace. */
4954 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
4956 struct objfile *objfile = cu->objfile;
4960 /* Add a symbol associated to this if we haven't seen the namespace
4961 before. Also, add a using directive if it's an anonymous
4964 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
4968 type = read_type_die (die, cu);
4969 new_symbol (die, type, cu);
4971 name = namespace_name (die, &is_anonymous, cu);
4974 const char *previous_prefix = determine_prefix (die, cu);
4975 cp_add_using_directive (TYPE_NAME (type),
4976 strlen (previous_prefix),
4977 strlen (TYPE_NAME (type)));
4981 if (die->child != NULL)
4983 struct die_info *child_die = die->child;
4985 while (child_die && child_die->tag)
4987 process_die (child_die, cu);
4988 child_die = sibling_die (child_die);
4993 /* Read a Fortran module. */
4996 read_module (struct die_info *die, struct dwarf2_cu *cu)
4998 struct die_info *child_die = die->child;
5000 /* FIXME: Support the separate Fortran module namespaces. */
5002 while (child_die && child_die->tag)
5004 process_die (child_die, cu);
5005 child_die = sibling_die (child_die);
5009 /* Return the name of the namespace represented by DIE. Set
5010 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5014 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
5016 struct die_info *current_die;
5017 const char *name = NULL;
5019 /* Loop through the extensions until we find a name. */
5021 for (current_die = die;
5022 current_die != NULL;
5023 current_die = dwarf2_extension (die, &cu))
5025 name = dwarf2_name (current_die, cu);
5030 /* Is it an anonymous namespace? */
5032 *is_anonymous = (name == NULL);
5034 name = "(anonymous namespace)";
5039 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5040 the user defined type vector. */
5042 static struct type *
5043 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
5045 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5046 struct comp_unit_head *cu_header = &cu->header;
5048 struct attribute *attr_byte_size;
5049 struct attribute *attr_address_class;
5050 int byte_size, addr_class;
5052 type = lookup_pointer_type (die_type (die, cu));
5054 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
5056 byte_size = DW_UNSND (attr_byte_size);
5058 byte_size = cu_header->addr_size;
5060 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
5061 if (attr_address_class)
5062 addr_class = DW_UNSND (attr_address_class);
5064 addr_class = DW_ADDR_none;
5066 /* If the pointer size or address class is different than the
5067 default, create a type variant marked as such and set the
5068 length accordingly. */
5069 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
5071 if (gdbarch_address_class_type_flags_p (gdbarch))
5075 type_flags = gdbarch_address_class_type_flags
5076 (gdbarch, byte_size, addr_class);
5077 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
5079 type = make_type_with_address_space (type, type_flags);
5081 else if (TYPE_LENGTH (type) != byte_size)
5083 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
5086 /* Should we also complain about unhandled address classes? */
5090 TYPE_LENGTH (type) = byte_size;
5091 return set_die_type (die, type, cu);
5094 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5095 the user defined type vector. */
5097 static struct type *
5098 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
5100 struct objfile *objfile = cu->objfile;
5102 struct type *to_type;
5103 struct type *domain;
5105 to_type = die_type (die, cu);
5106 domain = die_containing_type (die, cu);
5108 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
5109 type = lookup_methodptr_type (to_type);
5111 type = lookup_memberptr_type (to_type, domain);
5113 return set_die_type (die, type, cu);
5116 /* Extract all information from a DW_TAG_reference_type DIE and add to
5117 the user defined type vector. */
5119 static struct type *
5120 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
5122 struct comp_unit_head *cu_header = &cu->header;
5124 struct attribute *attr;
5126 type = lookup_reference_type (die_type (die, cu));
5127 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5130 TYPE_LENGTH (type) = DW_UNSND (attr);
5134 TYPE_LENGTH (type) = cu_header->addr_size;
5136 return set_die_type (die, type, cu);
5139 static struct type *
5140 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
5142 struct type *base_type, *cv_type;
5144 base_type = die_type (die, cu);
5145 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
5146 return set_die_type (die, cv_type, cu);
5149 static struct type *
5150 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
5152 struct type *base_type, *cv_type;
5154 base_type = die_type (die, cu);
5155 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
5156 return set_die_type (die, cv_type, cu);
5159 /* Extract all information from a DW_TAG_string_type DIE and add to
5160 the user defined type vector. It isn't really a user defined type,
5161 but it behaves like one, with other DIE's using an AT_user_def_type
5162 attribute to reference it. */
5164 static struct type *
5165 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5167 struct objfile *objfile = cu->objfile;
5168 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5169 struct type *type, *range_type, *index_type, *char_type;
5170 struct attribute *attr;
5171 unsigned int length;
5173 attr = dwarf2_attr (die, DW_AT_string_length, cu);
5176 length = DW_UNSND (attr);
5180 /* check for the DW_AT_byte_size attribute */
5181 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5184 length = DW_UNSND (attr);
5192 index_type = builtin_type_int32;
5193 range_type = create_range_type (NULL, index_type, 1, length);
5194 char_type = language_string_char_type (cu->language_defn, gdbarch);
5195 type = create_string_type (NULL, char_type, range_type);
5197 return set_die_type (die, type, cu);
5200 /* Handle DIES due to C code like:
5204 int (*funcp)(int a, long l);
5208 ('funcp' generates a DW_TAG_subroutine_type DIE)
5211 static struct type *
5212 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
5214 struct type *type; /* Type that this function returns */
5215 struct type *ftype; /* Function that returns above type */
5216 struct attribute *attr;
5218 type = die_type (die, cu);
5219 ftype = make_function_type (type, (struct type **) 0, cu->objfile);
5221 /* All functions in C++, Pascal and Java have prototypes. */
5222 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
5223 if ((attr && (DW_UNSND (attr) != 0))
5224 || cu->language == language_cplus
5225 || cu->language == language_java
5226 || cu->language == language_pascal)
5227 TYPE_PROTOTYPED (ftype) = 1;
5229 /* Store the calling convention in the type if it's available in
5230 the subroutine die. Otherwise set the calling convention to
5231 the default value DW_CC_normal. */
5232 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
5233 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
5235 if (die->child != NULL)
5237 struct die_info *child_die;
5241 /* Count the number of parameters.
5242 FIXME: GDB currently ignores vararg functions, but knows about
5243 vararg member functions. */
5244 child_die = die->child;
5245 while (child_die && child_die->tag)
5247 if (child_die->tag == DW_TAG_formal_parameter)
5249 else if (child_die->tag == DW_TAG_unspecified_parameters)
5250 TYPE_VARARGS (ftype) = 1;
5251 child_die = sibling_die (child_die);
5254 /* Allocate storage for parameters and fill them in. */
5255 TYPE_NFIELDS (ftype) = nparams;
5256 TYPE_FIELDS (ftype) = (struct field *)
5257 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
5259 child_die = die->child;
5260 while (child_die && child_die->tag)
5262 if (child_die->tag == DW_TAG_formal_parameter)
5264 /* Dwarf2 has no clean way to discern C++ static and non-static
5265 member functions. G++ helps GDB by marking the first
5266 parameter for non-static member functions (which is the
5267 this pointer) as artificial. We pass this information
5268 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5269 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
5271 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
5273 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
5274 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
5277 child_die = sibling_die (child_die);
5281 return set_die_type (die, ftype, cu);
5284 static struct type *
5285 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
5287 struct objfile *objfile = cu->objfile;
5288 struct attribute *attr;
5289 const char *name = NULL;
5290 struct type *this_type;
5292 name = dwarf2_full_name (die, cu);
5293 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
5294 TYPE_FLAG_TARGET_STUB, NULL, objfile);
5295 TYPE_NAME (this_type) = (char *) name;
5296 set_die_type (die, this_type, cu);
5297 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
5301 /* Find a representation of a given base type and install
5302 it in the TYPE field of the die. */
5304 static struct type *
5305 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
5307 struct objfile *objfile = cu->objfile;
5309 struct attribute *attr;
5310 int encoding = 0, size = 0;
5312 enum type_code code = TYPE_CODE_INT;
5314 struct type *target_type = NULL;
5316 attr = dwarf2_attr (die, DW_AT_encoding, cu);
5319 encoding = DW_UNSND (attr);
5321 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5324 size = DW_UNSND (attr);
5326 name = dwarf2_name (die, cu);
5329 complaint (&symfile_complaints,
5330 _("DW_AT_name missing from DW_TAG_base_type"));
5335 case DW_ATE_address:
5336 /* Turn DW_ATE_address into a void * pointer. */
5337 code = TYPE_CODE_PTR;
5338 type_flags |= TYPE_FLAG_UNSIGNED;
5339 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
5341 case DW_ATE_boolean:
5342 code = TYPE_CODE_BOOL;
5343 type_flags |= TYPE_FLAG_UNSIGNED;
5345 case DW_ATE_complex_float:
5346 code = TYPE_CODE_COMPLEX;
5347 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
5349 case DW_ATE_decimal_float:
5350 code = TYPE_CODE_DECFLOAT;
5353 code = TYPE_CODE_FLT;
5357 case DW_ATE_unsigned:
5358 type_flags |= TYPE_FLAG_UNSIGNED;
5360 case DW_ATE_signed_char:
5361 if (cu->language == language_ada || cu->language == language_m2
5362 || cu->language == language_pascal)
5363 code = TYPE_CODE_CHAR;
5365 case DW_ATE_unsigned_char:
5366 if (cu->language == language_ada || cu->language == language_m2
5367 || cu->language == language_pascal)
5368 code = TYPE_CODE_CHAR;
5369 type_flags |= TYPE_FLAG_UNSIGNED;
5372 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
5373 dwarf_type_encoding_name (encoding));
5377 type = init_type (code, size, type_flags, NULL, objfile);
5378 TYPE_NAME (type) = name;
5379 TYPE_TARGET_TYPE (type) = target_type;
5381 if (name && strcmp (name, "char") == 0)
5382 TYPE_NOSIGN (type) = 1;
5384 return set_die_type (die, type, cu);
5387 /* Read the given DW_AT_subrange DIE. */
5389 static struct type *
5390 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5392 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5393 struct type *base_type;
5394 struct type *range_type;
5395 struct attribute *attr;
5400 base_type = die_type (die, cu);
5401 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
5403 complaint (&symfile_complaints,
5404 _("DW_AT_type missing from DW_TAG_subrange_type"));
5406 = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
5407 0, NULL, cu->objfile);
5410 if (cu->language == language_fortran)
5412 /* FORTRAN implies a lower bound of 1, if not given. */
5416 /* FIXME: For variable sized arrays either of these could be
5417 a variable rather than a constant value. We'll allow it,
5418 but we don't know how to handle it. */
5419 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
5421 low = dwarf2_get_attr_constant_value (attr, 0);
5423 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
5426 if (attr->form == DW_FORM_block1)
5428 /* GCC encodes arrays with unspecified or dynamic length
5429 with a DW_FORM_block1 attribute.
5430 FIXME: GDB does not yet know how to handle dynamic
5431 arrays properly, treat them as arrays with unspecified
5434 FIXME: jimb/2003-09-22: GDB does not really know
5435 how to handle arrays of unspecified length
5436 either; we just represent them as zero-length
5437 arrays. Choose an appropriate upper bound given
5438 the lower bound we've computed above. */
5442 high = dwarf2_get_attr_constant_value (attr, 1);
5445 range_type = create_range_type (NULL, base_type, low, high);
5447 name = dwarf2_name (die, cu);
5449 TYPE_NAME (range_type) = name;
5451 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5453 TYPE_LENGTH (range_type) = DW_UNSND (attr);
5455 return set_die_type (die, range_type, cu);
5458 static struct type *
5459 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
5463 /* For now, we only support the C meaning of an unspecified type: void. */
5465 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
5466 TYPE_NAME (type) = dwarf2_name (die, cu);
5468 return set_die_type (die, type, cu);
5471 /* Trivial hash function for die_info: the hash value of a DIE
5472 is its offset in .debug_info for this objfile. */
5475 die_hash (const void *item)
5477 const struct die_info *die = item;
5481 /* Trivial comparison function for die_info structures: two DIEs
5482 are equal if they have the same offset. */
5485 die_eq (const void *item_lhs, const void *item_rhs)
5487 const struct die_info *die_lhs = item_lhs;
5488 const struct die_info *die_rhs = item_rhs;
5489 return die_lhs->offset == die_rhs->offset;
5492 /* Read a whole compilation unit into a linked list of dies. */
5494 static struct die_info *
5495 read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
5498 = htab_create_alloc_ex (cu->header.length / 12,
5502 &cu->comp_unit_obstack,
5503 hashtab_obstack_allocate,
5504 dummy_obstack_deallocate);
5506 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
5509 /* Main entry point for reading a DIE and all children.
5510 Read the DIE and dump it if requested. */
5512 static struct die_info *
5513 read_die_and_children (gdb_byte *info_ptr, bfd *abfd,
5514 struct dwarf2_cu *cu,
5515 gdb_byte **new_info_ptr,
5516 struct die_info *parent)
5518 struct die_info *result = read_die_and_children_1 (info_ptr, abfd, cu,
5519 new_info_ptr, parent);
5521 if (dwarf2_die_debug)
5523 fprintf_unfiltered (gdb_stdlog, "Read die from .debug_info:\n");
5524 dump_die (result, dwarf2_die_debug);
5530 /* Read a single die and all its descendents. Set the die's sibling
5531 field to NULL; set other fields in the die correctly, and set all
5532 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5533 location of the info_ptr after reading all of those dies. PARENT
5534 is the parent of the die in question. */
5536 static struct die_info *
5537 read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd,
5538 struct dwarf2_cu *cu,
5539 gdb_byte **new_info_ptr,
5540 struct die_info *parent)
5542 struct die_info *die;
5546 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
5549 *new_info_ptr = cur_ptr;
5552 store_in_ref_table (die, cu);
5556 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
5562 *new_info_ptr = cur_ptr;
5565 die->sibling = NULL;
5566 die->parent = parent;
5570 /* Read a die, all of its descendents, and all of its siblings; set
5571 all of the fields of all of the dies correctly. Arguments are as
5572 in read_die_and_children. */
5574 static struct die_info *
5575 read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd,
5576 struct dwarf2_cu *cu,
5577 gdb_byte **new_info_ptr,
5578 struct die_info *parent)
5580 struct die_info *first_die, *last_sibling;
5584 first_die = last_sibling = NULL;
5588 struct die_info *die
5589 = read_die_and_children_1 (cur_ptr, abfd, cu, &cur_ptr, parent);
5593 *new_info_ptr = cur_ptr;
5600 last_sibling->sibling = die;
5606 /* In DWARF version 2, the description of the debugging information is
5607 stored in a separate .debug_abbrev section. Before we read any
5608 dies from a section we read in all abbreviations and install them
5609 in a hash table. This function also sets flags in CU describing
5610 the data found in the abbrev table. */
5613 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
5615 struct comp_unit_head *cu_header = &cu->header;
5616 gdb_byte *abbrev_ptr;
5617 struct abbrev_info *cur_abbrev;
5618 unsigned int abbrev_number, bytes_read, abbrev_name;
5619 unsigned int abbrev_form, hash_number;
5620 struct attr_abbrev *cur_attrs;
5621 unsigned int allocated_attrs;
5623 /* Initialize dwarf2 abbrevs */
5624 obstack_init (&cu->abbrev_obstack);
5625 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
5627 * sizeof (struct abbrev_info *)));
5628 memset (cu->dwarf2_abbrevs, 0,
5629 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
5631 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
5632 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5633 abbrev_ptr += bytes_read;
5635 allocated_attrs = ATTR_ALLOC_CHUNK;
5636 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
5638 /* loop until we reach an abbrev number of 0 */
5639 while (abbrev_number)
5641 cur_abbrev = dwarf_alloc_abbrev (cu);
5643 /* read in abbrev header */
5644 cur_abbrev->number = abbrev_number;
5645 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5646 abbrev_ptr += bytes_read;
5647 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
5650 if (cur_abbrev->tag == DW_TAG_namespace)
5651 cu->has_namespace_info = 1;
5653 /* now read in declarations */
5654 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5655 abbrev_ptr += bytes_read;
5656 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5657 abbrev_ptr += bytes_read;
5660 if (cur_abbrev->num_attrs == allocated_attrs)
5662 allocated_attrs += ATTR_ALLOC_CHUNK;
5664 = xrealloc (cur_attrs, (allocated_attrs
5665 * sizeof (struct attr_abbrev)));
5668 /* Record whether this compilation unit might have
5669 inter-compilation-unit references. If we don't know what form
5670 this attribute will have, then it might potentially be a
5671 DW_FORM_ref_addr, so we conservatively expect inter-CU
5674 if (abbrev_form == DW_FORM_ref_addr
5675 || abbrev_form == DW_FORM_indirect)
5676 cu->has_form_ref_addr = 1;
5678 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
5679 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
5680 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5681 abbrev_ptr += bytes_read;
5682 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5683 abbrev_ptr += bytes_read;
5686 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
5687 (cur_abbrev->num_attrs
5688 * sizeof (struct attr_abbrev)));
5689 memcpy (cur_abbrev->attrs, cur_attrs,
5690 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
5692 hash_number = abbrev_number % ABBREV_HASH_SIZE;
5693 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
5694 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
5696 /* Get next abbreviation.
5697 Under Irix6 the abbreviations for a compilation unit are not
5698 always properly terminated with an abbrev number of 0.
5699 Exit loop if we encounter an abbreviation which we have
5700 already read (which means we are about to read the abbreviations
5701 for the next compile unit) or if the end of the abbreviation
5702 table is reached. */
5703 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
5704 >= dwarf2_per_objfile->abbrev.size)
5706 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5707 abbrev_ptr += bytes_read;
5708 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
5715 /* Release the memory used by the abbrev table for a compilation unit. */
5718 dwarf2_free_abbrev_table (void *ptr_to_cu)
5720 struct dwarf2_cu *cu = ptr_to_cu;
5722 obstack_free (&cu->abbrev_obstack, NULL);
5723 cu->dwarf2_abbrevs = NULL;
5726 /* Lookup an abbrev_info structure in the abbrev hash table. */
5728 static struct abbrev_info *
5729 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
5731 unsigned int hash_number;
5732 struct abbrev_info *abbrev;
5734 hash_number = number % ABBREV_HASH_SIZE;
5735 abbrev = cu->dwarf2_abbrevs[hash_number];
5739 if (abbrev->number == number)
5742 abbrev = abbrev->next;
5747 /* Returns nonzero if TAG represents a type that we might generate a partial
5751 is_type_tag_for_partial (int tag)
5756 /* Some types that would be reasonable to generate partial symbols for,
5757 that we don't at present. */
5758 case DW_TAG_array_type:
5759 case DW_TAG_file_type:
5760 case DW_TAG_ptr_to_member_type:
5761 case DW_TAG_set_type:
5762 case DW_TAG_string_type:
5763 case DW_TAG_subroutine_type:
5765 case DW_TAG_base_type:
5766 case DW_TAG_class_type:
5767 case DW_TAG_interface_type:
5768 case DW_TAG_enumeration_type:
5769 case DW_TAG_structure_type:
5770 case DW_TAG_subrange_type:
5771 case DW_TAG_typedef:
5772 case DW_TAG_union_type:
5779 /* Load all DIEs that are interesting for partial symbols into memory. */
5781 static struct partial_die_info *
5782 load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab,
5783 struct dwarf2_cu *cu)
5785 struct partial_die_info *part_die;
5786 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
5787 struct abbrev_info *abbrev;
5788 unsigned int bytes_read;
5789 unsigned int load_all = 0;
5791 int nesting_level = 1;
5796 if (cu->per_cu && cu->per_cu->load_all_dies)
5800 = htab_create_alloc_ex (cu->header.length / 12,
5804 &cu->comp_unit_obstack,
5805 hashtab_obstack_allocate,
5806 dummy_obstack_deallocate);
5808 part_die = obstack_alloc (&cu->comp_unit_obstack,
5809 sizeof (struct partial_die_info));
5813 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
5815 /* A NULL abbrev means the end of a series of children. */
5818 if (--nesting_level == 0)
5820 /* PART_DIE was probably the last thing allocated on the
5821 comp_unit_obstack, so we could call obstack_free
5822 here. We don't do that because the waste is small,
5823 and will be cleaned up when we're done with this
5824 compilation unit. This way, we're also more robust
5825 against other users of the comp_unit_obstack. */
5828 info_ptr += bytes_read;
5829 last_die = parent_die;
5830 parent_die = parent_die->die_parent;
5834 /* Check whether this DIE is interesting enough to save. Normally
5835 we would not be interested in members here, but there may be
5836 later variables referencing them via DW_AT_specification (for
5839 && !is_type_tag_for_partial (abbrev->tag)
5840 && abbrev->tag != DW_TAG_enumerator
5841 && abbrev->tag != DW_TAG_subprogram
5842 && abbrev->tag != DW_TAG_lexical_block
5843 && abbrev->tag != DW_TAG_variable
5844 && abbrev->tag != DW_TAG_namespace
5845 && abbrev->tag != DW_TAG_member)
5847 /* Otherwise we skip to the next sibling, if any. */
5848 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
5852 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
5853 abfd, info_ptr, cu);
5855 /* This two-pass algorithm for processing partial symbols has a
5856 high cost in cache pressure. Thus, handle some simple cases
5857 here which cover the majority of C partial symbols. DIEs
5858 which neither have specification tags in them, nor could have
5859 specification tags elsewhere pointing at them, can simply be
5860 processed and discarded.
5862 This segment is also optional; scan_partial_symbols and
5863 add_partial_symbol will handle these DIEs if we chain
5864 them in normally. When compilers which do not emit large
5865 quantities of duplicate debug information are more common,
5866 this code can probably be removed. */
5868 /* Any complete simple types at the top level (pretty much all
5869 of them, for a language without namespaces), can be processed
5871 if (parent_die == NULL
5872 && part_die->has_specification == 0
5873 && part_die->is_declaration == 0
5874 && (part_die->tag == DW_TAG_typedef
5875 || part_die->tag == DW_TAG_base_type
5876 || part_die->tag == DW_TAG_subrange_type))
5878 if (building_psymtab && part_die->name != NULL)
5879 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5880 VAR_DOMAIN, LOC_TYPEDEF,
5881 &cu->objfile->static_psymbols,
5882 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5883 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5887 /* If we're at the second level, and we're an enumerator, and
5888 our parent has no specification (meaning possibly lives in a
5889 namespace elsewhere), then we can add the partial symbol now
5890 instead of queueing it. */
5891 if (part_die->tag == DW_TAG_enumerator
5892 && parent_die != NULL
5893 && parent_die->die_parent == NULL
5894 && parent_die->tag == DW_TAG_enumeration_type
5895 && parent_die->has_specification == 0)
5897 if (part_die->name == NULL)
5898 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
5899 else if (building_psymtab)
5900 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5901 VAR_DOMAIN, LOC_CONST,
5902 (cu->language == language_cplus
5903 || cu->language == language_java)
5904 ? &cu->objfile->global_psymbols
5905 : &cu->objfile->static_psymbols,
5906 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5908 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5912 /* We'll save this DIE so link it in. */
5913 part_die->die_parent = parent_die;
5914 part_die->die_sibling = NULL;
5915 part_die->die_child = NULL;
5917 if (last_die && last_die == parent_die)
5918 last_die->die_child = part_die;
5920 last_die->die_sibling = part_die;
5922 last_die = part_die;
5924 if (first_die == NULL)
5925 first_die = part_die;
5927 /* Maybe add the DIE to the hash table. Not all DIEs that we
5928 find interesting need to be in the hash table, because we
5929 also have the parent/sibling/child chains; only those that we
5930 might refer to by offset later during partial symbol reading.
5932 For now this means things that might have be the target of a
5933 DW_AT_specification, DW_AT_abstract_origin, or
5934 DW_AT_extension. DW_AT_extension will refer only to
5935 namespaces; DW_AT_abstract_origin refers to functions (and
5936 many things under the function DIE, but we do not recurse
5937 into function DIEs during partial symbol reading) and
5938 possibly variables as well; DW_AT_specification refers to
5939 declarations. Declarations ought to have the DW_AT_declaration
5940 flag. It happens that GCC forgets to put it in sometimes, but
5941 only for functions, not for types.
5943 Adding more things than necessary to the hash table is harmless
5944 except for the performance cost. Adding too few will result in
5945 wasted time in find_partial_die, when we reread the compilation
5946 unit with load_all_dies set. */
5949 || abbrev->tag == DW_TAG_subprogram
5950 || abbrev->tag == DW_TAG_variable
5951 || abbrev->tag == DW_TAG_namespace
5952 || part_die->is_declaration)
5956 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
5957 part_die->offset, INSERT);
5961 part_die = obstack_alloc (&cu->comp_unit_obstack,
5962 sizeof (struct partial_die_info));
5964 /* For some DIEs we want to follow their children (if any). For C
5965 we have no reason to follow the children of structures; for other
5966 languages we have to, both so that we can get at method physnames
5967 to infer fully qualified class names, and for DW_AT_specification.
5969 For Ada, we need to scan the children of subprograms and lexical
5970 blocks as well because Ada allows the definition of nested
5971 entities that could be interesting for the debugger, such as
5972 nested subprograms for instance. */
5973 if (last_die->has_children
5975 || last_die->tag == DW_TAG_namespace
5976 || last_die->tag == DW_TAG_enumeration_type
5977 || (cu->language != language_c
5978 && (last_die->tag == DW_TAG_class_type
5979 || last_die->tag == DW_TAG_interface_type
5980 || last_die->tag == DW_TAG_structure_type
5981 || last_die->tag == DW_TAG_union_type))
5982 || (cu->language == language_ada
5983 && (last_die->tag == DW_TAG_subprogram
5984 || last_die->tag == DW_TAG_lexical_block))))
5987 parent_die = last_die;
5991 /* Otherwise we skip to the next sibling, if any. */
5992 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
5994 /* Back to the top, do it again. */
5998 /* Read a minimal amount of information into the minimal die structure. */
6001 read_partial_die (struct partial_die_info *part_die,
6002 struct abbrev_info *abbrev,
6003 unsigned int abbrev_len, bfd *abfd,
6004 gdb_byte *info_ptr, struct dwarf2_cu *cu)
6006 unsigned int bytes_read, i;
6007 struct attribute attr;
6008 int has_low_pc_attr = 0;
6009 int has_high_pc_attr = 0;
6010 CORE_ADDR base_address = 0;
6014 base_address_low_pc,
6015 /* Overrides BASE_ADDRESS_LOW_PC. */
6016 base_address_entry_pc
6018 base_address_type = base_address_none;
6020 memset (part_die, 0, sizeof (struct partial_die_info));
6022 part_die->offset = info_ptr - dwarf2_per_objfile->info.buffer;
6024 info_ptr += abbrev_len;
6029 part_die->tag = abbrev->tag;
6030 part_die->has_children = abbrev->has_children;
6032 for (i = 0; i < abbrev->num_attrs; ++i)
6034 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
6036 /* Store the data if it is of an attribute we want to keep in a
6037 partial symbol table. */
6041 switch (part_die->tag)
6043 case DW_TAG_compile_unit:
6044 /* Compilation units have a DW_AT_name that is a filename, not
6045 a source language identifier. */
6046 case DW_TAG_enumeration_type:
6047 case DW_TAG_enumerator:
6048 /* These tags always have simple identifiers already; no need
6049 to canonicalize them. */
6050 part_die->name = DW_STRING (&attr);
6054 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
6055 &cu->comp_unit_obstack);
6059 case DW_AT_comp_dir:
6060 if (part_die->dirname == NULL)
6061 part_die->dirname = DW_STRING (&attr);
6063 case DW_AT_MIPS_linkage_name:
6064 part_die->name = DW_STRING (&attr);
6067 has_low_pc_attr = 1;
6068 part_die->lowpc = DW_ADDR (&attr);
6069 if (part_die->tag == DW_TAG_compile_unit
6070 && base_address_type < base_address_low_pc)
6072 base_address = DW_ADDR (&attr);
6073 base_address_type = base_address_low_pc;
6077 has_high_pc_attr = 1;
6078 part_die->highpc = DW_ADDR (&attr);
6080 case DW_AT_entry_pc:
6081 if (part_die->tag == DW_TAG_compile_unit
6082 && base_address_type < base_address_entry_pc)
6084 base_address = DW_ADDR (&attr);
6085 base_address_type = base_address_entry_pc;
6089 if (part_die->tag == DW_TAG_compile_unit)
6091 cu->ranges_offset = DW_UNSND (&attr);
6092 cu->has_ranges_offset = 1;
6095 case DW_AT_location:
6096 /* Support the .debug_loc offsets */
6097 if (attr_form_is_block (&attr))
6099 part_die->locdesc = DW_BLOCK (&attr);
6101 else if (attr_form_is_section_offset (&attr))
6103 dwarf2_complex_location_expr_complaint ();
6107 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6108 "partial symbol information");
6111 case DW_AT_language:
6112 part_die->language = DW_UNSND (&attr);
6114 case DW_AT_external:
6115 part_die->is_external = DW_UNSND (&attr);
6117 case DW_AT_declaration:
6118 part_die->is_declaration = DW_UNSND (&attr);
6121 part_die->has_type = 1;
6123 case DW_AT_abstract_origin:
6124 case DW_AT_specification:
6125 case DW_AT_extension:
6126 part_die->has_specification = 1;
6127 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
6130 /* Ignore absolute siblings, they might point outside of
6131 the current compile unit. */
6132 if (attr.form == DW_FORM_ref_addr)
6133 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
6135 part_die->sibling = dwarf2_per_objfile->info.buffer
6136 + dwarf2_get_ref_die_offset (&attr);
6138 case DW_AT_stmt_list:
6139 part_die->has_stmt_list = 1;
6140 part_die->line_offset = DW_UNSND (&attr);
6142 case DW_AT_byte_size:
6143 part_die->has_byte_size = 1;
6145 case DW_AT_calling_convention:
6146 /* DWARF doesn't provide a way to identify a program's source-level
6147 entry point. DW_AT_calling_convention attributes are only meant
6148 to describe functions' calling conventions.
6150 However, because it's a necessary piece of information in
6151 Fortran, and because DW_CC_program is the only piece of debugging
6152 information whose definition refers to a 'main program' at all,
6153 several compilers have begun marking Fortran main programs with
6154 DW_CC_program --- even when those functions use the standard
6155 calling conventions.
6157 So until DWARF specifies a way to provide this information and
6158 compilers pick up the new representation, we'll support this
6160 if (DW_UNSND (&attr) == DW_CC_program
6161 && cu->language == language_fortran)
6162 set_main_name (part_die->name);
6169 /* When using the GNU linker, .gnu.linkonce. sections are used to
6170 eliminate duplicate copies of functions and vtables and such.
6171 The linker will arbitrarily choose one and discard the others.
6172 The AT_*_pc values for such functions refer to local labels in
6173 these sections. If the section from that file was discarded, the
6174 labels are not in the output, so the relocs get a value of 0.
6175 If this is a discarded function, mark the pc bounds as invalid,
6176 so that GDB will ignore it. */
6177 if (has_low_pc_attr && has_high_pc_attr
6178 && part_die->lowpc < part_die->highpc
6179 && (part_die->lowpc != 0
6180 || dwarf2_per_objfile->has_section_at_zero))
6181 part_die->has_pc_info = 1;
6183 if (base_address_type != base_address_none && !cu->base_known)
6185 gdb_assert (part_die->tag == DW_TAG_compile_unit);
6187 cu->base_address = base_address;
6193 /* Find a cached partial DIE at OFFSET in CU. */
6195 static struct partial_die_info *
6196 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
6198 struct partial_die_info *lookup_die = NULL;
6199 struct partial_die_info part_die;
6201 part_die.offset = offset;
6202 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
6207 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6209 static struct partial_die_info *
6210 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
6212 struct dwarf2_per_cu_data *per_cu = NULL;
6213 struct partial_die_info *pd = NULL;
6215 if (offset_in_cu_p (&cu->header, offset))
6217 pd = find_partial_die_in_comp_unit (offset, cu);
6222 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
6224 if (per_cu->cu == NULL)
6226 load_comp_unit (per_cu, cu->objfile);
6227 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
6228 dwarf2_per_objfile->read_in_chain = per_cu;
6231 per_cu->cu->last_used = 0;
6232 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6234 if (pd == NULL && per_cu->load_all_dies == 0)
6236 struct cleanup *back_to;
6237 struct partial_die_info comp_unit_die;
6238 struct abbrev_info *abbrev;
6239 unsigned int bytes_read;
6242 per_cu->load_all_dies = 1;
6244 /* Re-read the DIEs. */
6245 back_to = make_cleanup (null_cleanup, 0);
6246 if (per_cu->cu->dwarf2_abbrevs == NULL)
6248 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
6249 back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
6251 info_ptr = (dwarf2_per_objfile->info.buffer
6252 + per_cu->cu->header.offset
6253 + per_cu->cu->header.first_die_offset);
6254 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
6255 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
6256 per_cu->cu->objfile->obfd, info_ptr,
6258 if (comp_unit_die.has_children)
6259 load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu);
6260 do_cleanups (back_to);
6262 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6266 internal_error (__FILE__, __LINE__,
6267 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6268 offset, bfd_get_filename (cu->objfile->obfd));
6272 /* Adjust PART_DIE before generating a symbol for it. This function
6273 may set the is_external flag or change the DIE's name. */
6276 fixup_partial_die (struct partial_die_info *part_die,
6277 struct dwarf2_cu *cu)
6279 /* If we found a reference attribute and the DIE has no name, try
6280 to find a name in the referred to DIE. */
6282 if (part_die->name == NULL && part_die->has_specification)
6284 struct partial_die_info *spec_die;
6286 spec_die = find_partial_die (part_die->spec_offset, cu);
6288 fixup_partial_die (spec_die, cu);
6292 part_die->name = spec_die->name;
6294 /* Copy DW_AT_external attribute if it is set. */
6295 if (spec_die->is_external)
6296 part_die->is_external = spec_die->is_external;
6300 /* Set default names for some unnamed DIEs. */
6301 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
6302 || part_die->tag == DW_TAG_class_type))
6303 part_die->name = "(anonymous class)";
6305 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
6306 part_die->name = "(anonymous namespace)";
6308 if (part_die->tag == DW_TAG_structure_type
6309 || part_die->tag == DW_TAG_class_type
6310 || part_die->tag == DW_TAG_union_type)
6311 guess_structure_name (part_die, cu);
6314 /* Read the die from the .debug_info section buffer. Set DIEP to
6315 point to a newly allocated die with its information, except for its
6316 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6317 whether the die has children or not. */
6320 read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr,
6321 struct dwarf2_cu *cu, int *has_children)
6323 unsigned int abbrev_number, bytes_read, i, offset;
6324 struct abbrev_info *abbrev;
6325 struct die_info *die;
6327 offset = info_ptr - dwarf2_per_objfile->info.buffer;
6328 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6329 info_ptr += bytes_read;
6337 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
6340 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6342 bfd_get_filename (abfd));
6344 die = dwarf_alloc_die (cu, abbrev->num_attrs);
6345 die->offset = offset;
6346 die->tag = abbrev->tag;
6347 die->abbrev = abbrev_number;
6349 die->num_attrs = abbrev->num_attrs;
6351 for (i = 0; i < abbrev->num_attrs; ++i)
6352 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
6353 abfd, info_ptr, cu);
6356 *has_children = abbrev->has_children;
6360 /* Read an attribute value described by an attribute form. */
6363 read_attribute_value (struct attribute *attr, unsigned form,
6364 bfd *abfd, gdb_byte *info_ptr,
6365 struct dwarf2_cu *cu)
6367 struct comp_unit_head *cu_header = &cu->header;
6368 unsigned int bytes_read;
6369 struct dwarf_block *blk;
6375 case DW_FORM_ref_addr:
6376 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
6377 info_ptr += bytes_read;
6379 case DW_FORM_block2:
6380 blk = dwarf_alloc_block (cu);
6381 blk->size = read_2_bytes (abfd, info_ptr);
6383 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6384 info_ptr += blk->size;
6385 DW_BLOCK (attr) = blk;
6387 case DW_FORM_block4:
6388 blk = dwarf_alloc_block (cu);
6389 blk->size = read_4_bytes (abfd, info_ptr);
6391 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6392 info_ptr += blk->size;
6393 DW_BLOCK (attr) = blk;
6396 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
6400 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
6404 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
6407 case DW_FORM_string:
6408 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
6409 info_ptr += bytes_read;
6412 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
6414 info_ptr += bytes_read;
6417 blk = dwarf_alloc_block (cu);
6418 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6419 info_ptr += bytes_read;
6420 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6421 info_ptr += blk->size;
6422 DW_BLOCK (attr) = blk;
6424 case DW_FORM_block1:
6425 blk = dwarf_alloc_block (cu);
6426 blk->size = read_1_byte (abfd, info_ptr);
6428 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6429 info_ptr += blk->size;
6430 DW_BLOCK (attr) = blk;
6433 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
6437 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
6441 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
6442 info_ptr += bytes_read;
6445 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6446 info_ptr += bytes_read;
6449 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
6453 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
6457 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
6461 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
6464 case DW_FORM_ref_udata:
6465 DW_ADDR (attr) = (cu->header.offset
6466 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
6467 info_ptr += bytes_read;
6469 case DW_FORM_indirect:
6470 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6471 info_ptr += bytes_read;
6472 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
6475 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6476 dwarf_form_name (form),
6477 bfd_get_filename (abfd));
6480 /* We have seen instances where the compiler tried to emit a byte
6481 size attribute of -1 which ended up being encoded as an unsigned
6482 0xffffffff. Although 0xffffffff is technically a valid size value,
6483 an object of this size seems pretty unlikely so we can relatively
6484 safely treat these cases as if the size attribute was invalid and
6485 treat them as zero by default. */
6486 if (attr->name == DW_AT_byte_size
6487 && form == DW_FORM_data4
6488 && DW_UNSND (attr) >= 0xffffffff)
6491 (&symfile_complaints,
6492 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6494 DW_UNSND (attr) = 0;
6500 /* Read an attribute described by an abbreviated attribute. */
6503 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
6504 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
6506 attr->name = abbrev->name;
6507 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
6510 /* read dwarf information from a buffer */
6513 read_1_byte (bfd *abfd, gdb_byte *buf)
6515 return bfd_get_8 (abfd, buf);
6519 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
6521 return bfd_get_signed_8 (abfd, buf);
6525 read_2_bytes (bfd *abfd, gdb_byte *buf)
6527 return bfd_get_16 (abfd, buf);
6531 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
6533 return bfd_get_signed_16 (abfd, buf);
6537 read_4_bytes (bfd *abfd, gdb_byte *buf)
6539 return bfd_get_32 (abfd, buf);
6543 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
6545 return bfd_get_signed_32 (abfd, buf);
6548 static unsigned long
6549 read_8_bytes (bfd *abfd, gdb_byte *buf)
6551 return bfd_get_64 (abfd, buf);
6555 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
6556 unsigned int *bytes_read)
6558 struct comp_unit_head *cu_header = &cu->header;
6559 CORE_ADDR retval = 0;
6561 if (cu_header->signed_addr_p)
6563 switch (cu_header->addr_size)
6566 retval = bfd_get_signed_16 (abfd, buf);
6569 retval = bfd_get_signed_32 (abfd, buf);
6572 retval = bfd_get_signed_64 (abfd, buf);
6575 internal_error (__FILE__, __LINE__,
6576 _("read_address: bad switch, signed [in module %s]"),
6577 bfd_get_filename (abfd));
6582 switch (cu_header->addr_size)
6585 retval = bfd_get_16 (abfd, buf);
6588 retval = bfd_get_32 (abfd, buf);
6591 retval = bfd_get_64 (abfd, buf);
6594 internal_error (__FILE__, __LINE__,
6595 _("read_address: bad switch, unsigned [in module %s]"),
6596 bfd_get_filename (abfd));
6600 *bytes_read = cu_header->addr_size;
6604 /* Read the initial length from a section. The (draft) DWARF 3
6605 specification allows the initial length to take up either 4 bytes
6606 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6607 bytes describe the length and all offsets will be 8 bytes in length
6610 An older, non-standard 64-bit format is also handled by this
6611 function. The older format in question stores the initial length
6612 as an 8-byte quantity without an escape value. Lengths greater
6613 than 2^32 aren't very common which means that the initial 4 bytes
6614 is almost always zero. Since a length value of zero doesn't make
6615 sense for the 32-bit format, this initial zero can be considered to
6616 be an escape value which indicates the presence of the older 64-bit
6617 format. As written, the code can't detect (old format) lengths
6618 greater than 4GB. If it becomes necessary to handle lengths
6619 somewhat larger than 4GB, we could allow other small values (such
6620 as the non-sensical values of 1, 2, and 3) to also be used as
6621 escape values indicating the presence of the old format.
6623 The value returned via bytes_read should be used to increment the
6624 relevant pointer after calling read_initial_length().
6626 [ Note: read_initial_length() and read_offset() are based on the
6627 document entitled "DWARF Debugging Information Format", revision
6628 3, draft 8, dated November 19, 2001. This document was obtained
6631 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6633 This document is only a draft and is subject to change. (So beware.)
6635 Details regarding the older, non-standard 64-bit format were
6636 determined empirically by examining 64-bit ELF files produced by
6637 the SGI toolchain on an IRIX 6.5 machine.
6639 - Kevin, July 16, 2002
6643 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
6645 LONGEST length = bfd_get_32 (abfd, buf);
6647 if (length == 0xffffffff)
6649 length = bfd_get_64 (abfd, buf + 4);
6652 else if (length == 0)
6654 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6655 length = bfd_get_64 (abfd, buf);
6666 /* Cover function for read_initial_length.
6667 Returns the length of the object at BUF, and stores the size of the
6668 initial length in *BYTES_READ and stores the size that offsets will be in
6670 If the initial length size is not equivalent to that specified in
6671 CU_HEADER then issue a complaint.
6672 This is useful when reading non-comp-unit headers. */
6675 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
6676 const struct comp_unit_head *cu_header,
6677 unsigned int *bytes_read,
6678 unsigned int *offset_size)
6680 LONGEST length = read_initial_length (abfd, buf, bytes_read);
6682 gdb_assert (cu_header->initial_length_size == 4
6683 || cu_header->initial_length_size == 8
6684 || cu_header->initial_length_size == 12);
6686 if (cu_header->initial_length_size != *bytes_read)
6687 complaint (&symfile_complaints,
6688 _("intermixed 32-bit and 64-bit DWARF sections"));
6690 *offset_size = (*bytes_read == 4) ? 4 : 8;
6694 /* Read an offset from the data stream. The size of the offset is
6695 given by cu_header->offset_size. */
6698 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
6699 unsigned int *bytes_read)
6701 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
6702 *bytes_read = cu_header->offset_size;
6706 /* Read an offset from the data stream. */
6709 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
6713 switch (offset_size)
6716 retval = bfd_get_32 (abfd, buf);
6719 retval = bfd_get_64 (abfd, buf);
6722 internal_error (__FILE__, __LINE__,
6723 _("read_offset_1: bad switch [in module %s]"),
6724 bfd_get_filename (abfd));
6731 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
6733 /* If the size of a host char is 8 bits, we can return a pointer
6734 to the buffer, otherwise we have to copy the data to a buffer
6735 allocated on the temporary obstack. */
6736 gdb_assert (HOST_CHAR_BIT == 8);
6741 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6743 /* If the size of a host char is 8 bits, we can return a pointer
6744 to the string, otherwise we have to copy the string to a buffer
6745 allocated on the temporary obstack. */
6746 gdb_assert (HOST_CHAR_BIT == 8);
6749 *bytes_read_ptr = 1;
6752 *bytes_read_ptr = strlen ((char *) buf) + 1;
6753 return (char *) buf;
6757 read_indirect_string (bfd *abfd, gdb_byte *buf,
6758 const struct comp_unit_head *cu_header,
6759 unsigned int *bytes_read_ptr)
6761 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
6763 if (dwarf2_per_objfile->str.buffer == NULL)
6765 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6766 bfd_get_filename (abfd));
6769 if (str_offset >= dwarf2_per_objfile->str.size)
6771 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6772 bfd_get_filename (abfd));
6775 gdb_assert (HOST_CHAR_BIT == 8);
6776 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
6778 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
6781 static unsigned long
6782 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6784 unsigned long result;
6785 unsigned int num_read;
6795 byte = bfd_get_8 (abfd, buf);
6798 result |= ((unsigned long)(byte & 127) << shift);
6799 if ((byte & 128) == 0)
6805 *bytes_read_ptr = num_read;
6810 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6813 int i, shift, num_read;
6822 byte = bfd_get_8 (abfd, buf);
6825 result |= ((long)(byte & 127) << shift);
6827 if ((byte & 128) == 0)
6832 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
6833 result |= -(((long)1) << shift);
6834 *bytes_read_ptr = num_read;
6838 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6841 skip_leb128 (bfd *abfd, gdb_byte *buf)
6847 byte = bfd_get_8 (abfd, buf);
6849 if ((byte & 128) == 0)
6855 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
6862 cu->language = language_c;
6864 case DW_LANG_C_plus_plus:
6865 cu->language = language_cplus;
6867 case DW_LANG_Fortran77:
6868 case DW_LANG_Fortran90:
6869 case DW_LANG_Fortran95:
6870 cu->language = language_fortran;
6872 case DW_LANG_Mips_Assembler:
6873 cu->language = language_asm;
6876 cu->language = language_java;
6880 cu->language = language_ada;
6882 case DW_LANG_Modula2:
6883 cu->language = language_m2;
6885 case DW_LANG_Pascal83:
6886 cu->language = language_pascal;
6889 cu->language = language_objc;
6891 case DW_LANG_Cobol74:
6892 case DW_LANG_Cobol85:
6894 cu->language = language_minimal;
6897 cu->language_defn = language_def (cu->language);
6900 /* Return the named attribute or NULL if not there. */
6902 static struct attribute *
6903 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
6906 struct attribute *spec = NULL;
6908 for (i = 0; i < die->num_attrs; ++i)
6910 if (die->attrs[i].name == name)
6911 return &die->attrs[i];
6912 if (die->attrs[i].name == DW_AT_specification
6913 || die->attrs[i].name == DW_AT_abstract_origin)
6914 spec = &die->attrs[i];
6919 die = follow_die_ref (die, spec, &cu);
6920 return dwarf2_attr (die, name, cu);
6926 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6927 and holds a non-zero value. This function should only be used for
6928 DW_FORM_flag attributes. */
6931 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
6933 struct attribute *attr = dwarf2_attr (die, name, cu);
6935 return (attr && DW_UNSND (attr));
6939 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
6941 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6942 which value is non-zero. However, we have to be careful with
6943 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6944 (via dwarf2_flag_true_p) follows this attribute. So we may
6945 end up accidently finding a declaration attribute that belongs
6946 to a different DIE referenced by the specification attribute,
6947 even though the given DIE does not have a declaration attribute. */
6948 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
6949 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
6952 /* Return the die giving the specification for DIE, if there is
6953 one. *SPEC_CU is the CU containing DIE on input, and the CU
6954 containing the return value on output. */
6956 static struct die_info *
6957 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
6959 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
6962 if (spec_attr == NULL)
6965 return follow_die_ref (die, spec_attr, spec_cu);
6968 /* Free the line_header structure *LH, and any arrays and strings it
6971 free_line_header (struct line_header *lh)
6973 if (lh->standard_opcode_lengths)
6974 xfree (lh->standard_opcode_lengths);
6976 /* Remember that all the lh->file_names[i].name pointers are
6977 pointers into debug_line_buffer, and don't need to be freed. */
6979 xfree (lh->file_names);
6981 /* Similarly for the include directory names. */
6982 if (lh->include_dirs)
6983 xfree (lh->include_dirs);
6989 /* Add an entry to LH's include directory table. */
6991 add_include_dir (struct line_header *lh, char *include_dir)
6993 /* Grow the array if necessary. */
6994 if (lh->include_dirs_size == 0)
6996 lh->include_dirs_size = 1; /* for testing */
6997 lh->include_dirs = xmalloc (lh->include_dirs_size
6998 * sizeof (*lh->include_dirs));
7000 else if (lh->num_include_dirs >= lh->include_dirs_size)
7002 lh->include_dirs_size *= 2;
7003 lh->include_dirs = xrealloc (lh->include_dirs,
7004 (lh->include_dirs_size
7005 * sizeof (*lh->include_dirs)));
7008 lh->include_dirs[lh->num_include_dirs++] = include_dir;
7012 /* Add an entry to LH's file name table. */
7014 add_file_name (struct line_header *lh,
7016 unsigned int dir_index,
7017 unsigned int mod_time,
7018 unsigned int length)
7020 struct file_entry *fe;
7022 /* Grow the array if necessary. */
7023 if (lh->file_names_size == 0)
7025 lh->file_names_size = 1; /* for testing */
7026 lh->file_names = xmalloc (lh->file_names_size
7027 * sizeof (*lh->file_names));
7029 else if (lh->num_file_names >= lh->file_names_size)
7031 lh->file_names_size *= 2;
7032 lh->file_names = xrealloc (lh->file_names,
7033 (lh->file_names_size
7034 * sizeof (*lh->file_names)));
7037 fe = &lh->file_names[lh->num_file_names++];
7039 fe->dir_index = dir_index;
7040 fe->mod_time = mod_time;
7041 fe->length = length;
7047 /* Read the statement program header starting at OFFSET in
7048 .debug_line, according to the endianness of ABFD. Return a pointer
7049 to a struct line_header, allocated using xmalloc.
7051 NOTE: the strings in the include directory and file name tables of
7052 the returned object point into debug_line_buffer, and must not be
7054 static struct line_header *
7055 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
7056 struct dwarf2_cu *cu)
7058 struct cleanup *back_to;
7059 struct line_header *lh;
7061 unsigned int bytes_read, offset_size;
7063 char *cur_dir, *cur_file;
7065 if (dwarf2_per_objfile->line.buffer == NULL)
7067 complaint (&symfile_complaints, _("missing .debug_line section"));
7071 /* Make sure that at least there's room for the total_length field.
7072 That could be 12 bytes long, but we're just going to fudge that. */
7073 if (offset + 4 >= dwarf2_per_objfile->line.size)
7075 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7079 lh = xmalloc (sizeof (*lh));
7080 memset (lh, 0, sizeof (*lh));
7081 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
7084 line_ptr = dwarf2_per_objfile->line.buffer + offset;
7086 /* Read in the header. */
7088 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
7089 &bytes_read, &offset_size);
7090 line_ptr += bytes_read;
7091 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
7092 + dwarf2_per_objfile->line.size))
7094 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7097 lh->statement_program_end = line_ptr + lh->total_length;
7098 lh->version = read_2_bytes (abfd, line_ptr);
7100 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
7101 line_ptr += offset_size;
7102 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
7104 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
7106 lh->line_base = read_1_signed_byte (abfd, line_ptr);
7108 lh->line_range = read_1_byte (abfd, line_ptr);
7110 lh->opcode_base = read_1_byte (abfd, line_ptr);
7112 lh->standard_opcode_lengths
7113 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
7115 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
7116 for (i = 1; i < lh->opcode_base; ++i)
7118 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
7122 /* Read directory table. */
7123 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7125 line_ptr += bytes_read;
7126 add_include_dir (lh, cur_dir);
7128 line_ptr += bytes_read;
7130 /* Read file name table. */
7131 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7133 unsigned int dir_index, mod_time, length;
7135 line_ptr += bytes_read;
7136 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7137 line_ptr += bytes_read;
7138 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7139 line_ptr += bytes_read;
7140 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7141 line_ptr += bytes_read;
7143 add_file_name (lh, cur_file, dir_index, mod_time, length);
7145 line_ptr += bytes_read;
7146 lh->statement_program_start = line_ptr;
7148 if (line_ptr > (dwarf2_per_objfile->line.buffer
7149 + dwarf2_per_objfile->line.size))
7150 complaint (&symfile_complaints,
7151 _("line number info header doesn't fit in `.debug_line' section"));
7153 discard_cleanups (back_to);
7157 /* This function exists to work around a bug in certain compilers
7158 (particularly GCC 2.95), in which the first line number marker of a
7159 function does not show up until after the prologue, right before
7160 the second line number marker. This function shifts ADDRESS down
7161 to the beginning of the function if necessary, and is called on
7162 addresses passed to record_line. */
7165 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
7167 struct function_range *fn;
7169 /* Find the function_range containing address. */
7174 cu->cached_fn = cu->first_fn;
7178 if (fn->lowpc <= address && fn->highpc > address)
7184 while (fn && fn != cu->cached_fn)
7185 if (fn->lowpc <= address && fn->highpc > address)
7195 if (address != fn->lowpc)
7196 complaint (&symfile_complaints,
7197 _("misplaced first line number at 0x%lx for '%s'"),
7198 (unsigned long) address, fn->name);
7203 /* Decode the Line Number Program (LNP) for the given line_header
7204 structure and CU. The actual information extracted and the type
7205 of structures created from the LNP depends on the value of PST.
7207 1. If PST is NULL, then this procedure uses the data from the program
7208 to create all necessary symbol tables, and their linetables.
7209 The compilation directory of the file is passed in COMP_DIR,
7210 and must not be NULL.
7212 2. If PST is not NULL, this procedure reads the program to determine
7213 the list of files included by the unit represented by PST, and
7214 builds all the associated partial symbol tables. In this case,
7215 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7216 is not used to compute the full name of the symtab, and therefore
7217 omitting it when building the partial symtab does not introduce
7218 the potential for inconsistency - a partial symtab and its associated
7219 symbtab having a different fullname -). */
7222 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
7223 struct dwarf2_cu *cu, struct partial_symtab *pst)
7225 gdb_byte *line_ptr, *extended_end;
7227 unsigned int bytes_read, extended_len;
7228 unsigned char op_code, extended_op, adj_opcode;
7230 struct objfile *objfile = cu->objfile;
7231 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7232 const int decode_for_pst_p = (pst != NULL);
7233 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
7235 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7237 line_ptr = lh->statement_program_start;
7238 line_end = lh->statement_program_end;
7240 /* Read the statement sequences until there's nothing left. */
7241 while (line_ptr < line_end)
7243 /* state machine registers */
7244 CORE_ADDR address = 0;
7245 unsigned int file = 1;
7246 unsigned int line = 1;
7247 unsigned int column = 0;
7248 int is_stmt = lh->default_is_stmt;
7249 int basic_block = 0;
7250 int end_sequence = 0;
7253 if (!decode_for_pst_p && lh->num_file_names >= file)
7255 /* Start a subfile for the current file of the state machine. */
7256 /* lh->include_dirs and lh->file_names are 0-based, but the
7257 directory and file name numbers in the statement program
7259 struct file_entry *fe = &lh->file_names[file - 1];
7263 dir = lh->include_dirs[fe->dir_index - 1];
7265 dwarf2_start_subfile (fe->name, dir, comp_dir);
7268 /* Decode the table. */
7269 while (!end_sequence)
7271 op_code = read_1_byte (abfd, line_ptr);
7273 if (line_ptr > line_end)
7275 dwarf2_debug_line_missing_end_sequence_complaint ();
7279 if (op_code >= lh->opcode_base)
7281 /* Special operand. */
7282 adj_opcode = op_code - lh->opcode_base;
7283 address += (adj_opcode / lh->line_range)
7284 * lh->minimum_instruction_length;
7285 line += lh->line_base + (adj_opcode % lh->line_range);
7286 if (lh->num_file_names < file || file == 0)
7287 dwarf2_debug_line_missing_file_complaint ();
7290 lh->file_names[file - 1].included_p = 1;
7291 if (!decode_for_pst_p)
7293 if (last_subfile != current_subfile)
7295 addr = gdbarch_addr_bits_remove (gdbarch, address);
7297 record_line (last_subfile, 0, addr);
7298 last_subfile = current_subfile;
7300 /* Append row to matrix using current values. */
7301 addr = check_cu_functions (address, cu);
7302 addr = gdbarch_addr_bits_remove (gdbarch, addr);
7303 record_line (current_subfile, line, addr);
7308 else switch (op_code)
7310 case DW_LNS_extended_op:
7311 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7312 line_ptr += bytes_read;
7313 extended_end = line_ptr + extended_len;
7314 extended_op = read_1_byte (abfd, line_ptr);
7316 switch (extended_op)
7318 case DW_LNE_end_sequence:
7321 case DW_LNE_set_address:
7322 address = read_address (abfd, line_ptr, cu, &bytes_read);
7323 line_ptr += bytes_read;
7324 address += baseaddr;
7326 case DW_LNE_define_file:
7329 unsigned int dir_index, mod_time, length;
7331 cur_file = read_string (abfd, line_ptr, &bytes_read);
7332 line_ptr += bytes_read;
7334 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7335 line_ptr += bytes_read;
7337 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7338 line_ptr += bytes_read;
7340 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7341 line_ptr += bytes_read;
7342 add_file_name (lh, cur_file, dir_index, mod_time, length);
7345 case DW_LNE_set_discriminator:
7346 /* The discriminator is not interesting to the debugger;
7348 line_ptr = extended_end;
7351 complaint (&symfile_complaints,
7352 _("mangled .debug_line section"));
7355 /* Make sure that we parsed the extended op correctly. If e.g.
7356 we expected a different address size than the producer used,
7357 we may have read the wrong number of bytes. */
7358 if (line_ptr != extended_end)
7360 complaint (&symfile_complaints,
7361 _("mangled .debug_line section"));
7366 if (lh->num_file_names < file || file == 0)
7367 dwarf2_debug_line_missing_file_complaint ();
7370 lh->file_names[file - 1].included_p = 1;
7371 if (!decode_for_pst_p)
7373 if (last_subfile != current_subfile)
7375 addr = gdbarch_addr_bits_remove (gdbarch, address);
7377 record_line (last_subfile, 0, addr);
7378 last_subfile = current_subfile;
7380 addr = check_cu_functions (address, cu);
7381 addr = gdbarch_addr_bits_remove (gdbarch, addr);
7382 record_line (current_subfile, line, addr);
7387 case DW_LNS_advance_pc:
7388 address += lh->minimum_instruction_length
7389 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7390 line_ptr += bytes_read;
7392 case DW_LNS_advance_line:
7393 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
7394 line_ptr += bytes_read;
7396 case DW_LNS_set_file:
7398 /* The arrays lh->include_dirs and lh->file_names are
7399 0-based, but the directory and file name numbers in
7400 the statement program are 1-based. */
7401 struct file_entry *fe;
7404 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7405 line_ptr += bytes_read;
7406 if (lh->num_file_names < file || file == 0)
7407 dwarf2_debug_line_missing_file_complaint ();
7410 fe = &lh->file_names[file - 1];
7412 dir = lh->include_dirs[fe->dir_index - 1];
7413 if (!decode_for_pst_p)
7415 last_subfile = current_subfile;
7416 dwarf2_start_subfile (fe->name, dir, comp_dir);
7421 case DW_LNS_set_column:
7422 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7423 line_ptr += bytes_read;
7425 case DW_LNS_negate_stmt:
7426 is_stmt = (!is_stmt);
7428 case DW_LNS_set_basic_block:
7431 /* Add to the address register of the state machine the
7432 address increment value corresponding to special opcode
7433 255. I.e., this value is scaled by the minimum
7434 instruction length since special opcode 255 would have
7435 scaled the the increment. */
7436 case DW_LNS_const_add_pc:
7437 address += (lh->minimum_instruction_length
7438 * ((255 - lh->opcode_base) / lh->line_range));
7440 case DW_LNS_fixed_advance_pc:
7441 address += read_2_bytes (abfd, line_ptr);
7446 /* Unknown standard opcode, ignore it. */
7449 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
7451 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7452 line_ptr += bytes_read;
7457 if (lh->num_file_names < file || file == 0)
7458 dwarf2_debug_line_missing_file_complaint ();
7461 lh->file_names[file - 1].included_p = 1;
7462 if (!decode_for_pst_p)
7464 addr = gdbarch_addr_bits_remove (gdbarch, address);
7465 record_line (current_subfile, 0, addr);
7470 if (decode_for_pst_p)
7474 /* Now that we're done scanning the Line Header Program, we can
7475 create the psymtab of each included file. */
7476 for (file_index = 0; file_index < lh->num_file_names; file_index++)
7477 if (lh->file_names[file_index].included_p == 1)
7479 const struct file_entry fe = lh->file_names [file_index];
7480 char *include_name = fe.name;
7481 char *dir_name = NULL;
7482 char *pst_filename = pst->filename;
7485 dir_name = lh->include_dirs[fe.dir_index - 1];
7487 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
7489 include_name = concat (dir_name, SLASH_STRING,
7490 include_name, (char *)NULL);
7491 make_cleanup (xfree, include_name);
7494 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
7496 pst_filename = concat (pst->dirname, SLASH_STRING,
7497 pst_filename, (char *)NULL);
7498 make_cleanup (xfree, pst_filename);
7501 if (strcmp (include_name, pst_filename) != 0)
7502 dwarf2_create_include_psymtab (include_name, pst, objfile);
7507 /* Make sure a symtab is created for every file, even files
7508 which contain only variables (i.e. no code with associated
7512 struct file_entry *fe;
7514 for (i = 0; i < lh->num_file_names; i++)
7517 fe = &lh->file_names[i];
7519 dir = lh->include_dirs[fe->dir_index - 1];
7520 dwarf2_start_subfile (fe->name, dir, comp_dir);
7522 /* Skip the main file; we don't need it, and it must be
7523 allocated last, so that it will show up before the
7524 non-primary symtabs in the objfile's symtab list. */
7525 if (current_subfile == first_subfile)
7528 if (current_subfile->symtab == NULL)
7529 current_subfile->symtab = allocate_symtab (current_subfile->name,
7531 fe->symtab = current_subfile->symtab;
7536 /* Start a subfile for DWARF. FILENAME is the name of the file and
7537 DIRNAME the name of the source directory which contains FILENAME
7538 or NULL if not known. COMP_DIR is the compilation directory for the
7539 linetable's compilation unit or NULL if not known.
7540 This routine tries to keep line numbers from identical absolute and
7541 relative file names in a common subfile.
7543 Using the `list' example from the GDB testsuite, which resides in
7544 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7545 of /srcdir/list0.c yields the following debugging information for list0.c:
7547 DW_AT_name: /srcdir/list0.c
7548 DW_AT_comp_dir: /compdir
7549 files.files[0].name: list0.h
7550 files.files[0].dir: /srcdir
7551 files.files[1].name: list0.c
7552 files.files[1].dir: /srcdir
7554 The line number information for list0.c has to end up in a single
7555 subfile, so that `break /srcdir/list0.c:1' works as expected.
7556 start_subfile will ensure that this happens provided that we pass the
7557 concatenation of files.files[1].dir and files.files[1].name as the
7561 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
7565 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7566 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7567 second argument to start_subfile. To be consistent, we do the
7568 same here. In order not to lose the line information directory,
7569 we concatenate it to the filename when it makes sense.
7570 Note that the Dwarf3 standard says (speaking of filenames in line
7571 information): ``The directory index is ignored for file names
7572 that represent full path names''. Thus ignoring dirname in the
7573 `else' branch below isn't an issue. */
7575 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
7576 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
7578 fullname = filename;
7580 start_subfile (fullname, comp_dir);
7582 if (fullname != filename)
7587 var_decode_location (struct attribute *attr, struct symbol *sym,
7588 struct dwarf2_cu *cu)
7590 struct objfile *objfile = cu->objfile;
7591 struct comp_unit_head *cu_header = &cu->header;
7593 /* NOTE drow/2003-01-30: There used to be a comment and some special
7594 code here to turn a symbol with DW_AT_external and a
7595 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7596 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7597 with some versions of binutils) where shared libraries could have
7598 relocations against symbols in their debug information - the
7599 minimal symbol would have the right address, but the debug info
7600 would not. It's no longer necessary, because we will explicitly
7601 apply relocations when we read in the debug information now. */
7603 /* A DW_AT_location attribute with no contents indicates that a
7604 variable has been optimized away. */
7605 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
7607 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7611 /* Handle one degenerate form of location expression specially, to
7612 preserve GDB's previous behavior when section offsets are
7613 specified. If this is just a DW_OP_addr then mark this symbol
7616 if (attr_form_is_block (attr)
7617 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
7618 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
7622 SYMBOL_VALUE_ADDRESS (sym) =
7623 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
7624 SYMBOL_CLASS (sym) = LOC_STATIC;
7625 fixup_symbol_section (sym, objfile);
7626 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
7627 SYMBOL_SECTION (sym));
7631 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7632 expression evaluator, and use LOC_COMPUTED only when necessary
7633 (i.e. when the value of a register or memory location is
7634 referenced, or a thread-local block, etc.). Then again, it might
7635 not be worthwhile. I'm assuming that it isn't unless performance
7636 or memory numbers show me otherwise. */
7638 dwarf2_symbol_mark_computed (attr, sym, cu);
7639 SYMBOL_CLASS (sym) = LOC_COMPUTED;
7642 /* Given a pointer to a DWARF information entry, figure out if we need
7643 to make a symbol table entry for it, and if so, create a new entry
7644 and return a pointer to it.
7645 If TYPE is NULL, determine symbol type from the die, otherwise
7646 used the passed type. */
7648 static struct symbol *
7649 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
7651 struct objfile *objfile = cu->objfile;
7652 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7653 struct symbol *sym = NULL;
7655 struct attribute *attr = NULL;
7656 struct attribute *attr2 = NULL;
7659 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7661 if (die->tag != DW_TAG_namespace)
7662 name = dwarf2_linkage_name (die, cu);
7664 name = TYPE_NAME (type);
7668 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
7669 sizeof (struct symbol));
7670 OBJSTAT (objfile, n_syms++);
7671 memset (sym, 0, sizeof (struct symbol));
7673 /* Cache this symbol's name and the name's demangled form (if any). */
7674 SYMBOL_LANGUAGE (sym) = cu->language;
7675 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
7677 /* Default assumptions.
7678 Use the passed type or decode it from the die. */
7679 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7680 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7682 SYMBOL_TYPE (sym) = type;
7684 SYMBOL_TYPE (sym) = die_type (die, cu);
7685 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
7688 SYMBOL_LINE (sym) = DW_UNSND (attr);
7691 attr = dwarf2_attr (die, DW_AT_decl_file, cu);
7694 int file_index = DW_UNSND (attr);
7695 if (cu->line_header == NULL
7696 || file_index > cu->line_header->num_file_names)
7697 complaint (&symfile_complaints,
7698 _("file index out of range"));
7699 else if (file_index > 0)
7701 struct file_entry *fe;
7702 fe = &cu->line_header->file_names[file_index - 1];
7703 SYMBOL_SYMTAB (sym) = fe->symtab;
7710 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
7713 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
7715 SYMBOL_CLASS (sym) = LOC_LABEL;
7717 case DW_TAG_subprogram:
7718 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7720 SYMBOL_CLASS (sym) = LOC_BLOCK;
7721 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7722 if ((attr2 && (DW_UNSND (attr2) != 0))
7723 || cu->language == language_ada)
7725 /* Subprograms marked external are stored as a global symbol.
7726 Ada subprograms, whether marked external or not, are always
7727 stored as a global symbol, because we want to be able to
7728 access them globally. For instance, we want to be able
7729 to break on a nested subprogram without having to
7730 specify the context. */
7731 add_symbol_to_list (sym, &global_symbols);
7735 add_symbol_to_list (sym, cu->list_in_scope);
7738 case DW_TAG_variable:
7739 /* Compilation with minimal debug info may result in variables
7740 with missing type entries. Change the misleading `void' type
7741 to something sensible. */
7742 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
7744 = builtin_type (gdbarch)->nodebug_data_symbol;
7746 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7749 dwarf2_const_value (attr, sym, cu);
7750 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7751 if (attr2 && (DW_UNSND (attr2) != 0))
7752 add_symbol_to_list (sym, &global_symbols);
7754 add_symbol_to_list (sym, cu->list_in_scope);
7757 attr = dwarf2_attr (die, DW_AT_location, cu);
7760 var_decode_location (attr, sym, cu);
7761 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7762 if (attr2 && (DW_UNSND (attr2) != 0))
7763 add_symbol_to_list (sym, &global_symbols);
7765 add_symbol_to_list (sym, cu->list_in_scope);
7769 /* We do not know the address of this symbol.
7770 If it is an external symbol and we have type information
7771 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7772 The address of the variable will then be determined from
7773 the minimal symbol table whenever the variable is
7775 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7776 if (attr2 && (DW_UNSND (attr2) != 0)
7777 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
7779 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
7780 add_symbol_to_list (sym, cu->list_in_scope);
7782 else if (!die_is_declaration (die, cu))
7784 /* Use the default LOC_OPTIMIZED_OUT class. */
7785 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
7786 add_symbol_to_list (sym, cu->list_in_scope);
7790 case DW_TAG_formal_parameter:
7791 SYMBOL_IS_ARGUMENT (sym) = 1;
7792 attr = dwarf2_attr (die, DW_AT_location, cu);
7795 var_decode_location (attr, sym, cu);
7797 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7800 dwarf2_const_value (attr, sym, cu);
7802 add_symbol_to_list (sym, cu->list_in_scope);
7804 case DW_TAG_unspecified_parameters:
7805 /* From varargs functions; gdb doesn't seem to have any
7806 interest in this information, so just ignore it for now.
7809 case DW_TAG_class_type:
7810 case DW_TAG_interface_type:
7811 case DW_TAG_structure_type:
7812 case DW_TAG_union_type:
7813 case DW_TAG_set_type:
7814 case DW_TAG_enumeration_type:
7815 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7816 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
7818 /* Make sure that the symbol includes appropriate enclosing
7819 classes/namespaces in its name. These are calculated in
7820 read_structure_type, and the correct name is saved in
7823 if (cu->language == language_cplus
7824 || cu->language == language_java)
7826 struct type *type = SYMBOL_TYPE (sym);
7828 if (TYPE_TAG_NAME (type) != NULL)
7830 /* FIXME: carlton/2003-11-10: Should this use
7831 SYMBOL_SET_NAMES instead? (The same problem also
7832 arises further down in this function.) */
7833 /* The type's name is already allocated along with
7834 this objfile, so we don't need to duplicate it
7836 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
7841 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7842 really ever be static objects: otherwise, if you try
7843 to, say, break of a class's method and you're in a file
7844 which doesn't mention that class, it won't work unless
7845 the check for all static symbols in lookup_symbol_aux
7846 saves you. See the OtherFileClass tests in
7847 gdb.c++/namespace.exp. */
7849 struct pending **list_to_add;
7851 list_to_add = (cu->list_in_scope == &file_symbols
7852 && (cu->language == language_cplus
7853 || cu->language == language_java)
7854 ? &global_symbols : cu->list_in_scope);
7856 add_symbol_to_list (sym, list_to_add);
7858 /* The semantics of C++ state that "struct foo { ... }" also
7859 defines a typedef for "foo". A Java class declaration also
7860 defines a typedef for the class. */
7861 if (cu->language == language_cplus
7862 || cu->language == language_java
7863 || cu->language == language_ada)
7865 /* The symbol's name is already allocated along with
7866 this objfile, so we don't need to duplicate it for
7868 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
7869 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
7873 case DW_TAG_typedef:
7874 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
7875 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7876 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7877 add_symbol_to_list (sym, cu->list_in_scope);
7879 case DW_TAG_base_type:
7880 case DW_TAG_subrange_type:
7881 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7882 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7883 add_symbol_to_list (sym, cu->list_in_scope);
7885 case DW_TAG_enumerator:
7886 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
7887 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7890 dwarf2_const_value (attr, sym, cu);
7893 /* NOTE: carlton/2003-11-10: See comment above in the
7894 DW_TAG_class_type, etc. block. */
7896 struct pending **list_to_add;
7898 list_to_add = (cu->list_in_scope == &file_symbols
7899 && (cu->language == language_cplus
7900 || cu->language == language_java)
7901 ? &global_symbols : cu->list_in_scope);
7903 add_symbol_to_list (sym, list_to_add);
7906 case DW_TAG_namespace:
7907 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7908 add_symbol_to_list (sym, &global_symbols);
7911 /* Not a tag we recognize. Hopefully we aren't processing
7912 trash data, but since we must specifically ignore things
7913 we don't recognize, there is nothing else we should do at
7915 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
7916 dwarf_tag_name (die->tag));
7920 /* For the benefit of old versions of GCC, check for anonymous
7921 namespaces based on the demangled name. */
7922 if (!processing_has_namespace_info
7923 && cu->language == language_cplus
7924 && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
7925 cp_scan_for_anonymous_namespaces (sym);
7930 /* Copy constant value from an attribute to a symbol. */
7933 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
7934 struct dwarf2_cu *cu)
7936 struct objfile *objfile = cu->objfile;
7937 struct comp_unit_head *cu_header = &cu->header;
7938 struct dwarf_block *blk;
7943 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
7944 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
7945 cu_header->addr_size,
7946 TYPE_LENGTH (SYMBOL_TYPE
7948 SYMBOL_VALUE_BYTES (sym) =
7949 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
7950 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7951 it's body - store_unsigned_integer. */
7952 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
7954 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7956 case DW_FORM_string:
7958 /* DW_STRING is already allocated on the obstack, point directly
7960 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
7961 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7963 case DW_FORM_block1:
7964 case DW_FORM_block2:
7965 case DW_FORM_block4:
7967 blk = DW_BLOCK (attr);
7968 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
7969 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
7971 TYPE_LENGTH (SYMBOL_TYPE
7973 SYMBOL_VALUE_BYTES (sym) =
7974 obstack_alloc (&objfile->objfile_obstack, blk->size);
7975 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
7976 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7979 /* The DW_AT_const_value attributes are supposed to carry the
7980 symbol's value "represented as it would be on the target
7981 architecture." By the time we get here, it's already been
7982 converted to host endianness, so we just need to sign- or
7983 zero-extend it as appropriate. */
7985 dwarf2_const_value_data (attr, sym, 8);
7988 dwarf2_const_value_data (attr, sym, 16);
7991 dwarf2_const_value_data (attr, sym, 32);
7994 dwarf2_const_value_data (attr, sym, 64);
7998 SYMBOL_VALUE (sym) = DW_SND (attr);
7999 SYMBOL_CLASS (sym) = LOC_CONST;
8003 SYMBOL_VALUE (sym) = DW_UNSND (attr);
8004 SYMBOL_CLASS (sym) = LOC_CONST;
8008 complaint (&symfile_complaints,
8009 _("unsupported const value attribute form: '%s'"),
8010 dwarf_form_name (attr->form));
8011 SYMBOL_VALUE (sym) = 0;
8012 SYMBOL_CLASS (sym) = LOC_CONST;
8018 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8019 or zero-extend it as appropriate for the symbol's type. */
8021 dwarf2_const_value_data (struct attribute *attr,
8025 LONGEST l = DW_UNSND (attr);
8027 if (bits < sizeof (l) * 8)
8029 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
8030 l &= ((LONGEST) 1 << bits) - 1;
8032 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
8035 SYMBOL_VALUE (sym) = l;
8036 SYMBOL_CLASS (sym) = LOC_CONST;
8040 /* Return the type of the die in question using its DW_AT_type attribute. */
8042 static struct type *
8043 die_type (struct die_info *die, struct dwarf2_cu *cu)
8045 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8047 struct attribute *type_attr;
8048 struct die_info *type_die;
8050 type_attr = dwarf2_attr (die, DW_AT_type, cu);
8053 /* A missing DW_AT_type represents a void type. */
8054 return builtin_type (gdbarch)->builtin_void;
8057 type_die = follow_die_ref (die, type_attr, &cu);
8059 type = tag_type_to_type (type_die, cu);
8062 dump_die_for_error (type_die);
8063 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8069 /* Return the containing type of the die in question using its
8070 DW_AT_containing_type attribute. */
8072 static struct type *
8073 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
8075 struct type *type = NULL;
8076 struct attribute *type_attr;
8077 struct die_info *type_die = NULL;
8079 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
8082 type_die = follow_die_ref (die, type_attr, &cu);
8083 type = tag_type_to_type (type_die, cu);
8088 dump_die_for_error (type_die);
8089 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8095 static struct type *
8096 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
8098 struct type *this_type;
8100 this_type = read_type_die (die, cu);
8103 dump_die_for_error (die);
8104 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8110 static struct type *
8111 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
8113 struct type *this_type;
8115 this_type = get_die_type (die, cu);
8121 case DW_TAG_class_type:
8122 case DW_TAG_interface_type:
8123 case DW_TAG_structure_type:
8124 case DW_TAG_union_type:
8125 this_type = read_structure_type (die, cu);
8127 case DW_TAG_enumeration_type:
8128 this_type = read_enumeration_type (die, cu);
8130 case DW_TAG_subprogram:
8131 case DW_TAG_subroutine_type:
8132 this_type = read_subroutine_type (die, cu);
8134 case DW_TAG_array_type:
8135 this_type = read_array_type (die, cu);
8137 case DW_TAG_set_type:
8138 this_type = read_set_type (die, cu);
8140 case DW_TAG_pointer_type:
8141 this_type = read_tag_pointer_type (die, cu);
8143 case DW_TAG_ptr_to_member_type:
8144 this_type = read_tag_ptr_to_member_type (die, cu);
8146 case DW_TAG_reference_type:
8147 this_type = read_tag_reference_type (die, cu);
8149 case DW_TAG_const_type:
8150 this_type = read_tag_const_type (die, cu);
8152 case DW_TAG_volatile_type:
8153 this_type = read_tag_volatile_type (die, cu);
8155 case DW_TAG_string_type:
8156 this_type = read_tag_string_type (die, cu);
8158 case DW_TAG_typedef:
8159 this_type = read_typedef (die, cu);
8161 case DW_TAG_subrange_type:
8162 this_type = read_subrange_type (die, cu);
8164 case DW_TAG_base_type:
8165 this_type = read_base_type (die, cu);
8167 case DW_TAG_unspecified_type:
8168 this_type = read_unspecified_type (die, cu);
8170 case DW_TAG_namespace:
8171 this_type = read_namespace_type (die, cu);
8174 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
8175 dwarf_tag_name (die->tag));
8182 /* Return the name of the namespace/class that DIE is defined within,
8183 or "" if we can't tell. The caller should not xfree the result.
8185 For example, if we're within the method foo() in the following
8195 then determine_prefix on foo's die will return "N::C". */
8198 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
8200 struct die_info *parent, *spec_die;
8201 struct dwarf2_cu *spec_cu;
8202 struct type *parent_type;
8204 if (cu->language != language_cplus
8205 && cu->language != language_java)
8208 /* We have to be careful in the presence of DW_AT_specification.
8209 For example, with GCC 3.4, given the code
8213 // Definition of N::foo.
8217 then we'll have a tree of DIEs like this:
8219 1: DW_TAG_compile_unit
8220 2: DW_TAG_namespace // N
8221 3: DW_TAG_subprogram // declaration of N::foo
8222 4: DW_TAG_subprogram // definition of N::foo
8223 DW_AT_specification // refers to die #3
8225 Thus, when processing die #4, we have to pretend that we're in
8226 the context of its DW_AT_specification, namely the contex of die
8229 spec_die = die_specification (die, &spec_cu);
8230 if (spec_die == NULL)
8231 parent = die->parent;
8234 parent = spec_die->parent;
8241 switch (parent->tag)
8243 case DW_TAG_namespace:
8244 parent_type = read_type_die (parent, cu);
8245 /* We give a name to even anonymous namespaces. */
8246 return TYPE_TAG_NAME (parent_type);
8247 case DW_TAG_class_type:
8248 case DW_TAG_interface_type:
8249 case DW_TAG_structure_type:
8250 case DW_TAG_union_type:
8251 parent_type = read_type_die (parent, cu);
8252 if (TYPE_TAG_NAME (parent_type) != NULL)
8253 return TYPE_TAG_NAME (parent_type);
8255 /* An anonymous structure is only allowed non-static data
8256 members; no typedefs, no member functions, et cetera.
8257 So it does not need a prefix. */
8260 return determine_prefix (parent, cu);
8264 /* Return a newly-allocated string formed by concatenating PREFIX and
8265 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8266 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8267 perform an obconcat, otherwise allocate storage for the result. The CU argument
8268 is used to determine the language and hence, the appropriate separator. */
8270 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8273 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
8274 struct dwarf2_cu *cu)
8278 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
8280 else if (cu->language == language_java)
8292 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
8293 strcpy (retval, prefix);
8294 strcat (retval, sep);
8295 strcat (retval, suffix);
8300 /* We have an obstack. */
8301 return obconcat (obs, prefix, sep, suffix);
8305 /* Return sibling of die, NULL if no sibling. */
8307 static struct die_info *
8308 sibling_die (struct die_info *die)
8310 return die->sibling;
8313 /* Get linkage name of a die, return NULL if not found. */
8316 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
8318 struct attribute *attr;
8320 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
8321 if (attr && DW_STRING (attr))
8322 return DW_STRING (attr);
8323 return dwarf2_name (die, cu);
8326 /* Get name of a die, return NULL if not found. */
8329 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
8330 struct obstack *obstack)
8332 if (name && cu->language == language_cplus)
8334 char *canon_name = cp_canonicalize_string (name);
8336 if (canon_name != NULL)
8338 if (strcmp (canon_name, name) != 0)
8339 name = obsavestring (canon_name, strlen (canon_name),
8348 /* Get name of a die, return NULL if not found. */
8351 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
8353 struct attribute *attr;
8355 attr = dwarf2_attr (die, DW_AT_name, cu);
8356 if (!attr || !DW_STRING (attr))
8361 case DW_TAG_compile_unit:
8362 /* Compilation units have a DW_AT_name that is a filename, not
8363 a source language identifier. */
8364 case DW_TAG_enumeration_type:
8365 case DW_TAG_enumerator:
8366 /* These tags always have simple identifiers already; no need
8367 to canonicalize them. */
8368 return DW_STRING (attr);
8370 if (attr->form != GDB_FORM_cached_string)
8373 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
8374 &cu->objfile->objfile_obstack);
8375 attr->form = GDB_FORM_cached_string;
8377 return DW_STRING (attr);
8381 /* Return the die that this die in an extension of, or NULL if there
8382 is none. *EXT_CU is the CU containing DIE on input, and the CU
8383 containing the return value on output. */
8385 static struct die_info *
8386 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
8388 struct attribute *attr;
8390 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
8394 return follow_die_ref (die, attr, ext_cu);
8397 /* Convert a DIE tag into its string name. */
8400 dwarf_tag_name (unsigned tag)
8404 case DW_TAG_padding:
8405 return "DW_TAG_padding";
8406 case DW_TAG_array_type:
8407 return "DW_TAG_array_type";
8408 case DW_TAG_class_type:
8409 return "DW_TAG_class_type";
8410 case DW_TAG_entry_point:
8411 return "DW_TAG_entry_point";
8412 case DW_TAG_enumeration_type:
8413 return "DW_TAG_enumeration_type";
8414 case DW_TAG_formal_parameter:
8415 return "DW_TAG_formal_parameter";
8416 case DW_TAG_imported_declaration:
8417 return "DW_TAG_imported_declaration";
8419 return "DW_TAG_label";
8420 case DW_TAG_lexical_block:
8421 return "DW_TAG_lexical_block";
8423 return "DW_TAG_member";
8424 case DW_TAG_pointer_type:
8425 return "DW_TAG_pointer_type";
8426 case DW_TAG_reference_type:
8427 return "DW_TAG_reference_type";
8428 case DW_TAG_compile_unit:
8429 return "DW_TAG_compile_unit";
8430 case DW_TAG_string_type:
8431 return "DW_TAG_string_type";
8432 case DW_TAG_structure_type:
8433 return "DW_TAG_structure_type";
8434 case DW_TAG_subroutine_type:
8435 return "DW_TAG_subroutine_type";
8436 case DW_TAG_typedef:
8437 return "DW_TAG_typedef";
8438 case DW_TAG_union_type:
8439 return "DW_TAG_union_type";
8440 case DW_TAG_unspecified_parameters:
8441 return "DW_TAG_unspecified_parameters";
8442 case DW_TAG_variant:
8443 return "DW_TAG_variant";
8444 case DW_TAG_common_block:
8445 return "DW_TAG_common_block";
8446 case DW_TAG_common_inclusion:
8447 return "DW_TAG_common_inclusion";
8448 case DW_TAG_inheritance:
8449 return "DW_TAG_inheritance";
8450 case DW_TAG_inlined_subroutine:
8451 return "DW_TAG_inlined_subroutine";
8453 return "DW_TAG_module";
8454 case DW_TAG_ptr_to_member_type:
8455 return "DW_TAG_ptr_to_member_type";
8456 case DW_TAG_set_type:
8457 return "DW_TAG_set_type";
8458 case DW_TAG_subrange_type:
8459 return "DW_TAG_subrange_type";
8460 case DW_TAG_with_stmt:
8461 return "DW_TAG_with_stmt";
8462 case DW_TAG_access_declaration:
8463 return "DW_TAG_access_declaration";
8464 case DW_TAG_base_type:
8465 return "DW_TAG_base_type";
8466 case DW_TAG_catch_block:
8467 return "DW_TAG_catch_block";
8468 case DW_TAG_const_type:
8469 return "DW_TAG_const_type";
8470 case DW_TAG_constant:
8471 return "DW_TAG_constant";
8472 case DW_TAG_enumerator:
8473 return "DW_TAG_enumerator";
8474 case DW_TAG_file_type:
8475 return "DW_TAG_file_type";
8477 return "DW_TAG_friend";
8478 case DW_TAG_namelist:
8479 return "DW_TAG_namelist";
8480 case DW_TAG_namelist_item:
8481 return "DW_TAG_namelist_item";
8482 case DW_TAG_packed_type:
8483 return "DW_TAG_packed_type";
8484 case DW_TAG_subprogram:
8485 return "DW_TAG_subprogram";
8486 case DW_TAG_template_type_param:
8487 return "DW_TAG_template_type_param";
8488 case DW_TAG_template_value_param:
8489 return "DW_TAG_template_value_param";
8490 case DW_TAG_thrown_type:
8491 return "DW_TAG_thrown_type";
8492 case DW_TAG_try_block:
8493 return "DW_TAG_try_block";
8494 case DW_TAG_variant_part:
8495 return "DW_TAG_variant_part";
8496 case DW_TAG_variable:
8497 return "DW_TAG_variable";
8498 case DW_TAG_volatile_type:
8499 return "DW_TAG_volatile_type";
8500 case DW_TAG_dwarf_procedure:
8501 return "DW_TAG_dwarf_procedure";
8502 case DW_TAG_restrict_type:
8503 return "DW_TAG_restrict_type";
8504 case DW_TAG_interface_type:
8505 return "DW_TAG_interface_type";
8506 case DW_TAG_namespace:
8507 return "DW_TAG_namespace";
8508 case DW_TAG_imported_module:
8509 return "DW_TAG_imported_module";
8510 case DW_TAG_unspecified_type:
8511 return "DW_TAG_unspecified_type";
8512 case DW_TAG_partial_unit:
8513 return "DW_TAG_partial_unit";
8514 case DW_TAG_imported_unit:
8515 return "DW_TAG_imported_unit";
8516 case DW_TAG_condition:
8517 return "DW_TAG_condition";
8518 case DW_TAG_shared_type:
8519 return "DW_TAG_shared_type";
8520 case DW_TAG_MIPS_loop:
8521 return "DW_TAG_MIPS_loop";
8522 case DW_TAG_HP_array_descriptor:
8523 return "DW_TAG_HP_array_descriptor";
8524 case DW_TAG_format_label:
8525 return "DW_TAG_format_label";
8526 case DW_TAG_function_template:
8527 return "DW_TAG_function_template";
8528 case DW_TAG_class_template:
8529 return "DW_TAG_class_template";
8530 case DW_TAG_GNU_BINCL:
8531 return "DW_TAG_GNU_BINCL";
8532 case DW_TAG_GNU_EINCL:
8533 return "DW_TAG_GNU_EINCL";
8534 case DW_TAG_upc_shared_type:
8535 return "DW_TAG_upc_shared_type";
8536 case DW_TAG_upc_strict_type:
8537 return "DW_TAG_upc_strict_type";
8538 case DW_TAG_upc_relaxed_type:
8539 return "DW_TAG_upc_relaxed_type";
8540 case DW_TAG_PGI_kanji_type:
8541 return "DW_TAG_PGI_kanji_type";
8542 case DW_TAG_PGI_interface_block:
8543 return "DW_TAG_PGI_interface_block";
8545 return "DW_TAG_<unknown>";
8549 /* Convert a DWARF attribute code into its string name. */
8552 dwarf_attr_name (unsigned attr)
8557 return "DW_AT_sibling";
8558 case DW_AT_location:
8559 return "DW_AT_location";
8561 return "DW_AT_name";
8562 case DW_AT_ordering:
8563 return "DW_AT_ordering";
8564 case DW_AT_subscr_data:
8565 return "DW_AT_subscr_data";
8566 case DW_AT_byte_size:
8567 return "DW_AT_byte_size";
8568 case DW_AT_bit_offset:
8569 return "DW_AT_bit_offset";
8570 case DW_AT_bit_size:
8571 return "DW_AT_bit_size";
8572 case DW_AT_element_list:
8573 return "DW_AT_element_list";
8574 case DW_AT_stmt_list:
8575 return "DW_AT_stmt_list";
8577 return "DW_AT_low_pc";
8579 return "DW_AT_high_pc";
8580 case DW_AT_language:
8581 return "DW_AT_language";
8583 return "DW_AT_member";
8585 return "DW_AT_discr";
8586 case DW_AT_discr_value:
8587 return "DW_AT_discr_value";
8588 case DW_AT_visibility:
8589 return "DW_AT_visibility";
8591 return "DW_AT_import";
8592 case DW_AT_string_length:
8593 return "DW_AT_string_length";
8594 case DW_AT_common_reference:
8595 return "DW_AT_common_reference";
8596 case DW_AT_comp_dir:
8597 return "DW_AT_comp_dir";
8598 case DW_AT_const_value:
8599 return "DW_AT_const_value";
8600 case DW_AT_containing_type:
8601 return "DW_AT_containing_type";
8602 case DW_AT_default_value:
8603 return "DW_AT_default_value";
8605 return "DW_AT_inline";
8606 case DW_AT_is_optional:
8607 return "DW_AT_is_optional";
8608 case DW_AT_lower_bound:
8609 return "DW_AT_lower_bound";
8610 case DW_AT_producer:
8611 return "DW_AT_producer";
8612 case DW_AT_prototyped:
8613 return "DW_AT_prototyped";
8614 case DW_AT_return_addr:
8615 return "DW_AT_return_addr";
8616 case DW_AT_start_scope:
8617 return "DW_AT_start_scope";
8618 case DW_AT_bit_stride:
8619 return "DW_AT_bit_stride";
8620 case DW_AT_upper_bound:
8621 return "DW_AT_upper_bound";
8622 case DW_AT_abstract_origin:
8623 return "DW_AT_abstract_origin";
8624 case DW_AT_accessibility:
8625 return "DW_AT_accessibility";
8626 case DW_AT_address_class:
8627 return "DW_AT_address_class";
8628 case DW_AT_artificial:
8629 return "DW_AT_artificial";
8630 case DW_AT_base_types:
8631 return "DW_AT_base_types";
8632 case DW_AT_calling_convention:
8633 return "DW_AT_calling_convention";
8635 return "DW_AT_count";
8636 case DW_AT_data_member_location:
8637 return "DW_AT_data_member_location";
8638 case DW_AT_decl_column:
8639 return "DW_AT_decl_column";
8640 case DW_AT_decl_file:
8641 return "DW_AT_decl_file";
8642 case DW_AT_decl_line:
8643 return "DW_AT_decl_line";
8644 case DW_AT_declaration:
8645 return "DW_AT_declaration";
8646 case DW_AT_discr_list:
8647 return "DW_AT_discr_list";
8648 case DW_AT_encoding:
8649 return "DW_AT_encoding";
8650 case DW_AT_external:
8651 return "DW_AT_external";
8652 case DW_AT_frame_base:
8653 return "DW_AT_frame_base";
8655 return "DW_AT_friend";
8656 case DW_AT_identifier_case:
8657 return "DW_AT_identifier_case";
8658 case DW_AT_macro_info:
8659 return "DW_AT_macro_info";
8660 case DW_AT_namelist_items:
8661 return "DW_AT_namelist_items";
8662 case DW_AT_priority:
8663 return "DW_AT_priority";
8665 return "DW_AT_segment";
8666 case DW_AT_specification:
8667 return "DW_AT_specification";
8668 case DW_AT_static_link:
8669 return "DW_AT_static_link";
8671 return "DW_AT_type";
8672 case DW_AT_use_location:
8673 return "DW_AT_use_location";
8674 case DW_AT_variable_parameter:
8675 return "DW_AT_variable_parameter";
8676 case DW_AT_virtuality:
8677 return "DW_AT_virtuality";
8678 case DW_AT_vtable_elem_location:
8679 return "DW_AT_vtable_elem_location";
8680 /* DWARF 3 values. */
8681 case DW_AT_allocated:
8682 return "DW_AT_allocated";
8683 case DW_AT_associated:
8684 return "DW_AT_associated";
8685 case DW_AT_data_location:
8686 return "DW_AT_data_location";
8687 case DW_AT_byte_stride:
8688 return "DW_AT_byte_stride";
8689 case DW_AT_entry_pc:
8690 return "DW_AT_entry_pc";
8691 case DW_AT_use_UTF8:
8692 return "DW_AT_use_UTF8";
8693 case DW_AT_extension:
8694 return "DW_AT_extension";
8696 return "DW_AT_ranges";
8697 case DW_AT_trampoline:
8698 return "DW_AT_trampoline";
8699 case DW_AT_call_column:
8700 return "DW_AT_call_column";
8701 case DW_AT_call_file:
8702 return "DW_AT_call_file";
8703 case DW_AT_call_line:
8704 return "DW_AT_call_line";
8705 case DW_AT_description:
8706 return "DW_AT_description";
8707 case DW_AT_binary_scale:
8708 return "DW_AT_binary_scale";
8709 case DW_AT_decimal_scale:
8710 return "DW_AT_decimal_scale";
8712 return "DW_AT_small";
8713 case DW_AT_decimal_sign:
8714 return "DW_AT_decimal_sign";
8715 case DW_AT_digit_count:
8716 return "DW_AT_digit_count";
8717 case DW_AT_picture_string:
8718 return "DW_AT_picture_string";
8720 return "DW_AT_mutable";
8721 case DW_AT_threads_scaled:
8722 return "DW_AT_threads_scaled";
8723 case DW_AT_explicit:
8724 return "DW_AT_explicit";
8725 case DW_AT_object_pointer:
8726 return "DW_AT_object_pointer";
8727 case DW_AT_endianity:
8728 return "DW_AT_endianity";
8729 case DW_AT_elemental:
8730 return "DW_AT_elemental";
8732 return "DW_AT_pure";
8733 case DW_AT_recursive:
8734 return "DW_AT_recursive";
8735 /* SGI/MIPS extensions. */
8736 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8737 case DW_AT_MIPS_fde:
8738 return "DW_AT_MIPS_fde";
8740 case DW_AT_MIPS_loop_begin:
8741 return "DW_AT_MIPS_loop_begin";
8742 case DW_AT_MIPS_tail_loop_begin:
8743 return "DW_AT_MIPS_tail_loop_begin";
8744 case DW_AT_MIPS_epilog_begin:
8745 return "DW_AT_MIPS_epilog_begin";
8746 case DW_AT_MIPS_loop_unroll_factor:
8747 return "DW_AT_MIPS_loop_unroll_factor";
8748 case DW_AT_MIPS_software_pipeline_depth:
8749 return "DW_AT_MIPS_software_pipeline_depth";
8750 case DW_AT_MIPS_linkage_name:
8751 return "DW_AT_MIPS_linkage_name";
8752 case DW_AT_MIPS_stride:
8753 return "DW_AT_MIPS_stride";
8754 case DW_AT_MIPS_abstract_name:
8755 return "DW_AT_MIPS_abstract_name";
8756 case DW_AT_MIPS_clone_origin:
8757 return "DW_AT_MIPS_clone_origin";
8758 case DW_AT_MIPS_has_inlines:
8759 return "DW_AT_MIPS_has_inlines";
8760 /* HP extensions. */
8761 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8762 case DW_AT_HP_block_index:
8763 return "DW_AT_HP_block_index";
8765 case DW_AT_HP_unmodifiable:
8766 return "DW_AT_HP_unmodifiable";
8767 case DW_AT_HP_actuals_stmt_list:
8768 return "DW_AT_HP_actuals_stmt_list";
8769 case DW_AT_HP_proc_per_section:
8770 return "DW_AT_HP_proc_per_section";
8771 case DW_AT_HP_raw_data_ptr:
8772 return "DW_AT_HP_raw_data_ptr";
8773 case DW_AT_HP_pass_by_reference:
8774 return "DW_AT_HP_pass_by_reference";
8775 case DW_AT_HP_opt_level:
8776 return "DW_AT_HP_opt_level";
8777 case DW_AT_HP_prof_version_id:
8778 return "DW_AT_HP_prof_version_id";
8779 case DW_AT_HP_opt_flags:
8780 return "DW_AT_HP_opt_flags";
8781 case DW_AT_HP_cold_region_low_pc:
8782 return "DW_AT_HP_cold_region_low_pc";
8783 case DW_AT_HP_cold_region_high_pc:
8784 return "DW_AT_HP_cold_region_high_pc";
8785 case DW_AT_HP_all_variables_modifiable:
8786 return "DW_AT_HP_all_variables_modifiable";
8787 case DW_AT_HP_linkage_name:
8788 return "DW_AT_HP_linkage_name";
8789 case DW_AT_HP_prof_flags:
8790 return "DW_AT_HP_prof_flags";
8791 /* GNU extensions. */
8792 case DW_AT_sf_names:
8793 return "DW_AT_sf_names";
8794 case DW_AT_src_info:
8795 return "DW_AT_src_info";
8796 case DW_AT_mac_info:
8797 return "DW_AT_mac_info";
8798 case DW_AT_src_coords:
8799 return "DW_AT_src_coords";
8800 case DW_AT_body_begin:
8801 return "DW_AT_body_begin";
8802 case DW_AT_body_end:
8803 return "DW_AT_body_end";
8804 case DW_AT_GNU_vector:
8805 return "DW_AT_GNU_vector";
8806 /* VMS extensions. */
8807 case DW_AT_VMS_rtnbeg_pd_address:
8808 return "DW_AT_VMS_rtnbeg_pd_address";
8809 /* UPC extension. */
8810 case DW_AT_upc_threads_scaled:
8811 return "DW_AT_upc_threads_scaled";
8812 /* PGI (STMicroelectronics) extensions. */
8813 case DW_AT_PGI_lbase:
8814 return "DW_AT_PGI_lbase";
8815 case DW_AT_PGI_soffset:
8816 return "DW_AT_PGI_soffset";
8817 case DW_AT_PGI_lstride:
8818 return "DW_AT_PGI_lstride";
8820 return "DW_AT_<unknown>";
8824 /* Convert a DWARF value form code into its string name. */
8827 dwarf_form_name (unsigned form)
8832 return "DW_FORM_addr";
8833 case DW_FORM_block2:
8834 return "DW_FORM_block2";
8835 case DW_FORM_block4:
8836 return "DW_FORM_block4";
8838 return "DW_FORM_data2";
8840 return "DW_FORM_data4";
8842 return "DW_FORM_data8";
8843 case DW_FORM_string:
8844 return "DW_FORM_string";
8846 return "DW_FORM_block";
8847 case DW_FORM_block1:
8848 return "DW_FORM_block1";
8850 return "DW_FORM_data1";
8852 return "DW_FORM_flag";
8854 return "DW_FORM_sdata";
8856 return "DW_FORM_strp";
8858 return "DW_FORM_udata";
8859 case DW_FORM_ref_addr:
8860 return "DW_FORM_ref_addr";
8862 return "DW_FORM_ref1";
8864 return "DW_FORM_ref2";
8866 return "DW_FORM_ref4";
8868 return "DW_FORM_ref8";
8869 case DW_FORM_ref_udata:
8870 return "DW_FORM_ref_udata";
8871 case DW_FORM_indirect:
8872 return "DW_FORM_indirect";
8873 case GDB_FORM_cached_string:
8874 return "GDB_FORM_cached_string";
8876 return "DW_FORM_<unknown>";
8880 /* Convert a DWARF stack opcode into its string name. */
8883 dwarf_stack_op_name (unsigned op)
8888 return "DW_OP_addr";
8890 return "DW_OP_deref";
8892 return "DW_OP_const1u";
8894 return "DW_OP_const1s";
8896 return "DW_OP_const2u";
8898 return "DW_OP_const2s";
8900 return "DW_OP_const4u";
8902 return "DW_OP_const4s";
8904 return "DW_OP_const8u";
8906 return "DW_OP_const8s";
8908 return "DW_OP_constu";
8910 return "DW_OP_consts";
8914 return "DW_OP_drop";
8916 return "DW_OP_over";
8918 return "DW_OP_pick";
8920 return "DW_OP_swap";
8924 return "DW_OP_xderef";
8932 return "DW_OP_minus";
8944 return "DW_OP_plus";
8945 case DW_OP_plus_uconst:
8946 return "DW_OP_plus_uconst";
8952 return "DW_OP_shra";
8970 return "DW_OP_skip";
8972 return "DW_OP_lit0";
8974 return "DW_OP_lit1";
8976 return "DW_OP_lit2";
8978 return "DW_OP_lit3";
8980 return "DW_OP_lit4";
8982 return "DW_OP_lit5";
8984 return "DW_OP_lit6";
8986 return "DW_OP_lit7";
8988 return "DW_OP_lit8";
8990 return "DW_OP_lit9";
8992 return "DW_OP_lit10";
8994 return "DW_OP_lit11";
8996 return "DW_OP_lit12";
8998 return "DW_OP_lit13";
9000 return "DW_OP_lit14";
9002 return "DW_OP_lit15";
9004 return "DW_OP_lit16";
9006 return "DW_OP_lit17";
9008 return "DW_OP_lit18";
9010 return "DW_OP_lit19";
9012 return "DW_OP_lit20";
9014 return "DW_OP_lit21";
9016 return "DW_OP_lit22";
9018 return "DW_OP_lit23";
9020 return "DW_OP_lit24";
9022 return "DW_OP_lit25";
9024 return "DW_OP_lit26";
9026 return "DW_OP_lit27";
9028 return "DW_OP_lit28";
9030 return "DW_OP_lit29";
9032 return "DW_OP_lit30";
9034 return "DW_OP_lit31";
9036 return "DW_OP_reg0";
9038 return "DW_OP_reg1";
9040 return "DW_OP_reg2";
9042 return "DW_OP_reg3";
9044 return "DW_OP_reg4";
9046 return "DW_OP_reg5";
9048 return "DW_OP_reg6";
9050 return "DW_OP_reg7";
9052 return "DW_OP_reg8";
9054 return "DW_OP_reg9";
9056 return "DW_OP_reg10";
9058 return "DW_OP_reg11";
9060 return "DW_OP_reg12";
9062 return "DW_OP_reg13";
9064 return "DW_OP_reg14";
9066 return "DW_OP_reg15";
9068 return "DW_OP_reg16";
9070 return "DW_OP_reg17";
9072 return "DW_OP_reg18";
9074 return "DW_OP_reg19";
9076 return "DW_OP_reg20";
9078 return "DW_OP_reg21";
9080 return "DW_OP_reg22";
9082 return "DW_OP_reg23";
9084 return "DW_OP_reg24";
9086 return "DW_OP_reg25";
9088 return "DW_OP_reg26";
9090 return "DW_OP_reg27";
9092 return "DW_OP_reg28";
9094 return "DW_OP_reg29";
9096 return "DW_OP_reg30";
9098 return "DW_OP_reg31";
9100 return "DW_OP_breg0";
9102 return "DW_OP_breg1";
9104 return "DW_OP_breg2";
9106 return "DW_OP_breg3";
9108 return "DW_OP_breg4";
9110 return "DW_OP_breg5";
9112 return "DW_OP_breg6";
9114 return "DW_OP_breg7";
9116 return "DW_OP_breg8";
9118 return "DW_OP_breg9";
9120 return "DW_OP_breg10";
9122 return "DW_OP_breg11";
9124 return "DW_OP_breg12";
9126 return "DW_OP_breg13";
9128 return "DW_OP_breg14";
9130 return "DW_OP_breg15";
9132 return "DW_OP_breg16";
9134 return "DW_OP_breg17";
9136 return "DW_OP_breg18";
9138 return "DW_OP_breg19";
9140 return "DW_OP_breg20";
9142 return "DW_OP_breg21";
9144 return "DW_OP_breg22";
9146 return "DW_OP_breg23";
9148 return "DW_OP_breg24";
9150 return "DW_OP_breg25";
9152 return "DW_OP_breg26";
9154 return "DW_OP_breg27";
9156 return "DW_OP_breg28";
9158 return "DW_OP_breg29";
9160 return "DW_OP_breg30";
9162 return "DW_OP_breg31";
9164 return "DW_OP_regx";
9166 return "DW_OP_fbreg";
9168 return "DW_OP_bregx";
9170 return "DW_OP_piece";
9171 case DW_OP_deref_size:
9172 return "DW_OP_deref_size";
9173 case DW_OP_xderef_size:
9174 return "DW_OP_xderef_size";
9177 /* DWARF 3 extensions. */
9178 case DW_OP_push_object_address:
9179 return "DW_OP_push_object_address";
9181 return "DW_OP_call2";
9183 return "DW_OP_call4";
9184 case DW_OP_call_ref:
9185 return "DW_OP_call_ref";
9186 /* GNU extensions. */
9187 case DW_OP_form_tls_address:
9188 return "DW_OP_form_tls_address";
9189 case DW_OP_call_frame_cfa:
9190 return "DW_OP_call_frame_cfa";
9191 case DW_OP_bit_piece:
9192 return "DW_OP_bit_piece";
9193 case DW_OP_GNU_push_tls_address:
9194 return "DW_OP_GNU_push_tls_address";
9195 case DW_OP_GNU_uninit:
9196 return "DW_OP_GNU_uninit";
9197 /* HP extensions. */
9198 case DW_OP_HP_is_value:
9199 return "DW_OP_HP_is_value";
9200 case DW_OP_HP_fltconst4:
9201 return "DW_OP_HP_fltconst4";
9202 case DW_OP_HP_fltconst8:
9203 return "DW_OP_HP_fltconst8";
9204 case DW_OP_HP_mod_range:
9205 return "DW_OP_HP_mod_range";
9206 case DW_OP_HP_unmod_range:
9207 return "DW_OP_HP_unmod_range";
9209 return "DW_OP_HP_tls";
9211 return "OP_<unknown>";
9216 dwarf_bool_name (unsigned mybool)
9224 /* Convert a DWARF type code into its string name. */
9227 dwarf_type_encoding_name (unsigned enc)
9232 return "DW_ATE_void";
9233 case DW_ATE_address:
9234 return "DW_ATE_address";
9235 case DW_ATE_boolean:
9236 return "DW_ATE_boolean";
9237 case DW_ATE_complex_float:
9238 return "DW_ATE_complex_float";
9240 return "DW_ATE_float";
9242 return "DW_ATE_signed";
9243 case DW_ATE_signed_char:
9244 return "DW_ATE_signed_char";
9245 case DW_ATE_unsigned:
9246 return "DW_ATE_unsigned";
9247 case DW_ATE_unsigned_char:
9248 return "DW_ATE_unsigned_char";
9250 case DW_ATE_imaginary_float:
9251 return "DW_ATE_imaginary_float";
9252 case DW_ATE_packed_decimal:
9253 return "DW_ATE_packed_decimal";
9254 case DW_ATE_numeric_string:
9255 return "DW_ATE_numeric_string";
9257 return "DW_ATE_edited";
9258 case DW_ATE_signed_fixed:
9259 return "DW_ATE_signed_fixed";
9260 case DW_ATE_unsigned_fixed:
9261 return "DW_ATE_unsigned_fixed";
9262 case DW_ATE_decimal_float:
9263 return "DW_ATE_decimal_float";
9264 /* HP extensions. */
9265 case DW_ATE_HP_float80:
9266 return "DW_ATE_HP_float80";
9267 case DW_ATE_HP_complex_float80:
9268 return "DW_ATE_HP_complex_float80";
9269 case DW_ATE_HP_float128:
9270 return "DW_ATE_HP_float128";
9271 case DW_ATE_HP_complex_float128:
9272 return "DW_ATE_HP_complex_float128";
9273 case DW_ATE_HP_floathpintel:
9274 return "DW_ATE_HP_floathpintel";
9275 case DW_ATE_HP_imaginary_float80:
9276 return "DW_ATE_HP_imaginary_float80";
9277 case DW_ATE_HP_imaginary_float128:
9278 return "DW_ATE_HP_imaginary_float128";
9280 return "DW_ATE_<unknown>";
9284 /* Convert a DWARF call frame info operation to its string name. */
9288 dwarf_cfi_name (unsigned cfi_opc)
9292 case DW_CFA_advance_loc:
9293 return "DW_CFA_advance_loc";
9295 return "DW_CFA_offset";
9296 case DW_CFA_restore:
9297 return "DW_CFA_restore";
9299 return "DW_CFA_nop";
9300 case DW_CFA_set_loc:
9301 return "DW_CFA_set_loc";
9302 case DW_CFA_advance_loc1:
9303 return "DW_CFA_advance_loc1";
9304 case DW_CFA_advance_loc2:
9305 return "DW_CFA_advance_loc2";
9306 case DW_CFA_advance_loc4:
9307 return "DW_CFA_advance_loc4";
9308 case DW_CFA_offset_extended:
9309 return "DW_CFA_offset_extended";
9310 case DW_CFA_restore_extended:
9311 return "DW_CFA_restore_extended";
9312 case DW_CFA_undefined:
9313 return "DW_CFA_undefined";
9314 case DW_CFA_same_value:
9315 return "DW_CFA_same_value";
9316 case DW_CFA_register:
9317 return "DW_CFA_register";
9318 case DW_CFA_remember_state:
9319 return "DW_CFA_remember_state";
9320 case DW_CFA_restore_state:
9321 return "DW_CFA_restore_state";
9322 case DW_CFA_def_cfa:
9323 return "DW_CFA_def_cfa";
9324 case DW_CFA_def_cfa_register:
9325 return "DW_CFA_def_cfa_register";
9326 case DW_CFA_def_cfa_offset:
9327 return "DW_CFA_def_cfa_offset";
9329 case DW_CFA_def_cfa_expression:
9330 return "DW_CFA_def_cfa_expression";
9331 case DW_CFA_expression:
9332 return "DW_CFA_expression";
9333 case DW_CFA_offset_extended_sf:
9334 return "DW_CFA_offset_extended_sf";
9335 case DW_CFA_def_cfa_sf:
9336 return "DW_CFA_def_cfa_sf";
9337 case DW_CFA_def_cfa_offset_sf:
9338 return "DW_CFA_def_cfa_offset_sf";
9339 case DW_CFA_val_offset:
9340 return "DW_CFA_val_offset";
9341 case DW_CFA_val_offset_sf:
9342 return "DW_CFA_val_offset_sf";
9343 case DW_CFA_val_expression:
9344 return "DW_CFA_val_expression";
9345 /* SGI/MIPS specific. */
9346 case DW_CFA_MIPS_advance_loc8:
9347 return "DW_CFA_MIPS_advance_loc8";
9348 /* GNU extensions. */
9349 case DW_CFA_GNU_window_save:
9350 return "DW_CFA_GNU_window_save";
9351 case DW_CFA_GNU_args_size:
9352 return "DW_CFA_GNU_args_size";
9353 case DW_CFA_GNU_negative_offset_extended:
9354 return "DW_CFA_GNU_negative_offset_extended";
9356 return "DW_CFA_<unknown>";
9362 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
9366 print_spaces (indent, f);
9367 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
9368 dwarf_tag_name (die->tag), die->abbrev, die->offset);
9370 if (die->parent != NULL)
9372 print_spaces (indent, f);
9373 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
9374 die->parent->offset);
9377 print_spaces (indent, f);
9378 fprintf_unfiltered (f, " has children: %s\n",
9379 dwarf_bool_name (die->child != NULL));
9381 print_spaces (indent, f);
9382 fprintf_unfiltered (f, " attributes:\n");
9384 for (i = 0; i < die->num_attrs; ++i)
9386 print_spaces (indent, f);
9387 fprintf_unfiltered (f, " %s (%s) ",
9388 dwarf_attr_name (die->attrs[i].name),
9389 dwarf_form_name (die->attrs[i].form));
9391 switch (die->attrs[i].form)
9393 case DW_FORM_ref_addr:
9395 fprintf_unfiltered (f, "address: ");
9396 fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), f);
9398 case DW_FORM_block2:
9399 case DW_FORM_block4:
9401 case DW_FORM_block1:
9402 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
9407 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
9408 (long) (DW_ADDR (&die->attrs[i])));
9416 fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
9418 case DW_FORM_string:
9420 case GDB_FORM_cached_string:
9421 fprintf_unfiltered (f, "string: \"%s\"",
9422 DW_STRING (&die->attrs[i])
9423 ? DW_STRING (&die->attrs[i]) : "");
9426 if (DW_UNSND (&die->attrs[i]))
9427 fprintf_unfiltered (f, "flag: TRUE");
9429 fprintf_unfiltered (f, "flag: FALSE");
9431 case DW_FORM_indirect:
9432 /* the reader will have reduced the indirect form to
9433 the "base form" so this form should not occur */
9434 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
9437 fprintf_unfiltered (f, "unsupported attribute form: %d.",
9438 die->attrs[i].form);
9441 fprintf_unfiltered (f, "\n");
9446 dump_die_for_error (struct die_info *die)
9448 dump_die_shallow (gdb_stderr, 0, die);
9452 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
9454 int indent = level * 4;
9456 gdb_assert (die != NULL);
9458 if (level >= max_level)
9461 dump_die_shallow (f, indent, die);
9463 if (die->child != NULL)
9465 print_spaces (indent, f);
9466 fprintf_unfiltered (f, " Children:");
9467 if (level + 1 < max_level)
9469 fprintf_unfiltered (f, "\n");
9470 dump_die_1 (f, level + 1, max_level, die->child);
9474 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
9478 if (die->sibling != NULL && level > 0)
9480 dump_die_1 (f, level, max_level, die->sibling);
9484 /* This is called from the pdie macro in gdbinit.in.
9485 It's not static so gcc will keep a copy callable from gdb. */
9488 dump_die (struct die_info *die, int max_level)
9490 dump_die_1 (gdb_stdlog, 0, max_level, die);
9494 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
9498 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
9504 dwarf2_get_ref_die_offset (struct attribute *attr)
9506 unsigned int result = 0;
9510 case DW_FORM_ref_addr:
9515 case DW_FORM_ref_udata:
9516 result = DW_ADDR (attr);
9519 complaint (&symfile_complaints,
9520 _("unsupported die ref attribute form: '%s'"),
9521 dwarf_form_name (attr->form));
9526 /* Return the constant value held by the given attribute. Return -1
9527 if the value held by the attribute is not constant. */
9530 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
9532 if (attr->form == DW_FORM_sdata)
9533 return DW_SND (attr);
9534 else if (attr->form == DW_FORM_udata
9535 || attr->form == DW_FORM_data1
9536 || attr->form == DW_FORM_data2
9537 || attr->form == DW_FORM_data4
9538 || attr->form == DW_FORM_data8)
9539 return DW_UNSND (attr);
9542 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
9543 dwarf_form_name (attr->form));
9544 return default_value;
9548 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9549 unit and add it to our queue. */
9552 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
9553 struct dwarf2_per_cu_data *per_cu)
9555 /* Mark the dependence relation so that we don't flush PER_CU
9557 dwarf2_add_dependence (this_cu, per_cu);
9559 /* If it's already on the queue, we have nothing to do. */
9563 /* If the compilation unit is already loaded, just mark it as
9565 if (per_cu->cu != NULL)
9567 per_cu->cu->last_used = 0;
9571 /* Add it to the queue. */
9572 queue_comp_unit (per_cu, this_cu->objfile);
9575 /* Follow reference attribute ATTR of SRC_DIE.
9576 On entry *REF_CU is the CU of SRC_DIE.
9577 On exit *REF_CU is the CU of the result. */
9579 static struct die_info *
9580 follow_die_ref (struct die_info *src_die, struct attribute *attr,
9581 struct dwarf2_cu **ref_cu)
9583 struct die_info *die;
9584 unsigned int offset;
9585 struct die_info temp_die;
9586 struct dwarf2_cu *target_cu, *cu = *ref_cu;
9588 offset = dwarf2_get_ref_die_offset (attr);
9590 if (! offset_in_cu_p (&cu->header, offset))
9592 struct dwarf2_per_cu_data *per_cu;
9593 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9595 /* If necessary, add it to the queue and load its DIEs. */
9596 maybe_queue_comp_unit (cu, per_cu);
9598 target_cu = per_cu->cu;
9603 *ref_cu = target_cu;
9604 temp_die.offset = offset;
9605 die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
9609 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9610 "at 0x%lx [in module %s]"),
9611 (long) offset, (long) src_die->offset, cu->objfile->name);
9614 /* Decode simple location descriptions.
9615 Given a pointer to a dwarf block that defines a location, compute
9616 the location and return the value.
9618 NOTE drow/2003-11-18: This function is called in two situations
9619 now: for the address of static or global variables (partial symbols
9620 only) and for offsets into structures which are expected to be
9621 (more or less) constant. The partial symbol case should go away,
9622 and only the constant case should remain. That will let this
9623 function complain more accurately. A few special modes are allowed
9624 without complaint for global variables (for instance, global
9625 register values and thread-local values).
9627 A location description containing no operations indicates that the
9628 object is optimized out. The return value is 0 for that case.
9629 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9630 callers will only want a very basic result and this can become a
9633 Note that stack[0] is unused except as a default error return.
9634 Note that stack overflow is not yet handled. */
9637 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
9639 struct objfile *objfile = cu->objfile;
9640 struct comp_unit_head *cu_header = &cu->header;
9642 int size = blk->size;
9643 gdb_byte *data = blk->data;
9644 CORE_ADDR stack[64];
9646 unsigned int bytes_read, unsnd;
9690 stack[++stacki] = op - DW_OP_lit0;
9725 stack[++stacki] = op - DW_OP_reg0;
9727 dwarf2_complex_location_expr_complaint ();
9731 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
9733 stack[++stacki] = unsnd;
9735 dwarf2_complex_location_expr_complaint ();
9739 stack[++stacki] = read_address (objfile->obfd, &data[i],
9745 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
9750 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
9755 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
9760 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
9765 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
9770 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
9775 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
9781 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
9786 stack[stacki + 1] = stack[stacki];
9791 stack[stacki - 1] += stack[stacki];
9795 case DW_OP_plus_uconst:
9796 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
9801 stack[stacki - 1] -= stack[stacki];
9806 /* If we're not the last op, then we definitely can't encode
9807 this using GDB's address_class enum. This is valid for partial
9808 global symbols, although the variable's address will be bogus
9811 dwarf2_complex_location_expr_complaint ();
9814 case DW_OP_GNU_push_tls_address:
9815 /* The top of the stack has the offset from the beginning
9816 of the thread control block at which the variable is located. */
9817 /* Nothing should follow this operator, so the top of stack would
9819 /* This is valid for partial global symbols, but the variable's
9820 address will be bogus in the psymtab. */
9822 dwarf2_complex_location_expr_complaint ();
9825 case DW_OP_GNU_uninit:
9829 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
9830 dwarf_stack_op_name (op));
9831 return (stack[stacki]);
9834 return (stack[stacki]);
9837 /* memory allocation interface */
9839 static struct dwarf_block *
9840 dwarf_alloc_block (struct dwarf2_cu *cu)
9842 struct dwarf_block *blk;
9844 blk = (struct dwarf_block *)
9845 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
9849 static struct abbrev_info *
9850 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
9852 struct abbrev_info *abbrev;
9854 abbrev = (struct abbrev_info *)
9855 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
9856 memset (abbrev, 0, sizeof (struct abbrev_info));
9860 static struct die_info *
9861 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
9863 struct die_info *die;
9864 size_t size = sizeof (struct die_info);
9867 size += (num_attrs - 1) * sizeof (struct attribute);
9869 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
9870 memset (die, 0, sizeof (struct die_info));
9875 /* Macro support. */
9878 /* Return the full name of file number I in *LH's file name table.
9879 Use COMP_DIR as the name of the current directory of the
9880 compilation. The result is allocated using xmalloc; the caller is
9881 responsible for freeing it. */
9883 file_full_name (int file, struct line_header *lh, const char *comp_dir)
9885 /* Is the file number a valid index into the line header's file name
9886 table? Remember that file numbers start with one, not zero. */
9887 if (1 <= file && file <= lh->num_file_names)
9889 struct file_entry *fe = &lh->file_names[file - 1];
9891 if (IS_ABSOLUTE_PATH (fe->name))
9892 return xstrdup (fe->name);
9900 dir = lh->include_dirs[fe->dir_index - 1];
9906 dir_len = strlen (dir);
9907 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
9908 strcpy (full_name, dir);
9909 full_name[dir_len] = '/';
9910 strcpy (full_name + dir_len + 1, fe->name);
9914 return xstrdup (fe->name);
9919 /* The compiler produced a bogus file number. We can at least
9920 record the macro definitions made in the file, even if we
9921 won't be able to find the file by name. */
9923 sprintf (fake_name, "<bad macro file number %d>", file);
9925 complaint (&symfile_complaints,
9926 _("bad file number in macro information (%d)"),
9929 return xstrdup (fake_name);
9934 static struct macro_source_file *
9935 macro_start_file (int file, int line,
9936 struct macro_source_file *current_file,
9937 const char *comp_dir,
9938 struct line_header *lh, struct objfile *objfile)
9940 /* The full name of this source file. */
9941 char *full_name = file_full_name (file, lh, comp_dir);
9943 /* We don't create a macro table for this compilation unit
9944 at all until we actually get a filename. */
9945 if (! pending_macros)
9946 pending_macros = new_macro_table (&objfile->objfile_obstack,
9947 objfile->macro_cache);
9950 /* If we have no current file, then this must be the start_file
9951 directive for the compilation unit's main source file. */
9952 current_file = macro_set_main (pending_macros, full_name);
9954 current_file = macro_include (current_file, line, full_name);
9958 return current_file;
9962 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9963 followed by a null byte. */
9965 copy_string (const char *buf, int len)
9967 char *s = xmalloc (len + 1);
9968 memcpy (s, buf, len);
9976 consume_improper_spaces (const char *p, const char *body)
9980 complaint (&symfile_complaints,
9981 _("macro definition contains spaces in formal argument list:\n`%s'"),
9993 parse_macro_definition (struct macro_source_file *file, int line,
9998 /* The body string takes one of two forms. For object-like macro
9999 definitions, it should be:
10001 <macro name> " " <definition>
10003 For function-like macro definitions, it should be:
10005 <macro name> "() " <definition>
10007 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10009 Spaces may appear only where explicitly indicated, and in the
10012 The Dwarf 2 spec says that an object-like macro's name is always
10013 followed by a space, but versions of GCC around March 2002 omit
10014 the space when the macro's definition is the empty string.
10016 The Dwarf 2 spec says that there should be no spaces between the
10017 formal arguments in a function-like macro's formal argument list,
10018 but versions of GCC around March 2002 include spaces after the
10022 /* Find the extent of the macro name. The macro name is terminated
10023 by either a space or null character (for an object-like macro) or
10024 an opening paren (for a function-like macro). */
10025 for (p = body; *p; p++)
10026 if (*p == ' ' || *p == '(')
10029 if (*p == ' ' || *p == '\0')
10031 /* It's an object-like macro. */
10032 int name_len = p - body;
10033 char *name = copy_string (body, name_len);
10034 const char *replacement;
10037 replacement = body + name_len + 1;
10040 dwarf2_macro_malformed_definition_complaint (body);
10041 replacement = body + name_len;
10044 macro_define_object (file, line, name, replacement);
10048 else if (*p == '(')
10050 /* It's a function-like macro. */
10051 char *name = copy_string (body, p - body);
10054 char **argv = xmalloc (argv_size * sizeof (*argv));
10058 p = consume_improper_spaces (p, body);
10060 /* Parse the formal argument list. */
10061 while (*p && *p != ')')
10063 /* Find the extent of the current argument name. */
10064 const char *arg_start = p;
10066 while (*p && *p != ',' && *p != ')' && *p != ' ')
10069 if (! *p || p == arg_start)
10070 dwarf2_macro_malformed_definition_complaint (body);
10073 /* Make sure argv has room for the new argument. */
10074 if (argc >= argv_size)
10077 argv = xrealloc (argv, argv_size * sizeof (*argv));
10080 argv[argc++] = copy_string (arg_start, p - arg_start);
10083 p = consume_improper_spaces (p, body);
10085 /* Consume the comma, if present. */
10090 p = consume_improper_spaces (p, body);
10099 /* Perfectly formed definition, no complaints. */
10100 macro_define_function (file, line, name,
10101 argc, (const char **) argv,
10103 else if (*p == '\0')
10105 /* Complain, but do define it. */
10106 dwarf2_macro_malformed_definition_complaint (body);
10107 macro_define_function (file, line, name,
10108 argc, (const char **) argv,
10112 /* Just complain. */
10113 dwarf2_macro_malformed_definition_complaint (body);
10116 /* Just complain. */
10117 dwarf2_macro_malformed_definition_complaint (body);
10123 for (i = 0; i < argc; i++)
10129 dwarf2_macro_malformed_definition_complaint (body);
10134 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
10135 char *comp_dir, bfd *abfd,
10136 struct dwarf2_cu *cu)
10138 gdb_byte *mac_ptr, *mac_end;
10139 struct macro_source_file *current_file = 0;
10140 enum dwarf_macinfo_record_type macinfo_type;
10141 int at_commandline;
10143 if (dwarf2_per_objfile->macinfo.buffer == NULL)
10145 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
10149 /* First pass: Find the name of the base filename.
10150 This filename is needed in order to process all macros whose definition
10151 (or undefinition) comes from the command line. These macros are defined
10152 before the first DW_MACINFO_start_file entry, and yet still need to be
10153 associated to the base file.
10155 To determine the base file name, we scan the macro definitions until we
10156 reach the first DW_MACINFO_start_file entry. We then initialize
10157 CURRENT_FILE accordingly so that any macro definition found before the
10158 first DW_MACINFO_start_file can still be associated to the base file. */
10160 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
10161 mac_end = dwarf2_per_objfile->macinfo.buffer
10162 + dwarf2_per_objfile->macinfo.size;
10166 /* Do we at least have room for a macinfo type byte? */
10167 if (mac_ptr >= mac_end)
10169 /* Complaint is printed during the second pass as GDB will probably
10170 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10174 macinfo_type = read_1_byte (abfd, mac_ptr);
10177 switch (macinfo_type)
10179 /* A zero macinfo type indicates the end of the macro
10184 case DW_MACINFO_define:
10185 case DW_MACINFO_undef:
10186 /* Only skip the data by MAC_PTR. */
10188 unsigned int bytes_read;
10190 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10191 mac_ptr += bytes_read;
10192 read_string (abfd, mac_ptr, &bytes_read);
10193 mac_ptr += bytes_read;
10197 case DW_MACINFO_start_file:
10199 unsigned int bytes_read;
10202 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10203 mac_ptr += bytes_read;
10204 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10205 mac_ptr += bytes_read;
10207 current_file = macro_start_file (file, line, current_file, comp_dir,
10212 case DW_MACINFO_end_file:
10213 /* No data to skip by MAC_PTR. */
10216 case DW_MACINFO_vendor_ext:
10217 /* Only skip the data by MAC_PTR. */
10219 unsigned int bytes_read;
10221 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10222 mac_ptr += bytes_read;
10223 read_string (abfd, mac_ptr, &bytes_read);
10224 mac_ptr += bytes_read;
10231 } while (macinfo_type != 0 && current_file == NULL);
10233 /* Second pass: Process all entries.
10235 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10236 command-line macro definitions/undefinitions. This flag is unset when we
10237 reach the first DW_MACINFO_start_file entry. */
10239 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
10241 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10242 GDB is still reading the definitions from command line. First
10243 DW_MACINFO_start_file will need to be ignored as it was already executed
10244 to create CURRENT_FILE for the main source holding also the command line
10245 definitions. On first met DW_MACINFO_start_file this flag is reset to
10246 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10248 at_commandline = 1;
10252 /* Do we at least have room for a macinfo type byte? */
10253 if (mac_ptr >= mac_end)
10255 dwarf2_macros_too_long_complaint ();
10259 macinfo_type = read_1_byte (abfd, mac_ptr);
10262 switch (macinfo_type)
10264 /* A zero macinfo type indicates the end of the macro
10269 case DW_MACINFO_define:
10270 case DW_MACINFO_undef:
10272 unsigned int bytes_read;
10276 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10277 mac_ptr += bytes_read;
10278 body = read_string (abfd, mac_ptr, &bytes_read);
10279 mac_ptr += bytes_read;
10281 if (! current_file)
10283 /* DWARF violation as no main source is present. */
10284 complaint (&symfile_complaints,
10285 _("debug info with no main source gives macro %s "
10288 DW_MACINFO_define ? _("definition") : macinfo_type ==
10289 DW_MACINFO_undef ? _("undefinition") :
10290 "something-or-other", line, body);
10293 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
10294 complaint (&symfile_complaints,
10295 _("debug info gives %s macro %s with %s line %d: %s"),
10296 at_commandline ? _("command-line") : _("in-file"),
10298 DW_MACINFO_define ? _("definition") : macinfo_type ==
10299 DW_MACINFO_undef ? _("undefinition") :
10300 "something-or-other",
10301 line == 0 ? _("zero") : _("non-zero"), line, body);
10303 if (macinfo_type == DW_MACINFO_define)
10304 parse_macro_definition (current_file, line, body);
10305 else if (macinfo_type == DW_MACINFO_undef)
10306 macro_undef (current_file, line, body);
10310 case DW_MACINFO_start_file:
10312 unsigned int bytes_read;
10315 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10316 mac_ptr += bytes_read;
10317 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10318 mac_ptr += bytes_read;
10320 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
10321 complaint (&symfile_complaints,
10322 _("debug info gives source %d included "
10323 "from %s at %s line %d"),
10324 file, at_commandline ? _("command-line") : _("file"),
10325 line == 0 ? _("zero") : _("non-zero"), line);
10327 if (at_commandline)
10329 /* This DW_MACINFO_start_file was executed in the pass one. */
10330 at_commandline = 0;
10333 current_file = macro_start_file (file, line,
10334 current_file, comp_dir,
10339 case DW_MACINFO_end_file:
10340 if (! current_file)
10341 complaint (&symfile_complaints,
10342 _("macro debug info has an unmatched `close_file' directive"));
10345 current_file = current_file->included_by;
10346 if (! current_file)
10348 enum dwarf_macinfo_record_type next_type;
10350 /* GCC circa March 2002 doesn't produce the zero
10351 type byte marking the end of the compilation
10352 unit. Complain if it's not there, but exit no
10355 /* Do we at least have room for a macinfo type byte? */
10356 if (mac_ptr >= mac_end)
10358 dwarf2_macros_too_long_complaint ();
10362 /* We don't increment mac_ptr here, so this is just
10364 next_type = read_1_byte (abfd, mac_ptr);
10365 if (next_type != 0)
10366 complaint (&symfile_complaints,
10367 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10374 case DW_MACINFO_vendor_ext:
10376 unsigned int bytes_read;
10380 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10381 mac_ptr += bytes_read;
10382 string = read_string (abfd, mac_ptr, &bytes_read);
10383 mac_ptr += bytes_read;
10385 /* We don't recognize any vendor extensions. */
10389 } while (macinfo_type != 0);
10392 /* Check if the attribute's form is a DW_FORM_block*
10393 if so return true else false. */
10395 attr_form_is_block (struct attribute *attr)
10397 return (attr == NULL ? 0 :
10398 attr->form == DW_FORM_block1
10399 || attr->form == DW_FORM_block2
10400 || attr->form == DW_FORM_block4
10401 || attr->form == DW_FORM_block);
10404 /* Return non-zero if ATTR's value is a section offset --- classes
10405 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10406 You may use DW_UNSND (attr) to retrieve such offsets.
10408 Section 7.5.4, "Attribute Encodings", explains that no attribute
10409 may have a value that belongs to more than one of these classes; it
10410 would be ambiguous if we did, because we use the same forms for all
10413 attr_form_is_section_offset (struct attribute *attr)
10415 return (attr->form == DW_FORM_data4
10416 || attr->form == DW_FORM_data8);
10420 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10421 zero otherwise. When this function returns true, you can apply
10422 dwarf2_get_attr_constant_value to it.
10424 However, note that for some attributes you must check
10425 attr_form_is_section_offset before using this test. DW_FORM_data4
10426 and DW_FORM_data8 are members of both the constant class, and of
10427 the classes that contain offsets into other debug sections
10428 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10429 that, if an attribute's can be either a constant or one of the
10430 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10431 taken as section offsets, not constants. */
10433 attr_form_is_constant (struct attribute *attr)
10435 switch (attr->form)
10437 case DW_FORM_sdata:
10438 case DW_FORM_udata:
10439 case DW_FORM_data1:
10440 case DW_FORM_data2:
10441 case DW_FORM_data4:
10442 case DW_FORM_data8:
10450 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
10451 struct dwarf2_cu *cu)
10453 if (attr_form_is_section_offset (attr)
10454 /* ".debug_loc" may not exist at all, or the offset may be outside
10455 the section. If so, fall through to the complaint in the
10457 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
10459 struct dwarf2_loclist_baton *baton;
10461 baton = obstack_alloc (&cu->objfile->objfile_obstack,
10462 sizeof (struct dwarf2_loclist_baton));
10463 baton->per_cu = cu->per_cu;
10464 gdb_assert (baton->per_cu);
10466 /* We don't know how long the location list is, but make sure we
10467 don't run off the edge of the section. */
10468 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
10469 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
10470 baton->base_address = cu->base_address;
10471 if (cu->base_known == 0)
10472 complaint (&symfile_complaints,
10473 _("Location list used without specifying the CU base address."));
10475 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
10476 SYMBOL_LOCATION_BATON (sym) = baton;
10480 struct dwarf2_locexpr_baton *baton;
10482 baton = obstack_alloc (&cu->objfile->objfile_obstack,
10483 sizeof (struct dwarf2_locexpr_baton));
10484 baton->per_cu = cu->per_cu;
10485 gdb_assert (baton->per_cu);
10487 if (attr_form_is_block (attr))
10489 /* Note that we're just copying the block's data pointer
10490 here, not the actual data. We're still pointing into the
10491 info_buffer for SYM's objfile; right now we never release
10492 that buffer, but when we do clean up properly this may
10494 baton->size = DW_BLOCK (attr)->size;
10495 baton->data = DW_BLOCK (attr)->data;
10499 dwarf2_invalid_attrib_class_complaint ("location description",
10500 SYMBOL_NATURAL_NAME (sym));
10502 baton->data = NULL;
10505 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
10506 SYMBOL_LOCATION_BATON (sym) = baton;
10510 /* Return the OBJFILE associated with the compilation unit CU. */
10513 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
10515 struct objfile *objfile = per_cu->psymtab->objfile;
10517 /* Return the master objfile, so that we can report and look up the
10518 correct file containing this variable. */
10519 if (objfile->separate_debug_objfile_backlink)
10520 objfile = objfile->separate_debug_objfile_backlink;
10525 /* Return the address size given in the compilation unit header for CU. */
10528 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
10531 return per_cu->cu->header.addr_size;
10534 /* If the CU is not currently read in, we re-read its header. */
10535 struct objfile *objfile = per_cu->psymtab->objfile;
10536 struct dwarf2_per_objfile *per_objfile
10537 = objfile_data (objfile, dwarf2_objfile_data_key);
10538 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
10540 struct comp_unit_head cu_header;
10541 memset (&cu_header, 0, sizeof cu_header);
10542 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
10543 return cu_header.addr_size;
10547 /* Locate the compilation unit from CU's objfile which contains the
10548 DIE at OFFSET. Raises an error on failure. */
10550 static struct dwarf2_per_cu_data *
10551 dwarf2_find_containing_comp_unit (unsigned int offset,
10552 struct objfile *objfile)
10554 struct dwarf2_per_cu_data *this_cu;
10558 high = dwarf2_per_objfile->n_comp_units - 1;
10561 int mid = low + (high - low) / 2;
10562 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
10567 gdb_assert (low == high);
10568 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
10571 error (_("Dwarf Error: could not find partial DIE containing "
10572 "offset 0x%lx [in module %s]"),
10573 (long) offset, bfd_get_filename (objfile->obfd));
10575 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
10576 return dwarf2_per_objfile->all_comp_units[low-1];
10580 this_cu = dwarf2_per_objfile->all_comp_units[low];
10581 if (low == dwarf2_per_objfile->n_comp_units - 1
10582 && offset >= this_cu->offset + this_cu->length)
10583 error (_("invalid dwarf2 offset %u"), offset);
10584 gdb_assert (offset < this_cu->offset + this_cu->length);
10589 /* Locate the compilation unit from OBJFILE which is located at exactly
10590 OFFSET. Raises an error on failure. */
10592 static struct dwarf2_per_cu_data *
10593 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
10595 struct dwarf2_per_cu_data *this_cu;
10596 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
10597 if (this_cu->offset != offset)
10598 error (_("no compilation unit with offset %u."), offset);
10602 /* Release one cached compilation unit, CU. We unlink it from the tree
10603 of compilation units, but we don't remove it from the read_in_chain;
10604 the caller is responsible for that. */
10607 free_one_comp_unit (void *data)
10609 struct dwarf2_cu *cu = data;
10611 if (cu->per_cu != NULL)
10612 cu->per_cu->cu = NULL;
10615 obstack_free (&cu->comp_unit_obstack, NULL);
10620 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10621 when we're finished with it. We can't free the pointer itself, but be
10622 sure to unlink it from the cache. Also release any associated storage
10623 and perform cache maintenance.
10625 Only used during partial symbol parsing. */
10628 free_stack_comp_unit (void *data)
10630 struct dwarf2_cu *cu = data;
10632 obstack_free (&cu->comp_unit_obstack, NULL);
10633 cu->partial_dies = NULL;
10635 if (cu->per_cu != NULL)
10637 /* This compilation unit is on the stack in our caller, so we
10638 should not xfree it. Just unlink it. */
10639 cu->per_cu->cu = NULL;
10642 /* If we had a per-cu pointer, then we may have other compilation
10643 units loaded, so age them now. */
10644 age_cached_comp_units ();
10648 /* Free all cached compilation units. */
10651 free_cached_comp_units (void *data)
10653 struct dwarf2_per_cu_data *per_cu, **last_chain;
10655 per_cu = dwarf2_per_objfile->read_in_chain;
10656 last_chain = &dwarf2_per_objfile->read_in_chain;
10657 while (per_cu != NULL)
10659 struct dwarf2_per_cu_data *next_cu;
10661 next_cu = per_cu->cu->read_in_chain;
10663 free_one_comp_unit (per_cu->cu);
10664 *last_chain = next_cu;
10670 /* Increase the age counter on each cached compilation unit, and free
10671 any that are too old. */
10674 age_cached_comp_units (void)
10676 struct dwarf2_per_cu_data *per_cu, **last_chain;
10678 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
10679 per_cu = dwarf2_per_objfile->read_in_chain;
10680 while (per_cu != NULL)
10682 per_cu->cu->last_used ++;
10683 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
10684 dwarf2_mark (per_cu->cu);
10685 per_cu = per_cu->cu->read_in_chain;
10688 per_cu = dwarf2_per_objfile->read_in_chain;
10689 last_chain = &dwarf2_per_objfile->read_in_chain;
10690 while (per_cu != NULL)
10692 struct dwarf2_per_cu_data *next_cu;
10694 next_cu = per_cu->cu->read_in_chain;
10696 if (!per_cu->cu->mark)
10698 free_one_comp_unit (per_cu->cu);
10699 *last_chain = next_cu;
10702 last_chain = &per_cu->cu->read_in_chain;
10708 /* Remove a single compilation unit from the cache. */
10711 free_one_cached_comp_unit (void *target_cu)
10713 struct dwarf2_per_cu_data *per_cu, **last_chain;
10715 per_cu = dwarf2_per_objfile->read_in_chain;
10716 last_chain = &dwarf2_per_objfile->read_in_chain;
10717 while (per_cu != NULL)
10719 struct dwarf2_per_cu_data *next_cu;
10721 next_cu = per_cu->cu->read_in_chain;
10723 if (per_cu->cu == target_cu)
10725 free_one_comp_unit (per_cu->cu);
10726 *last_chain = next_cu;
10730 last_chain = &per_cu->cu->read_in_chain;
10736 /* Release all extra memory associated with OBJFILE. */
10739 dwarf2_free_objfile (struct objfile *objfile)
10741 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
10743 if (dwarf2_per_objfile == NULL)
10746 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10747 free_cached_comp_units (NULL);
10749 /* Everything else should be on the objfile obstack. */
10752 /* A pair of DIE offset and GDB type pointer. We store these
10753 in a hash table separate from the DIEs, and preserve them
10754 when the DIEs are flushed out of cache. */
10756 struct dwarf2_offset_and_type
10758 unsigned int offset;
10762 /* Hash function for a dwarf2_offset_and_type. */
10765 offset_and_type_hash (const void *item)
10767 const struct dwarf2_offset_and_type *ofs = item;
10768 return ofs->offset;
10771 /* Equality function for a dwarf2_offset_and_type. */
10774 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
10776 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
10777 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
10778 return ofs_lhs->offset == ofs_rhs->offset;
10781 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10782 table if necessary. For convenience, return TYPE. */
10784 static struct type *
10785 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
10787 struct dwarf2_offset_and_type **slot, ofs;
10789 if (cu->type_hash == NULL)
10791 gdb_assert (cu->per_cu != NULL);
10792 cu->per_cu->type_hash
10793 = htab_create_alloc_ex (cu->header.length / 24,
10794 offset_and_type_hash,
10795 offset_and_type_eq,
10797 &cu->objfile->objfile_obstack,
10798 hashtab_obstack_allocate,
10799 dummy_obstack_deallocate);
10800 cu->type_hash = cu->per_cu->type_hash;
10803 ofs.offset = die->offset;
10805 slot = (struct dwarf2_offset_and_type **)
10806 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
10807 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
10812 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10813 not have a saved type. */
10815 static struct type *
10816 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
10818 struct dwarf2_offset_and_type *slot, ofs;
10819 htab_t type_hash = cu->type_hash;
10821 if (type_hash == NULL)
10824 ofs.offset = die->offset;
10825 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
10832 /* Add a dependence relationship from CU to REF_PER_CU. */
10835 dwarf2_add_dependence (struct dwarf2_cu *cu,
10836 struct dwarf2_per_cu_data *ref_per_cu)
10840 if (cu->dependencies == NULL)
10842 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
10843 NULL, &cu->comp_unit_obstack,
10844 hashtab_obstack_allocate,
10845 dummy_obstack_deallocate);
10847 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
10849 *slot = ref_per_cu;
10852 /* Subroutine of dwarf2_mark to pass to htab_traverse.
10853 Set the mark field in every compilation unit in the
10854 cache that we must keep because we are keeping CU. */
10857 dwarf2_mark_helper (void **slot, void *data)
10859 struct dwarf2_per_cu_data *per_cu;
10861 per_cu = (struct dwarf2_per_cu_data *) *slot;
10862 if (per_cu->cu->mark)
10864 per_cu->cu->mark = 1;
10866 if (per_cu->cu->dependencies != NULL)
10867 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
10872 /* Set the mark field in CU and in every other compilation unit in the
10873 cache that we must keep because we are keeping CU. */
10876 dwarf2_mark (struct dwarf2_cu *cu)
10881 if (cu->dependencies != NULL)
10882 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
10886 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
10890 per_cu->cu->mark = 0;
10891 per_cu = per_cu->cu->read_in_chain;
10895 /* Trivial hash function for partial_die_info: the hash value of a DIE
10896 is its offset in .debug_info for this objfile. */
10899 partial_die_hash (const void *item)
10901 const struct partial_die_info *part_die = item;
10902 return part_die->offset;
10905 /* Trivial comparison function for partial_die_info structures: two DIEs
10906 are equal if they have the same offset. */
10909 partial_die_eq (const void *item_lhs, const void *item_rhs)
10911 const struct partial_die_info *part_die_lhs = item_lhs;
10912 const struct partial_die_info *part_die_rhs = item_rhs;
10913 return part_die_lhs->offset == part_die_rhs->offset;
10916 static struct cmd_list_element *set_dwarf2_cmdlist;
10917 static struct cmd_list_element *show_dwarf2_cmdlist;
10920 set_dwarf2_cmd (char *args, int from_tty)
10922 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
10926 show_dwarf2_cmd (char *args, int from_tty)
10928 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
10931 /* If section described by INFO was mmapped, munmap it now. */
10934 munmap_section_buffer (struct dwarf2_section_info *info)
10936 if (info->was_mmapped)
10939 intptr_t begin = (intptr_t) info->buffer;
10940 intptr_t map_begin = begin & ~(pagesize - 1);
10941 size_t map_length = info->size + begin - map_begin;
10942 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
10944 /* Without HAVE_MMAP, we should never be here to begin with. */
10950 /* munmap debug sections for OBJFILE, if necessary. */
10953 dwarf2_per_objfile_cleanup (struct objfile *objfile, void *d)
10955 struct dwarf2_per_objfile *data = d;
10956 munmap_section_buffer (&data->info);
10957 munmap_section_buffer (&data->abbrev);
10958 munmap_section_buffer (&data->line);
10959 munmap_section_buffer (&data->str);
10960 munmap_section_buffer (&data->macinfo);
10961 munmap_section_buffer (&data->ranges);
10962 munmap_section_buffer (&data->loc);
10963 munmap_section_buffer (&data->frame);
10964 munmap_section_buffer (&data->eh_frame);
10967 void _initialize_dwarf2_read (void);
10970 _initialize_dwarf2_read (void)
10972 dwarf2_objfile_data_key
10973 = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup);
10975 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
10976 Set DWARF 2 specific variables.\n\
10977 Configure DWARF 2 variables such as the cache size"),
10978 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
10979 0/*allow-unknown*/, &maintenance_set_cmdlist);
10981 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
10982 Show DWARF 2 specific variables\n\
10983 Show DWARF 2 variables such as the cache size"),
10984 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
10985 0/*allow-unknown*/, &maintenance_show_cmdlist);
10987 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
10988 &dwarf2_max_cache_age, _("\
10989 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10990 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10991 A higher limit means that cached compilation units will be stored\n\
10992 in memory longer, and more total memory will be used. Zero disables\n\
10993 caching, which can slow down startup."),
10995 show_dwarf2_max_cache_age,
10996 &set_dwarf2_cmdlist,
10997 &show_dwarf2_cmdlist);
10999 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
11000 Set debugging of the dwarf2 DIE reader."), _("\
11001 Show debugging of the dwarf2 DIE reader."), _("\
11002 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11003 The value is the maximum depth to print."),
11006 &setdebuglist, &showdebuglist);