1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
56 #include "gdb_string.h"
57 #include "gdb_assert.h"
58 #include <sys/types.h>
65 #define MAP_FAILED ((void *) -1)
70 /* .debug_info header for a compilation unit
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct comp_unit_header
75 unsigned int length; /* length of the .debug_info
77 unsigned short version; /* version number -- 2 for DWARF
79 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
80 unsigned char addr_size; /* byte size of an address -- 4 */
83 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
86 /* .debug_line statement program prologue
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct statement_prologue
91 unsigned int total_length; /* byte length of the statement
93 unsigned short version; /* version number -- 2 for DWARF
95 unsigned int prologue_length; /* # bytes between prologue &
97 unsigned char minimum_instruction_length; /* byte size of
99 unsigned char default_is_stmt; /* initial value of is_stmt
102 unsigned char line_range;
103 unsigned char opcode_base; /* number assigned to first special
105 unsigned char *standard_opcode_lengths;
109 /* When non-zero, dump DIEs after they are read in. */
110 static int dwarf2_die_debug = 0;
114 /* When set, the file that we're processing is known to have debugging
115 info for C++ namespaces. GCC 3.3.x did not produce this information,
116 but later versions do. */
118 static int processing_has_namespace_info;
120 static const struct objfile_data *dwarf2_objfile_data_key;
122 struct dwarf2_section_info
128 /* True if we have tried to read this section. */
132 struct dwarf2_per_objfile
134 struct dwarf2_section_info info;
135 struct dwarf2_section_info abbrev;
136 struct dwarf2_section_info line;
137 struct dwarf2_section_info loc;
138 struct dwarf2_section_info macinfo;
139 struct dwarf2_section_info str;
140 struct dwarf2_section_info ranges;
141 struct dwarf2_section_info types;
142 struct dwarf2_section_info frame;
143 struct dwarf2_section_info eh_frame;
146 struct objfile *objfile;
148 /* A list of all the compilation units. This is used to locate
149 the target compilation unit of a particular reference. */
150 struct dwarf2_per_cu_data **all_comp_units;
152 /* The number of compilation units in ALL_COMP_UNITS. */
155 /* A chain of compilation units that are currently read in, so that
156 they can be freed later. */
157 struct dwarf2_per_cu_data *read_in_chain;
159 /* A table mapping .debug_types signatures to its signatured_type entry.
160 This is NULL if the .debug_types section hasn't been read in yet. */
161 htab_t signatured_types;
163 /* A flag indicating wether this objfile has a section loaded at a
165 int has_section_at_zero;
168 static struct dwarf2_per_objfile *dwarf2_per_objfile;
170 /* names of the debugging sections */
172 /* Note that if the debugging section has been compressed, it might
173 have a name like .zdebug_info. */
175 #define INFO_SECTION "debug_info"
176 #define ABBREV_SECTION "debug_abbrev"
177 #define LINE_SECTION "debug_line"
178 #define LOC_SECTION "debug_loc"
179 #define MACINFO_SECTION "debug_macinfo"
180 #define STR_SECTION "debug_str"
181 #define RANGES_SECTION "debug_ranges"
182 #define TYPES_SECTION "debug_types"
183 #define FRAME_SECTION "debug_frame"
184 #define EH_FRAME_SECTION "eh_frame"
186 /* local data types */
188 /* We hold several abbreviation tables in memory at the same time. */
189 #ifndef ABBREV_HASH_SIZE
190 #define ABBREV_HASH_SIZE 121
193 /* The data in a compilation unit header, after target2host
194 translation, looks like this. */
195 struct comp_unit_head
199 unsigned char addr_size;
200 unsigned char signed_addr_p;
201 unsigned int abbrev_offset;
203 /* Size of file offsets; either 4 or 8. */
204 unsigned int offset_size;
206 /* Size of the length field; either 4 or 12. */
207 unsigned int initial_length_size;
209 /* Offset to the first byte of this compilation unit header in the
210 .debug_info section, for resolving relative reference dies. */
213 /* Offset to first die in this cu from the start of the cu.
214 This will be the first byte following the compilation unit header. */
215 unsigned int first_die_offset;
218 /* Internal state when decoding a particular compilation unit. */
221 /* The objfile containing this compilation unit. */
222 struct objfile *objfile;
224 /* The header of the compilation unit. */
225 struct comp_unit_head header;
227 /* Base address of this compilation unit. */
228 CORE_ADDR base_address;
230 /* Non-zero if base_address has been set. */
233 struct function_range *first_fn, *last_fn, *cached_fn;
235 /* The language we are debugging. */
236 enum language language;
237 const struct language_defn *language_defn;
239 const char *producer;
241 /* The generic symbol table building routines have separate lists for
242 file scope symbols and all all other scopes (local scopes). So
243 we need to select the right one to pass to add_symbol_to_list().
244 We do it by keeping a pointer to the correct list in list_in_scope.
246 FIXME: The original dwarf code just treated the file scope as the
247 first local scope, and all other local scopes as nested local
248 scopes, and worked fine. Check to see if we really need to
249 distinguish these in buildsym.c. */
250 struct pending **list_in_scope;
252 /* DWARF abbreviation table associated with this compilation unit. */
253 struct abbrev_info **dwarf2_abbrevs;
255 /* Storage for the abbrev table. */
256 struct obstack abbrev_obstack;
258 /* Hash table holding all the loaded partial DIEs. */
261 /* Storage for things with the same lifetime as this read-in compilation
262 unit, including partial DIEs. */
263 struct obstack comp_unit_obstack;
265 /* When multiple dwarf2_cu structures are living in memory, this field
266 chains them all together, so that they can be released efficiently.
267 We will probably also want a generation counter so that most-recently-used
268 compilation units are cached... */
269 struct dwarf2_per_cu_data *read_in_chain;
271 /* Backchain to our per_cu entry if the tree has been built. */
272 struct dwarf2_per_cu_data *per_cu;
274 /* Pointer to the die -> type map. Although it is stored
275 permanently in per_cu, we copy it here to avoid double
279 /* How many compilation units ago was this CU last referenced? */
282 /* A hash table of die offsets for following references. */
285 /* Full DIEs if read in. */
286 struct die_info *dies;
288 /* A set of pointers to dwarf2_per_cu_data objects for compilation
289 units referenced by this one. Only set during full symbol processing;
290 partial symbol tables do not have dependencies. */
293 /* Header data from the line table, during full symbol processing. */
294 struct line_header *line_header;
296 /* Mark used when releasing cached dies. */
297 unsigned int mark : 1;
299 /* This flag will be set if this compilation unit might include
300 inter-compilation-unit references. */
301 unsigned int has_form_ref_addr : 1;
303 /* This flag will be set if this compilation unit includes any
304 DW_TAG_namespace DIEs. If we know that there are explicit
305 DIEs for namespaces, we don't need to try to infer them
306 from mangled names. */
307 unsigned int has_namespace_info : 1;
310 /* Persistent data held for a compilation unit, even when not
311 processing it. We put a pointer to this structure in the
312 read_symtab_private field of the psymtab. If we encounter
313 inter-compilation-unit references, we also maintain a sorted
314 list of all compilation units. */
316 struct dwarf2_per_cu_data
318 /* The start offset and length of this compilation unit. 2**29-1
319 bytes should suffice to store the length of any compilation unit
320 - if it doesn't, GDB will fall over anyway.
321 NOTE: Unlike comp_unit_head.length, this length includes
322 initial_length_size. */
324 unsigned int length : 29;
326 /* Flag indicating this compilation unit will be read in before
327 any of the current compilation units are processed. */
328 unsigned int queued : 1;
330 /* This flag will be set if we need to load absolutely all DIEs
331 for this compilation unit, instead of just the ones we think
332 are interesting. It gets set if we look for a DIE in the
333 hash table and don't find it. */
334 unsigned int load_all_dies : 1;
336 /* Non-zero if this CU is from .debug_types.
337 Otherwise it's from .debug_info. */
338 unsigned int from_debug_types : 1;
340 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
341 of the CU cache it gets reset to NULL again. */
342 struct dwarf2_cu *cu;
344 /* If full symbols for this CU have been read in, then this field
345 holds a map of DIE offsets to types. It isn't always possible
346 to reconstruct this information later, so we have to preserve
350 /* The partial symbol table associated with this compilation unit,
351 or NULL for partial units (which do not have an associated
353 struct partial_symtab *psymtab;
356 /* Entry in the signatured_types hash table. */
358 struct signatured_type
362 /* Offset in .debug_types of the TU (type_unit) for this type. */
365 /* Offset in .debug_types of the type defined by this TU. */
366 unsigned int type_offset;
368 /* The CU(/TU) of this type. */
369 struct dwarf2_per_cu_data per_cu;
372 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
373 which are used for both .debug_info and .debug_types dies.
374 All parameters here are unchanging for the life of the call.
375 This struct exists to abstract away the constant parameters of
378 struct die_reader_specs
380 /* The bfd of this objfile. */
383 /* The CU of the DIE we are parsing. */
384 struct dwarf2_cu *cu;
386 /* Pointer to start of section buffer.
387 This is either the start of .debug_info or .debug_types. */
388 const gdb_byte *buffer;
391 /* The line number information for a compilation unit (found in the
392 .debug_line section) begins with a "statement program header",
393 which contains the following information. */
396 unsigned int total_length;
397 unsigned short version;
398 unsigned int header_length;
399 unsigned char minimum_instruction_length;
400 unsigned char maximum_ops_per_instruction;
401 unsigned char default_is_stmt;
403 unsigned char line_range;
404 unsigned char opcode_base;
406 /* standard_opcode_lengths[i] is the number of operands for the
407 standard opcode whose value is i. This means that
408 standard_opcode_lengths[0] is unused, and the last meaningful
409 element is standard_opcode_lengths[opcode_base - 1]. */
410 unsigned char *standard_opcode_lengths;
412 /* The include_directories table. NOTE! These strings are not
413 allocated with xmalloc; instead, they are pointers into
414 debug_line_buffer. If you try to free them, `free' will get
416 unsigned int num_include_dirs, include_dirs_size;
419 /* The file_names table. NOTE! These strings are not allocated
420 with xmalloc; instead, they are pointers into debug_line_buffer.
421 Don't try to free them directly. */
422 unsigned int num_file_names, file_names_size;
426 unsigned int dir_index;
427 unsigned int mod_time;
429 int included_p; /* Non-zero if referenced by the Line Number Program. */
430 struct symtab *symtab; /* The associated symbol table, if any. */
433 /* The start and end of the statement program following this
434 header. These point into dwarf2_per_objfile->line_buffer. */
435 gdb_byte *statement_program_start, *statement_program_end;
438 /* When we construct a partial symbol table entry we only
439 need this much information. */
440 struct partial_die_info
442 /* Offset of this DIE. */
445 /* DWARF-2 tag for this DIE. */
446 ENUM_BITFIELD(dwarf_tag) tag : 16;
448 /* Assorted flags describing the data found in this DIE. */
449 unsigned int has_children : 1;
450 unsigned int is_external : 1;
451 unsigned int is_declaration : 1;
452 unsigned int has_type : 1;
453 unsigned int has_specification : 1;
454 unsigned int has_pc_info : 1;
456 /* Flag set if the SCOPE field of this structure has been
458 unsigned int scope_set : 1;
460 /* Flag set if the DIE has a byte_size attribute. */
461 unsigned int has_byte_size : 1;
463 /* The name of this DIE. Normally the value of DW_AT_name, but
464 sometimes a default name for unnamed DIEs. */
467 /* The scope to prepend to our children. This is generally
468 allocated on the comp_unit_obstack, so will disappear
469 when this compilation unit leaves the cache. */
472 /* The location description associated with this DIE, if any. */
473 struct dwarf_block *locdesc;
475 /* If HAS_PC_INFO, the PC range associated with this DIE. */
479 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
480 DW_AT_sibling, if any. */
483 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
484 DW_AT_specification (or DW_AT_abstract_origin or
486 unsigned int spec_offset;
488 /* Pointers to this DIE's parent, first child, and next sibling,
490 struct partial_die_info *die_parent, *die_child, *die_sibling;
493 /* This data structure holds the information of an abbrev. */
496 unsigned int number; /* number identifying abbrev */
497 enum dwarf_tag tag; /* dwarf tag */
498 unsigned short has_children; /* boolean */
499 unsigned short num_attrs; /* number of attributes */
500 struct attr_abbrev *attrs; /* an array of attribute descriptions */
501 struct abbrev_info *next; /* next in chain */
506 ENUM_BITFIELD(dwarf_attribute) name : 16;
507 ENUM_BITFIELD(dwarf_form) form : 16;
510 /* Attributes have a name and a value */
513 ENUM_BITFIELD(dwarf_attribute) name : 16;
514 ENUM_BITFIELD(dwarf_form) form : 15;
516 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
517 field should be in u.str (existing only for DW_STRING) but it is kept
518 here for better struct attribute alignment. */
519 unsigned int string_is_canonical : 1;
524 struct dwarf_block *blk;
528 struct signatured_type *signatured_type;
533 /* This data structure holds a complete die structure. */
536 /* DWARF-2 tag for this DIE. */
537 ENUM_BITFIELD(dwarf_tag) tag : 16;
539 /* Number of attributes */
540 unsigned short num_attrs;
545 /* Offset in .debug_info or .debug_types section. */
548 /* The dies in a compilation unit form an n-ary tree. PARENT
549 points to this die's parent; CHILD points to the first child of
550 this node; and all the children of a given node are chained
551 together via their SIBLING fields, terminated by a die whose
553 struct die_info *child; /* Its first child, if any. */
554 struct die_info *sibling; /* Its next sibling, if any. */
555 struct die_info *parent; /* Its parent, if any. */
557 /* An array of attributes, with NUM_ATTRS elements. There may be
558 zero, but it's not common and zero-sized arrays are not
559 sufficiently portable C. */
560 struct attribute attrs[1];
563 struct function_range
566 CORE_ADDR lowpc, highpc;
568 struct function_range *next;
571 /* Get at parts of an attribute structure */
573 #define DW_STRING(attr) ((attr)->u.str)
574 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
575 #define DW_UNSND(attr) ((attr)->u.unsnd)
576 #define DW_BLOCK(attr) ((attr)->u.blk)
577 #define DW_SND(attr) ((attr)->u.snd)
578 #define DW_ADDR(attr) ((attr)->u.addr)
579 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
581 /* Blocks are a bunch of untyped bytes. */
588 #ifndef ATTR_ALLOC_CHUNK
589 #define ATTR_ALLOC_CHUNK 4
592 /* Allocate fields for structs, unions and enums in this size. */
593 #ifndef DW_FIELD_ALLOC_CHUNK
594 #define DW_FIELD_ALLOC_CHUNK 4
597 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
598 but this would require a corresponding change in unpack_field_as_long
600 static int bits_per_byte = 8;
602 /* The routines that read and process dies for a C struct or C++ class
603 pass lists of data member fields and lists of member function fields
604 in an instance of a field_info structure, as defined below. */
607 /* List of data member and baseclasses fields. */
610 struct nextfield *next;
615 *fields, *baseclasses;
617 /* Number of fields (including baseclasses). */
620 /* Number of baseclasses. */
623 /* Set if the accesibility of one of the fields is not public. */
624 int non_public_fields;
626 /* Member function fields array, entries are allocated in the order they
627 are encountered in the object file. */
630 struct nextfnfield *next;
631 struct fn_field fnfield;
635 /* Member function fieldlist array, contains name of possibly overloaded
636 member function, number of overloaded member functions and a pointer
637 to the head of the member function field chain. */
642 struct nextfnfield *head;
646 /* Number of entries in the fnfieldlists array. */
649 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
650 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
651 struct typedef_field_list
653 struct typedef_field field;
654 struct typedef_field_list *next;
657 unsigned typedef_field_list_count;
660 /* One item on the queue of compilation units to read in full symbols
662 struct dwarf2_queue_item
664 struct dwarf2_per_cu_data *per_cu;
665 struct dwarf2_queue_item *next;
668 /* The current queue. */
669 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
671 /* Loaded secondary compilation units are kept in memory until they
672 have not been referenced for the processing of this many
673 compilation units. Set this to zero to disable caching. Cache
674 sizes of up to at least twenty will improve startup time for
675 typical inter-CU-reference binaries, at an obvious memory cost. */
676 static int dwarf2_max_cache_age = 5;
678 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
679 struct cmd_list_element *c, const char *value)
681 fprintf_filtered (file, _("\
682 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
687 /* Various complaints about symbol reading that don't abort the process */
690 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
692 complaint (&symfile_complaints,
693 _("statement list doesn't fit in .debug_line section"));
697 dwarf2_debug_line_missing_file_complaint (void)
699 complaint (&symfile_complaints,
700 _(".debug_line section has line data without a file"));
704 dwarf2_debug_line_missing_end_sequence_complaint (void)
706 complaint (&symfile_complaints,
707 _(".debug_line section has line program sequence without an end"));
711 dwarf2_complex_location_expr_complaint (void)
713 complaint (&symfile_complaints, _("location expression too complex"));
717 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
720 complaint (&symfile_complaints,
721 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
726 dwarf2_macros_too_long_complaint (void)
728 complaint (&symfile_complaints,
729 _("macro info runs off end of `.debug_macinfo' section"));
733 dwarf2_macro_malformed_definition_complaint (const char *arg1)
735 complaint (&symfile_complaints,
736 _("macro debug info contains a malformed macro definition:\n`%s'"),
741 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
743 complaint (&symfile_complaints,
744 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
747 /* local function prototypes */
749 static void dwarf2_locate_sections (bfd *, asection *, void *);
751 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
754 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
756 struct partial_symtab *);
758 static void dwarf2_build_psymtabs_hard (struct objfile *);
760 static void scan_partial_symbols (struct partial_die_info *,
761 CORE_ADDR *, CORE_ADDR *,
762 int, struct dwarf2_cu *);
764 static void add_partial_symbol (struct partial_die_info *,
767 static void add_partial_namespace (struct partial_die_info *pdi,
768 CORE_ADDR *lowpc, CORE_ADDR *highpc,
769 int need_pc, struct dwarf2_cu *cu);
771 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
772 CORE_ADDR *highpc, int need_pc,
773 struct dwarf2_cu *cu);
775 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
776 struct dwarf2_cu *cu);
778 static void add_partial_subprogram (struct partial_die_info *pdi,
779 CORE_ADDR *lowpc, CORE_ADDR *highpc,
780 int need_pc, struct dwarf2_cu *cu);
782 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
783 gdb_byte *buffer, gdb_byte *info_ptr,
784 bfd *abfd, struct dwarf2_cu *cu);
786 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
788 static void psymtab_to_symtab_1 (struct partial_symtab *);
790 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
792 static void dwarf2_free_abbrev_table (void *);
794 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
797 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
800 static struct partial_die_info *load_partial_dies (bfd *,
801 gdb_byte *, gdb_byte *,
802 int, struct dwarf2_cu *);
804 static gdb_byte *read_partial_die (struct partial_die_info *,
805 struct abbrev_info *abbrev,
807 gdb_byte *, gdb_byte *,
810 static struct partial_die_info *find_partial_die (unsigned int,
813 static void fixup_partial_die (struct partial_die_info *,
816 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
817 bfd *, gdb_byte *, struct dwarf2_cu *);
819 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
820 bfd *, gdb_byte *, struct dwarf2_cu *);
822 static unsigned int read_1_byte (bfd *, gdb_byte *);
824 static int read_1_signed_byte (bfd *, gdb_byte *);
826 static unsigned int read_2_bytes (bfd *, gdb_byte *);
828 static unsigned int read_4_bytes (bfd *, gdb_byte *);
830 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
832 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
835 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
837 static LONGEST read_checked_initial_length_and_offset
838 (bfd *, gdb_byte *, const struct comp_unit_head *,
839 unsigned int *, unsigned int *);
841 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
844 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
846 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
848 static char *read_string (bfd *, gdb_byte *, unsigned int *);
850 static char *read_indirect_string (bfd *, gdb_byte *,
851 const struct comp_unit_head *,
854 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
856 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
858 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
860 static void set_cu_language (unsigned int, struct dwarf2_cu *);
862 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
865 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
869 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
870 struct dwarf2_cu *cu);
872 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
874 static struct die_info *die_specification (struct die_info *die,
875 struct dwarf2_cu **);
877 static void free_line_header (struct line_header *lh);
879 static void add_file_name (struct line_header *, char *, unsigned int,
880 unsigned int, unsigned int);
882 static struct line_header *(dwarf_decode_line_header
883 (unsigned int offset,
884 bfd *abfd, struct dwarf2_cu *cu));
886 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
887 struct dwarf2_cu *, struct partial_symtab *);
889 static void dwarf2_start_subfile (char *, char *, char *);
891 static struct symbol *new_symbol (struct die_info *, struct type *,
894 static void dwarf2_const_value (struct attribute *, struct symbol *,
897 static void dwarf2_const_value_data (struct attribute *attr,
901 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
903 static int need_gnat_info (struct dwarf2_cu *);
905 static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *);
907 static void set_descriptive_type (struct type *, struct die_info *,
910 static struct type *die_containing_type (struct die_info *,
913 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
915 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
917 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
919 static char *typename_concat (struct obstack *obs, const char *prefix,
920 const char *suffix, int physname,
921 struct dwarf2_cu *cu);
923 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
925 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
927 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
929 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
931 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
932 struct dwarf2_cu *, struct partial_symtab *);
934 static int dwarf2_get_pc_bounds (struct die_info *,
935 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
936 struct partial_symtab *);
938 static void get_scope_pc_bounds (struct die_info *,
939 CORE_ADDR *, CORE_ADDR *,
942 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
943 CORE_ADDR, struct dwarf2_cu *);
945 static void dwarf2_add_field (struct field_info *, struct die_info *,
948 static void dwarf2_attach_fields_to_type (struct field_info *,
949 struct type *, struct dwarf2_cu *);
951 static void dwarf2_add_member_fn (struct field_info *,
952 struct die_info *, struct type *,
955 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
956 struct type *, struct dwarf2_cu *);
958 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
960 static void read_common_block (struct die_info *, struct dwarf2_cu *);
962 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
964 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
966 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
968 static struct type *read_module_type (struct die_info *die,
969 struct dwarf2_cu *cu);
971 static const char *namespace_name (struct die_info *die,
972 int *is_anonymous, struct dwarf2_cu *);
974 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
976 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
978 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
981 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
983 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
985 gdb_byte **new_info_ptr,
986 struct die_info *parent);
988 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
990 gdb_byte **new_info_ptr,
991 struct die_info *parent);
993 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
995 gdb_byte **new_info_ptr,
996 struct die_info *parent);
998 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
999 struct die_info **, gdb_byte *,
1002 static void process_die (struct die_info *, struct dwarf2_cu *);
1004 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1007 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1009 static struct die_info *dwarf2_extension (struct die_info *die,
1010 struct dwarf2_cu **);
1012 static char *dwarf_tag_name (unsigned int);
1014 static char *dwarf_attr_name (unsigned int);
1016 static char *dwarf_form_name (unsigned int);
1018 static char *dwarf_bool_name (unsigned int);
1020 static char *dwarf_type_encoding_name (unsigned int);
1023 static char *dwarf_cfi_name (unsigned int);
1026 static struct die_info *sibling_die (struct die_info *);
1028 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1030 static void dump_die_for_error (struct die_info *);
1032 static void dump_die_1 (struct ui_file *, int level, int max_level,
1035 /*static*/ void dump_die (struct die_info *, int max_level);
1037 static void store_in_ref_table (struct die_info *,
1038 struct dwarf2_cu *);
1040 static int is_ref_attr (struct attribute *);
1042 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1044 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1046 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1048 struct dwarf2_cu **);
1050 static struct die_info *follow_die_ref (struct die_info *,
1052 struct dwarf2_cu **);
1054 static struct die_info *follow_die_sig (struct die_info *,
1056 struct dwarf2_cu **);
1058 static void read_signatured_type_at_offset (struct objfile *objfile,
1059 unsigned int offset);
1061 static void read_signatured_type (struct objfile *,
1062 struct signatured_type *type_sig);
1064 /* memory allocation interface */
1066 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1068 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1070 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1072 static void initialize_cu_func_list (struct dwarf2_cu *);
1074 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1075 struct dwarf2_cu *);
1077 static void dwarf_decode_macros (struct line_header *, unsigned int,
1078 char *, bfd *, struct dwarf2_cu *);
1080 static int attr_form_is_block (struct attribute *);
1082 static int attr_form_is_section_offset (struct attribute *);
1084 static int attr_form_is_constant (struct attribute *);
1086 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1088 struct dwarf2_cu *cu);
1090 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1091 struct abbrev_info *abbrev,
1092 struct dwarf2_cu *cu);
1094 static void free_stack_comp_unit (void *);
1096 static hashval_t partial_die_hash (const void *item);
1098 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1100 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1101 (unsigned int offset, struct objfile *objfile);
1103 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1104 (unsigned int offset, struct objfile *objfile);
1106 static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
1108 static void free_one_comp_unit (void *);
1110 static void free_cached_comp_units (void *);
1112 static void age_cached_comp_units (void);
1114 static void free_one_cached_comp_unit (void *);
1116 static struct type *set_die_type (struct die_info *, struct type *,
1117 struct dwarf2_cu *);
1119 static void create_all_comp_units (struct objfile *);
1121 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1124 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1126 static void dwarf2_add_dependence (struct dwarf2_cu *,
1127 struct dwarf2_per_cu_data *);
1129 static void dwarf2_mark (struct dwarf2_cu *);
1131 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1133 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1135 /* Try to locate the sections we need for DWARF 2 debugging
1136 information and return true if we have enough to do something. */
1139 dwarf2_has_info (struct objfile *objfile)
1141 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1142 if (!dwarf2_per_objfile)
1144 /* Initialize per-objfile state. */
1145 struct dwarf2_per_objfile *data
1146 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1148 memset (data, 0, sizeof (*data));
1149 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1150 dwarf2_per_objfile = data;
1152 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1153 dwarf2_per_objfile->objfile = objfile;
1155 return (dwarf2_per_objfile->info.asection != NULL
1156 && dwarf2_per_objfile->abbrev.asection != NULL);
1159 /* When loading sections, we can either look for ".<name>", or for
1160 * ".z<name>", which indicates a compressed section. */
1163 section_is_p (const char *section_name, const char *name)
1165 return (section_name[0] == '.'
1166 && (strcmp (section_name + 1, name) == 0
1167 || (section_name[1] == 'z'
1168 && strcmp (section_name + 2, name) == 0)));
1171 /* This function is mapped across the sections and remembers the
1172 offset and size of each of the debugging sections we are interested
1176 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1178 if (section_is_p (sectp->name, INFO_SECTION))
1180 dwarf2_per_objfile->info.asection = sectp;
1181 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1183 else if (section_is_p (sectp->name, ABBREV_SECTION))
1185 dwarf2_per_objfile->abbrev.asection = sectp;
1186 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1188 else if (section_is_p (sectp->name, LINE_SECTION))
1190 dwarf2_per_objfile->line.asection = sectp;
1191 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1193 else if (section_is_p (sectp->name, LOC_SECTION))
1195 dwarf2_per_objfile->loc.asection = sectp;
1196 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1198 else if (section_is_p (sectp->name, MACINFO_SECTION))
1200 dwarf2_per_objfile->macinfo.asection = sectp;
1201 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1203 else if (section_is_p (sectp->name, STR_SECTION))
1205 dwarf2_per_objfile->str.asection = sectp;
1206 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1208 else if (section_is_p (sectp->name, FRAME_SECTION))
1210 dwarf2_per_objfile->frame.asection = sectp;
1211 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1213 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1215 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1217 if (aflag & SEC_HAS_CONTENTS)
1219 dwarf2_per_objfile->eh_frame.asection = sectp;
1220 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1223 else if (section_is_p (sectp->name, RANGES_SECTION))
1225 dwarf2_per_objfile->ranges.asection = sectp;
1226 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1228 else if (section_is_p (sectp->name, TYPES_SECTION))
1230 dwarf2_per_objfile->types.asection = sectp;
1231 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1234 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1235 && bfd_section_vma (abfd, sectp) == 0)
1236 dwarf2_per_objfile->has_section_at_zero = 1;
1239 /* Decompress a section that was compressed using zlib. Store the
1240 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1243 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1244 gdb_byte **outbuf, bfd_size_type *outsize)
1246 bfd *abfd = objfile->obfd;
1248 error (_("Support for zlib-compressed DWARF data (from '%s') "
1249 "is disabled in this copy of GDB"),
1250 bfd_get_filename (abfd));
1252 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1253 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1254 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1255 bfd_size_type uncompressed_size;
1256 gdb_byte *uncompressed_buffer;
1259 int header_size = 12;
1261 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1262 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1263 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1264 bfd_get_filename (abfd));
1266 /* Read the zlib header. In this case, it should be "ZLIB" followed
1267 by the uncompressed section size, 8 bytes in big-endian order. */
1268 if (compressed_size < header_size
1269 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1270 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1271 bfd_get_filename (abfd));
1272 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1273 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1274 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1275 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1276 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1277 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1278 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1279 uncompressed_size += compressed_buffer[11];
1281 /* It is possible the section consists of several compressed
1282 buffers concatenated together, so we uncompress in a loop. */
1286 strm.avail_in = compressed_size - header_size;
1287 strm.next_in = (Bytef*) compressed_buffer + header_size;
1288 strm.avail_out = uncompressed_size;
1289 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1291 rc = inflateInit (&strm);
1292 while (strm.avail_in > 0)
1295 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1296 bfd_get_filename (abfd), rc);
1297 strm.next_out = ((Bytef*) uncompressed_buffer
1298 + (uncompressed_size - strm.avail_out));
1299 rc = inflate (&strm, Z_FINISH);
1300 if (rc != Z_STREAM_END)
1301 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1302 bfd_get_filename (abfd), rc);
1303 rc = inflateReset (&strm);
1305 rc = inflateEnd (&strm);
1307 || strm.avail_out != 0)
1308 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1309 bfd_get_filename (abfd), rc);
1311 do_cleanups (cleanup);
1312 *outbuf = uncompressed_buffer;
1313 *outsize = uncompressed_size;
1317 /* Read the contents of the section SECTP from object file specified by
1318 OBJFILE, store info about the section into INFO.
1319 If the section is compressed, uncompress it before returning. */
1322 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1324 bfd *abfd = objfile->obfd;
1325 asection *sectp = info->asection;
1326 gdb_byte *buf, *retbuf;
1327 unsigned char header[4];
1331 info->buffer = NULL;
1332 info->was_mmapped = 0;
1335 if (info->asection == NULL || info->size == 0)
1338 /* Check if the file has a 4-byte header indicating compression. */
1339 if (info->size > sizeof (header)
1340 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1341 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1343 /* Upon decompression, update the buffer and its size. */
1344 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1346 zlib_decompress_section (objfile, sectp, &info->buffer,
1354 pagesize = getpagesize ();
1356 /* Only try to mmap sections which are large enough: we don't want to
1357 waste space due to fragmentation. Also, only try mmap for sections
1358 without relocations. */
1360 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1362 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1363 size_t map_length = info->size + sectp->filepos - pg_offset;
1364 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1365 MAP_PRIVATE, pg_offset);
1367 if (retbuf != MAP_FAILED)
1369 info->was_mmapped = 1;
1370 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1371 #if HAVE_POSIX_MADVISE
1372 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1379 /* If we get here, we are a normal, not-compressed section. */
1381 = obstack_alloc (&objfile->objfile_obstack, info->size);
1383 /* When debugging .o files, we may need to apply relocations; see
1384 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1385 We never compress sections in .o files, so we only need to
1386 try this when the section is not compressed. */
1387 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1390 info->buffer = retbuf;
1394 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1395 || bfd_bread (buf, info->size, abfd) != info->size)
1396 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1397 bfd_get_filename (abfd));
1400 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1404 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1405 asection **sectp, gdb_byte **bufp,
1406 bfd_size_type *sizep)
1408 struct dwarf2_per_objfile *data
1409 = objfile_data (objfile, dwarf2_objfile_data_key);
1410 struct dwarf2_section_info *info;
1412 /* We may see an objfile without any DWARF, in which case we just
1421 if (section_is_p (section_name, EH_FRAME_SECTION))
1422 info = &data->eh_frame;
1423 else if (section_is_p (section_name, FRAME_SECTION))
1424 info = &data->frame;
1428 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1429 /* We haven't read this section in yet. Do it now. */
1430 dwarf2_read_section (objfile, info);
1432 *sectp = info->asection;
1433 *bufp = info->buffer;
1434 *sizep = info->size;
1437 /* Build a partial symbol table. */
1440 dwarf2_build_psymtabs (struct objfile *objfile)
1442 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
1444 init_psymbol_list (objfile, 1024);
1447 dwarf2_build_psymtabs_hard (objfile);
1450 /* Return TRUE if OFFSET is within CU_HEADER. */
1453 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
1455 unsigned int bottom = cu_header->offset;
1456 unsigned int top = (cu_header->offset
1458 + cu_header->initial_length_size);
1460 return (offset >= bottom && offset < top);
1463 /* Read in the comp unit header information from the debug_info at info_ptr.
1464 NOTE: This leaves members offset, first_die_offset to be filled in
1468 read_comp_unit_head (struct comp_unit_head *cu_header,
1469 gdb_byte *info_ptr, bfd *abfd)
1472 unsigned int bytes_read;
1474 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
1475 cu_header->initial_length_size = bytes_read;
1476 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
1477 info_ptr += bytes_read;
1478 cu_header->version = read_2_bytes (abfd, info_ptr);
1480 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1482 info_ptr += bytes_read;
1483 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1485 signed_addr = bfd_get_sign_extend_vma (abfd);
1486 if (signed_addr < 0)
1487 internal_error (__FILE__, __LINE__,
1488 _("read_comp_unit_head: dwarf from non elf file"));
1489 cu_header->signed_addr_p = signed_addr;
1495 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
1496 gdb_byte *buffer, unsigned int buffer_size,
1499 gdb_byte *beg_of_comp_unit = info_ptr;
1501 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1503 if (header->version != 2 && header->version != 3 && header->version != 4)
1504 error (_("Dwarf Error: wrong version in compilation unit header "
1505 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
1506 bfd_get_filename (abfd));
1508 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
1509 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1510 "(offset 0x%lx + 6) [in module %s]"),
1511 (long) header->abbrev_offset,
1512 (long) (beg_of_comp_unit - buffer),
1513 bfd_get_filename (abfd));
1515 if (beg_of_comp_unit + header->length + header->initial_length_size
1516 > buffer + buffer_size)
1517 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1518 "(offset 0x%lx + 0) [in module %s]"),
1519 (long) header->length,
1520 (long) (beg_of_comp_unit - buffer),
1521 bfd_get_filename (abfd));
1526 /* Read in the types comp unit header information from .debug_types entry at
1527 types_ptr. The result is a pointer to one past the end of the header. */
1530 read_type_comp_unit_head (struct comp_unit_head *cu_header,
1531 ULONGEST *signature,
1532 gdb_byte *types_ptr, bfd *abfd)
1534 gdb_byte *initial_types_ptr = types_ptr;
1536 dwarf2_read_section (dwarf2_per_objfile->objfile,
1537 &dwarf2_per_objfile->types);
1538 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
1540 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
1542 *signature = read_8_bytes (abfd, types_ptr);
1544 types_ptr += cu_header->offset_size;
1545 cu_header->first_die_offset = types_ptr - initial_types_ptr;
1550 /* Allocate a new partial symtab for file named NAME and mark this new
1551 partial symtab as being an include of PST. */
1554 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1555 struct objfile *objfile)
1557 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1559 subpst->section_offsets = pst->section_offsets;
1560 subpst->textlow = 0;
1561 subpst->texthigh = 0;
1563 subpst->dependencies = (struct partial_symtab **)
1564 obstack_alloc (&objfile->objfile_obstack,
1565 sizeof (struct partial_symtab *));
1566 subpst->dependencies[0] = pst;
1567 subpst->number_of_dependencies = 1;
1569 subpst->globals_offset = 0;
1570 subpst->n_global_syms = 0;
1571 subpst->statics_offset = 0;
1572 subpst->n_static_syms = 0;
1573 subpst->symtab = NULL;
1574 subpst->read_symtab = pst->read_symtab;
1577 /* No private part is necessary for include psymtabs. This property
1578 can be used to differentiate between such include psymtabs and
1579 the regular ones. */
1580 subpst->read_symtab_private = NULL;
1583 /* Read the Line Number Program data and extract the list of files
1584 included by the source file represented by PST. Build an include
1585 partial symtab for each of these included files. */
1588 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1589 struct die_info *die,
1590 struct partial_symtab *pst)
1592 struct objfile *objfile = cu->objfile;
1593 bfd *abfd = objfile->obfd;
1594 struct line_header *lh = NULL;
1595 struct attribute *attr;
1597 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
1600 unsigned int line_offset = DW_UNSND (attr);
1602 lh = dwarf_decode_line_header (line_offset, abfd, cu);
1605 return; /* No linetable, so no includes. */
1607 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1609 free_line_header (lh);
1613 hash_type_signature (const void *item)
1615 const struct signatured_type *type_sig = item;
1617 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1618 return type_sig->signature;
1622 eq_type_signature (const void *item_lhs, const void *item_rhs)
1624 const struct signatured_type *lhs = item_lhs;
1625 const struct signatured_type *rhs = item_rhs;
1627 return lhs->signature == rhs->signature;
1630 /* Create the hash table of all entries in the .debug_types section.
1631 The result is zero if there is an error (e.g. missing .debug_types section),
1632 otherwise non-zero. */
1635 create_debug_types_hash_table (struct objfile *objfile)
1640 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
1641 info_ptr = dwarf2_per_objfile->types.buffer;
1643 if (info_ptr == NULL)
1645 dwarf2_per_objfile->signatured_types = NULL;
1649 types_htab = htab_create_alloc_ex (41,
1650 hash_type_signature,
1653 &objfile->objfile_obstack,
1654 hashtab_obstack_allocate,
1655 dummy_obstack_deallocate);
1657 if (dwarf2_die_debug)
1658 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
1660 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1662 unsigned int offset;
1663 unsigned int offset_size;
1664 unsigned int type_offset;
1665 unsigned int length, initial_length_size;
1666 unsigned short version;
1668 struct signatured_type *type_sig;
1670 gdb_byte *ptr = info_ptr;
1672 offset = ptr - dwarf2_per_objfile->types.buffer;
1674 /* We need to read the type's signature in order to build the hash
1675 table, but we don't need to read anything else just yet. */
1677 /* Sanity check to ensure entire cu is present. */
1678 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
1679 if (ptr + length + initial_length_size
1680 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1682 complaint (&symfile_complaints,
1683 _("debug type entry runs off end of `.debug_types' section, ignored"));
1687 offset_size = initial_length_size == 4 ? 4 : 8;
1688 ptr += initial_length_size;
1689 version = bfd_get_16 (objfile->obfd, ptr);
1691 ptr += offset_size; /* abbrev offset */
1692 ptr += 1; /* address size */
1693 signature = bfd_get_64 (objfile->obfd, ptr);
1695 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
1697 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
1698 memset (type_sig, 0, sizeof (*type_sig));
1699 type_sig->signature = signature;
1700 type_sig->offset = offset;
1701 type_sig->type_offset = type_offset;
1703 slot = htab_find_slot (types_htab, type_sig, INSERT);
1704 gdb_assert (slot != NULL);
1707 if (dwarf2_die_debug)
1708 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
1709 offset, phex (signature, sizeof (signature)));
1711 info_ptr = info_ptr + initial_length_size + length;
1714 dwarf2_per_objfile->signatured_types = types_htab;
1719 /* Lookup a signature based type.
1720 Returns NULL if SIG is not present in the table. */
1722 static struct signatured_type *
1723 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
1725 struct signatured_type find_entry, *entry;
1727 if (dwarf2_per_objfile->signatured_types == NULL)
1729 complaint (&symfile_complaints,
1730 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1734 find_entry.signature = sig;
1735 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
1739 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1742 init_cu_die_reader (struct die_reader_specs *reader,
1743 struct dwarf2_cu *cu)
1745 reader->abfd = cu->objfile->obfd;
1747 if (cu->per_cu->from_debug_types)
1749 gdb_assert (dwarf2_per_objfile->types.readin);
1750 reader->buffer = dwarf2_per_objfile->types.buffer;
1754 gdb_assert (dwarf2_per_objfile->info.readin);
1755 reader->buffer = dwarf2_per_objfile->info.buffer;
1759 /* Find the base address of the compilation unit for range lists and
1760 location lists. It will normally be specified by DW_AT_low_pc.
1761 In DWARF-3 draft 4, the base address could be overridden by
1762 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1763 compilation units with discontinuous ranges. */
1766 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
1768 struct attribute *attr;
1771 cu->base_address = 0;
1773 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
1776 cu->base_address = DW_ADDR (attr);
1781 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
1784 cu->base_address = DW_ADDR (attr);
1790 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1791 to combine the common parts.
1792 Process a compilation unit for a psymtab.
1793 BUFFER is a pointer to the beginning of the dwarf section buffer,
1794 either .debug_info or debug_types.
1795 INFO_PTR is a pointer to the start of the CU.
1796 Returns a pointer to the next CU. */
1799 process_psymtab_comp_unit (struct objfile *objfile,
1800 struct dwarf2_per_cu_data *this_cu,
1801 gdb_byte *buffer, gdb_byte *info_ptr,
1802 unsigned int buffer_size)
1804 bfd *abfd = objfile->obfd;
1805 gdb_byte *beg_of_comp_unit = info_ptr;
1806 struct die_info *comp_unit_die;
1807 struct partial_symtab *pst;
1809 struct cleanup *back_to_inner;
1810 struct dwarf2_cu cu;
1811 int has_children, has_pc_info;
1812 struct attribute *attr;
1813 CORE_ADDR best_lowpc = 0, best_highpc = 0;
1814 struct die_reader_specs reader_specs;
1816 memset (&cu, 0, sizeof (cu));
1817 cu.objfile = objfile;
1818 obstack_init (&cu.comp_unit_obstack);
1820 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1822 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
1823 buffer, buffer_size,
1826 /* Complete the cu_header. */
1827 cu.header.offset = beg_of_comp_unit - buffer;
1828 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1830 cu.list_in_scope = &file_symbols;
1832 /* If this compilation unit was already read in, free the
1833 cached copy in order to read it in again. This is
1834 necessary because we skipped some symbols when we first
1835 read in the compilation unit (see load_partial_dies).
1836 This problem could be avoided, but the benefit is
1838 if (this_cu->cu != NULL)
1839 free_one_cached_comp_unit (this_cu->cu);
1841 /* Note that this is a pointer to our stack frame, being
1842 added to a global data structure. It will be cleaned up
1843 in free_stack_comp_unit when we finish with this
1844 compilation unit. */
1846 cu.per_cu = this_cu;
1848 /* Read the abbrevs for this compilation unit into a table. */
1849 dwarf2_read_abbrevs (abfd, &cu);
1850 make_cleanup (dwarf2_free_abbrev_table, &cu);
1852 /* Read the compilation unit die. */
1853 if (this_cu->from_debug_types)
1854 info_ptr += 8 /*signature*/ + cu.header.offset_size;
1855 init_cu_die_reader (&reader_specs, &cu);
1856 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
1859 if (this_cu->from_debug_types)
1861 /* offset,length haven't been set yet for type units. */
1862 this_cu->offset = cu.header.offset;
1863 this_cu->length = cu.header.length + cu.header.initial_length_size;
1865 else if (comp_unit_die->tag == DW_TAG_partial_unit)
1867 info_ptr = (beg_of_comp_unit + cu.header.length
1868 + cu.header.initial_length_size);
1869 do_cleanups (back_to_inner);
1873 /* Set the language we're debugging. */
1874 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
1876 set_cu_language (DW_UNSND (attr), &cu);
1878 set_cu_language (language_minimal, &cu);
1880 /* Allocate a new partial symbol table structure. */
1881 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
1882 pst = start_psymtab_common (objfile, objfile->section_offsets,
1883 (attr != NULL) ? DW_STRING (attr) : "",
1884 /* TEXTLOW and TEXTHIGH are set below. */
1886 objfile->global_psymbols.next,
1887 objfile->static_psymbols.next);
1889 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
1891 pst->dirname = DW_STRING (attr);
1893 pst->read_symtab_private = this_cu;
1895 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1897 /* Store the function that reads in the rest of the symbol table */
1898 pst->read_symtab = dwarf2_psymtab_to_symtab;
1900 this_cu->psymtab = pst;
1902 dwarf2_find_base_address (comp_unit_die, &cu);
1904 /* Possibly set the default values of LOWPC and HIGHPC from
1906 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
1907 &best_highpc, &cu, pst);
1908 if (has_pc_info == 1 && best_lowpc < best_highpc)
1909 /* Store the contiguous range if it is not empty; it can be empty for
1910 CUs with no code. */
1911 addrmap_set_empty (objfile->psymtabs_addrmap,
1912 best_lowpc + baseaddr,
1913 best_highpc + baseaddr - 1, pst);
1915 /* Check if comp unit has_children.
1916 If so, read the rest of the partial symbols from this comp unit.
1917 If not, there's no more debug_info for this comp unit. */
1920 struct partial_die_info *first_die;
1921 CORE_ADDR lowpc, highpc;
1923 lowpc = ((CORE_ADDR) -1);
1924 highpc = ((CORE_ADDR) 0);
1926 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
1928 scan_partial_symbols (first_die, &lowpc, &highpc,
1929 ! has_pc_info, &cu);
1931 /* If we didn't find a lowpc, set it to highpc to avoid
1932 complaints from `maint check'. */
1933 if (lowpc == ((CORE_ADDR) -1))
1936 /* If the compilation unit didn't have an explicit address range,
1937 then use the information extracted from its child dies. */
1941 best_highpc = highpc;
1944 pst->textlow = best_lowpc + baseaddr;
1945 pst->texthigh = best_highpc + baseaddr;
1947 pst->n_global_syms = objfile->global_psymbols.next -
1948 (objfile->global_psymbols.list + pst->globals_offset);
1949 pst->n_static_syms = objfile->static_psymbols.next -
1950 (objfile->static_psymbols.list + pst->statics_offset);
1951 sort_pst_symbols (pst);
1953 info_ptr = (beg_of_comp_unit + cu.header.length
1954 + cu.header.initial_length_size);
1956 if (this_cu->from_debug_types)
1958 /* It's not clear we want to do anything with stmt lists here.
1959 Waiting to see what gcc ultimately does. */
1963 /* Get the list of files included in the current compilation unit,
1964 and build a psymtab for each of them. */
1965 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
1968 do_cleanups (back_to_inner);
1973 /* Traversal function for htab_traverse_noresize.
1974 Process one .debug_types comp-unit. */
1977 process_type_comp_unit (void **slot, void *info)
1979 struct signatured_type *entry = (struct signatured_type *) *slot;
1980 struct objfile *objfile = (struct objfile *) info;
1981 struct dwarf2_per_cu_data *this_cu;
1983 this_cu = &entry->per_cu;
1984 this_cu->from_debug_types = 1;
1986 gdb_assert (dwarf2_per_objfile->types.readin);
1987 process_psymtab_comp_unit (objfile, this_cu,
1988 dwarf2_per_objfile->types.buffer,
1989 dwarf2_per_objfile->types.buffer + entry->offset,
1990 dwarf2_per_objfile->types.size);
1995 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1996 Build partial symbol tables for the .debug_types comp-units. */
1999 build_type_psymtabs (struct objfile *objfile)
2001 if (! create_debug_types_hash_table (objfile))
2004 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
2005 process_type_comp_unit, objfile);
2008 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
2011 psymtabs_addrmap_cleanup (void *o)
2013 struct objfile *objfile = o;
2015 objfile->psymtabs_addrmap = NULL;
2018 /* Build the partial symbol table by doing a quick pass through the
2019 .debug_info and .debug_abbrev sections. */
2022 dwarf2_build_psymtabs_hard (struct objfile *objfile)
2025 struct cleanup *back_to, *addrmap_cleanup;
2026 struct obstack temp_obstack;
2028 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2029 info_ptr = dwarf2_per_objfile->info.buffer;
2031 /* Any cached compilation units will be linked by the per-objfile
2032 read_in_chain. Make sure to free them when we're done. */
2033 back_to = make_cleanup (free_cached_comp_units, NULL);
2035 build_type_psymtabs (objfile);
2037 create_all_comp_units (objfile);
2039 /* Create a temporary address map on a temporary obstack. We later
2040 copy this to the final obstack. */
2041 obstack_init (&temp_obstack);
2042 make_cleanup_obstack_free (&temp_obstack);
2043 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
2044 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
2046 /* Since the objects we're extracting from .debug_info vary in
2047 length, only the individual functions to extract them (like
2048 read_comp_unit_head and load_partial_die) can really know whether
2049 the buffer is large enough to hold another complete object.
2051 At the moment, they don't actually check that. If .debug_info
2052 holds just one extra byte after the last compilation unit's dies,
2053 then read_comp_unit_head will happily read off the end of the
2054 buffer. read_partial_die is similarly casual. Those functions
2057 For this loop condition, simply checking whether there's any data
2058 left at all should be sufficient. */
2060 while (info_ptr < (dwarf2_per_objfile->info.buffer
2061 + dwarf2_per_objfile->info.size))
2063 struct dwarf2_per_cu_data *this_cu;
2065 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
2068 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
2069 dwarf2_per_objfile->info.buffer,
2071 dwarf2_per_objfile->info.size);
2074 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
2075 &objfile->objfile_obstack);
2076 discard_cleanups (addrmap_cleanup);
2078 do_cleanups (back_to);
2081 /* Load the partial DIEs for a secondary CU into memory. */
2084 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
2085 struct objfile *objfile)
2087 bfd *abfd = objfile->obfd;
2088 gdb_byte *info_ptr, *beg_of_comp_unit;
2089 struct die_info *comp_unit_die;
2090 struct dwarf2_cu *cu;
2091 struct cleanup *back_to;
2092 struct attribute *attr;
2094 struct die_reader_specs reader_specs;
2096 gdb_assert (! this_cu->from_debug_types);
2098 gdb_assert (dwarf2_per_objfile->info.readin);
2099 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
2100 beg_of_comp_unit = info_ptr;
2102 cu = alloc_one_comp_unit (objfile);
2104 /* ??? Missing cleanup for CU? */
2106 /* Link this compilation unit into the compilation unit tree. */
2108 cu->per_cu = this_cu;
2109 cu->type_hash = this_cu->type_hash;
2111 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
2112 dwarf2_per_objfile->info.buffer,
2113 dwarf2_per_objfile->info.size,
2116 /* Complete the cu_header. */
2117 cu->header.offset = this_cu->offset;
2118 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
2120 /* Read the abbrevs for this compilation unit into a table. */
2121 dwarf2_read_abbrevs (abfd, cu);
2122 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2124 /* Read the compilation unit die. */
2125 init_cu_die_reader (&reader_specs, cu);
2126 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2129 /* Set the language we're debugging. */
2130 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
2132 set_cu_language (DW_UNSND (attr), cu);
2134 set_cu_language (language_minimal, cu);
2136 /* Check if comp unit has_children.
2137 If so, read the rest of the partial symbols from this comp unit.
2138 If not, there's no more debug_info for this comp unit. */
2140 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
2142 do_cleanups (back_to);
2145 /* Create a list of all compilation units in OBJFILE. We do this only
2146 if an inter-comp-unit reference is found; presumably if there is one,
2147 there will be many, and one will occur early in the .debug_info section.
2148 So there's no point in building this list incrementally. */
2151 create_all_comp_units (struct objfile *objfile)
2155 struct dwarf2_per_cu_data **all_comp_units;
2158 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2159 info_ptr = dwarf2_per_objfile->info.buffer;
2163 all_comp_units = xmalloc (n_allocated
2164 * sizeof (struct dwarf2_per_cu_data *));
2166 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
2168 unsigned int length, initial_length_size;
2169 struct dwarf2_per_cu_data *this_cu;
2170 unsigned int offset;
2172 offset = info_ptr - dwarf2_per_objfile->info.buffer;
2174 /* Read just enough information to find out where the next
2175 compilation unit is. */
2176 length = read_initial_length (objfile->obfd, info_ptr,
2177 &initial_length_size);
2179 /* Save the compilation unit for later lookup. */
2180 this_cu = obstack_alloc (&objfile->objfile_obstack,
2181 sizeof (struct dwarf2_per_cu_data));
2182 memset (this_cu, 0, sizeof (*this_cu));
2183 this_cu->offset = offset;
2184 this_cu->length = length + initial_length_size;
2186 if (n_comp_units == n_allocated)
2189 all_comp_units = xrealloc (all_comp_units,
2191 * sizeof (struct dwarf2_per_cu_data *));
2193 all_comp_units[n_comp_units++] = this_cu;
2195 info_ptr = info_ptr + this_cu->length;
2198 dwarf2_per_objfile->all_comp_units
2199 = obstack_alloc (&objfile->objfile_obstack,
2200 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2201 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
2202 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2203 xfree (all_comp_units);
2204 dwarf2_per_objfile->n_comp_units = n_comp_units;
2207 /* Process all loaded DIEs for compilation unit CU, starting at
2208 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2209 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2210 DW_AT_ranges). If NEED_PC is set, then this function will set
2211 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2212 and record the covered ranges in the addrmap. */
2215 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
2216 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2218 struct partial_die_info *pdi;
2220 /* Now, march along the PDI's, descending into ones which have
2221 interesting children but skipping the children of the other ones,
2222 until we reach the end of the compilation unit. */
2228 fixup_partial_die (pdi, cu);
2230 /* Anonymous namespaces or modules have no name but have interesting
2231 children, so we need to look at them. Ditto for anonymous
2234 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
2235 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
2239 case DW_TAG_subprogram:
2240 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2242 case DW_TAG_variable:
2243 case DW_TAG_typedef:
2244 case DW_TAG_union_type:
2245 if (!pdi->is_declaration)
2247 add_partial_symbol (pdi, cu);
2250 case DW_TAG_class_type:
2251 case DW_TAG_interface_type:
2252 case DW_TAG_structure_type:
2253 if (!pdi->is_declaration)
2255 add_partial_symbol (pdi, cu);
2258 case DW_TAG_enumeration_type:
2259 if (!pdi->is_declaration)
2260 add_partial_enumeration (pdi, cu);
2262 case DW_TAG_base_type:
2263 case DW_TAG_subrange_type:
2264 /* File scope base type definitions are added to the partial
2266 add_partial_symbol (pdi, cu);
2268 case DW_TAG_namespace:
2269 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
2272 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
2279 /* If the die has a sibling, skip to the sibling. */
2281 pdi = pdi->die_sibling;
2285 /* Functions used to compute the fully scoped name of a partial DIE.
2287 Normally, this is simple. For C++, the parent DIE's fully scoped
2288 name is concatenated with "::" and the partial DIE's name. For
2289 Java, the same thing occurs except that "." is used instead of "::".
2290 Enumerators are an exception; they use the scope of their parent
2291 enumeration type, i.e. the name of the enumeration type is not
2292 prepended to the enumerator.
2294 There are two complexities. One is DW_AT_specification; in this
2295 case "parent" means the parent of the target of the specification,
2296 instead of the direct parent of the DIE. The other is compilers
2297 which do not emit DW_TAG_namespace; in this case we try to guess
2298 the fully qualified name of structure types from their members'
2299 linkage names. This must be done using the DIE's children rather
2300 than the children of any DW_AT_specification target. We only need
2301 to do this for structures at the top level, i.e. if the target of
2302 any DW_AT_specification (if any; otherwise the DIE itself) does not
2305 /* Compute the scope prefix associated with PDI's parent, in
2306 compilation unit CU. The result will be allocated on CU's
2307 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2308 field. NULL is returned if no prefix is necessary. */
2310 partial_die_parent_scope (struct partial_die_info *pdi,
2311 struct dwarf2_cu *cu)
2313 char *grandparent_scope;
2314 struct partial_die_info *parent, *real_pdi;
2316 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2317 then this means the parent of the specification DIE. */
2320 while (real_pdi->has_specification)
2321 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2323 parent = real_pdi->die_parent;
2327 if (parent->scope_set)
2328 return parent->scope;
2330 fixup_partial_die (parent, cu);
2332 grandparent_scope = partial_die_parent_scope (parent, cu);
2334 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
2335 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
2336 Work around this problem here. */
2337 if (cu->language == language_cplus
2338 && parent->tag == DW_TAG_namespace
2339 && strcmp (parent->name, "::") == 0
2340 && grandparent_scope == NULL)
2342 parent->scope = NULL;
2343 parent->scope_set = 1;
2347 if (parent->tag == DW_TAG_namespace
2348 || parent->tag == DW_TAG_module
2349 || parent->tag == DW_TAG_structure_type
2350 || parent->tag == DW_TAG_class_type
2351 || parent->tag == DW_TAG_interface_type
2352 || parent->tag == DW_TAG_union_type
2353 || parent->tag == DW_TAG_enumeration_type)
2355 if (grandparent_scope == NULL)
2356 parent->scope = parent->name;
2358 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
2359 parent->name, 0, cu);
2361 else if (parent->tag == DW_TAG_enumerator)
2362 /* Enumerators should not get the name of the enumeration as a prefix. */
2363 parent->scope = grandparent_scope;
2366 /* FIXME drow/2004-04-01: What should we be doing with
2367 function-local names? For partial symbols, we should probably be
2369 complaint (&symfile_complaints,
2370 _("unhandled containing DIE tag %d for DIE at %d"),
2371 parent->tag, pdi->offset);
2372 parent->scope = grandparent_scope;
2375 parent->scope_set = 1;
2376 return parent->scope;
2379 /* Return the fully scoped name associated with PDI, from compilation unit
2380 CU. The result will be allocated with malloc. */
2382 partial_die_full_name (struct partial_die_info *pdi,
2383 struct dwarf2_cu *cu)
2387 parent_scope = partial_die_parent_scope (pdi, cu);
2388 if (parent_scope == NULL)
2391 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
2395 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
2397 struct objfile *objfile = cu->objfile;
2399 char *actual_name = NULL;
2400 const struct partial_symbol *psym = NULL;
2402 int built_actual_name = 0;
2404 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2406 actual_name = partial_die_full_name (pdi, cu);
2408 built_actual_name = 1;
2410 if (actual_name == NULL)
2411 actual_name = pdi->name;
2415 case DW_TAG_subprogram:
2416 if (pdi->is_external || cu->language == language_ada)
2418 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2419 of the global scope. But in Ada, we want to be able to access
2420 nested procedures globally. So all Ada subprograms are stored
2421 in the global scope. */
2422 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2423 mst_text, objfile); */
2424 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2426 VAR_DOMAIN, LOC_BLOCK,
2427 &objfile->global_psymbols,
2428 0, pdi->lowpc + baseaddr,
2429 cu->language, objfile);
2433 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2434 mst_file_text, objfile); */
2435 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2437 VAR_DOMAIN, LOC_BLOCK,
2438 &objfile->static_psymbols,
2439 0, pdi->lowpc + baseaddr,
2440 cu->language, objfile);
2443 case DW_TAG_variable:
2444 if (pdi->is_external)
2447 Don't enter into the minimal symbol tables as there is
2448 a minimal symbol table entry from the ELF symbols already.
2449 Enter into partial symbol table if it has a location
2450 descriptor or a type.
2451 If the location descriptor is missing, new_symbol will create
2452 a LOC_UNRESOLVED symbol, the address of the variable will then
2453 be determined from the minimal symbol table whenever the variable
2455 The address for the partial symbol table entry is not
2456 used by GDB, but it comes in handy for debugging partial symbol
2460 addr = decode_locdesc (pdi->locdesc, cu);
2461 if (pdi->locdesc || pdi->has_type)
2462 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2464 VAR_DOMAIN, LOC_STATIC,
2465 &objfile->global_psymbols,
2467 cu->language, objfile);
2471 /* Static Variable. Skip symbols without location descriptors. */
2472 if (pdi->locdesc == NULL)
2474 if (built_actual_name)
2475 xfree (actual_name);
2478 addr = decode_locdesc (pdi->locdesc, cu);
2479 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2480 mst_file_data, objfile); */
2481 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2483 VAR_DOMAIN, LOC_STATIC,
2484 &objfile->static_psymbols,
2486 cu->language, objfile);
2489 case DW_TAG_typedef:
2490 case DW_TAG_base_type:
2491 case DW_TAG_subrange_type:
2492 add_psymbol_to_list (actual_name, strlen (actual_name),
2494 VAR_DOMAIN, LOC_TYPEDEF,
2495 &objfile->static_psymbols,
2496 0, (CORE_ADDR) 0, cu->language, objfile);
2498 case DW_TAG_namespace:
2499 add_psymbol_to_list (actual_name, strlen (actual_name),
2501 VAR_DOMAIN, LOC_TYPEDEF,
2502 &objfile->global_psymbols,
2503 0, (CORE_ADDR) 0, cu->language, objfile);
2505 case DW_TAG_class_type:
2506 case DW_TAG_interface_type:
2507 case DW_TAG_structure_type:
2508 case DW_TAG_union_type:
2509 case DW_TAG_enumeration_type:
2510 /* Skip external references. The DWARF standard says in the section
2511 about "Structure, Union, and Class Type Entries": "An incomplete
2512 structure, union or class type is represented by a structure,
2513 union or class entry that does not have a byte size attribute
2514 and that has a DW_AT_declaration attribute." */
2515 if (!pdi->has_byte_size && pdi->is_declaration)
2517 if (built_actual_name)
2518 xfree (actual_name);
2522 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2523 static vs. global. */
2524 add_psymbol_to_list (actual_name, strlen (actual_name),
2526 STRUCT_DOMAIN, LOC_TYPEDEF,
2527 (cu->language == language_cplus
2528 || cu->language == language_java)
2529 ? &objfile->global_psymbols
2530 : &objfile->static_psymbols,
2531 0, (CORE_ADDR) 0, cu->language, objfile);
2534 case DW_TAG_enumerator:
2535 add_psymbol_to_list (actual_name, strlen (actual_name),
2537 VAR_DOMAIN, LOC_CONST,
2538 (cu->language == language_cplus
2539 || cu->language == language_java)
2540 ? &objfile->global_psymbols
2541 : &objfile->static_psymbols,
2542 0, (CORE_ADDR) 0, cu->language, objfile);
2548 if (built_actual_name)
2549 xfree (actual_name);
2552 /* Read a partial die corresponding to a namespace; also, add a symbol
2553 corresponding to that namespace to the symbol table. NAMESPACE is
2554 the name of the enclosing namespace. */
2557 add_partial_namespace (struct partial_die_info *pdi,
2558 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2559 int need_pc, struct dwarf2_cu *cu)
2561 /* Add a symbol for the namespace. */
2563 add_partial_symbol (pdi, cu);
2565 /* Now scan partial symbols in that namespace. */
2567 if (pdi->has_children)
2568 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2571 /* Read a partial die corresponding to a Fortran module. */
2574 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
2575 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2577 /* Now scan partial symbols in that module. */
2579 if (pdi->has_children)
2580 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2583 /* Read a partial die corresponding to a subprogram and create a partial
2584 symbol for that subprogram. When the CU language allows it, this
2585 routine also defines a partial symbol for each nested subprogram
2586 that this subprogram contains.
2588 DIE my also be a lexical block, in which case we simply search
2589 recursively for suprograms defined inside that lexical block.
2590 Again, this is only performed when the CU language allows this
2591 type of definitions. */
2594 add_partial_subprogram (struct partial_die_info *pdi,
2595 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2596 int need_pc, struct dwarf2_cu *cu)
2598 if (pdi->tag == DW_TAG_subprogram)
2600 if (pdi->has_pc_info)
2602 if (pdi->lowpc < *lowpc)
2603 *lowpc = pdi->lowpc;
2604 if (pdi->highpc > *highpc)
2605 *highpc = pdi->highpc;
2609 struct objfile *objfile = cu->objfile;
2611 baseaddr = ANOFFSET (objfile->section_offsets,
2612 SECT_OFF_TEXT (objfile));
2613 addrmap_set_empty (objfile->psymtabs_addrmap,
2614 pdi->lowpc + baseaddr,
2615 pdi->highpc - 1 + baseaddr,
2616 cu->per_cu->psymtab);
2618 if (!pdi->is_declaration)
2619 /* Ignore subprogram DIEs that do not have a name, they are
2620 illegal. Do not emit a complaint at this point, we will
2621 do so when we convert this psymtab into a symtab. */
2623 add_partial_symbol (pdi, cu);
2627 if (! pdi->has_children)
2630 if (cu->language == language_ada)
2632 pdi = pdi->die_child;
2635 fixup_partial_die (pdi, cu);
2636 if (pdi->tag == DW_TAG_subprogram
2637 || pdi->tag == DW_TAG_lexical_block)
2638 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2639 pdi = pdi->die_sibling;
2644 /* See if we can figure out if the class lives in a namespace. We do
2645 this by looking for a member function; its demangled name will
2646 contain namespace info, if there is any. */
2649 guess_structure_name (struct partial_die_info *struct_pdi,
2650 struct dwarf2_cu *cu)
2652 if ((cu->language == language_cplus
2653 || cu->language == language_java)
2654 && cu->has_namespace_info == 0
2655 && struct_pdi->has_children)
2657 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2658 what template types look like, because the demangler
2659 frequently doesn't give the same name as the debug info. We
2660 could fix this by only using the demangled name to get the
2661 prefix (but see comment in read_structure_type). */
2663 struct partial_die_info *real_pdi;
2665 /* If this DIE (this DIE's specification, if any) has a parent, then
2666 we should not do this. We'll prepend the parent's fully qualified
2667 name when we create the partial symbol. */
2669 real_pdi = struct_pdi;
2670 while (real_pdi->has_specification)
2671 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2673 if (real_pdi->die_parent != NULL)
2678 /* Read a partial die corresponding to an enumeration type. */
2681 add_partial_enumeration (struct partial_die_info *enum_pdi,
2682 struct dwarf2_cu *cu)
2684 struct partial_die_info *pdi;
2686 if (enum_pdi->name != NULL)
2687 add_partial_symbol (enum_pdi, cu);
2689 pdi = enum_pdi->die_child;
2692 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2693 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2695 add_partial_symbol (pdi, cu);
2696 pdi = pdi->die_sibling;
2700 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2701 Return the corresponding abbrev, or NULL if the number is zero (indicating
2702 an empty DIE). In either case *BYTES_READ will be set to the length of
2703 the initial number. */
2705 static struct abbrev_info *
2706 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
2707 struct dwarf2_cu *cu)
2709 bfd *abfd = cu->objfile->obfd;
2710 unsigned int abbrev_number;
2711 struct abbrev_info *abbrev;
2713 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2715 if (abbrev_number == 0)
2718 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2721 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2722 bfd_get_filename (abfd));
2728 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2729 Returns a pointer to the end of a series of DIEs, terminated by an empty
2730 DIE. Any children of the skipped DIEs will also be skipped. */
2733 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
2735 struct abbrev_info *abbrev;
2736 unsigned int bytes_read;
2740 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2742 return info_ptr + bytes_read;
2744 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
2748 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2749 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2750 abbrev corresponding to that skipped uleb128 should be passed in
2751 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2755 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
2756 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
2758 unsigned int bytes_read;
2759 struct attribute attr;
2760 bfd *abfd = cu->objfile->obfd;
2761 unsigned int form, i;
2763 for (i = 0; i < abbrev->num_attrs; i++)
2765 /* The only abbrev we care about is DW_AT_sibling. */
2766 if (abbrev->attrs[i].name == DW_AT_sibling)
2768 read_attribute (&attr, &abbrev->attrs[i],
2769 abfd, info_ptr, cu);
2770 if (attr.form == DW_FORM_ref_addr)
2771 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2773 return buffer + dwarf2_get_ref_die_offset (&attr);
2776 /* If it isn't DW_AT_sibling, skip this attribute. */
2777 form = abbrev->attrs[i].form;
2781 case DW_FORM_ref_addr:
2782 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2783 and later it is offset sized. */
2784 if (cu->header.version == 2)
2785 info_ptr += cu->header.addr_size;
2787 info_ptr += cu->header.offset_size;
2790 info_ptr += cu->header.addr_size;
2797 case DW_FORM_flag_present:
2812 case DW_FORM_string:
2813 read_string (abfd, info_ptr, &bytes_read);
2814 info_ptr += bytes_read;
2816 case DW_FORM_sec_offset:
2818 info_ptr += cu->header.offset_size;
2820 case DW_FORM_exprloc:
2822 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2823 info_ptr += bytes_read;
2825 case DW_FORM_block1:
2826 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2828 case DW_FORM_block2:
2829 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2831 case DW_FORM_block4:
2832 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2836 case DW_FORM_ref_udata:
2837 info_ptr = skip_leb128 (abfd, info_ptr);
2839 case DW_FORM_indirect:
2840 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2841 info_ptr += bytes_read;
2842 /* We need to continue parsing from here, so just go back to
2844 goto skip_attribute;
2847 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2848 dwarf_form_name (form),
2849 bfd_get_filename (abfd));
2853 if (abbrev->has_children)
2854 return skip_children (buffer, info_ptr, cu);
2859 /* Locate ORIG_PDI's sibling.
2860 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2864 locate_pdi_sibling (struct partial_die_info *orig_pdi,
2865 gdb_byte *buffer, gdb_byte *info_ptr,
2866 bfd *abfd, struct dwarf2_cu *cu)
2868 /* Do we know the sibling already? */
2870 if (orig_pdi->sibling)
2871 return orig_pdi->sibling;
2873 /* Are there any children to deal with? */
2875 if (!orig_pdi->has_children)
2878 /* Skip the children the long way. */
2880 return skip_children (buffer, info_ptr, cu);
2883 /* Expand this partial symbol table into a full symbol table. */
2886 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2888 /* FIXME: This is barely more than a stub. */
2893 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2899 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2900 gdb_flush (gdb_stdout);
2903 /* Restore our global data. */
2904 dwarf2_per_objfile = objfile_data (pst->objfile,
2905 dwarf2_objfile_data_key);
2907 /* If this psymtab is constructed from a debug-only objfile, the
2908 has_section_at_zero flag will not necessarily be correct. We
2909 can get the correct value for this flag by looking at the data
2910 associated with the (presumably stripped) associated objfile. */
2911 if (pst->objfile->separate_debug_objfile_backlink)
2913 struct dwarf2_per_objfile *dpo_backlink
2914 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
2915 dwarf2_objfile_data_key);
2917 dwarf2_per_objfile->has_section_at_zero
2918 = dpo_backlink->has_section_at_zero;
2921 psymtab_to_symtab_1 (pst);
2923 /* Finish up the debug error message. */
2925 printf_filtered (_("done.\n"));
2930 /* Add PER_CU to the queue. */
2933 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2935 struct dwarf2_queue_item *item;
2938 item = xmalloc (sizeof (*item));
2939 item->per_cu = per_cu;
2942 if (dwarf2_queue == NULL)
2943 dwarf2_queue = item;
2945 dwarf2_queue_tail->next = item;
2947 dwarf2_queue_tail = item;
2950 /* Process the queue. */
2953 process_queue (struct objfile *objfile)
2955 struct dwarf2_queue_item *item, *next_item;
2957 /* The queue starts out with one item, but following a DIE reference
2958 may load a new CU, adding it to the end of the queue. */
2959 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
2961 if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
2962 process_full_comp_unit (item->per_cu);
2964 item->per_cu->queued = 0;
2965 next_item = item->next;
2969 dwarf2_queue_tail = NULL;
2972 /* Free all allocated queue entries. This function only releases anything if
2973 an error was thrown; if the queue was processed then it would have been
2974 freed as we went along. */
2977 dwarf2_release_queue (void *dummy)
2979 struct dwarf2_queue_item *item, *last;
2981 item = dwarf2_queue;
2984 /* Anything still marked queued is likely to be in an
2985 inconsistent state, so discard it. */
2986 if (item->per_cu->queued)
2988 if (item->per_cu->cu != NULL)
2989 free_one_cached_comp_unit (item->per_cu->cu);
2990 item->per_cu->queued = 0;
2998 dwarf2_queue = dwarf2_queue_tail = NULL;
3001 /* Read in full symbols for PST, and anything it depends on. */
3004 psymtab_to_symtab_1 (struct partial_symtab *pst)
3006 struct dwarf2_per_cu_data *per_cu;
3007 struct cleanup *back_to;
3010 for (i = 0; i < pst->number_of_dependencies; i++)
3011 if (!pst->dependencies[i]->readin)
3013 /* Inform about additional files that need to be read in. */
3016 /* FIXME: i18n: Need to make this a single string. */
3017 fputs_filtered (" ", gdb_stdout);
3019 fputs_filtered ("and ", gdb_stdout);
3021 printf_filtered ("%s...", pst->dependencies[i]->filename);
3022 wrap_here (""); /* Flush output */
3023 gdb_flush (gdb_stdout);
3025 psymtab_to_symtab_1 (pst->dependencies[i]);
3028 per_cu = pst->read_symtab_private;
3032 /* It's an include file, no symbols to read for it.
3033 Everything is in the parent symtab. */
3038 back_to = make_cleanup (dwarf2_release_queue, NULL);
3040 queue_comp_unit (per_cu, pst->objfile);
3042 if (per_cu->from_debug_types)
3043 read_signatured_type_at_offset (pst->objfile, per_cu->offset);
3045 load_full_comp_unit (per_cu, pst->objfile);
3047 process_queue (pst->objfile);
3049 /* Age the cache, releasing compilation units that have not
3050 been used recently. */
3051 age_cached_comp_units ();
3053 do_cleanups (back_to);
3056 /* Load the DIEs associated with PER_CU into memory. */
3059 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3061 bfd *abfd = objfile->obfd;
3062 struct dwarf2_cu *cu;
3063 unsigned int offset;
3064 gdb_byte *info_ptr, *beg_of_comp_unit;
3065 struct cleanup *back_to, *free_cu_cleanup;
3066 struct attribute *attr;
3068 gdb_assert (! per_cu->from_debug_types);
3070 /* Set local variables from the partial symbol table info. */
3071 offset = per_cu->offset;
3073 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3074 info_ptr = dwarf2_per_objfile->info.buffer + offset;
3075 beg_of_comp_unit = info_ptr;
3077 cu = alloc_one_comp_unit (objfile);
3079 /* If an error occurs while loading, release our storage. */
3080 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3082 /* Read in the comp_unit header. */
3083 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
3085 /* Complete the cu_header. */
3086 cu->header.offset = offset;
3087 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3089 /* Read the abbrevs for this compilation unit. */
3090 dwarf2_read_abbrevs (abfd, cu);
3091 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
3093 /* Link this compilation unit into the compilation unit tree. */
3095 cu->per_cu = per_cu;
3096 cu->type_hash = per_cu->type_hash;
3098 cu->dies = read_comp_unit (info_ptr, cu);
3100 /* We try not to read any attributes in this function, because not
3101 all objfiles needed for references have been loaded yet, and symbol
3102 table processing isn't initialized. But we have to set the CU language,
3103 or we won't be able to build types correctly. */
3104 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
3106 set_cu_language (DW_UNSND (attr), cu);
3108 set_cu_language (language_minimal, cu);
3110 /* Similarly, if we do not read the producer, we can not apply
3111 producer-specific interpretation. */
3112 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
3114 cu->producer = DW_STRING (attr);
3116 /* Link this CU into read_in_chain. */
3117 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3118 dwarf2_per_objfile->read_in_chain = per_cu;
3120 do_cleanups (back_to);
3122 /* We've successfully allocated this compilation unit. Let our caller
3123 clean it up when finished with it. */
3124 discard_cleanups (free_cu_cleanup);
3127 /* Generate full symbol information for PST and CU, whose DIEs have
3128 already been loaded into memory. */
3131 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3133 struct partial_symtab *pst = per_cu->psymtab;
3134 struct dwarf2_cu *cu = per_cu->cu;
3135 struct objfile *objfile = pst->objfile;
3136 CORE_ADDR lowpc, highpc;
3137 struct symtab *symtab;
3138 struct cleanup *back_to;
3141 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3144 back_to = make_cleanup (really_free_pendings, NULL);
3146 cu->list_in_scope = &file_symbols;
3148 dwarf2_find_base_address (cu->dies, cu);
3150 /* Do line number decoding in read_file_scope () */
3151 process_die (cu->dies, cu);
3153 /* Some compilers don't define a DW_AT_high_pc attribute for the
3154 compilation unit. If the DW_AT_high_pc is missing, synthesize
3155 it, by scanning the DIE's below the compilation unit. */
3156 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
3158 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
3160 /* Set symtab language to language from DW_AT_language.
3161 If the compilation is from a C file generated by language preprocessors,
3162 do not set the language if it was already deduced by start_subfile. */
3164 && !(cu->language == language_c && symtab->language != language_c))
3166 symtab->language = cu->language;
3168 pst->symtab = symtab;
3171 do_cleanups (back_to);
3174 /* Process a die and its children. */
3177 process_die (struct die_info *die, struct dwarf2_cu *cu)
3181 case DW_TAG_padding:
3183 case DW_TAG_compile_unit:
3184 read_file_scope (die, cu);
3186 case DW_TAG_type_unit:
3187 read_type_unit_scope (die, cu);
3189 case DW_TAG_subprogram:
3190 case DW_TAG_inlined_subroutine:
3191 read_func_scope (die, cu);
3193 case DW_TAG_lexical_block:
3194 case DW_TAG_try_block:
3195 case DW_TAG_catch_block:
3196 read_lexical_block_scope (die, cu);
3198 case DW_TAG_class_type:
3199 case DW_TAG_interface_type:
3200 case DW_TAG_structure_type:
3201 case DW_TAG_union_type:
3202 process_structure_scope (die, cu);
3204 case DW_TAG_enumeration_type:
3205 process_enumeration_scope (die, cu);
3208 /* These dies have a type, but processing them does not create
3209 a symbol or recurse to process the children. Therefore we can
3210 read them on-demand through read_type_die. */
3211 case DW_TAG_subroutine_type:
3212 case DW_TAG_set_type:
3213 case DW_TAG_array_type:
3214 case DW_TAG_pointer_type:
3215 case DW_TAG_ptr_to_member_type:
3216 case DW_TAG_reference_type:
3217 case DW_TAG_string_type:
3220 case DW_TAG_base_type:
3221 case DW_TAG_subrange_type:
3222 case DW_TAG_typedef:
3223 case DW_TAG_const_type:
3224 case DW_TAG_volatile_type:
3225 /* Add a typedef symbol for the type definition, if it has a
3227 new_symbol (die, read_type_die (die, cu), cu);
3229 case DW_TAG_common_block:
3230 read_common_block (die, cu);
3232 case DW_TAG_common_inclusion:
3234 case DW_TAG_namespace:
3235 processing_has_namespace_info = 1;
3236 read_namespace (die, cu);
3239 processing_has_namespace_info = 1;
3240 read_module (die, cu);
3242 case DW_TAG_imported_declaration:
3243 case DW_TAG_imported_module:
3244 processing_has_namespace_info = 1;
3245 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
3246 || cu->language != language_fortran))
3247 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
3248 dwarf_tag_name (die->tag));
3249 read_import_statement (die, cu);
3252 new_symbol (die, NULL, cu);
3257 /* A helper function for dwarf2_compute_name which determines whether DIE
3258 needs to have the name of the scope prepended to the name listed in the
3262 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
3264 struct attribute *attr;
3268 case DW_TAG_namespace:
3269 case DW_TAG_typedef:
3270 case DW_TAG_class_type:
3271 case DW_TAG_interface_type:
3272 case DW_TAG_structure_type:
3273 case DW_TAG_union_type:
3274 case DW_TAG_enumeration_type:
3275 case DW_TAG_enumerator:
3276 case DW_TAG_subprogram:
3280 case DW_TAG_variable:
3281 /* We only need to prefix "globally" visible variables. These include
3282 any variable marked with DW_AT_external or any variable that
3283 lives in a namespace. [Variables in anonymous namespaces
3284 require prefixing, but they are not DW_AT_external.] */
3286 if (dwarf2_attr (die, DW_AT_specification, cu))
3288 struct dwarf2_cu *spec_cu = cu;
3290 return die_needs_namespace (die_specification (die, &spec_cu),
3294 attr = dwarf2_attr (die, DW_AT_external, cu);
3295 if (attr == NULL && die->parent->tag != DW_TAG_namespace
3296 && die->parent->tag != DW_TAG_module)
3298 /* A variable in a lexical block of some kind does not need a
3299 namespace, even though in C++ such variables may be external
3300 and have a mangled name. */
3301 if (die->parent->tag == DW_TAG_lexical_block
3302 || die->parent->tag == DW_TAG_try_block
3303 || die->parent->tag == DW_TAG_catch_block
3304 || die->parent->tag == DW_TAG_subprogram)
3313 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3314 compute the physname for the object, which include a method's
3315 formal parameters (C++/Java) and return type (Java).
3317 For Ada, return the DIE's linkage name rather than the fully qualified
3318 name. PHYSNAME is ignored..
3320 The result is allocated on the objfile_obstack and canonicalized. */
3323 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
3327 name = dwarf2_name (die, cu);
3329 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
3330 compute it by typename_concat inside GDB. */
3331 if (cu->language == language_ada
3332 || (cu->language == language_fortran && physname))
3334 /* For Ada unit, we prefer the linkage name over the name, as
3335 the former contains the exported name, which the user expects
3336 to be able to reference. Ideally, we want the user to be able
3337 to reference this entity using either natural or linkage name,
3338 but we haven't started looking at this enhancement yet. */
3339 struct attribute *attr;
3341 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
3343 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
3344 if (attr && DW_STRING (attr))
3345 return DW_STRING (attr);
3348 /* These are the only languages we know how to qualify names in. */
3350 && (cu->language == language_cplus || cu->language == language_java
3351 || cu->language == language_fortran))
3353 if (die_needs_namespace (die, cu))
3357 struct ui_file *buf;
3359 prefix = determine_prefix (die, cu);
3360 buf = mem_fileopen ();
3361 if (*prefix != '\0')
3363 char *prefixed_name = typename_concat (NULL, prefix, name,
3366 fputs_unfiltered (prefixed_name, buf);
3367 xfree (prefixed_name);
3370 fputs_unfiltered (name ? name : "", buf);
3372 /* For Java and C++ methods, append formal parameter type
3373 information, if PHYSNAME. */
3375 if (physname && die->tag == DW_TAG_subprogram
3376 && (cu->language == language_cplus
3377 || cu->language == language_java))
3379 struct type *type = read_type_die (die, cu);
3381 c_type_print_args (type, buf, 0, cu->language);
3383 if (cu->language == language_java)
3385 /* For java, we must append the return type to method
3387 if (die->tag == DW_TAG_subprogram)
3388 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
3391 else if (cu->language == language_cplus)
3393 if (TYPE_NFIELDS (type) > 0
3394 && TYPE_FIELD_ARTIFICIAL (type, 0)
3395 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
3396 fputs_unfiltered (" const", buf);
3400 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
3402 ui_file_delete (buf);
3404 if (cu->language == language_cplus)
3407 = dwarf2_canonicalize_name (name, cu,
3408 &cu->objfile->objfile_obstack);
3419 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3420 If scope qualifiers are appropriate they will be added. The result
3421 will be allocated on the objfile_obstack, or NULL if the DIE does
3422 not have a name. NAME may either be from a previous call to
3423 dwarf2_name or NULL.
3425 The output string will be canonicalized (if C++/Java). */
3428 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
3430 return dwarf2_compute_name (name, die, cu, 0);
3433 /* Construct a physname for the given DIE in CU. NAME may either be
3434 from a previous call to dwarf2_name or NULL. The result will be
3435 allocated on the objfile_objstack or NULL if the DIE does not have a
3438 The output string will be canonicalized (if C++/Java). */
3441 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
3443 return dwarf2_compute_name (name, die, cu, 1);
3446 /* Read the import statement specified by the given die and record it. */
3449 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
3451 struct attribute *import_attr;
3452 struct die_info *imported_die;
3453 struct dwarf2_cu *imported_cu;
3454 const char *imported_name;
3455 const char *imported_name_prefix;
3456 const char *canonical_name;
3457 const char *import_alias;
3458 const char *imported_declaration = NULL;
3459 const char *import_prefix;
3463 import_attr = dwarf2_attr (die, DW_AT_import, cu);
3464 if (import_attr == NULL)
3466 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
3467 dwarf_tag_name (die->tag));
3472 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
3473 imported_name = dwarf2_name (imported_die, imported_cu);
3474 if (imported_name == NULL)
3476 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3478 The import in the following code:
3492 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3493 <52> DW_AT_decl_file : 1
3494 <53> DW_AT_decl_line : 6
3495 <54> DW_AT_import : <0x75>
3496 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3498 <5b> DW_AT_decl_file : 1
3499 <5c> DW_AT_decl_line : 2
3500 <5d> DW_AT_type : <0x6e>
3502 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3503 <76> DW_AT_byte_size : 4
3504 <77> DW_AT_encoding : 5 (signed)
3506 imports the wrong die ( 0x75 instead of 0x58 ).
3507 This case will be ignored until the gcc bug is fixed. */
3511 /* Figure out the local name after import. */
3512 import_alias = dwarf2_name (die, cu);
3514 /* Figure out where the statement is being imported to. */
3515 import_prefix = determine_prefix (die, cu);
3517 /* Figure out what the scope of the imported die is and prepend it
3518 to the name of the imported die. */
3519 imported_name_prefix = determine_prefix (imported_die, imported_cu);
3521 if (imported_die->tag != DW_TAG_namespace
3522 && imported_die->tag != DW_TAG_module)
3524 imported_declaration = imported_name;
3525 canonical_name = imported_name_prefix;
3527 else if (strlen (imported_name_prefix) > 0)
3529 temp = alloca (strlen (imported_name_prefix)
3530 + 2 + strlen (imported_name) + 1);
3531 strcpy (temp, imported_name_prefix);
3532 strcat (temp, "::");
3533 strcat (temp, imported_name);
3534 canonical_name = temp;
3537 canonical_name = imported_name;
3539 cp_add_using_directive (import_prefix,
3542 imported_declaration,
3543 &cu->objfile->objfile_obstack);
3547 initialize_cu_func_list (struct dwarf2_cu *cu)
3549 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
3553 free_cu_line_header (void *arg)
3555 struct dwarf2_cu *cu = arg;
3557 free_line_header (cu->line_header);
3558 cu->line_header = NULL;
3562 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3564 struct objfile *objfile = cu->objfile;
3565 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3566 CORE_ADDR lowpc = ((CORE_ADDR) -1);
3567 CORE_ADDR highpc = ((CORE_ADDR) 0);
3568 struct attribute *attr;
3570 char *comp_dir = NULL;
3571 struct die_info *child_die;
3572 bfd *abfd = objfile->obfd;
3573 struct line_header *line_header = 0;
3576 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3578 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
3580 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3581 from finish_block. */
3582 if (lowpc == ((CORE_ADDR) -1))
3587 /* Find the filename. Do not use dwarf2_name here, since the filename
3588 is not a source language identifier. */
3589 attr = dwarf2_attr (die, DW_AT_name, cu);
3592 name = DW_STRING (attr);
3595 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3597 comp_dir = DW_STRING (attr);
3598 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3600 comp_dir = ldirname (name);
3601 if (comp_dir != NULL)
3602 make_cleanup (xfree, comp_dir);
3604 if (comp_dir != NULL)
3606 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3607 directory, get rid of it. */
3608 char *cp = strchr (comp_dir, ':');
3610 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3617 attr = dwarf2_attr (die, DW_AT_language, cu);
3620 set_cu_language (DW_UNSND (attr), cu);
3623 attr = dwarf2_attr (die, DW_AT_producer, cu);
3625 cu->producer = DW_STRING (attr);
3627 /* We assume that we're processing GCC output. */
3628 processing_gcc_compilation = 2;
3630 processing_has_namespace_info = 0;
3632 start_symtab (name, comp_dir, lowpc);
3633 record_debugformat ("DWARF 2");
3634 record_producer (cu->producer);
3636 initialize_cu_func_list (cu);
3638 /* Decode line number information if present. We do this before
3639 processing child DIEs, so that the line header table is available
3640 for DW_AT_decl_file. */
3641 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3644 unsigned int line_offset = DW_UNSND (attr);
3645 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
3648 cu->line_header = line_header;
3649 make_cleanup (free_cu_line_header, cu);
3650 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
3654 /* Process all dies in compilation unit. */
3655 if (die->child != NULL)
3657 child_die = die->child;
3658 while (child_die && child_die->tag)
3660 process_die (child_die, cu);
3661 child_die = sibling_die (child_die);
3665 /* Decode macro information, if present. Dwarf 2 macro information
3666 refers to information in the line number info statement program
3667 header, so we can only read it if we've read the header
3669 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
3670 if (attr && line_header)
3672 unsigned int macro_offset = DW_UNSND (attr);
3674 dwarf_decode_macros (line_header, macro_offset,
3675 comp_dir, abfd, cu);
3677 do_cleanups (back_to);
3680 /* For TUs we want to skip the first top level sibling if it's not the
3681 actual type being defined by this TU. In this case the first top
3682 level sibling is there to provide context only. */
3685 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
3687 struct objfile *objfile = cu->objfile;
3688 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3690 struct attribute *attr;
3692 char *comp_dir = NULL;
3693 struct die_info *child_die;
3694 bfd *abfd = objfile->obfd;
3696 /* start_symtab needs a low pc, but we don't really have one.
3697 Do what read_file_scope would do in the absence of such info. */
3698 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3700 /* Find the filename. Do not use dwarf2_name here, since the filename
3701 is not a source language identifier. */
3702 attr = dwarf2_attr (die, DW_AT_name, cu);
3704 name = DW_STRING (attr);
3706 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3708 comp_dir = DW_STRING (attr);
3709 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3711 comp_dir = ldirname (name);
3712 if (comp_dir != NULL)
3713 make_cleanup (xfree, comp_dir);
3719 attr = dwarf2_attr (die, DW_AT_language, cu);
3721 set_cu_language (DW_UNSND (attr), cu);
3723 /* This isn't technically needed today. It is done for symmetry
3724 with read_file_scope. */
3725 attr = dwarf2_attr (die, DW_AT_producer, cu);
3727 cu->producer = DW_STRING (attr);
3729 /* We assume that we're processing GCC output. */
3730 processing_gcc_compilation = 2;
3732 processing_has_namespace_info = 0;
3734 start_symtab (name, comp_dir, lowpc);
3735 record_debugformat ("DWARF 2");
3736 record_producer (cu->producer);
3738 /* Process the dies in the type unit. */
3739 if (die->child == NULL)
3741 dump_die_for_error (die);
3742 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3743 bfd_get_filename (abfd));
3746 child_die = die->child;
3748 while (child_die && child_die->tag)
3750 process_die (child_die, cu);
3752 child_die = sibling_die (child_die);
3755 do_cleanups (back_to);
3759 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
3760 struct dwarf2_cu *cu)
3762 struct function_range *thisfn;
3764 thisfn = (struct function_range *)
3765 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
3766 thisfn->name = name;
3767 thisfn->lowpc = lowpc;
3768 thisfn->highpc = highpc;
3769 thisfn->seen_line = 0;
3770 thisfn->next = NULL;
3772 if (cu->last_fn == NULL)
3773 cu->first_fn = thisfn;
3775 cu->last_fn->next = thisfn;
3777 cu->last_fn = thisfn;
3780 /* qsort helper for inherit_abstract_dies. */
3783 unsigned_int_compar (const void *ap, const void *bp)
3785 unsigned int a = *(unsigned int *) ap;
3786 unsigned int b = *(unsigned int *) bp;
3788 return (a > b) - (b > a);
3791 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3792 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3793 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3796 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
3798 struct die_info *child_die;
3799 unsigned die_children_count;
3800 /* CU offsets which were referenced by children of the current DIE. */
3802 unsigned *offsets_end, *offsetp;
3803 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3804 struct die_info *origin_die;
3805 /* Iterator of the ORIGIN_DIE children. */
3806 struct die_info *origin_child_die;
3807 struct cleanup *cleanups;
3808 struct attribute *attr;
3810 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
3814 origin_die = follow_die_ref (die, attr, &cu);
3815 if (die->tag != origin_die->tag
3816 && !(die->tag == DW_TAG_inlined_subroutine
3817 && origin_die->tag == DW_TAG_subprogram))
3818 complaint (&symfile_complaints,
3819 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3820 die->offset, origin_die->offset);
3822 child_die = die->child;
3823 die_children_count = 0;
3824 while (child_die && child_die->tag)
3826 child_die = sibling_die (child_die);
3827 die_children_count++;
3829 offsets = xmalloc (sizeof (*offsets) * die_children_count);
3830 cleanups = make_cleanup (xfree, offsets);
3832 offsets_end = offsets;
3833 child_die = die->child;
3834 while (child_die && child_die->tag)
3836 /* For each CHILD_DIE, find the corresponding child of
3837 ORIGIN_DIE. If there is more than one layer of
3838 DW_AT_abstract_origin, follow them all; there shouldn't be,
3839 but GCC versions at least through 4.4 generate this (GCC PR
3841 struct die_info *child_origin_die = child_die;
3845 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
3848 child_origin_die = follow_die_ref (child_origin_die, attr, &cu);
3851 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3852 counterpart may exist. */
3853 if (child_origin_die != child_die)
3855 if (child_die->tag != child_origin_die->tag
3856 && !(child_die->tag == DW_TAG_inlined_subroutine
3857 && child_origin_die->tag == DW_TAG_subprogram))
3858 complaint (&symfile_complaints,
3859 _("Child DIE 0x%x and its abstract origin 0x%x have "
3860 "different tags"), child_die->offset,
3861 child_origin_die->offset);
3862 if (child_origin_die->parent != origin_die)
3863 complaint (&symfile_complaints,
3864 _("Child DIE 0x%x and its abstract origin 0x%x have "
3865 "different parents"), child_die->offset,
3866 child_origin_die->offset);
3868 *offsets_end++ = child_origin_die->offset;
3870 child_die = sibling_die (child_die);
3872 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
3873 unsigned_int_compar);
3874 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
3875 if (offsetp[-1] == *offsetp)
3876 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
3877 "to DIE 0x%x as their abstract origin"),
3878 die->offset, *offsetp);
3881 origin_child_die = origin_die->child;
3882 while (origin_child_die && origin_child_die->tag)
3884 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3885 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
3887 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
3889 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3890 process_die (origin_child_die, cu);
3892 origin_child_die = sibling_die (origin_child_die);
3895 do_cleanups (cleanups);
3899 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
3901 struct objfile *objfile = cu->objfile;
3902 struct context_stack *new;
3905 struct die_info *child_die;
3906 struct attribute *attr, *call_line, *call_file;
3909 struct block *block;
3910 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
3914 /* If we do not have call site information, we can't show the
3915 caller of this inlined function. That's too confusing, so
3916 only use the scope for local variables. */
3917 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
3918 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
3919 if (call_line == NULL || call_file == NULL)
3921 read_lexical_block_scope (die, cu);
3926 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3928 name = dwarf2_name (die, cu);
3930 /* Ignore functions with missing or empty names. These are actually
3931 illegal according to the DWARF standard. */
3934 complaint (&symfile_complaints,
3935 _("missing name for subprogram DIE at %d"), die->offset);
3939 /* Ignore functions with missing or invalid low and high pc attributes. */
3940 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
3942 attr = dwarf2_attr (die, DW_AT_external, cu);
3943 if (!attr || !DW_UNSND (attr))
3944 complaint (&symfile_complaints,
3945 _("cannot get low and high bounds for subprogram DIE at %d"),
3953 /* Record the function range for dwarf_decode_lines. */
3954 add_to_cu_func_list (name, lowpc, highpc, cu);
3956 new = push_context (0, lowpc);
3957 new->name = new_symbol (die, read_type_die (die, cu), cu);
3959 /* If there is a location expression for DW_AT_frame_base, record
3961 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
3963 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3964 expression is being recorded directly in the function's symbol
3965 and not in a separate frame-base object. I guess this hack is
3966 to avoid adding some sort of frame-base adjunct/annex to the
3967 function's symbol :-(. The problem with doing this is that it
3968 results in a function symbol with a location expression that
3969 has nothing to do with the location of the function, ouch! The
3970 relationship should be: a function's symbol has-a frame base; a
3971 frame-base has-a location expression. */
3972 dwarf2_symbol_mark_computed (attr, new->name, cu);
3974 cu->list_in_scope = &local_symbols;
3976 if (die->child != NULL)
3978 child_die = die->child;
3979 while (child_die && child_die->tag)
3981 process_die (child_die, cu);
3982 child_die = sibling_die (child_die);
3986 inherit_abstract_dies (die, cu);
3988 /* If we have a DW_AT_specification, we might need to import using
3989 directives from the context of the specification DIE. See the
3990 comment in determine_prefix. */
3991 if (cu->language == language_cplus
3992 && dwarf2_attr (die, DW_AT_specification, cu))
3994 struct dwarf2_cu *spec_cu = cu;
3995 struct die_info *spec_die = die_specification (die, &spec_cu);
3999 child_die = spec_die->child;
4000 while (child_die && child_die->tag)
4002 if (child_die->tag == DW_TAG_imported_module)
4003 process_die (child_die, spec_cu);
4004 child_die = sibling_die (child_die);
4007 /* In some cases, GCC generates specification DIEs that
4008 themselves contain DW_AT_specification attributes. */
4009 spec_die = die_specification (spec_die, &spec_cu);
4013 new = pop_context ();
4014 /* Make a block for the local symbols within. */
4015 block = finish_block (new->name, &local_symbols, new->old_blocks,
4016 lowpc, highpc, objfile);
4018 /* For C++, set the block's scope. */
4019 if (cu->language == language_cplus || cu->language == language_fortran)
4020 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
4021 determine_prefix (die, cu),
4022 processing_has_namespace_info);
4024 /* If we have address ranges, record them. */
4025 dwarf2_record_block_ranges (die, block, baseaddr, cu);
4027 /* In C++, we can have functions nested inside functions (e.g., when
4028 a function declares a class that has methods). This means that
4029 when we finish processing a function scope, we may need to go
4030 back to building a containing block's symbol lists. */
4031 local_symbols = new->locals;
4032 param_symbols = new->params;
4033 using_directives = new->using_directives;
4035 /* If we've finished processing a top-level function, subsequent
4036 symbols go in the file symbol list. */
4037 if (outermost_context_p ())
4038 cu->list_in_scope = &file_symbols;
4041 /* Process all the DIES contained within a lexical block scope. Start
4042 a new scope, process the dies, and then close the scope. */
4045 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
4047 struct objfile *objfile = cu->objfile;
4048 struct context_stack *new;
4049 CORE_ADDR lowpc, highpc;
4050 struct die_info *child_die;
4053 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4055 /* Ignore blocks with missing or invalid low and high pc attributes. */
4056 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4057 as multiple lexical blocks? Handling children in a sane way would
4058 be nasty. Might be easier to properly extend generic blocks to
4060 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
4065 push_context (0, lowpc);
4066 if (die->child != NULL)
4068 child_die = die->child;
4069 while (child_die && child_die->tag)
4071 process_die (child_die, cu);
4072 child_die = sibling_die (child_die);
4075 new = pop_context ();
4077 if (local_symbols != NULL || using_directives != NULL)
4080 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
4083 /* Note that recording ranges after traversing children, as we
4084 do here, means that recording a parent's ranges entails
4085 walking across all its children's ranges as they appear in
4086 the address map, which is quadratic behavior.
4088 It would be nicer to record the parent's ranges before
4089 traversing its children, simply overriding whatever you find
4090 there. But since we don't even decide whether to create a
4091 block until after we've traversed its children, that's hard
4093 dwarf2_record_block_ranges (die, block, baseaddr, cu);
4095 local_symbols = new->locals;
4096 using_directives = new->using_directives;
4099 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4100 Return 1 if the attributes are present and valid, otherwise, return 0.
4101 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4104 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
4105 CORE_ADDR *high_return, struct dwarf2_cu *cu,
4106 struct partial_symtab *ranges_pst)
4108 struct objfile *objfile = cu->objfile;
4109 struct comp_unit_head *cu_header = &cu->header;
4110 bfd *obfd = objfile->obfd;
4111 unsigned int addr_size = cu_header->addr_size;
4112 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
4113 /* Base address selection entry. */
4124 found_base = cu->base_known;
4125 base = cu->base_address;
4127 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
4128 if (offset >= dwarf2_per_objfile->ranges.size)
4130 complaint (&symfile_complaints,
4131 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4135 buffer = dwarf2_per_objfile->ranges.buffer + offset;
4137 /* Read in the largest possible address. */
4138 marker = read_address (obfd, buffer, cu, &dummy);
4139 if ((marker & mask) == mask)
4141 /* If we found the largest possible address, then
4142 read the base address. */
4143 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4144 buffer += 2 * addr_size;
4145 offset += 2 * addr_size;
4151 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4155 CORE_ADDR range_beginning, range_end;
4157 range_beginning = read_address (obfd, buffer, cu, &dummy);
4158 buffer += addr_size;
4159 range_end = read_address (obfd, buffer, cu, &dummy);
4160 buffer += addr_size;
4161 offset += 2 * addr_size;
4163 /* An end of list marker is a pair of zero addresses. */
4164 if (range_beginning == 0 && range_end == 0)
4165 /* Found the end of list entry. */
4168 /* Each base address selection entry is a pair of 2 values.
4169 The first is the largest possible address, the second is
4170 the base address. Check for a base address here. */
4171 if ((range_beginning & mask) == mask)
4173 /* If we found the largest possible address, then
4174 read the base address. */
4175 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4182 /* We have no valid base address for the ranges
4184 complaint (&symfile_complaints,
4185 _("Invalid .debug_ranges data (no base address)"));
4189 range_beginning += base;
4192 if (ranges_pst != NULL && range_beginning < range_end)
4193 addrmap_set_empty (objfile->psymtabs_addrmap,
4194 range_beginning + baseaddr, range_end - 1 + baseaddr,
4197 /* FIXME: This is recording everything as a low-high
4198 segment of consecutive addresses. We should have a
4199 data structure for discontiguous block ranges
4203 low = range_beginning;
4209 if (range_beginning < low)
4210 low = range_beginning;
4211 if (range_end > high)
4217 /* If the first entry is an end-of-list marker, the range
4218 describes an empty scope, i.e. no instructions. */
4224 *high_return = high;
4228 /* Get low and high pc attributes from a die. Return 1 if the attributes
4229 are present and valid, otherwise, return 0. Return -1 if the range is
4230 discontinuous, i.e. derived from DW_AT_ranges information. */
4232 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
4233 CORE_ADDR *highpc, struct dwarf2_cu *cu,
4234 struct partial_symtab *pst)
4236 struct attribute *attr;
4241 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4244 high = DW_ADDR (attr);
4245 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4247 low = DW_ADDR (attr);
4249 /* Found high w/o low attribute. */
4252 /* Found consecutive range of addresses. */
4257 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4260 /* Value of the DW_AT_ranges attribute is the offset in the
4261 .debug_ranges section. */
4262 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
4264 /* Found discontinuous range of addresses. */
4272 /* When using the GNU linker, .gnu.linkonce. sections are used to
4273 eliminate duplicate copies of functions and vtables and such.
4274 The linker will arbitrarily choose one and discard the others.
4275 The AT_*_pc values for such functions refer to local labels in
4276 these sections. If the section from that file was discarded, the
4277 labels are not in the output, so the relocs get a value of 0.
4278 If this is a discarded function, mark the pc bounds as invalid,
4279 so that GDB will ignore it. */
4280 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
4288 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4289 its low and high PC addresses. Do nothing if these addresses could not
4290 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4291 and HIGHPC to the high address if greater than HIGHPC. */
4294 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
4295 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4296 struct dwarf2_cu *cu)
4298 CORE_ADDR low, high;
4299 struct die_info *child = die->child;
4301 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
4303 *lowpc = min (*lowpc, low);
4304 *highpc = max (*highpc, high);
4307 /* If the language does not allow nested subprograms (either inside
4308 subprograms or lexical blocks), we're done. */
4309 if (cu->language != language_ada)
4312 /* Check all the children of the given DIE. If it contains nested
4313 subprograms, then check their pc bounds. Likewise, we need to
4314 check lexical blocks as well, as they may also contain subprogram
4316 while (child && child->tag)
4318 if (child->tag == DW_TAG_subprogram
4319 || child->tag == DW_TAG_lexical_block)
4320 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
4321 child = sibling_die (child);
4325 /* Get the low and high pc's represented by the scope DIE, and store
4326 them in *LOWPC and *HIGHPC. If the correct values can't be
4327 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4330 get_scope_pc_bounds (struct die_info *die,
4331 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4332 struct dwarf2_cu *cu)
4334 CORE_ADDR best_low = (CORE_ADDR) -1;
4335 CORE_ADDR best_high = (CORE_ADDR) 0;
4336 CORE_ADDR current_low, current_high;
4338 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
4340 best_low = current_low;
4341 best_high = current_high;
4345 struct die_info *child = die->child;
4347 while (child && child->tag)
4349 switch (child->tag) {
4350 case DW_TAG_subprogram:
4351 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
4353 case DW_TAG_namespace:
4355 /* FIXME: carlton/2004-01-16: Should we do this for
4356 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4357 that current GCC's always emit the DIEs corresponding
4358 to definitions of methods of classes as children of a
4359 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4360 the DIEs giving the declarations, which could be
4361 anywhere). But I don't see any reason why the
4362 standards says that they have to be there. */
4363 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
4365 if (current_low != ((CORE_ADDR) -1))
4367 best_low = min (best_low, current_low);
4368 best_high = max (best_high, current_high);
4376 child = sibling_die (child);
4381 *highpc = best_high;
4384 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4387 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
4388 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
4390 struct attribute *attr;
4392 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4395 CORE_ADDR high = DW_ADDR (attr);
4397 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4400 CORE_ADDR low = DW_ADDR (attr);
4402 record_block_range (block, baseaddr + low, baseaddr + high - 1);
4406 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4409 bfd *obfd = cu->objfile->obfd;
4411 /* The value of the DW_AT_ranges attribute is the offset of the
4412 address range list in the .debug_ranges section. */
4413 unsigned long offset = DW_UNSND (attr);
4414 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
4416 /* For some target architectures, but not others, the
4417 read_address function sign-extends the addresses it returns.
4418 To recognize base address selection entries, we need a
4420 unsigned int addr_size = cu->header.addr_size;
4421 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
4423 /* The base address, to which the next pair is relative. Note
4424 that this 'base' is a DWARF concept: most entries in a range
4425 list are relative, to reduce the number of relocs against the
4426 debugging information. This is separate from this function's
4427 'baseaddr' argument, which GDB uses to relocate debugging
4428 information from a shared library based on the address at
4429 which the library was loaded. */
4430 CORE_ADDR base = cu->base_address;
4431 int base_known = cu->base_known;
4433 gdb_assert (dwarf2_per_objfile->ranges.readin);
4434 if (offset >= dwarf2_per_objfile->ranges.size)
4436 complaint (&symfile_complaints,
4437 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4444 unsigned int bytes_read;
4445 CORE_ADDR start, end;
4447 start = read_address (obfd, buffer, cu, &bytes_read);
4448 buffer += bytes_read;
4449 end = read_address (obfd, buffer, cu, &bytes_read);
4450 buffer += bytes_read;
4452 /* Did we find the end of the range list? */
4453 if (start == 0 && end == 0)
4456 /* Did we find a base address selection entry? */
4457 else if ((start & base_select_mask) == base_select_mask)
4463 /* We found an ordinary address range. */
4468 complaint (&symfile_complaints,
4469 _("Invalid .debug_ranges data (no base address)"));
4473 record_block_range (block,
4474 baseaddr + base + start,
4475 baseaddr + base + end - 1);
4481 /* Add an aggregate field to the field list. */
4484 dwarf2_add_field (struct field_info *fip, struct die_info *die,
4485 struct dwarf2_cu *cu)
4487 struct objfile *objfile = cu->objfile;
4488 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4489 struct nextfield *new_field;
4490 struct attribute *attr;
4492 char *fieldname = "";
4494 /* Allocate a new field list entry and link it in. */
4495 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4496 make_cleanup (xfree, new_field);
4497 memset (new_field, 0, sizeof (struct nextfield));
4499 if (die->tag == DW_TAG_inheritance)
4501 new_field->next = fip->baseclasses;
4502 fip->baseclasses = new_field;
4506 new_field->next = fip->fields;
4507 fip->fields = new_field;
4511 /* Handle accessibility and virtuality of field.
4512 The default accessibility for members is public, the default
4513 accessibility for inheritance is private. */
4514 if (die->tag != DW_TAG_inheritance)
4515 new_field->accessibility = DW_ACCESS_public;
4517 new_field->accessibility = DW_ACCESS_private;
4518 new_field->virtuality = DW_VIRTUALITY_none;
4520 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4522 new_field->accessibility = DW_UNSND (attr);
4523 if (new_field->accessibility != DW_ACCESS_public)
4524 fip->non_public_fields = 1;
4525 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
4527 new_field->virtuality = DW_UNSND (attr);
4529 fp = &new_field->field;
4531 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
4533 /* Data member other than a C++ static data member. */
4535 /* Get type of field. */
4536 fp->type = die_type (die, cu);
4538 SET_FIELD_BITPOS (*fp, 0);
4540 /* Get bit size of field (zero if none). */
4541 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
4544 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
4548 FIELD_BITSIZE (*fp) = 0;
4551 /* Get bit offset of field. */
4552 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4555 int byte_offset = 0;
4557 if (attr_form_is_section_offset (attr))
4558 dwarf2_complex_location_expr_complaint ();
4559 else if (attr_form_is_constant (attr))
4560 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4561 else if (attr_form_is_block (attr))
4562 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4564 dwarf2_complex_location_expr_complaint ();
4566 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4568 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
4571 if (gdbarch_bits_big_endian (gdbarch))
4573 /* For big endian bits, the DW_AT_bit_offset gives the
4574 additional bit offset from the MSB of the containing
4575 anonymous object to the MSB of the field. We don't
4576 have to do anything special since we don't need to
4577 know the size of the anonymous object. */
4578 FIELD_BITPOS (*fp) += DW_UNSND (attr);
4582 /* For little endian bits, compute the bit offset to the
4583 MSB of the anonymous object, subtract off the number of
4584 bits from the MSB of the field to the MSB of the
4585 object, and then subtract off the number of bits of
4586 the field itself. The result is the bit offset of
4587 the LSB of the field. */
4589 int bit_offset = DW_UNSND (attr);
4591 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4594 /* The size of the anonymous object containing
4595 the bit field is explicit, so use the
4596 indicated size (in bytes). */
4597 anonymous_size = DW_UNSND (attr);
4601 /* The size of the anonymous object containing
4602 the bit field must be inferred from the type
4603 attribute of the data member containing the
4605 anonymous_size = TYPE_LENGTH (fp->type);
4607 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
4608 - bit_offset - FIELD_BITSIZE (*fp);
4612 /* Get name of field. */
4613 fieldname = dwarf2_name (die, cu);
4614 if (fieldname == NULL)
4617 /* The name is already allocated along with this objfile, so we don't
4618 need to duplicate it for the type. */
4619 fp->name = fieldname;
4621 /* Change accessibility for artificial fields (e.g. virtual table
4622 pointer or virtual base class pointer) to private. */
4623 if (dwarf2_attr (die, DW_AT_artificial, cu))
4625 FIELD_ARTIFICIAL (*fp) = 1;
4626 new_field->accessibility = DW_ACCESS_private;
4627 fip->non_public_fields = 1;
4630 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
4632 /* C++ static member. */
4634 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4635 is a declaration, but all versions of G++ as of this writing
4636 (so through at least 3.2.1) incorrectly generate
4637 DW_TAG_variable tags. */
4641 /* Get name of field. */
4642 fieldname = dwarf2_name (die, cu);
4643 if (fieldname == NULL)
4646 /* Get physical name. */
4647 physname = (char *) dwarf2_physname (fieldname, die, cu);
4649 /* The name is already allocated along with this objfile, so we don't
4650 need to duplicate it for the type. */
4651 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
4652 FIELD_TYPE (*fp) = die_type (die, cu);
4653 FIELD_NAME (*fp) = fieldname;
4655 else if (die->tag == DW_TAG_inheritance)
4657 /* C++ base class field. */
4658 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4661 int byte_offset = 0;
4663 if (attr_form_is_section_offset (attr))
4664 dwarf2_complex_location_expr_complaint ();
4665 else if (attr_form_is_constant (attr))
4666 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4667 else if (attr_form_is_block (attr))
4668 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4670 dwarf2_complex_location_expr_complaint ();
4672 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4674 FIELD_BITSIZE (*fp) = 0;
4675 FIELD_TYPE (*fp) = die_type (die, cu);
4676 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
4677 fip->nbaseclasses++;
4681 /* Add a typedef defined in the scope of the FIP's class. */
4684 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
4685 struct dwarf2_cu *cu)
4687 struct objfile *objfile = cu->objfile;
4688 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4689 struct typedef_field_list *new_field;
4690 struct attribute *attr;
4691 struct typedef_field *fp;
4692 char *fieldname = "";
4694 /* Allocate a new field list entry and link it in. */
4695 new_field = xzalloc (sizeof (*new_field));
4696 make_cleanup (xfree, new_field);
4698 gdb_assert (die->tag == DW_TAG_typedef);
4700 fp = &new_field->field;
4702 /* Get name of field. */
4703 fp->name = dwarf2_name (die, cu);
4704 if (fp->name == NULL)
4707 fp->type = read_type_die (die, cu);
4709 new_field->next = fip->typedef_field_list;
4710 fip->typedef_field_list = new_field;
4711 fip->typedef_field_list_count++;
4714 /* Create the vector of fields, and attach it to the type. */
4717 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
4718 struct dwarf2_cu *cu)
4720 int nfields = fip->nfields;
4722 /* Record the field count, allocate space for the array of fields,
4723 and create blank accessibility bitfields if necessary. */
4724 TYPE_NFIELDS (type) = nfields;
4725 TYPE_FIELDS (type) = (struct field *)
4726 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4727 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4729 if (fip->non_public_fields && cu->language != language_ada)
4731 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4733 TYPE_FIELD_PRIVATE_BITS (type) =
4734 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4735 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4737 TYPE_FIELD_PROTECTED_BITS (type) =
4738 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4739 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4741 TYPE_FIELD_IGNORE_BITS (type) =
4742 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4743 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4746 /* If the type has baseclasses, allocate and clear a bit vector for
4747 TYPE_FIELD_VIRTUAL_BITS. */
4748 if (fip->nbaseclasses && cu->language != language_ada)
4750 int num_bytes = B_BYTES (fip->nbaseclasses);
4751 unsigned char *pointer;
4753 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4754 pointer = TYPE_ALLOC (type, num_bytes);
4755 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
4756 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
4757 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
4760 /* Copy the saved-up fields into the field vector. Start from the head
4761 of the list, adding to the tail of the field array, so that they end
4762 up in the same order in the array in which they were added to the list. */
4763 while (nfields-- > 0)
4765 struct nextfield *fieldp;
4769 fieldp = fip->fields;
4770 fip->fields = fieldp->next;
4774 fieldp = fip->baseclasses;
4775 fip->baseclasses = fieldp->next;
4778 TYPE_FIELD (type, nfields) = fieldp->field;
4779 switch (fieldp->accessibility)
4781 case DW_ACCESS_private:
4782 if (cu->language != language_ada)
4783 SET_TYPE_FIELD_PRIVATE (type, nfields);
4786 case DW_ACCESS_protected:
4787 if (cu->language != language_ada)
4788 SET_TYPE_FIELD_PROTECTED (type, nfields);
4791 case DW_ACCESS_public:
4795 /* Unknown accessibility. Complain and treat it as public. */
4797 complaint (&symfile_complaints, _("unsupported accessibility %d"),
4798 fieldp->accessibility);
4802 if (nfields < fip->nbaseclasses)
4804 switch (fieldp->virtuality)
4806 case DW_VIRTUALITY_virtual:
4807 case DW_VIRTUALITY_pure_virtual:
4808 if (cu->language == language_ada)
4809 error ("unexpected virtuality in component of Ada type");
4810 SET_TYPE_FIELD_VIRTUAL (type, nfields);
4817 /* Add a member function to the proper fieldlist. */
4820 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
4821 struct type *type, struct dwarf2_cu *cu)
4823 struct objfile *objfile = cu->objfile;
4824 struct attribute *attr;
4825 struct fnfieldlist *flp;
4827 struct fn_field *fnp;
4830 struct nextfnfield *new_fnfield;
4831 struct type *this_type;
4833 if (cu->language == language_ada)
4834 error ("unexpected member function in Ada type");
4836 /* Get name of member function. */
4837 fieldname = dwarf2_name (die, cu);
4838 if (fieldname == NULL)
4841 /* Get the mangled name. */
4842 physname = (char *) dwarf2_physname (fieldname, die, cu);
4844 /* Look up member function name in fieldlist. */
4845 for (i = 0; i < fip->nfnfields; i++)
4847 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
4851 /* Create new list element if necessary. */
4852 if (i < fip->nfnfields)
4853 flp = &fip->fnfieldlists[i];
4856 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
4858 fip->fnfieldlists = (struct fnfieldlist *)
4859 xrealloc (fip->fnfieldlists,
4860 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
4861 * sizeof (struct fnfieldlist));
4862 if (fip->nfnfields == 0)
4863 make_cleanup (free_current_contents, &fip->fnfieldlists);
4865 flp = &fip->fnfieldlists[fip->nfnfields];
4866 flp->name = fieldname;
4872 /* Create a new member function field and chain it to the field list
4874 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
4875 make_cleanup (xfree, new_fnfield);
4876 memset (new_fnfield, 0, sizeof (struct nextfnfield));
4877 new_fnfield->next = flp->head;
4878 flp->head = new_fnfield;
4881 /* Fill in the member function field info. */
4882 fnp = &new_fnfield->fnfield;
4883 /* The name is already allocated along with this objfile, so we don't
4884 need to duplicate it for the type. */
4885 fnp->physname = physname ? physname : "";
4886 fnp->type = alloc_type (objfile);
4887 this_type = read_type_die (die, cu);
4888 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
4890 int nparams = TYPE_NFIELDS (this_type);
4892 /* TYPE is the domain of this method, and THIS_TYPE is the type
4893 of the method itself (TYPE_CODE_METHOD). */
4894 smash_to_method_type (fnp->type, type,
4895 TYPE_TARGET_TYPE (this_type),
4896 TYPE_FIELDS (this_type),
4897 TYPE_NFIELDS (this_type),
4898 TYPE_VARARGS (this_type));
4900 /* Handle static member functions.
4901 Dwarf2 has no clean way to discern C++ static and non-static
4902 member functions. G++ helps GDB by marking the first
4903 parameter for non-static member functions (which is the
4904 this pointer) as artificial. We obtain this information
4905 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4906 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
4907 fnp->voffset = VOFFSET_STATIC;
4910 complaint (&symfile_complaints, _("member function type missing for '%s'"),
4913 /* Get fcontext from DW_AT_containing_type if present. */
4914 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4915 fnp->fcontext = die_containing_type (die, cu);
4917 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4918 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4920 /* Get accessibility. */
4921 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4924 switch (DW_UNSND (attr))
4926 case DW_ACCESS_private:
4927 fnp->is_private = 1;
4929 case DW_ACCESS_protected:
4930 fnp->is_protected = 1;
4935 /* Check for artificial methods. */
4936 attr = dwarf2_attr (die, DW_AT_artificial, cu);
4937 if (attr && DW_UNSND (attr) != 0)
4938 fnp->is_artificial = 1;
4940 /* Get index in virtual function table if it is a virtual member
4941 function. For older versions of GCC, this is an offset in the
4942 appropriate virtual table, as specified by DW_AT_containing_type.
4943 For everyone else, it is an expression to be evaluated relative
4944 to the object address. */
4946 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
4949 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
4951 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
4953 /* Old-style GCC. */
4954 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
4956 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
4957 || (DW_BLOCK (attr)->size > 1
4958 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
4959 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
4961 struct dwarf_block blk;
4964 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
4966 blk.size = DW_BLOCK (attr)->size - offset;
4967 blk.data = DW_BLOCK (attr)->data + offset;
4968 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
4969 if ((fnp->voffset % cu->header.addr_size) != 0)
4970 dwarf2_complex_location_expr_complaint ();
4972 fnp->voffset /= cu->header.addr_size;
4976 dwarf2_complex_location_expr_complaint ();
4979 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
4981 else if (attr_form_is_section_offset (attr))
4983 dwarf2_complex_location_expr_complaint ();
4987 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4993 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
4994 if (attr && DW_UNSND (attr))
4996 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4997 complaint (&symfile_complaints,
4998 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4999 fieldname, die->offset);
5000 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5001 TYPE_CPLUS_DYNAMIC (type) = 1;
5006 /* Create the vector of member function fields, and attach it to the type. */
5009 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
5010 struct dwarf2_cu *cu)
5012 struct fnfieldlist *flp;
5013 int total_length = 0;
5016 if (cu->language == language_ada)
5017 error ("unexpected member functions in Ada type");
5019 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5020 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
5021 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
5023 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
5025 struct nextfnfield *nfp = flp->head;
5026 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
5029 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
5030 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
5031 fn_flp->fn_fields = (struct fn_field *)
5032 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
5033 for (k = flp->length; (k--, nfp); nfp = nfp->next)
5034 fn_flp->fn_fields[k] = nfp->fnfield;
5036 total_length += flp->length;
5039 TYPE_NFN_FIELDS (type) = fip->nfnfields;
5040 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
5043 /* Returns non-zero if NAME is the name of a vtable member in CU's
5044 language, zero otherwise. */
5046 is_vtable_name (const char *name, struct dwarf2_cu *cu)
5048 static const char vptr[] = "_vptr";
5049 static const char vtable[] = "vtable";
5051 /* Look for the C++ and Java forms of the vtable. */
5052 if ((cu->language == language_java
5053 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
5054 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
5055 && is_cplus_marker (name[sizeof (vptr) - 1])))
5061 /* GCC outputs unnamed structures that are really pointers to member
5062 functions, with the ABI-specified layout. If TYPE describes
5063 such a structure, smash it into a member function type.
5065 GCC shouldn't do this; it should just output pointer to member DIEs.
5066 This is GCC PR debug/28767. */
5069 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
5071 struct type *pfn_type, *domain_type, *new_type;
5073 /* Check for a structure with no name and two children. */
5074 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
5077 /* Check for __pfn and __delta members. */
5078 if (TYPE_FIELD_NAME (type, 0) == NULL
5079 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
5080 || TYPE_FIELD_NAME (type, 1) == NULL
5081 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
5084 /* Find the type of the method. */
5085 pfn_type = TYPE_FIELD_TYPE (type, 0);
5086 if (pfn_type == NULL
5087 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
5088 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
5091 /* Look for the "this" argument. */
5092 pfn_type = TYPE_TARGET_TYPE (pfn_type);
5093 if (TYPE_NFIELDS (pfn_type) == 0
5094 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5095 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
5098 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
5099 new_type = alloc_type (objfile);
5100 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
5101 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
5102 TYPE_VARARGS (pfn_type));
5103 smash_to_methodptr_type (type, new_type);
5106 /* Called when we find the DIE that starts a structure or union scope
5107 (definition) to process all dies that define the members of the
5110 NOTE: we need to call struct_type regardless of whether or not the
5111 DIE has an at_name attribute, since it might be an anonymous
5112 structure or union. This gets the type entered into our set of
5115 However, if the structure is incomplete (an opaque struct/union)
5116 then suppress creating a symbol table entry for it since gdb only
5117 wants to find the one with the complete definition. Note that if
5118 it is complete, we just call new_symbol, which does it's own
5119 checking about whether the struct/union is anonymous or not (and
5120 suppresses creating a symbol table entry itself). */
5122 static struct type *
5123 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
5125 struct objfile *objfile = cu->objfile;
5127 struct attribute *attr;
5129 struct cleanup *back_to;
5131 /* If the definition of this type lives in .debug_types, read that type.
5132 Don't follow DW_AT_specification though, that will take us back up
5133 the chain and we want to go down. */
5134 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
5137 struct dwarf2_cu *type_cu = cu;
5138 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
5140 /* We could just recurse on read_structure_type, but we need to call
5141 get_die_type to ensure only one type for this DIE is created.
5142 This is important, for example, because for c++ classes we need
5143 TYPE_NAME set which is only done by new_symbol. Blech. */
5144 type = read_type_die (type_die, type_cu);
5145 return set_die_type (die, type, cu);
5148 back_to = make_cleanup (null_cleanup, 0);
5150 type = alloc_type (objfile);
5151 INIT_CPLUS_SPECIFIC (type);
5153 name = dwarf2_name (die, cu);
5156 if (cu->language == language_cplus
5157 || cu->language == language_java)
5159 TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu);
5160 if (die->tag == DW_TAG_structure_type
5161 || die->tag == DW_TAG_class_type)
5162 TYPE_NAME (type) = TYPE_TAG_NAME (type);
5166 /* The name is already allocated along with this objfile, so
5167 we don't need to duplicate it for the type. */
5168 TYPE_TAG_NAME (type) = (char *) name;
5169 if (die->tag == DW_TAG_class_type)
5170 TYPE_NAME (type) = TYPE_TAG_NAME (type);
5174 if (die->tag == DW_TAG_structure_type)
5176 TYPE_CODE (type) = TYPE_CODE_STRUCT;
5178 else if (die->tag == DW_TAG_union_type)
5180 TYPE_CODE (type) = TYPE_CODE_UNION;
5184 TYPE_CODE (type) = TYPE_CODE_CLASS;
5187 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
5188 TYPE_DECLARED_CLASS (type) = 1;
5190 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5193 TYPE_LENGTH (type) = DW_UNSND (attr);
5197 TYPE_LENGTH (type) = 0;
5200 TYPE_STUB_SUPPORTED (type) = 1;
5201 if (die_is_declaration (die, cu))
5202 TYPE_STUB (type) = 1;
5203 else if (attr == NULL && die->child == NULL
5204 && producer_is_realview (cu->producer))
5205 /* RealView does not output the required DW_AT_declaration
5206 on incomplete types. */
5207 TYPE_STUB (type) = 1;
5209 /* We need to add the type field to the die immediately so we don't
5210 infinitely recurse when dealing with pointers to the structure
5211 type within the structure itself. */
5212 set_die_type (die, type, cu);
5214 /* set_die_type should be already done. */
5215 set_descriptive_type (type, die, cu);
5217 if (die->child != NULL && ! die_is_declaration (die, cu))
5219 struct field_info fi;
5220 struct die_info *child_die;
5222 memset (&fi, 0, sizeof (struct field_info));
5224 child_die = die->child;
5226 while (child_die && child_die->tag)
5228 if (child_die->tag == DW_TAG_member
5229 || child_die->tag == DW_TAG_variable)
5231 /* NOTE: carlton/2002-11-05: A C++ static data member
5232 should be a DW_TAG_member that is a declaration, but
5233 all versions of G++ as of this writing (so through at
5234 least 3.2.1) incorrectly generate DW_TAG_variable
5235 tags for them instead. */
5236 dwarf2_add_field (&fi, child_die, cu);
5238 else if (child_die->tag == DW_TAG_subprogram)
5240 /* C++ member function. */
5241 dwarf2_add_member_fn (&fi, child_die, type, cu);
5243 else if (child_die->tag == DW_TAG_inheritance)
5245 /* C++ base class field. */
5246 dwarf2_add_field (&fi, child_die, cu);
5248 else if (child_die->tag == DW_TAG_typedef)
5249 dwarf2_add_typedef (&fi, child_die, cu);
5250 child_die = sibling_die (child_die);
5253 /* Attach fields and member functions to the type. */
5255 dwarf2_attach_fields_to_type (&fi, type, cu);
5258 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
5260 /* Get the type which refers to the base class (possibly this
5261 class itself) which contains the vtable pointer for the current
5262 class from the DW_AT_containing_type attribute. This use of
5263 DW_AT_containing_type is a GNU extension. */
5265 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
5267 struct type *t = die_containing_type (die, cu);
5269 TYPE_VPTR_BASETYPE (type) = t;
5274 /* Our own class provides vtbl ptr. */
5275 for (i = TYPE_NFIELDS (t) - 1;
5276 i >= TYPE_N_BASECLASSES (t);
5279 char *fieldname = TYPE_FIELD_NAME (t, i);
5281 if (is_vtable_name (fieldname, cu))
5283 TYPE_VPTR_FIELDNO (type) = i;
5288 /* Complain if virtual function table field not found. */
5289 if (i < TYPE_N_BASECLASSES (t))
5290 complaint (&symfile_complaints,
5291 _("virtual function table pointer not found when defining class '%s'"),
5292 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
5297 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
5300 else if (cu->producer
5301 && strncmp (cu->producer,
5302 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5304 /* The IBM XLC compiler does not provide direct indication
5305 of the containing type, but the vtable pointer is
5306 always named __vfp. */
5310 for (i = TYPE_NFIELDS (type) - 1;
5311 i >= TYPE_N_BASECLASSES (type);
5314 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
5316 TYPE_VPTR_FIELDNO (type) = i;
5317 TYPE_VPTR_BASETYPE (type) = type;
5324 /* Copy fi.typedef_field_list linked list elements content into the
5325 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
5326 if (fi.typedef_field_list)
5328 int i = fi.typedef_field_list_count;
5330 TYPE_TYPEDEF_FIELD_ARRAY (type)
5331 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
5332 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
5334 /* Reverse the list order to keep the debug info elements order. */
5337 struct typedef_field *dest, *src;
5339 dest = &TYPE_TYPEDEF_FIELD (type, i);
5340 src = &fi.typedef_field_list->field;
5341 fi.typedef_field_list = fi.typedef_field_list->next;
5347 quirk_gcc_member_function_pointer (type, cu->objfile);
5349 do_cleanups (back_to);
5354 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
5356 struct die_info *child_die = die->child;
5357 struct type *this_type;
5359 this_type = get_die_type (die, cu);
5360 if (this_type == NULL)
5361 this_type = read_structure_type (die, cu);
5363 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5364 snapshots) has been known to create a die giving a declaration
5365 for a class that has, as a child, a die giving a definition for a
5366 nested class. So we have to process our children even if the
5367 current die is a declaration. Normally, of course, a declaration
5368 won't have any children at all. */
5370 while (child_die != NULL && child_die->tag)
5372 if (child_die->tag == DW_TAG_member
5373 || child_die->tag == DW_TAG_variable
5374 || child_die->tag == DW_TAG_inheritance)
5379 process_die (child_die, cu);
5381 child_die = sibling_die (child_die);
5384 /* Do not consider external references. According to the DWARF standard,
5385 these DIEs are identified by the fact that they have no byte_size
5386 attribute, and a declaration attribute. */
5387 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
5388 || !die_is_declaration (die, cu))
5389 new_symbol (die, this_type, cu);
5392 /* Given a DW_AT_enumeration_type die, set its type. We do not
5393 complete the type's fields yet, or create any symbols. */
5395 static struct type *
5396 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
5398 struct objfile *objfile = cu->objfile;
5400 struct attribute *attr;
5403 /* If the definition of this type lives in .debug_types, read that type.
5404 Don't follow DW_AT_specification though, that will take us back up
5405 the chain and we want to go down. */
5406 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
5409 struct dwarf2_cu *type_cu = cu;
5410 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
5412 type = read_type_die (type_die, type_cu);
5413 return set_die_type (die, type, cu);
5416 type = alloc_type (objfile);
5418 TYPE_CODE (type) = TYPE_CODE_ENUM;
5419 name = dwarf2_full_name (NULL, die, cu);
5421 TYPE_TAG_NAME (type) = (char *) name;
5423 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5426 TYPE_LENGTH (type) = DW_UNSND (attr);
5430 TYPE_LENGTH (type) = 0;
5433 /* The enumeration DIE can be incomplete. In Ada, any type can be
5434 declared as private in the package spec, and then defined only
5435 inside the package body. Such types are known as Taft Amendment
5436 Types. When another package uses such a type, an incomplete DIE
5437 may be generated by the compiler. */
5438 if (die_is_declaration (die, cu))
5439 TYPE_STUB (type) = 1;
5441 return set_die_type (die, type, cu);
5444 /* Given a pointer to a die which begins an enumeration, process all
5445 the dies that define the members of the enumeration, and create the
5446 symbol for the enumeration type.
5448 NOTE: We reverse the order of the element list. */
5451 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
5453 struct die_info *child_die;
5454 struct field *fields;
5457 int unsigned_enum = 1;
5459 struct type *this_type;
5463 this_type = get_die_type (die, cu);
5464 if (this_type == NULL)
5465 this_type = read_enumeration_type (die, cu);
5466 if (die->child != NULL)
5468 child_die = die->child;
5469 while (child_die && child_die->tag)
5471 if (child_die->tag != DW_TAG_enumerator)
5473 process_die (child_die, cu);
5477 name = dwarf2_name (child_die, cu);
5480 sym = new_symbol (child_die, this_type, cu);
5481 if (SYMBOL_VALUE (sym) < 0)
5484 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
5486 fields = (struct field *)
5488 (num_fields + DW_FIELD_ALLOC_CHUNK)
5489 * sizeof (struct field));
5492 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
5493 FIELD_TYPE (fields[num_fields]) = NULL;
5494 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
5495 FIELD_BITSIZE (fields[num_fields]) = 0;
5501 child_die = sibling_die (child_die);
5506 TYPE_NFIELDS (this_type) = num_fields;
5507 TYPE_FIELDS (this_type) = (struct field *)
5508 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
5509 memcpy (TYPE_FIELDS (this_type), fields,
5510 sizeof (struct field) * num_fields);
5514 TYPE_UNSIGNED (this_type) = 1;
5517 new_symbol (die, this_type, cu);
5520 /* Extract all information from a DW_TAG_array_type DIE and put it in
5521 the DIE's type field. For now, this only handles one dimensional
5524 static struct type *
5525 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
5527 struct objfile *objfile = cu->objfile;
5528 struct die_info *child_die;
5530 struct type *element_type, *range_type, *index_type;
5531 struct type **range_types = NULL;
5532 struct attribute *attr;
5534 struct cleanup *back_to;
5537 element_type = die_type (die, cu);
5539 /* The die_type call above may have already set the type for this DIE. */
5540 type = get_die_type (die, cu);
5544 /* Irix 6.2 native cc creates array types without children for
5545 arrays with unspecified length. */
5546 if (die->child == NULL)
5548 index_type = objfile_type (objfile)->builtin_int;
5549 range_type = create_range_type (NULL, index_type, 0, -1);
5550 type = create_array_type (NULL, element_type, range_type);
5551 return set_die_type (die, type, cu);
5554 back_to = make_cleanup (null_cleanup, NULL);
5555 child_die = die->child;
5556 while (child_die && child_die->tag)
5558 if (child_die->tag == DW_TAG_subrange_type)
5560 struct type *child_type = read_type_die (child_die, cu);
5562 if (child_type != NULL)
5564 /* The range type was succesfully read. Save it for
5565 the array type creation. */
5566 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
5568 range_types = (struct type **)
5569 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
5570 * sizeof (struct type *));
5572 make_cleanup (free_current_contents, &range_types);
5574 range_types[ndim++] = child_type;
5577 child_die = sibling_die (child_die);
5580 /* Dwarf2 dimensions are output from left to right, create the
5581 necessary array types in backwards order. */
5583 type = element_type;
5585 if (read_array_order (die, cu) == DW_ORD_col_major)
5590 type = create_array_type (NULL, type, range_types[i++]);
5595 type = create_array_type (NULL, type, range_types[ndim]);
5598 /* Understand Dwarf2 support for vector types (like they occur on
5599 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5600 array type. This is not part of the Dwarf2/3 standard yet, but a
5601 custom vendor extension. The main difference between a regular
5602 array and the vector variant is that vectors are passed by value
5604 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
5606 make_vector_type (type);
5608 name = dwarf2_name (die, cu);
5610 TYPE_NAME (type) = name;
5612 /* Install the type in the die. */
5613 set_die_type (die, type, cu);
5615 /* set_die_type should be already done. */
5616 set_descriptive_type (type, die, cu);
5618 do_cleanups (back_to);
5623 static enum dwarf_array_dim_ordering
5624 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
5626 struct attribute *attr;
5628 attr = dwarf2_attr (die, DW_AT_ordering, cu);
5630 if (attr) return DW_SND (attr);
5633 GNU F77 is a special case, as at 08/2004 array type info is the
5634 opposite order to the dwarf2 specification, but data is still
5635 laid out as per normal fortran.
5637 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5641 if (cu->language == language_fortran
5642 && cu->producer && strstr (cu->producer, "GNU F77"))
5644 return DW_ORD_row_major;
5647 switch (cu->language_defn->la_array_ordering)
5649 case array_column_major:
5650 return DW_ORD_col_major;
5651 case array_row_major:
5653 return DW_ORD_row_major;
5657 /* Extract all information from a DW_TAG_set_type DIE and put it in
5658 the DIE's type field. */
5660 static struct type *
5661 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
5663 struct type *domain_type, *set_type;
5664 struct attribute *attr;
5666 domain_type = die_type (die, cu);
5668 /* The die_type call above may have already set the type for this DIE. */
5669 set_type = get_die_type (die, cu);
5673 set_type = create_set_type (NULL, domain_type);
5675 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5677 TYPE_LENGTH (set_type) = DW_UNSND (attr);
5679 return set_die_type (die, set_type, cu);
5682 /* First cut: install each common block member as a global variable. */
5685 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
5687 struct die_info *child_die;
5688 struct attribute *attr;
5690 CORE_ADDR base = (CORE_ADDR) 0;
5692 attr = dwarf2_attr (die, DW_AT_location, cu);
5695 /* Support the .debug_loc offsets */
5696 if (attr_form_is_block (attr))
5698 base = decode_locdesc (DW_BLOCK (attr), cu);
5700 else if (attr_form_is_section_offset (attr))
5702 dwarf2_complex_location_expr_complaint ();
5706 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5707 "common block member");
5710 if (die->child != NULL)
5712 child_die = die->child;
5713 while (child_die && child_die->tag)
5715 sym = new_symbol (child_die, NULL, cu);
5716 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
5719 CORE_ADDR byte_offset = 0;
5721 if (attr_form_is_section_offset (attr))
5722 dwarf2_complex_location_expr_complaint ();
5723 else if (attr_form_is_constant (attr))
5724 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5725 else if (attr_form_is_block (attr))
5726 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5728 dwarf2_complex_location_expr_complaint ();
5730 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
5731 add_symbol_to_list (sym, &global_symbols);
5733 child_die = sibling_die (child_die);
5738 /* Create a type for a C++ namespace. */
5740 static struct type *
5741 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
5743 struct objfile *objfile = cu->objfile;
5744 const char *previous_prefix, *name;
5748 /* For extensions, reuse the type of the original namespace. */
5749 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
5751 struct die_info *ext_die;
5752 struct dwarf2_cu *ext_cu = cu;
5754 ext_die = dwarf2_extension (die, &ext_cu);
5755 type = read_type_die (ext_die, ext_cu);
5756 return set_die_type (die, type, cu);
5759 name = namespace_name (die, &is_anonymous, cu);
5761 /* Now build the name of the current namespace. */
5763 previous_prefix = determine_prefix (die, cu);
5764 if (previous_prefix[0] != '\0')
5765 name = typename_concat (&objfile->objfile_obstack,
5766 previous_prefix, name, 0, cu);
5768 /* Create the type. */
5769 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
5771 TYPE_NAME (type) = (char *) name;
5772 TYPE_TAG_NAME (type) = TYPE_NAME (type);
5774 return set_die_type (die, type, cu);
5777 /* Read a C++ namespace. */
5780 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
5782 struct objfile *objfile = cu->objfile;
5786 /* Add a symbol associated to this if we haven't seen the namespace
5787 before. Also, add a using directive if it's an anonymous
5790 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
5794 type = read_type_die (die, cu);
5795 new_symbol (die, type, cu);
5797 name = namespace_name (die, &is_anonymous, cu);
5800 const char *previous_prefix = determine_prefix (die, cu);
5802 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
5803 NULL, &objfile->objfile_obstack);
5807 if (die->child != NULL)
5809 struct die_info *child_die = die->child;
5811 while (child_die && child_die->tag)
5813 process_die (child_die, cu);
5814 child_die = sibling_die (child_die);
5819 /* Read a Fortran module as type. This DIE can be only a declaration used for
5820 imported module. Still we need that type as local Fortran "use ... only"
5821 declaration imports depend on the created type in determine_prefix. */
5823 static struct type *
5824 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
5826 struct objfile *objfile = cu->objfile;
5830 module_name = dwarf2_name (die, cu);
5832 complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
5834 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
5836 /* determine_prefix uses TYPE_TAG_NAME. */
5837 TYPE_TAG_NAME (type) = TYPE_NAME (type);
5839 return set_die_type (die, type, cu);
5842 /* Read a Fortran module. */
5845 read_module (struct die_info *die, struct dwarf2_cu *cu)
5847 struct die_info *child_die = die->child;
5849 while (child_die && child_die->tag)
5851 process_die (child_die, cu);
5852 child_die = sibling_die (child_die);
5856 /* Return the name of the namespace represented by DIE. Set
5857 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5861 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
5863 struct die_info *current_die;
5864 const char *name = NULL;
5866 /* Loop through the extensions until we find a name. */
5868 for (current_die = die;
5869 current_die != NULL;
5870 current_die = dwarf2_extension (die, &cu))
5872 name = dwarf2_name (current_die, cu);
5877 /* Is it an anonymous namespace? */
5879 *is_anonymous = (name == NULL);
5881 name = "(anonymous namespace)";
5886 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5887 the user defined type vector. */
5889 static struct type *
5890 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
5892 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5893 struct comp_unit_head *cu_header = &cu->header;
5895 struct attribute *attr_byte_size;
5896 struct attribute *attr_address_class;
5897 int byte_size, addr_class;
5898 struct type *target_type;
5900 target_type = die_type (die, cu);
5902 /* The die_type call above may have already set the type for this DIE. */
5903 type = get_die_type (die, cu);
5907 type = lookup_pointer_type (target_type);
5909 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
5911 byte_size = DW_UNSND (attr_byte_size);
5913 byte_size = cu_header->addr_size;
5915 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
5916 if (attr_address_class)
5917 addr_class = DW_UNSND (attr_address_class);
5919 addr_class = DW_ADDR_none;
5921 /* If the pointer size or address class is different than the
5922 default, create a type variant marked as such and set the
5923 length accordingly. */
5924 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
5926 if (gdbarch_address_class_type_flags_p (gdbarch))
5930 type_flags = gdbarch_address_class_type_flags
5931 (gdbarch, byte_size, addr_class);
5932 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
5934 type = make_type_with_address_space (type, type_flags);
5936 else if (TYPE_LENGTH (type) != byte_size)
5938 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
5942 /* Should we also complain about unhandled address classes? */
5946 TYPE_LENGTH (type) = byte_size;
5947 return set_die_type (die, type, cu);
5950 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5951 the user defined type vector. */
5953 static struct type *
5954 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
5957 struct type *to_type;
5958 struct type *domain;
5960 to_type = die_type (die, cu);
5961 domain = die_containing_type (die, cu);
5963 /* The calls above may have already set the type for this DIE. */
5964 type = get_die_type (die, cu);
5968 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
5969 type = lookup_methodptr_type (to_type);
5971 type = lookup_memberptr_type (to_type, domain);
5973 return set_die_type (die, type, cu);
5976 /* Extract all information from a DW_TAG_reference_type DIE and add to
5977 the user defined type vector. */
5979 static struct type *
5980 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
5982 struct comp_unit_head *cu_header = &cu->header;
5983 struct type *type, *target_type;
5984 struct attribute *attr;
5986 target_type = die_type (die, cu);
5988 /* The die_type call above may have already set the type for this DIE. */
5989 type = get_die_type (die, cu);
5993 type = lookup_reference_type (target_type);
5994 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5997 TYPE_LENGTH (type) = DW_UNSND (attr);
6001 TYPE_LENGTH (type) = cu_header->addr_size;
6003 return set_die_type (die, type, cu);
6006 static struct type *
6007 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
6009 struct type *base_type, *cv_type;
6011 base_type = die_type (die, cu);
6013 /* The die_type call above may have already set the type for this DIE. */
6014 cv_type = get_die_type (die, cu);
6018 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
6019 return set_die_type (die, cv_type, cu);
6022 static struct type *
6023 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
6025 struct type *base_type, *cv_type;
6027 base_type = die_type (die, cu);
6029 /* The die_type call above may have already set the type for this DIE. */
6030 cv_type = get_die_type (die, cu);
6034 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
6035 return set_die_type (die, cv_type, cu);
6038 /* Extract all information from a DW_TAG_string_type DIE and add to
6039 the user defined type vector. It isn't really a user defined type,
6040 but it behaves like one, with other DIE's using an AT_user_def_type
6041 attribute to reference it. */
6043 static struct type *
6044 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
6046 struct objfile *objfile = cu->objfile;
6047 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6048 struct type *type, *range_type, *index_type, *char_type;
6049 struct attribute *attr;
6050 unsigned int length;
6052 attr = dwarf2_attr (die, DW_AT_string_length, cu);
6055 length = DW_UNSND (attr);
6059 /* check for the DW_AT_byte_size attribute */
6060 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6063 length = DW_UNSND (attr);
6071 index_type = objfile_type (objfile)->builtin_int;
6072 range_type = create_range_type (NULL, index_type, 1, length);
6073 char_type = language_string_char_type (cu->language_defn, gdbarch);
6074 type = create_string_type (NULL, char_type, range_type);
6076 return set_die_type (die, type, cu);
6079 /* Handle DIES due to C code like:
6083 int (*funcp)(int a, long l);
6087 ('funcp' generates a DW_TAG_subroutine_type DIE)
6090 static struct type *
6091 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
6093 struct type *type; /* Type that this function returns */
6094 struct type *ftype; /* Function that returns above type */
6095 struct attribute *attr;
6097 type = die_type (die, cu);
6099 /* The die_type call above may have already set the type for this DIE. */
6100 ftype = get_die_type (die, cu);
6104 ftype = lookup_function_type (type);
6106 /* All functions in C++, Pascal and Java have prototypes. */
6107 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
6108 if ((attr && (DW_UNSND (attr) != 0))
6109 || cu->language == language_cplus
6110 || cu->language == language_java
6111 || cu->language == language_pascal)
6112 TYPE_PROTOTYPED (ftype) = 1;
6113 else if (producer_is_realview (cu->producer))
6114 /* RealView does not emit DW_AT_prototyped. We can not
6115 distinguish prototyped and unprototyped functions; default to
6116 prototyped, since that is more common in modern code (and
6117 RealView warns about unprototyped functions). */
6118 TYPE_PROTOTYPED (ftype) = 1;
6120 /* Store the calling convention in the type if it's available in
6121 the subroutine die. Otherwise set the calling convention to
6122 the default value DW_CC_normal. */
6123 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
6124 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
6126 /* We need to add the subroutine type to the die immediately so
6127 we don't infinitely recurse when dealing with parameters
6128 declared as the same subroutine type. */
6129 set_die_type (die, ftype, cu);
6131 if (die->child != NULL)
6133 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
6134 struct die_info *child_die;
6135 int nparams, iparams;
6137 /* Count the number of parameters.
6138 FIXME: GDB currently ignores vararg functions, but knows about
6139 vararg member functions. */
6141 child_die = die->child;
6142 while (child_die && child_die->tag)
6144 if (child_die->tag == DW_TAG_formal_parameter)
6146 else if (child_die->tag == DW_TAG_unspecified_parameters)
6147 TYPE_VARARGS (ftype) = 1;
6148 child_die = sibling_die (child_die);
6151 /* Allocate storage for parameters and fill them in. */
6152 TYPE_NFIELDS (ftype) = nparams;
6153 TYPE_FIELDS (ftype) = (struct field *)
6154 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
6156 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
6157 even if we error out during the parameters reading below. */
6158 for (iparams = 0; iparams < nparams; iparams++)
6159 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
6162 child_die = die->child;
6163 while (child_die && child_die->tag)
6165 if (child_die->tag == DW_TAG_formal_parameter)
6167 /* Dwarf2 has no clean way to discern C++ static and non-static
6168 member functions. G++ helps GDB by marking the first
6169 parameter for non-static member functions (which is the
6170 this pointer) as artificial. We pass this information
6171 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
6172 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
6174 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
6177 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
6179 /* GCC/43521: In java, the formal parameter
6180 "this" is sometimes not marked with DW_AT_artificial. */
6181 if (cu->language == language_java)
6183 const char *name = dwarf2_name (child_die, cu);
6185 if (name && !strcmp (name, "this"))
6186 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
6189 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
6192 child_die = sibling_die (child_die);
6199 static struct type *
6200 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
6202 struct objfile *objfile = cu->objfile;
6203 const char *name = NULL;
6204 struct type *this_type;
6206 name = dwarf2_full_name (NULL, die, cu);
6207 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
6208 TYPE_FLAG_TARGET_STUB, NULL, objfile);
6209 TYPE_NAME (this_type) = (char *) name;
6210 set_die_type (die, this_type, cu);
6211 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
6215 /* Find a representation of a given base type and install
6216 it in the TYPE field of the die. */
6218 static struct type *
6219 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
6221 struct objfile *objfile = cu->objfile;
6223 struct attribute *attr;
6224 int encoding = 0, size = 0;
6226 enum type_code code = TYPE_CODE_INT;
6228 struct type *target_type = NULL;
6230 attr = dwarf2_attr (die, DW_AT_encoding, cu);
6233 encoding = DW_UNSND (attr);
6235 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6238 size = DW_UNSND (attr);
6240 name = dwarf2_name (die, cu);
6243 complaint (&symfile_complaints,
6244 _("DW_AT_name missing from DW_TAG_base_type"));
6249 case DW_ATE_address:
6250 /* Turn DW_ATE_address into a void * pointer. */
6251 code = TYPE_CODE_PTR;
6252 type_flags |= TYPE_FLAG_UNSIGNED;
6253 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
6255 case DW_ATE_boolean:
6256 code = TYPE_CODE_BOOL;
6257 type_flags |= TYPE_FLAG_UNSIGNED;
6259 case DW_ATE_complex_float:
6260 code = TYPE_CODE_COMPLEX;
6261 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
6263 case DW_ATE_decimal_float:
6264 code = TYPE_CODE_DECFLOAT;
6267 code = TYPE_CODE_FLT;
6271 case DW_ATE_unsigned:
6272 type_flags |= TYPE_FLAG_UNSIGNED;
6274 case DW_ATE_signed_char:
6275 if (cu->language == language_ada || cu->language == language_m2
6276 || cu->language == language_pascal)
6277 code = TYPE_CODE_CHAR;
6279 case DW_ATE_unsigned_char:
6280 if (cu->language == language_ada || cu->language == language_m2
6281 || cu->language == language_pascal)
6282 code = TYPE_CODE_CHAR;
6283 type_flags |= TYPE_FLAG_UNSIGNED;
6286 /* We just treat this as an integer and then recognize the
6287 type by name elsewhere. */
6291 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
6292 dwarf_type_encoding_name (encoding));
6296 type = init_type (code, size, type_flags, NULL, objfile);
6297 TYPE_NAME (type) = name;
6298 TYPE_TARGET_TYPE (type) = target_type;
6300 if (name && strcmp (name, "char") == 0)
6301 TYPE_NOSIGN (type) = 1;
6303 return set_die_type (die, type, cu);
6306 /* Read the given DW_AT_subrange DIE. */
6308 static struct type *
6309 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6311 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
6312 struct type *base_type;
6313 struct type *range_type;
6314 struct attribute *attr;
6318 LONGEST negative_mask;
6320 base_type = die_type (die, cu);
6322 /* The die_type call above may have already set the type for this DIE. */
6323 range_type = get_die_type (die, cu);
6327 if (cu->language == language_fortran)
6329 /* FORTRAN implies a lower bound of 1, if not given. */
6333 /* FIXME: For variable sized arrays either of these could be
6334 a variable rather than a constant value. We'll allow it,
6335 but we don't know how to handle it. */
6336 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6338 low = dwarf2_get_attr_constant_value (attr, 0);
6340 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6343 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
6345 /* GCC encodes arrays with unspecified or dynamic length
6346 with a DW_FORM_block1 attribute or a reference attribute.
6347 FIXME: GDB does not yet know how to handle dynamic
6348 arrays properly, treat them as arrays with unspecified
6351 FIXME: jimb/2003-09-22: GDB does not really know
6352 how to handle arrays of unspecified length
6353 either; we just represent them as zero-length
6354 arrays. Choose an appropriate upper bound given
6355 the lower bound we've computed above. */
6359 high = dwarf2_get_attr_constant_value (attr, 1);
6363 attr = dwarf2_attr (die, DW_AT_count, cu);
6366 int count = dwarf2_get_attr_constant_value (attr, 1);
6367 high = low + count - 1;
6371 /* Dwarf-2 specifications explicitly allows to create subrange types
6372 without specifying a base type.
6373 In that case, the base type must be set to the type of
6374 the lower bound, upper bound or count, in that order, if any of these
6375 three attributes references an object that has a type.
6376 If no base type is found, the Dwarf-2 specifications say that
6377 a signed integer type of size equal to the size of an address should
6379 For the following C code: `extern char gdb_int [];'
6380 GCC produces an empty range DIE.
6381 FIXME: muller/2010-05-28: Possible references to object for low bound,
6382 high bound or count are not yet handled by this code.
6384 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
6386 struct objfile *objfile = cu->objfile;
6387 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6388 int addr_size = gdbarch_addr_bit (gdbarch) /8;
6389 struct type *int_type = objfile_type (objfile)->builtin_int;
6391 /* Test "int", "long int", and "long long int" objfile types,
6392 and select the first one having a size above or equal to the
6393 architecture address size. */
6394 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
6395 base_type = int_type;
6398 int_type = objfile_type (objfile)->builtin_long;
6399 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
6400 base_type = int_type;
6403 int_type = objfile_type (objfile)->builtin_long_long;
6404 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
6405 base_type = int_type;
6411 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
6412 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
6413 low |= negative_mask;
6414 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
6415 high |= negative_mask;
6417 range_type = create_range_type (NULL, base_type, low, high);
6419 /* Mark arrays with dynamic length at least as an array of unspecified
6420 length. GDB could check the boundary but before it gets implemented at
6421 least allow accessing the array elements. */
6422 if (attr && attr->form == DW_FORM_block1)
6423 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
6425 name = dwarf2_name (die, cu);
6427 TYPE_NAME (range_type) = name;
6429 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6431 TYPE_LENGTH (range_type) = DW_UNSND (attr);
6433 set_die_type (die, range_type, cu);
6435 /* set_die_type should be already done. */
6436 set_descriptive_type (range_type, die, cu);
6441 static struct type *
6442 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
6446 /* For now, we only support the C meaning of an unspecified type: void. */
6448 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
6449 TYPE_NAME (type) = dwarf2_name (die, cu);
6451 return set_die_type (die, type, cu);
6454 /* Trivial hash function for die_info: the hash value of a DIE
6455 is its offset in .debug_info for this objfile. */
6458 die_hash (const void *item)
6460 const struct die_info *die = item;
6465 /* Trivial comparison function for die_info structures: two DIEs
6466 are equal if they have the same offset. */
6469 die_eq (const void *item_lhs, const void *item_rhs)
6471 const struct die_info *die_lhs = item_lhs;
6472 const struct die_info *die_rhs = item_rhs;
6474 return die_lhs->offset == die_rhs->offset;
6477 /* Read a whole compilation unit into a linked list of dies. */
6479 static struct die_info *
6480 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
6482 struct die_reader_specs reader_specs;
6484 gdb_assert (cu->die_hash == NULL);
6486 = htab_create_alloc_ex (cu->header.length / 12,
6490 &cu->comp_unit_obstack,
6491 hashtab_obstack_allocate,
6492 dummy_obstack_deallocate);
6494 init_cu_die_reader (&reader_specs, cu);
6496 return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
6499 /* Main entry point for reading a DIE and all children.
6500 Read the DIE and dump it if requested. */
6502 static struct die_info *
6503 read_die_and_children (const struct die_reader_specs *reader,
6505 gdb_byte **new_info_ptr,
6506 struct die_info *parent)
6508 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
6509 new_info_ptr, parent);
6511 if (dwarf2_die_debug)
6513 fprintf_unfiltered (gdb_stdlog,
6514 "\nRead die from %s of %s:\n",
6515 reader->buffer == dwarf2_per_objfile->info.buffer
6517 : reader->buffer == dwarf2_per_objfile->types.buffer
6519 : "unknown section",
6520 reader->abfd->filename);
6521 dump_die (result, dwarf2_die_debug);
6527 /* Read a single die and all its descendents. Set the die's sibling
6528 field to NULL; set other fields in the die correctly, and set all
6529 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6530 location of the info_ptr after reading all of those dies. PARENT
6531 is the parent of the die in question. */
6533 static struct die_info *
6534 read_die_and_children_1 (const struct die_reader_specs *reader,
6536 gdb_byte **new_info_ptr,
6537 struct die_info *parent)
6539 struct die_info *die;
6543 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
6546 *new_info_ptr = cur_ptr;
6549 store_in_ref_table (die, reader->cu);
6552 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
6556 *new_info_ptr = cur_ptr;
6559 die->sibling = NULL;
6560 die->parent = parent;
6564 /* Read a die, all of its descendents, and all of its siblings; set
6565 all of the fields of all of the dies correctly. Arguments are as
6566 in read_die_and_children. */
6568 static struct die_info *
6569 read_die_and_siblings (const struct die_reader_specs *reader,
6571 gdb_byte **new_info_ptr,
6572 struct die_info *parent)
6574 struct die_info *first_die, *last_sibling;
6578 first_die = last_sibling = NULL;
6582 struct die_info *die
6583 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
6587 *new_info_ptr = cur_ptr;
6594 last_sibling->sibling = die;
6600 /* Read the die from the .debug_info section buffer. Set DIEP to
6601 point to a newly allocated die with its information, except for its
6602 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6603 whether the die has children or not. */
6606 read_full_die (const struct die_reader_specs *reader,
6607 struct die_info **diep, gdb_byte *info_ptr,
6610 unsigned int abbrev_number, bytes_read, i, offset;
6611 struct abbrev_info *abbrev;
6612 struct die_info *die;
6613 struct dwarf2_cu *cu = reader->cu;
6614 bfd *abfd = reader->abfd;
6616 offset = info_ptr - reader->buffer;
6617 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6618 info_ptr += bytes_read;
6626 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
6628 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6630 bfd_get_filename (abfd));
6632 die = dwarf_alloc_die (cu, abbrev->num_attrs);
6633 die->offset = offset;
6634 die->tag = abbrev->tag;
6635 die->abbrev = abbrev_number;
6637 die->num_attrs = abbrev->num_attrs;
6639 for (i = 0; i < abbrev->num_attrs; ++i)
6640 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
6641 abfd, info_ptr, cu);
6644 *has_children = abbrev->has_children;
6648 /* In DWARF version 2, the description of the debugging information is
6649 stored in a separate .debug_abbrev section. Before we read any
6650 dies from a section we read in all abbreviations and install them
6651 in a hash table. This function also sets flags in CU describing
6652 the data found in the abbrev table. */
6655 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
6657 struct comp_unit_head *cu_header = &cu->header;
6658 gdb_byte *abbrev_ptr;
6659 struct abbrev_info *cur_abbrev;
6660 unsigned int abbrev_number, bytes_read, abbrev_name;
6661 unsigned int abbrev_form, hash_number;
6662 struct attr_abbrev *cur_attrs;
6663 unsigned int allocated_attrs;
6665 /* Initialize dwarf2 abbrevs */
6666 obstack_init (&cu->abbrev_obstack);
6667 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
6669 * sizeof (struct abbrev_info *)));
6670 memset (cu->dwarf2_abbrevs, 0,
6671 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
6673 dwarf2_read_section (dwarf2_per_objfile->objfile,
6674 &dwarf2_per_objfile->abbrev);
6675 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
6676 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6677 abbrev_ptr += bytes_read;
6679 allocated_attrs = ATTR_ALLOC_CHUNK;
6680 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
6682 /* loop until we reach an abbrev number of 0 */
6683 while (abbrev_number)
6685 cur_abbrev = dwarf_alloc_abbrev (cu);
6687 /* read in abbrev header */
6688 cur_abbrev->number = abbrev_number;
6689 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6690 abbrev_ptr += bytes_read;
6691 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
6694 if (cur_abbrev->tag == DW_TAG_namespace)
6695 cu->has_namespace_info = 1;
6697 /* now read in declarations */
6698 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6699 abbrev_ptr += bytes_read;
6700 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6701 abbrev_ptr += bytes_read;
6704 if (cur_abbrev->num_attrs == allocated_attrs)
6706 allocated_attrs += ATTR_ALLOC_CHUNK;
6708 = xrealloc (cur_attrs, (allocated_attrs
6709 * sizeof (struct attr_abbrev)));
6712 /* Record whether this compilation unit might have
6713 inter-compilation-unit references. If we don't know what form
6714 this attribute will have, then it might potentially be a
6715 DW_FORM_ref_addr, so we conservatively expect inter-CU
6718 if (abbrev_form == DW_FORM_ref_addr
6719 || abbrev_form == DW_FORM_indirect)
6720 cu->has_form_ref_addr = 1;
6722 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
6723 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
6724 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6725 abbrev_ptr += bytes_read;
6726 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6727 abbrev_ptr += bytes_read;
6730 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
6731 (cur_abbrev->num_attrs
6732 * sizeof (struct attr_abbrev)));
6733 memcpy (cur_abbrev->attrs, cur_attrs,
6734 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
6736 hash_number = abbrev_number % ABBREV_HASH_SIZE;
6737 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
6738 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
6740 /* Get next abbreviation.
6741 Under Irix6 the abbreviations for a compilation unit are not
6742 always properly terminated with an abbrev number of 0.
6743 Exit loop if we encounter an abbreviation which we have
6744 already read (which means we are about to read the abbreviations
6745 for the next compile unit) or if the end of the abbreviation
6746 table is reached. */
6747 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
6748 >= dwarf2_per_objfile->abbrev.size)
6750 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6751 abbrev_ptr += bytes_read;
6752 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
6759 /* Release the memory used by the abbrev table for a compilation unit. */
6762 dwarf2_free_abbrev_table (void *ptr_to_cu)
6764 struct dwarf2_cu *cu = ptr_to_cu;
6766 obstack_free (&cu->abbrev_obstack, NULL);
6767 cu->dwarf2_abbrevs = NULL;
6770 /* Lookup an abbrev_info structure in the abbrev hash table. */
6772 static struct abbrev_info *
6773 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
6775 unsigned int hash_number;
6776 struct abbrev_info *abbrev;
6778 hash_number = number % ABBREV_HASH_SIZE;
6779 abbrev = cu->dwarf2_abbrevs[hash_number];
6783 if (abbrev->number == number)
6786 abbrev = abbrev->next;
6791 /* Returns nonzero if TAG represents a type that we might generate a partial
6795 is_type_tag_for_partial (int tag)
6800 /* Some types that would be reasonable to generate partial symbols for,
6801 that we don't at present. */
6802 case DW_TAG_array_type:
6803 case DW_TAG_file_type:
6804 case DW_TAG_ptr_to_member_type:
6805 case DW_TAG_set_type:
6806 case DW_TAG_string_type:
6807 case DW_TAG_subroutine_type:
6809 case DW_TAG_base_type:
6810 case DW_TAG_class_type:
6811 case DW_TAG_interface_type:
6812 case DW_TAG_enumeration_type:
6813 case DW_TAG_structure_type:
6814 case DW_TAG_subrange_type:
6815 case DW_TAG_typedef:
6816 case DW_TAG_union_type:
6823 /* Load all DIEs that are interesting for partial symbols into memory. */
6825 static struct partial_die_info *
6826 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6827 int building_psymtab, struct dwarf2_cu *cu)
6829 struct partial_die_info *part_die;
6830 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
6831 struct abbrev_info *abbrev;
6832 unsigned int bytes_read;
6833 unsigned int load_all = 0;
6835 int nesting_level = 1;
6840 if (cu->per_cu && cu->per_cu->load_all_dies)
6844 = htab_create_alloc_ex (cu->header.length / 12,
6848 &cu->comp_unit_obstack,
6849 hashtab_obstack_allocate,
6850 dummy_obstack_deallocate);
6852 part_die = obstack_alloc (&cu->comp_unit_obstack,
6853 sizeof (struct partial_die_info));
6857 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6859 /* A NULL abbrev means the end of a series of children. */
6862 if (--nesting_level == 0)
6864 /* PART_DIE was probably the last thing allocated on the
6865 comp_unit_obstack, so we could call obstack_free
6866 here. We don't do that because the waste is small,
6867 and will be cleaned up when we're done with this
6868 compilation unit. This way, we're also more robust
6869 against other users of the comp_unit_obstack. */
6872 info_ptr += bytes_read;
6873 last_die = parent_die;
6874 parent_die = parent_die->die_parent;
6878 /* Check whether this DIE is interesting enough to save. Normally
6879 we would not be interested in members here, but there may be
6880 later variables referencing them via DW_AT_specification (for
6883 && !is_type_tag_for_partial (abbrev->tag)
6884 && abbrev->tag != DW_TAG_enumerator
6885 && abbrev->tag != DW_TAG_subprogram
6886 && abbrev->tag != DW_TAG_lexical_block
6887 && abbrev->tag != DW_TAG_variable
6888 && abbrev->tag != DW_TAG_namespace
6889 && abbrev->tag != DW_TAG_module
6890 && abbrev->tag != DW_TAG_member)
6892 /* Otherwise we skip to the next sibling, if any. */
6893 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
6897 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
6898 buffer, info_ptr, cu);
6900 /* This two-pass algorithm for processing partial symbols has a
6901 high cost in cache pressure. Thus, handle some simple cases
6902 here which cover the majority of C partial symbols. DIEs
6903 which neither have specification tags in them, nor could have
6904 specification tags elsewhere pointing at them, can simply be
6905 processed and discarded.
6907 This segment is also optional; scan_partial_symbols and
6908 add_partial_symbol will handle these DIEs if we chain
6909 them in normally. When compilers which do not emit large
6910 quantities of duplicate debug information are more common,
6911 this code can probably be removed. */
6913 /* Any complete simple types at the top level (pretty much all
6914 of them, for a language without namespaces), can be processed
6916 if (parent_die == NULL
6917 && part_die->has_specification == 0
6918 && part_die->is_declaration == 0
6919 && (part_die->tag == DW_TAG_typedef
6920 || part_die->tag == DW_TAG_base_type
6921 || part_die->tag == DW_TAG_subrange_type))
6923 if (building_psymtab && part_die->name != NULL)
6924 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
6925 VAR_DOMAIN, LOC_TYPEDEF,
6926 &cu->objfile->static_psymbols,
6927 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6928 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6932 /* If we're at the second level, and we're an enumerator, and
6933 our parent has no specification (meaning possibly lives in a
6934 namespace elsewhere), then we can add the partial symbol now
6935 instead of queueing it. */
6936 if (part_die->tag == DW_TAG_enumerator
6937 && parent_die != NULL
6938 && parent_die->die_parent == NULL
6939 && parent_die->tag == DW_TAG_enumeration_type
6940 && parent_die->has_specification == 0)
6942 if (part_die->name == NULL)
6943 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6944 else if (building_psymtab)
6945 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
6946 VAR_DOMAIN, LOC_CONST,
6947 (cu->language == language_cplus
6948 || cu->language == language_java)
6949 ? &cu->objfile->global_psymbols
6950 : &cu->objfile->static_psymbols,
6951 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6953 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6957 /* We'll save this DIE so link it in. */
6958 part_die->die_parent = parent_die;
6959 part_die->die_sibling = NULL;
6960 part_die->die_child = NULL;
6962 if (last_die && last_die == parent_die)
6963 last_die->die_child = part_die;
6965 last_die->die_sibling = part_die;
6967 last_die = part_die;
6969 if (first_die == NULL)
6970 first_die = part_die;
6972 /* Maybe add the DIE to the hash table. Not all DIEs that we
6973 find interesting need to be in the hash table, because we
6974 also have the parent/sibling/child chains; only those that we
6975 might refer to by offset later during partial symbol reading.
6977 For now this means things that might have be the target of a
6978 DW_AT_specification, DW_AT_abstract_origin, or
6979 DW_AT_extension. DW_AT_extension will refer only to
6980 namespaces; DW_AT_abstract_origin refers to functions (and
6981 many things under the function DIE, but we do not recurse
6982 into function DIEs during partial symbol reading) and
6983 possibly variables as well; DW_AT_specification refers to
6984 declarations. Declarations ought to have the DW_AT_declaration
6985 flag. It happens that GCC forgets to put it in sometimes, but
6986 only for functions, not for types.
6988 Adding more things than necessary to the hash table is harmless
6989 except for the performance cost. Adding too few will result in
6990 wasted time in find_partial_die, when we reread the compilation
6991 unit with load_all_dies set. */
6994 || abbrev->tag == DW_TAG_subprogram
6995 || abbrev->tag == DW_TAG_variable
6996 || abbrev->tag == DW_TAG_namespace
6997 || part_die->is_declaration)
7001 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
7002 part_die->offset, INSERT);
7006 part_die = obstack_alloc (&cu->comp_unit_obstack,
7007 sizeof (struct partial_die_info));
7009 /* For some DIEs we want to follow their children (if any). For C
7010 we have no reason to follow the children of structures; for other
7011 languages we have to, both so that we can get at method physnames
7012 to infer fully qualified class names, and for DW_AT_specification.
7014 For Ada, we need to scan the children of subprograms and lexical
7015 blocks as well because Ada allows the definition of nested
7016 entities that could be interesting for the debugger, such as
7017 nested subprograms for instance. */
7018 if (last_die->has_children
7020 || last_die->tag == DW_TAG_namespace
7021 || last_die->tag == DW_TAG_module
7022 || last_die->tag == DW_TAG_enumeration_type
7023 || (cu->language != language_c
7024 && (last_die->tag == DW_TAG_class_type
7025 || last_die->tag == DW_TAG_interface_type
7026 || last_die->tag == DW_TAG_structure_type
7027 || last_die->tag == DW_TAG_union_type))
7028 || (cu->language == language_ada
7029 && (last_die->tag == DW_TAG_subprogram
7030 || last_die->tag == DW_TAG_lexical_block))))
7033 parent_die = last_die;
7037 /* Otherwise we skip to the next sibling, if any. */
7038 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
7040 /* Back to the top, do it again. */
7044 /* Read a minimal amount of information into the minimal die structure. */
7047 read_partial_die (struct partial_die_info *part_die,
7048 struct abbrev_info *abbrev,
7049 unsigned int abbrev_len, bfd *abfd,
7050 gdb_byte *buffer, gdb_byte *info_ptr,
7051 struct dwarf2_cu *cu)
7054 struct attribute attr;
7055 int has_low_pc_attr = 0;
7056 int has_high_pc_attr = 0;
7058 memset (part_die, 0, sizeof (struct partial_die_info));
7060 part_die->offset = info_ptr - buffer;
7062 info_ptr += abbrev_len;
7067 part_die->tag = abbrev->tag;
7068 part_die->has_children = abbrev->has_children;
7070 for (i = 0; i < abbrev->num_attrs; ++i)
7072 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
7074 /* Store the data if it is of an attribute we want to keep in a
7075 partial symbol table. */
7079 switch (part_die->tag)
7081 case DW_TAG_compile_unit:
7082 case DW_TAG_type_unit:
7083 /* Compilation units have a DW_AT_name that is a filename, not
7084 a source language identifier. */
7085 case DW_TAG_enumeration_type:
7086 case DW_TAG_enumerator:
7087 /* These tags always have simple identifiers already; no need
7088 to canonicalize them. */
7089 part_die->name = DW_STRING (&attr);
7093 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
7094 &cu->objfile->objfile_obstack);
7098 case DW_AT_linkage_name:
7099 case DW_AT_MIPS_linkage_name:
7100 /* Note that both forms of linkage name might appear. We
7101 assume they will be the same, and we only store the last
7103 if (cu->language == language_ada)
7104 part_die->name = DW_STRING (&attr);
7107 has_low_pc_attr = 1;
7108 part_die->lowpc = DW_ADDR (&attr);
7111 has_high_pc_attr = 1;
7112 part_die->highpc = DW_ADDR (&attr);
7114 case DW_AT_location:
7115 /* Support the .debug_loc offsets */
7116 if (attr_form_is_block (&attr))
7118 part_die->locdesc = DW_BLOCK (&attr);
7120 else if (attr_form_is_section_offset (&attr))
7122 dwarf2_complex_location_expr_complaint ();
7126 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7127 "partial symbol information");
7130 case DW_AT_external:
7131 part_die->is_external = DW_UNSND (&attr);
7133 case DW_AT_declaration:
7134 part_die->is_declaration = DW_UNSND (&attr);
7137 part_die->has_type = 1;
7139 case DW_AT_abstract_origin:
7140 case DW_AT_specification:
7141 case DW_AT_extension:
7142 part_die->has_specification = 1;
7143 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
7146 /* Ignore absolute siblings, they might point outside of
7147 the current compile unit. */
7148 if (attr.form == DW_FORM_ref_addr)
7149 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
7151 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
7153 case DW_AT_byte_size:
7154 part_die->has_byte_size = 1;
7156 case DW_AT_calling_convention:
7157 /* DWARF doesn't provide a way to identify a program's source-level
7158 entry point. DW_AT_calling_convention attributes are only meant
7159 to describe functions' calling conventions.
7161 However, because it's a necessary piece of information in
7162 Fortran, and because DW_CC_program is the only piece of debugging
7163 information whose definition refers to a 'main program' at all,
7164 several compilers have begun marking Fortran main programs with
7165 DW_CC_program --- even when those functions use the standard
7166 calling conventions.
7168 So until DWARF specifies a way to provide this information and
7169 compilers pick up the new representation, we'll support this
7171 if (DW_UNSND (&attr) == DW_CC_program
7172 && cu->language == language_fortran)
7173 set_main_name (part_die->name);
7180 /* When using the GNU linker, .gnu.linkonce. sections are used to
7181 eliminate duplicate copies of functions and vtables and such.
7182 The linker will arbitrarily choose one and discard the others.
7183 The AT_*_pc values for such functions refer to local labels in
7184 these sections. If the section from that file was discarded, the
7185 labels are not in the output, so the relocs get a value of 0.
7186 If this is a discarded function, mark the pc bounds as invalid,
7187 so that GDB will ignore it. */
7188 if (has_low_pc_attr && has_high_pc_attr
7189 && part_die->lowpc < part_die->highpc
7190 && (part_die->lowpc != 0
7191 || dwarf2_per_objfile->has_section_at_zero))
7192 part_die->has_pc_info = 1;
7197 /* Find a cached partial DIE at OFFSET in CU. */
7199 static struct partial_die_info *
7200 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
7202 struct partial_die_info *lookup_die = NULL;
7203 struct partial_die_info part_die;
7205 part_die.offset = offset;
7206 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
7211 /* Find a partial DIE at OFFSET, which may or may not be in CU,
7212 except in the case of .debug_types DIEs which do not reference
7213 outside their CU (they do however referencing other types via
7216 static struct partial_die_info *
7217 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
7219 struct dwarf2_per_cu_data *per_cu = NULL;
7220 struct partial_die_info *pd = NULL;
7222 if (cu->per_cu->from_debug_types)
7224 pd = find_partial_die_in_comp_unit (offset, cu);
7230 if (offset_in_cu_p (&cu->header, offset))
7232 pd = find_partial_die_in_comp_unit (offset, cu);
7237 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
7239 if (per_cu->cu == NULL)
7241 load_partial_comp_unit (per_cu, cu->objfile);
7242 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
7243 dwarf2_per_objfile->read_in_chain = per_cu;
7246 per_cu->cu->last_used = 0;
7247 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
7249 if (pd == NULL && per_cu->load_all_dies == 0)
7251 struct cleanup *back_to;
7252 struct partial_die_info comp_unit_die;
7253 struct abbrev_info *abbrev;
7254 unsigned int bytes_read;
7257 per_cu->load_all_dies = 1;
7259 /* Re-read the DIEs. */
7260 back_to = make_cleanup (null_cleanup, 0);
7261 if (per_cu->cu->dwarf2_abbrevs == NULL)
7263 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
7264 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
7266 info_ptr = (dwarf2_per_objfile->info.buffer
7267 + per_cu->cu->header.offset
7268 + per_cu->cu->header.first_die_offset);
7269 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
7270 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
7271 per_cu->cu->objfile->obfd,
7272 dwarf2_per_objfile->info.buffer, info_ptr,
7274 if (comp_unit_die.has_children)
7275 load_partial_dies (per_cu->cu->objfile->obfd,
7276 dwarf2_per_objfile->info.buffer, info_ptr,
7278 do_cleanups (back_to);
7280 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
7286 internal_error (__FILE__, __LINE__,
7287 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7288 offset, bfd_get_filename (cu->objfile->obfd));
7292 /* Adjust PART_DIE before generating a symbol for it. This function
7293 may set the is_external flag or change the DIE's name. */
7296 fixup_partial_die (struct partial_die_info *part_die,
7297 struct dwarf2_cu *cu)
7299 /* If we found a reference attribute and the DIE has no name, try
7300 to find a name in the referred to DIE. */
7302 if (part_die->name == NULL && part_die->has_specification)
7304 struct partial_die_info *spec_die;
7306 spec_die = find_partial_die (part_die->spec_offset, cu);
7308 fixup_partial_die (spec_die, cu);
7312 part_die->name = spec_die->name;
7314 /* Copy DW_AT_external attribute if it is set. */
7315 if (spec_die->is_external)
7316 part_die->is_external = spec_die->is_external;
7320 /* Set default names for some unnamed DIEs. */
7321 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
7322 || part_die->tag == DW_TAG_class_type))
7323 part_die->name = "(anonymous class)";
7325 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
7326 part_die->name = "(anonymous namespace)";
7328 if (part_die->tag == DW_TAG_structure_type
7329 || part_die->tag == DW_TAG_class_type
7330 || part_die->tag == DW_TAG_union_type)
7331 guess_structure_name (part_die, cu);
7334 /* Read an attribute value described by an attribute form. */
7337 read_attribute_value (struct attribute *attr, unsigned form,
7338 bfd *abfd, gdb_byte *info_ptr,
7339 struct dwarf2_cu *cu)
7341 struct comp_unit_head *cu_header = &cu->header;
7342 unsigned int bytes_read;
7343 struct dwarf_block *blk;
7348 case DW_FORM_ref_addr:
7349 if (cu->header.version == 2)
7350 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
7352 DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
7353 info_ptr += bytes_read;
7356 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
7357 info_ptr += bytes_read;
7359 case DW_FORM_block2:
7360 blk = dwarf_alloc_block (cu);
7361 blk->size = read_2_bytes (abfd, info_ptr);
7363 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7364 info_ptr += blk->size;
7365 DW_BLOCK (attr) = blk;
7367 case DW_FORM_block4:
7368 blk = dwarf_alloc_block (cu);
7369 blk->size = read_4_bytes (abfd, info_ptr);
7371 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7372 info_ptr += blk->size;
7373 DW_BLOCK (attr) = blk;
7376 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
7380 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
7384 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
7387 case DW_FORM_sec_offset:
7388 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
7389 info_ptr += bytes_read;
7391 case DW_FORM_string:
7392 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
7393 DW_STRING_IS_CANONICAL (attr) = 0;
7394 info_ptr += bytes_read;
7397 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
7399 DW_STRING_IS_CANONICAL (attr) = 0;
7400 info_ptr += bytes_read;
7402 case DW_FORM_exprloc:
7404 blk = dwarf_alloc_block (cu);
7405 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7406 info_ptr += bytes_read;
7407 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7408 info_ptr += blk->size;
7409 DW_BLOCK (attr) = blk;
7411 case DW_FORM_block1:
7412 blk = dwarf_alloc_block (cu);
7413 blk->size = read_1_byte (abfd, info_ptr);
7415 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7416 info_ptr += blk->size;
7417 DW_BLOCK (attr) = blk;
7420 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7424 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7427 case DW_FORM_flag_present:
7428 DW_UNSND (attr) = 1;
7431 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
7432 info_ptr += bytes_read;
7435 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7436 info_ptr += bytes_read;
7439 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
7443 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
7447 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
7451 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
7455 /* Convert the signature to something we can record in DW_UNSND
7457 NOTE: This is NULL if the type wasn't found. */
7458 DW_SIGNATURED_TYPE (attr) =
7459 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
7462 case DW_FORM_ref_udata:
7463 DW_ADDR (attr) = (cu->header.offset
7464 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
7465 info_ptr += bytes_read;
7467 case DW_FORM_indirect:
7468 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7469 info_ptr += bytes_read;
7470 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
7473 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7474 dwarf_form_name (form),
7475 bfd_get_filename (abfd));
7478 /* We have seen instances where the compiler tried to emit a byte
7479 size attribute of -1 which ended up being encoded as an unsigned
7480 0xffffffff. Although 0xffffffff is technically a valid size value,
7481 an object of this size seems pretty unlikely so we can relatively
7482 safely treat these cases as if the size attribute was invalid and
7483 treat them as zero by default. */
7484 if (attr->name == DW_AT_byte_size
7485 && form == DW_FORM_data4
7486 && DW_UNSND (attr) >= 0xffffffff)
7489 (&symfile_complaints,
7490 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7491 hex_string (DW_UNSND (attr)));
7492 DW_UNSND (attr) = 0;
7498 /* Read an attribute described by an abbreviated attribute. */
7501 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
7502 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
7504 attr->name = abbrev->name;
7505 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
7508 /* read dwarf information from a buffer */
7511 read_1_byte (bfd *abfd, gdb_byte *buf)
7513 return bfd_get_8 (abfd, buf);
7517 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
7519 return bfd_get_signed_8 (abfd, buf);
7523 read_2_bytes (bfd *abfd, gdb_byte *buf)
7525 return bfd_get_16 (abfd, buf);
7529 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
7531 return bfd_get_signed_16 (abfd, buf);
7535 read_4_bytes (bfd *abfd, gdb_byte *buf)
7537 return bfd_get_32 (abfd, buf);
7541 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
7543 return bfd_get_signed_32 (abfd, buf);
7547 read_8_bytes (bfd *abfd, gdb_byte *buf)
7549 return bfd_get_64 (abfd, buf);
7553 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
7554 unsigned int *bytes_read)
7556 struct comp_unit_head *cu_header = &cu->header;
7557 CORE_ADDR retval = 0;
7559 if (cu_header->signed_addr_p)
7561 switch (cu_header->addr_size)
7564 retval = bfd_get_signed_16 (abfd, buf);
7567 retval = bfd_get_signed_32 (abfd, buf);
7570 retval = bfd_get_signed_64 (abfd, buf);
7573 internal_error (__FILE__, __LINE__,
7574 _("read_address: bad switch, signed [in module %s]"),
7575 bfd_get_filename (abfd));
7580 switch (cu_header->addr_size)
7583 retval = bfd_get_16 (abfd, buf);
7586 retval = bfd_get_32 (abfd, buf);
7589 retval = bfd_get_64 (abfd, buf);
7592 internal_error (__FILE__, __LINE__,
7593 _("read_address: bad switch, unsigned [in module %s]"),
7594 bfd_get_filename (abfd));
7598 *bytes_read = cu_header->addr_size;
7602 /* Read the initial length from a section. The (draft) DWARF 3
7603 specification allows the initial length to take up either 4 bytes
7604 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7605 bytes describe the length and all offsets will be 8 bytes in length
7608 An older, non-standard 64-bit format is also handled by this
7609 function. The older format in question stores the initial length
7610 as an 8-byte quantity without an escape value. Lengths greater
7611 than 2^32 aren't very common which means that the initial 4 bytes
7612 is almost always zero. Since a length value of zero doesn't make
7613 sense for the 32-bit format, this initial zero can be considered to
7614 be an escape value which indicates the presence of the older 64-bit
7615 format. As written, the code can't detect (old format) lengths
7616 greater than 4GB. If it becomes necessary to handle lengths
7617 somewhat larger than 4GB, we could allow other small values (such
7618 as the non-sensical values of 1, 2, and 3) to also be used as
7619 escape values indicating the presence of the old format.
7621 The value returned via bytes_read should be used to increment the
7622 relevant pointer after calling read_initial_length().
7624 [ Note: read_initial_length() and read_offset() are based on the
7625 document entitled "DWARF Debugging Information Format", revision
7626 3, draft 8, dated November 19, 2001. This document was obtained
7629 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7631 This document is only a draft and is subject to change. (So beware.)
7633 Details regarding the older, non-standard 64-bit format were
7634 determined empirically by examining 64-bit ELF files produced by
7635 the SGI toolchain on an IRIX 6.5 machine.
7637 - Kevin, July 16, 2002
7641 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
7643 LONGEST length = bfd_get_32 (abfd, buf);
7645 if (length == 0xffffffff)
7647 length = bfd_get_64 (abfd, buf + 4);
7650 else if (length == 0)
7652 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7653 length = bfd_get_64 (abfd, buf);
7664 /* Cover function for read_initial_length.
7665 Returns the length of the object at BUF, and stores the size of the
7666 initial length in *BYTES_READ and stores the size that offsets will be in
7668 If the initial length size is not equivalent to that specified in
7669 CU_HEADER then issue a complaint.
7670 This is useful when reading non-comp-unit headers. */
7673 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
7674 const struct comp_unit_head *cu_header,
7675 unsigned int *bytes_read,
7676 unsigned int *offset_size)
7678 LONGEST length = read_initial_length (abfd, buf, bytes_read);
7680 gdb_assert (cu_header->initial_length_size == 4
7681 || cu_header->initial_length_size == 8
7682 || cu_header->initial_length_size == 12);
7684 if (cu_header->initial_length_size != *bytes_read)
7685 complaint (&symfile_complaints,
7686 _("intermixed 32-bit and 64-bit DWARF sections"));
7688 *offset_size = (*bytes_read == 4) ? 4 : 8;
7692 /* Read an offset from the data stream. The size of the offset is
7693 given by cu_header->offset_size. */
7696 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
7697 unsigned int *bytes_read)
7699 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
7701 *bytes_read = cu_header->offset_size;
7705 /* Read an offset from the data stream. */
7708 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
7712 switch (offset_size)
7715 retval = bfd_get_32 (abfd, buf);
7718 retval = bfd_get_64 (abfd, buf);
7721 internal_error (__FILE__, __LINE__,
7722 _("read_offset_1: bad switch [in module %s]"),
7723 bfd_get_filename (abfd));
7730 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
7732 /* If the size of a host char is 8 bits, we can return a pointer
7733 to the buffer, otherwise we have to copy the data to a buffer
7734 allocated on the temporary obstack. */
7735 gdb_assert (HOST_CHAR_BIT == 8);
7740 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7742 /* If the size of a host char is 8 bits, we can return a pointer
7743 to the string, otherwise we have to copy the string to a buffer
7744 allocated on the temporary obstack. */
7745 gdb_assert (HOST_CHAR_BIT == 8);
7748 *bytes_read_ptr = 1;
7751 *bytes_read_ptr = strlen ((char *) buf) + 1;
7752 return (char *) buf;
7756 read_indirect_string (bfd *abfd, gdb_byte *buf,
7757 const struct comp_unit_head *cu_header,
7758 unsigned int *bytes_read_ptr)
7760 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
7762 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
7763 if (dwarf2_per_objfile->str.buffer == NULL)
7765 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7766 bfd_get_filename (abfd));
7769 if (str_offset >= dwarf2_per_objfile->str.size)
7771 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7772 bfd_get_filename (abfd));
7775 gdb_assert (HOST_CHAR_BIT == 8);
7776 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
7778 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
7781 static unsigned long
7782 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7784 unsigned long result;
7785 unsigned int num_read;
7795 byte = bfd_get_8 (abfd, buf);
7798 result |= ((unsigned long)(byte & 127) << shift);
7799 if ((byte & 128) == 0)
7805 *bytes_read_ptr = num_read;
7810 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7813 int i, shift, num_read;
7822 byte = bfd_get_8 (abfd, buf);
7825 result |= ((long)(byte & 127) << shift);
7827 if ((byte & 128) == 0)
7832 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
7833 result |= -(((long)1) << shift);
7834 *bytes_read_ptr = num_read;
7838 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7841 skip_leb128 (bfd *abfd, gdb_byte *buf)
7847 byte = bfd_get_8 (abfd, buf);
7849 if ((byte & 128) == 0)
7855 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
7862 cu->language = language_c;
7864 case DW_LANG_C_plus_plus:
7865 cu->language = language_cplus;
7868 cu->language = language_d;
7870 case DW_LANG_Fortran77:
7871 case DW_LANG_Fortran90:
7872 case DW_LANG_Fortran95:
7873 cu->language = language_fortran;
7875 case DW_LANG_Mips_Assembler:
7876 cu->language = language_asm;
7879 cu->language = language_java;
7883 cu->language = language_ada;
7885 case DW_LANG_Modula2:
7886 cu->language = language_m2;
7888 case DW_LANG_Pascal83:
7889 cu->language = language_pascal;
7892 cu->language = language_objc;
7894 case DW_LANG_Cobol74:
7895 case DW_LANG_Cobol85:
7897 cu->language = language_minimal;
7900 cu->language_defn = language_def (cu->language);
7903 /* Return the named attribute or NULL if not there. */
7905 static struct attribute *
7906 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
7909 struct attribute *spec = NULL;
7911 for (i = 0; i < die->num_attrs; ++i)
7913 if (die->attrs[i].name == name)
7914 return &die->attrs[i];
7915 if (die->attrs[i].name == DW_AT_specification
7916 || die->attrs[i].name == DW_AT_abstract_origin)
7917 spec = &die->attrs[i];
7922 die = follow_die_ref (die, spec, &cu);
7923 return dwarf2_attr (die, name, cu);
7929 /* Return the named attribute or NULL if not there,
7930 but do not follow DW_AT_specification, etc.
7931 This is for use in contexts where we're reading .debug_types dies.
7932 Following DW_AT_specification, DW_AT_abstract_origin will take us
7933 back up the chain, and we want to go down. */
7935 static struct attribute *
7936 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
7937 struct dwarf2_cu *cu)
7941 for (i = 0; i < die->num_attrs; ++i)
7942 if (die->attrs[i].name == name)
7943 return &die->attrs[i];
7948 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7949 and holds a non-zero value. This function should only be used for
7950 DW_FORM_flag or DW_FORM_flag_present attributes. */
7953 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
7955 struct attribute *attr = dwarf2_attr (die, name, cu);
7957 return (attr && DW_UNSND (attr));
7961 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
7963 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7964 which value is non-zero. However, we have to be careful with
7965 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7966 (via dwarf2_flag_true_p) follows this attribute. So we may
7967 end up accidently finding a declaration attribute that belongs
7968 to a different DIE referenced by the specification attribute,
7969 even though the given DIE does not have a declaration attribute. */
7970 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
7971 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
7974 /* Return the die giving the specification for DIE, if there is
7975 one. *SPEC_CU is the CU containing DIE on input, and the CU
7976 containing the return value on output. If there is no
7977 specification, but there is an abstract origin, that is
7980 static struct die_info *
7981 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
7983 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
7986 if (spec_attr == NULL)
7987 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
7989 if (spec_attr == NULL)
7992 return follow_die_ref (die, spec_attr, spec_cu);
7995 /* Free the line_header structure *LH, and any arrays and strings it
7998 free_line_header (struct line_header *lh)
8000 if (lh->standard_opcode_lengths)
8001 xfree (lh->standard_opcode_lengths);
8003 /* Remember that all the lh->file_names[i].name pointers are
8004 pointers into debug_line_buffer, and don't need to be freed. */
8006 xfree (lh->file_names);
8008 /* Similarly for the include directory names. */
8009 if (lh->include_dirs)
8010 xfree (lh->include_dirs);
8016 /* Add an entry to LH's include directory table. */
8018 add_include_dir (struct line_header *lh, char *include_dir)
8020 /* Grow the array if necessary. */
8021 if (lh->include_dirs_size == 0)
8023 lh->include_dirs_size = 1; /* for testing */
8024 lh->include_dirs = xmalloc (lh->include_dirs_size
8025 * sizeof (*lh->include_dirs));
8027 else if (lh->num_include_dirs >= lh->include_dirs_size)
8029 lh->include_dirs_size *= 2;
8030 lh->include_dirs = xrealloc (lh->include_dirs,
8031 (lh->include_dirs_size
8032 * sizeof (*lh->include_dirs)));
8035 lh->include_dirs[lh->num_include_dirs++] = include_dir;
8039 /* Add an entry to LH's file name table. */
8041 add_file_name (struct line_header *lh,
8043 unsigned int dir_index,
8044 unsigned int mod_time,
8045 unsigned int length)
8047 struct file_entry *fe;
8049 /* Grow the array if necessary. */
8050 if (lh->file_names_size == 0)
8052 lh->file_names_size = 1; /* for testing */
8053 lh->file_names = xmalloc (lh->file_names_size
8054 * sizeof (*lh->file_names));
8056 else if (lh->num_file_names >= lh->file_names_size)
8058 lh->file_names_size *= 2;
8059 lh->file_names = xrealloc (lh->file_names,
8060 (lh->file_names_size
8061 * sizeof (*lh->file_names)));
8064 fe = &lh->file_names[lh->num_file_names++];
8066 fe->dir_index = dir_index;
8067 fe->mod_time = mod_time;
8068 fe->length = length;
8074 /* Read the statement program header starting at OFFSET in
8075 .debug_line, according to the endianness of ABFD. Return a pointer
8076 to a struct line_header, allocated using xmalloc.
8078 NOTE: the strings in the include directory and file name tables of
8079 the returned object point into debug_line_buffer, and must not be
8081 static struct line_header *
8082 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
8083 struct dwarf2_cu *cu)
8085 struct cleanup *back_to;
8086 struct line_header *lh;
8088 unsigned int bytes_read, offset_size;
8090 char *cur_dir, *cur_file;
8092 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
8093 if (dwarf2_per_objfile->line.buffer == NULL)
8095 complaint (&symfile_complaints, _("missing .debug_line section"));
8099 /* Make sure that at least there's room for the total_length field.
8100 That could be 12 bytes long, but we're just going to fudge that. */
8101 if (offset + 4 >= dwarf2_per_objfile->line.size)
8103 dwarf2_statement_list_fits_in_line_number_section_complaint ();
8107 lh = xmalloc (sizeof (*lh));
8108 memset (lh, 0, sizeof (*lh));
8109 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
8112 line_ptr = dwarf2_per_objfile->line.buffer + offset;
8114 /* Read in the header. */
8116 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
8117 &bytes_read, &offset_size);
8118 line_ptr += bytes_read;
8119 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
8120 + dwarf2_per_objfile->line.size))
8122 dwarf2_statement_list_fits_in_line_number_section_complaint ();
8125 lh->statement_program_end = line_ptr + lh->total_length;
8126 lh->version = read_2_bytes (abfd, line_ptr);
8128 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
8129 line_ptr += offset_size;
8130 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
8132 if (lh->version >= 4)
8134 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
8138 lh->maximum_ops_per_instruction = 1;
8140 if (lh->maximum_ops_per_instruction == 0)
8142 lh->maximum_ops_per_instruction = 1;
8143 complaint (&symfile_complaints,
8144 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
8147 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
8149 lh->line_base = read_1_signed_byte (abfd, line_ptr);
8151 lh->line_range = read_1_byte (abfd, line_ptr);
8153 lh->opcode_base = read_1_byte (abfd, line_ptr);
8155 lh->standard_opcode_lengths
8156 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
8158 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
8159 for (i = 1; i < lh->opcode_base; ++i)
8161 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
8165 /* Read directory table. */
8166 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
8168 line_ptr += bytes_read;
8169 add_include_dir (lh, cur_dir);
8171 line_ptr += bytes_read;
8173 /* Read file name table. */
8174 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
8176 unsigned int dir_index, mod_time, length;
8178 line_ptr += bytes_read;
8179 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8180 line_ptr += bytes_read;
8181 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8182 line_ptr += bytes_read;
8183 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8184 line_ptr += bytes_read;
8186 add_file_name (lh, cur_file, dir_index, mod_time, length);
8188 line_ptr += bytes_read;
8189 lh->statement_program_start = line_ptr;
8191 if (line_ptr > (dwarf2_per_objfile->line.buffer
8192 + dwarf2_per_objfile->line.size))
8193 complaint (&symfile_complaints,
8194 _("line number info header doesn't fit in `.debug_line' section"));
8196 discard_cleanups (back_to);
8200 /* This function exists to work around a bug in certain compilers
8201 (particularly GCC 2.95), in which the first line number marker of a
8202 function does not show up until after the prologue, right before
8203 the second line number marker. This function shifts ADDRESS down
8204 to the beginning of the function if necessary, and is called on
8205 addresses passed to record_line. */
8208 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
8210 struct function_range *fn;
8212 /* Find the function_range containing address. */
8217 cu->cached_fn = cu->first_fn;
8221 if (fn->lowpc <= address && fn->highpc > address)
8227 while (fn && fn != cu->cached_fn)
8228 if (fn->lowpc <= address && fn->highpc > address)
8238 if (address != fn->lowpc)
8239 complaint (&symfile_complaints,
8240 _("misplaced first line number at 0x%lx for '%s'"),
8241 (unsigned long) address, fn->name);
8246 /* Decode the Line Number Program (LNP) for the given line_header
8247 structure and CU. The actual information extracted and the type
8248 of structures created from the LNP depends on the value of PST.
8250 1. If PST is NULL, then this procedure uses the data from the program
8251 to create all necessary symbol tables, and their linetables.
8252 The compilation directory of the file is passed in COMP_DIR,
8253 and must not be NULL.
8255 2. If PST is not NULL, this procedure reads the program to determine
8256 the list of files included by the unit represented by PST, and
8257 builds all the associated partial symbol tables. In this case,
8258 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
8259 is not used to compute the full name of the symtab, and therefore
8260 omitting it when building the partial symtab does not introduce
8261 the potential for inconsistency - a partial symtab and its associated
8262 symbtab having a different fullname -). */
8265 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
8266 struct dwarf2_cu *cu, struct partial_symtab *pst)
8268 gdb_byte *line_ptr, *extended_end;
8270 unsigned int bytes_read, extended_len;
8271 unsigned char op_code, extended_op, adj_opcode;
8273 struct objfile *objfile = cu->objfile;
8274 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8275 const int decode_for_pst_p = (pst != NULL);
8276 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
8278 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8280 line_ptr = lh->statement_program_start;
8281 line_end = lh->statement_program_end;
8283 /* Read the statement sequences until there's nothing left. */
8284 while (line_ptr < line_end)
8286 /* state machine registers */
8287 CORE_ADDR address = 0;
8288 unsigned int file = 1;
8289 unsigned int line = 1;
8290 unsigned int column = 0;
8291 int is_stmt = lh->default_is_stmt;
8292 int basic_block = 0;
8293 int end_sequence = 0;
8295 unsigned char op_index = 0;
8297 if (!decode_for_pst_p && lh->num_file_names >= file)
8299 /* Start a subfile for the current file of the state machine. */
8300 /* lh->include_dirs and lh->file_names are 0-based, but the
8301 directory and file name numbers in the statement program
8303 struct file_entry *fe = &lh->file_names[file - 1];
8307 dir = lh->include_dirs[fe->dir_index - 1];
8309 dwarf2_start_subfile (fe->name, dir, comp_dir);
8312 /* Decode the table. */
8313 while (!end_sequence)
8315 op_code = read_1_byte (abfd, line_ptr);
8317 if (line_ptr > line_end)
8319 dwarf2_debug_line_missing_end_sequence_complaint ();
8323 if (op_code >= lh->opcode_base)
8325 /* Special operand. */
8326 adj_opcode = op_code - lh->opcode_base;
8327 address += (((op_index + (adj_opcode / lh->line_range))
8328 / lh->maximum_ops_per_instruction)
8329 * lh->minimum_instruction_length);
8330 op_index = ((op_index + (adj_opcode / lh->line_range))
8331 % lh->maximum_ops_per_instruction);
8332 line += lh->line_base + (adj_opcode % lh->line_range);
8333 if (lh->num_file_names < file || file == 0)
8334 dwarf2_debug_line_missing_file_complaint ();
8335 /* For now we ignore lines not starting on an
8336 instruction boundary. */
8337 else if (op_index == 0)
8339 lh->file_names[file - 1].included_p = 1;
8340 if (!decode_for_pst_p && is_stmt)
8342 if (last_subfile != current_subfile)
8344 addr = gdbarch_addr_bits_remove (gdbarch, address);
8346 record_line (last_subfile, 0, addr);
8347 last_subfile = current_subfile;
8349 /* Append row to matrix using current values. */
8350 addr = check_cu_functions (address, cu);
8351 addr = gdbarch_addr_bits_remove (gdbarch, addr);
8352 record_line (current_subfile, line, addr);
8357 else switch (op_code)
8359 case DW_LNS_extended_op:
8360 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8361 line_ptr += bytes_read;
8362 extended_end = line_ptr + extended_len;
8363 extended_op = read_1_byte (abfd, line_ptr);
8365 switch (extended_op)
8367 case DW_LNE_end_sequence:
8370 case DW_LNE_set_address:
8371 address = read_address (abfd, line_ptr, cu, &bytes_read);
8373 line_ptr += bytes_read;
8374 address += baseaddr;
8376 case DW_LNE_define_file:
8379 unsigned int dir_index, mod_time, length;
8381 cur_file = read_string (abfd, line_ptr, &bytes_read);
8382 line_ptr += bytes_read;
8384 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8385 line_ptr += bytes_read;
8387 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8388 line_ptr += bytes_read;
8390 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8391 line_ptr += bytes_read;
8392 add_file_name (lh, cur_file, dir_index, mod_time, length);
8395 case DW_LNE_set_discriminator:
8396 /* The discriminator is not interesting to the debugger;
8398 line_ptr = extended_end;
8401 complaint (&symfile_complaints,
8402 _("mangled .debug_line section"));
8405 /* Make sure that we parsed the extended op correctly. If e.g.
8406 we expected a different address size than the producer used,
8407 we may have read the wrong number of bytes. */
8408 if (line_ptr != extended_end)
8410 complaint (&symfile_complaints,
8411 _("mangled .debug_line section"));
8416 if (lh->num_file_names < file || file == 0)
8417 dwarf2_debug_line_missing_file_complaint ();
8420 lh->file_names[file - 1].included_p = 1;
8421 if (!decode_for_pst_p && is_stmt)
8423 if (last_subfile != current_subfile)
8425 addr = gdbarch_addr_bits_remove (gdbarch, address);
8427 record_line (last_subfile, 0, addr);
8428 last_subfile = current_subfile;
8430 addr = check_cu_functions (address, cu);
8431 addr = gdbarch_addr_bits_remove (gdbarch, addr);
8432 record_line (current_subfile, line, addr);
8437 case DW_LNS_advance_pc:
8440 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8442 address += (((op_index + adjust)
8443 / lh->maximum_ops_per_instruction)
8444 * lh->minimum_instruction_length);
8445 op_index = ((op_index + adjust)
8446 % lh->maximum_ops_per_instruction);
8447 line_ptr += bytes_read;
8450 case DW_LNS_advance_line:
8451 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
8452 line_ptr += bytes_read;
8454 case DW_LNS_set_file:
8456 /* The arrays lh->include_dirs and lh->file_names are
8457 0-based, but the directory and file name numbers in
8458 the statement program are 1-based. */
8459 struct file_entry *fe;
8462 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8463 line_ptr += bytes_read;
8464 if (lh->num_file_names < file || file == 0)
8465 dwarf2_debug_line_missing_file_complaint ();
8468 fe = &lh->file_names[file - 1];
8470 dir = lh->include_dirs[fe->dir_index - 1];
8471 if (!decode_for_pst_p)
8473 last_subfile = current_subfile;
8474 dwarf2_start_subfile (fe->name, dir, comp_dir);
8479 case DW_LNS_set_column:
8480 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8481 line_ptr += bytes_read;
8483 case DW_LNS_negate_stmt:
8484 is_stmt = (!is_stmt);
8486 case DW_LNS_set_basic_block:
8489 /* Add to the address register of the state machine the
8490 address increment value corresponding to special opcode
8491 255. I.e., this value is scaled by the minimum
8492 instruction length since special opcode 255 would have
8493 scaled the the increment. */
8494 case DW_LNS_const_add_pc:
8496 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
8498 address += (((op_index + adjust)
8499 / lh->maximum_ops_per_instruction)
8500 * lh->minimum_instruction_length);
8501 op_index = ((op_index + adjust)
8502 % lh->maximum_ops_per_instruction);
8505 case DW_LNS_fixed_advance_pc:
8506 address += read_2_bytes (abfd, line_ptr);
8512 /* Unknown standard opcode, ignore it. */
8515 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
8517 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8518 line_ptr += bytes_read;
8523 if (lh->num_file_names < file || file == 0)
8524 dwarf2_debug_line_missing_file_complaint ();
8527 lh->file_names[file - 1].included_p = 1;
8528 if (!decode_for_pst_p)
8530 addr = gdbarch_addr_bits_remove (gdbarch, address);
8531 record_line (current_subfile, 0, addr);
8536 if (decode_for_pst_p)
8540 /* Now that we're done scanning the Line Header Program, we can
8541 create the psymtab of each included file. */
8542 for (file_index = 0; file_index < lh->num_file_names; file_index++)
8543 if (lh->file_names[file_index].included_p == 1)
8545 const struct file_entry fe = lh->file_names [file_index];
8546 char *include_name = fe.name;
8547 char *dir_name = NULL;
8548 char *pst_filename = pst->filename;
8551 dir_name = lh->include_dirs[fe.dir_index - 1];
8553 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
8555 include_name = concat (dir_name, SLASH_STRING,
8556 include_name, (char *)NULL);
8557 make_cleanup (xfree, include_name);
8560 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
8562 pst_filename = concat (pst->dirname, SLASH_STRING,
8563 pst_filename, (char *)NULL);
8564 make_cleanup (xfree, pst_filename);
8567 if (strcmp (include_name, pst_filename) != 0)
8568 dwarf2_create_include_psymtab (include_name, pst, objfile);
8573 /* Make sure a symtab is created for every file, even files
8574 which contain only variables (i.e. no code with associated
8578 struct file_entry *fe;
8580 for (i = 0; i < lh->num_file_names; i++)
8584 fe = &lh->file_names[i];
8586 dir = lh->include_dirs[fe->dir_index - 1];
8587 dwarf2_start_subfile (fe->name, dir, comp_dir);
8589 /* Skip the main file; we don't need it, and it must be
8590 allocated last, so that it will show up before the
8591 non-primary symtabs in the objfile's symtab list. */
8592 if (current_subfile == first_subfile)
8595 if (current_subfile->symtab == NULL)
8596 current_subfile->symtab = allocate_symtab (current_subfile->name,
8598 fe->symtab = current_subfile->symtab;
8603 /* Start a subfile for DWARF. FILENAME is the name of the file and
8604 DIRNAME the name of the source directory which contains FILENAME
8605 or NULL if not known. COMP_DIR is the compilation directory for the
8606 linetable's compilation unit or NULL if not known.
8607 This routine tries to keep line numbers from identical absolute and
8608 relative file names in a common subfile.
8610 Using the `list' example from the GDB testsuite, which resides in
8611 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8612 of /srcdir/list0.c yields the following debugging information for list0.c:
8614 DW_AT_name: /srcdir/list0.c
8615 DW_AT_comp_dir: /compdir
8616 files.files[0].name: list0.h
8617 files.files[0].dir: /srcdir
8618 files.files[1].name: list0.c
8619 files.files[1].dir: /srcdir
8621 The line number information for list0.c has to end up in a single
8622 subfile, so that `break /srcdir/list0.c:1' works as expected.
8623 start_subfile will ensure that this happens provided that we pass the
8624 concatenation of files.files[1].dir and files.files[1].name as the
8628 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
8632 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8633 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8634 second argument to start_subfile. To be consistent, we do the
8635 same here. In order not to lose the line information directory,
8636 we concatenate it to the filename when it makes sense.
8637 Note that the Dwarf3 standard says (speaking of filenames in line
8638 information): ``The directory index is ignored for file names
8639 that represent full path names''. Thus ignoring dirname in the
8640 `else' branch below isn't an issue. */
8642 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
8643 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
8645 fullname = filename;
8647 start_subfile (fullname, comp_dir);
8649 if (fullname != filename)
8654 var_decode_location (struct attribute *attr, struct symbol *sym,
8655 struct dwarf2_cu *cu)
8657 struct objfile *objfile = cu->objfile;
8658 struct comp_unit_head *cu_header = &cu->header;
8660 /* NOTE drow/2003-01-30: There used to be a comment and some special
8661 code here to turn a symbol with DW_AT_external and a
8662 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8663 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8664 with some versions of binutils) where shared libraries could have
8665 relocations against symbols in their debug information - the
8666 minimal symbol would have the right address, but the debug info
8667 would not. It's no longer necessary, because we will explicitly
8668 apply relocations when we read in the debug information now. */
8670 /* A DW_AT_location attribute with no contents indicates that a
8671 variable has been optimized away. */
8672 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
8674 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8678 /* Handle one degenerate form of location expression specially, to
8679 preserve GDB's previous behavior when section offsets are
8680 specified. If this is just a DW_OP_addr then mark this symbol
8683 if (attr_form_is_block (attr)
8684 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
8685 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
8689 SYMBOL_VALUE_ADDRESS (sym) =
8690 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
8691 SYMBOL_CLASS (sym) = LOC_STATIC;
8692 fixup_symbol_section (sym, objfile);
8693 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
8694 SYMBOL_SECTION (sym));
8698 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8699 expression evaluator, and use LOC_COMPUTED only when necessary
8700 (i.e. when the value of a register or memory location is
8701 referenced, or a thread-local block, etc.). Then again, it might
8702 not be worthwhile. I'm assuming that it isn't unless performance
8703 or memory numbers show me otherwise. */
8705 dwarf2_symbol_mark_computed (attr, sym, cu);
8706 SYMBOL_CLASS (sym) = LOC_COMPUTED;
8709 /* Given a pointer to a DWARF information entry, figure out if we need
8710 to make a symbol table entry for it, and if so, create a new entry
8711 and return a pointer to it.
8712 If TYPE is NULL, determine symbol type from the die, otherwise
8713 used the passed type. */
8715 static struct symbol *
8716 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
8718 struct objfile *objfile = cu->objfile;
8719 struct symbol *sym = NULL;
8721 struct attribute *attr = NULL;
8722 struct attribute *attr2 = NULL;
8724 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
8726 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8728 name = dwarf2_name (die, cu);
8731 const char *linkagename;
8733 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
8734 sizeof (struct symbol));
8735 OBJSTAT (objfile, n_syms++);
8736 memset (sym, 0, sizeof (struct symbol));
8738 /* Cache this symbol's name and the name's demangled form (if any). */
8739 SYMBOL_LANGUAGE (sym) = cu->language;
8740 linkagename = dwarf2_physname (name, die, cu);
8741 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
8743 /* Fortran does not have mangling standard and the mangling does differ
8744 between gfortran, iFort etc. */
8745 if (cu->language == language_fortran
8746 && sym->ginfo.language_specific.cplus_specific.demangled_name == NULL)
8747 sym->ginfo.language_specific.cplus_specific.demangled_name
8748 = (char *) dwarf2_full_name (name, die, cu);
8750 /* Default assumptions.
8751 Use the passed type or decode it from the die. */
8752 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8753 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8755 SYMBOL_TYPE (sym) = type;
8757 SYMBOL_TYPE (sym) = die_type (die, cu);
8758 attr = dwarf2_attr (die,
8759 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
8763 SYMBOL_LINE (sym) = DW_UNSND (attr);
8766 attr = dwarf2_attr (die,
8767 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
8771 int file_index = DW_UNSND (attr);
8773 if (cu->line_header == NULL
8774 || file_index > cu->line_header->num_file_names)
8775 complaint (&symfile_complaints,
8776 _("file index out of range"));
8777 else if (file_index > 0)
8779 struct file_entry *fe;
8781 fe = &cu->line_header->file_names[file_index - 1];
8782 SYMBOL_SYMTAB (sym) = fe->symtab;
8789 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
8792 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
8794 SYMBOL_CLASS (sym) = LOC_LABEL;
8796 case DW_TAG_subprogram:
8797 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8799 SYMBOL_CLASS (sym) = LOC_BLOCK;
8800 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8801 if ((attr2 && (DW_UNSND (attr2) != 0))
8802 || cu->language == language_ada)
8804 /* Subprograms marked external are stored as a global symbol.
8805 Ada subprograms, whether marked external or not, are always
8806 stored as a global symbol, because we want to be able to
8807 access them globally. For instance, we want to be able
8808 to break on a nested subprogram without having to
8809 specify the context. */
8810 add_symbol_to_list (sym, &global_symbols);
8814 add_symbol_to_list (sym, cu->list_in_scope);
8817 case DW_TAG_inlined_subroutine:
8818 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8820 SYMBOL_CLASS (sym) = LOC_BLOCK;
8821 SYMBOL_INLINED (sym) = 1;
8822 /* Do not add the symbol to any lists. It will be found via
8823 BLOCK_FUNCTION from the blockvector. */
8825 case DW_TAG_variable:
8826 /* Compilation with minimal debug info may result in variables
8827 with missing type entries. Change the misleading `void' type
8828 to something sensible. */
8829 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
8831 = objfile_type (objfile)->nodebug_data_symbol;
8833 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8836 dwarf2_const_value (attr, sym, cu);
8837 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8838 if (attr2 && (DW_UNSND (attr2) != 0))
8839 add_symbol_to_list (sym, &global_symbols);
8841 add_symbol_to_list (sym, cu->list_in_scope);
8844 attr = dwarf2_attr (die, DW_AT_location, cu);
8847 var_decode_location (attr, sym, cu);
8848 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8849 if (attr2 && (DW_UNSND (attr2) != 0))
8851 struct pending **list_to_add;
8853 /* Workaround gfortran PR debug/40040 - it uses
8854 DW_AT_location for variables in -fPIC libraries which may
8855 get overriden by other libraries/executable and get
8856 a different address. Resolve it by the minimal symbol
8857 which may come from inferior's executable using copy
8858 relocation. Make this workaround only for gfortran as for
8859 other compilers GDB cannot guess the minimal symbol
8860 Fortran mangling kind. */
8861 if (cu->language == language_fortran && die->parent
8862 && die->parent->tag == DW_TAG_module
8864 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
8865 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
8867 /* A variable with DW_AT_external is never static,
8868 but it may be block-scoped. */
8869 list_to_add = (cu->list_in_scope == &file_symbols
8870 ? &global_symbols : cu->list_in_scope);
8871 add_symbol_to_list (sym, list_to_add);
8874 add_symbol_to_list (sym, cu->list_in_scope);
8878 /* We do not know the address of this symbol.
8879 If it is an external symbol and we have type information
8880 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8881 The address of the variable will then be determined from
8882 the minimal symbol table whenever the variable is
8884 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8885 if (attr2 && (DW_UNSND (attr2) != 0)
8886 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
8888 struct pending **list_to_add;
8890 /* A variable with DW_AT_external is never static, but it
8891 may be block-scoped. */
8892 list_to_add = (cu->list_in_scope == &file_symbols
8893 ? &global_symbols : cu->list_in_scope);
8895 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
8896 add_symbol_to_list (sym, list_to_add);
8898 else if (!die_is_declaration (die, cu))
8900 /* Use the default LOC_OPTIMIZED_OUT class. */
8901 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
8902 add_symbol_to_list (sym, cu->list_in_scope);
8906 case DW_TAG_formal_parameter:
8907 /* If we are inside a function, mark this as an argument. If
8908 not, we might be looking at an argument to an inlined function
8909 when we do not have enough information to show inlined frames;
8910 pretend it's a local variable in that case so that the user can
8912 if (context_stack_depth > 0
8913 && context_stack[context_stack_depth - 1].name != NULL)
8914 SYMBOL_IS_ARGUMENT (sym) = 1;
8915 attr = dwarf2_attr (die, DW_AT_location, cu);
8918 var_decode_location (attr, sym, cu);
8920 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8923 dwarf2_const_value (attr, sym, cu);
8925 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
8926 if (attr && DW_UNSND (attr))
8928 struct type *ref_type;
8930 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
8931 SYMBOL_TYPE (sym) = ref_type;
8934 add_symbol_to_list (sym, cu->list_in_scope);
8936 case DW_TAG_unspecified_parameters:
8937 /* From varargs functions; gdb doesn't seem to have any
8938 interest in this information, so just ignore it for now.
8941 case DW_TAG_class_type:
8942 case DW_TAG_interface_type:
8943 case DW_TAG_structure_type:
8944 case DW_TAG_union_type:
8945 case DW_TAG_set_type:
8946 case DW_TAG_enumeration_type:
8947 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8948 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
8951 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8952 really ever be static objects: otherwise, if you try
8953 to, say, break of a class's method and you're in a file
8954 which doesn't mention that class, it won't work unless
8955 the check for all static symbols in lookup_symbol_aux
8956 saves you. See the OtherFileClass tests in
8957 gdb.c++/namespace.exp. */
8959 struct pending **list_to_add;
8961 list_to_add = (cu->list_in_scope == &file_symbols
8962 && (cu->language == language_cplus
8963 || cu->language == language_java)
8964 ? &global_symbols : cu->list_in_scope);
8966 add_symbol_to_list (sym, list_to_add);
8968 /* The semantics of C++ state that "struct foo { ... }" also
8969 defines a typedef for "foo". A Java class declaration also
8970 defines a typedef for the class. */
8971 if (cu->language == language_cplus
8972 || cu->language == language_java
8973 || cu->language == language_ada)
8975 /* The symbol's name is already allocated along with
8976 this objfile, so we don't need to duplicate it for
8978 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
8979 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
8983 case DW_TAG_typedef:
8984 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8985 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8986 add_symbol_to_list (sym, cu->list_in_scope);
8988 case DW_TAG_base_type:
8989 case DW_TAG_subrange_type:
8990 case DW_TAG_const_type:
8991 case DW_TAG_volatile_type:
8992 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8993 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8994 add_symbol_to_list (sym, cu->list_in_scope);
8996 case DW_TAG_enumerator:
8997 attr = dwarf2_attr (die, DW_AT_const_value, cu);
9000 dwarf2_const_value (attr, sym, cu);
9003 /* NOTE: carlton/2003-11-10: See comment above in the
9004 DW_TAG_class_type, etc. block. */
9006 struct pending **list_to_add;
9008 list_to_add = (cu->list_in_scope == &file_symbols
9009 && (cu->language == language_cplus
9010 || cu->language == language_java)
9011 ? &global_symbols : cu->list_in_scope);
9013 add_symbol_to_list (sym, list_to_add);
9016 case DW_TAG_namespace:
9017 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
9018 add_symbol_to_list (sym, &global_symbols);
9021 /* Not a tag we recognize. Hopefully we aren't processing
9022 trash data, but since we must specifically ignore things
9023 we don't recognize, there is nothing else we should do at
9025 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
9026 dwarf_tag_name (die->tag));
9030 /* For the benefit of old versions of GCC, check for anonymous
9031 namespaces based on the demangled name. */
9032 if (!processing_has_namespace_info
9033 && cu->language == language_cplus)
9034 cp_scan_for_anonymous_namespaces (sym);
9039 /* Copy constant value from an attribute to a symbol. */
9042 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
9043 struct dwarf2_cu *cu)
9045 struct objfile *objfile = cu->objfile;
9046 struct comp_unit_head *cu_header = &cu->header;
9047 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
9048 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
9049 struct dwarf_block *blk;
9054 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
9055 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
9056 cu_header->addr_size,
9057 TYPE_LENGTH (SYMBOL_TYPE
9059 SYMBOL_VALUE_BYTES (sym) =
9060 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
9061 /* NOTE: cagney/2003-05-09: In-lined store_address call with
9062 it's body - store_unsigned_integer. */
9063 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
9064 byte_order, DW_ADDR (attr));
9065 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
9067 case DW_FORM_string:
9069 /* DW_STRING is already allocated on the obstack, point directly
9071 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
9072 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
9074 case DW_FORM_block1:
9075 case DW_FORM_block2:
9076 case DW_FORM_block4:
9078 case DW_FORM_exprloc:
9079 blk = DW_BLOCK (attr);
9080 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
9081 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
9083 TYPE_LENGTH (SYMBOL_TYPE
9085 SYMBOL_VALUE_BYTES (sym) =
9086 obstack_alloc (&objfile->objfile_obstack, blk->size);
9087 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
9088 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
9091 /* The DW_AT_const_value attributes are supposed to carry the
9092 symbol's value "represented as it would be on the target
9093 architecture." By the time we get here, it's already been
9094 converted to host endianness, so we just need to sign- or
9095 zero-extend it as appropriate. */
9097 dwarf2_const_value_data (attr, sym, 8);
9100 dwarf2_const_value_data (attr, sym, 16);
9103 dwarf2_const_value_data (attr, sym, 32);
9106 dwarf2_const_value_data (attr, sym, 64);
9110 SYMBOL_VALUE (sym) = DW_SND (attr);
9111 SYMBOL_CLASS (sym) = LOC_CONST;
9115 SYMBOL_VALUE (sym) = DW_UNSND (attr);
9116 SYMBOL_CLASS (sym) = LOC_CONST;
9120 complaint (&symfile_complaints,
9121 _("unsupported const value attribute form: '%s'"),
9122 dwarf_form_name (attr->form));
9123 SYMBOL_VALUE (sym) = 0;
9124 SYMBOL_CLASS (sym) = LOC_CONST;
9130 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
9131 or zero-extend it as appropriate for the symbol's type. */
9133 dwarf2_const_value_data (struct attribute *attr,
9137 LONGEST l = DW_UNSND (attr);
9139 if (bits < sizeof (l) * 8)
9141 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
9142 l &= ((LONGEST) 1 << bits) - 1;
9144 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
9147 SYMBOL_VALUE (sym) = l;
9148 SYMBOL_CLASS (sym) = LOC_CONST;
9152 /* Return the type of the die in question using its DW_AT_type attribute. */
9154 static struct type *
9155 die_type (struct die_info *die, struct dwarf2_cu *cu)
9157 struct attribute *type_attr;
9158 struct die_info *type_die;
9160 type_attr = dwarf2_attr (die, DW_AT_type, cu);
9163 /* A missing DW_AT_type represents a void type. */
9164 return objfile_type (cu->objfile)->builtin_void;
9167 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
9169 return tag_type_to_type (type_die, cu);
9172 /* True iff CU's producer generates GNAT Ada auxiliary information
9173 that allows to find parallel types through that information instead
9174 of having to do expensive parallel lookups by type name. */
9177 need_gnat_info (struct dwarf2_cu *cu)
9179 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
9180 of GNAT produces this auxiliary information, without any indication
9181 that it is produced. Part of enhancing the FSF version of GNAT
9182 to produce that information will be to put in place an indicator
9183 that we can use in order to determine whether the descriptive type
9184 info is available or not. One suggestion that has been made is
9185 to use a new attribute, attached to the CU die. For now, assume
9186 that the descriptive type info is not available. */
9191 /* Return the auxiliary type of the die in question using its
9192 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
9193 attribute is not present. */
9195 static struct type *
9196 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
9198 struct attribute *type_attr;
9199 struct die_info *type_die;
9201 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
9205 type_die = follow_die_ref (die, type_attr, &cu);
9206 return tag_type_to_type (type_die, cu);
9209 /* If DIE has a descriptive_type attribute, then set the TYPE's
9210 descriptive type accordingly. */
9213 set_descriptive_type (struct type *type, struct die_info *die,
9214 struct dwarf2_cu *cu)
9216 struct type *descriptive_type = die_descriptive_type (die, cu);
9218 if (descriptive_type)
9220 ALLOCATE_GNAT_AUX_TYPE (type);
9221 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
9225 /* Return the containing type of the die in question using its
9226 DW_AT_containing_type attribute. */
9228 static struct type *
9229 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
9231 struct attribute *type_attr;
9232 struct die_info *type_die;
9234 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
9236 error (_("Dwarf Error: Problem turning containing type into gdb type "
9237 "[in module %s]"), cu->objfile->name);
9239 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
9240 return tag_type_to_type (type_die, cu);
9243 static struct type *
9244 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
9246 struct type *this_type;
9248 this_type = read_type_die (die, cu);
9251 char *message, *saved;
9253 /* read_type_die already issued a complaint. */
9254 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
9258 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
9259 message, strlen (message));
9262 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
9267 static struct type *
9268 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
9270 struct type *this_type;
9272 this_type = get_die_type (die, cu);
9278 case DW_TAG_class_type:
9279 case DW_TAG_interface_type:
9280 case DW_TAG_structure_type:
9281 case DW_TAG_union_type:
9282 this_type = read_structure_type (die, cu);
9284 case DW_TAG_enumeration_type:
9285 this_type = read_enumeration_type (die, cu);
9287 case DW_TAG_subprogram:
9288 case DW_TAG_subroutine_type:
9289 case DW_TAG_inlined_subroutine:
9290 this_type = read_subroutine_type (die, cu);
9292 case DW_TAG_array_type:
9293 this_type = read_array_type (die, cu);
9295 case DW_TAG_set_type:
9296 this_type = read_set_type (die, cu);
9298 case DW_TAG_pointer_type:
9299 this_type = read_tag_pointer_type (die, cu);
9301 case DW_TAG_ptr_to_member_type:
9302 this_type = read_tag_ptr_to_member_type (die, cu);
9304 case DW_TAG_reference_type:
9305 this_type = read_tag_reference_type (die, cu);
9307 case DW_TAG_const_type:
9308 this_type = read_tag_const_type (die, cu);
9310 case DW_TAG_volatile_type:
9311 this_type = read_tag_volatile_type (die, cu);
9313 case DW_TAG_string_type:
9314 this_type = read_tag_string_type (die, cu);
9316 case DW_TAG_typedef:
9317 this_type = read_typedef (die, cu);
9319 case DW_TAG_subrange_type:
9320 this_type = read_subrange_type (die, cu);
9322 case DW_TAG_base_type:
9323 this_type = read_base_type (die, cu);
9325 case DW_TAG_unspecified_type:
9326 this_type = read_unspecified_type (die, cu);
9328 case DW_TAG_namespace:
9329 this_type = read_namespace_type (die, cu);
9332 this_type = read_module_type (die, cu);
9335 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
9336 dwarf_tag_name (die->tag));
9343 /* Return the name of the namespace/class that DIE is defined within,
9344 or "" if we can't tell. The caller should not xfree the result.
9346 For example, if we're within the method foo() in the following
9356 then determine_prefix on foo's die will return "N::C". */
9359 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
9361 struct die_info *parent, *spec_die;
9362 struct dwarf2_cu *spec_cu;
9363 struct type *parent_type;
9365 if (cu->language != language_cplus && cu->language != language_java
9366 && cu->language != language_fortran)
9369 /* We have to be careful in the presence of DW_AT_specification.
9370 For example, with GCC 3.4, given the code
9374 // Definition of N::foo.
9378 then we'll have a tree of DIEs like this:
9380 1: DW_TAG_compile_unit
9381 2: DW_TAG_namespace // N
9382 3: DW_TAG_subprogram // declaration of N::foo
9383 4: DW_TAG_subprogram // definition of N::foo
9384 DW_AT_specification // refers to die #3
9386 Thus, when processing die #4, we have to pretend that we're in
9387 the context of its DW_AT_specification, namely the contex of die
9390 spec_die = die_specification (die, &spec_cu);
9391 if (spec_die == NULL)
9392 parent = die->parent;
9395 parent = spec_die->parent;
9402 switch (parent->tag)
9404 case DW_TAG_namespace:
9405 parent_type = read_type_die (parent, cu);
9406 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9407 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9408 Work around this problem here. */
9409 if (cu->language == language_cplus
9410 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
9412 /* We give a name to even anonymous namespaces. */
9413 return TYPE_TAG_NAME (parent_type);
9414 case DW_TAG_class_type:
9415 case DW_TAG_interface_type:
9416 case DW_TAG_structure_type:
9417 case DW_TAG_union_type:
9419 parent_type = read_type_die (parent, cu);
9420 if (TYPE_TAG_NAME (parent_type) != NULL)
9421 return TYPE_TAG_NAME (parent_type);
9423 /* An anonymous structure is only allowed non-static data
9424 members; no typedefs, no member functions, et cetera.
9425 So it does not need a prefix. */
9428 return determine_prefix (parent, cu);
9432 /* Return a newly-allocated string formed by concatenating PREFIX and
9433 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9434 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9435 perform an obconcat, otherwise allocate storage for the result. The CU argument
9436 is used to determine the language and hence, the appropriate separator. */
9438 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
9441 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
9442 int physname, struct dwarf2_cu *cu)
9444 const char *lead = "";
9447 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
9449 else if (cu->language == language_java)
9451 else if (cu->language == language_fortran && physname)
9453 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
9454 DW_AT_MIPS_linkage_name is preferred and used instead. */
9469 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
9471 strcpy (retval, lead);
9472 strcat (retval, prefix);
9473 strcat (retval, sep);
9474 strcat (retval, suffix);
9479 /* We have an obstack. */
9480 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
9484 /* Return sibling of die, NULL if no sibling. */
9486 static struct die_info *
9487 sibling_die (struct die_info *die)
9489 return die->sibling;
9492 /* Get name of a die, return NULL if not found. */
9495 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
9496 struct obstack *obstack)
9498 if (name && cu->language == language_cplus)
9500 char *canon_name = cp_canonicalize_string (name);
9502 if (canon_name != NULL)
9504 if (strcmp (canon_name, name) != 0)
9505 name = obsavestring (canon_name, strlen (canon_name),
9514 /* Get name of a die, return NULL if not found. */
9517 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
9519 struct attribute *attr;
9521 attr = dwarf2_attr (die, DW_AT_name, cu);
9522 if (!attr || !DW_STRING (attr))
9527 case DW_TAG_compile_unit:
9528 /* Compilation units have a DW_AT_name that is a filename, not
9529 a source language identifier. */
9530 case DW_TAG_enumeration_type:
9531 case DW_TAG_enumerator:
9532 /* These tags always have simple identifiers already; no need
9533 to canonicalize them. */
9534 return DW_STRING (attr);
9536 case DW_TAG_subprogram:
9537 /* Java constructors will all be named "<init>", so return
9538 the class name when we see this special case. */
9539 if (cu->language == language_java
9540 && DW_STRING (attr) != NULL
9541 && strcmp (DW_STRING (attr), "<init>") == 0)
9543 struct dwarf2_cu *spec_cu = cu;
9544 struct die_info *spec_die;
9546 /* GCJ will output '<init>' for Java constructor names.
9547 For this special case, return the name of the parent class. */
9549 /* GCJ may output suprogram DIEs with AT_specification set.
9550 If so, use the name of the specified DIE. */
9551 spec_die = die_specification (die, &spec_cu);
9552 if (spec_die != NULL)
9553 return dwarf2_name (spec_die, spec_cu);
9558 if (die->tag == DW_TAG_class_type)
9559 return dwarf2_name (die, cu);
9561 while (die->tag != DW_TAG_compile_unit);
9565 case DW_TAG_class_type:
9566 case DW_TAG_interface_type:
9567 case DW_TAG_structure_type:
9568 case DW_TAG_union_type:
9569 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9570 structures or unions. These were of the form "._%d" in GCC 4.1,
9571 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9572 and GCC 4.4. We work around this problem by ignoring these. */
9573 if (strncmp (DW_STRING (attr), "._", 2) == 0
9574 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
9582 if (!DW_STRING_IS_CANONICAL (attr))
9585 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
9586 &cu->objfile->objfile_obstack);
9587 DW_STRING_IS_CANONICAL (attr) = 1;
9589 return DW_STRING (attr);
9592 /* Return the die that this die in an extension of, or NULL if there
9593 is none. *EXT_CU is the CU containing DIE on input, and the CU
9594 containing the return value on output. */
9596 static struct die_info *
9597 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
9599 struct attribute *attr;
9601 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
9605 return follow_die_ref (die, attr, ext_cu);
9608 /* Convert a DIE tag into its string name. */
9611 dwarf_tag_name (unsigned tag)
9615 case DW_TAG_padding:
9616 return "DW_TAG_padding";
9617 case DW_TAG_array_type:
9618 return "DW_TAG_array_type";
9619 case DW_TAG_class_type:
9620 return "DW_TAG_class_type";
9621 case DW_TAG_entry_point:
9622 return "DW_TAG_entry_point";
9623 case DW_TAG_enumeration_type:
9624 return "DW_TAG_enumeration_type";
9625 case DW_TAG_formal_parameter:
9626 return "DW_TAG_formal_parameter";
9627 case DW_TAG_imported_declaration:
9628 return "DW_TAG_imported_declaration";
9630 return "DW_TAG_label";
9631 case DW_TAG_lexical_block:
9632 return "DW_TAG_lexical_block";
9634 return "DW_TAG_member";
9635 case DW_TAG_pointer_type:
9636 return "DW_TAG_pointer_type";
9637 case DW_TAG_reference_type:
9638 return "DW_TAG_reference_type";
9639 case DW_TAG_compile_unit:
9640 return "DW_TAG_compile_unit";
9641 case DW_TAG_string_type:
9642 return "DW_TAG_string_type";
9643 case DW_TAG_structure_type:
9644 return "DW_TAG_structure_type";
9645 case DW_TAG_subroutine_type:
9646 return "DW_TAG_subroutine_type";
9647 case DW_TAG_typedef:
9648 return "DW_TAG_typedef";
9649 case DW_TAG_union_type:
9650 return "DW_TAG_union_type";
9651 case DW_TAG_unspecified_parameters:
9652 return "DW_TAG_unspecified_parameters";
9653 case DW_TAG_variant:
9654 return "DW_TAG_variant";
9655 case DW_TAG_common_block:
9656 return "DW_TAG_common_block";
9657 case DW_TAG_common_inclusion:
9658 return "DW_TAG_common_inclusion";
9659 case DW_TAG_inheritance:
9660 return "DW_TAG_inheritance";
9661 case DW_TAG_inlined_subroutine:
9662 return "DW_TAG_inlined_subroutine";
9664 return "DW_TAG_module";
9665 case DW_TAG_ptr_to_member_type:
9666 return "DW_TAG_ptr_to_member_type";
9667 case DW_TAG_set_type:
9668 return "DW_TAG_set_type";
9669 case DW_TAG_subrange_type:
9670 return "DW_TAG_subrange_type";
9671 case DW_TAG_with_stmt:
9672 return "DW_TAG_with_stmt";
9673 case DW_TAG_access_declaration:
9674 return "DW_TAG_access_declaration";
9675 case DW_TAG_base_type:
9676 return "DW_TAG_base_type";
9677 case DW_TAG_catch_block:
9678 return "DW_TAG_catch_block";
9679 case DW_TAG_const_type:
9680 return "DW_TAG_const_type";
9681 case DW_TAG_constant:
9682 return "DW_TAG_constant";
9683 case DW_TAG_enumerator:
9684 return "DW_TAG_enumerator";
9685 case DW_TAG_file_type:
9686 return "DW_TAG_file_type";
9688 return "DW_TAG_friend";
9689 case DW_TAG_namelist:
9690 return "DW_TAG_namelist";
9691 case DW_TAG_namelist_item:
9692 return "DW_TAG_namelist_item";
9693 case DW_TAG_packed_type:
9694 return "DW_TAG_packed_type";
9695 case DW_TAG_subprogram:
9696 return "DW_TAG_subprogram";
9697 case DW_TAG_template_type_param:
9698 return "DW_TAG_template_type_param";
9699 case DW_TAG_template_value_param:
9700 return "DW_TAG_template_value_param";
9701 case DW_TAG_thrown_type:
9702 return "DW_TAG_thrown_type";
9703 case DW_TAG_try_block:
9704 return "DW_TAG_try_block";
9705 case DW_TAG_variant_part:
9706 return "DW_TAG_variant_part";
9707 case DW_TAG_variable:
9708 return "DW_TAG_variable";
9709 case DW_TAG_volatile_type:
9710 return "DW_TAG_volatile_type";
9711 case DW_TAG_dwarf_procedure:
9712 return "DW_TAG_dwarf_procedure";
9713 case DW_TAG_restrict_type:
9714 return "DW_TAG_restrict_type";
9715 case DW_TAG_interface_type:
9716 return "DW_TAG_interface_type";
9717 case DW_TAG_namespace:
9718 return "DW_TAG_namespace";
9719 case DW_TAG_imported_module:
9720 return "DW_TAG_imported_module";
9721 case DW_TAG_unspecified_type:
9722 return "DW_TAG_unspecified_type";
9723 case DW_TAG_partial_unit:
9724 return "DW_TAG_partial_unit";
9725 case DW_TAG_imported_unit:
9726 return "DW_TAG_imported_unit";
9727 case DW_TAG_condition:
9728 return "DW_TAG_condition";
9729 case DW_TAG_shared_type:
9730 return "DW_TAG_shared_type";
9731 case DW_TAG_type_unit:
9732 return "DW_TAG_type_unit";
9733 case DW_TAG_MIPS_loop:
9734 return "DW_TAG_MIPS_loop";
9735 case DW_TAG_HP_array_descriptor:
9736 return "DW_TAG_HP_array_descriptor";
9737 case DW_TAG_format_label:
9738 return "DW_TAG_format_label";
9739 case DW_TAG_function_template:
9740 return "DW_TAG_function_template";
9741 case DW_TAG_class_template:
9742 return "DW_TAG_class_template";
9743 case DW_TAG_GNU_BINCL:
9744 return "DW_TAG_GNU_BINCL";
9745 case DW_TAG_GNU_EINCL:
9746 return "DW_TAG_GNU_EINCL";
9747 case DW_TAG_upc_shared_type:
9748 return "DW_TAG_upc_shared_type";
9749 case DW_TAG_upc_strict_type:
9750 return "DW_TAG_upc_strict_type";
9751 case DW_TAG_upc_relaxed_type:
9752 return "DW_TAG_upc_relaxed_type";
9753 case DW_TAG_PGI_kanji_type:
9754 return "DW_TAG_PGI_kanji_type";
9755 case DW_TAG_PGI_interface_block:
9756 return "DW_TAG_PGI_interface_block";
9758 return "DW_TAG_<unknown>";
9762 /* Convert a DWARF attribute code into its string name. */
9765 dwarf_attr_name (unsigned attr)
9770 return "DW_AT_sibling";
9771 case DW_AT_location:
9772 return "DW_AT_location";
9774 return "DW_AT_name";
9775 case DW_AT_ordering:
9776 return "DW_AT_ordering";
9777 case DW_AT_subscr_data:
9778 return "DW_AT_subscr_data";
9779 case DW_AT_byte_size:
9780 return "DW_AT_byte_size";
9781 case DW_AT_bit_offset:
9782 return "DW_AT_bit_offset";
9783 case DW_AT_bit_size:
9784 return "DW_AT_bit_size";
9785 case DW_AT_element_list:
9786 return "DW_AT_element_list";
9787 case DW_AT_stmt_list:
9788 return "DW_AT_stmt_list";
9790 return "DW_AT_low_pc";
9792 return "DW_AT_high_pc";
9793 case DW_AT_language:
9794 return "DW_AT_language";
9796 return "DW_AT_member";
9798 return "DW_AT_discr";
9799 case DW_AT_discr_value:
9800 return "DW_AT_discr_value";
9801 case DW_AT_visibility:
9802 return "DW_AT_visibility";
9804 return "DW_AT_import";
9805 case DW_AT_string_length:
9806 return "DW_AT_string_length";
9807 case DW_AT_common_reference:
9808 return "DW_AT_common_reference";
9809 case DW_AT_comp_dir:
9810 return "DW_AT_comp_dir";
9811 case DW_AT_const_value:
9812 return "DW_AT_const_value";
9813 case DW_AT_containing_type:
9814 return "DW_AT_containing_type";
9815 case DW_AT_default_value:
9816 return "DW_AT_default_value";
9818 return "DW_AT_inline";
9819 case DW_AT_is_optional:
9820 return "DW_AT_is_optional";
9821 case DW_AT_lower_bound:
9822 return "DW_AT_lower_bound";
9823 case DW_AT_producer:
9824 return "DW_AT_producer";
9825 case DW_AT_prototyped:
9826 return "DW_AT_prototyped";
9827 case DW_AT_return_addr:
9828 return "DW_AT_return_addr";
9829 case DW_AT_start_scope:
9830 return "DW_AT_start_scope";
9831 case DW_AT_bit_stride:
9832 return "DW_AT_bit_stride";
9833 case DW_AT_upper_bound:
9834 return "DW_AT_upper_bound";
9835 case DW_AT_abstract_origin:
9836 return "DW_AT_abstract_origin";
9837 case DW_AT_accessibility:
9838 return "DW_AT_accessibility";
9839 case DW_AT_address_class:
9840 return "DW_AT_address_class";
9841 case DW_AT_artificial:
9842 return "DW_AT_artificial";
9843 case DW_AT_base_types:
9844 return "DW_AT_base_types";
9845 case DW_AT_calling_convention:
9846 return "DW_AT_calling_convention";
9848 return "DW_AT_count";
9849 case DW_AT_data_member_location:
9850 return "DW_AT_data_member_location";
9851 case DW_AT_decl_column:
9852 return "DW_AT_decl_column";
9853 case DW_AT_decl_file:
9854 return "DW_AT_decl_file";
9855 case DW_AT_decl_line:
9856 return "DW_AT_decl_line";
9857 case DW_AT_declaration:
9858 return "DW_AT_declaration";
9859 case DW_AT_discr_list:
9860 return "DW_AT_discr_list";
9861 case DW_AT_encoding:
9862 return "DW_AT_encoding";
9863 case DW_AT_external:
9864 return "DW_AT_external";
9865 case DW_AT_frame_base:
9866 return "DW_AT_frame_base";
9868 return "DW_AT_friend";
9869 case DW_AT_identifier_case:
9870 return "DW_AT_identifier_case";
9871 case DW_AT_macro_info:
9872 return "DW_AT_macro_info";
9873 case DW_AT_namelist_items:
9874 return "DW_AT_namelist_items";
9875 case DW_AT_priority:
9876 return "DW_AT_priority";
9878 return "DW_AT_segment";
9879 case DW_AT_specification:
9880 return "DW_AT_specification";
9881 case DW_AT_static_link:
9882 return "DW_AT_static_link";
9884 return "DW_AT_type";
9885 case DW_AT_use_location:
9886 return "DW_AT_use_location";
9887 case DW_AT_variable_parameter:
9888 return "DW_AT_variable_parameter";
9889 case DW_AT_virtuality:
9890 return "DW_AT_virtuality";
9891 case DW_AT_vtable_elem_location:
9892 return "DW_AT_vtable_elem_location";
9893 /* DWARF 3 values. */
9894 case DW_AT_allocated:
9895 return "DW_AT_allocated";
9896 case DW_AT_associated:
9897 return "DW_AT_associated";
9898 case DW_AT_data_location:
9899 return "DW_AT_data_location";
9900 case DW_AT_byte_stride:
9901 return "DW_AT_byte_stride";
9902 case DW_AT_entry_pc:
9903 return "DW_AT_entry_pc";
9904 case DW_AT_use_UTF8:
9905 return "DW_AT_use_UTF8";
9906 case DW_AT_extension:
9907 return "DW_AT_extension";
9909 return "DW_AT_ranges";
9910 case DW_AT_trampoline:
9911 return "DW_AT_trampoline";
9912 case DW_AT_call_column:
9913 return "DW_AT_call_column";
9914 case DW_AT_call_file:
9915 return "DW_AT_call_file";
9916 case DW_AT_call_line:
9917 return "DW_AT_call_line";
9918 case DW_AT_description:
9919 return "DW_AT_description";
9920 case DW_AT_binary_scale:
9921 return "DW_AT_binary_scale";
9922 case DW_AT_decimal_scale:
9923 return "DW_AT_decimal_scale";
9925 return "DW_AT_small";
9926 case DW_AT_decimal_sign:
9927 return "DW_AT_decimal_sign";
9928 case DW_AT_digit_count:
9929 return "DW_AT_digit_count";
9930 case DW_AT_picture_string:
9931 return "DW_AT_picture_string";
9933 return "DW_AT_mutable";
9934 case DW_AT_threads_scaled:
9935 return "DW_AT_threads_scaled";
9936 case DW_AT_explicit:
9937 return "DW_AT_explicit";
9938 case DW_AT_object_pointer:
9939 return "DW_AT_object_pointer";
9940 case DW_AT_endianity:
9941 return "DW_AT_endianity";
9942 case DW_AT_elemental:
9943 return "DW_AT_elemental";
9945 return "DW_AT_pure";
9946 case DW_AT_recursive:
9947 return "DW_AT_recursive";
9948 /* DWARF 4 values. */
9949 case DW_AT_signature:
9950 return "DW_AT_signature";
9951 case DW_AT_linkage_name:
9952 return "DW_AT_linkage_name";
9953 /* SGI/MIPS extensions. */
9954 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9955 case DW_AT_MIPS_fde:
9956 return "DW_AT_MIPS_fde";
9958 case DW_AT_MIPS_loop_begin:
9959 return "DW_AT_MIPS_loop_begin";
9960 case DW_AT_MIPS_tail_loop_begin:
9961 return "DW_AT_MIPS_tail_loop_begin";
9962 case DW_AT_MIPS_epilog_begin:
9963 return "DW_AT_MIPS_epilog_begin";
9964 case DW_AT_MIPS_loop_unroll_factor:
9965 return "DW_AT_MIPS_loop_unroll_factor";
9966 case DW_AT_MIPS_software_pipeline_depth:
9967 return "DW_AT_MIPS_software_pipeline_depth";
9968 case DW_AT_MIPS_linkage_name:
9969 return "DW_AT_MIPS_linkage_name";
9970 case DW_AT_MIPS_stride:
9971 return "DW_AT_MIPS_stride";
9972 case DW_AT_MIPS_abstract_name:
9973 return "DW_AT_MIPS_abstract_name";
9974 case DW_AT_MIPS_clone_origin:
9975 return "DW_AT_MIPS_clone_origin";
9976 case DW_AT_MIPS_has_inlines:
9977 return "DW_AT_MIPS_has_inlines";
9978 /* HP extensions. */
9979 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9980 case DW_AT_HP_block_index:
9981 return "DW_AT_HP_block_index";
9983 case DW_AT_HP_unmodifiable:
9984 return "DW_AT_HP_unmodifiable";
9985 case DW_AT_HP_actuals_stmt_list:
9986 return "DW_AT_HP_actuals_stmt_list";
9987 case DW_AT_HP_proc_per_section:
9988 return "DW_AT_HP_proc_per_section";
9989 case DW_AT_HP_raw_data_ptr:
9990 return "DW_AT_HP_raw_data_ptr";
9991 case DW_AT_HP_pass_by_reference:
9992 return "DW_AT_HP_pass_by_reference";
9993 case DW_AT_HP_opt_level:
9994 return "DW_AT_HP_opt_level";
9995 case DW_AT_HP_prof_version_id:
9996 return "DW_AT_HP_prof_version_id";
9997 case DW_AT_HP_opt_flags:
9998 return "DW_AT_HP_opt_flags";
9999 case DW_AT_HP_cold_region_low_pc:
10000 return "DW_AT_HP_cold_region_low_pc";
10001 case DW_AT_HP_cold_region_high_pc:
10002 return "DW_AT_HP_cold_region_high_pc";
10003 case DW_AT_HP_all_variables_modifiable:
10004 return "DW_AT_HP_all_variables_modifiable";
10005 case DW_AT_HP_linkage_name:
10006 return "DW_AT_HP_linkage_name";
10007 case DW_AT_HP_prof_flags:
10008 return "DW_AT_HP_prof_flags";
10009 /* GNU extensions. */
10010 case DW_AT_sf_names:
10011 return "DW_AT_sf_names";
10012 case DW_AT_src_info:
10013 return "DW_AT_src_info";
10014 case DW_AT_mac_info:
10015 return "DW_AT_mac_info";
10016 case DW_AT_src_coords:
10017 return "DW_AT_src_coords";
10018 case DW_AT_body_begin:
10019 return "DW_AT_body_begin";
10020 case DW_AT_body_end:
10021 return "DW_AT_body_end";
10022 case DW_AT_GNU_vector:
10023 return "DW_AT_GNU_vector";
10024 /* VMS extensions. */
10025 case DW_AT_VMS_rtnbeg_pd_address:
10026 return "DW_AT_VMS_rtnbeg_pd_address";
10027 /* UPC extension. */
10028 case DW_AT_upc_threads_scaled:
10029 return "DW_AT_upc_threads_scaled";
10030 /* PGI (STMicroelectronics) extensions. */
10031 case DW_AT_PGI_lbase:
10032 return "DW_AT_PGI_lbase";
10033 case DW_AT_PGI_soffset:
10034 return "DW_AT_PGI_soffset";
10035 case DW_AT_PGI_lstride:
10036 return "DW_AT_PGI_lstride";
10038 return "DW_AT_<unknown>";
10042 /* Convert a DWARF value form code into its string name. */
10045 dwarf_form_name (unsigned form)
10050 return "DW_FORM_addr";
10051 case DW_FORM_block2:
10052 return "DW_FORM_block2";
10053 case DW_FORM_block4:
10054 return "DW_FORM_block4";
10055 case DW_FORM_data2:
10056 return "DW_FORM_data2";
10057 case DW_FORM_data4:
10058 return "DW_FORM_data4";
10059 case DW_FORM_data8:
10060 return "DW_FORM_data8";
10061 case DW_FORM_string:
10062 return "DW_FORM_string";
10063 case DW_FORM_block:
10064 return "DW_FORM_block";
10065 case DW_FORM_block1:
10066 return "DW_FORM_block1";
10067 case DW_FORM_data1:
10068 return "DW_FORM_data1";
10070 return "DW_FORM_flag";
10071 case DW_FORM_sdata:
10072 return "DW_FORM_sdata";
10074 return "DW_FORM_strp";
10075 case DW_FORM_udata:
10076 return "DW_FORM_udata";
10077 case DW_FORM_ref_addr:
10078 return "DW_FORM_ref_addr";
10080 return "DW_FORM_ref1";
10082 return "DW_FORM_ref2";
10084 return "DW_FORM_ref4";
10086 return "DW_FORM_ref8";
10087 case DW_FORM_ref_udata:
10088 return "DW_FORM_ref_udata";
10089 case DW_FORM_indirect:
10090 return "DW_FORM_indirect";
10091 case DW_FORM_sec_offset:
10092 return "DW_FORM_sec_offset";
10093 case DW_FORM_exprloc:
10094 return "DW_FORM_exprloc";
10095 case DW_FORM_flag_present:
10096 return "DW_FORM_flag_present";
10098 return "DW_FORM_sig8";
10100 return "DW_FORM_<unknown>";
10104 /* Convert a DWARF stack opcode into its string name. */
10107 dwarf_stack_op_name (unsigned op, int def)
10112 return "DW_OP_addr";
10114 return "DW_OP_deref";
10115 case DW_OP_const1u:
10116 return "DW_OP_const1u";
10117 case DW_OP_const1s:
10118 return "DW_OP_const1s";
10119 case DW_OP_const2u:
10120 return "DW_OP_const2u";
10121 case DW_OP_const2s:
10122 return "DW_OP_const2s";
10123 case DW_OP_const4u:
10124 return "DW_OP_const4u";
10125 case DW_OP_const4s:
10126 return "DW_OP_const4s";
10127 case DW_OP_const8u:
10128 return "DW_OP_const8u";
10129 case DW_OP_const8s:
10130 return "DW_OP_const8s";
10132 return "DW_OP_constu";
10134 return "DW_OP_consts";
10136 return "DW_OP_dup";
10138 return "DW_OP_drop";
10140 return "DW_OP_over";
10142 return "DW_OP_pick";
10144 return "DW_OP_swap";
10146 return "DW_OP_rot";
10148 return "DW_OP_xderef";
10150 return "DW_OP_abs";
10152 return "DW_OP_and";
10154 return "DW_OP_div";
10156 return "DW_OP_minus";
10158 return "DW_OP_mod";
10160 return "DW_OP_mul";
10162 return "DW_OP_neg";
10164 return "DW_OP_not";
10168 return "DW_OP_plus";
10169 case DW_OP_plus_uconst:
10170 return "DW_OP_plus_uconst";
10172 return "DW_OP_shl";
10174 return "DW_OP_shr";
10176 return "DW_OP_shra";
10178 return "DW_OP_xor";
10180 return "DW_OP_bra";
10194 return "DW_OP_skip";
10196 return "DW_OP_lit0";
10198 return "DW_OP_lit1";
10200 return "DW_OP_lit2";
10202 return "DW_OP_lit3";
10204 return "DW_OP_lit4";
10206 return "DW_OP_lit5";
10208 return "DW_OP_lit6";
10210 return "DW_OP_lit7";
10212 return "DW_OP_lit8";
10214 return "DW_OP_lit9";
10216 return "DW_OP_lit10";
10218 return "DW_OP_lit11";
10220 return "DW_OP_lit12";
10222 return "DW_OP_lit13";
10224 return "DW_OP_lit14";
10226 return "DW_OP_lit15";
10228 return "DW_OP_lit16";
10230 return "DW_OP_lit17";
10232 return "DW_OP_lit18";
10234 return "DW_OP_lit19";
10236 return "DW_OP_lit20";
10238 return "DW_OP_lit21";
10240 return "DW_OP_lit22";
10242 return "DW_OP_lit23";
10244 return "DW_OP_lit24";
10246 return "DW_OP_lit25";
10248 return "DW_OP_lit26";
10250 return "DW_OP_lit27";
10252 return "DW_OP_lit28";
10254 return "DW_OP_lit29";
10256 return "DW_OP_lit30";
10258 return "DW_OP_lit31";
10260 return "DW_OP_reg0";
10262 return "DW_OP_reg1";
10264 return "DW_OP_reg2";
10266 return "DW_OP_reg3";
10268 return "DW_OP_reg4";
10270 return "DW_OP_reg5";
10272 return "DW_OP_reg6";
10274 return "DW_OP_reg7";
10276 return "DW_OP_reg8";
10278 return "DW_OP_reg9";
10280 return "DW_OP_reg10";
10282 return "DW_OP_reg11";
10284 return "DW_OP_reg12";
10286 return "DW_OP_reg13";
10288 return "DW_OP_reg14";
10290 return "DW_OP_reg15";
10292 return "DW_OP_reg16";
10294 return "DW_OP_reg17";
10296 return "DW_OP_reg18";
10298 return "DW_OP_reg19";
10300 return "DW_OP_reg20";
10302 return "DW_OP_reg21";
10304 return "DW_OP_reg22";
10306 return "DW_OP_reg23";
10308 return "DW_OP_reg24";
10310 return "DW_OP_reg25";
10312 return "DW_OP_reg26";
10314 return "DW_OP_reg27";
10316 return "DW_OP_reg28";
10318 return "DW_OP_reg29";
10320 return "DW_OP_reg30";
10322 return "DW_OP_reg31";
10324 return "DW_OP_breg0";
10326 return "DW_OP_breg1";
10328 return "DW_OP_breg2";
10330 return "DW_OP_breg3";
10332 return "DW_OP_breg4";
10334 return "DW_OP_breg5";
10336 return "DW_OP_breg6";
10338 return "DW_OP_breg7";
10340 return "DW_OP_breg8";
10342 return "DW_OP_breg9";
10344 return "DW_OP_breg10";
10346 return "DW_OP_breg11";
10348 return "DW_OP_breg12";
10350 return "DW_OP_breg13";
10352 return "DW_OP_breg14";
10354 return "DW_OP_breg15";
10356 return "DW_OP_breg16";
10358 return "DW_OP_breg17";
10360 return "DW_OP_breg18";
10362 return "DW_OP_breg19";
10364 return "DW_OP_breg20";
10366 return "DW_OP_breg21";
10368 return "DW_OP_breg22";
10370 return "DW_OP_breg23";
10372 return "DW_OP_breg24";
10374 return "DW_OP_breg25";
10376 return "DW_OP_breg26";
10378 return "DW_OP_breg27";
10380 return "DW_OP_breg28";
10382 return "DW_OP_breg29";
10384 return "DW_OP_breg30";
10386 return "DW_OP_breg31";
10388 return "DW_OP_regx";
10390 return "DW_OP_fbreg";
10392 return "DW_OP_bregx";
10394 return "DW_OP_piece";
10395 case DW_OP_deref_size:
10396 return "DW_OP_deref_size";
10397 case DW_OP_xderef_size:
10398 return "DW_OP_xderef_size";
10400 return "DW_OP_nop";
10401 /* DWARF 3 extensions. */
10402 case DW_OP_push_object_address:
10403 return "DW_OP_push_object_address";
10405 return "DW_OP_call2";
10407 return "DW_OP_call4";
10408 case DW_OP_call_ref:
10409 return "DW_OP_call_ref";
10410 case DW_OP_form_tls_address:
10411 return "DW_OP_form_tls_address";
10412 case DW_OP_call_frame_cfa:
10413 return "DW_OP_call_frame_cfa";
10414 case DW_OP_bit_piece:
10415 return "DW_OP_bit_piece";
10416 /* DWARF 4 extensions. */
10417 case DW_OP_implicit_value:
10418 return "DW_OP_implicit_value";
10419 case DW_OP_stack_value:
10420 return "DW_OP_stack_value";
10421 /* GNU extensions. */
10422 case DW_OP_GNU_push_tls_address:
10423 return "DW_OP_GNU_push_tls_address";
10424 case DW_OP_GNU_uninit:
10425 return "DW_OP_GNU_uninit";
10427 return def ? "OP_<unknown>" : NULL;
10432 dwarf_bool_name (unsigned mybool)
10440 /* Convert a DWARF type code into its string name. */
10443 dwarf_type_encoding_name (unsigned enc)
10448 return "DW_ATE_void";
10449 case DW_ATE_address:
10450 return "DW_ATE_address";
10451 case DW_ATE_boolean:
10452 return "DW_ATE_boolean";
10453 case DW_ATE_complex_float:
10454 return "DW_ATE_complex_float";
10456 return "DW_ATE_float";
10457 case DW_ATE_signed:
10458 return "DW_ATE_signed";
10459 case DW_ATE_signed_char:
10460 return "DW_ATE_signed_char";
10461 case DW_ATE_unsigned:
10462 return "DW_ATE_unsigned";
10463 case DW_ATE_unsigned_char:
10464 return "DW_ATE_unsigned_char";
10466 case DW_ATE_imaginary_float:
10467 return "DW_ATE_imaginary_float";
10468 case DW_ATE_packed_decimal:
10469 return "DW_ATE_packed_decimal";
10470 case DW_ATE_numeric_string:
10471 return "DW_ATE_numeric_string";
10472 case DW_ATE_edited:
10473 return "DW_ATE_edited";
10474 case DW_ATE_signed_fixed:
10475 return "DW_ATE_signed_fixed";
10476 case DW_ATE_unsigned_fixed:
10477 return "DW_ATE_unsigned_fixed";
10478 case DW_ATE_decimal_float:
10479 return "DW_ATE_decimal_float";
10482 return "DW_ATE_UTF";
10483 /* HP extensions. */
10484 case DW_ATE_HP_float80:
10485 return "DW_ATE_HP_float80";
10486 case DW_ATE_HP_complex_float80:
10487 return "DW_ATE_HP_complex_float80";
10488 case DW_ATE_HP_float128:
10489 return "DW_ATE_HP_float128";
10490 case DW_ATE_HP_complex_float128:
10491 return "DW_ATE_HP_complex_float128";
10492 case DW_ATE_HP_floathpintel:
10493 return "DW_ATE_HP_floathpintel";
10494 case DW_ATE_HP_imaginary_float80:
10495 return "DW_ATE_HP_imaginary_float80";
10496 case DW_ATE_HP_imaginary_float128:
10497 return "DW_ATE_HP_imaginary_float128";
10499 return "DW_ATE_<unknown>";
10503 /* Convert a DWARF call frame info operation to its string name. */
10507 dwarf_cfi_name (unsigned cfi_opc)
10511 case DW_CFA_advance_loc:
10512 return "DW_CFA_advance_loc";
10513 case DW_CFA_offset:
10514 return "DW_CFA_offset";
10515 case DW_CFA_restore:
10516 return "DW_CFA_restore";
10518 return "DW_CFA_nop";
10519 case DW_CFA_set_loc:
10520 return "DW_CFA_set_loc";
10521 case DW_CFA_advance_loc1:
10522 return "DW_CFA_advance_loc1";
10523 case DW_CFA_advance_loc2:
10524 return "DW_CFA_advance_loc2";
10525 case DW_CFA_advance_loc4:
10526 return "DW_CFA_advance_loc4";
10527 case DW_CFA_offset_extended:
10528 return "DW_CFA_offset_extended";
10529 case DW_CFA_restore_extended:
10530 return "DW_CFA_restore_extended";
10531 case DW_CFA_undefined:
10532 return "DW_CFA_undefined";
10533 case DW_CFA_same_value:
10534 return "DW_CFA_same_value";
10535 case DW_CFA_register:
10536 return "DW_CFA_register";
10537 case DW_CFA_remember_state:
10538 return "DW_CFA_remember_state";
10539 case DW_CFA_restore_state:
10540 return "DW_CFA_restore_state";
10541 case DW_CFA_def_cfa:
10542 return "DW_CFA_def_cfa";
10543 case DW_CFA_def_cfa_register:
10544 return "DW_CFA_def_cfa_register";
10545 case DW_CFA_def_cfa_offset:
10546 return "DW_CFA_def_cfa_offset";
10548 case DW_CFA_def_cfa_expression:
10549 return "DW_CFA_def_cfa_expression";
10550 case DW_CFA_expression:
10551 return "DW_CFA_expression";
10552 case DW_CFA_offset_extended_sf:
10553 return "DW_CFA_offset_extended_sf";
10554 case DW_CFA_def_cfa_sf:
10555 return "DW_CFA_def_cfa_sf";
10556 case DW_CFA_def_cfa_offset_sf:
10557 return "DW_CFA_def_cfa_offset_sf";
10558 case DW_CFA_val_offset:
10559 return "DW_CFA_val_offset";
10560 case DW_CFA_val_offset_sf:
10561 return "DW_CFA_val_offset_sf";
10562 case DW_CFA_val_expression:
10563 return "DW_CFA_val_expression";
10564 /* SGI/MIPS specific. */
10565 case DW_CFA_MIPS_advance_loc8:
10566 return "DW_CFA_MIPS_advance_loc8";
10567 /* GNU extensions. */
10568 case DW_CFA_GNU_window_save:
10569 return "DW_CFA_GNU_window_save";
10570 case DW_CFA_GNU_args_size:
10571 return "DW_CFA_GNU_args_size";
10572 case DW_CFA_GNU_negative_offset_extended:
10573 return "DW_CFA_GNU_negative_offset_extended";
10575 return "DW_CFA_<unknown>";
10581 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
10585 print_spaces (indent, f);
10586 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
10587 dwarf_tag_name (die->tag), die->abbrev, die->offset);
10589 if (die->parent != NULL)
10591 print_spaces (indent, f);
10592 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
10593 die->parent->offset);
10596 print_spaces (indent, f);
10597 fprintf_unfiltered (f, " has children: %s\n",
10598 dwarf_bool_name (die->child != NULL));
10600 print_spaces (indent, f);
10601 fprintf_unfiltered (f, " attributes:\n");
10603 for (i = 0; i < die->num_attrs; ++i)
10605 print_spaces (indent, f);
10606 fprintf_unfiltered (f, " %s (%s) ",
10607 dwarf_attr_name (die->attrs[i].name),
10608 dwarf_form_name (die->attrs[i].form));
10610 switch (die->attrs[i].form)
10612 case DW_FORM_ref_addr:
10614 fprintf_unfiltered (f, "address: ");
10615 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
10617 case DW_FORM_block2:
10618 case DW_FORM_block4:
10619 case DW_FORM_block:
10620 case DW_FORM_block1:
10621 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
10623 case DW_FORM_exprloc:
10624 fprintf_unfiltered (f, "expression: size %u",
10625 DW_BLOCK (&die->attrs[i])->size);
10630 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
10631 (long) (DW_ADDR (&die->attrs[i])));
10633 case DW_FORM_data1:
10634 case DW_FORM_data2:
10635 case DW_FORM_data4:
10636 case DW_FORM_data8:
10637 case DW_FORM_udata:
10638 case DW_FORM_sdata:
10639 fprintf_unfiltered (f, "constant: %s",
10640 pulongest (DW_UNSND (&die->attrs[i])));
10642 case DW_FORM_sec_offset:
10643 fprintf_unfiltered (f, "section offset: %s",
10644 pulongest (DW_UNSND (&die->attrs[i])));
10647 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
10648 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
10649 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
10651 fprintf_unfiltered (f, "signatured type, offset: unknown");
10653 case DW_FORM_string:
10655 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
10656 DW_STRING (&die->attrs[i])
10657 ? DW_STRING (&die->attrs[i]) : "",
10658 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
10661 if (DW_UNSND (&die->attrs[i]))
10662 fprintf_unfiltered (f, "flag: TRUE");
10664 fprintf_unfiltered (f, "flag: FALSE");
10666 case DW_FORM_flag_present:
10667 fprintf_unfiltered (f, "flag: TRUE");
10669 case DW_FORM_indirect:
10670 /* the reader will have reduced the indirect form to
10671 the "base form" so this form should not occur */
10672 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
10675 fprintf_unfiltered (f, "unsupported attribute form: %d.",
10676 die->attrs[i].form);
10679 fprintf_unfiltered (f, "\n");
10684 dump_die_for_error (struct die_info *die)
10686 dump_die_shallow (gdb_stderr, 0, die);
10690 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
10692 int indent = level * 4;
10694 gdb_assert (die != NULL);
10696 if (level >= max_level)
10699 dump_die_shallow (f, indent, die);
10701 if (die->child != NULL)
10703 print_spaces (indent, f);
10704 fprintf_unfiltered (f, " Children:");
10705 if (level + 1 < max_level)
10707 fprintf_unfiltered (f, "\n");
10708 dump_die_1 (f, level + 1, max_level, die->child);
10712 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
10716 if (die->sibling != NULL && level > 0)
10718 dump_die_1 (f, level, max_level, die->sibling);
10722 /* This is called from the pdie macro in gdbinit.in.
10723 It's not static so gcc will keep a copy callable from gdb. */
10726 dump_die (struct die_info *die, int max_level)
10728 dump_die_1 (gdb_stdlog, 0, max_level, die);
10732 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
10736 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
10742 is_ref_attr (struct attribute *attr)
10744 switch (attr->form)
10746 case DW_FORM_ref_addr:
10751 case DW_FORM_ref_udata:
10758 static unsigned int
10759 dwarf2_get_ref_die_offset (struct attribute *attr)
10761 if (is_ref_attr (attr))
10762 return DW_ADDR (attr);
10764 complaint (&symfile_complaints,
10765 _("unsupported die ref attribute form: '%s'"),
10766 dwarf_form_name (attr->form));
10770 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10771 * the value held by the attribute is not constant. */
10774 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
10776 if (attr->form == DW_FORM_sdata)
10777 return DW_SND (attr);
10778 else if (attr->form == DW_FORM_udata
10779 || attr->form == DW_FORM_data1
10780 || attr->form == DW_FORM_data2
10781 || attr->form == DW_FORM_data4
10782 || attr->form == DW_FORM_data8)
10783 return DW_UNSND (attr);
10786 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
10787 dwarf_form_name (attr->form));
10788 return default_value;
10792 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10793 unit and add it to our queue.
10794 The result is non-zero if PER_CU was queued, otherwise the result is zero
10795 meaning either PER_CU is already queued or it is already loaded. */
10798 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
10799 struct dwarf2_per_cu_data *per_cu)
10801 /* Mark the dependence relation so that we don't flush PER_CU
10803 dwarf2_add_dependence (this_cu, per_cu);
10805 /* If it's already on the queue, we have nothing to do. */
10806 if (per_cu->queued)
10809 /* If the compilation unit is already loaded, just mark it as
10811 if (per_cu->cu != NULL)
10813 per_cu->cu->last_used = 0;
10817 /* Add it to the queue. */
10818 queue_comp_unit (per_cu, this_cu->objfile);
10823 /* Follow reference or signature attribute ATTR of SRC_DIE.
10824 On entry *REF_CU is the CU of SRC_DIE.
10825 On exit *REF_CU is the CU of the result. */
10827 static struct die_info *
10828 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
10829 struct dwarf2_cu **ref_cu)
10831 struct die_info *die;
10833 if (is_ref_attr (attr))
10834 die = follow_die_ref (src_die, attr, ref_cu);
10835 else if (attr->form == DW_FORM_sig8)
10836 die = follow_die_sig (src_die, attr, ref_cu);
10839 dump_die_for_error (src_die);
10840 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10841 (*ref_cu)->objfile->name);
10847 /* Follow reference OFFSET.
10848 On entry *REF_CU is the CU of source DIE referencing OFFSET.
10849 On exit *REF_CU is the CU of the result. */
10851 static struct die_info *
10852 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
10854 struct die_info temp_die;
10855 struct dwarf2_cu *target_cu, *cu = *ref_cu;
10857 gdb_assert (cu->per_cu != NULL);
10859 if (cu->per_cu->from_debug_types)
10861 /* .debug_types CUs cannot reference anything outside their CU.
10862 If they need to, they have to reference a signatured type via
10864 if (! offset_in_cu_p (&cu->header, offset))
10868 else if (! offset_in_cu_p (&cu->header, offset))
10870 struct dwarf2_per_cu_data *per_cu;
10872 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
10874 /* If necessary, add it to the queue and load its DIEs. */
10875 if (maybe_queue_comp_unit (cu, per_cu))
10876 load_full_comp_unit (per_cu, cu->objfile);
10878 target_cu = per_cu->cu;
10883 *ref_cu = target_cu;
10884 temp_die.offset = offset;
10885 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
10888 /* Follow reference attribute ATTR of SRC_DIE.
10889 On entry *REF_CU is the CU of SRC_DIE.
10890 On exit *REF_CU is the CU of the result. */
10892 static struct die_info *
10893 follow_die_ref (struct die_info *src_die, struct attribute *attr,
10894 struct dwarf2_cu **ref_cu)
10896 unsigned int offset = dwarf2_get_ref_die_offset (attr);
10897 struct dwarf2_cu *cu = *ref_cu;
10898 struct die_info *die;
10900 die = follow_die_offset (offset, ref_cu);
10902 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10903 "at 0x%x [in module %s]"),
10904 offset, src_die->offset, cu->objfile->name);
10909 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
10910 value is intended for DW_OP_call*. */
10912 struct dwarf2_locexpr_baton
10913 dwarf2_fetch_die_location_block (unsigned int offset,
10914 struct dwarf2_per_cu_data *per_cu)
10916 struct dwarf2_cu *cu = per_cu->cu;
10917 struct die_info *die;
10918 struct attribute *attr;
10919 struct dwarf2_locexpr_baton retval;
10921 die = follow_die_offset (offset, &cu);
10923 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
10924 offset, per_cu->cu->objfile->name);
10926 attr = dwarf2_attr (die, DW_AT_location, cu);
10929 /* DWARF: "If there is no such attribute, then there is no effect.". */
10931 retval.data = NULL;
10936 if (!attr_form_is_block (attr))
10937 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
10938 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
10939 offset, per_cu->cu->objfile->name);
10941 retval.data = DW_BLOCK (attr)->data;
10942 retval.size = DW_BLOCK (attr)->size;
10944 retval.per_cu = cu->per_cu;
10948 /* Follow the signature attribute ATTR in SRC_DIE.
10949 On entry *REF_CU is the CU of SRC_DIE.
10950 On exit *REF_CU is the CU of the result. */
10952 static struct die_info *
10953 follow_die_sig (struct die_info *src_die, struct attribute *attr,
10954 struct dwarf2_cu **ref_cu)
10956 struct objfile *objfile = (*ref_cu)->objfile;
10957 struct die_info temp_die;
10958 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
10959 struct dwarf2_cu *sig_cu;
10960 struct die_info *die;
10962 /* sig_type will be NULL if the signatured type is missing from
10964 if (sig_type == NULL)
10965 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10966 "at 0x%x [in module %s]"),
10967 src_die->offset, objfile->name);
10969 /* If necessary, add it to the queue and load its DIEs. */
10971 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
10972 read_signatured_type (objfile, sig_type);
10974 gdb_assert (sig_type->per_cu.cu != NULL);
10976 sig_cu = sig_type->per_cu.cu;
10977 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
10978 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
10985 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10986 "at 0x%x [in module %s]"),
10987 sig_type->type_offset, src_die->offset, objfile->name);
10990 /* Given an offset of a signatured type, return its signatured_type. */
10992 static struct signatured_type *
10993 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
10995 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
10996 unsigned int length, initial_length_size;
10997 unsigned int sig_offset;
10998 struct signatured_type find_entry, *type_sig;
11000 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
11001 sig_offset = (initial_length_size
11003 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
11004 + 1 /*address_size*/);
11005 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
11006 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
11008 /* This is only used to lookup previously recorded types.
11009 If we didn't find it, it's our bug. */
11010 gdb_assert (type_sig != NULL);
11011 gdb_assert (offset == type_sig->offset);
11016 /* Read in signatured type at OFFSET and build its CU and die(s). */
11019 read_signatured_type_at_offset (struct objfile *objfile,
11020 unsigned int offset)
11022 struct signatured_type *type_sig;
11024 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
11026 /* We have the section offset, but we need the signature to do the
11027 hash table lookup. */
11028 type_sig = lookup_signatured_type_at_offset (objfile, offset);
11030 gdb_assert (type_sig->per_cu.cu == NULL);
11032 read_signatured_type (objfile, type_sig);
11034 gdb_assert (type_sig->per_cu.cu != NULL);
11037 /* Read in a signatured type and build its CU and DIEs. */
11040 read_signatured_type (struct objfile *objfile,
11041 struct signatured_type *type_sig)
11043 gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
11044 struct die_reader_specs reader_specs;
11045 struct dwarf2_cu *cu;
11046 ULONGEST signature;
11047 struct cleanup *back_to, *free_cu_cleanup;
11048 struct attribute *attr;
11050 gdb_assert (type_sig->per_cu.cu == NULL);
11052 cu = xmalloc (sizeof (struct dwarf2_cu));
11053 memset (cu, 0, sizeof (struct dwarf2_cu));
11054 obstack_init (&cu->comp_unit_obstack);
11055 cu->objfile = objfile;
11056 type_sig->per_cu.cu = cu;
11057 cu->per_cu = &type_sig->per_cu;
11059 /* If an error occurs while loading, release our storage. */
11060 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
11062 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
11063 types_ptr, objfile->obfd);
11064 gdb_assert (signature == type_sig->signature);
11067 = htab_create_alloc_ex (cu->header.length / 12,
11071 &cu->comp_unit_obstack,
11072 hashtab_obstack_allocate,
11073 dummy_obstack_deallocate);
11075 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
11076 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
11078 init_cu_die_reader (&reader_specs, cu);
11080 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
11083 /* We try not to read any attributes in this function, because not
11084 all objfiles needed for references have been loaded yet, and symbol
11085 table processing isn't initialized. But we have to set the CU language,
11086 or we won't be able to build types correctly. */
11087 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
11089 set_cu_language (DW_UNSND (attr), cu);
11091 set_cu_language (language_minimal, cu);
11093 do_cleanups (back_to);
11095 /* We've successfully allocated this compilation unit. Let our caller
11096 clean it up when finished with it. */
11097 discard_cleanups (free_cu_cleanup);
11099 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
11100 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
11103 /* Decode simple location descriptions.
11104 Given a pointer to a dwarf block that defines a location, compute
11105 the location and return the value.
11107 NOTE drow/2003-11-18: This function is called in two situations
11108 now: for the address of static or global variables (partial symbols
11109 only) and for offsets into structures which are expected to be
11110 (more or less) constant. The partial symbol case should go away,
11111 and only the constant case should remain. That will let this
11112 function complain more accurately. A few special modes are allowed
11113 without complaint for global variables (for instance, global
11114 register values and thread-local values).
11116 A location description containing no operations indicates that the
11117 object is optimized out. The return value is 0 for that case.
11118 FIXME drow/2003-11-16: No callers check for this case any more; soon all
11119 callers will only want a very basic result and this can become a
11122 Note that stack[0] is unused except as a default error return.
11123 Note that stack overflow is not yet handled. */
11126 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
11128 struct objfile *objfile = cu->objfile;
11130 int size = blk->size;
11131 gdb_byte *data = blk->data;
11132 CORE_ADDR stack[64];
11134 unsigned int bytes_read, unsnd;
11178 stack[++stacki] = op - DW_OP_lit0;
11213 stack[++stacki] = op - DW_OP_reg0;
11215 dwarf2_complex_location_expr_complaint ();
11219 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
11221 stack[++stacki] = unsnd;
11223 dwarf2_complex_location_expr_complaint ();
11227 stack[++stacki] = read_address (objfile->obfd, &data[i],
11232 case DW_OP_const1u:
11233 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
11237 case DW_OP_const1s:
11238 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
11242 case DW_OP_const2u:
11243 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
11247 case DW_OP_const2s:
11248 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
11252 case DW_OP_const4u:
11253 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
11257 case DW_OP_const4s:
11258 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
11263 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
11269 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
11274 stack[stacki + 1] = stack[stacki];
11279 stack[stacki - 1] += stack[stacki];
11283 case DW_OP_plus_uconst:
11284 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
11289 stack[stacki - 1] -= stack[stacki];
11294 /* If we're not the last op, then we definitely can't encode
11295 this using GDB's address_class enum. This is valid for partial
11296 global symbols, although the variable's address will be bogus
11299 dwarf2_complex_location_expr_complaint ();
11302 case DW_OP_GNU_push_tls_address:
11303 /* The top of the stack has the offset from the beginning
11304 of the thread control block at which the variable is located. */
11305 /* Nothing should follow this operator, so the top of stack would
11307 /* This is valid for partial global symbols, but the variable's
11308 address will be bogus in the psymtab. */
11310 dwarf2_complex_location_expr_complaint ();
11313 case DW_OP_GNU_uninit:
11317 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
11318 dwarf_stack_op_name (op, 1));
11319 return (stack[stacki]);
11322 return (stack[stacki]);
11325 /* memory allocation interface */
11327 static struct dwarf_block *
11328 dwarf_alloc_block (struct dwarf2_cu *cu)
11330 struct dwarf_block *blk;
11332 blk = (struct dwarf_block *)
11333 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
11337 static struct abbrev_info *
11338 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
11340 struct abbrev_info *abbrev;
11342 abbrev = (struct abbrev_info *)
11343 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
11344 memset (abbrev, 0, sizeof (struct abbrev_info));
11348 static struct die_info *
11349 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
11351 struct die_info *die;
11352 size_t size = sizeof (struct die_info);
11355 size += (num_attrs - 1) * sizeof (struct attribute);
11357 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
11358 memset (die, 0, sizeof (struct die_info));
11363 /* Macro support. */
11366 /* Return the full name of file number I in *LH's file name table.
11367 Use COMP_DIR as the name of the current directory of the
11368 compilation. The result is allocated using xmalloc; the caller is
11369 responsible for freeing it. */
11371 file_full_name (int file, struct line_header *lh, const char *comp_dir)
11373 /* Is the file number a valid index into the line header's file name
11374 table? Remember that file numbers start with one, not zero. */
11375 if (1 <= file && file <= lh->num_file_names)
11377 struct file_entry *fe = &lh->file_names[file - 1];
11379 if (IS_ABSOLUTE_PATH (fe->name))
11380 return xstrdup (fe->name);
11388 dir = lh->include_dirs[fe->dir_index - 1];
11394 dir_len = strlen (dir);
11395 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
11396 strcpy (full_name, dir);
11397 full_name[dir_len] = '/';
11398 strcpy (full_name + dir_len + 1, fe->name);
11402 return xstrdup (fe->name);
11407 /* The compiler produced a bogus file number. We can at least
11408 record the macro definitions made in the file, even if we
11409 won't be able to find the file by name. */
11410 char fake_name[80];
11412 sprintf (fake_name, "<bad macro file number %d>", file);
11414 complaint (&symfile_complaints,
11415 _("bad file number in macro information (%d)"),
11418 return xstrdup (fake_name);
11423 static struct macro_source_file *
11424 macro_start_file (int file, int line,
11425 struct macro_source_file *current_file,
11426 const char *comp_dir,
11427 struct line_header *lh, struct objfile *objfile)
11429 /* The full name of this source file. */
11430 char *full_name = file_full_name (file, lh, comp_dir);
11432 /* We don't create a macro table for this compilation unit
11433 at all until we actually get a filename. */
11434 if (! pending_macros)
11435 pending_macros = new_macro_table (&objfile->objfile_obstack,
11436 objfile->macro_cache);
11438 if (! current_file)
11439 /* If we have no current file, then this must be the start_file
11440 directive for the compilation unit's main source file. */
11441 current_file = macro_set_main (pending_macros, full_name);
11443 current_file = macro_include (current_file, line, full_name);
11447 return current_file;
11451 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11452 followed by a null byte. */
11454 copy_string (const char *buf, int len)
11456 char *s = xmalloc (len + 1);
11458 memcpy (s, buf, len);
11464 static const char *
11465 consume_improper_spaces (const char *p, const char *body)
11469 complaint (&symfile_complaints,
11470 _("macro definition contains spaces in formal argument list:\n`%s'"),
11482 parse_macro_definition (struct macro_source_file *file, int line,
11487 /* The body string takes one of two forms. For object-like macro
11488 definitions, it should be:
11490 <macro name> " " <definition>
11492 For function-like macro definitions, it should be:
11494 <macro name> "() " <definition>
11496 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11498 Spaces may appear only where explicitly indicated, and in the
11501 The Dwarf 2 spec says that an object-like macro's name is always
11502 followed by a space, but versions of GCC around March 2002 omit
11503 the space when the macro's definition is the empty string.
11505 The Dwarf 2 spec says that there should be no spaces between the
11506 formal arguments in a function-like macro's formal argument list,
11507 but versions of GCC around March 2002 include spaces after the
11511 /* Find the extent of the macro name. The macro name is terminated
11512 by either a space or null character (for an object-like macro) or
11513 an opening paren (for a function-like macro). */
11514 for (p = body; *p; p++)
11515 if (*p == ' ' || *p == '(')
11518 if (*p == ' ' || *p == '\0')
11520 /* It's an object-like macro. */
11521 int name_len = p - body;
11522 char *name = copy_string (body, name_len);
11523 const char *replacement;
11526 replacement = body + name_len + 1;
11529 dwarf2_macro_malformed_definition_complaint (body);
11530 replacement = body + name_len;
11533 macro_define_object (file, line, name, replacement);
11537 else if (*p == '(')
11539 /* It's a function-like macro. */
11540 char *name = copy_string (body, p - body);
11543 char **argv = xmalloc (argv_size * sizeof (*argv));
11547 p = consume_improper_spaces (p, body);
11549 /* Parse the formal argument list. */
11550 while (*p && *p != ')')
11552 /* Find the extent of the current argument name. */
11553 const char *arg_start = p;
11555 while (*p && *p != ',' && *p != ')' && *p != ' ')
11558 if (! *p || p == arg_start)
11559 dwarf2_macro_malformed_definition_complaint (body);
11562 /* Make sure argv has room for the new argument. */
11563 if (argc >= argv_size)
11566 argv = xrealloc (argv, argv_size * sizeof (*argv));
11569 argv[argc++] = copy_string (arg_start, p - arg_start);
11572 p = consume_improper_spaces (p, body);
11574 /* Consume the comma, if present. */
11579 p = consume_improper_spaces (p, body);
11588 /* Perfectly formed definition, no complaints. */
11589 macro_define_function (file, line, name,
11590 argc, (const char **) argv,
11592 else if (*p == '\0')
11594 /* Complain, but do define it. */
11595 dwarf2_macro_malformed_definition_complaint (body);
11596 macro_define_function (file, line, name,
11597 argc, (const char **) argv,
11601 /* Just complain. */
11602 dwarf2_macro_malformed_definition_complaint (body);
11605 /* Just complain. */
11606 dwarf2_macro_malformed_definition_complaint (body);
11612 for (i = 0; i < argc; i++)
11618 dwarf2_macro_malformed_definition_complaint (body);
11623 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
11624 char *comp_dir, bfd *abfd,
11625 struct dwarf2_cu *cu)
11627 gdb_byte *mac_ptr, *mac_end;
11628 struct macro_source_file *current_file = 0;
11629 enum dwarf_macinfo_record_type macinfo_type;
11630 int at_commandline;
11632 dwarf2_read_section (dwarf2_per_objfile->objfile,
11633 &dwarf2_per_objfile->macinfo);
11634 if (dwarf2_per_objfile->macinfo.buffer == NULL)
11636 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
11640 /* First pass: Find the name of the base filename.
11641 This filename is needed in order to process all macros whose definition
11642 (or undefinition) comes from the command line. These macros are defined
11643 before the first DW_MACINFO_start_file entry, and yet still need to be
11644 associated to the base file.
11646 To determine the base file name, we scan the macro definitions until we
11647 reach the first DW_MACINFO_start_file entry. We then initialize
11648 CURRENT_FILE accordingly so that any macro definition found before the
11649 first DW_MACINFO_start_file can still be associated to the base file. */
11651 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11652 mac_end = dwarf2_per_objfile->macinfo.buffer
11653 + dwarf2_per_objfile->macinfo.size;
11657 /* Do we at least have room for a macinfo type byte? */
11658 if (mac_ptr >= mac_end)
11660 /* Complaint is printed during the second pass as GDB will probably
11661 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11665 macinfo_type = read_1_byte (abfd, mac_ptr);
11668 switch (macinfo_type)
11670 /* A zero macinfo type indicates the end of the macro
11675 case DW_MACINFO_define:
11676 case DW_MACINFO_undef:
11677 /* Only skip the data by MAC_PTR. */
11679 unsigned int bytes_read;
11681 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11682 mac_ptr += bytes_read;
11683 read_string (abfd, mac_ptr, &bytes_read);
11684 mac_ptr += bytes_read;
11688 case DW_MACINFO_start_file:
11690 unsigned int bytes_read;
11693 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11694 mac_ptr += bytes_read;
11695 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11696 mac_ptr += bytes_read;
11698 current_file = macro_start_file (file, line, current_file, comp_dir,
11703 case DW_MACINFO_end_file:
11704 /* No data to skip by MAC_PTR. */
11707 case DW_MACINFO_vendor_ext:
11708 /* Only skip the data by MAC_PTR. */
11710 unsigned int bytes_read;
11712 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11713 mac_ptr += bytes_read;
11714 read_string (abfd, mac_ptr, &bytes_read);
11715 mac_ptr += bytes_read;
11722 } while (macinfo_type != 0 && current_file == NULL);
11724 /* Second pass: Process all entries.
11726 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11727 command-line macro definitions/undefinitions. This flag is unset when we
11728 reach the first DW_MACINFO_start_file entry. */
11730 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11732 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11733 GDB is still reading the definitions from command line. First
11734 DW_MACINFO_start_file will need to be ignored as it was already executed
11735 to create CURRENT_FILE for the main source holding also the command line
11736 definitions. On first met DW_MACINFO_start_file this flag is reset to
11737 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11739 at_commandline = 1;
11743 /* Do we at least have room for a macinfo type byte? */
11744 if (mac_ptr >= mac_end)
11746 dwarf2_macros_too_long_complaint ();
11750 macinfo_type = read_1_byte (abfd, mac_ptr);
11753 switch (macinfo_type)
11755 /* A zero macinfo type indicates the end of the macro
11760 case DW_MACINFO_define:
11761 case DW_MACINFO_undef:
11763 unsigned int bytes_read;
11767 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11768 mac_ptr += bytes_read;
11769 body = read_string (abfd, mac_ptr, &bytes_read);
11770 mac_ptr += bytes_read;
11772 if (! current_file)
11774 /* DWARF violation as no main source is present. */
11775 complaint (&symfile_complaints,
11776 _("debug info with no main source gives macro %s "
11778 macinfo_type == DW_MACINFO_define ?
11780 macinfo_type == DW_MACINFO_undef ?
11781 _("undefinition") :
11782 _("something-or-other"), line, body);
11785 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11786 complaint (&symfile_complaints,
11787 _("debug info gives %s macro %s with %s line %d: %s"),
11788 at_commandline ? _("command-line") : _("in-file"),
11789 macinfo_type == DW_MACINFO_define ?
11791 macinfo_type == DW_MACINFO_undef ?
11792 _("undefinition") :
11793 _("something-or-other"),
11794 line == 0 ? _("zero") : _("non-zero"), line, body);
11796 if (macinfo_type == DW_MACINFO_define)
11797 parse_macro_definition (current_file, line, body);
11798 else if (macinfo_type == DW_MACINFO_undef)
11799 macro_undef (current_file, line, body);
11803 case DW_MACINFO_start_file:
11805 unsigned int bytes_read;
11808 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11809 mac_ptr += bytes_read;
11810 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11811 mac_ptr += bytes_read;
11813 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11814 complaint (&symfile_complaints,
11815 _("debug info gives source %d included "
11816 "from %s at %s line %d"),
11817 file, at_commandline ? _("command-line") : _("file"),
11818 line == 0 ? _("zero") : _("non-zero"), line);
11820 if (at_commandline)
11822 /* This DW_MACINFO_start_file was executed in the pass one. */
11823 at_commandline = 0;
11826 current_file = macro_start_file (file, line,
11827 current_file, comp_dir,
11832 case DW_MACINFO_end_file:
11833 if (! current_file)
11834 complaint (&symfile_complaints,
11835 _("macro debug info has an unmatched `close_file' directive"));
11838 current_file = current_file->included_by;
11839 if (! current_file)
11841 enum dwarf_macinfo_record_type next_type;
11843 /* GCC circa March 2002 doesn't produce the zero
11844 type byte marking the end of the compilation
11845 unit. Complain if it's not there, but exit no
11848 /* Do we at least have room for a macinfo type byte? */
11849 if (mac_ptr >= mac_end)
11851 dwarf2_macros_too_long_complaint ();
11855 /* We don't increment mac_ptr here, so this is just
11857 next_type = read_1_byte (abfd, mac_ptr);
11858 if (next_type != 0)
11859 complaint (&symfile_complaints,
11860 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11867 case DW_MACINFO_vendor_ext:
11869 unsigned int bytes_read;
11873 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11874 mac_ptr += bytes_read;
11875 string = read_string (abfd, mac_ptr, &bytes_read);
11876 mac_ptr += bytes_read;
11878 /* We don't recognize any vendor extensions. */
11882 } while (macinfo_type != 0);
11885 /* Check if the attribute's form is a DW_FORM_block*
11886 if so return true else false. */
11888 attr_form_is_block (struct attribute *attr)
11890 return (attr == NULL ? 0 :
11891 attr->form == DW_FORM_block1
11892 || attr->form == DW_FORM_block2
11893 || attr->form == DW_FORM_block4
11894 || attr->form == DW_FORM_block
11895 || attr->form == DW_FORM_exprloc);
11898 /* Return non-zero if ATTR's value is a section offset --- classes
11899 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11900 You may use DW_UNSND (attr) to retrieve such offsets.
11902 Section 7.5.4, "Attribute Encodings", explains that no attribute
11903 may have a value that belongs to more than one of these classes; it
11904 would be ambiguous if we did, because we use the same forms for all
11907 attr_form_is_section_offset (struct attribute *attr)
11909 return (attr->form == DW_FORM_data4
11910 || attr->form == DW_FORM_data8
11911 || attr->form == DW_FORM_sec_offset);
11915 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11916 zero otherwise. When this function returns true, you can apply
11917 dwarf2_get_attr_constant_value to it.
11919 However, note that for some attributes you must check
11920 attr_form_is_section_offset before using this test. DW_FORM_data4
11921 and DW_FORM_data8 are members of both the constant class, and of
11922 the classes that contain offsets into other debug sections
11923 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11924 that, if an attribute's can be either a constant or one of the
11925 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11926 taken as section offsets, not constants. */
11928 attr_form_is_constant (struct attribute *attr)
11930 switch (attr->form)
11932 case DW_FORM_sdata:
11933 case DW_FORM_udata:
11934 case DW_FORM_data1:
11935 case DW_FORM_data2:
11936 case DW_FORM_data4:
11937 case DW_FORM_data8:
11945 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
11946 struct dwarf2_cu *cu)
11948 if (attr_form_is_section_offset (attr)
11949 /* ".debug_loc" may not exist at all, or the offset may be outside
11950 the section. If so, fall through to the complaint in the
11952 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
11954 struct dwarf2_loclist_baton *baton;
11956 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11957 sizeof (struct dwarf2_loclist_baton));
11958 baton->per_cu = cu->per_cu;
11959 gdb_assert (baton->per_cu);
11961 dwarf2_read_section (dwarf2_per_objfile->objfile,
11962 &dwarf2_per_objfile->loc);
11964 /* We don't know how long the location list is, but make sure we
11965 don't run off the edge of the section. */
11966 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
11967 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
11968 baton->base_address = cu->base_address;
11969 if (cu->base_known == 0)
11970 complaint (&symfile_complaints,
11971 _("Location list used without specifying the CU base address."));
11973 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
11974 SYMBOL_LOCATION_BATON (sym) = baton;
11978 struct dwarf2_locexpr_baton *baton;
11980 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11981 sizeof (struct dwarf2_locexpr_baton));
11982 baton->per_cu = cu->per_cu;
11983 gdb_assert (baton->per_cu);
11985 if (attr_form_is_block (attr))
11987 /* Note that we're just copying the block's data pointer
11988 here, not the actual data. We're still pointing into the
11989 info_buffer for SYM's objfile; right now we never release
11990 that buffer, but when we do clean up properly this may
11992 baton->size = DW_BLOCK (attr)->size;
11993 baton->data = DW_BLOCK (attr)->data;
11997 dwarf2_invalid_attrib_class_complaint ("location description",
11998 SYMBOL_NATURAL_NAME (sym));
12000 baton->data = NULL;
12003 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12004 SYMBOL_LOCATION_BATON (sym) = baton;
12008 /* Return the OBJFILE associated with the compilation unit CU. */
12011 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
12013 struct objfile *objfile = per_cu->psymtab->objfile;
12015 /* Return the master objfile, so that we can report and look up the
12016 correct file containing this variable. */
12017 if (objfile->separate_debug_objfile_backlink)
12018 objfile = objfile->separate_debug_objfile_backlink;
12023 /* Return the address size given in the compilation unit header for CU. */
12026 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
12029 return per_cu->cu->header.addr_size;
12032 /* If the CU is not currently read in, we re-read its header. */
12033 struct objfile *objfile = per_cu->psymtab->objfile;
12034 struct dwarf2_per_objfile *per_objfile
12035 = objfile_data (objfile, dwarf2_objfile_data_key);
12036 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
12037 struct comp_unit_head cu_header;
12039 memset (&cu_header, 0, sizeof cu_header);
12040 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
12041 return cu_header.addr_size;
12045 /* Return the offset size given in the compilation unit header for CU. */
12048 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
12051 return per_cu->cu->header.offset_size;
12054 /* If the CU is not currently read in, we re-read its header. */
12055 struct objfile *objfile = per_cu->psymtab->objfile;
12056 struct dwarf2_per_objfile *per_objfile
12057 = objfile_data (objfile, dwarf2_objfile_data_key);
12058 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
12059 struct comp_unit_head cu_header;
12061 memset (&cu_header, 0, sizeof cu_header);
12062 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
12063 return cu_header.offset_size;
12067 /* Locate the .debug_info compilation unit from CU's objfile which contains
12068 the DIE at OFFSET. Raises an error on failure. */
12070 static struct dwarf2_per_cu_data *
12071 dwarf2_find_containing_comp_unit (unsigned int offset,
12072 struct objfile *objfile)
12074 struct dwarf2_per_cu_data *this_cu;
12078 high = dwarf2_per_objfile->n_comp_units - 1;
12081 int mid = low + (high - low) / 2;
12083 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
12088 gdb_assert (low == high);
12089 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
12092 error (_("Dwarf Error: could not find partial DIE containing "
12093 "offset 0x%lx [in module %s]"),
12094 (long) offset, bfd_get_filename (objfile->obfd));
12096 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
12097 return dwarf2_per_objfile->all_comp_units[low-1];
12101 this_cu = dwarf2_per_objfile->all_comp_units[low];
12102 if (low == dwarf2_per_objfile->n_comp_units - 1
12103 && offset >= this_cu->offset + this_cu->length)
12104 error (_("invalid dwarf2 offset %u"), offset);
12105 gdb_assert (offset < this_cu->offset + this_cu->length);
12110 /* Locate the compilation unit from OBJFILE which is located at exactly
12111 OFFSET. Raises an error on failure. */
12113 static struct dwarf2_per_cu_data *
12114 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
12116 struct dwarf2_per_cu_data *this_cu;
12118 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
12119 if (this_cu->offset != offset)
12120 error (_("no compilation unit with offset %u."), offset);
12124 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
12126 static struct dwarf2_cu *
12127 alloc_one_comp_unit (struct objfile *objfile)
12129 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
12130 cu->objfile = objfile;
12131 obstack_init (&cu->comp_unit_obstack);
12135 /* Release one cached compilation unit, CU. We unlink it from the tree
12136 of compilation units, but we don't remove it from the read_in_chain;
12137 the caller is responsible for that.
12138 NOTE: DATA is a void * because this function is also used as a
12139 cleanup routine. */
12142 free_one_comp_unit (void *data)
12144 struct dwarf2_cu *cu = data;
12146 if (cu->per_cu != NULL)
12147 cu->per_cu->cu = NULL;
12150 obstack_free (&cu->comp_unit_obstack, NULL);
12155 /* This cleanup function is passed the address of a dwarf2_cu on the stack
12156 when we're finished with it. We can't free the pointer itself, but be
12157 sure to unlink it from the cache. Also release any associated storage
12158 and perform cache maintenance.
12160 Only used during partial symbol parsing. */
12163 free_stack_comp_unit (void *data)
12165 struct dwarf2_cu *cu = data;
12167 obstack_free (&cu->comp_unit_obstack, NULL);
12168 cu->partial_dies = NULL;
12170 if (cu->per_cu != NULL)
12172 /* This compilation unit is on the stack in our caller, so we
12173 should not xfree it. Just unlink it. */
12174 cu->per_cu->cu = NULL;
12177 /* If we had a per-cu pointer, then we may have other compilation
12178 units loaded, so age them now. */
12179 age_cached_comp_units ();
12183 /* Free all cached compilation units. */
12186 free_cached_comp_units (void *data)
12188 struct dwarf2_per_cu_data *per_cu, **last_chain;
12190 per_cu = dwarf2_per_objfile->read_in_chain;
12191 last_chain = &dwarf2_per_objfile->read_in_chain;
12192 while (per_cu != NULL)
12194 struct dwarf2_per_cu_data *next_cu;
12196 next_cu = per_cu->cu->read_in_chain;
12198 free_one_comp_unit (per_cu->cu);
12199 *last_chain = next_cu;
12205 /* Increase the age counter on each cached compilation unit, and free
12206 any that are too old. */
12209 age_cached_comp_units (void)
12211 struct dwarf2_per_cu_data *per_cu, **last_chain;
12213 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
12214 per_cu = dwarf2_per_objfile->read_in_chain;
12215 while (per_cu != NULL)
12217 per_cu->cu->last_used ++;
12218 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
12219 dwarf2_mark (per_cu->cu);
12220 per_cu = per_cu->cu->read_in_chain;
12223 per_cu = dwarf2_per_objfile->read_in_chain;
12224 last_chain = &dwarf2_per_objfile->read_in_chain;
12225 while (per_cu != NULL)
12227 struct dwarf2_per_cu_data *next_cu;
12229 next_cu = per_cu->cu->read_in_chain;
12231 if (!per_cu->cu->mark)
12233 free_one_comp_unit (per_cu->cu);
12234 *last_chain = next_cu;
12237 last_chain = &per_cu->cu->read_in_chain;
12243 /* Remove a single compilation unit from the cache. */
12246 free_one_cached_comp_unit (void *target_cu)
12248 struct dwarf2_per_cu_data *per_cu, **last_chain;
12250 per_cu = dwarf2_per_objfile->read_in_chain;
12251 last_chain = &dwarf2_per_objfile->read_in_chain;
12252 while (per_cu != NULL)
12254 struct dwarf2_per_cu_data *next_cu;
12256 next_cu = per_cu->cu->read_in_chain;
12258 if (per_cu->cu == target_cu)
12260 free_one_comp_unit (per_cu->cu);
12261 *last_chain = next_cu;
12265 last_chain = &per_cu->cu->read_in_chain;
12271 /* Release all extra memory associated with OBJFILE. */
12274 dwarf2_free_objfile (struct objfile *objfile)
12276 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
12278 if (dwarf2_per_objfile == NULL)
12281 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
12282 free_cached_comp_units (NULL);
12284 /* Everything else should be on the objfile obstack. */
12287 /* A pair of DIE offset and GDB type pointer. We store these
12288 in a hash table separate from the DIEs, and preserve them
12289 when the DIEs are flushed out of cache. */
12291 struct dwarf2_offset_and_type
12293 unsigned int offset;
12297 /* Hash function for a dwarf2_offset_and_type. */
12300 offset_and_type_hash (const void *item)
12302 const struct dwarf2_offset_and_type *ofs = item;
12304 return ofs->offset;
12307 /* Equality function for a dwarf2_offset_and_type. */
12310 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
12312 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
12313 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
12315 return ofs_lhs->offset == ofs_rhs->offset;
12318 /* Set the type associated with DIE to TYPE. Save it in CU's hash
12319 table if necessary. For convenience, return TYPE.
12321 The DIEs reading must have careful ordering to:
12322 * Not cause infite loops trying to read in DIEs as a prerequisite for
12323 reading current DIE.
12324 * Not trying to dereference contents of still incompletely read in types
12325 while reading in other DIEs.
12326 * Enable referencing still incompletely read in types just by a pointer to
12327 the type without accessing its fields.
12329 Therefore caller should follow these rules:
12330 * Try to fetch any prerequisite types we may need to build this DIE type
12331 before building the type and calling set_die_type.
12332 * After building typer call set_die_type for current DIE as soon as
12333 possible before fetching more types to complete the current type.
12334 * Make the type as complete as possible before fetching more types. */
12336 static struct type *
12337 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
12339 struct dwarf2_offset_and_type **slot, ofs;
12341 /* For Ada types, make sure that the gnat-specific data is always
12342 initialized (if not already set). There are a few types where
12343 we should not be doing so, because the type-specific area is
12344 already used to hold some other piece of info (eg: TYPE_CODE_FLT
12345 where the type-specific area is used to store the floatformat).
12346 But this is not a problem, because the gnat-specific information
12347 is actually not needed for these types. */
12348 if (need_gnat_info (cu)
12349 && TYPE_CODE (type) != TYPE_CODE_FUNC
12350 && TYPE_CODE (type) != TYPE_CODE_FLT
12351 && !HAVE_GNAT_AUX_INFO (type))
12352 INIT_GNAT_SPECIFIC (type);
12354 if (cu->type_hash == NULL)
12356 gdb_assert (cu->per_cu != NULL);
12357 cu->per_cu->type_hash
12358 = htab_create_alloc_ex (cu->header.length / 24,
12359 offset_and_type_hash,
12360 offset_and_type_eq,
12362 &cu->objfile->objfile_obstack,
12363 hashtab_obstack_allocate,
12364 dummy_obstack_deallocate);
12365 cu->type_hash = cu->per_cu->type_hash;
12368 ofs.offset = die->offset;
12370 slot = (struct dwarf2_offset_and_type **)
12371 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
12373 complaint (&symfile_complaints,
12374 _("A problem internal to GDB: DIE 0x%x has type already set"),
12376 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
12381 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
12382 not have a saved type. */
12384 static struct type *
12385 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
12387 struct dwarf2_offset_and_type *slot, ofs;
12388 htab_t type_hash = cu->type_hash;
12390 if (type_hash == NULL)
12393 ofs.offset = die->offset;
12394 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
12401 /* Add a dependence relationship from CU to REF_PER_CU. */
12404 dwarf2_add_dependence (struct dwarf2_cu *cu,
12405 struct dwarf2_per_cu_data *ref_per_cu)
12409 if (cu->dependencies == NULL)
12411 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
12412 NULL, &cu->comp_unit_obstack,
12413 hashtab_obstack_allocate,
12414 dummy_obstack_deallocate);
12416 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
12418 *slot = ref_per_cu;
12421 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12422 Set the mark field in every compilation unit in the
12423 cache that we must keep because we are keeping CU. */
12426 dwarf2_mark_helper (void **slot, void *data)
12428 struct dwarf2_per_cu_data *per_cu;
12430 per_cu = (struct dwarf2_per_cu_data *) *slot;
12431 if (per_cu->cu->mark)
12433 per_cu->cu->mark = 1;
12435 if (per_cu->cu->dependencies != NULL)
12436 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
12441 /* Set the mark field in CU and in every other compilation unit in the
12442 cache that we must keep because we are keeping CU. */
12445 dwarf2_mark (struct dwarf2_cu *cu)
12450 if (cu->dependencies != NULL)
12451 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
12455 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
12459 per_cu->cu->mark = 0;
12460 per_cu = per_cu->cu->read_in_chain;
12464 /* Trivial hash function for partial_die_info: the hash value of a DIE
12465 is its offset in .debug_info for this objfile. */
12468 partial_die_hash (const void *item)
12470 const struct partial_die_info *part_die = item;
12472 return part_die->offset;
12475 /* Trivial comparison function for partial_die_info structures: two DIEs
12476 are equal if they have the same offset. */
12479 partial_die_eq (const void *item_lhs, const void *item_rhs)
12481 const struct partial_die_info *part_die_lhs = item_lhs;
12482 const struct partial_die_info *part_die_rhs = item_rhs;
12484 return part_die_lhs->offset == part_die_rhs->offset;
12487 static struct cmd_list_element *set_dwarf2_cmdlist;
12488 static struct cmd_list_element *show_dwarf2_cmdlist;
12491 set_dwarf2_cmd (char *args, int from_tty)
12493 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
12497 show_dwarf2_cmd (char *args, int from_tty)
12499 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
12502 /* If section described by INFO was mmapped, munmap it now. */
12505 munmap_section_buffer (struct dwarf2_section_info *info)
12507 if (info->was_mmapped)
12510 intptr_t begin = (intptr_t) info->buffer;
12511 intptr_t map_begin = begin & ~(pagesize - 1);
12512 size_t map_length = info->size + begin - map_begin;
12514 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
12516 /* Without HAVE_MMAP, we should never be here to begin with. */
12522 /* munmap debug sections for OBJFILE, if necessary. */
12525 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
12527 struct dwarf2_per_objfile *data = d;
12529 munmap_section_buffer (&data->info);
12530 munmap_section_buffer (&data->abbrev);
12531 munmap_section_buffer (&data->line);
12532 munmap_section_buffer (&data->str);
12533 munmap_section_buffer (&data->macinfo);
12534 munmap_section_buffer (&data->ranges);
12535 munmap_section_buffer (&data->loc);
12536 munmap_section_buffer (&data->frame);
12537 munmap_section_buffer (&data->eh_frame);
12540 int dwarf2_always_disassemble;
12543 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
12544 struct cmd_list_element *c, const char *value)
12546 fprintf_filtered (file, _("\
12547 Whether to always disassemble DWARF expressions is %s.\n"),
12551 void _initialize_dwarf2_read (void);
12554 _initialize_dwarf2_read (void)
12556 dwarf2_objfile_data_key
12557 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
12559 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
12560 Set DWARF 2 specific variables.\n\
12561 Configure DWARF 2 variables such as the cache size"),
12562 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
12563 0/*allow-unknown*/, &maintenance_set_cmdlist);
12565 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
12566 Show DWARF 2 specific variables\n\
12567 Show DWARF 2 variables such as the cache size"),
12568 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
12569 0/*allow-unknown*/, &maintenance_show_cmdlist);
12571 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
12572 &dwarf2_max_cache_age, _("\
12573 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12574 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12575 A higher limit means that cached compilation units will be stored\n\
12576 in memory longer, and more total memory will be used. Zero disables\n\
12577 caching, which can slow down startup."),
12579 show_dwarf2_max_cache_age,
12580 &set_dwarf2_cmdlist,
12581 &show_dwarf2_cmdlist);
12583 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
12584 &dwarf2_always_disassemble, _("\
12585 Set whether `info address' always disassembles DWARF expressions."), _("\
12586 Show whether `info address' always disassembles DWARF expressions."), _("\
12587 When enabled, DWARF expressions are always printed in an assembly-like\n\
12588 syntax. When disabled, expressions will be printed in a more\n\
12589 conversational style, when possible."),
12591 show_dwarf2_always_disassemble,
12592 &set_dwarf2_cmdlist,
12593 &show_dwarf2_cmdlist);
12595 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
12596 Set debugging of the dwarf2 DIE reader."), _("\
12597 Show debugging of the dwarf2 DIE reader."), _("\
12598 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12599 The value is the maximum depth to print."),
12602 &setdebuglist, &showdebuglist);