1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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"
53 #include "gdb_string.h"
54 #include "gdb_assert.h"
55 #include <sys/types.h>
64 /* .debug_info header for a compilation unit
65 Because of alignment constraints, this structure has padding and cannot
66 be mapped directly onto the beginning of the .debug_info section. */
67 typedef struct comp_unit_header
69 unsigned int length; /* length of the .debug_info
71 unsigned short version; /* version number -- 2 for DWARF
73 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
74 unsigned char addr_size; /* byte size of an address -- 4 */
77 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
80 /* .debug_pubnames header
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct pubnames_header
85 unsigned int length; /* length of the .debug_pubnames
87 unsigned char version; /* version number -- 2 for DWARF
89 unsigned int info_offset; /* offset into .debug_info section */
90 unsigned int info_size; /* byte size of .debug_info section
94 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
96 /* .debug_pubnames header
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct aranges_header
101 unsigned int length; /* byte len of the .debug_aranges
103 unsigned short version; /* version number -- 2 for DWARF
105 unsigned int info_offset; /* offset into .debug_info section */
106 unsigned char addr_size; /* byte size of an address */
107 unsigned char seg_size; /* byte size of segment descriptor */
110 #define _ACTUAL_ARANGES_HEADER_SIZE 12
112 /* .debug_line statement program prologue
113 Because of alignment constraints, this structure has padding and cannot
114 be mapped directly onto the beginning of the .debug_info section. */
115 typedef struct statement_prologue
117 unsigned int total_length; /* byte length of the statement
119 unsigned short version; /* version number -- 2 for DWARF
121 unsigned int prologue_length; /* # bytes between prologue &
123 unsigned char minimum_instruction_length; /* byte size of
125 unsigned char default_is_stmt; /* initial value of is_stmt
128 unsigned char line_range;
129 unsigned char opcode_base; /* number assigned to first special
131 unsigned char *standard_opcode_lengths;
135 /* When non-zero, dump DIEs after they are read in. */
136 static int dwarf2_die_debug = 0;
140 /* When set, the file that we're processing is known to have debugging
141 info for C++ namespaces. GCC 3.3.x did not produce this information,
142 but later versions do. */
144 static int processing_has_namespace_info;
146 static const struct objfile_data *dwarf2_objfile_data_key;
148 struct dwarf2_section_info
156 struct dwarf2_per_objfile
158 struct dwarf2_section_info info;
159 struct dwarf2_section_info abbrev;
160 struct dwarf2_section_info line;
161 struct dwarf2_section_info pubnames;
162 struct dwarf2_section_info aranges;
163 struct dwarf2_section_info loc;
164 struct dwarf2_section_info macinfo;
165 struct dwarf2_section_info str;
166 struct dwarf2_section_info ranges;
167 struct dwarf2_section_info types;
168 struct dwarf2_section_info frame;
169 struct dwarf2_section_info eh_frame;
171 /* A list of all the compilation units. This is used to locate
172 the target compilation unit of a particular reference. */
173 struct dwarf2_per_cu_data **all_comp_units;
175 /* The number of compilation units in ALL_COMP_UNITS. */
178 /* A chain of compilation units that are currently read in, so that
179 they can be freed later. */
180 struct dwarf2_per_cu_data *read_in_chain;
182 /* A table mapping .debug_types signatures to its signatured_type entry.
183 This is NULL if the .debug_types section hasn't been read in yet. */
184 htab_t signatured_types;
186 /* A flag indicating wether this objfile has a section loaded at a
188 int has_section_at_zero;
191 static struct dwarf2_per_objfile *dwarf2_per_objfile;
193 /* names of the debugging sections */
195 /* Note that if the debugging section has been compressed, it might
196 have a name like .zdebug_info. */
198 #define INFO_SECTION "debug_info"
199 #define ABBREV_SECTION "debug_abbrev"
200 #define LINE_SECTION "debug_line"
201 #define PUBNAMES_SECTION "debug_pubnames"
202 #define ARANGES_SECTION "debug_aranges"
203 #define LOC_SECTION "debug_loc"
204 #define MACINFO_SECTION "debug_macinfo"
205 #define STR_SECTION "debug_str"
206 #define RANGES_SECTION "debug_ranges"
207 #define TYPES_SECTION "debug_types"
208 #define FRAME_SECTION "debug_frame"
209 #define EH_FRAME_SECTION "eh_frame"
211 /* local data types */
213 /* We hold several abbreviation tables in memory at the same time. */
214 #ifndef ABBREV_HASH_SIZE
215 #define ABBREV_HASH_SIZE 121
218 /* The data in a compilation unit header, after target2host
219 translation, looks like this. */
220 struct comp_unit_head
224 unsigned char addr_size;
225 unsigned char signed_addr_p;
226 unsigned int abbrev_offset;
228 /* Size of file offsets; either 4 or 8. */
229 unsigned int offset_size;
231 /* Size of the length field; either 4 or 12. */
232 unsigned int initial_length_size;
234 /* Offset to the first byte of this compilation unit header in the
235 .debug_info section, for resolving relative reference dies. */
238 /* Offset to first die in this cu from the start of the cu.
239 This will be the first byte following the compilation unit header. */
240 unsigned int first_die_offset;
243 /* Internal state when decoding a particular compilation unit. */
246 /* The objfile containing this compilation unit. */
247 struct objfile *objfile;
249 /* The header of the compilation unit. */
250 struct comp_unit_head header;
252 /* Base address of this compilation unit. */
253 CORE_ADDR base_address;
255 /* Non-zero if base_address has been set. */
258 struct function_range *first_fn, *last_fn, *cached_fn;
260 /* The language we are debugging. */
261 enum language language;
262 const struct language_defn *language_defn;
264 const char *producer;
266 /* The generic symbol table building routines have separate lists for
267 file scope symbols and all all other scopes (local scopes). So
268 we need to select the right one to pass to add_symbol_to_list().
269 We do it by keeping a pointer to the correct list in list_in_scope.
271 FIXME: The original dwarf code just treated the file scope as the
272 first local scope, and all other local scopes as nested local
273 scopes, and worked fine. Check to see if we really need to
274 distinguish these in buildsym.c. */
275 struct pending **list_in_scope;
277 /* DWARF abbreviation table associated with this compilation unit. */
278 struct abbrev_info **dwarf2_abbrevs;
280 /* Storage for the abbrev table. */
281 struct obstack abbrev_obstack;
283 /* Hash table holding all the loaded partial DIEs. */
286 /* Storage for things with the same lifetime as this read-in compilation
287 unit, including partial DIEs. */
288 struct obstack comp_unit_obstack;
290 /* When multiple dwarf2_cu structures are living in memory, this field
291 chains them all together, so that they can be released efficiently.
292 We will probably also want a generation counter so that most-recently-used
293 compilation units are cached... */
294 struct dwarf2_per_cu_data *read_in_chain;
296 /* Backchain to our per_cu entry if the tree has been built. */
297 struct dwarf2_per_cu_data *per_cu;
299 /* Pointer to the die -> type map. Although it is stored
300 permanently in per_cu, we copy it here to avoid double
304 /* How many compilation units ago was this CU last referenced? */
307 /* A hash table of die offsets for following references. */
310 /* Full DIEs if read in. */
311 struct die_info *dies;
313 /* A set of pointers to dwarf2_per_cu_data objects for compilation
314 units referenced by this one. Only set during full symbol processing;
315 partial symbol tables do not have dependencies. */
318 /* Header data from the line table, during full symbol processing. */
319 struct line_header *line_header;
321 /* Mark used when releasing cached dies. */
322 unsigned int mark : 1;
324 /* This flag will be set if this compilation unit might include
325 inter-compilation-unit references. */
326 unsigned int has_form_ref_addr : 1;
328 /* This flag will be set if this compilation unit includes any
329 DW_TAG_namespace DIEs. If we know that there are explicit
330 DIEs for namespaces, we don't need to try to infer them
331 from mangled names. */
332 unsigned int has_namespace_info : 1;
335 /* Persistent data held for a compilation unit, even when not
336 processing it. We put a pointer to this structure in the
337 read_symtab_private field of the psymtab. If we encounter
338 inter-compilation-unit references, we also maintain a sorted
339 list of all compilation units. */
341 struct dwarf2_per_cu_data
343 /* The start offset and length of this compilation unit. 2**29-1
344 bytes should suffice to store the length of any compilation unit
345 - if it doesn't, GDB will fall over anyway.
346 NOTE: Unlike comp_unit_head.length, this length includes
347 initial_length_size. */
349 unsigned int length : 29;
351 /* Flag indicating this compilation unit will be read in before
352 any of the current compilation units are processed. */
353 unsigned int queued : 1;
355 /* This flag will be set if we need to load absolutely all DIEs
356 for this compilation unit, instead of just the ones we think
357 are interesting. It gets set if we look for a DIE in the
358 hash table and don't find it. */
359 unsigned int load_all_dies : 1;
361 /* Non-zero if this CU is from .debug_types.
362 Otherwise it's from .debug_info. */
363 unsigned int from_debug_types : 1;
365 /* Set iff currently read in. */
366 struct dwarf2_cu *cu;
368 /* If full symbols for this CU have been read in, then this field
369 holds a map of DIE offsets to types. It isn't always possible
370 to reconstruct this information later, so we have to preserve
374 /* The partial symbol table associated with this compilation unit,
375 or NULL for partial units (which do not have an associated
377 struct partial_symtab *psymtab;
380 /* Entry in the signatured_types hash table. */
382 struct signatured_type
386 /* Offset in .debug_types of the TU (type_unit) for this type. */
389 /* Offset in .debug_types of the type defined by this TU. */
390 unsigned int type_offset;
392 /* The CU(/TU) of this type. */
393 struct dwarf2_per_cu_data per_cu;
396 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
397 which are used for both .debug_info and .debug_types dies.
398 All parameters here are unchanging for the life of the call.
399 This struct exists to abstract away the constant parameters of
402 struct die_reader_specs
404 /* The bfd of this objfile. */
407 /* The CU of the DIE we are parsing. */
408 struct dwarf2_cu *cu;
410 /* Pointer to start of section buffer.
411 This is either the start of .debug_info or .debug_types. */
412 const gdb_byte *buffer;
415 /* The line number information for a compilation unit (found in the
416 .debug_line section) begins with a "statement program header",
417 which contains the following information. */
420 unsigned int total_length;
421 unsigned short version;
422 unsigned int header_length;
423 unsigned char minimum_instruction_length;
424 unsigned char default_is_stmt;
426 unsigned char line_range;
427 unsigned char opcode_base;
429 /* standard_opcode_lengths[i] is the number of operands for the
430 standard opcode whose value is i. This means that
431 standard_opcode_lengths[0] is unused, and the last meaningful
432 element is standard_opcode_lengths[opcode_base - 1]. */
433 unsigned char *standard_opcode_lengths;
435 /* The include_directories table. NOTE! These strings are not
436 allocated with xmalloc; instead, they are pointers into
437 debug_line_buffer. If you try to free them, `free' will get
439 unsigned int num_include_dirs, include_dirs_size;
442 /* The file_names table. NOTE! These strings are not allocated
443 with xmalloc; instead, they are pointers into debug_line_buffer.
444 Don't try to free them directly. */
445 unsigned int num_file_names, file_names_size;
449 unsigned int dir_index;
450 unsigned int mod_time;
452 int included_p; /* Non-zero if referenced by the Line Number Program. */
453 struct symtab *symtab; /* The associated symbol table, if any. */
456 /* The start and end of the statement program following this
457 header. These point into dwarf2_per_objfile->line_buffer. */
458 gdb_byte *statement_program_start, *statement_program_end;
461 /* When we construct a partial symbol table entry we only
462 need this much information. */
463 struct partial_die_info
465 /* Offset of this DIE. */
468 /* DWARF-2 tag for this DIE. */
469 ENUM_BITFIELD(dwarf_tag) tag : 16;
471 /* Assorted flags describing the data found in this DIE. */
472 unsigned int has_children : 1;
473 unsigned int is_external : 1;
474 unsigned int is_declaration : 1;
475 unsigned int has_type : 1;
476 unsigned int has_specification : 1;
477 unsigned int has_pc_info : 1;
479 /* Flag set if the SCOPE field of this structure has been
481 unsigned int scope_set : 1;
483 /* Flag set if the DIE has a byte_size attribute. */
484 unsigned int has_byte_size : 1;
486 /* The name of this DIE. Normally the value of DW_AT_name, but
487 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
491 /* The scope to prepend to our children. This is generally
492 allocated on the comp_unit_obstack, so will disappear
493 when this compilation unit leaves the cache. */
496 /* The location description associated with this DIE, if any. */
497 struct dwarf_block *locdesc;
499 /* If HAS_PC_INFO, the PC range associated with this DIE. */
503 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
504 DW_AT_sibling, if any. */
507 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
508 DW_AT_specification (or DW_AT_abstract_origin or
510 unsigned int spec_offset;
512 /* Pointers to this DIE's parent, first child, and next sibling,
514 struct partial_die_info *die_parent, *die_child, *die_sibling;
517 /* This data structure holds the information of an abbrev. */
520 unsigned int number; /* number identifying abbrev */
521 enum dwarf_tag tag; /* dwarf tag */
522 unsigned short has_children; /* boolean */
523 unsigned short num_attrs; /* number of attributes */
524 struct attr_abbrev *attrs; /* an array of attribute descriptions */
525 struct abbrev_info *next; /* next in chain */
530 ENUM_BITFIELD(dwarf_attribute) name : 16;
531 ENUM_BITFIELD(dwarf_form) form : 16;
534 /* Attributes have a name and a value */
537 ENUM_BITFIELD(dwarf_attribute) name : 16;
538 ENUM_BITFIELD(dwarf_form) form : 15;
540 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
541 field should be in u.str (existing only for DW_STRING) but it is kept
542 here for better struct attribute alignment. */
543 unsigned int string_is_canonical : 1;
548 struct dwarf_block *blk;
552 struct signatured_type *signatured_type;
557 /* This data structure holds a complete die structure. */
560 /* DWARF-2 tag for this DIE. */
561 ENUM_BITFIELD(dwarf_tag) tag : 16;
563 /* Number of attributes */
564 unsigned short num_attrs;
569 /* Offset in .debug_info or .debug_types section. */
572 /* The dies in a compilation unit form an n-ary tree. PARENT
573 points to this die's parent; CHILD points to the first child of
574 this node; and all the children of a given node are chained
575 together via their SIBLING fields, terminated by a die whose
577 struct die_info *child; /* Its first child, if any. */
578 struct die_info *sibling; /* Its next sibling, if any. */
579 struct die_info *parent; /* Its parent, if any. */
581 /* An array of attributes, with NUM_ATTRS elements. There may be
582 zero, but it's not common and zero-sized arrays are not
583 sufficiently portable C. */
584 struct attribute attrs[1];
587 struct function_range
590 CORE_ADDR lowpc, highpc;
592 struct function_range *next;
595 /* Get at parts of an attribute structure */
597 #define DW_STRING(attr) ((attr)->u.str)
598 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
599 #define DW_UNSND(attr) ((attr)->u.unsnd)
600 #define DW_BLOCK(attr) ((attr)->u.blk)
601 #define DW_SND(attr) ((attr)->u.snd)
602 #define DW_ADDR(attr) ((attr)->u.addr)
603 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
605 /* Blocks are a bunch of untyped bytes. */
612 #ifndef ATTR_ALLOC_CHUNK
613 #define ATTR_ALLOC_CHUNK 4
616 /* Allocate fields for structs, unions and enums in this size. */
617 #ifndef DW_FIELD_ALLOC_CHUNK
618 #define DW_FIELD_ALLOC_CHUNK 4
621 /* A zeroed version of a partial die for initialization purposes. */
622 static struct partial_die_info zeroed_partial_die;
624 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
625 but this would require a corresponding change in unpack_field_as_long
627 static int bits_per_byte = 8;
629 /* The routines that read and process dies for a C struct or C++ class
630 pass lists of data member fields and lists of member function fields
631 in an instance of a field_info structure, as defined below. */
634 /* List of data member and baseclasses fields. */
637 struct nextfield *next;
642 *fields, *baseclasses;
644 /* Number of fields (including baseclasses). */
647 /* Number of baseclasses. */
650 /* Set if the accesibility of one of the fields is not public. */
651 int non_public_fields;
653 /* Member function fields array, entries are allocated in the order they
654 are encountered in the object file. */
657 struct nextfnfield *next;
658 struct fn_field fnfield;
662 /* Member function fieldlist array, contains name of possibly overloaded
663 member function, number of overloaded member functions and a pointer
664 to the head of the member function field chain. */
669 struct nextfnfield *head;
673 /* Number of entries in the fnfieldlists array. */
677 /* One item on the queue of compilation units to read in full symbols
679 struct dwarf2_queue_item
681 struct dwarf2_per_cu_data *per_cu;
682 struct dwarf2_queue_item *next;
685 /* The current queue. */
686 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
688 /* Loaded secondary compilation units are kept in memory until they
689 have not been referenced for the processing of this many
690 compilation units. Set this to zero to disable caching. Cache
691 sizes of up to at least twenty will improve startup time for
692 typical inter-CU-reference binaries, at an obvious memory cost. */
693 static int dwarf2_max_cache_age = 5;
695 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
696 struct cmd_list_element *c, const char *value)
698 fprintf_filtered (file, _("\
699 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
704 /* Various complaints about symbol reading that don't abort the process */
707 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
709 complaint (&symfile_complaints,
710 _("statement list doesn't fit in .debug_line section"));
714 dwarf2_debug_line_missing_file_complaint (void)
716 complaint (&symfile_complaints,
717 _(".debug_line section has line data without a file"));
721 dwarf2_debug_line_missing_end_sequence_complaint (void)
723 complaint (&symfile_complaints,
724 _(".debug_line section has line program sequence without an end"));
728 dwarf2_complex_location_expr_complaint (void)
730 complaint (&symfile_complaints, _("location expression too complex"));
734 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
737 complaint (&symfile_complaints,
738 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
743 dwarf2_macros_too_long_complaint (void)
745 complaint (&symfile_complaints,
746 _("macro info runs off end of `.debug_macinfo' section"));
750 dwarf2_macro_malformed_definition_complaint (const char *arg1)
752 complaint (&symfile_complaints,
753 _("macro debug info contains a malformed macro definition:\n`%s'"),
758 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
760 complaint (&symfile_complaints,
761 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
764 /* local function prototypes */
766 static void dwarf2_locate_sections (bfd *, asection *, void *);
769 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
772 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
775 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
777 struct partial_symtab *);
779 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
781 static void scan_partial_symbols (struct partial_die_info *,
782 CORE_ADDR *, CORE_ADDR *,
783 int, struct dwarf2_cu *);
785 static void add_partial_symbol (struct partial_die_info *,
788 static int pdi_needs_namespace (enum dwarf_tag tag);
790 static void add_partial_namespace (struct partial_die_info *pdi,
791 CORE_ADDR *lowpc, CORE_ADDR *highpc,
792 int need_pc, struct dwarf2_cu *cu);
794 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
795 CORE_ADDR *highpc, int need_pc,
796 struct dwarf2_cu *cu);
798 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
799 struct dwarf2_cu *cu);
801 static void add_partial_subprogram (struct partial_die_info *pdi,
802 CORE_ADDR *lowpc, CORE_ADDR *highpc,
803 int need_pc, struct dwarf2_cu *cu);
805 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
806 gdb_byte *buffer, gdb_byte *info_ptr,
807 bfd *abfd, struct dwarf2_cu *cu);
809 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
811 static void psymtab_to_symtab_1 (struct partial_symtab *);
813 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
815 static void dwarf2_free_abbrev_table (void *);
817 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
820 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
823 static struct partial_die_info *load_partial_dies (bfd *,
824 gdb_byte *, gdb_byte *,
825 int, struct dwarf2_cu *);
827 static gdb_byte *read_partial_die (struct partial_die_info *,
828 struct abbrev_info *abbrev,
830 gdb_byte *, gdb_byte *,
833 static struct partial_die_info *find_partial_die (unsigned int,
836 static void fixup_partial_die (struct partial_die_info *,
839 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
840 bfd *, gdb_byte *, struct dwarf2_cu *);
842 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
843 bfd *, gdb_byte *, struct dwarf2_cu *);
845 static unsigned int read_1_byte (bfd *, gdb_byte *);
847 static int read_1_signed_byte (bfd *, gdb_byte *);
849 static unsigned int read_2_bytes (bfd *, gdb_byte *);
851 static unsigned int read_4_bytes (bfd *, gdb_byte *);
853 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
855 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
858 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
860 static LONGEST read_checked_initial_length_and_offset
861 (bfd *, gdb_byte *, const struct comp_unit_head *,
862 unsigned int *, unsigned int *);
864 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
867 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
869 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
871 static char *read_string (bfd *, gdb_byte *, unsigned int *);
873 static char *read_indirect_string (bfd *, gdb_byte *,
874 const struct comp_unit_head *,
877 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
879 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
881 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
883 static void set_cu_language (unsigned int, struct dwarf2_cu *);
885 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
888 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
892 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
893 struct dwarf2_cu *cu);
895 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
897 static struct die_info *die_specification (struct die_info *die,
898 struct dwarf2_cu **);
900 static void free_line_header (struct line_header *lh);
902 static void add_file_name (struct line_header *, char *, unsigned int,
903 unsigned int, unsigned int);
905 static struct line_header *(dwarf_decode_line_header
906 (unsigned int offset,
907 bfd *abfd, struct dwarf2_cu *cu));
909 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
910 struct dwarf2_cu *, struct partial_symtab *);
912 static void dwarf2_start_subfile (char *, char *, char *);
914 static struct symbol *new_symbol (struct die_info *, struct type *,
917 static void dwarf2_const_value (struct attribute *, struct symbol *,
920 static void dwarf2_const_value_data (struct attribute *attr,
924 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
926 static struct type *die_containing_type (struct die_info *,
929 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
931 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
933 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
935 static char *typename_concat (struct obstack *,
940 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
942 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
944 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
946 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
948 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
949 struct dwarf2_cu *, struct partial_symtab *);
951 static int dwarf2_get_pc_bounds (struct die_info *,
952 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
953 struct partial_symtab *);
955 static void get_scope_pc_bounds (struct die_info *,
956 CORE_ADDR *, CORE_ADDR *,
959 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
960 CORE_ADDR, struct dwarf2_cu *);
962 static void dwarf2_add_field (struct field_info *, struct die_info *,
965 static void dwarf2_attach_fields_to_type (struct field_info *,
966 struct type *, struct dwarf2_cu *);
968 static void dwarf2_add_member_fn (struct field_info *,
969 struct die_info *, struct type *,
972 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
973 struct type *, struct dwarf2_cu *);
975 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
977 static const char *determine_class_name (struct die_info *die,
978 struct dwarf2_cu *cu);
980 static void read_common_block (struct die_info *, struct dwarf2_cu *);
982 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
984 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
986 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
988 static const char *namespace_name (struct die_info *die,
989 int *is_anonymous, struct dwarf2_cu *);
991 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
993 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
995 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
998 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1000 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1002 gdb_byte **new_info_ptr,
1003 struct die_info *parent);
1005 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1007 gdb_byte **new_info_ptr,
1008 struct die_info *parent);
1010 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1012 gdb_byte **new_info_ptr,
1013 struct die_info *parent);
1015 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1016 struct die_info **, gdb_byte *,
1019 static void process_die (struct die_info *, struct dwarf2_cu *);
1021 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
1023 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1026 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1028 static struct die_info *dwarf2_extension (struct die_info *die,
1029 struct dwarf2_cu **);
1031 static char *dwarf_tag_name (unsigned int);
1033 static char *dwarf_attr_name (unsigned int);
1035 static char *dwarf_form_name (unsigned int);
1037 static char *dwarf_stack_op_name (unsigned int);
1039 static char *dwarf_bool_name (unsigned int);
1041 static char *dwarf_type_encoding_name (unsigned int);
1044 static char *dwarf_cfi_name (unsigned int);
1047 static struct die_info *sibling_die (struct die_info *);
1049 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1051 static void dump_die_for_error (struct die_info *);
1053 static void dump_die_1 (struct ui_file *, int level, int max_level,
1056 /*static*/ void dump_die (struct die_info *, int max_level);
1058 static void store_in_ref_table (struct die_info *,
1059 struct dwarf2_cu *);
1061 static int is_ref_attr (struct attribute *);
1063 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1065 static int dwarf2_get_attr_constant_value (struct attribute *, int);
1067 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1069 struct dwarf2_cu **);
1071 static struct die_info *follow_die_ref (struct die_info *,
1073 struct dwarf2_cu **);
1075 static struct die_info *follow_die_sig (struct die_info *,
1077 struct dwarf2_cu **);
1079 static void read_signatured_type_at_offset (struct objfile *objfile,
1080 unsigned int offset);
1082 static void read_signatured_type (struct objfile *,
1083 struct signatured_type *type_sig);
1085 /* memory allocation interface */
1087 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1089 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1091 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1093 static void initialize_cu_func_list (struct dwarf2_cu *);
1095 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1096 struct dwarf2_cu *);
1098 static void dwarf_decode_macros (struct line_header *, unsigned int,
1099 char *, bfd *, struct dwarf2_cu *);
1101 static int attr_form_is_block (struct attribute *);
1103 static int attr_form_is_section_offset (struct attribute *);
1105 static int attr_form_is_constant (struct attribute *);
1107 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1109 struct dwarf2_cu *cu);
1111 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1112 struct abbrev_info *abbrev,
1113 struct dwarf2_cu *cu);
1115 static void free_stack_comp_unit (void *);
1117 static hashval_t partial_die_hash (const void *item);
1119 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1121 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1122 (unsigned int offset, struct objfile *objfile);
1124 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1125 (unsigned int offset, struct objfile *objfile);
1127 static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile);
1129 static void free_one_comp_unit (void *);
1131 static void free_cached_comp_units (void *);
1133 static void age_cached_comp_units (void);
1135 static void free_one_cached_comp_unit (void *);
1137 static struct type *set_die_type (struct die_info *, struct type *,
1138 struct dwarf2_cu *);
1140 static void create_all_comp_units (struct objfile *);
1142 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1145 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1147 static void dwarf2_add_dependence (struct dwarf2_cu *,
1148 struct dwarf2_per_cu_data *);
1150 static void dwarf2_mark (struct dwarf2_cu *);
1152 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1154 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1156 /* Try to locate the sections we need for DWARF 2 debugging
1157 information and return true if we have enough to do something. */
1160 dwarf2_has_info (struct objfile *objfile)
1162 struct dwarf2_per_objfile *data;
1164 /* Initialize per-objfile state. */
1165 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1166 memset (data, 0, sizeof (*data));
1167 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1168 dwarf2_per_objfile = data;
1170 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1171 return (data->info.asection != NULL && data->abbrev.asection != NULL);
1174 /* When loading sections, we can either look for ".<name>", or for
1175 * ".z<name>", which indicates a compressed section. */
1178 section_is_p (const char *section_name, const char *name)
1180 return (section_name[0] == '.'
1181 && (strcmp (section_name + 1, name) == 0
1182 || (section_name[1] == 'z'
1183 && strcmp (section_name + 2, name) == 0)));
1186 /* This function is mapped across the sections and remembers the
1187 offset and size of each of the debugging sections we are interested
1191 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1193 if (section_is_p (sectp->name, INFO_SECTION))
1195 dwarf2_per_objfile->info.asection = sectp;
1196 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1198 else if (section_is_p (sectp->name, ABBREV_SECTION))
1200 dwarf2_per_objfile->abbrev.asection = sectp;
1201 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1203 else if (section_is_p (sectp->name, LINE_SECTION))
1205 dwarf2_per_objfile->line.asection = sectp;
1206 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1208 else if (section_is_p (sectp->name, PUBNAMES_SECTION))
1210 dwarf2_per_objfile->pubnames.asection = sectp;
1211 dwarf2_per_objfile->pubnames.size = bfd_get_section_size (sectp);
1213 else if (section_is_p (sectp->name, ARANGES_SECTION))
1215 dwarf2_per_objfile->aranges.asection = sectp;
1216 dwarf2_per_objfile->aranges.size = bfd_get_section_size (sectp);
1218 else if (section_is_p (sectp->name, LOC_SECTION))
1220 dwarf2_per_objfile->loc.asection = sectp;
1221 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1223 else if (section_is_p (sectp->name, MACINFO_SECTION))
1225 dwarf2_per_objfile->macinfo.asection = sectp;
1226 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1228 else if (section_is_p (sectp->name, STR_SECTION))
1230 dwarf2_per_objfile->str.asection = sectp;
1231 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1233 else if (section_is_p (sectp->name, FRAME_SECTION))
1235 dwarf2_per_objfile->frame.asection = sectp;
1236 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1238 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1240 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1241 if (aflag & SEC_HAS_CONTENTS)
1243 dwarf2_per_objfile->eh_frame.asection = sectp;
1244 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1247 else if (section_is_p (sectp->name, RANGES_SECTION))
1249 dwarf2_per_objfile->ranges.asection = sectp;
1250 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1252 else if (section_is_p (sectp->name, TYPES_SECTION))
1254 dwarf2_per_objfile->types.asection = sectp;
1255 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1258 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1259 && bfd_section_vma (abfd, sectp) == 0)
1260 dwarf2_per_objfile->has_section_at_zero = 1;
1263 /* Decompress a section that was compressed using zlib. Store the
1264 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1267 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1268 gdb_byte **outbuf, bfd_size_type *outsize)
1270 bfd *abfd = objfile->obfd;
1272 error (_("Support for zlib-compressed DWARF data (from '%s') "
1273 "is disabled in this copy of GDB"),
1274 bfd_get_filename (abfd));
1276 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1277 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1278 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1279 bfd_size_type uncompressed_size;
1280 gdb_byte *uncompressed_buffer;
1283 int header_size = 12;
1285 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1286 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
1287 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1288 bfd_get_filename (abfd));
1290 /* Read the zlib header. In this case, it should be "ZLIB" followed
1291 by the uncompressed section size, 8 bytes in big-endian order. */
1292 if (compressed_size < header_size
1293 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1294 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1295 bfd_get_filename (abfd));
1296 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1297 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1298 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1299 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1300 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1301 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1302 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1303 uncompressed_size += compressed_buffer[11];
1305 /* It is possible the section consists of several compressed
1306 buffers concatenated together, so we uncompress in a loop. */
1310 strm.avail_in = compressed_size - header_size;
1311 strm.next_in = (Bytef*) compressed_buffer + header_size;
1312 strm.avail_out = uncompressed_size;
1313 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1315 rc = inflateInit (&strm);
1316 while (strm.avail_in > 0)
1319 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1320 bfd_get_filename (abfd), rc);
1321 strm.next_out = ((Bytef*) uncompressed_buffer
1322 + (uncompressed_size - strm.avail_out));
1323 rc = inflate (&strm, Z_FINISH);
1324 if (rc != Z_STREAM_END)
1325 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1326 bfd_get_filename (abfd), rc);
1327 rc = inflateReset (&strm);
1329 rc = inflateEnd (&strm);
1331 || strm.avail_out != 0)
1332 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1333 bfd_get_filename (abfd), rc);
1335 do_cleanups (cleanup);
1336 *outbuf = uncompressed_buffer;
1337 *outsize = uncompressed_size;
1341 /* Read the contents of the section SECTP from object file specified by
1342 OBJFILE, store info about the section into INFO.
1343 If the section is compressed, uncompress it before returning. */
1346 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1348 bfd *abfd = objfile->obfd;
1349 asection *sectp = info->asection;
1350 gdb_byte *buf, *retbuf;
1351 unsigned char header[4];
1353 info->buffer = NULL;
1354 info->was_mmapped = 0;
1356 if (info->asection == NULL || info->size == 0)
1359 /* Check if the file has a 4-byte header indicating compression. */
1360 if (info->size > sizeof (header)
1361 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1362 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1364 /* Upon decompression, update the buffer and its size. */
1365 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1367 zlib_decompress_section (objfile, sectp, &info->buffer,
1375 pagesize = getpagesize ();
1377 /* Only try to mmap sections which are large enough: we don't want to
1378 waste space due to fragmentation. Also, only try mmap for sections
1379 without relocations. */
1381 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1383 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1384 size_t map_length = info->size + sectp->filepos - pg_offset;
1385 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1386 MAP_PRIVATE, pg_offset);
1388 if (retbuf != MAP_FAILED)
1390 info->was_mmapped = 1;
1391 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1397 /* If we get here, we are a normal, not-compressed section. */
1399 = obstack_alloc (&objfile->objfile_obstack, info->size);
1401 /* When debugging .o files, we may need to apply relocations; see
1402 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1403 We never compress sections in .o files, so we only need to
1404 try this when the section is not compressed. */
1405 retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
1408 info->buffer = retbuf;
1412 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1413 || bfd_bread (buf, info->size, abfd) != info->size)
1414 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1415 bfd_get_filename (abfd));
1418 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1422 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1423 asection **sectp, gdb_byte **bufp,
1424 bfd_size_type *sizep)
1426 struct dwarf2_per_objfile *data
1427 = objfile_data (objfile, dwarf2_objfile_data_key);
1428 struct dwarf2_section_info *info;
1429 if (section_is_p (section_name, EH_FRAME_SECTION))
1430 info = &data->eh_frame;
1431 else if (section_is_p (section_name, FRAME_SECTION))
1432 info = &data->frame;
1436 if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
1437 /* We haven't read this section in yet. Do it now. */
1438 dwarf2_read_section (objfile, info);
1440 *sectp = info->asection;
1441 *bufp = info->buffer;
1442 *sizep = info->size;
1445 /* Build a partial symbol table. */
1448 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1450 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
1451 dwarf2_read_section (objfile, &dwarf2_per_objfile->abbrev);
1452 dwarf2_read_section (objfile, &dwarf2_per_objfile->line);
1453 dwarf2_read_section (objfile, &dwarf2_per_objfile->str);
1454 dwarf2_read_section (objfile, &dwarf2_per_objfile->macinfo);
1455 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
1456 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
1457 dwarf2_read_section (objfile, &dwarf2_per_objfile->loc);
1458 dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame);
1459 dwarf2_read_section (objfile, &dwarf2_per_objfile->frame);
1462 || (objfile->global_psymbols.size == 0
1463 && objfile->static_psymbols.size == 0))
1465 init_psymbol_list (objfile, 1024);
1469 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1471 /* Things are significantly easier if we have .debug_aranges and
1472 .debug_pubnames sections */
1474 dwarf2_build_psymtabs_easy (objfile, mainline);
1478 /* only test this case for now */
1480 /* In this case we have to work a bit harder */
1481 dwarf2_build_psymtabs_hard (objfile, mainline);
1486 /* Build the partial symbol table from the information in the
1487 .debug_pubnames and .debug_aranges sections. */
1490 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1492 bfd *abfd = objfile->obfd;
1493 char *aranges_buffer, *pubnames_buffer;
1494 char *aranges_ptr, *pubnames_ptr;
1495 unsigned int entry_length, version, info_offset, info_size;
1497 pubnames_buffer = dwarf2_read_section (objfile,
1498 dwarf_pubnames_section);
1499 pubnames_ptr = pubnames_buffer;
1500 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames.size)
1502 unsigned int bytes_read;
1504 entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read);
1505 pubnames_ptr += bytes_read;
1506 version = read_1_byte (abfd, pubnames_ptr);
1508 info_offset = read_4_bytes (abfd, pubnames_ptr);
1510 info_size = read_4_bytes (abfd, pubnames_ptr);
1514 aranges_buffer = dwarf2_read_section (objfile,
1515 dwarf_aranges_section);
1520 /* Return TRUE if OFFSET is within CU_HEADER. */
1523 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
1525 unsigned int bottom = cu_header->offset;
1526 unsigned int top = (cu_header->offset
1528 + cu_header->initial_length_size);
1529 return (offset >= bottom && offset < top);
1532 /* Read in the comp unit header information from the debug_info at info_ptr.
1533 NOTE: This leaves members offset, first_die_offset to be filled in
1537 read_comp_unit_head (struct comp_unit_head *cu_header,
1538 gdb_byte *info_ptr, bfd *abfd)
1541 unsigned int bytes_read;
1543 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
1544 cu_header->initial_length_size = bytes_read;
1545 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
1546 info_ptr += bytes_read;
1547 cu_header->version = read_2_bytes (abfd, info_ptr);
1549 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1551 info_ptr += bytes_read;
1552 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1554 signed_addr = bfd_get_sign_extend_vma (abfd);
1555 if (signed_addr < 0)
1556 internal_error (__FILE__, __LINE__,
1557 _("read_comp_unit_head: dwarf from non elf file"));
1558 cu_header->signed_addr_p = signed_addr;
1564 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
1565 gdb_byte *buffer, unsigned int buffer_size,
1568 gdb_byte *beg_of_comp_unit = info_ptr;
1570 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1572 if (header->version != 2 && header->version != 3)
1573 error (_("Dwarf Error: wrong version in compilation unit header "
1574 "(is %d, should be %d) [in module %s]"), header->version,
1575 2, bfd_get_filename (abfd));
1577 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
1578 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1579 "(offset 0x%lx + 6) [in module %s]"),
1580 (long) header->abbrev_offset,
1581 (long) (beg_of_comp_unit - buffer),
1582 bfd_get_filename (abfd));
1584 if (beg_of_comp_unit + header->length + header->initial_length_size
1585 > buffer + buffer_size)
1586 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1587 "(offset 0x%lx + 0) [in module %s]"),
1588 (long) header->length,
1589 (long) (beg_of_comp_unit - buffer),
1590 bfd_get_filename (abfd));
1595 /* Read in the types comp unit header information from .debug_types entry at
1596 types_ptr. The result is a pointer to one past the end of the header. */
1599 read_type_comp_unit_head (struct comp_unit_head *cu_header,
1600 ULONGEST *signature,
1601 gdb_byte *types_ptr, bfd *abfd)
1603 unsigned int bytes_read;
1604 gdb_byte *initial_types_ptr = types_ptr;
1606 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
1608 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
1610 *signature = read_8_bytes (abfd, types_ptr);
1612 types_ptr += cu_header->offset_size;
1613 cu_header->first_die_offset = types_ptr - initial_types_ptr;
1618 /* Allocate a new partial symtab for file named NAME and mark this new
1619 partial symtab as being an include of PST. */
1622 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1623 struct objfile *objfile)
1625 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1627 subpst->section_offsets = pst->section_offsets;
1628 subpst->textlow = 0;
1629 subpst->texthigh = 0;
1631 subpst->dependencies = (struct partial_symtab **)
1632 obstack_alloc (&objfile->objfile_obstack,
1633 sizeof (struct partial_symtab *));
1634 subpst->dependencies[0] = pst;
1635 subpst->number_of_dependencies = 1;
1637 subpst->globals_offset = 0;
1638 subpst->n_global_syms = 0;
1639 subpst->statics_offset = 0;
1640 subpst->n_static_syms = 0;
1641 subpst->symtab = NULL;
1642 subpst->read_symtab = pst->read_symtab;
1645 /* No private part is necessary for include psymtabs. This property
1646 can be used to differentiate between such include psymtabs and
1647 the regular ones. */
1648 subpst->read_symtab_private = NULL;
1651 /* Read the Line Number Program data and extract the list of files
1652 included by the source file represented by PST. Build an include
1653 partial symtab for each of these included files. */
1656 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1657 struct die_info *die,
1658 struct partial_symtab *pst)
1660 struct objfile *objfile = cu->objfile;
1661 bfd *abfd = objfile->obfd;
1662 struct line_header *lh = NULL;
1663 struct attribute *attr;
1665 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
1668 unsigned int line_offset = DW_UNSND (attr);
1669 lh = dwarf_decode_line_header (line_offset, abfd, cu);
1672 return; /* No linetable, so no includes. */
1674 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1676 free_line_header (lh);
1680 hash_type_signature (const void *item)
1682 const struct signatured_type *type_sig = item;
1683 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1684 return type_sig->signature;
1688 eq_type_signature (const void *item_lhs, const void *item_rhs)
1690 const struct signatured_type *lhs = item_lhs;
1691 const struct signatured_type *rhs = item_rhs;
1692 return lhs->signature == rhs->signature;
1695 /* Create the hash table of all entries in the .debug_types section.
1696 The result is zero if there is an error (e.g. missing .debug_types section),
1697 otherwise non-zero. */
1700 create_debug_types_hash_table (struct objfile *objfile)
1702 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer;
1705 if (info_ptr == NULL)
1707 dwarf2_per_objfile->signatured_types = NULL;
1711 types_htab = htab_create_alloc_ex (41,
1712 hash_type_signature,
1715 &objfile->objfile_obstack,
1716 hashtab_obstack_allocate,
1717 dummy_obstack_deallocate);
1719 if (dwarf2_die_debug)
1720 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
1722 while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1724 unsigned int offset;
1725 unsigned int offset_size;
1726 unsigned int type_offset;
1727 unsigned int length, initial_length_size;
1728 unsigned short version;
1730 struct signatured_type *type_sig;
1732 gdb_byte *ptr = info_ptr;
1734 offset = ptr - dwarf2_per_objfile->types.buffer;
1736 /* We need to read the type's signature in order to build the hash
1737 table, but we don't need to read anything else just yet. */
1739 /* Sanity check to ensure entire cu is present. */
1740 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
1741 if (ptr + length + initial_length_size
1742 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
1744 complaint (&symfile_complaints,
1745 _("debug type entry runs off end of `.debug_types' section, ignored"));
1749 offset_size = initial_length_size == 4 ? 4 : 8;
1750 ptr += initial_length_size;
1751 version = bfd_get_16 (objfile->obfd, ptr);
1753 ptr += offset_size; /* abbrev offset */
1754 ptr += 1; /* address size */
1755 signature = bfd_get_64 (objfile->obfd, ptr);
1757 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
1759 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
1760 memset (type_sig, 0, sizeof (*type_sig));
1761 type_sig->signature = signature;
1762 type_sig->offset = offset;
1763 type_sig->type_offset = type_offset;
1765 slot = htab_find_slot (types_htab, type_sig, INSERT);
1766 gdb_assert (slot != NULL);
1769 if (dwarf2_die_debug)
1770 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
1771 offset, phex (signature, sizeof (signature)));
1773 info_ptr = info_ptr + initial_length_size + length;
1776 dwarf2_per_objfile->signatured_types = types_htab;
1781 /* Lookup a signature based type.
1782 Returns NULL if SIG is not present in the table. */
1784 static struct signatured_type *
1785 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
1787 struct signatured_type find_entry, *entry;
1789 if (dwarf2_per_objfile->signatured_types == NULL)
1791 complaint (&symfile_complaints,
1792 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1796 find_entry.signature = sig;
1797 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
1801 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1804 init_cu_die_reader (struct die_reader_specs *reader,
1805 struct dwarf2_cu *cu)
1807 reader->abfd = cu->objfile->obfd;
1809 if (cu->per_cu->from_debug_types)
1810 reader->buffer = dwarf2_per_objfile->types.buffer;
1812 reader->buffer = dwarf2_per_objfile->info.buffer;
1815 /* Find the base address of the compilation unit for range lists and
1816 location lists. It will normally be specified by DW_AT_low_pc.
1817 In DWARF-3 draft 4, the base address could be overridden by
1818 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1819 compilation units with discontinuous ranges. */
1822 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
1824 struct attribute *attr;
1827 cu->base_address = 0;
1829 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
1832 cu->base_address = DW_ADDR (attr);
1837 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
1840 cu->base_address = DW_ADDR (attr);
1846 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1847 to combine the common parts.
1848 Process a compilation unit for a psymtab.
1849 BUFFER is a pointer to the beginning of the dwarf section buffer,
1850 either .debug_info or debug_types.
1851 INFO_PTR is a pointer to the start of the CU.
1852 Returns a pointer to the next CU. */
1855 process_psymtab_comp_unit (struct objfile *objfile,
1856 struct dwarf2_per_cu_data *this_cu,
1857 gdb_byte *buffer, gdb_byte *info_ptr,
1858 unsigned int buffer_size)
1860 bfd *abfd = objfile->obfd;
1861 gdb_byte *beg_of_comp_unit = info_ptr;
1862 struct die_info *comp_unit_die;
1863 struct partial_symtab *pst;
1865 struct cleanup *back_to_inner;
1866 struct dwarf2_cu cu;
1867 unsigned int bytes_read;
1868 int has_children, has_pc_info;
1869 struct attribute *attr;
1871 CORE_ADDR best_lowpc = 0, best_highpc = 0;
1872 struct die_reader_specs reader_specs;
1874 memset (&cu, 0, sizeof (cu));
1875 cu.objfile = objfile;
1876 obstack_init (&cu.comp_unit_obstack);
1878 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1880 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
1881 buffer, buffer_size,
1884 /* Complete the cu_header. */
1885 cu.header.offset = beg_of_comp_unit - buffer;
1886 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1888 cu.list_in_scope = &file_symbols;
1890 /* If this compilation unit was already read in, free the
1891 cached copy in order to read it in again. This is
1892 necessary because we skipped some symbols when we first
1893 read in the compilation unit (see load_partial_dies).
1894 This problem could be avoided, but the benefit is
1896 if (this_cu->cu != NULL)
1897 free_one_cached_comp_unit (this_cu->cu);
1899 /* Note that this is a pointer to our stack frame, being
1900 added to a global data structure. It will be cleaned up
1901 in free_stack_comp_unit when we finish with this
1902 compilation unit. */
1904 cu.per_cu = this_cu;
1906 /* Read the abbrevs for this compilation unit into a table. */
1907 dwarf2_read_abbrevs (abfd, &cu);
1908 make_cleanup (dwarf2_free_abbrev_table, &cu);
1910 /* Read the compilation unit die. */
1911 if (this_cu->from_debug_types)
1912 info_ptr += 8 /*signature*/ + cu.header.offset_size;
1913 init_cu_die_reader (&reader_specs, &cu);
1914 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
1917 if (this_cu->from_debug_types)
1919 /* offset,length haven't been set yet for type units. */
1920 this_cu->offset = cu.header.offset;
1921 this_cu->length = cu.header.length + cu.header.initial_length_size;
1923 else if (comp_unit_die->tag == DW_TAG_partial_unit)
1925 info_ptr = (beg_of_comp_unit + cu.header.length
1926 + cu.header.initial_length_size);
1927 do_cleanups (back_to_inner);
1931 /* Set the language we're debugging. */
1932 attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu);
1934 set_cu_language (DW_UNSND (attr), &cu);
1936 set_cu_language (language_minimal, &cu);
1938 /* Allocate a new partial symbol table structure. */
1939 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
1940 pst = start_psymtab_common (objfile, objfile->section_offsets,
1941 (attr != NULL) ? DW_STRING (attr) : "",
1942 /* TEXTLOW and TEXTHIGH are set below. */
1944 objfile->global_psymbols.next,
1945 objfile->static_psymbols.next);
1947 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
1949 pst->dirname = DW_STRING (attr);
1951 pst->read_symtab_private = (char *) this_cu;
1953 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1955 /* Store the function that reads in the rest of the symbol table */
1956 pst->read_symtab = dwarf2_psymtab_to_symtab;
1958 this_cu->psymtab = pst;
1960 dwarf2_find_base_address (comp_unit_die, &cu);
1962 /* Possibly set the default values of LOWPC and HIGHPC from
1964 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
1965 &best_highpc, &cu, pst);
1966 if (has_pc_info == 1 && best_lowpc < best_highpc)
1967 /* Store the contiguous range if it is not empty; it can be empty for
1968 CUs with no code. */
1969 addrmap_set_empty (objfile->psymtabs_addrmap,
1970 best_lowpc + baseaddr,
1971 best_highpc + baseaddr - 1, pst);
1973 /* Check if comp unit has_children.
1974 If so, read the rest of the partial symbols from this comp unit.
1975 If not, there's no more debug_info for this comp unit. */
1978 struct partial_die_info *first_die;
1979 CORE_ADDR lowpc, highpc;
1981 lowpc = ((CORE_ADDR) -1);
1982 highpc = ((CORE_ADDR) 0);
1984 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
1986 scan_partial_symbols (first_die, &lowpc, &highpc,
1987 ! has_pc_info, &cu);
1989 /* If we didn't find a lowpc, set it to highpc to avoid
1990 complaints from `maint check'. */
1991 if (lowpc == ((CORE_ADDR) -1))
1994 /* If the compilation unit didn't have an explicit address range,
1995 then use the information extracted from its child dies. */
1999 best_highpc = highpc;
2002 pst->textlow = best_lowpc + baseaddr;
2003 pst->texthigh = best_highpc + baseaddr;
2005 pst->n_global_syms = objfile->global_psymbols.next -
2006 (objfile->global_psymbols.list + pst->globals_offset);
2007 pst->n_static_syms = objfile->static_psymbols.next -
2008 (objfile->static_psymbols.list + pst->statics_offset);
2009 sort_pst_symbols (pst);
2011 /* If there is already a psymtab or symtab for a file of this
2012 name, remove it. (If there is a symtab, more drastic things
2013 also happen.) This happens in VxWorks. */
2014 if (! this_cu->from_debug_types)
2015 free_named_symtabs (pst->filename);
2017 info_ptr = (beg_of_comp_unit + cu.header.length
2018 + cu.header.initial_length_size);
2020 if (this_cu->from_debug_types)
2022 /* It's not clear we want to do anything with stmt lists here.
2023 Waiting to see what gcc ultimately does. */
2027 /* Get the list of files included in the current compilation unit,
2028 and build a psymtab for each of them. */
2029 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
2032 do_cleanups (back_to_inner);
2037 /* Traversal function for htab_traverse_noresize.
2038 Process one .debug_types comp-unit. */
2041 process_type_comp_unit (void **slot, void *info)
2043 struct signatured_type *entry = (struct signatured_type *) *slot;
2044 struct objfile *objfile = (struct objfile *) info;
2045 struct dwarf2_per_cu_data *this_cu;
2047 this_cu = &entry->per_cu;
2048 this_cu->from_debug_types = 1;
2050 process_psymtab_comp_unit (objfile, this_cu,
2051 dwarf2_per_objfile->types.buffer,
2052 dwarf2_per_objfile->types.buffer + entry->offset,
2053 dwarf2_per_objfile->types.size);
2058 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2059 Build partial symbol tables for the .debug_types comp-units. */
2062 build_type_psymtabs (struct objfile *objfile)
2064 if (! create_debug_types_hash_table (objfile))
2067 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
2068 process_type_comp_unit, objfile);
2071 /* Build the partial symbol table by doing a quick pass through the
2072 .debug_info and .debug_abbrev sections. */
2075 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
2077 /* Instead of reading this into a big buffer, we should probably use
2078 mmap() on architectures that support it. (FIXME) */
2079 bfd *abfd = objfile->obfd;
2081 struct cleanup *back_to;
2083 info_ptr = dwarf2_per_objfile->info.buffer;
2085 /* Any cached compilation units will be linked by the per-objfile
2086 read_in_chain. Make sure to free them when we're done. */
2087 back_to = make_cleanup (free_cached_comp_units, NULL);
2089 build_type_psymtabs (objfile);
2091 create_all_comp_units (objfile);
2093 objfile->psymtabs_addrmap =
2094 addrmap_create_mutable (&objfile->objfile_obstack);
2096 /* Since the objects we're extracting from .debug_info vary in
2097 length, only the individual functions to extract them (like
2098 read_comp_unit_head and load_partial_die) can really know whether
2099 the buffer is large enough to hold another complete object.
2101 At the moment, they don't actually check that. If .debug_info
2102 holds just one extra byte after the last compilation unit's dies,
2103 then read_comp_unit_head will happily read off the end of the
2104 buffer. read_partial_die is similarly casual. Those functions
2107 For this loop condition, simply checking whether there's any data
2108 left at all should be sufficient. */
2110 while (info_ptr < (dwarf2_per_objfile->info.buffer
2111 + dwarf2_per_objfile->info.size))
2113 struct dwarf2_per_cu_data *this_cu;
2115 this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer,
2118 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
2119 dwarf2_per_objfile->info.buffer,
2121 dwarf2_per_objfile->info.size);
2124 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
2125 &objfile->objfile_obstack);
2127 do_cleanups (back_to);
2130 /* Load the partial DIEs for a secondary CU into memory. */
2133 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
2134 struct objfile *objfile)
2136 bfd *abfd = objfile->obfd;
2137 gdb_byte *info_ptr, *beg_of_comp_unit;
2138 struct die_info *comp_unit_die;
2139 struct dwarf2_cu *cu;
2140 unsigned int bytes_read;
2141 struct cleanup *back_to;
2142 struct attribute *attr;
2144 struct die_reader_specs reader_specs;
2146 gdb_assert (! this_cu->from_debug_types);
2148 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
2149 beg_of_comp_unit = info_ptr;
2151 cu = alloc_one_comp_unit (objfile);
2153 /* ??? Missing cleanup for CU? */
2155 /* Link this compilation unit into the compilation unit tree. */
2157 cu->per_cu = this_cu;
2158 cu->type_hash = this_cu->type_hash;
2160 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
2161 dwarf2_per_objfile->info.buffer,
2162 dwarf2_per_objfile->info.size,
2165 /* Complete the cu_header. */
2166 cu->header.offset = this_cu->offset;
2167 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
2169 /* Read the abbrevs for this compilation unit into a table. */
2170 dwarf2_read_abbrevs (abfd, cu);
2171 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2173 /* Read the compilation unit die. */
2174 init_cu_die_reader (&reader_specs, cu);
2175 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2178 /* Set the language we're debugging. */
2179 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
2181 set_cu_language (DW_UNSND (attr), cu);
2183 set_cu_language (language_minimal, cu);
2185 /* Check if comp unit has_children.
2186 If so, read the rest of the partial symbols from this comp unit.
2187 If not, there's no more debug_info for this comp unit. */
2189 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
2191 do_cleanups (back_to);
2194 /* Create a list of all compilation units in OBJFILE. We do this only
2195 if an inter-comp-unit reference is found; presumably if there is one,
2196 there will be many, and one will occur early in the .debug_info section.
2197 So there's no point in building this list incrementally. */
2200 create_all_comp_units (struct objfile *objfile)
2204 struct dwarf2_per_cu_data **all_comp_units;
2205 gdb_byte *info_ptr = dwarf2_per_objfile->info.buffer;
2209 all_comp_units = xmalloc (n_allocated
2210 * sizeof (struct dwarf2_per_cu_data *));
2212 while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size)
2214 unsigned int length, initial_length_size;
2215 gdb_byte *beg_of_comp_unit;
2216 struct dwarf2_per_cu_data *this_cu;
2217 unsigned int offset;
2219 offset = info_ptr - dwarf2_per_objfile->info.buffer;
2221 /* Read just enough information to find out where the next
2222 compilation unit is. */
2223 length = read_initial_length (objfile->obfd, info_ptr,
2224 &initial_length_size);
2226 /* Save the compilation unit for later lookup. */
2227 this_cu = obstack_alloc (&objfile->objfile_obstack,
2228 sizeof (struct dwarf2_per_cu_data));
2229 memset (this_cu, 0, sizeof (*this_cu));
2230 this_cu->offset = offset;
2231 this_cu->length = length + initial_length_size;
2233 if (n_comp_units == n_allocated)
2236 all_comp_units = xrealloc (all_comp_units,
2238 * sizeof (struct dwarf2_per_cu_data *));
2240 all_comp_units[n_comp_units++] = this_cu;
2242 info_ptr = info_ptr + this_cu->length;
2245 dwarf2_per_objfile->all_comp_units
2246 = obstack_alloc (&objfile->objfile_obstack,
2247 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2248 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
2249 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
2250 xfree (all_comp_units);
2251 dwarf2_per_objfile->n_comp_units = n_comp_units;
2254 /* Process all loaded DIEs for compilation unit CU, starting at
2255 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2256 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2257 DW_AT_ranges). If NEED_PC is set, then this function will set
2258 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2259 and record the covered ranges in the addrmap. */
2262 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
2263 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2265 struct objfile *objfile = cu->objfile;
2266 bfd *abfd = objfile->obfd;
2267 struct partial_die_info *pdi;
2269 /* Now, march along the PDI's, descending into ones which have
2270 interesting children but skipping the children of the other ones,
2271 until we reach the end of the compilation unit. */
2277 fixup_partial_die (pdi, cu);
2279 /* Anonymous namespaces have no name but have interesting
2280 children, so we need to look at them. Ditto for anonymous
2283 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
2284 || pdi->tag == DW_TAG_enumeration_type)
2288 case DW_TAG_subprogram:
2289 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2291 case DW_TAG_variable:
2292 case DW_TAG_typedef:
2293 case DW_TAG_union_type:
2294 if (!pdi->is_declaration)
2296 add_partial_symbol (pdi, cu);
2299 case DW_TAG_class_type:
2300 case DW_TAG_interface_type:
2301 case DW_TAG_structure_type:
2302 if (!pdi->is_declaration)
2304 add_partial_symbol (pdi, cu);
2307 case DW_TAG_enumeration_type:
2308 if (!pdi->is_declaration)
2309 add_partial_enumeration (pdi, cu);
2311 case DW_TAG_base_type:
2312 case DW_TAG_subrange_type:
2313 /* File scope base type definitions are added to the partial
2315 add_partial_symbol (pdi, cu);
2317 case DW_TAG_namespace:
2318 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
2321 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
2328 /* If the die has a sibling, skip to the sibling. */
2330 pdi = pdi->die_sibling;
2334 /* Functions used to compute the fully scoped name of a partial DIE.
2336 Normally, this is simple. For C++, the parent DIE's fully scoped
2337 name is concatenated with "::" and the partial DIE's name. For
2338 Java, the same thing occurs except that "." is used instead of "::".
2339 Enumerators are an exception; they use the scope of their parent
2340 enumeration type, i.e. the name of the enumeration type is not
2341 prepended to the enumerator.
2343 There are two complexities. One is DW_AT_specification; in this
2344 case "parent" means the parent of the target of the specification,
2345 instead of the direct parent of the DIE. The other is compilers
2346 which do not emit DW_TAG_namespace; in this case we try to guess
2347 the fully qualified name of structure types from their members'
2348 linkage names. This must be done using the DIE's children rather
2349 than the children of any DW_AT_specification target. We only need
2350 to do this for structures at the top level, i.e. if the target of
2351 any DW_AT_specification (if any; otherwise the DIE itself) does not
2354 /* Compute the scope prefix associated with PDI's parent, in
2355 compilation unit CU. The result will be allocated on CU's
2356 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2357 field. NULL is returned if no prefix is necessary. */
2359 partial_die_parent_scope (struct partial_die_info *pdi,
2360 struct dwarf2_cu *cu)
2362 char *grandparent_scope;
2363 struct partial_die_info *parent, *real_pdi;
2365 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2366 then this means the parent of the specification DIE. */
2369 while (real_pdi->has_specification)
2370 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2372 parent = real_pdi->die_parent;
2376 if (parent->scope_set)
2377 return parent->scope;
2379 fixup_partial_die (parent, cu);
2381 grandparent_scope = partial_die_parent_scope (parent, cu);
2383 if (parent->tag == DW_TAG_namespace
2384 || parent->tag == DW_TAG_structure_type
2385 || parent->tag == DW_TAG_class_type
2386 || parent->tag == DW_TAG_interface_type
2387 || parent->tag == DW_TAG_union_type)
2389 if (grandparent_scope == NULL)
2390 parent->scope = parent->name;
2392 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
2395 else if (parent->tag == DW_TAG_enumeration_type)
2396 /* Enumerators should not get the name of the enumeration as a prefix. */
2397 parent->scope = grandparent_scope;
2400 /* FIXME drow/2004-04-01: What should we be doing with
2401 function-local names? For partial symbols, we should probably be
2403 complaint (&symfile_complaints,
2404 _("unhandled containing DIE tag %d for DIE at %d"),
2405 parent->tag, pdi->offset);
2406 parent->scope = grandparent_scope;
2409 parent->scope_set = 1;
2410 return parent->scope;
2413 /* Return the fully scoped name associated with PDI, from compilation unit
2414 CU. The result will be allocated with malloc. */
2416 partial_die_full_name (struct partial_die_info *pdi,
2417 struct dwarf2_cu *cu)
2421 parent_scope = partial_die_parent_scope (pdi, cu);
2422 if (parent_scope == NULL)
2425 return typename_concat (NULL, parent_scope, pdi->name, cu);
2429 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
2431 struct objfile *objfile = cu->objfile;
2433 char *actual_name = NULL;
2434 const char *my_prefix;
2435 const struct partial_symbol *psym = NULL;
2437 int built_actual_name = 0;
2439 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2441 if (pdi_needs_namespace (pdi->tag))
2443 actual_name = partial_die_full_name (pdi, cu);
2445 built_actual_name = 1;
2448 if (actual_name == NULL)
2449 actual_name = pdi->name;
2453 case DW_TAG_subprogram:
2454 if (pdi->is_external || cu->language == language_ada)
2456 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2457 of the global scope. But in Ada, we want to be able to access
2458 nested procedures globally. So all Ada subprograms are stored
2459 in the global scope. */
2460 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2461 mst_text, objfile); */
2462 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2463 VAR_DOMAIN, LOC_BLOCK,
2464 &objfile->global_psymbols,
2465 0, pdi->lowpc + baseaddr,
2466 cu->language, objfile);
2470 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2471 mst_file_text, objfile); */
2472 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2473 VAR_DOMAIN, LOC_BLOCK,
2474 &objfile->static_psymbols,
2475 0, pdi->lowpc + baseaddr,
2476 cu->language, objfile);
2479 case DW_TAG_variable:
2480 if (pdi->is_external)
2483 Don't enter into the minimal symbol tables as there is
2484 a minimal symbol table entry from the ELF symbols already.
2485 Enter into partial symbol table if it has a location
2486 descriptor or a type.
2487 If the location descriptor is missing, new_symbol will create
2488 a LOC_UNRESOLVED symbol, the address of the variable will then
2489 be determined from the minimal symbol table whenever the variable
2491 The address for the partial symbol table entry is not
2492 used by GDB, but it comes in handy for debugging partial symbol
2496 addr = decode_locdesc (pdi->locdesc, cu);
2497 if (pdi->locdesc || pdi->has_type)
2498 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2499 VAR_DOMAIN, LOC_STATIC,
2500 &objfile->global_psymbols,
2502 cu->language, objfile);
2506 /* Static Variable. Skip symbols without location descriptors. */
2507 if (pdi->locdesc == NULL)
2509 if (built_actual_name)
2510 xfree (actual_name);
2513 addr = decode_locdesc (pdi->locdesc, cu);
2514 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2515 mst_file_data, objfile); */
2516 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2517 VAR_DOMAIN, LOC_STATIC,
2518 &objfile->static_psymbols,
2520 cu->language, objfile);
2523 case DW_TAG_typedef:
2524 case DW_TAG_base_type:
2525 case DW_TAG_subrange_type:
2526 add_psymbol_to_list (actual_name, strlen (actual_name),
2527 VAR_DOMAIN, LOC_TYPEDEF,
2528 &objfile->static_psymbols,
2529 0, (CORE_ADDR) 0, cu->language, objfile);
2531 case DW_TAG_namespace:
2532 add_psymbol_to_list (actual_name, strlen (actual_name),
2533 VAR_DOMAIN, LOC_TYPEDEF,
2534 &objfile->global_psymbols,
2535 0, (CORE_ADDR) 0, cu->language, objfile);
2537 case DW_TAG_class_type:
2538 case DW_TAG_interface_type:
2539 case DW_TAG_structure_type:
2540 case DW_TAG_union_type:
2541 case DW_TAG_enumeration_type:
2542 /* Skip external references. The DWARF standard says in the section
2543 about "Structure, Union, and Class Type Entries": "An incomplete
2544 structure, union or class type is represented by a structure,
2545 union or class entry that does not have a byte size attribute
2546 and that has a DW_AT_declaration attribute." */
2547 if (!pdi->has_byte_size && pdi->is_declaration)
2549 if (built_actual_name)
2550 xfree (actual_name);
2554 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2555 static vs. global. */
2556 add_psymbol_to_list (actual_name, strlen (actual_name),
2557 STRUCT_DOMAIN, LOC_TYPEDEF,
2558 (cu->language == language_cplus
2559 || cu->language == language_java)
2560 ? &objfile->global_psymbols
2561 : &objfile->static_psymbols,
2562 0, (CORE_ADDR) 0, cu->language, objfile);
2565 case DW_TAG_enumerator:
2566 add_psymbol_to_list (actual_name, strlen (actual_name),
2567 VAR_DOMAIN, LOC_CONST,
2568 (cu->language == language_cplus
2569 || cu->language == language_java)
2570 ? &objfile->global_psymbols
2571 : &objfile->static_psymbols,
2572 0, (CORE_ADDR) 0, cu->language, objfile);
2578 /* Check to see if we should scan the name for possible namespace
2579 info. Only do this if this is C++, if we don't have namespace
2580 debugging info in the file, if the psym is of an appropriate type
2581 (otherwise we'll have psym == NULL), and if we actually had a
2582 mangled name to begin with. */
2584 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2585 cases which do not set PSYM above? */
2587 if (cu->language == language_cplus
2588 && cu->has_namespace_info == 0
2590 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
2591 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
2594 if (built_actual_name)
2595 xfree (actual_name);
2598 /* Determine whether a die of type TAG living in a C++ class or
2599 namespace needs to have the name of the scope prepended to the
2600 name listed in the die. */
2603 pdi_needs_namespace (enum dwarf_tag tag)
2607 case DW_TAG_namespace:
2608 case DW_TAG_typedef:
2609 case DW_TAG_class_type:
2610 case DW_TAG_interface_type:
2611 case DW_TAG_structure_type:
2612 case DW_TAG_union_type:
2613 case DW_TAG_enumeration_type:
2614 case DW_TAG_enumerator:
2621 /* Read a partial die corresponding to a namespace; also, add a symbol
2622 corresponding to that namespace to the symbol table. NAMESPACE is
2623 the name of the enclosing namespace. */
2626 add_partial_namespace (struct partial_die_info *pdi,
2627 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2628 int need_pc, struct dwarf2_cu *cu)
2630 struct objfile *objfile = cu->objfile;
2632 /* Add a symbol for the namespace. */
2634 add_partial_symbol (pdi, cu);
2636 /* Now scan partial symbols in that namespace. */
2638 if (pdi->has_children)
2639 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2642 /* Read a partial die corresponding to a Fortran module. */
2645 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
2646 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2648 /* Now scan partial symbols in that module.
2650 FIXME: Support the separate Fortran module namespaces. */
2652 if (pdi->has_children)
2653 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2656 /* Read a partial die corresponding to a subprogram and create a partial
2657 symbol for that subprogram. When the CU language allows it, this
2658 routine also defines a partial symbol for each nested subprogram
2659 that this subprogram contains.
2661 DIE my also be a lexical block, in which case we simply search
2662 recursively for suprograms defined inside that lexical block.
2663 Again, this is only performed when the CU language allows this
2664 type of definitions. */
2667 add_partial_subprogram (struct partial_die_info *pdi,
2668 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2669 int need_pc, struct dwarf2_cu *cu)
2671 if (pdi->tag == DW_TAG_subprogram)
2673 if (pdi->has_pc_info)
2675 if (pdi->lowpc < *lowpc)
2676 *lowpc = pdi->lowpc;
2677 if (pdi->highpc > *highpc)
2678 *highpc = pdi->highpc;
2682 struct objfile *objfile = cu->objfile;
2684 baseaddr = ANOFFSET (objfile->section_offsets,
2685 SECT_OFF_TEXT (objfile));
2686 addrmap_set_empty (objfile->psymtabs_addrmap,
2687 pdi->lowpc, pdi->highpc - 1,
2688 cu->per_cu->psymtab);
2690 if (!pdi->is_declaration)
2691 add_partial_symbol (pdi, cu);
2695 if (! pdi->has_children)
2698 if (cu->language == language_ada)
2700 pdi = pdi->die_child;
2703 fixup_partial_die (pdi, cu);
2704 if (pdi->tag == DW_TAG_subprogram
2705 || pdi->tag == DW_TAG_lexical_block)
2706 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2707 pdi = pdi->die_sibling;
2712 /* See if we can figure out if the class lives in a namespace. We do
2713 this by looking for a member function; its demangled name will
2714 contain namespace info, if there is any. */
2717 guess_structure_name (struct partial_die_info *struct_pdi,
2718 struct dwarf2_cu *cu)
2720 if ((cu->language == language_cplus
2721 || cu->language == language_java)
2722 && cu->has_namespace_info == 0
2723 && struct_pdi->has_children)
2725 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2726 what template types look like, because the demangler
2727 frequently doesn't give the same name as the debug info. We
2728 could fix this by only using the demangled name to get the
2729 prefix (but see comment in read_structure_type). */
2731 struct partial_die_info *child_pdi = struct_pdi->die_child;
2732 struct partial_die_info *real_pdi;
2734 /* If this DIE (this DIE's specification, if any) has a parent, then
2735 we should not do this. We'll prepend the parent's fully qualified
2736 name when we create the partial symbol. */
2738 real_pdi = struct_pdi;
2739 while (real_pdi->has_specification)
2740 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2742 if (real_pdi->die_parent != NULL)
2745 while (child_pdi != NULL)
2747 if (child_pdi->tag == DW_TAG_subprogram)
2749 char *actual_class_name
2750 = language_class_name_from_physname (cu->language_defn,
2752 if (actual_class_name != NULL)
2755 = obsavestring (actual_class_name,
2756 strlen (actual_class_name),
2757 &cu->comp_unit_obstack);
2758 xfree (actual_class_name);
2763 child_pdi = child_pdi->die_sibling;
2768 /* Read a partial die corresponding to an enumeration type. */
2771 add_partial_enumeration (struct partial_die_info *enum_pdi,
2772 struct dwarf2_cu *cu)
2774 struct objfile *objfile = cu->objfile;
2775 bfd *abfd = objfile->obfd;
2776 struct partial_die_info *pdi;
2778 if (enum_pdi->name != NULL)
2779 add_partial_symbol (enum_pdi, cu);
2781 pdi = enum_pdi->die_child;
2784 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2785 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2787 add_partial_symbol (pdi, cu);
2788 pdi = pdi->die_sibling;
2792 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2793 Return the corresponding abbrev, or NULL if the number is zero (indicating
2794 an empty DIE). In either case *BYTES_READ will be set to the length of
2795 the initial number. */
2797 static struct abbrev_info *
2798 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
2799 struct dwarf2_cu *cu)
2801 bfd *abfd = cu->objfile->obfd;
2802 unsigned int abbrev_number;
2803 struct abbrev_info *abbrev;
2805 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2807 if (abbrev_number == 0)
2810 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2813 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2814 bfd_get_filename (abfd));
2820 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2821 Returns a pointer to the end of a series of DIEs, terminated by an empty
2822 DIE. Any children of the skipped DIEs will also be skipped. */
2825 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
2827 struct abbrev_info *abbrev;
2828 unsigned int bytes_read;
2832 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2834 return info_ptr + bytes_read;
2836 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
2840 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2841 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2842 abbrev corresponding to that skipped uleb128 should be passed in
2843 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2847 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
2848 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
2850 unsigned int bytes_read;
2851 struct attribute attr;
2852 bfd *abfd = cu->objfile->obfd;
2853 unsigned int form, i;
2855 for (i = 0; i < abbrev->num_attrs; i++)
2857 /* The only abbrev we care about is DW_AT_sibling. */
2858 if (abbrev->attrs[i].name == DW_AT_sibling)
2860 read_attribute (&attr, &abbrev->attrs[i],
2861 abfd, info_ptr, cu);
2862 if (attr.form == DW_FORM_ref_addr)
2863 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2865 return buffer + dwarf2_get_ref_die_offset (&attr);
2868 /* If it isn't DW_AT_sibling, skip this attribute. */
2869 form = abbrev->attrs[i].form;
2874 case DW_FORM_ref_addr:
2875 info_ptr += cu->header.addr_size;
2895 case DW_FORM_string:
2896 read_string (abfd, info_ptr, &bytes_read);
2897 info_ptr += bytes_read;
2900 info_ptr += cu->header.offset_size;
2903 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2904 info_ptr += bytes_read;
2906 case DW_FORM_block1:
2907 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2909 case DW_FORM_block2:
2910 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2912 case DW_FORM_block4:
2913 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2917 case DW_FORM_ref_udata:
2918 info_ptr = skip_leb128 (abfd, info_ptr);
2920 case DW_FORM_indirect:
2921 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2922 info_ptr += bytes_read;
2923 /* We need to continue parsing from here, so just go back to
2925 goto skip_attribute;
2928 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2929 dwarf_form_name (form),
2930 bfd_get_filename (abfd));
2934 if (abbrev->has_children)
2935 return skip_children (buffer, info_ptr, cu);
2940 /* Locate ORIG_PDI's sibling.
2941 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2945 locate_pdi_sibling (struct partial_die_info *orig_pdi,
2946 gdb_byte *buffer, gdb_byte *info_ptr,
2947 bfd *abfd, struct dwarf2_cu *cu)
2949 /* Do we know the sibling already? */
2951 if (orig_pdi->sibling)
2952 return orig_pdi->sibling;
2954 /* Are there any children to deal with? */
2956 if (!orig_pdi->has_children)
2959 /* Skip the children the long way. */
2961 return skip_children (buffer, info_ptr, cu);
2964 /* Expand this partial symbol table into a full symbol table. */
2967 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2969 /* FIXME: This is barely more than a stub. */
2974 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2980 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2981 gdb_flush (gdb_stdout);
2984 /* Restore our global data. */
2985 dwarf2_per_objfile = objfile_data (pst->objfile,
2986 dwarf2_objfile_data_key);
2988 /* If this psymtab is constructed from a debug-only objfile, the
2989 has_section_at_zero flag will not necessarily be correct. We
2990 can get the correct value for this flag by looking at the data
2991 associated with the (presumably stripped) associated objfile. */
2992 if (pst->objfile->separate_debug_objfile_backlink)
2994 struct dwarf2_per_objfile *dpo_backlink
2995 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
2996 dwarf2_objfile_data_key);
2997 dwarf2_per_objfile->has_section_at_zero
2998 = dpo_backlink->has_section_at_zero;
3001 psymtab_to_symtab_1 (pst);
3003 /* Finish up the debug error message. */
3005 printf_filtered (_("done.\n"));
3010 /* Add PER_CU to the queue. */
3013 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3015 struct dwarf2_queue_item *item;
3018 item = xmalloc (sizeof (*item));
3019 item->per_cu = per_cu;
3022 if (dwarf2_queue == NULL)
3023 dwarf2_queue = item;
3025 dwarf2_queue_tail->next = item;
3027 dwarf2_queue_tail = item;
3030 /* Process the queue. */
3033 process_queue (struct objfile *objfile)
3035 struct dwarf2_queue_item *item, *next_item;
3037 /* The queue starts out with one item, but following a DIE reference
3038 may load a new CU, adding it to the end of the queue. */
3039 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
3041 if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
3042 process_full_comp_unit (item->per_cu);
3044 item->per_cu->queued = 0;
3045 next_item = item->next;
3049 dwarf2_queue_tail = NULL;
3052 /* Free all allocated queue entries. This function only releases anything if
3053 an error was thrown; if the queue was processed then it would have been
3054 freed as we went along. */
3057 dwarf2_release_queue (void *dummy)
3059 struct dwarf2_queue_item *item, *last;
3061 item = dwarf2_queue;
3064 /* Anything still marked queued is likely to be in an
3065 inconsistent state, so discard it. */
3066 if (item->per_cu->queued)
3068 if (item->per_cu->cu != NULL)
3069 free_one_cached_comp_unit (item->per_cu->cu);
3070 item->per_cu->queued = 0;
3078 dwarf2_queue = dwarf2_queue_tail = NULL;
3081 /* Read in full symbols for PST, and anything it depends on. */
3084 psymtab_to_symtab_1 (struct partial_symtab *pst)
3086 struct dwarf2_per_cu_data *per_cu;
3087 struct cleanup *back_to;
3090 for (i = 0; i < pst->number_of_dependencies; i++)
3091 if (!pst->dependencies[i]->readin)
3093 /* Inform about additional files that need to be read in. */
3096 /* FIXME: i18n: Need to make this a single string. */
3097 fputs_filtered (" ", gdb_stdout);
3099 fputs_filtered ("and ", gdb_stdout);
3101 printf_filtered ("%s...", pst->dependencies[i]->filename);
3102 wrap_here (""); /* Flush output */
3103 gdb_flush (gdb_stdout);
3105 psymtab_to_symtab_1 (pst->dependencies[i]);
3108 per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private;
3112 /* It's an include file, no symbols to read for it.
3113 Everything is in the parent symtab. */
3118 back_to = make_cleanup (dwarf2_release_queue, NULL);
3120 queue_comp_unit (per_cu, pst->objfile);
3122 if (per_cu->from_debug_types)
3123 read_signatured_type_at_offset (pst->objfile, per_cu->offset);
3125 load_full_comp_unit (per_cu, pst->objfile);
3127 process_queue (pst->objfile);
3129 /* Age the cache, releasing compilation units that have not
3130 been used recently. */
3131 age_cached_comp_units ();
3133 do_cleanups (back_to);
3136 /* Load the DIEs associated with PER_CU into memory. */
3139 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3141 bfd *abfd = objfile->obfd;
3142 struct dwarf2_cu *cu;
3143 unsigned int offset;
3144 gdb_byte *info_ptr, *beg_of_comp_unit;
3145 struct cleanup *back_to, *free_cu_cleanup;
3146 struct attribute *attr;
3149 gdb_assert (! per_cu->from_debug_types);
3151 /* Set local variables from the partial symbol table info. */
3152 offset = per_cu->offset;
3154 info_ptr = dwarf2_per_objfile->info.buffer + offset;
3155 beg_of_comp_unit = info_ptr;
3157 cu = alloc_one_comp_unit (objfile);
3159 /* If an error occurs while loading, release our storage. */
3160 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3162 /* Read in the comp_unit header. */
3163 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
3165 /* Complete the cu_header. */
3166 cu->header.offset = offset;
3167 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3169 /* Read the abbrevs for this compilation unit. */
3170 dwarf2_read_abbrevs (abfd, cu);
3171 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
3173 /* Link this compilation unit into the compilation unit tree. */
3175 cu->per_cu = per_cu;
3176 cu->type_hash = per_cu->type_hash;
3178 cu->dies = read_comp_unit (info_ptr, cu);
3180 /* We try not to read any attributes in this function, because not
3181 all objfiles needed for references have been loaded yet, and symbol
3182 table processing isn't initialized. But we have to set the CU language,
3183 or we won't be able to build types correctly. */
3184 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
3186 set_cu_language (DW_UNSND (attr), cu);
3188 set_cu_language (language_minimal, cu);
3190 /* Link this CU into read_in_chain. */
3191 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3192 dwarf2_per_objfile->read_in_chain = per_cu;
3194 do_cleanups (back_to);
3196 /* We've successfully allocated this compilation unit. Let our caller
3197 clean it up when finished with it. */
3198 discard_cleanups (free_cu_cleanup);
3201 /* Generate full symbol information for PST and CU, whose DIEs have
3202 already been loaded into memory. */
3205 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3207 struct partial_symtab *pst = per_cu->psymtab;
3208 struct dwarf2_cu *cu = per_cu->cu;
3209 struct objfile *objfile = pst->objfile;
3210 bfd *abfd = objfile->obfd;
3211 CORE_ADDR lowpc, highpc;
3212 struct symtab *symtab;
3213 struct cleanup *back_to;
3216 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3219 back_to = make_cleanup (really_free_pendings, NULL);
3221 cu->list_in_scope = &file_symbols;
3223 dwarf2_find_base_address (cu->dies, cu);
3225 /* Do line number decoding in read_file_scope () */
3226 process_die (cu->dies, cu);
3228 /* Some compilers don't define a DW_AT_high_pc attribute for the
3229 compilation unit. If the DW_AT_high_pc is missing, synthesize
3230 it, by scanning the DIE's below the compilation unit. */
3231 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
3233 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
3235 /* Set symtab language to language from DW_AT_language.
3236 If the compilation is from a C file generated by language preprocessors,
3237 do not set the language if it was already deduced by start_subfile. */
3239 && !(cu->language == language_c && symtab->language != language_c))
3241 symtab->language = cu->language;
3243 pst->symtab = symtab;
3246 do_cleanups (back_to);
3249 /* Process a die and its children. */
3252 process_die (struct die_info *die, struct dwarf2_cu *cu)
3256 case DW_TAG_padding:
3258 case DW_TAG_compile_unit:
3259 read_file_scope (die, cu);
3261 case DW_TAG_type_unit:
3262 read_type_unit_scope (die, cu);
3264 case DW_TAG_subprogram:
3265 case DW_TAG_inlined_subroutine:
3266 read_func_scope (die, cu);
3268 case DW_TAG_lexical_block:
3269 case DW_TAG_try_block:
3270 case DW_TAG_catch_block:
3271 read_lexical_block_scope (die, cu);
3273 case DW_TAG_class_type:
3274 case DW_TAG_interface_type:
3275 case DW_TAG_structure_type:
3276 case DW_TAG_union_type:
3277 process_structure_scope (die, cu);
3279 case DW_TAG_enumeration_type:
3280 process_enumeration_scope (die, cu);
3283 /* These dies have a type, but processing them does not create
3284 a symbol or recurse to process the children. Therefore we can
3285 read them on-demand through read_type_die. */
3286 case DW_TAG_subroutine_type:
3287 case DW_TAG_set_type:
3288 case DW_TAG_array_type:
3289 case DW_TAG_pointer_type:
3290 case DW_TAG_ptr_to_member_type:
3291 case DW_TAG_reference_type:
3292 case DW_TAG_string_type:
3295 case DW_TAG_base_type:
3296 case DW_TAG_subrange_type:
3297 case DW_TAG_typedef:
3298 /* Add a typedef symbol for the type definition, if it has a
3300 new_symbol (die, read_type_die (die, cu), cu);
3302 case DW_TAG_common_block:
3303 read_common_block (die, cu);
3305 case DW_TAG_common_inclusion:
3307 case DW_TAG_namespace:
3308 processing_has_namespace_info = 1;
3309 read_namespace (die, cu);
3312 read_module (die, cu);
3314 case DW_TAG_imported_declaration:
3315 case DW_TAG_imported_module:
3316 processing_has_namespace_info = 1;
3317 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
3318 || cu->language != language_fortran))
3319 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
3320 dwarf_tag_name (die->tag));
3321 read_import_statement (die, cu);
3324 new_symbol (die, NULL, cu);
3329 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3330 If scope qualifiers are appropriate they will be added. The result
3331 will be allocated on the objfile_obstack, or NULL if the DIE does
3335 dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
3337 struct attribute *attr;
3338 char *prefix, *name;
3339 struct ui_file *buf = NULL;
3341 name = dwarf2_name (die, cu);
3345 /* These are the only languages we know how to qualify names in. */
3346 if (cu->language != language_cplus
3347 && cu->language != language_java)
3350 /* If no prefix is necessary for this type of DIE, return the
3351 unqualified name. The other three tags listed could be handled
3352 in pdi_needs_namespace, but that requires broader changes. */
3353 if (!pdi_needs_namespace (die->tag)
3354 && die->tag != DW_TAG_subprogram
3355 && die->tag != DW_TAG_variable
3356 && die->tag != DW_TAG_member)
3359 prefix = determine_prefix (die, cu);
3360 if (*prefix != '\0')
3361 name = typename_concat (&cu->objfile->objfile_obstack, prefix,
3367 /* Read the import statement specified by the given die and record it. */
3370 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
3372 struct attribute *import_attr;
3373 struct die_info *imported_die;
3374 struct dwarf2_cu *imported_cu;
3375 const char *imported_name;
3376 const char *imported_name_prefix;
3377 const char *import_prefix;
3378 char *canonical_name;
3380 import_attr = dwarf2_attr (die, DW_AT_import, cu);
3381 if (import_attr == NULL)
3383 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
3384 dwarf_tag_name (die->tag));
3389 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
3390 imported_name = dwarf2_name (imported_die, imported_cu);
3391 if (imported_name == NULL)
3393 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3395 The import in the following code:
3409 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3410 <52> DW_AT_decl_file : 1
3411 <53> DW_AT_decl_line : 6
3412 <54> DW_AT_import : <0x75>
3413 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3415 <5b> DW_AT_decl_file : 1
3416 <5c> DW_AT_decl_line : 2
3417 <5d> DW_AT_type : <0x6e>
3419 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3420 <76> DW_AT_byte_size : 4
3421 <77> DW_AT_encoding : 5 (signed)
3423 imports the wrong die ( 0x75 instead of 0x58 ).
3424 This case will be ignored until the gcc bug is fixed. */
3428 /* FIXME: dwarf2_name (die); for the local name after import. */
3430 /* Figure out where the statement is being imported to. */
3431 import_prefix = determine_prefix (die, cu);
3433 /* Figure out what the scope of the imported die is and prepend it
3434 to the name of the imported die. */
3435 imported_name_prefix = determine_prefix (imported_die, imported_cu);
3437 if (strlen (imported_name_prefix) > 0)
3439 canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1);
3440 strcpy (canonical_name, imported_name_prefix);
3441 strcat (canonical_name, "::");
3442 strcat (canonical_name, imported_name);
3446 canonical_name = alloca (strlen (imported_name) + 1);
3447 strcpy (canonical_name, imported_name);
3450 using_directives = cp_add_using (import_prefix,canonical_name, using_directives);
3454 initialize_cu_func_list (struct dwarf2_cu *cu)
3456 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
3460 free_cu_line_header (void *arg)
3462 struct dwarf2_cu *cu = arg;
3464 free_line_header (cu->line_header);
3465 cu->line_header = NULL;
3469 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3471 struct objfile *objfile = cu->objfile;
3472 struct comp_unit_head *cu_header = &cu->header;
3473 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3474 CORE_ADDR lowpc = ((CORE_ADDR) -1);
3475 CORE_ADDR highpc = ((CORE_ADDR) 0);
3476 struct attribute *attr;
3478 char *comp_dir = NULL;
3479 struct die_info *child_die;
3480 bfd *abfd = objfile->obfd;
3481 struct line_header *line_header = 0;
3484 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3486 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
3488 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3489 from finish_block. */
3490 if (lowpc == ((CORE_ADDR) -1))
3495 /* Find the filename. Do not use dwarf2_name here, since the filename
3496 is not a source language identifier. */
3497 attr = dwarf2_attr (die, DW_AT_name, cu);
3500 name = DW_STRING (attr);
3503 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3505 comp_dir = DW_STRING (attr);
3506 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3508 comp_dir = ldirname (name);
3509 if (comp_dir != NULL)
3510 make_cleanup (xfree, comp_dir);
3512 if (comp_dir != NULL)
3514 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3515 directory, get rid of it. */
3516 char *cp = strchr (comp_dir, ':');
3518 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3525 attr = dwarf2_attr (die, DW_AT_language, cu);
3528 set_cu_language (DW_UNSND (attr), cu);
3531 attr = dwarf2_attr (die, DW_AT_producer, cu);
3533 cu->producer = DW_STRING (attr);
3535 /* We assume that we're processing GCC output. */
3536 processing_gcc_compilation = 2;
3538 processing_has_namespace_info = 0;
3540 start_symtab (name, comp_dir, lowpc);
3541 record_debugformat ("DWARF 2");
3542 record_producer (cu->producer);
3544 initialize_cu_func_list (cu);
3546 /* Decode line number information if present. We do this before
3547 processing child DIEs, so that the line header table is available
3548 for DW_AT_decl_file. */
3549 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3552 unsigned int line_offset = DW_UNSND (attr);
3553 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
3556 cu->line_header = line_header;
3557 make_cleanup (free_cu_line_header, cu);
3558 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
3562 /* Process all dies in compilation unit. */
3563 if (die->child != NULL)
3565 child_die = die->child;
3566 while (child_die && child_die->tag)
3568 process_die (child_die, cu);
3569 child_die = sibling_die (child_die);
3573 /* Decode macro information, if present. Dwarf 2 macro information
3574 refers to information in the line number info statement program
3575 header, so we can only read it if we've read the header
3577 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
3578 if (attr && line_header)
3580 unsigned int macro_offset = DW_UNSND (attr);
3581 dwarf_decode_macros (line_header, macro_offset,
3582 comp_dir, abfd, cu);
3584 do_cleanups (back_to);
3587 /* For TUs we want to skip the first top level sibling if it's not the
3588 actual type being defined by this TU. In this case the first top
3589 level sibling is there to provide context only. */
3592 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
3594 struct objfile *objfile = cu->objfile;
3595 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3597 struct attribute *attr;
3599 char *comp_dir = NULL;
3600 struct die_info *child_die;
3601 bfd *abfd = objfile->obfd;
3602 struct line_header *line_header = 0;
3604 /* start_symtab needs a low pc, but we don't really have one.
3605 Do what read_file_scope would do in the absence of such info. */
3606 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3608 /* Find the filename. Do not use dwarf2_name here, since the filename
3609 is not a source language identifier. */
3610 attr = dwarf2_attr (die, DW_AT_name, cu);
3612 name = DW_STRING (attr);
3614 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3616 comp_dir = DW_STRING (attr);
3617 else if (name != NULL && IS_ABSOLUTE_PATH (name))
3619 comp_dir = ldirname (name);
3620 if (comp_dir != NULL)
3621 make_cleanup (xfree, comp_dir);
3627 attr = dwarf2_attr (die, DW_AT_language, cu);
3629 set_cu_language (DW_UNSND (attr), cu);
3631 /* This isn't technically needed today. It is done for symmetry
3632 with read_file_scope. */
3633 attr = dwarf2_attr (die, DW_AT_producer, cu);
3635 cu->producer = DW_STRING (attr);
3637 /* We assume that we're processing GCC output. */
3638 processing_gcc_compilation = 2;
3640 processing_has_namespace_info = 0;
3642 start_symtab (name, comp_dir, lowpc);
3643 record_debugformat ("DWARF 2");
3644 record_producer (cu->producer);
3646 /* Process the dies in the type unit. */
3647 if (die->child == NULL)
3649 dump_die_for_error (die);
3650 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3651 bfd_get_filename (abfd));
3654 child_die = die->child;
3656 while (child_die && child_die->tag)
3658 process_die (child_die, cu);
3660 child_die = sibling_die (child_die);
3663 do_cleanups (back_to);
3667 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
3668 struct dwarf2_cu *cu)
3670 struct function_range *thisfn;
3672 thisfn = (struct function_range *)
3673 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
3674 thisfn->name = name;
3675 thisfn->lowpc = lowpc;
3676 thisfn->highpc = highpc;
3677 thisfn->seen_line = 0;
3678 thisfn->next = NULL;
3680 if (cu->last_fn == NULL)
3681 cu->first_fn = thisfn;
3683 cu->last_fn->next = thisfn;
3685 cu->last_fn = thisfn;
3688 /* qsort helper for inherit_abstract_dies. */
3691 unsigned_int_compar (const void *ap, const void *bp)
3693 unsigned int a = *(unsigned int *) ap;
3694 unsigned int b = *(unsigned int *) bp;
3696 return (a > b) - (b > a);
3699 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3700 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3701 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3704 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
3706 struct die_info *child_die;
3707 unsigned die_children_count;
3708 /* CU offsets which were referenced by children of the current DIE. */
3710 unsigned *offsets_end, *offsetp;
3711 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3712 struct die_info *origin_die;
3713 /* Iterator of the ORIGIN_DIE children. */
3714 struct die_info *origin_child_die;
3715 struct cleanup *cleanups;
3716 struct attribute *attr;
3718 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
3722 origin_die = follow_die_ref (die, attr, &cu);
3723 if (die->tag != origin_die->tag
3724 && !(die->tag == DW_TAG_inlined_subroutine
3725 && origin_die->tag == DW_TAG_subprogram))
3726 complaint (&symfile_complaints,
3727 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3728 die->offset, origin_die->offset);
3730 child_die = die->child;
3731 die_children_count = 0;
3732 while (child_die && child_die->tag)
3734 child_die = sibling_die (child_die);
3735 die_children_count++;
3737 offsets = xmalloc (sizeof (*offsets) * die_children_count);
3738 cleanups = make_cleanup (xfree, offsets);
3740 offsets_end = offsets;
3741 child_die = die->child;
3742 while (child_die && child_die->tag)
3744 /* For each CHILD_DIE, find the corresponding child of
3745 ORIGIN_DIE. If there is more than one layer of
3746 DW_AT_abstract_origin, follow them all; there shouldn't be,
3747 but GCC versions at least through 4.4 generate this (GCC PR
3749 struct die_info *child_origin_die = child_die;
3752 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu);
3755 child_origin_die = follow_die_ref (child_origin_die, attr, &cu);
3758 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3759 counterpart may exist. */
3760 if (child_origin_die != child_die)
3762 if (child_die->tag != child_origin_die->tag
3763 && !(child_die->tag == DW_TAG_inlined_subroutine
3764 && child_origin_die->tag == DW_TAG_subprogram))
3765 complaint (&symfile_complaints,
3766 _("Child DIE 0x%x and its abstract origin 0x%x have "
3767 "different tags"), child_die->offset,
3768 child_origin_die->offset);
3769 if (child_origin_die->parent != origin_die)
3770 complaint (&symfile_complaints,
3771 _("Child DIE 0x%x and its abstract origin 0x%x have "
3772 "different parents"), child_die->offset,
3773 child_origin_die->offset);
3775 *offsets_end++ = child_origin_die->offset;
3777 child_die = sibling_die (child_die);
3779 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
3780 unsigned_int_compar);
3781 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
3782 if (offsetp[-1] == *offsetp)
3783 complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer "
3784 "to DIE 0x%x as their abstract origin"),
3785 die->offset, *offsetp);
3788 origin_child_die = origin_die->child;
3789 while (origin_child_die && origin_child_die->tag)
3791 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3792 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
3794 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
3796 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3797 process_die (origin_child_die, cu);
3799 origin_child_die = sibling_die (origin_child_die);
3802 do_cleanups (cleanups);
3806 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
3808 struct objfile *objfile = cu->objfile;
3809 struct context_stack *new;
3812 struct die_info *child_die;
3813 struct attribute *attr, *call_line, *call_file;
3816 struct block *block;
3817 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
3821 /* If we do not have call site information, we can't show the
3822 caller of this inlined function. That's too confusing, so
3823 only use the scope for local variables. */
3824 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
3825 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
3826 if (call_line == NULL || call_file == NULL)
3828 read_lexical_block_scope (die, cu);
3833 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3835 name = dwarf2_linkage_name (die, cu);
3837 /* Ignore functions with missing or empty names and functions with
3838 missing or invalid low and high pc attributes. */
3839 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
3845 /* Record the function range for dwarf_decode_lines. */
3846 add_to_cu_func_list (name, lowpc, highpc, cu);
3848 new = push_context (0, lowpc);
3849 new->name = new_symbol (die, read_type_die (die, cu), cu);
3851 /* If there is a location expression for DW_AT_frame_base, record
3853 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
3855 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3856 expression is being recorded directly in the function's symbol
3857 and not in a separate frame-base object. I guess this hack is
3858 to avoid adding some sort of frame-base adjunct/annex to the
3859 function's symbol :-(. The problem with doing this is that it
3860 results in a function symbol with a location expression that
3861 has nothing to do with the location of the function, ouch! The
3862 relationship should be: a function's symbol has-a frame base; a
3863 frame-base has-a location expression. */
3864 dwarf2_symbol_mark_computed (attr, new->name, cu);
3866 cu->list_in_scope = &local_symbols;
3868 if (die->child != NULL)
3870 child_die = die->child;
3871 while (child_die && child_die->tag)
3873 process_die (child_die, cu);
3874 child_die = sibling_die (child_die);
3878 inherit_abstract_dies (die, cu);
3880 new = pop_context ();
3881 /* Make a block for the local symbols within. */
3882 block = finish_block (new->name, &local_symbols, new->old_blocks,
3883 lowpc, highpc, objfile);
3885 /* For C++, set the block's scope. */
3886 if (cu->language == language_cplus)
3887 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
3888 determine_prefix (die, cu),
3889 processing_has_namespace_info);
3891 /* If we have address ranges, record them. */
3892 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3894 /* In C++, we can have functions nested inside functions (e.g., when
3895 a function declares a class that has methods). This means that
3896 when we finish processing a function scope, we may need to go
3897 back to building a containing block's symbol lists. */
3898 local_symbols = new->locals;
3899 param_symbols = new->params;
3900 using_directives = new->using_directives;
3902 /* If we've finished processing a top-level function, subsequent
3903 symbols go in the file symbol list. */
3904 if (outermost_context_p ())
3905 cu->list_in_scope = &file_symbols;
3908 /* Process all the DIES contained within a lexical block scope. Start
3909 a new scope, process the dies, and then close the scope. */
3912 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
3914 struct objfile *objfile = cu->objfile;
3915 struct context_stack *new;
3916 CORE_ADDR lowpc, highpc;
3917 struct die_info *child_die;
3920 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3922 /* Ignore blocks with missing or invalid low and high pc attributes. */
3923 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3924 as multiple lexical blocks? Handling children in a sane way would
3925 be nasty. Might be easier to properly extend generic blocks to
3927 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
3932 push_context (0, lowpc);
3933 if (die->child != NULL)
3935 child_die = die->child;
3936 while (child_die && child_die->tag)
3938 process_die (child_die, cu);
3939 child_die = sibling_die (child_die);
3942 new = pop_context ();
3944 if (local_symbols != NULL)
3947 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
3950 /* Note that recording ranges after traversing children, as we
3951 do here, means that recording a parent's ranges entails
3952 walking across all its children's ranges as they appear in
3953 the address map, which is quadratic behavior.
3955 It would be nicer to record the parent's ranges before
3956 traversing its children, simply overriding whatever you find
3957 there. But since we don't even decide whether to create a
3958 block until after we've traversed its children, that's hard
3960 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3962 local_symbols = new->locals;
3963 using_directives = new->using_directives;
3966 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3967 Return 1 if the attributes are present and valid, otherwise, return 0.
3968 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3971 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
3972 CORE_ADDR *high_return, struct dwarf2_cu *cu,
3973 struct partial_symtab *ranges_pst)
3975 struct objfile *objfile = cu->objfile;
3976 struct comp_unit_head *cu_header = &cu->header;
3977 bfd *obfd = objfile->obfd;
3978 unsigned int addr_size = cu_header->addr_size;
3979 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3980 /* Base address selection entry. */
3991 found_base = cu->base_known;
3992 base = cu->base_address;
3994 if (offset >= dwarf2_per_objfile->ranges.size)
3996 complaint (&symfile_complaints,
3997 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4001 buffer = dwarf2_per_objfile->ranges.buffer + offset;
4003 /* Read in the largest possible address. */
4004 marker = read_address (obfd, buffer, cu, &dummy);
4005 if ((marker & mask) == mask)
4007 /* If we found the largest possible address, then
4008 read the base address. */
4009 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4010 buffer += 2 * addr_size;
4011 offset += 2 * addr_size;
4017 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4021 CORE_ADDR range_beginning, range_end;
4023 range_beginning = read_address (obfd, buffer, cu, &dummy);
4024 buffer += addr_size;
4025 range_end = read_address (obfd, buffer, cu, &dummy);
4026 buffer += addr_size;
4027 offset += 2 * addr_size;
4029 /* An end of list marker is a pair of zero addresses. */
4030 if (range_beginning == 0 && range_end == 0)
4031 /* Found the end of list entry. */
4034 /* Each base address selection entry is a pair of 2 values.
4035 The first is the largest possible address, the second is
4036 the base address. Check for a base address here. */
4037 if ((range_beginning & mask) == mask)
4039 /* If we found the largest possible address, then
4040 read the base address. */
4041 base = read_address (obfd, buffer + addr_size, cu, &dummy);
4048 /* We have no valid base address for the ranges
4050 complaint (&symfile_complaints,
4051 _("Invalid .debug_ranges data (no base address)"));
4055 range_beginning += base;
4058 if (ranges_pst != NULL && range_beginning < range_end)
4059 addrmap_set_empty (objfile->psymtabs_addrmap,
4060 range_beginning + baseaddr, range_end - 1 + baseaddr,
4063 /* FIXME: This is recording everything as a low-high
4064 segment of consecutive addresses. We should have a
4065 data structure for discontiguous block ranges
4069 low = range_beginning;
4075 if (range_beginning < low)
4076 low = range_beginning;
4077 if (range_end > high)
4083 /* If the first entry is an end-of-list marker, the range
4084 describes an empty scope, i.e. no instructions. */
4090 *high_return = high;
4094 /* Get low and high pc attributes from a die. Return 1 if the attributes
4095 are present and valid, otherwise, return 0. Return -1 if the range is
4096 discontinuous, i.e. derived from DW_AT_ranges information. */
4098 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
4099 CORE_ADDR *highpc, struct dwarf2_cu *cu,
4100 struct partial_symtab *pst)
4102 struct attribute *attr;
4107 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4110 high = DW_ADDR (attr);
4111 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4113 low = DW_ADDR (attr);
4115 /* Found high w/o low attribute. */
4118 /* Found consecutive range of addresses. */
4123 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4126 /* Value of the DW_AT_ranges attribute is the offset in the
4127 .debug_ranges section. */
4128 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
4130 /* Found discontinuous range of addresses. */
4138 /* When using the GNU linker, .gnu.linkonce. sections are used to
4139 eliminate duplicate copies of functions and vtables and such.
4140 The linker will arbitrarily choose one and discard the others.
4141 The AT_*_pc values for such functions refer to local labels in
4142 these sections. If the section from that file was discarded, the
4143 labels are not in the output, so the relocs get a value of 0.
4144 If this is a discarded function, mark the pc bounds as invalid,
4145 so that GDB will ignore it. */
4146 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
4154 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4155 its low and high PC addresses. Do nothing if these addresses could not
4156 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4157 and HIGHPC to the high address if greater than HIGHPC. */
4160 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
4161 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4162 struct dwarf2_cu *cu)
4164 CORE_ADDR low, high;
4165 struct die_info *child = die->child;
4167 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
4169 *lowpc = min (*lowpc, low);
4170 *highpc = max (*highpc, high);
4173 /* If the language does not allow nested subprograms (either inside
4174 subprograms or lexical blocks), we're done. */
4175 if (cu->language != language_ada)
4178 /* Check all the children of the given DIE. If it contains nested
4179 subprograms, then check their pc bounds. Likewise, we need to
4180 check lexical blocks as well, as they may also contain subprogram
4182 while (child && child->tag)
4184 if (child->tag == DW_TAG_subprogram
4185 || child->tag == DW_TAG_lexical_block)
4186 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
4187 child = sibling_die (child);
4191 /* Get the low and high pc's represented by the scope DIE, and store
4192 them in *LOWPC and *HIGHPC. If the correct values can't be
4193 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4196 get_scope_pc_bounds (struct die_info *die,
4197 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4198 struct dwarf2_cu *cu)
4200 CORE_ADDR best_low = (CORE_ADDR) -1;
4201 CORE_ADDR best_high = (CORE_ADDR) 0;
4202 CORE_ADDR current_low, current_high;
4204 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
4206 best_low = current_low;
4207 best_high = current_high;
4211 struct die_info *child = die->child;
4213 while (child && child->tag)
4215 switch (child->tag) {
4216 case DW_TAG_subprogram:
4217 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
4219 case DW_TAG_namespace:
4220 /* FIXME: carlton/2004-01-16: Should we do this for
4221 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4222 that current GCC's always emit the DIEs corresponding
4223 to definitions of methods of classes as children of a
4224 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4225 the DIEs giving the declarations, which could be
4226 anywhere). But I don't see any reason why the
4227 standards says that they have to be there. */
4228 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
4230 if (current_low != ((CORE_ADDR) -1))
4232 best_low = min (best_low, current_low);
4233 best_high = max (best_high, current_high);
4241 child = sibling_die (child);
4246 *highpc = best_high;
4249 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4252 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
4253 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
4255 struct attribute *attr;
4257 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
4260 CORE_ADDR high = DW_ADDR (attr);
4261 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
4264 CORE_ADDR low = DW_ADDR (attr);
4265 record_block_range (block, baseaddr + low, baseaddr + high - 1);
4269 attr = dwarf2_attr (die, DW_AT_ranges, cu);
4272 bfd *obfd = cu->objfile->obfd;
4274 /* The value of the DW_AT_ranges attribute is the offset of the
4275 address range list in the .debug_ranges section. */
4276 unsigned long offset = DW_UNSND (attr);
4277 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
4279 /* For some target architectures, but not others, the
4280 read_address function sign-extends the addresses it returns.
4281 To recognize base address selection entries, we need a
4283 unsigned int addr_size = cu->header.addr_size;
4284 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
4286 /* The base address, to which the next pair is relative. Note
4287 that this 'base' is a DWARF concept: most entries in a range
4288 list are relative, to reduce the number of relocs against the
4289 debugging information. This is separate from this function's
4290 'baseaddr' argument, which GDB uses to relocate debugging
4291 information from a shared library based on the address at
4292 which the library was loaded. */
4293 CORE_ADDR base = cu->base_address;
4294 int base_known = cu->base_known;
4296 if (offset >= dwarf2_per_objfile->ranges.size)
4298 complaint (&symfile_complaints,
4299 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4306 unsigned int bytes_read;
4307 CORE_ADDR start, end;
4309 start = read_address (obfd, buffer, cu, &bytes_read);
4310 buffer += bytes_read;
4311 end = read_address (obfd, buffer, cu, &bytes_read);
4312 buffer += bytes_read;
4314 /* Did we find the end of the range list? */
4315 if (start == 0 && end == 0)
4318 /* Did we find a base address selection entry? */
4319 else if ((start & base_select_mask) == base_select_mask)
4325 /* We found an ordinary address range. */
4330 complaint (&symfile_complaints,
4331 _("Invalid .debug_ranges data (no base address)"));
4335 record_block_range (block,
4336 baseaddr + base + start,
4337 baseaddr + base + end - 1);
4343 /* Add an aggregate field to the field list. */
4346 dwarf2_add_field (struct field_info *fip, struct die_info *die,
4347 struct dwarf2_cu *cu)
4349 struct objfile *objfile = cu->objfile;
4350 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4351 struct nextfield *new_field;
4352 struct attribute *attr;
4354 char *fieldname = "";
4356 /* Allocate a new field list entry and link it in. */
4357 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4358 make_cleanup (xfree, new_field);
4359 memset (new_field, 0, sizeof (struct nextfield));
4361 if (die->tag == DW_TAG_inheritance)
4363 new_field->next = fip->baseclasses;
4364 fip->baseclasses = new_field;
4368 new_field->next = fip->fields;
4369 fip->fields = new_field;
4373 /* Handle accessibility and virtuality of field.
4374 The default accessibility for members is public, the default
4375 accessibility for inheritance is private. */
4376 if (die->tag != DW_TAG_inheritance)
4377 new_field->accessibility = DW_ACCESS_public;
4379 new_field->accessibility = DW_ACCESS_private;
4380 new_field->virtuality = DW_VIRTUALITY_none;
4382 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4384 new_field->accessibility = DW_UNSND (attr);
4385 if (new_field->accessibility != DW_ACCESS_public)
4386 fip->non_public_fields = 1;
4387 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
4389 new_field->virtuality = DW_UNSND (attr);
4391 fp = &new_field->field;
4393 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
4395 /* Data member other than a C++ static data member. */
4397 /* Get type of field. */
4398 fp->type = die_type (die, cu);
4400 SET_FIELD_BITPOS (*fp, 0);
4402 /* Get bit size of field (zero if none). */
4403 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
4406 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
4410 FIELD_BITSIZE (*fp) = 0;
4413 /* Get bit offset of field. */
4414 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4417 int byte_offset = 0;
4419 if (attr_form_is_section_offset (attr))
4420 dwarf2_complex_location_expr_complaint ();
4421 else if (attr_form_is_constant (attr))
4422 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4423 else if (attr_form_is_block (attr))
4424 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4426 dwarf2_complex_location_expr_complaint ();
4428 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4430 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
4433 if (gdbarch_bits_big_endian (gdbarch))
4435 /* For big endian bits, the DW_AT_bit_offset gives the
4436 additional bit offset from the MSB of the containing
4437 anonymous object to the MSB of the field. We don't
4438 have to do anything special since we don't need to
4439 know the size of the anonymous object. */
4440 FIELD_BITPOS (*fp) += DW_UNSND (attr);
4444 /* For little endian bits, compute the bit offset to the
4445 MSB of the anonymous object, subtract off the number of
4446 bits from the MSB of the field to the MSB of the
4447 object, and then subtract off the number of bits of
4448 the field itself. The result is the bit offset of
4449 the LSB of the field. */
4451 int bit_offset = DW_UNSND (attr);
4453 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4456 /* The size of the anonymous object containing
4457 the bit field is explicit, so use the
4458 indicated size (in bytes). */
4459 anonymous_size = DW_UNSND (attr);
4463 /* The size of the anonymous object containing
4464 the bit field must be inferred from the type
4465 attribute of the data member containing the
4467 anonymous_size = TYPE_LENGTH (fp->type);
4469 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
4470 - bit_offset - FIELD_BITSIZE (*fp);
4474 /* Get name of field. */
4475 fieldname = dwarf2_name (die, cu);
4476 if (fieldname == NULL)
4479 /* The name is already allocated along with this objfile, so we don't
4480 need to duplicate it for the type. */
4481 fp->name = fieldname;
4483 /* Change accessibility for artificial fields (e.g. virtual table
4484 pointer or virtual base class pointer) to private. */
4485 if (dwarf2_attr (die, DW_AT_artificial, cu))
4487 new_field->accessibility = DW_ACCESS_private;
4488 fip->non_public_fields = 1;
4491 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
4493 /* C++ static member. */
4495 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4496 is a declaration, but all versions of G++ as of this writing
4497 (so through at least 3.2.1) incorrectly generate
4498 DW_TAG_variable tags. */
4502 /* Get name of field. */
4503 fieldname = dwarf2_name (die, cu);
4504 if (fieldname == NULL)
4507 /* Get physical name. */
4508 physname = dwarf2_linkage_name (die, cu);
4510 /* The name is already allocated along with this objfile, so we don't
4511 need to duplicate it for the type. */
4512 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
4513 FIELD_TYPE (*fp) = die_type (die, cu);
4514 FIELD_NAME (*fp) = fieldname;
4516 else if (die->tag == DW_TAG_inheritance)
4518 /* C++ base class field. */
4519 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
4522 int byte_offset = 0;
4524 if (attr_form_is_section_offset (attr))
4525 dwarf2_complex_location_expr_complaint ();
4526 else if (attr_form_is_constant (attr))
4527 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
4528 else if (attr_form_is_block (attr))
4529 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
4531 dwarf2_complex_location_expr_complaint ();
4533 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
4535 FIELD_BITSIZE (*fp) = 0;
4536 FIELD_TYPE (*fp) = die_type (die, cu);
4537 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
4538 fip->nbaseclasses++;
4542 /* Create the vector of fields, and attach it to the type. */
4545 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
4546 struct dwarf2_cu *cu)
4548 int nfields = fip->nfields;
4550 /* Record the field count, allocate space for the array of fields,
4551 and create blank accessibility bitfields if necessary. */
4552 TYPE_NFIELDS (type) = nfields;
4553 TYPE_FIELDS (type) = (struct field *)
4554 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4555 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4557 if (fip->non_public_fields)
4559 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4561 TYPE_FIELD_PRIVATE_BITS (type) =
4562 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4563 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4565 TYPE_FIELD_PROTECTED_BITS (type) =
4566 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4567 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4569 TYPE_FIELD_IGNORE_BITS (type) =
4570 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4571 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4574 /* If the type has baseclasses, allocate and clear a bit vector for
4575 TYPE_FIELD_VIRTUAL_BITS. */
4576 if (fip->nbaseclasses)
4578 int num_bytes = B_BYTES (fip->nbaseclasses);
4579 unsigned char *pointer;
4581 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4582 pointer = TYPE_ALLOC (type, num_bytes);
4583 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
4584 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
4585 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
4588 /* Copy the saved-up fields into the field vector. Start from the head
4589 of the list, adding to the tail of the field array, so that they end
4590 up in the same order in the array in which they were added to the list. */
4591 while (nfields-- > 0)
4593 struct nextfield *fieldp;
4597 fieldp = fip->fields;
4598 fip->fields = fieldp->next;
4602 fieldp = fip->baseclasses;
4603 fip->baseclasses = fieldp->next;
4606 TYPE_FIELD (type, nfields) = fieldp->field;
4607 switch (fieldp->accessibility)
4609 case DW_ACCESS_private:
4610 SET_TYPE_FIELD_PRIVATE (type, nfields);
4613 case DW_ACCESS_protected:
4614 SET_TYPE_FIELD_PROTECTED (type, nfields);
4617 case DW_ACCESS_public:
4621 /* Unknown accessibility. Complain and treat it as public. */
4623 complaint (&symfile_complaints, _("unsupported accessibility %d"),
4624 fieldp->accessibility);
4628 if (nfields < fip->nbaseclasses)
4630 switch (fieldp->virtuality)
4632 case DW_VIRTUALITY_virtual:
4633 case DW_VIRTUALITY_pure_virtual:
4634 SET_TYPE_FIELD_VIRTUAL (type, nfields);
4641 /* Add a member function to the proper fieldlist. */
4644 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
4645 struct type *type, struct dwarf2_cu *cu)
4647 struct objfile *objfile = cu->objfile;
4648 struct attribute *attr;
4649 struct fnfieldlist *flp;
4651 struct fn_field *fnp;
4654 struct nextfnfield *new_fnfield;
4655 struct type *this_type;
4657 /* Get name of member function. */
4658 fieldname = dwarf2_name (die, cu);
4659 if (fieldname == NULL)
4662 /* Get the mangled name. */
4663 physname = dwarf2_linkage_name (die, cu);
4665 /* Look up member function name in fieldlist. */
4666 for (i = 0; i < fip->nfnfields; i++)
4668 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
4672 /* Create new list element if necessary. */
4673 if (i < fip->nfnfields)
4674 flp = &fip->fnfieldlists[i];
4677 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
4679 fip->fnfieldlists = (struct fnfieldlist *)
4680 xrealloc (fip->fnfieldlists,
4681 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
4682 * sizeof (struct fnfieldlist));
4683 if (fip->nfnfields == 0)
4684 make_cleanup (free_current_contents, &fip->fnfieldlists);
4686 flp = &fip->fnfieldlists[fip->nfnfields];
4687 flp->name = fieldname;
4693 /* Create a new member function field and chain it to the field list
4695 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
4696 make_cleanup (xfree, new_fnfield);
4697 memset (new_fnfield, 0, sizeof (struct nextfnfield));
4698 new_fnfield->next = flp->head;
4699 flp->head = new_fnfield;
4702 /* Fill in the member function field info. */
4703 fnp = &new_fnfield->fnfield;
4704 /* The name is already allocated along with this objfile, so we don't
4705 need to duplicate it for the type. */
4706 fnp->physname = physname ? physname : "";
4707 fnp->type = alloc_type (objfile);
4708 this_type = read_type_die (die, cu);
4709 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
4711 int nparams = TYPE_NFIELDS (this_type);
4713 /* TYPE is the domain of this method, and THIS_TYPE is the type
4714 of the method itself (TYPE_CODE_METHOD). */
4715 smash_to_method_type (fnp->type, type,
4716 TYPE_TARGET_TYPE (this_type),
4717 TYPE_FIELDS (this_type),
4718 TYPE_NFIELDS (this_type),
4719 TYPE_VARARGS (this_type));
4721 /* Handle static member functions.
4722 Dwarf2 has no clean way to discern C++ static and non-static
4723 member functions. G++ helps GDB by marking the first
4724 parameter for non-static member functions (which is the
4725 this pointer) as artificial. We obtain this information
4726 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4727 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
4728 fnp->voffset = VOFFSET_STATIC;
4731 complaint (&symfile_complaints, _("member function type missing for '%s'"),
4734 /* Get fcontext from DW_AT_containing_type if present. */
4735 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4736 fnp->fcontext = die_containing_type (die, cu);
4738 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4739 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4741 /* Get accessibility. */
4742 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
4745 switch (DW_UNSND (attr))
4747 case DW_ACCESS_private:
4748 fnp->is_private = 1;
4750 case DW_ACCESS_protected:
4751 fnp->is_protected = 1;
4756 /* Check for artificial methods. */
4757 attr = dwarf2_attr (die, DW_AT_artificial, cu);
4758 if (attr && DW_UNSND (attr) != 0)
4759 fnp->is_artificial = 1;
4761 /* Get index in virtual function table if it is a virtual member function. */
4762 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
4765 /* Support the .debug_loc offsets */
4766 if (attr_form_is_block (attr))
4768 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
4770 else if (attr_form_is_section_offset (attr))
4772 dwarf2_complex_location_expr_complaint ();
4776 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4782 /* Create the vector of member function fields, and attach it to the type. */
4785 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
4786 struct dwarf2_cu *cu)
4788 struct fnfieldlist *flp;
4789 int total_length = 0;
4792 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4793 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4794 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
4796 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
4798 struct nextfnfield *nfp = flp->head;
4799 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
4802 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
4803 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
4804 fn_flp->fn_fields = (struct fn_field *)
4805 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
4806 for (k = flp->length; (k--, nfp); nfp = nfp->next)
4807 fn_flp->fn_fields[k] = nfp->fnfield;
4809 total_length += flp->length;
4812 TYPE_NFN_FIELDS (type) = fip->nfnfields;
4813 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
4816 /* Returns non-zero if NAME is the name of a vtable member in CU's
4817 language, zero otherwise. */
4819 is_vtable_name (const char *name, struct dwarf2_cu *cu)
4821 static const char vptr[] = "_vptr";
4822 static const char vtable[] = "vtable";
4824 /* Look for the C++ and Java forms of the vtable. */
4825 if ((cu->language == language_java
4826 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
4827 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
4828 && is_cplus_marker (name[sizeof (vptr) - 1])))
4834 /* GCC outputs unnamed structures that are really pointers to member
4835 functions, with the ABI-specified layout. If DIE (from CU) describes
4836 such a structure, set its type, and return nonzero. Otherwise return
4839 GCC shouldn't do this; it should just output pointer to member DIEs.
4840 This is GCC PR debug/28767. */
4842 static struct type *
4843 quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
4845 struct objfile *objfile = cu->objfile;
4847 struct die_info *pfn_die, *delta_die;
4848 struct attribute *pfn_name, *delta_name;
4849 struct type *pfn_type, *domain_type;
4851 /* Check for a structure with no name and two children. */
4852 if (die->tag != DW_TAG_structure_type
4853 || dwarf2_attr (die, DW_AT_name, cu) != NULL
4854 || die->child == NULL
4855 || die->child->sibling == NULL
4856 || (die->child->sibling->sibling != NULL
4857 && die->child->sibling->sibling->tag != DW_TAG_padding))
4860 /* Check for __pfn and __delta members. */
4861 pfn_die = die->child;
4862 pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu);
4863 if (pfn_die->tag != DW_TAG_member
4865 || DW_STRING (pfn_name) == NULL
4866 || strcmp ("__pfn", DW_STRING (pfn_name)) != 0)
4869 delta_die = pfn_die->sibling;
4870 delta_name = dwarf2_attr (delta_die, DW_AT_name, cu);
4871 if (delta_die->tag != DW_TAG_member
4872 || delta_name == NULL
4873 || DW_STRING (delta_name) == NULL
4874 || strcmp ("__delta", DW_STRING (delta_name)) != 0)
4877 /* Find the type of the method. */
4878 pfn_type = die_type (pfn_die, cu);
4879 if (pfn_type == NULL
4880 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
4881 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
4884 /* Look for the "this" argument. */
4885 pfn_type = TYPE_TARGET_TYPE (pfn_type);
4886 if (TYPE_NFIELDS (pfn_type) == 0
4887 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
4890 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
4891 type = alloc_type (objfile);
4892 smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
4893 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
4894 TYPE_VARARGS (pfn_type));
4895 type = lookup_methodptr_type (type);
4896 return set_die_type (die, type, cu);
4899 /* Called when we find the DIE that starts a structure or union scope
4900 (definition) to process all dies that define the members of the
4903 NOTE: we need to call struct_type regardless of whether or not the
4904 DIE has an at_name attribute, since it might be an anonymous
4905 structure or union. This gets the type entered into our set of
4908 However, if the structure is incomplete (an opaque struct/union)
4909 then suppress creating a symbol table entry for it since gdb only
4910 wants to find the one with the complete definition. Note that if
4911 it is complete, we just call new_symbol, which does it's own
4912 checking about whether the struct/union is anonymous or not (and
4913 suppresses creating a symbol table entry itself). */
4915 static struct type *
4916 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
4918 struct objfile *objfile = cu->objfile;
4920 struct attribute *attr;
4922 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4924 type = quirk_gcc_member_function_pointer (die, cu);
4928 /* If the definition of this type lives in .debug_types, read that type.
4929 Don't follow DW_AT_specification though, that will take us back up
4930 the chain and we want to go down. */
4931 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
4934 struct dwarf2_cu *type_cu = cu;
4935 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
4936 /* We could just recurse on read_structure_type, but we need to call
4937 get_die_type to ensure only one type for this DIE is created.
4938 This is important, for example, because for c++ classes we need
4939 TYPE_NAME set which is only done by new_symbol. Blech. */
4940 type = read_type_die (type_die, type_cu);
4941 return set_die_type (die, type, cu);
4944 type = alloc_type (objfile);
4945 INIT_CPLUS_SPECIFIC (type);
4947 name = dwarf2_name (die, cu);
4950 if (cu->language == language_cplus
4951 || cu->language == language_java)
4953 const char *new_prefix = determine_class_name (die, cu);
4954 TYPE_TAG_NAME (type) = (char *) new_prefix;
4958 /* The name is already allocated along with this objfile, so
4959 we don't need to duplicate it for the type. */
4960 TYPE_TAG_NAME (type) = name;
4964 if (die->tag == DW_TAG_structure_type)
4966 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4968 else if (die->tag == DW_TAG_union_type)
4970 TYPE_CODE (type) = TYPE_CODE_UNION;
4974 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4976 TYPE_CODE (type) = TYPE_CODE_CLASS;
4979 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4982 TYPE_LENGTH (type) = DW_UNSND (attr);
4986 TYPE_LENGTH (type) = 0;
4989 TYPE_STUB_SUPPORTED (type) = 1;
4990 if (die_is_declaration (die, cu))
4991 TYPE_STUB (type) = 1;
4993 /* We need to add the type field to the die immediately so we don't
4994 infinitely recurse when dealing with pointers to the structure
4995 type within the structure itself. */
4996 set_die_type (die, type, cu);
4998 if (die->child != NULL && ! die_is_declaration (die, cu))
5000 struct field_info fi;
5001 struct die_info *child_die;
5003 memset (&fi, 0, sizeof (struct field_info));
5005 child_die = die->child;
5007 while (child_die && child_die->tag)
5009 if (child_die->tag == DW_TAG_member
5010 || child_die->tag == DW_TAG_variable)
5012 /* NOTE: carlton/2002-11-05: A C++ static data member
5013 should be a DW_TAG_member that is a declaration, but
5014 all versions of G++ as of this writing (so through at
5015 least 3.2.1) incorrectly generate DW_TAG_variable
5016 tags for them instead. */
5017 dwarf2_add_field (&fi, child_die, cu);
5019 else if (child_die->tag == DW_TAG_subprogram)
5021 /* C++ member function. */
5022 dwarf2_add_member_fn (&fi, child_die, type, cu);
5024 else if (child_die->tag == DW_TAG_inheritance)
5026 /* C++ base class field. */
5027 dwarf2_add_field (&fi, child_die, cu);
5029 child_die = sibling_die (child_die);
5032 /* Attach fields and member functions to the type. */
5034 dwarf2_attach_fields_to_type (&fi, type, cu);
5037 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
5039 /* Get the type which refers to the base class (possibly this
5040 class itself) which contains the vtable pointer for the current
5041 class from the DW_AT_containing_type attribute. */
5043 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
5045 struct type *t = die_containing_type (die, cu);
5047 TYPE_VPTR_BASETYPE (type) = t;
5052 /* Our own class provides vtbl ptr. */
5053 for (i = TYPE_NFIELDS (t) - 1;
5054 i >= TYPE_N_BASECLASSES (t);
5057 char *fieldname = TYPE_FIELD_NAME (t, i);
5059 if (is_vtable_name (fieldname, cu))
5061 TYPE_VPTR_FIELDNO (type) = i;
5066 /* Complain if virtual function table field not found. */
5067 if (i < TYPE_N_BASECLASSES (t))
5068 complaint (&symfile_complaints,
5069 _("virtual function table pointer not found when defining class '%s'"),
5070 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
5075 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
5078 else if (cu->producer
5079 && strncmp (cu->producer,
5080 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5082 /* The IBM XLC compiler does not provide direct indication
5083 of the containing type, but the vtable pointer is
5084 always named __vfp. */
5088 for (i = TYPE_NFIELDS (type) - 1;
5089 i >= TYPE_N_BASECLASSES (type);
5092 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
5094 TYPE_VPTR_FIELDNO (type) = i;
5095 TYPE_VPTR_BASETYPE (type) = type;
5103 do_cleanups (back_to);
5108 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
5110 struct objfile *objfile = cu->objfile;
5111 struct die_info *child_die = die->child;
5112 struct type *this_type;
5114 this_type = get_die_type (die, cu);
5115 if (this_type == NULL)
5116 this_type = read_structure_type (die, cu);
5118 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5119 snapshots) has been known to create a die giving a declaration
5120 for a class that has, as a child, a die giving a definition for a
5121 nested class. So we have to process our children even if the
5122 current die is a declaration. Normally, of course, a declaration
5123 won't have any children at all. */
5125 while (child_die != NULL && child_die->tag)
5127 if (child_die->tag == DW_TAG_member
5128 || child_die->tag == DW_TAG_variable
5129 || child_die->tag == DW_TAG_inheritance)
5134 process_die (child_die, cu);
5136 child_die = sibling_die (child_die);
5139 /* Do not consider external references. According to the DWARF standard,
5140 these DIEs are identified by the fact that they have no byte_size
5141 attribute, and a declaration attribute. */
5142 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
5143 || !die_is_declaration (die, cu))
5144 new_symbol (die, this_type, cu);
5147 /* Given a DW_AT_enumeration_type die, set its type. We do not
5148 complete the type's fields yet, or create any symbols. */
5150 static struct type *
5151 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
5153 struct objfile *objfile = cu->objfile;
5155 struct attribute *attr;
5158 /* If the definition of this type lives in .debug_types, read that type.
5159 Don't follow DW_AT_specification though, that will take us back up
5160 the chain and we want to go down. */
5161 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
5164 struct dwarf2_cu *type_cu = cu;
5165 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
5166 type = read_type_die (type_die, type_cu);
5167 return set_die_type (die, type, cu);
5170 type = alloc_type (objfile);
5172 TYPE_CODE (type) = TYPE_CODE_ENUM;
5173 name = dwarf2_full_name (die, cu);
5175 TYPE_TAG_NAME (type) = (char *) name;
5177 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5180 TYPE_LENGTH (type) = DW_UNSND (attr);
5184 TYPE_LENGTH (type) = 0;
5187 /* The enumeration DIE can be incomplete. In Ada, any type can be
5188 declared as private in the package spec, and then defined only
5189 inside the package body. Such types are known as Taft Amendment
5190 Types. When another package uses such a type, an incomplete DIE
5191 may be generated by the compiler. */
5192 if (die_is_declaration (die, cu))
5193 TYPE_STUB (type) = 1;
5195 return set_die_type (die, type, cu);
5198 /* Determine the name of the type represented by DIE, which should be
5199 a named C++ or Java compound type. Return the name in question,
5200 allocated on the objfile obstack. */
5203 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
5205 const char *new_prefix = NULL;
5207 /* If we don't have namespace debug info, guess the name by trying
5208 to demangle the names of members, just like we did in
5209 guess_structure_name. */
5210 if (!processing_has_namespace_info)
5212 struct die_info *child;
5214 for (child = die->child;
5215 child != NULL && child->tag != 0;
5216 child = sibling_die (child))
5218 if (child->tag == DW_TAG_subprogram)
5221 = language_class_name_from_physname (cu->language_defn,
5225 if (phys_prefix != NULL)
5228 = obsavestring (phys_prefix, strlen (phys_prefix),
5229 &cu->objfile->objfile_obstack);
5230 xfree (phys_prefix);
5237 if (new_prefix == NULL)
5238 new_prefix = dwarf2_full_name (die, cu);
5243 /* Given a pointer to a die which begins an enumeration, process all
5244 the dies that define the members of the enumeration, and create the
5245 symbol for the enumeration type.
5247 NOTE: We reverse the order of the element list. */
5250 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
5252 struct objfile *objfile = cu->objfile;
5253 struct die_info *child_die;
5254 struct field *fields;
5257 int unsigned_enum = 1;
5259 struct type *this_type;
5263 this_type = get_die_type (die, cu);
5264 if (this_type == NULL)
5265 this_type = read_enumeration_type (die, cu);
5266 if (die->child != NULL)
5268 child_die = die->child;
5269 while (child_die && child_die->tag)
5271 if (child_die->tag != DW_TAG_enumerator)
5273 process_die (child_die, cu);
5277 name = dwarf2_name (child_die, cu);
5280 sym = new_symbol (child_die, this_type, cu);
5281 if (SYMBOL_VALUE (sym) < 0)
5284 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
5286 fields = (struct field *)
5288 (num_fields + DW_FIELD_ALLOC_CHUNK)
5289 * sizeof (struct field));
5292 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
5293 FIELD_TYPE (fields[num_fields]) = NULL;
5294 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
5295 FIELD_BITSIZE (fields[num_fields]) = 0;
5301 child_die = sibling_die (child_die);
5306 TYPE_NFIELDS (this_type) = num_fields;
5307 TYPE_FIELDS (this_type) = (struct field *)
5308 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
5309 memcpy (TYPE_FIELDS (this_type), fields,
5310 sizeof (struct field) * num_fields);
5314 TYPE_UNSIGNED (this_type) = 1;
5317 new_symbol (die, this_type, cu);
5320 /* Extract all information from a DW_TAG_array_type DIE and put it in
5321 the DIE's type field. For now, this only handles one dimensional
5324 static struct type *
5325 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
5327 struct objfile *objfile = cu->objfile;
5328 struct die_info *child_die;
5329 struct type *type = NULL;
5330 struct type *element_type, *range_type, *index_type;
5331 struct type **range_types = NULL;
5332 struct attribute *attr;
5334 struct cleanup *back_to;
5337 element_type = die_type (die, cu);
5339 /* Irix 6.2 native cc creates array types without children for
5340 arrays with unspecified length. */
5341 if (die->child == NULL)
5343 index_type = objfile_type (objfile)->builtin_int;
5344 range_type = create_range_type (NULL, index_type, 0, -1);
5345 type = create_array_type (NULL, element_type, range_type);
5346 return set_die_type (die, type, cu);
5349 back_to = make_cleanup (null_cleanup, NULL);
5350 child_die = die->child;
5351 while (child_die && child_die->tag)
5353 if (child_die->tag == DW_TAG_subrange_type)
5355 struct type *child_type = read_type_die (child_die, cu);
5356 if (child_type != NULL)
5358 /* The range type was succesfully read. Save it for
5359 the array type creation. */
5360 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
5362 range_types = (struct type **)
5363 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
5364 * sizeof (struct type *));
5366 make_cleanup (free_current_contents, &range_types);
5368 range_types[ndim++] = child_type;
5371 child_die = sibling_die (child_die);
5374 /* Dwarf2 dimensions are output from left to right, create the
5375 necessary array types in backwards order. */
5377 type = element_type;
5379 if (read_array_order (die, cu) == DW_ORD_col_major)
5383 type = create_array_type (NULL, type, range_types[i++]);
5388 type = create_array_type (NULL, type, range_types[ndim]);
5391 /* Understand Dwarf2 support for vector types (like they occur on
5392 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5393 array type. This is not part of the Dwarf2/3 standard yet, but a
5394 custom vendor extension. The main difference between a regular
5395 array and the vector variant is that vectors are passed by value
5397 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
5399 make_vector_type (type);
5401 name = dwarf2_name (die, cu);
5403 TYPE_NAME (type) = name;
5405 do_cleanups (back_to);
5407 /* Install the type in the die. */
5408 return set_die_type (die, type, cu);
5411 static enum dwarf_array_dim_ordering
5412 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
5414 struct attribute *attr;
5416 attr = dwarf2_attr (die, DW_AT_ordering, cu);
5418 if (attr) return DW_SND (attr);
5421 GNU F77 is a special case, as at 08/2004 array type info is the
5422 opposite order to the dwarf2 specification, but data is still
5423 laid out as per normal fortran.
5425 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5429 if (cu->language == language_fortran
5430 && cu->producer && strstr (cu->producer, "GNU F77"))
5432 return DW_ORD_row_major;
5435 switch (cu->language_defn->la_array_ordering)
5437 case array_column_major:
5438 return DW_ORD_col_major;
5439 case array_row_major:
5441 return DW_ORD_row_major;
5445 /* Extract all information from a DW_TAG_set_type DIE and put it in
5446 the DIE's type field. */
5448 static struct type *
5449 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
5451 struct type *set_type = create_set_type (NULL, die_type (die, cu));
5453 return set_die_type (die, set_type, cu);
5456 /* First cut: install each common block member as a global variable. */
5459 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
5461 struct die_info *child_die;
5462 struct attribute *attr;
5464 CORE_ADDR base = (CORE_ADDR) 0;
5466 attr = dwarf2_attr (die, DW_AT_location, cu);
5469 /* Support the .debug_loc offsets */
5470 if (attr_form_is_block (attr))
5472 base = decode_locdesc (DW_BLOCK (attr), cu);
5474 else if (attr_form_is_section_offset (attr))
5476 dwarf2_complex_location_expr_complaint ();
5480 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5481 "common block member");
5484 if (die->child != NULL)
5486 child_die = die->child;
5487 while (child_die && child_die->tag)
5489 sym = new_symbol (child_die, NULL, cu);
5490 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
5493 CORE_ADDR byte_offset = 0;
5495 if (attr_form_is_section_offset (attr))
5496 dwarf2_complex_location_expr_complaint ();
5497 else if (attr_form_is_constant (attr))
5498 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
5499 else if (attr_form_is_block (attr))
5500 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
5502 dwarf2_complex_location_expr_complaint ();
5504 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
5505 add_symbol_to_list (sym, &global_symbols);
5507 child_die = sibling_die (child_die);
5512 /* Create a type for a C++ namespace. */
5514 static struct type *
5515 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
5517 struct objfile *objfile = cu->objfile;
5518 const char *previous_prefix, *name;
5522 /* For extensions, reuse the type of the original namespace. */
5523 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
5525 struct die_info *ext_die;
5526 struct dwarf2_cu *ext_cu = cu;
5527 ext_die = dwarf2_extension (die, &ext_cu);
5528 type = read_type_die (ext_die, ext_cu);
5529 return set_die_type (die, type, cu);
5532 name = namespace_name (die, &is_anonymous, cu);
5534 /* Now build the name of the current namespace. */
5536 previous_prefix = determine_prefix (die, cu);
5537 if (previous_prefix[0] != '\0')
5538 name = typename_concat (&objfile->objfile_obstack,
5539 previous_prefix, name, cu);
5541 /* Create the type. */
5542 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
5544 TYPE_NAME (type) = (char *) name;
5545 TYPE_TAG_NAME (type) = TYPE_NAME (type);
5547 set_die_type (die, type, cu);
5552 /* Read a C++ namespace. */
5555 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
5557 struct objfile *objfile = cu->objfile;
5561 /* Add a symbol associated to this if we haven't seen the namespace
5562 before. Also, add a using directive if it's an anonymous
5565 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
5569 type = read_type_die (die, cu);
5570 new_symbol (die, type, cu);
5572 name = namespace_name (die, &is_anonymous, cu);
5575 const char *previous_prefix = determine_prefix (die, cu);
5576 cp_add_using_directive (previous_prefix, TYPE_NAME (type));
5580 if (die->child != NULL)
5582 struct die_info *child_die = die->child;
5584 while (child_die && child_die->tag)
5586 process_die (child_die, cu);
5587 child_die = sibling_die (child_die);
5592 /* Read a Fortran module. */
5595 read_module (struct die_info *die, struct dwarf2_cu *cu)
5597 struct die_info *child_die = die->child;
5599 /* FIXME: Support the separate Fortran module namespaces. */
5601 while (child_die && child_die->tag)
5603 process_die (child_die, cu);
5604 child_die = sibling_die (child_die);
5608 /* Return the name of the namespace represented by DIE. Set
5609 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5613 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
5615 struct die_info *current_die;
5616 const char *name = NULL;
5618 /* Loop through the extensions until we find a name. */
5620 for (current_die = die;
5621 current_die != NULL;
5622 current_die = dwarf2_extension (die, &cu))
5624 name = dwarf2_name (current_die, cu);
5629 /* Is it an anonymous namespace? */
5631 *is_anonymous = (name == NULL);
5633 name = "(anonymous namespace)";
5638 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5639 the user defined type vector. */
5641 static struct type *
5642 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
5644 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5645 struct comp_unit_head *cu_header = &cu->header;
5647 struct attribute *attr_byte_size;
5648 struct attribute *attr_address_class;
5649 int byte_size, addr_class;
5651 type = lookup_pointer_type (die_type (die, cu));
5653 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
5655 byte_size = DW_UNSND (attr_byte_size);
5657 byte_size = cu_header->addr_size;
5659 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
5660 if (attr_address_class)
5661 addr_class = DW_UNSND (attr_address_class);
5663 addr_class = DW_ADDR_none;
5665 /* If the pointer size or address class is different than the
5666 default, create a type variant marked as such and set the
5667 length accordingly. */
5668 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
5670 if (gdbarch_address_class_type_flags_p (gdbarch))
5674 type_flags = gdbarch_address_class_type_flags
5675 (gdbarch, byte_size, addr_class);
5676 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
5678 type = make_type_with_address_space (type, type_flags);
5680 else if (TYPE_LENGTH (type) != byte_size)
5682 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
5685 /* Should we also complain about unhandled address classes? */
5689 TYPE_LENGTH (type) = byte_size;
5690 return set_die_type (die, type, cu);
5693 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5694 the user defined type vector. */
5696 static struct type *
5697 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
5699 struct objfile *objfile = cu->objfile;
5701 struct type *to_type;
5702 struct type *domain;
5704 to_type = die_type (die, cu);
5705 domain = die_containing_type (die, cu);
5707 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
5708 type = lookup_methodptr_type (to_type);
5710 type = lookup_memberptr_type (to_type, domain);
5712 return set_die_type (die, type, cu);
5715 /* Extract all information from a DW_TAG_reference_type DIE and add to
5716 the user defined type vector. */
5718 static struct type *
5719 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
5721 struct comp_unit_head *cu_header = &cu->header;
5723 struct attribute *attr;
5725 type = lookup_reference_type (die_type (die, cu));
5726 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5729 TYPE_LENGTH (type) = DW_UNSND (attr);
5733 TYPE_LENGTH (type) = cu_header->addr_size;
5735 return set_die_type (die, type, cu);
5738 static struct type *
5739 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
5741 struct type *base_type, *cv_type;
5743 base_type = die_type (die, cu);
5744 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
5745 return set_die_type (die, cv_type, cu);
5748 static struct type *
5749 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
5751 struct type *base_type, *cv_type;
5753 base_type = die_type (die, cu);
5754 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
5755 return set_die_type (die, cv_type, cu);
5758 /* Extract all information from a DW_TAG_string_type DIE and add to
5759 the user defined type vector. It isn't really a user defined type,
5760 but it behaves like one, with other DIE's using an AT_user_def_type
5761 attribute to reference it. */
5763 static struct type *
5764 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5766 struct objfile *objfile = cu->objfile;
5767 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5768 struct type *type, *range_type, *index_type, *char_type;
5769 struct attribute *attr;
5770 unsigned int length;
5772 attr = dwarf2_attr (die, DW_AT_string_length, cu);
5775 length = DW_UNSND (attr);
5779 /* check for the DW_AT_byte_size attribute */
5780 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5783 length = DW_UNSND (attr);
5791 index_type = objfile_type (objfile)->builtin_int;
5792 range_type = create_range_type (NULL, index_type, 1, length);
5793 char_type = language_string_char_type (cu->language_defn, gdbarch);
5794 type = create_string_type (NULL, char_type, range_type);
5796 return set_die_type (die, type, cu);
5799 /* Handle DIES due to C code like:
5803 int (*funcp)(int a, long l);
5807 ('funcp' generates a DW_TAG_subroutine_type DIE)
5810 static struct type *
5811 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
5813 struct type *type; /* Type that this function returns */
5814 struct type *ftype; /* Function that returns above type */
5815 struct attribute *attr;
5817 type = die_type (die, cu);
5818 ftype = lookup_function_type (type);
5820 /* All functions in C++, Pascal and Java have prototypes. */
5821 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
5822 if ((attr && (DW_UNSND (attr) != 0))
5823 || cu->language == language_cplus
5824 || cu->language == language_java
5825 || cu->language == language_pascal)
5826 TYPE_PROTOTYPED (ftype) = 1;
5828 /* Store the calling convention in the type if it's available in
5829 the subroutine die. Otherwise set the calling convention to
5830 the default value DW_CC_normal. */
5831 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
5832 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
5834 if (die->child != NULL)
5836 struct die_info *child_die;
5840 /* Count the number of parameters.
5841 FIXME: GDB currently ignores vararg functions, but knows about
5842 vararg member functions. */
5843 child_die = die->child;
5844 while (child_die && child_die->tag)
5846 if (child_die->tag == DW_TAG_formal_parameter)
5848 else if (child_die->tag == DW_TAG_unspecified_parameters)
5849 TYPE_VARARGS (ftype) = 1;
5850 child_die = sibling_die (child_die);
5853 /* Allocate storage for parameters and fill them in. */
5854 TYPE_NFIELDS (ftype) = nparams;
5855 TYPE_FIELDS (ftype) = (struct field *)
5856 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
5858 child_die = die->child;
5859 while (child_die && child_die->tag)
5861 if (child_die->tag == DW_TAG_formal_parameter)
5863 /* Dwarf2 has no clean way to discern C++ static and non-static
5864 member functions. G++ helps GDB by marking the first
5865 parameter for non-static member functions (which is the
5866 this pointer) as artificial. We pass this information
5867 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5868 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
5870 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
5872 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
5873 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
5876 child_die = sibling_die (child_die);
5880 return set_die_type (die, ftype, cu);
5883 static struct type *
5884 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
5886 struct objfile *objfile = cu->objfile;
5887 struct attribute *attr;
5888 const char *name = NULL;
5889 struct type *this_type;
5891 name = dwarf2_full_name (die, cu);
5892 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
5893 TYPE_FLAG_TARGET_STUB, NULL, objfile);
5894 TYPE_NAME (this_type) = (char *) name;
5895 set_die_type (die, this_type, cu);
5896 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
5900 /* Find a representation of a given base type and install
5901 it in the TYPE field of the die. */
5903 static struct type *
5904 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
5906 struct objfile *objfile = cu->objfile;
5908 struct attribute *attr;
5909 int encoding = 0, size = 0;
5911 enum type_code code = TYPE_CODE_INT;
5913 struct type *target_type = NULL;
5915 attr = dwarf2_attr (die, DW_AT_encoding, cu);
5918 encoding = DW_UNSND (attr);
5920 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5923 size = DW_UNSND (attr);
5925 name = dwarf2_name (die, cu);
5928 complaint (&symfile_complaints,
5929 _("DW_AT_name missing from DW_TAG_base_type"));
5934 case DW_ATE_address:
5935 /* Turn DW_ATE_address into a void * pointer. */
5936 code = TYPE_CODE_PTR;
5937 type_flags |= TYPE_FLAG_UNSIGNED;
5938 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
5940 case DW_ATE_boolean:
5941 code = TYPE_CODE_BOOL;
5942 type_flags |= TYPE_FLAG_UNSIGNED;
5944 case DW_ATE_complex_float:
5945 code = TYPE_CODE_COMPLEX;
5946 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
5948 case DW_ATE_decimal_float:
5949 code = TYPE_CODE_DECFLOAT;
5952 code = TYPE_CODE_FLT;
5956 case DW_ATE_unsigned:
5957 type_flags |= TYPE_FLAG_UNSIGNED;
5959 case DW_ATE_signed_char:
5960 if (cu->language == language_ada || cu->language == language_m2
5961 || cu->language == language_pascal)
5962 code = TYPE_CODE_CHAR;
5964 case DW_ATE_unsigned_char:
5965 if (cu->language == language_ada || cu->language == language_m2
5966 || cu->language == language_pascal)
5967 code = TYPE_CODE_CHAR;
5968 type_flags |= TYPE_FLAG_UNSIGNED;
5971 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
5972 dwarf_type_encoding_name (encoding));
5976 type = init_type (code, size, type_flags, NULL, objfile);
5977 TYPE_NAME (type) = name;
5978 TYPE_TARGET_TYPE (type) = target_type;
5980 if (name && strcmp (name, "char") == 0)
5981 TYPE_NOSIGN (type) = 1;
5983 return set_die_type (die, type, cu);
5986 /* Read the given DW_AT_subrange DIE. */
5988 static struct type *
5989 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5991 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5992 struct type *base_type;
5993 struct type *range_type;
5994 struct attribute *attr;
5999 base_type = die_type (die, cu);
6000 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
6002 complaint (&symfile_complaints,
6003 _("DW_AT_type missing from DW_TAG_subrange_type"));
6005 = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
6006 0, NULL, cu->objfile);
6009 if (cu->language == language_fortran)
6011 /* FORTRAN implies a lower bound of 1, if not given. */
6015 /* FIXME: For variable sized arrays either of these could be
6016 a variable rather than a constant value. We'll allow it,
6017 but we don't know how to handle it. */
6018 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6020 low = dwarf2_get_attr_constant_value (attr, 0);
6022 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6025 if (attr->form == DW_FORM_block1)
6027 /* GCC encodes arrays with unspecified or dynamic length
6028 with a DW_FORM_block1 attribute.
6029 FIXME: GDB does not yet know how to handle dynamic
6030 arrays properly, treat them as arrays with unspecified
6033 FIXME: jimb/2003-09-22: GDB does not really know
6034 how to handle arrays of unspecified length
6035 either; we just represent them as zero-length
6036 arrays. Choose an appropriate upper bound given
6037 the lower bound we've computed above. */
6041 high = dwarf2_get_attr_constant_value (attr, 1);
6044 range_type = create_range_type (NULL, base_type, low, high);
6046 name = dwarf2_name (die, cu);
6048 TYPE_NAME (range_type) = name;
6050 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6052 TYPE_LENGTH (range_type) = DW_UNSND (attr);
6054 return set_die_type (die, range_type, cu);
6057 static struct type *
6058 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
6062 /* For now, we only support the C meaning of an unspecified type: void. */
6064 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
6065 TYPE_NAME (type) = dwarf2_name (die, cu);
6067 return set_die_type (die, type, cu);
6070 /* Trivial hash function for die_info: the hash value of a DIE
6071 is its offset in .debug_info for this objfile. */
6074 die_hash (const void *item)
6076 const struct die_info *die = item;
6080 /* Trivial comparison function for die_info structures: two DIEs
6081 are equal if they have the same offset. */
6084 die_eq (const void *item_lhs, const void *item_rhs)
6086 const struct die_info *die_lhs = item_lhs;
6087 const struct die_info *die_rhs = item_rhs;
6088 return die_lhs->offset == die_rhs->offset;
6091 /* Read a whole compilation unit into a linked list of dies. */
6093 static struct die_info *
6094 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
6096 struct die_reader_specs reader_specs;
6098 gdb_assert (cu->die_hash == NULL);
6100 = htab_create_alloc_ex (cu->header.length / 12,
6104 &cu->comp_unit_obstack,
6105 hashtab_obstack_allocate,
6106 dummy_obstack_deallocate);
6108 init_cu_die_reader (&reader_specs, cu);
6110 return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
6113 /* Main entry point for reading a DIE and all children.
6114 Read the DIE and dump it if requested. */
6116 static struct die_info *
6117 read_die_and_children (const struct die_reader_specs *reader,
6119 gdb_byte **new_info_ptr,
6120 struct die_info *parent)
6122 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
6123 new_info_ptr, parent);
6125 if (dwarf2_die_debug)
6127 fprintf_unfiltered (gdb_stdlog,
6128 "\nRead die from %s of %s:\n",
6129 reader->buffer == dwarf2_per_objfile->info.buffer
6131 : reader->buffer == dwarf2_per_objfile->types.buffer
6133 : "unknown section",
6134 reader->abfd->filename);
6135 dump_die (result, dwarf2_die_debug);
6141 /* Read a single die and all its descendents. Set the die's sibling
6142 field to NULL; set other fields in the die correctly, and set all
6143 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6144 location of the info_ptr after reading all of those dies. PARENT
6145 is the parent of the die in question. */
6147 static struct die_info *
6148 read_die_and_children_1 (const struct die_reader_specs *reader,
6150 gdb_byte **new_info_ptr,
6151 struct die_info *parent)
6153 struct die_info *die;
6157 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
6160 *new_info_ptr = cur_ptr;
6163 store_in_ref_table (die, reader->cu);
6166 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
6170 *new_info_ptr = cur_ptr;
6173 die->sibling = NULL;
6174 die->parent = parent;
6178 /* Read a die, all of its descendents, and all of its siblings; set
6179 all of the fields of all of the dies correctly. Arguments are as
6180 in read_die_and_children. */
6182 static struct die_info *
6183 read_die_and_siblings (const struct die_reader_specs *reader,
6185 gdb_byte **new_info_ptr,
6186 struct die_info *parent)
6188 struct die_info *first_die, *last_sibling;
6192 first_die = last_sibling = NULL;
6196 struct die_info *die
6197 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
6201 *new_info_ptr = cur_ptr;
6208 last_sibling->sibling = die;
6214 /* Read the die from the .debug_info section buffer. Set DIEP to
6215 point to a newly allocated die with its information, except for its
6216 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6217 whether the die has children or not. */
6220 read_full_die (const struct die_reader_specs *reader,
6221 struct die_info **diep, gdb_byte *info_ptr,
6224 unsigned int abbrev_number, bytes_read, i, offset;
6225 struct abbrev_info *abbrev;
6226 struct die_info *die;
6227 struct dwarf2_cu *cu = reader->cu;
6228 bfd *abfd = reader->abfd;
6230 offset = info_ptr - reader->buffer;
6231 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6232 info_ptr += bytes_read;
6240 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
6242 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6244 bfd_get_filename (abfd));
6246 die = dwarf_alloc_die (cu, abbrev->num_attrs);
6247 die->offset = offset;
6248 die->tag = abbrev->tag;
6249 die->abbrev = abbrev_number;
6251 die->num_attrs = abbrev->num_attrs;
6253 for (i = 0; i < abbrev->num_attrs; ++i)
6254 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
6255 abfd, info_ptr, cu);
6258 *has_children = abbrev->has_children;
6262 /* In DWARF version 2, the description of the debugging information is
6263 stored in a separate .debug_abbrev section. Before we read any
6264 dies from a section we read in all abbreviations and install them
6265 in a hash table. This function also sets flags in CU describing
6266 the data found in the abbrev table. */
6269 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
6271 struct comp_unit_head *cu_header = &cu->header;
6272 gdb_byte *abbrev_ptr;
6273 struct abbrev_info *cur_abbrev;
6274 unsigned int abbrev_number, bytes_read, abbrev_name;
6275 unsigned int abbrev_form, hash_number;
6276 struct attr_abbrev *cur_attrs;
6277 unsigned int allocated_attrs;
6279 /* Initialize dwarf2 abbrevs */
6280 obstack_init (&cu->abbrev_obstack);
6281 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
6283 * sizeof (struct abbrev_info *)));
6284 memset (cu->dwarf2_abbrevs, 0,
6285 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
6287 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
6288 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6289 abbrev_ptr += bytes_read;
6291 allocated_attrs = ATTR_ALLOC_CHUNK;
6292 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
6294 /* loop until we reach an abbrev number of 0 */
6295 while (abbrev_number)
6297 cur_abbrev = dwarf_alloc_abbrev (cu);
6299 /* read in abbrev header */
6300 cur_abbrev->number = abbrev_number;
6301 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6302 abbrev_ptr += bytes_read;
6303 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
6306 if (cur_abbrev->tag == DW_TAG_namespace)
6307 cu->has_namespace_info = 1;
6309 /* now read in declarations */
6310 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6311 abbrev_ptr += bytes_read;
6312 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6313 abbrev_ptr += bytes_read;
6316 if (cur_abbrev->num_attrs == allocated_attrs)
6318 allocated_attrs += ATTR_ALLOC_CHUNK;
6320 = xrealloc (cur_attrs, (allocated_attrs
6321 * sizeof (struct attr_abbrev)));
6324 /* Record whether this compilation unit might have
6325 inter-compilation-unit references. If we don't know what form
6326 this attribute will have, then it might potentially be a
6327 DW_FORM_ref_addr, so we conservatively expect inter-CU
6330 if (abbrev_form == DW_FORM_ref_addr
6331 || abbrev_form == DW_FORM_indirect)
6332 cu->has_form_ref_addr = 1;
6334 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
6335 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
6336 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6337 abbrev_ptr += bytes_read;
6338 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6339 abbrev_ptr += bytes_read;
6342 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
6343 (cur_abbrev->num_attrs
6344 * sizeof (struct attr_abbrev)));
6345 memcpy (cur_abbrev->attrs, cur_attrs,
6346 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
6348 hash_number = abbrev_number % ABBREV_HASH_SIZE;
6349 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
6350 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
6352 /* Get next abbreviation.
6353 Under Irix6 the abbreviations for a compilation unit are not
6354 always properly terminated with an abbrev number of 0.
6355 Exit loop if we encounter an abbreviation which we have
6356 already read (which means we are about to read the abbreviations
6357 for the next compile unit) or if the end of the abbreviation
6358 table is reached. */
6359 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
6360 >= dwarf2_per_objfile->abbrev.size)
6362 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
6363 abbrev_ptr += bytes_read;
6364 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
6371 /* Release the memory used by the abbrev table for a compilation unit. */
6374 dwarf2_free_abbrev_table (void *ptr_to_cu)
6376 struct dwarf2_cu *cu = ptr_to_cu;
6378 obstack_free (&cu->abbrev_obstack, NULL);
6379 cu->dwarf2_abbrevs = NULL;
6382 /* Lookup an abbrev_info structure in the abbrev hash table. */
6384 static struct abbrev_info *
6385 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
6387 unsigned int hash_number;
6388 struct abbrev_info *abbrev;
6390 hash_number = number % ABBREV_HASH_SIZE;
6391 abbrev = cu->dwarf2_abbrevs[hash_number];
6395 if (abbrev->number == number)
6398 abbrev = abbrev->next;
6403 /* Returns nonzero if TAG represents a type that we might generate a partial
6407 is_type_tag_for_partial (int tag)
6412 /* Some types that would be reasonable to generate partial symbols for,
6413 that we don't at present. */
6414 case DW_TAG_array_type:
6415 case DW_TAG_file_type:
6416 case DW_TAG_ptr_to_member_type:
6417 case DW_TAG_set_type:
6418 case DW_TAG_string_type:
6419 case DW_TAG_subroutine_type:
6421 case DW_TAG_base_type:
6422 case DW_TAG_class_type:
6423 case DW_TAG_interface_type:
6424 case DW_TAG_enumeration_type:
6425 case DW_TAG_structure_type:
6426 case DW_TAG_subrange_type:
6427 case DW_TAG_typedef:
6428 case DW_TAG_union_type:
6435 /* Load all DIEs that are interesting for partial symbols into memory. */
6437 static struct partial_die_info *
6438 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6439 int building_psymtab, struct dwarf2_cu *cu)
6441 struct partial_die_info *part_die;
6442 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
6443 struct abbrev_info *abbrev;
6444 unsigned int bytes_read;
6445 unsigned int load_all = 0;
6447 int nesting_level = 1;
6452 if (cu->per_cu && cu->per_cu->load_all_dies)
6456 = htab_create_alloc_ex (cu->header.length / 12,
6460 &cu->comp_unit_obstack,
6461 hashtab_obstack_allocate,
6462 dummy_obstack_deallocate);
6464 part_die = obstack_alloc (&cu->comp_unit_obstack,
6465 sizeof (struct partial_die_info));
6469 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6471 /* A NULL abbrev means the end of a series of children. */
6474 if (--nesting_level == 0)
6476 /* PART_DIE was probably the last thing allocated on the
6477 comp_unit_obstack, so we could call obstack_free
6478 here. We don't do that because the waste is small,
6479 and will be cleaned up when we're done with this
6480 compilation unit. This way, we're also more robust
6481 against other users of the comp_unit_obstack. */
6484 info_ptr += bytes_read;
6485 last_die = parent_die;
6486 parent_die = parent_die->die_parent;
6490 /* Check whether this DIE is interesting enough to save. Normally
6491 we would not be interested in members here, but there may be
6492 later variables referencing them via DW_AT_specification (for
6495 && !is_type_tag_for_partial (abbrev->tag)
6496 && abbrev->tag != DW_TAG_enumerator
6497 && abbrev->tag != DW_TAG_subprogram
6498 && abbrev->tag != DW_TAG_lexical_block
6499 && abbrev->tag != DW_TAG_variable
6500 && abbrev->tag != DW_TAG_namespace
6501 && abbrev->tag != DW_TAG_member)
6503 /* Otherwise we skip to the next sibling, if any. */
6504 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
6508 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
6509 buffer, info_ptr, cu);
6511 /* This two-pass algorithm for processing partial symbols has a
6512 high cost in cache pressure. Thus, handle some simple cases
6513 here which cover the majority of C partial symbols. DIEs
6514 which neither have specification tags in them, nor could have
6515 specification tags elsewhere pointing at them, can simply be
6516 processed and discarded.
6518 This segment is also optional; scan_partial_symbols and
6519 add_partial_symbol will handle these DIEs if we chain
6520 them in normally. When compilers which do not emit large
6521 quantities of duplicate debug information are more common,
6522 this code can probably be removed. */
6524 /* Any complete simple types at the top level (pretty much all
6525 of them, for a language without namespaces), can be processed
6527 if (parent_die == NULL
6528 && part_die->has_specification == 0
6529 && part_die->is_declaration == 0
6530 && (part_die->tag == DW_TAG_typedef
6531 || part_die->tag == DW_TAG_base_type
6532 || part_die->tag == DW_TAG_subrange_type))
6534 if (building_psymtab && part_die->name != NULL)
6535 add_psymbol_to_list (part_die->name, strlen (part_die->name),
6536 VAR_DOMAIN, LOC_TYPEDEF,
6537 &cu->objfile->static_psymbols,
6538 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6539 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6543 /* If we're at the second level, and we're an enumerator, and
6544 our parent has no specification (meaning possibly lives in a
6545 namespace elsewhere), then we can add the partial symbol now
6546 instead of queueing it. */
6547 if (part_die->tag == DW_TAG_enumerator
6548 && parent_die != NULL
6549 && parent_die->die_parent == NULL
6550 && parent_die->tag == DW_TAG_enumeration_type
6551 && parent_die->has_specification == 0)
6553 if (part_die->name == NULL)
6554 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6555 else if (building_psymtab)
6556 add_psymbol_to_list (part_die->name, strlen (part_die->name),
6557 VAR_DOMAIN, LOC_CONST,
6558 (cu->language == language_cplus
6559 || cu->language == language_java)
6560 ? &cu->objfile->global_psymbols
6561 : &cu->objfile->static_psymbols,
6562 0, (CORE_ADDR) 0, cu->language, cu->objfile);
6564 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
6568 /* We'll save this DIE so link it in. */
6569 part_die->die_parent = parent_die;
6570 part_die->die_sibling = NULL;
6571 part_die->die_child = NULL;
6573 if (last_die && last_die == parent_die)
6574 last_die->die_child = part_die;
6576 last_die->die_sibling = part_die;
6578 last_die = part_die;
6580 if (first_die == NULL)
6581 first_die = part_die;
6583 /* Maybe add the DIE to the hash table. Not all DIEs that we
6584 find interesting need to be in the hash table, because we
6585 also have the parent/sibling/child chains; only those that we
6586 might refer to by offset later during partial symbol reading.
6588 For now this means things that might have be the target of a
6589 DW_AT_specification, DW_AT_abstract_origin, or
6590 DW_AT_extension. DW_AT_extension will refer only to
6591 namespaces; DW_AT_abstract_origin refers to functions (and
6592 many things under the function DIE, but we do not recurse
6593 into function DIEs during partial symbol reading) and
6594 possibly variables as well; DW_AT_specification refers to
6595 declarations. Declarations ought to have the DW_AT_declaration
6596 flag. It happens that GCC forgets to put it in sometimes, but
6597 only for functions, not for types.
6599 Adding more things than necessary to the hash table is harmless
6600 except for the performance cost. Adding too few will result in
6601 wasted time in find_partial_die, when we reread the compilation
6602 unit with load_all_dies set. */
6605 || abbrev->tag == DW_TAG_subprogram
6606 || abbrev->tag == DW_TAG_variable
6607 || abbrev->tag == DW_TAG_namespace
6608 || part_die->is_declaration)
6612 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
6613 part_die->offset, INSERT);
6617 part_die = obstack_alloc (&cu->comp_unit_obstack,
6618 sizeof (struct partial_die_info));
6620 /* For some DIEs we want to follow their children (if any). For C
6621 we have no reason to follow the children of structures; for other
6622 languages we have to, both so that we can get at method physnames
6623 to infer fully qualified class names, and for DW_AT_specification.
6625 For Ada, we need to scan the children of subprograms and lexical
6626 blocks as well because Ada allows the definition of nested
6627 entities that could be interesting for the debugger, such as
6628 nested subprograms for instance. */
6629 if (last_die->has_children
6631 || last_die->tag == DW_TAG_namespace
6632 || last_die->tag == DW_TAG_enumeration_type
6633 || (cu->language != language_c
6634 && (last_die->tag == DW_TAG_class_type
6635 || last_die->tag == DW_TAG_interface_type
6636 || last_die->tag == DW_TAG_structure_type
6637 || last_die->tag == DW_TAG_union_type))
6638 || (cu->language == language_ada
6639 && (last_die->tag == DW_TAG_subprogram
6640 || last_die->tag == DW_TAG_lexical_block))))
6643 parent_die = last_die;
6647 /* Otherwise we skip to the next sibling, if any. */
6648 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
6650 /* Back to the top, do it again. */
6654 /* Read a minimal amount of information into the minimal die structure. */
6657 read_partial_die (struct partial_die_info *part_die,
6658 struct abbrev_info *abbrev,
6659 unsigned int abbrev_len, bfd *abfd,
6660 gdb_byte *buffer, gdb_byte *info_ptr,
6661 struct dwarf2_cu *cu)
6663 unsigned int bytes_read, i;
6664 struct attribute attr;
6665 int has_low_pc_attr = 0;
6666 int has_high_pc_attr = 0;
6668 memset (part_die, 0, sizeof (struct partial_die_info));
6670 part_die->offset = info_ptr - buffer;
6672 info_ptr += abbrev_len;
6677 part_die->tag = abbrev->tag;
6678 part_die->has_children = abbrev->has_children;
6680 for (i = 0; i < abbrev->num_attrs; ++i)
6682 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
6684 /* Store the data if it is of an attribute we want to keep in a
6685 partial symbol table. */
6689 switch (part_die->tag)
6691 case DW_TAG_compile_unit:
6692 case DW_TAG_type_unit:
6693 /* Compilation units have a DW_AT_name that is a filename, not
6694 a source language identifier. */
6695 case DW_TAG_enumeration_type:
6696 case DW_TAG_enumerator:
6697 /* These tags always have simple identifiers already; no need
6698 to canonicalize them. */
6699 part_die->name = DW_STRING (&attr);
6703 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
6704 &cu->comp_unit_obstack);
6708 case DW_AT_MIPS_linkage_name:
6709 part_die->name = DW_STRING (&attr);
6712 has_low_pc_attr = 1;
6713 part_die->lowpc = DW_ADDR (&attr);
6716 has_high_pc_attr = 1;
6717 part_die->highpc = DW_ADDR (&attr);
6719 case DW_AT_location:
6720 /* Support the .debug_loc offsets */
6721 if (attr_form_is_block (&attr))
6723 part_die->locdesc = DW_BLOCK (&attr);
6725 else if (attr_form_is_section_offset (&attr))
6727 dwarf2_complex_location_expr_complaint ();
6731 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6732 "partial symbol information");
6735 case DW_AT_external:
6736 part_die->is_external = DW_UNSND (&attr);
6738 case DW_AT_declaration:
6739 part_die->is_declaration = DW_UNSND (&attr);
6742 part_die->has_type = 1;
6744 case DW_AT_abstract_origin:
6745 case DW_AT_specification:
6746 case DW_AT_extension:
6747 part_die->has_specification = 1;
6748 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
6751 /* Ignore absolute siblings, they might point outside of
6752 the current compile unit. */
6753 if (attr.form == DW_FORM_ref_addr)
6754 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
6756 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
6758 case DW_AT_byte_size:
6759 part_die->has_byte_size = 1;
6761 case DW_AT_calling_convention:
6762 /* DWARF doesn't provide a way to identify a program's source-level
6763 entry point. DW_AT_calling_convention attributes are only meant
6764 to describe functions' calling conventions.
6766 However, because it's a necessary piece of information in
6767 Fortran, and because DW_CC_program is the only piece of debugging
6768 information whose definition refers to a 'main program' at all,
6769 several compilers have begun marking Fortran main programs with
6770 DW_CC_program --- even when those functions use the standard
6771 calling conventions.
6773 So until DWARF specifies a way to provide this information and
6774 compilers pick up the new representation, we'll support this
6776 if (DW_UNSND (&attr) == DW_CC_program
6777 && cu->language == language_fortran)
6778 set_main_name (part_die->name);
6785 /* When using the GNU linker, .gnu.linkonce. sections are used to
6786 eliminate duplicate copies of functions and vtables and such.
6787 The linker will arbitrarily choose one and discard the others.
6788 The AT_*_pc values for such functions refer to local labels in
6789 these sections. If the section from that file was discarded, the
6790 labels are not in the output, so the relocs get a value of 0.
6791 If this is a discarded function, mark the pc bounds as invalid,
6792 so that GDB will ignore it. */
6793 if (has_low_pc_attr && has_high_pc_attr
6794 && part_die->lowpc < part_die->highpc
6795 && (part_die->lowpc != 0
6796 || dwarf2_per_objfile->has_section_at_zero))
6797 part_die->has_pc_info = 1;
6802 /* Find a cached partial DIE at OFFSET in CU. */
6804 static struct partial_die_info *
6805 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
6807 struct partial_die_info *lookup_die = NULL;
6808 struct partial_die_info part_die;
6810 part_die.offset = offset;
6811 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
6816 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6817 except in the case of .debug_types DIEs which do not reference
6818 outside their CU (they do however referencing other types via
6821 static struct partial_die_info *
6822 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
6824 struct dwarf2_per_cu_data *per_cu = NULL;
6825 struct partial_die_info *pd = NULL;
6827 if (cu->per_cu->from_debug_types)
6829 pd = find_partial_die_in_comp_unit (offset, cu);
6835 if (offset_in_cu_p (&cu->header, offset))
6837 pd = find_partial_die_in_comp_unit (offset, cu);
6842 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
6844 if (per_cu->cu == NULL)
6846 load_partial_comp_unit (per_cu, cu->objfile);
6847 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
6848 dwarf2_per_objfile->read_in_chain = per_cu;
6851 per_cu->cu->last_used = 0;
6852 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6854 if (pd == NULL && per_cu->load_all_dies == 0)
6856 struct cleanup *back_to;
6857 struct partial_die_info comp_unit_die;
6858 struct abbrev_info *abbrev;
6859 unsigned int bytes_read;
6862 per_cu->load_all_dies = 1;
6864 /* Re-read the DIEs. */
6865 back_to = make_cleanup (null_cleanup, 0);
6866 if (per_cu->cu->dwarf2_abbrevs == NULL)
6868 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
6869 back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
6871 info_ptr = (dwarf2_per_objfile->info.buffer
6872 + per_cu->cu->header.offset
6873 + per_cu->cu->header.first_die_offset);
6874 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
6875 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
6876 per_cu->cu->objfile->obfd,
6877 dwarf2_per_objfile->info.buffer, info_ptr,
6879 if (comp_unit_die.has_children)
6880 load_partial_dies (per_cu->cu->objfile->obfd,
6881 dwarf2_per_objfile->info.buffer, info_ptr,
6883 do_cleanups (back_to);
6885 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6891 internal_error (__FILE__, __LINE__,
6892 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6893 offset, bfd_get_filename (cu->objfile->obfd));
6897 /* Adjust PART_DIE before generating a symbol for it. This function
6898 may set the is_external flag or change the DIE's name. */
6901 fixup_partial_die (struct partial_die_info *part_die,
6902 struct dwarf2_cu *cu)
6904 /* If we found a reference attribute and the DIE has no name, try
6905 to find a name in the referred to DIE. */
6907 if (part_die->name == NULL && part_die->has_specification)
6909 struct partial_die_info *spec_die;
6911 spec_die = find_partial_die (part_die->spec_offset, cu);
6913 fixup_partial_die (spec_die, cu);
6917 part_die->name = spec_die->name;
6919 /* Copy DW_AT_external attribute if it is set. */
6920 if (spec_die->is_external)
6921 part_die->is_external = spec_die->is_external;
6925 /* Set default names for some unnamed DIEs. */
6926 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
6927 || part_die->tag == DW_TAG_class_type))
6928 part_die->name = "(anonymous class)";
6930 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
6931 part_die->name = "(anonymous namespace)";
6933 if (part_die->tag == DW_TAG_structure_type
6934 || part_die->tag == DW_TAG_class_type
6935 || part_die->tag == DW_TAG_union_type)
6936 guess_structure_name (part_die, cu);
6939 /* Read an attribute value described by an attribute form. */
6942 read_attribute_value (struct attribute *attr, unsigned form,
6943 bfd *abfd, gdb_byte *info_ptr,
6944 struct dwarf2_cu *cu)
6946 struct comp_unit_head *cu_header = &cu->header;
6947 unsigned int bytes_read;
6948 struct dwarf_block *blk;
6954 case DW_FORM_ref_addr:
6955 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
6956 info_ptr += bytes_read;
6958 case DW_FORM_block2:
6959 blk = dwarf_alloc_block (cu);
6960 blk->size = read_2_bytes (abfd, info_ptr);
6962 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6963 info_ptr += blk->size;
6964 DW_BLOCK (attr) = blk;
6966 case DW_FORM_block4:
6967 blk = dwarf_alloc_block (cu);
6968 blk->size = read_4_bytes (abfd, info_ptr);
6970 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6971 info_ptr += blk->size;
6972 DW_BLOCK (attr) = blk;
6975 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
6979 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
6983 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
6986 case DW_FORM_string:
6987 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
6988 DW_STRING_IS_CANONICAL (attr) = 0;
6989 info_ptr += bytes_read;
6992 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
6994 DW_STRING_IS_CANONICAL (attr) = 0;
6995 info_ptr += bytes_read;
6998 blk = dwarf_alloc_block (cu);
6999 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7000 info_ptr += bytes_read;
7001 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7002 info_ptr += blk->size;
7003 DW_BLOCK (attr) = blk;
7005 case DW_FORM_block1:
7006 blk = dwarf_alloc_block (cu);
7007 blk->size = read_1_byte (abfd, info_ptr);
7009 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
7010 info_ptr += blk->size;
7011 DW_BLOCK (attr) = blk;
7014 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7018 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
7022 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
7023 info_ptr += bytes_read;
7026 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7027 info_ptr += bytes_read;
7030 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
7034 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
7038 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
7042 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
7046 /* Convert the signature to something we can record in DW_UNSND
7048 NOTE: This is NULL if the type wasn't found. */
7049 DW_SIGNATURED_TYPE (attr) =
7050 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
7053 case DW_FORM_ref_udata:
7054 DW_ADDR (attr) = (cu->header.offset
7055 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
7056 info_ptr += bytes_read;
7058 case DW_FORM_indirect:
7059 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7060 info_ptr += bytes_read;
7061 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
7064 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7065 dwarf_form_name (form),
7066 bfd_get_filename (abfd));
7069 /* We have seen instances where the compiler tried to emit a byte
7070 size attribute of -1 which ended up being encoded as an unsigned
7071 0xffffffff. Although 0xffffffff is technically a valid size value,
7072 an object of this size seems pretty unlikely so we can relatively
7073 safely treat these cases as if the size attribute was invalid and
7074 treat them as zero by default. */
7075 if (attr->name == DW_AT_byte_size
7076 && form == DW_FORM_data4
7077 && DW_UNSND (attr) >= 0xffffffff)
7080 (&symfile_complaints,
7081 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
7083 DW_UNSND (attr) = 0;
7089 /* Read an attribute described by an abbreviated attribute. */
7092 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
7093 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
7095 attr->name = abbrev->name;
7096 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
7099 /* read dwarf information from a buffer */
7102 read_1_byte (bfd *abfd, gdb_byte *buf)
7104 return bfd_get_8 (abfd, buf);
7108 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
7110 return bfd_get_signed_8 (abfd, buf);
7114 read_2_bytes (bfd *abfd, gdb_byte *buf)
7116 return bfd_get_16 (abfd, buf);
7120 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
7122 return bfd_get_signed_16 (abfd, buf);
7126 read_4_bytes (bfd *abfd, gdb_byte *buf)
7128 return bfd_get_32 (abfd, buf);
7132 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
7134 return bfd_get_signed_32 (abfd, buf);
7138 read_8_bytes (bfd *abfd, gdb_byte *buf)
7140 return bfd_get_64 (abfd, buf);
7144 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
7145 unsigned int *bytes_read)
7147 struct comp_unit_head *cu_header = &cu->header;
7148 CORE_ADDR retval = 0;
7150 if (cu_header->signed_addr_p)
7152 switch (cu_header->addr_size)
7155 retval = bfd_get_signed_16 (abfd, buf);
7158 retval = bfd_get_signed_32 (abfd, buf);
7161 retval = bfd_get_signed_64 (abfd, buf);
7164 internal_error (__FILE__, __LINE__,
7165 _("read_address: bad switch, signed [in module %s]"),
7166 bfd_get_filename (abfd));
7171 switch (cu_header->addr_size)
7174 retval = bfd_get_16 (abfd, buf);
7177 retval = bfd_get_32 (abfd, buf);
7180 retval = bfd_get_64 (abfd, buf);
7183 internal_error (__FILE__, __LINE__,
7184 _("read_address: bad switch, unsigned [in module %s]"),
7185 bfd_get_filename (abfd));
7189 *bytes_read = cu_header->addr_size;
7193 /* Read the initial length from a section. The (draft) DWARF 3
7194 specification allows the initial length to take up either 4 bytes
7195 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7196 bytes describe the length and all offsets will be 8 bytes in length
7199 An older, non-standard 64-bit format is also handled by this
7200 function. The older format in question stores the initial length
7201 as an 8-byte quantity without an escape value. Lengths greater
7202 than 2^32 aren't very common which means that the initial 4 bytes
7203 is almost always zero. Since a length value of zero doesn't make
7204 sense for the 32-bit format, this initial zero can be considered to
7205 be an escape value which indicates the presence of the older 64-bit
7206 format. As written, the code can't detect (old format) lengths
7207 greater than 4GB. If it becomes necessary to handle lengths
7208 somewhat larger than 4GB, we could allow other small values (such
7209 as the non-sensical values of 1, 2, and 3) to also be used as
7210 escape values indicating the presence of the old format.
7212 The value returned via bytes_read should be used to increment the
7213 relevant pointer after calling read_initial_length().
7215 [ Note: read_initial_length() and read_offset() are based on the
7216 document entitled "DWARF Debugging Information Format", revision
7217 3, draft 8, dated November 19, 2001. This document was obtained
7220 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7222 This document is only a draft and is subject to change. (So beware.)
7224 Details regarding the older, non-standard 64-bit format were
7225 determined empirically by examining 64-bit ELF files produced by
7226 the SGI toolchain on an IRIX 6.5 machine.
7228 - Kevin, July 16, 2002
7232 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
7234 LONGEST length = bfd_get_32 (abfd, buf);
7236 if (length == 0xffffffff)
7238 length = bfd_get_64 (abfd, buf + 4);
7241 else if (length == 0)
7243 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7244 length = bfd_get_64 (abfd, buf);
7255 /* Cover function for read_initial_length.
7256 Returns the length of the object at BUF, and stores the size of the
7257 initial length in *BYTES_READ and stores the size that offsets will be in
7259 If the initial length size is not equivalent to that specified in
7260 CU_HEADER then issue a complaint.
7261 This is useful when reading non-comp-unit headers. */
7264 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
7265 const struct comp_unit_head *cu_header,
7266 unsigned int *bytes_read,
7267 unsigned int *offset_size)
7269 LONGEST length = read_initial_length (abfd, buf, bytes_read);
7271 gdb_assert (cu_header->initial_length_size == 4
7272 || cu_header->initial_length_size == 8
7273 || cu_header->initial_length_size == 12);
7275 if (cu_header->initial_length_size != *bytes_read)
7276 complaint (&symfile_complaints,
7277 _("intermixed 32-bit and 64-bit DWARF sections"));
7279 *offset_size = (*bytes_read == 4) ? 4 : 8;
7283 /* Read an offset from the data stream. The size of the offset is
7284 given by cu_header->offset_size. */
7287 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
7288 unsigned int *bytes_read)
7290 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
7291 *bytes_read = cu_header->offset_size;
7295 /* Read an offset from the data stream. */
7298 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
7302 switch (offset_size)
7305 retval = bfd_get_32 (abfd, buf);
7308 retval = bfd_get_64 (abfd, buf);
7311 internal_error (__FILE__, __LINE__,
7312 _("read_offset_1: bad switch [in module %s]"),
7313 bfd_get_filename (abfd));
7320 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
7322 /* If the size of a host char is 8 bits, we can return a pointer
7323 to the buffer, otherwise we have to copy the data to a buffer
7324 allocated on the temporary obstack. */
7325 gdb_assert (HOST_CHAR_BIT == 8);
7330 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7332 /* If the size of a host char is 8 bits, we can return a pointer
7333 to the string, otherwise we have to copy the string to a buffer
7334 allocated on the temporary obstack. */
7335 gdb_assert (HOST_CHAR_BIT == 8);
7338 *bytes_read_ptr = 1;
7341 *bytes_read_ptr = strlen ((char *) buf) + 1;
7342 return (char *) buf;
7346 read_indirect_string (bfd *abfd, gdb_byte *buf,
7347 const struct comp_unit_head *cu_header,
7348 unsigned int *bytes_read_ptr)
7350 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
7352 if (dwarf2_per_objfile->str.buffer == NULL)
7354 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7355 bfd_get_filename (abfd));
7358 if (str_offset >= dwarf2_per_objfile->str.size)
7360 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7361 bfd_get_filename (abfd));
7364 gdb_assert (HOST_CHAR_BIT == 8);
7365 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
7367 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
7370 static unsigned long
7371 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7373 unsigned long result;
7374 unsigned int num_read;
7384 byte = bfd_get_8 (abfd, buf);
7387 result |= ((unsigned long)(byte & 127) << shift);
7388 if ((byte & 128) == 0)
7394 *bytes_read_ptr = num_read;
7399 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
7402 int i, shift, num_read;
7411 byte = bfd_get_8 (abfd, buf);
7414 result |= ((long)(byte & 127) << shift);
7416 if ((byte & 128) == 0)
7421 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
7422 result |= -(((long)1) << shift);
7423 *bytes_read_ptr = num_read;
7427 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7430 skip_leb128 (bfd *abfd, gdb_byte *buf)
7436 byte = bfd_get_8 (abfd, buf);
7438 if ((byte & 128) == 0)
7444 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
7451 cu->language = language_c;
7453 case DW_LANG_C_plus_plus:
7454 cu->language = language_cplus;
7456 case DW_LANG_Fortran77:
7457 case DW_LANG_Fortran90:
7458 case DW_LANG_Fortran95:
7459 cu->language = language_fortran;
7461 case DW_LANG_Mips_Assembler:
7462 cu->language = language_asm;
7465 cu->language = language_java;
7469 cu->language = language_ada;
7471 case DW_LANG_Modula2:
7472 cu->language = language_m2;
7474 case DW_LANG_Pascal83:
7475 cu->language = language_pascal;
7478 cu->language = language_objc;
7480 case DW_LANG_Cobol74:
7481 case DW_LANG_Cobol85:
7483 cu->language = language_minimal;
7486 cu->language_defn = language_def (cu->language);
7489 /* Return the named attribute or NULL if not there. */
7491 static struct attribute *
7492 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
7495 struct attribute *spec = NULL;
7497 for (i = 0; i < die->num_attrs; ++i)
7499 if (die->attrs[i].name == name)
7500 return &die->attrs[i];
7501 if (die->attrs[i].name == DW_AT_specification
7502 || die->attrs[i].name == DW_AT_abstract_origin)
7503 spec = &die->attrs[i];
7508 die = follow_die_ref (die, spec, &cu);
7509 return dwarf2_attr (die, name, cu);
7515 /* Return the named attribute or NULL if not there,
7516 but do not follow DW_AT_specification, etc.
7517 This is for use in contexts where we're reading .debug_types dies.
7518 Following DW_AT_specification, DW_AT_abstract_origin will take us
7519 back up the chain, and we want to go down. */
7521 static struct attribute *
7522 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
7523 struct dwarf2_cu *cu)
7527 for (i = 0; i < die->num_attrs; ++i)
7528 if (die->attrs[i].name == name)
7529 return &die->attrs[i];
7534 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7535 and holds a non-zero value. This function should only be used for
7536 DW_FORM_flag attributes. */
7539 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
7541 struct attribute *attr = dwarf2_attr (die, name, cu);
7543 return (attr && DW_UNSND (attr));
7547 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
7549 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7550 which value is non-zero. However, we have to be careful with
7551 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7552 (via dwarf2_flag_true_p) follows this attribute. So we may
7553 end up accidently finding a declaration attribute that belongs
7554 to a different DIE referenced by the specification attribute,
7555 even though the given DIE does not have a declaration attribute. */
7556 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
7557 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
7560 /* Return the die giving the specification for DIE, if there is
7561 one. *SPEC_CU is the CU containing DIE on input, and the CU
7562 containing the return value on output. If there is no
7563 specification, but there is an abstract origin, that is
7566 static struct die_info *
7567 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
7569 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
7572 if (spec_attr == NULL)
7573 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
7575 if (spec_attr == NULL)
7578 return follow_die_ref (die, spec_attr, spec_cu);
7581 /* Free the line_header structure *LH, and any arrays and strings it
7584 free_line_header (struct line_header *lh)
7586 if (lh->standard_opcode_lengths)
7587 xfree (lh->standard_opcode_lengths);
7589 /* Remember that all the lh->file_names[i].name pointers are
7590 pointers into debug_line_buffer, and don't need to be freed. */
7592 xfree (lh->file_names);
7594 /* Similarly for the include directory names. */
7595 if (lh->include_dirs)
7596 xfree (lh->include_dirs);
7602 /* Add an entry to LH's include directory table. */
7604 add_include_dir (struct line_header *lh, char *include_dir)
7606 /* Grow the array if necessary. */
7607 if (lh->include_dirs_size == 0)
7609 lh->include_dirs_size = 1; /* for testing */
7610 lh->include_dirs = xmalloc (lh->include_dirs_size
7611 * sizeof (*lh->include_dirs));
7613 else if (lh->num_include_dirs >= lh->include_dirs_size)
7615 lh->include_dirs_size *= 2;
7616 lh->include_dirs = xrealloc (lh->include_dirs,
7617 (lh->include_dirs_size
7618 * sizeof (*lh->include_dirs)));
7621 lh->include_dirs[lh->num_include_dirs++] = include_dir;
7625 /* Add an entry to LH's file name table. */
7627 add_file_name (struct line_header *lh,
7629 unsigned int dir_index,
7630 unsigned int mod_time,
7631 unsigned int length)
7633 struct file_entry *fe;
7635 /* Grow the array if necessary. */
7636 if (lh->file_names_size == 0)
7638 lh->file_names_size = 1; /* for testing */
7639 lh->file_names = xmalloc (lh->file_names_size
7640 * sizeof (*lh->file_names));
7642 else if (lh->num_file_names >= lh->file_names_size)
7644 lh->file_names_size *= 2;
7645 lh->file_names = xrealloc (lh->file_names,
7646 (lh->file_names_size
7647 * sizeof (*lh->file_names)));
7650 fe = &lh->file_names[lh->num_file_names++];
7652 fe->dir_index = dir_index;
7653 fe->mod_time = mod_time;
7654 fe->length = length;
7660 /* Read the statement program header starting at OFFSET in
7661 .debug_line, according to the endianness of ABFD. Return a pointer
7662 to a struct line_header, allocated using xmalloc.
7664 NOTE: the strings in the include directory and file name tables of
7665 the returned object point into debug_line_buffer, and must not be
7667 static struct line_header *
7668 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
7669 struct dwarf2_cu *cu)
7671 struct cleanup *back_to;
7672 struct line_header *lh;
7674 unsigned int bytes_read, offset_size;
7676 char *cur_dir, *cur_file;
7678 if (dwarf2_per_objfile->line.buffer == NULL)
7680 complaint (&symfile_complaints, _("missing .debug_line section"));
7684 /* Make sure that at least there's room for the total_length field.
7685 That could be 12 bytes long, but we're just going to fudge that. */
7686 if (offset + 4 >= dwarf2_per_objfile->line.size)
7688 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7692 lh = xmalloc (sizeof (*lh));
7693 memset (lh, 0, sizeof (*lh));
7694 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
7697 line_ptr = dwarf2_per_objfile->line.buffer + offset;
7699 /* Read in the header. */
7701 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
7702 &bytes_read, &offset_size);
7703 line_ptr += bytes_read;
7704 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
7705 + dwarf2_per_objfile->line.size))
7707 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7710 lh->statement_program_end = line_ptr + lh->total_length;
7711 lh->version = read_2_bytes (abfd, line_ptr);
7713 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
7714 line_ptr += offset_size;
7715 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
7717 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
7719 lh->line_base = read_1_signed_byte (abfd, line_ptr);
7721 lh->line_range = read_1_byte (abfd, line_ptr);
7723 lh->opcode_base = read_1_byte (abfd, line_ptr);
7725 lh->standard_opcode_lengths
7726 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
7728 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
7729 for (i = 1; i < lh->opcode_base; ++i)
7731 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
7735 /* Read directory table. */
7736 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7738 line_ptr += bytes_read;
7739 add_include_dir (lh, cur_dir);
7741 line_ptr += bytes_read;
7743 /* Read file name table. */
7744 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7746 unsigned int dir_index, mod_time, length;
7748 line_ptr += bytes_read;
7749 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7750 line_ptr += bytes_read;
7751 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7752 line_ptr += bytes_read;
7753 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7754 line_ptr += bytes_read;
7756 add_file_name (lh, cur_file, dir_index, mod_time, length);
7758 line_ptr += bytes_read;
7759 lh->statement_program_start = line_ptr;
7761 if (line_ptr > (dwarf2_per_objfile->line.buffer
7762 + dwarf2_per_objfile->line.size))
7763 complaint (&symfile_complaints,
7764 _("line number info header doesn't fit in `.debug_line' section"));
7766 discard_cleanups (back_to);
7770 /* This function exists to work around a bug in certain compilers
7771 (particularly GCC 2.95), in which the first line number marker of a
7772 function does not show up until after the prologue, right before
7773 the second line number marker. This function shifts ADDRESS down
7774 to the beginning of the function if necessary, and is called on
7775 addresses passed to record_line. */
7778 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
7780 struct function_range *fn;
7782 /* Find the function_range containing address. */
7787 cu->cached_fn = cu->first_fn;
7791 if (fn->lowpc <= address && fn->highpc > address)
7797 while (fn && fn != cu->cached_fn)
7798 if (fn->lowpc <= address && fn->highpc > address)
7808 if (address != fn->lowpc)
7809 complaint (&symfile_complaints,
7810 _("misplaced first line number at 0x%lx for '%s'"),
7811 (unsigned long) address, fn->name);
7816 /* Decode the Line Number Program (LNP) for the given line_header
7817 structure and CU. The actual information extracted and the type
7818 of structures created from the LNP depends on the value of PST.
7820 1. If PST is NULL, then this procedure uses the data from the program
7821 to create all necessary symbol tables, and their linetables.
7822 The compilation directory of the file is passed in COMP_DIR,
7823 and must not be NULL.
7825 2. If PST is not NULL, this procedure reads the program to determine
7826 the list of files included by the unit represented by PST, and
7827 builds all the associated partial symbol tables. In this case,
7828 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7829 is not used to compute the full name of the symtab, and therefore
7830 omitting it when building the partial symtab does not introduce
7831 the potential for inconsistency - a partial symtab and its associated
7832 symbtab having a different fullname -). */
7835 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
7836 struct dwarf2_cu *cu, struct partial_symtab *pst)
7838 gdb_byte *line_ptr, *extended_end;
7840 unsigned int bytes_read, extended_len;
7841 unsigned char op_code, extended_op, adj_opcode;
7843 struct objfile *objfile = cu->objfile;
7844 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7845 const int decode_for_pst_p = (pst != NULL);
7846 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
7848 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7850 line_ptr = lh->statement_program_start;
7851 line_end = lh->statement_program_end;
7853 /* Read the statement sequences until there's nothing left. */
7854 while (line_ptr < line_end)
7856 /* state machine registers */
7857 CORE_ADDR address = 0;
7858 unsigned int file = 1;
7859 unsigned int line = 1;
7860 unsigned int column = 0;
7861 int is_stmt = lh->default_is_stmt;
7862 int basic_block = 0;
7863 int end_sequence = 0;
7866 if (!decode_for_pst_p && lh->num_file_names >= file)
7868 /* Start a subfile for the current file of the state machine. */
7869 /* lh->include_dirs and lh->file_names are 0-based, but the
7870 directory and file name numbers in the statement program
7872 struct file_entry *fe = &lh->file_names[file - 1];
7876 dir = lh->include_dirs[fe->dir_index - 1];
7878 dwarf2_start_subfile (fe->name, dir, comp_dir);
7881 /* Decode the table. */
7882 while (!end_sequence)
7884 op_code = read_1_byte (abfd, line_ptr);
7886 if (line_ptr > line_end)
7888 dwarf2_debug_line_missing_end_sequence_complaint ();
7892 if (op_code >= lh->opcode_base)
7894 /* Special operand. */
7895 adj_opcode = op_code - lh->opcode_base;
7896 address += (adj_opcode / lh->line_range)
7897 * lh->minimum_instruction_length;
7898 line += lh->line_base + (adj_opcode % lh->line_range);
7899 if (lh->num_file_names < file || file == 0)
7900 dwarf2_debug_line_missing_file_complaint ();
7903 lh->file_names[file - 1].included_p = 1;
7904 if (!decode_for_pst_p && is_stmt)
7906 if (last_subfile != current_subfile)
7908 addr = gdbarch_addr_bits_remove (gdbarch, address);
7910 record_line (last_subfile, 0, addr);
7911 last_subfile = current_subfile;
7913 /* Append row to matrix using current values. */
7914 addr = check_cu_functions (address, cu);
7915 addr = gdbarch_addr_bits_remove (gdbarch, addr);
7916 record_line (current_subfile, line, addr);
7921 else switch (op_code)
7923 case DW_LNS_extended_op:
7924 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7925 line_ptr += bytes_read;
7926 extended_end = line_ptr + extended_len;
7927 extended_op = read_1_byte (abfd, line_ptr);
7929 switch (extended_op)
7931 case DW_LNE_end_sequence:
7934 case DW_LNE_set_address:
7935 address = read_address (abfd, line_ptr, cu, &bytes_read);
7936 line_ptr += bytes_read;
7937 address += baseaddr;
7939 case DW_LNE_define_file:
7942 unsigned int dir_index, mod_time, length;
7944 cur_file = read_string (abfd, line_ptr, &bytes_read);
7945 line_ptr += bytes_read;
7947 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7948 line_ptr += bytes_read;
7950 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7951 line_ptr += bytes_read;
7953 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7954 line_ptr += bytes_read;
7955 add_file_name (lh, cur_file, dir_index, mod_time, length);
7958 case DW_LNE_set_discriminator:
7959 /* The discriminator is not interesting to the debugger;
7961 line_ptr = extended_end;
7964 complaint (&symfile_complaints,
7965 _("mangled .debug_line section"));
7968 /* Make sure that we parsed the extended op correctly. If e.g.
7969 we expected a different address size than the producer used,
7970 we may have read the wrong number of bytes. */
7971 if (line_ptr != extended_end)
7973 complaint (&symfile_complaints,
7974 _("mangled .debug_line section"));
7979 if (lh->num_file_names < file || file == 0)
7980 dwarf2_debug_line_missing_file_complaint ();
7983 lh->file_names[file - 1].included_p = 1;
7984 if (!decode_for_pst_p && is_stmt)
7986 if (last_subfile != current_subfile)
7988 addr = gdbarch_addr_bits_remove (gdbarch, address);
7990 record_line (last_subfile, 0, addr);
7991 last_subfile = current_subfile;
7993 addr = check_cu_functions (address, cu);
7994 addr = gdbarch_addr_bits_remove (gdbarch, addr);
7995 record_line (current_subfile, line, addr);
8000 case DW_LNS_advance_pc:
8001 address += lh->minimum_instruction_length
8002 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8003 line_ptr += bytes_read;
8005 case DW_LNS_advance_line:
8006 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
8007 line_ptr += bytes_read;
8009 case DW_LNS_set_file:
8011 /* The arrays lh->include_dirs and lh->file_names are
8012 0-based, but the directory and file name numbers in
8013 the statement program are 1-based. */
8014 struct file_entry *fe;
8017 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8018 line_ptr += bytes_read;
8019 if (lh->num_file_names < file || file == 0)
8020 dwarf2_debug_line_missing_file_complaint ();
8023 fe = &lh->file_names[file - 1];
8025 dir = lh->include_dirs[fe->dir_index - 1];
8026 if (!decode_for_pst_p)
8028 last_subfile = current_subfile;
8029 dwarf2_start_subfile (fe->name, dir, comp_dir);
8034 case DW_LNS_set_column:
8035 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8036 line_ptr += bytes_read;
8038 case DW_LNS_negate_stmt:
8039 is_stmt = (!is_stmt);
8041 case DW_LNS_set_basic_block:
8044 /* Add to the address register of the state machine the
8045 address increment value corresponding to special opcode
8046 255. I.e., this value is scaled by the minimum
8047 instruction length since special opcode 255 would have
8048 scaled the the increment. */
8049 case DW_LNS_const_add_pc:
8050 address += (lh->minimum_instruction_length
8051 * ((255 - lh->opcode_base) / lh->line_range));
8053 case DW_LNS_fixed_advance_pc:
8054 address += read_2_bytes (abfd, line_ptr);
8059 /* Unknown standard opcode, ignore it. */
8062 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
8064 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
8065 line_ptr += bytes_read;
8070 if (lh->num_file_names < file || file == 0)
8071 dwarf2_debug_line_missing_file_complaint ();
8074 lh->file_names[file - 1].included_p = 1;
8075 if (!decode_for_pst_p)
8077 addr = gdbarch_addr_bits_remove (gdbarch, address);
8078 record_line (current_subfile, 0, addr);
8083 if (decode_for_pst_p)
8087 /* Now that we're done scanning the Line Header Program, we can
8088 create the psymtab of each included file. */
8089 for (file_index = 0; file_index < lh->num_file_names; file_index++)
8090 if (lh->file_names[file_index].included_p == 1)
8092 const struct file_entry fe = lh->file_names [file_index];
8093 char *include_name = fe.name;
8094 char *dir_name = NULL;
8095 char *pst_filename = pst->filename;
8098 dir_name = lh->include_dirs[fe.dir_index - 1];
8100 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
8102 include_name = concat (dir_name, SLASH_STRING,
8103 include_name, (char *)NULL);
8104 make_cleanup (xfree, include_name);
8107 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
8109 pst_filename = concat (pst->dirname, SLASH_STRING,
8110 pst_filename, (char *)NULL);
8111 make_cleanup (xfree, pst_filename);
8114 if (strcmp (include_name, pst_filename) != 0)
8115 dwarf2_create_include_psymtab (include_name, pst, objfile);
8120 /* Make sure a symtab is created for every file, even files
8121 which contain only variables (i.e. no code with associated
8125 struct file_entry *fe;
8127 for (i = 0; i < lh->num_file_names; i++)
8130 fe = &lh->file_names[i];
8132 dir = lh->include_dirs[fe->dir_index - 1];
8133 dwarf2_start_subfile (fe->name, dir, comp_dir);
8135 /* Skip the main file; we don't need it, and it must be
8136 allocated last, so that it will show up before the
8137 non-primary symtabs in the objfile's symtab list. */
8138 if (current_subfile == first_subfile)
8141 if (current_subfile->symtab == NULL)
8142 current_subfile->symtab = allocate_symtab (current_subfile->name,
8144 fe->symtab = current_subfile->symtab;
8149 /* Start a subfile for DWARF. FILENAME is the name of the file and
8150 DIRNAME the name of the source directory which contains FILENAME
8151 or NULL if not known. COMP_DIR is the compilation directory for the
8152 linetable's compilation unit or NULL if not known.
8153 This routine tries to keep line numbers from identical absolute and
8154 relative file names in a common subfile.
8156 Using the `list' example from the GDB testsuite, which resides in
8157 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8158 of /srcdir/list0.c yields the following debugging information for list0.c:
8160 DW_AT_name: /srcdir/list0.c
8161 DW_AT_comp_dir: /compdir
8162 files.files[0].name: list0.h
8163 files.files[0].dir: /srcdir
8164 files.files[1].name: list0.c
8165 files.files[1].dir: /srcdir
8167 The line number information for list0.c has to end up in a single
8168 subfile, so that `break /srcdir/list0.c:1' works as expected.
8169 start_subfile will ensure that this happens provided that we pass the
8170 concatenation of files.files[1].dir and files.files[1].name as the
8174 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
8178 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8179 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8180 second argument to start_subfile. To be consistent, we do the
8181 same here. In order not to lose the line information directory,
8182 we concatenate it to the filename when it makes sense.
8183 Note that the Dwarf3 standard says (speaking of filenames in line
8184 information): ``The directory index is ignored for file names
8185 that represent full path names''. Thus ignoring dirname in the
8186 `else' branch below isn't an issue. */
8188 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
8189 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
8191 fullname = filename;
8193 start_subfile (fullname, comp_dir);
8195 if (fullname != filename)
8200 var_decode_location (struct attribute *attr, struct symbol *sym,
8201 struct dwarf2_cu *cu)
8203 struct objfile *objfile = cu->objfile;
8204 struct comp_unit_head *cu_header = &cu->header;
8206 /* NOTE drow/2003-01-30: There used to be a comment and some special
8207 code here to turn a symbol with DW_AT_external and a
8208 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8209 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8210 with some versions of binutils) where shared libraries could have
8211 relocations against symbols in their debug information - the
8212 minimal symbol would have the right address, but the debug info
8213 would not. It's no longer necessary, because we will explicitly
8214 apply relocations when we read in the debug information now. */
8216 /* A DW_AT_location attribute with no contents indicates that a
8217 variable has been optimized away. */
8218 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
8220 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8224 /* Handle one degenerate form of location expression specially, to
8225 preserve GDB's previous behavior when section offsets are
8226 specified. If this is just a DW_OP_addr then mark this symbol
8229 if (attr_form_is_block (attr)
8230 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
8231 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
8235 SYMBOL_VALUE_ADDRESS (sym) =
8236 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
8237 SYMBOL_CLASS (sym) = LOC_STATIC;
8238 fixup_symbol_section (sym, objfile);
8239 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
8240 SYMBOL_SECTION (sym));
8244 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8245 expression evaluator, and use LOC_COMPUTED only when necessary
8246 (i.e. when the value of a register or memory location is
8247 referenced, or a thread-local block, etc.). Then again, it might
8248 not be worthwhile. I'm assuming that it isn't unless performance
8249 or memory numbers show me otherwise. */
8251 dwarf2_symbol_mark_computed (attr, sym, cu);
8252 SYMBOL_CLASS (sym) = LOC_COMPUTED;
8255 /* Given a pointer to a DWARF information entry, figure out if we need
8256 to make a symbol table entry for it, and if so, create a new entry
8257 and return a pointer to it.
8258 If TYPE is NULL, determine symbol type from the die, otherwise
8259 used the passed type. */
8261 static struct symbol *
8262 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
8264 struct objfile *objfile = cu->objfile;
8265 struct symbol *sym = NULL;
8267 struct attribute *attr = NULL;
8268 struct attribute *attr2 = NULL;
8270 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
8272 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8274 if (die->tag != DW_TAG_namespace)
8275 name = dwarf2_linkage_name (die, cu);
8277 name = TYPE_NAME (type);
8281 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
8282 sizeof (struct symbol));
8283 OBJSTAT (objfile, n_syms++);
8284 memset (sym, 0, sizeof (struct symbol));
8286 /* Cache this symbol's name and the name's demangled form (if any). */
8287 SYMBOL_LANGUAGE (sym) = cu->language;
8288 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
8290 /* Default assumptions.
8291 Use the passed type or decode it from the die. */
8292 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8293 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
8295 SYMBOL_TYPE (sym) = type;
8297 SYMBOL_TYPE (sym) = die_type (die, cu);
8298 attr = dwarf2_attr (die,
8299 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
8303 SYMBOL_LINE (sym) = DW_UNSND (attr);
8306 attr = dwarf2_attr (die,
8307 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
8311 int file_index = DW_UNSND (attr);
8312 if (cu->line_header == NULL
8313 || file_index > cu->line_header->num_file_names)
8314 complaint (&symfile_complaints,
8315 _("file index out of range"));
8316 else if (file_index > 0)
8318 struct file_entry *fe;
8319 fe = &cu->line_header->file_names[file_index - 1];
8320 SYMBOL_SYMTAB (sym) = fe->symtab;
8327 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
8330 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
8332 SYMBOL_CLASS (sym) = LOC_LABEL;
8334 case DW_TAG_subprogram:
8335 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8337 SYMBOL_CLASS (sym) = LOC_BLOCK;
8338 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8339 if ((attr2 && (DW_UNSND (attr2) != 0))
8340 || cu->language == language_ada)
8342 /* Subprograms marked external are stored as a global symbol.
8343 Ada subprograms, whether marked external or not, are always
8344 stored as a global symbol, because we want to be able to
8345 access them globally. For instance, we want to be able
8346 to break on a nested subprogram without having to
8347 specify the context. */
8348 add_symbol_to_list (sym, &global_symbols);
8352 add_symbol_to_list (sym, cu->list_in_scope);
8355 case DW_TAG_inlined_subroutine:
8356 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8358 SYMBOL_CLASS (sym) = LOC_BLOCK;
8359 SYMBOL_INLINED (sym) = 1;
8360 /* Do not add the symbol to any lists. It will be found via
8361 BLOCK_FUNCTION from the blockvector. */
8363 case DW_TAG_variable:
8364 /* Compilation with minimal debug info may result in variables
8365 with missing type entries. Change the misleading `void' type
8366 to something sensible. */
8367 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
8369 = objfile_type (objfile)->nodebug_data_symbol;
8371 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8374 dwarf2_const_value (attr, sym, cu);
8375 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8376 if (attr2 && (DW_UNSND (attr2) != 0))
8377 add_symbol_to_list (sym, &global_symbols);
8379 add_symbol_to_list (sym, cu->list_in_scope);
8382 attr = dwarf2_attr (die, DW_AT_location, cu);
8385 var_decode_location (attr, sym, cu);
8386 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8387 if (attr2 && (DW_UNSND (attr2) != 0))
8388 add_symbol_to_list (sym, &global_symbols);
8390 add_symbol_to_list (sym, cu->list_in_scope);
8394 /* We do not know the address of this symbol.
8395 If it is an external symbol and we have type information
8396 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8397 The address of the variable will then be determined from
8398 the minimal symbol table whenever the variable is
8400 attr2 = dwarf2_attr (die, DW_AT_external, cu);
8401 if (attr2 && (DW_UNSND (attr2) != 0)
8402 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
8404 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
8405 add_symbol_to_list (sym, cu->list_in_scope);
8407 else if (!die_is_declaration (die, cu))
8409 /* Use the default LOC_OPTIMIZED_OUT class. */
8410 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
8411 add_symbol_to_list (sym, cu->list_in_scope);
8415 case DW_TAG_formal_parameter:
8416 /* If we are inside a function, mark this as an argument. If
8417 not, we might be looking at an argument to an inlined function
8418 when we do not have enough information to show inlined frames;
8419 pretend it's a local variable in that case so that the user can
8421 if (context_stack_depth > 0
8422 && context_stack[context_stack_depth - 1].name != NULL)
8423 SYMBOL_IS_ARGUMENT (sym) = 1;
8424 attr = dwarf2_attr (die, DW_AT_location, cu);
8427 var_decode_location (attr, sym, cu);
8429 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8432 dwarf2_const_value (attr, sym, cu);
8434 add_symbol_to_list (sym, cu->list_in_scope);
8436 case DW_TAG_unspecified_parameters:
8437 /* From varargs functions; gdb doesn't seem to have any
8438 interest in this information, so just ignore it for now.
8441 case DW_TAG_class_type:
8442 case DW_TAG_interface_type:
8443 case DW_TAG_structure_type:
8444 case DW_TAG_union_type:
8445 case DW_TAG_set_type:
8446 case DW_TAG_enumeration_type:
8447 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8448 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
8450 /* Make sure that the symbol includes appropriate enclosing
8451 classes/namespaces in its name. These are calculated in
8452 read_structure_type, and the correct name is saved in
8455 if (cu->language == language_cplus
8456 || cu->language == language_java)
8458 struct type *type = SYMBOL_TYPE (sym);
8460 if (TYPE_TAG_NAME (type) != NULL)
8462 /* FIXME: carlton/2003-11-10: Should this use
8463 SYMBOL_SET_NAMES instead? (The same problem also
8464 arises further down in this function.) */
8465 /* The type's name is already allocated along with
8466 this objfile, so we don't need to duplicate it
8468 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
8473 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8474 really ever be static objects: otherwise, if you try
8475 to, say, break of a class's method and you're in a file
8476 which doesn't mention that class, it won't work unless
8477 the check for all static symbols in lookup_symbol_aux
8478 saves you. See the OtherFileClass tests in
8479 gdb.c++/namespace.exp. */
8481 struct pending **list_to_add;
8483 list_to_add = (cu->list_in_scope == &file_symbols
8484 && (cu->language == language_cplus
8485 || cu->language == language_java)
8486 ? &global_symbols : cu->list_in_scope);
8488 add_symbol_to_list (sym, list_to_add);
8490 /* The semantics of C++ state that "struct foo { ... }" also
8491 defines a typedef for "foo". A Java class declaration also
8492 defines a typedef for the class. */
8493 if (cu->language == language_cplus
8494 || cu->language == language_java
8495 || cu->language == language_ada)
8497 /* The symbol's name is already allocated along with
8498 this objfile, so we don't need to duplicate it for
8500 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
8501 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
8505 case DW_TAG_typedef:
8506 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
8507 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8508 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8509 add_symbol_to_list (sym, cu->list_in_scope);
8511 case DW_TAG_base_type:
8512 case DW_TAG_subrange_type:
8513 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8514 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8515 add_symbol_to_list (sym, cu->list_in_scope);
8517 case DW_TAG_enumerator:
8518 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
8519 attr = dwarf2_attr (die, DW_AT_const_value, cu);
8522 dwarf2_const_value (attr, sym, cu);
8525 /* NOTE: carlton/2003-11-10: See comment above in the
8526 DW_TAG_class_type, etc. block. */
8528 struct pending **list_to_add;
8530 list_to_add = (cu->list_in_scope == &file_symbols
8531 && (cu->language == language_cplus
8532 || cu->language == language_java)
8533 ? &global_symbols : cu->list_in_scope);
8535 add_symbol_to_list (sym, list_to_add);
8538 case DW_TAG_namespace:
8539 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
8540 add_symbol_to_list (sym, &global_symbols);
8543 /* Not a tag we recognize. Hopefully we aren't processing
8544 trash data, but since we must specifically ignore things
8545 we don't recognize, there is nothing else we should do at
8547 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
8548 dwarf_tag_name (die->tag));
8552 /* For the benefit of old versions of GCC, check for anonymous
8553 namespaces based on the demangled name. */
8554 if (!processing_has_namespace_info
8555 && cu->language == language_cplus
8556 && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
8557 cp_scan_for_anonymous_namespaces (sym);
8562 /* Copy constant value from an attribute to a symbol. */
8565 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
8566 struct dwarf2_cu *cu)
8568 struct objfile *objfile = cu->objfile;
8569 struct comp_unit_head *cu_header = &cu->header;
8570 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
8571 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
8572 struct dwarf_block *blk;
8577 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
8578 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
8579 cu_header->addr_size,
8580 TYPE_LENGTH (SYMBOL_TYPE
8582 SYMBOL_VALUE_BYTES (sym) =
8583 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
8584 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8585 it's body - store_unsigned_integer. */
8586 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
8587 byte_order, DW_ADDR (attr));
8588 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8590 case DW_FORM_string:
8592 /* DW_STRING is already allocated on the obstack, point directly
8594 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
8595 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8597 case DW_FORM_block1:
8598 case DW_FORM_block2:
8599 case DW_FORM_block4:
8601 blk = DW_BLOCK (attr);
8602 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
8603 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
8605 TYPE_LENGTH (SYMBOL_TYPE
8607 SYMBOL_VALUE_BYTES (sym) =
8608 obstack_alloc (&objfile->objfile_obstack, blk->size);
8609 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
8610 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
8613 /* The DW_AT_const_value attributes are supposed to carry the
8614 symbol's value "represented as it would be on the target
8615 architecture." By the time we get here, it's already been
8616 converted to host endianness, so we just need to sign- or
8617 zero-extend it as appropriate. */
8619 dwarf2_const_value_data (attr, sym, 8);
8622 dwarf2_const_value_data (attr, sym, 16);
8625 dwarf2_const_value_data (attr, sym, 32);
8628 dwarf2_const_value_data (attr, sym, 64);
8632 SYMBOL_VALUE (sym) = DW_SND (attr);
8633 SYMBOL_CLASS (sym) = LOC_CONST;
8637 SYMBOL_VALUE (sym) = DW_UNSND (attr);
8638 SYMBOL_CLASS (sym) = LOC_CONST;
8642 complaint (&symfile_complaints,
8643 _("unsupported const value attribute form: '%s'"),
8644 dwarf_form_name (attr->form));
8645 SYMBOL_VALUE (sym) = 0;
8646 SYMBOL_CLASS (sym) = LOC_CONST;
8652 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8653 or zero-extend it as appropriate for the symbol's type. */
8655 dwarf2_const_value_data (struct attribute *attr,
8659 LONGEST l = DW_UNSND (attr);
8661 if (bits < sizeof (l) * 8)
8663 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
8664 l &= ((LONGEST) 1 << bits) - 1;
8666 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
8669 SYMBOL_VALUE (sym) = l;
8670 SYMBOL_CLASS (sym) = LOC_CONST;
8674 /* Return the type of the die in question using its DW_AT_type attribute. */
8676 static struct type *
8677 die_type (struct die_info *die, struct dwarf2_cu *cu)
8680 struct attribute *type_attr;
8681 struct die_info *type_die;
8683 type_attr = dwarf2_attr (die, DW_AT_type, cu);
8686 /* A missing DW_AT_type represents a void type. */
8687 return objfile_type (cu->objfile)->builtin_void;
8690 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
8692 type = tag_type_to_type (type_die, cu);
8695 dump_die_for_error (type_die);
8696 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8702 /* Return the containing type of the die in question using its
8703 DW_AT_containing_type attribute. */
8705 static struct type *
8706 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
8708 struct type *type = NULL;
8709 struct attribute *type_attr;
8710 struct die_info *type_die = NULL;
8712 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
8715 type_die = follow_die_ref_or_sig (die, type_attr, &cu);
8716 type = tag_type_to_type (type_die, cu);
8721 dump_die_for_error (type_die);
8722 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8728 static struct type *
8729 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
8731 struct type *this_type;
8733 this_type = read_type_die (die, cu);
8736 dump_die_for_error (die);
8737 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8743 static struct type *
8744 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
8746 struct type *this_type;
8748 this_type = get_die_type (die, cu);
8754 case DW_TAG_class_type:
8755 case DW_TAG_interface_type:
8756 case DW_TAG_structure_type:
8757 case DW_TAG_union_type:
8758 this_type = read_structure_type (die, cu);
8760 case DW_TAG_enumeration_type:
8761 this_type = read_enumeration_type (die, cu);
8763 case DW_TAG_subprogram:
8764 case DW_TAG_subroutine_type:
8765 case DW_TAG_inlined_subroutine:
8766 this_type = read_subroutine_type (die, cu);
8768 case DW_TAG_array_type:
8769 this_type = read_array_type (die, cu);
8771 case DW_TAG_set_type:
8772 this_type = read_set_type (die, cu);
8774 case DW_TAG_pointer_type:
8775 this_type = read_tag_pointer_type (die, cu);
8777 case DW_TAG_ptr_to_member_type:
8778 this_type = read_tag_ptr_to_member_type (die, cu);
8780 case DW_TAG_reference_type:
8781 this_type = read_tag_reference_type (die, cu);
8783 case DW_TAG_const_type:
8784 this_type = read_tag_const_type (die, cu);
8786 case DW_TAG_volatile_type:
8787 this_type = read_tag_volatile_type (die, cu);
8789 case DW_TAG_string_type:
8790 this_type = read_tag_string_type (die, cu);
8792 case DW_TAG_typedef:
8793 this_type = read_typedef (die, cu);
8795 case DW_TAG_subrange_type:
8796 this_type = read_subrange_type (die, cu);
8798 case DW_TAG_base_type:
8799 this_type = read_base_type (die, cu);
8801 case DW_TAG_unspecified_type:
8802 this_type = read_unspecified_type (die, cu);
8804 case DW_TAG_namespace:
8805 this_type = read_namespace_type (die, cu);
8808 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
8809 dwarf_tag_name (die->tag));
8816 /* Return the name of the namespace/class that DIE is defined within,
8817 or "" if we can't tell. The caller should not xfree the result.
8819 For example, if we're within the method foo() in the following
8829 then determine_prefix on foo's die will return "N::C". */
8832 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
8834 struct die_info *parent, *spec_die;
8835 struct dwarf2_cu *spec_cu;
8836 struct type *parent_type;
8838 if (cu->language != language_cplus
8839 && cu->language != language_java)
8842 /* We have to be careful in the presence of DW_AT_specification.
8843 For example, with GCC 3.4, given the code
8847 // Definition of N::foo.
8851 then we'll have a tree of DIEs like this:
8853 1: DW_TAG_compile_unit
8854 2: DW_TAG_namespace // N
8855 3: DW_TAG_subprogram // declaration of N::foo
8856 4: DW_TAG_subprogram // definition of N::foo
8857 DW_AT_specification // refers to die #3
8859 Thus, when processing die #4, we have to pretend that we're in
8860 the context of its DW_AT_specification, namely the contex of die
8863 spec_die = die_specification (die, &spec_cu);
8864 if (spec_die == NULL)
8865 parent = die->parent;
8868 parent = spec_die->parent;
8875 switch (parent->tag)
8877 case DW_TAG_namespace:
8878 parent_type = read_type_die (parent, cu);
8879 /* We give a name to even anonymous namespaces. */
8880 return TYPE_TAG_NAME (parent_type);
8881 case DW_TAG_class_type:
8882 case DW_TAG_interface_type:
8883 case DW_TAG_structure_type:
8884 case DW_TAG_union_type:
8885 parent_type = read_type_die (parent, cu);
8886 if (TYPE_TAG_NAME (parent_type) != NULL)
8887 return TYPE_TAG_NAME (parent_type);
8889 /* An anonymous structure is only allowed non-static data
8890 members; no typedefs, no member functions, et cetera.
8891 So it does not need a prefix. */
8894 return determine_prefix (parent, cu);
8898 /* Return a newly-allocated string formed by concatenating PREFIX and
8899 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8900 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8901 perform an obconcat, otherwise allocate storage for the result. The CU argument
8902 is used to determine the language and hence, the appropriate separator. */
8904 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8907 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
8908 struct dwarf2_cu *cu)
8912 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
8914 else if (cu->language == language_java)
8926 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
8927 strcpy (retval, prefix);
8928 strcat (retval, sep);
8929 strcat (retval, suffix);
8934 /* We have an obstack. */
8935 return obconcat (obs, prefix, sep, suffix);
8939 /* Return sibling of die, NULL if no sibling. */
8941 static struct die_info *
8942 sibling_die (struct die_info *die)
8944 return die->sibling;
8947 /* Get linkage name of a die, return NULL if not found. */
8950 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
8952 struct attribute *attr;
8954 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
8955 if (attr && DW_STRING (attr))
8956 return DW_STRING (attr);
8957 return dwarf2_name (die, cu);
8960 /* Get name of a die, return NULL if not found. */
8963 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
8964 struct obstack *obstack)
8966 if (name && cu->language == language_cplus)
8968 char *canon_name = cp_canonicalize_string (name);
8970 if (canon_name != NULL)
8972 if (strcmp (canon_name, name) != 0)
8973 name = obsavestring (canon_name, strlen (canon_name),
8982 /* Get name of a die, return NULL if not found. */
8985 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
8987 struct attribute *attr;
8989 attr = dwarf2_attr (die, DW_AT_name, cu);
8990 if (!attr || !DW_STRING (attr))
8995 case DW_TAG_compile_unit:
8996 /* Compilation units have a DW_AT_name that is a filename, not
8997 a source language identifier. */
8998 case DW_TAG_enumeration_type:
8999 case DW_TAG_enumerator:
9000 /* These tags always have simple identifiers already; no need
9001 to canonicalize them. */
9002 return DW_STRING (attr);
9004 if (!DW_STRING_IS_CANONICAL (attr))
9007 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
9008 &cu->objfile->objfile_obstack);
9009 DW_STRING_IS_CANONICAL (attr) = 1;
9011 return DW_STRING (attr);
9015 /* Return the die that this die in an extension of, or NULL if there
9016 is none. *EXT_CU is the CU containing DIE on input, and the CU
9017 containing the return value on output. */
9019 static struct die_info *
9020 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
9022 struct attribute *attr;
9024 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
9028 return follow_die_ref (die, attr, ext_cu);
9031 /* Convert a DIE tag into its string name. */
9034 dwarf_tag_name (unsigned tag)
9038 case DW_TAG_padding:
9039 return "DW_TAG_padding";
9040 case DW_TAG_array_type:
9041 return "DW_TAG_array_type";
9042 case DW_TAG_class_type:
9043 return "DW_TAG_class_type";
9044 case DW_TAG_entry_point:
9045 return "DW_TAG_entry_point";
9046 case DW_TAG_enumeration_type:
9047 return "DW_TAG_enumeration_type";
9048 case DW_TAG_formal_parameter:
9049 return "DW_TAG_formal_parameter";
9050 case DW_TAG_imported_declaration:
9051 return "DW_TAG_imported_declaration";
9053 return "DW_TAG_label";
9054 case DW_TAG_lexical_block:
9055 return "DW_TAG_lexical_block";
9057 return "DW_TAG_member";
9058 case DW_TAG_pointer_type:
9059 return "DW_TAG_pointer_type";
9060 case DW_TAG_reference_type:
9061 return "DW_TAG_reference_type";
9062 case DW_TAG_compile_unit:
9063 return "DW_TAG_compile_unit";
9064 case DW_TAG_string_type:
9065 return "DW_TAG_string_type";
9066 case DW_TAG_structure_type:
9067 return "DW_TAG_structure_type";
9068 case DW_TAG_subroutine_type:
9069 return "DW_TAG_subroutine_type";
9070 case DW_TAG_typedef:
9071 return "DW_TAG_typedef";
9072 case DW_TAG_union_type:
9073 return "DW_TAG_union_type";
9074 case DW_TAG_unspecified_parameters:
9075 return "DW_TAG_unspecified_parameters";
9076 case DW_TAG_variant:
9077 return "DW_TAG_variant";
9078 case DW_TAG_common_block:
9079 return "DW_TAG_common_block";
9080 case DW_TAG_common_inclusion:
9081 return "DW_TAG_common_inclusion";
9082 case DW_TAG_inheritance:
9083 return "DW_TAG_inheritance";
9084 case DW_TAG_inlined_subroutine:
9085 return "DW_TAG_inlined_subroutine";
9087 return "DW_TAG_module";
9088 case DW_TAG_ptr_to_member_type:
9089 return "DW_TAG_ptr_to_member_type";
9090 case DW_TAG_set_type:
9091 return "DW_TAG_set_type";
9092 case DW_TAG_subrange_type:
9093 return "DW_TAG_subrange_type";
9094 case DW_TAG_with_stmt:
9095 return "DW_TAG_with_stmt";
9096 case DW_TAG_access_declaration:
9097 return "DW_TAG_access_declaration";
9098 case DW_TAG_base_type:
9099 return "DW_TAG_base_type";
9100 case DW_TAG_catch_block:
9101 return "DW_TAG_catch_block";
9102 case DW_TAG_const_type:
9103 return "DW_TAG_const_type";
9104 case DW_TAG_constant:
9105 return "DW_TAG_constant";
9106 case DW_TAG_enumerator:
9107 return "DW_TAG_enumerator";
9108 case DW_TAG_file_type:
9109 return "DW_TAG_file_type";
9111 return "DW_TAG_friend";
9112 case DW_TAG_namelist:
9113 return "DW_TAG_namelist";
9114 case DW_TAG_namelist_item:
9115 return "DW_TAG_namelist_item";
9116 case DW_TAG_packed_type:
9117 return "DW_TAG_packed_type";
9118 case DW_TAG_subprogram:
9119 return "DW_TAG_subprogram";
9120 case DW_TAG_template_type_param:
9121 return "DW_TAG_template_type_param";
9122 case DW_TAG_template_value_param:
9123 return "DW_TAG_template_value_param";
9124 case DW_TAG_thrown_type:
9125 return "DW_TAG_thrown_type";
9126 case DW_TAG_try_block:
9127 return "DW_TAG_try_block";
9128 case DW_TAG_variant_part:
9129 return "DW_TAG_variant_part";
9130 case DW_TAG_variable:
9131 return "DW_TAG_variable";
9132 case DW_TAG_volatile_type:
9133 return "DW_TAG_volatile_type";
9134 case DW_TAG_dwarf_procedure:
9135 return "DW_TAG_dwarf_procedure";
9136 case DW_TAG_restrict_type:
9137 return "DW_TAG_restrict_type";
9138 case DW_TAG_interface_type:
9139 return "DW_TAG_interface_type";
9140 case DW_TAG_namespace:
9141 return "DW_TAG_namespace";
9142 case DW_TAG_imported_module:
9143 return "DW_TAG_imported_module";
9144 case DW_TAG_unspecified_type:
9145 return "DW_TAG_unspecified_type";
9146 case DW_TAG_partial_unit:
9147 return "DW_TAG_partial_unit";
9148 case DW_TAG_imported_unit:
9149 return "DW_TAG_imported_unit";
9150 case DW_TAG_condition:
9151 return "DW_TAG_condition";
9152 case DW_TAG_shared_type:
9153 return "DW_TAG_shared_type";
9154 case DW_TAG_type_unit:
9155 return "DW_TAG_type_unit";
9156 case DW_TAG_MIPS_loop:
9157 return "DW_TAG_MIPS_loop";
9158 case DW_TAG_HP_array_descriptor:
9159 return "DW_TAG_HP_array_descriptor";
9160 case DW_TAG_format_label:
9161 return "DW_TAG_format_label";
9162 case DW_TAG_function_template:
9163 return "DW_TAG_function_template";
9164 case DW_TAG_class_template:
9165 return "DW_TAG_class_template";
9166 case DW_TAG_GNU_BINCL:
9167 return "DW_TAG_GNU_BINCL";
9168 case DW_TAG_GNU_EINCL:
9169 return "DW_TAG_GNU_EINCL";
9170 case DW_TAG_upc_shared_type:
9171 return "DW_TAG_upc_shared_type";
9172 case DW_TAG_upc_strict_type:
9173 return "DW_TAG_upc_strict_type";
9174 case DW_TAG_upc_relaxed_type:
9175 return "DW_TAG_upc_relaxed_type";
9176 case DW_TAG_PGI_kanji_type:
9177 return "DW_TAG_PGI_kanji_type";
9178 case DW_TAG_PGI_interface_block:
9179 return "DW_TAG_PGI_interface_block";
9181 return "DW_TAG_<unknown>";
9185 /* Convert a DWARF attribute code into its string name. */
9188 dwarf_attr_name (unsigned attr)
9193 return "DW_AT_sibling";
9194 case DW_AT_location:
9195 return "DW_AT_location";
9197 return "DW_AT_name";
9198 case DW_AT_ordering:
9199 return "DW_AT_ordering";
9200 case DW_AT_subscr_data:
9201 return "DW_AT_subscr_data";
9202 case DW_AT_byte_size:
9203 return "DW_AT_byte_size";
9204 case DW_AT_bit_offset:
9205 return "DW_AT_bit_offset";
9206 case DW_AT_bit_size:
9207 return "DW_AT_bit_size";
9208 case DW_AT_element_list:
9209 return "DW_AT_element_list";
9210 case DW_AT_stmt_list:
9211 return "DW_AT_stmt_list";
9213 return "DW_AT_low_pc";
9215 return "DW_AT_high_pc";
9216 case DW_AT_language:
9217 return "DW_AT_language";
9219 return "DW_AT_member";
9221 return "DW_AT_discr";
9222 case DW_AT_discr_value:
9223 return "DW_AT_discr_value";
9224 case DW_AT_visibility:
9225 return "DW_AT_visibility";
9227 return "DW_AT_import";
9228 case DW_AT_string_length:
9229 return "DW_AT_string_length";
9230 case DW_AT_common_reference:
9231 return "DW_AT_common_reference";
9232 case DW_AT_comp_dir:
9233 return "DW_AT_comp_dir";
9234 case DW_AT_const_value:
9235 return "DW_AT_const_value";
9236 case DW_AT_containing_type:
9237 return "DW_AT_containing_type";
9238 case DW_AT_default_value:
9239 return "DW_AT_default_value";
9241 return "DW_AT_inline";
9242 case DW_AT_is_optional:
9243 return "DW_AT_is_optional";
9244 case DW_AT_lower_bound:
9245 return "DW_AT_lower_bound";
9246 case DW_AT_producer:
9247 return "DW_AT_producer";
9248 case DW_AT_prototyped:
9249 return "DW_AT_prototyped";
9250 case DW_AT_return_addr:
9251 return "DW_AT_return_addr";
9252 case DW_AT_start_scope:
9253 return "DW_AT_start_scope";
9254 case DW_AT_bit_stride:
9255 return "DW_AT_bit_stride";
9256 case DW_AT_upper_bound:
9257 return "DW_AT_upper_bound";
9258 case DW_AT_abstract_origin:
9259 return "DW_AT_abstract_origin";
9260 case DW_AT_accessibility:
9261 return "DW_AT_accessibility";
9262 case DW_AT_address_class:
9263 return "DW_AT_address_class";
9264 case DW_AT_artificial:
9265 return "DW_AT_artificial";
9266 case DW_AT_base_types:
9267 return "DW_AT_base_types";
9268 case DW_AT_calling_convention:
9269 return "DW_AT_calling_convention";
9271 return "DW_AT_count";
9272 case DW_AT_data_member_location:
9273 return "DW_AT_data_member_location";
9274 case DW_AT_decl_column:
9275 return "DW_AT_decl_column";
9276 case DW_AT_decl_file:
9277 return "DW_AT_decl_file";
9278 case DW_AT_decl_line:
9279 return "DW_AT_decl_line";
9280 case DW_AT_declaration:
9281 return "DW_AT_declaration";
9282 case DW_AT_discr_list:
9283 return "DW_AT_discr_list";
9284 case DW_AT_encoding:
9285 return "DW_AT_encoding";
9286 case DW_AT_external:
9287 return "DW_AT_external";
9288 case DW_AT_frame_base:
9289 return "DW_AT_frame_base";
9291 return "DW_AT_friend";
9292 case DW_AT_identifier_case:
9293 return "DW_AT_identifier_case";
9294 case DW_AT_macro_info:
9295 return "DW_AT_macro_info";
9296 case DW_AT_namelist_items:
9297 return "DW_AT_namelist_items";
9298 case DW_AT_priority:
9299 return "DW_AT_priority";
9301 return "DW_AT_segment";
9302 case DW_AT_specification:
9303 return "DW_AT_specification";
9304 case DW_AT_static_link:
9305 return "DW_AT_static_link";
9307 return "DW_AT_type";
9308 case DW_AT_use_location:
9309 return "DW_AT_use_location";
9310 case DW_AT_variable_parameter:
9311 return "DW_AT_variable_parameter";
9312 case DW_AT_virtuality:
9313 return "DW_AT_virtuality";
9314 case DW_AT_vtable_elem_location:
9315 return "DW_AT_vtable_elem_location";
9316 /* DWARF 3 values. */
9317 case DW_AT_allocated:
9318 return "DW_AT_allocated";
9319 case DW_AT_associated:
9320 return "DW_AT_associated";
9321 case DW_AT_data_location:
9322 return "DW_AT_data_location";
9323 case DW_AT_byte_stride:
9324 return "DW_AT_byte_stride";
9325 case DW_AT_entry_pc:
9326 return "DW_AT_entry_pc";
9327 case DW_AT_use_UTF8:
9328 return "DW_AT_use_UTF8";
9329 case DW_AT_extension:
9330 return "DW_AT_extension";
9332 return "DW_AT_ranges";
9333 case DW_AT_trampoline:
9334 return "DW_AT_trampoline";
9335 case DW_AT_call_column:
9336 return "DW_AT_call_column";
9337 case DW_AT_call_file:
9338 return "DW_AT_call_file";
9339 case DW_AT_call_line:
9340 return "DW_AT_call_line";
9341 case DW_AT_description:
9342 return "DW_AT_description";
9343 case DW_AT_binary_scale:
9344 return "DW_AT_binary_scale";
9345 case DW_AT_decimal_scale:
9346 return "DW_AT_decimal_scale";
9348 return "DW_AT_small";
9349 case DW_AT_decimal_sign:
9350 return "DW_AT_decimal_sign";
9351 case DW_AT_digit_count:
9352 return "DW_AT_digit_count";
9353 case DW_AT_picture_string:
9354 return "DW_AT_picture_string";
9356 return "DW_AT_mutable";
9357 case DW_AT_threads_scaled:
9358 return "DW_AT_threads_scaled";
9359 case DW_AT_explicit:
9360 return "DW_AT_explicit";
9361 case DW_AT_object_pointer:
9362 return "DW_AT_object_pointer";
9363 case DW_AT_endianity:
9364 return "DW_AT_endianity";
9365 case DW_AT_elemental:
9366 return "DW_AT_elemental";
9368 return "DW_AT_pure";
9369 case DW_AT_recursive:
9370 return "DW_AT_recursive";
9371 /* DWARF 4 values. */
9372 case DW_AT_signature:
9373 return "DW_AT_signature";
9374 /* SGI/MIPS extensions. */
9375 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9376 case DW_AT_MIPS_fde:
9377 return "DW_AT_MIPS_fde";
9379 case DW_AT_MIPS_loop_begin:
9380 return "DW_AT_MIPS_loop_begin";
9381 case DW_AT_MIPS_tail_loop_begin:
9382 return "DW_AT_MIPS_tail_loop_begin";
9383 case DW_AT_MIPS_epilog_begin:
9384 return "DW_AT_MIPS_epilog_begin";
9385 case DW_AT_MIPS_loop_unroll_factor:
9386 return "DW_AT_MIPS_loop_unroll_factor";
9387 case DW_AT_MIPS_software_pipeline_depth:
9388 return "DW_AT_MIPS_software_pipeline_depth";
9389 case DW_AT_MIPS_linkage_name:
9390 return "DW_AT_MIPS_linkage_name";
9391 case DW_AT_MIPS_stride:
9392 return "DW_AT_MIPS_stride";
9393 case DW_AT_MIPS_abstract_name:
9394 return "DW_AT_MIPS_abstract_name";
9395 case DW_AT_MIPS_clone_origin:
9396 return "DW_AT_MIPS_clone_origin";
9397 case DW_AT_MIPS_has_inlines:
9398 return "DW_AT_MIPS_has_inlines";
9399 /* HP extensions. */
9400 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9401 case DW_AT_HP_block_index:
9402 return "DW_AT_HP_block_index";
9404 case DW_AT_HP_unmodifiable:
9405 return "DW_AT_HP_unmodifiable";
9406 case DW_AT_HP_actuals_stmt_list:
9407 return "DW_AT_HP_actuals_stmt_list";
9408 case DW_AT_HP_proc_per_section:
9409 return "DW_AT_HP_proc_per_section";
9410 case DW_AT_HP_raw_data_ptr:
9411 return "DW_AT_HP_raw_data_ptr";
9412 case DW_AT_HP_pass_by_reference:
9413 return "DW_AT_HP_pass_by_reference";
9414 case DW_AT_HP_opt_level:
9415 return "DW_AT_HP_opt_level";
9416 case DW_AT_HP_prof_version_id:
9417 return "DW_AT_HP_prof_version_id";
9418 case DW_AT_HP_opt_flags:
9419 return "DW_AT_HP_opt_flags";
9420 case DW_AT_HP_cold_region_low_pc:
9421 return "DW_AT_HP_cold_region_low_pc";
9422 case DW_AT_HP_cold_region_high_pc:
9423 return "DW_AT_HP_cold_region_high_pc";
9424 case DW_AT_HP_all_variables_modifiable:
9425 return "DW_AT_HP_all_variables_modifiable";
9426 case DW_AT_HP_linkage_name:
9427 return "DW_AT_HP_linkage_name";
9428 case DW_AT_HP_prof_flags:
9429 return "DW_AT_HP_prof_flags";
9430 /* GNU extensions. */
9431 case DW_AT_sf_names:
9432 return "DW_AT_sf_names";
9433 case DW_AT_src_info:
9434 return "DW_AT_src_info";
9435 case DW_AT_mac_info:
9436 return "DW_AT_mac_info";
9437 case DW_AT_src_coords:
9438 return "DW_AT_src_coords";
9439 case DW_AT_body_begin:
9440 return "DW_AT_body_begin";
9441 case DW_AT_body_end:
9442 return "DW_AT_body_end";
9443 case DW_AT_GNU_vector:
9444 return "DW_AT_GNU_vector";
9445 /* VMS extensions. */
9446 case DW_AT_VMS_rtnbeg_pd_address:
9447 return "DW_AT_VMS_rtnbeg_pd_address";
9448 /* UPC extension. */
9449 case DW_AT_upc_threads_scaled:
9450 return "DW_AT_upc_threads_scaled";
9451 /* PGI (STMicroelectronics) extensions. */
9452 case DW_AT_PGI_lbase:
9453 return "DW_AT_PGI_lbase";
9454 case DW_AT_PGI_soffset:
9455 return "DW_AT_PGI_soffset";
9456 case DW_AT_PGI_lstride:
9457 return "DW_AT_PGI_lstride";
9459 return "DW_AT_<unknown>";
9463 /* Convert a DWARF value form code into its string name. */
9466 dwarf_form_name (unsigned form)
9471 return "DW_FORM_addr";
9472 case DW_FORM_block2:
9473 return "DW_FORM_block2";
9474 case DW_FORM_block4:
9475 return "DW_FORM_block4";
9477 return "DW_FORM_data2";
9479 return "DW_FORM_data4";
9481 return "DW_FORM_data8";
9482 case DW_FORM_string:
9483 return "DW_FORM_string";
9485 return "DW_FORM_block";
9486 case DW_FORM_block1:
9487 return "DW_FORM_block1";
9489 return "DW_FORM_data1";
9491 return "DW_FORM_flag";
9493 return "DW_FORM_sdata";
9495 return "DW_FORM_strp";
9497 return "DW_FORM_udata";
9498 case DW_FORM_ref_addr:
9499 return "DW_FORM_ref_addr";
9501 return "DW_FORM_ref1";
9503 return "DW_FORM_ref2";
9505 return "DW_FORM_ref4";
9507 return "DW_FORM_ref8";
9508 case DW_FORM_ref_udata:
9509 return "DW_FORM_ref_udata";
9510 case DW_FORM_indirect:
9511 return "DW_FORM_indirect";
9512 case DW_FORM_sec_offset:
9513 return "DW_FORM_sec_offset";
9514 case DW_FORM_exprloc:
9515 return "DW_FORM_exprloc";
9516 case DW_FORM_flag_present:
9517 return "DW_FORM_flag_present";
9519 return "DW_FORM_sig8";
9521 return "DW_FORM_<unknown>";
9525 /* Convert a DWARF stack opcode into its string name. */
9528 dwarf_stack_op_name (unsigned op)
9533 return "DW_OP_addr";
9535 return "DW_OP_deref";
9537 return "DW_OP_const1u";
9539 return "DW_OP_const1s";
9541 return "DW_OP_const2u";
9543 return "DW_OP_const2s";
9545 return "DW_OP_const4u";
9547 return "DW_OP_const4s";
9549 return "DW_OP_const8u";
9551 return "DW_OP_const8s";
9553 return "DW_OP_constu";
9555 return "DW_OP_consts";
9559 return "DW_OP_drop";
9561 return "DW_OP_over";
9563 return "DW_OP_pick";
9565 return "DW_OP_swap";
9569 return "DW_OP_xderef";
9577 return "DW_OP_minus";
9589 return "DW_OP_plus";
9590 case DW_OP_plus_uconst:
9591 return "DW_OP_plus_uconst";
9597 return "DW_OP_shra";
9615 return "DW_OP_skip";
9617 return "DW_OP_lit0";
9619 return "DW_OP_lit1";
9621 return "DW_OP_lit2";
9623 return "DW_OP_lit3";
9625 return "DW_OP_lit4";
9627 return "DW_OP_lit5";
9629 return "DW_OP_lit6";
9631 return "DW_OP_lit7";
9633 return "DW_OP_lit8";
9635 return "DW_OP_lit9";
9637 return "DW_OP_lit10";
9639 return "DW_OP_lit11";
9641 return "DW_OP_lit12";
9643 return "DW_OP_lit13";
9645 return "DW_OP_lit14";
9647 return "DW_OP_lit15";
9649 return "DW_OP_lit16";
9651 return "DW_OP_lit17";
9653 return "DW_OP_lit18";
9655 return "DW_OP_lit19";
9657 return "DW_OP_lit20";
9659 return "DW_OP_lit21";
9661 return "DW_OP_lit22";
9663 return "DW_OP_lit23";
9665 return "DW_OP_lit24";
9667 return "DW_OP_lit25";
9669 return "DW_OP_lit26";
9671 return "DW_OP_lit27";
9673 return "DW_OP_lit28";
9675 return "DW_OP_lit29";
9677 return "DW_OP_lit30";
9679 return "DW_OP_lit31";
9681 return "DW_OP_reg0";
9683 return "DW_OP_reg1";
9685 return "DW_OP_reg2";
9687 return "DW_OP_reg3";
9689 return "DW_OP_reg4";
9691 return "DW_OP_reg5";
9693 return "DW_OP_reg6";
9695 return "DW_OP_reg7";
9697 return "DW_OP_reg8";
9699 return "DW_OP_reg9";
9701 return "DW_OP_reg10";
9703 return "DW_OP_reg11";
9705 return "DW_OP_reg12";
9707 return "DW_OP_reg13";
9709 return "DW_OP_reg14";
9711 return "DW_OP_reg15";
9713 return "DW_OP_reg16";
9715 return "DW_OP_reg17";
9717 return "DW_OP_reg18";
9719 return "DW_OP_reg19";
9721 return "DW_OP_reg20";
9723 return "DW_OP_reg21";
9725 return "DW_OP_reg22";
9727 return "DW_OP_reg23";
9729 return "DW_OP_reg24";
9731 return "DW_OP_reg25";
9733 return "DW_OP_reg26";
9735 return "DW_OP_reg27";
9737 return "DW_OP_reg28";
9739 return "DW_OP_reg29";
9741 return "DW_OP_reg30";
9743 return "DW_OP_reg31";
9745 return "DW_OP_breg0";
9747 return "DW_OP_breg1";
9749 return "DW_OP_breg2";
9751 return "DW_OP_breg3";
9753 return "DW_OP_breg4";
9755 return "DW_OP_breg5";
9757 return "DW_OP_breg6";
9759 return "DW_OP_breg7";
9761 return "DW_OP_breg8";
9763 return "DW_OP_breg9";
9765 return "DW_OP_breg10";
9767 return "DW_OP_breg11";
9769 return "DW_OP_breg12";
9771 return "DW_OP_breg13";
9773 return "DW_OP_breg14";
9775 return "DW_OP_breg15";
9777 return "DW_OP_breg16";
9779 return "DW_OP_breg17";
9781 return "DW_OP_breg18";
9783 return "DW_OP_breg19";
9785 return "DW_OP_breg20";
9787 return "DW_OP_breg21";
9789 return "DW_OP_breg22";
9791 return "DW_OP_breg23";
9793 return "DW_OP_breg24";
9795 return "DW_OP_breg25";
9797 return "DW_OP_breg26";
9799 return "DW_OP_breg27";
9801 return "DW_OP_breg28";
9803 return "DW_OP_breg29";
9805 return "DW_OP_breg30";
9807 return "DW_OP_breg31";
9809 return "DW_OP_regx";
9811 return "DW_OP_fbreg";
9813 return "DW_OP_bregx";
9815 return "DW_OP_piece";
9816 case DW_OP_deref_size:
9817 return "DW_OP_deref_size";
9818 case DW_OP_xderef_size:
9819 return "DW_OP_xderef_size";
9822 /* DWARF 3 extensions. */
9823 case DW_OP_push_object_address:
9824 return "DW_OP_push_object_address";
9826 return "DW_OP_call2";
9828 return "DW_OP_call4";
9829 case DW_OP_call_ref:
9830 return "DW_OP_call_ref";
9831 /* GNU extensions. */
9832 case DW_OP_form_tls_address:
9833 return "DW_OP_form_tls_address";
9834 case DW_OP_call_frame_cfa:
9835 return "DW_OP_call_frame_cfa";
9836 case DW_OP_bit_piece:
9837 return "DW_OP_bit_piece";
9838 case DW_OP_GNU_push_tls_address:
9839 return "DW_OP_GNU_push_tls_address";
9840 case DW_OP_GNU_uninit:
9841 return "DW_OP_GNU_uninit";
9842 /* HP extensions. */
9843 case DW_OP_HP_is_value:
9844 return "DW_OP_HP_is_value";
9845 case DW_OP_HP_fltconst4:
9846 return "DW_OP_HP_fltconst4";
9847 case DW_OP_HP_fltconst8:
9848 return "DW_OP_HP_fltconst8";
9849 case DW_OP_HP_mod_range:
9850 return "DW_OP_HP_mod_range";
9851 case DW_OP_HP_unmod_range:
9852 return "DW_OP_HP_unmod_range";
9854 return "DW_OP_HP_tls";
9856 return "OP_<unknown>";
9861 dwarf_bool_name (unsigned mybool)
9869 /* Convert a DWARF type code into its string name. */
9872 dwarf_type_encoding_name (unsigned enc)
9877 return "DW_ATE_void";
9878 case DW_ATE_address:
9879 return "DW_ATE_address";
9880 case DW_ATE_boolean:
9881 return "DW_ATE_boolean";
9882 case DW_ATE_complex_float:
9883 return "DW_ATE_complex_float";
9885 return "DW_ATE_float";
9887 return "DW_ATE_signed";
9888 case DW_ATE_signed_char:
9889 return "DW_ATE_signed_char";
9890 case DW_ATE_unsigned:
9891 return "DW_ATE_unsigned";
9892 case DW_ATE_unsigned_char:
9893 return "DW_ATE_unsigned_char";
9895 case DW_ATE_imaginary_float:
9896 return "DW_ATE_imaginary_float";
9897 case DW_ATE_packed_decimal:
9898 return "DW_ATE_packed_decimal";
9899 case DW_ATE_numeric_string:
9900 return "DW_ATE_numeric_string";
9902 return "DW_ATE_edited";
9903 case DW_ATE_signed_fixed:
9904 return "DW_ATE_signed_fixed";
9905 case DW_ATE_unsigned_fixed:
9906 return "DW_ATE_unsigned_fixed";
9907 case DW_ATE_decimal_float:
9908 return "DW_ATE_decimal_float";
9909 /* HP extensions. */
9910 case DW_ATE_HP_float80:
9911 return "DW_ATE_HP_float80";
9912 case DW_ATE_HP_complex_float80:
9913 return "DW_ATE_HP_complex_float80";
9914 case DW_ATE_HP_float128:
9915 return "DW_ATE_HP_float128";
9916 case DW_ATE_HP_complex_float128:
9917 return "DW_ATE_HP_complex_float128";
9918 case DW_ATE_HP_floathpintel:
9919 return "DW_ATE_HP_floathpintel";
9920 case DW_ATE_HP_imaginary_float80:
9921 return "DW_ATE_HP_imaginary_float80";
9922 case DW_ATE_HP_imaginary_float128:
9923 return "DW_ATE_HP_imaginary_float128";
9925 return "DW_ATE_<unknown>";
9929 /* Convert a DWARF call frame info operation to its string name. */
9933 dwarf_cfi_name (unsigned cfi_opc)
9937 case DW_CFA_advance_loc:
9938 return "DW_CFA_advance_loc";
9940 return "DW_CFA_offset";
9941 case DW_CFA_restore:
9942 return "DW_CFA_restore";
9944 return "DW_CFA_nop";
9945 case DW_CFA_set_loc:
9946 return "DW_CFA_set_loc";
9947 case DW_CFA_advance_loc1:
9948 return "DW_CFA_advance_loc1";
9949 case DW_CFA_advance_loc2:
9950 return "DW_CFA_advance_loc2";
9951 case DW_CFA_advance_loc4:
9952 return "DW_CFA_advance_loc4";
9953 case DW_CFA_offset_extended:
9954 return "DW_CFA_offset_extended";
9955 case DW_CFA_restore_extended:
9956 return "DW_CFA_restore_extended";
9957 case DW_CFA_undefined:
9958 return "DW_CFA_undefined";
9959 case DW_CFA_same_value:
9960 return "DW_CFA_same_value";
9961 case DW_CFA_register:
9962 return "DW_CFA_register";
9963 case DW_CFA_remember_state:
9964 return "DW_CFA_remember_state";
9965 case DW_CFA_restore_state:
9966 return "DW_CFA_restore_state";
9967 case DW_CFA_def_cfa:
9968 return "DW_CFA_def_cfa";
9969 case DW_CFA_def_cfa_register:
9970 return "DW_CFA_def_cfa_register";
9971 case DW_CFA_def_cfa_offset:
9972 return "DW_CFA_def_cfa_offset";
9974 case DW_CFA_def_cfa_expression:
9975 return "DW_CFA_def_cfa_expression";
9976 case DW_CFA_expression:
9977 return "DW_CFA_expression";
9978 case DW_CFA_offset_extended_sf:
9979 return "DW_CFA_offset_extended_sf";
9980 case DW_CFA_def_cfa_sf:
9981 return "DW_CFA_def_cfa_sf";
9982 case DW_CFA_def_cfa_offset_sf:
9983 return "DW_CFA_def_cfa_offset_sf";
9984 case DW_CFA_val_offset:
9985 return "DW_CFA_val_offset";
9986 case DW_CFA_val_offset_sf:
9987 return "DW_CFA_val_offset_sf";
9988 case DW_CFA_val_expression:
9989 return "DW_CFA_val_expression";
9990 /* SGI/MIPS specific. */
9991 case DW_CFA_MIPS_advance_loc8:
9992 return "DW_CFA_MIPS_advance_loc8";
9993 /* GNU extensions. */
9994 case DW_CFA_GNU_window_save:
9995 return "DW_CFA_GNU_window_save";
9996 case DW_CFA_GNU_args_size:
9997 return "DW_CFA_GNU_args_size";
9998 case DW_CFA_GNU_negative_offset_extended:
9999 return "DW_CFA_GNU_negative_offset_extended";
10001 return "DW_CFA_<unknown>";
10007 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
10011 print_spaces (indent, f);
10012 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
10013 dwarf_tag_name (die->tag), die->abbrev, die->offset);
10015 if (die->parent != NULL)
10017 print_spaces (indent, f);
10018 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
10019 die->parent->offset);
10022 print_spaces (indent, f);
10023 fprintf_unfiltered (f, " has children: %s\n",
10024 dwarf_bool_name (die->child != NULL));
10026 print_spaces (indent, f);
10027 fprintf_unfiltered (f, " attributes:\n");
10029 for (i = 0; i < die->num_attrs; ++i)
10031 print_spaces (indent, f);
10032 fprintf_unfiltered (f, " %s (%s) ",
10033 dwarf_attr_name (die->attrs[i].name),
10034 dwarf_form_name (die->attrs[i].form));
10036 switch (die->attrs[i].form)
10038 case DW_FORM_ref_addr:
10040 fprintf_unfiltered (f, "address: ");
10041 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
10043 case DW_FORM_block2:
10044 case DW_FORM_block4:
10045 case DW_FORM_block:
10046 case DW_FORM_block1:
10047 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
10052 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
10053 (long) (DW_ADDR (&die->attrs[i])));
10055 case DW_FORM_data1:
10056 case DW_FORM_data2:
10057 case DW_FORM_data4:
10058 case DW_FORM_data8:
10059 case DW_FORM_udata:
10060 case DW_FORM_sdata:
10061 fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
10064 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
10065 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
10066 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
10068 fprintf_unfiltered (f, "signatured type, offset: unknown");
10070 case DW_FORM_string:
10072 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
10073 DW_STRING (&die->attrs[i])
10074 ? DW_STRING (&die->attrs[i]) : "",
10075 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
10078 if (DW_UNSND (&die->attrs[i]))
10079 fprintf_unfiltered (f, "flag: TRUE");
10081 fprintf_unfiltered (f, "flag: FALSE");
10083 case DW_FORM_indirect:
10084 /* the reader will have reduced the indirect form to
10085 the "base form" so this form should not occur */
10086 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
10089 fprintf_unfiltered (f, "unsupported attribute form: %d.",
10090 die->attrs[i].form);
10093 fprintf_unfiltered (f, "\n");
10098 dump_die_for_error (struct die_info *die)
10100 dump_die_shallow (gdb_stderr, 0, die);
10104 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
10106 int indent = level * 4;
10108 gdb_assert (die != NULL);
10110 if (level >= max_level)
10113 dump_die_shallow (f, indent, die);
10115 if (die->child != NULL)
10117 print_spaces (indent, f);
10118 fprintf_unfiltered (f, " Children:");
10119 if (level + 1 < max_level)
10121 fprintf_unfiltered (f, "\n");
10122 dump_die_1 (f, level + 1, max_level, die->child);
10126 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
10130 if (die->sibling != NULL && level > 0)
10132 dump_die_1 (f, level, max_level, die->sibling);
10136 /* This is called from the pdie macro in gdbinit.in.
10137 It's not static so gcc will keep a copy callable from gdb. */
10140 dump_die (struct die_info *die, int max_level)
10142 dump_die_1 (gdb_stdlog, 0, max_level, die);
10146 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
10150 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
10156 is_ref_attr (struct attribute *attr)
10158 switch (attr->form)
10160 case DW_FORM_ref_addr:
10165 case DW_FORM_ref_udata:
10172 static unsigned int
10173 dwarf2_get_ref_die_offset (struct attribute *attr)
10175 if (is_ref_attr (attr))
10176 return DW_ADDR (attr);
10178 complaint (&symfile_complaints,
10179 _("unsupported die ref attribute form: '%s'"),
10180 dwarf_form_name (attr->form));
10184 /* Return the constant value held by the given attribute. Return -1
10185 if the value held by the attribute is not constant. */
10188 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
10190 if (attr->form == DW_FORM_sdata)
10191 return DW_SND (attr);
10192 else if (attr->form == DW_FORM_udata
10193 || attr->form == DW_FORM_data1
10194 || attr->form == DW_FORM_data2
10195 || attr->form == DW_FORM_data4
10196 || attr->form == DW_FORM_data8)
10197 return DW_UNSND (attr);
10200 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
10201 dwarf_form_name (attr->form));
10202 return default_value;
10206 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10207 unit and add it to our queue.
10208 The result is non-zero if PER_CU was queued, otherwise the result is zero
10209 meaning either PER_CU is already queued or it is already loaded. */
10212 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
10213 struct dwarf2_per_cu_data *per_cu)
10215 /* Mark the dependence relation so that we don't flush PER_CU
10217 dwarf2_add_dependence (this_cu, per_cu);
10219 /* If it's already on the queue, we have nothing to do. */
10220 if (per_cu->queued)
10223 /* If the compilation unit is already loaded, just mark it as
10225 if (per_cu->cu != NULL)
10227 per_cu->cu->last_used = 0;
10231 /* Add it to the queue. */
10232 queue_comp_unit (per_cu, this_cu->objfile);
10237 /* Follow reference or signature attribute ATTR of SRC_DIE.
10238 On entry *REF_CU is the CU of SRC_DIE.
10239 On exit *REF_CU is the CU of the result. */
10241 static struct die_info *
10242 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
10243 struct dwarf2_cu **ref_cu)
10245 struct die_info *die;
10247 if (is_ref_attr (attr))
10248 die = follow_die_ref (src_die, attr, ref_cu);
10249 else if (attr->form == DW_FORM_sig8)
10250 die = follow_die_sig (src_die, attr, ref_cu);
10253 dump_die_for_error (src_die);
10254 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10255 (*ref_cu)->objfile->name);
10261 /* Follow reference attribute ATTR of SRC_DIE.
10262 On entry *REF_CU is the CU of SRC_DIE.
10263 On exit *REF_CU is the CU of the result. */
10265 static struct die_info *
10266 follow_die_ref (struct die_info *src_die, struct attribute *attr,
10267 struct dwarf2_cu **ref_cu)
10269 struct die_info *die;
10270 unsigned int offset;
10271 struct die_info temp_die;
10272 struct dwarf2_cu *target_cu, *cu = *ref_cu;
10274 gdb_assert (cu->per_cu != NULL);
10276 offset = dwarf2_get_ref_die_offset (attr);
10278 if (cu->per_cu->from_debug_types)
10280 /* .debug_types CUs cannot reference anything outside their CU.
10281 If they need to, they have to reference a signatured type via
10283 if (! offset_in_cu_p (&cu->header, offset))
10287 else if (! offset_in_cu_p (&cu->header, offset))
10289 struct dwarf2_per_cu_data *per_cu;
10290 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
10292 /* If necessary, add it to the queue and load its DIEs. */
10293 if (maybe_queue_comp_unit (cu, per_cu))
10294 load_full_comp_unit (per_cu, cu->objfile);
10296 target_cu = per_cu->cu;
10301 *ref_cu = target_cu;
10302 temp_die.offset = offset;
10303 die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
10309 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10310 "at 0x%x [in module %s]"),
10311 offset, src_die->offset, cu->objfile->name);
10314 /* Follow the signature attribute ATTR in SRC_DIE.
10315 On entry *REF_CU is the CU of SRC_DIE.
10316 On exit *REF_CU is the CU of the result. */
10318 static struct die_info *
10319 follow_die_sig (struct die_info *src_die, struct attribute *attr,
10320 struct dwarf2_cu **ref_cu)
10322 struct objfile *objfile = (*ref_cu)->objfile;
10323 struct die_info temp_die;
10324 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
10325 struct dwarf2_cu *sig_cu;
10326 struct die_info *die;
10328 /* sig_type will be NULL if the signatured type is missing from
10330 if (sig_type == NULL)
10331 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10332 "at 0x%x [in module %s]"),
10333 src_die->offset, objfile->name);
10335 /* If necessary, add it to the queue and load its DIEs. */
10337 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
10338 read_signatured_type (objfile, sig_type);
10340 gdb_assert (sig_type->per_cu.cu != NULL);
10342 sig_cu = sig_type->per_cu.cu;
10343 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
10344 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
10351 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10352 "at 0x%x [in module %s]"),
10353 sig_type->type_offset, src_die->offset, objfile->name);
10356 /* Given an offset of a signatured type, return its signatured_type. */
10358 static struct signatured_type *
10359 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
10361 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
10362 unsigned int length, initial_length_size;
10363 unsigned int sig_offset;
10364 struct signatured_type find_entry, *type_sig;
10366 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
10367 sig_offset = (initial_length_size
10369 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
10370 + 1 /*address_size*/);
10371 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
10372 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
10374 /* This is only used to lookup previously recorded types.
10375 If we didn't find it, it's our bug. */
10376 gdb_assert (type_sig != NULL);
10377 gdb_assert (offset == type_sig->offset);
10382 /* Read in signatured type at OFFSET and build its CU and die(s). */
10385 read_signatured_type_at_offset (struct objfile *objfile,
10386 unsigned int offset)
10388 struct signatured_type *type_sig;
10390 /* We have the section offset, but we need the signature to do the
10391 hash table lookup. */
10392 type_sig = lookup_signatured_type_at_offset (objfile, offset);
10394 gdb_assert (type_sig->per_cu.cu == NULL);
10396 read_signatured_type (objfile, type_sig);
10398 gdb_assert (type_sig->per_cu.cu != NULL);
10401 /* Read in a signatured type and build its CU and DIEs. */
10404 read_signatured_type (struct objfile *objfile,
10405 struct signatured_type *type_sig)
10407 gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
10408 struct die_reader_specs reader_specs;
10409 struct dwarf2_cu *cu;
10410 ULONGEST signature;
10411 struct cleanup *back_to, *free_cu_cleanup;
10412 struct attribute *attr;
10414 gdb_assert (type_sig->per_cu.cu == NULL);
10416 cu = xmalloc (sizeof (struct dwarf2_cu));
10417 memset (cu, 0, sizeof (struct dwarf2_cu));
10418 obstack_init (&cu->comp_unit_obstack);
10419 cu->objfile = objfile;
10420 type_sig->per_cu.cu = cu;
10421 cu->per_cu = &type_sig->per_cu;
10423 /* If an error occurs while loading, release our storage. */
10424 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
10426 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
10427 types_ptr, objfile->obfd);
10428 gdb_assert (signature == type_sig->signature);
10431 = htab_create_alloc_ex (cu->header.length / 12,
10435 &cu->comp_unit_obstack,
10436 hashtab_obstack_allocate,
10437 dummy_obstack_deallocate);
10439 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
10440 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
10442 init_cu_die_reader (&reader_specs, cu);
10444 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
10447 /* We try not to read any attributes in this function, because not
10448 all objfiles needed for references have been loaded yet, and symbol
10449 table processing isn't initialized. But we have to set the CU language,
10450 or we won't be able to build types correctly. */
10451 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
10453 set_cu_language (DW_UNSND (attr), cu);
10455 set_cu_language (language_minimal, cu);
10457 do_cleanups (back_to);
10459 /* We've successfully allocated this compilation unit. Let our caller
10460 clean it up when finished with it. */
10461 discard_cleanups (free_cu_cleanup);
10463 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
10464 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
10467 /* Decode simple location descriptions.
10468 Given a pointer to a dwarf block that defines a location, compute
10469 the location and return the value.
10471 NOTE drow/2003-11-18: This function is called in two situations
10472 now: for the address of static or global variables (partial symbols
10473 only) and for offsets into structures which are expected to be
10474 (more or less) constant. The partial symbol case should go away,
10475 and only the constant case should remain. That will let this
10476 function complain more accurately. A few special modes are allowed
10477 without complaint for global variables (for instance, global
10478 register values and thread-local values).
10480 A location description containing no operations indicates that the
10481 object is optimized out. The return value is 0 for that case.
10482 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10483 callers will only want a very basic result and this can become a
10486 Note that stack[0] is unused except as a default error return.
10487 Note that stack overflow is not yet handled. */
10490 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
10492 struct objfile *objfile = cu->objfile;
10493 struct comp_unit_head *cu_header = &cu->header;
10495 int size = blk->size;
10496 gdb_byte *data = blk->data;
10497 CORE_ADDR stack[64];
10499 unsigned int bytes_read, unsnd;
10543 stack[++stacki] = op - DW_OP_lit0;
10578 stack[++stacki] = op - DW_OP_reg0;
10580 dwarf2_complex_location_expr_complaint ();
10584 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
10586 stack[++stacki] = unsnd;
10588 dwarf2_complex_location_expr_complaint ();
10592 stack[++stacki] = read_address (objfile->obfd, &data[i],
10597 case DW_OP_const1u:
10598 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
10602 case DW_OP_const1s:
10603 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
10607 case DW_OP_const2u:
10608 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
10612 case DW_OP_const2s:
10613 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
10617 case DW_OP_const4u:
10618 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
10622 case DW_OP_const4s:
10623 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
10628 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
10634 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
10639 stack[stacki + 1] = stack[stacki];
10644 stack[stacki - 1] += stack[stacki];
10648 case DW_OP_plus_uconst:
10649 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
10654 stack[stacki - 1] -= stack[stacki];
10659 /* If we're not the last op, then we definitely can't encode
10660 this using GDB's address_class enum. This is valid for partial
10661 global symbols, although the variable's address will be bogus
10664 dwarf2_complex_location_expr_complaint ();
10667 case DW_OP_GNU_push_tls_address:
10668 /* The top of the stack has the offset from the beginning
10669 of the thread control block at which the variable is located. */
10670 /* Nothing should follow this operator, so the top of stack would
10672 /* This is valid for partial global symbols, but the variable's
10673 address will be bogus in the psymtab. */
10675 dwarf2_complex_location_expr_complaint ();
10678 case DW_OP_GNU_uninit:
10682 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
10683 dwarf_stack_op_name (op));
10684 return (stack[stacki]);
10687 return (stack[stacki]);
10690 /* memory allocation interface */
10692 static struct dwarf_block *
10693 dwarf_alloc_block (struct dwarf2_cu *cu)
10695 struct dwarf_block *blk;
10697 blk = (struct dwarf_block *)
10698 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
10702 static struct abbrev_info *
10703 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
10705 struct abbrev_info *abbrev;
10707 abbrev = (struct abbrev_info *)
10708 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
10709 memset (abbrev, 0, sizeof (struct abbrev_info));
10713 static struct die_info *
10714 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
10716 struct die_info *die;
10717 size_t size = sizeof (struct die_info);
10720 size += (num_attrs - 1) * sizeof (struct attribute);
10722 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
10723 memset (die, 0, sizeof (struct die_info));
10728 /* Macro support. */
10731 /* Return the full name of file number I in *LH's file name table.
10732 Use COMP_DIR as the name of the current directory of the
10733 compilation. The result is allocated using xmalloc; the caller is
10734 responsible for freeing it. */
10736 file_full_name (int file, struct line_header *lh, const char *comp_dir)
10738 /* Is the file number a valid index into the line header's file name
10739 table? Remember that file numbers start with one, not zero. */
10740 if (1 <= file && file <= lh->num_file_names)
10742 struct file_entry *fe = &lh->file_names[file - 1];
10744 if (IS_ABSOLUTE_PATH (fe->name))
10745 return xstrdup (fe->name);
10753 dir = lh->include_dirs[fe->dir_index - 1];
10759 dir_len = strlen (dir);
10760 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
10761 strcpy (full_name, dir);
10762 full_name[dir_len] = '/';
10763 strcpy (full_name + dir_len + 1, fe->name);
10767 return xstrdup (fe->name);
10772 /* The compiler produced a bogus file number. We can at least
10773 record the macro definitions made in the file, even if we
10774 won't be able to find the file by name. */
10775 char fake_name[80];
10776 sprintf (fake_name, "<bad macro file number %d>", file);
10778 complaint (&symfile_complaints,
10779 _("bad file number in macro information (%d)"),
10782 return xstrdup (fake_name);
10787 static struct macro_source_file *
10788 macro_start_file (int file, int line,
10789 struct macro_source_file *current_file,
10790 const char *comp_dir,
10791 struct line_header *lh, struct objfile *objfile)
10793 /* The full name of this source file. */
10794 char *full_name = file_full_name (file, lh, comp_dir);
10796 /* We don't create a macro table for this compilation unit
10797 at all until we actually get a filename. */
10798 if (! pending_macros)
10799 pending_macros = new_macro_table (&objfile->objfile_obstack,
10800 objfile->macro_cache);
10802 if (! current_file)
10803 /* If we have no current file, then this must be the start_file
10804 directive for the compilation unit's main source file. */
10805 current_file = macro_set_main (pending_macros, full_name);
10807 current_file = macro_include (current_file, line, full_name);
10811 return current_file;
10815 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10816 followed by a null byte. */
10818 copy_string (const char *buf, int len)
10820 char *s = xmalloc (len + 1);
10821 memcpy (s, buf, len);
10828 static const char *
10829 consume_improper_spaces (const char *p, const char *body)
10833 complaint (&symfile_complaints,
10834 _("macro definition contains spaces in formal argument list:\n`%s'"),
10846 parse_macro_definition (struct macro_source_file *file, int line,
10851 /* The body string takes one of two forms. For object-like macro
10852 definitions, it should be:
10854 <macro name> " " <definition>
10856 For function-like macro definitions, it should be:
10858 <macro name> "() " <definition>
10860 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10862 Spaces may appear only where explicitly indicated, and in the
10865 The Dwarf 2 spec says that an object-like macro's name is always
10866 followed by a space, but versions of GCC around March 2002 omit
10867 the space when the macro's definition is the empty string.
10869 The Dwarf 2 spec says that there should be no spaces between the
10870 formal arguments in a function-like macro's formal argument list,
10871 but versions of GCC around March 2002 include spaces after the
10875 /* Find the extent of the macro name. The macro name is terminated
10876 by either a space or null character (for an object-like macro) or
10877 an opening paren (for a function-like macro). */
10878 for (p = body; *p; p++)
10879 if (*p == ' ' || *p == '(')
10882 if (*p == ' ' || *p == '\0')
10884 /* It's an object-like macro. */
10885 int name_len = p - body;
10886 char *name = copy_string (body, name_len);
10887 const char *replacement;
10890 replacement = body + name_len + 1;
10893 dwarf2_macro_malformed_definition_complaint (body);
10894 replacement = body + name_len;
10897 macro_define_object (file, line, name, replacement);
10901 else if (*p == '(')
10903 /* It's a function-like macro. */
10904 char *name = copy_string (body, p - body);
10907 char **argv = xmalloc (argv_size * sizeof (*argv));
10911 p = consume_improper_spaces (p, body);
10913 /* Parse the formal argument list. */
10914 while (*p && *p != ')')
10916 /* Find the extent of the current argument name. */
10917 const char *arg_start = p;
10919 while (*p && *p != ',' && *p != ')' && *p != ' ')
10922 if (! *p || p == arg_start)
10923 dwarf2_macro_malformed_definition_complaint (body);
10926 /* Make sure argv has room for the new argument. */
10927 if (argc >= argv_size)
10930 argv = xrealloc (argv, argv_size * sizeof (*argv));
10933 argv[argc++] = copy_string (arg_start, p - arg_start);
10936 p = consume_improper_spaces (p, body);
10938 /* Consume the comma, if present. */
10943 p = consume_improper_spaces (p, body);
10952 /* Perfectly formed definition, no complaints. */
10953 macro_define_function (file, line, name,
10954 argc, (const char **) argv,
10956 else if (*p == '\0')
10958 /* Complain, but do define it. */
10959 dwarf2_macro_malformed_definition_complaint (body);
10960 macro_define_function (file, line, name,
10961 argc, (const char **) argv,
10965 /* Just complain. */
10966 dwarf2_macro_malformed_definition_complaint (body);
10969 /* Just complain. */
10970 dwarf2_macro_malformed_definition_complaint (body);
10976 for (i = 0; i < argc; i++)
10982 dwarf2_macro_malformed_definition_complaint (body);
10987 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
10988 char *comp_dir, bfd *abfd,
10989 struct dwarf2_cu *cu)
10991 gdb_byte *mac_ptr, *mac_end;
10992 struct macro_source_file *current_file = 0;
10993 enum dwarf_macinfo_record_type macinfo_type;
10994 int at_commandline;
10996 if (dwarf2_per_objfile->macinfo.buffer == NULL)
10998 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
11002 /* First pass: Find the name of the base filename.
11003 This filename is needed in order to process all macros whose definition
11004 (or undefinition) comes from the command line. These macros are defined
11005 before the first DW_MACINFO_start_file entry, and yet still need to be
11006 associated to the base file.
11008 To determine the base file name, we scan the macro definitions until we
11009 reach the first DW_MACINFO_start_file entry. We then initialize
11010 CURRENT_FILE accordingly so that any macro definition found before the
11011 first DW_MACINFO_start_file can still be associated to the base file. */
11013 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11014 mac_end = dwarf2_per_objfile->macinfo.buffer
11015 + dwarf2_per_objfile->macinfo.size;
11019 /* Do we at least have room for a macinfo type byte? */
11020 if (mac_ptr >= mac_end)
11022 /* Complaint is printed during the second pass as GDB will probably
11023 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11027 macinfo_type = read_1_byte (abfd, mac_ptr);
11030 switch (macinfo_type)
11032 /* A zero macinfo type indicates the end of the macro
11037 case DW_MACINFO_define:
11038 case DW_MACINFO_undef:
11039 /* Only skip the data by MAC_PTR. */
11041 unsigned int bytes_read;
11043 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11044 mac_ptr += bytes_read;
11045 read_string (abfd, mac_ptr, &bytes_read);
11046 mac_ptr += bytes_read;
11050 case DW_MACINFO_start_file:
11052 unsigned int bytes_read;
11055 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11056 mac_ptr += bytes_read;
11057 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11058 mac_ptr += bytes_read;
11060 current_file = macro_start_file (file, line, current_file, comp_dir,
11065 case DW_MACINFO_end_file:
11066 /* No data to skip by MAC_PTR. */
11069 case DW_MACINFO_vendor_ext:
11070 /* Only skip the data by MAC_PTR. */
11072 unsigned int bytes_read;
11074 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11075 mac_ptr += bytes_read;
11076 read_string (abfd, mac_ptr, &bytes_read);
11077 mac_ptr += bytes_read;
11084 } while (macinfo_type != 0 && current_file == NULL);
11086 /* Second pass: Process all entries.
11088 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11089 command-line macro definitions/undefinitions. This flag is unset when we
11090 reach the first DW_MACINFO_start_file entry. */
11092 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
11094 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11095 GDB is still reading the definitions from command line. First
11096 DW_MACINFO_start_file will need to be ignored as it was already executed
11097 to create CURRENT_FILE for the main source holding also the command line
11098 definitions. On first met DW_MACINFO_start_file this flag is reset to
11099 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11101 at_commandline = 1;
11105 /* Do we at least have room for a macinfo type byte? */
11106 if (mac_ptr >= mac_end)
11108 dwarf2_macros_too_long_complaint ();
11112 macinfo_type = read_1_byte (abfd, mac_ptr);
11115 switch (macinfo_type)
11117 /* A zero macinfo type indicates the end of the macro
11122 case DW_MACINFO_define:
11123 case DW_MACINFO_undef:
11125 unsigned int bytes_read;
11129 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11130 mac_ptr += bytes_read;
11131 body = read_string (abfd, mac_ptr, &bytes_read);
11132 mac_ptr += bytes_read;
11134 if (! current_file)
11136 /* DWARF violation as no main source is present. */
11137 complaint (&symfile_complaints,
11138 _("debug info with no main source gives macro %s "
11140 macinfo_type == DW_MACINFO_define ?
11142 macinfo_type == DW_MACINFO_undef ?
11143 _("undefinition") :
11144 _("something-or-other"), line, body);
11147 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11148 complaint (&symfile_complaints,
11149 _("debug info gives %s macro %s with %s line %d: %s"),
11150 at_commandline ? _("command-line") : _("in-file"),
11151 macinfo_type == DW_MACINFO_define ?
11153 macinfo_type == DW_MACINFO_undef ?
11154 _("undefinition") :
11155 _("something-or-other"),
11156 line == 0 ? _("zero") : _("non-zero"), line, body);
11158 if (macinfo_type == DW_MACINFO_define)
11159 parse_macro_definition (current_file, line, body);
11160 else if (macinfo_type == DW_MACINFO_undef)
11161 macro_undef (current_file, line, body);
11165 case DW_MACINFO_start_file:
11167 unsigned int bytes_read;
11170 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11171 mac_ptr += bytes_read;
11172 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11173 mac_ptr += bytes_read;
11175 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
11176 complaint (&symfile_complaints,
11177 _("debug info gives source %d included "
11178 "from %s at %s line %d"),
11179 file, at_commandline ? _("command-line") : _("file"),
11180 line == 0 ? _("zero") : _("non-zero"), line);
11182 if (at_commandline)
11184 /* This DW_MACINFO_start_file was executed in the pass one. */
11185 at_commandline = 0;
11188 current_file = macro_start_file (file, line,
11189 current_file, comp_dir,
11194 case DW_MACINFO_end_file:
11195 if (! current_file)
11196 complaint (&symfile_complaints,
11197 _("macro debug info has an unmatched `close_file' directive"));
11200 current_file = current_file->included_by;
11201 if (! current_file)
11203 enum dwarf_macinfo_record_type next_type;
11205 /* GCC circa March 2002 doesn't produce the zero
11206 type byte marking the end of the compilation
11207 unit. Complain if it's not there, but exit no
11210 /* Do we at least have room for a macinfo type byte? */
11211 if (mac_ptr >= mac_end)
11213 dwarf2_macros_too_long_complaint ();
11217 /* We don't increment mac_ptr here, so this is just
11219 next_type = read_1_byte (abfd, mac_ptr);
11220 if (next_type != 0)
11221 complaint (&symfile_complaints,
11222 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11229 case DW_MACINFO_vendor_ext:
11231 unsigned int bytes_read;
11235 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
11236 mac_ptr += bytes_read;
11237 string = read_string (abfd, mac_ptr, &bytes_read);
11238 mac_ptr += bytes_read;
11240 /* We don't recognize any vendor extensions. */
11244 } while (macinfo_type != 0);
11247 /* Check if the attribute's form is a DW_FORM_block*
11248 if so return true else false. */
11250 attr_form_is_block (struct attribute *attr)
11252 return (attr == NULL ? 0 :
11253 attr->form == DW_FORM_block1
11254 || attr->form == DW_FORM_block2
11255 || attr->form == DW_FORM_block4
11256 || attr->form == DW_FORM_block);
11259 /* Return non-zero if ATTR's value is a section offset --- classes
11260 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11261 You may use DW_UNSND (attr) to retrieve such offsets.
11263 Section 7.5.4, "Attribute Encodings", explains that no attribute
11264 may have a value that belongs to more than one of these classes; it
11265 would be ambiguous if we did, because we use the same forms for all
11268 attr_form_is_section_offset (struct attribute *attr)
11270 return (attr->form == DW_FORM_data4
11271 || attr->form == DW_FORM_data8);
11275 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11276 zero otherwise. When this function returns true, you can apply
11277 dwarf2_get_attr_constant_value to it.
11279 However, note that for some attributes you must check
11280 attr_form_is_section_offset before using this test. DW_FORM_data4
11281 and DW_FORM_data8 are members of both the constant class, and of
11282 the classes that contain offsets into other debug sections
11283 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11284 that, if an attribute's can be either a constant or one of the
11285 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11286 taken as section offsets, not constants. */
11288 attr_form_is_constant (struct attribute *attr)
11290 switch (attr->form)
11292 case DW_FORM_sdata:
11293 case DW_FORM_udata:
11294 case DW_FORM_data1:
11295 case DW_FORM_data2:
11296 case DW_FORM_data4:
11297 case DW_FORM_data8:
11305 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
11306 struct dwarf2_cu *cu)
11308 if (attr_form_is_section_offset (attr)
11309 /* ".debug_loc" may not exist at all, or the offset may be outside
11310 the section. If so, fall through to the complaint in the
11312 && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
11314 struct dwarf2_loclist_baton *baton;
11316 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11317 sizeof (struct dwarf2_loclist_baton));
11318 baton->per_cu = cu->per_cu;
11319 gdb_assert (baton->per_cu);
11321 /* We don't know how long the location list is, but make sure we
11322 don't run off the edge of the section. */
11323 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
11324 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
11325 baton->base_address = cu->base_address;
11326 if (cu->base_known == 0)
11327 complaint (&symfile_complaints,
11328 _("Location list used without specifying the CU base address."));
11330 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
11331 SYMBOL_LOCATION_BATON (sym) = baton;
11335 struct dwarf2_locexpr_baton *baton;
11337 baton = obstack_alloc (&cu->objfile->objfile_obstack,
11338 sizeof (struct dwarf2_locexpr_baton));
11339 baton->per_cu = cu->per_cu;
11340 gdb_assert (baton->per_cu);
11342 if (attr_form_is_block (attr))
11344 /* Note that we're just copying the block's data pointer
11345 here, not the actual data. We're still pointing into the
11346 info_buffer for SYM's objfile; right now we never release
11347 that buffer, but when we do clean up properly this may
11349 baton->size = DW_BLOCK (attr)->size;
11350 baton->data = DW_BLOCK (attr)->data;
11354 dwarf2_invalid_attrib_class_complaint ("location description",
11355 SYMBOL_NATURAL_NAME (sym));
11357 baton->data = NULL;
11360 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11361 SYMBOL_LOCATION_BATON (sym) = baton;
11365 /* Return the OBJFILE associated with the compilation unit CU. */
11368 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
11370 struct objfile *objfile = per_cu->psymtab->objfile;
11372 /* Return the master objfile, so that we can report and look up the
11373 correct file containing this variable. */
11374 if (objfile->separate_debug_objfile_backlink)
11375 objfile = objfile->separate_debug_objfile_backlink;
11380 /* Return the address size given in the compilation unit header for CU. */
11383 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
11386 return per_cu->cu->header.addr_size;
11389 /* If the CU is not currently read in, we re-read its header. */
11390 struct objfile *objfile = per_cu->psymtab->objfile;
11391 struct dwarf2_per_objfile *per_objfile
11392 = objfile_data (objfile, dwarf2_objfile_data_key);
11393 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
11395 struct comp_unit_head cu_header;
11396 memset (&cu_header, 0, sizeof cu_header);
11397 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
11398 return cu_header.addr_size;
11402 /* Locate the .debug_info compilation unit from CU's objfile which contains
11403 the DIE at OFFSET. Raises an error on failure. */
11405 static struct dwarf2_per_cu_data *
11406 dwarf2_find_containing_comp_unit (unsigned int offset,
11407 struct objfile *objfile)
11409 struct dwarf2_per_cu_data *this_cu;
11413 high = dwarf2_per_objfile->n_comp_units - 1;
11416 int mid = low + (high - low) / 2;
11417 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
11422 gdb_assert (low == high);
11423 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
11426 error (_("Dwarf Error: could not find partial DIE containing "
11427 "offset 0x%lx [in module %s]"),
11428 (long) offset, bfd_get_filename (objfile->obfd));
11430 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
11431 return dwarf2_per_objfile->all_comp_units[low-1];
11435 this_cu = dwarf2_per_objfile->all_comp_units[low];
11436 if (low == dwarf2_per_objfile->n_comp_units - 1
11437 && offset >= this_cu->offset + this_cu->length)
11438 error (_("invalid dwarf2 offset %u"), offset);
11439 gdb_assert (offset < this_cu->offset + this_cu->length);
11444 /* Locate the compilation unit from OBJFILE which is located at exactly
11445 OFFSET. Raises an error on failure. */
11447 static struct dwarf2_per_cu_data *
11448 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
11450 struct dwarf2_per_cu_data *this_cu;
11451 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
11452 if (this_cu->offset != offset)
11453 error (_("no compilation unit with offset %u."), offset);
11457 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11459 static struct dwarf2_cu *
11460 alloc_one_comp_unit (struct objfile *objfile)
11462 struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu));
11463 cu->objfile = objfile;
11464 obstack_init (&cu->comp_unit_obstack);
11468 /* Release one cached compilation unit, CU. We unlink it from the tree
11469 of compilation units, but we don't remove it from the read_in_chain;
11470 the caller is responsible for that.
11471 NOTE: DATA is a void * because this function is also used as a
11472 cleanup routine. */
11475 free_one_comp_unit (void *data)
11477 struct dwarf2_cu *cu = data;
11479 if (cu->per_cu != NULL)
11480 cu->per_cu->cu = NULL;
11483 obstack_free (&cu->comp_unit_obstack, NULL);
11488 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11489 when we're finished with it. We can't free the pointer itself, but be
11490 sure to unlink it from the cache. Also release any associated storage
11491 and perform cache maintenance.
11493 Only used during partial symbol parsing. */
11496 free_stack_comp_unit (void *data)
11498 struct dwarf2_cu *cu = data;
11500 obstack_free (&cu->comp_unit_obstack, NULL);
11501 cu->partial_dies = NULL;
11503 if (cu->per_cu != NULL)
11505 /* This compilation unit is on the stack in our caller, so we
11506 should not xfree it. Just unlink it. */
11507 cu->per_cu->cu = NULL;
11510 /* If we had a per-cu pointer, then we may have other compilation
11511 units loaded, so age them now. */
11512 age_cached_comp_units ();
11516 /* Free all cached compilation units. */
11519 free_cached_comp_units (void *data)
11521 struct dwarf2_per_cu_data *per_cu, **last_chain;
11523 per_cu = dwarf2_per_objfile->read_in_chain;
11524 last_chain = &dwarf2_per_objfile->read_in_chain;
11525 while (per_cu != NULL)
11527 struct dwarf2_per_cu_data *next_cu;
11529 next_cu = per_cu->cu->read_in_chain;
11531 free_one_comp_unit (per_cu->cu);
11532 *last_chain = next_cu;
11538 /* Increase the age counter on each cached compilation unit, and free
11539 any that are too old. */
11542 age_cached_comp_units (void)
11544 struct dwarf2_per_cu_data *per_cu, **last_chain;
11546 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
11547 per_cu = dwarf2_per_objfile->read_in_chain;
11548 while (per_cu != NULL)
11550 per_cu->cu->last_used ++;
11551 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
11552 dwarf2_mark (per_cu->cu);
11553 per_cu = per_cu->cu->read_in_chain;
11556 per_cu = dwarf2_per_objfile->read_in_chain;
11557 last_chain = &dwarf2_per_objfile->read_in_chain;
11558 while (per_cu != NULL)
11560 struct dwarf2_per_cu_data *next_cu;
11562 next_cu = per_cu->cu->read_in_chain;
11564 if (!per_cu->cu->mark)
11566 free_one_comp_unit (per_cu->cu);
11567 *last_chain = next_cu;
11570 last_chain = &per_cu->cu->read_in_chain;
11576 /* Remove a single compilation unit from the cache. */
11579 free_one_cached_comp_unit (void *target_cu)
11581 struct dwarf2_per_cu_data *per_cu, **last_chain;
11583 per_cu = dwarf2_per_objfile->read_in_chain;
11584 last_chain = &dwarf2_per_objfile->read_in_chain;
11585 while (per_cu != NULL)
11587 struct dwarf2_per_cu_data *next_cu;
11589 next_cu = per_cu->cu->read_in_chain;
11591 if (per_cu->cu == target_cu)
11593 free_one_comp_unit (per_cu->cu);
11594 *last_chain = next_cu;
11598 last_chain = &per_cu->cu->read_in_chain;
11604 /* Release all extra memory associated with OBJFILE. */
11607 dwarf2_free_objfile (struct objfile *objfile)
11609 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
11611 if (dwarf2_per_objfile == NULL)
11614 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11615 free_cached_comp_units (NULL);
11617 /* Everything else should be on the objfile obstack. */
11620 /* A pair of DIE offset and GDB type pointer. We store these
11621 in a hash table separate from the DIEs, and preserve them
11622 when the DIEs are flushed out of cache. */
11624 struct dwarf2_offset_and_type
11626 unsigned int offset;
11630 /* Hash function for a dwarf2_offset_and_type. */
11633 offset_and_type_hash (const void *item)
11635 const struct dwarf2_offset_and_type *ofs = item;
11636 return ofs->offset;
11639 /* Equality function for a dwarf2_offset_and_type. */
11642 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
11644 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
11645 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
11646 return ofs_lhs->offset == ofs_rhs->offset;
11649 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11650 table if necessary. For convenience, return TYPE. */
11652 static struct type *
11653 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11655 struct dwarf2_offset_and_type **slot, ofs;
11657 if (cu->type_hash == NULL)
11659 gdb_assert (cu->per_cu != NULL);
11660 cu->per_cu->type_hash
11661 = htab_create_alloc_ex (cu->header.length / 24,
11662 offset_and_type_hash,
11663 offset_and_type_eq,
11665 &cu->objfile->objfile_obstack,
11666 hashtab_obstack_allocate,
11667 dummy_obstack_deallocate);
11668 cu->type_hash = cu->per_cu->type_hash;
11671 ofs.offset = die->offset;
11673 slot = (struct dwarf2_offset_and_type **)
11674 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
11675 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
11680 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11681 not have a saved type. */
11683 static struct type *
11684 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
11686 struct dwarf2_offset_and_type *slot, ofs;
11687 htab_t type_hash = cu->type_hash;
11689 if (type_hash == NULL)
11692 ofs.offset = die->offset;
11693 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
11700 /* Add a dependence relationship from CU to REF_PER_CU. */
11703 dwarf2_add_dependence (struct dwarf2_cu *cu,
11704 struct dwarf2_per_cu_data *ref_per_cu)
11708 if (cu->dependencies == NULL)
11710 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
11711 NULL, &cu->comp_unit_obstack,
11712 hashtab_obstack_allocate,
11713 dummy_obstack_deallocate);
11715 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
11717 *slot = ref_per_cu;
11720 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11721 Set the mark field in every compilation unit in the
11722 cache that we must keep because we are keeping CU. */
11725 dwarf2_mark_helper (void **slot, void *data)
11727 struct dwarf2_per_cu_data *per_cu;
11729 per_cu = (struct dwarf2_per_cu_data *) *slot;
11730 if (per_cu->cu->mark)
11732 per_cu->cu->mark = 1;
11734 if (per_cu->cu->dependencies != NULL)
11735 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
11740 /* Set the mark field in CU and in every other compilation unit in the
11741 cache that we must keep because we are keeping CU. */
11744 dwarf2_mark (struct dwarf2_cu *cu)
11749 if (cu->dependencies != NULL)
11750 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
11754 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
11758 per_cu->cu->mark = 0;
11759 per_cu = per_cu->cu->read_in_chain;
11763 /* Trivial hash function for partial_die_info: the hash value of a DIE
11764 is its offset in .debug_info for this objfile. */
11767 partial_die_hash (const void *item)
11769 const struct partial_die_info *part_die = item;
11770 return part_die->offset;
11773 /* Trivial comparison function for partial_die_info structures: two DIEs
11774 are equal if they have the same offset. */
11777 partial_die_eq (const void *item_lhs, const void *item_rhs)
11779 const struct partial_die_info *part_die_lhs = item_lhs;
11780 const struct partial_die_info *part_die_rhs = item_rhs;
11781 return part_die_lhs->offset == part_die_rhs->offset;
11784 static struct cmd_list_element *set_dwarf2_cmdlist;
11785 static struct cmd_list_element *show_dwarf2_cmdlist;
11788 set_dwarf2_cmd (char *args, int from_tty)
11790 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
11794 show_dwarf2_cmd (char *args, int from_tty)
11796 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
11799 /* If section described by INFO was mmapped, munmap it now. */
11802 munmap_section_buffer (struct dwarf2_section_info *info)
11804 if (info->was_mmapped)
11807 intptr_t begin = (intptr_t) info->buffer;
11808 intptr_t map_begin = begin & ~(pagesize - 1);
11809 size_t map_length = info->size + begin - map_begin;
11810 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
11812 /* Without HAVE_MMAP, we should never be here to begin with. */
11818 /* munmap debug sections for OBJFILE, if necessary. */
11821 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
11823 struct dwarf2_per_objfile *data = d;
11824 munmap_section_buffer (&data->info);
11825 munmap_section_buffer (&data->abbrev);
11826 munmap_section_buffer (&data->line);
11827 munmap_section_buffer (&data->str);
11828 munmap_section_buffer (&data->macinfo);
11829 munmap_section_buffer (&data->ranges);
11830 munmap_section_buffer (&data->loc);
11831 munmap_section_buffer (&data->frame);
11832 munmap_section_buffer (&data->eh_frame);
11835 void _initialize_dwarf2_read (void);
11838 _initialize_dwarf2_read (void)
11840 dwarf2_objfile_data_key
11841 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
11843 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
11844 Set DWARF 2 specific variables.\n\
11845 Configure DWARF 2 variables such as the cache size"),
11846 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
11847 0/*allow-unknown*/, &maintenance_set_cmdlist);
11849 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
11850 Show DWARF 2 specific variables\n\
11851 Show DWARF 2 variables such as the cache size"),
11852 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
11853 0/*allow-unknown*/, &maintenance_show_cmdlist);
11855 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
11856 &dwarf2_max_cache_age, _("\
11857 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11858 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
11859 A higher limit means that cached compilation units will be stored\n\
11860 in memory longer, and more total memory will be used. Zero disables\n\
11861 caching, which can slow down startup."),
11863 show_dwarf2_max_cache_age,
11864 &set_dwarf2_cmdlist,
11865 &show_dwarf2_cmdlist);
11867 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
11868 Set debugging of the dwarf2 DIE reader."), _("\
11869 Show debugging of the dwarf2 DIE reader."), _("\
11870 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11871 The value is the maximum depth to print."),
11874 &setdebuglist, &showdebuglist);