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.
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 iff currently read in. */
341 struct dwarf2_cu *cu;
343 /* If full symbols for this CU have been read in, then this field
344 holds a map of DIE offsets to types. It isn't always possible
345 to reconstruct this information later, so we have to preserve
349 /* The partial symbol table associated with this compilation unit,
350 or NULL for partial units (which do not have an associated
352 struct partial_symtab *psymtab;
355 /* Entry in the signatured_types hash table. */
357 struct signatured_type
361 /* Offset in .debug_types of the TU (type_unit) for this type. */
364 /* Offset in .debug_types of the type defined by this TU. */
365 unsigned int type_offset;
367 /* The CU(/TU) of this type. */
368 struct dwarf2_per_cu_data per_cu;
371 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
372 which are used for both .debug_info and .debug_types dies.
373 All parameters here are unchanging for the life of the call.
374 This struct exists to abstract away the constant parameters of
377 struct die_reader_specs
379 /* The bfd of this objfile. */
382 /* The CU of the DIE we are parsing. */
383 struct dwarf2_cu *cu;
385 /* Pointer to start of section buffer.
386 This is either the start of .debug_info or .debug_types. */
387 const gdb_byte *buffer;
390 /* The line number information for a compilation unit (found in the
391 .debug_line section) begins with a "statement program header",
392 which contains the following information. */
395 unsigned int total_length;
396 unsigned short version;
397 unsigned int header_length;
398 unsigned char minimum_instruction_length;
399 unsigned char maximum_ops_per_instruction;
400 unsigned char default_is_stmt;
402 unsigned char line_range;
403 unsigned char opcode_base;
405 /* standard_opcode_lengths[i] is the number of operands for the
406 standard opcode whose value is i. This means that
407 standard_opcode_lengths[0] is unused, and the last meaningful
408 element is standard_opcode_lengths[opcode_base - 1]. */
409 unsigned char *standard_opcode_lengths;
411 /* The include_directories table. NOTE! These strings are not
412 allocated with xmalloc; instead, they are pointers into
413 debug_line_buffer. If you try to free them, `free' will get
415 unsigned int num_include_dirs, include_dirs_size;
418 /* The file_names table. NOTE! These strings are not allocated
419 with xmalloc; instead, they are pointers into debug_line_buffer.
420 Don't try to free them directly. */
421 unsigned int num_file_names, file_names_size;
425 unsigned int dir_index;
426 unsigned int mod_time;
428 int included_p; /* Non-zero if referenced by the Line Number Program. */
429 struct symtab *symtab; /* The associated symbol table, if any. */
432 /* The start and end of the statement program following this
433 header. These point into dwarf2_per_objfile->line_buffer. */
434 gdb_byte *statement_program_start, *statement_program_end;
437 /* When we construct a partial symbol table entry we only
438 need this much information. */
439 struct partial_die_info
441 /* Offset of this DIE. */
444 /* DWARF-2 tag for this DIE. */
445 ENUM_BITFIELD(dwarf_tag) tag : 16;
447 /* Assorted flags describing the data found in this DIE. */
448 unsigned int has_children : 1;
449 unsigned int is_external : 1;
450 unsigned int is_declaration : 1;
451 unsigned int has_type : 1;
452 unsigned int has_specification : 1;
453 unsigned int has_pc_info : 1;
455 /* Flag set if the SCOPE field of this structure has been
457 unsigned int scope_set : 1;
459 /* Flag set if the DIE has a byte_size attribute. */
460 unsigned int has_byte_size : 1;
462 /* The name of this DIE. Normally the value of DW_AT_name, but
463 sometimes a default name for unnamed DIEs. */
466 /* The scope to prepend to our children. This is generally
467 allocated on the comp_unit_obstack, so will disappear
468 when this compilation unit leaves the cache. */
471 /* The location description associated with this DIE, if any. */
472 struct dwarf_block *locdesc;
474 /* If HAS_PC_INFO, the PC range associated with this DIE. */
478 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
479 DW_AT_sibling, if any. */
482 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
483 DW_AT_specification (or DW_AT_abstract_origin or
485 unsigned int spec_offset;
487 /* Pointers to this DIE's parent, first child, and next sibling,
489 struct partial_die_info *die_parent, *die_child, *die_sibling;
492 /* This data structure holds the information of an abbrev. */
495 unsigned int number; /* number identifying abbrev */
496 enum dwarf_tag tag; /* dwarf tag */
497 unsigned short has_children; /* boolean */
498 unsigned short num_attrs; /* number of attributes */
499 struct attr_abbrev *attrs; /* an array of attribute descriptions */
500 struct abbrev_info *next; /* next in chain */
505 ENUM_BITFIELD(dwarf_attribute) name : 16;
506 ENUM_BITFIELD(dwarf_form) form : 16;
509 /* Attributes have a name and a value */
512 ENUM_BITFIELD(dwarf_attribute) name : 16;
513 ENUM_BITFIELD(dwarf_form) form : 15;
515 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
516 field should be in u.str (existing only for DW_STRING) but it is kept
517 here for better struct attribute alignment. */
518 unsigned int string_is_canonical : 1;
523 struct dwarf_block *blk;
527 struct signatured_type *signatured_type;
532 /* This data structure holds a complete die structure. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag) tag : 16;
538 /* Number of attributes */
539 unsigned short num_attrs;
544 /* Offset in .debug_info or .debug_types section. */
547 /* The dies in a compilation unit form an n-ary tree. PARENT
548 points to this die's parent; CHILD points to the first child of
549 this node; and all the children of a given node are chained
550 together via their SIBLING fields, terminated by a die whose
552 struct die_info *child; /* Its first child, if any. */
553 struct die_info *sibling; /* Its next sibling, if any. */
554 struct die_info *parent; /* Its parent, if any. */
556 /* An array of attributes, with NUM_ATTRS elements. There may be
557 zero, but it's not common and zero-sized arrays are not
558 sufficiently portable C. */
559 struct attribute attrs[1];
562 struct function_range
565 CORE_ADDR lowpc, highpc;
567 struct function_range *next;
570 /* Get at parts of an attribute structure */
572 #define DW_STRING(attr) ((attr)->u.str)
573 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
574 #define DW_UNSND(attr) ((attr)->u.unsnd)
575 #define DW_BLOCK(attr) ((attr)->u.blk)
576 #define DW_SND(attr) ((attr)->u.snd)
577 #define DW_ADDR(attr) ((attr)->u.addr)
578 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
580 /* Blocks are a bunch of untyped bytes. */
587 #ifndef ATTR_ALLOC_CHUNK
588 #define ATTR_ALLOC_CHUNK 4
591 /* Allocate fields for structs, unions and enums in this size. */
592 #ifndef DW_FIELD_ALLOC_CHUNK
593 #define DW_FIELD_ALLOC_CHUNK 4
596 /* A zeroed version of a partial die for initialization purposes. */
597 static struct partial_die_info zeroed_partial_die;
599 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
600 but this would require a corresponding change in unpack_field_as_long
602 static int bits_per_byte = 8;
604 /* The routines that read and process dies for a C struct or C++ class
605 pass lists of data member fields and lists of member function fields
606 in an instance of a field_info structure, as defined below. */
609 /* List of data member and baseclasses fields. */
612 struct nextfield *next;
617 *fields, *baseclasses;
619 /* Number of fields (including baseclasses). */
622 /* Number of baseclasses. */
625 /* Set if the accesibility of one of the fields is not public. */
626 int non_public_fields;
628 /* Member function fields array, entries are allocated in the order they
629 are encountered in the object file. */
632 struct nextfnfield *next;
633 struct fn_field fnfield;
637 /* Member function fieldlist array, contains name of possibly overloaded
638 member function, number of overloaded member functions and a pointer
639 to the head of the member function field chain. */
644 struct nextfnfield *head;
648 /* Number of entries in the fnfieldlists array. */
652 /* One item on the queue of compilation units to read in full symbols
654 struct dwarf2_queue_item
656 struct dwarf2_per_cu_data *per_cu;
657 struct dwarf2_queue_item *next;
660 /* The current queue. */
661 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
663 /* Loaded secondary compilation units are kept in memory until they
664 have not been referenced for the processing of this many
665 compilation units. Set this to zero to disable caching. Cache
666 sizes of up to at least twenty will improve startup time for
667 typical inter-CU-reference binaries, at an obvious memory cost. */
668 static int dwarf2_max_cache_age = 5;
670 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
671 struct cmd_list_element *c, const char *value)
673 fprintf_filtered (file, _("\
674 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
679 /* Various complaints about symbol reading that don't abort the process */
682 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
684 complaint (&symfile_complaints,
685 _("statement list doesn't fit in .debug_line section"));
689 dwarf2_debug_line_missing_file_complaint (void)
691 complaint (&symfile_complaints,
692 _(".debug_line section has line data without a file"));
696 dwarf2_debug_line_missing_end_sequence_complaint (void)
698 complaint (&symfile_complaints,
699 _(".debug_line section has line program sequence without an end"));
703 dwarf2_complex_location_expr_complaint (void)
705 complaint (&symfile_complaints, _("location expression too complex"));
709 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
712 complaint (&symfile_complaints,
713 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
718 dwarf2_macros_too_long_complaint (void)
720 complaint (&symfile_complaints,
721 _("macro info runs off end of `.debug_macinfo' section"));
725 dwarf2_macro_malformed_definition_complaint (const char *arg1)
727 complaint (&symfile_complaints,
728 _("macro debug info contains a malformed macro definition:\n`%s'"),
733 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
735 complaint (&symfile_complaints,
736 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
739 /* local function prototypes */
741 static void dwarf2_locate_sections (bfd *, asection *, void *);
743 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
746 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
748 struct partial_symtab *);
750 static void dwarf2_build_psymtabs_hard (struct objfile *);
752 static void scan_partial_symbols (struct partial_die_info *,
753 CORE_ADDR *, CORE_ADDR *,
754 int, struct dwarf2_cu *);
756 static void add_partial_symbol (struct partial_die_info *,
759 static void add_partial_namespace (struct partial_die_info *pdi,
760 CORE_ADDR *lowpc, CORE_ADDR *highpc,
761 int need_pc, struct dwarf2_cu *cu);
763 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
764 CORE_ADDR *highpc, int need_pc,
765 struct dwarf2_cu *cu);
767 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
768 struct dwarf2_cu *cu);
770 static void add_partial_subprogram (struct partial_die_info *pdi,
771 CORE_ADDR *lowpc, CORE_ADDR *highpc,
772 int need_pc, struct dwarf2_cu *cu);
774 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
775 gdb_byte *buffer, gdb_byte *info_ptr,
776 bfd *abfd, struct dwarf2_cu *cu);
778 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
780 static void psymtab_to_symtab_1 (struct partial_symtab *);
782 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
784 static void dwarf2_free_abbrev_table (void *);
786 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
789 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
792 static struct partial_die_info *load_partial_dies (bfd *,
793 gdb_byte *, gdb_byte *,
794 int, struct dwarf2_cu *);
796 static gdb_byte *read_partial_die (struct partial_die_info *,
797 struct abbrev_info *abbrev,
799 gdb_byte *, gdb_byte *,
802 static struct partial_die_info *find_partial_die (unsigned int,
805 static void fixup_partial_die (struct partial_die_info *,
808 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
809 bfd *, gdb_byte *, struct dwarf2_cu *);
811 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
812 bfd *, gdb_byte *, struct dwarf2_cu *);
814 static unsigned int read_1_byte (bfd *, gdb_byte *);
816 static int read_1_signed_byte (bfd *, gdb_byte *);
818 static unsigned int read_2_bytes (bfd *, gdb_byte *);
820 static unsigned int read_4_bytes (bfd *, gdb_byte *);
822 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
824 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
827 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
829 static LONGEST read_checked_initial_length_and_offset
830 (bfd *, gdb_byte *, const struct comp_unit_head *,
831 unsigned int *, unsigned int *);
833 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
836 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
838 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
840 static char *read_string (bfd *, gdb_byte *, unsigned int *);
842 static char *read_indirect_string (bfd *, gdb_byte *,
843 const struct comp_unit_head *,
846 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
848 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
850 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
852 static void set_cu_language (unsigned int, struct dwarf2_cu *);
854 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
857 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
861 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
862 struct dwarf2_cu *cu);
864 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
866 static struct die_info *die_specification (struct die_info *die,
867 struct dwarf2_cu **);
869 static void free_line_header (struct line_header *lh);
871 static void add_file_name (struct line_header *, char *, unsigned int,
872 unsigned int, unsigned int);
874 static struct line_header *(dwarf_decode_line_header
875 (unsigned int offset,
876 bfd *abfd, struct dwarf2_cu *cu));
878 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
879 struct dwarf2_cu *, struct partial_symtab *);
881 static void dwarf2_start_subfile (char *, char *, char *);
883 static struct symbol *new_symbol (struct die_info *, struct type *,
886 static void dwarf2_const_value (struct attribute *, struct symbol *,
889 static void dwarf2_const_value_data (struct attribute *attr,
893 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
895 static int need_gnat_info (struct dwarf2_cu *);
897 static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *);
899 static void set_descriptive_type (struct type *, struct die_info *,
902 static struct type *die_containing_type (struct die_info *,
905 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
907 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
909 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
911 static char *typename_concat (struct obstack *,
916 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
918 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
920 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
922 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
924 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
925 struct dwarf2_cu *, struct partial_symtab *);
927 static int dwarf2_get_pc_bounds (struct die_info *,
928 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
929 struct partial_symtab *);
931 static void get_scope_pc_bounds (struct die_info *,
932 CORE_ADDR *, CORE_ADDR *,
935 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
936 CORE_ADDR, struct dwarf2_cu *);
938 static void dwarf2_add_field (struct field_info *, struct die_info *,
941 static void dwarf2_attach_fields_to_type (struct field_info *,
942 struct type *, struct dwarf2_cu *);
944 static void dwarf2_add_member_fn (struct field_info *,
945 struct die_info *, struct type *,
948 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
949 struct type *, struct dwarf2_cu *);
951 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
953 static void read_common_block (struct die_info *, struct dwarf2_cu *);
955 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
957 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
959 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
961 static const char *namespace_name (struct die_info *die,
962 int *is_anonymous, struct dwarf2_cu *);
964 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
966 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
968 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
971 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
973 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
975 gdb_byte **new_info_ptr,
976 struct die_info *parent);
978 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
980 gdb_byte **new_info_ptr,
981 struct die_info *parent);
983 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
985 gdb_byte **new_info_ptr,
986 struct die_info *parent);
988 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
989 struct die_info **, gdb_byte *,
992 static void process_die (struct die_info *, struct dwarf2_cu *);
994 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
997 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
999 static struct die_info *dwarf2_extension (struct die_info *die,
1000 struct dwarf2_cu **);
1002 static char *dwarf_tag_name (unsigned int);
1004 static char *dwarf_attr_name (unsigned int);
1006 static char *dwarf_form_name (unsigned int);
1008 static char *dwarf_stack_op_name (unsigned int);
1010 static char *dwarf_bool_name (unsigned int);
1012 static char *dwarf_type_encoding_name (unsigned int);
1015 static char *dwarf_cfi_name (unsigned int);
1018 static struct die_info *sibling_die (struct die_info *);
1020 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1022 static void dump_die_for_error (struct die_info *);
1024 static void dump_die_1 (struct ui_file *, int level, int max_level,
1027 /*static*/ void dump_die (struct die_info *, int max_level);
1029 static void store_in_ref_table (struct die_info *,
1030 struct dwarf2_cu *);
1032 static int is_ref_attr (struct attribute *);
1034 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1036 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1038 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1040 struct dwarf2_cu **);
1042 static struct die_info *follow_die_ref (struct die_info *,
1044 struct dwarf2_cu **);
1046 static struct die_info *follow_die_sig (struct die_info *,
1048 struct dwarf2_cu **);
1050 static void read_signatured_type_at_offset (struct objfile *objfile,
1051 unsigned int offset);
1053 static void read_signatured_type (struct objfile *,
1054 struct signatured_type *type_sig);
1056 /* memory allocation interface */
1058 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1060 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1062 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1064 static void initialize_cu_func_list (struct dwarf2_cu *);
1066 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1067 struct dwarf2_cu *);
1069 static void dwarf_decode_macros (struct line_header *, unsigned int,
1070 char *, bfd *, struct dwarf2_cu *);
1072 static int attr_form_is_block (struct attribute *);
1074 static int attr_form_is_section_offset (struct attribute *);
1076 static int attr_form_is_constant (struct attribute *);
1078 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1080 struct dwarf2_cu *cu);
1082 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1083 struct abbrev_info *abbrev,
1084 struct dwarf2_cu *cu);
1086 static void free_stack_comp_unit (void *);
1088 static hashval_t partial_die_hash (const void *item);
1090 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1092 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1093 (unsigned int offset, struct objfile *objfile);
1095 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1096 (unsigned int offset, struct objfile *objfile);
1098 static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
1100 static void free_one_comp_unit (void *);
1102 static void free_cached_comp_units (void *);
1104 static void age_cached_comp_units (void);
1106 static void free_one_cached_comp_unit (void *);
1108 static struct type *set_die_type (struct die_info *, struct type *,
1109 struct dwarf2_cu *);
1111 static void create_all_comp_units (struct objfile *);
1113 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1116 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1118 static void dwarf2_add_dependence (struct dwarf2_cu *,
1119 struct dwarf2_per_cu_data *);
1121 static void dwarf2_mark (struct dwarf2_cu *);
1123 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1125 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1127 /* Try to locate the sections we need for DWARF 2 debugging
1128 information and return true if we have enough to do something. */
1131 dwarf2_has_info (struct objfile *objfile)
1133 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1134 if (!dwarf2_per_objfile)
1136 /* Initialize per-objfile state. */
1137 struct dwarf2_per_objfile *data
1138 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1139 memset (data, 0, sizeof (*data));
1140 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1141 dwarf2_per_objfile = data;
1143 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1144 dwarf2_per_objfile->objfile = objfile;
1146 return (dwarf2_per_objfile->info.asection != NULL
1147 && dwarf2_per_objfile->abbrev.asection != NULL);
1150 /* When loading sections, we can either look for ".<name>", or for
1151 * ".z<name>", which indicates a compressed section. */
1154 section_is_p (const char *section_name, const char *name)
1156 return (section_name[0] == '.'
1157 && (strcmp (section_name + 1, name) == 0
1158 || (section_name[1] == 'z'
1159 && strcmp (section_name + 2, name) == 0)));
1162 /* This function is mapped across the sections and remembers the
1163 offset and size of each of the debugging sections we are interested
1167 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1169 if (section_is_p (sectp->name, INFO_SECTION))
1171 dwarf2_per_objfile->info.asection = sectp;
1172 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1174 else if (section_is_p (sectp->name, ABBREV_SECTION))
1176 dwarf2_per_objfile->abbrev.asection = sectp;
1177 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1179 else if (section_is_p (sectp->name, LINE_SECTION))
1181 dwarf2_per_objfile->line.asection = sectp;
1182 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1184 else if (section_is_p (sectp->name, LOC_SECTION))
1186 dwarf2_per_objfile->loc.asection = sectp;
1187 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1189 else if (section_is_p (sectp->name, MACINFO_SECTION))
1191 dwarf2_per_objfile->macinfo.asection = sectp;
1192 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1194 else if (section_is_p (sectp->name, STR_SECTION))
1196 dwarf2_per_objfile->str.asection = sectp;
1197 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1199 else if (section_is_p (sectp->name, FRAME_SECTION))
1201 dwarf2_per_objfile->frame.asection = sectp;
1202 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1204 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1206 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1207 if (aflag & SEC_HAS_CONTENTS)
1209 dwarf2_per_objfile->eh_frame.asection = sectp;
1210 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1213 else if (section_is_p (sectp->name, RANGES_SECTION))
1215 dwarf2_per_objfile->ranges.asection = sectp;
1216 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1218 else if (section_is_p (sectp->name, TYPES_SECTION))
1220 dwarf2_per_objfile->types.asection = sectp;
1221 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1224 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1225 && bfd_section_vma (abfd, sectp) == 0)
1226 dwarf2_per_objfile->has_section_at_zero = 1;
1229 /* Decompress a section that was compressed using zlib. Store the
1230 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1233 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1234 gdb_byte **outbuf, bfd_size_type *outsize)
1236 bfd *abfd = objfile->obfd;
1238 error (_("Support for zlib-compressed DWARF data (from '%s') "
1239 "is disabled in this copy of GDB"),
1240 bfd_get_filename (abfd));
1242 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1243 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1244 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1245 bfd_size_type uncompressed_size;
1246 gdb_byte *uncompressed_buffer;
1249 int header_size = 12;
1251 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1252 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1253 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1254 bfd_get_filename (abfd));
1256 /* Read the zlib header. In this case, it should be "ZLIB" followed
1257 by the uncompressed section size, 8 bytes in big-endian order. */
1258 if (compressed_size < header_size
1259 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1260 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1261 bfd_get_filename (abfd));
1262 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1263 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1264 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1265 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1266 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1267 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1268 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1269 uncompressed_size += compressed_buffer[11];
1271 /* It is possible the section consists of several compressed
1272 buffers concatenated together, so we uncompress in a loop. */
1276 strm.avail_in = compressed_size - header_size;
1277 strm.next_in = (Bytef*) compressed_buffer + header_size;
1278 strm.avail_out = uncompressed_size;
1279 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1281 rc = inflateInit (&strm);
1282 while (strm.avail_in > 0)
1285 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1286 bfd_get_filename (abfd), rc);
1287 strm.next_out = ((Bytef*) uncompressed_buffer
1288 + (uncompressed_size - strm.avail_out));
1289 rc = inflate (&strm, Z_FINISH);
1290 if (rc != Z_STREAM_END)
1291 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1292 bfd_get_filename (abfd), rc);
1293 rc = inflateReset (&strm);
1295 rc = inflateEnd (&strm);
1297 || strm.avail_out != 0)
1298 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1299 bfd_get_filename (abfd), rc);
1301 do_cleanups (cleanup);
1302 *outbuf = uncompressed_buffer;
1303 *outsize = uncompressed_size;
1307 /* Read the contents of the section SECTP from object file specified by
1308 OBJFILE, store info about the section into INFO.
1309 If the section is compressed, uncompress it before returning. */
1312 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1314 bfd *abfd = objfile->obfd;
1315 asection *sectp = info->asection;
1316 gdb_byte *buf, *retbuf;
1317 unsigned char header[4];
1321 info->buffer = NULL;
1322 info->was_mmapped = 0;
1325 if (info->asection == NULL || info->size == 0)
1328 /* Check if the file has a 4-byte header indicating compression. */
1329 if (info->size > sizeof (header)
1330 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1331 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1333 /* Upon decompression, update the buffer and its size. */
1334 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1336 zlib_decompress_section (objfile, sectp, &info->buffer,
1344 pagesize = getpagesize ();
1346 /* Only try to mmap sections which are large enough: we don't want to
1347 waste space due to fragmentation. Also, only try mmap for sections
1348 without relocations. */
1350 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1352 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1353 size_t map_length = info->size + sectp->filepos - pg_offset;
1354 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1355 MAP_PRIVATE, pg_offset);
1357 if (retbuf != MAP_FAILED)
1359 info->was_mmapped = 1;
1360 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1361 #if HAVE_POSIX_MADVISE
1362 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1369 /* If we get here, we are a normal, not-compressed section. */
1371 = obstack_alloc (&objfile->objfile_obstack, info->size);
1373 /* When debugging .o files, we may need to apply relocations; see
1374 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1375 We never compress sections in .o files, so we only need to
1376 try this when the section is not compressed. */
1377 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1380 info->buffer = retbuf;
1384 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1385 || bfd_bread (buf, info->size, abfd) != info->size)
1386 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1387 bfd_get_filename (abfd));
1390 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1394 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1395 asection **sectp, gdb_byte **bufp,
1396 bfd_size_type *sizep)
1398 struct dwarf2_per_objfile *data
1399 = objfile_data (objfile, dwarf2_objfile_data_key);
1400 struct dwarf2_section_info *info;
1402 /* We may see an objfile without any DWARF, in which case we just
1411 if (section_is_p (section_name, EH_FRAME_SECTION))
1412 info = &data->eh_frame;
1413 else if (section_is_p (section_name, FRAME_SECTION))
1414 info = &data->frame;
1418 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1419 /* We haven't read this section in yet. Do it now. */
1420 dwarf2_read_section (objfile, info);
1422 *sectp = info->asection;
1423 *bufp = info->buffer;
1424 *sizep = info->size;
1427 /* Build a partial symbol table. */
1430 dwarf2_build_psymtabs (struct objfile *objfile)
1432 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
1434 init_psymbol_list (objfile, 1024);
1437 dwarf2_build_psymtabs_hard (objfile);
1440 /* Return TRUE if OFFSET is within CU_HEADER. */
1443 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
1445 unsigned int bottom = cu_header->offset;
1446 unsigned int top = (cu_header->offset
1448 + cu_header->initial_length_size);
1449 return (offset >= bottom && offset < top);
1452 /* Read in the comp unit header information from the debug_info at info_ptr.
1453 NOTE: This leaves members offset, first_die_offset to be filled in
1457 read_comp_unit_head (struct comp_unit_head *cu_header,
1458 gdb_byte *info_ptr, bfd *abfd)
1461 unsigned int bytes_read;
1463 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
1464 cu_header->initial_length_size = bytes_read;
1465 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
1466 info_ptr += bytes_read;
1467 cu_header->version = read_2_bytes (abfd, info_ptr);
1469 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1471 info_ptr += bytes_read;
1472 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1474 signed_addr = bfd_get_sign_extend_vma (abfd);
1475 if (signed_addr < 0)
1476 internal_error (__FILE__, __LINE__,
1477 _("read_comp_unit_head: dwarf from non elf file"));
1478 cu_header->signed_addr_p = signed_addr;
1484 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
1485 gdb_byte *buffer, unsigned int buffer_size,
1488 gdb_byte *beg_of_comp_unit = info_ptr;
1490 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1492 if (header->version != 2 && header->version != 3 && header->version != 4)
1493 error (_("Dwarf Error: wrong version in compilation unit header "
1494 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
1495 bfd_get_filename (abfd));
1497 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
1498 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1499 "(offset 0x%lx + 6) [in module %s]"),
1500 (long) header->abbrev_offset,
1501 (long) (beg_of_comp_unit - buffer),
1502 bfd_get_filename (abfd));
1504 if (beg_of_comp_unit + header->length + header->initial_length_size
1505 > buffer + buffer_size)
1506 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1507 "(offset 0x%lx + 0) [in module %s]"),
1508 (long) header->length,
1509 (long) (beg_of_comp_unit - buffer),
1510 bfd_get_filename (abfd));
1515 /* Read in the types comp unit header information from .debug_types entry at
1516 types_ptr. The result is a pointer to one past the end of the header. */
1519 read_type_comp_unit_head (struct comp_unit_head *cu_header,
1520 ULONGEST *signature,
1521 gdb_byte *types_ptr, bfd *abfd)
1523 unsigned int bytes_read;
1524 gdb_byte *initial_types_ptr = types_ptr;
1526 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->types);
1527 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
1529 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
1531 *signature = read_8_bytes (abfd, types_ptr);
1533 types_ptr += cu_header->offset_size;
1534 cu_header->first_die_offset = types_ptr - initial_types_ptr;
1539 /* Allocate a new partial symtab for file named NAME and mark this new
1540 partial symtab as being an include of PST. */
1543 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1544 struct objfile *objfile)
1546 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1548 subpst->section_offsets = pst->section_offsets;
1549 subpst->textlow = 0;
1550 subpst->texthigh = 0;
1552 subpst->dependencies = (struct partial_symtab **)
1553 obstack_alloc (&objfile->objfile_obstack,
1554 sizeof (struct partial_symtab *));
1555 subpst->dependencies[0] = pst;
1556 subpst->number_of_dependencies = 1;
1558 subpst->globals_offset = 0;
1559 subpst->n_global_syms = 0;
1560 subpst->statics_offset = 0;
1561 subpst->n_static_syms = 0;
1562 subpst->symtab = NULL;
1563 subpst->read_symtab = pst->read_symtab;
1566 /* No private part is necessary for include psymtabs. This property
1567 can be used to differentiate between such include psymtabs and
1568 the regular ones. */
1569 subpst->read_symtab_private = NULL;
1572 /* Read the Line Number Program data and extract the list of files
1573 included by the source file represented by PST. Build an include
1574 partial symtab for each of these included files. */
1577 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1578 struct die_info *die,
1579 struct partial_symtab *pst)
1581 struct objfile *objfile = cu->objfile;
1582 bfd *abfd = objfile->obfd;
1583 struct line_header *lh = NULL;
1584 struct attribute *attr;
1586 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
1589 unsigned int line_offset = DW_UNSND (attr);
1590 lh = dwarf_decode_line_header (line_offset, abfd, cu);
1593 return; /* No linetable, so no includes. */
1595 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1597 free_line_header (lh);
1601 hash_type_signature (const void *item)
1603 const struct signatured_type *type_sig = item;
1604 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1605 return type_sig->signature;
1609 eq_type_signature (const void *item_lhs, const void *item_rhs)
1611 const struct signatured_type *lhs = item_lhs;
1612 const struct signatured_type *rhs = item_rhs;
1613 return lhs->signature == rhs->signature;
1616 /* Create the hash table of all entries in the .debug_types section.
1617 The result is zero if there is an error (e.g. missing .debug_types section),
1618 otherwise non-zero. */
1621 create_debug_types_hash_table (struct objfile *objfile)
1626 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
1627 info_ptr = dwarf2_per_objfile->types.buffer;
1629 if (info_ptr == NULL)
1631 dwarf2_per_objfile->signatured_types = NULL;
1635 types_htab = htab_create_alloc_ex (41,
1636 hash_type_signature,
1639 &objfile->objfile_obstack,
1640 hashtab_obstack_allocate,
1641 dummy_obstack_deallocate);
1643 if (dwarf2_die_debug)
1644 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
1646 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1648 unsigned int offset;
1649 unsigned int offset_size;
1650 unsigned int type_offset;
1651 unsigned int length, initial_length_size;
1652 unsigned short version;
1654 struct signatured_type *type_sig;
1656 gdb_byte *ptr = info_ptr;
1658 offset = ptr - dwarf2_per_objfile->types.buffer;
1660 /* We need to read the type's signature in order to build the hash
1661 table, but we don't need to read anything else just yet. */
1663 /* Sanity check to ensure entire cu is present. */
1664 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
1665 if (ptr + length + initial_length_size
1666 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1668 complaint (&symfile_complaints,
1669 _("debug type entry runs off end of `.debug_types' section, ignored"));
1673 offset_size = initial_length_size == 4 ? 4 : 8;
1674 ptr += initial_length_size;
1675 version = bfd_get_16 (objfile->obfd, ptr);
1677 ptr += offset_size; /* abbrev offset */
1678 ptr += 1; /* address size */
1679 signature = bfd_get_64 (objfile->obfd, ptr);
1681 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
1683 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
1684 memset (type_sig, 0, sizeof (*type_sig));
1685 type_sig->signature = signature;
1686 type_sig->offset = offset;
1687 type_sig->type_offset = type_offset;
1689 slot = htab_find_slot (types_htab, type_sig, INSERT);
1690 gdb_assert (slot != NULL);
1693 if (dwarf2_die_debug)
1694 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
1695 offset, phex (signature, sizeof (signature)));
1697 info_ptr = info_ptr + initial_length_size + length;
1700 dwarf2_per_objfile->signatured_types = types_htab;
1705 /* Lookup a signature based type.
1706 Returns NULL if SIG is not present in the table. */
1708 static struct signatured_type *
1709 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
1711 struct signatured_type find_entry, *entry;
1713 if (dwarf2_per_objfile->signatured_types == NULL)
1715 complaint (&symfile_complaints,
1716 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1720 find_entry.signature = sig;
1721 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
1725 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1728 init_cu_die_reader (struct die_reader_specs *reader,
1729 struct dwarf2_cu *cu)
1731 reader->abfd = cu->objfile->obfd;
1733 if (cu->per_cu->from_debug_types)
1735 gdb_assert (dwarf2_per_objfile->types.readin);
1736 reader->buffer = dwarf2_per_objfile->types.buffer;
1740 gdb_assert (dwarf2_per_objfile->info.readin);
1741 reader->buffer = dwarf2_per_objfile->info.buffer;
1745 /* Find the base address of the compilation unit for range lists and
1746 location lists. It will normally be specified by DW_AT_low_pc.
1747 In DWARF-3 draft 4, the base address could be overridden by
1748 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1749 compilation units with discontinuous ranges. */
1752 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
1754 struct attribute *attr;
1757 cu->base_address = 0;
1759 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
1762 cu->base_address = DW_ADDR (attr);
1767 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
1770 cu->base_address = DW_ADDR (attr);
1776 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1777 to combine the common parts.
1778 Process a compilation unit for a psymtab.
1779 BUFFER is a pointer to the beginning of the dwarf section buffer,
1780 either .debug_info or debug_types.
1781 INFO_PTR is a pointer to the start of the CU.
1782 Returns a pointer to the next CU. */
1785 process_psymtab_comp_unit (struct objfile *objfile,
1786 struct dwarf2_per_cu_data *this_cu,
1787 gdb_byte *buffer, gdb_byte *info_ptr,
1788 unsigned int buffer_size)
1790 bfd *abfd = objfile->obfd;
1791 gdb_byte *beg_of_comp_unit = info_ptr;
1792 struct die_info *comp_unit_die;
1793 struct partial_symtab *pst;
1795 struct cleanup *back_to_inner;
1796 struct dwarf2_cu cu;
1797 unsigned int bytes_read;
1798 int has_children, has_pc_info;
1799 struct attribute *attr;
1801 CORE_ADDR best_lowpc = 0, best_highpc = 0;
1802 struct die_reader_specs reader_specs;
1804 memset (&cu, 0, sizeof (cu));
1805 cu.objfile = objfile;
1806 obstack_init (&cu.comp_unit_obstack);
1808 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1810 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
1811 buffer, buffer_size,
1814 /* Complete the cu_header. */
1815 cu.header.offset = beg_of_comp_unit - buffer;
1816 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1818 cu.list_in_scope = &file_symbols;
1820 /* If this compilation unit was already read in, free the
1821 cached copy in order to read it in again. This is
1822 necessary because we skipped some symbols when we first
1823 read in the compilation unit (see load_partial_dies).
1824 This problem could be avoided, but the benefit is
1826 if (this_cu->cu != NULL)
1827 free_one_cached_comp_unit (this_cu->cu);
1829 /* Note that this is a pointer to our stack frame, being
1830 added to a global data structure. It will be cleaned up
1831 in free_stack_comp_unit when we finish with this
1832 compilation unit. */
1834 cu.per_cu = this_cu;
1836 /* Read the abbrevs for this compilation unit into a table. */
1837 dwarf2_read_abbrevs (abfd, &cu);
1838 make_cleanup (dwarf2_free_abbrev_table, &cu);
1840 /* Read the compilation unit die. */
1841 if (this_cu->from_debug_types)
1842 info_ptr += 8 /*signature*/ + cu.header.offset_size;
1843 init_cu_die_reader (&reader_specs, &cu);
1844 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
1847 if (this_cu->from_debug_types)
1849 /* offset,length haven't been set yet for type units. */
1850 this_cu->offset = cu.header.offset;
1851 this_cu->length = cu.header.length + cu.header.initial_length_size;
1853 else if (comp_unit_die->tag == DW_TAG_partial_unit)
1855 info_ptr = (beg_of_comp_unit + cu.header.length
1856 + cu.header.initial_length_size);
1857 do_cleanups (back_to_inner);
1861 /* Set the language we're debugging. */
1862 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
1864 set_cu_language (DW_UNSND (attr), &cu);
1866 set_cu_language (language_minimal, &cu);
1868 /* Allocate a new partial symbol table structure. */
1869 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
1870 pst = start_psymtab_common (objfile, objfile->section_offsets,
1871 (attr != NULL) ? DW_STRING (attr) : "",
1872 /* TEXTLOW and TEXTHIGH are set below. */
1874 objfile->global_psymbols.next,
1875 objfile->static_psymbols.next);
1877 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
1879 pst->dirname = DW_STRING (attr);
1881 pst->read_symtab_private = this_cu;
1883 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1885 /* Store the function that reads in the rest of the symbol table */
1886 pst->read_symtab = dwarf2_psymtab_to_symtab;
1888 this_cu->psymtab = pst;
1890 dwarf2_find_base_address (comp_unit_die, &cu);
1892 /* Possibly set the default values of LOWPC and HIGHPC from
1894 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
1895 &best_highpc, &cu, pst);
1896 if (has_pc_info == 1 && best_lowpc < best_highpc)
1897 /* Store the contiguous range if it is not empty; it can be empty for
1898 CUs with no code. */
1899 addrmap_set_empty (objfile->psymtabs_addrmap,
1900 best_lowpc + baseaddr,
1901 best_highpc + baseaddr - 1, pst);
1903 /* Check if comp unit has_children.
1904 If so, read the rest of the partial symbols from this comp unit.
1905 If not, there's no more debug_info for this comp unit. */
1908 struct partial_die_info *first_die;
1909 CORE_ADDR lowpc, highpc;
1911 lowpc = ((CORE_ADDR) -1);
1912 highpc = ((CORE_ADDR) 0);
1914 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
1916 scan_partial_symbols (first_die, &lowpc, &highpc,
1917 ! has_pc_info, &cu);
1919 /* If we didn't find a lowpc, set it to highpc to avoid
1920 complaints from `maint check'. */
1921 if (lowpc == ((CORE_ADDR) -1))
1924 /* If the compilation unit didn't have an explicit address range,
1925 then use the information extracted from its child dies. */
1929 best_highpc = highpc;
1932 pst->textlow = best_lowpc + baseaddr;
1933 pst->texthigh = best_highpc + baseaddr;
1935 pst->n_global_syms = objfile->global_psymbols.next -
1936 (objfile->global_psymbols.list + pst->globals_offset);
1937 pst->n_static_syms = objfile->static_psymbols.next -
1938 (objfile->static_psymbols.list + pst->statics_offset);
1939 sort_pst_symbols (pst);
1941 info_ptr = (beg_of_comp_unit + cu.header.length
1942 + cu.header.initial_length_size);
1944 if (this_cu->from_debug_types)
1946 /* It's not clear we want to do anything with stmt lists here.
1947 Waiting to see what gcc ultimately does. */
1951 /* Get the list of files included in the current compilation unit,
1952 and build a psymtab for each of them. */
1953 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
1956 do_cleanups (back_to_inner);
1961 /* Traversal function for htab_traverse_noresize.
1962 Process one .debug_types comp-unit. */
1965 process_type_comp_unit (void **slot, void *info)
1967 struct signatured_type *entry = (struct signatured_type *) *slot;
1968 struct objfile *objfile = (struct objfile *) info;
1969 struct dwarf2_per_cu_data *this_cu;
1971 this_cu = &entry->per_cu;
1972 this_cu->from_debug_types = 1;
1974 gdb_assert (dwarf2_per_objfile->types.readin);
1975 process_psymtab_comp_unit (objfile, this_cu,
1976 dwarf2_per_objfile->types.buffer,
1977 dwarf2_per_objfile->types.buffer + entry->offset,
1978 dwarf2_per_objfile->types.size);
1983 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1984 Build partial symbol tables for the .debug_types comp-units. */
1987 build_type_psymtabs (struct objfile *objfile)
1989 if (! create_debug_types_hash_table (objfile))
1992 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
1993 process_type_comp_unit, objfile);
1996 /* Build the partial symbol table by doing a quick pass through the
1997 .debug_info and .debug_abbrev sections. */
2000 dwarf2_build_psymtabs_hard (struct objfile *objfile)
2002 bfd *abfd = objfile->obfd;
2004 struct cleanup *back_to;
2006 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2007 info_ptr = dwarf2_per_objfile->info.buffer;
2009 /* Any cached compilation units will be linked by the per-objfile
2010 read_in_chain. Make sure to free them when we're done. */
2011 back_to = make_cleanup (free_cached_comp_units, NULL);
2013 build_type_psymtabs (objfile);
2015 create_all_comp_units (objfile);
2017 objfile->psymtabs_addrmap =
2018 addrmap_create_mutable (&objfile->objfile_obstack);
2020 /* Since the objects we're extracting from .debug_info vary in
2021 length, only the individual functions to extract them (like
2022 read_comp_unit_head and load_partial_die) can really know whether
2023 the buffer is large enough to hold another complete object.
2025 At the moment, they don't actually check that. If .debug_info
2026 holds just one extra byte after the last compilation unit's dies,
2027 then read_comp_unit_head will happily read off the end of the
2028 buffer. read_partial_die is similarly casual. Those functions
2031 For this loop condition, simply checking whether there's any data
2032 left at all should be sufficient. */
2034 while (info_ptr < (dwarf2_per_objfile->info.buffer
2035 + dwarf2_per_objfile->info.size))
2037 struct dwarf2_per_cu_data *this_cu;
2039 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
2042 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
2043 dwarf2_per_objfile->info.buffer,
2045 dwarf2_per_objfile->info.size);
2048 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
2049 &objfile->objfile_obstack);
2051 do_cleanups (back_to);
2054 /* Load the partial DIEs for a secondary CU into memory. */
2057 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
2058 struct objfile *objfile)
2060 bfd *abfd = objfile->obfd;
2061 gdb_byte *info_ptr, *beg_of_comp_unit;
2062 struct die_info *comp_unit_die;
2063 struct dwarf2_cu *cu;
2064 unsigned int bytes_read;
2065 struct cleanup *back_to;
2066 struct attribute *attr;
2068 struct die_reader_specs reader_specs;
2070 gdb_assert (! this_cu->from_debug_types);
2072 gdb_assert (dwarf2_per_objfile->info.readin);
2073 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
2074 beg_of_comp_unit = info_ptr;
2076 cu = alloc_one_comp_unit (objfile);
2078 /* ??? Missing cleanup for CU? */
2080 /* Link this compilation unit into the compilation unit tree. */
2082 cu->per_cu = this_cu;
2083 cu->type_hash = this_cu->type_hash;
2085 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
2086 dwarf2_per_objfile->info.buffer,
2087 dwarf2_per_objfile->info.size,
2090 /* Complete the cu_header. */
2091 cu->header.offset = this_cu->offset;
2092 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
2094 /* Read the abbrevs for this compilation unit into a table. */
2095 dwarf2_read_abbrevs (abfd, cu);
2096 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2098 /* Read the compilation unit die. */
2099 init_cu_die_reader (&reader_specs, cu);
2100 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2103 /* Set the language we're debugging. */
2104 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
2106 set_cu_language (DW_UNSND (attr), cu);
2108 set_cu_language (language_minimal, cu);
2110 /* Check if comp unit has_children.
2111 If so, read the rest of the partial symbols from this comp unit.
2112 If not, there's no more debug_info for this comp unit. */
2114 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
2116 do_cleanups (back_to);
2119 /* Create a list of all compilation units in OBJFILE. We do this only
2120 if an inter-comp-unit reference is found; presumably if there is one,
2121 there will be many, and one will occur early in the .debug_info section.
2122 So there's no point in building this list incrementally. */
2125 create_all_comp_units (struct objfile *objfile)
2129 struct dwarf2_per_cu_data **all_comp_units;
2132 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2133 info_ptr = dwarf2_per_objfile->info.buffer;
2137 all_comp_units = xmalloc (n_allocated
2138 * sizeof (struct dwarf2_per_cu_data *));
2140 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
2142 unsigned int length, initial_length_size;
2143 gdb_byte *beg_of_comp_unit;
2144 struct dwarf2_per_cu_data *this_cu;
2145 unsigned int offset;
2147 offset = info_ptr - dwarf2_per_objfile->info.buffer;
2149 /* Read just enough information to find out where the next
2150 compilation unit is. */
2151 length = read_initial_length (objfile->obfd, info_ptr,
2152 &initial_length_size);
2154 /* Save the compilation unit for later lookup. */
2155 this_cu = obstack_alloc (&objfile->objfile_obstack,
2156 sizeof (struct dwarf2_per_cu_data));
2157 memset (this_cu, 0, sizeof (*this_cu));
2158 this_cu->offset = offset;
2159 this_cu->length = length + initial_length_size;
2161 if (n_comp_units == n_allocated)
2164 all_comp_units = xrealloc (all_comp_units,
2166 * sizeof (struct dwarf2_per_cu_data *));
2168 all_comp_units[n_comp_units++] = this_cu;
2170 info_ptr = info_ptr + this_cu->length;
2173 dwarf2_per_objfile->all_comp_units
2174 = obstack_alloc (&objfile->objfile_obstack,
2175 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2176 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
2177 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2178 xfree (all_comp_units);
2179 dwarf2_per_objfile->n_comp_units = n_comp_units;
2182 /* Process all loaded DIEs for compilation unit CU, starting at
2183 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2184 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2185 DW_AT_ranges). If NEED_PC is set, then this function will set
2186 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2187 and record the covered ranges in the addrmap. */
2190 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
2191 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2193 struct objfile *objfile = cu->objfile;
2194 bfd *abfd = objfile->obfd;
2195 struct partial_die_info *pdi;
2197 /* Now, march along the PDI's, descending into ones which have
2198 interesting children but skipping the children of the other ones,
2199 until we reach the end of the compilation unit. */
2205 fixup_partial_die (pdi, cu);
2207 /* Anonymous namespaces have no name but have interesting
2208 children, so we need to look at them. Ditto for anonymous
2211 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
2212 || pdi->tag == DW_TAG_enumeration_type)
2216 case DW_TAG_subprogram:
2217 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2219 case DW_TAG_variable:
2220 case DW_TAG_typedef:
2221 case DW_TAG_union_type:
2222 if (!pdi->is_declaration)
2224 add_partial_symbol (pdi, cu);
2227 case DW_TAG_class_type:
2228 case DW_TAG_interface_type:
2229 case DW_TAG_structure_type:
2230 if (!pdi->is_declaration)
2232 add_partial_symbol (pdi, cu);
2235 case DW_TAG_enumeration_type:
2236 if (!pdi->is_declaration)
2237 add_partial_enumeration (pdi, cu);
2239 case DW_TAG_base_type:
2240 case DW_TAG_subrange_type:
2241 /* File scope base type definitions are added to the partial
2243 add_partial_symbol (pdi, cu);
2245 case DW_TAG_namespace:
2246 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
2249 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
2256 /* If the die has a sibling, skip to the sibling. */
2258 pdi = pdi->die_sibling;
2262 /* Functions used to compute the fully scoped name of a partial DIE.
2264 Normally, this is simple. For C++, the parent DIE's fully scoped
2265 name is concatenated with "::" and the partial DIE's name. For
2266 Java, the same thing occurs except that "." is used instead of "::".
2267 Enumerators are an exception; they use the scope of their parent
2268 enumeration type, i.e. the name of the enumeration type is not
2269 prepended to the enumerator.
2271 There are two complexities. One is DW_AT_specification; in this
2272 case "parent" means the parent of the target of the specification,
2273 instead of the direct parent of the DIE. The other is compilers
2274 which do not emit DW_TAG_namespace; in this case we try to guess
2275 the fully qualified name of structure types from their members'
2276 linkage names. This must be done using the DIE's children rather
2277 than the children of any DW_AT_specification target. We only need
2278 to do this for structures at the top level, i.e. if the target of
2279 any DW_AT_specification (if any; otherwise the DIE itself) does not
2282 /* Compute the scope prefix associated with PDI's parent, in
2283 compilation unit CU. The result will be allocated on CU's
2284 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2285 field. NULL is returned if no prefix is necessary. */
2287 partial_die_parent_scope (struct partial_die_info *pdi,
2288 struct dwarf2_cu *cu)
2290 char *grandparent_scope;
2291 struct partial_die_info *parent, *real_pdi;
2293 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2294 then this means the parent of the specification DIE. */
2297 while (real_pdi->has_specification)
2298 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2300 parent = real_pdi->die_parent;
2304 if (parent->scope_set)
2305 return parent->scope;
2307 fixup_partial_die (parent, cu);
2309 grandparent_scope = partial_die_parent_scope (parent, cu);
2311 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
2312 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
2313 Work around this problem here. */
2314 if (cu->language == language_cplus
2315 && parent->tag == DW_TAG_namespace
2316 && strcmp (parent->name, "::") == 0
2317 && grandparent_scope == NULL)
2319 parent->scope = NULL;
2320 parent->scope_set = 1;
2324 if (parent->tag == DW_TAG_namespace
2325 || parent->tag == DW_TAG_structure_type
2326 || parent->tag == DW_TAG_class_type
2327 || parent->tag == DW_TAG_interface_type
2328 || parent->tag == DW_TAG_union_type
2329 || parent->tag == DW_TAG_enumeration_type)
2331 if (grandparent_scope == NULL)
2332 parent->scope = parent->name;
2334 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
2337 else if (parent->tag == DW_TAG_enumerator)
2338 /* Enumerators should not get the name of the enumeration as a prefix. */
2339 parent->scope = grandparent_scope;
2342 /* FIXME drow/2004-04-01: What should we be doing with
2343 function-local names? For partial symbols, we should probably be
2345 complaint (&symfile_complaints,
2346 _("unhandled containing DIE tag %d for DIE at %d"),
2347 parent->tag, pdi->offset);
2348 parent->scope = grandparent_scope;
2351 parent->scope_set = 1;
2352 return parent->scope;
2355 /* Return the fully scoped name associated with PDI, from compilation unit
2356 CU. The result will be allocated with malloc. */
2358 partial_die_full_name (struct partial_die_info *pdi,
2359 struct dwarf2_cu *cu)
2363 parent_scope = partial_die_parent_scope (pdi, cu);
2364 if (parent_scope == NULL)
2367 return typename_concat (NULL, parent_scope, pdi->name, cu);
2371 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
2373 struct objfile *objfile = cu->objfile;
2375 char *actual_name = NULL;
2376 const char *my_prefix;
2377 const struct partial_symbol *psym = NULL;
2379 int built_actual_name = 0;
2381 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2383 actual_name = partial_die_full_name (pdi, cu);
2385 built_actual_name = 1;
2387 if (actual_name == NULL)
2388 actual_name = pdi->name;
2392 case DW_TAG_subprogram:
2393 if (pdi->is_external || cu->language == language_ada)
2395 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2396 of the global scope. But in Ada, we want to be able to access
2397 nested procedures globally. So all Ada subprograms are stored
2398 in the global scope. */
2399 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2400 mst_text, objfile); */
2401 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2403 VAR_DOMAIN, LOC_BLOCK,
2404 &objfile->global_psymbols,
2405 0, pdi->lowpc + baseaddr,
2406 cu->language, objfile);
2410 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2411 mst_file_text, objfile); */
2412 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2414 VAR_DOMAIN, LOC_BLOCK,
2415 &objfile->static_psymbols,
2416 0, pdi->lowpc + baseaddr,
2417 cu->language, objfile);
2420 case DW_TAG_variable:
2421 if (pdi->is_external)
2424 Don't enter into the minimal symbol tables as there is
2425 a minimal symbol table entry from the ELF symbols already.
2426 Enter into partial symbol table if it has a location
2427 descriptor or a type.
2428 If the location descriptor is missing, new_symbol will create
2429 a LOC_UNRESOLVED symbol, the address of the variable will then
2430 be determined from the minimal symbol table whenever the variable
2432 The address for the partial symbol table entry is not
2433 used by GDB, but it comes in handy for debugging partial symbol
2437 addr = decode_locdesc (pdi->locdesc, cu);
2438 if (pdi->locdesc || pdi->has_type)
2439 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2441 VAR_DOMAIN, LOC_STATIC,
2442 &objfile->global_psymbols,
2444 cu->language, objfile);
2448 /* Static Variable. Skip symbols without location descriptors. */
2449 if (pdi->locdesc == NULL)
2451 if (built_actual_name)
2452 xfree (actual_name);
2455 addr = decode_locdesc (pdi->locdesc, cu);
2456 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2457 mst_file_data, objfile); */
2458 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2460 VAR_DOMAIN, LOC_STATIC,
2461 &objfile->static_psymbols,
2463 cu->language, objfile);
2466 case DW_TAG_typedef:
2467 case DW_TAG_base_type:
2468 case DW_TAG_subrange_type:
2469 add_psymbol_to_list (actual_name, strlen (actual_name),
2471 VAR_DOMAIN, LOC_TYPEDEF,
2472 &objfile->static_psymbols,
2473 0, (CORE_ADDR) 0, cu->language, objfile);
2475 case DW_TAG_namespace:
2476 add_psymbol_to_list (actual_name, strlen (actual_name),
2478 VAR_DOMAIN, LOC_TYPEDEF,
2479 &objfile->global_psymbols,
2480 0, (CORE_ADDR) 0, cu->language, objfile);
2482 case DW_TAG_class_type:
2483 case DW_TAG_interface_type:
2484 case DW_TAG_structure_type:
2485 case DW_TAG_union_type:
2486 case DW_TAG_enumeration_type:
2487 /* Skip external references. The DWARF standard says in the section
2488 about "Structure, Union, and Class Type Entries": "An incomplete
2489 structure, union or class type is represented by a structure,
2490 union or class entry that does not have a byte size attribute
2491 and that has a DW_AT_declaration attribute." */
2492 if (!pdi->has_byte_size && pdi->is_declaration)
2494 if (built_actual_name)
2495 xfree (actual_name);
2499 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2500 static vs. global. */
2501 add_psymbol_to_list (actual_name, strlen (actual_name),
2503 STRUCT_DOMAIN, LOC_TYPEDEF,
2504 (cu->language == language_cplus
2505 || cu->language == language_java)
2506 ? &objfile->global_psymbols
2507 : &objfile->static_psymbols,
2508 0, (CORE_ADDR) 0, cu->language, objfile);
2511 case DW_TAG_enumerator:
2512 add_psymbol_to_list (actual_name, strlen (actual_name),
2514 VAR_DOMAIN, LOC_CONST,
2515 (cu->language == language_cplus
2516 || cu->language == language_java)
2517 ? &objfile->global_psymbols
2518 : &objfile->static_psymbols,
2519 0, (CORE_ADDR) 0, cu->language, objfile);
2525 if (built_actual_name)
2526 xfree (actual_name);
2529 /* Read a partial die corresponding to a namespace; also, add a symbol
2530 corresponding to that namespace to the symbol table. NAMESPACE is
2531 the name of the enclosing namespace. */
2534 add_partial_namespace (struct partial_die_info *pdi,
2535 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2536 int need_pc, struct dwarf2_cu *cu)
2538 struct objfile *objfile = cu->objfile;
2540 /* Add a symbol for the namespace. */
2542 add_partial_symbol (pdi, cu);
2544 /* Now scan partial symbols in that namespace. */
2546 if (pdi->has_children)
2547 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2550 /* Read a partial die corresponding to a Fortran module. */
2553 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
2554 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2556 /* Now scan partial symbols in that module.
2558 FIXME: Support the separate Fortran module namespaces. */
2560 if (pdi->has_children)
2561 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2564 /* Read a partial die corresponding to a subprogram and create a partial
2565 symbol for that subprogram. When the CU language allows it, this
2566 routine also defines a partial symbol for each nested subprogram
2567 that this subprogram contains.
2569 DIE my also be a lexical block, in which case we simply search
2570 recursively for suprograms defined inside that lexical block.
2571 Again, this is only performed when the CU language allows this
2572 type of definitions. */
2575 add_partial_subprogram (struct partial_die_info *pdi,
2576 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2577 int need_pc, struct dwarf2_cu *cu)
2579 if (pdi->tag == DW_TAG_subprogram)
2581 if (pdi->has_pc_info)
2583 if (pdi->lowpc < *lowpc)
2584 *lowpc = pdi->lowpc;
2585 if (pdi->highpc > *highpc)
2586 *highpc = pdi->highpc;
2590 struct objfile *objfile = cu->objfile;
2592 baseaddr = ANOFFSET (objfile->section_offsets,
2593 SECT_OFF_TEXT (objfile));
2594 addrmap_set_empty (objfile->psymtabs_addrmap,
2595 pdi->lowpc + baseaddr,
2596 pdi->highpc - 1 + baseaddr,
2597 cu->per_cu->psymtab);
2599 if (!pdi->is_declaration)
2600 /* Ignore subprogram DIEs that do not have a name, they are
2601 illegal. Do not emit a complaint at this point, we will
2602 do so when we convert this psymtab into a symtab. */
2604 add_partial_symbol (pdi, cu);
2608 if (! pdi->has_children)
2611 if (cu->language == language_ada)
2613 pdi = pdi->die_child;
2616 fixup_partial_die (pdi, cu);
2617 if (pdi->tag == DW_TAG_subprogram
2618 || pdi->tag == DW_TAG_lexical_block)
2619 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2620 pdi = pdi->die_sibling;
2625 /* See if we can figure out if the class lives in a namespace. We do
2626 this by looking for a member function; its demangled name will
2627 contain namespace info, if there is any. */
2630 guess_structure_name (struct partial_die_info *struct_pdi,
2631 struct dwarf2_cu *cu)
2633 if ((cu->language == language_cplus
2634 || cu->language == language_java)
2635 && cu->has_namespace_info == 0
2636 && struct_pdi->has_children)
2638 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2639 what template types look like, because the demangler
2640 frequently doesn't give the same name as the debug info. We
2641 could fix this by only using the demangled name to get the
2642 prefix (but see comment in read_structure_type). */
2644 struct partial_die_info *real_pdi;
2646 /* If this DIE (this DIE's specification, if any) has a parent, then
2647 we should not do this. We'll prepend the parent's fully qualified
2648 name when we create the partial symbol. */
2650 real_pdi = struct_pdi;
2651 while (real_pdi->has_specification)
2652 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2654 if (real_pdi->die_parent != NULL)
2659 /* Read a partial die corresponding to an enumeration type. */
2662 add_partial_enumeration (struct partial_die_info *enum_pdi,
2663 struct dwarf2_cu *cu)
2665 struct objfile *objfile = cu->objfile;
2666 bfd *abfd = objfile->obfd;
2667 struct partial_die_info *pdi;
2669 if (enum_pdi->name != NULL)
2670 add_partial_symbol (enum_pdi, cu);
2672 pdi = enum_pdi->die_child;
2675 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2676 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2678 add_partial_symbol (pdi, cu);
2679 pdi = pdi->die_sibling;
2683 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2684 Return the corresponding abbrev, or NULL if the number is zero (indicating
2685 an empty DIE). In either case *BYTES_READ will be set to the length of
2686 the initial number. */
2688 static struct abbrev_info *
2689 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
2690 struct dwarf2_cu *cu)
2692 bfd *abfd = cu->objfile->obfd;
2693 unsigned int abbrev_number;
2694 struct abbrev_info *abbrev;
2696 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2698 if (abbrev_number == 0)
2701 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2704 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2705 bfd_get_filename (abfd));
2711 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2712 Returns a pointer to the end of a series of DIEs, terminated by an empty
2713 DIE. Any children of the skipped DIEs will also be skipped. */
2716 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
2718 struct abbrev_info *abbrev;
2719 unsigned int bytes_read;
2723 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2725 return info_ptr + bytes_read;
2727 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
2731 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2732 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2733 abbrev corresponding to that skipped uleb128 should be passed in
2734 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2738 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
2739 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
2741 unsigned int bytes_read;
2742 struct attribute attr;
2743 bfd *abfd = cu->objfile->obfd;
2744 unsigned int form, i;
2746 for (i = 0; i < abbrev->num_attrs; i++)
2748 /* The only abbrev we care about is DW_AT_sibling. */
2749 if (abbrev->attrs[i].name == DW_AT_sibling)
2751 read_attribute (&attr, &abbrev->attrs[i],
2752 abfd, info_ptr, cu);
2753 if (attr.form == DW_FORM_ref_addr)
2754 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2756 return buffer + dwarf2_get_ref_die_offset (&attr);
2759 /* If it isn't DW_AT_sibling, skip this attribute. */
2760 form = abbrev->attrs[i].form;
2764 case DW_FORM_ref_addr:
2765 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2766 and later it is offset sized. */
2767 if (cu->header.version == 2)
2768 info_ptr += cu->header.addr_size;
2770 info_ptr += cu->header.offset_size;
2773 info_ptr += cu->header.addr_size;
2780 case DW_FORM_flag_present:
2795 case DW_FORM_string:
2796 read_string (abfd, info_ptr, &bytes_read);
2797 info_ptr += bytes_read;
2799 case DW_FORM_sec_offset:
2801 info_ptr += cu->header.offset_size;
2803 case DW_FORM_exprloc:
2805 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2806 info_ptr += bytes_read;
2808 case DW_FORM_block1:
2809 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2811 case DW_FORM_block2:
2812 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2814 case DW_FORM_block4:
2815 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2819 case DW_FORM_ref_udata:
2820 info_ptr = skip_leb128 (abfd, info_ptr);
2822 case DW_FORM_indirect:
2823 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2824 info_ptr += bytes_read;
2825 /* We need to continue parsing from here, so just go back to
2827 goto skip_attribute;
2830 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2831 dwarf_form_name (form),
2832 bfd_get_filename (abfd));
2836 if (abbrev->has_children)
2837 return skip_children (buffer, info_ptr, cu);
2842 /* Locate ORIG_PDI's sibling.
2843 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2847 locate_pdi_sibling (struct partial_die_info *orig_pdi,
2848 gdb_byte *buffer, gdb_byte *info_ptr,
2849 bfd *abfd, struct dwarf2_cu *cu)
2851 /* Do we know the sibling already? */
2853 if (orig_pdi->sibling)
2854 return orig_pdi->sibling;
2856 /* Are there any children to deal with? */
2858 if (!orig_pdi->has_children)
2861 /* Skip the children the long way. */
2863 return skip_children (buffer, info_ptr, cu);
2866 /* Expand this partial symbol table into a full symbol table. */
2869 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2871 /* FIXME: This is barely more than a stub. */
2876 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2882 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2883 gdb_flush (gdb_stdout);
2886 /* Restore our global data. */
2887 dwarf2_per_objfile = objfile_data (pst->objfile,
2888 dwarf2_objfile_data_key);
2890 /* If this psymtab is constructed from a debug-only objfile, the
2891 has_section_at_zero flag will not necessarily be correct. We
2892 can get the correct value for this flag by looking at the data
2893 associated with the (presumably stripped) associated objfile. */
2894 if (pst->objfile->separate_debug_objfile_backlink)
2896 struct dwarf2_per_objfile *dpo_backlink
2897 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
2898 dwarf2_objfile_data_key);
2899 dwarf2_per_objfile->has_section_at_zero
2900 = dpo_backlink->has_section_at_zero;
2903 psymtab_to_symtab_1 (pst);
2905 /* Finish up the debug error message. */
2907 printf_filtered (_("done.\n"));
2912 /* Add PER_CU to the queue. */
2915 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2917 struct dwarf2_queue_item *item;
2920 item = xmalloc (sizeof (*item));
2921 item->per_cu = per_cu;
2924 if (dwarf2_queue == NULL)
2925 dwarf2_queue = item;
2927 dwarf2_queue_tail->next = item;
2929 dwarf2_queue_tail = item;
2932 /* Process the queue. */
2935 process_queue (struct objfile *objfile)
2937 struct dwarf2_queue_item *item, *next_item;
2939 /* The queue starts out with one item, but following a DIE reference
2940 may load a new CU, adding it to the end of the queue. */
2941 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
2943 if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
2944 process_full_comp_unit (item->per_cu);
2946 item->per_cu->queued = 0;
2947 next_item = item->next;
2951 dwarf2_queue_tail = NULL;
2954 /* Free all allocated queue entries. This function only releases anything if
2955 an error was thrown; if the queue was processed then it would have been
2956 freed as we went along. */
2959 dwarf2_release_queue (void *dummy)
2961 struct dwarf2_queue_item *item, *last;
2963 item = dwarf2_queue;
2966 /* Anything still marked queued is likely to be in an
2967 inconsistent state, so discard it. */
2968 if (item->per_cu->queued)
2970 if (item->per_cu->cu != NULL)
2971 free_one_cached_comp_unit (item->per_cu->cu);
2972 item->per_cu->queued = 0;
2980 dwarf2_queue = dwarf2_queue_tail = NULL;
2983 /* Read in full symbols for PST, and anything it depends on. */
2986 psymtab_to_symtab_1 (struct partial_symtab *pst)
2988 struct dwarf2_per_cu_data *per_cu;
2989 struct cleanup *back_to;
2992 for (i = 0; i < pst->number_of_dependencies; i++)
2993 if (!pst->dependencies[i]->readin)
2995 /* Inform about additional files that need to be read in. */
2998 /* FIXME: i18n: Need to make this a single string. */
2999 fputs_filtered (" ", gdb_stdout);
3001 fputs_filtered ("and ", gdb_stdout);
3003 printf_filtered ("%s...", pst->dependencies[i]->filename);
3004 wrap_here (""); /* Flush output */
3005 gdb_flush (gdb_stdout);
3007 psymtab_to_symtab_1 (pst->dependencies[i]);
3010 per_cu = pst->read_symtab_private;
3014 /* It's an include file, no symbols to read for it.
3015 Everything is in the parent symtab. */
3020 back_to = make_cleanup (dwarf2_release_queue, NULL);
3022 queue_comp_unit (per_cu, pst->objfile);
3024 if (per_cu->from_debug_types)
3025 read_signatured_type_at_offset (pst->objfile, per_cu->offset);
3027 load_full_comp_unit (per_cu, pst->objfile);
3029 process_queue (pst->objfile);
3031 /* Age the cache, releasing compilation units that have not
3032 been used recently. */
3033 age_cached_comp_units ();
3035 do_cleanups (back_to);
3038 /* Load the DIEs associated with PER_CU into memory. */
3041 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3043 bfd *abfd = objfile->obfd;
3044 struct dwarf2_cu *cu;
3045 unsigned int offset;
3046 gdb_byte *info_ptr, *beg_of_comp_unit;
3047 struct cleanup *back_to, *free_cu_cleanup;
3048 struct attribute *attr;
3051 gdb_assert (! per_cu->from_debug_types);
3053 /* Set local variables from the partial symbol table info. */
3054 offset = per_cu->offset;
3056 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3057 info_ptr = dwarf2_per_objfile->info.buffer + offset;
3058 beg_of_comp_unit = info_ptr;
3060 cu = alloc_one_comp_unit (objfile);
3062 /* If an error occurs while loading, release our storage. */
3063 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3065 /* Read in the comp_unit header. */
3066 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
3068 /* Complete the cu_header. */
3069 cu->header.offset = offset;
3070 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3072 /* Read the abbrevs for this compilation unit. */
3073 dwarf2_read_abbrevs (abfd, cu);
3074 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
3076 /* Link this compilation unit into the compilation unit tree. */
3078 cu->per_cu = per_cu;
3079 cu->type_hash = per_cu->type_hash;
3081 cu->dies = read_comp_unit (info_ptr, cu);
3083 /* We try not to read any attributes in this function, because not
3084 all objfiles needed for references have been loaded yet, and symbol
3085 table processing isn't initialized. But we have to set the CU language,
3086 or we won't be able to build types correctly. */
3087 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
3089 set_cu_language (DW_UNSND (attr), cu);
3091 set_cu_language (language_minimal, cu);
3093 /* Similarly, if we do not read the producer, we can not apply
3094 producer-specific interpretation. */
3095 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
3097 cu->producer = DW_STRING (attr);
3099 /* Link this CU into read_in_chain. */
3100 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3101 dwarf2_per_objfile->read_in_chain = per_cu;
3103 do_cleanups (back_to);
3105 /* We've successfully allocated this compilation unit. Let our caller
3106 clean it up when finished with it. */
3107 discard_cleanups (free_cu_cleanup);
3110 /* Generate full symbol information for PST and CU, whose DIEs have
3111 already been loaded into memory. */
3114 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3116 struct partial_symtab *pst = per_cu->psymtab;
3117 struct dwarf2_cu *cu = per_cu->cu;
3118 struct objfile *objfile = pst->objfile;
3119 bfd *abfd = objfile->obfd;
3120 CORE_ADDR lowpc, highpc;
3121 struct symtab *symtab;
3122 struct cleanup *back_to;
3125 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3128 back_to = make_cleanup (really_free_pendings, NULL);
3130 cu->list_in_scope = &file_symbols;
3132 dwarf2_find_base_address (cu->dies, cu);
3134 /* Do line number decoding in read_file_scope () */
3135 process_die (cu->dies, cu);
3137 /* Some compilers don't define a DW_AT_high_pc attribute for the
3138 compilation unit. If the DW_AT_high_pc is missing, synthesize
3139 it, by scanning the DIE's below the compilation unit. */
3140 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
3142 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
3144 /* Set symtab language to language from DW_AT_language.
3145 If the compilation is from a C file generated by language preprocessors,
3146 do not set the language if it was already deduced by start_subfile. */
3148 && !(cu->language == language_c && symtab->language != language_c))
3150 symtab->language = cu->language;
3152 pst->symtab = symtab;
3155 do_cleanups (back_to);
3158 /* Process a die and its children. */
3161 process_die (struct die_info *die, struct dwarf2_cu *cu)
3165 case DW_TAG_padding:
3167 case DW_TAG_compile_unit:
3168 read_file_scope (die, cu);
3170 case DW_TAG_type_unit:
3171 read_type_unit_scope (die, cu);
3173 case DW_TAG_subprogram:
3174 case DW_TAG_inlined_subroutine:
3175 read_func_scope (die, cu);
3177 case DW_TAG_lexical_block:
3178 case DW_TAG_try_block:
3179 case DW_TAG_catch_block:
3180 read_lexical_block_scope (die, cu);
3182 case DW_TAG_class_type:
3183 case DW_TAG_interface_type:
3184 case DW_TAG_structure_type:
3185 case DW_TAG_union_type:
3186 process_structure_scope (die, cu);
3188 case DW_TAG_enumeration_type:
3189 process_enumeration_scope (die, cu);
3192 /* These dies have a type, but processing them does not create
3193 a symbol or recurse to process the children. Therefore we can
3194 read them on-demand through read_type_die. */
3195 case DW_TAG_subroutine_type:
3196 case DW_TAG_set_type:
3197 case DW_TAG_array_type:
3198 case DW_TAG_pointer_type:
3199 case DW_TAG_ptr_to_member_type:
3200 case DW_TAG_reference_type:
3201 case DW_TAG_string_type:
3204 case DW_TAG_base_type:
3205 case DW_TAG_subrange_type:
3206 case DW_TAG_typedef:
3207 /* Add a typedef symbol for the type definition, if it has a
3209 new_symbol (die, read_type_die (die, cu), cu);
3211 case DW_TAG_common_block:
3212 read_common_block (die, cu);
3214 case DW_TAG_common_inclusion:
3216 case DW_TAG_namespace:
3217 processing_has_namespace_info = 1;
3218 read_namespace (die, cu);
3221 read_module (die, cu);
3223 case DW_TAG_imported_declaration:
3224 case DW_TAG_imported_module:
3225 processing_has_namespace_info = 1;
3226 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
3227 || cu->language != language_fortran))
3228 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
3229 dwarf_tag_name (die->tag));
3230 read_import_statement (die, cu);
3233 new_symbol (die, NULL, cu);
3238 /* A helper function for dwarf2_compute_name which determines whether DIE
3239 needs to have the name of the scope prepended to the name listed in the
3243 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
3245 struct attribute *attr;
3249 case DW_TAG_namespace:
3250 case DW_TAG_typedef:
3251 case DW_TAG_class_type:
3252 case DW_TAG_interface_type:
3253 case DW_TAG_structure_type:
3254 case DW_TAG_union_type:
3255 case DW_TAG_enumeration_type:
3256 case DW_TAG_enumerator:
3257 case DW_TAG_subprogram:
3261 case DW_TAG_variable:
3262 /* We only need to prefix "globally" visible variables. These include
3263 any variable marked with DW_AT_external or any variable that
3264 lives in a namespace. [Variables in anonymous namespaces
3265 require prefixing, but they are not DW_AT_external.] */
3267 if (dwarf2_attr (die, DW_AT_specification, cu))
3269 struct dwarf2_cu *spec_cu = cu;
3270 return die_needs_namespace (die_specification (die, &spec_cu),
3274 attr = dwarf2_attr (die, DW_AT_external, cu);
3275 if (attr == NULL && die->parent->tag != DW_TAG_namespace)
3277 /* A variable in a lexical block of some kind does not need a
3278 namespace, even though in C++ such variables may be external
3279 and have a mangled name. */
3280 if (die->parent->tag == DW_TAG_lexical_block
3281 || die->parent->tag == DW_TAG_try_block
3282 || die->parent->tag == DW_TAG_catch_block
3283 || die->parent->tag == DW_TAG_subprogram)
3292 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3293 compute the physname for the object, which include a method's
3294 formal parameters (C++/Java) and return type (Java).
3296 For Ada, return the DIE's linkage name rather than the fully qualified
3297 name. PHYSNAME is ignored..
3299 The result is allocated on the objfile_obstack and canonicalized. */
3302 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
3306 name = dwarf2_name (die, cu);
3308 /* These are the only languages we know how to qualify names in. */
3310 && (cu->language == language_cplus || cu->language == language_java))
3312 if (die_needs_namespace (die, cu))
3316 struct ui_file *buf;
3318 prefix = determine_prefix (die, cu);
3319 buf = mem_fileopen ();
3320 if (*prefix != '\0')
3322 char *prefixed_name = typename_concat (NULL, prefix, name, cu);
3323 fputs_unfiltered (prefixed_name, buf);
3324 xfree (prefixed_name);
3327 fputs_unfiltered (name ? name : "", buf);
3329 /* For Java and C++ methods, append formal parameter type
3330 information, if PHYSNAME. */
3332 if (physname && die->tag == DW_TAG_subprogram
3333 && (cu->language == language_cplus
3334 || cu->language == language_java))
3336 struct type *type = read_type_die (die, cu);
3338 c_type_print_args (type, buf, 0, cu->language);
3340 if (cu->language == language_java)
3342 /* For java, we must append the return type to method
3344 if (die->tag == DW_TAG_subprogram)
3345 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
3348 else if (cu->language == language_cplus)
3350 if (TYPE_NFIELDS (type) > 0
3351 && TYPE_FIELD_ARTIFICIAL (type, 0)
3352 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
3353 fputs_unfiltered (" const", buf);
3357 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
3359 ui_file_delete (buf);
3361 if (cu->language == language_cplus)
3364 = dwarf2_canonicalize_name (name, cu,
3365 &cu->objfile->objfile_obstack);
3371 else if (cu->language == language_ada)
3373 /* For Ada unit, we prefer the linkage name over the name, as
3374 the former contains the exported name, which the user expects
3375 to be able to reference. Ideally, we want the user to be able
3376 to reference this entity using either natural or linkage name,
3377 but we haven't started looking at this enhancement yet. */
3378 struct attribute *attr;
3380 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
3381 if (attr && DW_STRING (attr))
3382 name = DW_STRING (attr);
3388 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3389 If scope qualifiers are appropriate they will be added. The result
3390 will be allocated on the objfile_obstack, or NULL if the DIE does
3391 not have a name. NAME may either be from a previous call to
3392 dwarf2_name or NULL.
3394 The output string will be canonicalized (if C++/Java). */
3397 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
3399 return dwarf2_compute_name (name, die, cu, 0);
3402 /* Construct a physname for the given DIE in CU. NAME may either be
3403 from a previous call to dwarf2_name or NULL. The result will be
3404 allocated on the objfile_objstack or NULL if the DIE does not have a
3407 The output string will be canonicalized (if C++/Java). */
3410 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
3412 return dwarf2_compute_name (name, die, cu, 1);
3415 /* Read the import statement specified by the given die and record it. */
3418 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
3420 struct attribute *import_attr;
3421 struct die_info *imported_die;
3422 struct dwarf2_cu *imported_cu;
3423 const char *imported_name;
3424 const char *imported_name_prefix;
3425 const char *canonical_name;
3426 const char *import_alias;
3427 const char *imported_declaration = NULL;
3428 const char *import_prefix;
3432 import_attr = dwarf2_attr (die, DW_AT_import, cu);
3433 if (import_attr == NULL)
3435 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
3436 dwarf_tag_name (die->tag));
3441 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
3442 imported_name = dwarf2_name (imported_die, imported_cu);
3443 if (imported_name == NULL)
3445 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3447 The import in the following code:
3461 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3462 <52> DW_AT_decl_file : 1
3463 <53> DW_AT_decl_line : 6
3464 <54> DW_AT_import : <0x75>
3465 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3467 <5b> DW_AT_decl_file : 1
3468 <5c> DW_AT_decl_line : 2
3469 <5d> DW_AT_type : <0x6e>
3471 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3472 <76> DW_AT_byte_size : 4
3473 <77> DW_AT_encoding : 5 (signed)
3475 imports the wrong die ( 0x75 instead of 0x58 ).
3476 This case will be ignored until the gcc bug is fixed. */
3480 /* Figure out the local name after import. */
3481 import_alias = dwarf2_name (die, cu);
3483 /* Figure out where the statement is being imported to. */
3484 import_prefix = determine_prefix (die, cu);
3486 /* Figure out what the scope of the imported die is and prepend it
3487 to the name of the imported die. */
3488 imported_name_prefix = determine_prefix (imported_die, imported_cu);
3490 if (imported_die->tag != DW_TAG_namespace)
3492 imported_declaration = imported_name;
3493 canonical_name = imported_name_prefix;
3495 else if (strlen (imported_name_prefix) > 0)
3497 temp = alloca (strlen (imported_name_prefix)
3498 + 2 + strlen (imported_name) + 1);
3499 strcpy (temp, imported_name_prefix);
3500 strcat (temp, "::");
3501 strcat (temp, imported_name);
3502 canonical_name = temp;
3505 canonical_name = imported_name;
3507 cp_add_using_directive (import_prefix,
3510 imported_declaration,
3511 &cu->objfile->objfile_obstack);
3515 initialize_cu_func_list (struct dwarf2_cu *cu)
3517 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
3521 free_cu_line_header (void *arg)
3523 struct dwarf2_cu *cu = arg;
3525 free_line_header (cu->line_header);
3526 cu->line_header = NULL;
3530 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3532 struct objfile *objfile = cu->objfile;
3533 struct comp_unit_head *cu_header = &cu->header;
3534 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3535 CORE_ADDR lowpc = ((CORE_ADDR) -1);
3536 CORE_ADDR highpc = ((CORE_ADDR) 0);
3537 struct attribute *attr;
3539 char *comp_dir = NULL;
3540 struct die_info *child_die;
3541 bfd *abfd = objfile->obfd;
3542 struct line_header *line_header = 0;
3545 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3547 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
3549 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3550 from finish_block. */
3551 if (lowpc == ((CORE_ADDR) -1))
3556 /* Find the filename. Do not use dwarf2_name here, since the filename
3557 is not a source language identifier. */
3558 attr = dwarf2_attr (die, DW_AT_name, cu);
3561 name = DW_STRING (attr);
3564 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3566 comp_dir = DW_STRING (attr);
3567 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3569 comp_dir = ldirname (name);
3570 if (comp_dir != NULL)
3571 make_cleanup (xfree, comp_dir);
3573 if (comp_dir != NULL)
3575 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3576 directory, get rid of it. */
3577 char *cp = strchr (comp_dir, ':');
3579 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3586 attr = dwarf2_attr (die, DW_AT_language, cu);
3589 set_cu_language (DW_UNSND (attr), cu);
3592 attr = dwarf2_attr (die, DW_AT_producer, cu);
3594 cu->producer = DW_STRING (attr);
3596 /* We assume that we're processing GCC output. */
3597 processing_gcc_compilation = 2;
3599 processing_has_namespace_info = 0;
3601 start_symtab (name, comp_dir, lowpc);
3602 record_debugformat ("DWARF 2");
3603 record_producer (cu->producer);
3605 initialize_cu_func_list (cu);
3607 /* Decode line number information if present. We do this before
3608 processing child DIEs, so that the line header table is available
3609 for DW_AT_decl_file. */
3610 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3613 unsigned int line_offset = DW_UNSND (attr);
3614 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
3617 cu->line_header = line_header;
3618 make_cleanup (free_cu_line_header, cu);
3619 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
3623 /* Process all dies in compilation unit. */
3624 if (die->child != NULL)
3626 child_die = die->child;
3627 while (child_die && child_die->tag)
3629 process_die (child_die, cu);
3630 child_die = sibling_die (child_die);
3634 /* Decode macro information, if present. Dwarf 2 macro information
3635 refers to information in the line number info statement program
3636 header, so we can only read it if we've read the header
3638 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
3639 if (attr && line_header)
3641 unsigned int macro_offset = DW_UNSND (attr);
3642 dwarf_decode_macros (line_header, macro_offset,
3643 comp_dir, abfd, cu);
3645 do_cleanups (back_to);
3648 /* For TUs we want to skip the first top level sibling if it's not the
3649 actual type being defined by this TU. In this case the first top
3650 level sibling is there to provide context only. */
3653 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
3655 struct objfile *objfile = cu->objfile;
3656 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3658 struct attribute *attr;
3660 char *comp_dir = NULL;
3661 struct die_info *child_die;
3662 bfd *abfd = objfile->obfd;
3663 struct line_header *line_header = 0;
3665 /* start_symtab needs a low pc, but we don't really have one.
3666 Do what read_file_scope would do in the absence of such info. */
3667 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3669 /* Find the filename. Do not use dwarf2_name here, since the filename
3670 is not a source language identifier. */
3671 attr = dwarf2_attr (die, DW_AT_name, cu);
3673 name = DW_STRING (attr);
3675 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3677 comp_dir = DW_STRING (attr);
3678 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3680 comp_dir = ldirname (name);
3681 if (comp_dir != NULL)
3682 make_cleanup (xfree, comp_dir);
3688 attr = dwarf2_attr (die, DW_AT_language, cu);
3690 set_cu_language (DW_UNSND (attr), cu);
3692 /* This isn't technically needed today. It is done for symmetry
3693 with read_file_scope. */
3694 attr = dwarf2_attr (die, DW_AT_producer, cu);
3696 cu->producer = DW_STRING (attr);
3698 /* We assume that we're processing GCC output. */
3699 processing_gcc_compilation = 2;
3701 processing_has_namespace_info = 0;
3703 start_symtab (name, comp_dir, lowpc);
3704 record_debugformat ("DWARF 2");
3705 record_producer (cu->producer);
3707 /* Process the dies in the type unit. */
3708 if (die->child == NULL)
3710 dump_die_for_error (die);
3711 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3712 bfd_get_filename (abfd));
3715 child_die = die->child;
3717 while (child_die && child_die->tag)
3719 process_die (child_die, cu);
3721 child_die = sibling_die (child_die);
3724 do_cleanups (back_to);
3728 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
3729 struct dwarf2_cu *cu)
3731 struct function_range *thisfn;
3733 thisfn = (struct function_range *)
3734 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
3735 thisfn->name = name;
3736 thisfn->lowpc = lowpc;
3737 thisfn->highpc = highpc;
3738 thisfn->seen_line = 0;
3739 thisfn->next = NULL;
3741 if (cu->last_fn == NULL)
3742 cu->first_fn = thisfn;
3744 cu->last_fn->next = thisfn;
3746 cu->last_fn = thisfn;
3749 /* qsort helper for inherit_abstract_dies. */
3752 unsigned_int_compar (const void *ap, const void *bp)
3754 unsigned int a = *(unsigned int *) ap;
3755 unsigned int b = *(unsigned int *) bp;
3757 return (a > b) - (b > a);
3760 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3761 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3762 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3765 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
3767 struct die_info *child_die;
3768 unsigned die_children_count;
3769 /* CU offsets which were referenced by children of the current DIE. */
3771 unsigned *offsets_end, *offsetp;
3772 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3773 struct die_info *origin_die;
3774 /* Iterator of the ORIGIN_DIE children. */
3775 struct die_info *origin_child_die;
3776 struct cleanup *cleanups;
3777 struct attribute *attr;
3779 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
3783 origin_die = follow_die_ref (die, attr, &cu);
3784 if (die->tag != origin_die->tag
3785 && !(die->tag == DW_TAG_inlined_subroutine
3786 && origin_die->tag == DW_TAG_subprogram))
3787 complaint (&symfile_complaints,
3788 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3789 die->offset, origin_die->offset);
3791 child_die = die->child;
3792 die_children_count = 0;
3793 while (child_die && child_die->tag)
3795 child_die = sibling_die (child_die);
3796 die_children_count++;
3798 offsets = xmalloc (sizeof (*offsets) * die_children_count);
3799 cleanups = make_cleanup (xfree, offsets);
3801 offsets_end = offsets;
3802 child_die = die->child;
3803 while (child_die && child_die->tag)
3805 /* For each CHILD_DIE, find the corresponding child of
3806 ORIGIN_DIE. If there is more than one layer of
3807 DW_AT_abstract_origin, follow them all; there shouldn't be,
3808 but GCC versions at least through 4.4 generate this (GCC PR
3810 struct die_info *child_origin_die = child_die;
3813 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
3816 child_origin_die = follow_die_ref (child_origin_die, attr, &cu);
3819 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3820 counterpart may exist. */
3821 if (child_origin_die != child_die)
3823 if (child_die->tag != child_origin_die->tag
3824 && !(child_die->tag == DW_TAG_inlined_subroutine
3825 && child_origin_die->tag == DW_TAG_subprogram))
3826 complaint (&symfile_complaints,
3827 _("Child DIE 0x%x and its abstract origin 0x%x have "
3828 "different tags"), child_die->offset,
3829 child_origin_die->offset);
3830 if (child_origin_die->parent != origin_die)
3831 complaint (&symfile_complaints,
3832 _("Child DIE 0x%x and its abstract origin 0x%x have "
3833 "different parents"), child_die->offset,
3834 child_origin_die->offset);
3836 *offsets_end++ = child_origin_die->offset;
3838 child_die = sibling_die (child_die);
3840 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
3841 unsigned_int_compar);
3842 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
3843 if (offsetp[-1] == *offsetp)
3844 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
3845 "to DIE 0x%x as their abstract origin"),
3846 die->offset, *offsetp);
3849 origin_child_die = origin_die->child;
3850 while (origin_child_die && origin_child_die->tag)
3852 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3853 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
3855 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
3857 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3858 process_die (origin_child_die, cu);
3860 origin_child_die = sibling_die (origin_child_die);
3863 do_cleanups (cleanups);
3867 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
3869 struct objfile *objfile = cu->objfile;
3870 struct context_stack *new;
3873 struct die_info *child_die;
3874 struct attribute *attr, *call_line, *call_file;
3877 struct block *block;
3878 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
3882 /* If we do not have call site information, we can't show the
3883 caller of this inlined function. That's too confusing, so
3884 only use the scope for local variables. */
3885 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
3886 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
3887 if (call_line == NULL || call_file == NULL)
3889 read_lexical_block_scope (die, cu);
3894 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3896 name = dwarf2_name (die, cu);
3898 /* Ignore functions with missing or empty names. These are actually
3899 illegal according to the DWARF standard. */
3902 complaint (&symfile_complaints,
3903 _("missing name for subprogram DIE at %d"), die->offset);
3907 /* Ignore functions with missing or invalid low and high pc attributes. */
3908 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
3910 complaint (&symfile_complaints,
3911 _("cannot get low and high bounds for subprogram DIE at %d"),
3919 /* Record the function range for dwarf_decode_lines. */
3920 add_to_cu_func_list (name, lowpc, highpc, cu);
3922 new = push_context (0, lowpc);
3923 new->name = new_symbol (die, read_type_die (die, cu), cu);
3925 /* If there is a location expression for DW_AT_frame_base, record
3927 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
3929 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3930 expression is being recorded directly in the function's symbol
3931 and not in a separate frame-base object. I guess this hack is
3932 to avoid adding some sort of frame-base adjunct/annex to the
3933 function's symbol :-(. The problem with doing this is that it
3934 results in a function symbol with a location expression that
3935 has nothing to do with the location of the function, ouch! The
3936 relationship should be: a function's symbol has-a frame base; a
3937 frame-base has-a location expression. */
3938 dwarf2_symbol_mark_computed (attr, new->name, cu);
3940 cu->list_in_scope = &local_symbols;
3942 if (die->child != NULL)
3944 child_die = die->child;
3945 while (child_die && child_die->tag)
3947 process_die (child_die, cu);
3948 child_die = sibling_die (child_die);
3952 inherit_abstract_dies (die, cu);
3954 /* If we have a DW_AT_specification, we might need to import using
3955 directives from the context of the specification DIE. See the
3956 comment in determine_prefix. */
3957 if (cu->language == language_cplus
3958 && dwarf2_attr (die, DW_AT_specification, cu))
3960 struct dwarf2_cu *spec_cu = cu;
3961 struct die_info *spec_die = die_specification (die, &spec_cu);
3965 child_die = spec_die->child;
3966 while (child_die && child_die->tag)
3968 if (child_die->tag == DW_TAG_imported_module)
3969 process_die (child_die, spec_cu);
3970 child_die = sibling_die (child_die);
3973 /* In some cases, GCC generates specification DIEs that
3974 themselves contain DW_AT_specification attributes. */
3975 spec_die = die_specification (spec_die, &spec_cu);
3979 new = pop_context ();
3980 /* Make a block for the local symbols within. */
3981 block = finish_block (new->name, &local_symbols, new->old_blocks,
3982 lowpc, highpc, objfile);
3984 /* For C++, set the block's scope. */
3985 if (cu->language == language_cplus)
3986 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
3987 determine_prefix (die, cu),
3988 processing_has_namespace_info);
3990 /* If we have address ranges, record them. */
3991 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3993 /* In C++, we can have functions nested inside functions (e.g., when
3994 a function declares a class that has methods). This means that
3995 when we finish processing a function scope, we may need to go
3996 back to building a containing block's symbol lists. */
3997 local_symbols = new->locals;
3998 param_symbols = new->params;
3999 using_directives = new->using_directives;
4001 /* If we've finished processing a top-level function, subsequent
4002 symbols go in the file symbol list. */
4003 if (outermost_context_p ())
4004 cu->list_in_scope = &file_symbols;
4007 /* Process all the DIES contained within a lexical block scope. Start
4008 a new scope, process the dies, and then close the scope. */
4011 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
4013 struct objfile *objfile = cu->objfile;
4014 struct context_stack *new;
4015 CORE_ADDR lowpc, highpc;
4016 struct die_info *child_die;
4019 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4021 /* Ignore blocks with missing or invalid low and high pc attributes. */
4022 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4023 as multiple lexical blocks? Handling children in a sane way would
4024 be nasty. Might be easier to properly extend generic blocks to
4026 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
4031 push_context (0, lowpc);
4032 if (die->child != NULL)
4034 child_die = die->child;
4035 while (child_die && child_die->tag)
4037 process_die (child_die, cu);
4038 child_die = sibling_die (child_die);
4041 new = pop_context ();
4043 if (local_symbols != NULL || using_directives != NULL)
4046 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
4049 /* Note that recording ranges after traversing children, as we
4050 do here, means that recording a parent's ranges entails
4051 walking across all its children's ranges as they appear in
4052 the address map, which is quadratic behavior.
4054 It would be nicer to record the parent's ranges before
4055 traversing its children, simply overriding whatever you find
4056 there. But since we don't even decide whether to create a
4057 block until after we've traversed its children, that's hard
4059 dwarf2_record_block_ranges (die, block, baseaddr, cu);
4061 local_symbols = new->locals;
4062 using_directives = new->using_directives;
4065 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4066 Return 1 if the attributes are present and valid, otherwise, return 0.
4067 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4070 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
4071 CORE_ADDR *high_return, struct dwarf2_cu *cu,
4072 struct partial_symtab *ranges_pst)
4074 struct objfile *objfile = cu->objfile;
4075 struct comp_unit_head *cu_header = &cu->header;
4076 bfd *obfd = objfile->obfd;
4077 unsigned int addr_size = cu_header->addr_size;
4078 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
4079 /* Base address selection entry. */
4090 found_base = cu->base_known;
4091 base = cu->base_address;
4093 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
4094 if (offset >= dwarf2_per_objfile->ranges.size)
4096 complaint (&symfile_complaints,
4097 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4101 buffer = dwarf2_per_objfile->ranges.buffer + offset;
4103 /* Read in the largest possible address. */
4104 marker = read_address (obfd, buffer, cu, &dummy);
4105 if ((marker & mask) == mask)
4107 /* If we found the largest possible address, then
4108 read the base address. */
4109 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4110 buffer += 2 * addr_size;
4111 offset += 2 * addr_size;
4117 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4121 CORE_ADDR range_beginning, range_end;
4123 range_beginning = read_address (obfd, buffer, cu, &dummy);
4124 buffer += addr_size;
4125 range_end = read_address (obfd, buffer, cu, &dummy);
4126 buffer += addr_size;
4127 offset += 2 * addr_size;
4129 /* An end of list marker is a pair of zero addresses. */
4130 if (range_beginning == 0 && range_end == 0)
4131 /* Found the end of list entry. */
4134 /* Each base address selection entry is a pair of 2 values.
4135 The first is the largest possible address, the second is
4136 the base address. Check for a base address here. */
4137 if ((range_beginning & mask) == mask)
4139 /* If we found the largest possible address, then
4140 read the base address. */
4141 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4148 /* We have no valid base address for the ranges
4150 complaint (&symfile_complaints,
4151 _("Invalid .debug_ranges data (no base address)"));
4155 range_beginning += base;
4158 if (ranges_pst != NULL && range_beginning < range_end)
4159 addrmap_set_empty (objfile->psymtabs_addrmap,
4160 range_beginning + baseaddr, range_end - 1 + baseaddr,
4163 /* FIXME: This is recording everything as a low-high
4164 segment of consecutive addresses. We should have a
4165 data structure for discontiguous block ranges
4169 low = range_beginning;
4175 if (range_beginning < low)
4176 low = range_beginning;
4177 if (range_end > high)
4183 /* If the first entry is an end-of-list marker, the range
4184 describes an empty scope, i.e. no instructions. */
4190 *high_return = high;
4194 /* Get low and high pc attributes from a die. Return 1 if the attributes
4195 are present and valid, otherwise, return 0. Return -1 if the range is
4196 discontinuous, i.e. derived from DW_AT_ranges information. */
4198 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
4199 CORE_ADDR *highpc, struct dwarf2_cu *cu,
4200 struct partial_symtab *pst)
4202 struct attribute *attr;
4207 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4210 high = DW_ADDR (attr);
4211 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4213 low = DW_ADDR (attr);
4215 /* Found high w/o low attribute. */
4218 /* Found consecutive range of addresses. */
4223 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4226 /* Value of the DW_AT_ranges attribute is the offset in the
4227 .debug_ranges section. */
4228 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
4230 /* Found discontinuous range of addresses. */
4238 /* When using the GNU linker, .gnu.linkonce. sections are used to
4239 eliminate duplicate copies of functions and vtables and such.
4240 The linker will arbitrarily choose one and discard the others.
4241 The AT_*_pc values for such functions refer to local labels in
4242 these sections. If the section from that file was discarded, the
4243 labels are not in the output, so the relocs get a value of 0.
4244 If this is a discarded function, mark the pc bounds as invalid,
4245 so that GDB will ignore it. */
4246 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
4254 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4255 its low and high PC addresses. Do nothing if these addresses could not
4256 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4257 and HIGHPC to the high address if greater than HIGHPC. */
4260 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
4261 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4262 struct dwarf2_cu *cu)
4264 CORE_ADDR low, high;
4265 struct die_info *child = die->child;
4267 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
4269 *lowpc = min (*lowpc, low);
4270 *highpc = max (*highpc, high);
4273 /* If the language does not allow nested subprograms (either inside
4274 subprograms or lexical blocks), we're done. */
4275 if (cu->language != language_ada)
4278 /* Check all the children of the given DIE. If it contains nested
4279 subprograms, then check their pc bounds. Likewise, we need to
4280 check lexical blocks as well, as they may also contain subprogram
4282 while (child && child->tag)
4284 if (child->tag == DW_TAG_subprogram
4285 || child->tag == DW_TAG_lexical_block)
4286 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
4287 child = sibling_die (child);
4291 /* Get the low and high pc's represented by the scope DIE, and store
4292 them in *LOWPC and *HIGHPC. If the correct values can't be
4293 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4296 get_scope_pc_bounds (struct die_info *die,
4297 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4298 struct dwarf2_cu *cu)
4300 CORE_ADDR best_low = (CORE_ADDR) -1;
4301 CORE_ADDR best_high = (CORE_ADDR) 0;
4302 CORE_ADDR current_low, current_high;
4304 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
4306 best_low = current_low;
4307 best_high = current_high;
4311 struct die_info *child = die->child;
4313 while (child && child->tag)
4315 switch (child->tag) {
4316 case DW_TAG_subprogram:
4317 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
4319 case DW_TAG_namespace:
4320 /* FIXME: carlton/2004-01-16: Should we do this for
4321 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4322 that current GCC's always emit the DIEs corresponding
4323 to definitions of methods of classes as children of a
4324 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4325 the DIEs giving the declarations, which could be
4326 anywhere). But I don't see any reason why the
4327 standards says that they have to be there. */
4328 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
4330 if (current_low != ((CORE_ADDR) -1))
4332 best_low = min (best_low, current_low);
4333 best_high = max (best_high, current_high);
4341 child = sibling_die (child);
4346 *highpc = best_high;
4349 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4352 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
4353 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
4355 struct attribute *attr;
4357 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4360 CORE_ADDR high = DW_ADDR (attr);
4361 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4364 CORE_ADDR low = DW_ADDR (attr);
4365 record_block_range (block, baseaddr + low, baseaddr + high - 1);
4369 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4372 bfd *obfd = cu->objfile->obfd;
4374 /* The value of the DW_AT_ranges attribute is the offset of the
4375 address range list in the .debug_ranges section. */
4376 unsigned long offset = DW_UNSND (attr);
4377 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
4379 /* For some target architectures, but not others, the
4380 read_address function sign-extends the addresses it returns.
4381 To recognize base address selection entries, we need a
4383 unsigned int addr_size = cu->header.addr_size;
4384 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
4386 /* The base address, to which the next pair is relative. Note
4387 that this 'base' is a DWARF concept: most entries in a range
4388 list are relative, to reduce the number of relocs against the
4389 debugging information. This is separate from this function's
4390 'baseaddr' argument, which GDB uses to relocate debugging
4391 information from a shared library based on the address at
4392 which the library was loaded. */
4393 CORE_ADDR base = cu->base_address;
4394 int base_known = cu->base_known;
4396 gdb_assert (dwarf2_per_objfile->ranges.readin);
4397 if (offset >= dwarf2_per_objfile->ranges.size)
4399 complaint (&symfile_complaints,
4400 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4407 unsigned int bytes_read;
4408 CORE_ADDR start, end;
4410 start = read_address (obfd, buffer, cu, &bytes_read);
4411 buffer += bytes_read;
4412 end = read_address (obfd, buffer, cu, &bytes_read);
4413 buffer += bytes_read;
4415 /* Did we find the end of the range list? */
4416 if (start == 0 && end == 0)
4419 /* Did we find a base address selection entry? */
4420 else if ((start & base_select_mask) == base_select_mask)
4426 /* We found an ordinary address range. */
4431 complaint (&symfile_complaints,
4432 _("Invalid .debug_ranges data (no base address)"));
4436 record_block_range (block,
4437 baseaddr + base + start,
4438 baseaddr + base + end - 1);
4444 /* Add an aggregate field to the field list. */
4447 dwarf2_add_field (struct field_info *fip, struct die_info *die,
4448 struct dwarf2_cu *cu)
4450 struct objfile *objfile = cu->objfile;
4451 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4452 struct nextfield *new_field;
4453 struct attribute *attr;
4455 char *fieldname = "";
4457 /* Allocate a new field list entry and link it in. */
4458 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4459 make_cleanup (xfree, new_field);
4460 memset (new_field, 0, sizeof (struct nextfield));
4462 if (die->tag == DW_TAG_inheritance)
4464 new_field->next = fip->baseclasses;
4465 fip->baseclasses = new_field;
4469 new_field->next = fip->fields;
4470 fip->fields = new_field;
4474 /* Handle accessibility and virtuality of field.
4475 The default accessibility for members is public, the default
4476 accessibility for inheritance is private. */
4477 if (die->tag != DW_TAG_inheritance)
4478 new_field->accessibility = DW_ACCESS_public;
4480 new_field->accessibility = DW_ACCESS_private;
4481 new_field->virtuality = DW_VIRTUALITY_none;
4483 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4485 new_field->accessibility = DW_UNSND (attr);
4486 if (new_field->accessibility != DW_ACCESS_public)
4487 fip->non_public_fields = 1;
4488 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
4490 new_field->virtuality = DW_UNSND (attr);
4492 fp = &new_field->field;
4494 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
4496 /* Data member other than a C++ static data member. */
4498 /* Get type of field. */
4499 fp->type = die_type (die, cu);
4501 SET_FIELD_BITPOS (*fp, 0);
4503 /* Get bit size of field (zero if none). */
4504 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
4507 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
4511 FIELD_BITSIZE (*fp) = 0;
4514 /* Get bit offset of field. */
4515 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4518 int byte_offset = 0;
4520 if (attr_form_is_section_offset (attr))
4521 dwarf2_complex_location_expr_complaint ();
4522 else if (attr_form_is_constant (attr))
4523 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4524 else if (attr_form_is_block (attr))
4525 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4527 dwarf2_complex_location_expr_complaint ();
4529 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4531 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
4534 if (gdbarch_bits_big_endian (gdbarch))
4536 /* For big endian bits, the DW_AT_bit_offset gives the
4537 additional bit offset from the MSB of the containing
4538 anonymous object to the MSB of the field. We don't
4539 have to do anything special since we don't need to
4540 know the size of the anonymous object. */
4541 FIELD_BITPOS (*fp) += DW_UNSND (attr);
4545 /* For little endian bits, compute the bit offset to the
4546 MSB of the anonymous object, subtract off the number of
4547 bits from the MSB of the field to the MSB of the
4548 object, and then subtract off the number of bits of
4549 the field itself. The result is the bit offset of
4550 the LSB of the field. */
4552 int bit_offset = DW_UNSND (attr);
4554 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4557 /* The size of the anonymous object containing
4558 the bit field is explicit, so use the
4559 indicated size (in bytes). */
4560 anonymous_size = DW_UNSND (attr);
4564 /* The size of the anonymous object containing
4565 the bit field must be inferred from the type
4566 attribute of the data member containing the
4568 anonymous_size = TYPE_LENGTH (fp->type);
4570 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
4571 - bit_offset - FIELD_BITSIZE (*fp);
4575 /* Get name of field. */
4576 fieldname = dwarf2_name (die, cu);
4577 if (fieldname == NULL)
4580 /* The name is already allocated along with this objfile, so we don't
4581 need to duplicate it for the type. */
4582 fp->name = fieldname;
4584 /* Change accessibility for artificial fields (e.g. virtual table
4585 pointer or virtual base class pointer) to private. */
4586 if (dwarf2_attr (die, DW_AT_artificial, cu))
4588 FIELD_ARTIFICIAL (*fp) = 1;
4589 new_field->accessibility = DW_ACCESS_private;
4590 fip->non_public_fields = 1;
4593 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
4595 /* C++ static member. */
4597 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4598 is a declaration, but all versions of G++ as of this writing
4599 (so through at least 3.2.1) incorrectly generate
4600 DW_TAG_variable tags. */
4604 /* Get name of field. */
4605 fieldname = dwarf2_name (die, cu);
4606 if (fieldname == NULL)
4609 /* Get physical name. */
4610 physname = (char *) dwarf2_physname (fieldname, die, cu);
4612 /* The name is already allocated along with this objfile, so we don't
4613 need to duplicate it for the type. */
4614 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
4615 FIELD_TYPE (*fp) = die_type (die, cu);
4616 FIELD_NAME (*fp) = fieldname;
4618 else if (die->tag == DW_TAG_inheritance)
4620 /* C++ base class field. */
4621 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4624 int byte_offset = 0;
4626 if (attr_form_is_section_offset (attr))
4627 dwarf2_complex_location_expr_complaint ();
4628 else if (attr_form_is_constant (attr))
4629 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4630 else if (attr_form_is_block (attr))
4631 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4633 dwarf2_complex_location_expr_complaint ();
4635 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4637 FIELD_BITSIZE (*fp) = 0;
4638 FIELD_TYPE (*fp) = die_type (die, cu);
4639 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
4640 fip->nbaseclasses++;
4644 /* Create the vector of fields, and attach it to the type. */
4647 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
4648 struct dwarf2_cu *cu)
4650 int nfields = fip->nfields;
4652 /* Record the field count, allocate space for the array of fields,
4653 and create blank accessibility bitfields if necessary. */
4654 TYPE_NFIELDS (type) = nfields;
4655 TYPE_FIELDS (type) = (struct field *)
4656 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4657 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4659 if (fip->non_public_fields && cu->language != language_ada)
4661 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4663 TYPE_FIELD_PRIVATE_BITS (type) =
4664 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4665 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4667 TYPE_FIELD_PROTECTED_BITS (type) =
4668 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4669 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4671 TYPE_FIELD_IGNORE_BITS (type) =
4672 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4673 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4676 /* If the type has baseclasses, allocate and clear a bit vector for
4677 TYPE_FIELD_VIRTUAL_BITS. */
4678 if (fip->nbaseclasses && cu->language != language_ada)
4680 int num_bytes = B_BYTES (fip->nbaseclasses);
4681 unsigned char *pointer;
4683 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4684 pointer = TYPE_ALLOC (type, num_bytes);
4685 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
4686 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
4687 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
4690 /* Copy the saved-up fields into the field vector. Start from the head
4691 of the list, adding to the tail of the field array, so that they end
4692 up in the same order in the array in which they were added to the list. */
4693 while (nfields-- > 0)
4695 struct nextfield *fieldp;
4699 fieldp = fip->fields;
4700 fip->fields = fieldp->next;
4704 fieldp = fip->baseclasses;
4705 fip->baseclasses = fieldp->next;
4708 TYPE_FIELD (type, nfields) = fieldp->field;
4709 switch (fieldp->accessibility)
4711 case DW_ACCESS_private:
4712 if (cu->language != language_ada)
4713 SET_TYPE_FIELD_PRIVATE (type, nfields);
4716 case DW_ACCESS_protected:
4717 if (cu->language != language_ada)
4718 SET_TYPE_FIELD_PROTECTED (type, nfields);
4721 case DW_ACCESS_public:
4725 /* Unknown accessibility. Complain and treat it as public. */
4727 complaint (&symfile_complaints, _("unsupported accessibility %d"),
4728 fieldp->accessibility);
4732 if (nfields < fip->nbaseclasses)
4734 switch (fieldp->virtuality)
4736 case DW_VIRTUALITY_virtual:
4737 case DW_VIRTUALITY_pure_virtual:
4738 if (cu->language == language_ada)
4739 error ("unexpected virtuality in component of Ada type");
4740 SET_TYPE_FIELD_VIRTUAL (type, nfields);
4747 /* Add a member function to the proper fieldlist. */
4750 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
4751 struct type *type, struct dwarf2_cu *cu)
4753 struct objfile *objfile = cu->objfile;
4754 struct attribute *attr;
4755 struct fnfieldlist *flp;
4757 struct fn_field *fnp;
4760 struct nextfnfield *new_fnfield;
4761 struct type *this_type;
4763 if (cu->language == language_ada)
4764 error ("unexpected member function in Ada type");
4766 /* Get name of member function. */
4767 fieldname = dwarf2_name (die, cu);
4768 if (fieldname == NULL)
4771 /* Get the mangled name. */
4772 physname = (char *) dwarf2_physname (fieldname, die, cu);
4774 /* Look up member function name in fieldlist. */
4775 for (i = 0; i < fip->nfnfields; i++)
4777 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
4781 /* Create new list element if necessary. */
4782 if (i < fip->nfnfields)
4783 flp = &fip->fnfieldlists[i];
4786 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
4788 fip->fnfieldlists = (struct fnfieldlist *)
4789 xrealloc (fip->fnfieldlists,
4790 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
4791 * sizeof (struct fnfieldlist));
4792 if (fip->nfnfields == 0)
4793 make_cleanup (free_current_contents, &fip->fnfieldlists);
4795 flp = &fip->fnfieldlists[fip->nfnfields];
4796 flp->name = fieldname;
4802 /* Create a new member function field and chain it to the field list
4804 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
4805 make_cleanup (xfree, new_fnfield);
4806 memset (new_fnfield, 0, sizeof (struct nextfnfield));
4807 new_fnfield->next = flp->head;
4808 flp->head = new_fnfield;
4811 /* Fill in the member function field info. */
4812 fnp = &new_fnfield->fnfield;
4813 /* The name is already allocated along with this objfile, so we don't
4814 need to duplicate it for the type. */
4815 fnp->physname = physname ? physname : "";
4816 fnp->type = alloc_type (objfile);
4817 this_type = read_type_die (die, cu);
4818 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
4820 int nparams = TYPE_NFIELDS (this_type);
4822 /* TYPE is the domain of this method, and THIS_TYPE is the type
4823 of the method itself (TYPE_CODE_METHOD). */
4824 smash_to_method_type (fnp->type, type,
4825 TYPE_TARGET_TYPE (this_type),
4826 TYPE_FIELDS (this_type),
4827 TYPE_NFIELDS (this_type),
4828 TYPE_VARARGS (this_type));
4830 /* Handle static member functions.
4831 Dwarf2 has no clean way to discern C++ static and non-static
4832 member functions. G++ helps GDB by marking the first
4833 parameter for non-static member functions (which is the
4834 this pointer) as artificial. We obtain this information
4835 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4836 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
4837 fnp->voffset = VOFFSET_STATIC;
4840 complaint (&symfile_complaints, _("member function type missing for '%s'"),
4843 /* Get fcontext from DW_AT_containing_type if present. */
4844 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4845 fnp->fcontext = die_containing_type (die, cu);
4847 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4848 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4850 /* Get accessibility. */
4851 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4854 switch (DW_UNSND (attr))
4856 case DW_ACCESS_private:
4857 fnp->is_private = 1;
4859 case DW_ACCESS_protected:
4860 fnp->is_protected = 1;
4865 /* Check for artificial methods. */
4866 attr = dwarf2_attr (die, DW_AT_artificial, cu);
4867 if (attr && DW_UNSND (attr) != 0)
4868 fnp->is_artificial = 1;
4870 /* Get index in virtual function table if it is a virtual member
4871 function. For GCC, this is an offset in the appropriate
4872 virtual table, as specified by DW_AT_containing_type. For
4873 everyone else, it is an expression to be evaluated relative
4874 to the object address. */
4876 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
4877 if (attr && fnp->fcontext)
4879 /* Support the .debug_loc offsets */
4880 if (attr_form_is_block (attr))
4882 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
4884 else if (attr_form_is_section_offset (attr))
4886 dwarf2_complex_location_expr_complaint ();
4890 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4896 /* We only support trivial expressions here. This hack will work
4897 for v3 classes, which always start with the vtable pointer. */
4898 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0
4899 && DW_BLOCK (attr)->data[0] == DW_OP_deref)
4901 struct dwarf_block blk;
4902 blk.size = DW_BLOCK (attr)->size - 1;
4903 blk.data = DW_BLOCK (attr)->data + 1;
4904 fnp->voffset = decode_locdesc (&blk, cu);
4905 if ((fnp->voffset % cu->header.addr_size) != 0)
4906 dwarf2_complex_location_expr_complaint ();
4908 fnp->voffset /= cu->header.addr_size;
4910 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
4913 dwarf2_complex_location_expr_complaint ();
4917 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
4918 if (attr && DW_UNSND (attr))
4920 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4921 complaint (&symfile_complaints,
4922 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4923 fieldname, die->offset);
4924 TYPE_CPLUS_DYNAMIC (type) = 1;
4929 /* Create the vector of member function fields, and attach it to the type. */
4932 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
4933 struct dwarf2_cu *cu)
4935 struct fnfieldlist *flp;
4936 int total_length = 0;
4939 if (cu->language == language_ada)
4940 error ("unexpected member functions in Ada type");
4942 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4943 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4944 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
4946 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
4948 struct nextfnfield *nfp = flp->head;
4949 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
4952 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
4953 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
4954 fn_flp->fn_fields = (struct fn_field *)
4955 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
4956 for (k = flp->length; (k--, nfp); nfp = nfp->next)
4957 fn_flp->fn_fields[k] = nfp->fnfield;
4959 total_length += flp->length;
4962 TYPE_NFN_FIELDS (type) = fip->nfnfields;
4963 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
4966 /* Returns non-zero if NAME is the name of a vtable member in CU's
4967 language, zero otherwise. */
4969 is_vtable_name (const char *name, struct dwarf2_cu *cu)
4971 static const char vptr[] = "_vptr";
4972 static const char vtable[] = "vtable";
4974 /* Look for the C++ and Java forms of the vtable. */
4975 if ((cu->language == language_java
4976 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
4977 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
4978 && is_cplus_marker (name[sizeof (vptr) - 1])))
4984 /* GCC outputs unnamed structures that are really pointers to member
4985 functions, with the ABI-specified layout. If TYPE describes
4986 such a structure, smash it into a member function type.
4988 GCC shouldn't do this; it should just output pointer to member DIEs.
4989 This is GCC PR debug/28767. */
4992 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
4994 struct type *pfn_type, *domain_type, *new_type;
4996 /* Check for a structure with no name and two children. */
4997 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
5000 /* Check for __pfn and __delta members. */
5001 if (TYPE_FIELD_NAME (type, 0) == NULL
5002 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
5003 || TYPE_FIELD_NAME (type, 1) == NULL
5004 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
5007 /* Find the type of the method. */
5008 pfn_type = TYPE_FIELD_TYPE (type, 0);
5009 if (pfn_type == NULL
5010 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
5011 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
5014 /* Look for the "this" argument. */
5015 pfn_type = TYPE_TARGET_TYPE (pfn_type);
5016 if (TYPE_NFIELDS (pfn_type) == 0
5017 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5018 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
5021 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
5022 new_type = alloc_type (objfile);
5023 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
5024 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
5025 TYPE_VARARGS (pfn_type));
5026 smash_to_methodptr_type (type, new_type);
5029 /* Called when we find the DIE that starts a structure or union scope
5030 (definition) to process all dies that define the members of the
5033 NOTE: we need to call struct_type regardless of whether or not the
5034 DIE has an at_name attribute, since it might be an anonymous
5035 structure or union. This gets the type entered into our set of
5038 However, if the structure is incomplete (an opaque struct/union)
5039 then suppress creating a symbol table entry for it since gdb only
5040 wants to find the one with the complete definition. Note that if
5041 it is complete, we just call new_symbol, which does it's own
5042 checking about whether the struct/union is anonymous or not (and
5043 suppresses creating a symbol table entry itself). */
5045 static struct type *
5046 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
5048 struct objfile *objfile = cu->objfile;
5050 struct attribute *attr;
5052 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5054 /* If the definition of this type lives in .debug_types, read that type.
5055 Don't follow DW_AT_specification though, that will take us back up
5056 the chain and we want to go down. */
5057 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
5060 struct dwarf2_cu *type_cu = cu;
5061 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
5062 /* We could just recurse on read_structure_type, but we need to call
5063 get_die_type to ensure only one type for this DIE is created.
5064 This is important, for example, because for c++ classes we need
5065 TYPE_NAME set which is only done by new_symbol. Blech. */
5066 type = read_type_die (type_die, type_cu);
5067 return set_die_type (die, type, cu);
5070 type = alloc_type (objfile);
5071 INIT_CPLUS_SPECIFIC (type);
5073 name = dwarf2_name (die, cu);
5076 if (cu->language == language_cplus
5077 || cu->language == language_java)
5079 TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu);
5080 if (die->tag == DW_TAG_structure_type
5081 || die->tag == DW_TAG_class_type)
5082 TYPE_NAME (type) = TYPE_TAG_NAME (type);
5086 /* The name is already allocated along with this objfile, so
5087 we don't need to duplicate it for the type. */
5088 TYPE_TAG_NAME (type) = (char *) name;
5089 if (die->tag == DW_TAG_class_type)
5090 TYPE_NAME (type) = TYPE_TAG_NAME (type);
5094 if (die->tag == DW_TAG_structure_type)
5096 TYPE_CODE (type) = TYPE_CODE_STRUCT;
5098 else if (die->tag == DW_TAG_union_type)
5100 TYPE_CODE (type) = TYPE_CODE_UNION;
5104 TYPE_CODE (type) = TYPE_CODE_CLASS;
5107 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
5108 TYPE_DECLARED_CLASS (type) = 1;
5110 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5113 TYPE_LENGTH (type) = DW_UNSND (attr);
5117 TYPE_LENGTH (type) = 0;
5120 TYPE_STUB_SUPPORTED (type) = 1;
5121 if (die_is_declaration (die, cu))
5122 TYPE_STUB (type) = 1;
5123 else if (attr == NULL && die->child == NULL
5124 && producer_is_realview (cu->producer))
5125 /* RealView does not output the required DW_AT_declaration
5126 on incomplete types. */
5127 TYPE_STUB (type) = 1;
5129 set_descriptive_type (type, die, cu);
5131 /* We need to add the type field to the die immediately so we don't
5132 infinitely recurse when dealing with pointers to the structure
5133 type within the structure itself. */
5134 set_die_type (die, type, cu);
5136 if (die->child != NULL && ! die_is_declaration (die, cu))
5138 struct field_info fi;
5139 struct die_info *child_die;
5141 memset (&fi, 0, sizeof (struct field_info));
5143 child_die = die->child;
5145 while (child_die && child_die->tag)
5147 if (child_die->tag == DW_TAG_member
5148 || child_die->tag == DW_TAG_variable)
5150 /* NOTE: carlton/2002-11-05: A C++ static data member
5151 should be a DW_TAG_member that is a declaration, but
5152 all versions of G++ as of this writing (so through at
5153 least 3.2.1) incorrectly generate DW_TAG_variable
5154 tags for them instead. */
5155 dwarf2_add_field (&fi, child_die, cu);
5157 else if (child_die->tag == DW_TAG_subprogram)
5159 /* C++ member function. */
5160 dwarf2_add_member_fn (&fi, child_die, type, cu);
5162 else if (child_die->tag == DW_TAG_inheritance)
5164 /* C++ base class field. */
5165 dwarf2_add_field (&fi, child_die, cu);
5167 child_die = sibling_die (child_die);
5170 /* Attach fields and member functions to the type. */
5172 dwarf2_attach_fields_to_type (&fi, type, cu);
5175 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
5177 /* Get the type which refers to the base class (possibly this
5178 class itself) which contains the vtable pointer for the current
5179 class from the DW_AT_containing_type attribute. This use of
5180 DW_AT_containing_type is a GNU extension. */
5182 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
5184 struct type *t = die_containing_type (die, cu);
5186 TYPE_VPTR_BASETYPE (type) = t;
5191 /* Our own class provides vtbl ptr. */
5192 for (i = TYPE_NFIELDS (t) - 1;
5193 i >= TYPE_N_BASECLASSES (t);
5196 char *fieldname = TYPE_FIELD_NAME (t, i);
5198 if (is_vtable_name (fieldname, cu))
5200 TYPE_VPTR_FIELDNO (type) = i;
5205 /* Complain if virtual function table field not found. */
5206 if (i < TYPE_N_BASECLASSES (t))
5207 complaint (&symfile_complaints,
5208 _("virtual function table pointer not found when defining class '%s'"),
5209 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
5214 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
5217 else if (cu->producer
5218 && strncmp (cu->producer,
5219 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5221 /* The IBM XLC compiler does not provide direct indication
5222 of the containing type, but the vtable pointer is
5223 always named __vfp. */
5227 for (i = TYPE_NFIELDS (type) - 1;
5228 i >= TYPE_N_BASECLASSES (type);
5231 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
5233 TYPE_VPTR_FIELDNO (type) = i;
5234 TYPE_VPTR_BASETYPE (type) = type;
5242 quirk_gcc_member_function_pointer (type, cu->objfile);
5244 do_cleanups (back_to);
5249 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
5251 struct objfile *objfile = cu->objfile;
5252 struct die_info *child_die = die->child;
5253 struct type *this_type;
5255 this_type = get_die_type (die, cu);
5256 if (this_type == NULL)
5257 this_type = read_structure_type (die, cu);
5259 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5260 snapshots) has been known to create a die giving a declaration
5261 for a class that has, as a child, a die giving a definition for a
5262 nested class. So we have to process our children even if the
5263 current die is a declaration. Normally, of course, a declaration
5264 won't have any children at all. */
5266 while (child_die != NULL && child_die->tag)
5268 if (child_die->tag == DW_TAG_member
5269 || child_die->tag == DW_TAG_variable
5270 || child_die->tag == DW_TAG_inheritance)
5275 process_die (child_die, cu);
5277 child_die = sibling_die (child_die);
5280 /* Do not consider external references. According to the DWARF standard,
5281 these DIEs are identified by the fact that they have no byte_size
5282 attribute, and a declaration attribute. */
5283 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
5284 || !die_is_declaration (die, cu))
5285 new_symbol (die, this_type, cu);
5288 /* Given a DW_AT_enumeration_type die, set its type. We do not
5289 complete the type's fields yet, or create any symbols. */
5291 static struct type *
5292 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
5294 struct objfile *objfile = cu->objfile;
5296 struct attribute *attr;
5299 /* If the definition of this type lives in .debug_types, read that type.
5300 Don't follow DW_AT_specification though, that will take us back up
5301 the chain and we want to go down. */
5302 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
5305 struct dwarf2_cu *type_cu = cu;
5306 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
5307 type = read_type_die (type_die, type_cu);
5308 return set_die_type (die, type, cu);
5311 type = alloc_type (objfile);
5313 TYPE_CODE (type) = TYPE_CODE_ENUM;
5314 name = dwarf2_full_name (NULL, die, cu);
5316 TYPE_TAG_NAME (type) = (char *) name;
5318 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5321 TYPE_LENGTH (type) = DW_UNSND (attr);
5325 TYPE_LENGTH (type) = 0;
5328 /* The enumeration DIE can be incomplete. In Ada, any type can be
5329 declared as private in the package spec, and then defined only
5330 inside the package body. Such types are known as Taft Amendment
5331 Types. When another package uses such a type, an incomplete DIE
5332 may be generated by the compiler. */
5333 if (die_is_declaration (die, cu))
5334 TYPE_STUB (type) = 1;
5336 return set_die_type (die, type, cu);
5339 /* Given a pointer to a die which begins an enumeration, process all
5340 the dies that define the members of the enumeration, and create the
5341 symbol for the enumeration type.
5343 NOTE: We reverse the order of the element list. */
5346 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
5348 struct objfile *objfile = cu->objfile;
5349 struct die_info *child_die;
5350 struct field *fields;
5353 int unsigned_enum = 1;
5355 struct type *this_type;
5359 this_type = get_die_type (die, cu);
5360 if (this_type == NULL)
5361 this_type = read_enumeration_type (die, cu);
5362 if (die->child != NULL)
5364 child_die = die->child;
5365 while (child_die && child_die->tag)
5367 if (child_die->tag != DW_TAG_enumerator)
5369 process_die (child_die, cu);
5373 name = dwarf2_name (child_die, cu);
5376 sym = new_symbol (child_die, this_type, cu);
5377 if (SYMBOL_VALUE (sym) < 0)
5380 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
5382 fields = (struct field *)
5384 (num_fields + DW_FIELD_ALLOC_CHUNK)
5385 * sizeof (struct field));
5388 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
5389 FIELD_TYPE (fields[num_fields]) = NULL;
5390 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
5391 FIELD_BITSIZE (fields[num_fields]) = 0;
5397 child_die = sibling_die (child_die);
5402 TYPE_NFIELDS (this_type) = num_fields;
5403 TYPE_FIELDS (this_type) = (struct field *)
5404 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
5405 memcpy (TYPE_FIELDS (this_type), fields,
5406 sizeof (struct field) * num_fields);
5410 TYPE_UNSIGNED (this_type) = 1;
5413 new_symbol (die, this_type, cu);
5416 /* Extract all information from a DW_TAG_array_type DIE and put it in
5417 the DIE's type field. For now, this only handles one dimensional
5420 static struct type *
5421 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
5423 struct objfile *objfile = cu->objfile;
5424 struct die_info *child_die;
5425 struct type *type = NULL;
5426 struct type *element_type, *range_type, *index_type;
5427 struct type **range_types = NULL;
5428 struct attribute *attr;
5430 struct cleanup *back_to;
5433 element_type = die_type (die, cu);
5435 /* Irix 6.2 native cc creates array types without children for
5436 arrays with unspecified length. */
5437 if (die->child == NULL)
5439 index_type = objfile_type (objfile)->builtin_int;
5440 range_type = create_range_type (NULL, index_type, 0, -1);
5441 type = create_array_type (NULL, element_type, range_type);
5442 return set_die_type (die, type, cu);
5445 back_to = make_cleanup (null_cleanup, NULL);
5446 child_die = die->child;
5447 while (child_die && child_die->tag)
5449 if (child_die->tag == DW_TAG_subrange_type)
5451 struct type *child_type = read_type_die (child_die, cu);
5452 if (child_type != NULL)
5454 /* The range type was succesfully read. Save it for
5455 the array type creation. */
5456 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
5458 range_types = (struct type **)
5459 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
5460 * sizeof (struct type *));
5462 make_cleanup (free_current_contents, &range_types);
5464 range_types[ndim++] = child_type;
5467 child_die = sibling_die (child_die);
5470 /* Dwarf2 dimensions are output from left to right, create the
5471 necessary array types in backwards order. */
5473 type = element_type;
5475 if (read_array_order (die, cu) == DW_ORD_col_major)
5479 type = create_array_type (NULL, type, range_types[i++]);
5484 type = create_array_type (NULL, type, range_types[ndim]);
5487 /* Understand Dwarf2 support for vector types (like they occur on
5488 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5489 array type. This is not part of the Dwarf2/3 standard yet, but a
5490 custom vendor extension. The main difference between a regular
5491 array and the vector variant is that vectors are passed by value
5493 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
5495 make_vector_type (type);
5497 name = dwarf2_name (die, cu);
5499 TYPE_NAME (type) = name;
5501 set_descriptive_type (type, die, cu);
5503 do_cleanups (back_to);
5505 /* Install the type in the die. */
5506 return set_die_type (die, type, cu);
5509 static enum dwarf_array_dim_ordering
5510 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
5512 struct attribute *attr;
5514 attr = dwarf2_attr (die, DW_AT_ordering, cu);
5516 if (attr) return DW_SND (attr);
5519 GNU F77 is a special case, as at 08/2004 array type info is the
5520 opposite order to the dwarf2 specification, but data is still
5521 laid out as per normal fortran.
5523 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5527 if (cu->language == language_fortran
5528 && cu->producer && strstr (cu->producer, "GNU F77"))
5530 return DW_ORD_row_major;
5533 switch (cu->language_defn->la_array_ordering)
5535 case array_column_major:
5536 return DW_ORD_col_major;
5537 case array_row_major:
5539 return DW_ORD_row_major;
5543 /* Extract all information from a DW_TAG_set_type DIE and put it in
5544 the DIE's type field. */
5546 static struct type *
5547 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
5549 struct type *set_type = create_set_type (NULL, die_type (die, cu));
5551 return set_die_type (die, set_type, cu);
5554 /* First cut: install each common block member as a global variable. */
5557 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
5559 struct die_info *child_die;
5560 struct attribute *attr;
5562 CORE_ADDR base = (CORE_ADDR) 0;
5564 attr = dwarf2_attr (die, DW_AT_location, cu);
5567 /* Support the .debug_loc offsets */
5568 if (attr_form_is_block (attr))
5570 base = decode_locdesc (DW_BLOCK (attr), cu);
5572 else if (attr_form_is_section_offset (attr))
5574 dwarf2_complex_location_expr_complaint ();
5578 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5579 "common block member");
5582 if (die->child != NULL)
5584 child_die = die->child;
5585 while (child_die && child_die->tag)
5587 sym = new_symbol (child_die, NULL, cu);
5588 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
5591 CORE_ADDR byte_offset = 0;
5593 if (attr_form_is_section_offset (attr))
5594 dwarf2_complex_location_expr_complaint ();
5595 else if (attr_form_is_constant (attr))
5596 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5597 else if (attr_form_is_block (attr))
5598 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5600 dwarf2_complex_location_expr_complaint ();
5602 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
5603 add_symbol_to_list (sym, &global_symbols);
5605 child_die = sibling_die (child_die);
5610 /* Create a type for a C++ namespace. */
5612 static struct type *
5613 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
5615 struct objfile *objfile = cu->objfile;
5616 const char *previous_prefix, *name;
5620 /* For extensions, reuse the type of the original namespace. */
5621 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
5623 struct die_info *ext_die;
5624 struct dwarf2_cu *ext_cu = cu;
5625 ext_die = dwarf2_extension (die, &ext_cu);
5626 type = read_type_die (ext_die, ext_cu);
5627 return set_die_type (die, type, cu);
5630 name = namespace_name (die, &is_anonymous, cu);
5632 /* Now build the name of the current namespace. */
5634 previous_prefix = determine_prefix (die, cu);
5635 if (previous_prefix[0] != '\0')
5636 name = typename_concat (&objfile->objfile_obstack,
5637 previous_prefix, name, cu);
5639 /* Create the type. */
5640 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
5642 TYPE_NAME (type) = (char *) name;
5643 TYPE_TAG_NAME (type) = TYPE_NAME (type);
5645 return set_die_type (die, type, cu);
5648 /* Read a C++ namespace. */
5651 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
5653 struct objfile *objfile = cu->objfile;
5657 /* Add a symbol associated to this if we haven't seen the namespace
5658 before. Also, add a using directive if it's an anonymous
5661 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
5665 type = read_type_die (die, cu);
5666 new_symbol (die, type, cu);
5668 name = namespace_name (die, &is_anonymous, cu);
5671 const char *previous_prefix = determine_prefix (die, cu);
5672 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
5673 NULL, &objfile->objfile_obstack);
5677 if (die->child != NULL)
5679 struct die_info *child_die = die->child;
5681 while (child_die && child_die->tag)
5683 process_die (child_die, cu);
5684 child_die = sibling_die (child_die);
5689 /* Read a Fortran module. */
5692 read_module (struct die_info *die, struct dwarf2_cu *cu)
5694 struct die_info *child_die = die->child;
5696 /* FIXME: Support the separate Fortran module namespaces. */
5698 while (child_die && child_die->tag)
5700 process_die (child_die, cu);
5701 child_die = sibling_die (child_die);
5705 /* Return the name of the namespace represented by DIE. Set
5706 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5710 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
5712 struct die_info *current_die;
5713 const char *name = NULL;
5715 /* Loop through the extensions until we find a name. */
5717 for (current_die = die;
5718 current_die != NULL;
5719 current_die = dwarf2_extension (die, &cu))
5721 name = dwarf2_name (current_die, cu);
5726 /* Is it an anonymous namespace? */
5728 *is_anonymous = (name == NULL);
5730 name = "(anonymous namespace)";
5735 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5736 the user defined type vector. */
5738 static struct type *
5739 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
5741 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5742 struct comp_unit_head *cu_header = &cu->header;
5744 struct attribute *attr_byte_size;
5745 struct attribute *attr_address_class;
5746 int byte_size, addr_class;
5748 type = lookup_pointer_type (die_type (die, cu));
5750 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
5752 byte_size = DW_UNSND (attr_byte_size);
5754 byte_size = cu_header->addr_size;
5756 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
5757 if (attr_address_class)
5758 addr_class = DW_UNSND (attr_address_class);
5760 addr_class = DW_ADDR_none;
5762 /* If the pointer size or address class is different than the
5763 default, create a type variant marked as such and set the
5764 length accordingly. */
5765 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
5767 if (gdbarch_address_class_type_flags_p (gdbarch))
5771 type_flags = gdbarch_address_class_type_flags
5772 (gdbarch, byte_size, addr_class);
5773 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
5775 type = make_type_with_address_space (type, type_flags);
5777 else if (TYPE_LENGTH (type) != byte_size)
5779 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
5782 /* Should we also complain about unhandled address classes? */
5786 TYPE_LENGTH (type) = byte_size;
5787 return set_die_type (die, type, cu);
5790 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5791 the user defined type vector. */
5793 static struct type *
5794 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
5796 struct objfile *objfile = cu->objfile;
5798 struct type *to_type;
5799 struct type *domain;
5801 to_type = die_type (die, cu);
5802 domain = die_containing_type (die, cu);
5804 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
5805 type = lookup_methodptr_type (to_type);
5807 type = lookup_memberptr_type (to_type, domain);
5809 return set_die_type (die, type, cu);
5812 /* Extract all information from a DW_TAG_reference_type DIE and add to
5813 the user defined type vector. */
5815 static struct type *
5816 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
5818 struct comp_unit_head *cu_header = &cu->header;
5820 struct attribute *attr;
5822 type = lookup_reference_type (die_type (die, cu));
5823 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5826 TYPE_LENGTH (type) = DW_UNSND (attr);
5830 TYPE_LENGTH (type) = cu_header->addr_size;
5832 return set_die_type (die, type, cu);
5835 static struct type *
5836 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
5838 struct type *base_type, *cv_type;
5840 base_type = die_type (die, cu);
5841 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
5842 return set_die_type (die, cv_type, cu);
5845 static struct type *
5846 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
5848 struct type *base_type, *cv_type;
5850 base_type = die_type (die, cu);
5851 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
5852 return set_die_type (die, cv_type, cu);
5855 /* Extract all information from a DW_TAG_string_type DIE and add to
5856 the user defined type vector. It isn't really a user defined type,
5857 but it behaves like one, with other DIE's using an AT_user_def_type
5858 attribute to reference it. */
5860 static struct type *
5861 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5863 struct objfile *objfile = cu->objfile;
5864 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5865 struct type *type, *range_type, *index_type, *char_type;
5866 struct attribute *attr;
5867 unsigned int length;
5869 attr = dwarf2_attr (die, DW_AT_string_length, cu);
5872 length = DW_UNSND (attr);
5876 /* check for the DW_AT_byte_size attribute */
5877 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5880 length = DW_UNSND (attr);
5888 index_type = objfile_type (objfile)->builtin_int;
5889 range_type = create_range_type (NULL, index_type, 1, length);
5890 char_type = language_string_char_type (cu->language_defn, gdbarch);
5891 type = create_string_type (NULL, char_type, range_type);
5893 return set_die_type (die, type, cu);
5896 /* Handle DIES due to C code like:
5900 int (*funcp)(int a, long l);
5904 ('funcp' generates a DW_TAG_subroutine_type DIE)
5907 static struct type *
5908 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
5910 struct type *type; /* Type that this function returns */
5911 struct type *ftype; /* Function that returns above type */
5912 struct attribute *attr;
5914 type = die_type (die, cu);
5915 ftype = lookup_function_type (type);
5917 /* All functions in C++, Pascal and Java have prototypes. */
5918 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
5919 if ((attr && (DW_UNSND (attr) != 0))
5920 || cu->language == language_cplus
5921 || cu->language == language_java
5922 || cu->language == language_pascal)
5923 TYPE_PROTOTYPED (ftype) = 1;
5924 else if (producer_is_realview (cu->producer))
5925 /* RealView does not emit DW_AT_prototyped. We can not
5926 distinguish prototyped and unprototyped functions; default to
5927 prototyped, since that is more common in modern code (and
5928 RealView warns about unprototyped functions). */
5929 TYPE_PROTOTYPED (ftype) = 1;
5931 /* Store the calling convention in the type if it's available in
5932 the subroutine die. Otherwise set the calling convention to
5933 the default value DW_CC_normal. */
5934 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
5935 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
5937 /* We need to add the subroutine type to the die immediately so
5938 we don't infinitely recurse when dealing with parameters
5939 declared as the same subroutine type. */
5940 set_die_type (die, ftype, cu);
5942 if (die->child != NULL)
5944 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
5945 struct die_info *child_die;
5946 int nparams, iparams;
5948 /* Count the number of parameters.
5949 FIXME: GDB currently ignores vararg functions, but knows about
5950 vararg member functions. */
5952 child_die = die->child;
5953 while (child_die && child_die->tag)
5955 if (child_die->tag == DW_TAG_formal_parameter)
5957 else if (child_die->tag == DW_TAG_unspecified_parameters)
5958 TYPE_VARARGS (ftype) = 1;
5959 child_die = sibling_die (child_die);
5962 /* Allocate storage for parameters and fill them in. */
5963 TYPE_NFIELDS (ftype) = nparams;
5964 TYPE_FIELDS (ftype) = (struct field *)
5965 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
5967 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
5968 even if we error out during the parameters reading below. */
5969 for (iparams = 0; iparams < nparams; iparams++)
5970 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
5973 child_die = die->child;
5974 while (child_die && child_die->tag)
5976 if (child_die->tag == DW_TAG_formal_parameter)
5978 /* Dwarf2 has no clean way to discern C++ static and non-static
5979 member functions. G++ helps GDB by marking the first
5980 parameter for non-static member functions (which is the
5981 this pointer) as artificial. We pass this information
5982 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5983 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
5985 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
5988 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
5990 /* GCC/43521: In java, the formal parameter
5991 "this" is sometimes not marked with DW_AT_artificial. */
5992 if (cu->language == language_java)
5994 const char *name = dwarf2_name (child_die, cu);
5995 if (name && !strcmp (name, "this"))
5996 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
5999 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
6002 child_die = sibling_die (child_die);
6009 static struct type *
6010 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
6012 struct objfile *objfile = cu->objfile;
6013 struct attribute *attr;
6014 const char *name = NULL;
6015 struct type *this_type;
6017 name = dwarf2_full_name (NULL, die, cu);
6018 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
6019 TYPE_FLAG_TARGET_STUB, NULL, objfile);
6020 TYPE_NAME (this_type) = (char *) name;
6021 set_die_type (die, this_type, cu);
6022 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
6026 /* Find a representation of a given base type and install
6027 it in the TYPE field of the die. */
6029 static struct type *
6030 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
6032 struct objfile *objfile = cu->objfile;
6034 struct attribute *attr;
6035 int encoding = 0, size = 0;
6037 enum type_code code = TYPE_CODE_INT;
6039 struct type *target_type = NULL;
6041 attr = dwarf2_attr (die, DW_AT_encoding, cu);
6044 encoding = DW_UNSND (attr);
6046 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6049 size = DW_UNSND (attr);
6051 name = dwarf2_name (die, cu);
6054 complaint (&symfile_complaints,
6055 _("DW_AT_name missing from DW_TAG_base_type"));
6060 case DW_ATE_address:
6061 /* Turn DW_ATE_address into a void * pointer. */
6062 code = TYPE_CODE_PTR;
6063 type_flags |= TYPE_FLAG_UNSIGNED;
6064 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
6066 case DW_ATE_boolean:
6067 code = TYPE_CODE_BOOL;
6068 type_flags |= TYPE_FLAG_UNSIGNED;
6070 case DW_ATE_complex_float:
6071 code = TYPE_CODE_COMPLEX;
6072 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
6074 case DW_ATE_decimal_float:
6075 code = TYPE_CODE_DECFLOAT;
6078 code = TYPE_CODE_FLT;
6082 case DW_ATE_unsigned:
6083 type_flags |= TYPE_FLAG_UNSIGNED;
6085 case DW_ATE_signed_char:
6086 if (cu->language == language_ada || cu->language == language_m2
6087 || cu->language == language_pascal)
6088 code = TYPE_CODE_CHAR;
6090 case DW_ATE_unsigned_char:
6091 if (cu->language == language_ada || cu->language == language_m2
6092 || cu->language == language_pascal)
6093 code = TYPE_CODE_CHAR;
6094 type_flags |= TYPE_FLAG_UNSIGNED;
6097 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
6098 dwarf_type_encoding_name (encoding));
6102 type = init_type (code, size, type_flags, NULL, objfile);
6103 TYPE_NAME (type) = name;
6104 TYPE_TARGET_TYPE (type) = target_type;
6106 if (name && strcmp (name, "char") == 0)
6107 TYPE_NOSIGN (type) = 1;
6109 return set_die_type (die, type, cu);
6112 /* Read the given DW_AT_subrange DIE. */
6114 static struct type *
6115 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6117 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
6118 struct type *base_type;
6119 struct type *range_type;
6120 struct attribute *attr;
6124 LONGEST negative_mask;
6126 base_type = die_type (die, cu);
6127 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
6129 complaint (&symfile_complaints,
6130 _("DW_AT_type missing from DW_TAG_subrange_type"));
6132 = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
6133 0, NULL, cu->objfile);
6136 if (cu->language == language_fortran)
6138 /* FORTRAN implies a lower bound of 1, if not given. */
6142 /* FIXME: For variable sized arrays either of these could be
6143 a variable rather than a constant value. We'll allow it,
6144 but we don't know how to handle it. */
6145 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6147 low = dwarf2_get_attr_constant_value (attr, 0);
6149 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6152 if (attr->form == DW_FORM_block1)
6154 /* GCC encodes arrays with unspecified or dynamic length
6155 with a DW_FORM_block1 attribute.
6156 FIXME: GDB does not yet know how to handle dynamic
6157 arrays properly, treat them as arrays with unspecified
6160 FIXME: jimb/2003-09-22: GDB does not really know
6161 how to handle arrays of unspecified length
6162 either; we just represent them as zero-length
6163 arrays. Choose an appropriate upper bound given
6164 the lower bound we've computed above. */
6168 high = dwarf2_get_attr_constant_value (attr, 1);
6172 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
6173 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
6174 low |= negative_mask;
6175 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
6176 high |= negative_mask;
6178 range_type = create_range_type (NULL, base_type, low, high);
6180 /* Mark arrays with dynamic length at least as an array of unspecified
6181 length. GDB could check the boundary but before it gets implemented at
6182 least allow accessing the array elements. */
6183 if (attr && attr->form == DW_FORM_block1)
6184 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
6186 name = dwarf2_name (die, cu);
6188 TYPE_NAME (range_type) = name;
6190 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6192 TYPE_LENGTH (range_type) = DW_UNSND (attr);
6194 set_descriptive_type (range_type, die, cu);
6196 return set_die_type (die, range_type, cu);
6199 static struct type *
6200 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
6204 /* For now, we only support the C meaning of an unspecified type: void. */
6206 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
6207 TYPE_NAME (type) = dwarf2_name (die, cu);
6209 return set_die_type (die, type, cu);
6212 /* Trivial hash function for die_info: the hash value of a DIE
6213 is its offset in .debug_info for this objfile. */
6216 die_hash (const void *item)
6218 const struct die_info *die = item;
6222 /* Trivial comparison function for die_info structures: two DIEs
6223 are equal if they have the same offset. */
6226 die_eq (const void *item_lhs, const void *item_rhs)
6228 const struct die_info *die_lhs = item_lhs;
6229 const struct die_info *die_rhs = item_rhs;
6230 return die_lhs->offset == die_rhs->offset;
6233 /* Read a whole compilation unit into a linked list of dies. */
6235 static struct die_info *
6236 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
6238 struct die_reader_specs reader_specs;
6240 gdb_assert (cu->die_hash == NULL);
6242 = htab_create_alloc_ex (cu->header.length / 12,
6246 &cu->comp_unit_obstack,
6247 hashtab_obstack_allocate,
6248 dummy_obstack_deallocate);
6250 init_cu_die_reader (&reader_specs, cu);
6252 return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
6255 /* Main entry point for reading a DIE and all children.
6256 Read the DIE and dump it if requested. */
6258 static struct die_info *
6259 read_die_and_children (const struct die_reader_specs *reader,
6261 gdb_byte **new_info_ptr,
6262 struct die_info *parent)
6264 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
6265 new_info_ptr, parent);
6267 if (dwarf2_die_debug)
6269 fprintf_unfiltered (gdb_stdlog,
6270 "\nRead die from %s of %s:\n",
6271 reader->buffer == dwarf2_per_objfile->info.buffer
6273 : reader->buffer == dwarf2_per_objfile->types.buffer
6275 : "unknown section",
6276 reader->abfd->filename);
6277 dump_die (result, dwarf2_die_debug);
6283 /* Read a single die and all its descendents. Set the die's sibling
6284 field to NULL; set other fields in the die correctly, and set all
6285 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6286 location of the info_ptr after reading all of those dies. PARENT
6287 is the parent of the die in question. */
6289 static struct die_info *
6290 read_die_and_children_1 (const struct die_reader_specs *reader,
6292 gdb_byte **new_info_ptr,
6293 struct die_info *parent)
6295 struct die_info *die;
6299 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
6302 *new_info_ptr = cur_ptr;
6305 store_in_ref_table (die, reader->cu);
6308 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
6312 *new_info_ptr = cur_ptr;
6315 die->sibling = NULL;
6316 die->parent = parent;
6320 /* Read a die, all of its descendents, and all of its siblings; set
6321 all of the fields of all of the dies correctly. Arguments are as
6322 in read_die_and_children. */
6324 static struct die_info *
6325 read_die_and_siblings (const struct die_reader_specs *reader,
6327 gdb_byte **new_info_ptr,
6328 struct die_info *parent)
6330 struct die_info *first_die, *last_sibling;
6334 first_die = last_sibling = NULL;
6338 struct die_info *die
6339 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
6343 *new_info_ptr = cur_ptr;
6350 last_sibling->sibling = die;
6356 /* Read the die from the .debug_info section buffer. Set DIEP to
6357 point to a newly allocated die with its information, except for its
6358 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6359 whether the die has children or not. */
6362 read_full_die (const struct die_reader_specs *reader,
6363 struct die_info **diep, gdb_byte *info_ptr,
6366 unsigned int abbrev_number, bytes_read, i, offset;
6367 struct abbrev_info *abbrev;
6368 struct die_info *die;
6369 struct dwarf2_cu *cu = reader->cu;
6370 bfd *abfd = reader->abfd;
6372 offset = info_ptr - reader->buffer;
6373 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6374 info_ptr += bytes_read;
6382 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
6384 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6386 bfd_get_filename (abfd));
6388 die = dwarf_alloc_die (cu, abbrev->num_attrs);
6389 die->offset = offset;
6390 die->tag = abbrev->tag;
6391 die->abbrev = abbrev_number;
6393 die->num_attrs = abbrev->num_attrs;
6395 for (i = 0; i < abbrev->num_attrs; ++i)
6396 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
6397 abfd, info_ptr, cu);
6400 *has_children = abbrev->has_children;
6404 /* In DWARF version 2, the description of the debugging information is
6405 stored in a separate .debug_abbrev section. Before we read any
6406 dies from a section we read in all abbreviations and install them
6407 in a hash table. This function also sets flags in CU describing
6408 the data found in the abbrev table. */
6411 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
6413 struct comp_unit_head *cu_header = &cu->header;
6414 gdb_byte *abbrev_ptr;
6415 struct abbrev_info *cur_abbrev;
6416 unsigned int abbrev_number, bytes_read, abbrev_name;
6417 unsigned int abbrev_form, hash_number;
6418 struct attr_abbrev *cur_attrs;
6419 unsigned int allocated_attrs;
6421 /* Initialize dwarf2 abbrevs */
6422 obstack_init (&cu->abbrev_obstack);
6423 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
6425 * sizeof (struct abbrev_info *)));
6426 memset (cu->dwarf2_abbrevs, 0,
6427 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
6429 dwarf2_read_section (dwarf2_per_objfile->objfile,
6430 &dwarf2_per_objfile->abbrev);
6431 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
6432 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6433 abbrev_ptr += bytes_read;
6435 allocated_attrs = ATTR_ALLOC_CHUNK;
6436 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
6438 /* loop until we reach an abbrev number of 0 */
6439 while (abbrev_number)
6441 cur_abbrev = dwarf_alloc_abbrev (cu);
6443 /* read in abbrev header */
6444 cur_abbrev->number = abbrev_number;
6445 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6446 abbrev_ptr += bytes_read;
6447 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
6450 if (cur_abbrev->tag == DW_TAG_namespace)
6451 cu->has_namespace_info = 1;
6453 /* now read in declarations */
6454 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6455 abbrev_ptr += bytes_read;
6456 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6457 abbrev_ptr += bytes_read;
6460 if (cur_abbrev->num_attrs == allocated_attrs)
6462 allocated_attrs += ATTR_ALLOC_CHUNK;
6464 = xrealloc (cur_attrs, (allocated_attrs
6465 * sizeof (struct attr_abbrev)));
6468 /* Record whether this compilation unit might have
6469 inter-compilation-unit references. If we don't know what form
6470 this attribute will have, then it might potentially be a
6471 DW_FORM_ref_addr, so we conservatively expect inter-CU
6474 if (abbrev_form == DW_FORM_ref_addr
6475 || abbrev_form == DW_FORM_indirect)
6476 cu->has_form_ref_addr = 1;
6478 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
6479 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
6480 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6481 abbrev_ptr += bytes_read;
6482 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6483 abbrev_ptr += bytes_read;
6486 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
6487 (cur_abbrev->num_attrs
6488 * sizeof (struct attr_abbrev)));
6489 memcpy (cur_abbrev->attrs, cur_attrs,
6490 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
6492 hash_number = abbrev_number % ABBREV_HASH_SIZE;
6493 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
6494 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
6496 /* Get next abbreviation.
6497 Under Irix6 the abbreviations for a compilation unit are not
6498 always properly terminated with an abbrev number of 0.
6499 Exit loop if we encounter an abbreviation which we have
6500 already read (which means we are about to read the abbreviations
6501 for the next compile unit) or if the end of the abbreviation
6502 table is reached. */
6503 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
6504 >= dwarf2_per_objfile->abbrev.size)
6506 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6507 abbrev_ptr += bytes_read;
6508 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
6515 /* Release the memory used by the abbrev table for a compilation unit. */
6518 dwarf2_free_abbrev_table (void *ptr_to_cu)
6520 struct dwarf2_cu *cu = ptr_to_cu;
6522 obstack_free (&cu->abbrev_obstack, NULL);
6523 cu->dwarf2_abbrevs = NULL;
6526 /* Lookup an abbrev_info structure in the abbrev hash table. */
6528 static struct abbrev_info *
6529 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
6531 unsigned int hash_number;
6532 struct abbrev_info *abbrev;
6534 hash_number = number % ABBREV_HASH_SIZE;
6535 abbrev = cu->dwarf2_abbrevs[hash_number];
6539 if (abbrev->number == number)
6542 abbrev = abbrev->next;
6547 /* Returns nonzero if TAG represents a type that we might generate a partial
6551 is_type_tag_for_partial (int tag)
6556 /* Some types that would be reasonable to generate partial symbols for,
6557 that we don't at present. */
6558 case DW_TAG_array_type:
6559 case DW_TAG_file_type:
6560 case DW_TAG_ptr_to_member_type:
6561 case DW_TAG_set_type:
6562 case DW_TAG_string_type:
6563 case DW_TAG_subroutine_type:
6565 case DW_TAG_base_type:
6566 case DW_TAG_class_type:
6567 case DW_TAG_interface_type:
6568 case DW_TAG_enumeration_type:
6569 case DW_TAG_structure_type:
6570 case DW_TAG_subrange_type:
6571 case DW_TAG_typedef:
6572 case DW_TAG_union_type:
6579 /* Load all DIEs that are interesting for partial symbols into memory. */
6581 static struct partial_die_info *
6582 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6583 int building_psymtab, struct dwarf2_cu *cu)
6585 struct partial_die_info *part_die;
6586 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
6587 struct abbrev_info *abbrev;
6588 unsigned int bytes_read;
6589 unsigned int load_all = 0;
6591 int nesting_level = 1;
6596 if (cu->per_cu && cu->per_cu->load_all_dies)
6600 = htab_create_alloc_ex (cu->header.length / 12,
6604 &cu->comp_unit_obstack,
6605 hashtab_obstack_allocate,
6606 dummy_obstack_deallocate);
6608 part_die = obstack_alloc (&cu->comp_unit_obstack,
6609 sizeof (struct partial_die_info));
6613 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6615 /* A NULL abbrev means the end of a series of children. */
6618 if (--nesting_level == 0)
6620 /* PART_DIE was probably the last thing allocated on the
6621 comp_unit_obstack, so we could call obstack_free
6622 here. We don't do that because the waste is small,
6623 and will be cleaned up when we're done with this
6624 compilation unit. This way, we're also more robust
6625 against other users of the comp_unit_obstack. */
6628 info_ptr += bytes_read;
6629 last_die = parent_die;
6630 parent_die = parent_die->die_parent;
6634 /* Check whether this DIE is interesting enough to save. Normally
6635 we would not be interested in members here, but there may be
6636 later variables referencing them via DW_AT_specification (for
6639 && !is_type_tag_for_partial (abbrev->tag)
6640 && abbrev->tag != DW_TAG_enumerator
6641 && abbrev->tag != DW_TAG_subprogram
6642 && abbrev->tag != DW_TAG_lexical_block
6643 && abbrev->tag != DW_TAG_variable
6644 && abbrev->tag != DW_TAG_namespace
6645 && abbrev->tag != DW_TAG_member)
6647 /* Otherwise we skip to the next sibling, if any. */
6648 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
6652 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
6653 buffer, info_ptr, cu);
6655 /* This two-pass algorithm for processing partial symbols has a
6656 high cost in cache pressure. Thus, handle some simple cases
6657 here which cover the majority of C partial symbols. DIEs
6658 which neither have specification tags in them, nor could have
6659 specification tags elsewhere pointing at them, can simply be
6660 processed and discarded.
6662 This segment is also optional; scan_partial_symbols and
6663 add_partial_symbol will handle these DIEs if we chain
6664 them in normally. When compilers which do not emit large
6665 quantities of duplicate debug information are more common,
6666 this code can probably be removed. */
6668 /* Any complete simple types at the top level (pretty much all
6669 of them, for a language without namespaces), can be processed
6671 if (parent_die == NULL
6672 && part_die->has_specification == 0
6673 && part_die->is_declaration == 0
6674 && (part_die->tag == DW_TAG_typedef
6675 || part_die->tag == DW_TAG_base_type
6676 || part_die->tag == DW_TAG_subrange_type))
6678 if (building_psymtab && part_die->name != NULL)
6679 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
6680 VAR_DOMAIN, LOC_TYPEDEF,
6681 &cu->objfile->static_psymbols,
6682 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6683 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6687 /* If we're at the second level, and we're an enumerator, and
6688 our parent has no specification (meaning possibly lives in a
6689 namespace elsewhere), then we can add the partial symbol now
6690 instead of queueing it. */
6691 if (part_die->tag == DW_TAG_enumerator
6692 && parent_die != NULL
6693 && parent_die->die_parent == NULL
6694 && parent_die->tag == DW_TAG_enumeration_type
6695 && parent_die->has_specification == 0)
6697 if (part_die->name == NULL)
6698 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6699 else if (building_psymtab)
6700 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
6701 VAR_DOMAIN, LOC_CONST,
6702 (cu->language == language_cplus
6703 || cu->language == language_java)
6704 ? &cu->objfile->global_psymbols
6705 : &cu->objfile->static_psymbols,
6706 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6708 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6712 /* We'll save this DIE so link it in. */
6713 part_die->die_parent = parent_die;
6714 part_die->die_sibling = NULL;
6715 part_die->die_child = NULL;
6717 if (last_die && last_die == parent_die)
6718 last_die->die_child = part_die;
6720 last_die->die_sibling = part_die;
6722 last_die = part_die;
6724 if (first_die == NULL)
6725 first_die = part_die;
6727 /* Maybe add the DIE to the hash table. Not all DIEs that we
6728 find interesting need to be in the hash table, because we
6729 also have the parent/sibling/child chains; only those that we
6730 might refer to by offset later during partial symbol reading.
6732 For now this means things that might have be the target of a
6733 DW_AT_specification, DW_AT_abstract_origin, or
6734 DW_AT_extension. DW_AT_extension will refer only to
6735 namespaces; DW_AT_abstract_origin refers to functions (and
6736 many things under the function DIE, but we do not recurse
6737 into function DIEs during partial symbol reading) and
6738 possibly variables as well; DW_AT_specification refers to
6739 declarations. Declarations ought to have the DW_AT_declaration
6740 flag. It happens that GCC forgets to put it in sometimes, but
6741 only for functions, not for types.
6743 Adding more things than necessary to the hash table is harmless
6744 except for the performance cost. Adding too few will result in
6745 wasted time in find_partial_die, when we reread the compilation
6746 unit with load_all_dies set. */
6749 || abbrev->tag == DW_TAG_subprogram
6750 || abbrev->tag == DW_TAG_variable
6751 || abbrev->tag == DW_TAG_namespace
6752 || part_die->is_declaration)
6756 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
6757 part_die->offset, INSERT);
6761 part_die = obstack_alloc (&cu->comp_unit_obstack,
6762 sizeof (struct partial_die_info));
6764 /* For some DIEs we want to follow their children (if any). For C
6765 we have no reason to follow the children of structures; for other
6766 languages we have to, both so that we can get at method physnames
6767 to infer fully qualified class names, and for DW_AT_specification.
6769 For Ada, we need to scan the children of subprograms and lexical
6770 blocks as well because Ada allows the definition of nested
6771 entities that could be interesting for the debugger, such as
6772 nested subprograms for instance. */
6773 if (last_die->has_children
6775 || last_die->tag == DW_TAG_namespace
6776 || last_die->tag == DW_TAG_enumeration_type
6777 || (cu->language != language_c
6778 && (last_die->tag == DW_TAG_class_type
6779 || last_die->tag == DW_TAG_interface_type
6780 || last_die->tag == DW_TAG_structure_type
6781 || last_die->tag == DW_TAG_union_type))
6782 || (cu->language == language_ada
6783 && (last_die->tag == DW_TAG_subprogram
6784 || last_die->tag == DW_TAG_lexical_block))))
6787 parent_die = last_die;
6791 /* Otherwise we skip to the next sibling, if any. */
6792 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
6794 /* Back to the top, do it again. */
6798 /* Read a minimal amount of information into the minimal die structure. */
6801 read_partial_die (struct partial_die_info *part_die,
6802 struct abbrev_info *abbrev,
6803 unsigned int abbrev_len, bfd *abfd,
6804 gdb_byte *buffer, gdb_byte *info_ptr,
6805 struct dwarf2_cu *cu)
6807 unsigned int bytes_read, i;
6808 struct attribute attr;
6809 int has_low_pc_attr = 0;
6810 int has_high_pc_attr = 0;
6812 memset (part_die, 0, sizeof (struct partial_die_info));
6814 part_die->offset = info_ptr - buffer;
6816 info_ptr += abbrev_len;
6821 part_die->tag = abbrev->tag;
6822 part_die->has_children = abbrev->has_children;
6824 for (i = 0; i < abbrev->num_attrs; ++i)
6826 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
6828 /* Store the data if it is of an attribute we want to keep in a
6829 partial symbol table. */
6833 switch (part_die->tag)
6835 case DW_TAG_compile_unit:
6836 case DW_TAG_type_unit:
6837 /* Compilation units have a DW_AT_name that is a filename, not
6838 a source language identifier. */
6839 case DW_TAG_enumeration_type:
6840 case DW_TAG_enumerator:
6841 /* These tags always have simple identifiers already; no need
6842 to canonicalize them. */
6843 part_die->name = DW_STRING (&attr);
6847 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
6848 &cu->objfile->objfile_obstack);
6852 case DW_AT_MIPS_linkage_name:
6853 if (cu->language == language_ada)
6854 part_die->name = DW_STRING (&attr);
6857 has_low_pc_attr = 1;
6858 part_die->lowpc = DW_ADDR (&attr);
6861 has_high_pc_attr = 1;
6862 part_die->highpc = DW_ADDR (&attr);
6864 case DW_AT_location:
6865 /* Support the .debug_loc offsets */
6866 if (attr_form_is_block (&attr))
6868 part_die->locdesc = DW_BLOCK (&attr);
6870 else if (attr_form_is_section_offset (&attr))
6872 dwarf2_complex_location_expr_complaint ();
6876 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6877 "partial symbol information");
6880 case DW_AT_external:
6881 part_die->is_external = DW_UNSND (&attr);
6883 case DW_AT_declaration:
6884 part_die->is_declaration = DW_UNSND (&attr);
6887 part_die->has_type = 1;
6889 case DW_AT_abstract_origin:
6890 case DW_AT_specification:
6891 case DW_AT_extension:
6892 part_die->has_specification = 1;
6893 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
6896 /* Ignore absolute siblings, they might point outside of
6897 the current compile unit. */
6898 if (attr.form == DW_FORM_ref_addr)
6899 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
6901 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
6903 case DW_AT_byte_size:
6904 part_die->has_byte_size = 1;
6906 case DW_AT_calling_convention:
6907 /* DWARF doesn't provide a way to identify a program's source-level
6908 entry point. DW_AT_calling_convention attributes are only meant
6909 to describe functions' calling conventions.
6911 However, because it's a necessary piece of information in
6912 Fortran, and because DW_CC_program is the only piece of debugging
6913 information whose definition refers to a 'main program' at all,
6914 several compilers have begun marking Fortran main programs with
6915 DW_CC_program --- even when those functions use the standard
6916 calling conventions.
6918 So until DWARF specifies a way to provide this information and
6919 compilers pick up the new representation, we'll support this
6921 if (DW_UNSND (&attr) == DW_CC_program
6922 && cu->language == language_fortran)
6923 set_main_name (part_die->name);
6930 /* When using the GNU linker, .gnu.linkonce. sections are used to
6931 eliminate duplicate copies of functions and vtables and such.
6932 The linker will arbitrarily choose one and discard the others.
6933 The AT_*_pc values for such functions refer to local labels in
6934 these sections. If the section from that file was discarded, the
6935 labels are not in the output, so the relocs get a value of 0.
6936 If this is a discarded function, mark the pc bounds as invalid,
6937 so that GDB will ignore it. */
6938 if (has_low_pc_attr && has_high_pc_attr
6939 && part_die->lowpc < part_die->highpc
6940 && (part_die->lowpc != 0
6941 || dwarf2_per_objfile->has_section_at_zero))
6942 part_die->has_pc_info = 1;
6947 /* Find a cached partial DIE at OFFSET in CU. */
6949 static struct partial_die_info *
6950 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
6952 struct partial_die_info *lookup_die = NULL;
6953 struct partial_die_info part_die;
6955 part_die.offset = offset;
6956 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
6961 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6962 except in the case of .debug_types DIEs which do not reference
6963 outside their CU (they do however referencing other types via
6966 static struct partial_die_info *
6967 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
6969 struct dwarf2_per_cu_data *per_cu = NULL;
6970 struct partial_die_info *pd = NULL;
6972 if (cu->per_cu->from_debug_types)
6974 pd = find_partial_die_in_comp_unit (offset, cu);
6980 if (offset_in_cu_p (&cu->header, offset))
6982 pd = find_partial_die_in_comp_unit (offset, cu);
6987 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
6989 if (per_cu->cu == NULL)
6991 load_partial_comp_unit (per_cu, cu->objfile);
6992 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
6993 dwarf2_per_objfile->read_in_chain = per_cu;
6996 per_cu->cu->last_used = 0;
6997 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6999 if (pd == NULL && per_cu->load_all_dies == 0)
7001 struct cleanup *back_to;
7002 struct partial_die_info comp_unit_die;
7003 struct abbrev_info *abbrev;
7004 unsigned int bytes_read;
7007 per_cu->load_all_dies = 1;
7009 /* Re-read the DIEs. */
7010 back_to = make_cleanup (null_cleanup, 0);
7011 if (per_cu->cu->dwarf2_abbrevs == NULL)
7013 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
7014 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
7016 info_ptr = (dwarf2_per_objfile->info.buffer
7017 + per_cu->cu->header.offset
7018 + per_cu->cu->header.first_die_offset);
7019 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
7020 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
7021 per_cu->cu->objfile->obfd,
7022 dwarf2_per_objfile->info.buffer, info_ptr,
7024 if (comp_unit_die.has_children)
7025 load_partial_dies (per_cu->cu->objfile->obfd,
7026 dwarf2_per_objfile->info.buffer, info_ptr,
7028 do_cleanups (back_to);
7030 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
7036 internal_error (__FILE__, __LINE__,
7037 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7038 offset, bfd_get_filename (cu->objfile->obfd));
7042 /* Adjust PART_DIE before generating a symbol for it. This function
7043 may set the is_external flag or change the DIE's name. */
7046 fixup_partial_die (struct partial_die_info *part_die,
7047 struct dwarf2_cu *cu)
7049 /* If we found a reference attribute and the DIE has no name, try
7050 to find a name in the referred to DIE. */
7052 if (part_die->name == NULL && part_die->has_specification)
7054 struct partial_die_info *spec_die;
7056 spec_die = find_partial_die (part_die->spec_offset, cu);
7058 fixup_partial_die (spec_die, cu);
7062 part_die->name = spec_die->name;
7064 /* Copy DW_AT_external attribute if it is set. */
7065 if (spec_die->is_external)
7066 part_die->is_external = spec_die->is_external;
7070 /* Set default names for some unnamed DIEs. */
7071 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
7072 || part_die->tag == DW_TAG_class_type))
7073 part_die->name = "(anonymous class)";
7075 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
7076 part_die->name = "(anonymous namespace)";
7078 if (part_die->tag == DW_TAG_structure_type
7079 || part_die->tag == DW_TAG_class_type
7080 || part_die->tag == DW_TAG_union_type)
7081 guess_structure_name (part_die, cu);
7084 /* Read an attribute value described by an attribute form. */
7087 read_attribute_value (struct attribute *attr, unsigned form,
7088 bfd *abfd, gdb_byte *info_ptr,
7089 struct dwarf2_cu *cu)
7091 struct comp_unit_head *cu_header = &cu->header;
7092 unsigned int bytes_read;
7093 struct dwarf_block *blk;
7098 case DW_FORM_ref_addr:
7099 if (cu->header.version == 2)
7100 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
7102 DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
7103 info_ptr += bytes_read;
7106 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
7107 info_ptr += bytes_read;
7109 case DW_FORM_block2:
7110 blk = dwarf_alloc_block (cu);
7111 blk->size = read_2_bytes (abfd, info_ptr);
7113 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7114 info_ptr += blk->size;
7115 DW_BLOCK (attr) = blk;
7117 case DW_FORM_block4:
7118 blk = dwarf_alloc_block (cu);
7119 blk->size = read_4_bytes (abfd, info_ptr);
7121 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7122 info_ptr += blk->size;
7123 DW_BLOCK (attr) = blk;
7126 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
7130 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
7134 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
7137 case DW_FORM_sec_offset:
7138 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
7139 info_ptr += bytes_read;
7141 case DW_FORM_string:
7142 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
7143 DW_STRING_IS_CANONICAL (attr) = 0;
7144 info_ptr += bytes_read;
7147 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
7149 DW_STRING_IS_CANONICAL (attr) = 0;
7150 info_ptr += bytes_read;
7152 case DW_FORM_exprloc:
7154 blk = dwarf_alloc_block (cu);
7155 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7156 info_ptr += bytes_read;
7157 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7158 info_ptr += blk->size;
7159 DW_BLOCK (attr) = blk;
7161 case DW_FORM_block1:
7162 blk = dwarf_alloc_block (cu);
7163 blk->size = read_1_byte (abfd, info_ptr);
7165 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7166 info_ptr += blk->size;
7167 DW_BLOCK (attr) = blk;
7170 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7174 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7177 case DW_FORM_flag_present:
7178 DW_UNSND (attr) = 1;
7181 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
7182 info_ptr += bytes_read;
7185 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7186 info_ptr += bytes_read;
7189 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
7193 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
7197 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
7201 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
7205 /* Convert the signature to something we can record in DW_UNSND
7207 NOTE: This is NULL if the type wasn't found. */
7208 DW_SIGNATURED_TYPE (attr) =
7209 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
7212 case DW_FORM_ref_udata:
7213 DW_ADDR (attr) = (cu->header.offset
7214 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
7215 info_ptr += bytes_read;
7217 case DW_FORM_indirect:
7218 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7219 info_ptr += bytes_read;
7220 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
7223 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7224 dwarf_form_name (form),
7225 bfd_get_filename (abfd));
7228 /* We have seen instances where the compiler tried to emit a byte
7229 size attribute of -1 which ended up being encoded as an unsigned
7230 0xffffffff. Although 0xffffffff is technically a valid size value,
7231 an object of this size seems pretty unlikely so we can relatively
7232 safely treat these cases as if the size attribute was invalid and
7233 treat them as zero by default. */
7234 if (attr->name == DW_AT_byte_size
7235 && form == DW_FORM_data4
7236 && DW_UNSND (attr) >= 0xffffffff)
7239 (&symfile_complaints,
7240 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7241 hex_string (DW_UNSND (attr)));
7242 DW_UNSND (attr) = 0;
7248 /* Read an attribute described by an abbreviated attribute. */
7251 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
7252 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
7254 attr->name = abbrev->name;
7255 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
7258 /* read dwarf information from a buffer */
7261 read_1_byte (bfd *abfd, gdb_byte *buf)
7263 return bfd_get_8 (abfd, buf);
7267 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
7269 return bfd_get_signed_8 (abfd, buf);
7273 read_2_bytes (bfd *abfd, gdb_byte *buf)
7275 return bfd_get_16 (abfd, buf);
7279 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
7281 return bfd_get_signed_16 (abfd, buf);
7285 read_4_bytes (bfd *abfd, gdb_byte *buf)
7287 return bfd_get_32 (abfd, buf);
7291 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
7293 return bfd_get_signed_32 (abfd, buf);
7297 read_8_bytes (bfd *abfd, gdb_byte *buf)
7299 return bfd_get_64 (abfd, buf);
7303 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
7304 unsigned int *bytes_read)
7306 struct comp_unit_head *cu_header = &cu->header;
7307 CORE_ADDR retval = 0;
7309 if (cu_header->signed_addr_p)
7311 switch (cu_header->addr_size)
7314 retval = bfd_get_signed_16 (abfd, buf);
7317 retval = bfd_get_signed_32 (abfd, buf);
7320 retval = bfd_get_signed_64 (abfd, buf);
7323 internal_error (__FILE__, __LINE__,
7324 _("read_address: bad switch, signed [in module %s]"),
7325 bfd_get_filename (abfd));
7330 switch (cu_header->addr_size)
7333 retval = bfd_get_16 (abfd, buf);
7336 retval = bfd_get_32 (abfd, buf);
7339 retval = bfd_get_64 (abfd, buf);
7342 internal_error (__FILE__, __LINE__,
7343 _("read_address: bad switch, unsigned [in module %s]"),
7344 bfd_get_filename (abfd));
7348 *bytes_read = cu_header->addr_size;
7352 /* Read the initial length from a section. The (draft) DWARF 3
7353 specification allows the initial length to take up either 4 bytes
7354 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7355 bytes describe the length and all offsets will be 8 bytes in length
7358 An older, non-standard 64-bit format is also handled by this
7359 function. The older format in question stores the initial length
7360 as an 8-byte quantity without an escape value. Lengths greater
7361 than 2^32 aren't very common which means that the initial 4 bytes
7362 is almost always zero. Since a length value of zero doesn't make
7363 sense for the 32-bit format, this initial zero can be considered to
7364 be an escape value which indicates the presence of the older 64-bit
7365 format. As written, the code can't detect (old format) lengths
7366 greater than 4GB. If it becomes necessary to handle lengths
7367 somewhat larger than 4GB, we could allow other small values (such
7368 as the non-sensical values of 1, 2, and 3) to also be used as
7369 escape values indicating the presence of the old format.
7371 The value returned via bytes_read should be used to increment the
7372 relevant pointer after calling read_initial_length().
7374 [ Note: read_initial_length() and read_offset() are based on the
7375 document entitled "DWARF Debugging Information Format", revision
7376 3, draft 8, dated November 19, 2001. This document was obtained
7379 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7381 This document is only a draft and is subject to change. (So beware.)
7383 Details regarding the older, non-standard 64-bit format were
7384 determined empirically by examining 64-bit ELF files produced by
7385 the SGI toolchain on an IRIX 6.5 machine.
7387 - Kevin, July 16, 2002
7391 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
7393 LONGEST length = bfd_get_32 (abfd, buf);
7395 if (length == 0xffffffff)
7397 length = bfd_get_64 (abfd, buf + 4);
7400 else if (length == 0)
7402 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7403 length = bfd_get_64 (abfd, buf);
7414 /* Cover function for read_initial_length.
7415 Returns the length of the object at BUF, and stores the size of the
7416 initial length in *BYTES_READ and stores the size that offsets will be in
7418 If the initial length size is not equivalent to that specified in
7419 CU_HEADER then issue a complaint.
7420 This is useful when reading non-comp-unit headers. */
7423 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
7424 const struct comp_unit_head *cu_header,
7425 unsigned int *bytes_read,
7426 unsigned int *offset_size)
7428 LONGEST length = read_initial_length (abfd, buf, bytes_read);
7430 gdb_assert (cu_header->initial_length_size == 4
7431 || cu_header->initial_length_size == 8
7432 || cu_header->initial_length_size == 12);
7434 if (cu_header->initial_length_size != *bytes_read)
7435 complaint (&symfile_complaints,
7436 _("intermixed 32-bit and 64-bit DWARF sections"));
7438 *offset_size = (*bytes_read == 4) ? 4 : 8;
7442 /* Read an offset from the data stream. The size of the offset is
7443 given by cu_header->offset_size. */
7446 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
7447 unsigned int *bytes_read)
7449 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
7450 *bytes_read = cu_header->offset_size;
7454 /* Read an offset from the data stream. */
7457 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
7461 switch (offset_size)
7464 retval = bfd_get_32 (abfd, buf);
7467 retval = bfd_get_64 (abfd, buf);
7470 internal_error (__FILE__, __LINE__,
7471 _("read_offset_1: bad switch [in module %s]"),
7472 bfd_get_filename (abfd));
7479 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
7481 /* If the size of a host char is 8 bits, we can return a pointer
7482 to the buffer, otherwise we have to copy the data to a buffer
7483 allocated on the temporary obstack. */
7484 gdb_assert (HOST_CHAR_BIT == 8);
7489 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7491 /* If the size of a host char is 8 bits, we can return a pointer
7492 to the string, otherwise we have to copy the string to a buffer
7493 allocated on the temporary obstack. */
7494 gdb_assert (HOST_CHAR_BIT == 8);
7497 *bytes_read_ptr = 1;
7500 *bytes_read_ptr = strlen ((char *) buf) + 1;
7501 return (char *) buf;
7505 read_indirect_string (bfd *abfd, gdb_byte *buf,
7506 const struct comp_unit_head *cu_header,
7507 unsigned int *bytes_read_ptr)
7509 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
7511 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
7512 if (dwarf2_per_objfile->str.buffer == NULL)
7514 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7515 bfd_get_filename (abfd));
7518 if (str_offset >= dwarf2_per_objfile->str.size)
7520 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7521 bfd_get_filename (abfd));
7524 gdb_assert (HOST_CHAR_BIT == 8);
7525 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
7527 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
7530 static unsigned long
7531 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7533 unsigned long result;
7534 unsigned int num_read;
7544 byte = bfd_get_8 (abfd, buf);
7547 result |= ((unsigned long)(byte & 127) << shift);
7548 if ((byte & 128) == 0)
7554 *bytes_read_ptr = num_read;
7559 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7562 int i, shift, num_read;
7571 byte = bfd_get_8 (abfd, buf);
7574 result |= ((long)(byte & 127) << shift);
7576 if ((byte & 128) == 0)
7581 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
7582 result |= -(((long)1) << shift);
7583 *bytes_read_ptr = num_read;
7587 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7590 skip_leb128 (bfd *abfd, gdb_byte *buf)
7596 byte = bfd_get_8 (abfd, buf);
7598 if ((byte & 128) == 0)
7604 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
7611 cu->language = language_c;
7613 case DW_LANG_C_plus_plus:
7614 cu->language = language_cplus;
7616 case DW_LANG_Fortran77:
7617 case DW_LANG_Fortran90:
7618 case DW_LANG_Fortran95:
7619 cu->language = language_fortran;
7621 case DW_LANG_Mips_Assembler:
7622 cu->language = language_asm;
7625 cu->language = language_java;
7629 cu->language = language_ada;
7631 case DW_LANG_Modula2:
7632 cu->language = language_m2;
7634 case DW_LANG_Pascal83:
7635 cu->language = language_pascal;
7638 cu->language = language_objc;
7640 case DW_LANG_Cobol74:
7641 case DW_LANG_Cobol85:
7643 cu->language = language_minimal;
7646 cu->language_defn = language_def (cu->language);
7649 /* Return the named attribute or NULL if not there. */
7651 static struct attribute *
7652 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
7655 struct attribute *spec = NULL;
7657 for (i = 0; i < die->num_attrs; ++i)
7659 if (die->attrs[i].name == name)
7660 return &die->attrs[i];
7661 if (die->attrs[i].name == DW_AT_specification
7662 || die->attrs[i].name == DW_AT_abstract_origin)
7663 spec = &die->attrs[i];
7668 die = follow_die_ref (die, spec, &cu);
7669 return dwarf2_attr (die, name, cu);
7675 /* Return the named attribute or NULL if not there,
7676 but do not follow DW_AT_specification, etc.
7677 This is for use in contexts where we're reading .debug_types dies.
7678 Following DW_AT_specification, DW_AT_abstract_origin will take us
7679 back up the chain, and we want to go down. */
7681 static struct attribute *
7682 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
7683 struct dwarf2_cu *cu)
7687 for (i = 0; i < die->num_attrs; ++i)
7688 if (die->attrs[i].name == name)
7689 return &die->attrs[i];
7694 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7695 and holds a non-zero value. This function should only be used for
7696 DW_FORM_flag or DW_FORM_flag_present attributes. */
7699 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
7701 struct attribute *attr = dwarf2_attr (die, name, cu);
7703 return (attr && DW_UNSND (attr));
7707 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
7709 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7710 which value is non-zero. However, we have to be careful with
7711 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7712 (via dwarf2_flag_true_p) follows this attribute. So we may
7713 end up accidently finding a declaration attribute that belongs
7714 to a different DIE referenced by the specification attribute,
7715 even though the given DIE does not have a declaration attribute. */
7716 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
7717 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
7720 /* Return the die giving the specification for DIE, if there is
7721 one. *SPEC_CU is the CU containing DIE on input, and the CU
7722 containing the return value on output. If there is no
7723 specification, but there is an abstract origin, that is
7726 static struct die_info *
7727 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
7729 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
7732 if (spec_attr == NULL)
7733 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
7735 if (spec_attr == NULL)
7738 return follow_die_ref (die, spec_attr, spec_cu);
7741 /* Free the line_header structure *LH, and any arrays and strings it
7744 free_line_header (struct line_header *lh)
7746 if (lh->standard_opcode_lengths)
7747 xfree (lh->standard_opcode_lengths);
7749 /* Remember that all the lh->file_names[i].name pointers are
7750 pointers into debug_line_buffer, and don't need to be freed. */
7752 xfree (lh->file_names);
7754 /* Similarly for the include directory names. */
7755 if (lh->include_dirs)
7756 xfree (lh->include_dirs);
7762 /* Add an entry to LH's include directory table. */
7764 add_include_dir (struct line_header *lh, char *include_dir)
7766 /* Grow the array if necessary. */
7767 if (lh->include_dirs_size == 0)
7769 lh->include_dirs_size = 1; /* for testing */
7770 lh->include_dirs = xmalloc (lh->include_dirs_size
7771 * sizeof (*lh->include_dirs));
7773 else if (lh->num_include_dirs >= lh->include_dirs_size)
7775 lh->include_dirs_size *= 2;
7776 lh->include_dirs = xrealloc (lh->include_dirs,
7777 (lh->include_dirs_size
7778 * sizeof (*lh->include_dirs)));
7781 lh->include_dirs[lh->num_include_dirs++] = include_dir;
7785 /* Add an entry to LH's file name table. */
7787 add_file_name (struct line_header *lh,
7789 unsigned int dir_index,
7790 unsigned int mod_time,
7791 unsigned int length)
7793 struct file_entry *fe;
7795 /* Grow the array if necessary. */
7796 if (lh->file_names_size == 0)
7798 lh->file_names_size = 1; /* for testing */
7799 lh->file_names = xmalloc (lh->file_names_size
7800 * sizeof (*lh->file_names));
7802 else if (lh->num_file_names >= lh->file_names_size)
7804 lh->file_names_size *= 2;
7805 lh->file_names = xrealloc (lh->file_names,
7806 (lh->file_names_size
7807 * sizeof (*lh->file_names)));
7810 fe = &lh->file_names[lh->num_file_names++];
7812 fe->dir_index = dir_index;
7813 fe->mod_time = mod_time;
7814 fe->length = length;
7820 /* Read the statement program header starting at OFFSET in
7821 .debug_line, according to the endianness of ABFD. Return a pointer
7822 to a struct line_header, allocated using xmalloc.
7824 NOTE: the strings in the include directory and file name tables of
7825 the returned object point into debug_line_buffer, and must not be
7827 static struct line_header *
7828 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
7829 struct dwarf2_cu *cu)
7831 struct cleanup *back_to;
7832 struct line_header *lh;
7834 unsigned int bytes_read, offset_size;
7836 char *cur_dir, *cur_file;
7838 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
7839 if (dwarf2_per_objfile->line.buffer == NULL)
7841 complaint (&symfile_complaints, _("missing .debug_line section"));
7845 /* Make sure that at least there's room for the total_length field.
7846 That could be 12 bytes long, but we're just going to fudge that. */
7847 if (offset + 4 >= dwarf2_per_objfile->line.size)
7849 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7853 lh = xmalloc (sizeof (*lh));
7854 memset (lh, 0, sizeof (*lh));
7855 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
7858 line_ptr = dwarf2_per_objfile->line.buffer + offset;
7860 /* Read in the header. */
7862 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
7863 &bytes_read, &offset_size);
7864 line_ptr += bytes_read;
7865 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
7866 + dwarf2_per_objfile->line.size))
7868 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7871 lh->statement_program_end = line_ptr + lh->total_length;
7872 lh->version = read_2_bytes (abfd, line_ptr);
7874 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
7875 line_ptr += offset_size;
7876 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
7878 if (lh->version >= 4)
7880 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
7884 lh->maximum_ops_per_instruction = 1;
7886 if (lh->maximum_ops_per_instruction == 0)
7888 lh->maximum_ops_per_instruction = 1;
7889 complaint (&symfile_complaints,
7890 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
7893 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
7895 lh->line_base = read_1_signed_byte (abfd, line_ptr);
7897 lh->line_range = read_1_byte (abfd, line_ptr);
7899 lh->opcode_base = read_1_byte (abfd, line_ptr);
7901 lh->standard_opcode_lengths
7902 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
7904 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
7905 for (i = 1; i < lh->opcode_base; ++i)
7907 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
7911 /* Read directory table. */
7912 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7914 line_ptr += bytes_read;
7915 add_include_dir (lh, cur_dir);
7917 line_ptr += bytes_read;
7919 /* Read file name table. */
7920 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7922 unsigned int dir_index, mod_time, length;
7924 line_ptr += bytes_read;
7925 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7926 line_ptr += bytes_read;
7927 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7928 line_ptr += bytes_read;
7929 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7930 line_ptr += bytes_read;
7932 add_file_name (lh, cur_file, dir_index, mod_time, length);
7934 line_ptr += bytes_read;
7935 lh->statement_program_start = line_ptr;
7937 if (line_ptr > (dwarf2_per_objfile->line.buffer
7938 + dwarf2_per_objfile->line.size))
7939 complaint (&symfile_complaints,
7940 _("line number info header doesn't fit in `.debug_line' section"));
7942 discard_cleanups (back_to);
7946 /* This function exists to work around a bug in certain compilers
7947 (particularly GCC 2.95), in which the first line number marker of a
7948 function does not show up until after the prologue, right before
7949 the second line number marker. This function shifts ADDRESS down
7950 to the beginning of the function if necessary, and is called on
7951 addresses passed to record_line. */
7954 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
7956 struct function_range *fn;
7958 /* Find the function_range containing address. */
7963 cu->cached_fn = cu->first_fn;
7967 if (fn->lowpc <= address && fn->highpc > address)
7973 while (fn && fn != cu->cached_fn)
7974 if (fn->lowpc <= address && fn->highpc > address)
7984 if (address != fn->lowpc)
7985 complaint (&symfile_complaints,
7986 _("misplaced first line number at 0x%lx for '%s'"),
7987 (unsigned long) address, fn->name);
7992 /* Decode the Line Number Program (LNP) for the given line_header
7993 structure and CU. The actual information extracted and the type
7994 of structures created from the LNP depends on the value of PST.
7996 1. If PST is NULL, then this procedure uses the data from the program
7997 to create all necessary symbol tables, and their linetables.
7998 The compilation directory of the file is passed in COMP_DIR,
7999 and must not be NULL.
8001 2. If PST is not NULL, this procedure reads the program to determine
8002 the list of files included by the unit represented by PST, and
8003 builds all the associated partial symbol tables. In this case,
8004 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
8005 is not used to compute the full name of the symtab, and therefore
8006 omitting it when building the partial symtab does not introduce
8007 the potential for inconsistency - a partial symtab and its associated
8008 symbtab having a different fullname -). */
8011 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
8012 struct dwarf2_cu *cu, struct partial_symtab *pst)
8014 gdb_byte *line_ptr, *extended_end;
8016 unsigned int bytes_read, extended_len;
8017 unsigned char op_code, extended_op, adj_opcode;
8019 struct objfile *objfile = cu->objfile;
8020 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8021 const int decode_for_pst_p = (pst != NULL);
8022 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
8024 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8026 line_ptr = lh->statement_program_start;
8027 line_end = lh->statement_program_end;
8029 /* Read the statement sequences until there's nothing left. */
8030 while (line_ptr < line_end)
8032 /* state machine registers */
8033 CORE_ADDR address = 0;
8034 unsigned int file = 1;
8035 unsigned int line = 1;
8036 unsigned int column = 0;
8037 int is_stmt = lh->default_is_stmt;
8038 int basic_block = 0;
8039 int end_sequence = 0;
8041 unsigned char op_index = 0;
8043 if (!decode_for_pst_p && lh->num_file_names >= file)
8045 /* Start a subfile for the current file of the state machine. */
8046 /* lh->include_dirs and lh->file_names are 0-based, but the
8047 directory and file name numbers in the statement program
8049 struct file_entry *fe = &lh->file_names[file - 1];
8053 dir = lh->include_dirs[fe->dir_index - 1];
8055 dwarf2_start_subfile (fe->name, dir, comp_dir);
8058 /* Decode the table. */
8059 while (!end_sequence)
8061 op_code = read_1_byte (abfd, line_ptr);
8063 if (line_ptr > line_end)
8065 dwarf2_debug_line_missing_end_sequence_complaint ();
8069 if (op_code >= lh->opcode_base)
8071 /* Special operand. */
8072 adj_opcode = op_code - lh->opcode_base;
8073 address += (((op_index + (adj_opcode / lh->line_range))
8074 / lh->maximum_ops_per_instruction)
8075 * lh->minimum_instruction_length);
8076 op_index = ((op_index + (adj_opcode / lh->line_range))
8077 % lh->maximum_ops_per_instruction);
8078 line += lh->line_base + (adj_opcode % lh->line_range);
8079 if (lh->num_file_names < file || file == 0)
8080 dwarf2_debug_line_missing_file_complaint ();
8081 /* For now we ignore lines not starting on an
8082 instruction boundary. */
8083 else if (op_index == 0)
8085 lh->file_names[file - 1].included_p = 1;
8086 if (!decode_for_pst_p && is_stmt)
8088 if (last_subfile != current_subfile)
8090 addr = gdbarch_addr_bits_remove (gdbarch, address);
8092 record_line (last_subfile, 0, addr);
8093 last_subfile = current_subfile;
8095 /* Append row to matrix using current values. */
8096 addr = check_cu_functions (address, cu);
8097 addr = gdbarch_addr_bits_remove (gdbarch, addr);
8098 record_line (current_subfile, line, addr);
8103 else switch (op_code)
8105 case DW_LNS_extended_op:
8106 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8107 line_ptr += bytes_read;
8108 extended_end = line_ptr + extended_len;
8109 extended_op = read_1_byte (abfd, line_ptr);
8111 switch (extended_op)
8113 case DW_LNE_end_sequence:
8116 case DW_LNE_set_address:
8117 address = read_address (abfd, line_ptr, cu, &bytes_read);
8119 line_ptr += bytes_read;
8120 address += baseaddr;
8122 case DW_LNE_define_file:
8125 unsigned int dir_index, mod_time, length;
8127 cur_file = read_string (abfd, line_ptr, &bytes_read);
8128 line_ptr += bytes_read;
8130 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8131 line_ptr += bytes_read;
8133 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8134 line_ptr += bytes_read;
8136 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8137 line_ptr += bytes_read;
8138 add_file_name (lh, cur_file, dir_index, mod_time, length);
8141 case DW_LNE_set_discriminator:
8142 /* The discriminator is not interesting to the debugger;
8144 line_ptr = extended_end;
8147 complaint (&symfile_complaints,
8148 _("mangled .debug_line section"));
8151 /* Make sure that we parsed the extended op correctly. If e.g.
8152 we expected a different address size than the producer used,
8153 we may have read the wrong number of bytes. */
8154 if (line_ptr != extended_end)
8156 complaint (&symfile_complaints,
8157 _("mangled .debug_line section"));
8162 if (lh->num_file_names < file || file == 0)
8163 dwarf2_debug_line_missing_file_complaint ();
8166 lh->file_names[file - 1].included_p = 1;
8167 if (!decode_for_pst_p && is_stmt)
8169 if (last_subfile != current_subfile)
8171 addr = gdbarch_addr_bits_remove (gdbarch, address);
8173 record_line (last_subfile, 0, addr);
8174 last_subfile = current_subfile;
8176 addr = check_cu_functions (address, cu);
8177 addr = gdbarch_addr_bits_remove (gdbarch, addr);
8178 record_line (current_subfile, line, addr);
8183 case DW_LNS_advance_pc:
8186 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8188 address += (((op_index + adjust)
8189 / lh->maximum_ops_per_instruction)
8190 * lh->minimum_instruction_length);
8191 op_index = ((op_index + adjust)
8192 % lh->maximum_ops_per_instruction);
8193 line_ptr += bytes_read;
8196 case DW_LNS_advance_line:
8197 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
8198 line_ptr += bytes_read;
8200 case DW_LNS_set_file:
8202 /* The arrays lh->include_dirs and lh->file_names are
8203 0-based, but the directory and file name numbers in
8204 the statement program are 1-based. */
8205 struct file_entry *fe;
8208 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8209 line_ptr += bytes_read;
8210 if (lh->num_file_names < file || file == 0)
8211 dwarf2_debug_line_missing_file_complaint ();
8214 fe = &lh->file_names[file - 1];
8216 dir = lh->include_dirs[fe->dir_index - 1];
8217 if (!decode_for_pst_p)
8219 last_subfile = current_subfile;
8220 dwarf2_start_subfile (fe->name, dir, comp_dir);
8225 case DW_LNS_set_column:
8226 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8227 line_ptr += bytes_read;
8229 case DW_LNS_negate_stmt:
8230 is_stmt = (!is_stmt);
8232 case DW_LNS_set_basic_block:
8235 /* Add to the address register of the state machine the
8236 address increment value corresponding to special opcode
8237 255. I.e., this value is scaled by the minimum
8238 instruction length since special opcode 255 would have
8239 scaled the the increment. */
8240 case DW_LNS_const_add_pc:
8242 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
8244 address += (((op_index + adjust)
8245 / lh->maximum_ops_per_instruction)
8246 * lh->minimum_instruction_length);
8247 op_index = ((op_index + adjust)
8248 % lh->maximum_ops_per_instruction);
8251 case DW_LNS_fixed_advance_pc:
8252 address += read_2_bytes (abfd, line_ptr);
8258 /* Unknown standard opcode, ignore it. */
8261 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
8263 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8264 line_ptr += bytes_read;
8269 if (lh->num_file_names < file || file == 0)
8270 dwarf2_debug_line_missing_file_complaint ();
8273 lh->file_names[file - 1].included_p = 1;
8274 if (!decode_for_pst_p)
8276 addr = gdbarch_addr_bits_remove (gdbarch, address);
8277 record_line (current_subfile, 0, addr);
8282 if (decode_for_pst_p)
8286 /* Now that we're done scanning the Line Header Program, we can
8287 create the psymtab of each included file. */
8288 for (file_index = 0; file_index < lh->num_file_names; file_index++)
8289 if (lh->file_names[file_index].included_p == 1)
8291 const struct file_entry fe = lh->file_names [file_index];
8292 char *include_name = fe.name;
8293 char *dir_name = NULL;
8294 char *pst_filename = pst->filename;
8297 dir_name = lh->include_dirs[fe.dir_index - 1];
8299 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
8301 include_name = concat (dir_name, SLASH_STRING,
8302 include_name, (char *)NULL);
8303 make_cleanup (xfree, include_name);
8306 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
8308 pst_filename = concat (pst->dirname, SLASH_STRING,
8309 pst_filename, (char *)NULL);
8310 make_cleanup (xfree, pst_filename);
8313 if (strcmp (include_name, pst_filename) != 0)
8314 dwarf2_create_include_psymtab (include_name, pst, objfile);
8319 /* Make sure a symtab is created for every file, even files
8320 which contain only variables (i.e. no code with associated
8324 struct file_entry *fe;
8326 for (i = 0; i < lh->num_file_names; i++)
8329 fe = &lh->file_names[i];
8331 dir = lh->include_dirs[fe->dir_index - 1];
8332 dwarf2_start_subfile (fe->name, dir, comp_dir);
8334 /* Skip the main file; we don't need it, and it must be
8335 allocated last, so that it will show up before the
8336 non-primary symtabs in the objfile's symtab list. */
8337 if (current_subfile == first_subfile)
8340 if (current_subfile->symtab == NULL)
8341 current_subfile->symtab = allocate_symtab (current_subfile->name,
8343 fe->symtab = current_subfile->symtab;
8348 /* Start a subfile for DWARF. FILENAME is the name of the file and
8349 DIRNAME the name of the source directory which contains FILENAME
8350 or NULL if not known. COMP_DIR is the compilation directory for the
8351 linetable's compilation unit or NULL if not known.
8352 This routine tries to keep line numbers from identical absolute and
8353 relative file names in a common subfile.
8355 Using the `list' example from the GDB testsuite, which resides in
8356 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8357 of /srcdir/list0.c yields the following debugging information for list0.c:
8359 DW_AT_name: /srcdir/list0.c
8360 DW_AT_comp_dir: /compdir
8361 files.files[0].name: list0.h
8362 files.files[0].dir: /srcdir
8363 files.files[1].name: list0.c
8364 files.files[1].dir: /srcdir
8366 The line number information for list0.c has to end up in a single
8367 subfile, so that `break /srcdir/list0.c:1' works as expected.
8368 start_subfile will ensure that this happens provided that we pass the
8369 concatenation of files.files[1].dir and files.files[1].name as the
8373 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
8377 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8378 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8379 second argument to start_subfile. To be consistent, we do the
8380 same here. In order not to lose the line information directory,
8381 we concatenate it to the filename when it makes sense.
8382 Note that the Dwarf3 standard says (speaking of filenames in line
8383 information): ``The directory index is ignored for file names
8384 that represent full path names''. Thus ignoring dirname in the
8385 `else' branch below isn't an issue. */
8387 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
8388 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
8390 fullname = filename;
8392 start_subfile (fullname, comp_dir);
8394 if (fullname != filename)
8399 var_decode_location (struct attribute *attr, struct symbol *sym,
8400 struct dwarf2_cu *cu)
8402 struct objfile *objfile = cu->objfile;
8403 struct comp_unit_head *cu_header = &cu->header;
8405 /* NOTE drow/2003-01-30: There used to be a comment and some special
8406 code here to turn a symbol with DW_AT_external and a
8407 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8408 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8409 with some versions of binutils) where shared libraries could have
8410 relocations against symbols in their debug information - the
8411 minimal symbol would have the right address, but the debug info
8412 would not. It's no longer necessary, because we will explicitly
8413 apply relocations when we read in the debug information now. */
8415 /* A DW_AT_location attribute with no contents indicates that a
8416 variable has been optimized away. */
8417 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
8419 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8423 /* Handle one degenerate form of location expression specially, to
8424 preserve GDB's previous behavior when section offsets are
8425 specified. If this is just a DW_OP_addr then mark this symbol
8428 if (attr_form_is_block (attr)
8429 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
8430 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
8434 SYMBOL_VALUE_ADDRESS (sym) =
8435 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
8436 SYMBOL_CLASS (sym) = LOC_STATIC;
8437 fixup_symbol_section (sym, objfile);
8438 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
8439 SYMBOL_SECTION (sym));
8443 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8444 expression evaluator, and use LOC_COMPUTED only when necessary
8445 (i.e. when the value of a register or memory location is
8446 referenced, or a thread-local block, etc.). Then again, it might
8447 not be worthwhile. I'm assuming that it isn't unless performance
8448 or memory numbers show me otherwise. */
8450 dwarf2_symbol_mark_computed (attr, sym, cu);
8451 SYMBOL_CLASS (sym) = LOC_COMPUTED;
8454 /* Given a pointer to a DWARF information entry, figure out if we need
8455 to make a symbol table entry for it, and if so, create a new entry
8456 and return a pointer to it.
8457 If TYPE is NULL, determine symbol type from the die, otherwise
8458 used the passed type. */
8460 static struct symbol *
8461 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
8463 struct objfile *objfile = cu->objfile;
8464 struct symbol *sym = NULL;
8466 struct attribute *attr = NULL;
8467 struct attribute *attr2 = NULL;
8469 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
8471 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8473 name = dwarf2_name (die, cu);
8476 const char *linkagename;
8478 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
8479 sizeof (struct symbol));
8480 OBJSTAT (objfile, n_syms++);
8481 memset (sym, 0, sizeof (struct symbol));
8483 /* Cache this symbol's name and the name's demangled form (if any). */
8484 SYMBOL_LANGUAGE (sym) = cu->language;
8485 linkagename = dwarf2_physname (name, die, cu);
8486 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
8488 /* Default assumptions.
8489 Use the passed type or decode it from the die. */
8490 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8491 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8493 SYMBOL_TYPE (sym) = type;
8495 SYMBOL_TYPE (sym) = die_type (die, cu);
8496 attr = dwarf2_attr (die,
8497 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
8501 SYMBOL_LINE (sym) = DW_UNSND (attr);
8504 attr = dwarf2_attr (die,
8505 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
8509 int file_index = DW_UNSND (attr);
8510 if (cu->line_header == NULL
8511 || file_index > cu->line_header->num_file_names)
8512 complaint (&symfile_complaints,
8513 _("file index out of range"));
8514 else if (file_index > 0)
8516 struct file_entry *fe;
8517 fe = &cu->line_header->file_names[file_index - 1];
8518 SYMBOL_SYMTAB (sym) = fe->symtab;
8525 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
8528 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
8530 SYMBOL_CLASS (sym) = LOC_LABEL;
8532 case DW_TAG_subprogram:
8533 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8535 SYMBOL_CLASS (sym) = LOC_BLOCK;
8536 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8537 if ((attr2 && (DW_UNSND (attr2) != 0))
8538 || cu->language == language_ada)
8540 /* Subprograms marked external are stored as a global symbol.
8541 Ada subprograms, whether marked external or not, are always
8542 stored as a global symbol, because we want to be able to
8543 access them globally. For instance, we want to be able
8544 to break on a nested subprogram without having to
8545 specify the context. */
8546 add_symbol_to_list (sym, &global_symbols);
8550 add_symbol_to_list (sym, cu->list_in_scope);
8553 case DW_TAG_inlined_subroutine:
8554 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8556 SYMBOL_CLASS (sym) = LOC_BLOCK;
8557 SYMBOL_INLINED (sym) = 1;
8558 /* Do not add the symbol to any lists. It will be found via
8559 BLOCK_FUNCTION from the blockvector. */
8561 case DW_TAG_variable:
8562 /* Compilation with minimal debug info may result in variables
8563 with missing type entries. Change the misleading `void' type
8564 to something sensible. */
8565 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
8567 = objfile_type (objfile)->nodebug_data_symbol;
8569 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8572 dwarf2_const_value (attr, sym, cu);
8573 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8574 if (attr2 && (DW_UNSND (attr2) != 0))
8575 add_symbol_to_list (sym, &global_symbols);
8577 add_symbol_to_list (sym, cu->list_in_scope);
8580 attr = dwarf2_attr (die, DW_AT_location, cu);
8583 var_decode_location (attr, sym, cu);
8584 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8585 if (attr2 && (DW_UNSND (attr2) != 0))
8587 struct pending **list_to_add;
8589 /* A variable with DW_AT_external is never static,
8590 but it may be block-scoped. */
8591 list_to_add = (cu->list_in_scope == &file_symbols
8592 ? &global_symbols : cu->list_in_scope);
8593 add_symbol_to_list (sym, list_to_add);
8596 add_symbol_to_list (sym, cu->list_in_scope);
8600 /* We do not know the address of this symbol.
8601 If it is an external symbol and we have type information
8602 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8603 The address of the variable will then be determined from
8604 the minimal symbol table whenever the variable is
8606 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8607 if (attr2 && (DW_UNSND (attr2) != 0)
8608 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
8610 struct pending **list_to_add;
8612 /* A variable with DW_AT_external is never static, but it
8613 may be block-scoped. */
8614 list_to_add = (cu->list_in_scope == &file_symbols
8615 ? &global_symbols : cu->list_in_scope);
8617 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
8618 add_symbol_to_list (sym, list_to_add);
8620 else if (!die_is_declaration (die, cu))
8622 /* Use the default LOC_OPTIMIZED_OUT class. */
8623 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
8624 add_symbol_to_list (sym, cu->list_in_scope);
8628 case DW_TAG_formal_parameter:
8629 /* If we are inside a function, mark this as an argument. If
8630 not, we might be looking at an argument to an inlined function
8631 when we do not have enough information to show inlined frames;
8632 pretend it's a local variable in that case so that the user can
8634 if (context_stack_depth > 0
8635 && context_stack[context_stack_depth - 1].name != NULL)
8636 SYMBOL_IS_ARGUMENT (sym) = 1;
8637 attr = dwarf2_attr (die, DW_AT_location, cu);
8640 var_decode_location (attr, sym, cu);
8642 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8645 dwarf2_const_value (attr, sym, cu);
8647 add_symbol_to_list (sym, cu->list_in_scope);
8649 case DW_TAG_unspecified_parameters:
8650 /* From varargs functions; gdb doesn't seem to have any
8651 interest in this information, so just ignore it for now.
8654 case DW_TAG_class_type:
8655 case DW_TAG_interface_type:
8656 case DW_TAG_structure_type:
8657 case DW_TAG_union_type:
8658 case DW_TAG_set_type:
8659 case DW_TAG_enumeration_type:
8660 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8661 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
8663 /* Make sure that the symbol includes appropriate enclosing
8664 classes/namespaces in its name. These are calculated in
8665 read_structure_type, and the correct name is saved in
8668 if (cu->language == language_cplus
8669 || cu->language == language_java)
8671 struct type *type = SYMBOL_TYPE (sym);
8673 if (TYPE_TAG_NAME (type) != NULL)
8675 /* FIXME: carlton/2003-11-10: Should this use
8676 SYMBOL_SET_NAMES instead? (The same problem also
8677 arises further down in this function.) */
8678 /* The type's name is already allocated along with
8679 this objfile, so we don't need to duplicate it
8681 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
8686 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8687 really ever be static objects: otherwise, if you try
8688 to, say, break of a class's method and you're in a file
8689 which doesn't mention that class, it won't work unless
8690 the check for all static symbols in lookup_symbol_aux
8691 saves you. See the OtherFileClass tests in
8692 gdb.c++/namespace.exp. */
8694 struct pending **list_to_add;
8696 list_to_add = (cu->list_in_scope == &file_symbols
8697 && (cu->language == language_cplus
8698 || cu->language == language_java)
8699 ? &global_symbols : cu->list_in_scope);
8701 add_symbol_to_list (sym, list_to_add);
8703 /* The semantics of C++ state that "struct foo { ... }" also
8704 defines a typedef for "foo". A Java class declaration also
8705 defines a typedef for the class. */
8706 if (cu->language == language_cplus
8707 || cu->language == language_java
8708 || cu->language == language_ada)
8710 /* The symbol's name is already allocated along with
8711 this objfile, so we don't need to duplicate it for
8713 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
8714 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
8718 case DW_TAG_typedef:
8719 SYMBOL_LINKAGE_NAME (sym)
8720 = (char *) dwarf2_full_name (name, die, cu);
8721 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8722 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8723 add_symbol_to_list (sym, cu->list_in_scope);
8725 case DW_TAG_base_type:
8726 case DW_TAG_subrange_type:
8727 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8728 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8729 add_symbol_to_list (sym, cu->list_in_scope);
8731 case DW_TAG_enumerator:
8732 SYMBOL_LINKAGE_NAME (sym)
8733 = (char *) dwarf2_full_name (name, die, cu);
8734 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8737 dwarf2_const_value (attr, sym, cu);
8740 /* NOTE: carlton/2003-11-10: See comment above in the
8741 DW_TAG_class_type, etc. block. */
8743 struct pending **list_to_add;
8745 list_to_add = (cu->list_in_scope == &file_symbols
8746 && (cu->language == language_cplus
8747 || cu->language == language_java)
8748 ? &global_symbols : cu->list_in_scope);
8750 add_symbol_to_list (sym, list_to_add);
8753 case DW_TAG_namespace:
8754 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8755 add_symbol_to_list (sym, &global_symbols);
8758 /* Not a tag we recognize. Hopefully we aren't processing
8759 trash data, but since we must specifically ignore things
8760 we don't recognize, there is nothing else we should do at
8762 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
8763 dwarf_tag_name (die->tag));
8767 /* For the benefit of old versions of GCC, check for anonymous
8768 namespaces based on the demangled name. */
8769 if (!processing_has_namespace_info
8770 && cu->language == language_cplus)
8771 cp_scan_for_anonymous_namespaces (sym);
8776 /* Copy constant value from an attribute to a symbol. */
8779 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
8780 struct dwarf2_cu *cu)
8782 struct objfile *objfile = cu->objfile;
8783 struct comp_unit_head *cu_header = &cu->header;
8784 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
8785 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
8786 struct dwarf_block *blk;
8791 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
8792 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
8793 cu_header->addr_size,
8794 TYPE_LENGTH (SYMBOL_TYPE
8796 SYMBOL_VALUE_BYTES (sym) =
8797 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
8798 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8799 it's body - store_unsigned_integer. */
8800 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
8801 byte_order, DW_ADDR (attr));
8802 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8804 case DW_FORM_string:
8806 /* DW_STRING is already allocated on the obstack, point directly
8808 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
8809 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8811 case DW_FORM_block1:
8812 case DW_FORM_block2:
8813 case DW_FORM_block4:
8815 case DW_FORM_exprloc:
8816 blk = DW_BLOCK (attr);
8817 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
8818 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
8820 TYPE_LENGTH (SYMBOL_TYPE
8822 SYMBOL_VALUE_BYTES (sym) =
8823 obstack_alloc (&objfile->objfile_obstack, blk->size);
8824 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
8825 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8828 /* The DW_AT_const_value attributes are supposed to carry the
8829 symbol's value "represented as it would be on the target
8830 architecture." By the time we get here, it's already been
8831 converted to host endianness, so we just need to sign- or
8832 zero-extend it as appropriate. */
8834 dwarf2_const_value_data (attr, sym, 8);
8837 dwarf2_const_value_data (attr, sym, 16);
8840 dwarf2_const_value_data (attr, sym, 32);
8843 dwarf2_const_value_data (attr, sym, 64);
8847 SYMBOL_VALUE (sym) = DW_SND (attr);
8848 SYMBOL_CLASS (sym) = LOC_CONST;
8852 SYMBOL_VALUE (sym) = DW_UNSND (attr);
8853 SYMBOL_CLASS (sym) = LOC_CONST;
8857 complaint (&symfile_complaints,
8858 _("unsupported const value attribute form: '%s'"),
8859 dwarf_form_name (attr->form));
8860 SYMBOL_VALUE (sym) = 0;
8861 SYMBOL_CLASS (sym) = LOC_CONST;
8867 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8868 or zero-extend it as appropriate for the symbol's type. */
8870 dwarf2_const_value_data (struct attribute *attr,
8874 LONGEST l = DW_UNSND (attr);
8876 if (bits < sizeof (l) * 8)
8878 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
8879 l &= ((LONGEST) 1 << bits) - 1;
8881 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
8884 SYMBOL_VALUE (sym) = l;
8885 SYMBOL_CLASS (sym) = LOC_CONST;
8889 /* Return the type of the die in question using its DW_AT_type attribute. */
8891 static struct type *
8892 die_type (struct die_info *die, struct dwarf2_cu *cu)
8895 struct attribute *type_attr;
8896 struct die_info *type_die;
8898 type_attr = dwarf2_attr (die, DW_AT_type, cu);
8901 /* A missing DW_AT_type represents a void type. */
8902 return objfile_type (cu->objfile)->builtin_void;
8905 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
8907 type = tag_type_to_type (type_die, cu);
8910 dump_die_for_error (type_die);
8911 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8917 /* True iff CU's producer generates GNAT Ada auxiliary information
8918 that allows to find parallel types through that information instead
8919 of having to do expensive parallel lookups by type name. */
8922 need_gnat_info (struct dwarf2_cu *cu)
8924 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8925 of GNAT produces this auxiliary information, without any indication
8926 that it is produced. Part of enhancing the FSF version of GNAT
8927 to produce that information will be to put in place an indicator
8928 that we can use in order to determine whether the descriptive type
8929 info is available or not. One suggestion that has been made is
8930 to use a new attribute, attached to the CU die. For now, assume
8931 that the descriptive type info is not available. */
8936 /* Return the auxiliary type of the die in question using its
8937 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8938 attribute is not present. */
8940 static struct type *
8941 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
8944 struct attribute *type_attr;
8945 struct die_info *type_die;
8947 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
8951 type_die = follow_die_ref (die, type_attr, &cu);
8952 type = tag_type_to_type (type_die, cu);
8955 dump_die_for_error (type_die);
8956 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8962 /* If DIE has a descriptive_type attribute, then set the TYPE's
8963 descriptive type accordingly. */
8966 set_descriptive_type (struct type *type, struct die_info *die,
8967 struct dwarf2_cu *cu)
8969 struct type *descriptive_type = die_descriptive_type (die, cu);
8971 if (descriptive_type)
8973 ALLOCATE_GNAT_AUX_TYPE (type);
8974 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
8978 /* Return the containing type of the die in question using its
8979 DW_AT_containing_type attribute. */
8981 static struct type *
8982 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
8984 struct type *type = NULL;
8985 struct attribute *type_attr;
8986 struct die_info *type_die = NULL;
8988 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
8991 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
8992 type = tag_type_to_type (type_die, cu);
8997 dump_die_for_error (type_die);
8998 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
9004 static struct type *
9005 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
9007 struct type *this_type;
9009 this_type = read_type_die (die, cu);
9012 dump_die_for_error (die);
9013 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
9019 static struct type *
9020 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
9022 struct type *this_type;
9024 this_type = get_die_type (die, cu);
9030 case DW_TAG_class_type:
9031 case DW_TAG_interface_type:
9032 case DW_TAG_structure_type:
9033 case DW_TAG_union_type:
9034 this_type = read_structure_type (die, cu);
9036 case DW_TAG_enumeration_type:
9037 this_type = read_enumeration_type (die, cu);
9039 case DW_TAG_subprogram:
9040 case DW_TAG_subroutine_type:
9041 case DW_TAG_inlined_subroutine:
9042 this_type = read_subroutine_type (die, cu);
9044 case DW_TAG_array_type:
9045 this_type = read_array_type (die, cu);
9047 case DW_TAG_set_type:
9048 this_type = read_set_type (die, cu);
9050 case DW_TAG_pointer_type:
9051 this_type = read_tag_pointer_type (die, cu);
9053 case DW_TAG_ptr_to_member_type:
9054 this_type = read_tag_ptr_to_member_type (die, cu);
9056 case DW_TAG_reference_type:
9057 this_type = read_tag_reference_type (die, cu);
9059 case DW_TAG_const_type:
9060 this_type = read_tag_const_type (die, cu);
9062 case DW_TAG_volatile_type:
9063 this_type = read_tag_volatile_type (die, cu);
9065 case DW_TAG_string_type:
9066 this_type = read_tag_string_type (die, cu);
9068 case DW_TAG_typedef:
9069 this_type = read_typedef (die, cu);
9071 case DW_TAG_subrange_type:
9072 this_type = read_subrange_type (die, cu);
9074 case DW_TAG_base_type:
9075 this_type = read_base_type (die, cu);
9077 case DW_TAG_unspecified_type:
9078 this_type = read_unspecified_type (die, cu);
9080 case DW_TAG_namespace:
9081 this_type = read_namespace_type (die, cu);
9084 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
9085 dwarf_tag_name (die->tag));
9092 /* Return the name of the namespace/class that DIE is defined within,
9093 or "" if we can't tell. The caller should not xfree the result.
9095 For example, if we're within the method foo() in the following
9105 then determine_prefix on foo's die will return "N::C". */
9108 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
9110 struct die_info *parent, *spec_die;
9111 struct dwarf2_cu *spec_cu;
9112 struct type *parent_type;
9114 if (cu->language != language_cplus
9115 && cu->language != language_java)
9118 /* We have to be careful in the presence of DW_AT_specification.
9119 For example, with GCC 3.4, given the code
9123 // Definition of N::foo.
9127 then we'll have a tree of DIEs like this:
9129 1: DW_TAG_compile_unit
9130 2: DW_TAG_namespace // N
9131 3: DW_TAG_subprogram // declaration of N::foo
9132 4: DW_TAG_subprogram // definition of N::foo
9133 DW_AT_specification // refers to die #3
9135 Thus, when processing die #4, we have to pretend that we're in
9136 the context of its DW_AT_specification, namely the contex of die
9139 spec_die = die_specification (die, &spec_cu);
9140 if (spec_die == NULL)
9141 parent = die->parent;
9144 parent = spec_die->parent;
9151 switch (parent->tag)
9153 case DW_TAG_namespace:
9154 parent_type = read_type_die (parent, cu);
9155 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9156 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9157 Work around this problem here. */
9158 if (cu->language == language_cplus
9159 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
9161 /* We give a name to even anonymous namespaces. */
9162 return TYPE_TAG_NAME (parent_type);
9163 case DW_TAG_class_type:
9164 case DW_TAG_interface_type:
9165 case DW_TAG_structure_type:
9166 case DW_TAG_union_type:
9167 parent_type = read_type_die (parent, cu);
9168 if (TYPE_TAG_NAME (parent_type) != NULL)
9169 return TYPE_TAG_NAME (parent_type);
9171 /* An anonymous structure is only allowed non-static data
9172 members; no typedefs, no member functions, et cetera.
9173 So it does not need a prefix. */
9176 return determine_prefix (parent, cu);
9180 /* Return a newly-allocated string formed by concatenating PREFIX and
9181 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9182 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9183 perform an obconcat, otherwise allocate storage for the result. The CU argument
9184 is used to determine the language and hence, the appropriate separator. */
9186 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9189 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
9190 struct dwarf2_cu *cu)
9194 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
9196 else if (cu->language == language_java)
9208 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
9209 strcpy (retval, prefix);
9210 strcat (retval, sep);
9211 strcat (retval, suffix);
9216 /* We have an obstack. */
9217 return obconcat (obs, prefix, sep, suffix);
9221 /* Return sibling of die, NULL if no sibling. */
9223 static struct die_info *
9224 sibling_die (struct die_info *die)
9226 return die->sibling;
9229 /* Get name of a die, return NULL if not found. */
9232 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
9233 struct obstack *obstack)
9235 if (name && cu->language == language_cplus)
9237 char *canon_name = cp_canonicalize_string (name);
9239 if (canon_name != NULL)
9241 if (strcmp (canon_name, name) != 0)
9242 name = obsavestring (canon_name, strlen (canon_name),
9251 /* Get name of a die, return NULL if not found. */
9254 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
9256 struct attribute *attr;
9258 attr = dwarf2_attr (die, DW_AT_name, cu);
9259 if (!attr || !DW_STRING (attr))
9264 case DW_TAG_compile_unit:
9265 /* Compilation units have a DW_AT_name that is a filename, not
9266 a source language identifier. */
9267 case DW_TAG_enumeration_type:
9268 case DW_TAG_enumerator:
9269 /* These tags always have simple identifiers already; no need
9270 to canonicalize them. */
9271 return DW_STRING (attr);
9273 case DW_TAG_subprogram:
9274 /* Java constructors will all be named "<init>", so return
9275 the class name when we see this special case. */
9276 if (cu->language == language_java
9277 && DW_STRING (attr) != NULL
9278 && strcmp (DW_STRING (attr), "<init>") == 0)
9280 struct dwarf2_cu *spec_cu = cu;
9281 struct die_info *spec_die;
9283 /* GCJ will output '<init>' for Java constructor names.
9284 For this special case, return the name of the parent class. */
9286 /* GCJ may output suprogram DIEs with AT_specification set.
9287 If so, use the name of the specified DIE. */
9288 spec_die = die_specification (die, &spec_cu);
9289 if (spec_die != NULL)
9290 return dwarf2_name (spec_die, spec_cu);
9295 if (die->tag == DW_TAG_class_type)
9296 return dwarf2_name (die, cu);
9298 while (die->tag != DW_TAG_compile_unit);
9302 case DW_TAG_class_type:
9303 case DW_TAG_interface_type:
9304 case DW_TAG_structure_type:
9305 case DW_TAG_union_type:
9306 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9307 structures or unions. These were of the form "._%d" in GCC 4.1,
9308 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9309 and GCC 4.4. We work around this problem by ignoring these. */
9310 if (strncmp (DW_STRING (attr), "._", 2) == 0
9311 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)
9319 if (!DW_STRING_IS_CANONICAL (attr))
9322 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
9323 &cu->objfile->objfile_obstack);
9324 DW_STRING_IS_CANONICAL (attr) = 1;
9326 return DW_STRING (attr);
9329 /* Return the die that this die in an extension of, or NULL if there
9330 is none. *EXT_CU is the CU containing DIE on input, and the CU
9331 containing the return value on output. */
9333 static struct die_info *
9334 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
9336 struct attribute *attr;
9338 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
9342 return follow_die_ref (die, attr, ext_cu);
9345 /* Convert a DIE tag into its string name. */
9348 dwarf_tag_name (unsigned tag)
9352 case DW_TAG_padding:
9353 return "DW_TAG_padding";
9354 case DW_TAG_array_type:
9355 return "DW_TAG_array_type";
9356 case DW_TAG_class_type:
9357 return "DW_TAG_class_type";
9358 case DW_TAG_entry_point:
9359 return "DW_TAG_entry_point";
9360 case DW_TAG_enumeration_type:
9361 return "DW_TAG_enumeration_type";
9362 case DW_TAG_formal_parameter:
9363 return "DW_TAG_formal_parameter";
9364 case DW_TAG_imported_declaration:
9365 return "DW_TAG_imported_declaration";
9367 return "DW_TAG_label";
9368 case DW_TAG_lexical_block:
9369 return "DW_TAG_lexical_block";
9371 return "DW_TAG_member";
9372 case DW_TAG_pointer_type:
9373 return "DW_TAG_pointer_type";
9374 case DW_TAG_reference_type:
9375 return "DW_TAG_reference_type";
9376 case DW_TAG_compile_unit:
9377 return "DW_TAG_compile_unit";
9378 case DW_TAG_string_type:
9379 return "DW_TAG_string_type";
9380 case DW_TAG_structure_type:
9381 return "DW_TAG_structure_type";
9382 case DW_TAG_subroutine_type:
9383 return "DW_TAG_subroutine_type";
9384 case DW_TAG_typedef:
9385 return "DW_TAG_typedef";
9386 case DW_TAG_union_type:
9387 return "DW_TAG_union_type";
9388 case DW_TAG_unspecified_parameters:
9389 return "DW_TAG_unspecified_parameters";
9390 case DW_TAG_variant:
9391 return "DW_TAG_variant";
9392 case DW_TAG_common_block:
9393 return "DW_TAG_common_block";
9394 case DW_TAG_common_inclusion:
9395 return "DW_TAG_common_inclusion";
9396 case DW_TAG_inheritance:
9397 return "DW_TAG_inheritance";
9398 case DW_TAG_inlined_subroutine:
9399 return "DW_TAG_inlined_subroutine";
9401 return "DW_TAG_module";
9402 case DW_TAG_ptr_to_member_type:
9403 return "DW_TAG_ptr_to_member_type";
9404 case DW_TAG_set_type:
9405 return "DW_TAG_set_type";
9406 case DW_TAG_subrange_type:
9407 return "DW_TAG_subrange_type";
9408 case DW_TAG_with_stmt:
9409 return "DW_TAG_with_stmt";
9410 case DW_TAG_access_declaration:
9411 return "DW_TAG_access_declaration";
9412 case DW_TAG_base_type:
9413 return "DW_TAG_base_type";
9414 case DW_TAG_catch_block:
9415 return "DW_TAG_catch_block";
9416 case DW_TAG_const_type:
9417 return "DW_TAG_const_type";
9418 case DW_TAG_constant:
9419 return "DW_TAG_constant";
9420 case DW_TAG_enumerator:
9421 return "DW_TAG_enumerator";
9422 case DW_TAG_file_type:
9423 return "DW_TAG_file_type";
9425 return "DW_TAG_friend";
9426 case DW_TAG_namelist:
9427 return "DW_TAG_namelist";
9428 case DW_TAG_namelist_item:
9429 return "DW_TAG_namelist_item";
9430 case DW_TAG_packed_type:
9431 return "DW_TAG_packed_type";
9432 case DW_TAG_subprogram:
9433 return "DW_TAG_subprogram";
9434 case DW_TAG_template_type_param:
9435 return "DW_TAG_template_type_param";
9436 case DW_TAG_template_value_param:
9437 return "DW_TAG_template_value_param";
9438 case DW_TAG_thrown_type:
9439 return "DW_TAG_thrown_type";
9440 case DW_TAG_try_block:
9441 return "DW_TAG_try_block";
9442 case DW_TAG_variant_part:
9443 return "DW_TAG_variant_part";
9444 case DW_TAG_variable:
9445 return "DW_TAG_variable";
9446 case DW_TAG_volatile_type:
9447 return "DW_TAG_volatile_type";
9448 case DW_TAG_dwarf_procedure:
9449 return "DW_TAG_dwarf_procedure";
9450 case DW_TAG_restrict_type:
9451 return "DW_TAG_restrict_type";
9452 case DW_TAG_interface_type:
9453 return "DW_TAG_interface_type";
9454 case DW_TAG_namespace:
9455 return "DW_TAG_namespace";
9456 case DW_TAG_imported_module:
9457 return "DW_TAG_imported_module";
9458 case DW_TAG_unspecified_type:
9459 return "DW_TAG_unspecified_type";
9460 case DW_TAG_partial_unit:
9461 return "DW_TAG_partial_unit";
9462 case DW_TAG_imported_unit:
9463 return "DW_TAG_imported_unit";
9464 case DW_TAG_condition:
9465 return "DW_TAG_condition";
9466 case DW_TAG_shared_type:
9467 return "DW_TAG_shared_type";
9468 case DW_TAG_type_unit:
9469 return "DW_TAG_type_unit";
9470 case DW_TAG_MIPS_loop:
9471 return "DW_TAG_MIPS_loop";
9472 case DW_TAG_HP_array_descriptor:
9473 return "DW_TAG_HP_array_descriptor";
9474 case DW_TAG_format_label:
9475 return "DW_TAG_format_label";
9476 case DW_TAG_function_template:
9477 return "DW_TAG_function_template";
9478 case DW_TAG_class_template:
9479 return "DW_TAG_class_template";
9480 case DW_TAG_GNU_BINCL:
9481 return "DW_TAG_GNU_BINCL";
9482 case DW_TAG_GNU_EINCL:
9483 return "DW_TAG_GNU_EINCL";
9484 case DW_TAG_upc_shared_type:
9485 return "DW_TAG_upc_shared_type";
9486 case DW_TAG_upc_strict_type:
9487 return "DW_TAG_upc_strict_type";
9488 case DW_TAG_upc_relaxed_type:
9489 return "DW_TAG_upc_relaxed_type";
9490 case DW_TAG_PGI_kanji_type:
9491 return "DW_TAG_PGI_kanji_type";
9492 case DW_TAG_PGI_interface_block:
9493 return "DW_TAG_PGI_interface_block";
9495 return "DW_TAG_<unknown>";
9499 /* Convert a DWARF attribute code into its string name. */
9502 dwarf_attr_name (unsigned attr)
9507 return "DW_AT_sibling";
9508 case DW_AT_location:
9509 return "DW_AT_location";
9511 return "DW_AT_name";
9512 case DW_AT_ordering:
9513 return "DW_AT_ordering";
9514 case DW_AT_subscr_data:
9515 return "DW_AT_subscr_data";
9516 case DW_AT_byte_size:
9517 return "DW_AT_byte_size";
9518 case DW_AT_bit_offset:
9519 return "DW_AT_bit_offset";
9520 case DW_AT_bit_size:
9521 return "DW_AT_bit_size";
9522 case DW_AT_element_list:
9523 return "DW_AT_element_list";
9524 case DW_AT_stmt_list:
9525 return "DW_AT_stmt_list";
9527 return "DW_AT_low_pc";
9529 return "DW_AT_high_pc";
9530 case DW_AT_language:
9531 return "DW_AT_language";
9533 return "DW_AT_member";
9535 return "DW_AT_discr";
9536 case DW_AT_discr_value:
9537 return "DW_AT_discr_value";
9538 case DW_AT_visibility:
9539 return "DW_AT_visibility";
9541 return "DW_AT_import";
9542 case DW_AT_string_length:
9543 return "DW_AT_string_length";
9544 case DW_AT_common_reference:
9545 return "DW_AT_common_reference";
9546 case DW_AT_comp_dir:
9547 return "DW_AT_comp_dir";
9548 case DW_AT_const_value:
9549 return "DW_AT_const_value";
9550 case DW_AT_containing_type:
9551 return "DW_AT_containing_type";
9552 case DW_AT_default_value:
9553 return "DW_AT_default_value";
9555 return "DW_AT_inline";
9556 case DW_AT_is_optional:
9557 return "DW_AT_is_optional";
9558 case DW_AT_lower_bound:
9559 return "DW_AT_lower_bound";
9560 case DW_AT_producer:
9561 return "DW_AT_producer";
9562 case DW_AT_prototyped:
9563 return "DW_AT_prototyped";
9564 case DW_AT_return_addr:
9565 return "DW_AT_return_addr";
9566 case DW_AT_start_scope:
9567 return "DW_AT_start_scope";
9568 case DW_AT_bit_stride:
9569 return "DW_AT_bit_stride";
9570 case DW_AT_upper_bound:
9571 return "DW_AT_upper_bound";
9572 case DW_AT_abstract_origin:
9573 return "DW_AT_abstract_origin";
9574 case DW_AT_accessibility:
9575 return "DW_AT_accessibility";
9576 case DW_AT_address_class:
9577 return "DW_AT_address_class";
9578 case DW_AT_artificial:
9579 return "DW_AT_artificial";
9580 case DW_AT_base_types:
9581 return "DW_AT_base_types";
9582 case DW_AT_calling_convention:
9583 return "DW_AT_calling_convention";
9585 return "DW_AT_count";
9586 case DW_AT_data_member_location:
9587 return "DW_AT_data_member_location";
9588 case DW_AT_decl_column:
9589 return "DW_AT_decl_column";
9590 case DW_AT_decl_file:
9591 return "DW_AT_decl_file";
9592 case DW_AT_decl_line:
9593 return "DW_AT_decl_line";
9594 case DW_AT_declaration:
9595 return "DW_AT_declaration";
9596 case DW_AT_discr_list:
9597 return "DW_AT_discr_list";
9598 case DW_AT_encoding:
9599 return "DW_AT_encoding";
9600 case DW_AT_external:
9601 return "DW_AT_external";
9602 case DW_AT_frame_base:
9603 return "DW_AT_frame_base";
9605 return "DW_AT_friend";
9606 case DW_AT_identifier_case:
9607 return "DW_AT_identifier_case";
9608 case DW_AT_macro_info:
9609 return "DW_AT_macro_info";
9610 case DW_AT_namelist_items:
9611 return "DW_AT_namelist_items";
9612 case DW_AT_priority:
9613 return "DW_AT_priority";
9615 return "DW_AT_segment";
9616 case DW_AT_specification:
9617 return "DW_AT_specification";
9618 case DW_AT_static_link:
9619 return "DW_AT_static_link";
9621 return "DW_AT_type";
9622 case DW_AT_use_location:
9623 return "DW_AT_use_location";
9624 case DW_AT_variable_parameter:
9625 return "DW_AT_variable_parameter";
9626 case DW_AT_virtuality:
9627 return "DW_AT_virtuality";
9628 case DW_AT_vtable_elem_location:
9629 return "DW_AT_vtable_elem_location";
9630 /* DWARF 3 values. */
9631 case DW_AT_allocated:
9632 return "DW_AT_allocated";
9633 case DW_AT_associated:
9634 return "DW_AT_associated";
9635 case DW_AT_data_location:
9636 return "DW_AT_data_location";
9637 case DW_AT_byte_stride:
9638 return "DW_AT_byte_stride";
9639 case DW_AT_entry_pc:
9640 return "DW_AT_entry_pc";
9641 case DW_AT_use_UTF8:
9642 return "DW_AT_use_UTF8";
9643 case DW_AT_extension:
9644 return "DW_AT_extension";
9646 return "DW_AT_ranges";
9647 case DW_AT_trampoline:
9648 return "DW_AT_trampoline";
9649 case DW_AT_call_column:
9650 return "DW_AT_call_column";
9651 case DW_AT_call_file:
9652 return "DW_AT_call_file";
9653 case DW_AT_call_line:
9654 return "DW_AT_call_line";
9655 case DW_AT_description:
9656 return "DW_AT_description";
9657 case DW_AT_binary_scale:
9658 return "DW_AT_binary_scale";
9659 case DW_AT_decimal_scale:
9660 return "DW_AT_decimal_scale";
9662 return "DW_AT_small";
9663 case DW_AT_decimal_sign:
9664 return "DW_AT_decimal_sign";
9665 case DW_AT_digit_count:
9666 return "DW_AT_digit_count";
9667 case DW_AT_picture_string:
9668 return "DW_AT_picture_string";
9670 return "DW_AT_mutable";
9671 case DW_AT_threads_scaled:
9672 return "DW_AT_threads_scaled";
9673 case DW_AT_explicit:
9674 return "DW_AT_explicit";
9675 case DW_AT_object_pointer:
9676 return "DW_AT_object_pointer";
9677 case DW_AT_endianity:
9678 return "DW_AT_endianity";
9679 case DW_AT_elemental:
9680 return "DW_AT_elemental";
9682 return "DW_AT_pure";
9683 case DW_AT_recursive:
9684 return "DW_AT_recursive";
9685 /* DWARF 4 values. */
9686 case DW_AT_signature:
9687 return "DW_AT_signature";
9688 /* SGI/MIPS extensions. */
9689 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9690 case DW_AT_MIPS_fde:
9691 return "DW_AT_MIPS_fde";
9693 case DW_AT_MIPS_loop_begin:
9694 return "DW_AT_MIPS_loop_begin";
9695 case DW_AT_MIPS_tail_loop_begin:
9696 return "DW_AT_MIPS_tail_loop_begin";
9697 case DW_AT_MIPS_epilog_begin:
9698 return "DW_AT_MIPS_epilog_begin";
9699 case DW_AT_MIPS_loop_unroll_factor:
9700 return "DW_AT_MIPS_loop_unroll_factor";
9701 case DW_AT_MIPS_software_pipeline_depth:
9702 return "DW_AT_MIPS_software_pipeline_depth";
9703 case DW_AT_MIPS_linkage_name:
9704 return "DW_AT_MIPS_linkage_name";
9705 case DW_AT_MIPS_stride:
9706 return "DW_AT_MIPS_stride";
9707 case DW_AT_MIPS_abstract_name:
9708 return "DW_AT_MIPS_abstract_name";
9709 case DW_AT_MIPS_clone_origin:
9710 return "DW_AT_MIPS_clone_origin";
9711 case DW_AT_MIPS_has_inlines:
9712 return "DW_AT_MIPS_has_inlines";
9713 /* HP extensions. */
9714 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9715 case DW_AT_HP_block_index:
9716 return "DW_AT_HP_block_index";
9718 case DW_AT_HP_unmodifiable:
9719 return "DW_AT_HP_unmodifiable";
9720 case DW_AT_HP_actuals_stmt_list:
9721 return "DW_AT_HP_actuals_stmt_list";
9722 case DW_AT_HP_proc_per_section:
9723 return "DW_AT_HP_proc_per_section";
9724 case DW_AT_HP_raw_data_ptr:
9725 return "DW_AT_HP_raw_data_ptr";
9726 case DW_AT_HP_pass_by_reference:
9727 return "DW_AT_HP_pass_by_reference";
9728 case DW_AT_HP_opt_level:
9729 return "DW_AT_HP_opt_level";
9730 case DW_AT_HP_prof_version_id:
9731 return "DW_AT_HP_prof_version_id";
9732 case DW_AT_HP_opt_flags:
9733 return "DW_AT_HP_opt_flags";
9734 case DW_AT_HP_cold_region_low_pc:
9735 return "DW_AT_HP_cold_region_low_pc";
9736 case DW_AT_HP_cold_region_high_pc:
9737 return "DW_AT_HP_cold_region_high_pc";
9738 case DW_AT_HP_all_variables_modifiable:
9739 return "DW_AT_HP_all_variables_modifiable";
9740 case DW_AT_HP_linkage_name:
9741 return "DW_AT_HP_linkage_name";
9742 case DW_AT_HP_prof_flags:
9743 return "DW_AT_HP_prof_flags";
9744 /* GNU extensions. */
9745 case DW_AT_sf_names:
9746 return "DW_AT_sf_names";
9747 case DW_AT_src_info:
9748 return "DW_AT_src_info";
9749 case DW_AT_mac_info:
9750 return "DW_AT_mac_info";
9751 case DW_AT_src_coords:
9752 return "DW_AT_src_coords";
9753 case DW_AT_body_begin:
9754 return "DW_AT_body_begin";
9755 case DW_AT_body_end:
9756 return "DW_AT_body_end";
9757 case DW_AT_GNU_vector:
9758 return "DW_AT_GNU_vector";
9759 /* VMS extensions. */
9760 case DW_AT_VMS_rtnbeg_pd_address:
9761 return "DW_AT_VMS_rtnbeg_pd_address";
9762 /* UPC extension. */
9763 case DW_AT_upc_threads_scaled:
9764 return "DW_AT_upc_threads_scaled";
9765 /* PGI (STMicroelectronics) extensions. */
9766 case DW_AT_PGI_lbase:
9767 return "DW_AT_PGI_lbase";
9768 case DW_AT_PGI_soffset:
9769 return "DW_AT_PGI_soffset";
9770 case DW_AT_PGI_lstride:
9771 return "DW_AT_PGI_lstride";
9773 return "DW_AT_<unknown>";
9777 /* Convert a DWARF value form code into its string name. */
9780 dwarf_form_name (unsigned form)
9785 return "DW_FORM_addr";
9786 case DW_FORM_block2:
9787 return "DW_FORM_block2";
9788 case DW_FORM_block4:
9789 return "DW_FORM_block4";
9791 return "DW_FORM_data2";
9793 return "DW_FORM_data4";
9795 return "DW_FORM_data8";
9796 case DW_FORM_string:
9797 return "DW_FORM_string";
9799 return "DW_FORM_block";
9800 case DW_FORM_block1:
9801 return "DW_FORM_block1";
9803 return "DW_FORM_data1";
9805 return "DW_FORM_flag";
9807 return "DW_FORM_sdata";
9809 return "DW_FORM_strp";
9811 return "DW_FORM_udata";
9812 case DW_FORM_ref_addr:
9813 return "DW_FORM_ref_addr";
9815 return "DW_FORM_ref1";
9817 return "DW_FORM_ref2";
9819 return "DW_FORM_ref4";
9821 return "DW_FORM_ref8";
9822 case DW_FORM_ref_udata:
9823 return "DW_FORM_ref_udata";
9824 case DW_FORM_indirect:
9825 return "DW_FORM_indirect";
9826 case DW_FORM_sec_offset:
9827 return "DW_FORM_sec_offset";
9828 case DW_FORM_exprloc:
9829 return "DW_FORM_exprloc";
9830 case DW_FORM_flag_present:
9831 return "DW_FORM_flag_present";
9833 return "DW_FORM_sig8";
9835 return "DW_FORM_<unknown>";
9839 /* Convert a DWARF stack opcode into its string name. */
9842 dwarf_stack_op_name (unsigned op)
9847 return "DW_OP_addr";
9849 return "DW_OP_deref";
9851 return "DW_OP_const1u";
9853 return "DW_OP_const1s";
9855 return "DW_OP_const2u";
9857 return "DW_OP_const2s";
9859 return "DW_OP_const4u";
9861 return "DW_OP_const4s";
9863 return "DW_OP_const8u";
9865 return "DW_OP_const8s";
9867 return "DW_OP_constu";
9869 return "DW_OP_consts";
9873 return "DW_OP_drop";
9875 return "DW_OP_over";
9877 return "DW_OP_pick";
9879 return "DW_OP_swap";
9883 return "DW_OP_xderef";
9891 return "DW_OP_minus";
9903 return "DW_OP_plus";
9904 case DW_OP_plus_uconst:
9905 return "DW_OP_plus_uconst";
9911 return "DW_OP_shra";
9929 return "DW_OP_skip";
9931 return "DW_OP_lit0";
9933 return "DW_OP_lit1";
9935 return "DW_OP_lit2";
9937 return "DW_OP_lit3";
9939 return "DW_OP_lit4";
9941 return "DW_OP_lit5";
9943 return "DW_OP_lit6";
9945 return "DW_OP_lit7";
9947 return "DW_OP_lit8";
9949 return "DW_OP_lit9";
9951 return "DW_OP_lit10";
9953 return "DW_OP_lit11";
9955 return "DW_OP_lit12";
9957 return "DW_OP_lit13";
9959 return "DW_OP_lit14";
9961 return "DW_OP_lit15";
9963 return "DW_OP_lit16";
9965 return "DW_OP_lit17";
9967 return "DW_OP_lit18";
9969 return "DW_OP_lit19";
9971 return "DW_OP_lit20";
9973 return "DW_OP_lit21";
9975 return "DW_OP_lit22";
9977 return "DW_OP_lit23";
9979 return "DW_OP_lit24";
9981 return "DW_OP_lit25";
9983 return "DW_OP_lit26";
9985 return "DW_OP_lit27";
9987 return "DW_OP_lit28";
9989 return "DW_OP_lit29";
9991 return "DW_OP_lit30";
9993 return "DW_OP_lit31";
9995 return "DW_OP_reg0";
9997 return "DW_OP_reg1";
9999 return "DW_OP_reg2";
10001 return "DW_OP_reg3";
10003 return "DW_OP_reg4";
10005 return "DW_OP_reg5";
10007 return "DW_OP_reg6";
10009 return "DW_OP_reg7";
10011 return "DW_OP_reg8";
10013 return "DW_OP_reg9";
10015 return "DW_OP_reg10";
10017 return "DW_OP_reg11";
10019 return "DW_OP_reg12";
10021 return "DW_OP_reg13";
10023 return "DW_OP_reg14";
10025 return "DW_OP_reg15";
10027 return "DW_OP_reg16";
10029 return "DW_OP_reg17";
10031 return "DW_OP_reg18";
10033 return "DW_OP_reg19";
10035 return "DW_OP_reg20";
10037 return "DW_OP_reg21";
10039 return "DW_OP_reg22";
10041 return "DW_OP_reg23";
10043 return "DW_OP_reg24";
10045 return "DW_OP_reg25";
10047 return "DW_OP_reg26";
10049 return "DW_OP_reg27";
10051 return "DW_OP_reg28";
10053 return "DW_OP_reg29";
10055 return "DW_OP_reg30";
10057 return "DW_OP_reg31";
10059 return "DW_OP_breg0";
10061 return "DW_OP_breg1";
10063 return "DW_OP_breg2";
10065 return "DW_OP_breg3";
10067 return "DW_OP_breg4";
10069 return "DW_OP_breg5";
10071 return "DW_OP_breg6";
10073 return "DW_OP_breg7";
10075 return "DW_OP_breg8";
10077 return "DW_OP_breg9";
10079 return "DW_OP_breg10";
10081 return "DW_OP_breg11";
10083 return "DW_OP_breg12";
10085 return "DW_OP_breg13";
10087 return "DW_OP_breg14";
10089 return "DW_OP_breg15";
10091 return "DW_OP_breg16";
10093 return "DW_OP_breg17";
10095 return "DW_OP_breg18";
10097 return "DW_OP_breg19";
10099 return "DW_OP_breg20";
10101 return "DW_OP_breg21";
10103 return "DW_OP_breg22";
10105 return "DW_OP_breg23";
10107 return "DW_OP_breg24";
10109 return "DW_OP_breg25";
10111 return "DW_OP_breg26";
10113 return "DW_OP_breg27";
10115 return "DW_OP_breg28";
10117 return "DW_OP_breg29";
10119 return "DW_OP_breg30";
10121 return "DW_OP_breg31";
10123 return "DW_OP_regx";
10125 return "DW_OP_fbreg";
10127 return "DW_OP_bregx";
10129 return "DW_OP_piece";
10130 case DW_OP_deref_size:
10131 return "DW_OP_deref_size";
10132 case DW_OP_xderef_size:
10133 return "DW_OP_xderef_size";
10135 return "DW_OP_nop";
10136 /* DWARF 3 extensions. */
10137 case DW_OP_push_object_address:
10138 return "DW_OP_push_object_address";
10140 return "DW_OP_call2";
10142 return "DW_OP_call4";
10143 case DW_OP_call_ref:
10144 return "DW_OP_call_ref";
10145 /* GNU extensions. */
10146 case DW_OP_form_tls_address:
10147 return "DW_OP_form_tls_address";
10148 case DW_OP_call_frame_cfa:
10149 return "DW_OP_call_frame_cfa";
10150 case DW_OP_bit_piece:
10151 return "DW_OP_bit_piece";
10152 case DW_OP_GNU_push_tls_address:
10153 return "DW_OP_GNU_push_tls_address";
10154 case DW_OP_GNU_uninit:
10155 return "DW_OP_GNU_uninit";
10156 /* HP extensions. */
10157 case DW_OP_HP_is_value:
10158 return "DW_OP_HP_is_value";
10159 case DW_OP_HP_fltconst4:
10160 return "DW_OP_HP_fltconst4";
10161 case DW_OP_HP_fltconst8:
10162 return "DW_OP_HP_fltconst8";
10163 case DW_OP_HP_mod_range:
10164 return "DW_OP_HP_mod_range";
10165 case DW_OP_HP_unmod_range:
10166 return "DW_OP_HP_unmod_range";
10168 return "DW_OP_HP_tls";
10170 return "OP_<unknown>";
10175 dwarf_bool_name (unsigned mybool)
10183 /* Convert a DWARF type code into its string name. */
10186 dwarf_type_encoding_name (unsigned enc)
10191 return "DW_ATE_void";
10192 case DW_ATE_address:
10193 return "DW_ATE_address";
10194 case DW_ATE_boolean:
10195 return "DW_ATE_boolean";
10196 case DW_ATE_complex_float:
10197 return "DW_ATE_complex_float";
10199 return "DW_ATE_float";
10200 case DW_ATE_signed:
10201 return "DW_ATE_signed";
10202 case DW_ATE_signed_char:
10203 return "DW_ATE_signed_char";
10204 case DW_ATE_unsigned:
10205 return "DW_ATE_unsigned";
10206 case DW_ATE_unsigned_char:
10207 return "DW_ATE_unsigned_char";
10209 case DW_ATE_imaginary_float:
10210 return "DW_ATE_imaginary_float";
10211 case DW_ATE_packed_decimal:
10212 return "DW_ATE_packed_decimal";
10213 case DW_ATE_numeric_string:
10214 return "DW_ATE_numeric_string";
10215 case DW_ATE_edited:
10216 return "DW_ATE_edited";
10217 case DW_ATE_signed_fixed:
10218 return "DW_ATE_signed_fixed";
10219 case DW_ATE_unsigned_fixed:
10220 return "DW_ATE_unsigned_fixed";
10221 case DW_ATE_decimal_float:
10222 return "DW_ATE_decimal_float";
10223 /* HP extensions. */
10224 case DW_ATE_HP_float80:
10225 return "DW_ATE_HP_float80";
10226 case DW_ATE_HP_complex_float80:
10227 return "DW_ATE_HP_complex_float80";
10228 case DW_ATE_HP_float128:
10229 return "DW_ATE_HP_float128";
10230 case DW_ATE_HP_complex_float128:
10231 return "DW_ATE_HP_complex_float128";
10232 case DW_ATE_HP_floathpintel:
10233 return "DW_ATE_HP_floathpintel";
10234 case DW_ATE_HP_imaginary_float80:
10235 return "DW_ATE_HP_imaginary_float80";
10236 case DW_ATE_HP_imaginary_float128:
10237 return "DW_ATE_HP_imaginary_float128";
10239 return "DW_ATE_<unknown>";
10243 /* Convert a DWARF call frame info operation to its string name. */
10247 dwarf_cfi_name (unsigned cfi_opc)
10251 case DW_CFA_advance_loc:
10252 return "DW_CFA_advance_loc";
10253 case DW_CFA_offset:
10254 return "DW_CFA_offset";
10255 case DW_CFA_restore:
10256 return "DW_CFA_restore";
10258 return "DW_CFA_nop";
10259 case DW_CFA_set_loc:
10260 return "DW_CFA_set_loc";
10261 case DW_CFA_advance_loc1:
10262 return "DW_CFA_advance_loc1";
10263 case DW_CFA_advance_loc2:
10264 return "DW_CFA_advance_loc2";
10265 case DW_CFA_advance_loc4:
10266 return "DW_CFA_advance_loc4";
10267 case DW_CFA_offset_extended:
10268 return "DW_CFA_offset_extended";
10269 case DW_CFA_restore_extended:
10270 return "DW_CFA_restore_extended";
10271 case DW_CFA_undefined:
10272 return "DW_CFA_undefined";
10273 case DW_CFA_same_value:
10274 return "DW_CFA_same_value";
10275 case DW_CFA_register:
10276 return "DW_CFA_register";
10277 case DW_CFA_remember_state:
10278 return "DW_CFA_remember_state";
10279 case DW_CFA_restore_state:
10280 return "DW_CFA_restore_state";
10281 case DW_CFA_def_cfa:
10282 return "DW_CFA_def_cfa";
10283 case DW_CFA_def_cfa_register:
10284 return "DW_CFA_def_cfa_register";
10285 case DW_CFA_def_cfa_offset:
10286 return "DW_CFA_def_cfa_offset";
10288 case DW_CFA_def_cfa_expression:
10289 return "DW_CFA_def_cfa_expression";
10290 case DW_CFA_expression:
10291 return "DW_CFA_expression";
10292 case DW_CFA_offset_extended_sf:
10293 return "DW_CFA_offset_extended_sf";
10294 case DW_CFA_def_cfa_sf:
10295 return "DW_CFA_def_cfa_sf";
10296 case DW_CFA_def_cfa_offset_sf:
10297 return "DW_CFA_def_cfa_offset_sf";
10298 case DW_CFA_val_offset:
10299 return "DW_CFA_val_offset";
10300 case DW_CFA_val_offset_sf:
10301 return "DW_CFA_val_offset_sf";
10302 case DW_CFA_val_expression:
10303 return "DW_CFA_val_expression";
10304 /* SGI/MIPS specific. */
10305 case DW_CFA_MIPS_advance_loc8:
10306 return "DW_CFA_MIPS_advance_loc8";
10307 /* GNU extensions. */
10308 case DW_CFA_GNU_window_save:
10309 return "DW_CFA_GNU_window_save";
10310 case DW_CFA_GNU_args_size:
10311 return "DW_CFA_GNU_args_size";
10312 case DW_CFA_GNU_negative_offset_extended:
10313 return "DW_CFA_GNU_negative_offset_extended";
10315 return "DW_CFA_<unknown>";
10321 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
10325 print_spaces (indent, f);
10326 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
10327 dwarf_tag_name (die->tag), die->abbrev, die->offset);
10329 if (die->parent != NULL)
10331 print_spaces (indent, f);
10332 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
10333 die->parent->offset);
10336 print_spaces (indent, f);
10337 fprintf_unfiltered (f, " has children: %s\n",
10338 dwarf_bool_name (die->child != NULL));
10340 print_spaces (indent, f);
10341 fprintf_unfiltered (f, " attributes:\n");
10343 for (i = 0; i < die->num_attrs; ++i)
10345 print_spaces (indent, f);
10346 fprintf_unfiltered (f, " %s (%s) ",
10347 dwarf_attr_name (die->attrs[i].name),
10348 dwarf_form_name (die->attrs[i].form));
10350 switch (die->attrs[i].form)
10352 case DW_FORM_ref_addr:
10354 fprintf_unfiltered (f, "address: ");
10355 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
10357 case DW_FORM_block2:
10358 case DW_FORM_block4:
10359 case DW_FORM_block:
10360 case DW_FORM_block1:
10361 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
10363 case DW_FORM_exprloc:
10364 fprintf_unfiltered (f, "expression: size %u",
10365 DW_BLOCK (&die->attrs[i])->size);
10370 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
10371 (long) (DW_ADDR (&die->attrs[i])));
10373 case DW_FORM_data1:
10374 case DW_FORM_data2:
10375 case DW_FORM_data4:
10376 case DW_FORM_data8:
10377 case DW_FORM_udata:
10378 case DW_FORM_sdata:
10379 fprintf_unfiltered (f, "constant: %s",
10380 pulongest (DW_UNSND (&die->attrs[i])));
10382 case DW_FORM_sec_offset:
10383 fprintf_unfiltered (f, "section offset: %s",
10384 pulongest (DW_UNSND (&die->attrs[i])));
10387 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
10388 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
10389 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
10391 fprintf_unfiltered (f, "signatured type, offset: unknown");
10393 case DW_FORM_string:
10395 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
10396 DW_STRING (&die->attrs[i])
10397 ? DW_STRING (&die->attrs[i]) : "",
10398 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
10401 if (DW_UNSND (&die->attrs[i]))
10402 fprintf_unfiltered (f, "flag: TRUE");
10404 fprintf_unfiltered (f, "flag: FALSE");
10406 case DW_FORM_flag_present:
10407 fprintf_unfiltered (f, "flag: TRUE");
10409 case DW_FORM_indirect:
10410 /* the reader will have reduced the indirect form to
10411 the "base form" so this form should not occur */
10412 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
10415 fprintf_unfiltered (f, "unsupported attribute form: %d.",
10416 die->attrs[i].form);
10419 fprintf_unfiltered (f, "\n");
10424 dump_die_for_error (struct die_info *die)
10426 dump_die_shallow (gdb_stderr, 0, die);
10430 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
10432 int indent = level * 4;
10434 gdb_assert (die != NULL);
10436 if (level >= max_level)
10439 dump_die_shallow (f, indent, die);
10441 if (die->child != NULL)
10443 print_spaces (indent, f);
10444 fprintf_unfiltered (f, " Children:");
10445 if (level + 1 < max_level)
10447 fprintf_unfiltered (f, "\n");
10448 dump_die_1 (f, level + 1, max_level, die->child);
10452 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
10456 if (die->sibling != NULL && level > 0)
10458 dump_die_1 (f, level, max_level, die->sibling);
10462 /* This is called from the pdie macro in gdbinit.in.
10463 It's not static so gcc will keep a copy callable from gdb. */
10466 dump_die (struct die_info *die, int max_level)
10468 dump_die_1 (gdb_stdlog, 0, max_level, die);
10472 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
10476 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
10482 is_ref_attr (struct attribute *attr)
10484 switch (attr->form)
10486 case DW_FORM_ref_addr:
10491 case DW_FORM_ref_udata:
10498 static unsigned int
10499 dwarf2_get_ref_die_offset (struct attribute *attr)
10501 if (is_ref_attr (attr))
10502 return DW_ADDR (attr);
10504 complaint (&symfile_complaints,
10505 _("unsupported die ref attribute form: '%s'"),
10506 dwarf_form_name (attr->form));
10510 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10511 * the value held by the attribute is not constant. */
10514 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
10516 if (attr->form == DW_FORM_sdata)
10517 return DW_SND (attr);
10518 else if (attr->form == DW_FORM_udata
10519 || attr->form == DW_FORM_data1
10520 || attr->form == DW_FORM_data2
10521 || attr->form == DW_FORM_data4
10522 || attr->form == DW_FORM_data8)
10523 return DW_UNSND (attr);
10526 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
10527 dwarf_form_name (attr->form));
10528 return default_value;
10532 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10533 unit and add it to our queue.
10534 The result is non-zero if PER_CU was queued, otherwise the result is zero
10535 meaning either PER_CU is already queued or it is already loaded. */
10538 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
10539 struct dwarf2_per_cu_data *per_cu)
10541 /* Mark the dependence relation so that we don't flush PER_CU
10543 dwarf2_add_dependence (this_cu, per_cu);
10545 /* If it's already on the queue, we have nothing to do. */
10546 if (per_cu->queued)
10549 /* If the compilation unit is already loaded, just mark it as
10551 if (per_cu->cu != NULL)
10553 per_cu->cu->last_used = 0;
10557 /* Add it to the queue. */
10558 queue_comp_unit (per_cu, this_cu->objfile);
10563 /* Follow reference or signature attribute ATTR of SRC_DIE.
10564 On entry *REF_CU is the CU of SRC_DIE.
10565 On exit *REF_CU is the CU of the result. */
10567 static struct die_info *
10568 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
10569 struct dwarf2_cu **ref_cu)
10571 struct die_info *die;
10573 if (is_ref_attr (attr))
10574 die = follow_die_ref (src_die, attr, ref_cu);
10575 else if (attr->form == DW_FORM_sig8)
10576 die = follow_die_sig (src_die, attr, ref_cu);
10579 dump_die_for_error (src_die);
10580 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10581 (*ref_cu)->objfile->name);
10587 /* Follow reference attribute ATTR of SRC_DIE.
10588 On entry *REF_CU is the CU of SRC_DIE.
10589 On exit *REF_CU is the CU of the result. */
10591 static struct die_info *
10592 follow_die_ref (struct die_info *src_die, struct attribute *attr,
10593 struct dwarf2_cu **ref_cu)
10595 struct die_info *die;
10596 unsigned int offset;
10597 struct die_info temp_die;
10598 struct dwarf2_cu *target_cu, *cu = *ref_cu;
10600 gdb_assert (cu->per_cu != NULL);
10602 offset = dwarf2_get_ref_die_offset (attr);
10604 if (cu->per_cu->from_debug_types)
10606 /* .debug_types CUs cannot reference anything outside their CU.
10607 If they need to, they have to reference a signatured type via
10609 if (! offset_in_cu_p (&cu->header, offset))
10613 else if (! offset_in_cu_p (&cu->header, offset))
10615 struct dwarf2_per_cu_data *per_cu;
10616 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
10618 /* If necessary, add it to the queue and load its DIEs. */
10619 if (maybe_queue_comp_unit (cu, per_cu))
10620 load_full_comp_unit (per_cu, cu->objfile);
10622 target_cu = per_cu->cu;
10627 *ref_cu = target_cu;
10628 temp_die.offset = offset;
10629 die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
10635 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10636 "at 0x%x [in module %s]"),
10637 offset, src_die->offset, cu->objfile->name);
10640 /* Follow the signature attribute ATTR in SRC_DIE.
10641 On entry *REF_CU is the CU of SRC_DIE.
10642 On exit *REF_CU is the CU of the result. */
10644 static struct die_info *
10645 follow_die_sig (struct die_info *src_die, struct attribute *attr,
10646 struct dwarf2_cu **ref_cu)
10648 struct objfile *objfile = (*ref_cu)->objfile;
10649 struct die_info temp_die;
10650 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
10651 struct dwarf2_cu *sig_cu;
10652 struct die_info *die;
10654 /* sig_type will be NULL if the signatured type is missing from
10656 if (sig_type == NULL)
10657 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10658 "at 0x%x [in module %s]"),
10659 src_die->offset, objfile->name);
10661 /* If necessary, add it to the queue and load its DIEs. */
10663 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
10664 read_signatured_type (objfile, sig_type);
10666 gdb_assert (sig_type->per_cu.cu != NULL);
10668 sig_cu = sig_type->per_cu.cu;
10669 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
10670 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
10677 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10678 "at 0x%x [in module %s]"),
10679 sig_type->type_offset, src_die->offset, objfile->name);
10682 /* Given an offset of a signatured type, return its signatured_type. */
10684 static struct signatured_type *
10685 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
10687 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
10688 unsigned int length, initial_length_size;
10689 unsigned int sig_offset;
10690 struct signatured_type find_entry, *type_sig;
10692 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
10693 sig_offset = (initial_length_size
10695 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
10696 + 1 /*address_size*/);
10697 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
10698 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
10700 /* This is only used to lookup previously recorded types.
10701 If we didn't find it, it's our bug. */
10702 gdb_assert (type_sig != NULL);
10703 gdb_assert (offset == type_sig->offset);
10708 /* Read in signatured type at OFFSET and build its CU and die(s). */
10711 read_signatured_type_at_offset (struct objfile *objfile,
10712 unsigned int offset)
10714 struct signatured_type *type_sig;
10716 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
10718 /* We have the section offset, but we need the signature to do the
10719 hash table lookup. */
10720 type_sig = lookup_signatured_type_at_offset (objfile, offset);
10722 gdb_assert (type_sig->per_cu.cu == NULL);
10724 read_signatured_type (objfile, type_sig);
10726 gdb_assert (type_sig->per_cu.cu != NULL);
10729 /* Read in a signatured type and build its CU and DIEs. */
10732 read_signatured_type (struct objfile *objfile,
10733 struct signatured_type *type_sig)
10735 gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
10736 struct die_reader_specs reader_specs;
10737 struct dwarf2_cu *cu;
10738 ULONGEST signature;
10739 struct cleanup *back_to, *free_cu_cleanup;
10740 struct attribute *attr;
10742 gdb_assert (type_sig->per_cu.cu == NULL);
10744 cu = xmalloc (sizeof (struct dwarf2_cu));
10745 memset (cu, 0, sizeof (struct dwarf2_cu));
10746 obstack_init (&cu->comp_unit_obstack);
10747 cu->objfile = objfile;
10748 type_sig->per_cu.cu = cu;
10749 cu->per_cu = &type_sig->per_cu;
10751 /* If an error occurs while loading, release our storage. */
10752 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
10754 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
10755 types_ptr, objfile->obfd);
10756 gdb_assert (signature == type_sig->signature);
10759 = htab_create_alloc_ex (cu->header.length / 12,
10763 &cu->comp_unit_obstack,
10764 hashtab_obstack_allocate,
10765 dummy_obstack_deallocate);
10767 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
10768 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
10770 init_cu_die_reader (&reader_specs, cu);
10772 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
10775 /* We try not to read any attributes in this function, because not
10776 all objfiles needed for references have been loaded yet, and symbol
10777 table processing isn't initialized. But we have to set the CU language,
10778 or we won't be able to build types correctly. */
10779 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
10781 set_cu_language (DW_UNSND (attr), cu);
10783 set_cu_language (language_minimal, cu);
10785 do_cleanups (back_to);
10787 /* We've successfully allocated this compilation unit. Let our caller
10788 clean it up when finished with it. */
10789 discard_cleanups (free_cu_cleanup);
10791 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
10792 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
10795 /* Decode simple location descriptions.
10796 Given a pointer to a dwarf block that defines a location, compute
10797 the location and return the value.
10799 NOTE drow/2003-11-18: This function is called in two situations
10800 now: for the address of static or global variables (partial symbols
10801 only) and for offsets into structures which are expected to be
10802 (more or less) constant. The partial symbol case should go away,
10803 and only the constant case should remain. That will let this
10804 function complain more accurately. A few special modes are allowed
10805 without complaint for global variables (for instance, global
10806 register values and thread-local values).
10808 A location description containing no operations indicates that the
10809 object is optimized out. The return value is 0 for that case.
10810 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10811 callers will only want a very basic result and this can become a
10814 Note that stack[0] is unused except as a default error return.
10815 Note that stack overflow is not yet handled. */
10818 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
10820 struct objfile *objfile = cu->objfile;
10821 struct comp_unit_head *cu_header = &cu->header;
10823 int size = blk->size;
10824 gdb_byte *data = blk->data;
10825 CORE_ADDR stack[64];
10827 unsigned int bytes_read, unsnd;
10871 stack[++stacki] = op - DW_OP_lit0;
10906 stack[++stacki] = op - DW_OP_reg0;
10908 dwarf2_complex_location_expr_complaint ();
10912 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
10914 stack[++stacki] = unsnd;
10916 dwarf2_complex_location_expr_complaint ();
10920 stack[++stacki] = read_address (objfile->obfd, &data[i],
10925 case DW_OP_const1u:
10926 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
10930 case DW_OP_const1s:
10931 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
10935 case DW_OP_const2u:
10936 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
10940 case DW_OP_const2s:
10941 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
10945 case DW_OP_const4u:
10946 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
10950 case DW_OP_const4s:
10951 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
10956 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
10962 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
10967 stack[stacki + 1] = stack[stacki];
10972 stack[stacki - 1] += stack[stacki];
10976 case DW_OP_plus_uconst:
10977 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
10982 stack[stacki - 1] -= stack[stacki];
10987 /* If we're not the last op, then we definitely can't encode
10988 this using GDB's address_class enum. This is valid for partial
10989 global symbols, although the variable's address will be bogus
10992 dwarf2_complex_location_expr_complaint ();
10995 case DW_OP_GNU_push_tls_address:
10996 /* The top of the stack has the offset from the beginning
10997 of the thread control block at which the variable is located. */
10998 /* Nothing should follow this operator, so the top of stack would
11000 /* This is valid for partial global symbols, but the variable's
11001 address will be bogus in the psymtab. */
11003 dwarf2_complex_location_expr_complaint ();
11006 case DW_OP_GNU_uninit:
11010 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
11011 dwarf_stack_op_name (op));
11012 return (stack[stacki]);
11015 return (stack[stacki]);
11018 /* memory allocation interface */
11020 static struct dwarf_block *
11021 dwarf_alloc_block (struct dwarf2_cu *cu)
11023 struct dwarf_block *blk;
11025 blk = (struct dwarf_block *)
11026 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
11030 static struct abbrev_info *
11031 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
11033 struct abbrev_info *abbrev;
11035 abbrev = (struct abbrev_info *)
11036 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
11037 memset (abbrev, 0, sizeof (struct abbrev_info));
11041 static struct die_info *
11042 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
11044 struct die_info *die;
11045 size_t size = sizeof (struct die_info);
11048 size += (num_attrs - 1) * sizeof (struct attribute);
11050 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
11051 memset (die, 0, sizeof (struct die_info));
11056 /* Macro support. */
11059 /* Return the full name of file number I in *LH's file name table.
11060 Use COMP_DIR as the name of the current directory of the
11061 compilation. The result is allocated using xmalloc; the caller is
11062 responsible for freeing it. */
11064 file_full_name (int file, struct line_header *lh, const char *comp_dir)
11066 /* Is the file number a valid index into the line header's file name
11067 table? Remember that file numbers start with one, not zero. */
11068 if (1 <= file && file <= lh->num_file_names)
11070 struct file_entry *fe = &lh->file_names[file - 1];
11072 if (IS_ABSOLUTE_PATH (fe->name))
11073 return xstrdup (fe->name);
11081 dir = lh->include_dirs[fe->dir_index - 1];
11087 dir_len = strlen (dir);
11088 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
11089 strcpy (full_name, dir);
11090 full_name[dir_len] = '/';
11091 strcpy (full_name + dir_len + 1, fe->name);
11095 return xstrdup (fe->name);
11100 /* The compiler produced a bogus file number. We can at least
11101 record the macro definitions made in the file, even if we
11102 won't be able to find the file by name. */
11103 char fake_name[80];
11104 sprintf (fake_name, "<bad macro file number %d>", file);
11106 complaint (&symfile_complaints,
11107 _("bad file number in macro information (%d)"),
11110 return xstrdup (fake_name);
11115 static struct macro_source_file *
11116 macro_start_file (int file, int line,
11117 struct macro_source_file *current_file,
11118 const char *comp_dir,
11119 struct line_header *lh, struct objfile *objfile)
11121 /* The full name of this source file. */
11122 char *full_name = file_full_name (file, lh, comp_dir);
11124 /* We don't create a macro table for this compilation unit
11125 at all until we actually get a filename. */
11126 if (! pending_macros)
11127 pending_macros = new_macro_table (&objfile->objfile_obstack,
11128 objfile->macro_cache);
11130 if (! current_file)
11131 /* If we have no current file, then this must be the start_file
11132 directive for the compilation unit's main source file. */
11133 current_file = macro_set_main (pending_macros, full_name);
11135 current_file = macro_include (current_file, line, full_name);
11139 return current_file;
11143 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11144 followed by a null byte. */
11146 copy_string (const char *buf, int len)
11148 char *s = xmalloc (len + 1);
11149 memcpy (s, buf, len);
11156 static const char *
11157 consume_improper_spaces (const char *p, const char *body)
11161 complaint (&symfile_complaints,
11162 _("macro definition contains spaces in formal argument list:\n`%s'"),
11174 parse_macro_definition (struct macro_source_file *file, int line,
11179 /* The body string takes one of two forms. For object-like macro
11180 definitions, it should be:
11182 <macro name> " " <definition>
11184 For function-like macro definitions, it should be:
11186 <macro name> "() " <definition>
11188 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11190 Spaces may appear only where explicitly indicated, and in the
11193 The Dwarf 2 spec says that an object-like macro's name is always
11194 followed by a space, but versions of GCC around March 2002 omit
11195 the space when the macro's definition is the empty string.
11197 The Dwarf 2 spec says that there should be no spaces between the
11198 formal arguments in a function-like macro's formal argument list,
11199 but versions of GCC around March 2002 include spaces after the
11203 /* Find the extent of the macro name. The macro name is terminated
11204 by either a space or null character (for an object-like macro) or
11205 an opening paren (for a function-like macro). */
11206 for (p = body; *p; p++)
11207 if (*p == ' ' || *p == '(')
11210 if (*p == ' ' || *p == '\0')
11212 /* It's an object-like macro. */
11213 int name_len = p - body;
11214 char *name = copy_string (body, name_len);
11215 const char *replacement;
11218 replacement = body + name_len + 1;
11221 dwarf2_macro_malformed_definition_complaint (body);
11222 replacement = body + name_len;
11225 macro_define_object (file, line, name, replacement);
11229 else if (*p == '(')
11231 /* It's a function-like macro. */
11232 char *name = copy_string (body, p - body);
11235 char **argv = xmalloc (argv_size * sizeof (*argv));
11239 p = consume_improper_spaces (p, body);
11241 /* Parse the formal argument list. */
11242 while (*p && *p != ')')
11244 /* Find the extent of the current argument name. */
11245 const char *arg_start = p;
11247 while (*p && *p != ',' && *p != ')' && *p != ' ')
11250 if (! *p || p == arg_start)
11251 dwarf2_macro_malformed_definition_complaint (body);
11254 /* Make sure argv has room for the new argument. */
11255 if (argc >= argv_size)
11258 argv = xrealloc (argv, argv_size * sizeof (*argv));
11261 argv[argc++] = copy_string (arg_start, p - arg_start);
11264 p = consume_improper_spaces (p, body);
11266 /* Consume the comma, if present. */
11271 p = consume_improper_spaces (p, body);
11280 /* Perfectly formed definition, no complaints. */
11281 macro_define_function (file, line, name,
11282 argc, (const char **) argv,
11284 else if (*p == '\0')
11286 /* Complain, but do define it. */
11287 dwarf2_macro_malformed_definition_complaint (body);
11288 macro_define_function (file, line, name,
11289 argc, (const char **) argv,
11293 /* Just complain. */
11294 dwarf2_macro_malformed_definition_complaint (body);
11297 /* Just complain. */
11298 dwarf2_macro_malformed_definition_complaint (body);
11304 for (i = 0; i < argc; i++)
11310 dwarf2_macro_malformed_definition_complaint (body);
11315 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
11316 char *comp_dir, bfd *abfd,
11317 struct dwarf2_cu *cu)
11319 gdb_byte *mac_ptr, *mac_end;
11320 struct macro_source_file *current_file = 0;
11321 enum dwarf_macinfo_record_type macinfo_type;
11322 int at_commandline;
11324 dwarf2_read_section (dwarf2_per_objfile->objfile,
11325 &dwarf2_per_objfile->macinfo);
11326 if (dwarf2_per_objfile->macinfo.buffer == NULL)
11328 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
11332 /* First pass: Find the name of the base filename.
11333 This filename is needed in order to process all macros whose definition
11334 (or undefinition) comes from the command line. These macros are defined
11335 before the first DW_MACINFO_start_file entry, and yet still need to be
11336 associated to the base file.
11338 To determine the base file name, we scan the macro definitions until we
11339 reach the first DW_MACINFO_start_file entry. We then initialize
11340 CURRENT_FILE accordingly so that any macro definition found before the
11341 first DW_MACINFO_start_file can still be associated to the base file. */
11343 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11344 mac_end = dwarf2_per_objfile->macinfo.buffer
11345 + dwarf2_per_objfile->macinfo.size;
11349 /* Do we at least have room for a macinfo type byte? */
11350 if (mac_ptr >= mac_end)
11352 /* Complaint is printed during the second pass as GDB will probably
11353 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11357 macinfo_type = read_1_byte (abfd, mac_ptr);
11360 switch (macinfo_type)
11362 /* A zero macinfo type indicates the end of the macro
11367 case DW_MACINFO_define:
11368 case DW_MACINFO_undef:
11369 /* Only skip the data by MAC_PTR. */
11371 unsigned int bytes_read;
11373 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11374 mac_ptr += bytes_read;
11375 read_string (abfd, mac_ptr, &bytes_read);
11376 mac_ptr += bytes_read;
11380 case DW_MACINFO_start_file:
11382 unsigned int bytes_read;
11385 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11386 mac_ptr += bytes_read;
11387 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11388 mac_ptr += bytes_read;
11390 current_file = macro_start_file (file, line, current_file, comp_dir,
11395 case DW_MACINFO_end_file:
11396 /* No data to skip by MAC_PTR. */
11399 case DW_MACINFO_vendor_ext:
11400 /* Only skip the data by MAC_PTR. */
11402 unsigned int bytes_read;
11404 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11405 mac_ptr += bytes_read;
11406 read_string (abfd, mac_ptr, &bytes_read);
11407 mac_ptr += bytes_read;
11414 } while (macinfo_type != 0 && current_file == NULL);
11416 /* Second pass: Process all entries.
11418 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11419 command-line macro definitions/undefinitions. This flag is unset when we
11420 reach the first DW_MACINFO_start_file entry. */
11422 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11424 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11425 GDB is still reading the definitions from command line. First
11426 DW_MACINFO_start_file will need to be ignored as it was already executed
11427 to create CURRENT_FILE for the main source holding also the command line
11428 definitions. On first met DW_MACINFO_start_file this flag is reset to
11429 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11431 at_commandline = 1;
11435 /* Do we at least have room for a macinfo type byte? */
11436 if (mac_ptr >= mac_end)
11438 dwarf2_macros_too_long_complaint ();
11442 macinfo_type = read_1_byte (abfd, mac_ptr);
11445 switch (macinfo_type)
11447 /* A zero macinfo type indicates the end of the macro
11452 case DW_MACINFO_define:
11453 case DW_MACINFO_undef:
11455 unsigned int bytes_read;
11459 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11460 mac_ptr += bytes_read;
11461 body = read_string (abfd, mac_ptr, &bytes_read);
11462 mac_ptr += bytes_read;
11464 if (! current_file)
11466 /* DWARF violation as no main source is present. */
11467 complaint (&symfile_complaints,
11468 _("debug info with no main source gives macro %s "
11470 macinfo_type == DW_MACINFO_define ?
11472 macinfo_type == DW_MACINFO_undef ?
11473 _("undefinition") :
11474 _("something-or-other"), line, body);
11477 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11478 complaint (&symfile_complaints,
11479 _("debug info gives %s macro %s with %s line %d: %s"),
11480 at_commandline ? _("command-line") : _("in-file"),
11481 macinfo_type == DW_MACINFO_define ?
11483 macinfo_type == DW_MACINFO_undef ?
11484 _("undefinition") :
11485 _("something-or-other"),
11486 line == 0 ? _("zero") : _("non-zero"), line, body);
11488 if (macinfo_type == DW_MACINFO_define)
11489 parse_macro_definition (current_file, line, body);
11490 else if (macinfo_type == DW_MACINFO_undef)
11491 macro_undef (current_file, line, body);
11495 case DW_MACINFO_start_file:
11497 unsigned int bytes_read;
11500 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11501 mac_ptr += bytes_read;
11502 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11503 mac_ptr += bytes_read;
11505 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11506 complaint (&symfile_complaints,
11507 _("debug info gives source %d included "
11508 "from %s at %s line %d"),
11509 file, at_commandline ? _("command-line") : _("file"),
11510 line == 0 ? _("zero") : _("non-zero"), line);
11512 if (at_commandline)
11514 /* This DW_MACINFO_start_file was executed in the pass one. */
11515 at_commandline = 0;
11518 current_file = macro_start_file (file, line,
11519 current_file, comp_dir,
11524 case DW_MACINFO_end_file:
11525 if (! current_file)
11526 complaint (&symfile_complaints,
11527 _("macro debug info has an unmatched `close_file' directive"));
11530 current_file = current_file->included_by;
11531 if (! current_file)
11533 enum dwarf_macinfo_record_type next_type;
11535 /* GCC circa March 2002 doesn't produce the zero
11536 type byte marking the end of the compilation
11537 unit. Complain if it's not there, but exit no
11540 /* Do we at least have room for a macinfo type byte? */
11541 if (mac_ptr >= mac_end)
11543 dwarf2_macros_too_long_complaint ();
11547 /* We don't increment mac_ptr here, so this is just
11549 next_type = read_1_byte (abfd, mac_ptr);
11550 if (next_type != 0)
11551 complaint (&symfile_complaints,
11552 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11559 case DW_MACINFO_vendor_ext:
11561 unsigned int bytes_read;
11565 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11566 mac_ptr += bytes_read;
11567 string = read_string (abfd, mac_ptr, &bytes_read);
11568 mac_ptr += bytes_read;
11570 /* We don't recognize any vendor extensions. */
11574 } while (macinfo_type != 0);
11577 /* Check if the attribute's form is a DW_FORM_block*
11578 if so return true else false. */
11580 attr_form_is_block (struct attribute *attr)
11582 return (attr == NULL ? 0 :
11583 attr->form == DW_FORM_block1
11584 || attr->form == DW_FORM_block2
11585 || attr->form == DW_FORM_block4
11586 || attr->form == DW_FORM_block
11587 || attr->form == DW_FORM_exprloc);
11590 /* Return non-zero if ATTR's value is a section offset --- classes
11591 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11592 You may use DW_UNSND (attr) to retrieve such offsets.
11594 Section 7.5.4, "Attribute Encodings", explains that no attribute
11595 may have a value that belongs to more than one of these classes; it
11596 would be ambiguous if we did, because we use the same forms for all
11599 attr_form_is_section_offset (struct attribute *attr)
11601 return (attr->form == DW_FORM_data4
11602 || attr->form == DW_FORM_data8
11603 || attr->form == DW_FORM_sec_offset);
11607 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11608 zero otherwise. When this function returns true, you can apply
11609 dwarf2_get_attr_constant_value to it.
11611 However, note that for some attributes you must check
11612 attr_form_is_section_offset before using this test. DW_FORM_data4
11613 and DW_FORM_data8 are members of both the constant class, and of
11614 the classes that contain offsets into other debug sections
11615 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11616 that, if an attribute's can be either a constant or one of the
11617 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11618 taken as section offsets, not constants. */
11620 attr_form_is_constant (struct attribute *attr)
11622 switch (attr->form)
11624 case DW_FORM_sdata:
11625 case DW_FORM_udata:
11626 case DW_FORM_data1:
11627 case DW_FORM_data2:
11628 case DW_FORM_data4:
11629 case DW_FORM_data8:
11637 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
11638 struct dwarf2_cu *cu)
11640 if (attr_form_is_section_offset (attr)
11641 /* ".debug_loc" may not exist at all, or the offset may be outside
11642 the section. If so, fall through to the complaint in the
11644 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
11646 struct dwarf2_loclist_baton *baton;
11648 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11649 sizeof (struct dwarf2_loclist_baton));
11650 baton->per_cu = cu->per_cu;
11651 gdb_assert (baton->per_cu);
11653 dwarf2_read_section (dwarf2_per_objfile->objfile,
11654 &dwarf2_per_objfile->loc);
11656 /* We don't know how long the location list is, but make sure we
11657 don't run off the edge of the section. */
11658 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
11659 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
11660 baton->base_address = cu->base_address;
11661 if (cu->base_known == 0)
11662 complaint (&symfile_complaints,
11663 _("Location list used without specifying the CU base address."));
11665 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
11666 SYMBOL_LOCATION_BATON (sym) = baton;
11670 struct dwarf2_locexpr_baton *baton;
11672 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11673 sizeof (struct dwarf2_locexpr_baton));
11674 baton->per_cu = cu->per_cu;
11675 gdb_assert (baton->per_cu);
11677 if (attr_form_is_block (attr))
11679 /* Note that we're just copying the block's data pointer
11680 here, not the actual data. We're still pointing into the
11681 info_buffer for SYM's objfile; right now we never release
11682 that buffer, but when we do clean up properly this may
11684 baton->size = DW_BLOCK (attr)->size;
11685 baton->data = DW_BLOCK (attr)->data;
11689 dwarf2_invalid_attrib_class_complaint ("location description",
11690 SYMBOL_NATURAL_NAME (sym));
11692 baton->data = NULL;
11695 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11696 SYMBOL_LOCATION_BATON (sym) = baton;
11700 /* Return the OBJFILE associated with the compilation unit CU. */
11703 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
11705 struct objfile *objfile = per_cu->psymtab->objfile;
11707 /* Return the master objfile, so that we can report and look up the
11708 correct file containing this variable. */
11709 if (objfile->separate_debug_objfile_backlink)
11710 objfile = objfile->separate_debug_objfile_backlink;
11715 /* Return the address size given in the compilation unit header for CU. */
11718 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
11721 return per_cu->cu->header.addr_size;
11724 /* If the CU is not currently read in, we re-read its header. */
11725 struct objfile *objfile = per_cu->psymtab->objfile;
11726 struct dwarf2_per_objfile *per_objfile
11727 = objfile_data (objfile, dwarf2_objfile_data_key);
11728 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
11730 struct comp_unit_head cu_header;
11731 memset (&cu_header, 0, sizeof cu_header);
11732 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
11733 return cu_header.addr_size;
11737 /* Locate the .debug_info compilation unit from CU's objfile which contains
11738 the DIE at OFFSET. Raises an error on failure. */
11740 static struct dwarf2_per_cu_data *
11741 dwarf2_find_containing_comp_unit (unsigned int offset,
11742 struct objfile *objfile)
11744 struct dwarf2_per_cu_data *this_cu;
11748 high = dwarf2_per_objfile->n_comp_units - 1;
11751 int mid = low + (high - low) / 2;
11752 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
11757 gdb_assert (low == high);
11758 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
11761 error (_("Dwarf Error: could not find partial DIE containing "
11762 "offset 0x%lx [in module %s]"),
11763 (long) offset, bfd_get_filename (objfile->obfd));
11765 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
11766 return dwarf2_per_objfile->all_comp_units[low-1];
11770 this_cu = dwarf2_per_objfile->all_comp_units[low];
11771 if (low == dwarf2_per_objfile->n_comp_units - 1
11772 && offset >= this_cu->offset + this_cu->length)
11773 error (_("invalid dwarf2 offset %u"), offset);
11774 gdb_assert (offset < this_cu->offset + this_cu->length);
11779 /* Locate the compilation unit from OBJFILE which is located at exactly
11780 OFFSET. Raises an error on failure. */
11782 static struct dwarf2_per_cu_data *
11783 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
11785 struct dwarf2_per_cu_data *this_cu;
11786 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
11787 if (this_cu->offset != offset)
11788 error (_("no compilation unit with offset %u."), offset);
11792 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11794 static struct dwarf2_cu *
11795 alloc_one_comp_unit (struct objfile *objfile)
11797 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
11798 cu->objfile = objfile;
11799 obstack_init (&cu->comp_unit_obstack);
11803 /* Release one cached compilation unit, CU. We unlink it from the tree
11804 of compilation units, but we don't remove it from the read_in_chain;
11805 the caller is responsible for that.
11806 NOTE: DATA is a void * because this function is also used as a
11807 cleanup routine. */
11810 free_one_comp_unit (void *data)
11812 struct dwarf2_cu *cu = data;
11814 if (cu->per_cu != NULL)
11815 cu->per_cu->cu = NULL;
11818 obstack_free (&cu->comp_unit_obstack, NULL);
11823 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11824 when we're finished with it. We can't free the pointer itself, but be
11825 sure to unlink it from the cache. Also release any associated storage
11826 and perform cache maintenance.
11828 Only used during partial symbol parsing. */
11831 free_stack_comp_unit (void *data)
11833 struct dwarf2_cu *cu = data;
11835 obstack_free (&cu->comp_unit_obstack, NULL);
11836 cu->partial_dies = NULL;
11838 if (cu->per_cu != NULL)
11840 /* This compilation unit is on the stack in our caller, so we
11841 should not xfree it. Just unlink it. */
11842 cu->per_cu->cu = NULL;
11845 /* If we had a per-cu pointer, then we may have other compilation
11846 units loaded, so age them now. */
11847 age_cached_comp_units ();
11851 /* Free all cached compilation units. */
11854 free_cached_comp_units (void *data)
11856 struct dwarf2_per_cu_data *per_cu, **last_chain;
11858 per_cu = dwarf2_per_objfile->read_in_chain;
11859 last_chain = &dwarf2_per_objfile->read_in_chain;
11860 while (per_cu != NULL)
11862 struct dwarf2_per_cu_data *next_cu;
11864 next_cu = per_cu->cu->read_in_chain;
11866 free_one_comp_unit (per_cu->cu);
11867 *last_chain = next_cu;
11873 /* Increase the age counter on each cached compilation unit, and free
11874 any that are too old. */
11877 age_cached_comp_units (void)
11879 struct dwarf2_per_cu_data *per_cu, **last_chain;
11881 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
11882 per_cu = dwarf2_per_objfile->read_in_chain;
11883 while (per_cu != NULL)
11885 per_cu->cu->last_used ++;
11886 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
11887 dwarf2_mark (per_cu->cu);
11888 per_cu = per_cu->cu->read_in_chain;
11891 per_cu = dwarf2_per_objfile->read_in_chain;
11892 last_chain = &dwarf2_per_objfile->read_in_chain;
11893 while (per_cu != NULL)
11895 struct dwarf2_per_cu_data *next_cu;
11897 next_cu = per_cu->cu->read_in_chain;
11899 if (!per_cu->cu->mark)
11901 free_one_comp_unit (per_cu->cu);
11902 *last_chain = next_cu;
11905 last_chain = &per_cu->cu->read_in_chain;
11911 /* Remove a single compilation unit from the cache. */
11914 free_one_cached_comp_unit (void *target_cu)
11916 struct dwarf2_per_cu_data *per_cu, **last_chain;
11918 per_cu = dwarf2_per_objfile->read_in_chain;
11919 last_chain = &dwarf2_per_objfile->read_in_chain;
11920 while (per_cu != NULL)
11922 struct dwarf2_per_cu_data *next_cu;
11924 next_cu = per_cu->cu->read_in_chain;
11926 if (per_cu->cu == target_cu)
11928 free_one_comp_unit (per_cu->cu);
11929 *last_chain = next_cu;
11933 last_chain = &per_cu->cu->read_in_chain;
11939 /* Release all extra memory associated with OBJFILE. */
11942 dwarf2_free_objfile (struct objfile *objfile)
11944 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
11946 if (dwarf2_per_objfile == NULL)
11949 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11950 free_cached_comp_units (NULL);
11952 /* Everything else should be on the objfile obstack. */
11955 /* A pair of DIE offset and GDB type pointer. We store these
11956 in a hash table separate from the DIEs, and preserve them
11957 when the DIEs are flushed out of cache. */
11959 struct dwarf2_offset_and_type
11961 unsigned int offset;
11965 /* Hash function for a dwarf2_offset_and_type. */
11968 offset_and_type_hash (const void *item)
11970 const struct dwarf2_offset_and_type *ofs = item;
11971 return ofs->offset;
11974 /* Equality function for a dwarf2_offset_and_type. */
11977 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
11979 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
11980 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
11981 return ofs_lhs->offset == ofs_rhs->offset;
11984 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11985 table if necessary. For convenience, return TYPE. */
11987 static struct type *
11988 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11990 struct dwarf2_offset_and_type **slot, ofs;
11992 /* For Ada types, make sure that the gnat-specific data is always
11993 initialized (if not already set). There are a few types where
11994 we should not be doing so, because the type-specific area is
11995 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11996 where the type-specific area is used to store the floatformat).
11997 But this is not a problem, because the gnat-specific information
11998 is actually not needed for these types. */
11999 if (need_gnat_info (cu)
12000 && TYPE_CODE (type) != TYPE_CODE_FUNC
12001 && TYPE_CODE (type) != TYPE_CODE_FLT
12002 && !HAVE_GNAT_AUX_INFO (type))
12003 INIT_GNAT_SPECIFIC (type);
12005 if (cu->type_hash == NULL)
12007 gdb_assert (cu->per_cu != NULL);
12008 cu->per_cu->type_hash
12009 = htab_create_alloc_ex (cu->header.length / 24,
12010 offset_and_type_hash,
12011 offset_and_type_eq,
12013 &cu->objfile->objfile_obstack,
12014 hashtab_obstack_allocate,
12015 dummy_obstack_deallocate);
12016 cu->type_hash = cu->per_cu->type_hash;
12019 ofs.offset = die->offset;
12021 slot = (struct dwarf2_offset_and_type **)
12022 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
12023 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
12028 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
12029 not have a saved type. */
12031 static struct type *
12032 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
12034 struct dwarf2_offset_and_type *slot, ofs;
12035 htab_t type_hash = cu->type_hash;
12037 if (type_hash == NULL)
12040 ofs.offset = die->offset;
12041 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
12048 /* Add a dependence relationship from CU to REF_PER_CU. */
12051 dwarf2_add_dependence (struct dwarf2_cu *cu,
12052 struct dwarf2_per_cu_data *ref_per_cu)
12056 if (cu->dependencies == NULL)
12058 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
12059 NULL, &cu->comp_unit_obstack,
12060 hashtab_obstack_allocate,
12061 dummy_obstack_deallocate);
12063 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
12065 *slot = ref_per_cu;
12068 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12069 Set the mark field in every compilation unit in the
12070 cache that we must keep because we are keeping CU. */
12073 dwarf2_mark_helper (void **slot, void *data)
12075 struct dwarf2_per_cu_data *per_cu;
12077 per_cu = (struct dwarf2_per_cu_data *) *slot;
12078 if (per_cu->cu->mark)
12080 per_cu->cu->mark = 1;
12082 if (per_cu->cu->dependencies != NULL)
12083 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
12088 /* Set the mark field in CU and in every other compilation unit in the
12089 cache that we must keep because we are keeping CU. */
12092 dwarf2_mark (struct dwarf2_cu *cu)
12097 if (cu->dependencies != NULL)
12098 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
12102 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
12106 per_cu->cu->mark = 0;
12107 per_cu = per_cu->cu->read_in_chain;
12111 /* Trivial hash function for partial_die_info: the hash value of a DIE
12112 is its offset in .debug_info for this objfile. */
12115 partial_die_hash (const void *item)
12117 const struct partial_die_info *part_die = item;
12118 return part_die->offset;
12121 /* Trivial comparison function for partial_die_info structures: two DIEs
12122 are equal if they have the same offset. */
12125 partial_die_eq (const void *item_lhs, const void *item_rhs)
12127 const struct partial_die_info *part_die_lhs = item_lhs;
12128 const struct partial_die_info *part_die_rhs = item_rhs;
12129 return part_die_lhs->offset == part_die_rhs->offset;
12132 static struct cmd_list_element *set_dwarf2_cmdlist;
12133 static struct cmd_list_element *show_dwarf2_cmdlist;
12136 set_dwarf2_cmd (char *args, int from_tty)
12138 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
12142 show_dwarf2_cmd (char *args, int from_tty)
12144 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
12147 /* If section described by INFO was mmapped, munmap it now. */
12150 munmap_section_buffer (struct dwarf2_section_info *info)
12152 if (info->was_mmapped)
12155 intptr_t begin = (intptr_t) info->buffer;
12156 intptr_t map_begin = begin & ~(pagesize - 1);
12157 size_t map_length = info->size + begin - map_begin;
12158 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
12160 /* Without HAVE_MMAP, we should never be here to begin with. */
12166 /* munmap debug sections for OBJFILE, if necessary. */
12169 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
12171 struct dwarf2_per_objfile *data = d;
12172 munmap_section_buffer (&data->info);
12173 munmap_section_buffer (&data->abbrev);
12174 munmap_section_buffer (&data->line);
12175 munmap_section_buffer (&data->str);
12176 munmap_section_buffer (&data->macinfo);
12177 munmap_section_buffer (&data->ranges);
12178 munmap_section_buffer (&data->loc);
12179 munmap_section_buffer (&data->frame);
12180 munmap_section_buffer (&data->eh_frame);
12183 void _initialize_dwarf2_read (void);
12186 _initialize_dwarf2_read (void)
12188 dwarf2_objfile_data_key
12189 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
12191 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
12192 Set DWARF 2 specific variables.\n\
12193 Configure DWARF 2 variables such as the cache size"),
12194 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
12195 0/*allow-unknown*/, &maintenance_set_cmdlist);
12197 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
12198 Show DWARF 2 specific variables\n\
12199 Show DWARF 2 variables such as the cache size"),
12200 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
12201 0/*allow-unknown*/, &maintenance_show_cmdlist);
12203 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
12204 &dwarf2_max_cache_age, _("\
12205 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12206 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12207 A higher limit means that cached compilation units will be stored\n\
12208 in memory longer, and more total memory will be used. Zero disables\n\
12209 caching, which can slow down startup."),
12211 show_dwarf2_max_cache_age,
12212 &set_dwarf2_cmdlist,
12213 &show_dwarf2_cmdlist);
12215 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
12216 Set debugging of the dwarf2 DIE reader."), _("\
12217 Show debugging of the dwarf2 DIE reader."), _("\
12218 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12219 The value is the maximum depth to print."),
12222 &setdebuglist, &showdebuglist);