1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
59 /* A note on memory usage for this file.
61 At the present time, this code reads the debug info sections into
62 the objfile's objfile_obstack. A definite improvement for startup
63 time, on platforms which do not emit relocations for debug
64 sections, would be to use mmap instead. The object's complete
65 debug information is loaded into memory, partly to simplify
66 absolute DIE references.
68 Whether using obstacks or mmap, the sections should remain loaded
69 until the objfile is released, and pointers into the section data
70 can be used for any other data associated to the objfile (symbol
71 names, type names, location expressions to name a few). */
74 /* .debug_info header for a compilation unit
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct comp_unit_header
79 unsigned int length; /* length of the .debug_info
81 unsigned short version; /* version number -- 2 for DWARF
83 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
84 unsigned char addr_size; /* byte size of an address -- 4 */
87 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct pubnames_header
95 unsigned int length; /* length of the .debug_pubnames
97 unsigned char version; /* version number -- 2 for DWARF
99 unsigned int info_offset; /* offset into .debug_info section */
100 unsigned int info_size; /* byte size of .debug_info section
104 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
106 /* .debug_pubnames header
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct aranges_header
111 unsigned int length; /* byte len of the .debug_aranges
113 unsigned short version; /* version number -- 2 for DWARF
115 unsigned int info_offset; /* offset into .debug_info section */
116 unsigned char addr_size; /* byte size of an address */
117 unsigned char seg_size; /* byte size of segment descriptor */
120 #define _ACTUAL_ARANGES_HEADER_SIZE 12
122 /* .debug_line statement program prologue
123 Because of alignment constraints, this structure has padding and cannot
124 be mapped directly onto the beginning of the .debug_info section. */
125 typedef struct statement_prologue
127 unsigned int total_length; /* byte length of the statement
129 unsigned short version; /* version number -- 2 for DWARF
131 unsigned int prologue_length; /* # bytes between prologue &
133 unsigned char minimum_instruction_length; /* byte size of
135 unsigned char default_is_stmt; /* initial value of is_stmt
138 unsigned char line_range;
139 unsigned char opcode_base; /* number assigned to first special
141 unsigned char *standard_opcode_lengths;
145 /* When non-zero, dump DIEs after they are read in. */
146 static int dwarf2_die_debug = 0;
148 /* When set, the file that we're processing is known to have debugging
149 info for C++ namespaces. GCC 3.3.x did not produce this information,
150 but later versions do. */
152 static int processing_has_namespace_info;
154 static const struct objfile_data *dwarf2_objfile_data_key;
156 struct dwarf2_per_objfile
158 /* Sizes of debugging sections. */
159 unsigned int info_size;
160 unsigned int abbrev_size;
161 unsigned int line_size;
162 unsigned int pubnames_size;
163 unsigned int aranges_size;
164 unsigned int loc_size;
165 unsigned int macinfo_size;
166 unsigned int str_size;
167 unsigned int ranges_size;
168 unsigned int frame_size;
169 unsigned int eh_frame_size;
171 /* Loaded data from the sections. */
172 gdb_byte *info_buffer;
173 gdb_byte *abbrev_buffer;
174 gdb_byte *line_buffer;
175 gdb_byte *str_buffer;
176 gdb_byte *macinfo_buffer;
177 gdb_byte *ranges_buffer;
178 gdb_byte *loc_buffer;
180 /* A list of all the compilation units. This is used to locate
181 the target compilation unit of a particular reference. */
182 struct dwarf2_per_cu_data **all_comp_units;
184 /* The number of compilation units in ALL_COMP_UNITS. */
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data *read_in_chain;
191 /* A flag indicating wether this objfile has a section loaded at a
193 int has_section_at_zero;
196 static struct dwarf2_per_objfile *dwarf2_per_objfile;
198 static asection *dwarf_info_section;
199 static asection *dwarf_abbrev_section;
200 static asection *dwarf_line_section;
201 static asection *dwarf_pubnames_section;
202 static asection *dwarf_aranges_section;
203 static asection *dwarf_loc_section;
204 static asection *dwarf_macinfo_section;
205 static asection *dwarf_str_section;
206 static asection *dwarf_ranges_section;
207 asection *dwarf_frame_section;
208 asection *dwarf_eh_frame_section;
210 /* names of the debugging sections */
212 /* Note that if the debugging section has been compressed, it might
213 have a name like .zdebug_info. */
215 #define INFO_SECTION "debug_info"
216 #define ABBREV_SECTION "debug_abbrev"
217 #define LINE_SECTION "debug_line"
218 #define PUBNAMES_SECTION "debug_pubnames"
219 #define ARANGES_SECTION "debug_aranges"
220 #define LOC_SECTION "debug_loc"
221 #define MACINFO_SECTION "debug_macinfo"
222 #define STR_SECTION "debug_str"
223 #define RANGES_SECTION "debug_ranges"
224 #define FRAME_SECTION "debug_frame"
225 #define EH_FRAME_SECTION "eh_frame"
227 /* local data types */
229 /* We hold several abbreviation tables in memory at the same time. */
230 #ifndef ABBREV_HASH_SIZE
231 #define ABBREV_HASH_SIZE 121
234 /* The data in a compilation unit header, after target2host
235 translation, looks like this. */
236 struct comp_unit_head
240 unsigned char addr_size;
241 unsigned char signed_addr_p;
242 unsigned int abbrev_offset;
244 /* Size of file offsets; either 4 or 8. */
245 unsigned int offset_size;
247 /* Size of the length field; either 4 or 12. */
248 unsigned int initial_length_size;
250 /* Offset to the first byte of this compilation unit header in the
251 .debug_info section, for resolving relative reference dies. */
254 /* Offset to first die in this cu from the start of the cu.
255 This will be the first byte following the compilation unit header. */
256 unsigned int first_die_offset;
259 /* Internal state when decoding a particular compilation unit. */
262 /* The objfile containing this compilation unit. */
263 struct objfile *objfile;
265 /* The header of the compilation unit. */
266 struct comp_unit_head header;
268 /* Base address of this compilation unit. */
269 CORE_ADDR base_address;
271 /* Non-zero if base_address has been set. */
274 struct function_range *first_fn, *last_fn, *cached_fn;
276 /* The language we are debugging. */
277 enum language language;
278 const struct language_defn *language_defn;
280 const char *producer;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending **list_in_scope;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info **dwarf2_abbrevs;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned int ranges_offset;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack;
309 /* When multiple dwarf2_cu structures are living in memory, this field
310 chains them all together, so that they can be released efficiently.
311 We will probably also want a generation counter so that most-recently-used
312 compilation units are cached... */
313 struct dwarf2_per_cu_data *read_in_chain;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data *per_cu;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info *dies;
332 /* A set of pointers to dwarf2_per_cu_data objects for compilation
333 units referenced by this one. Only set during full symbol processing;
334 partial symbol tables do not have dependencies. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header *line_header;
340 /* Mark used when releasing cached dies. */
341 unsigned int mark : 1;
343 /* This flag will be set if this compilation unit might include
344 inter-compilation-unit references. */
345 unsigned int has_form_ref_addr : 1;
347 /* This flag will be set if this compilation unit includes any
348 DW_TAG_namespace DIEs. If we know that there are explicit
349 DIEs for namespaces, we don't need to try to infer them
350 from mangled names. */
351 unsigned int has_namespace_info : 1;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset : 1;
357 /* Persistent data held for a compilation unit, even when not
358 processing it. We put a pointer to this structure in the
359 read_symtab_private field of the psymtab. If we encounter
360 inter-compilation-unit references, we also maintain a sorted
361 list of all compilation units. */
363 struct dwarf2_per_cu_data
365 /* The start offset and length of this compilation unit. 2**30-1
366 bytes should suffice to store the length of any compilation unit
367 - if it doesn't, GDB will fall over anyway.
368 NOTE: Unlike comp_unit_head.length, this length includes
369 initial_length_size. */
371 unsigned int length : 30;
373 /* Flag indicating this compilation unit will be read in before
374 any of the current compilation units are processed. */
375 unsigned int queued : 1;
377 /* This flag will be set if we need to load absolutely all DIEs
378 for this compilation unit, instead of just the ones we think
379 are interesting. It gets set if we look for a DIE in the
380 hash table and don't find it. */
381 unsigned int load_all_dies : 1;
383 /* Set iff currently read in. */
384 struct dwarf2_cu *cu;
386 /* If full symbols for this CU have been read in, then this field
387 holds a map of DIE offsets to types. It isn't always possible
388 to reconstruct this information later, so we have to preserve
392 /* The partial symbol table associated with this compilation unit,
393 or NULL for partial units (which do not have an associated
395 struct partial_symtab *psymtab;
398 /* The line number information for a compilation unit (found in the
399 .debug_line section) begins with a "statement program header",
400 which contains the following information. */
403 unsigned int total_length;
404 unsigned short version;
405 unsigned int header_length;
406 unsigned char minimum_instruction_length;
407 unsigned char default_is_stmt;
409 unsigned char line_range;
410 unsigned char opcode_base;
412 /* standard_opcode_lengths[i] is the number of operands for the
413 standard opcode whose value is i. This means that
414 standard_opcode_lengths[0] is unused, and the last meaningful
415 element is standard_opcode_lengths[opcode_base - 1]. */
416 unsigned char *standard_opcode_lengths;
418 /* The include_directories table. NOTE! These strings are not
419 allocated with xmalloc; instead, they are pointers into
420 debug_line_buffer. If you try to free them, `free' will get
422 unsigned int num_include_dirs, include_dirs_size;
425 /* The file_names table. NOTE! These strings are not allocated
426 with xmalloc; instead, they are pointers into debug_line_buffer.
427 Don't try to free them directly. */
428 unsigned int num_file_names, file_names_size;
432 unsigned int dir_index;
433 unsigned int mod_time;
435 int included_p; /* Non-zero if referenced by the Line Number Program. */
436 struct symtab *symtab; /* The associated symbol table, if any. */
439 /* The start and end of the statement program following this
440 header. These point into dwarf2_per_objfile->line_buffer. */
441 gdb_byte *statement_program_start, *statement_program_end;
444 /* When we construct a partial symbol table entry we only
445 need this much information. */
446 struct partial_die_info
448 /* Offset of this DIE. */
451 /* DWARF-2 tag for this DIE. */
452 ENUM_BITFIELD(dwarf_tag) tag : 16;
454 /* Language code associated with this DIE. This is only used
455 for the compilation unit DIE. */
456 unsigned int language : 8;
458 /* Assorted flags describing the data found in this DIE. */
459 unsigned int has_children : 1;
460 unsigned int is_external : 1;
461 unsigned int is_declaration : 1;
462 unsigned int has_type : 1;
463 unsigned int has_specification : 1;
464 unsigned int has_stmt_list : 1;
465 unsigned int has_pc_info : 1;
467 /* Flag set if the SCOPE field of this structure has been
469 unsigned int scope_set : 1;
471 /* Flag set if the DIE has a byte_size attribute. */
472 unsigned int has_byte_size : 1;
474 /* The name of this DIE. Normally the value of DW_AT_name, but
475 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
480 /* The scope to prepend to our children. This is generally
481 allocated on the comp_unit_obstack, so will disappear
482 when this compilation unit leaves the cache. */
485 /* The location description associated with this DIE, if any. */
486 struct dwarf_block *locdesc;
488 /* If HAS_PC_INFO, the PC range associated with this DIE. */
492 /* Pointer into the info_buffer pointing at the target of
493 DW_AT_sibling, if any. */
496 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
497 DW_AT_specification (or DW_AT_abstract_origin or
499 unsigned int spec_offset;
501 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
502 unsigned int line_offset;
504 /* Pointers to this DIE's parent, first child, and next sibling,
506 struct partial_die_info *die_parent, *die_child, *die_sibling;
509 /* This data structure holds the information of an abbrev. */
512 unsigned int number; /* number identifying abbrev */
513 enum dwarf_tag tag; /* dwarf tag */
514 unsigned short has_children; /* boolean */
515 unsigned short num_attrs; /* number of attributes */
516 struct attr_abbrev *attrs; /* an array of attribute descriptions */
517 struct abbrev_info *next; /* next in chain */
522 ENUM_BITFIELD(dwarf_attribute) name : 16;
523 ENUM_BITFIELD(dwarf_form) form : 16;
526 /* Attributes have a name and a value */
529 ENUM_BITFIELD(dwarf_attribute) name : 16;
530 ENUM_BITFIELD(dwarf_form) form : 16;
534 struct dwarf_block *blk;
542 /* This data structure holds a complete die structure. */
545 /* DWARF-2 tag for this DIE. */
546 ENUM_BITFIELD(dwarf_tag) tag : 16;
548 /* Number of attributes */
549 unsigned short num_attrs;
554 /* Offset in .debug_info section */
557 /* The dies in a compilation unit form an n-ary tree. PARENT
558 points to this die's parent; CHILD points to the first child of
559 this node; and all the children of a given node are chained
560 together via their SIBLING fields, terminated by a die whose
562 struct die_info *child; /* Its first child, if any. */
563 struct die_info *sibling; /* Its next sibling, if any. */
564 struct die_info *parent; /* Its parent, if any. */
566 /* An array of attributes, with NUM_ATTRS elements. There may be
567 zero, but it's not common and zero-sized arrays are not
568 sufficiently portable C. */
569 struct attribute attrs[1];
572 struct function_range
575 CORE_ADDR lowpc, highpc;
577 struct function_range *next;
580 /* Get at parts of an attribute structure */
582 #define DW_STRING(attr) ((attr)->u.str)
583 #define DW_UNSND(attr) ((attr)->u.unsnd)
584 #define DW_BLOCK(attr) ((attr)->u.blk)
585 #define DW_SND(attr) ((attr)->u.snd)
586 #define DW_ADDR(attr) ((attr)->u.addr)
588 /* Blocks are a bunch of untyped bytes. */
595 #ifndef ATTR_ALLOC_CHUNK
596 #define ATTR_ALLOC_CHUNK 4
599 /* Allocate fields for structs, unions and enums in this size. */
600 #ifndef DW_FIELD_ALLOC_CHUNK
601 #define DW_FIELD_ALLOC_CHUNK 4
604 /* A zeroed version of a partial die for initialization purposes. */
605 static struct partial_die_info zeroed_partial_die;
607 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
608 but this would require a corresponding change in unpack_field_as_long
610 static int bits_per_byte = 8;
612 /* The routines that read and process dies for a C struct or C++ class
613 pass lists of data member fields and lists of member function fields
614 in an instance of a field_info structure, as defined below. */
617 /* List of data member and baseclasses fields. */
620 struct nextfield *next;
627 /* Number of fields. */
630 /* Number of baseclasses. */
633 /* Set if the accesibility of one of the fields is not public. */
634 int non_public_fields;
636 /* Member function fields array, entries are allocated in the order they
637 are encountered in the object file. */
640 struct nextfnfield *next;
641 struct fn_field fnfield;
645 /* Member function fieldlist array, contains name of possibly overloaded
646 member function, number of overloaded member functions and a pointer
647 to the head of the member function field chain. */
652 struct nextfnfield *head;
656 /* Number of entries in the fnfieldlists array. */
660 /* One item on the queue of compilation units to read in full symbols
662 struct dwarf2_queue_item
664 struct dwarf2_per_cu_data *per_cu;
665 struct dwarf2_queue_item *next;
668 /* The current queue. */
669 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
671 /* Loaded secondary compilation units are kept in memory until they
672 have not been referenced for the processing of this many
673 compilation units. Set this to zero to disable caching. Cache
674 sizes of up to at least twenty will improve startup time for
675 typical inter-CU-reference binaries, at an obvious memory cost. */
676 static int dwarf2_max_cache_age = 5;
678 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
679 struct cmd_list_element *c, const char *value)
681 fprintf_filtered (file, _("\
682 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
687 /* Various complaints about symbol reading that don't abort the process */
690 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
692 complaint (&symfile_complaints,
693 _("statement list doesn't fit in .debug_line section"));
697 dwarf2_debug_line_missing_file_complaint (void)
699 complaint (&symfile_complaints,
700 _(".debug_line section has line data without a file"));
704 dwarf2_debug_line_missing_end_sequence_complaint (void)
706 complaint (&symfile_complaints,
707 _(".debug_line section has line program sequence without an end"));
711 dwarf2_complex_location_expr_complaint (void)
713 complaint (&symfile_complaints, _("location expression too complex"));
717 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
720 complaint (&symfile_complaints,
721 _("const value length mismatch for '%s', got %d, expected %d"), arg1,
726 dwarf2_macros_too_long_complaint (void)
728 complaint (&symfile_complaints,
729 _("macro info runs off end of `.debug_macinfo' section"));
733 dwarf2_macro_malformed_definition_complaint (const char *arg1)
735 complaint (&symfile_complaints,
736 _("macro debug info contains a malformed macro definition:\n`%s'"),
741 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
743 complaint (&symfile_complaints,
744 _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2);
747 /* local function prototypes */
749 static void dwarf2_locate_sections (bfd *, asection *, void *);
752 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
755 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
758 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
759 struct partial_die_info *,
760 struct partial_symtab *);
762 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
764 static void scan_partial_symbols (struct partial_die_info *,
765 CORE_ADDR *, CORE_ADDR *,
766 int, struct dwarf2_cu *);
768 static void add_partial_symbol (struct partial_die_info *,
771 static int pdi_needs_namespace (enum dwarf_tag tag);
773 static void add_partial_namespace (struct partial_die_info *pdi,
774 CORE_ADDR *lowpc, CORE_ADDR *highpc,
775 int need_pc, struct dwarf2_cu *cu);
777 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
778 CORE_ADDR *highpc, int need_pc,
779 struct dwarf2_cu *cu);
781 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
782 struct dwarf2_cu *cu);
784 static void add_partial_subprogram (struct partial_die_info *pdi,
785 CORE_ADDR *lowpc, CORE_ADDR *highpc,
786 int need_pc, struct dwarf2_cu *cu);
788 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
791 struct dwarf2_cu *cu);
793 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
795 static void psymtab_to_symtab_1 (struct partial_symtab *);
797 gdb_byte *dwarf2_read_section (struct objfile *, asection *);
799 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
801 static void dwarf2_free_abbrev_table (void *);
803 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
806 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
809 static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int,
812 static gdb_byte *read_partial_die (struct partial_die_info *,
813 struct abbrev_info *abbrev, unsigned int,
814 bfd *, gdb_byte *, struct dwarf2_cu *);
816 static struct partial_die_info *find_partial_die (unsigned int,
819 static void fixup_partial_die (struct partial_die_info *,
822 static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *,
823 struct dwarf2_cu *, int *);
825 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
826 bfd *, gdb_byte *, struct dwarf2_cu *);
828 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
829 bfd *, gdb_byte *, struct dwarf2_cu *);
831 static unsigned int read_1_byte (bfd *, gdb_byte *);
833 static int read_1_signed_byte (bfd *, gdb_byte *);
835 static unsigned int read_2_bytes (bfd *, gdb_byte *);
837 static unsigned int read_4_bytes (bfd *, gdb_byte *);
839 static unsigned long read_8_bytes (bfd *, gdb_byte *);
841 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
844 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
846 static LONGEST read_checked_initial_length_and_offset
847 (bfd *, gdb_byte *, const struct comp_unit_head *,
848 unsigned int *, unsigned int *);
850 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
853 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
855 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
857 static char *read_string (bfd *, gdb_byte *, unsigned int *);
859 static char *read_indirect_string (bfd *, gdb_byte *,
860 const struct comp_unit_head *,
863 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
865 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
867 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
869 static void set_cu_language (unsigned int, struct dwarf2_cu *);
871 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
874 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
875 struct dwarf2_cu *cu);
877 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
879 static struct die_info *die_specification (struct die_info *die,
880 struct dwarf2_cu **);
882 static void free_line_header (struct line_header *lh);
884 static void add_file_name (struct line_header *, char *, unsigned int,
885 unsigned int, unsigned int);
887 static struct line_header *(dwarf_decode_line_header
888 (unsigned int offset,
889 bfd *abfd, struct dwarf2_cu *cu));
891 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
892 struct dwarf2_cu *, struct partial_symtab *);
894 static void dwarf2_start_subfile (char *, char *, char *);
896 static struct symbol *new_symbol (struct die_info *, struct type *,
899 static void dwarf2_const_value (struct attribute *, struct symbol *,
902 static void dwarf2_const_value_data (struct attribute *attr,
906 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
908 static struct type *die_containing_type (struct die_info *,
911 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
913 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
915 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
917 static char *typename_concat (struct obstack *,
922 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
924 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
926 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
928 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
929 struct dwarf2_cu *, struct partial_symtab *);
931 static int dwarf2_get_pc_bounds (struct die_info *,
932 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
934 static void get_scope_pc_bounds (struct die_info *,
935 CORE_ADDR *, CORE_ADDR *,
938 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
939 CORE_ADDR, struct dwarf2_cu *);
941 static void dwarf2_add_field (struct field_info *, struct die_info *,
944 static void dwarf2_attach_fields_to_type (struct field_info *,
945 struct type *, struct dwarf2_cu *);
947 static void dwarf2_add_member_fn (struct field_info *,
948 struct die_info *, struct type *,
951 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
952 struct type *, struct dwarf2_cu *);
954 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
956 static const char *determine_class_name (struct die_info *die,
957 struct dwarf2_cu *cu);
959 static void read_common_block (struct die_info *, struct dwarf2_cu *);
961 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
963 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
965 static const char *namespace_name (struct die_info *die,
966 int *is_anonymous, struct dwarf2_cu *);
968 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
970 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
972 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
975 static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *);
977 static struct die_info *read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd,
979 gdb_byte **new_info_ptr,
980 struct die_info *parent);
982 static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd,
984 gdb_byte **new_info_ptr,
985 struct die_info *parent);
987 static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd,
989 gdb_byte **new_info_ptr,
990 struct die_info *parent);
992 static void process_die (struct die_info *, struct dwarf2_cu *);
994 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
996 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
998 static struct die_info *dwarf2_extension (struct die_info *die,
999 struct dwarf2_cu **);
1001 static char *dwarf_tag_name (unsigned int);
1003 static char *dwarf_attr_name (unsigned int);
1005 static char *dwarf_form_name (unsigned int);
1007 static char *dwarf_stack_op_name (unsigned int);
1009 static char *dwarf_bool_name (unsigned int);
1011 static char *dwarf_type_encoding_name (unsigned int);
1014 static char *dwarf_cfi_name (unsigned int);
1017 static struct die_info *sibling_die (struct die_info *);
1019 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1021 static void dump_die_for_error (struct die_info *);
1023 static void dump_die_1 (struct ui_file *, int level, int max_level,
1026 /*static*/ void dump_die (struct die_info *, int max_level);
1028 static void store_in_ref_table (struct die_info *,
1029 struct dwarf2_cu *);
1031 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1033 static int dwarf2_get_attr_constant_value (struct attribute *, int);
1035 static struct die_info *follow_die_ref (struct die_info *,
1037 struct dwarf2_cu **);
1039 /* memory allocation interface */
1041 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1043 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1045 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1047 static void initialize_cu_func_list (struct dwarf2_cu *);
1049 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1050 struct dwarf2_cu *);
1052 static void dwarf_decode_macros (struct line_header *, unsigned int,
1053 char *, bfd *, struct dwarf2_cu *);
1055 static int attr_form_is_block (struct attribute *);
1057 static int attr_form_is_section_offset (struct attribute *);
1059 static int attr_form_is_constant (struct attribute *);
1061 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1063 struct dwarf2_cu *cu);
1065 static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev,
1066 struct dwarf2_cu *cu);
1068 static void free_stack_comp_unit (void *);
1070 static hashval_t partial_die_hash (const void *item);
1072 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1074 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1075 (unsigned int offset, struct objfile *objfile);
1077 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1078 (unsigned int offset, struct objfile *objfile);
1080 static void free_one_comp_unit (void *);
1082 static void free_cached_comp_units (void *);
1084 static void age_cached_comp_units (void);
1086 static void free_one_cached_comp_unit (void *);
1088 static struct type *set_die_type (struct die_info *, struct type *,
1089 struct dwarf2_cu *);
1091 static void create_all_comp_units (struct objfile *);
1093 static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *,
1096 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1098 static void dwarf2_add_dependence (struct dwarf2_cu *,
1099 struct dwarf2_per_cu_data *);
1101 static void dwarf2_mark (struct dwarf2_cu *);
1103 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1105 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1107 /* Try to locate the sections we need for DWARF 2 debugging
1108 information and return true if we have enough to do something. */
1111 dwarf2_has_info (struct objfile *objfile)
1113 struct dwarf2_per_objfile *data;
1115 /* Initialize per-objfile state. */
1116 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1117 memset (data, 0, sizeof (*data));
1118 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1119 dwarf2_per_objfile = data;
1121 dwarf_info_section = 0;
1122 dwarf_abbrev_section = 0;
1123 dwarf_line_section = 0;
1124 dwarf_str_section = 0;
1125 dwarf_macinfo_section = 0;
1126 dwarf_frame_section = 0;
1127 dwarf_eh_frame_section = 0;
1128 dwarf_ranges_section = 0;
1129 dwarf_loc_section = 0;
1131 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1132 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
1135 /* When loading sections, we can either look for ".<name>", or for
1136 * ".z<name>", which indicates a compressed section. */
1139 section_is_p (asection *sectp, const char *name)
1141 return ((sectp->name[0] == '.'
1142 && strcmp (sectp->name + 1, name) == 0)
1143 || (sectp->name[0] == '.' && sectp->name[1] == 'z'
1144 && strcmp (sectp->name + 2, name) == 0));
1147 /* This function is mapped across the sections and remembers the
1148 offset and size of each of the debugging sections we are interested
1152 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1154 if (section_is_p (sectp, INFO_SECTION))
1156 dwarf2_per_objfile->info_size = bfd_get_section_size (sectp);
1157 dwarf_info_section = sectp;
1159 else if (section_is_p (sectp, ABBREV_SECTION))
1161 dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp);
1162 dwarf_abbrev_section = sectp;
1164 else if (section_is_p (sectp, LINE_SECTION))
1166 dwarf2_per_objfile->line_size = bfd_get_section_size (sectp);
1167 dwarf_line_section = sectp;
1169 else if (section_is_p (sectp, PUBNAMES_SECTION))
1171 dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp);
1172 dwarf_pubnames_section = sectp;
1174 else if (section_is_p (sectp, ARANGES_SECTION))
1176 dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp);
1177 dwarf_aranges_section = sectp;
1179 else if (section_is_p (sectp, LOC_SECTION))
1181 dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp);
1182 dwarf_loc_section = sectp;
1184 else if (section_is_p (sectp, MACINFO_SECTION))
1186 dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp);
1187 dwarf_macinfo_section = sectp;
1189 else if (section_is_p (sectp, STR_SECTION))
1191 dwarf2_per_objfile->str_size = bfd_get_section_size (sectp);
1192 dwarf_str_section = sectp;
1194 else if (section_is_p (sectp, FRAME_SECTION))
1196 dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp);
1197 dwarf_frame_section = sectp;
1199 else if (section_is_p (sectp, EH_FRAME_SECTION))
1201 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1202 if (aflag & SEC_HAS_CONTENTS)
1204 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp);
1205 dwarf_eh_frame_section = sectp;
1208 else if (section_is_p (sectp, RANGES_SECTION))
1210 dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
1211 dwarf_ranges_section = sectp;
1214 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1215 && bfd_section_vma (abfd, sectp) == 0)
1216 dwarf2_per_objfile->has_section_at_zero = 1;
1219 /* This function is called after decompressing a section, so
1220 dwarf2_per_objfile can record its new, uncompressed size. */
1223 dwarf2_resize_section (asection *sectp, bfd_size_type new_size)
1225 if (section_is_p (sectp, INFO_SECTION))
1226 dwarf2_per_objfile->info_size = new_size;
1227 else if (section_is_p (sectp, ABBREV_SECTION))
1228 dwarf2_per_objfile->abbrev_size = new_size;
1229 else if (section_is_p (sectp, LINE_SECTION))
1230 dwarf2_per_objfile->line_size = new_size;
1231 else if (section_is_p (sectp, PUBNAMES_SECTION))
1232 dwarf2_per_objfile->pubnames_size = new_size;
1233 else if (section_is_p (sectp, ARANGES_SECTION))
1234 dwarf2_per_objfile->aranges_size = new_size;
1235 else if (section_is_p (sectp, LOC_SECTION))
1236 dwarf2_per_objfile->loc_size = new_size;
1237 else if (section_is_p (sectp, MACINFO_SECTION))
1238 dwarf2_per_objfile->macinfo_size = new_size;
1239 else if (section_is_p (sectp, STR_SECTION))
1240 dwarf2_per_objfile->str_size = new_size;
1241 else if (section_is_p (sectp, FRAME_SECTION))
1242 dwarf2_per_objfile->frame_size = new_size;
1243 else if (section_is_p (sectp, EH_FRAME_SECTION))
1244 dwarf2_per_objfile->eh_frame_size = new_size;
1245 else if (section_is_p (sectp, RANGES_SECTION))
1246 dwarf2_per_objfile->ranges_size = new_size;
1248 internal_error (__FILE__, __LINE__,
1249 _("dwarf2_resize_section: missing section_is_p check: %s"),
1253 /* Build a partial symbol table. */
1256 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1258 /* We definitely need the .debug_info and .debug_abbrev sections */
1260 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1261 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1263 if (dwarf_line_section)
1264 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1266 dwarf2_per_objfile->line_buffer = NULL;
1268 if (dwarf_str_section)
1269 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1271 dwarf2_per_objfile->str_buffer = NULL;
1273 if (dwarf_macinfo_section)
1274 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1275 dwarf_macinfo_section);
1277 dwarf2_per_objfile->macinfo_buffer = NULL;
1279 if (dwarf_ranges_section)
1280 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1282 dwarf2_per_objfile->ranges_buffer = NULL;
1284 if (dwarf_loc_section)
1285 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1287 dwarf2_per_objfile->loc_buffer = NULL;
1290 || (objfile->global_psymbols.size == 0
1291 && objfile->static_psymbols.size == 0))
1293 init_psymbol_list (objfile, 1024);
1297 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1299 /* Things are significantly easier if we have .debug_aranges and
1300 .debug_pubnames sections */
1302 dwarf2_build_psymtabs_easy (objfile, mainline);
1306 /* only test this case for now */
1308 /* In this case we have to work a bit harder */
1309 dwarf2_build_psymtabs_hard (objfile, mainline);
1314 /* Build the partial symbol table from the information in the
1315 .debug_pubnames and .debug_aranges sections. */
1318 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1320 bfd *abfd = objfile->obfd;
1321 char *aranges_buffer, *pubnames_buffer;
1322 char *aranges_ptr, *pubnames_ptr;
1323 unsigned int entry_length, version, info_offset, info_size;
1325 pubnames_buffer = dwarf2_read_section (objfile,
1326 dwarf_pubnames_section);
1327 pubnames_ptr = pubnames_buffer;
1328 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1330 unsigned int bytes_read;
1332 entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read);
1333 pubnames_ptr += bytes_read;
1334 version = read_1_byte (abfd, pubnames_ptr);
1336 info_offset = read_4_bytes (abfd, pubnames_ptr);
1338 info_size = read_4_bytes (abfd, pubnames_ptr);
1342 aranges_buffer = dwarf2_read_section (objfile,
1343 dwarf_aranges_section);
1348 /* Return TRUE if OFFSET is within CU_HEADER. */
1351 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
1353 unsigned int bottom = cu_header->offset;
1354 unsigned int top = (cu_header->offset
1356 + cu_header->initial_length_size);
1357 return (offset >= bottom && offset < top);
1360 /* Read in the comp unit header information from the debug_info at
1364 read_comp_unit_head (struct comp_unit_head *cu_header,
1365 gdb_byte *info_ptr, bfd *abfd)
1368 unsigned int bytes_read;
1370 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
1371 cu_header->initial_length_size = bytes_read;
1372 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
1373 info_ptr += bytes_read;
1374 cu_header->version = read_2_bytes (abfd, info_ptr);
1376 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1378 info_ptr += bytes_read;
1379 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1381 signed_addr = bfd_get_sign_extend_vma (abfd);
1382 if (signed_addr < 0)
1383 internal_error (__FILE__, __LINE__,
1384 _("read_comp_unit_head: dwarf from non elf file"));
1385 cu_header->signed_addr_p = signed_addr;
1391 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
1394 gdb_byte *beg_of_comp_unit = info_ptr;
1396 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1398 if (header->version != 2 && header->version != 3)
1399 error (_("Dwarf Error: wrong version in compilation unit header "
1400 "(is %d, should be %d) [in module %s]"), header->version,
1401 2, bfd_get_filename (abfd));
1403 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1404 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1405 "(offset 0x%lx + 6) [in module %s]"),
1406 (long) header->abbrev_offset,
1407 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1408 bfd_get_filename (abfd));
1410 if (beg_of_comp_unit + header->length + header->initial_length_size
1411 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1412 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1413 "(offset 0x%lx + 0) [in module %s]"),
1414 (long) header->length,
1415 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1416 bfd_get_filename (abfd));
1421 /* Allocate a new partial symtab for file named NAME and mark this new
1422 partial symtab as being an include of PST. */
1425 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1426 struct objfile *objfile)
1428 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1430 subpst->section_offsets = pst->section_offsets;
1431 subpst->textlow = 0;
1432 subpst->texthigh = 0;
1434 subpst->dependencies = (struct partial_symtab **)
1435 obstack_alloc (&objfile->objfile_obstack,
1436 sizeof (struct partial_symtab *));
1437 subpst->dependencies[0] = pst;
1438 subpst->number_of_dependencies = 1;
1440 subpst->globals_offset = 0;
1441 subpst->n_global_syms = 0;
1442 subpst->statics_offset = 0;
1443 subpst->n_static_syms = 0;
1444 subpst->symtab = NULL;
1445 subpst->read_symtab = pst->read_symtab;
1448 /* No private part is necessary for include psymtabs. This property
1449 can be used to differentiate between such include psymtabs and
1450 the regular ones. */
1451 subpst->read_symtab_private = NULL;
1454 /* Read the Line Number Program data and extract the list of files
1455 included by the source file represented by PST. Build an include
1456 partial symtab for each of these included files.
1458 This procedure assumes that there *is* a Line Number Program in
1459 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1460 before calling this procedure. */
1463 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1464 struct partial_die_info *pdi,
1465 struct partial_symtab *pst)
1467 struct objfile *objfile = cu->objfile;
1468 bfd *abfd = objfile->obfd;
1469 struct line_header *lh;
1471 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1473 return; /* No linetable, so no includes. */
1475 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1477 free_line_header (lh);
1481 /* Build the partial symbol table by doing a quick pass through the
1482 .debug_info and .debug_abbrev sections. */
1485 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1487 /* Instead of reading this into a big buffer, we should probably use
1488 mmap() on architectures that support it. (FIXME) */
1489 bfd *abfd = objfile->obfd;
1491 gdb_byte *beg_of_comp_unit;
1492 struct partial_die_info comp_unit_die;
1493 struct partial_symtab *pst;
1494 struct cleanup *back_to;
1497 info_ptr = dwarf2_per_objfile->info_buffer;
1499 /* Any cached compilation units will be linked by the per-objfile
1500 read_in_chain. Make sure to free them when we're done. */
1501 back_to = make_cleanup (free_cached_comp_units, NULL);
1503 create_all_comp_units (objfile);
1505 objfile->psymtabs_addrmap = addrmap_create_mutable
1506 (&objfile->objfile_obstack);
1508 /* Since the objects we're extracting from .debug_info vary in
1509 length, only the individual functions to extract them (like
1510 read_comp_unit_head and load_partial_die) can really know whether
1511 the buffer is large enough to hold another complete object.
1513 At the moment, they don't actually check that. If .debug_info
1514 holds just one extra byte after the last compilation unit's dies,
1515 then read_comp_unit_head will happily read off the end of the
1516 buffer. read_partial_die is similarly casual. Those functions
1519 For this loop condition, simply checking whether there's any data
1520 left at all should be sufficient. */
1521 while (info_ptr < (dwarf2_per_objfile->info_buffer
1522 + dwarf2_per_objfile->info_size))
1524 struct cleanup *back_to_inner;
1525 struct dwarf2_cu cu;
1526 struct abbrev_info *abbrev;
1527 unsigned int bytes_read;
1528 struct dwarf2_per_cu_data *this_cu;
1530 beg_of_comp_unit = info_ptr;
1532 memset (&cu, 0, sizeof (cu));
1534 obstack_init (&cu.comp_unit_obstack);
1536 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1538 cu.objfile = objfile;
1539 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1541 /* Complete the cu_header */
1542 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1543 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
1545 cu.list_in_scope = &file_symbols;
1547 /* Read the abbrevs for this compilation unit into a table */
1548 dwarf2_read_abbrevs (abfd, &cu);
1549 make_cleanup (dwarf2_free_abbrev_table, &cu);
1551 this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile);
1553 /* Read the compilation unit die */
1554 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1555 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1556 abfd, info_ptr, &cu);
1558 if (comp_unit_die.tag == DW_TAG_partial_unit)
1560 info_ptr = (beg_of_comp_unit + cu.header.length
1561 + cu.header.initial_length_size);
1562 do_cleanups (back_to_inner);
1566 /* Set the language we're debugging */
1567 set_cu_language (comp_unit_die.language, &cu);
1569 /* Allocate a new partial symbol table structure */
1570 pst = start_psymtab_common (objfile, objfile->section_offsets,
1571 comp_unit_die.name ? comp_unit_die.name : "",
1572 /* TEXTLOW and TEXTHIGH are set below. */
1574 objfile->global_psymbols.next,
1575 objfile->static_psymbols.next);
1577 if (comp_unit_die.dirname)
1578 pst->dirname = obsavestring (comp_unit_die.dirname,
1579 strlen (comp_unit_die.dirname),
1580 &objfile->objfile_obstack);
1582 pst->read_symtab_private = (char *) this_cu;
1584 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1586 /* Store the function that reads in the rest of the symbol table */
1587 pst->read_symtab = dwarf2_psymtab_to_symtab;
1589 /* If this compilation unit was already read in, free the
1590 cached copy in order to read it in again. This is
1591 necessary because we skipped some symbols when we first
1592 read in the compilation unit (see load_partial_dies).
1593 This problem could be avoided, but the benefit is
1595 if (this_cu->cu != NULL)
1596 free_one_cached_comp_unit (this_cu->cu);
1598 cu.per_cu = this_cu;
1600 /* Note that this is a pointer to our stack frame, being
1601 added to a global data structure. It will be cleaned up
1602 in free_stack_comp_unit when we finish with this
1603 compilation unit. */
1606 this_cu->psymtab = pst;
1608 /* Possibly set the default values of LOWPC and HIGHPC from
1610 if (cu.has_ranges_offset)
1612 if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc,
1613 &comp_unit_die.highpc, &cu, pst))
1614 comp_unit_die.has_pc_info = 1;
1616 else if (comp_unit_die.has_pc_info
1617 && comp_unit_die.lowpc < comp_unit_die.highpc)
1618 /* Store the contiguous range if it is not empty; it can be empty for
1619 CUs with no code. */
1620 addrmap_set_empty (objfile->psymtabs_addrmap,
1621 comp_unit_die.lowpc + baseaddr,
1622 comp_unit_die.highpc + baseaddr - 1, pst);
1624 /* Check if comp unit has_children.
1625 If so, read the rest of the partial symbols from this comp unit.
1626 If not, there's no more debug_info for this comp unit. */
1627 if (comp_unit_die.has_children)
1629 struct partial_die_info *first_die;
1630 CORE_ADDR lowpc, highpc;
1632 lowpc = ((CORE_ADDR) -1);
1633 highpc = ((CORE_ADDR) 0);
1635 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1637 scan_partial_symbols (first_die, &lowpc, &highpc,
1638 ! comp_unit_die.has_pc_info, &cu);
1640 /* If we didn't find a lowpc, set it to highpc to avoid
1641 complaints from `maint check'. */
1642 if (lowpc == ((CORE_ADDR) -1))
1645 /* If the compilation unit didn't have an explicit address range,
1646 then use the information extracted from its child dies. */
1647 if (! comp_unit_die.has_pc_info)
1649 comp_unit_die.lowpc = lowpc;
1650 comp_unit_die.highpc = highpc;
1653 pst->textlow = comp_unit_die.lowpc + baseaddr;
1654 pst->texthigh = comp_unit_die.highpc + baseaddr;
1656 pst->n_global_syms = objfile->global_psymbols.next -
1657 (objfile->global_psymbols.list + pst->globals_offset);
1658 pst->n_static_syms = objfile->static_psymbols.next -
1659 (objfile->static_psymbols.list + pst->statics_offset);
1660 sort_pst_symbols (pst);
1662 /* If there is already a psymtab or symtab for a file of this
1663 name, remove it. (If there is a symtab, more drastic things
1664 also happen.) This happens in VxWorks. */
1665 free_named_symtabs (pst->filename);
1667 info_ptr = beg_of_comp_unit + cu.header.length
1668 + cu.header.initial_length_size;
1670 if (comp_unit_die.has_stmt_list)
1672 /* Get the list of files included in the current compilation unit,
1673 and build a psymtab for each of them. */
1674 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1677 do_cleanups (back_to_inner);
1680 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
1681 &objfile->objfile_obstack);
1683 do_cleanups (back_to);
1686 /* Load the DIEs for a secondary CU into memory. */
1689 load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile)
1691 bfd *abfd = objfile->obfd;
1692 gdb_byte *info_ptr, *beg_of_comp_unit;
1693 struct partial_die_info comp_unit_die;
1694 struct dwarf2_cu *cu;
1695 struct abbrev_info *abbrev;
1696 unsigned int bytes_read;
1697 struct cleanup *back_to;
1699 info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset;
1700 beg_of_comp_unit = info_ptr;
1702 cu = xmalloc (sizeof (struct dwarf2_cu));
1703 memset (cu, 0, sizeof (struct dwarf2_cu));
1705 obstack_init (&cu->comp_unit_obstack);
1707 cu->objfile = objfile;
1708 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd);
1710 /* Complete the cu_header. */
1711 cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1712 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
1714 /* Read the abbrevs for this compilation unit into a table. */
1715 dwarf2_read_abbrevs (abfd, cu);
1716 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
1718 /* Read the compilation unit die. */
1719 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1720 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1721 abfd, info_ptr, cu);
1723 /* Set the language we're debugging. */
1724 set_cu_language (comp_unit_die.language, cu);
1726 /* Link this compilation unit into the compilation unit tree. */
1728 cu->per_cu = this_cu;
1729 cu->type_hash = cu->per_cu->type_hash;
1731 /* Check if comp unit has_children.
1732 If so, read the rest of the partial symbols from this comp unit.
1733 If not, there's no more debug_info for this comp unit. */
1734 if (comp_unit_die.has_children)
1735 load_partial_dies (abfd, info_ptr, 0, cu);
1737 do_cleanups (back_to);
1740 /* Create a list of all compilation units in OBJFILE. We do this only
1741 if an inter-comp-unit reference is found; presumably if there is one,
1742 there will be many, and one will occur early in the .debug_info section.
1743 So there's no point in building this list incrementally. */
1746 create_all_comp_units (struct objfile *objfile)
1750 struct dwarf2_per_cu_data **all_comp_units;
1751 gdb_byte *info_ptr = dwarf2_per_objfile->info_buffer;
1755 all_comp_units = xmalloc (n_allocated
1756 * sizeof (struct dwarf2_per_cu_data *));
1758 while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1760 unsigned int length, initial_length_size;
1761 gdb_byte *beg_of_comp_unit;
1762 struct dwarf2_per_cu_data *this_cu;
1763 unsigned int offset;
1765 offset = info_ptr - dwarf2_per_objfile->info_buffer;
1767 /* Read just enough information to find out where the next
1768 compilation unit is. */
1769 length = read_initial_length (objfile->obfd, info_ptr,
1770 &initial_length_size);
1772 /* Save the compilation unit for later lookup. */
1773 this_cu = obstack_alloc (&objfile->objfile_obstack,
1774 sizeof (struct dwarf2_per_cu_data));
1775 memset (this_cu, 0, sizeof (*this_cu));
1776 this_cu->offset = offset;
1777 this_cu->length = length + initial_length_size;
1779 if (n_comp_units == n_allocated)
1782 all_comp_units = xrealloc (all_comp_units,
1784 * sizeof (struct dwarf2_per_cu_data *));
1786 all_comp_units[n_comp_units++] = this_cu;
1788 info_ptr = info_ptr + this_cu->length;
1791 dwarf2_per_objfile->all_comp_units
1792 = obstack_alloc (&objfile->objfile_obstack,
1793 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1794 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
1795 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
1796 xfree (all_comp_units);
1797 dwarf2_per_objfile->n_comp_units = n_comp_units;
1800 /* Process all loaded DIEs for compilation unit CU, starting at
1801 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1802 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1803 DW_AT_ranges). If NEED_PC is set, then this function will set
1804 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1805 and record the covered ranges in the addrmap. */
1808 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1809 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
1811 struct objfile *objfile = cu->objfile;
1812 bfd *abfd = objfile->obfd;
1813 struct partial_die_info *pdi;
1815 /* Now, march along the PDI's, descending into ones which have
1816 interesting children but skipping the children of the other ones,
1817 until we reach the end of the compilation unit. */
1823 fixup_partial_die (pdi, cu);
1825 /* Anonymous namespaces have no name but have interesting
1826 children, so we need to look at them. Ditto for anonymous
1829 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1830 || pdi->tag == DW_TAG_enumeration_type)
1834 case DW_TAG_subprogram:
1835 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
1837 case DW_TAG_variable:
1838 case DW_TAG_typedef:
1839 case DW_TAG_union_type:
1840 if (!pdi->is_declaration)
1842 add_partial_symbol (pdi, cu);
1845 case DW_TAG_class_type:
1846 case DW_TAG_interface_type:
1847 case DW_TAG_structure_type:
1848 if (!pdi->is_declaration)
1850 add_partial_symbol (pdi, cu);
1853 case DW_TAG_enumeration_type:
1854 if (!pdi->is_declaration)
1855 add_partial_enumeration (pdi, cu);
1857 case DW_TAG_base_type:
1858 case DW_TAG_subrange_type:
1859 /* File scope base type definitions are added to the partial
1861 add_partial_symbol (pdi, cu);
1863 case DW_TAG_namespace:
1864 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
1867 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
1874 /* If the die has a sibling, skip to the sibling. */
1876 pdi = pdi->die_sibling;
1880 /* Functions used to compute the fully scoped name of a partial DIE.
1882 Normally, this is simple. For C++, the parent DIE's fully scoped
1883 name is concatenated with "::" and the partial DIE's name. For
1884 Java, the same thing occurs except that "." is used instead of "::".
1885 Enumerators are an exception; they use the scope of their parent
1886 enumeration type, i.e. the name of the enumeration type is not
1887 prepended to the enumerator.
1889 There are two complexities. One is DW_AT_specification; in this
1890 case "parent" means the parent of the target of the specification,
1891 instead of the direct parent of the DIE. The other is compilers
1892 which do not emit DW_TAG_namespace; in this case we try to guess
1893 the fully qualified name of structure types from their members'
1894 linkage names. This must be done using the DIE's children rather
1895 than the children of any DW_AT_specification target. We only need
1896 to do this for structures at the top level, i.e. if the target of
1897 any DW_AT_specification (if any; otherwise the DIE itself) does not
1900 /* Compute the scope prefix associated with PDI's parent, in
1901 compilation unit CU. The result will be allocated on CU's
1902 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1903 field. NULL is returned if no prefix is necessary. */
1905 partial_die_parent_scope (struct partial_die_info *pdi,
1906 struct dwarf2_cu *cu)
1908 char *grandparent_scope;
1909 struct partial_die_info *parent, *real_pdi;
1911 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1912 then this means the parent of the specification DIE. */
1915 while (real_pdi->has_specification)
1916 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
1918 parent = real_pdi->die_parent;
1922 if (parent->scope_set)
1923 return parent->scope;
1925 fixup_partial_die (parent, cu);
1927 grandparent_scope = partial_die_parent_scope (parent, cu);
1929 if (parent->tag == DW_TAG_namespace
1930 || parent->tag == DW_TAG_structure_type
1931 || parent->tag == DW_TAG_class_type
1932 || parent->tag == DW_TAG_interface_type
1933 || parent->tag == DW_TAG_union_type)
1935 if (grandparent_scope == NULL)
1936 parent->scope = parent->name;
1938 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
1941 else if (parent->tag == DW_TAG_enumeration_type)
1942 /* Enumerators should not get the name of the enumeration as a prefix. */
1943 parent->scope = grandparent_scope;
1946 /* FIXME drow/2004-04-01: What should we be doing with
1947 function-local names? For partial symbols, we should probably be
1949 complaint (&symfile_complaints,
1950 _("unhandled containing DIE tag %d for DIE at %d"),
1951 parent->tag, pdi->offset);
1952 parent->scope = grandparent_scope;
1955 parent->scope_set = 1;
1956 return parent->scope;
1959 /* Return the fully scoped name associated with PDI, from compilation unit
1960 CU. The result will be allocated with malloc. */
1962 partial_die_full_name (struct partial_die_info *pdi,
1963 struct dwarf2_cu *cu)
1967 parent_scope = partial_die_parent_scope (pdi, cu);
1968 if (parent_scope == NULL)
1971 return typename_concat (NULL, parent_scope, pdi->name, cu);
1975 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1977 struct objfile *objfile = cu->objfile;
1979 char *actual_name = NULL;
1980 const char *my_prefix;
1981 const struct partial_symbol *psym = NULL;
1983 int built_actual_name = 0;
1985 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1987 if (pdi_needs_namespace (pdi->tag))
1989 actual_name = partial_die_full_name (pdi, cu);
1991 built_actual_name = 1;
1994 if (actual_name == NULL)
1995 actual_name = pdi->name;
1999 case DW_TAG_subprogram:
2000 if (pdi->is_external || cu->language == language_ada)
2002 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2003 of the global scope. But in Ada, we want to be able to access
2004 nested procedures globally. So all Ada subprograms are stored
2005 in the global scope. */
2006 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2007 mst_text, objfile); */
2008 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2009 VAR_DOMAIN, LOC_BLOCK,
2010 &objfile->global_psymbols,
2011 0, pdi->lowpc + baseaddr,
2012 cu->language, objfile);
2016 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2017 mst_file_text, objfile); */
2018 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2019 VAR_DOMAIN, LOC_BLOCK,
2020 &objfile->static_psymbols,
2021 0, pdi->lowpc + baseaddr,
2022 cu->language, objfile);
2025 case DW_TAG_variable:
2026 if (pdi->is_external)
2029 Don't enter into the minimal symbol tables as there is
2030 a minimal symbol table entry from the ELF symbols already.
2031 Enter into partial symbol table if it has a location
2032 descriptor or a type.
2033 If the location descriptor is missing, new_symbol will create
2034 a LOC_UNRESOLVED symbol, the address of the variable will then
2035 be determined from the minimal symbol table whenever the variable
2037 The address for the partial symbol table entry is not
2038 used by GDB, but it comes in handy for debugging partial symbol
2042 addr = decode_locdesc (pdi->locdesc, cu);
2043 if (pdi->locdesc || pdi->has_type)
2044 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2045 VAR_DOMAIN, LOC_STATIC,
2046 &objfile->global_psymbols,
2048 cu->language, objfile);
2052 /* Static Variable. Skip symbols without location descriptors. */
2053 if (pdi->locdesc == NULL)
2055 if (built_actual_name)
2056 xfree (actual_name);
2059 addr = decode_locdesc (pdi->locdesc, cu);
2060 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2061 mst_file_data, objfile); */
2062 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
2063 VAR_DOMAIN, LOC_STATIC,
2064 &objfile->static_psymbols,
2066 cu->language, objfile);
2069 case DW_TAG_typedef:
2070 case DW_TAG_base_type:
2071 case DW_TAG_subrange_type:
2072 add_psymbol_to_list (actual_name, strlen (actual_name),
2073 VAR_DOMAIN, LOC_TYPEDEF,
2074 &objfile->static_psymbols,
2075 0, (CORE_ADDR) 0, cu->language, objfile);
2077 case DW_TAG_namespace:
2078 add_psymbol_to_list (actual_name, strlen (actual_name),
2079 VAR_DOMAIN, LOC_TYPEDEF,
2080 &objfile->global_psymbols,
2081 0, (CORE_ADDR) 0, cu->language, objfile);
2083 case DW_TAG_class_type:
2084 case DW_TAG_interface_type:
2085 case DW_TAG_structure_type:
2086 case DW_TAG_union_type:
2087 case DW_TAG_enumeration_type:
2088 /* Skip external references. The DWARF standard says in the section
2089 about "Structure, Union, and Class Type Entries": "An incomplete
2090 structure, union or class type is represented by a structure,
2091 union or class entry that does not have a byte size attribute
2092 and that has a DW_AT_declaration attribute." */
2093 if (!pdi->has_byte_size && pdi->is_declaration)
2095 if (built_actual_name)
2096 xfree (actual_name);
2100 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2101 static vs. global. */
2102 add_psymbol_to_list (actual_name, strlen (actual_name),
2103 STRUCT_DOMAIN, LOC_TYPEDEF,
2104 (cu->language == language_cplus
2105 || cu->language == language_java)
2106 ? &objfile->global_psymbols
2107 : &objfile->static_psymbols,
2108 0, (CORE_ADDR) 0, cu->language, objfile);
2111 case DW_TAG_enumerator:
2112 add_psymbol_to_list (actual_name, strlen (actual_name),
2113 VAR_DOMAIN, LOC_CONST,
2114 (cu->language == language_cplus
2115 || cu->language == language_java)
2116 ? &objfile->global_psymbols
2117 : &objfile->static_psymbols,
2118 0, (CORE_ADDR) 0, cu->language, objfile);
2124 /* Check to see if we should scan the name for possible namespace
2125 info. Only do this if this is C++, if we don't have namespace
2126 debugging info in the file, if the psym is of an appropriate type
2127 (otherwise we'll have psym == NULL), and if we actually had a
2128 mangled name to begin with. */
2130 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2131 cases which do not set PSYM above? */
2133 if (cu->language == language_cplus
2134 && cu->has_namespace_info == 0
2136 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
2137 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
2140 if (built_actual_name)
2141 xfree (actual_name);
2144 /* Determine whether a die of type TAG living in a C++ class or
2145 namespace needs to have the name of the scope prepended to the
2146 name listed in the die. */
2149 pdi_needs_namespace (enum dwarf_tag tag)
2153 case DW_TAG_namespace:
2154 case DW_TAG_typedef:
2155 case DW_TAG_class_type:
2156 case DW_TAG_interface_type:
2157 case DW_TAG_structure_type:
2158 case DW_TAG_union_type:
2159 case DW_TAG_enumeration_type:
2160 case DW_TAG_enumerator:
2167 /* Read a partial die corresponding to a namespace; also, add a symbol
2168 corresponding to that namespace to the symbol table. NAMESPACE is
2169 the name of the enclosing namespace. */
2172 add_partial_namespace (struct partial_die_info *pdi,
2173 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2174 int need_pc, struct dwarf2_cu *cu)
2176 struct objfile *objfile = cu->objfile;
2178 /* Add a symbol for the namespace. */
2180 add_partial_symbol (pdi, cu);
2182 /* Now scan partial symbols in that namespace. */
2184 if (pdi->has_children)
2185 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2188 /* Read a partial die corresponding to a Fortran module. */
2191 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
2192 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
2194 /* Now scan partial symbols in that module.
2196 FIXME: Support the separate Fortran module namespaces. */
2198 if (pdi->has_children)
2199 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
2202 /* Read a partial die corresponding to a subprogram and create a partial
2203 symbol for that subprogram. When the CU language allows it, this
2204 routine also defines a partial symbol for each nested subprogram
2205 that this subprogram contains.
2207 DIE my also be a lexical block, in which case we simply search
2208 recursively for suprograms defined inside that lexical block.
2209 Again, this is only performed when the CU language allows this
2210 type of definitions. */
2213 add_partial_subprogram (struct partial_die_info *pdi,
2214 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2215 int need_pc, struct dwarf2_cu *cu)
2217 if (pdi->tag == DW_TAG_subprogram)
2219 if (pdi->has_pc_info)
2221 if (pdi->lowpc < *lowpc)
2222 *lowpc = pdi->lowpc;
2223 if (pdi->highpc > *highpc)
2224 *highpc = pdi->highpc;
2228 struct objfile *objfile = cu->objfile;
2230 baseaddr = ANOFFSET (objfile->section_offsets,
2231 SECT_OFF_TEXT (objfile));
2232 addrmap_set_empty (objfile->psymtabs_addrmap,
2233 pdi->lowpc, pdi->highpc - 1,
2234 cu->per_cu->psymtab);
2236 if (!pdi->is_declaration)
2237 add_partial_symbol (pdi, cu);
2241 if (! pdi->has_children)
2244 if (cu->language == language_ada)
2246 pdi = pdi->die_child;
2249 fixup_partial_die (pdi, cu);
2250 if (pdi->tag == DW_TAG_subprogram
2251 || pdi->tag == DW_TAG_lexical_block)
2252 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
2253 pdi = pdi->die_sibling;
2258 /* See if we can figure out if the class lives in a namespace. We do
2259 this by looking for a member function; its demangled name will
2260 contain namespace info, if there is any. */
2263 guess_structure_name (struct partial_die_info *struct_pdi,
2264 struct dwarf2_cu *cu)
2266 if ((cu->language == language_cplus
2267 || cu->language == language_java)
2268 && cu->has_namespace_info == 0
2269 && struct_pdi->has_children)
2271 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2272 what template types look like, because the demangler
2273 frequently doesn't give the same name as the debug info. We
2274 could fix this by only using the demangled name to get the
2275 prefix (but see comment in read_structure_type). */
2277 struct partial_die_info *child_pdi = struct_pdi->die_child;
2278 struct partial_die_info *real_pdi;
2280 /* If this DIE (this DIE's specification, if any) has a parent, then
2281 we should not do this. We'll prepend the parent's fully qualified
2282 name when we create the partial symbol. */
2284 real_pdi = struct_pdi;
2285 while (real_pdi->has_specification)
2286 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2288 if (real_pdi->die_parent != NULL)
2291 while (child_pdi != NULL)
2293 if (child_pdi->tag == DW_TAG_subprogram)
2295 char *actual_class_name
2296 = language_class_name_from_physname (cu->language_defn,
2298 if (actual_class_name != NULL)
2301 = obsavestring (actual_class_name,
2302 strlen (actual_class_name),
2303 &cu->comp_unit_obstack);
2304 xfree (actual_class_name);
2309 child_pdi = child_pdi->die_sibling;
2314 /* Read a partial die corresponding to an enumeration type. */
2317 add_partial_enumeration (struct partial_die_info *enum_pdi,
2318 struct dwarf2_cu *cu)
2320 struct objfile *objfile = cu->objfile;
2321 bfd *abfd = objfile->obfd;
2322 struct partial_die_info *pdi;
2324 if (enum_pdi->name != NULL)
2325 add_partial_symbol (enum_pdi, cu);
2327 pdi = enum_pdi->die_child;
2330 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
2331 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
2333 add_partial_symbol (pdi, cu);
2334 pdi = pdi->die_sibling;
2338 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2339 Return the corresponding abbrev, or NULL if the number is zero (indicating
2340 an empty DIE). In either case *BYTES_READ will be set to the length of
2341 the initial number. */
2343 static struct abbrev_info *
2344 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
2345 struct dwarf2_cu *cu)
2347 bfd *abfd = cu->objfile->obfd;
2348 unsigned int abbrev_number;
2349 struct abbrev_info *abbrev;
2351 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
2353 if (abbrev_number == 0)
2356 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
2359 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number,
2360 bfd_get_filename (abfd));
2366 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2367 pointer to the end of a series of DIEs, terminated by an empty
2368 DIE. Any children of the skipped DIEs will also be skipped. */
2371 skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu)
2373 struct abbrev_info *abbrev;
2374 unsigned int bytes_read;
2378 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
2380 return info_ptr + bytes_read;
2382 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
2386 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2387 should point just after the initial uleb128 of a DIE, and the
2388 abbrev corresponding to that skipped uleb128 should be passed in
2389 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2393 skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev,
2394 struct dwarf2_cu *cu)
2396 unsigned int bytes_read;
2397 struct attribute attr;
2398 bfd *abfd = cu->objfile->obfd;
2399 unsigned int form, i;
2401 for (i = 0; i < abbrev->num_attrs; i++)
2403 /* The only abbrev we care about is DW_AT_sibling. */
2404 if (abbrev->attrs[i].name == DW_AT_sibling)
2406 read_attribute (&attr, &abbrev->attrs[i],
2407 abfd, info_ptr, cu);
2408 if (attr.form == DW_FORM_ref_addr)
2409 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
2411 return dwarf2_per_objfile->info_buffer
2412 + dwarf2_get_ref_die_offset (&attr);
2415 /* If it isn't DW_AT_sibling, skip this attribute. */
2416 form = abbrev->attrs[i].form;
2421 case DW_FORM_ref_addr:
2422 info_ptr += cu->header.addr_size;
2441 case DW_FORM_string:
2442 read_string (abfd, info_ptr, &bytes_read);
2443 info_ptr += bytes_read;
2446 info_ptr += cu->header.offset_size;
2449 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2450 info_ptr += bytes_read;
2452 case DW_FORM_block1:
2453 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2455 case DW_FORM_block2:
2456 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2458 case DW_FORM_block4:
2459 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2463 case DW_FORM_ref_udata:
2464 info_ptr = skip_leb128 (abfd, info_ptr);
2466 case DW_FORM_indirect:
2467 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2468 info_ptr += bytes_read;
2469 /* We need to continue parsing from here, so just go back to
2471 goto skip_attribute;
2474 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2475 dwarf_form_name (form),
2476 bfd_get_filename (abfd));
2480 if (abbrev->has_children)
2481 return skip_children (info_ptr, cu);
2486 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2487 the next DIE after ORIG_PDI. */
2490 locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr,
2491 bfd *abfd, struct dwarf2_cu *cu)
2493 /* Do we know the sibling already? */
2495 if (orig_pdi->sibling)
2496 return orig_pdi->sibling;
2498 /* Are there any children to deal with? */
2500 if (!orig_pdi->has_children)
2503 /* Skip the children the long way. */
2505 return skip_children (info_ptr, cu);
2508 /* Expand this partial symbol table into a full symbol table. */
2511 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2513 /* FIXME: This is barely more than a stub. */
2518 warning (_("bug: psymtab for %s is already read in."), pst->filename);
2524 printf_filtered (_("Reading in symbols for %s..."), pst->filename);
2525 gdb_flush (gdb_stdout);
2528 /* Restore our global data. */
2529 dwarf2_per_objfile = objfile_data (pst->objfile,
2530 dwarf2_objfile_data_key);
2532 psymtab_to_symtab_1 (pst);
2534 /* Finish up the debug error message. */
2536 printf_filtered (_("done.\n"));
2541 /* Add PER_CU to the queue. */
2544 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2546 struct dwarf2_queue_item *item;
2549 item = xmalloc (sizeof (*item));
2550 item->per_cu = per_cu;
2553 if (dwarf2_queue == NULL)
2554 dwarf2_queue = item;
2556 dwarf2_queue_tail->next = item;
2558 dwarf2_queue_tail = item;
2560 /* Either PER_CU is the CU we want to process, or we're following a reference
2561 pointing into PER_CU. Either way, we need its DIEs now. */
2562 load_full_comp_unit (item->per_cu, objfile);
2563 item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
2564 dwarf2_per_objfile->read_in_chain = item->per_cu;
2567 /* Process the queue. */
2570 process_queue (struct objfile *objfile)
2572 struct dwarf2_queue_item *item, *next_item;
2574 /* The queue starts out with one item, but following a DIE reference
2575 may load a new CU, adding it to the end of the queue. */
2576 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
2578 if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
2579 process_full_comp_unit (item->per_cu);
2581 item->per_cu->queued = 0;
2582 next_item = item->next;
2586 dwarf2_queue_tail = NULL;
2589 /* Free all allocated queue entries. This function only releases anything if
2590 an error was thrown; if the queue was processed then it would have been
2591 freed as we went along. */
2594 dwarf2_release_queue (void *dummy)
2596 struct dwarf2_queue_item *item, *last;
2598 item = dwarf2_queue;
2601 /* Anything still marked queued is likely to be in an
2602 inconsistent state, so discard it. */
2603 if (item->per_cu->queued)
2605 if (item->per_cu->cu != NULL)
2606 free_one_cached_comp_unit (item->per_cu->cu);
2607 item->per_cu->queued = 0;
2615 dwarf2_queue = dwarf2_queue_tail = NULL;
2618 /* Read in full symbols for PST, and anything it depends on. */
2621 psymtab_to_symtab_1 (struct partial_symtab *pst)
2623 struct dwarf2_per_cu_data *per_cu;
2624 struct cleanup *back_to;
2627 for (i = 0; i < pst->number_of_dependencies; i++)
2628 if (!pst->dependencies[i]->readin)
2630 /* Inform about additional files that need to be read in. */
2633 /* FIXME: i18n: Need to make this a single string. */
2634 fputs_filtered (" ", gdb_stdout);
2636 fputs_filtered ("and ", gdb_stdout);
2638 printf_filtered ("%s...", pst->dependencies[i]->filename);
2639 wrap_here (""); /* Flush output */
2640 gdb_flush (gdb_stdout);
2642 psymtab_to_symtab_1 (pst->dependencies[i]);
2645 per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private;
2649 /* It's an include file, no symbols to read for it.
2650 Everything is in the parent symtab. */
2655 back_to = make_cleanup (dwarf2_release_queue, NULL);
2657 queue_comp_unit (per_cu, pst->objfile);
2659 process_queue (pst->objfile);
2661 /* Age the cache, releasing compilation units that have not
2662 been used recently. */
2663 age_cached_comp_units ();
2665 do_cleanups (back_to);
2668 /* Load the DIEs associated with PST and PER_CU into memory. */
2670 static struct dwarf2_cu *
2671 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
2673 bfd *abfd = objfile->obfd;
2674 struct dwarf2_cu *cu;
2675 unsigned int offset;
2677 struct cleanup *back_to, *free_cu_cleanup;
2678 struct attribute *attr;
2681 /* Set local variables from the partial symbol table info. */
2682 offset = per_cu->offset;
2684 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2686 cu = xmalloc (sizeof (struct dwarf2_cu));
2687 memset (cu, 0, sizeof (struct dwarf2_cu));
2689 /* If an error occurs while loading, release our storage. */
2690 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
2692 cu->objfile = objfile;
2694 /* read in the comp_unit header */
2695 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
2697 /* Read the abbrevs for this compilation unit */
2698 dwarf2_read_abbrevs (abfd, cu);
2699 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
2701 cu->header.offset = offset;
2703 cu->per_cu = per_cu;
2705 cu->type_hash = per_cu->type_hash;
2707 /* We use this obstack for block values in dwarf_alloc_block. */
2708 obstack_init (&cu->comp_unit_obstack);
2710 cu->dies = read_comp_unit (info_ptr, abfd, cu);
2712 /* We try not to read any attributes in this function, because not
2713 all objfiles needed for references have been loaded yet, and symbol
2714 table processing isn't initialized. But we have to set the CU language,
2715 or we won't be able to build types correctly. */
2716 attr = dwarf2_attr (cu->dies, DW_AT_language, cu);
2718 set_cu_language (DW_UNSND (attr), cu);
2720 set_cu_language (language_minimal, cu);
2722 do_cleanups (back_to);
2724 /* We've successfully allocated this compilation unit. Let our caller
2725 clean it up when finished with it. */
2726 discard_cleanups (free_cu_cleanup);
2731 /* Generate full symbol information for PST and CU, whose DIEs have
2732 already been loaded into memory. */
2735 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
2737 struct partial_symtab *pst = per_cu->psymtab;
2738 struct dwarf2_cu *cu = per_cu->cu;
2739 struct objfile *objfile = pst->objfile;
2740 bfd *abfd = objfile->obfd;
2741 CORE_ADDR lowpc, highpc;
2742 struct symtab *symtab;
2743 struct cleanup *back_to;
2744 struct attribute *attr;
2747 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2750 back_to = make_cleanup (really_free_pendings, NULL);
2752 cu->list_in_scope = &file_symbols;
2754 /* Find the base address of the compilation unit for range lists and
2755 location lists. It will normally be specified by DW_AT_low_pc.
2756 In DWARF-3 draft 4, the base address could be overridden by
2757 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2758 compilation units with discontinuous ranges. */
2761 cu->base_address = 0;
2763 attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu);
2766 cu->base_address = DW_ADDR (attr);
2771 attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu);
2774 cu->base_address = DW_ADDR (attr);
2779 /* Do line number decoding in read_file_scope () */
2780 process_die (cu->dies, cu);
2782 /* Some compilers don't define a DW_AT_high_pc attribute for the
2783 compilation unit. If the DW_AT_high_pc is missing, synthesize
2784 it, by scanning the DIE's below the compilation unit. */
2785 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
2787 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2789 /* Set symtab language to language from DW_AT_language.
2790 If the compilation is from a C file generated by language preprocessors,
2791 do not set the language if it was already deduced by start_subfile. */
2793 && !(cu->language == language_c && symtab->language != language_c))
2795 symtab->language = cu->language;
2797 pst->symtab = symtab;
2800 do_cleanups (back_to);
2803 /* Process a die and its children. */
2806 process_die (struct die_info *die, struct dwarf2_cu *cu)
2810 case DW_TAG_padding:
2812 case DW_TAG_compile_unit:
2813 read_file_scope (die, cu);
2815 case DW_TAG_subprogram:
2816 read_func_scope (die, cu);
2818 case DW_TAG_inlined_subroutine:
2819 /* FIXME: These are ignored for now.
2820 They could be used to set breakpoints on all inlined instances
2821 of a function and make GDB `next' properly over inlined functions. */
2823 case DW_TAG_lexical_block:
2824 case DW_TAG_try_block:
2825 case DW_TAG_catch_block:
2826 read_lexical_block_scope (die, cu);
2828 case DW_TAG_class_type:
2829 case DW_TAG_interface_type:
2830 case DW_TAG_structure_type:
2831 case DW_TAG_union_type:
2832 process_structure_scope (die, cu);
2834 case DW_TAG_enumeration_type:
2835 process_enumeration_scope (die, cu);
2838 /* These dies have a type, but processing them does not create
2839 a symbol or recurse to process the children. Therefore we can
2840 read them on-demand through read_type_die. */
2841 case DW_TAG_subroutine_type:
2842 case DW_TAG_set_type:
2843 case DW_TAG_array_type:
2844 case DW_TAG_pointer_type:
2845 case DW_TAG_ptr_to_member_type:
2846 case DW_TAG_reference_type:
2847 case DW_TAG_string_type:
2850 case DW_TAG_base_type:
2851 case DW_TAG_subrange_type:
2852 case DW_TAG_typedef:
2853 /* Add a typedef symbol for the type definition, if it has a
2855 new_symbol (die, read_type_die (die, cu), cu);
2857 case DW_TAG_common_block:
2858 read_common_block (die, cu);
2860 case DW_TAG_common_inclusion:
2862 case DW_TAG_namespace:
2863 processing_has_namespace_info = 1;
2864 read_namespace (die, cu);
2867 read_module (die, cu);
2869 case DW_TAG_imported_declaration:
2870 case DW_TAG_imported_module:
2871 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2872 information contained in these. DW_TAG_imported_declaration
2873 dies shouldn't have children; DW_TAG_imported_module dies
2874 shouldn't in the C++ case, but conceivably could in the
2876 processing_has_namespace_info = 1;
2877 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
2878 dwarf_tag_name (die->tag));
2881 new_symbol (die, NULL, cu);
2886 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2887 If scope qualifiers are appropriate they will be added. The result
2888 will be allocated on the objfile_obstack, or NULL if the DIE does
2892 dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
2894 struct attribute *attr;
2895 char *prefix, *name;
2896 struct ui_file *buf = NULL;
2898 name = dwarf2_name (die, cu);
2902 /* These are the only languages we know how to qualify names in. */
2903 if (cu->language != language_cplus
2904 && cu->language != language_java)
2907 /* If no prefix is necessary for this type of DIE, return the
2908 unqualified name. The other three tags listed could be handled
2909 in pdi_needs_namespace, but that requires broader changes. */
2910 if (!pdi_needs_namespace (die->tag)
2911 && die->tag != DW_TAG_subprogram
2912 && die->tag != DW_TAG_variable
2913 && die->tag != DW_TAG_member)
2916 prefix = determine_prefix (die, cu);
2917 if (*prefix != '\0')
2918 name = typename_concat (&cu->objfile->objfile_obstack, prefix,
2925 initialize_cu_func_list (struct dwarf2_cu *cu)
2927 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2931 free_cu_line_header (void *arg)
2933 struct dwarf2_cu *cu = arg;
2935 free_line_header (cu->line_header);
2936 cu->line_header = NULL;
2940 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2942 struct objfile *objfile = cu->objfile;
2943 struct comp_unit_head *cu_header = &cu->header;
2944 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2945 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2946 CORE_ADDR highpc = ((CORE_ADDR) 0);
2947 struct attribute *attr;
2949 char *comp_dir = NULL;
2950 struct die_info *child_die;
2951 bfd *abfd = objfile->obfd;
2952 struct line_header *line_header = 0;
2955 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2957 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2959 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2960 from finish_block. */
2961 if (lowpc == ((CORE_ADDR) -1))
2966 /* Find the filename. Do not use dwarf2_name here, since the filename
2967 is not a source language identifier. */
2968 attr = dwarf2_attr (die, DW_AT_name, cu);
2971 name = DW_STRING (attr);
2974 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2976 comp_dir = DW_STRING (attr);
2977 else if (name != NULL && IS_ABSOLUTE_PATH (name))
2979 comp_dir = ldirname (name);
2980 if (comp_dir != NULL)
2981 make_cleanup (xfree, comp_dir);
2983 if (comp_dir != NULL)
2985 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2986 directory, get rid of it. */
2987 char *cp = strchr (comp_dir, ':');
2989 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2996 attr = dwarf2_attr (die, DW_AT_language, cu);
2999 set_cu_language (DW_UNSND (attr), cu);
3002 attr = dwarf2_attr (die, DW_AT_producer, cu);
3004 cu->producer = DW_STRING (attr);
3006 /* We assume that we're processing GCC output. */
3007 processing_gcc_compilation = 2;
3009 processing_has_namespace_info = 0;
3011 start_symtab (name, comp_dir, lowpc);
3012 record_debugformat ("DWARF 2");
3013 record_producer (cu->producer);
3015 initialize_cu_func_list (cu);
3017 /* Decode line number information if present. We do this before
3018 processing child DIEs, so that the line header table is available
3019 for DW_AT_decl_file. */
3020 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3023 unsigned int line_offset = DW_UNSND (attr);
3024 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
3027 cu->line_header = line_header;
3028 make_cleanup (free_cu_line_header, cu);
3029 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
3033 /* Process all dies in compilation unit. */
3034 if (die->child != NULL)
3036 child_die = die->child;
3037 while (child_die && child_die->tag)
3039 process_die (child_die, cu);
3040 child_die = sibling_die (child_die);
3044 /* Decode macro information, if present. Dwarf 2 macro information
3045 refers to information in the line number info statement program
3046 header, so we can only read it if we've read the header
3048 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
3049 if (attr && line_header)
3051 unsigned int macro_offset = DW_UNSND (attr);
3052 dwarf_decode_macros (line_header, macro_offset,
3053 comp_dir, abfd, cu);
3055 do_cleanups (back_to);
3059 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
3060 struct dwarf2_cu *cu)
3062 struct function_range *thisfn;
3064 thisfn = (struct function_range *)
3065 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
3066 thisfn->name = name;
3067 thisfn->lowpc = lowpc;
3068 thisfn->highpc = highpc;
3069 thisfn->seen_line = 0;
3070 thisfn->next = NULL;
3072 if (cu->last_fn == NULL)
3073 cu->first_fn = thisfn;
3075 cu->last_fn->next = thisfn;
3077 cu->last_fn = thisfn;
3081 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
3083 struct objfile *objfile = cu->objfile;
3084 struct context_stack *new;
3087 struct die_info *child_die;
3088 struct attribute *attr;
3091 struct block *block;
3093 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3095 name = dwarf2_linkage_name (die, cu);
3097 /* Ignore functions with missing or empty names and functions with
3098 missing or invalid low and high pc attributes. */
3099 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
3105 /* Record the function range for dwarf_decode_lines. */
3106 add_to_cu_func_list (name, lowpc, highpc, cu);
3108 new = push_context (0, lowpc);
3109 new->name = new_symbol (die, read_type_die (die, cu), cu);
3111 /* If there is a location expression for DW_AT_frame_base, record
3113 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
3115 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3116 expression is being recorded directly in the function's symbol
3117 and not in a separate frame-base object. I guess this hack is
3118 to avoid adding some sort of frame-base adjunct/annex to the
3119 function's symbol :-(. The problem with doing this is that it
3120 results in a function symbol with a location expression that
3121 has nothing to do with the location of the function, ouch! The
3122 relationship should be: a function's symbol has-a frame base; a
3123 frame-base has-a location expression. */
3124 dwarf2_symbol_mark_computed (attr, new->name, cu);
3126 cu->list_in_scope = &local_symbols;
3128 if (die->child != NULL)
3130 child_die = die->child;
3131 while (child_die && child_die->tag)
3133 process_die (child_die, cu);
3134 child_die = sibling_die (child_die);
3138 new = pop_context ();
3139 /* Make a block for the local symbols within. */
3140 block = finish_block (new->name, &local_symbols, new->old_blocks,
3141 lowpc, highpc, objfile);
3143 /* For C++, set the block's scope. */
3144 if (cu->language == language_cplus)
3145 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
3146 determine_prefix (die, cu),
3147 processing_has_namespace_info);
3149 /* If we have address ranges, record them. */
3150 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3152 /* In C++, we can have functions nested inside functions (e.g., when
3153 a function declares a class that has methods). This means that
3154 when we finish processing a function scope, we may need to go
3155 back to building a containing block's symbol lists. */
3156 local_symbols = new->locals;
3157 param_symbols = new->params;
3159 /* If we've finished processing a top-level function, subsequent
3160 symbols go in the file symbol list. */
3161 if (outermost_context_p ())
3162 cu->list_in_scope = &file_symbols;
3165 /* Process all the DIES contained within a lexical block scope. Start
3166 a new scope, process the dies, and then close the scope. */
3169 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
3171 struct objfile *objfile = cu->objfile;
3172 struct context_stack *new;
3173 CORE_ADDR lowpc, highpc;
3174 struct die_info *child_die;
3177 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3179 /* Ignore blocks with missing or invalid low and high pc attributes. */
3180 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3181 as multiple lexical blocks? Handling children in a sane way would
3182 be nasty. Might be easier to properly extend generic blocks to
3184 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
3189 push_context (0, lowpc);
3190 if (die->child != NULL)
3192 child_die = die->child;
3193 while (child_die && child_die->tag)
3195 process_die (child_die, cu);
3196 child_die = sibling_die (child_die);
3199 new = pop_context ();
3201 if (local_symbols != NULL)
3204 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
3207 /* Note that recording ranges after traversing children, as we
3208 do here, means that recording a parent's ranges entails
3209 walking across all its children's ranges as they appear in
3210 the address map, which is quadratic behavior.
3212 It would be nicer to record the parent's ranges before
3213 traversing its children, simply overriding whatever you find
3214 there. But since we don't even decide whether to create a
3215 block until after we've traversed its children, that's hard
3217 dwarf2_record_block_ranges (die, block, baseaddr, cu);
3219 local_symbols = new->locals;
3222 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3223 Return 1 if the attributes are present and valid, otherwise, return 0.
3224 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3227 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
3228 CORE_ADDR *high_return, struct dwarf2_cu *cu,
3229 struct partial_symtab *ranges_pst)
3231 struct objfile *objfile = cu->objfile;
3232 struct comp_unit_head *cu_header = &cu->header;
3233 bfd *obfd = objfile->obfd;
3234 unsigned int addr_size = cu_header->addr_size;
3235 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3236 /* Base address selection entry. */
3247 found_base = cu->base_known;
3248 base = cu->base_address;
3250 if (offset >= dwarf2_per_objfile->ranges_size)
3252 complaint (&symfile_complaints,
3253 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3257 buffer = dwarf2_per_objfile->ranges_buffer + offset;
3259 /* Read in the largest possible address. */
3260 marker = read_address (obfd, buffer, cu, &dummy);
3261 if ((marker & mask) == mask)
3263 /* If we found the largest possible address, then
3264 read the base address. */
3265 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3266 buffer += 2 * addr_size;
3267 offset += 2 * addr_size;
3273 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3277 CORE_ADDR range_beginning, range_end;
3279 range_beginning = read_address (obfd, buffer, cu, &dummy);
3280 buffer += addr_size;
3281 range_end = read_address (obfd, buffer, cu, &dummy);
3282 buffer += addr_size;
3283 offset += 2 * addr_size;
3285 /* An end of list marker is a pair of zero addresses. */
3286 if (range_beginning == 0 && range_end == 0)
3287 /* Found the end of list entry. */
3290 /* Each base address selection entry is a pair of 2 values.
3291 The first is the largest possible address, the second is
3292 the base address. Check for a base address here. */
3293 if ((range_beginning & mask) == mask)
3295 /* If we found the largest possible address, then
3296 read the base address. */
3297 base = read_address (obfd, buffer + addr_size, cu, &dummy);
3304 /* We have no valid base address for the ranges
3306 complaint (&symfile_complaints,
3307 _("Invalid .debug_ranges data (no base address)"));
3311 range_beginning += base;
3314 if (ranges_pst != NULL && range_beginning < range_end)
3315 addrmap_set_empty (objfile->psymtabs_addrmap,
3316 range_beginning + baseaddr, range_end - 1 + baseaddr,
3319 /* FIXME: This is recording everything as a low-high
3320 segment of consecutive addresses. We should have a
3321 data structure for discontiguous block ranges
3325 low = range_beginning;
3331 if (range_beginning < low)
3332 low = range_beginning;
3333 if (range_end > high)
3339 /* If the first entry is an end-of-list marker, the range
3340 describes an empty scope, i.e. no instructions. */
3346 *high_return = high;
3350 /* Get low and high pc attributes from a die. Return 1 if the attributes
3351 are present and valid, otherwise, return 0. Return -1 if the range is
3352 discontinuous, i.e. derived from DW_AT_ranges information. */
3354 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
3355 CORE_ADDR *highpc, struct dwarf2_cu *cu)
3357 struct attribute *attr;
3362 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
3365 high = DW_ADDR (attr);
3366 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3368 low = DW_ADDR (attr);
3370 /* Found high w/o low attribute. */
3373 /* Found consecutive range of addresses. */
3378 attr = dwarf2_attr (die, DW_AT_ranges, cu);
3381 /* Value of the DW_AT_ranges attribute is the offset in the
3382 .debug_ranges section. */
3383 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL))
3385 /* Found discontinuous range of addresses. */
3393 /* When using the GNU linker, .gnu.linkonce. sections are used to
3394 eliminate duplicate copies of functions and vtables and such.
3395 The linker will arbitrarily choose one and discard the others.
3396 The AT_*_pc values for such functions refer to local labels in
3397 these sections. If the section from that file was discarded, the
3398 labels are not in the output, so the relocs get a value of 0.
3399 If this is a discarded function, mark the pc bounds as invalid,
3400 so that GDB will ignore it. */
3401 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
3409 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3410 its low and high PC addresses. Do nothing if these addresses could not
3411 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3412 and HIGHPC to the high address if greater than HIGHPC. */
3415 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
3416 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3417 struct dwarf2_cu *cu)
3419 CORE_ADDR low, high;
3420 struct die_info *child = die->child;
3422 if (dwarf2_get_pc_bounds (die, &low, &high, cu))
3424 *lowpc = min (*lowpc, low);
3425 *highpc = max (*highpc, high);
3428 /* If the language does not allow nested subprograms (either inside
3429 subprograms or lexical blocks), we're done. */
3430 if (cu->language != language_ada)
3433 /* Check all the children of the given DIE. If it contains nested
3434 subprograms, then check their pc bounds. Likewise, we need to
3435 check lexical blocks as well, as they may also contain subprogram
3437 while (child && child->tag)
3439 if (child->tag == DW_TAG_subprogram
3440 || child->tag == DW_TAG_lexical_block)
3441 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
3442 child = sibling_die (child);
3446 /* Get the low and high pc's represented by the scope DIE, and store
3447 them in *LOWPC and *HIGHPC. If the correct values can't be
3448 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3451 get_scope_pc_bounds (struct die_info *die,
3452 CORE_ADDR *lowpc, CORE_ADDR *highpc,
3453 struct dwarf2_cu *cu)
3455 CORE_ADDR best_low = (CORE_ADDR) -1;
3456 CORE_ADDR best_high = (CORE_ADDR) 0;
3457 CORE_ADDR current_low, current_high;
3459 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
3461 best_low = current_low;
3462 best_high = current_high;
3466 struct die_info *child = die->child;
3468 while (child && child->tag)
3470 switch (child->tag) {
3471 case DW_TAG_subprogram:
3472 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
3474 case DW_TAG_namespace:
3475 /* FIXME: carlton/2004-01-16: Should we do this for
3476 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3477 that current GCC's always emit the DIEs corresponding
3478 to definitions of methods of classes as children of a
3479 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3480 the DIEs giving the declarations, which could be
3481 anywhere). But I don't see any reason why the
3482 standards says that they have to be there. */
3483 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
3485 if (current_low != ((CORE_ADDR) -1))
3487 best_low = min (best_low, current_low);
3488 best_high = max (best_high, current_high);
3496 child = sibling_die (child);
3501 *highpc = best_high;
3504 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3507 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
3508 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
3510 struct attribute *attr;
3512 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
3515 CORE_ADDR high = DW_ADDR (attr);
3516 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3519 CORE_ADDR low = DW_ADDR (attr);
3520 record_block_range (block, baseaddr + low, baseaddr + high - 1);
3524 attr = dwarf2_attr (die, DW_AT_ranges, cu);
3527 bfd *obfd = cu->objfile->obfd;
3529 /* The value of the DW_AT_ranges attribute is the offset of the
3530 address range list in the .debug_ranges section. */
3531 unsigned long offset = DW_UNSND (attr);
3532 gdb_byte *buffer = dwarf2_per_objfile->ranges_buffer + offset;
3534 /* For some target architectures, but not others, the
3535 read_address function sign-extends the addresses it returns.
3536 To recognize base address selection entries, we need a
3538 unsigned int addr_size = cu->header.addr_size;
3539 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3541 /* The base address, to which the next pair is relative. Note
3542 that this 'base' is a DWARF concept: most entries in a range
3543 list are relative, to reduce the number of relocs against the
3544 debugging information. This is separate from this function's
3545 'baseaddr' argument, which GDB uses to relocate debugging
3546 information from a shared library based on the address at
3547 which the library was loaded. */
3548 CORE_ADDR base = cu->base_address;
3549 int base_known = cu->base_known;
3551 if (offset >= dwarf2_per_objfile->ranges_size)
3553 complaint (&symfile_complaints,
3554 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3561 unsigned int bytes_read;
3562 CORE_ADDR start, end;
3564 start = read_address (obfd, buffer, cu, &bytes_read);
3565 buffer += bytes_read;
3566 end = read_address (obfd, buffer, cu, &bytes_read);
3567 buffer += bytes_read;
3569 /* Did we find the end of the range list? */
3570 if (start == 0 && end == 0)
3573 /* Did we find a base address selection entry? */
3574 else if ((start & base_select_mask) == base_select_mask)
3580 /* We found an ordinary address range. */
3585 complaint (&symfile_complaints,
3586 _("Invalid .debug_ranges data (no base address)"));
3590 record_block_range (block,
3591 baseaddr + base + start,
3592 baseaddr + base + end - 1);
3598 /* Add an aggregate field to the field list. */
3601 dwarf2_add_field (struct field_info *fip, struct die_info *die,
3602 struct dwarf2_cu *cu)
3604 struct objfile *objfile = cu->objfile;
3605 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3606 struct nextfield *new_field;
3607 struct attribute *attr;
3609 char *fieldname = "";
3611 /* Allocate a new field list entry and link it in. */
3612 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3613 make_cleanup (xfree, new_field);
3614 memset (new_field, 0, sizeof (struct nextfield));
3615 new_field->next = fip->fields;
3616 fip->fields = new_field;
3619 /* Handle accessibility and virtuality of field.
3620 The default accessibility for members is public, the default
3621 accessibility for inheritance is private. */
3622 if (die->tag != DW_TAG_inheritance)
3623 new_field->accessibility = DW_ACCESS_public;
3625 new_field->accessibility = DW_ACCESS_private;
3626 new_field->virtuality = DW_VIRTUALITY_none;
3628 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3630 new_field->accessibility = DW_UNSND (attr);
3631 if (new_field->accessibility != DW_ACCESS_public)
3632 fip->non_public_fields = 1;
3633 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
3635 new_field->virtuality = DW_UNSND (attr);
3637 fp = &new_field->field;
3639 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
3641 /* Data member other than a C++ static data member. */
3643 /* Get type of field. */
3644 fp->type = die_type (die, cu);
3646 SET_FIELD_BITPOS (*fp, 0);
3648 /* Get bit size of field (zero if none). */
3649 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
3652 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
3656 FIELD_BITSIZE (*fp) = 0;
3659 /* Get bit offset of field. */
3660 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3665 if (attr_form_is_section_offset (attr))
3667 dwarf2_complex_location_expr_complaint ();
3670 else if (attr_form_is_constant (attr))
3671 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
3673 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
3675 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
3677 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
3680 if (gdbarch_bits_big_endian (gdbarch))
3682 /* For big endian bits, the DW_AT_bit_offset gives the
3683 additional bit offset from the MSB of the containing
3684 anonymous object to the MSB of the field. We don't
3685 have to do anything special since we don't need to
3686 know the size of the anonymous object. */
3687 FIELD_BITPOS (*fp) += DW_UNSND (attr);
3691 /* For little endian bits, compute the bit offset to the
3692 MSB of the anonymous object, subtract off the number of
3693 bits from the MSB of the field to the MSB of the
3694 object, and then subtract off the number of bits of
3695 the field itself. The result is the bit offset of
3696 the LSB of the field. */
3698 int bit_offset = DW_UNSND (attr);
3700 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3703 /* The size of the anonymous object containing
3704 the bit field is explicit, so use the
3705 indicated size (in bytes). */
3706 anonymous_size = DW_UNSND (attr);
3710 /* The size of the anonymous object containing
3711 the bit field must be inferred from the type
3712 attribute of the data member containing the
3714 anonymous_size = TYPE_LENGTH (fp->type);
3716 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
3717 - bit_offset - FIELD_BITSIZE (*fp);
3721 /* Get name of field. */
3722 fieldname = dwarf2_name (die, cu);
3723 if (fieldname == NULL)
3726 /* The name is already allocated along with this objfile, so we don't
3727 need to duplicate it for the type. */
3728 fp->name = fieldname;
3730 /* Change accessibility for artificial fields (e.g. virtual table
3731 pointer or virtual base class pointer) to private. */
3732 if (dwarf2_attr (die, DW_AT_artificial, cu))
3734 new_field->accessibility = DW_ACCESS_private;
3735 fip->non_public_fields = 1;
3738 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
3740 /* C++ static member. */
3742 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3743 is a declaration, but all versions of G++ as of this writing
3744 (so through at least 3.2.1) incorrectly generate
3745 DW_TAG_variable tags. */
3749 /* Get name of field. */
3750 fieldname = dwarf2_name (die, cu);
3751 if (fieldname == NULL)
3754 /* Get physical name. */
3755 physname = dwarf2_linkage_name (die, cu);
3757 /* The name is already allocated along with this objfile, so we don't
3758 need to duplicate it for the type. */
3759 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
3760 FIELD_TYPE (*fp) = die_type (die, cu);
3761 FIELD_NAME (*fp) = fieldname;
3763 else if (die->tag == DW_TAG_inheritance)
3765 /* C++ base class field. */
3766 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3768 SET_FIELD_BITPOS (*fp, decode_locdesc (DW_BLOCK (attr), cu)
3770 FIELD_BITSIZE (*fp) = 0;
3771 FIELD_TYPE (*fp) = die_type (die, cu);
3772 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3773 fip->nbaseclasses++;
3777 /* Create the vector of fields, and attach it to the type. */
3780 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3781 struct dwarf2_cu *cu)
3783 int nfields = fip->nfields;
3785 /* Record the field count, allocate space for the array of fields,
3786 and create blank accessibility bitfields if necessary. */
3787 TYPE_NFIELDS (type) = nfields;
3788 TYPE_FIELDS (type) = (struct field *)
3789 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3790 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3792 if (fip->non_public_fields)
3794 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3796 TYPE_FIELD_PRIVATE_BITS (type) =
3797 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3798 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3800 TYPE_FIELD_PROTECTED_BITS (type) =
3801 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3802 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3804 TYPE_FIELD_IGNORE_BITS (type) =
3805 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3806 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3809 /* If the type has baseclasses, allocate and clear a bit vector for
3810 TYPE_FIELD_VIRTUAL_BITS. */
3811 if (fip->nbaseclasses)
3813 int num_bytes = B_BYTES (fip->nbaseclasses);
3814 unsigned char *pointer;
3816 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3817 pointer = TYPE_ALLOC (type, num_bytes);
3818 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
3819 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
3820 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
3823 /* Copy the saved-up fields into the field vector. Start from the head
3824 of the list, adding to the tail of the field array, so that they end
3825 up in the same order in the array in which they were added to the list. */
3826 while (nfields-- > 0)
3828 TYPE_FIELD (type, nfields) = fip->fields->field;
3829 switch (fip->fields->accessibility)
3831 case DW_ACCESS_private:
3832 SET_TYPE_FIELD_PRIVATE (type, nfields);
3835 case DW_ACCESS_protected:
3836 SET_TYPE_FIELD_PROTECTED (type, nfields);
3839 case DW_ACCESS_public:
3843 /* Unknown accessibility. Complain and treat it as public. */
3845 complaint (&symfile_complaints, _("unsupported accessibility %d"),
3846 fip->fields->accessibility);
3850 if (nfields < fip->nbaseclasses)
3852 switch (fip->fields->virtuality)
3854 case DW_VIRTUALITY_virtual:
3855 case DW_VIRTUALITY_pure_virtual:
3856 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3860 fip->fields = fip->fields->next;
3864 /* Add a member function to the proper fieldlist. */
3867 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3868 struct type *type, struct dwarf2_cu *cu)
3870 struct objfile *objfile = cu->objfile;
3871 struct attribute *attr;
3872 struct fnfieldlist *flp;
3874 struct fn_field *fnp;
3877 struct nextfnfield *new_fnfield;
3878 struct type *this_type;
3880 /* Get name of member function. */
3881 fieldname = dwarf2_name (die, cu);
3882 if (fieldname == NULL)
3885 /* Get the mangled name. */
3886 physname = dwarf2_linkage_name (die, cu);
3888 /* Look up member function name in fieldlist. */
3889 for (i = 0; i < fip->nfnfields; i++)
3891 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3895 /* Create new list element if necessary. */
3896 if (i < fip->nfnfields)
3897 flp = &fip->fnfieldlists[i];
3900 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3902 fip->fnfieldlists = (struct fnfieldlist *)
3903 xrealloc (fip->fnfieldlists,
3904 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3905 * sizeof (struct fnfieldlist));
3906 if (fip->nfnfields == 0)
3907 make_cleanup (free_current_contents, &fip->fnfieldlists);
3909 flp = &fip->fnfieldlists[fip->nfnfields];
3910 flp->name = fieldname;
3916 /* Create a new member function field and chain it to the field list
3918 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3919 make_cleanup (xfree, new_fnfield);
3920 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3921 new_fnfield->next = flp->head;
3922 flp->head = new_fnfield;
3925 /* Fill in the member function field info. */
3926 fnp = &new_fnfield->fnfield;
3927 /* The name is already allocated along with this objfile, so we don't
3928 need to duplicate it for the type. */
3929 fnp->physname = physname ? physname : "";
3930 fnp->type = alloc_type (objfile);
3931 this_type = read_type_die (die, cu);
3932 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
3934 int nparams = TYPE_NFIELDS (this_type);
3936 /* TYPE is the domain of this method, and THIS_TYPE is the type
3937 of the method itself (TYPE_CODE_METHOD). */
3938 smash_to_method_type (fnp->type, type,
3939 TYPE_TARGET_TYPE (this_type),
3940 TYPE_FIELDS (this_type),
3941 TYPE_NFIELDS (this_type),
3942 TYPE_VARARGS (this_type));
3944 /* Handle static member functions.
3945 Dwarf2 has no clean way to discern C++ static and non-static
3946 member functions. G++ helps GDB by marking the first
3947 parameter for non-static member functions (which is the
3948 this pointer) as artificial. We obtain this information
3949 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3950 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
3951 fnp->voffset = VOFFSET_STATIC;
3954 complaint (&symfile_complaints, _("member function type missing for '%s'"),
3957 /* Get fcontext from DW_AT_containing_type if present. */
3958 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3959 fnp->fcontext = die_containing_type (die, cu);
3961 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3962 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3964 /* Get accessibility. */
3965 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3968 switch (DW_UNSND (attr))
3970 case DW_ACCESS_private:
3971 fnp->is_private = 1;
3973 case DW_ACCESS_protected:
3974 fnp->is_protected = 1;
3979 /* Check for artificial methods. */
3980 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3981 if (attr && DW_UNSND (attr) != 0)
3982 fnp->is_artificial = 1;
3984 /* Get index in virtual function table if it is a virtual member function. */
3985 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3988 /* Support the .debug_loc offsets */
3989 if (attr_form_is_block (attr))
3991 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3993 else if (attr_form_is_section_offset (attr))
3995 dwarf2_complex_location_expr_complaint ();
3999 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4005 /* Create the vector of member function fields, and attach it to the type. */
4008 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
4009 struct dwarf2_cu *cu)
4011 struct fnfieldlist *flp;
4012 int total_length = 0;
4015 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4016 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4017 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
4019 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
4021 struct nextfnfield *nfp = flp->head;
4022 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
4025 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
4026 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
4027 fn_flp->fn_fields = (struct fn_field *)
4028 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
4029 for (k = flp->length; (k--, nfp); nfp = nfp->next)
4030 fn_flp->fn_fields[k] = nfp->fnfield;
4032 total_length += flp->length;
4035 TYPE_NFN_FIELDS (type) = fip->nfnfields;
4036 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
4039 /* Returns non-zero if NAME is the name of a vtable member in CU's
4040 language, zero otherwise. */
4042 is_vtable_name (const char *name, struct dwarf2_cu *cu)
4044 static const char vptr[] = "_vptr";
4045 static const char vtable[] = "vtable";
4047 /* Look for the C++ and Java forms of the vtable. */
4048 if ((cu->language == language_java
4049 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
4050 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
4051 && is_cplus_marker (name[sizeof (vptr) - 1])))
4057 /* GCC outputs unnamed structures that are really pointers to member
4058 functions, with the ABI-specified layout. If DIE (from CU) describes
4059 such a structure, set its type, and return nonzero. Otherwise return
4062 GCC shouldn't do this; it should just output pointer to member DIEs.
4063 This is GCC PR debug/28767. */
4065 static struct type *
4066 quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
4068 struct objfile *objfile = cu->objfile;
4070 struct die_info *pfn_die, *delta_die;
4071 struct attribute *pfn_name, *delta_name;
4072 struct type *pfn_type, *domain_type;
4074 /* Check for a structure with no name and two children. */
4075 if (die->tag != DW_TAG_structure_type
4076 || dwarf2_attr (die, DW_AT_name, cu) != NULL
4077 || die->child == NULL
4078 || die->child->sibling == NULL
4079 || (die->child->sibling->sibling != NULL
4080 && die->child->sibling->sibling->tag != DW_TAG_padding))
4083 /* Check for __pfn and __delta members. */
4084 pfn_die = die->child;
4085 pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu);
4086 if (pfn_die->tag != DW_TAG_member
4088 || DW_STRING (pfn_name) == NULL
4089 || strcmp ("__pfn", DW_STRING (pfn_name)) != 0)
4092 delta_die = pfn_die->sibling;
4093 delta_name = dwarf2_attr (delta_die, DW_AT_name, cu);
4094 if (delta_die->tag != DW_TAG_member
4095 || delta_name == NULL
4096 || DW_STRING (delta_name) == NULL
4097 || strcmp ("__delta", DW_STRING (delta_name)) != 0)
4100 /* Find the type of the method. */
4101 pfn_type = die_type (pfn_die, cu);
4102 if (pfn_type == NULL
4103 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
4104 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
4107 /* Look for the "this" argument. */
4108 pfn_type = TYPE_TARGET_TYPE (pfn_type);
4109 if (TYPE_NFIELDS (pfn_type) == 0
4110 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
4113 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
4114 type = alloc_type (objfile);
4115 smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
4116 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
4117 TYPE_VARARGS (pfn_type));
4118 type = lookup_methodptr_type (type);
4119 return set_die_type (die, type, cu);
4122 /* Called when we find the DIE that starts a structure or union scope
4123 (definition) to process all dies that define the members of the
4126 NOTE: we need to call struct_type regardless of whether or not the
4127 DIE has an at_name attribute, since it might be an anonymous
4128 structure or union. This gets the type entered into our set of
4131 However, if the structure is incomplete (an opaque struct/union)
4132 then suppress creating a symbol table entry for it since gdb only
4133 wants to find the one with the complete definition. Note that if
4134 it is complete, we just call new_symbol, which does it's own
4135 checking about whether the struct/union is anonymous or not (and
4136 suppresses creating a symbol table entry itself). */
4138 static struct type *
4139 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
4141 struct objfile *objfile = cu->objfile;
4143 struct attribute *attr;
4145 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4147 type = quirk_gcc_member_function_pointer (die, cu);
4151 type = alloc_type (objfile);
4152 INIT_CPLUS_SPECIFIC (type);
4153 name = dwarf2_name (die, cu);
4156 if (cu->language == language_cplus
4157 || cu->language == language_java)
4159 const char *new_prefix = determine_class_name (die, cu);
4160 TYPE_TAG_NAME (type) = (char *) new_prefix;
4164 /* The name is already allocated along with this objfile, so
4165 we don't need to duplicate it for the type. */
4166 TYPE_TAG_NAME (type) = name;
4170 if (die->tag == DW_TAG_structure_type)
4172 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4174 else if (die->tag == DW_TAG_union_type)
4176 TYPE_CODE (type) = TYPE_CODE_UNION;
4180 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4182 TYPE_CODE (type) = TYPE_CODE_CLASS;
4185 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4188 TYPE_LENGTH (type) = DW_UNSND (attr);
4192 TYPE_LENGTH (type) = 0;
4195 TYPE_STUB_SUPPORTED (type) = 1;
4196 if (die_is_declaration (die, cu))
4197 TYPE_STUB (type) = 1;
4199 /* We need to add the type field to the die immediately so we don't
4200 infinitely recurse when dealing with pointers to the structure
4201 type within the structure itself. */
4202 set_die_type (die, type, cu);
4204 if (die->child != NULL && ! die_is_declaration (die, cu))
4206 struct field_info fi;
4207 struct die_info *child_die;
4209 memset (&fi, 0, sizeof (struct field_info));
4211 child_die = die->child;
4213 while (child_die && child_die->tag)
4215 if (child_die->tag == DW_TAG_member
4216 || child_die->tag == DW_TAG_variable)
4218 /* NOTE: carlton/2002-11-05: A C++ static data member
4219 should be a DW_TAG_member that is a declaration, but
4220 all versions of G++ as of this writing (so through at
4221 least 3.2.1) incorrectly generate DW_TAG_variable
4222 tags for them instead. */
4223 dwarf2_add_field (&fi, child_die, cu);
4225 else if (child_die->tag == DW_TAG_subprogram)
4227 /* C++ member function. */
4228 dwarf2_add_member_fn (&fi, child_die, type, cu);
4230 else if (child_die->tag == DW_TAG_inheritance)
4232 /* C++ base class field. */
4233 dwarf2_add_field (&fi, child_die, cu);
4235 child_die = sibling_die (child_die);
4238 /* Attach fields and member functions to the type. */
4240 dwarf2_attach_fields_to_type (&fi, type, cu);
4243 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
4245 /* Get the type which refers to the base class (possibly this
4246 class itself) which contains the vtable pointer for the current
4247 class from the DW_AT_containing_type attribute. */
4249 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
4251 struct type *t = die_containing_type (die, cu);
4253 TYPE_VPTR_BASETYPE (type) = t;
4258 /* Our own class provides vtbl ptr. */
4259 for (i = TYPE_NFIELDS (t) - 1;
4260 i >= TYPE_N_BASECLASSES (t);
4263 char *fieldname = TYPE_FIELD_NAME (t, i);
4265 if (is_vtable_name (fieldname, cu))
4267 TYPE_VPTR_FIELDNO (type) = i;
4272 /* Complain if virtual function table field not found. */
4273 if (i < TYPE_N_BASECLASSES (t))
4274 complaint (&symfile_complaints,
4275 _("virtual function table pointer not found when defining class '%s'"),
4276 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
4281 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4284 else if (cu->producer
4285 && strncmp (cu->producer,
4286 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4288 /* The IBM XLC compiler does not provide direct indication
4289 of the containing type, but the vtable pointer is
4290 always named __vfp. */
4294 for (i = TYPE_NFIELDS (type) - 1;
4295 i >= TYPE_N_BASECLASSES (type);
4298 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
4300 TYPE_VPTR_FIELDNO (type) = i;
4301 TYPE_VPTR_BASETYPE (type) = type;
4309 do_cleanups (back_to);
4314 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
4316 struct objfile *objfile = cu->objfile;
4317 struct die_info *child_die = die->child;
4318 struct type *this_type;
4320 this_type = get_die_type (die, cu);
4321 if (this_type == NULL)
4322 this_type = read_structure_type (die, cu);
4324 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4325 snapshots) has been known to create a die giving a declaration
4326 for a class that has, as a child, a die giving a definition for a
4327 nested class. So we have to process our children even if the
4328 current die is a declaration. Normally, of course, a declaration
4329 won't have any children at all. */
4331 while (child_die != NULL && child_die->tag)
4333 if (child_die->tag == DW_TAG_member
4334 || child_die->tag == DW_TAG_variable
4335 || child_die->tag == DW_TAG_inheritance)
4340 process_die (child_die, cu);
4342 child_die = sibling_die (child_die);
4345 /* Do not consider external references. According to the DWARF standard,
4346 these DIEs are identified by the fact that they have no byte_size
4347 attribute, and a declaration attribute. */
4348 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
4349 || !die_is_declaration (die, cu))
4350 new_symbol (die, this_type, cu);
4353 /* Given a DW_AT_enumeration_type die, set its type. We do not
4354 complete the type's fields yet, or create any symbols. */
4356 static struct type *
4357 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
4359 struct objfile *objfile = cu->objfile;
4361 struct attribute *attr;
4364 type = alloc_type (objfile);
4366 TYPE_CODE (type) = TYPE_CODE_ENUM;
4367 name = dwarf2_full_name (die, cu);
4369 TYPE_TAG_NAME (type) = (char *) name;
4371 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4374 TYPE_LENGTH (type) = DW_UNSND (attr);
4378 TYPE_LENGTH (type) = 0;
4381 /* The enumeration DIE can be incomplete. In Ada, any type can be
4382 declared as private in the package spec, and then defined only
4383 inside the package body. Such types are known as Taft Amendment
4384 Types. When another package uses such a type, an incomplete DIE
4385 may be generated by the compiler. */
4386 if (die_is_declaration (die, cu))
4387 TYPE_STUB (type) = 1;
4389 return set_die_type (die, type, cu);
4392 /* Determine the name of the type represented by DIE, which should be
4393 a named C++ or Java compound type. Return the name in question,
4394 allocated on the objfile obstack. */
4397 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
4399 const char *new_prefix = NULL;
4401 /* If we don't have namespace debug info, guess the name by trying
4402 to demangle the names of members, just like we did in
4403 guess_structure_name. */
4404 if (!processing_has_namespace_info)
4406 struct die_info *child;
4408 for (child = die->child;
4409 child != NULL && child->tag != 0;
4410 child = sibling_die (child))
4412 if (child->tag == DW_TAG_subprogram)
4415 = language_class_name_from_physname (cu->language_defn,
4419 if (phys_prefix != NULL)
4422 = obsavestring (phys_prefix, strlen (phys_prefix),
4423 &cu->objfile->objfile_obstack);
4424 xfree (phys_prefix);
4431 if (new_prefix == NULL)
4432 new_prefix = dwarf2_full_name (die, cu);
4437 /* Given a pointer to a die which begins an enumeration, process all
4438 the dies that define the members of the enumeration, and create the
4439 symbol for the enumeration type.
4441 NOTE: We reverse the order of the element list. */
4444 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
4446 struct objfile *objfile = cu->objfile;
4447 struct die_info *child_die;
4448 struct field *fields;
4451 int unsigned_enum = 1;
4453 struct type *this_type;
4457 this_type = get_die_type (die, cu);
4458 if (this_type == NULL)
4459 this_type = read_enumeration_type (die, cu);
4460 if (die->child != NULL)
4462 child_die = die->child;
4463 while (child_die && child_die->tag)
4465 if (child_die->tag != DW_TAG_enumerator)
4467 process_die (child_die, cu);
4471 name = dwarf2_name (child_die, cu);
4474 sym = new_symbol (child_die, this_type, cu);
4475 if (SYMBOL_VALUE (sym) < 0)
4478 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
4480 fields = (struct field *)
4482 (num_fields + DW_FIELD_ALLOC_CHUNK)
4483 * sizeof (struct field));
4486 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
4487 FIELD_TYPE (fields[num_fields]) = NULL;
4488 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
4489 FIELD_BITSIZE (fields[num_fields]) = 0;
4495 child_die = sibling_die (child_die);
4500 TYPE_NFIELDS (this_type) = num_fields;
4501 TYPE_FIELDS (this_type) = (struct field *)
4502 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
4503 memcpy (TYPE_FIELDS (this_type), fields,
4504 sizeof (struct field) * num_fields);
4508 TYPE_UNSIGNED (this_type) = 1;
4511 new_symbol (die, this_type, cu);
4514 /* Extract all information from a DW_TAG_array_type DIE and put it in
4515 the DIE's type field. For now, this only handles one dimensional
4518 static struct type *
4519 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
4521 struct objfile *objfile = cu->objfile;
4522 struct die_info *child_die;
4523 struct type *type = NULL;
4524 struct type *element_type, *range_type, *index_type;
4525 struct type **range_types = NULL;
4526 struct attribute *attr;
4528 struct cleanup *back_to;
4531 element_type = die_type (die, cu);
4533 /* Irix 6.2 native cc creates array types without children for
4534 arrays with unspecified length. */
4535 if (die->child == NULL)
4537 index_type = builtin_type_int32;
4538 range_type = create_range_type (NULL, index_type, 0, -1);
4539 type = create_array_type (NULL, element_type, range_type);
4540 return set_die_type (die, type, cu);
4543 back_to = make_cleanup (null_cleanup, NULL);
4544 child_die = die->child;
4545 while (child_die && child_die->tag)
4547 if (child_die->tag == DW_TAG_subrange_type)
4549 struct type *child_type = read_type_die (child_die, cu);
4550 if (child_type != NULL)
4552 /* The range type was succesfully read. Save it for
4553 the array type creation. */
4554 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
4556 range_types = (struct type **)
4557 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
4558 * sizeof (struct type *));
4560 make_cleanup (free_current_contents, &range_types);
4562 range_types[ndim++] = child_type;
4565 child_die = sibling_die (child_die);
4568 /* Dwarf2 dimensions are output from left to right, create the
4569 necessary array types in backwards order. */
4571 type = element_type;
4573 if (read_array_order (die, cu) == DW_ORD_col_major)
4577 type = create_array_type (NULL, type, range_types[i++]);
4582 type = create_array_type (NULL, type, range_types[ndim]);
4585 /* Understand Dwarf2 support for vector types (like they occur on
4586 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4587 array type. This is not part of the Dwarf2/3 standard yet, but a
4588 custom vendor extension. The main difference between a regular
4589 array and the vector variant is that vectors are passed by value
4591 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
4593 make_vector_type (type);
4595 name = dwarf2_name (die, cu);
4597 TYPE_NAME (type) = name;
4599 do_cleanups (back_to);
4601 /* Install the type in the die. */
4602 return set_die_type (die, type, cu);
4605 static enum dwarf_array_dim_ordering
4606 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
4608 struct attribute *attr;
4610 attr = dwarf2_attr (die, DW_AT_ordering, cu);
4612 if (attr) return DW_SND (attr);
4615 GNU F77 is a special case, as at 08/2004 array type info is the
4616 opposite order to the dwarf2 specification, but data is still
4617 laid out as per normal fortran.
4619 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4623 if (cu->language == language_fortran &&
4624 cu->producer && strstr (cu->producer, "GNU F77"))
4626 return DW_ORD_row_major;
4629 switch (cu->language_defn->la_array_ordering)
4631 case array_column_major:
4632 return DW_ORD_col_major;
4633 case array_row_major:
4635 return DW_ORD_row_major;
4639 /* Extract all information from a DW_TAG_set_type DIE and put it in
4640 the DIE's type field. */
4642 static struct type *
4643 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
4645 struct type *set_type = create_set_type (NULL, die_type (die, cu));
4647 return set_die_type (die, set_type, cu);
4650 /* First cut: install each common block member as a global variable. */
4653 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
4655 struct die_info *child_die;
4656 struct attribute *attr;
4658 CORE_ADDR base = (CORE_ADDR) 0;
4660 attr = dwarf2_attr (die, DW_AT_location, cu);
4663 /* Support the .debug_loc offsets */
4664 if (attr_form_is_block (attr))
4666 base = decode_locdesc (DW_BLOCK (attr), cu);
4668 else if (attr_form_is_section_offset (attr))
4670 dwarf2_complex_location_expr_complaint ();
4674 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4675 "common block member");
4678 if (die->child != NULL)
4680 child_die = die->child;
4681 while (child_die && child_die->tag)
4683 sym = new_symbol (child_die, NULL, cu);
4684 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
4687 SYMBOL_VALUE_ADDRESS (sym) =
4688 base + decode_locdesc (DW_BLOCK (attr), cu);
4689 add_symbol_to_list (sym, &global_symbols);
4691 child_die = sibling_die (child_die);
4696 /* Create a type for a C++ namespace. */
4698 static struct type *
4699 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
4701 struct objfile *objfile = cu->objfile;
4702 const char *previous_prefix, *name;
4706 /* For extensions, reuse the type of the original namespace. */
4707 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
4709 struct die_info *ext_die;
4710 struct dwarf2_cu *ext_cu = cu;
4711 ext_die = dwarf2_extension (die, &ext_cu);
4712 type = read_type_die (ext_die, ext_cu);
4713 return set_die_type (die, type, cu);
4716 name = namespace_name (die, &is_anonymous, cu);
4718 /* Now build the name of the current namespace. */
4720 previous_prefix = determine_prefix (die, cu);
4721 if (previous_prefix[0] != '\0')
4722 name = typename_concat (&objfile->objfile_obstack,
4723 previous_prefix, name, cu);
4725 /* Create the type. */
4726 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
4728 TYPE_NAME (type) = (char *) name;
4729 TYPE_TAG_NAME (type) = TYPE_NAME (type);
4731 set_die_type (die, type, cu);
4736 /* Read a C++ namespace. */
4739 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
4741 struct objfile *objfile = cu->objfile;
4745 /* Add a symbol associated to this if we haven't seen the namespace
4746 before. Also, add a using directive if it's an anonymous
4749 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
4753 type = read_type_die (die, cu);
4754 new_symbol (die, type, cu);
4756 name = namespace_name (die, &is_anonymous, cu);
4759 const char *previous_prefix = determine_prefix (die, cu);
4760 cp_add_using_directive (TYPE_NAME (type),
4761 strlen (previous_prefix),
4762 strlen (TYPE_NAME (type)));
4766 if (die->child != NULL)
4768 struct die_info *child_die = die->child;
4770 while (child_die && child_die->tag)
4772 process_die (child_die, cu);
4773 child_die = sibling_die (child_die);
4778 /* Read a Fortran module. */
4781 read_module (struct die_info *die, struct dwarf2_cu *cu)
4783 struct die_info *child_die = die->child;
4785 /* FIXME: Support the separate Fortran module namespaces. */
4787 while (child_die && child_die->tag)
4789 process_die (child_die, cu);
4790 child_die = sibling_die (child_die);
4794 /* Return the name of the namespace represented by DIE. Set
4795 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4799 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
4801 struct die_info *current_die;
4802 const char *name = NULL;
4804 /* Loop through the extensions until we find a name. */
4806 for (current_die = die;
4807 current_die != NULL;
4808 current_die = dwarf2_extension (die, &cu))
4810 name = dwarf2_name (current_die, cu);
4815 /* Is it an anonymous namespace? */
4817 *is_anonymous = (name == NULL);
4819 name = "(anonymous namespace)";
4824 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4825 the user defined type vector. */
4827 static struct type *
4828 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
4830 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
4831 struct comp_unit_head *cu_header = &cu->header;
4833 struct attribute *attr_byte_size;
4834 struct attribute *attr_address_class;
4835 int byte_size, addr_class;
4837 type = lookup_pointer_type (die_type (die, cu));
4839 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
4841 byte_size = DW_UNSND (attr_byte_size);
4843 byte_size = cu_header->addr_size;
4845 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
4846 if (attr_address_class)
4847 addr_class = DW_UNSND (attr_address_class);
4849 addr_class = DW_ADDR_none;
4851 /* If the pointer size or address class is different than the
4852 default, create a type variant marked as such and set the
4853 length accordingly. */
4854 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
4856 if (gdbarch_address_class_type_flags_p (gdbarch))
4860 type_flags = gdbarch_address_class_type_flags
4861 (gdbarch, byte_size, addr_class);
4862 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
4864 type = make_type_with_address_space (type, type_flags);
4866 else if (TYPE_LENGTH (type) != byte_size)
4868 complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size);
4871 /* Should we also complain about unhandled address classes? */
4875 TYPE_LENGTH (type) = byte_size;
4876 return set_die_type (die, type, cu);
4879 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4880 the user defined type vector. */
4882 static struct type *
4883 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
4885 struct objfile *objfile = cu->objfile;
4887 struct type *to_type;
4888 struct type *domain;
4890 to_type = die_type (die, cu);
4891 domain = die_containing_type (die, cu);
4893 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
4894 type = lookup_methodptr_type (to_type);
4896 type = lookup_memberptr_type (to_type, domain);
4898 return set_die_type (die, type, cu);
4901 /* Extract all information from a DW_TAG_reference_type DIE and add to
4902 the user defined type vector. */
4904 static struct type *
4905 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
4907 struct comp_unit_head *cu_header = &cu->header;
4909 struct attribute *attr;
4911 type = lookup_reference_type (die_type (die, cu));
4912 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4915 TYPE_LENGTH (type) = DW_UNSND (attr);
4919 TYPE_LENGTH (type) = cu_header->addr_size;
4921 return set_die_type (die, type, cu);
4924 static struct type *
4925 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
4927 struct type *base_type, *cv_type;
4929 base_type = die_type (die, cu);
4930 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
4931 return set_die_type (die, cv_type, cu);
4934 static struct type *
4935 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
4937 struct type *base_type, *cv_type;
4939 base_type = die_type (die, cu);
4940 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
4941 return set_die_type (die, cv_type, cu);
4944 /* Extract all information from a DW_TAG_string_type DIE and add to
4945 the user defined type vector. It isn't really a user defined type,
4946 but it behaves like one, with other DIE's using an AT_user_def_type
4947 attribute to reference it. */
4949 static struct type *
4950 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
4952 struct objfile *objfile = cu->objfile;
4953 struct type *type, *range_type, *index_type, *char_type;
4954 struct attribute *attr;
4955 unsigned int length;
4957 attr = dwarf2_attr (die, DW_AT_string_length, cu);
4960 length = DW_UNSND (attr);
4964 /* check for the DW_AT_byte_size attribute */
4965 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4968 length = DW_UNSND (attr);
4976 index_type = builtin_type_int32;
4977 range_type = create_range_type (NULL, index_type, 1, length);
4978 type = create_string_type (NULL, range_type);
4980 return set_die_type (die, type, cu);
4983 /* Handle DIES due to C code like:
4987 int (*funcp)(int a, long l);
4991 ('funcp' generates a DW_TAG_subroutine_type DIE)
4994 static struct type *
4995 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4997 struct type *type; /* Type that this function returns */
4998 struct type *ftype; /* Function that returns above type */
4999 struct attribute *attr;
5001 type = die_type (die, cu);
5002 ftype = make_function_type (type, (struct type **) 0);
5004 /* All functions in C++, Pascal and Java have prototypes. */
5005 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
5006 if ((attr && (DW_UNSND (attr) != 0))
5007 || cu->language == language_cplus
5008 || cu->language == language_java
5009 || cu->language == language_pascal)
5010 TYPE_PROTOTYPED (ftype) = 1;
5012 /* Store the calling convention in the type if it's available in
5013 the subroutine die. Otherwise set the calling convention to
5014 the default value DW_CC_normal. */
5015 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
5016 TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
5018 if (die->child != NULL)
5020 struct die_info *child_die;
5024 /* Count the number of parameters.
5025 FIXME: GDB currently ignores vararg functions, but knows about
5026 vararg member functions. */
5027 child_die = die->child;
5028 while (child_die && child_die->tag)
5030 if (child_die->tag == DW_TAG_formal_parameter)
5032 else if (child_die->tag == DW_TAG_unspecified_parameters)
5033 TYPE_VARARGS (ftype) = 1;
5034 child_die = sibling_die (child_die);
5037 /* Allocate storage for parameters and fill them in. */
5038 TYPE_NFIELDS (ftype) = nparams;
5039 TYPE_FIELDS (ftype) = (struct field *)
5040 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
5042 child_die = die->child;
5043 while (child_die && child_die->tag)
5045 if (child_die->tag == DW_TAG_formal_parameter)
5047 /* Dwarf2 has no clean way to discern C++ static and non-static
5048 member functions. G++ helps GDB by marking the first
5049 parameter for non-static member functions (which is the
5050 this pointer) as artificial. We pass this information
5051 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5052 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
5054 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
5056 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
5057 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
5060 child_die = sibling_die (child_die);
5064 return set_die_type (die, ftype, cu);
5067 static struct type *
5068 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
5070 struct objfile *objfile = cu->objfile;
5071 struct attribute *attr;
5072 const char *name = NULL;
5073 struct type *this_type;
5075 name = dwarf2_full_name (die, cu);
5076 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
5077 TYPE_FLAG_TARGET_STUB, NULL, objfile);
5078 TYPE_NAME (this_type) = (char *) name;
5079 set_die_type (die, this_type, cu);
5080 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
5084 /* Find a representation of a given base type and install
5085 it in the TYPE field of the die. */
5087 static struct type *
5088 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
5090 struct objfile *objfile = cu->objfile;
5092 struct attribute *attr;
5093 int encoding = 0, size = 0;
5095 enum type_code code = TYPE_CODE_INT;
5097 struct type *target_type = NULL;
5099 attr = dwarf2_attr (die, DW_AT_encoding, cu);
5102 encoding = DW_UNSND (attr);
5104 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5107 size = DW_UNSND (attr);
5109 name = dwarf2_name (die, cu);
5112 complaint (&symfile_complaints,
5113 _("DW_AT_name missing from DW_TAG_base_type"));
5118 case DW_ATE_address:
5119 /* Turn DW_ATE_address into a void * pointer. */
5120 code = TYPE_CODE_PTR;
5121 type_flags |= TYPE_FLAG_UNSIGNED;
5122 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
5124 case DW_ATE_boolean:
5125 code = TYPE_CODE_BOOL;
5126 type_flags |= TYPE_FLAG_UNSIGNED;
5128 case DW_ATE_complex_float:
5129 code = TYPE_CODE_COMPLEX;
5130 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
5132 case DW_ATE_decimal_float:
5133 code = TYPE_CODE_DECFLOAT;
5136 code = TYPE_CODE_FLT;
5140 case DW_ATE_unsigned:
5141 type_flags |= TYPE_FLAG_UNSIGNED;
5143 case DW_ATE_signed_char:
5144 if (cu->language == language_ada || cu->language == language_m2
5145 || cu->language == language_pascal)
5146 code = TYPE_CODE_CHAR;
5148 case DW_ATE_unsigned_char:
5149 if (cu->language == language_ada || cu->language == language_m2
5150 || cu->language == language_pascal)
5151 code = TYPE_CODE_CHAR;
5152 type_flags |= TYPE_FLAG_UNSIGNED;
5155 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
5156 dwarf_type_encoding_name (encoding));
5160 type = init_type (code, size, type_flags, NULL, objfile);
5161 TYPE_NAME (type) = name;
5162 TYPE_TARGET_TYPE (type) = target_type;
5164 if (name && strcmp (name, "char") == 0)
5165 TYPE_NOSIGN (type) = 1;
5167 return set_die_type (die, type, cu);
5170 /* Read the given DW_AT_subrange DIE. */
5172 static struct type *
5173 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5175 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
5176 struct type *base_type;
5177 struct type *range_type;
5178 struct attribute *attr;
5183 base_type = die_type (die, cu);
5184 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
5186 complaint (&symfile_complaints,
5187 _("DW_AT_type missing from DW_TAG_subrange_type"));
5189 = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
5190 0, NULL, cu->objfile);
5193 if (cu->language == language_fortran)
5195 /* FORTRAN implies a lower bound of 1, if not given. */
5199 /* FIXME: For variable sized arrays either of these could be
5200 a variable rather than a constant value. We'll allow it,
5201 but we don't know how to handle it. */
5202 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
5204 low = dwarf2_get_attr_constant_value (attr, 0);
5206 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
5209 if (attr->form == DW_FORM_block1)
5211 /* GCC encodes arrays with unspecified or dynamic length
5212 with a DW_FORM_block1 attribute.
5213 FIXME: GDB does not yet know how to handle dynamic
5214 arrays properly, treat them as arrays with unspecified
5217 FIXME: jimb/2003-09-22: GDB does not really know
5218 how to handle arrays of unspecified length
5219 either; we just represent them as zero-length
5220 arrays. Choose an appropriate upper bound given
5221 the lower bound we've computed above. */
5225 high = dwarf2_get_attr_constant_value (attr, 1);
5228 range_type = create_range_type (NULL, base_type, low, high);
5230 name = dwarf2_name (die, cu);
5232 TYPE_NAME (range_type) = name;
5234 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5236 TYPE_LENGTH (range_type) = DW_UNSND (attr);
5238 return set_die_type (die, range_type, cu);
5241 static struct type *
5242 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
5246 /* For now, we only support the C meaning of an unspecified type: void. */
5248 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
5249 TYPE_NAME (type) = dwarf2_name (die, cu);
5251 return set_die_type (die, type, cu);
5254 /* Trivial hash function for die_info: the hash value of a DIE
5255 is its offset in .debug_info for this objfile. */
5258 die_hash (const void *item)
5260 const struct die_info *die = item;
5264 /* Trivial comparison function for die_info structures: two DIEs
5265 are equal if they have the same offset. */
5268 die_eq (const void *item_lhs, const void *item_rhs)
5270 const struct die_info *die_lhs = item_lhs;
5271 const struct die_info *die_rhs = item_rhs;
5272 return die_lhs->offset == die_rhs->offset;
5275 /* Read a whole compilation unit into a linked list of dies. */
5277 static struct die_info *
5278 read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
5281 = htab_create_alloc_ex (cu->header.length / 12,
5285 &cu->comp_unit_obstack,
5286 hashtab_obstack_allocate,
5287 dummy_obstack_deallocate);
5289 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
5292 /* Main entry point for reading a DIE and all children.
5293 Read the DIE and dump it if requested. */
5295 static struct die_info *
5296 read_die_and_children (gdb_byte *info_ptr, bfd *abfd,
5297 struct dwarf2_cu *cu,
5298 gdb_byte **new_info_ptr,
5299 struct die_info *parent)
5301 struct die_info *result = read_die_and_children_1 (info_ptr, abfd, cu,
5302 new_info_ptr, parent);
5304 if (dwarf2_die_debug)
5306 fprintf_unfiltered (gdb_stdlog, "Read die from .debug_info:\n");
5307 dump_die (result, dwarf2_die_debug);
5313 /* Read a single die and all its descendents. Set the die's sibling
5314 field to NULL; set other fields in the die correctly, and set all
5315 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5316 location of the info_ptr after reading all of those dies. PARENT
5317 is the parent of the die in question. */
5319 static struct die_info *
5320 read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd,
5321 struct dwarf2_cu *cu,
5322 gdb_byte **new_info_ptr,
5323 struct die_info *parent)
5325 struct die_info *die;
5329 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
5332 *new_info_ptr = cur_ptr;
5335 store_in_ref_table (die, cu);
5339 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
5345 *new_info_ptr = cur_ptr;
5348 die->sibling = NULL;
5349 die->parent = parent;
5353 /* Read a die, all of its descendents, and all of its siblings; set
5354 all of the fields of all of the dies correctly. Arguments are as
5355 in read_die_and_children. */
5357 static struct die_info *
5358 read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd,
5359 struct dwarf2_cu *cu,
5360 gdb_byte **new_info_ptr,
5361 struct die_info *parent)
5363 struct die_info *first_die, *last_sibling;
5367 first_die = last_sibling = NULL;
5371 struct die_info *die
5372 = read_die_and_children_1 (cur_ptr, abfd, cu, &cur_ptr, parent);
5376 *new_info_ptr = cur_ptr;
5383 last_sibling->sibling = die;
5389 /* Decompress a section that was compressed using zlib. Store the
5390 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5393 zlib_decompress_section (struct objfile *objfile, asection *sectp,
5394 gdb_byte **outbuf, bfd_size_type *outsize)
5396 bfd *abfd = objfile->obfd;
5398 error (_("Support for zlib-compressed DWARF data (from '%s') "
5399 "is disabled in this copy of GDB"),
5400 bfd_get_filename (abfd));
5402 bfd_size_type compressed_size = bfd_get_section_size (sectp);
5403 gdb_byte *compressed_buffer = xmalloc (compressed_size);
5404 bfd_size_type uncompressed_size;
5405 gdb_byte *uncompressed_buffer;
5408 int header_size = 12;
5410 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5411 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
5412 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5413 bfd_get_filename (abfd));
5415 /* Read the zlib header. In this case, it should be "ZLIB" followed
5416 by the uncompressed section size, 8 bytes in big-endian order. */
5417 if (compressed_size < header_size
5418 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
5419 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5420 bfd_get_filename (abfd));
5421 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
5422 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
5423 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
5424 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
5425 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
5426 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
5427 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
5428 uncompressed_size += compressed_buffer[11];
5430 /* It is possible the section consists of several compressed
5431 buffers concatenated together, so we uncompress in a loop. */
5435 strm.avail_in = compressed_size - header_size;
5436 strm.next_in = (Bytef*) compressed_buffer + header_size;
5437 strm.avail_out = uncompressed_size;
5438 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
5440 rc = inflateInit (&strm);
5441 while (strm.avail_in > 0)
5444 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5445 bfd_get_filename (abfd), rc);
5446 strm.next_out = ((Bytef*) uncompressed_buffer
5447 + (uncompressed_size - strm.avail_out));
5448 rc = inflate (&strm, Z_FINISH);
5449 if (rc != Z_STREAM_END)
5450 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5451 bfd_get_filename (abfd), rc);
5452 rc = inflateReset (&strm);
5454 rc = inflateEnd (&strm);
5456 || strm.avail_out != 0)
5457 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5458 bfd_get_filename (abfd), rc);
5460 xfree (compressed_buffer);
5461 *outbuf = uncompressed_buffer;
5462 *outsize = uncompressed_size;
5467 /* Read the contents of the section at OFFSET and of size SIZE from the
5468 object file specified by OBJFILE into the objfile_obstack and return it.
5469 If the section is compressed, uncompress it before returning. */
5472 dwarf2_read_section (struct objfile *objfile, asection *sectp)
5474 bfd *abfd = objfile->obfd;
5475 gdb_byte *buf, *retbuf;
5476 bfd_size_type size = bfd_get_section_size (sectp);
5477 unsigned char header[4];
5482 /* Check if the file has a 4-byte header indicating compression. */
5483 if (size > sizeof (header)
5484 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
5485 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
5487 /* Upon decompression, update the buffer and its size. */
5488 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
5490 zlib_decompress_section (objfile, sectp, &buf, &size);
5491 dwarf2_resize_section (sectp, size);
5496 /* If we get here, we are a normal, not-compressed section. */
5497 buf = obstack_alloc (&objfile->objfile_obstack, size);
5498 /* When debugging .o files, we may need to apply relocations; see
5499 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5500 We never compress sections in .o files, so we only need to
5501 try this when the section is not compressed. */
5502 retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
5506 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5507 || bfd_bread (buf, size, abfd) != size)
5508 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5509 bfd_get_filename (abfd));
5514 /* In DWARF version 2, the description of the debugging information is
5515 stored in a separate .debug_abbrev section. Before we read any
5516 dies from a section we read in all abbreviations and install them
5517 in a hash table. This function also sets flags in CU describing
5518 the data found in the abbrev table. */
5521 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
5523 struct comp_unit_head *cu_header = &cu->header;
5524 gdb_byte *abbrev_ptr;
5525 struct abbrev_info *cur_abbrev;
5526 unsigned int abbrev_number, bytes_read, abbrev_name;
5527 unsigned int abbrev_form, hash_number;
5528 struct attr_abbrev *cur_attrs;
5529 unsigned int allocated_attrs;
5531 /* Initialize dwarf2 abbrevs */
5532 obstack_init (&cu->abbrev_obstack);
5533 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
5535 * sizeof (struct abbrev_info *)));
5536 memset (cu->dwarf2_abbrevs, 0,
5537 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
5539 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
5540 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5541 abbrev_ptr += bytes_read;
5543 allocated_attrs = ATTR_ALLOC_CHUNK;
5544 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
5546 /* loop until we reach an abbrev number of 0 */
5547 while (abbrev_number)
5549 cur_abbrev = dwarf_alloc_abbrev (cu);
5551 /* read in abbrev header */
5552 cur_abbrev->number = abbrev_number;
5553 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5554 abbrev_ptr += bytes_read;
5555 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
5558 if (cur_abbrev->tag == DW_TAG_namespace)
5559 cu->has_namespace_info = 1;
5561 /* now read in declarations */
5562 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5563 abbrev_ptr += bytes_read;
5564 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5565 abbrev_ptr += bytes_read;
5568 if (cur_abbrev->num_attrs == allocated_attrs)
5570 allocated_attrs += ATTR_ALLOC_CHUNK;
5572 = xrealloc (cur_attrs, (allocated_attrs
5573 * sizeof (struct attr_abbrev)));
5576 /* Record whether this compilation unit might have
5577 inter-compilation-unit references. If we don't know what form
5578 this attribute will have, then it might potentially be a
5579 DW_FORM_ref_addr, so we conservatively expect inter-CU
5582 if (abbrev_form == DW_FORM_ref_addr
5583 || abbrev_form == DW_FORM_indirect)
5584 cu->has_form_ref_addr = 1;
5586 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
5587 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
5588 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5589 abbrev_ptr += bytes_read;
5590 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5591 abbrev_ptr += bytes_read;
5594 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
5595 (cur_abbrev->num_attrs
5596 * sizeof (struct attr_abbrev)));
5597 memcpy (cur_abbrev->attrs, cur_attrs,
5598 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
5600 hash_number = abbrev_number % ABBREV_HASH_SIZE;
5601 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
5602 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
5604 /* Get next abbreviation.
5605 Under Irix6 the abbreviations for a compilation unit are not
5606 always properly terminated with an abbrev number of 0.
5607 Exit loop if we encounter an abbreviation which we have
5608 already read (which means we are about to read the abbreviations
5609 for the next compile unit) or if the end of the abbreviation
5610 table is reached. */
5611 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
5612 >= dwarf2_per_objfile->abbrev_size)
5614 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
5615 abbrev_ptr += bytes_read;
5616 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
5623 /* Release the memory used by the abbrev table for a compilation unit. */
5626 dwarf2_free_abbrev_table (void *ptr_to_cu)
5628 struct dwarf2_cu *cu = ptr_to_cu;
5630 obstack_free (&cu->abbrev_obstack, NULL);
5631 cu->dwarf2_abbrevs = NULL;
5634 /* Lookup an abbrev_info structure in the abbrev hash table. */
5636 static struct abbrev_info *
5637 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
5639 unsigned int hash_number;
5640 struct abbrev_info *abbrev;
5642 hash_number = number % ABBREV_HASH_SIZE;
5643 abbrev = cu->dwarf2_abbrevs[hash_number];
5647 if (abbrev->number == number)
5650 abbrev = abbrev->next;
5655 /* Returns nonzero if TAG represents a type that we might generate a partial
5659 is_type_tag_for_partial (int tag)
5664 /* Some types that would be reasonable to generate partial symbols for,
5665 that we don't at present. */
5666 case DW_TAG_array_type:
5667 case DW_TAG_file_type:
5668 case DW_TAG_ptr_to_member_type:
5669 case DW_TAG_set_type:
5670 case DW_TAG_string_type:
5671 case DW_TAG_subroutine_type:
5673 case DW_TAG_base_type:
5674 case DW_TAG_class_type:
5675 case DW_TAG_interface_type:
5676 case DW_TAG_enumeration_type:
5677 case DW_TAG_structure_type:
5678 case DW_TAG_subrange_type:
5679 case DW_TAG_typedef:
5680 case DW_TAG_union_type:
5687 /* Load all DIEs that are interesting for partial symbols into memory. */
5689 static struct partial_die_info *
5690 load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab,
5691 struct dwarf2_cu *cu)
5693 struct partial_die_info *part_die;
5694 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
5695 struct abbrev_info *abbrev;
5696 unsigned int bytes_read;
5697 unsigned int load_all = 0;
5699 int nesting_level = 1;
5704 if (cu->per_cu && cu->per_cu->load_all_dies)
5708 = htab_create_alloc_ex (cu->header.length / 12,
5712 &cu->comp_unit_obstack,
5713 hashtab_obstack_allocate,
5714 dummy_obstack_deallocate);
5716 part_die = obstack_alloc (&cu->comp_unit_obstack,
5717 sizeof (struct partial_die_info));
5721 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
5723 /* A NULL abbrev means the end of a series of children. */
5726 if (--nesting_level == 0)
5728 /* PART_DIE was probably the last thing allocated on the
5729 comp_unit_obstack, so we could call obstack_free
5730 here. We don't do that because the waste is small,
5731 and will be cleaned up when we're done with this
5732 compilation unit. This way, we're also more robust
5733 against other users of the comp_unit_obstack. */
5736 info_ptr += bytes_read;
5737 last_die = parent_die;
5738 parent_die = parent_die->die_parent;
5742 /* Check whether this DIE is interesting enough to save. Normally
5743 we would not be interested in members here, but there may be
5744 later variables referencing them via DW_AT_specification (for
5747 && !is_type_tag_for_partial (abbrev->tag)
5748 && abbrev->tag != DW_TAG_enumerator
5749 && abbrev->tag != DW_TAG_subprogram
5750 && abbrev->tag != DW_TAG_lexical_block
5751 && abbrev->tag != DW_TAG_variable
5752 && abbrev->tag != DW_TAG_namespace
5753 && abbrev->tag != DW_TAG_member)
5755 /* Otherwise we skip to the next sibling, if any. */
5756 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
5760 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
5761 abfd, info_ptr, cu);
5763 /* This two-pass algorithm for processing partial symbols has a
5764 high cost in cache pressure. Thus, handle some simple cases
5765 here which cover the majority of C partial symbols. DIEs
5766 which neither have specification tags in them, nor could have
5767 specification tags elsewhere pointing at them, can simply be
5768 processed and discarded.
5770 This segment is also optional; scan_partial_symbols and
5771 add_partial_symbol will handle these DIEs if we chain
5772 them in normally. When compilers which do not emit large
5773 quantities of duplicate debug information are more common,
5774 this code can probably be removed. */
5776 /* Any complete simple types at the top level (pretty much all
5777 of them, for a language without namespaces), can be processed
5779 if (parent_die == NULL
5780 && part_die->has_specification == 0
5781 && part_die->is_declaration == 0
5782 && (part_die->tag == DW_TAG_typedef
5783 || part_die->tag == DW_TAG_base_type
5784 || part_die->tag == DW_TAG_subrange_type))
5786 if (building_psymtab && part_die->name != NULL)
5787 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5788 VAR_DOMAIN, LOC_TYPEDEF,
5789 &cu->objfile->static_psymbols,
5790 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5791 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5795 /* If we're at the second level, and we're an enumerator, and
5796 our parent has no specification (meaning possibly lives in a
5797 namespace elsewhere), then we can add the partial symbol now
5798 instead of queueing it. */
5799 if (part_die->tag == DW_TAG_enumerator
5800 && parent_die != NULL
5801 && parent_die->die_parent == NULL
5802 && parent_die->tag == DW_TAG_enumeration_type
5803 && parent_die->has_specification == 0)
5805 if (part_die->name == NULL)
5806 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
5807 else if (building_psymtab)
5808 add_psymbol_to_list (part_die->name, strlen (part_die->name),
5809 VAR_DOMAIN, LOC_CONST,
5810 (cu->language == language_cplus
5811 || cu->language == language_java)
5812 ? &cu->objfile->global_psymbols
5813 : &cu->objfile->static_psymbols,
5814 0, (CORE_ADDR) 0, cu->language, cu->objfile);
5816 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
5820 /* We'll save this DIE so link it in. */
5821 part_die->die_parent = parent_die;
5822 part_die->die_sibling = NULL;
5823 part_die->die_child = NULL;
5825 if (last_die && last_die == parent_die)
5826 last_die->die_child = part_die;
5828 last_die->die_sibling = part_die;
5830 last_die = part_die;
5832 if (first_die == NULL)
5833 first_die = part_die;
5835 /* Maybe add the DIE to the hash table. Not all DIEs that we
5836 find interesting need to be in the hash table, because we
5837 also have the parent/sibling/child chains; only those that we
5838 might refer to by offset later during partial symbol reading.
5840 For now this means things that might have be the target of a
5841 DW_AT_specification, DW_AT_abstract_origin, or
5842 DW_AT_extension. DW_AT_extension will refer only to
5843 namespaces; DW_AT_abstract_origin refers to functions (and
5844 many things under the function DIE, but we do not recurse
5845 into function DIEs during partial symbol reading) and
5846 possibly variables as well; DW_AT_specification refers to
5847 declarations. Declarations ought to have the DW_AT_declaration
5848 flag. It happens that GCC forgets to put it in sometimes, but
5849 only for functions, not for types.
5851 Adding more things than necessary to the hash table is harmless
5852 except for the performance cost. Adding too few will result in
5853 wasted time in find_partial_die, when we reread the compilation
5854 unit with load_all_dies set. */
5857 || abbrev->tag == DW_TAG_subprogram
5858 || abbrev->tag == DW_TAG_variable
5859 || abbrev->tag == DW_TAG_namespace
5860 || part_die->is_declaration)
5864 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
5865 part_die->offset, INSERT);
5869 part_die = obstack_alloc (&cu->comp_unit_obstack,
5870 sizeof (struct partial_die_info));
5872 /* For some DIEs we want to follow their children (if any). For C
5873 we have no reason to follow the children of structures; for other
5874 languages we have to, both so that we can get at method physnames
5875 to infer fully qualified class names, and for DW_AT_specification.
5877 For Ada, we need to scan the children of subprograms and lexical
5878 blocks as well because Ada allows the definition of nested
5879 entities that could be interesting for the debugger, such as
5880 nested subprograms for instance. */
5881 if (last_die->has_children
5883 || last_die->tag == DW_TAG_namespace
5884 || last_die->tag == DW_TAG_enumeration_type
5885 || (cu->language != language_c
5886 && (last_die->tag == DW_TAG_class_type
5887 || last_die->tag == DW_TAG_interface_type
5888 || last_die->tag == DW_TAG_structure_type
5889 || last_die->tag == DW_TAG_union_type))
5890 || (cu->language == language_ada
5891 && (last_die->tag == DW_TAG_subprogram
5892 || last_die->tag == DW_TAG_lexical_block))))
5895 parent_die = last_die;
5899 /* Otherwise we skip to the next sibling, if any. */
5900 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
5902 /* Back to the top, do it again. */
5906 /* Read a minimal amount of information into the minimal die structure. */
5909 read_partial_die (struct partial_die_info *part_die,
5910 struct abbrev_info *abbrev,
5911 unsigned int abbrev_len, bfd *abfd,
5912 gdb_byte *info_ptr, struct dwarf2_cu *cu)
5914 unsigned int bytes_read, i;
5915 struct attribute attr;
5916 int has_low_pc_attr = 0;
5917 int has_high_pc_attr = 0;
5918 CORE_ADDR base_address = 0;
5922 base_address_low_pc,
5923 /* Overrides BASE_ADDRESS_LOW_PC. */
5924 base_address_entry_pc
5926 base_address_type = base_address_none;
5928 memset (part_die, 0, sizeof (struct partial_die_info));
5930 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
5932 info_ptr += abbrev_len;
5937 part_die->tag = abbrev->tag;
5938 part_die->has_children = abbrev->has_children;
5940 for (i = 0; i < abbrev->num_attrs; ++i)
5942 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
5944 /* Store the data if it is of an attribute we want to keep in a
5945 partial symbol table. */
5950 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5951 if (part_die->name == NULL)
5952 part_die->name = DW_STRING (&attr);
5954 case DW_AT_comp_dir:
5955 if (part_die->dirname == NULL)
5956 part_die->dirname = DW_STRING (&attr);
5958 case DW_AT_MIPS_linkage_name:
5959 part_die->name = DW_STRING (&attr);
5962 has_low_pc_attr = 1;
5963 part_die->lowpc = DW_ADDR (&attr);
5964 if (part_die->tag == DW_TAG_compile_unit
5965 && base_address_type < base_address_low_pc)
5967 base_address = DW_ADDR (&attr);
5968 base_address_type = base_address_low_pc;
5972 has_high_pc_attr = 1;
5973 part_die->highpc = DW_ADDR (&attr);
5975 case DW_AT_entry_pc:
5976 if (part_die->tag == DW_TAG_compile_unit
5977 && base_address_type < base_address_entry_pc)
5979 base_address = DW_ADDR (&attr);
5980 base_address_type = base_address_entry_pc;
5984 if (part_die->tag == DW_TAG_compile_unit)
5986 cu->ranges_offset = DW_UNSND (&attr);
5987 cu->has_ranges_offset = 1;
5990 case DW_AT_location:
5991 /* Support the .debug_loc offsets */
5992 if (attr_form_is_block (&attr))
5994 part_die->locdesc = DW_BLOCK (&attr);
5996 else if (attr_form_is_section_offset (&attr))
5998 dwarf2_complex_location_expr_complaint ();
6002 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6003 "partial symbol information");
6006 case DW_AT_language:
6007 part_die->language = DW_UNSND (&attr);
6009 case DW_AT_external:
6010 part_die->is_external = DW_UNSND (&attr);
6012 case DW_AT_declaration:
6013 part_die->is_declaration = DW_UNSND (&attr);
6016 part_die->has_type = 1;
6018 case DW_AT_abstract_origin:
6019 case DW_AT_specification:
6020 case DW_AT_extension:
6021 part_die->has_specification = 1;
6022 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
6025 /* Ignore absolute siblings, they might point outside of
6026 the current compile unit. */
6027 if (attr.form == DW_FORM_ref_addr)
6028 complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling"));
6030 part_die->sibling = dwarf2_per_objfile->info_buffer
6031 + dwarf2_get_ref_die_offset (&attr);
6033 case DW_AT_stmt_list:
6034 part_die->has_stmt_list = 1;
6035 part_die->line_offset = DW_UNSND (&attr);
6037 case DW_AT_byte_size:
6038 part_die->has_byte_size = 1;
6040 case DW_AT_calling_convention:
6041 /* DWARF doesn't provide a way to identify a program's source-level
6042 entry point. DW_AT_calling_convention attributes are only meant
6043 to describe functions' calling conventions.
6045 However, because it's a necessary piece of information in
6046 Fortran, and because DW_CC_program is the only piece of debugging
6047 information whose definition refers to a 'main program' at all,
6048 several compilers have begun marking Fortran main programs with
6049 DW_CC_program --- even when those functions use the standard
6050 calling conventions.
6052 So until DWARF specifies a way to provide this information and
6053 compilers pick up the new representation, we'll support this
6055 if (DW_UNSND (&attr) == DW_CC_program
6056 && cu->language == language_fortran)
6057 set_main_name (part_die->name);
6064 /* When using the GNU linker, .gnu.linkonce. sections are used to
6065 eliminate duplicate copies of functions and vtables and such.
6066 The linker will arbitrarily choose one and discard the others.
6067 The AT_*_pc values for such functions refer to local labels in
6068 these sections. If the section from that file was discarded, the
6069 labels are not in the output, so the relocs get a value of 0.
6070 If this is a discarded function, mark the pc bounds as invalid,
6071 so that GDB will ignore it. */
6072 if (has_low_pc_attr && has_high_pc_attr
6073 && part_die->lowpc < part_die->highpc
6074 && (part_die->lowpc != 0
6075 || dwarf2_per_objfile->has_section_at_zero))
6076 part_die->has_pc_info = 1;
6078 if (base_address_type != base_address_none && !cu->base_known)
6080 gdb_assert (part_die->tag == DW_TAG_compile_unit);
6082 cu->base_address = base_address;
6088 /* Find a cached partial DIE at OFFSET in CU. */
6090 static struct partial_die_info *
6091 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
6093 struct partial_die_info *lookup_die = NULL;
6094 struct partial_die_info part_die;
6096 part_die.offset = offset;
6097 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
6102 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6104 static struct partial_die_info *
6105 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
6107 struct dwarf2_per_cu_data *per_cu = NULL;
6108 struct partial_die_info *pd = NULL;
6110 if (offset_in_cu_p (&cu->header, offset))
6112 pd = find_partial_die_in_comp_unit (offset, cu);
6117 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
6119 if (per_cu->cu == NULL)
6121 load_comp_unit (per_cu, cu->objfile);
6122 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
6123 dwarf2_per_objfile->read_in_chain = per_cu;
6126 per_cu->cu->last_used = 0;
6127 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6129 if (pd == NULL && per_cu->load_all_dies == 0)
6131 struct cleanup *back_to;
6132 struct partial_die_info comp_unit_die;
6133 struct abbrev_info *abbrev;
6134 unsigned int bytes_read;
6137 per_cu->load_all_dies = 1;
6139 /* Re-read the DIEs. */
6140 back_to = make_cleanup (null_cleanup, 0);
6141 if (per_cu->cu->dwarf2_abbrevs == NULL)
6143 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
6144 back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
6146 info_ptr = (dwarf2_per_objfile->info_buffer
6147 + per_cu->cu->header.offset
6148 + per_cu->cu->header.first_die_offset);
6149 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
6150 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
6151 per_cu->cu->objfile->obfd, info_ptr,
6153 if (comp_unit_die.has_children)
6154 load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu);
6155 do_cleanups (back_to);
6157 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
6161 internal_error (__FILE__, __LINE__,
6162 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6163 offset, bfd_get_filename (cu->objfile->obfd));
6167 /* Adjust PART_DIE before generating a symbol for it. This function
6168 may set the is_external flag or change the DIE's name. */
6171 fixup_partial_die (struct partial_die_info *part_die,
6172 struct dwarf2_cu *cu)
6174 /* If we found a reference attribute and the DIE has no name, try
6175 to find a name in the referred to DIE. */
6177 if (part_die->name == NULL && part_die->has_specification)
6179 struct partial_die_info *spec_die;
6181 spec_die = find_partial_die (part_die->spec_offset, cu);
6183 fixup_partial_die (spec_die, cu);
6187 part_die->name = spec_die->name;
6189 /* Copy DW_AT_external attribute if it is set. */
6190 if (spec_die->is_external)
6191 part_die->is_external = spec_die->is_external;
6195 /* Set default names for some unnamed DIEs. */
6196 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
6197 || part_die->tag == DW_TAG_class_type))
6198 part_die->name = "(anonymous class)";
6200 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
6201 part_die->name = "(anonymous namespace)";
6203 if (part_die->tag == DW_TAG_structure_type
6204 || part_die->tag == DW_TAG_class_type
6205 || part_die->tag == DW_TAG_union_type)
6206 guess_structure_name (part_die, cu);
6209 /* Read the die from the .debug_info section buffer. Set DIEP to
6210 point to a newly allocated die with its information, except for its
6211 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6212 whether the die has children or not. */
6215 read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr,
6216 struct dwarf2_cu *cu, int *has_children)
6218 unsigned int abbrev_number, bytes_read, i, offset;
6219 struct abbrev_info *abbrev;
6220 struct die_info *die;
6222 offset = info_ptr - dwarf2_per_objfile->info_buffer;
6223 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6224 info_ptr += bytes_read;
6232 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
6235 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6237 bfd_get_filename (abfd));
6239 die = dwarf_alloc_die (cu, abbrev->num_attrs);
6240 die->offset = offset;
6241 die->tag = abbrev->tag;
6242 die->abbrev = abbrev_number;
6244 die->num_attrs = abbrev->num_attrs;
6246 for (i = 0; i < abbrev->num_attrs; ++i)
6247 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
6248 abfd, info_ptr, cu);
6251 *has_children = abbrev->has_children;
6255 /* Read an attribute value described by an attribute form. */
6258 read_attribute_value (struct attribute *attr, unsigned form,
6259 bfd *abfd, gdb_byte *info_ptr,
6260 struct dwarf2_cu *cu)
6262 struct comp_unit_head *cu_header = &cu->header;
6263 unsigned int bytes_read;
6264 struct dwarf_block *blk;
6270 case DW_FORM_ref_addr:
6271 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
6272 info_ptr += bytes_read;
6274 case DW_FORM_block2:
6275 blk = dwarf_alloc_block (cu);
6276 blk->size = read_2_bytes (abfd, info_ptr);
6278 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6279 info_ptr += blk->size;
6280 DW_BLOCK (attr) = blk;
6282 case DW_FORM_block4:
6283 blk = dwarf_alloc_block (cu);
6284 blk->size = read_4_bytes (abfd, info_ptr);
6286 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6287 info_ptr += blk->size;
6288 DW_BLOCK (attr) = blk;
6291 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
6295 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
6299 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
6302 case DW_FORM_string:
6303 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
6304 info_ptr += bytes_read;
6307 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
6309 info_ptr += bytes_read;
6312 blk = dwarf_alloc_block (cu);
6313 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6314 info_ptr += bytes_read;
6315 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6316 info_ptr += blk->size;
6317 DW_BLOCK (attr) = blk;
6319 case DW_FORM_block1:
6320 blk = dwarf_alloc_block (cu);
6321 blk->size = read_1_byte (abfd, info_ptr);
6323 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
6324 info_ptr += blk->size;
6325 DW_BLOCK (attr) = blk;
6328 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
6332 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
6336 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
6337 info_ptr += bytes_read;
6340 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6341 info_ptr += bytes_read;
6344 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
6348 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
6352 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
6356 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
6359 case DW_FORM_ref_udata:
6360 DW_ADDR (attr) = (cu->header.offset
6361 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
6362 info_ptr += bytes_read;
6364 case DW_FORM_indirect:
6365 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6366 info_ptr += bytes_read;
6367 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
6370 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6371 dwarf_form_name (form),
6372 bfd_get_filename (abfd));
6375 /* We have seen instances where the compiler tried to emit a byte
6376 size attribute of -1 which ended up being encoded as an unsigned
6377 0xffffffff. Although 0xffffffff is technically a valid size value,
6378 an object of this size seems pretty unlikely so we can relatively
6379 safely treat these cases as if the size attribute was invalid and
6380 treat them as zero by default. */
6381 if (attr->name == DW_AT_byte_size
6382 && form == DW_FORM_data4
6383 && DW_UNSND (attr) >= 0xffffffff)
6386 (&symfile_complaints,
6387 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6389 DW_UNSND (attr) = 0;
6395 /* Read an attribute described by an abbreviated attribute. */
6398 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
6399 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
6401 attr->name = abbrev->name;
6402 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
6405 /* read dwarf information from a buffer */
6408 read_1_byte (bfd *abfd, gdb_byte *buf)
6410 return bfd_get_8 (abfd, buf);
6414 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
6416 return bfd_get_signed_8 (abfd, buf);
6420 read_2_bytes (bfd *abfd, gdb_byte *buf)
6422 return bfd_get_16 (abfd, buf);
6426 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
6428 return bfd_get_signed_16 (abfd, buf);
6432 read_4_bytes (bfd *abfd, gdb_byte *buf)
6434 return bfd_get_32 (abfd, buf);
6438 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
6440 return bfd_get_signed_32 (abfd, buf);
6443 static unsigned long
6444 read_8_bytes (bfd *abfd, gdb_byte *buf)
6446 return bfd_get_64 (abfd, buf);
6450 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
6451 unsigned int *bytes_read)
6453 struct comp_unit_head *cu_header = &cu->header;
6454 CORE_ADDR retval = 0;
6456 if (cu_header->signed_addr_p)
6458 switch (cu_header->addr_size)
6461 retval = bfd_get_signed_16 (abfd, buf);
6464 retval = bfd_get_signed_32 (abfd, buf);
6467 retval = bfd_get_signed_64 (abfd, buf);
6470 internal_error (__FILE__, __LINE__,
6471 _("read_address: bad switch, signed [in module %s]"),
6472 bfd_get_filename (abfd));
6477 switch (cu_header->addr_size)
6480 retval = bfd_get_16 (abfd, buf);
6483 retval = bfd_get_32 (abfd, buf);
6486 retval = bfd_get_64 (abfd, buf);
6489 internal_error (__FILE__, __LINE__,
6490 _("read_address: bad switch, unsigned [in module %s]"),
6491 bfd_get_filename (abfd));
6495 *bytes_read = cu_header->addr_size;
6499 /* Read the initial length from a section. The (draft) DWARF 3
6500 specification allows the initial length to take up either 4 bytes
6501 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6502 bytes describe the length and all offsets will be 8 bytes in length
6505 An older, non-standard 64-bit format is also handled by this
6506 function. The older format in question stores the initial length
6507 as an 8-byte quantity without an escape value. Lengths greater
6508 than 2^32 aren't very common which means that the initial 4 bytes
6509 is almost always zero. Since a length value of zero doesn't make
6510 sense for the 32-bit format, this initial zero can be considered to
6511 be an escape value which indicates the presence of the older 64-bit
6512 format. As written, the code can't detect (old format) lengths
6513 greater than 4GB. If it becomes necessary to handle lengths
6514 somewhat larger than 4GB, we could allow other small values (such
6515 as the non-sensical values of 1, 2, and 3) to also be used as
6516 escape values indicating the presence of the old format.
6518 The value returned via bytes_read should be used to increment the
6519 relevant pointer after calling read_initial_length().
6521 [ Note: read_initial_length() and read_offset() are based on the
6522 document entitled "DWARF Debugging Information Format", revision
6523 3, draft 8, dated November 19, 2001. This document was obtained
6526 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6528 This document is only a draft and is subject to change. (So beware.)
6530 Details regarding the older, non-standard 64-bit format were
6531 determined empirically by examining 64-bit ELF files produced by
6532 the SGI toolchain on an IRIX 6.5 machine.
6534 - Kevin, July 16, 2002
6538 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
6540 LONGEST length = bfd_get_32 (abfd, buf);
6542 if (length == 0xffffffff)
6544 length = bfd_get_64 (abfd, buf + 4);
6547 else if (length == 0)
6549 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6550 length = bfd_get_64 (abfd, buf);
6561 /* Cover function for read_initial_length.
6562 Returns the length of the object at BUF, and stores the size of the
6563 initial length in *BYTES_READ and stores the size that offsets will be in
6565 If the initial length size is not equivalent to that specified in
6566 CU_HEADER then issue a complaint.
6567 This is useful when reading non-comp-unit headers. */
6570 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
6571 const struct comp_unit_head *cu_header,
6572 unsigned int *bytes_read,
6573 unsigned int *offset_size)
6575 LONGEST length = read_initial_length (abfd, buf, bytes_read);
6577 gdb_assert (cu_header->initial_length_size == 4
6578 || cu_header->initial_length_size == 8
6579 || cu_header->initial_length_size == 12);
6581 if (cu_header->initial_length_size != *bytes_read)
6582 complaint (&symfile_complaints,
6583 _("intermixed 32-bit and 64-bit DWARF sections"));
6585 *offset_size = (*bytes_read == 4) ? 4 : 8;
6589 /* Read an offset from the data stream. The size of the offset is
6590 given by cu_header->offset_size. */
6593 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
6594 unsigned int *bytes_read)
6596 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
6597 *bytes_read = cu_header->offset_size;
6601 /* Read an offset from the data stream. */
6604 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
6608 switch (offset_size)
6611 retval = bfd_get_32 (abfd, buf);
6614 retval = bfd_get_64 (abfd, buf);
6617 internal_error (__FILE__, __LINE__,
6618 _("read_offset_1: bad switch [in module %s]"),
6619 bfd_get_filename (abfd));
6626 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
6628 /* If the size of a host char is 8 bits, we can return a pointer
6629 to the buffer, otherwise we have to copy the data to a buffer
6630 allocated on the temporary obstack. */
6631 gdb_assert (HOST_CHAR_BIT == 8);
6636 read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6638 /* If the size of a host char is 8 bits, we can return a pointer
6639 to the string, otherwise we have to copy the string to a buffer
6640 allocated on the temporary obstack. */
6641 gdb_assert (HOST_CHAR_BIT == 8);
6644 *bytes_read_ptr = 1;
6647 *bytes_read_ptr = strlen ((char *) buf) + 1;
6648 return (char *) buf;
6652 read_indirect_string (bfd *abfd, gdb_byte *buf,
6653 const struct comp_unit_head *cu_header,
6654 unsigned int *bytes_read_ptr)
6656 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
6658 if (dwarf2_per_objfile->str_buffer == NULL)
6660 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6661 bfd_get_filename (abfd));
6664 if (str_offset >= dwarf2_per_objfile->str_size)
6666 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6667 bfd_get_filename (abfd));
6670 gdb_assert (HOST_CHAR_BIT == 8);
6671 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
6673 return (char *) (dwarf2_per_objfile->str_buffer + str_offset);
6676 static unsigned long
6677 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6679 unsigned long result;
6680 unsigned int num_read;
6690 byte = bfd_get_8 (abfd, buf);
6693 result |= ((unsigned long)(byte & 127) << shift);
6694 if ((byte & 128) == 0)
6700 *bytes_read_ptr = num_read;
6705 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
6708 int i, shift, num_read;
6717 byte = bfd_get_8 (abfd, buf);
6720 result |= ((long)(byte & 127) << shift);
6722 if ((byte & 128) == 0)
6727 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
6728 result |= -(((long)1) << shift);
6729 *bytes_read_ptr = num_read;
6733 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6736 skip_leb128 (bfd *abfd, gdb_byte *buf)
6742 byte = bfd_get_8 (abfd, buf);
6744 if ((byte & 128) == 0)
6750 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
6756 cu->language = language_c;
6758 case DW_LANG_C_plus_plus:
6759 cu->language = language_cplus;
6761 case DW_LANG_Fortran77:
6762 case DW_LANG_Fortran90:
6763 case DW_LANG_Fortran95:
6764 cu->language = language_fortran;
6766 case DW_LANG_Mips_Assembler:
6767 cu->language = language_asm;
6770 cu->language = language_java;
6774 cu->language = language_ada;
6776 case DW_LANG_Modula2:
6777 cu->language = language_m2;
6779 case DW_LANG_Pascal83:
6780 cu->language = language_pascal;
6783 cu->language = language_objc;
6785 case DW_LANG_Cobol74:
6786 case DW_LANG_Cobol85:
6788 cu->language = language_minimal;
6791 cu->language_defn = language_def (cu->language);
6794 /* Return the named attribute or NULL if not there. */
6796 static struct attribute *
6797 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
6800 struct attribute *spec = NULL;
6802 for (i = 0; i < die->num_attrs; ++i)
6804 if (die->attrs[i].name == name)
6805 return &die->attrs[i];
6806 if (die->attrs[i].name == DW_AT_specification
6807 || die->attrs[i].name == DW_AT_abstract_origin)
6808 spec = &die->attrs[i];
6813 die = follow_die_ref (die, spec, &cu);
6814 return dwarf2_attr (die, name, cu);
6820 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6821 and holds a non-zero value. This function should only be used for
6822 DW_FORM_flag attributes. */
6825 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
6827 struct attribute *attr = dwarf2_attr (die, name, cu);
6829 return (attr && DW_UNSND (attr));
6833 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
6835 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6836 which value is non-zero. However, we have to be careful with
6837 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6838 (via dwarf2_flag_true_p) follows this attribute. So we may
6839 end up accidently finding a declaration attribute that belongs
6840 to a different DIE referenced by the specification attribute,
6841 even though the given DIE does not have a declaration attribute. */
6842 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
6843 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
6846 /* Return the die giving the specification for DIE, if there is
6847 one. *SPEC_CU is the CU containing DIE on input, and the CU
6848 containing the return value on output. */
6850 static struct die_info *
6851 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
6853 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
6856 if (spec_attr == NULL)
6859 return follow_die_ref (die, spec_attr, spec_cu);
6862 /* Free the line_header structure *LH, and any arrays and strings it
6865 free_line_header (struct line_header *lh)
6867 if (lh->standard_opcode_lengths)
6868 xfree (lh->standard_opcode_lengths);
6870 /* Remember that all the lh->file_names[i].name pointers are
6871 pointers into debug_line_buffer, and don't need to be freed. */
6873 xfree (lh->file_names);
6875 /* Similarly for the include directory names. */
6876 if (lh->include_dirs)
6877 xfree (lh->include_dirs);
6883 /* Add an entry to LH's include directory table. */
6885 add_include_dir (struct line_header *lh, char *include_dir)
6887 /* Grow the array if necessary. */
6888 if (lh->include_dirs_size == 0)
6890 lh->include_dirs_size = 1; /* for testing */
6891 lh->include_dirs = xmalloc (lh->include_dirs_size
6892 * sizeof (*lh->include_dirs));
6894 else if (lh->num_include_dirs >= lh->include_dirs_size)
6896 lh->include_dirs_size *= 2;
6897 lh->include_dirs = xrealloc (lh->include_dirs,
6898 (lh->include_dirs_size
6899 * sizeof (*lh->include_dirs)));
6902 lh->include_dirs[lh->num_include_dirs++] = include_dir;
6906 /* Add an entry to LH's file name table. */
6908 add_file_name (struct line_header *lh,
6910 unsigned int dir_index,
6911 unsigned int mod_time,
6912 unsigned int length)
6914 struct file_entry *fe;
6916 /* Grow the array if necessary. */
6917 if (lh->file_names_size == 0)
6919 lh->file_names_size = 1; /* for testing */
6920 lh->file_names = xmalloc (lh->file_names_size
6921 * sizeof (*lh->file_names));
6923 else if (lh->num_file_names >= lh->file_names_size)
6925 lh->file_names_size *= 2;
6926 lh->file_names = xrealloc (lh->file_names,
6927 (lh->file_names_size
6928 * sizeof (*lh->file_names)));
6931 fe = &lh->file_names[lh->num_file_names++];
6933 fe->dir_index = dir_index;
6934 fe->mod_time = mod_time;
6935 fe->length = length;
6941 /* Read the statement program header starting at OFFSET in
6942 .debug_line, according to the endianness of ABFD. Return a pointer
6943 to a struct line_header, allocated using xmalloc.
6945 NOTE: the strings in the include directory and file name tables of
6946 the returned object point into debug_line_buffer, and must not be
6948 static struct line_header *
6949 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
6950 struct dwarf2_cu *cu)
6952 struct cleanup *back_to;
6953 struct line_header *lh;
6955 unsigned int bytes_read, offset_size;
6957 char *cur_dir, *cur_file;
6959 if (dwarf2_per_objfile->line_buffer == NULL)
6961 complaint (&symfile_complaints, _("missing .debug_line section"));
6965 /* Make sure that at least there's room for the total_length field.
6966 That could be 12 bytes long, but we're just going to fudge that. */
6967 if (offset + 4 >= dwarf2_per_objfile->line_size)
6969 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6973 lh = xmalloc (sizeof (*lh));
6974 memset (lh, 0, sizeof (*lh));
6975 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
6978 line_ptr = dwarf2_per_objfile->line_buffer + offset;
6980 /* Read in the header. */
6982 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
6983 &bytes_read, &offset_size);
6984 line_ptr += bytes_read;
6985 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
6986 + dwarf2_per_objfile->line_size))
6988 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6991 lh->statement_program_end = line_ptr + lh->total_length;
6992 lh->version = read_2_bytes (abfd, line_ptr);
6994 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
6995 line_ptr += offset_size;
6996 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
6998 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
7000 lh->line_base = read_1_signed_byte (abfd, line_ptr);
7002 lh->line_range = read_1_byte (abfd, line_ptr);
7004 lh->opcode_base = read_1_byte (abfd, line_ptr);
7006 lh->standard_opcode_lengths
7007 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
7009 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
7010 for (i = 1; i < lh->opcode_base; ++i)
7012 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
7016 /* Read directory table. */
7017 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7019 line_ptr += bytes_read;
7020 add_include_dir (lh, cur_dir);
7022 line_ptr += bytes_read;
7024 /* Read file name table. */
7025 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
7027 unsigned int dir_index, mod_time, length;
7029 line_ptr += bytes_read;
7030 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7031 line_ptr += bytes_read;
7032 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7033 line_ptr += bytes_read;
7034 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7035 line_ptr += bytes_read;
7037 add_file_name (lh, cur_file, dir_index, mod_time, length);
7039 line_ptr += bytes_read;
7040 lh->statement_program_start = line_ptr;
7042 if (line_ptr > (dwarf2_per_objfile->line_buffer
7043 + dwarf2_per_objfile->line_size))
7044 complaint (&symfile_complaints,
7045 _("line number info header doesn't fit in `.debug_line' section"));
7047 discard_cleanups (back_to);
7051 /* This function exists to work around a bug in certain compilers
7052 (particularly GCC 2.95), in which the first line number marker of a
7053 function does not show up until after the prologue, right before
7054 the second line number marker. This function shifts ADDRESS down
7055 to the beginning of the function if necessary, and is called on
7056 addresses passed to record_line. */
7059 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
7061 struct function_range *fn;
7063 /* Find the function_range containing address. */
7068 cu->cached_fn = cu->first_fn;
7072 if (fn->lowpc <= address && fn->highpc > address)
7078 while (fn && fn != cu->cached_fn)
7079 if (fn->lowpc <= address && fn->highpc > address)
7089 if (address != fn->lowpc)
7090 complaint (&symfile_complaints,
7091 _("misplaced first line number at 0x%lx for '%s'"),
7092 (unsigned long) address, fn->name);
7097 /* Decode the Line Number Program (LNP) for the given line_header
7098 structure and CU. The actual information extracted and the type
7099 of structures created from the LNP depends on the value of PST.
7101 1. If PST is NULL, then this procedure uses the data from the program
7102 to create all necessary symbol tables, and their linetables.
7103 The compilation directory of the file is passed in COMP_DIR,
7104 and must not be NULL.
7106 2. If PST is not NULL, this procedure reads the program to determine
7107 the list of files included by the unit represented by PST, and
7108 builds all the associated partial symbol tables. In this case,
7109 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7110 is not used to compute the full name of the symtab, and therefore
7111 omitting it when building the partial symtab does not introduce
7112 the potential for inconsistency - a partial symtab and its associated
7113 symbtab having a different fullname -). */
7116 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
7117 struct dwarf2_cu *cu, struct partial_symtab *pst)
7119 gdb_byte *line_ptr, *extended_end;
7121 unsigned int bytes_read, extended_len;
7122 unsigned char op_code, extended_op, adj_opcode;
7124 struct objfile *objfile = cu->objfile;
7125 const int decode_for_pst_p = (pst != NULL);
7126 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
7128 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7130 line_ptr = lh->statement_program_start;
7131 line_end = lh->statement_program_end;
7133 /* Read the statement sequences until there's nothing left. */
7134 while (line_ptr < line_end)
7136 /* state machine registers */
7137 CORE_ADDR address = 0;
7138 unsigned int file = 1;
7139 unsigned int line = 1;
7140 unsigned int column = 0;
7141 int is_stmt = lh->default_is_stmt;
7142 int basic_block = 0;
7143 int end_sequence = 0;
7145 if (!decode_for_pst_p && lh->num_file_names >= file)
7147 /* Start a subfile for the current file of the state machine. */
7148 /* lh->include_dirs and lh->file_names are 0-based, but the
7149 directory and file name numbers in the statement program
7151 struct file_entry *fe = &lh->file_names[file - 1];
7155 dir = lh->include_dirs[fe->dir_index - 1];
7157 dwarf2_start_subfile (fe->name, dir, comp_dir);
7160 /* Decode the table. */
7161 while (!end_sequence)
7163 op_code = read_1_byte (abfd, line_ptr);
7165 if (line_ptr > line_end)
7167 dwarf2_debug_line_missing_end_sequence_complaint ();
7171 if (op_code >= lh->opcode_base)
7173 /* Special operand. */
7174 adj_opcode = op_code - lh->opcode_base;
7175 address += (adj_opcode / lh->line_range)
7176 * lh->minimum_instruction_length;
7177 line += lh->line_base + (adj_opcode % lh->line_range);
7178 if (lh->num_file_names < file || file == 0)
7179 dwarf2_debug_line_missing_file_complaint ();
7182 lh->file_names[file - 1].included_p = 1;
7183 if (!decode_for_pst_p)
7185 if (last_subfile != current_subfile)
7188 record_line (last_subfile, 0, address);
7189 last_subfile = current_subfile;
7191 /* Append row to matrix using current values. */
7192 record_line (current_subfile, line,
7193 check_cu_functions (address, cu));
7198 else switch (op_code)
7200 case DW_LNS_extended_op:
7201 extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7202 line_ptr += bytes_read;
7203 extended_end = line_ptr + extended_len;
7204 extended_op = read_1_byte (abfd, line_ptr);
7206 switch (extended_op)
7208 case DW_LNE_end_sequence:
7211 case DW_LNE_set_address:
7212 address = read_address (abfd, line_ptr, cu, &bytes_read);
7213 line_ptr += bytes_read;
7214 address += baseaddr;
7216 case DW_LNE_define_file:
7219 unsigned int dir_index, mod_time, length;
7221 cur_file = read_string (abfd, line_ptr, &bytes_read);
7222 line_ptr += bytes_read;
7224 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7225 line_ptr += bytes_read;
7227 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7228 line_ptr += bytes_read;
7230 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7231 line_ptr += bytes_read;
7232 add_file_name (lh, cur_file, dir_index, mod_time, length);
7236 complaint (&symfile_complaints,
7237 _("mangled .debug_line section"));
7240 /* Make sure that we parsed the extended op correctly. If e.g.
7241 we expected a different address size than the producer used,
7242 we may have read the wrong number of bytes. */
7243 if (line_ptr != extended_end)
7245 complaint (&symfile_complaints,
7246 _("mangled .debug_line section"));
7251 if (lh->num_file_names < file || file == 0)
7252 dwarf2_debug_line_missing_file_complaint ();
7255 lh->file_names[file - 1].included_p = 1;
7256 if (!decode_for_pst_p)
7258 if (last_subfile != current_subfile)
7261 record_line (last_subfile, 0, address);
7262 last_subfile = current_subfile;
7264 record_line (current_subfile, line,
7265 check_cu_functions (address, cu));
7270 case DW_LNS_advance_pc:
7271 address += lh->minimum_instruction_length
7272 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7273 line_ptr += bytes_read;
7275 case DW_LNS_advance_line:
7276 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
7277 line_ptr += bytes_read;
7279 case DW_LNS_set_file:
7281 /* The arrays lh->include_dirs and lh->file_names are
7282 0-based, but the directory and file name numbers in
7283 the statement program are 1-based. */
7284 struct file_entry *fe;
7287 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7288 line_ptr += bytes_read;
7289 if (lh->num_file_names < file || file == 0)
7290 dwarf2_debug_line_missing_file_complaint ();
7293 fe = &lh->file_names[file - 1];
7295 dir = lh->include_dirs[fe->dir_index - 1];
7296 if (!decode_for_pst_p)
7298 last_subfile = current_subfile;
7299 dwarf2_start_subfile (fe->name, dir, comp_dir);
7304 case DW_LNS_set_column:
7305 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7306 line_ptr += bytes_read;
7308 case DW_LNS_negate_stmt:
7309 is_stmt = (!is_stmt);
7311 case DW_LNS_set_basic_block:
7314 /* Add to the address register of the state machine the
7315 address increment value corresponding to special opcode
7316 255. I.e., this value is scaled by the minimum
7317 instruction length since special opcode 255 would have
7318 scaled the the increment. */
7319 case DW_LNS_const_add_pc:
7320 address += (lh->minimum_instruction_length
7321 * ((255 - lh->opcode_base) / lh->line_range));
7323 case DW_LNS_fixed_advance_pc:
7324 address += read_2_bytes (abfd, line_ptr);
7329 /* Unknown standard opcode, ignore it. */
7332 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
7334 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
7335 line_ptr += bytes_read;
7340 if (lh->num_file_names < file || file == 0)
7341 dwarf2_debug_line_missing_file_complaint ();
7344 lh->file_names[file - 1].included_p = 1;
7345 if (!decode_for_pst_p)
7346 record_line (current_subfile, 0, address);
7350 if (decode_for_pst_p)
7354 /* Now that we're done scanning the Line Header Program, we can
7355 create the psymtab of each included file. */
7356 for (file_index = 0; file_index < lh->num_file_names; file_index++)
7357 if (lh->file_names[file_index].included_p == 1)
7359 const struct file_entry fe = lh->file_names [file_index];
7360 char *include_name = fe.name;
7361 char *dir_name = NULL;
7362 char *pst_filename = pst->filename;
7365 dir_name = lh->include_dirs[fe.dir_index - 1];
7367 if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL)
7369 include_name = concat (dir_name, SLASH_STRING,
7370 include_name, (char *)NULL);
7371 make_cleanup (xfree, include_name);
7374 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
7376 pst_filename = concat (pst->dirname, SLASH_STRING,
7377 pst_filename, (char *)NULL);
7378 make_cleanup (xfree, pst_filename);
7381 if (strcmp (include_name, pst_filename) != 0)
7382 dwarf2_create_include_psymtab (include_name, pst, objfile);
7387 /* Make sure a symtab is created for every file, even files
7388 which contain only variables (i.e. no code with associated
7392 struct file_entry *fe;
7394 for (i = 0; i < lh->num_file_names; i++)
7397 fe = &lh->file_names[i];
7399 dir = lh->include_dirs[fe->dir_index - 1];
7400 dwarf2_start_subfile (fe->name, dir, comp_dir);
7402 /* Skip the main file; we don't need it, and it must be
7403 allocated last, so that it will show up before the
7404 non-primary symtabs in the objfile's symtab list. */
7405 if (current_subfile == first_subfile)
7408 if (current_subfile->symtab == NULL)
7409 current_subfile->symtab = allocate_symtab (current_subfile->name,
7411 fe->symtab = current_subfile->symtab;
7416 /* Start a subfile for DWARF. FILENAME is the name of the file and
7417 DIRNAME the name of the source directory which contains FILENAME
7418 or NULL if not known. COMP_DIR is the compilation directory for the
7419 linetable's compilation unit or NULL if not known.
7420 This routine tries to keep line numbers from identical absolute and
7421 relative file names in a common subfile.
7423 Using the `list' example from the GDB testsuite, which resides in
7424 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7425 of /srcdir/list0.c yields the following debugging information for list0.c:
7427 DW_AT_name: /srcdir/list0.c
7428 DW_AT_comp_dir: /compdir
7429 files.files[0].name: list0.h
7430 files.files[0].dir: /srcdir
7431 files.files[1].name: list0.c
7432 files.files[1].dir: /srcdir
7434 The line number information for list0.c has to end up in a single
7435 subfile, so that `break /srcdir/list0.c:1' works as expected.
7436 start_subfile will ensure that this happens provided that we pass the
7437 concatenation of files.files[1].dir and files.files[1].name as the
7441 dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
7445 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7446 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7447 second argument to start_subfile. To be consistent, we do the
7448 same here. In order not to lose the line information directory,
7449 we concatenate it to the filename when it makes sense.
7450 Note that the Dwarf3 standard says (speaking of filenames in line
7451 information): ``The directory index is ignored for file names
7452 that represent full path names''. Thus ignoring dirname in the
7453 `else' branch below isn't an issue. */
7455 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
7456 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
7458 fullname = filename;
7460 start_subfile (fullname, comp_dir);
7462 if (fullname != filename)
7467 var_decode_location (struct attribute *attr, struct symbol *sym,
7468 struct dwarf2_cu *cu)
7470 struct objfile *objfile = cu->objfile;
7471 struct comp_unit_head *cu_header = &cu->header;
7473 /* NOTE drow/2003-01-30: There used to be a comment and some special
7474 code here to turn a symbol with DW_AT_external and a
7475 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7476 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7477 with some versions of binutils) where shared libraries could have
7478 relocations against symbols in their debug information - the
7479 minimal symbol would have the right address, but the debug info
7480 would not. It's no longer necessary, because we will explicitly
7481 apply relocations when we read in the debug information now. */
7483 /* A DW_AT_location attribute with no contents indicates that a
7484 variable has been optimized away. */
7485 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
7487 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7491 /* Handle one degenerate form of location expression specially, to
7492 preserve GDB's previous behavior when section offsets are
7493 specified. If this is just a DW_OP_addr then mark this symbol
7496 if (attr_form_is_block (attr)
7497 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
7498 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
7502 SYMBOL_VALUE_ADDRESS (sym) =
7503 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
7504 SYMBOL_CLASS (sym) = LOC_STATIC;
7505 fixup_symbol_section (sym, objfile);
7506 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
7507 SYMBOL_SECTION (sym));
7511 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7512 expression evaluator, and use LOC_COMPUTED only when necessary
7513 (i.e. when the value of a register or memory location is
7514 referenced, or a thread-local block, etc.). Then again, it might
7515 not be worthwhile. I'm assuming that it isn't unless performance
7516 or memory numbers show me otherwise. */
7518 dwarf2_symbol_mark_computed (attr, sym, cu);
7519 SYMBOL_CLASS (sym) = LOC_COMPUTED;
7522 /* Given a pointer to a DWARF information entry, figure out if we need
7523 to make a symbol table entry for it, and if so, create a new entry
7524 and return a pointer to it.
7525 If TYPE is NULL, determine symbol type from the die, otherwise
7526 used the passed type. */
7528 static struct symbol *
7529 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
7531 struct objfile *objfile = cu->objfile;
7532 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7533 struct symbol *sym = NULL;
7535 struct attribute *attr = NULL;
7536 struct attribute *attr2 = NULL;
7539 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7541 if (die->tag != DW_TAG_namespace)
7542 name = dwarf2_linkage_name (die, cu);
7544 name = TYPE_NAME (type);
7548 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
7549 sizeof (struct symbol));
7550 OBJSTAT (objfile, n_syms++);
7551 memset (sym, 0, sizeof (struct symbol));
7553 /* Cache this symbol's name and the name's demangled form (if any). */
7554 SYMBOL_LANGUAGE (sym) = cu->language;
7555 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
7557 /* Default assumptions.
7558 Use the passed type or decode it from the die. */
7559 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7560 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7562 SYMBOL_TYPE (sym) = type;
7564 SYMBOL_TYPE (sym) = die_type (die, cu);
7565 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
7568 SYMBOL_LINE (sym) = DW_UNSND (attr);
7571 attr = dwarf2_attr (die, DW_AT_decl_file, cu);
7574 int file_index = DW_UNSND (attr);
7575 if (cu->line_header == NULL
7576 || file_index > cu->line_header->num_file_names)
7577 complaint (&symfile_complaints,
7578 _("file index out of range"));
7579 else if (file_index > 0)
7581 struct file_entry *fe;
7582 fe = &cu->line_header->file_names[file_index - 1];
7583 SYMBOL_SYMTAB (sym) = fe->symtab;
7590 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
7593 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
7595 SYMBOL_CLASS (sym) = LOC_LABEL;
7597 case DW_TAG_subprogram:
7598 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7600 SYMBOL_CLASS (sym) = LOC_BLOCK;
7601 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7602 if ((attr2 && (DW_UNSND (attr2) != 0))
7603 || cu->language == language_ada)
7605 /* Subprograms marked external are stored as a global symbol.
7606 Ada subprograms, whether marked external or not, are always
7607 stored as a global symbol, because we want to be able to
7608 access them globally. For instance, we want to be able
7609 to break on a nested subprogram without having to
7610 specify the context. */
7611 add_symbol_to_list (sym, &global_symbols);
7615 add_symbol_to_list (sym, cu->list_in_scope);
7618 case DW_TAG_variable:
7619 /* Compilation with minimal debug info may result in variables
7620 with missing type entries. Change the misleading `void' type
7621 to something sensible. */
7622 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
7624 = builtin_type (gdbarch)->nodebug_data_symbol;
7626 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7629 dwarf2_const_value (attr, sym, cu);
7630 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7631 if (attr2 && (DW_UNSND (attr2) != 0))
7632 add_symbol_to_list (sym, &global_symbols);
7634 add_symbol_to_list (sym, cu->list_in_scope);
7637 attr = dwarf2_attr (die, DW_AT_location, cu);
7640 var_decode_location (attr, sym, cu);
7641 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7642 if (attr2 && (DW_UNSND (attr2) != 0))
7643 add_symbol_to_list (sym, &global_symbols);
7645 add_symbol_to_list (sym, cu->list_in_scope);
7649 /* We do not know the address of this symbol.
7650 If it is an external symbol and we have type information
7651 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7652 The address of the variable will then be determined from
7653 the minimal symbol table whenever the variable is
7655 attr2 = dwarf2_attr (die, DW_AT_external, cu);
7656 if (attr2 && (DW_UNSND (attr2) != 0)
7657 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
7659 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
7660 add_symbol_to_list (sym, &global_symbols);
7662 else if (!die_is_declaration (die, cu))
7664 /* Use the default LOC_OPTIMIZED_OUT class. */
7665 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
7666 add_symbol_to_list (sym, cu->list_in_scope);
7670 case DW_TAG_formal_parameter:
7671 SYMBOL_IS_ARGUMENT (sym) = 1;
7672 attr = dwarf2_attr (die, DW_AT_location, cu);
7675 var_decode_location (attr, sym, cu);
7677 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7680 dwarf2_const_value (attr, sym, cu);
7682 add_symbol_to_list (sym, cu->list_in_scope);
7684 case DW_TAG_unspecified_parameters:
7685 /* From varargs functions; gdb doesn't seem to have any
7686 interest in this information, so just ignore it for now.
7689 case DW_TAG_class_type:
7690 case DW_TAG_interface_type:
7691 case DW_TAG_structure_type:
7692 case DW_TAG_union_type:
7693 case DW_TAG_set_type:
7694 case DW_TAG_enumeration_type:
7695 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7696 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
7698 /* Make sure that the symbol includes appropriate enclosing
7699 classes/namespaces in its name. These are calculated in
7700 read_structure_type, and the correct name is saved in
7703 if (cu->language == language_cplus
7704 || cu->language == language_java)
7706 struct type *type = SYMBOL_TYPE (sym);
7708 if (TYPE_TAG_NAME (type) != NULL)
7710 /* FIXME: carlton/2003-11-10: Should this use
7711 SYMBOL_SET_NAMES instead? (The same problem also
7712 arises further down in this function.) */
7713 /* The type's name is already allocated along with
7714 this objfile, so we don't need to duplicate it
7716 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
7721 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7722 really ever be static objects: otherwise, if you try
7723 to, say, break of a class's method and you're in a file
7724 which doesn't mention that class, it won't work unless
7725 the check for all static symbols in lookup_symbol_aux
7726 saves you. See the OtherFileClass tests in
7727 gdb.c++/namespace.exp. */
7729 struct pending **list_to_add;
7731 list_to_add = (cu->list_in_scope == &file_symbols
7732 && (cu->language == language_cplus
7733 || cu->language == language_java)
7734 ? &global_symbols : cu->list_in_scope);
7736 add_symbol_to_list (sym, list_to_add);
7738 /* The semantics of C++ state that "struct foo { ... }" also
7739 defines a typedef for "foo". A Java class declaration also
7740 defines a typedef for the class. */
7741 if (cu->language == language_cplus
7742 || cu->language == language_java
7743 || cu->language == language_ada)
7745 /* The symbol's name is already allocated along with
7746 this objfile, so we don't need to duplicate it for
7748 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
7749 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
7753 case DW_TAG_typedef:
7754 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
7755 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7756 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7757 add_symbol_to_list (sym, cu->list_in_scope);
7759 case DW_TAG_base_type:
7760 case DW_TAG_subrange_type:
7761 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7762 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7763 add_symbol_to_list (sym, cu->list_in_scope);
7765 case DW_TAG_enumerator:
7766 SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
7767 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7770 dwarf2_const_value (attr, sym, cu);
7773 /* NOTE: carlton/2003-11-10: See comment above in the
7774 DW_TAG_class_type, etc. block. */
7776 struct pending **list_to_add;
7778 list_to_add = (cu->list_in_scope == &file_symbols
7779 && (cu->language == language_cplus
7780 || cu->language == language_java)
7781 ? &global_symbols : cu->list_in_scope);
7783 add_symbol_to_list (sym, list_to_add);
7786 case DW_TAG_namespace:
7787 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
7788 add_symbol_to_list (sym, &global_symbols);
7791 /* Not a tag we recognize. Hopefully we aren't processing
7792 trash data, but since we must specifically ignore things
7793 we don't recognize, there is nothing else we should do at
7795 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
7796 dwarf_tag_name (die->tag));
7800 /* For the benefit of old versions of GCC, check for anonymous
7801 namespaces based on the demangled name. */
7802 if (!processing_has_namespace_info
7803 && cu->language == language_cplus
7804 && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
7805 cp_scan_for_anonymous_namespaces (sym);
7810 /* Copy constant value from an attribute to a symbol. */
7813 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
7814 struct dwarf2_cu *cu)
7816 struct objfile *objfile = cu->objfile;
7817 struct comp_unit_head *cu_header = &cu->header;
7818 struct dwarf_block *blk;
7823 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
7824 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
7825 cu_header->addr_size,
7826 TYPE_LENGTH (SYMBOL_TYPE
7828 SYMBOL_VALUE_BYTES (sym) =
7829 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
7830 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7831 it's body - store_unsigned_integer. */
7832 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
7834 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7837 /* DW_STRING is already allocated on the obstack, point directly
7839 SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr);
7840 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7842 case DW_FORM_block1:
7843 case DW_FORM_block2:
7844 case DW_FORM_block4:
7846 blk = DW_BLOCK (attr);
7847 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
7848 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym),
7850 TYPE_LENGTH (SYMBOL_TYPE
7852 SYMBOL_VALUE_BYTES (sym) =
7853 obstack_alloc (&objfile->objfile_obstack, blk->size);
7854 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
7855 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7858 /* The DW_AT_const_value attributes are supposed to carry the
7859 symbol's value "represented as it would be on the target
7860 architecture." By the time we get here, it's already been
7861 converted to host endianness, so we just need to sign- or
7862 zero-extend it as appropriate. */
7864 dwarf2_const_value_data (attr, sym, 8);
7867 dwarf2_const_value_data (attr, sym, 16);
7870 dwarf2_const_value_data (attr, sym, 32);
7873 dwarf2_const_value_data (attr, sym, 64);
7877 SYMBOL_VALUE (sym) = DW_SND (attr);
7878 SYMBOL_CLASS (sym) = LOC_CONST;
7882 SYMBOL_VALUE (sym) = DW_UNSND (attr);
7883 SYMBOL_CLASS (sym) = LOC_CONST;
7887 complaint (&symfile_complaints,
7888 _("unsupported const value attribute form: '%s'"),
7889 dwarf_form_name (attr->form));
7890 SYMBOL_VALUE (sym) = 0;
7891 SYMBOL_CLASS (sym) = LOC_CONST;
7897 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7898 or zero-extend it as appropriate for the symbol's type. */
7900 dwarf2_const_value_data (struct attribute *attr,
7904 LONGEST l = DW_UNSND (attr);
7906 if (bits < sizeof (l) * 8)
7908 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
7909 l &= ((LONGEST) 1 << bits) - 1;
7911 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
7914 SYMBOL_VALUE (sym) = l;
7915 SYMBOL_CLASS (sym) = LOC_CONST;
7919 /* Return the type of the die in question using its DW_AT_type attribute. */
7921 static struct type *
7922 die_type (struct die_info *die, struct dwarf2_cu *cu)
7924 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7926 struct attribute *type_attr;
7927 struct die_info *type_die;
7929 type_attr = dwarf2_attr (die, DW_AT_type, cu);
7932 /* A missing DW_AT_type represents a void type. */
7933 return builtin_type (gdbarch)->builtin_void;
7936 type_die = follow_die_ref (die, type_attr, &cu);
7938 type = tag_type_to_type (type_die, cu);
7941 dump_die_for_error (type_die);
7942 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7948 /* Return the containing type of the die in question using its
7949 DW_AT_containing_type attribute. */
7951 static struct type *
7952 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
7954 struct type *type = NULL;
7955 struct attribute *type_attr;
7956 struct die_info *type_die = NULL;
7958 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
7961 type_die = follow_die_ref (die, type_attr, &cu);
7962 type = tag_type_to_type (type_die, cu);
7967 dump_die_for_error (type_die);
7968 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7974 static struct type *
7975 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
7977 struct type *this_type;
7979 this_type = read_type_die (die, cu);
7982 dump_die_for_error (die);
7983 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7989 static struct type *
7990 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
7992 struct type *this_type;
7994 this_type = get_die_type (die, cu);
8000 case DW_TAG_class_type:
8001 case DW_TAG_interface_type:
8002 case DW_TAG_structure_type:
8003 case DW_TAG_union_type:
8004 this_type = read_structure_type (die, cu);
8006 case DW_TAG_enumeration_type:
8007 this_type = read_enumeration_type (die, cu);
8009 case DW_TAG_subprogram:
8010 case DW_TAG_subroutine_type:
8011 this_type = read_subroutine_type (die, cu);
8013 case DW_TAG_array_type:
8014 this_type = read_array_type (die, cu);
8016 case DW_TAG_set_type:
8017 this_type = read_set_type (die, cu);
8019 case DW_TAG_pointer_type:
8020 this_type = read_tag_pointer_type (die, cu);
8022 case DW_TAG_ptr_to_member_type:
8023 this_type = read_tag_ptr_to_member_type (die, cu);
8025 case DW_TAG_reference_type:
8026 this_type = read_tag_reference_type (die, cu);
8028 case DW_TAG_const_type:
8029 this_type = read_tag_const_type (die, cu);
8031 case DW_TAG_volatile_type:
8032 this_type = read_tag_volatile_type (die, cu);
8034 case DW_TAG_string_type:
8035 this_type = read_tag_string_type (die, cu);
8037 case DW_TAG_typedef:
8038 this_type = read_typedef (die, cu);
8040 case DW_TAG_subrange_type:
8041 this_type = read_subrange_type (die, cu);
8043 case DW_TAG_base_type:
8044 this_type = read_base_type (die, cu);
8046 case DW_TAG_unspecified_type:
8047 this_type = read_unspecified_type (die, cu);
8049 case DW_TAG_namespace:
8050 this_type = read_namespace_type (die, cu);
8053 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
8054 dwarf_tag_name (die->tag));
8061 /* Return the name of the namespace/class that DIE is defined within,
8062 or "" if we can't tell. The caller should not xfree the result.
8064 For example, if we're within the method foo() in the following
8074 then determine_prefix on foo's die will return "N::C". */
8077 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
8079 struct die_info *parent, *spec_die;
8080 struct dwarf2_cu *spec_cu;
8081 struct type *parent_type;
8083 if (cu->language != language_cplus
8084 && cu->language != language_java)
8087 /* We have to be careful in the presence of DW_AT_specification.
8088 For example, with GCC 3.4, given the code
8092 // Definition of N::foo.
8096 then we'll have a tree of DIEs like this:
8098 1: DW_TAG_compile_unit
8099 2: DW_TAG_namespace // N
8100 3: DW_TAG_subprogram // declaration of N::foo
8101 4: DW_TAG_subprogram // definition of N::foo
8102 DW_AT_specification // refers to die #3
8104 Thus, when processing die #4, we have to pretend that we're in
8105 the context of its DW_AT_specification, namely the contex of die
8108 spec_die = die_specification (die, &spec_cu);
8109 if (spec_die == NULL)
8110 parent = die->parent;
8113 parent = spec_die->parent;
8120 switch (parent->tag)
8122 case DW_TAG_namespace:
8123 parent_type = read_type_die (parent, cu);
8124 /* We give a name to even anonymous namespaces. */
8125 return TYPE_TAG_NAME (parent_type);
8126 case DW_TAG_class_type:
8127 case DW_TAG_interface_type:
8128 case DW_TAG_structure_type:
8129 case DW_TAG_union_type:
8130 parent_type = read_type_die (parent, cu);
8131 if (TYPE_TAG_NAME (parent_type) != NULL)
8132 return TYPE_TAG_NAME (parent_type);
8134 /* An anonymous structure is only allowed non-static data
8135 members; no typedefs, no member functions, et cetera.
8136 So it does not need a prefix. */
8139 return determine_prefix (parent, cu);
8143 /* Return a newly-allocated string formed by concatenating PREFIX and
8144 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8145 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8146 perform an obconcat, otherwise allocate storage for the result. The CU argument
8147 is used to determine the language and hence, the appropriate separator. */
8149 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8152 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
8153 struct dwarf2_cu *cu)
8157 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
8159 else if (cu->language == language_java)
8171 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
8172 strcpy (retval, prefix);
8173 strcat (retval, sep);
8174 strcat (retval, suffix);
8179 /* We have an obstack. */
8180 return obconcat (obs, prefix, sep, suffix);
8184 /* Return sibling of die, NULL if no sibling. */
8186 static struct die_info *
8187 sibling_die (struct die_info *die)
8189 return die->sibling;
8192 /* Get linkage name of a die, return NULL if not found. */
8195 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
8197 struct attribute *attr;
8199 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
8200 if (attr && DW_STRING (attr))
8201 return DW_STRING (attr);
8202 attr = dwarf2_attr (die, DW_AT_name, cu);
8203 if (attr && DW_STRING (attr))
8204 return DW_STRING (attr);
8208 /* Get name of a die, return NULL if not found. */
8211 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
8213 struct attribute *attr;
8215 attr = dwarf2_attr (die, DW_AT_name, cu);
8216 if (attr && DW_STRING (attr))
8217 return DW_STRING (attr);
8221 /* Return the die that this die in an extension of, or NULL if there
8222 is none. *EXT_CU is the CU containing DIE on input, and the CU
8223 containing the return value on output. */
8225 static struct die_info *
8226 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
8228 struct attribute *attr;
8230 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
8234 return follow_die_ref (die, attr, ext_cu);
8237 /* Convert a DIE tag into its string name. */
8240 dwarf_tag_name (unsigned tag)
8244 case DW_TAG_padding:
8245 return "DW_TAG_padding";
8246 case DW_TAG_array_type:
8247 return "DW_TAG_array_type";
8248 case DW_TAG_class_type:
8249 return "DW_TAG_class_type";
8250 case DW_TAG_entry_point:
8251 return "DW_TAG_entry_point";
8252 case DW_TAG_enumeration_type:
8253 return "DW_TAG_enumeration_type";
8254 case DW_TAG_formal_parameter:
8255 return "DW_TAG_formal_parameter";
8256 case DW_TAG_imported_declaration:
8257 return "DW_TAG_imported_declaration";
8259 return "DW_TAG_label";
8260 case DW_TAG_lexical_block:
8261 return "DW_TAG_lexical_block";
8263 return "DW_TAG_member";
8264 case DW_TAG_pointer_type:
8265 return "DW_TAG_pointer_type";
8266 case DW_TAG_reference_type:
8267 return "DW_TAG_reference_type";
8268 case DW_TAG_compile_unit:
8269 return "DW_TAG_compile_unit";
8270 case DW_TAG_string_type:
8271 return "DW_TAG_string_type";
8272 case DW_TAG_structure_type:
8273 return "DW_TAG_structure_type";
8274 case DW_TAG_subroutine_type:
8275 return "DW_TAG_subroutine_type";
8276 case DW_TAG_typedef:
8277 return "DW_TAG_typedef";
8278 case DW_TAG_union_type:
8279 return "DW_TAG_union_type";
8280 case DW_TAG_unspecified_parameters:
8281 return "DW_TAG_unspecified_parameters";
8282 case DW_TAG_variant:
8283 return "DW_TAG_variant";
8284 case DW_TAG_common_block:
8285 return "DW_TAG_common_block";
8286 case DW_TAG_common_inclusion:
8287 return "DW_TAG_common_inclusion";
8288 case DW_TAG_inheritance:
8289 return "DW_TAG_inheritance";
8290 case DW_TAG_inlined_subroutine:
8291 return "DW_TAG_inlined_subroutine";
8293 return "DW_TAG_module";
8294 case DW_TAG_ptr_to_member_type:
8295 return "DW_TAG_ptr_to_member_type";
8296 case DW_TAG_set_type:
8297 return "DW_TAG_set_type";
8298 case DW_TAG_subrange_type:
8299 return "DW_TAG_subrange_type";
8300 case DW_TAG_with_stmt:
8301 return "DW_TAG_with_stmt";
8302 case DW_TAG_access_declaration:
8303 return "DW_TAG_access_declaration";
8304 case DW_TAG_base_type:
8305 return "DW_TAG_base_type";
8306 case DW_TAG_catch_block:
8307 return "DW_TAG_catch_block";
8308 case DW_TAG_const_type:
8309 return "DW_TAG_const_type";
8310 case DW_TAG_constant:
8311 return "DW_TAG_constant";
8312 case DW_TAG_enumerator:
8313 return "DW_TAG_enumerator";
8314 case DW_TAG_file_type:
8315 return "DW_TAG_file_type";
8317 return "DW_TAG_friend";
8318 case DW_TAG_namelist:
8319 return "DW_TAG_namelist";
8320 case DW_TAG_namelist_item:
8321 return "DW_TAG_namelist_item";
8322 case DW_TAG_packed_type:
8323 return "DW_TAG_packed_type";
8324 case DW_TAG_subprogram:
8325 return "DW_TAG_subprogram";
8326 case DW_TAG_template_type_param:
8327 return "DW_TAG_template_type_param";
8328 case DW_TAG_template_value_param:
8329 return "DW_TAG_template_value_param";
8330 case DW_TAG_thrown_type:
8331 return "DW_TAG_thrown_type";
8332 case DW_TAG_try_block:
8333 return "DW_TAG_try_block";
8334 case DW_TAG_variant_part:
8335 return "DW_TAG_variant_part";
8336 case DW_TAG_variable:
8337 return "DW_TAG_variable";
8338 case DW_TAG_volatile_type:
8339 return "DW_TAG_volatile_type";
8340 case DW_TAG_dwarf_procedure:
8341 return "DW_TAG_dwarf_procedure";
8342 case DW_TAG_restrict_type:
8343 return "DW_TAG_restrict_type";
8344 case DW_TAG_interface_type:
8345 return "DW_TAG_interface_type";
8346 case DW_TAG_namespace:
8347 return "DW_TAG_namespace";
8348 case DW_TAG_imported_module:
8349 return "DW_TAG_imported_module";
8350 case DW_TAG_unspecified_type:
8351 return "DW_TAG_unspecified_type";
8352 case DW_TAG_partial_unit:
8353 return "DW_TAG_partial_unit";
8354 case DW_TAG_imported_unit:
8355 return "DW_TAG_imported_unit";
8356 case DW_TAG_condition:
8357 return "DW_TAG_condition";
8358 case DW_TAG_shared_type:
8359 return "DW_TAG_shared_type";
8360 case DW_TAG_MIPS_loop:
8361 return "DW_TAG_MIPS_loop";
8362 case DW_TAG_HP_array_descriptor:
8363 return "DW_TAG_HP_array_descriptor";
8364 case DW_TAG_format_label:
8365 return "DW_TAG_format_label";
8366 case DW_TAG_function_template:
8367 return "DW_TAG_function_template";
8368 case DW_TAG_class_template:
8369 return "DW_TAG_class_template";
8370 case DW_TAG_GNU_BINCL:
8371 return "DW_TAG_GNU_BINCL";
8372 case DW_TAG_GNU_EINCL:
8373 return "DW_TAG_GNU_EINCL";
8374 case DW_TAG_upc_shared_type:
8375 return "DW_TAG_upc_shared_type";
8376 case DW_TAG_upc_strict_type:
8377 return "DW_TAG_upc_strict_type";
8378 case DW_TAG_upc_relaxed_type:
8379 return "DW_TAG_upc_relaxed_type";
8380 case DW_TAG_PGI_kanji_type:
8381 return "DW_TAG_PGI_kanji_type";
8382 case DW_TAG_PGI_interface_block:
8383 return "DW_TAG_PGI_interface_block";
8385 return "DW_TAG_<unknown>";
8389 /* Convert a DWARF attribute code into its string name. */
8392 dwarf_attr_name (unsigned attr)
8397 return "DW_AT_sibling";
8398 case DW_AT_location:
8399 return "DW_AT_location";
8401 return "DW_AT_name";
8402 case DW_AT_ordering:
8403 return "DW_AT_ordering";
8404 case DW_AT_subscr_data:
8405 return "DW_AT_subscr_data";
8406 case DW_AT_byte_size:
8407 return "DW_AT_byte_size";
8408 case DW_AT_bit_offset:
8409 return "DW_AT_bit_offset";
8410 case DW_AT_bit_size:
8411 return "DW_AT_bit_size";
8412 case DW_AT_element_list:
8413 return "DW_AT_element_list";
8414 case DW_AT_stmt_list:
8415 return "DW_AT_stmt_list";
8417 return "DW_AT_low_pc";
8419 return "DW_AT_high_pc";
8420 case DW_AT_language:
8421 return "DW_AT_language";
8423 return "DW_AT_member";
8425 return "DW_AT_discr";
8426 case DW_AT_discr_value:
8427 return "DW_AT_discr_value";
8428 case DW_AT_visibility:
8429 return "DW_AT_visibility";
8431 return "DW_AT_import";
8432 case DW_AT_string_length:
8433 return "DW_AT_string_length";
8434 case DW_AT_common_reference:
8435 return "DW_AT_common_reference";
8436 case DW_AT_comp_dir:
8437 return "DW_AT_comp_dir";
8438 case DW_AT_const_value:
8439 return "DW_AT_const_value";
8440 case DW_AT_containing_type:
8441 return "DW_AT_containing_type";
8442 case DW_AT_default_value:
8443 return "DW_AT_default_value";
8445 return "DW_AT_inline";
8446 case DW_AT_is_optional:
8447 return "DW_AT_is_optional";
8448 case DW_AT_lower_bound:
8449 return "DW_AT_lower_bound";
8450 case DW_AT_producer:
8451 return "DW_AT_producer";
8452 case DW_AT_prototyped:
8453 return "DW_AT_prototyped";
8454 case DW_AT_return_addr:
8455 return "DW_AT_return_addr";
8456 case DW_AT_start_scope:
8457 return "DW_AT_start_scope";
8458 case DW_AT_bit_stride:
8459 return "DW_AT_bit_stride";
8460 case DW_AT_upper_bound:
8461 return "DW_AT_upper_bound";
8462 case DW_AT_abstract_origin:
8463 return "DW_AT_abstract_origin";
8464 case DW_AT_accessibility:
8465 return "DW_AT_accessibility";
8466 case DW_AT_address_class:
8467 return "DW_AT_address_class";
8468 case DW_AT_artificial:
8469 return "DW_AT_artificial";
8470 case DW_AT_base_types:
8471 return "DW_AT_base_types";
8472 case DW_AT_calling_convention:
8473 return "DW_AT_calling_convention";
8475 return "DW_AT_count";
8476 case DW_AT_data_member_location:
8477 return "DW_AT_data_member_location";
8478 case DW_AT_decl_column:
8479 return "DW_AT_decl_column";
8480 case DW_AT_decl_file:
8481 return "DW_AT_decl_file";
8482 case DW_AT_decl_line:
8483 return "DW_AT_decl_line";
8484 case DW_AT_declaration:
8485 return "DW_AT_declaration";
8486 case DW_AT_discr_list:
8487 return "DW_AT_discr_list";
8488 case DW_AT_encoding:
8489 return "DW_AT_encoding";
8490 case DW_AT_external:
8491 return "DW_AT_external";
8492 case DW_AT_frame_base:
8493 return "DW_AT_frame_base";
8495 return "DW_AT_friend";
8496 case DW_AT_identifier_case:
8497 return "DW_AT_identifier_case";
8498 case DW_AT_macro_info:
8499 return "DW_AT_macro_info";
8500 case DW_AT_namelist_items:
8501 return "DW_AT_namelist_items";
8502 case DW_AT_priority:
8503 return "DW_AT_priority";
8505 return "DW_AT_segment";
8506 case DW_AT_specification:
8507 return "DW_AT_specification";
8508 case DW_AT_static_link:
8509 return "DW_AT_static_link";
8511 return "DW_AT_type";
8512 case DW_AT_use_location:
8513 return "DW_AT_use_location";
8514 case DW_AT_variable_parameter:
8515 return "DW_AT_variable_parameter";
8516 case DW_AT_virtuality:
8517 return "DW_AT_virtuality";
8518 case DW_AT_vtable_elem_location:
8519 return "DW_AT_vtable_elem_location";
8520 /* DWARF 3 values. */
8521 case DW_AT_allocated:
8522 return "DW_AT_allocated";
8523 case DW_AT_associated:
8524 return "DW_AT_associated";
8525 case DW_AT_data_location:
8526 return "DW_AT_data_location";
8527 case DW_AT_byte_stride:
8528 return "DW_AT_byte_stride";
8529 case DW_AT_entry_pc:
8530 return "DW_AT_entry_pc";
8531 case DW_AT_use_UTF8:
8532 return "DW_AT_use_UTF8";
8533 case DW_AT_extension:
8534 return "DW_AT_extension";
8536 return "DW_AT_ranges";
8537 case DW_AT_trampoline:
8538 return "DW_AT_trampoline";
8539 case DW_AT_call_column:
8540 return "DW_AT_call_column";
8541 case DW_AT_call_file:
8542 return "DW_AT_call_file";
8543 case DW_AT_call_line:
8544 return "DW_AT_call_line";
8545 case DW_AT_description:
8546 return "DW_AT_description";
8547 case DW_AT_binary_scale:
8548 return "DW_AT_binary_scale";
8549 case DW_AT_decimal_scale:
8550 return "DW_AT_decimal_scale";
8552 return "DW_AT_small";
8553 case DW_AT_decimal_sign:
8554 return "DW_AT_decimal_sign";
8555 case DW_AT_digit_count:
8556 return "DW_AT_digit_count";
8557 case DW_AT_picture_string:
8558 return "DW_AT_picture_string";
8560 return "DW_AT_mutable";
8561 case DW_AT_threads_scaled:
8562 return "DW_AT_threads_scaled";
8563 case DW_AT_explicit:
8564 return "DW_AT_explicit";
8565 case DW_AT_object_pointer:
8566 return "DW_AT_object_pointer";
8567 case DW_AT_endianity:
8568 return "DW_AT_endianity";
8569 case DW_AT_elemental:
8570 return "DW_AT_elemental";
8572 return "DW_AT_pure";
8573 case DW_AT_recursive:
8574 return "DW_AT_recursive";
8575 /* SGI/MIPS extensions. */
8576 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8577 case DW_AT_MIPS_fde:
8578 return "DW_AT_MIPS_fde";
8580 case DW_AT_MIPS_loop_begin:
8581 return "DW_AT_MIPS_loop_begin";
8582 case DW_AT_MIPS_tail_loop_begin:
8583 return "DW_AT_MIPS_tail_loop_begin";
8584 case DW_AT_MIPS_epilog_begin:
8585 return "DW_AT_MIPS_epilog_begin";
8586 case DW_AT_MIPS_loop_unroll_factor:
8587 return "DW_AT_MIPS_loop_unroll_factor";
8588 case DW_AT_MIPS_software_pipeline_depth:
8589 return "DW_AT_MIPS_software_pipeline_depth";
8590 case DW_AT_MIPS_linkage_name:
8591 return "DW_AT_MIPS_linkage_name";
8592 case DW_AT_MIPS_stride:
8593 return "DW_AT_MIPS_stride";
8594 case DW_AT_MIPS_abstract_name:
8595 return "DW_AT_MIPS_abstract_name";
8596 case DW_AT_MIPS_clone_origin:
8597 return "DW_AT_MIPS_clone_origin";
8598 case DW_AT_MIPS_has_inlines:
8599 return "DW_AT_MIPS_has_inlines";
8600 /* HP extensions. */
8601 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8602 case DW_AT_HP_block_index:
8603 return "DW_AT_HP_block_index";
8605 case DW_AT_HP_unmodifiable:
8606 return "DW_AT_HP_unmodifiable";
8607 case DW_AT_HP_actuals_stmt_list:
8608 return "DW_AT_HP_actuals_stmt_list";
8609 case DW_AT_HP_proc_per_section:
8610 return "DW_AT_HP_proc_per_section";
8611 case DW_AT_HP_raw_data_ptr:
8612 return "DW_AT_HP_raw_data_ptr";
8613 case DW_AT_HP_pass_by_reference:
8614 return "DW_AT_HP_pass_by_reference";
8615 case DW_AT_HP_opt_level:
8616 return "DW_AT_HP_opt_level";
8617 case DW_AT_HP_prof_version_id:
8618 return "DW_AT_HP_prof_version_id";
8619 case DW_AT_HP_opt_flags:
8620 return "DW_AT_HP_opt_flags";
8621 case DW_AT_HP_cold_region_low_pc:
8622 return "DW_AT_HP_cold_region_low_pc";
8623 case DW_AT_HP_cold_region_high_pc:
8624 return "DW_AT_HP_cold_region_high_pc";
8625 case DW_AT_HP_all_variables_modifiable:
8626 return "DW_AT_HP_all_variables_modifiable";
8627 case DW_AT_HP_linkage_name:
8628 return "DW_AT_HP_linkage_name";
8629 case DW_AT_HP_prof_flags:
8630 return "DW_AT_HP_prof_flags";
8631 /* GNU extensions. */
8632 case DW_AT_sf_names:
8633 return "DW_AT_sf_names";
8634 case DW_AT_src_info:
8635 return "DW_AT_src_info";
8636 case DW_AT_mac_info:
8637 return "DW_AT_mac_info";
8638 case DW_AT_src_coords:
8639 return "DW_AT_src_coords";
8640 case DW_AT_body_begin:
8641 return "DW_AT_body_begin";
8642 case DW_AT_body_end:
8643 return "DW_AT_body_end";
8644 case DW_AT_GNU_vector:
8645 return "DW_AT_GNU_vector";
8646 /* VMS extensions. */
8647 case DW_AT_VMS_rtnbeg_pd_address:
8648 return "DW_AT_VMS_rtnbeg_pd_address";
8649 /* UPC extension. */
8650 case DW_AT_upc_threads_scaled:
8651 return "DW_AT_upc_threads_scaled";
8652 /* PGI (STMicroelectronics) extensions. */
8653 case DW_AT_PGI_lbase:
8654 return "DW_AT_PGI_lbase";
8655 case DW_AT_PGI_soffset:
8656 return "DW_AT_PGI_soffset";
8657 case DW_AT_PGI_lstride:
8658 return "DW_AT_PGI_lstride";
8660 return "DW_AT_<unknown>";
8664 /* Convert a DWARF value form code into its string name. */
8667 dwarf_form_name (unsigned form)
8672 return "DW_FORM_addr";
8673 case DW_FORM_block2:
8674 return "DW_FORM_block2";
8675 case DW_FORM_block4:
8676 return "DW_FORM_block4";
8678 return "DW_FORM_data2";
8680 return "DW_FORM_data4";
8682 return "DW_FORM_data8";
8683 case DW_FORM_string:
8684 return "DW_FORM_string";
8686 return "DW_FORM_block";
8687 case DW_FORM_block1:
8688 return "DW_FORM_block1";
8690 return "DW_FORM_data1";
8692 return "DW_FORM_flag";
8694 return "DW_FORM_sdata";
8696 return "DW_FORM_strp";
8698 return "DW_FORM_udata";
8699 case DW_FORM_ref_addr:
8700 return "DW_FORM_ref_addr";
8702 return "DW_FORM_ref1";
8704 return "DW_FORM_ref2";
8706 return "DW_FORM_ref4";
8708 return "DW_FORM_ref8";
8709 case DW_FORM_ref_udata:
8710 return "DW_FORM_ref_udata";
8711 case DW_FORM_indirect:
8712 return "DW_FORM_indirect";
8714 return "DW_FORM_<unknown>";
8718 /* Convert a DWARF stack opcode into its string name. */
8721 dwarf_stack_op_name (unsigned op)
8726 return "DW_OP_addr";
8728 return "DW_OP_deref";
8730 return "DW_OP_const1u";
8732 return "DW_OP_const1s";
8734 return "DW_OP_const2u";
8736 return "DW_OP_const2s";
8738 return "DW_OP_const4u";
8740 return "DW_OP_const4s";
8742 return "DW_OP_const8u";
8744 return "DW_OP_const8s";
8746 return "DW_OP_constu";
8748 return "DW_OP_consts";
8752 return "DW_OP_drop";
8754 return "DW_OP_over";
8756 return "DW_OP_pick";
8758 return "DW_OP_swap";
8762 return "DW_OP_xderef";
8770 return "DW_OP_minus";
8782 return "DW_OP_plus";
8783 case DW_OP_plus_uconst:
8784 return "DW_OP_plus_uconst";
8790 return "DW_OP_shra";
8808 return "DW_OP_skip";
8810 return "DW_OP_lit0";
8812 return "DW_OP_lit1";
8814 return "DW_OP_lit2";
8816 return "DW_OP_lit3";
8818 return "DW_OP_lit4";
8820 return "DW_OP_lit5";
8822 return "DW_OP_lit6";
8824 return "DW_OP_lit7";
8826 return "DW_OP_lit8";
8828 return "DW_OP_lit9";
8830 return "DW_OP_lit10";
8832 return "DW_OP_lit11";
8834 return "DW_OP_lit12";
8836 return "DW_OP_lit13";
8838 return "DW_OP_lit14";
8840 return "DW_OP_lit15";
8842 return "DW_OP_lit16";
8844 return "DW_OP_lit17";
8846 return "DW_OP_lit18";
8848 return "DW_OP_lit19";
8850 return "DW_OP_lit20";
8852 return "DW_OP_lit21";
8854 return "DW_OP_lit22";
8856 return "DW_OP_lit23";
8858 return "DW_OP_lit24";
8860 return "DW_OP_lit25";
8862 return "DW_OP_lit26";
8864 return "DW_OP_lit27";
8866 return "DW_OP_lit28";
8868 return "DW_OP_lit29";
8870 return "DW_OP_lit30";
8872 return "DW_OP_lit31";
8874 return "DW_OP_reg0";
8876 return "DW_OP_reg1";
8878 return "DW_OP_reg2";
8880 return "DW_OP_reg3";
8882 return "DW_OP_reg4";
8884 return "DW_OP_reg5";
8886 return "DW_OP_reg6";
8888 return "DW_OP_reg7";
8890 return "DW_OP_reg8";
8892 return "DW_OP_reg9";
8894 return "DW_OP_reg10";
8896 return "DW_OP_reg11";
8898 return "DW_OP_reg12";
8900 return "DW_OP_reg13";
8902 return "DW_OP_reg14";
8904 return "DW_OP_reg15";
8906 return "DW_OP_reg16";
8908 return "DW_OP_reg17";
8910 return "DW_OP_reg18";
8912 return "DW_OP_reg19";
8914 return "DW_OP_reg20";
8916 return "DW_OP_reg21";
8918 return "DW_OP_reg22";
8920 return "DW_OP_reg23";
8922 return "DW_OP_reg24";
8924 return "DW_OP_reg25";
8926 return "DW_OP_reg26";
8928 return "DW_OP_reg27";
8930 return "DW_OP_reg28";
8932 return "DW_OP_reg29";
8934 return "DW_OP_reg30";
8936 return "DW_OP_reg31";
8938 return "DW_OP_breg0";
8940 return "DW_OP_breg1";
8942 return "DW_OP_breg2";
8944 return "DW_OP_breg3";
8946 return "DW_OP_breg4";
8948 return "DW_OP_breg5";
8950 return "DW_OP_breg6";
8952 return "DW_OP_breg7";
8954 return "DW_OP_breg8";
8956 return "DW_OP_breg9";
8958 return "DW_OP_breg10";
8960 return "DW_OP_breg11";
8962 return "DW_OP_breg12";
8964 return "DW_OP_breg13";
8966 return "DW_OP_breg14";
8968 return "DW_OP_breg15";
8970 return "DW_OP_breg16";
8972 return "DW_OP_breg17";
8974 return "DW_OP_breg18";
8976 return "DW_OP_breg19";
8978 return "DW_OP_breg20";
8980 return "DW_OP_breg21";
8982 return "DW_OP_breg22";
8984 return "DW_OP_breg23";
8986 return "DW_OP_breg24";
8988 return "DW_OP_breg25";
8990 return "DW_OP_breg26";
8992 return "DW_OP_breg27";
8994 return "DW_OP_breg28";
8996 return "DW_OP_breg29";
8998 return "DW_OP_breg30";
9000 return "DW_OP_breg31";
9002 return "DW_OP_regx";
9004 return "DW_OP_fbreg";
9006 return "DW_OP_bregx";
9008 return "DW_OP_piece";
9009 case DW_OP_deref_size:
9010 return "DW_OP_deref_size";
9011 case DW_OP_xderef_size:
9012 return "DW_OP_xderef_size";
9015 /* DWARF 3 extensions. */
9016 case DW_OP_push_object_address:
9017 return "DW_OP_push_object_address";
9019 return "DW_OP_call2";
9021 return "DW_OP_call4";
9022 case DW_OP_call_ref:
9023 return "DW_OP_call_ref";
9024 /* GNU extensions. */
9025 case DW_OP_form_tls_address:
9026 return "DW_OP_form_tls_address";
9027 case DW_OP_call_frame_cfa:
9028 return "DW_OP_call_frame_cfa";
9029 case DW_OP_bit_piece:
9030 return "DW_OP_bit_piece";
9031 case DW_OP_GNU_push_tls_address:
9032 return "DW_OP_GNU_push_tls_address";
9033 case DW_OP_GNU_uninit:
9034 return "DW_OP_GNU_uninit";
9035 /* HP extensions. */
9036 case DW_OP_HP_is_value:
9037 return "DW_OP_HP_is_value";
9038 case DW_OP_HP_fltconst4:
9039 return "DW_OP_HP_fltconst4";
9040 case DW_OP_HP_fltconst8:
9041 return "DW_OP_HP_fltconst8";
9042 case DW_OP_HP_mod_range:
9043 return "DW_OP_HP_mod_range";
9044 case DW_OP_HP_unmod_range:
9045 return "DW_OP_HP_unmod_range";
9047 return "DW_OP_HP_tls";
9049 return "OP_<unknown>";
9054 dwarf_bool_name (unsigned mybool)
9062 /* Convert a DWARF type code into its string name. */
9065 dwarf_type_encoding_name (unsigned enc)
9070 return "DW_ATE_void";
9071 case DW_ATE_address:
9072 return "DW_ATE_address";
9073 case DW_ATE_boolean:
9074 return "DW_ATE_boolean";
9075 case DW_ATE_complex_float:
9076 return "DW_ATE_complex_float";
9078 return "DW_ATE_float";
9080 return "DW_ATE_signed";
9081 case DW_ATE_signed_char:
9082 return "DW_ATE_signed_char";
9083 case DW_ATE_unsigned:
9084 return "DW_ATE_unsigned";
9085 case DW_ATE_unsigned_char:
9086 return "DW_ATE_unsigned_char";
9088 case DW_ATE_imaginary_float:
9089 return "DW_ATE_imaginary_float";
9090 case DW_ATE_packed_decimal:
9091 return "DW_ATE_packed_decimal";
9092 case DW_ATE_numeric_string:
9093 return "DW_ATE_numeric_string";
9095 return "DW_ATE_edited";
9096 case DW_ATE_signed_fixed:
9097 return "DW_ATE_signed_fixed";
9098 case DW_ATE_unsigned_fixed:
9099 return "DW_ATE_unsigned_fixed";
9100 case DW_ATE_decimal_float:
9101 return "DW_ATE_decimal_float";
9102 /* HP extensions. */
9103 case DW_ATE_HP_float80:
9104 return "DW_ATE_HP_float80";
9105 case DW_ATE_HP_complex_float80:
9106 return "DW_ATE_HP_complex_float80";
9107 case DW_ATE_HP_float128:
9108 return "DW_ATE_HP_float128";
9109 case DW_ATE_HP_complex_float128:
9110 return "DW_ATE_HP_complex_float128";
9111 case DW_ATE_HP_floathpintel:
9112 return "DW_ATE_HP_floathpintel";
9113 case DW_ATE_HP_imaginary_float80:
9114 return "DW_ATE_HP_imaginary_float80";
9115 case DW_ATE_HP_imaginary_float128:
9116 return "DW_ATE_HP_imaginary_float128";
9118 return "DW_ATE_<unknown>";
9122 /* Convert a DWARF call frame info operation to its string name. */
9126 dwarf_cfi_name (unsigned cfi_opc)
9130 case DW_CFA_advance_loc:
9131 return "DW_CFA_advance_loc";
9133 return "DW_CFA_offset";
9134 case DW_CFA_restore:
9135 return "DW_CFA_restore";
9137 return "DW_CFA_nop";
9138 case DW_CFA_set_loc:
9139 return "DW_CFA_set_loc";
9140 case DW_CFA_advance_loc1:
9141 return "DW_CFA_advance_loc1";
9142 case DW_CFA_advance_loc2:
9143 return "DW_CFA_advance_loc2";
9144 case DW_CFA_advance_loc4:
9145 return "DW_CFA_advance_loc4";
9146 case DW_CFA_offset_extended:
9147 return "DW_CFA_offset_extended";
9148 case DW_CFA_restore_extended:
9149 return "DW_CFA_restore_extended";
9150 case DW_CFA_undefined:
9151 return "DW_CFA_undefined";
9152 case DW_CFA_same_value:
9153 return "DW_CFA_same_value";
9154 case DW_CFA_register:
9155 return "DW_CFA_register";
9156 case DW_CFA_remember_state:
9157 return "DW_CFA_remember_state";
9158 case DW_CFA_restore_state:
9159 return "DW_CFA_restore_state";
9160 case DW_CFA_def_cfa:
9161 return "DW_CFA_def_cfa";
9162 case DW_CFA_def_cfa_register:
9163 return "DW_CFA_def_cfa_register";
9164 case DW_CFA_def_cfa_offset:
9165 return "DW_CFA_def_cfa_offset";
9167 case DW_CFA_def_cfa_expression:
9168 return "DW_CFA_def_cfa_expression";
9169 case DW_CFA_expression:
9170 return "DW_CFA_expression";
9171 case DW_CFA_offset_extended_sf:
9172 return "DW_CFA_offset_extended_sf";
9173 case DW_CFA_def_cfa_sf:
9174 return "DW_CFA_def_cfa_sf";
9175 case DW_CFA_def_cfa_offset_sf:
9176 return "DW_CFA_def_cfa_offset_sf";
9177 case DW_CFA_val_offset:
9178 return "DW_CFA_val_offset";
9179 case DW_CFA_val_offset_sf:
9180 return "DW_CFA_val_offset_sf";
9181 case DW_CFA_val_expression:
9182 return "DW_CFA_val_expression";
9183 /* SGI/MIPS specific. */
9184 case DW_CFA_MIPS_advance_loc8:
9185 return "DW_CFA_MIPS_advance_loc8";
9186 /* GNU extensions. */
9187 case DW_CFA_GNU_window_save:
9188 return "DW_CFA_GNU_window_save";
9189 case DW_CFA_GNU_args_size:
9190 return "DW_CFA_GNU_args_size";
9191 case DW_CFA_GNU_negative_offset_extended:
9192 return "DW_CFA_GNU_negative_offset_extended";
9194 return "DW_CFA_<unknown>";
9200 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
9204 print_spaces (indent, f);
9205 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
9206 dwarf_tag_name (die->tag), die->abbrev, die->offset);
9208 if (die->parent != NULL)
9210 print_spaces (indent, f);
9211 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
9212 die->parent->offset);
9215 print_spaces (indent, f);
9216 fprintf_unfiltered (f, " has children: %s\n",
9217 dwarf_bool_name (die->child != NULL));
9219 print_spaces (indent, f);
9220 fprintf_unfiltered (f, " attributes:\n");
9222 for (i = 0; i < die->num_attrs; ++i)
9224 print_spaces (indent, f);
9225 fprintf_unfiltered (f, " %s (%s) ",
9226 dwarf_attr_name (die->attrs[i].name),
9227 dwarf_form_name (die->attrs[i].form));
9229 switch (die->attrs[i].form)
9231 case DW_FORM_ref_addr:
9233 fprintf_unfiltered (f, "address: ");
9234 fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), f);
9236 case DW_FORM_block2:
9237 case DW_FORM_block4:
9239 case DW_FORM_block1:
9240 fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
9245 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
9246 (long) (DW_ADDR (&die->attrs[i])));
9254 fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
9256 case DW_FORM_string:
9258 fprintf_unfiltered (f, "string: \"%s\"",
9259 DW_STRING (&die->attrs[i])
9260 ? DW_STRING (&die->attrs[i]) : "");
9263 if (DW_UNSND (&die->attrs[i]))
9264 fprintf_unfiltered (f, "flag: TRUE");
9266 fprintf_unfiltered (f, "flag: FALSE");
9268 case DW_FORM_indirect:
9269 /* the reader will have reduced the indirect form to
9270 the "base form" so this form should not occur */
9271 fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect");
9274 fprintf_unfiltered (f, "unsupported attribute form: %d.",
9275 die->attrs[i].form);
9278 fprintf_unfiltered (f, "\n");
9283 dump_die_for_error (struct die_info *die)
9285 dump_die_shallow (gdb_stderr, 0, die);
9289 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
9291 int indent = level * 4;
9293 gdb_assert (die != NULL);
9295 if (level >= max_level)
9298 dump_die_shallow (f, indent, die);
9300 if (die->child != NULL)
9302 print_spaces (indent, f);
9303 fprintf_unfiltered (f, " Children:");
9304 if (level + 1 < max_level)
9306 fprintf_unfiltered (f, "\n");
9307 dump_die_1 (f, level + 1, max_level, die->child);
9311 fprintf_unfiltered (f, " [not printed, max nesting level reached]\n");
9315 if (die->sibling != NULL && level > 0)
9317 dump_die_1 (f, level, max_level, die->sibling);
9321 /* This is called from the pdie macro in gdbinit.in.
9322 It's not static so gcc will keep a copy callable from gdb. */
9325 dump_die (struct die_info *die, int max_level)
9327 dump_die_1 (gdb_stdlog, 0, max_level, die);
9331 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
9335 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
9341 dwarf2_get_ref_die_offset (struct attribute *attr)
9343 unsigned int result = 0;
9347 case DW_FORM_ref_addr:
9352 case DW_FORM_ref_udata:
9353 result = DW_ADDR (attr);
9356 complaint (&symfile_complaints,
9357 _("unsupported die ref attribute form: '%s'"),
9358 dwarf_form_name (attr->form));
9363 /* Return the constant value held by the given attribute. Return -1
9364 if the value held by the attribute is not constant. */
9367 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
9369 if (attr->form == DW_FORM_sdata)
9370 return DW_SND (attr);
9371 else if (attr->form == DW_FORM_udata
9372 || attr->form == DW_FORM_data1
9373 || attr->form == DW_FORM_data2
9374 || attr->form == DW_FORM_data4
9375 || attr->form == DW_FORM_data8)
9376 return DW_UNSND (attr);
9379 complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"),
9380 dwarf_form_name (attr->form));
9381 return default_value;
9385 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9386 unit and add it to our queue. */
9389 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
9390 struct dwarf2_per_cu_data *per_cu)
9392 /* Mark the dependence relation so that we don't flush PER_CU
9394 dwarf2_add_dependence (this_cu, per_cu);
9396 /* If it's already on the queue, we have nothing to do. */
9400 /* If the compilation unit is already loaded, just mark it as
9402 if (per_cu->cu != NULL)
9404 per_cu->cu->last_used = 0;
9408 /* Add it to the queue. */
9409 queue_comp_unit (per_cu, this_cu->objfile);
9412 static struct die_info *
9413 follow_die_ref (struct die_info *src_die, struct attribute *attr,
9414 struct dwarf2_cu **ref_cu)
9416 struct die_info *die;
9417 unsigned int offset;
9418 struct die_info temp_die;
9419 struct dwarf2_cu *target_cu, *cu = *ref_cu;
9421 offset = dwarf2_get_ref_die_offset (attr);
9423 if (! offset_in_cu_p (&cu->header, offset))
9425 struct dwarf2_per_cu_data *per_cu;
9426 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9428 /* If necessary, add it to the queue and load its DIEs. */
9429 maybe_queue_comp_unit (cu, per_cu);
9431 target_cu = per_cu->cu;
9436 *ref_cu = target_cu;
9437 temp_die.offset = offset;
9438 die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
9442 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9443 "at 0x%lx [in module %s]"),
9444 (long) offset, (long) src_die->offset, cu->objfile->name);
9447 /* Decode simple location descriptions.
9448 Given a pointer to a dwarf block that defines a location, compute
9449 the location and return the value.
9451 NOTE drow/2003-11-18: This function is called in two situations
9452 now: for the address of static or global variables (partial symbols
9453 only) and for offsets into structures which are expected to be
9454 (more or less) constant. The partial symbol case should go away,
9455 and only the constant case should remain. That will let this
9456 function complain more accurately. A few special modes are allowed
9457 without complaint for global variables (for instance, global
9458 register values and thread-local values).
9460 A location description containing no operations indicates that the
9461 object is optimized out. The return value is 0 for that case.
9462 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9463 callers will only want a very basic result and this can become a
9466 Note that stack[0] is unused except as a default error return.
9467 Note that stack overflow is not yet handled. */
9470 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
9472 struct objfile *objfile = cu->objfile;
9473 struct comp_unit_head *cu_header = &cu->header;
9475 int size = blk->size;
9476 gdb_byte *data = blk->data;
9477 CORE_ADDR stack[64];
9479 unsigned int bytes_read, unsnd;
9523 stack[++stacki] = op - DW_OP_lit0;
9558 stack[++stacki] = op - DW_OP_reg0;
9560 dwarf2_complex_location_expr_complaint ();
9564 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
9566 stack[++stacki] = unsnd;
9568 dwarf2_complex_location_expr_complaint ();
9572 stack[++stacki] = read_address (objfile->obfd, &data[i],
9578 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
9583 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
9588 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
9593 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
9598 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
9603 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
9608 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
9614 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
9619 stack[stacki + 1] = stack[stacki];
9624 stack[stacki - 1] += stack[stacki];
9628 case DW_OP_plus_uconst:
9629 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
9634 stack[stacki - 1] -= stack[stacki];
9639 /* If we're not the last op, then we definitely can't encode
9640 this using GDB's address_class enum. This is valid for partial
9641 global symbols, although the variable's address will be bogus
9644 dwarf2_complex_location_expr_complaint ();
9647 case DW_OP_GNU_push_tls_address:
9648 /* The top of the stack has the offset from the beginning
9649 of the thread control block at which the variable is located. */
9650 /* Nothing should follow this operator, so the top of stack would
9652 /* This is valid for partial global symbols, but the variable's
9653 address will be bogus in the psymtab. */
9655 dwarf2_complex_location_expr_complaint ();
9658 case DW_OP_GNU_uninit:
9662 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
9663 dwarf_stack_op_name (op));
9664 return (stack[stacki]);
9667 return (stack[stacki]);
9670 /* memory allocation interface */
9672 static struct dwarf_block *
9673 dwarf_alloc_block (struct dwarf2_cu *cu)
9675 struct dwarf_block *blk;
9677 blk = (struct dwarf_block *)
9678 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
9682 static struct abbrev_info *
9683 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
9685 struct abbrev_info *abbrev;
9687 abbrev = (struct abbrev_info *)
9688 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
9689 memset (abbrev, 0, sizeof (struct abbrev_info));
9693 static struct die_info *
9694 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
9696 struct die_info *die;
9697 size_t size = sizeof (struct die_info);
9700 size += (num_attrs - 1) * sizeof (struct attribute);
9702 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
9703 memset (die, 0, sizeof (struct die_info));
9708 /* Macro support. */
9711 /* Return the full name of file number I in *LH's file name table.
9712 Use COMP_DIR as the name of the current directory of the
9713 compilation. The result is allocated using xmalloc; the caller is
9714 responsible for freeing it. */
9716 file_full_name (int file, struct line_header *lh, const char *comp_dir)
9718 /* Is the file number a valid index into the line header's file name
9719 table? Remember that file numbers start with one, not zero. */
9720 if (1 <= file && file <= lh->num_file_names)
9722 struct file_entry *fe = &lh->file_names[file - 1];
9724 if (IS_ABSOLUTE_PATH (fe->name))
9725 return xstrdup (fe->name);
9733 dir = lh->include_dirs[fe->dir_index - 1];
9739 dir_len = strlen (dir);
9740 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
9741 strcpy (full_name, dir);
9742 full_name[dir_len] = '/';
9743 strcpy (full_name + dir_len + 1, fe->name);
9747 return xstrdup (fe->name);
9752 /* The compiler produced a bogus file number. We can at least
9753 record the macro definitions made in the file, even if we
9754 won't be able to find the file by name. */
9756 sprintf (fake_name, "<bad macro file number %d>", file);
9758 complaint (&symfile_complaints,
9759 _("bad file number in macro information (%d)"),
9762 return xstrdup (fake_name);
9767 static struct macro_source_file *
9768 macro_start_file (int file, int line,
9769 struct macro_source_file *current_file,
9770 const char *comp_dir,
9771 struct line_header *lh, struct objfile *objfile)
9773 /* The full name of this source file. */
9774 char *full_name = file_full_name (file, lh, comp_dir);
9776 /* We don't create a macro table for this compilation unit
9777 at all until we actually get a filename. */
9778 if (! pending_macros)
9779 pending_macros = new_macro_table (&objfile->objfile_obstack,
9780 objfile->macro_cache);
9783 /* If we have no current file, then this must be the start_file
9784 directive for the compilation unit's main source file. */
9785 current_file = macro_set_main (pending_macros, full_name);
9787 current_file = macro_include (current_file, line, full_name);
9791 return current_file;
9795 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9796 followed by a null byte. */
9798 copy_string (const char *buf, int len)
9800 char *s = xmalloc (len + 1);
9801 memcpy (s, buf, len);
9809 consume_improper_spaces (const char *p, const char *body)
9813 complaint (&symfile_complaints,
9814 _("macro definition contains spaces in formal argument list:\n`%s'"),
9826 parse_macro_definition (struct macro_source_file *file, int line,
9831 /* The body string takes one of two forms. For object-like macro
9832 definitions, it should be:
9834 <macro name> " " <definition>
9836 For function-like macro definitions, it should be:
9838 <macro name> "() " <definition>
9840 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9842 Spaces may appear only where explicitly indicated, and in the
9845 The Dwarf 2 spec says that an object-like macro's name is always
9846 followed by a space, but versions of GCC around March 2002 omit
9847 the space when the macro's definition is the empty string.
9849 The Dwarf 2 spec says that there should be no spaces between the
9850 formal arguments in a function-like macro's formal argument list,
9851 but versions of GCC around March 2002 include spaces after the
9855 /* Find the extent of the macro name. The macro name is terminated
9856 by either a space or null character (for an object-like macro) or
9857 an opening paren (for a function-like macro). */
9858 for (p = body; *p; p++)
9859 if (*p == ' ' || *p == '(')
9862 if (*p == ' ' || *p == '\0')
9864 /* It's an object-like macro. */
9865 int name_len = p - body;
9866 char *name = copy_string (body, name_len);
9867 const char *replacement;
9870 replacement = body + name_len + 1;
9873 dwarf2_macro_malformed_definition_complaint (body);
9874 replacement = body + name_len;
9877 macro_define_object (file, line, name, replacement);
9883 /* It's a function-like macro. */
9884 char *name = copy_string (body, p - body);
9887 char **argv = xmalloc (argv_size * sizeof (*argv));
9891 p = consume_improper_spaces (p, body);
9893 /* Parse the formal argument list. */
9894 while (*p && *p != ')')
9896 /* Find the extent of the current argument name. */
9897 const char *arg_start = p;
9899 while (*p && *p != ',' && *p != ')' && *p != ' ')
9902 if (! *p || p == arg_start)
9903 dwarf2_macro_malformed_definition_complaint (body);
9906 /* Make sure argv has room for the new argument. */
9907 if (argc >= argv_size)
9910 argv = xrealloc (argv, argv_size * sizeof (*argv));
9913 argv[argc++] = copy_string (arg_start, p - arg_start);
9916 p = consume_improper_spaces (p, body);
9918 /* Consume the comma, if present. */
9923 p = consume_improper_spaces (p, body);
9932 /* Perfectly formed definition, no complaints. */
9933 macro_define_function (file, line, name,
9934 argc, (const char **) argv,
9936 else if (*p == '\0')
9938 /* Complain, but do define it. */
9939 dwarf2_macro_malformed_definition_complaint (body);
9940 macro_define_function (file, line, name,
9941 argc, (const char **) argv,
9945 /* Just complain. */
9946 dwarf2_macro_malformed_definition_complaint (body);
9949 /* Just complain. */
9950 dwarf2_macro_malformed_definition_complaint (body);
9956 for (i = 0; i < argc; i++)
9962 dwarf2_macro_malformed_definition_complaint (body);
9967 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
9968 char *comp_dir, bfd *abfd,
9969 struct dwarf2_cu *cu)
9971 gdb_byte *mac_ptr, *mac_end;
9972 struct macro_source_file *current_file = 0;
9973 enum dwarf_macinfo_record_type macinfo_type;
9976 if (dwarf2_per_objfile->macinfo_buffer == NULL)
9978 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
9982 /* First pass: Find the name of the base filename.
9983 This filename is needed in order to process all macros whose definition
9984 (or undefinition) comes from the command line. These macros are defined
9985 before the first DW_MACINFO_start_file entry, and yet still need to be
9986 associated to the base file.
9988 To determine the base file name, we scan the macro definitions until we
9989 reach the first DW_MACINFO_start_file entry. We then initialize
9990 CURRENT_FILE accordingly so that any macro definition found before the
9991 first DW_MACINFO_start_file can still be associated to the base file. */
9993 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
9994 mac_end = dwarf2_per_objfile->macinfo_buffer
9995 + dwarf2_per_objfile->macinfo_size;
9999 /* Do we at least have room for a macinfo type byte? */
10000 if (mac_ptr >= mac_end)
10002 /* Complaint is printed during the second pass as GDB will probably
10003 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10007 macinfo_type = read_1_byte (abfd, mac_ptr);
10010 switch (macinfo_type)
10012 /* A zero macinfo type indicates the end of the macro
10017 case DW_MACINFO_define:
10018 case DW_MACINFO_undef:
10019 /* Only skip the data by MAC_PTR. */
10021 unsigned int bytes_read;
10023 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10024 mac_ptr += bytes_read;
10025 read_string (abfd, mac_ptr, &bytes_read);
10026 mac_ptr += bytes_read;
10030 case DW_MACINFO_start_file:
10032 unsigned int bytes_read;
10035 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10036 mac_ptr += bytes_read;
10037 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10038 mac_ptr += bytes_read;
10040 current_file = macro_start_file (file, line, current_file, comp_dir,
10045 case DW_MACINFO_end_file:
10046 /* No data to skip by MAC_PTR. */
10049 case DW_MACINFO_vendor_ext:
10050 /* Only skip the data by MAC_PTR. */
10052 unsigned int bytes_read;
10054 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10055 mac_ptr += bytes_read;
10056 read_string (abfd, mac_ptr, &bytes_read);
10057 mac_ptr += bytes_read;
10064 } while (macinfo_type != 0 && current_file == NULL);
10066 /* Second pass: Process all entries.
10068 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10069 command-line macro definitions/undefinitions. This flag is unset when we
10070 reach the first DW_MACINFO_start_file entry. */
10072 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
10074 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10075 GDB is still reading the definitions from command line. First
10076 DW_MACINFO_start_file will need to be ignored as it was already executed
10077 to create CURRENT_FILE for the main source holding also the command line
10078 definitions. On first met DW_MACINFO_start_file this flag is reset to
10079 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10081 at_commandline = 1;
10085 /* Do we at least have room for a macinfo type byte? */
10086 if (mac_ptr >= mac_end)
10088 dwarf2_macros_too_long_complaint ();
10092 macinfo_type = read_1_byte (abfd, mac_ptr);
10095 switch (macinfo_type)
10097 /* A zero macinfo type indicates the end of the macro
10102 case DW_MACINFO_define:
10103 case DW_MACINFO_undef:
10105 unsigned int bytes_read;
10109 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10110 mac_ptr += bytes_read;
10111 body = read_string (abfd, mac_ptr, &bytes_read);
10112 mac_ptr += bytes_read;
10114 if (! current_file)
10116 /* DWARF violation as no main source is present. */
10117 complaint (&symfile_complaints,
10118 _("debug info with no main source gives macro %s "
10121 DW_MACINFO_define ? _("definition") : macinfo_type ==
10122 DW_MACINFO_undef ? _("undefinition") :
10123 "something-or-other", line, body);
10126 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
10127 complaint (&symfile_complaints,
10128 _("debug info gives %s macro %s with %s line %d: %s"),
10129 at_commandline ? _("command-line") : _("in-file"),
10131 DW_MACINFO_define ? _("definition") : macinfo_type ==
10132 DW_MACINFO_undef ? _("undefinition") :
10133 "something-or-other",
10134 line == 0 ? _("zero") : _("non-zero"), line, body);
10136 if (macinfo_type == DW_MACINFO_define)
10137 parse_macro_definition (current_file, line, body);
10138 else if (macinfo_type == DW_MACINFO_undef)
10139 macro_undef (current_file, line, body);
10143 case DW_MACINFO_start_file:
10145 unsigned int bytes_read;
10148 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10149 mac_ptr += bytes_read;
10150 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10151 mac_ptr += bytes_read;
10153 if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
10154 complaint (&symfile_complaints,
10155 _("debug info gives source %d included "
10156 "from %s at %s line %d"),
10157 file, at_commandline ? _("command-line") : _("file"),
10158 line == 0 ? _("zero") : _("non-zero"), line);
10160 if (at_commandline)
10162 /* This DW_MACINFO_start_file was executed in the pass one. */
10163 at_commandline = 0;
10166 current_file = macro_start_file (file, line,
10167 current_file, comp_dir,
10172 case DW_MACINFO_end_file:
10173 if (! current_file)
10174 complaint (&symfile_complaints,
10175 _("macro debug info has an unmatched `close_file' directive"));
10178 current_file = current_file->included_by;
10179 if (! current_file)
10181 enum dwarf_macinfo_record_type next_type;
10183 /* GCC circa March 2002 doesn't produce the zero
10184 type byte marking the end of the compilation
10185 unit. Complain if it's not there, but exit no
10188 /* Do we at least have room for a macinfo type byte? */
10189 if (mac_ptr >= mac_end)
10191 dwarf2_macros_too_long_complaint ();
10195 /* We don't increment mac_ptr here, so this is just
10197 next_type = read_1_byte (abfd, mac_ptr);
10198 if (next_type != 0)
10199 complaint (&symfile_complaints,
10200 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10207 case DW_MACINFO_vendor_ext:
10209 unsigned int bytes_read;
10213 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
10214 mac_ptr += bytes_read;
10215 string = read_string (abfd, mac_ptr, &bytes_read);
10216 mac_ptr += bytes_read;
10218 /* We don't recognize any vendor extensions. */
10222 } while (macinfo_type != 0);
10225 /* Check if the attribute's form is a DW_FORM_block*
10226 if so return true else false. */
10228 attr_form_is_block (struct attribute *attr)
10230 return (attr == NULL ? 0 :
10231 attr->form == DW_FORM_block1
10232 || attr->form == DW_FORM_block2
10233 || attr->form == DW_FORM_block4
10234 || attr->form == DW_FORM_block);
10237 /* Return non-zero if ATTR's value is a section offset --- classes
10238 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10239 You may use DW_UNSND (attr) to retrieve such offsets.
10241 Section 7.5.4, "Attribute Encodings", explains that no attribute
10242 may have a value that belongs to more than one of these classes; it
10243 would be ambiguous if we did, because we use the same forms for all
10246 attr_form_is_section_offset (struct attribute *attr)
10248 return (attr->form == DW_FORM_data4
10249 || attr->form == DW_FORM_data8);
10253 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10254 zero otherwise. When this function returns true, you can apply
10255 dwarf2_get_attr_constant_value to it.
10257 However, note that for some attributes you must check
10258 attr_form_is_section_offset before using this test. DW_FORM_data4
10259 and DW_FORM_data8 are members of both the constant class, and of
10260 the classes that contain offsets into other debug sections
10261 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10262 that, if an attribute's can be either a constant or one of the
10263 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10264 taken as section offsets, not constants. */
10266 attr_form_is_constant (struct attribute *attr)
10268 switch (attr->form)
10270 case DW_FORM_sdata:
10271 case DW_FORM_udata:
10272 case DW_FORM_data1:
10273 case DW_FORM_data2:
10274 case DW_FORM_data4:
10275 case DW_FORM_data8:
10283 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
10284 struct dwarf2_cu *cu)
10286 if (attr_form_is_section_offset (attr)
10287 /* ".debug_loc" may not exist at all, or the offset may be outside
10288 the section. If so, fall through to the complaint in the
10290 && DW_UNSND (attr) < dwarf2_per_objfile->loc_size)
10292 struct dwarf2_loclist_baton *baton;
10294 baton = obstack_alloc (&cu->objfile->objfile_obstack,
10295 sizeof (struct dwarf2_loclist_baton));
10296 baton->per_cu = cu->per_cu;
10297 gdb_assert (baton->per_cu);
10299 /* We don't know how long the location list is, but make sure we
10300 don't run off the edge of the section. */
10301 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
10302 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
10303 baton->base_address = cu->base_address;
10304 if (cu->base_known == 0)
10305 complaint (&symfile_complaints,
10306 _("Location list used without specifying the CU base address."));
10308 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
10309 SYMBOL_LOCATION_BATON (sym) = baton;
10313 struct dwarf2_locexpr_baton *baton;
10315 baton = obstack_alloc (&cu->objfile->objfile_obstack,
10316 sizeof (struct dwarf2_locexpr_baton));
10317 baton->per_cu = cu->per_cu;
10318 gdb_assert (baton->per_cu);
10320 if (attr_form_is_block (attr))
10322 /* Note that we're just copying the block's data pointer
10323 here, not the actual data. We're still pointing into the
10324 info_buffer for SYM's objfile; right now we never release
10325 that buffer, but when we do clean up properly this may
10327 baton->size = DW_BLOCK (attr)->size;
10328 baton->data = DW_BLOCK (attr)->data;
10332 dwarf2_invalid_attrib_class_complaint ("location description",
10333 SYMBOL_NATURAL_NAME (sym));
10335 baton->data = NULL;
10338 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
10339 SYMBOL_LOCATION_BATON (sym) = baton;
10343 /* Return the OBJFILE associated with the compilation unit CU. */
10346 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
10348 struct objfile *objfile = per_cu->psymtab->objfile;
10350 /* Return the master objfile, so that we can report and look up the
10351 correct file containing this variable. */
10352 if (objfile->separate_debug_objfile_backlink)
10353 objfile = objfile->separate_debug_objfile_backlink;
10358 /* Return the address size given in the compilation unit header for CU. */
10361 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
10364 return per_cu->cu->header.addr_size;
10367 /* If the CU is not currently read in, we re-read its header. */
10368 struct objfile *objfile = per_cu->psymtab->objfile;
10369 struct dwarf2_per_objfile *per_objfile
10370 = objfile_data (objfile, dwarf2_objfile_data_key);
10371 gdb_byte *info_ptr = per_objfile->info_buffer + per_cu->offset;
10373 struct comp_unit_head cu_header;
10374 memset (&cu_header, 0, sizeof cu_header);
10375 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
10376 return cu_header.addr_size;
10380 /* Locate the compilation unit from CU's objfile which contains the
10381 DIE at OFFSET. Raises an error on failure. */
10383 static struct dwarf2_per_cu_data *
10384 dwarf2_find_containing_comp_unit (unsigned int offset,
10385 struct objfile *objfile)
10387 struct dwarf2_per_cu_data *this_cu;
10391 high = dwarf2_per_objfile->n_comp_units - 1;
10394 int mid = low + (high - low) / 2;
10395 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
10400 gdb_assert (low == high);
10401 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
10404 error (_("Dwarf Error: could not find partial DIE containing "
10405 "offset 0x%lx [in module %s]"),
10406 (long) offset, bfd_get_filename (objfile->obfd));
10408 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
10409 return dwarf2_per_objfile->all_comp_units[low-1];
10413 this_cu = dwarf2_per_objfile->all_comp_units[low];
10414 if (low == dwarf2_per_objfile->n_comp_units - 1
10415 && offset >= this_cu->offset + this_cu->length)
10416 error (_("invalid dwarf2 offset %u"), offset);
10417 gdb_assert (offset < this_cu->offset + this_cu->length);
10422 /* Locate the compilation unit from OBJFILE which is located at exactly
10423 OFFSET. Raises an error on failure. */
10425 static struct dwarf2_per_cu_data *
10426 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
10428 struct dwarf2_per_cu_data *this_cu;
10429 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
10430 if (this_cu->offset != offset)
10431 error (_("no compilation unit with offset %u."), offset);
10435 /* Release one cached compilation unit, CU. We unlink it from the tree
10436 of compilation units, but we don't remove it from the read_in_chain;
10437 the caller is responsible for that. */
10440 free_one_comp_unit (void *data)
10442 struct dwarf2_cu *cu = data;
10444 if (cu->per_cu != NULL)
10445 cu->per_cu->cu = NULL;
10448 obstack_free (&cu->comp_unit_obstack, NULL);
10453 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10454 when we're finished with it. We can't free the pointer itself, but be
10455 sure to unlink it from the cache. Also release any associated storage
10456 and perform cache maintenance.
10458 Only used during partial symbol parsing. */
10461 free_stack_comp_unit (void *data)
10463 struct dwarf2_cu *cu = data;
10465 obstack_free (&cu->comp_unit_obstack, NULL);
10466 cu->partial_dies = NULL;
10468 if (cu->per_cu != NULL)
10470 /* This compilation unit is on the stack in our caller, so we
10471 should not xfree it. Just unlink it. */
10472 cu->per_cu->cu = NULL;
10475 /* If we had a per-cu pointer, then we may have other compilation
10476 units loaded, so age them now. */
10477 age_cached_comp_units ();
10481 /* Free all cached compilation units. */
10484 free_cached_comp_units (void *data)
10486 struct dwarf2_per_cu_data *per_cu, **last_chain;
10488 per_cu = dwarf2_per_objfile->read_in_chain;
10489 last_chain = &dwarf2_per_objfile->read_in_chain;
10490 while (per_cu != NULL)
10492 struct dwarf2_per_cu_data *next_cu;
10494 next_cu = per_cu->cu->read_in_chain;
10496 free_one_comp_unit (per_cu->cu);
10497 *last_chain = next_cu;
10503 /* Increase the age counter on each cached compilation unit, and free
10504 any that are too old. */
10507 age_cached_comp_units (void)
10509 struct dwarf2_per_cu_data *per_cu, **last_chain;
10511 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
10512 per_cu = dwarf2_per_objfile->read_in_chain;
10513 while (per_cu != NULL)
10515 per_cu->cu->last_used ++;
10516 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
10517 dwarf2_mark (per_cu->cu);
10518 per_cu = per_cu->cu->read_in_chain;
10521 per_cu = dwarf2_per_objfile->read_in_chain;
10522 last_chain = &dwarf2_per_objfile->read_in_chain;
10523 while (per_cu != NULL)
10525 struct dwarf2_per_cu_data *next_cu;
10527 next_cu = per_cu->cu->read_in_chain;
10529 if (!per_cu->cu->mark)
10531 free_one_comp_unit (per_cu->cu);
10532 *last_chain = next_cu;
10535 last_chain = &per_cu->cu->read_in_chain;
10541 /* Remove a single compilation unit from the cache. */
10544 free_one_cached_comp_unit (void *target_cu)
10546 struct dwarf2_per_cu_data *per_cu, **last_chain;
10548 per_cu = dwarf2_per_objfile->read_in_chain;
10549 last_chain = &dwarf2_per_objfile->read_in_chain;
10550 while (per_cu != NULL)
10552 struct dwarf2_per_cu_data *next_cu;
10554 next_cu = per_cu->cu->read_in_chain;
10556 if (per_cu->cu == target_cu)
10558 free_one_comp_unit (per_cu->cu);
10559 *last_chain = next_cu;
10563 last_chain = &per_cu->cu->read_in_chain;
10569 /* Release all extra memory associated with OBJFILE. */
10572 dwarf2_free_objfile (struct objfile *objfile)
10574 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
10576 if (dwarf2_per_objfile == NULL)
10579 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10580 free_cached_comp_units (NULL);
10582 /* Everything else should be on the objfile obstack. */
10585 /* A pair of DIE offset and GDB type pointer. We store these
10586 in a hash table separate from the DIEs, and preserve them
10587 when the DIEs are flushed out of cache. */
10589 struct dwarf2_offset_and_type
10591 unsigned int offset;
10595 /* Hash function for a dwarf2_offset_and_type. */
10598 offset_and_type_hash (const void *item)
10600 const struct dwarf2_offset_and_type *ofs = item;
10601 return ofs->offset;
10604 /* Equality function for a dwarf2_offset_and_type. */
10607 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
10609 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
10610 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
10611 return ofs_lhs->offset == ofs_rhs->offset;
10614 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10615 table if necessary. For convenience, return TYPE. */
10617 static struct type *
10618 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
10620 struct dwarf2_offset_and_type **slot, ofs;
10622 if (cu->type_hash == NULL)
10624 gdb_assert (cu->per_cu != NULL);
10625 cu->per_cu->type_hash
10626 = htab_create_alloc_ex (cu->header.length / 24,
10627 offset_and_type_hash,
10628 offset_and_type_eq,
10630 &cu->objfile->objfile_obstack,
10631 hashtab_obstack_allocate,
10632 dummy_obstack_deallocate);
10633 cu->type_hash = cu->per_cu->type_hash;
10636 ofs.offset = die->offset;
10638 slot = (struct dwarf2_offset_and_type **)
10639 htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT);
10640 *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot));
10645 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10646 not have a saved type. */
10648 static struct type *
10649 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
10651 struct dwarf2_offset_and_type *slot, ofs;
10652 htab_t type_hash = cu->type_hash;
10654 if (type_hash == NULL)
10657 ofs.offset = die->offset;
10658 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
10665 /* Set the mark field in CU and in every other compilation unit in the
10666 cache that we must keep because we are keeping CU. */
10668 /* Add a dependence relationship from CU to REF_PER_CU. */
10671 dwarf2_add_dependence (struct dwarf2_cu *cu,
10672 struct dwarf2_per_cu_data *ref_per_cu)
10676 if (cu->dependencies == NULL)
10678 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
10679 NULL, &cu->comp_unit_obstack,
10680 hashtab_obstack_allocate,
10681 dummy_obstack_deallocate);
10683 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
10685 *slot = ref_per_cu;
10688 /* Set the mark field in CU and in every other compilation unit in the
10689 cache that we must keep because we are keeping CU. */
10692 dwarf2_mark_helper (void **slot, void *data)
10694 struct dwarf2_per_cu_data *per_cu;
10696 per_cu = (struct dwarf2_per_cu_data *) *slot;
10697 if (per_cu->cu->mark)
10699 per_cu->cu->mark = 1;
10701 if (per_cu->cu->dependencies != NULL)
10702 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
10708 dwarf2_mark (struct dwarf2_cu *cu)
10713 if (cu->dependencies != NULL)
10714 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
10718 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
10722 per_cu->cu->mark = 0;
10723 per_cu = per_cu->cu->read_in_chain;
10727 /* Trivial hash function for partial_die_info: the hash value of a DIE
10728 is its offset in .debug_info for this objfile. */
10731 partial_die_hash (const void *item)
10733 const struct partial_die_info *part_die = item;
10734 return part_die->offset;
10737 /* Trivial comparison function for partial_die_info structures: two DIEs
10738 are equal if they have the same offset. */
10741 partial_die_eq (const void *item_lhs, const void *item_rhs)
10743 const struct partial_die_info *part_die_lhs = item_lhs;
10744 const struct partial_die_info *part_die_rhs = item_rhs;
10745 return part_die_lhs->offset == part_die_rhs->offset;
10748 static struct cmd_list_element *set_dwarf2_cmdlist;
10749 static struct cmd_list_element *show_dwarf2_cmdlist;
10752 set_dwarf2_cmd (char *args, int from_tty)
10754 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
10758 show_dwarf2_cmd (char *args, int from_tty)
10760 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
10763 void _initialize_dwarf2_read (void);
10766 _initialize_dwarf2_read (void)
10768 dwarf2_objfile_data_key = register_objfile_data ();
10770 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
10771 Set DWARF 2 specific variables.\n\
10772 Configure DWARF 2 variables such as the cache size"),
10773 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
10774 0/*allow-unknown*/, &maintenance_set_cmdlist);
10776 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
10777 Show DWARF 2 specific variables\n\
10778 Show DWARF 2 variables such as the cache size"),
10779 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
10780 0/*allow-unknown*/, &maintenance_show_cmdlist);
10782 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
10783 &dwarf2_max_cache_age, _("\
10784 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10785 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10786 A higher limit means that cached compilation units will be stored\n\
10787 in memory longer, and more total memory will be used. Zero disables\n\
10788 caching, which can slow down startup."),
10790 show_dwarf2_max_cache_age,
10791 &set_dwarf2_cmdlist,
10792 &show_dwarf2_cmdlist);
10794 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
10795 Set debugging of the dwarf2 DIE reader."), _("\
10796 Show debugging of the dwarf2 DIE reader."), _("\
10797 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10798 The value is the maximum depth to print."),
10801 &setdebuglist, &showdebuglist);