1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol *symbolp;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length; /* length of the .debug_info
87 unsigned short version; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
90 unsigned char addr_size; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length; /* byte length of the statement
103 unsigned short version; /* version number -- 2 for DWARF
105 unsigned int prologue_length; /* # bytes between prologue &
107 unsigned char minimum_instruction_length; /* byte size of
109 unsigned char default_is_stmt; /* initial value of is_stmt
112 unsigned char line_range;
113 unsigned char opcode_base; /* number assigned to first special
115 unsigned char *standard_opcode_lengths;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug = 0;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info;
130 static const struct objfile_data *dwarf2_objfile_data_key;
132 struct dwarf2_section_info
138 /* True if we have tried to read this section. */
142 /* All offsets in the index are of this type. It must be
143 architecture-independent. */
144 typedef uint32_t offset_type;
146 DEF_VEC_I (offset_type);
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* Index data format version. */
155 /* The total length of the buffer. */
158 /* A pointer to the address table data. */
159 const gdb_byte *address_table;
161 /* Size of the address table data in bytes. */
162 offset_type address_table_size;
164 /* The symbol table, implemented as a hash table. */
165 const offset_type *symbol_table;
167 /* Size in slots, each slot is 2 offset_types. */
168 offset_type symbol_table_slots;
170 /* A pointer to the constant pool. */
171 const char *constant_pool;
174 struct dwarf2_per_objfile
176 struct dwarf2_section_info info;
177 struct dwarf2_section_info abbrev;
178 struct dwarf2_section_info line;
179 struct dwarf2_section_info loc;
180 struct dwarf2_section_info macinfo;
181 struct dwarf2_section_info str;
182 struct dwarf2_section_info ranges;
183 struct dwarf2_section_info types;
184 struct dwarf2_section_info frame;
185 struct dwarf2_section_info eh_frame;
186 struct dwarf2_section_info gdb_index;
189 struct objfile *objfile;
191 /* A list of all the compilation units. This is used to locate
192 the target compilation unit of a particular reference. */
193 struct dwarf2_per_cu_data **all_comp_units;
195 /* The number of compilation units in ALL_COMP_UNITS. */
198 /* The number of .debug_types-related CUs. */
199 int n_type_comp_units;
201 /* The .debug_types-related CUs. */
202 struct dwarf2_per_cu_data **type_comp_units;
204 /* A chain of compilation units that are currently read in, so that
205 they can be freed later. */
206 struct dwarf2_per_cu_data *read_in_chain;
208 /* A table mapping .debug_types signatures to its signatured_type entry.
209 This is NULL if the .debug_types section hasn't been read in yet. */
210 htab_t signatured_types;
212 /* A flag indicating wether this objfile has a section loaded at a
214 int has_section_at_zero;
216 /* True if we are using the mapped index,
217 or we are faking it for OBJF_READNOW's sake. */
218 unsigned char using_index;
220 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
221 struct mapped_index *index_table;
223 /* When using index_table, this keeps track of all quick_file_names entries.
224 TUs can share line table entries with CUs or other TUs, and there can be
225 a lot more TUs than unique line tables, so we maintain a separate table
226 of all line table entries to support the sharing. */
227 htab_t quick_file_names_table;
229 /* Set during partial symbol reading, to prevent queueing of full
231 int reading_partial_symbols;
233 /* Table mapping type .debug_info DIE offsets to types.
234 This is NULL if not allocated yet.
235 It (currently) makes sense to allocate debug_types_type_hash lazily.
236 To keep things simple we allocate both lazily. */
237 htab_t debug_info_type_hash;
239 /* Table mapping type .debug_types DIE offsets to types.
240 This is NULL if not allocated yet. */
241 htab_t debug_types_type_hash;
244 static struct dwarf2_per_objfile *dwarf2_per_objfile;
246 /* names of the debugging sections */
248 /* Note that if the debugging section has been compressed, it might
249 have a name like .zdebug_info. */
251 #define INFO_SECTION "debug_info"
252 #define ABBREV_SECTION "debug_abbrev"
253 #define LINE_SECTION "debug_line"
254 #define LOC_SECTION "debug_loc"
255 #define MACINFO_SECTION "debug_macinfo"
256 #define STR_SECTION "debug_str"
257 #define RANGES_SECTION "debug_ranges"
258 #define TYPES_SECTION "debug_types"
259 #define FRAME_SECTION "debug_frame"
260 #define EH_FRAME_SECTION "eh_frame"
261 #define GDB_INDEX_SECTION "gdb_index"
263 /* local data types */
265 /* We hold several abbreviation tables in memory at the same time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
270 /* The data in a compilation unit header, after target2host
271 translation, looks like this. */
272 struct comp_unit_head
276 unsigned char addr_size;
277 unsigned char signed_addr_p;
278 unsigned int abbrev_offset;
280 /* Size of file offsets; either 4 or 8. */
281 unsigned int offset_size;
283 /* Size of the length field; either 4 or 12. */
284 unsigned int initial_length_size;
286 /* Offset to the first byte of this compilation unit header in the
287 .debug_info section, for resolving relative reference dies. */
290 /* Offset to first die in this cu from the start of the cu.
291 This will be the first byte following the compilation unit header. */
292 unsigned int first_die_offset;
295 /* Type used for delaying computation of method physnames.
296 See comments for compute_delayed_physnames. */
297 struct delayed_method_info
299 /* The type to which the method is attached, i.e., its parent class. */
302 /* The index of the method in the type's function fieldlists. */
305 /* The index of the method in the fieldlist. */
308 /* The name of the DIE. */
311 /* The DIE associated with this method. */
312 struct die_info *die;
315 typedef struct delayed_method_info delayed_method_info;
316 DEF_VEC_O (delayed_method_info);
318 /* Internal state when decoding a particular compilation unit. */
321 /* The objfile containing this compilation unit. */
322 struct objfile *objfile;
324 /* The header of the compilation unit. */
325 struct comp_unit_head header;
327 /* Base address of this compilation unit. */
328 CORE_ADDR base_address;
330 /* Non-zero if base_address has been set. */
333 struct function_range *first_fn, *last_fn, *cached_fn;
335 /* The language we are debugging. */
336 enum language language;
337 const struct language_defn *language_defn;
339 const char *producer;
341 /* The generic symbol table building routines have separate lists for
342 file scope symbols and all all other scopes (local scopes). So
343 we need to select the right one to pass to add_symbol_to_list().
344 We do it by keeping a pointer to the correct list in list_in_scope.
346 FIXME: The original dwarf code just treated the file scope as the
347 first local scope, and all other local scopes as nested local
348 scopes, and worked fine. Check to see if we really need to
349 distinguish these in buildsym.c. */
350 struct pending **list_in_scope;
352 /* DWARF abbreviation table associated with this compilation unit. */
353 struct abbrev_info **dwarf2_abbrevs;
355 /* Storage for the abbrev table. */
356 struct obstack abbrev_obstack;
358 /* Hash table holding all the loaded partial DIEs. */
361 /* Storage for things with the same lifetime as this read-in compilation
362 unit, including partial DIEs. */
363 struct obstack comp_unit_obstack;
365 /* When multiple dwarf2_cu structures are living in memory, this field
366 chains them all together, so that they can be released efficiently.
367 We will probably also want a generation counter so that most-recently-used
368 compilation units are cached... */
369 struct dwarf2_per_cu_data *read_in_chain;
371 /* Backchain to our per_cu entry if the tree has been built. */
372 struct dwarf2_per_cu_data *per_cu;
374 /* How many compilation units ago was this CU last referenced? */
377 /* A hash table of die offsets for following references. */
380 /* Full DIEs if read in. */
381 struct die_info *dies;
383 /* A set of pointers to dwarf2_per_cu_data objects for compilation
384 units referenced by this one. Only set during full symbol processing;
385 partial symbol tables do not have dependencies. */
388 /* Header data from the line table, during full symbol processing. */
389 struct line_header *line_header;
391 /* A list of methods which need to have physnames computed
392 after all type information has been read. */
393 VEC (delayed_method_info) *method_list;
395 /* Mark used when releasing cached dies. */
396 unsigned int mark : 1;
398 /* This flag will be set if this compilation unit might include
399 inter-compilation-unit references. */
400 unsigned int has_form_ref_addr : 1;
402 /* This flag will be set if this compilation unit includes any
403 DW_TAG_namespace DIEs. If we know that there are explicit
404 DIEs for namespaces, we don't need to try to infer them
405 from mangled names. */
406 unsigned int has_namespace_info : 1;
408 /* This CU references .debug_loc. See the symtab->locations_valid field.
409 This test is imperfect as there may exist optimized debug code not using
410 any location list and still facing inlining issues if handled as
411 unoptimized code. For a future better test see GCC PR other/32998. */
413 unsigned int has_loclist : 1;
416 /* Persistent data held for a compilation unit, even when not
417 processing it. We put a pointer to this structure in the
418 read_symtab_private field of the psymtab. If we encounter
419 inter-compilation-unit references, we also maintain a sorted
420 list of all compilation units. */
422 struct dwarf2_per_cu_data
424 /* The start offset and length of this compilation unit. 2**29-1
425 bytes should suffice to store the length of any compilation unit
426 - if it doesn't, GDB will fall over anyway.
427 NOTE: Unlike comp_unit_head.length, this length includes
428 initial_length_size. */
430 unsigned int length : 29;
432 /* Flag indicating this compilation unit will be read in before
433 any of the current compilation units are processed. */
434 unsigned int queued : 1;
436 /* This flag will be set if we need to load absolutely all DIEs
437 for this compilation unit, instead of just the ones we think
438 are interesting. It gets set if we look for a DIE in the
439 hash table and don't find it. */
440 unsigned int load_all_dies : 1;
442 /* Non-zero if this CU is from .debug_types.
443 Otherwise it's from .debug_info. */
444 unsigned int from_debug_types : 1;
446 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
447 of the CU cache it gets reset to NULL again. */
448 struct dwarf2_cu *cu;
450 /* The corresponding objfile. */
451 struct objfile *objfile;
453 /* When using partial symbol tables, the 'psymtab' field is active.
454 Otherwise the 'quick' field is active. */
457 /* The partial symbol table associated with this compilation unit,
458 or NULL for partial units (which do not have an associated
460 struct partial_symtab *psymtab;
462 /* Data needed by the "quick" functions. */
463 struct dwarf2_per_cu_quick_data *quick;
467 /* Entry in the signatured_types hash table. */
469 struct signatured_type
473 /* Offset in .debug_types of the type defined by this TU. */
474 unsigned int type_offset;
476 /* The CU(/TU) of this type. */
477 struct dwarf2_per_cu_data per_cu;
480 /* Struct used to pass misc. parameters to read_die_and_children, et
481 al. which are used for both .debug_info and .debug_types dies.
482 All parameters here are unchanging for the life of the call. This
483 struct exists to abstract away the constant parameters of die
486 struct die_reader_specs
488 /* The bfd of this objfile. */
491 /* The CU of the DIE we are parsing. */
492 struct dwarf2_cu *cu;
494 /* Pointer to start of section buffer.
495 This is either the start of .debug_info or .debug_types. */
496 const gdb_byte *buffer;
499 /* The line number information for a compilation unit (found in the
500 .debug_line section) begins with a "statement program header",
501 which contains the following information. */
504 unsigned int total_length;
505 unsigned short version;
506 unsigned int header_length;
507 unsigned char minimum_instruction_length;
508 unsigned char maximum_ops_per_instruction;
509 unsigned char default_is_stmt;
511 unsigned char line_range;
512 unsigned char opcode_base;
514 /* standard_opcode_lengths[i] is the number of operands for the
515 standard opcode whose value is i. This means that
516 standard_opcode_lengths[0] is unused, and the last meaningful
517 element is standard_opcode_lengths[opcode_base - 1]. */
518 unsigned char *standard_opcode_lengths;
520 /* The include_directories table. NOTE! These strings are not
521 allocated with xmalloc; instead, they are pointers into
522 debug_line_buffer. If you try to free them, `free' will get
524 unsigned int num_include_dirs, include_dirs_size;
527 /* The file_names table. NOTE! These strings are not allocated
528 with xmalloc; instead, they are pointers into debug_line_buffer.
529 Don't try to free them directly. */
530 unsigned int num_file_names, file_names_size;
534 unsigned int dir_index;
535 unsigned int mod_time;
537 int included_p; /* Non-zero if referenced by the Line Number Program. */
538 struct symtab *symtab; /* The associated symbol table, if any. */
541 /* The start and end of the statement program following this
542 header. These point into dwarf2_per_objfile->line_buffer. */
543 gdb_byte *statement_program_start, *statement_program_end;
546 /* When we construct a partial symbol table entry we only
547 need this much information. */
548 struct partial_die_info
550 /* Offset of this DIE. */
553 /* DWARF-2 tag for this DIE. */
554 ENUM_BITFIELD(dwarf_tag) tag : 16;
556 /* Assorted flags describing the data found in this DIE. */
557 unsigned int has_children : 1;
558 unsigned int is_external : 1;
559 unsigned int is_declaration : 1;
560 unsigned int has_type : 1;
561 unsigned int has_specification : 1;
562 unsigned int has_pc_info : 1;
564 /* Flag set if the SCOPE field of this structure has been
566 unsigned int scope_set : 1;
568 /* Flag set if the DIE has a byte_size attribute. */
569 unsigned int has_byte_size : 1;
571 /* Flag set if any of the DIE's children are template arguments. */
572 unsigned int has_template_arguments : 1;
574 /* Flag set if fixup_partial_die has been called on this die. */
575 unsigned int fixup_called : 1;
577 /* The name of this DIE. Normally the value of DW_AT_name, but
578 sometimes a default name for unnamed DIEs. */
581 /* The linkage name, if present. */
582 const char *linkage_name;
584 /* The scope to prepend to our children. This is generally
585 allocated on the comp_unit_obstack, so will disappear
586 when this compilation unit leaves the cache. */
589 /* The location description associated with this DIE, if any. */
590 struct dwarf_block *locdesc;
592 /* If HAS_PC_INFO, the PC range associated with this DIE. */
596 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
597 DW_AT_sibling, if any. */
598 /* NOTE: This member isn't strictly necessary, read_partial_die could
599 return DW_AT_sibling values to its caller load_partial_dies. */
602 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
603 DW_AT_specification (or DW_AT_abstract_origin or
605 unsigned int spec_offset;
607 /* Pointers to this DIE's parent, first child, and next sibling,
609 struct partial_die_info *die_parent, *die_child, *die_sibling;
612 /* This data structure holds the information of an abbrev. */
615 unsigned int number; /* number identifying abbrev */
616 enum dwarf_tag tag; /* dwarf tag */
617 unsigned short has_children; /* boolean */
618 unsigned short num_attrs; /* number of attributes */
619 struct attr_abbrev *attrs; /* an array of attribute descriptions */
620 struct abbrev_info *next; /* next in chain */
625 ENUM_BITFIELD(dwarf_attribute) name : 16;
626 ENUM_BITFIELD(dwarf_form) form : 16;
629 /* Attributes have a name and a value. */
632 ENUM_BITFIELD(dwarf_attribute) name : 16;
633 ENUM_BITFIELD(dwarf_form) form : 15;
635 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
636 field should be in u.str (existing only for DW_STRING) but it is kept
637 here for better struct attribute alignment. */
638 unsigned int string_is_canonical : 1;
643 struct dwarf_block *blk;
647 struct signatured_type *signatured_type;
652 /* This data structure holds a complete die structure. */
655 /* DWARF-2 tag for this DIE. */
656 ENUM_BITFIELD(dwarf_tag) tag : 16;
658 /* Number of attributes */
659 unsigned char num_attrs;
661 /* True if we're presently building the full type name for the
662 type derived from this DIE. */
663 unsigned char building_fullname : 1;
668 /* Offset in .debug_info or .debug_types section. */
671 /* The dies in a compilation unit form an n-ary tree. PARENT
672 points to this die's parent; CHILD points to the first child of
673 this node; and all the children of a given node are chained
674 together via their SIBLING fields. */
675 struct die_info *child; /* Its first child, if any. */
676 struct die_info *sibling; /* Its next sibling, if any. */
677 struct die_info *parent; /* Its parent, if any. */
679 /* An array of attributes, with NUM_ATTRS elements. There may be
680 zero, but it's not common and zero-sized arrays are not
681 sufficiently portable C. */
682 struct attribute attrs[1];
685 struct function_range
688 CORE_ADDR lowpc, highpc;
690 struct function_range *next;
693 /* Get at parts of an attribute structure. */
695 #define DW_STRING(attr) ((attr)->u.str)
696 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
697 #define DW_UNSND(attr) ((attr)->u.unsnd)
698 #define DW_BLOCK(attr) ((attr)->u.blk)
699 #define DW_SND(attr) ((attr)->u.snd)
700 #define DW_ADDR(attr) ((attr)->u.addr)
701 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
703 /* Blocks are a bunch of untyped bytes. */
710 #ifndef ATTR_ALLOC_CHUNK
711 #define ATTR_ALLOC_CHUNK 4
714 /* Allocate fields for structs, unions and enums in this size. */
715 #ifndef DW_FIELD_ALLOC_CHUNK
716 #define DW_FIELD_ALLOC_CHUNK 4
719 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
720 but this would require a corresponding change in unpack_field_as_long
722 static int bits_per_byte = 8;
724 /* The routines that read and process dies for a C struct or C++ class
725 pass lists of data member fields and lists of member function fields
726 in an instance of a field_info structure, as defined below. */
729 /* List of data member and baseclasses fields. */
732 struct nextfield *next;
737 *fields, *baseclasses;
739 /* Number of fields (including baseclasses). */
742 /* Number of baseclasses. */
745 /* Set if the accesibility of one of the fields is not public. */
746 int non_public_fields;
748 /* Member function fields array, entries are allocated in the order they
749 are encountered in the object file. */
752 struct nextfnfield *next;
753 struct fn_field fnfield;
757 /* Member function fieldlist array, contains name of possibly overloaded
758 member function, number of overloaded member functions and a pointer
759 to the head of the member function field chain. */
764 struct nextfnfield *head;
768 /* Number of entries in the fnfieldlists array. */
771 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
772 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
773 struct typedef_field_list
775 struct typedef_field field;
776 struct typedef_field_list *next;
779 unsigned typedef_field_list_count;
782 /* One item on the queue of compilation units to read in full symbols
784 struct dwarf2_queue_item
786 struct dwarf2_per_cu_data *per_cu;
787 struct dwarf2_queue_item *next;
790 /* The current queue. */
791 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
793 /* Loaded secondary compilation units are kept in memory until they
794 have not been referenced for the processing of this many
795 compilation units. Set this to zero to disable caching. Cache
796 sizes of up to at least twenty will improve startup time for
797 typical inter-CU-reference binaries, at an obvious memory cost. */
798 static int dwarf2_max_cache_age = 5;
800 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
801 struct cmd_list_element *c, const char *value)
803 fprintf_filtered (file, _("The upper bound on the age of cached "
804 "dwarf2 compilation units is %s.\n"),
809 /* Various complaints about symbol reading that don't abort the process. */
812 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
814 complaint (&symfile_complaints,
815 _("statement list doesn't fit in .debug_line section"));
819 dwarf2_debug_line_missing_file_complaint (void)
821 complaint (&symfile_complaints,
822 _(".debug_line section has line data without a file"));
826 dwarf2_debug_line_missing_end_sequence_complaint (void)
828 complaint (&symfile_complaints,
829 _(".debug_line section has line "
830 "program sequence without an end"));
834 dwarf2_complex_location_expr_complaint (void)
836 complaint (&symfile_complaints, _("location expression too complex"));
840 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
843 complaint (&symfile_complaints,
844 _("const value length mismatch for '%s', got %d, expected %d"),
849 dwarf2_macros_too_long_complaint (void)
851 complaint (&symfile_complaints,
852 _("macro info runs off end of `.debug_macinfo' section"));
856 dwarf2_macro_malformed_definition_complaint (const char *arg1)
858 complaint (&symfile_complaints,
859 _("macro debug info contains a "
860 "malformed macro definition:\n`%s'"),
865 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
867 complaint (&symfile_complaints,
868 _("invalid attribute class or form for '%s' in '%s'"),
872 /* local function prototypes */
874 static void dwarf2_locate_sections (bfd *, asection *, void *);
876 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
879 static void dwarf2_build_psymtabs_hard (struct objfile *);
881 static void scan_partial_symbols (struct partial_die_info *,
882 CORE_ADDR *, CORE_ADDR *,
883 int, struct dwarf2_cu *);
885 static void add_partial_symbol (struct partial_die_info *,
888 static void add_partial_namespace (struct partial_die_info *pdi,
889 CORE_ADDR *lowpc, CORE_ADDR *highpc,
890 int need_pc, struct dwarf2_cu *cu);
892 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
893 CORE_ADDR *highpc, int need_pc,
894 struct dwarf2_cu *cu);
896 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
897 struct dwarf2_cu *cu);
899 static void add_partial_subprogram (struct partial_die_info *pdi,
900 CORE_ADDR *lowpc, CORE_ADDR *highpc,
901 int need_pc, struct dwarf2_cu *cu);
903 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
904 gdb_byte *buffer, gdb_byte *info_ptr,
905 bfd *abfd, struct dwarf2_cu *cu);
907 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
909 static void psymtab_to_symtab_1 (struct partial_symtab *);
911 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
913 static void dwarf2_free_abbrev_table (void *);
915 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
918 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
921 static struct partial_die_info *load_partial_dies (bfd *,
922 gdb_byte *, gdb_byte *,
923 int, struct dwarf2_cu *);
925 static gdb_byte *read_partial_die (struct partial_die_info *,
926 struct abbrev_info *abbrev,
928 gdb_byte *, gdb_byte *,
931 static struct partial_die_info *find_partial_die (unsigned int,
934 static void fixup_partial_die (struct partial_die_info *,
937 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
938 bfd *, gdb_byte *, struct dwarf2_cu *);
940 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
941 bfd *, gdb_byte *, struct dwarf2_cu *);
943 static unsigned int read_1_byte (bfd *, gdb_byte *);
945 static int read_1_signed_byte (bfd *, gdb_byte *);
947 static unsigned int read_2_bytes (bfd *, gdb_byte *);
949 static unsigned int read_4_bytes (bfd *, gdb_byte *);
951 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
953 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
956 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
958 static LONGEST read_checked_initial_length_and_offset
959 (bfd *, gdb_byte *, const struct comp_unit_head *,
960 unsigned int *, unsigned int *);
962 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
965 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
967 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
969 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
971 static char *read_indirect_string (bfd *, gdb_byte *,
972 const struct comp_unit_head *,
975 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
977 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
979 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
981 static void set_cu_language (unsigned int, struct dwarf2_cu *);
983 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
986 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
990 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
991 struct dwarf2_cu *cu);
993 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
995 static struct die_info *die_specification (struct die_info *die,
996 struct dwarf2_cu **);
998 static void free_line_header (struct line_header *lh);
1000 static void add_file_name (struct line_header *, char *, unsigned int,
1001 unsigned int, unsigned int);
1003 static struct line_header *(dwarf_decode_line_header
1004 (unsigned int offset,
1005 bfd *abfd, struct dwarf2_cu *cu));
1007 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
1008 struct dwarf2_cu *, struct partial_symtab *);
1010 static void dwarf2_start_subfile (char *, const char *, const char *);
1012 static struct symbol *new_symbol (struct die_info *, struct type *,
1013 struct dwarf2_cu *);
1015 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1016 struct dwarf2_cu *, struct symbol *);
1018 static void dwarf2_const_value (struct attribute *, struct symbol *,
1019 struct dwarf2_cu *);
1021 static void dwarf2_const_value_attr (struct attribute *attr,
1024 struct obstack *obstack,
1025 struct dwarf2_cu *cu, long *value,
1027 struct dwarf2_locexpr_baton **baton);
1029 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1031 static int need_gnat_info (struct dwarf2_cu *);
1033 static struct type *die_descriptive_type (struct die_info *,
1034 struct dwarf2_cu *);
1036 static void set_descriptive_type (struct type *, struct die_info *,
1037 struct dwarf2_cu *);
1039 static struct type *die_containing_type (struct die_info *,
1040 struct dwarf2_cu *);
1042 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1043 struct dwarf2_cu *);
1045 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1047 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1049 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1051 static char *typename_concat (struct obstack *obs, const char *prefix,
1052 const char *suffix, int physname,
1053 struct dwarf2_cu *cu);
1055 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1057 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1059 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1061 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1063 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1064 struct dwarf2_cu *, struct partial_symtab *);
1066 static int dwarf2_get_pc_bounds (struct die_info *,
1067 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1068 struct partial_symtab *);
1070 static void get_scope_pc_bounds (struct die_info *,
1071 CORE_ADDR *, CORE_ADDR *,
1072 struct dwarf2_cu *);
1074 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1075 CORE_ADDR, struct dwarf2_cu *);
1077 static void dwarf2_add_field (struct field_info *, struct die_info *,
1078 struct dwarf2_cu *);
1080 static void dwarf2_attach_fields_to_type (struct field_info *,
1081 struct type *, struct dwarf2_cu *);
1083 static void dwarf2_add_member_fn (struct field_info *,
1084 struct die_info *, struct type *,
1085 struct dwarf2_cu *);
1087 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1089 struct dwarf2_cu *);
1091 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1093 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1095 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1097 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1099 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1101 static struct type *read_module_type (struct die_info *die,
1102 struct dwarf2_cu *cu);
1104 static const char *namespace_name (struct die_info *die,
1105 int *is_anonymous, struct dwarf2_cu *);
1107 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1109 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1111 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1112 struct dwarf2_cu *);
1114 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1116 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1118 gdb_byte **new_info_ptr,
1119 struct die_info *parent);
1121 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1123 gdb_byte **new_info_ptr,
1124 struct die_info *parent);
1126 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1128 gdb_byte **new_info_ptr,
1129 struct die_info *parent);
1131 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1132 struct die_info **, gdb_byte *,
1135 static void process_die (struct die_info *, struct dwarf2_cu *);
1137 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1140 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1142 static const char *dwarf2_full_name (char *name,
1143 struct die_info *die,
1144 struct dwarf2_cu *cu);
1146 static struct die_info *dwarf2_extension (struct die_info *die,
1147 struct dwarf2_cu **);
1149 static char *dwarf_tag_name (unsigned int);
1151 static char *dwarf_attr_name (unsigned int);
1153 static char *dwarf_form_name (unsigned int);
1155 static char *dwarf_bool_name (unsigned int);
1157 static char *dwarf_type_encoding_name (unsigned int);
1160 static char *dwarf_cfi_name (unsigned int);
1163 static struct die_info *sibling_die (struct die_info *);
1165 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1167 static void dump_die_for_error (struct die_info *);
1169 static void dump_die_1 (struct ui_file *, int level, int max_level,
1172 /*static*/ void dump_die (struct die_info *, int max_level);
1174 static void store_in_ref_table (struct die_info *,
1175 struct dwarf2_cu *);
1177 static int is_ref_attr (struct attribute *);
1179 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1181 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1183 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1185 struct dwarf2_cu **);
1187 static struct die_info *follow_die_ref (struct die_info *,
1189 struct dwarf2_cu **);
1191 static struct die_info *follow_die_sig (struct die_info *,
1193 struct dwarf2_cu **);
1195 static void read_signatured_type_at_offset (struct objfile *objfile,
1196 unsigned int offset);
1198 static void read_signatured_type (struct objfile *,
1199 struct signatured_type *type_sig);
1201 /* memory allocation interface */
1203 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1205 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1207 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1209 static void initialize_cu_func_list (struct dwarf2_cu *);
1211 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1212 struct dwarf2_cu *);
1214 static void dwarf_decode_macros (struct line_header *, unsigned int,
1215 char *, bfd *, struct dwarf2_cu *);
1217 static int attr_form_is_block (struct attribute *);
1219 static int attr_form_is_section_offset (struct attribute *);
1221 static int attr_form_is_constant (struct attribute *);
1223 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1224 struct dwarf2_loclist_baton *baton,
1225 struct attribute *attr);
1227 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1229 struct dwarf2_cu *cu);
1231 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1232 struct abbrev_info *abbrev,
1233 struct dwarf2_cu *cu);
1235 static void free_stack_comp_unit (void *);
1237 static hashval_t partial_die_hash (const void *item);
1239 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1241 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1242 (unsigned int offset, struct objfile *objfile);
1244 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1245 (unsigned int offset, struct objfile *objfile);
1247 static void init_one_comp_unit (struct dwarf2_cu *cu,
1248 struct objfile *objfile);
1250 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1251 struct die_info *comp_unit_die);
1253 static void free_one_comp_unit (void *);
1255 static void free_cached_comp_units (void *);
1257 static void age_cached_comp_units (void);
1259 static void free_one_cached_comp_unit (void *);
1261 static struct type *set_die_type (struct die_info *, struct type *,
1262 struct dwarf2_cu *);
1264 static void create_all_comp_units (struct objfile *);
1266 static int create_debug_types_hash_table (struct objfile *objfile);
1268 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1271 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1273 static void dwarf2_add_dependence (struct dwarf2_cu *,
1274 struct dwarf2_per_cu_data *);
1276 static void dwarf2_mark (struct dwarf2_cu *);
1278 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1280 static struct type *get_die_type_at_offset (unsigned int,
1281 struct dwarf2_per_cu_data *per_cu);
1283 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1285 static void dwarf2_release_queue (void *dummy);
1287 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1288 struct objfile *objfile);
1290 static void process_queue (struct objfile *objfile);
1292 static void find_file_and_directory (struct die_info *die,
1293 struct dwarf2_cu *cu,
1294 char **name, char **comp_dir);
1296 static char *file_full_name (int file, struct line_header *lh,
1297 const char *comp_dir);
1299 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1302 unsigned int buffer_size,
1305 static void init_cu_die_reader (struct die_reader_specs *reader,
1306 struct dwarf2_cu *cu);
1308 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1312 /* Convert VALUE between big- and little-endian. */
1314 byte_swap (offset_type value)
1318 result = (value & 0xff) << 24;
1319 result |= (value & 0xff00) << 8;
1320 result |= (value & 0xff0000) >> 8;
1321 result |= (value & 0xff000000) >> 24;
1325 #define MAYBE_SWAP(V) byte_swap (V)
1328 #define MAYBE_SWAP(V) (V)
1329 #endif /* WORDS_BIGENDIAN */
1331 /* The suffix for an index file. */
1332 #define INDEX_SUFFIX ".gdb-index"
1334 static const char *dwarf2_physname (char *name, struct die_info *die,
1335 struct dwarf2_cu *cu);
1337 /* Try to locate the sections we need for DWARF 2 debugging
1338 information and return true if we have enough to do something. */
1341 dwarf2_has_info (struct objfile *objfile)
1343 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1344 if (!dwarf2_per_objfile)
1346 /* Initialize per-objfile state. */
1347 struct dwarf2_per_objfile *data
1348 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1350 memset (data, 0, sizeof (*data));
1351 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1352 dwarf2_per_objfile = data;
1354 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1355 dwarf2_per_objfile->objfile = objfile;
1357 return (dwarf2_per_objfile->info.asection != NULL
1358 && dwarf2_per_objfile->abbrev.asection != NULL);
1361 /* When loading sections, we can either look for ".<name>", or for
1362 * ".z<name>", which indicates a compressed section. */
1365 section_is_p (const char *section_name, const char *name)
1367 return (section_name[0] == '.'
1368 && (strcmp (section_name + 1, name) == 0
1369 || (section_name[1] == 'z'
1370 && strcmp (section_name + 2, name) == 0)));
1373 /* This function is mapped across the sections and remembers the
1374 offset and size of each of the debugging sections we are interested
1378 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1380 if (section_is_p (sectp->name, INFO_SECTION))
1382 dwarf2_per_objfile->info.asection = sectp;
1383 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1385 else if (section_is_p (sectp->name, ABBREV_SECTION))
1387 dwarf2_per_objfile->abbrev.asection = sectp;
1388 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1390 else if (section_is_p (sectp->name, LINE_SECTION))
1392 dwarf2_per_objfile->line.asection = sectp;
1393 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1395 else if (section_is_p (sectp->name, LOC_SECTION))
1397 dwarf2_per_objfile->loc.asection = sectp;
1398 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1400 else if (section_is_p (sectp->name, MACINFO_SECTION))
1402 dwarf2_per_objfile->macinfo.asection = sectp;
1403 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1405 else if (section_is_p (sectp->name, STR_SECTION))
1407 dwarf2_per_objfile->str.asection = sectp;
1408 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1410 else if (section_is_p (sectp->name, FRAME_SECTION))
1412 dwarf2_per_objfile->frame.asection = sectp;
1413 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1415 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1417 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1419 if (aflag & SEC_HAS_CONTENTS)
1421 dwarf2_per_objfile->eh_frame.asection = sectp;
1422 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1425 else if (section_is_p (sectp->name, RANGES_SECTION))
1427 dwarf2_per_objfile->ranges.asection = sectp;
1428 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1430 else if (section_is_p (sectp->name, TYPES_SECTION))
1432 dwarf2_per_objfile->types.asection = sectp;
1433 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1435 else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
1437 dwarf2_per_objfile->gdb_index.asection = sectp;
1438 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1441 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1442 && bfd_section_vma (abfd, sectp) == 0)
1443 dwarf2_per_objfile->has_section_at_zero = 1;
1446 /* Decompress a section that was compressed using zlib. Store the
1447 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1450 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1451 gdb_byte **outbuf, bfd_size_type *outsize)
1453 bfd *abfd = objfile->obfd;
1455 error (_("Support for zlib-compressed DWARF data (from '%s') "
1456 "is disabled in this copy of GDB"),
1457 bfd_get_filename (abfd));
1459 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1460 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1461 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1462 bfd_size_type uncompressed_size;
1463 gdb_byte *uncompressed_buffer;
1466 int header_size = 12;
1468 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1469 || bfd_bread (compressed_buffer,
1470 compressed_size, abfd) != compressed_size)
1471 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1472 bfd_get_filename (abfd));
1474 /* Read the zlib header. In this case, it should be "ZLIB" followed
1475 by the uncompressed section size, 8 bytes in big-endian order. */
1476 if (compressed_size < header_size
1477 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1478 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1479 bfd_get_filename (abfd));
1480 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1481 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1482 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1483 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1484 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1485 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1486 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1487 uncompressed_size += compressed_buffer[11];
1489 /* It is possible the section consists of several compressed
1490 buffers concatenated together, so we uncompress in a loop. */
1494 strm.avail_in = compressed_size - header_size;
1495 strm.next_in = (Bytef*) compressed_buffer + header_size;
1496 strm.avail_out = uncompressed_size;
1497 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1499 rc = inflateInit (&strm);
1500 while (strm.avail_in > 0)
1503 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1504 bfd_get_filename (abfd), rc);
1505 strm.next_out = ((Bytef*) uncompressed_buffer
1506 + (uncompressed_size - strm.avail_out));
1507 rc = inflate (&strm, Z_FINISH);
1508 if (rc != Z_STREAM_END)
1509 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1510 bfd_get_filename (abfd), rc);
1511 rc = inflateReset (&strm);
1513 rc = inflateEnd (&strm);
1515 || strm.avail_out != 0)
1516 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1517 bfd_get_filename (abfd), rc);
1519 do_cleanups (cleanup);
1520 *outbuf = uncompressed_buffer;
1521 *outsize = uncompressed_size;
1525 /* A helper function that decides whether a section is empty. */
1528 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1530 return info->asection == NULL || info->size == 0;
1533 /* Read the contents of the section SECTP from object file specified by
1534 OBJFILE, store info about the section into INFO.
1535 If the section is compressed, uncompress it before returning. */
1538 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1540 bfd *abfd = objfile->obfd;
1541 asection *sectp = info->asection;
1542 gdb_byte *buf, *retbuf;
1543 unsigned char header[4];
1547 info->buffer = NULL;
1548 info->was_mmapped = 0;
1551 if (dwarf2_section_empty_p (info))
1554 /* Check if the file has a 4-byte header indicating compression. */
1555 if (info->size > sizeof (header)
1556 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1557 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1559 /* Upon decompression, update the buffer and its size. */
1560 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1562 zlib_decompress_section (objfile, sectp, &info->buffer,
1570 pagesize = getpagesize ();
1572 /* Only try to mmap sections which are large enough: we don't want to
1573 waste space due to fragmentation. Also, only try mmap for sections
1574 without relocations. */
1576 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1578 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1579 size_t map_length = info->size + sectp->filepos - pg_offset;
1580 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1581 MAP_PRIVATE, pg_offset);
1583 if (retbuf != MAP_FAILED)
1585 info->was_mmapped = 1;
1586 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1587 #if HAVE_POSIX_MADVISE
1588 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1595 /* If we get here, we are a normal, not-compressed section. */
1597 = obstack_alloc (&objfile->objfile_obstack, info->size);
1599 /* When debugging .o files, we may need to apply relocations; see
1600 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1601 We never compress sections in .o files, so we only need to
1602 try this when the section is not compressed. */
1603 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1606 info->buffer = retbuf;
1610 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1611 || bfd_bread (buf, info->size, abfd) != info->size)
1612 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1613 bfd_get_filename (abfd));
1616 /* A helper function that returns the size of a section in a safe way.
1617 If you are positive that the section has been read before using the
1618 size, then it is safe to refer to the dwarf2_section_info object's
1619 "size" field directly. In other cases, you must call this
1620 function, because for compressed sections the size field is not set
1621 correctly until the section has been read. */
1623 static bfd_size_type
1624 dwarf2_section_size (struct objfile *objfile,
1625 struct dwarf2_section_info *info)
1628 dwarf2_read_section (objfile, info);
1632 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1636 dwarf2_get_section_info (struct objfile *objfile,
1637 enum dwarf2_section_enum sect,
1638 asection **sectp, gdb_byte **bufp,
1639 bfd_size_type *sizep)
1641 struct dwarf2_per_objfile *data
1642 = objfile_data (objfile, dwarf2_objfile_data_key);
1643 struct dwarf2_section_info *info;
1645 /* We may see an objfile without any DWARF, in which case we just
1656 case DWARF2_DEBUG_FRAME:
1657 info = &data->frame;
1659 case DWARF2_EH_FRAME:
1660 info = &data->eh_frame;
1663 gdb_assert_not_reached ("unexpected section");
1666 dwarf2_read_section (objfile, info);
1668 *sectp = info->asection;
1669 *bufp = info->buffer;
1670 *sizep = info->size;
1674 /* DWARF quick_symbols_functions support. */
1676 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1677 unique line tables, so we maintain a separate table of all .debug_line
1678 derived entries to support the sharing.
1679 All the quick functions need is the list of file names. We discard the
1680 line_header when we're done and don't need to record it here. */
1681 struct quick_file_names
1683 /* The offset in .debug_line of the line table. We hash on this. */
1684 unsigned int offset;
1686 /* The number of entries in file_names, real_names. */
1687 unsigned int num_file_names;
1689 /* The file names from the line table, after being run through
1691 const char **file_names;
1693 /* The file names from the line table after being run through
1694 gdb_realpath. These are computed lazily. */
1695 const char **real_names;
1698 /* When using the index (and thus not using psymtabs), each CU has an
1699 object of this type. This is used to hold information needed by
1700 the various "quick" methods. */
1701 struct dwarf2_per_cu_quick_data
1703 /* The file table. This can be NULL if there was no file table
1704 or it's currently not read in.
1705 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1706 struct quick_file_names *file_names;
1708 /* The corresponding symbol table. This is NULL if symbols for this
1709 CU have not yet been read. */
1710 struct symtab *symtab;
1712 /* A temporary mark bit used when iterating over all CUs in
1713 expand_symtabs_matching. */
1714 unsigned int mark : 1;
1716 /* True if we've tried to read the file table and found there isn't one.
1717 There will be no point in trying to read it again next time. */
1718 unsigned int no_file_data : 1;
1721 /* Hash function for a quick_file_names. */
1724 hash_file_name_entry (const void *e)
1726 const struct quick_file_names *file_data = e;
1728 return file_data->offset;
1731 /* Equality function for a quick_file_names. */
1734 eq_file_name_entry (const void *a, const void *b)
1736 const struct quick_file_names *ea = a;
1737 const struct quick_file_names *eb = b;
1739 return ea->offset == eb->offset;
1742 /* Delete function for a quick_file_names. */
1745 delete_file_name_entry (void *e)
1747 struct quick_file_names *file_data = e;
1750 for (i = 0; i < file_data->num_file_names; ++i)
1752 xfree ((void*) file_data->file_names[i]);
1753 if (file_data->real_names)
1754 xfree ((void*) file_data->real_names[i]);
1757 /* The space for the struct itself lives on objfile_obstack,
1758 so we don't free it here. */
1761 /* Create a quick_file_names hash table. */
1764 create_quick_file_names_table (unsigned int nr_initial_entries)
1766 return htab_create_alloc (nr_initial_entries,
1767 hash_file_name_entry, eq_file_name_entry,
1768 delete_file_name_entry, xcalloc, xfree);
1771 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1775 dw2_do_instantiate_symtab (struct objfile *objfile,
1776 struct dwarf2_per_cu_data *per_cu)
1778 struct cleanup *back_to;
1780 back_to = make_cleanup (dwarf2_release_queue, NULL);
1782 queue_comp_unit (per_cu, objfile);
1784 if (per_cu->from_debug_types)
1785 read_signatured_type_at_offset (objfile, per_cu->offset);
1787 load_full_comp_unit (per_cu, objfile);
1789 process_queue (objfile);
1791 /* Age the cache, releasing compilation units that have not
1792 been used recently. */
1793 age_cached_comp_units ();
1795 do_cleanups (back_to);
1798 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1799 the objfile from which this CU came. Returns the resulting symbol
1802 static struct symtab *
1803 dw2_instantiate_symtab (struct objfile *objfile,
1804 struct dwarf2_per_cu_data *per_cu)
1806 if (!per_cu->v.quick->symtab)
1808 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1809 increment_reading_symtab ();
1810 dw2_do_instantiate_symtab (objfile, per_cu);
1811 do_cleanups (back_to);
1813 return per_cu->v.quick->symtab;
1816 /* Return the CU given its index. */
1818 static struct dwarf2_per_cu_data *
1819 dw2_get_cu (int index)
1821 if (index >= dwarf2_per_objfile->n_comp_units)
1823 index -= dwarf2_per_objfile->n_comp_units;
1824 return dwarf2_per_objfile->type_comp_units[index];
1826 return dwarf2_per_objfile->all_comp_units[index];
1829 /* A helper function that knows how to read a 64-bit value in a way
1830 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1834 extract_cu_value (const char *bytes, ULONGEST *result)
1836 if (sizeof (ULONGEST) < 8)
1840 /* Ignore the upper 4 bytes if they are all zero. */
1841 for (i = 0; i < 4; ++i)
1842 if (bytes[i + 4] != 0)
1845 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1848 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1852 /* Read the CU list from the mapped index, and use it to create all
1853 the CU objects for this objfile. Return 0 if something went wrong,
1854 1 if everything went ok. */
1857 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1858 offset_type cu_list_elements)
1862 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1863 dwarf2_per_objfile->all_comp_units
1864 = obstack_alloc (&objfile->objfile_obstack,
1865 dwarf2_per_objfile->n_comp_units
1866 * sizeof (struct dwarf2_per_cu_data *));
1868 for (i = 0; i < cu_list_elements; i += 2)
1870 struct dwarf2_per_cu_data *the_cu;
1871 ULONGEST offset, length;
1873 if (!extract_cu_value (cu_list, &offset)
1874 || !extract_cu_value (cu_list + 8, &length))
1878 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1879 struct dwarf2_per_cu_data);
1880 the_cu->offset = offset;
1881 the_cu->length = length;
1882 the_cu->objfile = objfile;
1883 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1884 struct dwarf2_per_cu_quick_data);
1885 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1891 /* Create the signatured type hash table from the index. */
1894 create_signatured_type_table_from_index (struct objfile *objfile,
1895 const gdb_byte *bytes,
1896 offset_type elements)
1899 htab_t sig_types_hash;
1901 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1902 dwarf2_per_objfile->type_comp_units
1903 = obstack_alloc (&objfile->objfile_obstack,
1904 dwarf2_per_objfile->n_type_comp_units
1905 * sizeof (struct dwarf2_per_cu_data *));
1907 sig_types_hash = allocate_signatured_type_table (objfile);
1909 for (i = 0; i < elements; i += 3)
1911 struct signatured_type *type_sig;
1912 ULONGEST offset, type_offset, signature;
1915 if (!extract_cu_value (bytes, &offset)
1916 || !extract_cu_value (bytes + 8, &type_offset))
1918 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1921 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1922 struct signatured_type);
1923 type_sig->signature = signature;
1924 type_sig->type_offset = type_offset;
1925 type_sig->per_cu.from_debug_types = 1;
1926 type_sig->per_cu.offset = offset;
1927 type_sig->per_cu.objfile = objfile;
1928 type_sig->per_cu.v.quick
1929 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1930 struct dwarf2_per_cu_quick_data);
1932 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1935 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1938 dwarf2_per_objfile->signatured_types = sig_types_hash;
1943 /* Read the address map data from the mapped index, and use it to
1944 populate the objfile's psymtabs_addrmap. */
1947 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1949 const gdb_byte *iter, *end;
1950 struct obstack temp_obstack;
1951 struct addrmap *mutable_map;
1952 struct cleanup *cleanup;
1955 obstack_init (&temp_obstack);
1956 cleanup = make_cleanup_obstack_free (&temp_obstack);
1957 mutable_map = addrmap_create_mutable (&temp_obstack);
1959 iter = index->address_table;
1960 end = iter + index->address_table_size;
1962 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1966 ULONGEST hi, lo, cu_index;
1967 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1969 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1971 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1974 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1975 dw2_get_cu (cu_index));
1978 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1979 &objfile->objfile_obstack);
1980 do_cleanups (cleanup);
1983 /* The hash function for strings in the mapped index. This is the same as
1984 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1985 implementation. This is necessary because the hash function is tied to the
1986 format of the mapped index file. The hash values do not have to match with
1989 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
1992 mapped_index_string_hash (int index_version, const void *p)
1994 const unsigned char *str = (const unsigned char *) p;
1998 while ((c = *str++) != 0)
2000 if (index_version >= 5)
2002 r = r * 67 + c - 113;
2008 /* Find a slot in the mapped index INDEX for the object named NAME.
2009 If NAME is found, set *VEC_OUT to point to the CU vector in the
2010 constant pool and return 1. If NAME cannot be found, return 0. */
2013 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2014 offset_type **vec_out)
2016 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2018 offset_type slot, step;
2019 int (*cmp) (const char *, const char *);
2021 if (current_language->la_language == language_cplus
2022 || current_language->la_language == language_java
2023 || current_language->la_language == language_fortran)
2025 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2027 const char *paren = strchr (name, '(');
2033 dup = xmalloc (paren - name + 1);
2034 memcpy (dup, name, paren - name);
2035 dup[paren - name] = 0;
2037 make_cleanup (xfree, dup);
2042 /* Index version 4 did not support case insensitive searches. But the
2043 indexes for case insensitive languages are built in lowercase, therefore
2044 simulate our NAME being searched is also lowercased. */
2045 hash = mapped_index_string_hash ((index->version == 4
2046 && case_sensitivity == case_sensitive_off
2047 ? 5 : index->version),
2050 slot = hash & (index->symbol_table_slots - 1);
2051 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2052 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2056 /* Convert a slot number to an offset into the table. */
2057 offset_type i = 2 * slot;
2059 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2061 do_cleanups (back_to);
2065 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2066 if (!cmp (name, str))
2068 *vec_out = (offset_type *) (index->constant_pool
2069 + MAYBE_SWAP (index->symbol_table[i + 1]));
2070 do_cleanups (back_to);
2074 slot = (slot + step) & (index->symbol_table_slots - 1);
2078 /* Read the index file. If everything went ok, initialize the "quick"
2079 elements of all the CUs and return 1. Otherwise, return 0. */
2082 dwarf2_read_index (struct objfile *objfile)
2085 struct mapped_index *map;
2086 offset_type *metadata;
2087 const gdb_byte *cu_list;
2088 const gdb_byte *types_list = NULL;
2089 offset_type version, cu_list_elements;
2090 offset_type types_list_elements = 0;
2093 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2096 /* Older elfutils strip versions could keep the section in the main
2097 executable while splitting it for the separate debug info file. */
2098 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2099 & SEC_HAS_CONTENTS) == 0)
2102 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2104 addr = dwarf2_per_objfile->gdb_index.buffer;
2105 /* Version check. */
2106 version = MAYBE_SWAP (*(offset_type *) addr);
2107 /* Versions earlier than 3 emitted every copy of a psymbol. This
2108 causes the index to behave very poorly for certain requests. Version 3
2109 contained incomplete addrmap. So, it seems better to just ignore such
2110 indices. Index version 4 uses a different hash function than index
2111 version 5 and later. */
2114 /* Indexes with higher version than the one supported by GDB may be no
2115 longer backward compatible. */
2119 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2120 map->version = version;
2121 map->total_size = dwarf2_per_objfile->gdb_index.size;
2123 metadata = (offset_type *) (addr + sizeof (offset_type));
2126 cu_list = addr + MAYBE_SWAP (metadata[i]);
2127 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2131 types_list = addr + MAYBE_SWAP (metadata[i]);
2132 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2133 - MAYBE_SWAP (metadata[i]))
2137 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2138 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2139 - MAYBE_SWAP (metadata[i]));
2142 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2143 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2144 - MAYBE_SWAP (metadata[i]))
2145 / (2 * sizeof (offset_type)));
2148 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2150 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2153 if (types_list_elements
2154 && !create_signatured_type_table_from_index (objfile, types_list,
2155 types_list_elements))
2158 create_addrmap_from_index (objfile, map);
2160 dwarf2_per_objfile->index_table = map;
2161 dwarf2_per_objfile->using_index = 1;
2162 dwarf2_per_objfile->quick_file_names_table =
2163 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2168 /* A helper for the "quick" functions which sets the global
2169 dwarf2_per_objfile according to OBJFILE. */
2172 dw2_setup (struct objfile *objfile)
2174 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2175 gdb_assert (dwarf2_per_objfile);
2178 /* A helper for the "quick" functions which attempts to read the line
2179 table for THIS_CU. */
2181 static struct quick_file_names *
2182 dw2_get_file_names (struct objfile *objfile,
2183 struct dwarf2_per_cu_data *this_cu)
2185 bfd *abfd = objfile->obfd;
2186 struct line_header *lh;
2187 struct attribute *attr;
2188 struct cleanup *cleanups;
2189 struct die_info *comp_unit_die;
2190 struct dwarf2_section_info* sec;
2191 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2192 int has_children, i;
2193 struct dwarf2_cu cu;
2194 unsigned int bytes_read, buffer_size;
2195 struct die_reader_specs reader_specs;
2196 char *name, *comp_dir;
2198 struct quick_file_names *qfn;
2199 unsigned int line_offset;
2201 if (this_cu->v.quick->file_names != NULL)
2202 return this_cu->v.quick->file_names;
2203 /* If we know there is no line data, no point in looking again. */
2204 if (this_cu->v.quick->no_file_data)
2207 init_one_comp_unit (&cu, objfile);
2208 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2210 if (this_cu->from_debug_types)
2211 sec = &dwarf2_per_objfile->types;
2213 sec = &dwarf2_per_objfile->info;
2214 dwarf2_read_section (objfile, sec);
2215 buffer_size = sec->size;
2216 buffer = sec->buffer;
2217 info_ptr = buffer + this_cu->offset;
2218 beg_of_comp_unit = info_ptr;
2220 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2221 buffer, buffer_size,
2224 /* Complete the cu_header. */
2225 cu.header.offset = beg_of_comp_unit - buffer;
2226 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2229 cu.per_cu = this_cu;
2231 dwarf2_read_abbrevs (abfd, &cu);
2232 make_cleanup (dwarf2_free_abbrev_table, &cu);
2234 if (this_cu->from_debug_types)
2235 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2236 init_cu_die_reader (&reader_specs, &cu);
2237 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2243 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2246 struct quick_file_names find_entry;
2248 line_offset = DW_UNSND (attr);
2250 /* We may have already read in this line header (TU line header sharing).
2251 If we have we're done. */
2252 find_entry.offset = line_offset;
2253 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2254 &find_entry, INSERT);
2257 do_cleanups (cleanups);
2258 this_cu->v.quick->file_names = *slot;
2262 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2266 do_cleanups (cleanups);
2267 this_cu->v.quick->no_file_data = 1;
2271 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2272 qfn->offset = line_offset;
2273 gdb_assert (slot != NULL);
2276 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2278 qfn->num_file_names = lh->num_file_names;
2279 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2280 lh->num_file_names * sizeof (char *));
2281 for (i = 0; i < lh->num_file_names; ++i)
2282 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2283 qfn->real_names = NULL;
2285 free_line_header (lh);
2286 do_cleanups (cleanups);
2288 this_cu->v.quick->file_names = qfn;
2292 /* A helper for the "quick" functions which computes and caches the
2293 real path for a given file name from the line table. */
2296 dw2_get_real_path (struct objfile *objfile,
2297 struct quick_file_names *qfn, int index)
2299 if (qfn->real_names == NULL)
2300 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2301 qfn->num_file_names, sizeof (char *));
2303 if (qfn->real_names[index] == NULL)
2304 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2306 return qfn->real_names[index];
2309 static struct symtab *
2310 dw2_find_last_source_symtab (struct objfile *objfile)
2314 dw2_setup (objfile);
2315 index = dwarf2_per_objfile->n_comp_units - 1;
2316 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2319 /* Traversal function for dw2_forget_cached_source_info. */
2322 dw2_free_cached_file_names (void **slot, void *info)
2324 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2326 if (file_data->real_names)
2330 for (i = 0; i < file_data->num_file_names; ++i)
2332 xfree ((void*) file_data->real_names[i]);
2333 file_data->real_names[i] = NULL;
2341 dw2_forget_cached_source_info (struct objfile *objfile)
2343 dw2_setup (objfile);
2345 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2346 dw2_free_cached_file_names, NULL);
2350 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2351 const char *full_path, const char *real_path,
2352 struct symtab **result)
2355 int check_basename = lbasename (name) == name;
2356 struct dwarf2_per_cu_data *base_cu = NULL;
2358 dw2_setup (objfile);
2360 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2361 + dwarf2_per_objfile->n_type_comp_units); ++i)
2364 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2365 struct quick_file_names *file_data;
2367 if (per_cu->v.quick->symtab)
2370 file_data = dw2_get_file_names (objfile, per_cu);
2371 if (file_data == NULL)
2374 for (j = 0; j < file_data->num_file_names; ++j)
2376 const char *this_name = file_data->file_names[j];
2378 if (FILENAME_CMP (name, this_name) == 0)
2380 *result = dw2_instantiate_symtab (objfile, per_cu);
2384 if (check_basename && ! base_cu
2385 && FILENAME_CMP (lbasename (this_name), name) == 0)
2388 if (full_path != NULL)
2390 const char *this_real_name = dw2_get_real_path (objfile,
2393 if (this_real_name != NULL
2394 && FILENAME_CMP (full_path, this_real_name) == 0)
2396 *result = dw2_instantiate_symtab (objfile, per_cu);
2401 if (real_path != NULL)
2403 const char *this_real_name = dw2_get_real_path (objfile,
2406 if (this_real_name != NULL
2407 && FILENAME_CMP (real_path, this_real_name) == 0)
2409 *result = dw2_instantiate_symtab (objfile, per_cu);
2418 *result = dw2_instantiate_symtab (objfile, base_cu);
2425 static struct symtab *
2426 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2427 const char *name, domain_enum domain)
2429 /* We do all the work in the pre_expand_symtabs_matching hook
2434 /* A helper function that expands all symtabs that hold an object
2438 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2440 dw2_setup (objfile);
2442 /* index_table is NULL if OBJF_READNOW. */
2443 if (dwarf2_per_objfile->index_table)
2447 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2450 offset_type i, len = MAYBE_SWAP (*vec);
2451 for (i = 0; i < len; ++i)
2453 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2454 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2456 dw2_instantiate_symtab (objfile, per_cu);
2463 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2464 enum block_enum block_kind, const char *name,
2467 dw2_do_expand_symtabs_matching (objfile, name);
2471 dw2_print_stats (struct objfile *objfile)
2475 dw2_setup (objfile);
2477 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2478 + dwarf2_per_objfile->n_type_comp_units); ++i)
2480 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2482 if (!per_cu->v.quick->symtab)
2485 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2489 dw2_dump (struct objfile *objfile)
2491 /* Nothing worth printing. */
2495 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2496 struct section_offsets *delta)
2498 /* There's nothing to relocate here. */
2502 dw2_expand_symtabs_for_function (struct objfile *objfile,
2503 const char *func_name)
2505 dw2_do_expand_symtabs_matching (objfile, func_name);
2509 dw2_expand_all_symtabs (struct objfile *objfile)
2513 dw2_setup (objfile);
2515 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2516 + dwarf2_per_objfile->n_type_comp_units); ++i)
2518 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2520 dw2_instantiate_symtab (objfile, per_cu);
2525 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2526 const char *filename)
2530 dw2_setup (objfile);
2532 /* We don't need to consider type units here.
2533 This is only called for examining code, e.g. expand_line_sal.
2534 There can be an order of magnitude (or more) more type units
2535 than comp units, and we avoid them if we can. */
2537 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2540 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2541 struct quick_file_names *file_data;
2543 if (per_cu->v.quick->symtab)
2546 file_data = dw2_get_file_names (objfile, per_cu);
2547 if (file_data == NULL)
2550 for (j = 0; j < file_data->num_file_names; ++j)
2552 const char *this_name = file_data->file_names[j];
2553 if (FILENAME_CMP (this_name, filename) == 0)
2555 dw2_instantiate_symtab (objfile, per_cu);
2563 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2565 struct dwarf2_per_cu_data *per_cu;
2567 struct quick_file_names *file_data;
2569 dw2_setup (objfile);
2571 /* index_table is NULL if OBJF_READNOW. */
2572 if (!dwarf2_per_objfile->index_table)
2575 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2579 /* Note that this just looks at the very first one named NAME -- but
2580 actually we are looking for a function. find_main_filename
2581 should be rewritten so that it doesn't require a custom hook. It
2582 could just use the ordinary symbol tables. */
2583 /* vec[0] is the length, which must always be >0. */
2584 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2586 file_data = dw2_get_file_names (objfile, per_cu);
2587 if (file_data == NULL)
2590 return file_data->file_names[file_data->num_file_names - 1];
2594 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2595 struct objfile *objfile, int global,
2596 int (*callback) (struct block *,
2597 struct symbol *, void *),
2598 void *data, symbol_compare_ftype *match,
2599 symbol_compare_ftype *ordered_compare)
2601 /* Currently unimplemented; used for Ada. The function can be called if the
2602 current language is Ada for a non-Ada objfile using GNU index. As Ada
2603 does not look for non-Ada symbols this function should just return. */
2607 dw2_expand_symtabs_matching (struct objfile *objfile,
2608 int (*file_matcher) (const char *, void *),
2609 int (*name_matcher) (const char *, void *),
2610 enum search_domain kind,
2615 struct mapped_index *index;
2617 dw2_setup (objfile);
2619 /* index_table is NULL if OBJF_READNOW. */
2620 if (!dwarf2_per_objfile->index_table)
2622 index = dwarf2_per_objfile->index_table;
2624 if (file_matcher != NULL)
2625 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2626 + dwarf2_per_objfile->n_type_comp_units); ++i)
2629 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2630 struct quick_file_names *file_data;
2632 per_cu->v.quick->mark = 0;
2633 if (per_cu->v.quick->symtab)
2636 file_data = dw2_get_file_names (objfile, per_cu);
2637 if (file_data == NULL)
2640 for (j = 0; j < file_data->num_file_names; ++j)
2642 if (file_matcher (file_data->file_names[j], data))
2644 per_cu->v.quick->mark = 1;
2650 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2652 offset_type idx = 2 * iter;
2654 offset_type *vec, vec_len, vec_idx;
2656 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2659 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2661 if (! (*name_matcher) (name, data))
2664 /* The name was matched, now expand corresponding CUs that were
2666 vec = (offset_type *) (index->constant_pool
2667 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2668 vec_len = MAYBE_SWAP (vec[0]);
2669 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2671 struct dwarf2_per_cu_data *per_cu;
2673 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2674 if (file_matcher == NULL || per_cu->v.quick->mark)
2675 dw2_instantiate_symtab (objfile, per_cu);
2680 static struct symtab *
2681 dw2_find_pc_sect_symtab (struct objfile *objfile,
2682 struct minimal_symbol *msymbol,
2684 struct obj_section *section,
2687 struct dwarf2_per_cu_data *data;
2689 dw2_setup (objfile);
2691 if (!objfile->psymtabs_addrmap)
2694 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2698 if (warn_if_readin && data->v.quick->symtab)
2699 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2700 paddress (get_objfile_arch (objfile), pc));
2702 return dw2_instantiate_symtab (objfile, data);
2706 dw2_map_symbol_filenames (struct objfile *objfile,
2707 void (*fun) (const char *, const char *, void *),
2712 dw2_setup (objfile);
2714 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2715 + dwarf2_per_objfile->n_type_comp_units); ++i)
2718 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2719 struct quick_file_names *file_data;
2721 if (per_cu->v.quick->symtab)
2724 file_data = dw2_get_file_names (objfile, per_cu);
2725 if (file_data == NULL)
2728 for (j = 0; j < file_data->num_file_names; ++j)
2730 const char *this_real_name = dw2_get_real_path (objfile, file_data,
2732 (*fun) (file_data->file_names[j], this_real_name, data);
2738 dw2_has_symbols (struct objfile *objfile)
2743 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2746 dw2_find_last_source_symtab,
2747 dw2_forget_cached_source_info,
2750 dw2_pre_expand_symtabs_matching,
2754 dw2_expand_symtabs_for_function,
2755 dw2_expand_all_symtabs,
2756 dw2_expand_symtabs_with_filename,
2757 dw2_find_symbol_file,
2758 dw2_map_matching_symbols,
2759 dw2_expand_symtabs_matching,
2760 dw2_find_pc_sect_symtab,
2761 dw2_map_symbol_filenames
2764 /* Initialize for reading DWARF for this objfile. Return 0 if this
2765 file will use psymtabs, or 1 if using the GNU index. */
2768 dwarf2_initialize_objfile (struct objfile *objfile)
2770 /* If we're about to read full symbols, don't bother with the
2771 indices. In this case we also don't care if some other debug
2772 format is making psymtabs, because they are all about to be
2774 if ((objfile->flags & OBJF_READNOW))
2778 dwarf2_per_objfile->using_index = 1;
2779 create_all_comp_units (objfile);
2780 create_debug_types_hash_table (objfile);
2781 dwarf2_per_objfile->quick_file_names_table =
2782 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2784 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2785 + dwarf2_per_objfile->n_type_comp_units); ++i)
2787 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2789 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2790 struct dwarf2_per_cu_quick_data);
2793 /* Return 1 so that gdb sees the "quick" functions. However,
2794 these functions will be no-ops because we will have expanded
2799 if (dwarf2_read_index (objfile))
2807 /* Build a partial symbol table. */
2810 dwarf2_build_psymtabs (struct objfile *objfile)
2812 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2814 init_psymbol_list (objfile, 1024);
2817 dwarf2_build_psymtabs_hard (objfile);
2820 /* Return TRUE if OFFSET is within CU_HEADER. */
2823 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2825 unsigned int bottom = cu_header->offset;
2826 unsigned int top = (cu_header->offset
2828 + cu_header->initial_length_size);
2830 return (offset >= bottom && offset < top);
2833 /* Read in the comp unit header information from the debug_info at info_ptr.
2834 NOTE: This leaves members offset, first_die_offset to be filled in
2838 read_comp_unit_head (struct comp_unit_head *cu_header,
2839 gdb_byte *info_ptr, bfd *abfd)
2842 unsigned int bytes_read;
2844 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2845 cu_header->initial_length_size = bytes_read;
2846 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2847 info_ptr += bytes_read;
2848 cu_header->version = read_2_bytes (abfd, info_ptr);
2850 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2852 info_ptr += bytes_read;
2853 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2855 signed_addr = bfd_get_sign_extend_vma (abfd);
2856 if (signed_addr < 0)
2857 internal_error (__FILE__, __LINE__,
2858 _("read_comp_unit_head: dwarf from non elf file"));
2859 cu_header->signed_addr_p = signed_addr;
2865 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2866 gdb_byte *buffer, unsigned int buffer_size,
2869 gdb_byte *beg_of_comp_unit = info_ptr;
2871 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2873 if (header->version != 2 && header->version != 3 && header->version != 4)
2874 error (_("Dwarf Error: wrong version in compilation unit header "
2875 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2876 bfd_get_filename (abfd));
2878 if (header->abbrev_offset
2879 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2880 &dwarf2_per_objfile->abbrev))
2881 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2882 "(offset 0x%lx + 6) [in module %s]"),
2883 (long) header->abbrev_offset,
2884 (long) (beg_of_comp_unit - buffer),
2885 bfd_get_filename (abfd));
2887 if (beg_of_comp_unit + header->length + header->initial_length_size
2888 > buffer + buffer_size)
2889 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2890 "(offset 0x%lx + 0) [in module %s]"),
2891 (long) header->length,
2892 (long) (beg_of_comp_unit - buffer),
2893 bfd_get_filename (abfd));
2898 /* Read in the types comp unit header information from .debug_types entry at
2899 types_ptr. The result is a pointer to one past the end of the header. */
2902 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2903 ULONGEST *signature,
2904 gdb_byte *types_ptr, bfd *abfd)
2906 gdb_byte *initial_types_ptr = types_ptr;
2908 dwarf2_read_section (dwarf2_per_objfile->objfile,
2909 &dwarf2_per_objfile->types);
2910 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2912 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2914 *signature = read_8_bytes (abfd, types_ptr);
2916 types_ptr += cu_header->offset_size;
2917 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2922 /* Allocate a new partial symtab for file named NAME and mark this new
2923 partial symtab as being an include of PST. */
2926 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2927 struct objfile *objfile)
2929 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2931 subpst->section_offsets = pst->section_offsets;
2932 subpst->textlow = 0;
2933 subpst->texthigh = 0;
2935 subpst->dependencies = (struct partial_symtab **)
2936 obstack_alloc (&objfile->objfile_obstack,
2937 sizeof (struct partial_symtab *));
2938 subpst->dependencies[0] = pst;
2939 subpst->number_of_dependencies = 1;
2941 subpst->globals_offset = 0;
2942 subpst->n_global_syms = 0;
2943 subpst->statics_offset = 0;
2944 subpst->n_static_syms = 0;
2945 subpst->symtab = NULL;
2946 subpst->read_symtab = pst->read_symtab;
2949 /* No private part is necessary for include psymtabs. This property
2950 can be used to differentiate between such include psymtabs and
2951 the regular ones. */
2952 subpst->read_symtab_private = NULL;
2955 /* Read the Line Number Program data and extract the list of files
2956 included by the source file represented by PST. Build an include
2957 partial symtab for each of these included files. */
2960 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2961 struct die_info *die,
2962 struct partial_symtab *pst)
2964 struct objfile *objfile = cu->objfile;
2965 bfd *abfd = objfile->obfd;
2966 struct line_header *lh = NULL;
2967 struct attribute *attr;
2969 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2972 unsigned int line_offset = DW_UNSND (attr);
2974 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2977 return; /* No linetable, so no includes. */
2979 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2980 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
2982 free_line_header (lh);
2986 hash_type_signature (const void *item)
2988 const struct signatured_type *type_sig = item;
2990 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2991 return type_sig->signature;
2995 eq_type_signature (const void *item_lhs, const void *item_rhs)
2997 const struct signatured_type *lhs = item_lhs;
2998 const struct signatured_type *rhs = item_rhs;
3000 return lhs->signature == rhs->signature;
3003 /* Allocate a hash table for signatured types. */
3006 allocate_signatured_type_table (struct objfile *objfile)
3008 return htab_create_alloc_ex (41,
3009 hash_type_signature,
3012 &objfile->objfile_obstack,
3013 hashtab_obstack_allocate,
3014 dummy_obstack_deallocate);
3017 /* A helper function to add a signatured type CU to a list. */
3020 add_signatured_type_cu_to_list (void **slot, void *datum)
3022 struct signatured_type *sigt = *slot;
3023 struct dwarf2_per_cu_data ***datap = datum;
3025 **datap = &sigt->per_cu;
3031 /* Create the hash table of all entries in the .debug_types section.
3032 The result is zero if there is an error (e.g. missing .debug_types section),
3033 otherwise non-zero. */
3036 create_debug_types_hash_table (struct objfile *objfile)
3040 struct dwarf2_per_cu_data **iter;
3042 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
3043 info_ptr = dwarf2_per_objfile->types.buffer;
3045 if (info_ptr == NULL)
3047 dwarf2_per_objfile->signatured_types = NULL;
3051 types_htab = allocate_signatured_type_table (objfile);
3053 if (dwarf2_die_debug)
3054 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3056 while (info_ptr < dwarf2_per_objfile->types.buffer
3057 + dwarf2_per_objfile->types.size)
3059 unsigned int offset;
3060 unsigned int offset_size;
3061 unsigned int type_offset;
3062 unsigned int length, initial_length_size;
3063 unsigned short version;
3065 struct signatured_type *type_sig;
3067 gdb_byte *ptr = info_ptr;
3069 offset = ptr - dwarf2_per_objfile->types.buffer;
3071 /* We need to read the type's signature in order to build the hash
3072 table, but we don't need to read anything else just yet. */
3074 /* Sanity check to ensure entire cu is present. */
3075 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
3076 if (ptr + length + initial_length_size
3077 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
3079 complaint (&symfile_complaints,
3080 _("debug type entry runs off end "
3081 "of `.debug_types' section, ignored"));
3085 offset_size = initial_length_size == 4 ? 4 : 8;
3086 ptr += initial_length_size;
3087 version = bfd_get_16 (objfile->obfd, ptr);
3089 ptr += offset_size; /* abbrev offset */
3090 ptr += 1; /* address size */
3091 signature = bfd_get_64 (objfile->obfd, ptr);
3093 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3095 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3096 memset (type_sig, 0, sizeof (*type_sig));
3097 type_sig->signature = signature;
3098 type_sig->type_offset = type_offset;
3099 type_sig->per_cu.objfile = objfile;
3100 type_sig->per_cu.from_debug_types = 1;
3101 type_sig->per_cu.offset = offset;
3103 slot = htab_find_slot (types_htab, type_sig, INSERT);
3104 gdb_assert (slot != NULL);
3107 const struct signatured_type *dup_sig = *slot;
3109 complaint (&symfile_complaints,
3110 _("debug type entry at offset 0x%x is duplicate to the "
3111 "entry at offset 0x%x, signature 0x%s"),
3112 offset, dup_sig->per_cu.offset,
3113 phex (signature, sizeof (signature)));
3114 gdb_assert (signature == dup_sig->signature);
3118 if (dwarf2_die_debug)
3119 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3120 offset, phex (signature, sizeof (signature)));
3122 info_ptr = info_ptr + initial_length_size + length;
3125 dwarf2_per_objfile->signatured_types = types_htab;
3127 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3128 dwarf2_per_objfile->type_comp_units
3129 = obstack_alloc (&objfile->objfile_obstack,
3130 dwarf2_per_objfile->n_type_comp_units
3131 * sizeof (struct dwarf2_per_cu_data *));
3132 iter = &dwarf2_per_objfile->type_comp_units[0];
3133 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3134 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3135 == dwarf2_per_objfile->n_type_comp_units);
3140 /* Lookup a signature based type.
3141 Returns NULL if SIG is not present in the table. */
3143 static struct signatured_type *
3144 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3146 struct signatured_type find_entry, *entry;
3148 if (dwarf2_per_objfile->signatured_types == NULL)
3150 complaint (&symfile_complaints,
3151 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3155 find_entry.signature = sig;
3156 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3160 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3163 init_cu_die_reader (struct die_reader_specs *reader,
3164 struct dwarf2_cu *cu)
3166 reader->abfd = cu->objfile->obfd;
3168 if (cu->per_cu->from_debug_types)
3170 gdb_assert (dwarf2_per_objfile->types.readin);
3171 reader->buffer = dwarf2_per_objfile->types.buffer;
3175 gdb_assert (dwarf2_per_objfile->info.readin);
3176 reader->buffer = dwarf2_per_objfile->info.buffer;
3180 /* Find the base address of the compilation unit for range lists and
3181 location lists. It will normally be specified by DW_AT_low_pc.
3182 In DWARF-3 draft 4, the base address could be overridden by
3183 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3184 compilation units with discontinuous ranges. */
3187 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3189 struct attribute *attr;
3192 cu->base_address = 0;
3194 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3197 cu->base_address = DW_ADDR (attr);
3202 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3205 cu->base_address = DW_ADDR (attr);
3211 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3212 to combine the common parts.
3213 Process a compilation unit for a psymtab.
3214 BUFFER is a pointer to the beginning of the dwarf section buffer,
3215 either .debug_info or debug_types.
3216 INFO_PTR is a pointer to the start of the CU.
3217 Returns a pointer to the next CU. */
3220 process_psymtab_comp_unit (struct objfile *objfile,
3221 struct dwarf2_per_cu_data *this_cu,
3222 gdb_byte *buffer, gdb_byte *info_ptr,
3223 unsigned int buffer_size)
3225 bfd *abfd = objfile->obfd;
3226 gdb_byte *beg_of_comp_unit = info_ptr;
3227 struct die_info *comp_unit_die;
3228 struct partial_symtab *pst;
3230 struct cleanup *back_to_inner;
3231 struct dwarf2_cu cu;
3232 int has_children, has_pc_info;
3233 struct attribute *attr;
3234 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3235 struct die_reader_specs reader_specs;
3236 const char *filename;
3238 init_one_comp_unit (&cu, objfile);
3239 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3241 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3242 buffer, buffer_size,
3245 /* Complete the cu_header. */
3246 cu.header.offset = beg_of_comp_unit - buffer;
3247 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3249 cu.list_in_scope = &file_symbols;
3251 /* If this compilation unit was already read in, free the
3252 cached copy in order to read it in again. This is
3253 necessary because we skipped some symbols when we first
3254 read in the compilation unit (see load_partial_dies).
3255 This problem could be avoided, but the benefit is
3257 if (this_cu->cu != NULL)
3258 free_one_cached_comp_unit (this_cu->cu);
3260 /* Note that this is a pointer to our stack frame, being
3261 added to a global data structure. It will be cleaned up
3262 in free_stack_comp_unit when we finish with this
3263 compilation unit. */
3265 cu.per_cu = this_cu;
3267 /* Read the abbrevs for this compilation unit into a table. */
3268 dwarf2_read_abbrevs (abfd, &cu);
3269 make_cleanup (dwarf2_free_abbrev_table, &cu);
3271 /* Read the compilation unit die. */
3272 if (this_cu->from_debug_types)
3273 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3274 init_cu_die_reader (&reader_specs, &cu);
3275 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3278 if (this_cu->from_debug_types)
3280 /* LENGTH has not been set yet for type units. */
3281 gdb_assert (this_cu->offset == cu.header.offset);
3282 this_cu->length = cu.header.length + cu.header.initial_length_size;
3284 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3286 info_ptr = (beg_of_comp_unit + cu.header.length
3287 + cu.header.initial_length_size);
3288 do_cleanups (back_to_inner);
3292 prepare_one_comp_unit (&cu, comp_unit_die);
3294 /* Allocate a new partial symbol table structure. */
3295 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3296 if (attr == NULL || !DW_STRING (attr))
3299 filename = DW_STRING (attr);
3300 pst = start_psymtab_common (objfile, objfile->section_offsets,
3302 /* TEXTLOW and TEXTHIGH are set below. */
3304 objfile->global_psymbols.next,
3305 objfile->static_psymbols.next);
3307 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3309 pst->dirname = DW_STRING (attr);
3311 pst->read_symtab_private = this_cu;
3313 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3315 /* Store the function that reads in the rest of the symbol table. */
3316 pst->read_symtab = dwarf2_psymtab_to_symtab;
3318 this_cu->v.psymtab = pst;
3320 dwarf2_find_base_address (comp_unit_die, &cu);
3322 /* Possibly set the default values of LOWPC and HIGHPC from
3324 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3325 &best_highpc, &cu, pst);
3326 if (has_pc_info == 1 && best_lowpc < best_highpc)
3327 /* Store the contiguous range if it is not empty; it can be empty for
3328 CUs with no code. */
3329 addrmap_set_empty (objfile->psymtabs_addrmap,
3330 best_lowpc + baseaddr,
3331 best_highpc + baseaddr - 1, pst);
3333 /* Check if comp unit has_children.
3334 If so, read the rest of the partial symbols from this comp unit.
3335 If not, there's no more debug_info for this comp unit. */
3338 struct partial_die_info *first_die;
3339 CORE_ADDR lowpc, highpc;
3341 lowpc = ((CORE_ADDR) -1);
3342 highpc = ((CORE_ADDR) 0);
3344 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3346 scan_partial_symbols (first_die, &lowpc, &highpc,
3347 ! has_pc_info, &cu);
3349 /* If we didn't find a lowpc, set it to highpc to avoid
3350 complaints from `maint check'. */
3351 if (lowpc == ((CORE_ADDR) -1))
3354 /* If the compilation unit didn't have an explicit address range,
3355 then use the information extracted from its child dies. */
3359 best_highpc = highpc;
3362 pst->textlow = best_lowpc + baseaddr;
3363 pst->texthigh = best_highpc + baseaddr;
3365 pst->n_global_syms = objfile->global_psymbols.next -
3366 (objfile->global_psymbols.list + pst->globals_offset);
3367 pst->n_static_syms = objfile->static_psymbols.next -
3368 (objfile->static_psymbols.list + pst->statics_offset);
3369 sort_pst_symbols (pst);
3371 info_ptr = (beg_of_comp_unit + cu.header.length
3372 + cu.header.initial_length_size);
3374 if (this_cu->from_debug_types)
3376 /* It's not clear we want to do anything with stmt lists here.
3377 Waiting to see what gcc ultimately does. */
3381 /* Get the list of files included in the current compilation unit,
3382 and build a psymtab for each of them. */
3383 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3386 do_cleanups (back_to_inner);
3391 /* Traversal function for htab_traverse_noresize.
3392 Process one .debug_types comp-unit. */
3395 process_type_comp_unit (void **slot, void *info)
3397 struct signatured_type *entry = (struct signatured_type *) *slot;
3398 struct objfile *objfile = (struct objfile *) info;
3399 struct dwarf2_per_cu_data *this_cu;
3401 this_cu = &entry->per_cu;
3403 gdb_assert (dwarf2_per_objfile->types.readin);
3404 process_psymtab_comp_unit (objfile, this_cu,
3405 dwarf2_per_objfile->types.buffer,
3406 dwarf2_per_objfile->types.buffer + this_cu->offset,
3407 dwarf2_per_objfile->types.size);
3412 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3413 Build partial symbol tables for the .debug_types comp-units. */
3416 build_type_psymtabs (struct objfile *objfile)
3418 if (! create_debug_types_hash_table (objfile))
3421 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3422 process_type_comp_unit, objfile);
3425 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3428 psymtabs_addrmap_cleanup (void *o)
3430 struct objfile *objfile = o;
3432 objfile->psymtabs_addrmap = NULL;
3435 /* Build the partial symbol table by doing a quick pass through the
3436 .debug_info and .debug_abbrev sections. */
3439 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3442 struct cleanup *back_to, *addrmap_cleanup;
3443 struct obstack temp_obstack;
3445 dwarf2_per_objfile->reading_partial_symbols = 1;
3447 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3448 info_ptr = dwarf2_per_objfile->info.buffer;
3450 /* Any cached compilation units will be linked by the per-objfile
3451 read_in_chain. Make sure to free them when we're done. */
3452 back_to = make_cleanup (free_cached_comp_units, NULL);
3454 build_type_psymtabs (objfile);
3456 create_all_comp_units (objfile);
3458 /* Create a temporary address map on a temporary obstack. We later
3459 copy this to the final obstack. */
3460 obstack_init (&temp_obstack);
3461 make_cleanup_obstack_free (&temp_obstack);
3462 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3463 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3465 /* Since the objects we're extracting from .debug_info vary in
3466 length, only the individual functions to extract them (like
3467 read_comp_unit_head and load_partial_die) can really know whether
3468 the buffer is large enough to hold another complete object.
3470 At the moment, they don't actually check that. If .debug_info
3471 holds just one extra byte after the last compilation unit's dies,
3472 then read_comp_unit_head will happily read off the end of the
3473 buffer. read_partial_die is similarly casual. Those functions
3476 For this loop condition, simply checking whether there's any data
3477 left at all should be sufficient. */
3479 while (info_ptr < (dwarf2_per_objfile->info.buffer
3480 + dwarf2_per_objfile->info.size))
3482 struct dwarf2_per_cu_data *this_cu;
3484 this_cu = dwarf2_find_comp_unit (info_ptr
3485 - dwarf2_per_objfile->info.buffer,
3488 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3489 dwarf2_per_objfile->info.buffer,
3491 dwarf2_per_objfile->info.size);
3494 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3495 &objfile->objfile_obstack);
3496 discard_cleanups (addrmap_cleanup);
3498 do_cleanups (back_to);
3501 /* Load the partial DIEs for a secondary CU into memory. */
3504 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3505 struct objfile *objfile)
3507 bfd *abfd = objfile->obfd;
3508 gdb_byte *info_ptr, *beg_of_comp_unit;
3509 struct die_info *comp_unit_die;
3510 struct dwarf2_cu *cu;
3511 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3513 struct die_reader_specs reader_specs;
3516 gdb_assert (! this_cu->from_debug_types);
3518 gdb_assert (dwarf2_per_objfile->info.readin);
3519 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3520 beg_of_comp_unit = info_ptr;
3522 if (this_cu->cu == NULL)
3524 cu = xmalloc (sizeof (*cu));
3525 init_one_comp_unit (cu, objfile);
3529 /* If an error occurs while loading, release our storage. */
3530 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3532 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3533 dwarf2_per_objfile->info.buffer,
3534 dwarf2_per_objfile->info.size,
3537 /* Complete the cu_header. */
3538 cu->header.offset = this_cu->offset;
3539 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3541 /* Link this compilation unit into the compilation unit tree. */
3543 cu->per_cu = this_cu;
3545 /* Link this CU into read_in_chain. */
3546 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3547 dwarf2_per_objfile->read_in_chain = this_cu;
3552 info_ptr += cu->header.first_die_offset;
3555 /* Read the abbrevs for this compilation unit into a table. */
3556 gdb_assert (cu->dwarf2_abbrevs == NULL);
3557 dwarf2_read_abbrevs (abfd, cu);
3558 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3560 /* Read the compilation unit die. */
3561 init_cu_die_reader (&reader_specs, cu);
3562 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3565 prepare_one_comp_unit (cu, comp_unit_die);
3567 /* Check if comp unit has_children.
3568 If so, read the rest of the partial symbols from this comp unit.
3569 If not, there's no more debug_info for this comp unit. */
3571 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3573 do_cleanups (free_abbrevs_cleanup);
3577 /* We've successfully allocated this compilation unit. Let our
3578 caller clean it up when finished with it. */
3579 discard_cleanups (free_cu_cleanup);
3583 /* Create a list of all compilation units in OBJFILE. We do this only
3584 if an inter-comp-unit reference is found; presumably if there is one,
3585 there will be many, and one will occur early in the .debug_info section.
3586 So there's no point in building this list incrementally. */
3589 create_all_comp_units (struct objfile *objfile)
3593 struct dwarf2_per_cu_data **all_comp_units;
3596 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3597 info_ptr = dwarf2_per_objfile->info.buffer;
3601 all_comp_units = xmalloc (n_allocated
3602 * sizeof (struct dwarf2_per_cu_data *));
3604 while (info_ptr < dwarf2_per_objfile->info.buffer
3605 + dwarf2_per_objfile->info.size)
3607 unsigned int length, initial_length_size;
3608 struct dwarf2_per_cu_data *this_cu;
3609 unsigned int offset;
3611 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3613 /* Read just enough information to find out where the next
3614 compilation unit is. */
3615 length = read_initial_length (objfile->obfd, info_ptr,
3616 &initial_length_size);
3618 /* Save the compilation unit for later lookup. */
3619 this_cu = obstack_alloc (&objfile->objfile_obstack,
3620 sizeof (struct dwarf2_per_cu_data));
3621 memset (this_cu, 0, sizeof (*this_cu));
3622 this_cu->offset = offset;
3623 this_cu->length = length + initial_length_size;
3624 this_cu->objfile = objfile;
3626 if (n_comp_units == n_allocated)
3629 all_comp_units = xrealloc (all_comp_units,
3631 * sizeof (struct dwarf2_per_cu_data *));
3633 all_comp_units[n_comp_units++] = this_cu;
3635 info_ptr = info_ptr + this_cu->length;
3638 dwarf2_per_objfile->all_comp_units
3639 = obstack_alloc (&objfile->objfile_obstack,
3640 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3641 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3642 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3643 xfree (all_comp_units);
3644 dwarf2_per_objfile->n_comp_units = n_comp_units;
3647 /* Process all loaded DIEs for compilation unit CU, starting at
3648 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3649 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3650 DW_AT_ranges). If NEED_PC is set, then this function will set
3651 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3652 and record the covered ranges in the addrmap. */
3655 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3656 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3658 struct partial_die_info *pdi;
3660 /* Now, march along the PDI's, descending into ones which have
3661 interesting children but skipping the children of the other ones,
3662 until we reach the end of the compilation unit. */
3668 fixup_partial_die (pdi, cu);
3670 /* Anonymous namespaces or modules have no name but have interesting
3671 children, so we need to look at them. Ditto for anonymous
3674 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3675 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3679 case DW_TAG_subprogram:
3680 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3682 case DW_TAG_constant:
3683 case DW_TAG_variable:
3684 case DW_TAG_typedef:
3685 case DW_TAG_union_type:
3686 if (!pdi->is_declaration)
3688 add_partial_symbol (pdi, cu);
3691 case DW_TAG_class_type:
3692 case DW_TAG_interface_type:
3693 case DW_TAG_structure_type:
3694 if (!pdi->is_declaration)
3696 add_partial_symbol (pdi, cu);
3699 case DW_TAG_enumeration_type:
3700 if (!pdi->is_declaration)
3701 add_partial_enumeration (pdi, cu);
3703 case DW_TAG_base_type:
3704 case DW_TAG_subrange_type:
3705 /* File scope base type definitions are added to the partial
3707 add_partial_symbol (pdi, cu);
3709 case DW_TAG_namespace:
3710 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3713 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3720 /* If the die has a sibling, skip to the sibling. */
3722 pdi = pdi->die_sibling;
3726 /* Functions used to compute the fully scoped name of a partial DIE.
3728 Normally, this is simple. For C++, the parent DIE's fully scoped
3729 name is concatenated with "::" and the partial DIE's name. For
3730 Java, the same thing occurs except that "." is used instead of "::".
3731 Enumerators are an exception; they use the scope of their parent
3732 enumeration type, i.e. the name of the enumeration type is not
3733 prepended to the enumerator.
3735 There are two complexities. One is DW_AT_specification; in this
3736 case "parent" means the parent of the target of the specification,
3737 instead of the direct parent of the DIE. The other is compilers
3738 which do not emit DW_TAG_namespace; in this case we try to guess
3739 the fully qualified name of structure types from their members'
3740 linkage names. This must be done using the DIE's children rather
3741 than the children of any DW_AT_specification target. We only need
3742 to do this for structures at the top level, i.e. if the target of
3743 any DW_AT_specification (if any; otherwise the DIE itself) does not
3746 /* Compute the scope prefix associated with PDI's parent, in
3747 compilation unit CU. The result will be allocated on CU's
3748 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3749 field. NULL is returned if no prefix is necessary. */
3751 partial_die_parent_scope (struct partial_die_info *pdi,
3752 struct dwarf2_cu *cu)
3754 char *grandparent_scope;
3755 struct partial_die_info *parent, *real_pdi;
3757 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3758 then this means the parent of the specification DIE. */
3761 while (real_pdi->has_specification)
3762 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3764 parent = real_pdi->die_parent;
3768 if (parent->scope_set)
3769 return parent->scope;
3771 fixup_partial_die (parent, cu);
3773 grandparent_scope = partial_die_parent_scope (parent, cu);
3775 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3776 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3777 Work around this problem here. */
3778 if (cu->language == language_cplus
3779 && parent->tag == DW_TAG_namespace
3780 && strcmp (parent->name, "::") == 0
3781 && grandparent_scope == NULL)
3783 parent->scope = NULL;
3784 parent->scope_set = 1;
3788 if (parent->tag == DW_TAG_namespace
3789 || parent->tag == DW_TAG_module
3790 || parent->tag == DW_TAG_structure_type
3791 || parent->tag == DW_TAG_class_type
3792 || parent->tag == DW_TAG_interface_type
3793 || parent->tag == DW_TAG_union_type
3794 || parent->tag == DW_TAG_enumeration_type)
3796 if (grandparent_scope == NULL)
3797 parent->scope = parent->name;
3799 parent->scope = typename_concat (&cu->comp_unit_obstack,
3801 parent->name, 0, cu);
3803 else if (parent->tag == DW_TAG_enumerator)
3804 /* Enumerators should not get the name of the enumeration as a prefix. */
3805 parent->scope = grandparent_scope;
3808 /* FIXME drow/2004-04-01: What should we be doing with
3809 function-local names? For partial symbols, we should probably be
3811 complaint (&symfile_complaints,
3812 _("unhandled containing DIE tag %d for DIE at %d"),
3813 parent->tag, pdi->offset);
3814 parent->scope = grandparent_scope;
3817 parent->scope_set = 1;
3818 return parent->scope;
3821 /* Return the fully scoped name associated with PDI, from compilation unit
3822 CU. The result will be allocated with malloc. */
3824 partial_die_full_name (struct partial_die_info *pdi,
3825 struct dwarf2_cu *cu)
3829 /* If this is a template instantiation, we can not work out the
3830 template arguments from partial DIEs. So, unfortunately, we have
3831 to go through the full DIEs. At least any work we do building
3832 types here will be reused if full symbols are loaded later. */
3833 if (pdi->has_template_arguments)
3835 fixup_partial_die (pdi, cu);
3837 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3839 struct die_info *die;
3840 struct attribute attr;
3841 struct dwarf2_cu *ref_cu = cu;
3844 attr.form = DW_FORM_ref_addr;
3845 attr.u.addr = pdi->offset;
3846 die = follow_die_ref (NULL, &attr, &ref_cu);
3848 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3852 parent_scope = partial_die_parent_scope (pdi, cu);
3853 if (parent_scope == NULL)
3856 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3860 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3862 struct objfile *objfile = cu->objfile;
3864 char *actual_name = NULL;
3865 const struct partial_symbol *psym = NULL;
3867 int built_actual_name = 0;
3869 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3871 actual_name = partial_die_full_name (pdi, cu);
3873 built_actual_name = 1;
3875 if (actual_name == NULL)
3876 actual_name = pdi->name;
3880 case DW_TAG_subprogram:
3881 if (pdi->is_external || cu->language == language_ada)
3883 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3884 of the global scope. But in Ada, we want to be able to access
3885 nested procedures globally. So all Ada subprograms are stored
3886 in the global scope. */
3887 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3888 mst_text, objfile); */
3889 add_psymbol_to_list (actual_name, strlen (actual_name),
3891 VAR_DOMAIN, LOC_BLOCK,
3892 &objfile->global_psymbols,
3893 0, pdi->lowpc + baseaddr,
3894 cu->language, objfile);
3898 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3899 mst_file_text, objfile); */
3900 add_psymbol_to_list (actual_name, strlen (actual_name),
3902 VAR_DOMAIN, LOC_BLOCK,
3903 &objfile->static_psymbols,
3904 0, pdi->lowpc + baseaddr,
3905 cu->language, objfile);
3908 case DW_TAG_constant:
3910 struct psymbol_allocation_list *list;
3912 if (pdi->is_external)
3913 list = &objfile->global_psymbols;
3915 list = &objfile->static_psymbols;
3916 add_psymbol_to_list (actual_name, strlen (actual_name),
3917 built_actual_name, VAR_DOMAIN, LOC_STATIC,
3918 list, 0, 0, cu->language, objfile);
3921 case DW_TAG_variable:
3923 addr = decode_locdesc (pdi->locdesc, cu);
3927 && !dwarf2_per_objfile->has_section_at_zero)
3929 /* A global or static variable may also have been stripped
3930 out by the linker if unused, in which case its address
3931 will be nullified; do not add such variables into partial
3932 symbol table then. */
3934 else if (pdi->is_external)
3937 Don't enter into the minimal symbol tables as there is
3938 a minimal symbol table entry from the ELF symbols already.
3939 Enter into partial symbol table if it has a location
3940 descriptor or a type.
3941 If the location descriptor is missing, new_symbol will create
3942 a LOC_UNRESOLVED symbol, the address of the variable will then
3943 be determined from the minimal symbol table whenever the variable
3945 The address for the partial symbol table entry is not
3946 used by GDB, but it comes in handy for debugging partial symbol
3949 if (pdi->locdesc || pdi->has_type)
3950 add_psymbol_to_list (actual_name, strlen (actual_name),
3952 VAR_DOMAIN, LOC_STATIC,
3953 &objfile->global_psymbols,
3955 cu->language, objfile);
3959 /* Static Variable. Skip symbols without location descriptors. */
3960 if (pdi->locdesc == NULL)
3962 if (built_actual_name)
3963 xfree (actual_name);
3966 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3967 mst_file_data, objfile); */
3968 add_psymbol_to_list (actual_name, strlen (actual_name),
3970 VAR_DOMAIN, LOC_STATIC,
3971 &objfile->static_psymbols,
3973 cu->language, objfile);
3976 case DW_TAG_typedef:
3977 case DW_TAG_base_type:
3978 case DW_TAG_subrange_type:
3979 add_psymbol_to_list (actual_name, strlen (actual_name),
3981 VAR_DOMAIN, LOC_TYPEDEF,
3982 &objfile->static_psymbols,
3983 0, (CORE_ADDR) 0, cu->language, objfile);
3985 case DW_TAG_namespace:
3986 add_psymbol_to_list (actual_name, strlen (actual_name),
3988 VAR_DOMAIN, LOC_TYPEDEF,
3989 &objfile->global_psymbols,
3990 0, (CORE_ADDR) 0, cu->language, objfile);
3992 case DW_TAG_class_type:
3993 case DW_TAG_interface_type:
3994 case DW_TAG_structure_type:
3995 case DW_TAG_union_type:
3996 case DW_TAG_enumeration_type:
3997 /* Skip external references. The DWARF standard says in the section
3998 about "Structure, Union, and Class Type Entries": "An incomplete
3999 structure, union or class type is represented by a structure,
4000 union or class entry that does not have a byte size attribute
4001 and that has a DW_AT_declaration attribute." */
4002 if (!pdi->has_byte_size && pdi->is_declaration)
4004 if (built_actual_name)
4005 xfree (actual_name);
4009 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4010 static vs. global. */
4011 add_psymbol_to_list (actual_name, strlen (actual_name),
4013 STRUCT_DOMAIN, LOC_TYPEDEF,
4014 (cu->language == language_cplus
4015 || cu->language == language_java)
4016 ? &objfile->global_psymbols
4017 : &objfile->static_psymbols,
4018 0, (CORE_ADDR) 0, cu->language, objfile);
4021 case DW_TAG_enumerator:
4022 add_psymbol_to_list (actual_name, strlen (actual_name),
4024 VAR_DOMAIN, LOC_CONST,
4025 (cu->language == language_cplus
4026 || cu->language == language_java)
4027 ? &objfile->global_psymbols
4028 : &objfile->static_psymbols,
4029 0, (CORE_ADDR) 0, cu->language, objfile);
4035 if (built_actual_name)
4036 xfree (actual_name);
4039 /* Read a partial die corresponding to a namespace; also, add a symbol
4040 corresponding to that namespace to the symbol table. NAMESPACE is
4041 the name of the enclosing namespace. */
4044 add_partial_namespace (struct partial_die_info *pdi,
4045 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4046 int need_pc, struct dwarf2_cu *cu)
4048 /* Add a symbol for the namespace. */
4050 add_partial_symbol (pdi, cu);
4052 /* Now scan partial symbols in that namespace. */
4054 if (pdi->has_children)
4055 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4058 /* Read a partial die corresponding to a Fortran module. */
4061 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4062 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4064 /* Now scan partial symbols in that module. */
4066 if (pdi->has_children)
4067 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4070 /* Read a partial die corresponding to a subprogram and create a partial
4071 symbol for that subprogram. When the CU language allows it, this
4072 routine also defines a partial symbol for each nested subprogram
4073 that this subprogram contains.
4075 DIE my also be a lexical block, in which case we simply search
4076 recursively for suprograms defined inside that lexical block.
4077 Again, this is only performed when the CU language allows this
4078 type of definitions. */
4081 add_partial_subprogram (struct partial_die_info *pdi,
4082 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4083 int need_pc, struct dwarf2_cu *cu)
4085 if (pdi->tag == DW_TAG_subprogram)
4087 if (pdi->has_pc_info)
4089 if (pdi->lowpc < *lowpc)
4090 *lowpc = pdi->lowpc;
4091 if (pdi->highpc > *highpc)
4092 *highpc = pdi->highpc;
4096 struct objfile *objfile = cu->objfile;
4098 baseaddr = ANOFFSET (objfile->section_offsets,
4099 SECT_OFF_TEXT (objfile));
4100 addrmap_set_empty (objfile->psymtabs_addrmap,
4101 pdi->lowpc + baseaddr,
4102 pdi->highpc - 1 + baseaddr,
4103 cu->per_cu->v.psymtab);
4105 if (!pdi->is_declaration)
4106 /* Ignore subprogram DIEs that do not have a name, they are
4107 illegal. Do not emit a complaint at this point, we will
4108 do so when we convert this psymtab into a symtab. */
4110 add_partial_symbol (pdi, cu);
4114 if (! pdi->has_children)
4117 if (cu->language == language_ada)
4119 pdi = pdi->die_child;
4122 fixup_partial_die (pdi, cu);
4123 if (pdi->tag == DW_TAG_subprogram
4124 || pdi->tag == DW_TAG_lexical_block)
4125 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4126 pdi = pdi->die_sibling;
4131 /* Read a partial die corresponding to an enumeration type. */
4134 add_partial_enumeration (struct partial_die_info *enum_pdi,
4135 struct dwarf2_cu *cu)
4137 struct partial_die_info *pdi;
4139 if (enum_pdi->name != NULL)
4140 add_partial_symbol (enum_pdi, cu);
4142 pdi = enum_pdi->die_child;
4145 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4146 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4148 add_partial_symbol (pdi, cu);
4149 pdi = pdi->die_sibling;
4153 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4154 Return the corresponding abbrev, or NULL if the number is zero (indicating
4155 an empty DIE). In either case *BYTES_READ will be set to the length of
4156 the initial number. */
4158 static struct abbrev_info *
4159 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4160 struct dwarf2_cu *cu)
4162 bfd *abfd = cu->objfile->obfd;
4163 unsigned int abbrev_number;
4164 struct abbrev_info *abbrev;
4166 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4168 if (abbrev_number == 0)
4171 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4174 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4175 abbrev_number, bfd_get_filename (abfd));
4181 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4182 Returns a pointer to the end of a series of DIEs, terminated by an empty
4183 DIE. Any children of the skipped DIEs will also be skipped. */
4186 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4188 struct abbrev_info *abbrev;
4189 unsigned int bytes_read;
4193 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4195 return info_ptr + bytes_read;
4197 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4201 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4202 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4203 abbrev corresponding to that skipped uleb128 should be passed in
4204 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4208 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4209 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4211 unsigned int bytes_read;
4212 struct attribute attr;
4213 bfd *abfd = cu->objfile->obfd;
4214 unsigned int form, i;
4216 for (i = 0; i < abbrev->num_attrs; i++)
4218 /* The only abbrev we care about is DW_AT_sibling. */
4219 if (abbrev->attrs[i].name == DW_AT_sibling)
4221 read_attribute (&attr, &abbrev->attrs[i],
4222 abfd, info_ptr, cu);
4223 if (attr.form == DW_FORM_ref_addr)
4224 complaint (&symfile_complaints,
4225 _("ignoring absolute DW_AT_sibling"));
4227 return buffer + dwarf2_get_ref_die_offset (&attr);
4230 /* If it isn't DW_AT_sibling, skip this attribute. */
4231 form = abbrev->attrs[i].form;
4235 case DW_FORM_ref_addr:
4236 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4237 and later it is offset sized. */
4238 if (cu->header.version == 2)
4239 info_ptr += cu->header.addr_size;
4241 info_ptr += cu->header.offset_size;
4244 info_ptr += cu->header.addr_size;
4251 case DW_FORM_flag_present:
4263 case DW_FORM_ref_sig8:
4266 case DW_FORM_string:
4267 read_direct_string (abfd, info_ptr, &bytes_read);
4268 info_ptr += bytes_read;
4270 case DW_FORM_sec_offset:
4272 info_ptr += cu->header.offset_size;
4274 case DW_FORM_exprloc:
4276 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4277 info_ptr += bytes_read;
4279 case DW_FORM_block1:
4280 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4282 case DW_FORM_block2:
4283 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4285 case DW_FORM_block4:
4286 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4290 case DW_FORM_ref_udata:
4291 info_ptr = skip_leb128 (abfd, info_ptr);
4293 case DW_FORM_indirect:
4294 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4295 info_ptr += bytes_read;
4296 /* We need to continue parsing from here, so just go back to
4298 goto skip_attribute;
4301 error (_("Dwarf Error: Cannot handle %s "
4302 "in DWARF reader [in module %s]"),
4303 dwarf_form_name (form),
4304 bfd_get_filename (abfd));
4308 if (abbrev->has_children)
4309 return skip_children (buffer, info_ptr, cu);
4314 /* Locate ORIG_PDI's sibling.
4315 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4319 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4320 gdb_byte *buffer, gdb_byte *info_ptr,
4321 bfd *abfd, struct dwarf2_cu *cu)
4323 /* Do we know the sibling already? */
4325 if (orig_pdi->sibling)
4326 return orig_pdi->sibling;
4328 /* Are there any children to deal with? */
4330 if (!orig_pdi->has_children)
4333 /* Skip the children the long way. */
4335 return skip_children (buffer, info_ptr, cu);
4338 /* Expand this partial symbol table into a full symbol table. */
4341 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4347 warning (_("bug: psymtab for %s is already read in."),
4354 printf_filtered (_("Reading in symbols for %s..."),
4356 gdb_flush (gdb_stdout);
4359 /* Restore our global data. */
4360 dwarf2_per_objfile = objfile_data (pst->objfile,
4361 dwarf2_objfile_data_key);
4363 /* If this psymtab is constructed from a debug-only objfile, the
4364 has_section_at_zero flag will not necessarily be correct. We
4365 can get the correct value for this flag by looking at the data
4366 associated with the (presumably stripped) associated objfile. */
4367 if (pst->objfile->separate_debug_objfile_backlink)
4369 struct dwarf2_per_objfile *dpo_backlink
4370 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4371 dwarf2_objfile_data_key);
4373 dwarf2_per_objfile->has_section_at_zero
4374 = dpo_backlink->has_section_at_zero;
4377 dwarf2_per_objfile->reading_partial_symbols = 0;
4379 psymtab_to_symtab_1 (pst);
4381 /* Finish up the debug error message. */
4383 printf_filtered (_("done.\n"));
4388 /* Add PER_CU to the queue. */
4391 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4393 struct dwarf2_queue_item *item;
4396 item = xmalloc (sizeof (*item));
4397 item->per_cu = per_cu;
4400 if (dwarf2_queue == NULL)
4401 dwarf2_queue = item;
4403 dwarf2_queue_tail->next = item;
4405 dwarf2_queue_tail = item;
4408 /* Process the queue. */
4411 process_queue (struct objfile *objfile)
4413 struct dwarf2_queue_item *item, *next_item;
4415 /* The queue starts out with one item, but following a DIE reference
4416 may load a new CU, adding it to the end of the queue. */
4417 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4419 if (dwarf2_per_objfile->using_index
4420 ? !item->per_cu->v.quick->symtab
4421 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4422 process_full_comp_unit (item->per_cu);
4424 item->per_cu->queued = 0;
4425 next_item = item->next;
4429 dwarf2_queue_tail = NULL;
4432 /* Free all allocated queue entries. This function only releases anything if
4433 an error was thrown; if the queue was processed then it would have been
4434 freed as we went along. */
4437 dwarf2_release_queue (void *dummy)
4439 struct dwarf2_queue_item *item, *last;
4441 item = dwarf2_queue;
4444 /* Anything still marked queued is likely to be in an
4445 inconsistent state, so discard it. */
4446 if (item->per_cu->queued)
4448 if (item->per_cu->cu != NULL)
4449 free_one_cached_comp_unit (item->per_cu->cu);
4450 item->per_cu->queued = 0;
4458 dwarf2_queue = dwarf2_queue_tail = NULL;
4461 /* Read in full symbols for PST, and anything it depends on. */
4464 psymtab_to_symtab_1 (struct partial_symtab *pst)
4466 struct dwarf2_per_cu_data *per_cu;
4467 struct cleanup *back_to;
4470 for (i = 0; i < pst->number_of_dependencies; i++)
4471 if (!pst->dependencies[i]->readin)
4473 /* Inform about additional files that need to be read in. */
4476 /* FIXME: i18n: Need to make this a single string. */
4477 fputs_filtered (" ", gdb_stdout);
4479 fputs_filtered ("and ", gdb_stdout);
4481 printf_filtered ("%s...", pst->dependencies[i]->filename);
4482 wrap_here (""); /* Flush output. */
4483 gdb_flush (gdb_stdout);
4485 psymtab_to_symtab_1 (pst->dependencies[i]);
4488 per_cu = pst->read_symtab_private;
4492 /* It's an include file, no symbols to read for it.
4493 Everything is in the parent symtab. */
4498 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4501 /* Load the DIEs associated with PER_CU into memory. */
4504 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4505 struct objfile *objfile)
4507 bfd *abfd = objfile->obfd;
4508 struct dwarf2_cu *cu;
4509 unsigned int offset;
4510 gdb_byte *info_ptr, *beg_of_comp_unit;
4511 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4512 struct attribute *attr;
4515 gdb_assert (! per_cu->from_debug_types);
4517 /* Set local variables from the partial symbol table info. */
4518 offset = per_cu->offset;
4520 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4521 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4522 beg_of_comp_unit = info_ptr;
4524 if (per_cu->cu == NULL)
4526 cu = xmalloc (sizeof (*cu));
4527 init_one_comp_unit (cu, objfile);
4531 /* If an error occurs while loading, release our storage. */
4532 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4534 /* Read in the comp_unit header. */
4535 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4537 /* Complete the cu_header. */
4538 cu->header.offset = offset;
4539 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4541 /* Read the abbrevs for this compilation unit. */
4542 dwarf2_read_abbrevs (abfd, cu);
4543 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4545 /* Link this compilation unit into the compilation unit tree. */
4547 cu->per_cu = per_cu;
4549 /* Link this CU into read_in_chain. */
4550 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4551 dwarf2_per_objfile->read_in_chain = per_cu;
4556 info_ptr += cu->header.first_die_offset;
4559 cu->dies = read_comp_unit (info_ptr, cu);
4561 /* We try not to read any attributes in this function, because not
4562 all objfiles needed for references have been loaded yet, and symbol
4563 table processing isn't initialized. But we have to set the CU language,
4564 or we won't be able to build types correctly. */
4565 prepare_one_comp_unit (cu, cu->dies);
4567 /* Similarly, if we do not read the producer, we can not apply
4568 producer-specific interpretation. */
4569 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4571 cu->producer = DW_STRING (attr);
4575 do_cleanups (free_abbrevs_cleanup);
4577 /* We've successfully allocated this compilation unit. Let our
4578 caller clean it up when finished with it. */
4579 discard_cleanups (free_cu_cleanup);
4583 /* Add a DIE to the delayed physname list. */
4586 add_to_method_list (struct type *type, int fnfield_index, int index,
4587 const char *name, struct die_info *die,
4588 struct dwarf2_cu *cu)
4590 struct delayed_method_info mi;
4592 mi.fnfield_index = fnfield_index;
4596 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4599 /* A cleanup for freeing the delayed method list. */
4602 free_delayed_list (void *ptr)
4604 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4605 if (cu->method_list != NULL)
4607 VEC_free (delayed_method_info, cu->method_list);
4608 cu->method_list = NULL;
4612 /* Compute the physnames of any methods on the CU's method list.
4614 The computation of method physnames is delayed in order to avoid the
4615 (bad) condition that one of the method's formal parameters is of an as yet
4619 compute_delayed_physnames (struct dwarf2_cu *cu)
4622 struct delayed_method_info *mi;
4623 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4625 const char *physname;
4626 struct fn_fieldlist *fn_flp
4627 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4628 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4629 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4633 /* Check for GCC >= 4.0. */
4636 producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
4641 if (cu->producer == NULL)
4643 /* For unknown compilers expect their behavior is not compliant. For GCC
4644 this case can also happen for -gdwarf-4 type units supported since
4650 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4652 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
4654 /* For non-GCC compilers expect their behavior is not compliant. */
4658 cs = &cu->producer[strlen ("GNU ")];
4659 while (*cs && !isdigit (*cs))
4661 if (sscanf (cs, "%d.%d", &major, &minor) != 2)
4663 /* Not recognized as GCC. */
4671 /* Generate full symbol information for PST and CU, whose DIEs have
4672 already been loaded into memory. */
4675 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4677 struct dwarf2_cu *cu = per_cu->cu;
4678 struct objfile *objfile = per_cu->objfile;
4679 CORE_ADDR lowpc, highpc;
4680 struct symtab *symtab;
4681 struct cleanup *back_to, *delayed_list_cleanup;
4684 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4687 back_to = make_cleanup (really_free_pendings, NULL);
4688 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4690 cu->list_in_scope = &file_symbols;
4692 dwarf2_find_base_address (cu->dies, cu);
4694 /* Do line number decoding in read_file_scope () */
4695 process_die (cu->dies, cu);
4697 /* Now that we have processed all the DIEs in the CU, all the types
4698 should be complete, and it should now be safe to compute all of the
4700 compute_delayed_physnames (cu);
4701 do_cleanups (delayed_list_cleanup);
4703 /* Some compilers don't define a DW_AT_high_pc attribute for the
4704 compilation unit. If the DW_AT_high_pc is missing, synthesize
4705 it, by scanning the DIE's below the compilation unit. */
4706 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4708 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4712 /* Set symtab language to language from DW_AT_language. If the
4713 compilation is from a C file generated by language preprocessors, do
4714 not set the language if it was already deduced by start_subfile. */
4715 if (!(cu->language == language_c && symtab->language != language_c))
4716 symtab->language = cu->language;
4718 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4719 produce DW_AT_location with location lists but it can be possibly
4720 invalid without -fvar-tracking.
4722 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4723 needed, it would be wrong due to missing DW_AT_producer there.
4725 Still one can confuse GDB by using non-standard GCC compilation
4726 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4728 if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu))
4729 symtab->locations_valid = 1;
4732 if (dwarf2_per_objfile->using_index)
4733 per_cu->v.quick->symtab = symtab;
4736 struct partial_symtab *pst = per_cu->v.psymtab;
4737 pst->symtab = symtab;
4741 do_cleanups (back_to);
4744 /* Process a die and its children. */
4747 process_die (struct die_info *die, struct dwarf2_cu *cu)
4751 case DW_TAG_padding:
4753 case DW_TAG_compile_unit:
4754 read_file_scope (die, cu);
4756 case DW_TAG_type_unit:
4757 read_type_unit_scope (die, cu);
4759 case DW_TAG_subprogram:
4760 case DW_TAG_inlined_subroutine:
4761 read_func_scope (die, cu);
4763 case DW_TAG_lexical_block:
4764 case DW_TAG_try_block:
4765 case DW_TAG_catch_block:
4766 read_lexical_block_scope (die, cu);
4768 case DW_TAG_class_type:
4769 case DW_TAG_interface_type:
4770 case DW_TAG_structure_type:
4771 case DW_TAG_union_type:
4772 process_structure_scope (die, cu);
4774 case DW_TAG_enumeration_type:
4775 process_enumeration_scope (die, cu);
4778 /* These dies have a type, but processing them does not create
4779 a symbol or recurse to process the children. Therefore we can
4780 read them on-demand through read_type_die. */
4781 case DW_TAG_subroutine_type:
4782 case DW_TAG_set_type:
4783 case DW_TAG_array_type:
4784 case DW_TAG_pointer_type:
4785 case DW_TAG_ptr_to_member_type:
4786 case DW_TAG_reference_type:
4787 case DW_TAG_string_type:
4790 case DW_TAG_base_type:
4791 case DW_TAG_subrange_type:
4792 case DW_TAG_typedef:
4793 /* Add a typedef symbol for the type definition, if it has a
4795 new_symbol (die, read_type_die (die, cu), cu);
4797 case DW_TAG_common_block:
4798 read_common_block (die, cu);
4800 case DW_TAG_common_inclusion:
4802 case DW_TAG_namespace:
4803 processing_has_namespace_info = 1;
4804 read_namespace (die, cu);
4807 processing_has_namespace_info = 1;
4808 read_module (die, cu);
4810 case DW_TAG_imported_declaration:
4811 case DW_TAG_imported_module:
4812 processing_has_namespace_info = 1;
4813 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4814 || cu->language != language_fortran))
4815 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4816 dwarf_tag_name (die->tag));
4817 read_import_statement (die, cu);
4820 new_symbol (die, NULL, cu);
4825 /* A helper function for dwarf2_compute_name which determines whether DIE
4826 needs to have the name of the scope prepended to the name listed in the
4830 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4832 struct attribute *attr;
4836 case DW_TAG_namespace:
4837 case DW_TAG_typedef:
4838 case DW_TAG_class_type:
4839 case DW_TAG_interface_type:
4840 case DW_TAG_structure_type:
4841 case DW_TAG_union_type:
4842 case DW_TAG_enumeration_type:
4843 case DW_TAG_enumerator:
4844 case DW_TAG_subprogram:
4848 case DW_TAG_variable:
4849 case DW_TAG_constant:
4850 /* We only need to prefix "globally" visible variables. These include
4851 any variable marked with DW_AT_external or any variable that
4852 lives in a namespace. [Variables in anonymous namespaces
4853 require prefixing, but they are not DW_AT_external.] */
4855 if (dwarf2_attr (die, DW_AT_specification, cu))
4857 struct dwarf2_cu *spec_cu = cu;
4859 return die_needs_namespace (die_specification (die, &spec_cu),
4863 attr = dwarf2_attr (die, DW_AT_external, cu);
4864 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4865 && die->parent->tag != DW_TAG_module)
4867 /* A variable in a lexical block of some kind does not need a
4868 namespace, even though in C++ such variables may be external
4869 and have a mangled name. */
4870 if (die->parent->tag == DW_TAG_lexical_block
4871 || die->parent->tag == DW_TAG_try_block
4872 || die->parent->tag == DW_TAG_catch_block
4873 || die->parent->tag == DW_TAG_subprogram)
4882 /* Retrieve the last character from a mem_file. */
4885 do_ui_file_peek_last (void *object, const char *buffer, long length)
4887 char *last_char_p = (char *) object;
4890 *last_char_p = buffer[length - 1];
4893 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4894 compute the physname for the object, which include a method's
4895 formal parameters (C++/Java) and return type (Java).
4897 For Ada, return the DIE's linkage name rather than the fully qualified
4898 name. PHYSNAME is ignored..
4900 The result is allocated on the objfile_obstack and canonicalized. */
4903 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4907 name = dwarf2_name (die, cu);
4909 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4910 compute it by typename_concat inside GDB. */
4911 if (cu->language == language_ada
4912 || (cu->language == language_fortran && physname))
4914 /* For Ada unit, we prefer the linkage name over the name, as
4915 the former contains the exported name, which the user expects
4916 to be able to reference. Ideally, we want the user to be able
4917 to reference this entity using either natural or linkage name,
4918 but we haven't started looking at this enhancement yet. */
4919 struct attribute *attr;
4921 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4923 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4924 if (attr && DW_STRING (attr))
4925 return DW_STRING (attr);
4928 /* These are the only languages we know how to qualify names in. */
4930 && (cu->language == language_cplus || cu->language == language_java
4931 || cu->language == language_fortran))
4933 if (die_needs_namespace (die, cu))
4937 struct ui_file *buf;
4939 prefix = determine_prefix (die, cu);
4940 buf = mem_fileopen ();
4941 if (*prefix != '\0')
4943 char *prefixed_name = typename_concat (NULL, prefix, name,
4946 fputs_unfiltered (prefixed_name, buf);
4947 xfree (prefixed_name);
4950 fputs_unfiltered (name, buf);
4952 /* Template parameters may be specified in the DIE's DW_AT_name, or
4953 as children with DW_TAG_template_type_param or
4954 DW_TAG_value_type_param. If the latter, add them to the name
4955 here. If the name already has template parameters, then
4956 skip this step; some versions of GCC emit both, and
4957 it is more efficient to use the pre-computed name.
4959 Something to keep in mind about this process: it is very
4960 unlikely, or in some cases downright impossible, to produce
4961 something that will match the mangled name of a function.
4962 If the definition of the function has the same debug info,
4963 we should be able to match up with it anyway. But fallbacks
4964 using the minimal symbol, for instance to find a method
4965 implemented in a stripped copy of libstdc++, will not work.
4966 If we do not have debug info for the definition, we will have to
4967 match them up some other way.
4969 When we do name matching there is a related problem with function
4970 templates; two instantiated function templates are allowed to
4971 differ only by their return types, which we do not add here. */
4973 if (cu->language == language_cplus && strchr (name, '<') == NULL)
4975 struct attribute *attr;
4976 struct die_info *child;
4979 die->building_fullname = 1;
4981 for (child = die->child; child != NULL; child = child->sibling)
4986 struct dwarf2_locexpr_baton *baton;
4989 if (child->tag != DW_TAG_template_type_param
4990 && child->tag != DW_TAG_template_value_param)
4995 fputs_unfiltered ("<", buf);
4999 fputs_unfiltered (", ", buf);
5001 attr = dwarf2_attr (child, DW_AT_type, cu);
5004 complaint (&symfile_complaints,
5005 _("template parameter missing DW_AT_type"));
5006 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5009 type = die_type (child, cu);
5011 if (child->tag == DW_TAG_template_type_param)
5013 c_print_type (type, "", buf, -1, 0);
5017 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5020 complaint (&symfile_complaints,
5021 _("template parameter missing "
5022 "DW_AT_const_value"));
5023 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5027 dwarf2_const_value_attr (attr, type, name,
5028 &cu->comp_unit_obstack, cu,
5029 &value, &bytes, &baton);
5031 if (TYPE_NOSIGN (type))
5032 /* GDB prints characters as NUMBER 'CHAR'. If that's
5033 changed, this can use value_print instead. */
5034 c_printchar (value, type, buf);
5037 struct value_print_options opts;
5040 v = dwarf2_evaluate_loc_desc (type, NULL,
5044 else if (bytes != NULL)
5046 v = allocate_value (type);
5047 memcpy (value_contents_writeable (v), bytes,
5048 TYPE_LENGTH (type));
5051 v = value_from_longest (type, value);
5053 /* Specify decimal so that we do not depend on
5055 get_formatted_print_options (&opts, 'd');
5057 value_print (v, buf, &opts);
5063 die->building_fullname = 0;
5067 /* Close the argument list, with a space if necessary
5068 (nested templates). */
5069 char last_char = '\0';
5070 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5071 if (last_char == '>')
5072 fputs_unfiltered (" >", buf);
5074 fputs_unfiltered (">", buf);
5078 /* For Java and C++ methods, append formal parameter type
5079 information, if PHYSNAME. */
5081 if (physname && die->tag == DW_TAG_subprogram
5082 && (cu->language == language_cplus
5083 || cu->language == language_java))
5085 struct type *type = read_type_die (die, cu);
5087 c_type_print_args (type, buf, 1, cu->language);
5089 if (cu->language == language_java)
5091 /* For java, we must append the return type to method
5093 if (die->tag == DW_TAG_subprogram)
5094 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5097 else if (cu->language == language_cplus)
5099 /* Assume that an artificial first parameter is
5100 "this", but do not crash if it is not. RealView
5101 marks unnamed (and thus unused) parameters as
5102 artificial; there is no way to differentiate
5104 if (TYPE_NFIELDS (type) > 0
5105 && TYPE_FIELD_ARTIFICIAL (type, 0)
5106 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5107 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5109 fputs_unfiltered (" const", buf);
5113 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5115 ui_file_delete (buf);
5117 if (cu->language == language_cplus)
5120 = dwarf2_canonicalize_name (name, cu,
5121 &cu->objfile->objfile_obstack);
5132 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5133 If scope qualifiers are appropriate they will be added. The result
5134 will be allocated on the objfile_obstack, or NULL if the DIE does
5135 not have a name. NAME may either be from a previous call to
5136 dwarf2_name or NULL.
5138 The output string will be canonicalized (if C++/Java). */
5141 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5143 return dwarf2_compute_name (name, die, cu, 0);
5146 /* Construct a physname for the given DIE in CU. NAME may either be
5147 from a previous call to dwarf2_name or NULL. The result will be
5148 allocated on the objfile_objstack or NULL if the DIE does not have a
5151 The output string will be canonicalized (if C++/Java). */
5154 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5156 return dwarf2_compute_name (name, die, cu, 1);
5159 /* Read the import statement specified by the given die and record it. */
5162 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5164 struct attribute *import_attr;
5165 struct die_info *imported_die;
5166 struct dwarf2_cu *imported_cu;
5167 const char *imported_name;
5168 const char *imported_name_prefix;
5169 const char *canonical_name;
5170 const char *import_alias;
5171 const char *imported_declaration = NULL;
5172 const char *import_prefix;
5176 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5177 if (import_attr == NULL)
5179 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5180 dwarf_tag_name (die->tag));
5185 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5186 imported_name = dwarf2_name (imported_die, imported_cu);
5187 if (imported_name == NULL)
5189 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5191 The import in the following code:
5205 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5206 <52> DW_AT_decl_file : 1
5207 <53> DW_AT_decl_line : 6
5208 <54> DW_AT_import : <0x75>
5209 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5211 <5b> DW_AT_decl_file : 1
5212 <5c> DW_AT_decl_line : 2
5213 <5d> DW_AT_type : <0x6e>
5215 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5216 <76> DW_AT_byte_size : 4
5217 <77> DW_AT_encoding : 5 (signed)
5219 imports the wrong die ( 0x75 instead of 0x58 ).
5220 This case will be ignored until the gcc bug is fixed. */
5224 /* Figure out the local name after import. */
5225 import_alias = dwarf2_name (die, cu);
5227 /* Figure out where the statement is being imported to. */
5228 import_prefix = determine_prefix (die, cu);
5230 /* Figure out what the scope of the imported die is and prepend it
5231 to the name of the imported die. */
5232 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5234 if (imported_die->tag != DW_TAG_namespace
5235 && imported_die->tag != DW_TAG_module)
5237 imported_declaration = imported_name;
5238 canonical_name = imported_name_prefix;
5240 else if (strlen (imported_name_prefix) > 0)
5242 temp = alloca (strlen (imported_name_prefix)
5243 + 2 + strlen (imported_name) + 1);
5244 strcpy (temp, imported_name_prefix);
5245 strcat (temp, "::");
5246 strcat (temp, imported_name);
5247 canonical_name = temp;
5250 canonical_name = imported_name;
5252 cp_add_using_directive (import_prefix,
5255 imported_declaration,
5256 &cu->objfile->objfile_obstack);
5260 initialize_cu_func_list (struct dwarf2_cu *cu)
5262 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5265 /* Cleanup function for read_file_scope. */
5268 free_cu_line_header (void *arg)
5270 struct dwarf2_cu *cu = arg;
5272 free_line_header (cu->line_header);
5273 cu->line_header = NULL;
5277 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5278 char **name, char **comp_dir)
5280 struct attribute *attr;
5285 /* Find the filename. Do not use dwarf2_name here, since the filename
5286 is not a source language identifier. */
5287 attr = dwarf2_attr (die, DW_AT_name, cu);
5290 *name = DW_STRING (attr);
5293 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5295 *comp_dir = DW_STRING (attr);
5296 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5298 *comp_dir = ldirname (*name);
5299 if (*comp_dir != NULL)
5300 make_cleanup (xfree, *comp_dir);
5302 if (*comp_dir != NULL)
5304 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5305 directory, get rid of it. */
5306 char *cp = strchr (*comp_dir, ':');
5308 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5313 *name = "<unknown>";
5316 /* Process DW_TAG_compile_unit. */
5319 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5321 struct objfile *objfile = cu->objfile;
5322 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5323 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5324 CORE_ADDR highpc = ((CORE_ADDR) 0);
5325 struct attribute *attr;
5327 char *comp_dir = NULL;
5328 struct die_info *child_die;
5329 bfd *abfd = objfile->obfd;
5330 struct line_header *line_header = 0;
5333 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5335 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5337 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5338 from finish_block. */
5339 if (lowpc == ((CORE_ADDR) -1))
5344 find_file_and_directory (die, cu, &name, &comp_dir);
5346 attr = dwarf2_attr (die, DW_AT_language, cu);
5349 set_cu_language (DW_UNSND (attr), cu);
5352 attr = dwarf2_attr (die, DW_AT_producer, cu);
5354 cu->producer = DW_STRING (attr);
5356 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5357 standardised yet. As a workaround for the language detection we fall
5358 back to the DW_AT_producer string. */
5359 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5360 cu->language = language_opencl;
5362 /* We assume that we're processing GCC output. */
5363 processing_gcc_compilation = 2;
5365 processing_has_namespace_info = 0;
5367 start_symtab (name, comp_dir, lowpc);
5368 record_debugformat ("DWARF 2");
5369 record_producer (cu->producer);
5371 initialize_cu_func_list (cu);
5373 /* Decode line number information if present. We do this before
5374 processing child DIEs, so that the line header table is available
5375 for DW_AT_decl_file. */
5376 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5379 unsigned int line_offset = DW_UNSND (attr);
5380 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
5383 cu->line_header = line_header;
5384 make_cleanup (free_cu_line_header, cu);
5385 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5389 /* Process all dies in compilation unit. */
5390 if (die->child != NULL)
5392 child_die = die->child;
5393 while (child_die && child_die->tag)
5395 process_die (child_die, cu);
5396 child_die = sibling_die (child_die);
5400 /* Decode macro information, if present. Dwarf 2 macro information
5401 refers to information in the line number info statement program
5402 header, so we can only read it if we've read the header
5404 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5405 if (attr && line_header)
5407 unsigned int macro_offset = DW_UNSND (attr);
5409 dwarf_decode_macros (line_header, macro_offset,
5410 comp_dir, abfd, cu);
5412 do_cleanups (back_to);
5415 /* Process DW_TAG_type_unit.
5416 For TUs we want to skip the first top level sibling if it's not the
5417 actual type being defined by this TU. In this case the first top
5418 level sibling is there to provide context only. */
5421 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5423 struct objfile *objfile = cu->objfile;
5424 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5426 struct attribute *attr;
5428 char *comp_dir = NULL;
5429 struct die_info *child_die;
5430 bfd *abfd = objfile->obfd;
5432 /* start_symtab needs a low pc, but we don't really have one.
5433 Do what read_file_scope would do in the absence of such info. */
5434 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5436 /* Find the filename. Do not use dwarf2_name here, since the filename
5437 is not a source language identifier. */
5438 attr = dwarf2_attr (die, DW_AT_name, cu);
5440 name = DW_STRING (attr);
5442 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5444 comp_dir = DW_STRING (attr);
5445 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5447 comp_dir = ldirname (name);
5448 if (comp_dir != NULL)
5449 make_cleanup (xfree, comp_dir);
5455 attr = dwarf2_attr (die, DW_AT_language, cu);
5457 set_cu_language (DW_UNSND (attr), cu);
5459 /* This isn't technically needed today. It is done for symmetry
5460 with read_file_scope. */
5461 attr = dwarf2_attr (die, DW_AT_producer, cu);
5463 cu->producer = DW_STRING (attr);
5465 /* We assume that we're processing GCC output. */
5466 processing_gcc_compilation = 2;
5468 processing_has_namespace_info = 0;
5470 start_symtab (name, comp_dir, lowpc);
5471 record_debugformat ("DWARF 2");
5472 record_producer (cu->producer);
5474 /* Process the dies in the type unit. */
5475 if (die->child == NULL)
5477 dump_die_for_error (die);
5478 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5479 bfd_get_filename (abfd));
5482 child_die = die->child;
5484 while (child_die && child_die->tag)
5486 process_die (child_die, cu);
5488 child_die = sibling_die (child_die);
5491 do_cleanups (back_to);
5495 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5496 struct dwarf2_cu *cu)
5498 struct function_range *thisfn;
5500 thisfn = (struct function_range *)
5501 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5502 thisfn->name = name;
5503 thisfn->lowpc = lowpc;
5504 thisfn->highpc = highpc;
5505 thisfn->seen_line = 0;
5506 thisfn->next = NULL;
5508 if (cu->last_fn == NULL)
5509 cu->first_fn = thisfn;
5511 cu->last_fn->next = thisfn;
5513 cu->last_fn = thisfn;
5516 /* qsort helper for inherit_abstract_dies. */
5519 unsigned_int_compar (const void *ap, const void *bp)
5521 unsigned int a = *(unsigned int *) ap;
5522 unsigned int b = *(unsigned int *) bp;
5524 return (a > b) - (b > a);
5527 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5528 Inherit only the children of the DW_AT_abstract_origin DIE not being
5529 already referenced by DW_AT_abstract_origin from the children of the
5533 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5535 struct die_info *child_die;
5536 unsigned die_children_count;
5537 /* CU offsets which were referenced by children of the current DIE. */
5539 unsigned *offsets_end, *offsetp;
5540 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5541 struct die_info *origin_die;
5542 /* Iterator of the ORIGIN_DIE children. */
5543 struct die_info *origin_child_die;
5544 struct cleanup *cleanups;
5545 struct attribute *attr;
5546 struct dwarf2_cu *origin_cu;
5547 struct pending **origin_previous_list_in_scope;
5549 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5553 /* Note that following die references may follow to a die in a
5557 origin_die = follow_die_ref (die, attr, &origin_cu);
5559 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5561 origin_previous_list_in_scope = origin_cu->list_in_scope;
5562 origin_cu->list_in_scope = cu->list_in_scope;
5564 if (die->tag != origin_die->tag
5565 && !(die->tag == DW_TAG_inlined_subroutine
5566 && origin_die->tag == DW_TAG_subprogram))
5567 complaint (&symfile_complaints,
5568 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5569 die->offset, origin_die->offset);
5571 child_die = die->child;
5572 die_children_count = 0;
5573 while (child_die && child_die->tag)
5575 child_die = sibling_die (child_die);
5576 die_children_count++;
5578 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5579 cleanups = make_cleanup (xfree, offsets);
5581 offsets_end = offsets;
5582 child_die = die->child;
5583 while (child_die && child_die->tag)
5585 /* For each CHILD_DIE, find the corresponding child of
5586 ORIGIN_DIE. If there is more than one layer of
5587 DW_AT_abstract_origin, follow them all; there shouldn't be,
5588 but GCC versions at least through 4.4 generate this (GCC PR
5590 struct die_info *child_origin_die = child_die;
5591 struct dwarf2_cu *child_origin_cu = cu;
5595 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5599 child_origin_die = follow_die_ref (child_origin_die, attr,
5603 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5604 counterpart may exist. */
5605 if (child_origin_die != child_die)
5607 if (child_die->tag != child_origin_die->tag
5608 && !(child_die->tag == DW_TAG_inlined_subroutine
5609 && child_origin_die->tag == DW_TAG_subprogram))
5610 complaint (&symfile_complaints,
5611 _("Child DIE 0x%x and its abstract origin 0x%x have "
5612 "different tags"), child_die->offset,
5613 child_origin_die->offset);
5614 if (child_origin_die->parent != origin_die)
5615 complaint (&symfile_complaints,
5616 _("Child DIE 0x%x and its abstract origin 0x%x have "
5617 "different parents"), child_die->offset,
5618 child_origin_die->offset);
5620 *offsets_end++ = child_origin_die->offset;
5622 child_die = sibling_die (child_die);
5624 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5625 unsigned_int_compar);
5626 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5627 if (offsetp[-1] == *offsetp)
5628 complaint (&symfile_complaints,
5629 _("Multiple children of DIE 0x%x refer "
5630 "to DIE 0x%x as their abstract origin"),
5631 die->offset, *offsetp);
5634 origin_child_die = origin_die->child;
5635 while (origin_child_die && origin_child_die->tag)
5637 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5638 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5640 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5642 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5643 process_die (origin_child_die, origin_cu);
5645 origin_child_die = sibling_die (origin_child_die);
5647 origin_cu->list_in_scope = origin_previous_list_in_scope;
5649 do_cleanups (cleanups);
5653 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5655 struct objfile *objfile = cu->objfile;
5656 struct context_stack *new;
5659 struct die_info *child_die;
5660 struct attribute *attr, *call_line, *call_file;
5663 struct block *block;
5664 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5665 VEC (symbolp) *template_args = NULL;
5666 struct template_symbol *templ_func = NULL;
5670 /* If we do not have call site information, we can't show the
5671 caller of this inlined function. That's too confusing, so
5672 only use the scope for local variables. */
5673 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5674 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5675 if (call_line == NULL || call_file == NULL)
5677 read_lexical_block_scope (die, cu);
5682 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5684 name = dwarf2_name (die, cu);
5686 /* Ignore functions with missing or empty names. These are actually
5687 illegal according to the DWARF standard. */
5690 complaint (&symfile_complaints,
5691 _("missing name for subprogram DIE at %d"), die->offset);
5695 /* Ignore functions with missing or invalid low and high pc attributes. */
5696 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5698 attr = dwarf2_attr (die, DW_AT_external, cu);
5699 if (!attr || !DW_UNSND (attr))
5700 complaint (&symfile_complaints,
5701 _("cannot get low and high bounds "
5702 "for subprogram DIE at %d"),
5710 /* Record the function range for dwarf_decode_lines. */
5711 add_to_cu_func_list (name, lowpc, highpc, cu);
5713 /* If we have any template arguments, then we must allocate a
5714 different sort of symbol. */
5715 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5717 if (child_die->tag == DW_TAG_template_type_param
5718 || child_die->tag == DW_TAG_template_value_param)
5720 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5721 struct template_symbol);
5722 templ_func->base.is_cplus_template_function = 1;
5727 new = push_context (0, lowpc);
5728 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5729 (struct symbol *) templ_func);
5731 /* If there is a location expression for DW_AT_frame_base, record
5733 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5735 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5736 expression is being recorded directly in the function's symbol
5737 and not in a separate frame-base object. I guess this hack is
5738 to avoid adding some sort of frame-base adjunct/annex to the
5739 function's symbol :-(. The problem with doing this is that it
5740 results in a function symbol with a location expression that
5741 has nothing to do with the location of the function, ouch! The
5742 relationship should be: a function's symbol has-a frame base; a
5743 frame-base has-a location expression. */
5744 dwarf2_symbol_mark_computed (attr, new->name, cu);
5746 cu->list_in_scope = &local_symbols;
5748 if (die->child != NULL)
5750 child_die = die->child;
5751 while (child_die && child_die->tag)
5753 if (child_die->tag == DW_TAG_template_type_param
5754 || child_die->tag == DW_TAG_template_value_param)
5756 struct symbol *arg = new_symbol (child_die, NULL, cu);
5759 VEC_safe_push (symbolp, template_args, arg);
5762 process_die (child_die, cu);
5763 child_die = sibling_die (child_die);
5767 inherit_abstract_dies (die, cu);
5769 /* If we have a DW_AT_specification, we might need to import using
5770 directives from the context of the specification DIE. See the
5771 comment in determine_prefix. */
5772 if (cu->language == language_cplus
5773 && dwarf2_attr (die, DW_AT_specification, cu))
5775 struct dwarf2_cu *spec_cu = cu;
5776 struct die_info *spec_die = die_specification (die, &spec_cu);
5780 child_die = spec_die->child;
5781 while (child_die && child_die->tag)
5783 if (child_die->tag == DW_TAG_imported_module)
5784 process_die (child_die, spec_cu);
5785 child_die = sibling_die (child_die);
5788 /* In some cases, GCC generates specification DIEs that
5789 themselves contain DW_AT_specification attributes. */
5790 spec_die = die_specification (spec_die, &spec_cu);
5794 new = pop_context ();
5795 /* Make a block for the local symbols within. */
5796 block = finish_block (new->name, &local_symbols, new->old_blocks,
5797 lowpc, highpc, objfile);
5799 /* For C++, set the block's scope. */
5800 if (cu->language == language_cplus || cu->language == language_fortran)
5801 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5802 determine_prefix (die, cu),
5803 processing_has_namespace_info);
5805 /* If we have address ranges, record them. */
5806 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5808 /* Attach template arguments to function. */
5809 if (! VEC_empty (symbolp, template_args))
5811 gdb_assert (templ_func != NULL);
5813 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
5814 templ_func->template_arguments
5815 = obstack_alloc (&objfile->objfile_obstack,
5816 (templ_func->n_template_arguments
5817 * sizeof (struct symbol *)));
5818 memcpy (templ_func->template_arguments,
5819 VEC_address (symbolp, template_args),
5820 (templ_func->n_template_arguments * sizeof (struct symbol *)));
5821 VEC_free (symbolp, template_args);
5824 /* In C++, we can have functions nested inside functions (e.g., when
5825 a function declares a class that has methods). This means that
5826 when we finish processing a function scope, we may need to go
5827 back to building a containing block's symbol lists. */
5828 local_symbols = new->locals;
5829 param_symbols = new->params;
5830 using_directives = new->using_directives;
5832 /* If we've finished processing a top-level function, subsequent
5833 symbols go in the file symbol list. */
5834 if (outermost_context_p ())
5835 cu->list_in_scope = &file_symbols;
5838 /* Process all the DIES contained within a lexical block scope. Start
5839 a new scope, process the dies, and then close the scope. */
5842 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5844 struct objfile *objfile = cu->objfile;
5845 struct context_stack *new;
5846 CORE_ADDR lowpc, highpc;
5847 struct die_info *child_die;
5850 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5852 /* Ignore blocks with missing or invalid low and high pc attributes. */
5853 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5854 as multiple lexical blocks? Handling children in a sane way would
5855 be nasty. Might be easier to properly extend generic blocks to
5857 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5862 push_context (0, lowpc);
5863 if (die->child != NULL)
5865 child_die = die->child;
5866 while (child_die && child_die->tag)
5868 process_die (child_die, cu);
5869 child_die = sibling_die (child_die);
5872 new = pop_context ();
5874 if (local_symbols != NULL || using_directives != NULL)
5877 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5880 /* Note that recording ranges after traversing children, as we
5881 do here, means that recording a parent's ranges entails
5882 walking across all its children's ranges as they appear in
5883 the address map, which is quadratic behavior.
5885 It would be nicer to record the parent's ranges before
5886 traversing its children, simply overriding whatever you find
5887 there. But since we don't even decide whether to create a
5888 block until after we've traversed its children, that's hard
5890 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5892 local_symbols = new->locals;
5893 using_directives = new->using_directives;
5896 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5897 Return 1 if the attributes are present and valid, otherwise, return 0.
5898 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5901 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5902 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5903 struct partial_symtab *ranges_pst)
5905 struct objfile *objfile = cu->objfile;
5906 struct comp_unit_head *cu_header = &cu->header;
5907 bfd *obfd = objfile->obfd;
5908 unsigned int addr_size = cu_header->addr_size;
5909 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5910 /* Base address selection entry. */
5921 found_base = cu->base_known;
5922 base = cu->base_address;
5924 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5925 if (offset >= dwarf2_per_objfile->ranges.size)
5927 complaint (&symfile_complaints,
5928 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5932 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5934 /* Read in the largest possible address. */
5935 marker = read_address (obfd, buffer, cu, &dummy);
5936 if ((marker & mask) == mask)
5938 /* If we found the largest possible address, then
5939 read the base address. */
5940 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5941 buffer += 2 * addr_size;
5942 offset += 2 * addr_size;
5948 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5952 CORE_ADDR range_beginning, range_end;
5954 range_beginning = read_address (obfd, buffer, cu, &dummy);
5955 buffer += addr_size;
5956 range_end = read_address (obfd, buffer, cu, &dummy);
5957 buffer += addr_size;
5958 offset += 2 * addr_size;
5960 /* An end of list marker is a pair of zero addresses. */
5961 if (range_beginning == 0 && range_end == 0)
5962 /* Found the end of list entry. */
5965 /* Each base address selection entry is a pair of 2 values.
5966 The first is the largest possible address, the second is
5967 the base address. Check for a base address here. */
5968 if ((range_beginning & mask) == mask)
5970 /* If we found the largest possible address, then
5971 read the base address. */
5972 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5979 /* We have no valid base address for the ranges
5981 complaint (&symfile_complaints,
5982 _("Invalid .debug_ranges data (no base address)"));
5986 if (range_beginning > range_end)
5988 /* Inverted range entries are invalid. */
5989 complaint (&symfile_complaints,
5990 _("Invalid .debug_ranges data (inverted range)"));
5994 /* Empty range entries have no effect. */
5995 if (range_beginning == range_end)
5998 range_beginning += base;
6001 if (ranges_pst != NULL)
6002 addrmap_set_empty (objfile->psymtabs_addrmap,
6003 range_beginning + baseaddr,
6004 range_end - 1 + baseaddr,
6007 /* FIXME: This is recording everything as a low-high
6008 segment of consecutive addresses. We should have a
6009 data structure for discontiguous block ranges
6013 low = range_beginning;
6019 if (range_beginning < low)
6020 low = range_beginning;
6021 if (range_end > high)
6027 /* If the first entry is an end-of-list marker, the range
6028 describes an empty scope, i.e. no instructions. */
6034 *high_return = high;
6038 /* Get low and high pc attributes from a die. Return 1 if the attributes
6039 are present and valid, otherwise, return 0. Return -1 if the range is
6040 discontinuous, i.e. derived from DW_AT_ranges information. */
6042 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6043 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6044 struct partial_symtab *pst)
6046 struct attribute *attr;
6051 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6054 high = DW_ADDR (attr);
6055 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6057 low = DW_ADDR (attr);
6059 /* Found high w/o low attribute. */
6062 /* Found consecutive range of addresses. */
6067 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6070 /* Value of the DW_AT_ranges attribute is the offset in the
6071 .debug_ranges section. */
6072 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6074 /* Found discontinuous range of addresses. */
6079 /* read_partial_die has also the strict LOW < HIGH requirement. */
6083 /* When using the GNU linker, .gnu.linkonce. sections are used to
6084 eliminate duplicate copies of functions and vtables and such.
6085 The linker will arbitrarily choose one and discard the others.
6086 The AT_*_pc values for such functions refer to local labels in
6087 these sections. If the section from that file was discarded, the
6088 labels are not in the output, so the relocs get a value of 0.
6089 If this is a discarded function, mark the pc bounds as invalid,
6090 so that GDB will ignore it. */
6091 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6099 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6100 its low and high PC addresses. Do nothing if these addresses could not
6101 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6102 and HIGHPC to the high address if greater than HIGHPC. */
6105 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6106 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6107 struct dwarf2_cu *cu)
6109 CORE_ADDR low, high;
6110 struct die_info *child = die->child;
6112 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6114 *lowpc = min (*lowpc, low);
6115 *highpc = max (*highpc, high);
6118 /* If the language does not allow nested subprograms (either inside
6119 subprograms or lexical blocks), we're done. */
6120 if (cu->language != language_ada)
6123 /* Check all the children of the given DIE. If it contains nested
6124 subprograms, then check their pc bounds. Likewise, we need to
6125 check lexical blocks as well, as they may also contain subprogram
6127 while (child && child->tag)
6129 if (child->tag == DW_TAG_subprogram
6130 || child->tag == DW_TAG_lexical_block)
6131 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6132 child = sibling_die (child);
6136 /* Get the low and high pc's represented by the scope DIE, and store
6137 them in *LOWPC and *HIGHPC. If the correct values can't be
6138 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6141 get_scope_pc_bounds (struct die_info *die,
6142 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6143 struct dwarf2_cu *cu)
6145 CORE_ADDR best_low = (CORE_ADDR) -1;
6146 CORE_ADDR best_high = (CORE_ADDR) 0;
6147 CORE_ADDR current_low, current_high;
6149 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6151 best_low = current_low;
6152 best_high = current_high;
6156 struct die_info *child = die->child;
6158 while (child && child->tag)
6160 switch (child->tag) {
6161 case DW_TAG_subprogram:
6162 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6164 case DW_TAG_namespace:
6166 /* FIXME: carlton/2004-01-16: Should we do this for
6167 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6168 that current GCC's always emit the DIEs corresponding
6169 to definitions of methods of classes as children of a
6170 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6171 the DIEs giving the declarations, which could be
6172 anywhere). But I don't see any reason why the
6173 standards says that they have to be there. */
6174 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6176 if (current_low != ((CORE_ADDR) -1))
6178 best_low = min (best_low, current_low);
6179 best_high = max (best_high, current_high);
6187 child = sibling_die (child);
6192 *highpc = best_high;
6195 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6198 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6199 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6201 struct attribute *attr;
6203 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6206 CORE_ADDR high = DW_ADDR (attr);
6208 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6211 CORE_ADDR low = DW_ADDR (attr);
6213 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6217 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6220 bfd *obfd = cu->objfile->obfd;
6222 /* The value of the DW_AT_ranges attribute is the offset of the
6223 address range list in the .debug_ranges section. */
6224 unsigned long offset = DW_UNSND (attr);
6225 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6227 /* For some target architectures, but not others, the
6228 read_address function sign-extends the addresses it returns.
6229 To recognize base address selection entries, we need a
6231 unsigned int addr_size = cu->header.addr_size;
6232 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6234 /* The base address, to which the next pair is relative. Note
6235 that this 'base' is a DWARF concept: most entries in a range
6236 list are relative, to reduce the number of relocs against the
6237 debugging information. This is separate from this function's
6238 'baseaddr' argument, which GDB uses to relocate debugging
6239 information from a shared library based on the address at
6240 which the library was loaded. */
6241 CORE_ADDR base = cu->base_address;
6242 int base_known = cu->base_known;
6244 gdb_assert (dwarf2_per_objfile->ranges.readin);
6245 if (offset >= dwarf2_per_objfile->ranges.size)
6247 complaint (&symfile_complaints,
6248 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6255 unsigned int bytes_read;
6256 CORE_ADDR start, end;
6258 start = read_address (obfd, buffer, cu, &bytes_read);
6259 buffer += bytes_read;
6260 end = read_address (obfd, buffer, cu, &bytes_read);
6261 buffer += bytes_read;
6263 /* Did we find the end of the range list? */
6264 if (start == 0 && end == 0)
6267 /* Did we find a base address selection entry? */
6268 else if ((start & base_select_mask) == base_select_mask)
6274 /* We found an ordinary address range. */
6279 complaint (&symfile_complaints,
6280 _("Invalid .debug_ranges data "
6281 "(no base address)"));
6287 /* Inverted range entries are invalid. */
6288 complaint (&symfile_complaints,
6289 _("Invalid .debug_ranges data "
6290 "(inverted range)"));
6294 /* Empty range entries have no effect. */
6298 record_block_range (block,
6299 baseaddr + base + start,
6300 baseaddr + base + end - 1);
6306 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6307 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6308 during 4.6.0 experimental. */
6311 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6314 int major, minor, release;
6316 if (cu->producer == NULL)
6318 /* For unknown compilers expect their behavior is DWARF version
6321 GCC started to support .debug_types sections by -gdwarf-4 since
6322 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6323 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6324 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6325 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6330 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6332 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6334 /* For non-GCC compilers expect their behavior is DWARF version
6339 cs = &cu->producer[strlen ("GNU ")];
6340 while (*cs && !isdigit (*cs))
6342 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6344 /* Not recognized as GCC. */
6349 return major < 4 || (major == 4 && minor < 6);
6352 /* Return the default accessibility type if it is not overriden by
6353 DW_AT_accessibility. */
6355 static enum dwarf_access_attribute
6356 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6358 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6360 /* The default DWARF 2 accessibility for members is public, the default
6361 accessibility for inheritance is private. */
6363 if (die->tag != DW_TAG_inheritance)
6364 return DW_ACCESS_public;
6366 return DW_ACCESS_private;
6370 /* DWARF 3+ defines the default accessibility a different way. The same
6371 rules apply now for DW_TAG_inheritance as for the members and it only
6372 depends on the container kind. */
6374 if (die->parent->tag == DW_TAG_class_type)
6375 return DW_ACCESS_private;
6377 return DW_ACCESS_public;
6381 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6382 offset. If the attribute was not found return 0, otherwise return
6383 1. If it was found but could not properly be handled, set *OFFSET
6387 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6390 struct attribute *attr;
6392 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6397 /* Note that we do not check for a section offset first here.
6398 This is because DW_AT_data_member_location is new in DWARF 4,
6399 so if we see it, we can assume that a constant form is really
6400 a constant and not a section offset. */
6401 if (attr_form_is_constant (attr))
6402 *offset = dwarf2_get_attr_constant_value (attr, 0);
6403 else if (attr_form_is_section_offset (attr))
6404 dwarf2_complex_location_expr_complaint ();
6405 else if (attr_form_is_block (attr))
6406 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6408 dwarf2_complex_location_expr_complaint ();
6416 /* Add an aggregate field to the field list. */
6419 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6420 struct dwarf2_cu *cu)
6422 struct objfile *objfile = cu->objfile;
6423 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6424 struct nextfield *new_field;
6425 struct attribute *attr;
6427 char *fieldname = "";
6429 /* Allocate a new field list entry and link it in. */
6430 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6431 make_cleanup (xfree, new_field);
6432 memset (new_field, 0, sizeof (struct nextfield));
6434 if (die->tag == DW_TAG_inheritance)
6436 new_field->next = fip->baseclasses;
6437 fip->baseclasses = new_field;
6441 new_field->next = fip->fields;
6442 fip->fields = new_field;
6446 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6448 new_field->accessibility = DW_UNSND (attr);
6450 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6451 if (new_field->accessibility != DW_ACCESS_public)
6452 fip->non_public_fields = 1;
6454 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6456 new_field->virtuality = DW_UNSND (attr);
6458 new_field->virtuality = DW_VIRTUALITY_none;
6460 fp = &new_field->field;
6462 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6466 /* Data member other than a C++ static data member. */
6468 /* Get type of field. */
6469 fp->type = die_type (die, cu);
6471 SET_FIELD_BITPOS (*fp, 0);
6473 /* Get bit size of field (zero if none). */
6474 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6477 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6481 FIELD_BITSIZE (*fp) = 0;
6484 /* Get bit offset of field. */
6485 if (handle_data_member_location (die, cu, &offset))
6486 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6487 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6490 if (gdbarch_bits_big_endian (gdbarch))
6492 /* For big endian bits, the DW_AT_bit_offset gives the
6493 additional bit offset from the MSB of the containing
6494 anonymous object to the MSB of the field. We don't
6495 have to do anything special since we don't need to
6496 know the size of the anonymous object. */
6497 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6501 /* For little endian bits, compute the bit offset to the
6502 MSB of the anonymous object, subtract off the number of
6503 bits from the MSB of the field to the MSB of the
6504 object, and then subtract off the number of bits of
6505 the field itself. The result is the bit offset of
6506 the LSB of the field. */
6508 int bit_offset = DW_UNSND (attr);
6510 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6513 /* The size of the anonymous object containing
6514 the bit field is explicit, so use the
6515 indicated size (in bytes). */
6516 anonymous_size = DW_UNSND (attr);
6520 /* The size of the anonymous object containing
6521 the bit field must be inferred from the type
6522 attribute of the data member containing the
6524 anonymous_size = TYPE_LENGTH (fp->type);
6526 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6527 - bit_offset - FIELD_BITSIZE (*fp);
6531 /* Get name of field. */
6532 fieldname = dwarf2_name (die, cu);
6533 if (fieldname == NULL)
6536 /* The name is already allocated along with this objfile, so we don't
6537 need to duplicate it for the type. */
6538 fp->name = fieldname;
6540 /* Change accessibility for artificial fields (e.g. virtual table
6541 pointer or virtual base class pointer) to private. */
6542 if (dwarf2_attr (die, DW_AT_artificial, cu))
6544 FIELD_ARTIFICIAL (*fp) = 1;
6545 new_field->accessibility = DW_ACCESS_private;
6546 fip->non_public_fields = 1;
6549 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6551 /* C++ static member. */
6553 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6554 is a declaration, but all versions of G++ as of this writing
6555 (so through at least 3.2.1) incorrectly generate
6556 DW_TAG_variable tags. */
6558 const char *physname;
6560 /* Get name of field. */
6561 fieldname = dwarf2_name (die, cu);
6562 if (fieldname == NULL)
6565 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6567 /* Only create a symbol if this is an external value.
6568 new_symbol checks this and puts the value in the global symbol
6569 table, which we want. If it is not external, new_symbol
6570 will try to put the value in cu->list_in_scope which is wrong. */
6571 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6573 /* A static const member, not much different than an enum as far as
6574 we're concerned, except that we can support more types. */
6575 new_symbol (die, NULL, cu);
6578 /* Get physical name. */
6579 physname = dwarf2_physname (fieldname, die, cu);
6581 /* The name is already allocated along with this objfile, so we don't
6582 need to duplicate it for the type. */
6583 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6584 FIELD_TYPE (*fp) = die_type (die, cu);
6585 FIELD_NAME (*fp) = fieldname;
6587 else if (die->tag == DW_TAG_inheritance)
6591 /* C++ base class field. */
6592 if (handle_data_member_location (die, cu, &offset))
6593 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6594 FIELD_BITSIZE (*fp) = 0;
6595 FIELD_TYPE (*fp) = die_type (die, cu);
6596 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6597 fip->nbaseclasses++;
6601 /* Add a typedef defined in the scope of the FIP's class. */
6604 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6605 struct dwarf2_cu *cu)
6607 struct objfile *objfile = cu->objfile;
6608 struct typedef_field_list *new_field;
6609 struct attribute *attr;
6610 struct typedef_field *fp;
6611 char *fieldname = "";
6613 /* Allocate a new field list entry and link it in. */
6614 new_field = xzalloc (sizeof (*new_field));
6615 make_cleanup (xfree, new_field);
6617 gdb_assert (die->tag == DW_TAG_typedef);
6619 fp = &new_field->field;
6621 /* Get name of field. */
6622 fp->name = dwarf2_name (die, cu);
6623 if (fp->name == NULL)
6626 fp->type = read_type_die (die, cu);
6628 new_field->next = fip->typedef_field_list;
6629 fip->typedef_field_list = new_field;
6630 fip->typedef_field_list_count++;
6633 /* Create the vector of fields, and attach it to the type. */
6636 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6637 struct dwarf2_cu *cu)
6639 int nfields = fip->nfields;
6641 /* Record the field count, allocate space for the array of fields,
6642 and create blank accessibility bitfields if necessary. */
6643 TYPE_NFIELDS (type) = nfields;
6644 TYPE_FIELDS (type) = (struct field *)
6645 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6646 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6648 if (fip->non_public_fields && cu->language != language_ada)
6650 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6652 TYPE_FIELD_PRIVATE_BITS (type) =
6653 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6654 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6656 TYPE_FIELD_PROTECTED_BITS (type) =
6657 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6658 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6660 TYPE_FIELD_IGNORE_BITS (type) =
6661 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6662 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
6665 /* If the type has baseclasses, allocate and clear a bit vector for
6666 TYPE_FIELD_VIRTUAL_BITS. */
6667 if (fip->nbaseclasses && cu->language != language_ada)
6669 int num_bytes = B_BYTES (fip->nbaseclasses);
6670 unsigned char *pointer;
6672 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6673 pointer = TYPE_ALLOC (type, num_bytes);
6674 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6675 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6676 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6679 /* Copy the saved-up fields into the field vector. Start from the head of
6680 the list, adding to the tail of the field array, so that they end up in
6681 the same order in the array in which they were added to the list. */
6682 while (nfields-- > 0)
6684 struct nextfield *fieldp;
6688 fieldp = fip->fields;
6689 fip->fields = fieldp->next;
6693 fieldp = fip->baseclasses;
6694 fip->baseclasses = fieldp->next;
6697 TYPE_FIELD (type, nfields) = fieldp->field;
6698 switch (fieldp->accessibility)
6700 case DW_ACCESS_private:
6701 if (cu->language != language_ada)
6702 SET_TYPE_FIELD_PRIVATE (type, nfields);
6705 case DW_ACCESS_protected:
6706 if (cu->language != language_ada)
6707 SET_TYPE_FIELD_PROTECTED (type, nfields);
6710 case DW_ACCESS_public:
6714 /* Unknown accessibility. Complain and treat it as public. */
6716 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6717 fieldp->accessibility);
6721 if (nfields < fip->nbaseclasses)
6723 switch (fieldp->virtuality)
6725 case DW_VIRTUALITY_virtual:
6726 case DW_VIRTUALITY_pure_virtual:
6727 if (cu->language == language_ada)
6728 error (_("unexpected virtuality in component of Ada type"));
6729 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6736 /* Add a member function to the proper fieldlist. */
6739 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6740 struct type *type, struct dwarf2_cu *cu)
6742 struct objfile *objfile = cu->objfile;
6743 struct attribute *attr;
6744 struct fnfieldlist *flp;
6746 struct fn_field *fnp;
6748 struct nextfnfield *new_fnfield;
6749 struct type *this_type;
6750 enum dwarf_access_attribute accessibility;
6752 if (cu->language == language_ada)
6753 error (_("unexpected member function in Ada type"));
6755 /* Get name of member function. */
6756 fieldname = dwarf2_name (die, cu);
6757 if (fieldname == NULL)
6760 /* Look up member function name in fieldlist. */
6761 for (i = 0; i < fip->nfnfields; i++)
6763 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6767 /* Create new list element if necessary. */
6768 if (i < fip->nfnfields)
6769 flp = &fip->fnfieldlists[i];
6772 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6774 fip->fnfieldlists = (struct fnfieldlist *)
6775 xrealloc (fip->fnfieldlists,
6776 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6777 * sizeof (struct fnfieldlist));
6778 if (fip->nfnfields == 0)
6779 make_cleanup (free_current_contents, &fip->fnfieldlists);
6781 flp = &fip->fnfieldlists[fip->nfnfields];
6782 flp->name = fieldname;
6785 i = fip->nfnfields++;
6788 /* Create a new member function field and chain it to the field list
6790 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6791 make_cleanup (xfree, new_fnfield);
6792 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6793 new_fnfield->next = flp->head;
6794 flp->head = new_fnfield;
6797 /* Fill in the member function field info. */
6798 fnp = &new_fnfield->fnfield;
6800 /* Delay processing of the physname until later. */
6801 if (cu->language == language_cplus || cu->language == language_java)
6803 add_to_method_list (type, i, flp->length - 1, fieldname,
6808 const char *physname = dwarf2_physname (fieldname, die, cu);
6809 fnp->physname = physname ? physname : "";
6812 fnp->type = alloc_type (objfile);
6813 this_type = read_type_die (die, cu);
6814 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6816 int nparams = TYPE_NFIELDS (this_type);
6818 /* TYPE is the domain of this method, and THIS_TYPE is the type
6819 of the method itself (TYPE_CODE_METHOD). */
6820 smash_to_method_type (fnp->type, type,
6821 TYPE_TARGET_TYPE (this_type),
6822 TYPE_FIELDS (this_type),
6823 TYPE_NFIELDS (this_type),
6824 TYPE_VARARGS (this_type));
6826 /* Handle static member functions.
6827 Dwarf2 has no clean way to discern C++ static and non-static
6828 member functions. G++ helps GDB by marking the first
6829 parameter for non-static member functions (which is the this
6830 pointer) as artificial. We obtain this information from
6831 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6832 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6833 fnp->voffset = VOFFSET_STATIC;
6836 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6837 dwarf2_full_name (fieldname, die, cu));
6839 /* Get fcontext from DW_AT_containing_type if present. */
6840 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6841 fnp->fcontext = die_containing_type (die, cu);
6843 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6844 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6846 /* Get accessibility. */
6847 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6849 accessibility = DW_UNSND (attr);
6851 accessibility = dwarf2_default_access_attribute (die, cu);
6852 switch (accessibility)
6854 case DW_ACCESS_private:
6855 fnp->is_private = 1;
6857 case DW_ACCESS_protected:
6858 fnp->is_protected = 1;
6862 /* Check for artificial methods. */
6863 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6864 if (attr && DW_UNSND (attr) != 0)
6865 fnp->is_artificial = 1;
6867 /* Get index in virtual function table if it is a virtual member
6868 function. For older versions of GCC, this is an offset in the
6869 appropriate virtual table, as specified by DW_AT_containing_type.
6870 For everyone else, it is an expression to be evaluated relative
6871 to the object address. */
6873 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6876 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6878 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6880 /* Old-style GCC. */
6881 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6883 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6884 || (DW_BLOCK (attr)->size > 1
6885 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6886 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6888 struct dwarf_block blk;
6891 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6893 blk.size = DW_BLOCK (attr)->size - offset;
6894 blk.data = DW_BLOCK (attr)->data + offset;
6895 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6896 if ((fnp->voffset % cu->header.addr_size) != 0)
6897 dwarf2_complex_location_expr_complaint ();
6899 fnp->voffset /= cu->header.addr_size;
6903 dwarf2_complex_location_expr_complaint ();
6906 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6908 else if (attr_form_is_section_offset (attr))
6910 dwarf2_complex_location_expr_complaint ();
6914 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6920 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6921 if (attr && DW_UNSND (attr))
6923 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6924 complaint (&symfile_complaints,
6925 _("Member function \"%s\" (offset %d) is virtual "
6926 "but the vtable offset is not specified"),
6927 fieldname, die->offset);
6928 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6929 TYPE_CPLUS_DYNAMIC (type) = 1;
6934 /* Create the vector of member function fields, and attach it to the type. */
6937 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6938 struct dwarf2_cu *cu)
6940 struct fnfieldlist *flp;
6941 int total_length = 0;
6944 if (cu->language == language_ada)
6945 error (_("unexpected member functions in Ada type"));
6947 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6948 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6949 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6951 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6953 struct nextfnfield *nfp = flp->head;
6954 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6957 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6958 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6959 fn_flp->fn_fields = (struct fn_field *)
6960 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6961 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6962 fn_flp->fn_fields[k] = nfp->fnfield;
6964 total_length += flp->length;
6967 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6968 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6971 /* Returns non-zero if NAME is the name of a vtable member in CU's
6972 language, zero otherwise. */
6974 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6976 static const char vptr[] = "_vptr";
6977 static const char vtable[] = "vtable";
6979 /* Look for the C++ and Java forms of the vtable. */
6980 if ((cu->language == language_java
6981 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6982 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
6983 && is_cplus_marker (name[sizeof (vptr) - 1])))
6989 /* GCC outputs unnamed structures that are really pointers to member
6990 functions, with the ABI-specified layout. If TYPE describes
6991 such a structure, smash it into a member function type.
6993 GCC shouldn't do this; it should just output pointer to member DIEs.
6994 This is GCC PR debug/28767. */
6997 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
6999 struct type *pfn_type, *domain_type, *new_type;
7001 /* Check for a structure with no name and two children. */
7002 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7005 /* Check for __pfn and __delta members. */
7006 if (TYPE_FIELD_NAME (type, 0) == NULL
7007 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7008 || TYPE_FIELD_NAME (type, 1) == NULL
7009 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7012 /* Find the type of the method. */
7013 pfn_type = TYPE_FIELD_TYPE (type, 0);
7014 if (pfn_type == NULL
7015 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7016 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7019 /* Look for the "this" argument. */
7020 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7021 if (TYPE_NFIELDS (pfn_type) == 0
7022 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7023 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7026 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7027 new_type = alloc_type (objfile);
7028 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7029 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7030 TYPE_VARARGS (pfn_type));
7031 smash_to_methodptr_type (type, new_type);
7034 /* Called when we find the DIE that starts a structure or union scope
7035 (definition) to create a type for the structure or union. Fill in
7036 the type's name and general properties; the members will not be
7037 processed until process_structure_type.
7039 NOTE: we need to call these functions regardless of whether or not the
7040 DIE has a DW_AT_name attribute, since it might be an anonymous
7041 structure or union. This gets the type entered into our set of
7044 However, if the structure is incomplete (an opaque struct/union)
7045 then suppress creating a symbol table entry for it since gdb only
7046 wants to find the one with the complete definition. Note that if
7047 it is complete, we just call new_symbol, which does it's own
7048 checking about whether the struct/union is anonymous or not (and
7049 suppresses creating a symbol table entry itself). */
7051 static struct type *
7052 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7054 struct objfile *objfile = cu->objfile;
7056 struct attribute *attr;
7059 /* If the definition of this type lives in .debug_types, read that type.
7060 Don't follow DW_AT_specification though, that will take us back up
7061 the chain and we want to go down. */
7062 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7065 struct dwarf2_cu *type_cu = cu;
7066 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7068 /* We could just recurse on read_structure_type, but we need to call
7069 get_die_type to ensure only one type for this DIE is created.
7070 This is important, for example, because for c++ classes we need
7071 TYPE_NAME set which is only done by new_symbol. Blech. */
7072 type = read_type_die (type_die, type_cu);
7074 /* TYPE_CU may not be the same as CU.
7075 Ensure TYPE is recorded in CU's type_hash table. */
7076 return set_die_type (die, type, cu);
7079 type = alloc_type (objfile);
7080 INIT_CPLUS_SPECIFIC (type);
7082 name = dwarf2_name (die, cu);
7085 if (cu->language == language_cplus
7086 || cu->language == language_java)
7088 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7090 /* dwarf2_full_name might have already finished building the DIE's
7091 type. If so, there is no need to continue. */
7092 if (get_die_type (die, cu) != NULL)
7093 return get_die_type (die, cu);
7095 TYPE_TAG_NAME (type) = full_name;
7096 if (die->tag == DW_TAG_structure_type
7097 || die->tag == DW_TAG_class_type)
7098 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7102 /* The name is already allocated along with this objfile, so
7103 we don't need to duplicate it for the type. */
7104 TYPE_TAG_NAME (type) = (char *) name;
7105 if (die->tag == DW_TAG_class_type)
7106 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7110 if (die->tag == DW_TAG_structure_type)
7112 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7114 else if (die->tag == DW_TAG_union_type)
7116 TYPE_CODE (type) = TYPE_CODE_UNION;
7120 TYPE_CODE (type) = TYPE_CODE_CLASS;
7123 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7124 TYPE_DECLARED_CLASS (type) = 1;
7126 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7129 TYPE_LENGTH (type) = DW_UNSND (attr);
7133 TYPE_LENGTH (type) = 0;
7136 TYPE_STUB_SUPPORTED (type) = 1;
7137 if (die_is_declaration (die, cu))
7138 TYPE_STUB (type) = 1;
7139 else if (attr == NULL && die->child == NULL
7140 && producer_is_realview (cu->producer))
7141 /* RealView does not output the required DW_AT_declaration
7142 on incomplete types. */
7143 TYPE_STUB (type) = 1;
7145 /* We need to add the type field to the die immediately so we don't
7146 infinitely recurse when dealing with pointers to the structure
7147 type within the structure itself. */
7148 set_die_type (die, type, cu);
7150 /* set_die_type should be already done. */
7151 set_descriptive_type (type, die, cu);
7156 /* Finish creating a structure or union type, including filling in
7157 its members and creating a symbol for it. */
7160 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7162 struct objfile *objfile = cu->objfile;
7163 struct die_info *child_die = die->child;
7166 type = get_die_type (die, cu);
7168 type = read_structure_type (die, cu);
7170 if (die->child != NULL && ! die_is_declaration (die, cu))
7172 struct field_info fi;
7173 struct die_info *child_die;
7174 VEC (symbolp) *template_args = NULL;
7175 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7177 memset (&fi, 0, sizeof (struct field_info));
7179 child_die = die->child;
7181 while (child_die && child_die->tag)
7183 if (child_die->tag == DW_TAG_member
7184 || child_die->tag == DW_TAG_variable)
7186 /* NOTE: carlton/2002-11-05: A C++ static data member
7187 should be a DW_TAG_member that is a declaration, but
7188 all versions of G++ as of this writing (so through at
7189 least 3.2.1) incorrectly generate DW_TAG_variable
7190 tags for them instead. */
7191 dwarf2_add_field (&fi, child_die, cu);
7193 else if (child_die->tag == DW_TAG_subprogram)
7195 /* C++ member function. */
7196 dwarf2_add_member_fn (&fi, child_die, type, cu);
7198 else if (child_die->tag == DW_TAG_inheritance)
7200 /* C++ base class field. */
7201 dwarf2_add_field (&fi, child_die, cu);
7203 else if (child_die->tag == DW_TAG_typedef)
7204 dwarf2_add_typedef (&fi, child_die, cu);
7205 else if (child_die->tag == DW_TAG_template_type_param
7206 || child_die->tag == DW_TAG_template_value_param)
7208 struct symbol *arg = new_symbol (child_die, NULL, cu);
7211 VEC_safe_push (symbolp, template_args, arg);
7214 child_die = sibling_die (child_die);
7217 /* Attach template arguments to type. */
7218 if (! VEC_empty (symbolp, template_args))
7220 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7221 TYPE_N_TEMPLATE_ARGUMENTS (type)
7222 = VEC_length (symbolp, template_args);
7223 TYPE_TEMPLATE_ARGUMENTS (type)
7224 = obstack_alloc (&objfile->objfile_obstack,
7225 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7226 * sizeof (struct symbol *)));
7227 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7228 VEC_address (symbolp, template_args),
7229 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7230 * sizeof (struct symbol *)));
7231 VEC_free (symbolp, template_args);
7234 /* Attach fields and member functions to the type. */
7236 dwarf2_attach_fields_to_type (&fi, type, cu);
7239 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7241 /* Get the type which refers to the base class (possibly this
7242 class itself) which contains the vtable pointer for the current
7243 class from the DW_AT_containing_type attribute. This use of
7244 DW_AT_containing_type is a GNU extension. */
7246 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7248 struct type *t = die_containing_type (die, cu);
7250 TYPE_VPTR_BASETYPE (type) = t;
7255 /* Our own class provides vtbl ptr. */
7256 for (i = TYPE_NFIELDS (t) - 1;
7257 i >= TYPE_N_BASECLASSES (t);
7260 char *fieldname = TYPE_FIELD_NAME (t, i);
7262 if (is_vtable_name (fieldname, cu))
7264 TYPE_VPTR_FIELDNO (type) = i;
7269 /* Complain if virtual function table field not found. */
7270 if (i < TYPE_N_BASECLASSES (t))
7271 complaint (&symfile_complaints,
7272 _("virtual function table pointer "
7273 "not found when defining class '%s'"),
7274 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7279 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7282 else if (cu->producer
7283 && strncmp (cu->producer,
7284 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7286 /* The IBM XLC compiler does not provide direct indication
7287 of the containing type, but the vtable pointer is
7288 always named __vfp. */
7292 for (i = TYPE_NFIELDS (type) - 1;
7293 i >= TYPE_N_BASECLASSES (type);
7296 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7298 TYPE_VPTR_FIELDNO (type) = i;
7299 TYPE_VPTR_BASETYPE (type) = type;
7306 /* Copy fi.typedef_field_list linked list elements content into the
7307 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7308 if (fi.typedef_field_list)
7310 int i = fi.typedef_field_list_count;
7312 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7313 TYPE_TYPEDEF_FIELD_ARRAY (type)
7314 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7315 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7317 /* Reverse the list order to keep the debug info elements order. */
7320 struct typedef_field *dest, *src;
7322 dest = &TYPE_TYPEDEF_FIELD (type, i);
7323 src = &fi.typedef_field_list->field;
7324 fi.typedef_field_list = fi.typedef_field_list->next;
7329 do_cleanups (back_to);
7332 quirk_gcc_member_function_pointer (type, cu->objfile);
7334 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7335 snapshots) has been known to create a die giving a declaration
7336 for a class that has, as a child, a die giving a definition for a
7337 nested class. So we have to process our children even if the
7338 current die is a declaration. Normally, of course, a declaration
7339 won't have any children at all. */
7341 while (child_die != NULL && child_die->tag)
7343 if (child_die->tag == DW_TAG_member
7344 || child_die->tag == DW_TAG_variable
7345 || child_die->tag == DW_TAG_inheritance
7346 || child_die->tag == DW_TAG_template_value_param
7347 || child_die->tag == DW_TAG_template_type_param)
7352 process_die (child_die, cu);
7354 child_die = sibling_die (child_die);
7357 /* Do not consider external references. According to the DWARF standard,
7358 these DIEs are identified by the fact that they have no byte_size
7359 attribute, and a declaration attribute. */
7360 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7361 || !die_is_declaration (die, cu))
7362 new_symbol (die, type, cu);
7365 /* Given a DW_AT_enumeration_type die, set its type. We do not
7366 complete the type's fields yet, or create any symbols. */
7368 static struct type *
7369 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7371 struct objfile *objfile = cu->objfile;
7373 struct attribute *attr;
7376 /* If the definition of this type lives in .debug_types, read that type.
7377 Don't follow DW_AT_specification though, that will take us back up
7378 the chain and we want to go down. */
7379 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7382 struct dwarf2_cu *type_cu = cu;
7383 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7385 type = read_type_die (type_die, type_cu);
7387 /* TYPE_CU may not be the same as CU.
7388 Ensure TYPE is recorded in CU's type_hash table. */
7389 return set_die_type (die, type, cu);
7392 type = alloc_type (objfile);
7394 TYPE_CODE (type) = TYPE_CODE_ENUM;
7395 name = dwarf2_full_name (NULL, die, cu);
7397 TYPE_TAG_NAME (type) = (char *) name;
7399 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7402 TYPE_LENGTH (type) = DW_UNSND (attr);
7406 TYPE_LENGTH (type) = 0;
7409 /* The enumeration DIE can be incomplete. In Ada, any type can be
7410 declared as private in the package spec, and then defined only
7411 inside the package body. Such types are known as Taft Amendment
7412 Types. When another package uses such a type, an incomplete DIE
7413 may be generated by the compiler. */
7414 if (die_is_declaration (die, cu))
7415 TYPE_STUB (type) = 1;
7417 return set_die_type (die, type, cu);
7420 /* Given a pointer to a die which begins an enumeration, process all
7421 the dies that define the members of the enumeration, and create the
7422 symbol for the enumeration type.
7424 NOTE: We reverse the order of the element list. */
7427 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7429 struct type *this_type;
7431 this_type = get_die_type (die, cu);
7432 if (this_type == NULL)
7433 this_type = read_enumeration_type (die, cu);
7435 if (die->child != NULL)
7437 struct die_info *child_die;
7439 struct field *fields = NULL;
7441 int unsigned_enum = 1;
7444 child_die = die->child;
7445 while (child_die && child_die->tag)
7447 if (child_die->tag != DW_TAG_enumerator)
7449 process_die (child_die, cu);
7453 name = dwarf2_name (child_die, cu);
7456 sym = new_symbol (child_die, this_type, cu);
7457 if (SYMBOL_VALUE (sym) < 0)
7460 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7462 fields = (struct field *)
7464 (num_fields + DW_FIELD_ALLOC_CHUNK)
7465 * sizeof (struct field));
7468 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7469 FIELD_TYPE (fields[num_fields]) = NULL;
7470 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7471 FIELD_BITSIZE (fields[num_fields]) = 0;
7477 child_die = sibling_die (child_die);
7482 TYPE_NFIELDS (this_type) = num_fields;
7483 TYPE_FIELDS (this_type) = (struct field *)
7484 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7485 memcpy (TYPE_FIELDS (this_type), fields,
7486 sizeof (struct field) * num_fields);
7490 TYPE_UNSIGNED (this_type) = 1;
7493 new_symbol (die, this_type, cu);
7496 /* Extract all information from a DW_TAG_array_type DIE and put it in
7497 the DIE's type field. For now, this only handles one dimensional
7500 static struct type *
7501 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7503 struct objfile *objfile = cu->objfile;
7504 struct die_info *child_die;
7506 struct type *element_type, *range_type, *index_type;
7507 struct type **range_types = NULL;
7508 struct attribute *attr;
7510 struct cleanup *back_to;
7513 element_type = die_type (die, cu);
7515 /* The die_type call above may have already set the type for this DIE. */
7516 type = get_die_type (die, cu);
7520 /* Irix 6.2 native cc creates array types without children for
7521 arrays with unspecified length. */
7522 if (die->child == NULL)
7524 index_type = objfile_type (objfile)->builtin_int;
7525 range_type = create_range_type (NULL, index_type, 0, -1);
7526 type = create_array_type (NULL, element_type, range_type);
7527 return set_die_type (die, type, cu);
7530 back_to = make_cleanup (null_cleanup, NULL);
7531 child_die = die->child;
7532 while (child_die && child_die->tag)
7534 if (child_die->tag == DW_TAG_subrange_type)
7536 struct type *child_type = read_type_die (child_die, cu);
7538 if (child_type != NULL)
7540 /* The range type was succesfully read. Save it for the
7541 array type creation. */
7542 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7544 range_types = (struct type **)
7545 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7546 * sizeof (struct type *));
7548 make_cleanup (free_current_contents, &range_types);
7550 range_types[ndim++] = child_type;
7553 child_die = sibling_die (child_die);
7556 /* Dwarf2 dimensions are output from left to right, create the
7557 necessary array types in backwards order. */
7559 type = element_type;
7561 if (read_array_order (die, cu) == DW_ORD_col_major)
7566 type = create_array_type (NULL, type, range_types[i++]);
7571 type = create_array_type (NULL, type, range_types[ndim]);
7574 /* Understand Dwarf2 support for vector types (like they occur on
7575 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7576 array type. This is not part of the Dwarf2/3 standard yet, but a
7577 custom vendor extension. The main difference between a regular
7578 array and the vector variant is that vectors are passed by value
7580 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7582 make_vector_type (type);
7584 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7585 implementation may choose to implement triple vectors using this
7587 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7590 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
7591 TYPE_LENGTH (type) = DW_UNSND (attr);
7593 complaint (&symfile_complaints,
7594 _("DW_AT_byte_size for array type smaller "
7595 "than the total size of elements"));
7598 name = dwarf2_name (die, cu);
7600 TYPE_NAME (type) = name;
7602 /* Install the type in the die. */
7603 set_die_type (die, type, cu);
7605 /* set_die_type should be already done. */
7606 set_descriptive_type (type, die, cu);
7608 do_cleanups (back_to);
7613 static enum dwarf_array_dim_ordering
7614 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7616 struct attribute *attr;
7618 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7620 if (attr) return DW_SND (attr);
7622 /* GNU F77 is a special case, as at 08/2004 array type info is the
7623 opposite order to the dwarf2 specification, but data is still
7624 laid out as per normal fortran.
7626 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7627 version checking. */
7629 if (cu->language == language_fortran
7630 && cu->producer && strstr (cu->producer, "GNU F77"))
7632 return DW_ORD_row_major;
7635 switch (cu->language_defn->la_array_ordering)
7637 case array_column_major:
7638 return DW_ORD_col_major;
7639 case array_row_major:
7641 return DW_ORD_row_major;
7645 /* Extract all information from a DW_TAG_set_type DIE and put it in
7646 the DIE's type field. */
7648 static struct type *
7649 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7651 struct type *domain_type, *set_type;
7652 struct attribute *attr;
7654 domain_type = die_type (die, cu);
7656 /* The die_type call above may have already set the type for this DIE. */
7657 set_type = get_die_type (die, cu);
7661 set_type = create_set_type (NULL, domain_type);
7663 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7665 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7667 return set_die_type (die, set_type, cu);
7670 /* First cut: install each common block member as a global variable. */
7673 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7675 struct die_info *child_die;
7676 struct attribute *attr;
7678 CORE_ADDR base = (CORE_ADDR) 0;
7680 attr = dwarf2_attr (die, DW_AT_location, cu);
7683 /* Support the .debug_loc offsets. */
7684 if (attr_form_is_block (attr))
7686 base = decode_locdesc (DW_BLOCK (attr), cu);
7688 else if (attr_form_is_section_offset (attr))
7690 dwarf2_complex_location_expr_complaint ();
7694 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7695 "common block member");
7698 if (die->child != NULL)
7700 child_die = die->child;
7701 while (child_die && child_die->tag)
7705 sym = new_symbol (child_die, NULL, cu);
7707 && handle_data_member_location (child_die, cu, &offset))
7709 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
7710 add_symbol_to_list (sym, &global_symbols);
7712 child_die = sibling_die (child_die);
7717 /* Create a type for a C++ namespace. */
7719 static struct type *
7720 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7722 struct objfile *objfile = cu->objfile;
7723 const char *previous_prefix, *name;
7727 /* For extensions, reuse the type of the original namespace. */
7728 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7730 struct die_info *ext_die;
7731 struct dwarf2_cu *ext_cu = cu;
7733 ext_die = dwarf2_extension (die, &ext_cu);
7734 type = read_type_die (ext_die, ext_cu);
7736 /* EXT_CU may not be the same as CU.
7737 Ensure TYPE is recorded in CU's type_hash table. */
7738 return set_die_type (die, type, cu);
7741 name = namespace_name (die, &is_anonymous, cu);
7743 /* Now build the name of the current namespace. */
7745 previous_prefix = determine_prefix (die, cu);
7746 if (previous_prefix[0] != '\0')
7747 name = typename_concat (&objfile->objfile_obstack,
7748 previous_prefix, name, 0, cu);
7750 /* Create the type. */
7751 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
7753 TYPE_NAME (type) = (char *) name;
7754 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7756 return set_die_type (die, type, cu);
7759 /* Read a C++ namespace. */
7762 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
7764 struct objfile *objfile = cu->objfile;
7767 /* Add a symbol associated to this if we haven't seen the namespace
7768 before. Also, add a using directive if it's an anonymous
7771 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
7775 type = read_type_die (die, cu);
7776 new_symbol (die, type, cu);
7778 namespace_name (die, &is_anonymous, cu);
7781 const char *previous_prefix = determine_prefix (die, cu);
7783 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
7784 NULL, &objfile->objfile_obstack);
7788 if (die->child != NULL)
7790 struct die_info *child_die = die->child;
7792 while (child_die && child_die->tag)
7794 process_die (child_die, cu);
7795 child_die = sibling_die (child_die);
7800 /* Read a Fortran module as type. This DIE can be only a declaration used for
7801 imported module. Still we need that type as local Fortran "use ... only"
7802 declaration imports depend on the created type in determine_prefix. */
7804 static struct type *
7805 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
7807 struct objfile *objfile = cu->objfile;
7811 module_name = dwarf2_name (die, cu);
7813 complaint (&symfile_complaints,
7814 _("DW_TAG_module has no name, offset 0x%x"),
7816 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
7818 /* determine_prefix uses TYPE_TAG_NAME. */
7819 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7821 return set_die_type (die, type, cu);
7824 /* Read a Fortran module. */
7827 read_module (struct die_info *die, struct dwarf2_cu *cu)
7829 struct die_info *child_die = die->child;
7831 while (child_die && child_die->tag)
7833 process_die (child_die, cu);
7834 child_die = sibling_die (child_die);
7838 /* Return the name of the namespace represented by DIE. Set
7839 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7843 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7845 struct die_info *current_die;
7846 const char *name = NULL;
7848 /* Loop through the extensions until we find a name. */
7850 for (current_die = die;
7851 current_die != NULL;
7852 current_die = dwarf2_extension (die, &cu))
7854 name = dwarf2_name (current_die, cu);
7859 /* Is it an anonymous namespace? */
7861 *is_anonymous = (name == NULL);
7863 name = "(anonymous namespace)";
7868 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7869 the user defined type vector. */
7871 static struct type *
7872 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7874 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7875 struct comp_unit_head *cu_header = &cu->header;
7877 struct attribute *attr_byte_size;
7878 struct attribute *attr_address_class;
7879 int byte_size, addr_class;
7880 struct type *target_type;
7882 target_type = die_type (die, cu);
7884 /* The die_type call above may have already set the type for this DIE. */
7885 type = get_die_type (die, cu);
7889 type = lookup_pointer_type (target_type);
7891 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7893 byte_size = DW_UNSND (attr_byte_size);
7895 byte_size = cu_header->addr_size;
7897 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7898 if (attr_address_class)
7899 addr_class = DW_UNSND (attr_address_class);
7901 addr_class = DW_ADDR_none;
7903 /* If the pointer size or address class is different than the
7904 default, create a type variant marked as such and set the
7905 length accordingly. */
7906 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7908 if (gdbarch_address_class_type_flags_p (gdbarch))
7912 type_flags = gdbarch_address_class_type_flags
7913 (gdbarch, byte_size, addr_class);
7914 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7916 type = make_type_with_address_space (type, type_flags);
7918 else if (TYPE_LENGTH (type) != byte_size)
7920 complaint (&symfile_complaints,
7921 _("invalid pointer size %d"), byte_size);
7925 /* Should we also complain about unhandled address classes? */
7929 TYPE_LENGTH (type) = byte_size;
7930 return set_die_type (die, type, cu);
7933 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7934 the user defined type vector. */
7936 static struct type *
7937 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7940 struct type *to_type;
7941 struct type *domain;
7943 to_type = die_type (die, cu);
7944 domain = die_containing_type (die, cu);
7946 /* The calls above may have already set the type for this DIE. */
7947 type = get_die_type (die, cu);
7951 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7952 type = lookup_methodptr_type (to_type);
7954 type = lookup_memberptr_type (to_type, domain);
7956 return set_die_type (die, type, cu);
7959 /* Extract all information from a DW_TAG_reference_type DIE and add to
7960 the user defined type vector. */
7962 static struct type *
7963 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7965 struct comp_unit_head *cu_header = &cu->header;
7966 struct type *type, *target_type;
7967 struct attribute *attr;
7969 target_type = die_type (die, cu);
7971 /* The die_type call above may have already set the type for this DIE. */
7972 type = get_die_type (die, cu);
7976 type = lookup_reference_type (target_type);
7977 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7980 TYPE_LENGTH (type) = DW_UNSND (attr);
7984 TYPE_LENGTH (type) = cu_header->addr_size;
7986 return set_die_type (die, type, cu);
7989 static struct type *
7990 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
7992 struct type *base_type, *cv_type;
7994 base_type = die_type (die, cu);
7996 /* The die_type call above may have already set the type for this DIE. */
7997 cv_type = get_die_type (die, cu);
8001 /* In case the const qualifier is applied to an array type, the element type
8002 is so qualified, not the array type (section 6.7.3 of C99). */
8003 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8005 struct type *el_type, *inner_array;
8007 base_type = copy_type (base_type);
8008 inner_array = base_type;
8010 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8012 TYPE_TARGET_TYPE (inner_array) =
8013 copy_type (TYPE_TARGET_TYPE (inner_array));
8014 inner_array = TYPE_TARGET_TYPE (inner_array);
8017 el_type = TYPE_TARGET_TYPE (inner_array);
8018 TYPE_TARGET_TYPE (inner_array) =
8019 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8021 return set_die_type (die, base_type, cu);
8024 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8025 return set_die_type (die, cv_type, cu);
8028 static struct type *
8029 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8031 struct type *base_type, *cv_type;
8033 base_type = die_type (die, cu);
8035 /* The die_type call above may have already set the type for this DIE. */
8036 cv_type = get_die_type (die, cu);
8040 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8041 return set_die_type (die, cv_type, cu);
8044 /* Extract all information from a DW_TAG_string_type DIE and add to
8045 the user defined type vector. It isn't really a user defined type,
8046 but it behaves like one, with other DIE's using an AT_user_def_type
8047 attribute to reference it. */
8049 static struct type *
8050 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8052 struct objfile *objfile = cu->objfile;
8053 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8054 struct type *type, *range_type, *index_type, *char_type;
8055 struct attribute *attr;
8056 unsigned int length;
8058 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8061 length = DW_UNSND (attr);
8065 /* Check for the DW_AT_byte_size attribute. */
8066 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8069 length = DW_UNSND (attr);
8077 index_type = objfile_type (objfile)->builtin_int;
8078 range_type = create_range_type (NULL, index_type, 1, length);
8079 char_type = language_string_char_type (cu->language_defn, gdbarch);
8080 type = create_string_type (NULL, char_type, range_type);
8082 return set_die_type (die, type, cu);
8085 /* Handle DIES due to C code like:
8089 int (*funcp)(int a, long l);
8093 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8095 static struct type *
8096 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8098 struct type *type; /* Type that this function returns. */
8099 struct type *ftype; /* Function that returns above type. */
8100 struct attribute *attr;
8102 type = die_type (die, cu);
8104 /* The die_type call above may have already set the type for this DIE. */
8105 ftype = get_die_type (die, cu);
8109 ftype = lookup_function_type (type);
8111 /* All functions in C++, Pascal and Java have prototypes. */
8112 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8113 if ((attr && (DW_UNSND (attr) != 0))
8114 || cu->language == language_cplus
8115 || cu->language == language_java
8116 || cu->language == language_pascal)
8117 TYPE_PROTOTYPED (ftype) = 1;
8118 else if (producer_is_realview (cu->producer))
8119 /* RealView does not emit DW_AT_prototyped. We can not
8120 distinguish prototyped and unprototyped functions; default to
8121 prototyped, since that is more common in modern code (and
8122 RealView warns about unprototyped functions). */
8123 TYPE_PROTOTYPED (ftype) = 1;
8125 /* Store the calling convention in the type if it's available in
8126 the subroutine die. Otherwise set the calling convention to
8127 the default value DW_CC_normal. */
8128 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8130 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8131 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8132 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8134 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8136 /* We need to add the subroutine type to the die immediately so
8137 we don't infinitely recurse when dealing with parameters
8138 declared as the same subroutine type. */
8139 set_die_type (die, ftype, cu);
8141 if (die->child != NULL)
8143 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8144 struct die_info *child_die;
8145 int nparams, iparams;
8147 /* Count the number of parameters.
8148 FIXME: GDB currently ignores vararg functions, but knows about
8149 vararg member functions. */
8151 child_die = die->child;
8152 while (child_die && child_die->tag)
8154 if (child_die->tag == DW_TAG_formal_parameter)
8156 else if (child_die->tag == DW_TAG_unspecified_parameters)
8157 TYPE_VARARGS (ftype) = 1;
8158 child_die = sibling_die (child_die);
8161 /* Allocate storage for parameters and fill them in. */
8162 TYPE_NFIELDS (ftype) = nparams;
8163 TYPE_FIELDS (ftype) = (struct field *)
8164 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8166 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8167 even if we error out during the parameters reading below. */
8168 for (iparams = 0; iparams < nparams; iparams++)
8169 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8172 child_die = die->child;
8173 while (child_die && child_die->tag)
8175 if (child_die->tag == DW_TAG_formal_parameter)
8177 struct type *arg_type;
8179 /* DWARF version 2 has no clean way to discern C++
8180 static and non-static member functions. G++ helps
8181 GDB by marking the first parameter for non-static
8182 member functions (which is the this pointer) as
8183 artificial. We pass this information to
8184 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8186 DWARF version 3 added DW_AT_object_pointer, which GCC
8187 4.5 does not yet generate. */
8188 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8190 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8193 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8195 /* GCC/43521: In java, the formal parameter
8196 "this" is sometimes not marked with DW_AT_artificial. */
8197 if (cu->language == language_java)
8199 const char *name = dwarf2_name (child_die, cu);
8201 if (name && !strcmp (name, "this"))
8202 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8205 arg_type = die_type (child_die, cu);
8207 /* RealView does not mark THIS as const, which the testsuite
8208 expects. GCC marks THIS as const in method definitions,
8209 but not in the class specifications (GCC PR 43053). */
8210 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8211 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8214 struct dwarf2_cu *arg_cu = cu;
8215 const char *name = dwarf2_name (child_die, cu);
8217 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8220 /* If the compiler emits this, use it. */
8221 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8224 else if (name && strcmp (name, "this") == 0)
8225 /* Function definitions will have the argument names. */
8227 else if (name == NULL && iparams == 0)
8228 /* Declarations may not have the names, so like
8229 elsewhere in GDB, assume an artificial first
8230 argument is "this". */
8234 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8238 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8241 child_die = sibling_die (child_die);
8248 static struct type *
8249 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8251 struct objfile *objfile = cu->objfile;
8252 const char *name = NULL;
8253 struct type *this_type;
8255 name = dwarf2_full_name (NULL, die, cu);
8256 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8257 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8258 TYPE_NAME (this_type) = (char *) name;
8259 set_die_type (die, this_type, cu);
8260 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8264 /* Find a representation of a given base type and install
8265 it in the TYPE field of the die. */
8267 static struct type *
8268 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8270 struct objfile *objfile = cu->objfile;
8272 struct attribute *attr;
8273 int encoding = 0, size = 0;
8275 enum type_code code = TYPE_CODE_INT;
8277 struct type *target_type = NULL;
8279 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8282 encoding = DW_UNSND (attr);
8284 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8287 size = DW_UNSND (attr);
8289 name = dwarf2_name (die, cu);
8292 complaint (&symfile_complaints,
8293 _("DW_AT_name missing from DW_TAG_base_type"));
8298 case DW_ATE_address:
8299 /* Turn DW_ATE_address into a void * pointer. */
8300 code = TYPE_CODE_PTR;
8301 type_flags |= TYPE_FLAG_UNSIGNED;
8302 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8304 case DW_ATE_boolean:
8305 code = TYPE_CODE_BOOL;
8306 type_flags |= TYPE_FLAG_UNSIGNED;
8308 case DW_ATE_complex_float:
8309 code = TYPE_CODE_COMPLEX;
8310 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8312 case DW_ATE_decimal_float:
8313 code = TYPE_CODE_DECFLOAT;
8316 code = TYPE_CODE_FLT;
8320 case DW_ATE_unsigned:
8321 type_flags |= TYPE_FLAG_UNSIGNED;
8323 case DW_ATE_signed_char:
8324 if (cu->language == language_ada || cu->language == language_m2
8325 || cu->language == language_pascal)
8326 code = TYPE_CODE_CHAR;
8328 case DW_ATE_unsigned_char:
8329 if (cu->language == language_ada || cu->language == language_m2
8330 || cu->language == language_pascal)
8331 code = TYPE_CODE_CHAR;
8332 type_flags |= TYPE_FLAG_UNSIGNED;
8335 /* We just treat this as an integer and then recognize the
8336 type by name elsewhere. */
8340 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8341 dwarf_type_encoding_name (encoding));
8345 type = init_type (code, size, type_flags, NULL, objfile);
8346 TYPE_NAME (type) = name;
8347 TYPE_TARGET_TYPE (type) = target_type;
8349 if (name && strcmp (name, "char") == 0)
8350 TYPE_NOSIGN (type) = 1;
8352 return set_die_type (die, type, cu);
8355 /* Read the given DW_AT_subrange DIE. */
8357 static struct type *
8358 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8360 struct type *base_type;
8361 struct type *range_type;
8362 struct attribute *attr;
8366 LONGEST negative_mask;
8368 base_type = die_type (die, cu);
8369 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8370 check_typedef (base_type);
8372 /* The die_type call above may have already set the type for this DIE. */
8373 range_type = get_die_type (die, cu);
8377 if (cu->language == language_fortran)
8379 /* FORTRAN implies a lower bound of 1, if not given. */
8383 /* FIXME: For variable sized arrays either of these could be
8384 a variable rather than a constant value. We'll allow it,
8385 but we don't know how to handle it. */
8386 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8388 low = dwarf2_get_attr_constant_value (attr, 0);
8390 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8393 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
8395 /* GCC encodes arrays with unspecified or dynamic length
8396 with a DW_FORM_block1 attribute or a reference attribute.
8397 FIXME: GDB does not yet know how to handle dynamic
8398 arrays properly, treat them as arrays with unspecified
8401 FIXME: jimb/2003-09-22: GDB does not really know
8402 how to handle arrays of unspecified length
8403 either; we just represent them as zero-length
8404 arrays. Choose an appropriate upper bound given
8405 the lower bound we've computed above. */
8409 high = dwarf2_get_attr_constant_value (attr, 1);
8413 attr = dwarf2_attr (die, DW_AT_count, cu);
8416 int count = dwarf2_get_attr_constant_value (attr, 1);
8417 high = low + count - 1;
8421 /* Unspecified array length. */
8426 /* Dwarf-2 specifications explicitly allows to create subrange types
8427 without specifying a base type.
8428 In that case, the base type must be set to the type of
8429 the lower bound, upper bound or count, in that order, if any of these
8430 three attributes references an object that has a type.
8431 If no base type is found, the Dwarf-2 specifications say that
8432 a signed integer type of size equal to the size of an address should
8434 For the following C code: `extern char gdb_int [];'
8435 GCC produces an empty range DIE.
8436 FIXME: muller/2010-05-28: Possible references to object for low bound,
8437 high bound or count are not yet handled by this code. */
8438 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8440 struct objfile *objfile = cu->objfile;
8441 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8442 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8443 struct type *int_type = objfile_type (objfile)->builtin_int;
8445 /* Test "int", "long int", and "long long int" objfile types,
8446 and select the first one having a size above or equal to the
8447 architecture address size. */
8448 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8449 base_type = int_type;
8452 int_type = objfile_type (objfile)->builtin_long;
8453 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8454 base_type = int_type;
8457 int_type = objfile_type (objfile)->builtin_long_long;
8458 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8459 base_type = int_type;
8465 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8466 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8467 low |= negative_mask;
8468 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8469 high |= negative_mask;
8471 range_type = create_range_type (NULL, base_type, low, high);
8473 /* Mark arrays with dynamic length at least as an array of unspecified
8474 length. GDB could check the boundary but before it gets implemented at
8475 least allow accessing the array elements. */
8476 if (attr && attr->form == DW_FORM_block1)
8477 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8479 /* Ada expects an empty array on no boundary attributes. */
8480 if (attr == NULL && cu->language != language_ada)
8481 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8483 name = dwarf2_name (die, cu);
8485 TYPE_NAME (range_type) = name;
8487 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8489 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8491 set_die_type (die, range_type, cu);
8493 /* set_die_type should be already done. */
8494 set_descriptive_type (range_type, die, cu);
8499 static struct type *
8500 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8504 /* For now, we only support the C meaning of an unspecified type: void. */
8506 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8507 TYPE_NAME (type) = dwarf2_name (die, cu);
8509 return set_die_type (die, type, cu);
8512 /* Trivial hash function for die_info: the hash value of a DIE
8513 is its offset in .debug_info for this objfile. */
8516 die_hash (const void *item)
8518 const struct die_info *die = item;
8523 /* Trivial comparison function for die_info structures: two DIEs
8524 are equal if they have the same offset. */
8527 die_eq (const void *item_lhs, const void *item_rhs)
8529 const struct die_info *die_lhs = item_lhs;
8530 const struct die_info *die_rhs = item_rhs;
8532 return die_lhs->offset == die_rhs->offset;
8535 /* Read a whole compilation unit into a linked list of dies. */
8537 static struct die_info *
8538 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8540 struct die_reader_specs reader_specs;
8541 int read_abbrevs = 0;
8542 struct cleanup *back_to = NULL;
8543 struct die_info *die;
8545 if (cu->dwarf2_abbrevs == NULL)
8547 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8548 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8552 gdb_assert (cu->die_hash == NULL);
8554 = htab_create_alloc_ex (cu->header.length / 12,
8558 &cu->comp_unit_obstack,
8559 hashtab_obstack_allocate,
8560 dummy_obstack_deallocate);
8562 init_cu_die_reader (&reader_specs, cu);
8564 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8567 do_cleanups (back_to);
8572 /* Main entry point for reading a DIE and all children.
8573 Read the DIE and dump it if requested. */
8575 static struct die_info *
8576 read_die_and_children (const struct die_reader_specs *reader,
8578 gdb_byte **new_info_ptr,
8579 struct die_info *parent)
8581 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8582 new_info_ptr, parent);
8584 if (dwarf2_die_debug)
8586 fprintf_unfiltered (gdb_stdlog,
8587 "\nRead die from %s of %s:\n",
8588 reader->buffer == dwarf2_per_objfile->info.buffer
8590 : reader->buffer == dwarf2_per_objfile->types.buffer
8592 : "unknown section",
8593 reader->abfd->filename);
8594 dump_die (result, dwarf2_die_debug);
8600 /* Read a single die and all its descendents. Set the die's sibling
8601 field to NULL; set other fields in the die correctly, and set all
8602 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8603 location of the info_ptr after reading all of those dies. PARENT
8604 is the parent of the die in question. */
8606 static struct die_info *
8607 read_die_and_children_1 (const struct die_reader_specs *reader,
8609 gdb_byte **new_info_ptr,
8610 struct die_info *parent)
8612 struct die_info *die;
8616 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8619 *new_info_ptr = cur_ptr;
8622 store_in_ref_table (die, reader->cu);
8625 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8629 *new_info_ptr = cur_ptr;
8632 die->sibling = NULL;
8633 die->parent = parent;
8637 /* Read a die, all of its descendents, and all of its siblings; set
8638 all of the fields of all of the dies correctly. Arguments are as
8639 in read_die_and_children. */
8641 static struct die_info *
8642 read_die_and_siblings (const struct die_reader_specs *reader,
8644 gdb_byte **new_info_ptr,
8645 struct die_info *parent)
8647 struct die_info *first_die, *last_sibling;
8651 first_die = last_sibling = NULL;
8655 struct die_info *die
8656 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8660 *new_info_ptr = cur_ptr;
8667 last_sibling->sibling = die;
8673 /* Read the die from the .debug_info section buffer. Set DIEP to
8674 point to a newly allocated die with its information, except for its
8675 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8676 whether the die has children or not. */
8679 read_full_die (const struct die_reader_specs *reader,
8680 struct die_info **diep, gdb_byte *info_ptr,
8683 unsigned int abbrev_number, bytes_read, i, offset;
8684 struct abbrev_info *abbrev;
8685 struct die_info *die;
8686 struct dwarf2_cu *cu = reader->cu;
8687 bfd *abfd = reader->abfd;
8689 offset = info_ptr - reader->buffer;
8690 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8691 info_ptr += bytes_read;
8699 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8701 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8703 bfd_get_filename (abfd));
8705 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8706 die->offset = offset;
8707 die->tag = abbrev->tag;
8708 die->abbrev = abbrev_number;
8710 die->num_attrs = abbrev->num_attrs;
8712 for (i = 0; i < abbrev->num_attrs; ++i)
8713 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8714 abfd, info_ptr, cu);
8717 *has_children = abbrev->has_children;
8721 /* In DWARF version 2, the description of the debugging information is
8722 stored in a separate .debug_abbrev section. Before we read any
8723 dies from a section we read in all abbreviations and install them
8724 in a hash table. This function also sets flags in CU describing
8725 the data found in the abbrev table. */
8728 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8730 struct comp_unit_head *cu_header = &cu->header;
8731 gdb_byte *abbrev_ptr;
8732 struct abbrev_info *cur_abbrev;
8733 unsigned int abbrev_number, bytes_read, abbrev_name;
8734 unsigned int abbrev_form, hash_number;
8735 struct attr_abbrev *cur_attrs;
8736 unsigned int allocated_attrs;
8738 /* Initialize dwarf2 abbrevs. */
8739 obstack_init (&cu->abbrev_obstack);
8740 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
8742 * sizeof (struct abbrev_info *)));
8743 memset (cu->dwarf2_abbrevs, 0,
8744 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
8746 dwarf2_read_section (dwarf2_per_objfile->objfile,
8747 &dwarf2_per_objfile->abbrev);
8748 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
8749 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8750 abbrev_ptr += bytes_read;
8752 allocated_attrs = ATTR_ALLOC_CHUNK;
8753 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
8755 /* Loop until we reach an abbrev number of 0. */
8756 while (abbrev_number)
8758 cur_abbrev = dwarf_alloc_abbrev (cu);
8760 /* read in abbrev header */
8761 cur_abbrev->number = abbrev_number;
8762 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8763 abbrev_ptr += bytes_read;
8764 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
8767 if (cur_abbrev->tag == DW_TAG_namespace)
8768 cu->has_namespace_info = 1;
8770 /* now read in declarations */
8771 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8772 abbrev_ptr += bytes_read;
8773 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8774 abbrev_ptr += bytes_read;
8777 if (cur_abbrev->num_attrs == allocated_attrs)
8779 allocated_attrs += ATTR_ALLOC_CHUNK;
8781 = xrealloc (cur_attrs, (allocated_attrs
8782 * sizeof (struct attr_abbrev)));
8785 /* Record whether this compilation unit might have
8786 inter-compilation-unit references. If we don't know what form
8787 this attribute will have, then it might potentially be a
8788 DW_FORM_ref_addr, so we conservatively expect inter-CU
8791 if (abbrev_form == DW_FORM_ref_addr
8792 || abbrev_form == DW_FORM_indirect)
8793 cu->has_form_ref_addr = 1;
8795 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
8796 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
8797 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8798 abbrev_ptr += bytes_read;
8799 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8800 abbrev_ptr += bytes_read;
8803 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
8804 (cur_abbrev->num_attrs
8805 * sizeof (struct attr_abbrev)));
8806 memcpy (cur_abbrev->attrs, cur_attrs,
8807 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
8809 hash_number = abbrev_number % ABBREV_HASH_SIZE;
8810 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
8811 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
8813 /* Get next abbreviation.
8814 Under Irix6 the abbreviations for a compilation unit are not
8815 always properly terminated with an abbrev number of 0.
8816 Exit loop if we encounter an abbreviation which we have
8817 already read (which means we are about to read the abbreviations
8818 for the next compile unit) or if the end of the abbreviation
8819 table is reached. */
8820 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
8821 >= dwarf2_per_objfile->abbrev.size)
8823 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8824 abbrev_ptr += bytes_read;
8825 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
8832 /* Release the memory used by the abbrev table for a compilation unit. */
8835 dwarf2_free_abbrev_table (void *ptr_to_cu)
8837 struct dwarf2_cu *cu = ptr_to_cu;
8839 obstack_free (&cu->abbrev_obstack, NULL);
8840 cu->dwarf2_abbrevs = NULL;
8843 /* Lookup an abbrev_info structure in the abbrev hash table. */
8845 static struct abbrev_info *
8846 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
8848 unsigned int hash_number;
8849 struct abbrev_info *abbrev;
8851 hash_number = number % ABBREV_HASH_SIZE;
8852 abbrev = cu->dwarf2_abbrevs[hash_number];
8856 if (abbrev->number == number)
8859 abbrev = abbrev->next;
8864 /* Returns nonzero if TAG represents a type that we might generate a partial
8868 is_type_tag_for_partial (int tag)
8873 /* Some types that would be reasonable to generate partial symbols for,
8874 that we don't at present. */
8875 case DW_TAG_array_type:
8876 case DW_TAG_file_type:
8877 case DW_TAG_ptr_to_member_type:
8878 case DW_TAG_set_type:
8879 case DW_TAG_string_type:
8880 case DW_TAG_subroutine_type:
8882 case DW_TAG_base_type:
8883 case DW_TAG_class_type:
8884 case DW_TAG_interface_type:
8885 case DW_TAG_enumeration_type:
8886 case DW_TAG_structure_type:
8887 case DW_TAG_subrange_type:
8888 case DW_TAG_typedef:
8889 case DW_TAG_union_type:
8896 /* Load all DIEs that are interesting for partial symbols into memory. */
8898 static struct partial_die_info *
8899 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
8900 int building_psymtab, struct dwarf2_cu *cu)
8902 struct partial_die_info *part_die;
8903 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
8904 struct abbrev_info *abbrev;
8905 unsigned int bytes_read;
8906 unsigned int load_all = 0;
8908 int nesting_level = 1;
8913 if (cu->per_cu && cu->per_cu->load_all_dies)
8917 = htab_create_alloc_ex (cu->header.length / 12,
8921 &cu->comp_unit_obstack,
8922 hashtab_obstack_allocate,
8923 dummy_obstack_deallocate);
8925 part_die = obstack_alloc (&cu->comp_unit_obstack,
8926 sizeof (struct partial_die_info));
8930 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8932 /* A NULL abbrev means the end of a series of children. */
8935 if (--nesting_level == 0)
8937 /* PART_DIE was probably the last thing allocated on the
8938 comp_unit_obstack, so we could call obstack_free
8939 here. We don't do that because the waste is small,
8940 and will be cleaned up when we're done with this
8941 compilation unit. This way, we're also more robust
8942 against other users of the comp_unit_obstack. */
8945 info_ptr += bytes_read;
8946 last_die = parent_die;
8947 parent_die = parent_die->die_parent;
8951 /* Check for template arguments. We never save these; if
8952 they're seen, we just mark the parent, and go on our way. */
8953 if (parent_die != NULL
8954 && cu->language == language_cplus
8955 && (abbrev->tag == DW_TAG_template_type_param
8956 || abbrev->tag == DW_TAG_template_value_param))
8958 parent_die->has_template_arguments = 1;
8962 /* We don't need a partial DIE for the template argument. */
8963 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
8969 /* We only recurse into subprograms looking for template arguments.
8970 Skip their other children. */
8972 && cu->language == language_cplus
8973 && parent_die != NULL
8974 && parent_die->tag == DW_TAG_subprogram)
8976 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8980 /* Check whether this DIE is interesting enough to save. Normally
8981 we would not be interested in members here, but there may be
8982 later variables referencing them via DW_AT_specification (for
8985 && !is_type_tag_for_partial (abbrev->tag)
8986 && abbrev->tag != DW_TAG_constant
8987 && abbrev->tag != DW_TAG_enumerator
8988 && abbrev->tag != DW_TAG_subprogram
8989 && abbrev->tag != DW_TAG_lexical_block
8990 && abbrev->tag != DW_TAG_variable
8991 && abbrev->tag != DW_TAG_namespace
8992 && abbrev->tag != DW_TAG_module
8993 && abbrev->tag != DW_TAG_member)
8995 /* Otherwise we skip to the next sibling, if any. */
8996 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9000 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9001 buffer, info_ptr, cu);
9003 /* This two-pass algorithm for processing partial symbols has a
9004 high cost in cache pressure. Thus, handle some simple cases
9005 here which cover the majority of C partial symbols. DIEs
9006 which neither have specification tags in them, nor could have
9007 specification tags elsewhere pointing at them, can simply be
9008 processed and discarded.
9010 This segment is also optional; scan_partial_symbols and
9011 add_partial_symbol will handle these DIEs if we chain
9012 them in normally. When compilers which do not emit large
9013 quantities of duplicate debug information are more common,
9014 this code can probably be removed. */
9016 /* Any complete simple types at the top level (pretty much all
9017 of them, for a language without namespaces), can be processed
9019 if (parent_die == NULL
9020 && part_die->has_specification == 0
9021 && part_die->is_declaration == 0
9022 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9023 || part_die->tag == DW_TAG_base_type
9024 || part_die->tag == DW_TAG_subrange_type))
9026 if (building_psymtab && part_die->name != NULL)
9027 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9028 VAR_DOMAIN, LOC_TYPEDEF,
9029 &cu->objfile->static_psymbols,
9030 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9031 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9035 /* The exception for DW_TAG_typedef with has_children above is
9036 a workaround of GCC PR debug/47510. In the case of this complaint
9037 type_name_no_tag_or_error will error on such types later.
9039 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9040 it could not find the child DIEs referenced later, this is checked
9041 above. In correct DWARF DW_TAG_typedef should have no children. */
9043 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9044 complaint (&symfile_complaints,
9045 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9046 "- DIE at 0x%x [in module %s]"),
9047 part_die->offset, cu->objfile->name);
9049 /* If we're at the second level, and we're an enumerator, and
9050 our parent has no specification (meaning possibly lives in a
9051 namespace elsewhere), then we can add the partial symbol now
9052 instead of queueing it. */
9053 if (part_die->tag == DW_TAG_enumerator
9054 && parent_die != NULL
9055 && parent_die->die_parent == NULL
9056 && parent_die->tag == DW_TAG_enumeration_type
9057 && parent_die->has_specification == 0)
9059 if (part_die->name == NULL)
9060 complaint (&symfile_complaints,
9061 _("malformed enumerator DIE ignored"));
9062 else if (building_psymtab)
9063 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9064 VAR_DOMAIN, LOC_CONST,
9065 (cu->language == language_cplus
9066 || cu->language == language_java)
9067 ? &cu->objfile->global_psymbols
9068 : &cu->objfile->static_psymbols,
9069 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9071 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9075 /* We'll save this DIE so link it in. */
9076 part_die->die_parent = parent_die;
9077 part_die->die_sibling = NULL;
9078 part_die->die_child = NULL;
9080 if (last_die && last_die == parent_die)
9081 last_die->die_child = part_die;
9083 last_die->die_sibling = part_die;
9085 last_die = part_die;
9087 if (first_die == NULL)
9088 first_die = part_die;
9090 /* Maybe add the DIE to the hash table. Not all DIEs that we
9091 find interesting need to be in the hash table, because we
9092 also have the parent/sibling/child chains; only those that we
9093 might refer to by offset later during partial symbol reading.
9095 For now this means things that might have be the target of a
9096 DW_AT_specification, DW_AT_abstract_origin, or
9097 DW_AT_extension. DW_AT_extension will refer only to
9098 namespaces; DW_AT_abstract_origin refers to functions (and
9099 many things under the function DIE, but we do not recurse
9100 into function DIEs during partial symbol reading) and
9101 possibly variables as well; DW_AT_specification refers to
9102 declarations. Declarations ought to have the DW_AT_declaration
9103 flag. It happens that GCC forgets to put it in sometimes, but
9104 only for functions, not for types.
9106 Adding more things than necessary to the hash table is harmless
9107 except for the performance cost. Adding too few will result in
9108 wasted time in find_partial_die, when we reread the compilation
9109 unit with load_all_dies set. */
9112 || abbrev->tag == DW_TAG_constant
9113 || abbrev->tag == DW_TAG_subprogram
9114 || abbrev->tag == DW_TAG_variable
9115 || abbrev->tag == DW_TAG_namespace
9116 || part_die->is_declaration)
9120 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9121 part_die->offset, INSERT);
9125 part_die = obstack_alloc (&cu->comp_unit_obstack,
9126 sizeof (struct partial_die_info));
9128 /* For some DIEs we want to follow their children (if any). For C
9129 we have no reason to follow the children of structures; for other
9130 languages we have to, so that we can get at method physnames
9131 to infer fully qualified class names, for DW_AT_specification,
9132 and for C++ template arguments. For C++, we also look one level
9133 inside functions to find template arguments (if the name of the
9134 function does not already contain the template arguments).
9136 For Ada, we need to scan the children of subprograms and lexical
9137 blocks as well because Ada allows the definition of nested
9138 entities that could be interesting for the debugger, such as
9139 nested subprograms for instance. */
9140 if (last_die->has_children
9142 || last_die->tag == DW_TAG_namespace
9143 || last_die->tag == DW_TAG_module
9144 || last_die->tag == DW_TAG_enumeration_type
9145 || (cu->language == language_cplus
9146 && last_die->tag == DW_TAG_subprogram
9147 && (last_die->name == NULL
9148 || strchr (last_die->name, '<') == NULL))
9149 || (cu->language != language_c
9150 && (last_die->tag == DW_TAG_class_type
9151 || last_die->tag == DW_TAG_interface_type
9152 || last_die->tag == DW_TAG_structure_type
9153 || last_die->tag == DW_TAG_union_type))
9154 || (cu->language == language_ada
9155 && (last_die->tag == DW_TAG_subprogram
9156 || last_die->tag == DW_TAG_lexical_block))))
9159 parent_die = last_die;
9163 /* Otherwise we skip to the next sibling, if any. */
9164 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9166 /* Back to the top, do it again. */
9170 /* Read a minimal amount of information into the minimal die structure. */
9173 read_partial_die (struct partial_die_info *part_die,
9174 struct abbrev_info *abbrev,
9175 unsigned int abbrev_len, bfd *abfd,
9176 gdb_byte *buffer, gdb_byte *info_ptr,
9177 struct dwarf2_cu *cu)
9180 struct attribute attr;
9181 int has_low_pc_attr = 0;
9182 int has_high_pc_attr = 0;
9184 memset (part_die, 0, sizeof (struct partial_die_info));
9186 part_die->offset = info_ptr - buffer;
9188 info_ptr += abbrev_len;
9193 part_die->tag = abbrev->tag;
9194 part_die->has_children = abbrev->has_children;
9196 for (i = 0; i < abbrev->num_attrs; ++i)
9198 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9200 /* Store the data if it is of an attribute we want to keep in a
9201 partial symbol table. */
9205 switch (part_die->tag)
9207 case DW_TAG_compile_unit:
9208 case DW_TAG_type_unit:
9209 /* Compilation units have a DW_AT_name that is a filename, not
9210 a source language identifier. */
9211 case DW_TAG_enumeration_type:
9212 case DW_TAG_enumerator:
9213 /* These tags always have simple identifiers already; no need
9214 to canonicalize them. */
9215 part_die->name = DW_STRING (&attr);
9219 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9220 &cu->objfile->objfile_obstack);
9224 case DW_AT_linkage_name:
9225 case DW_AT_MIPS_linkage_name:
9226 /* Note that both forms of linkage name might appear. We
9227 assume they will be the same, and we only store the last
9229 if (cu->language == language_ada)
9230 part_die->name = DW_STRING (&attr);
9231 part_die->linkage_name = DW_STRING (&attr);
9234 has_low_pc_attr = 1;
9235 part_die->lowpc = DW_ADDR (&attr);
9238 has_high_pc_attr = 1;
9239 part_die->highpc = DW_ADDR (&attr);
9241 case DW_AT_location:
9242 /* Support the .debug_loc offsets. */
9243 if (attr_form_is_block (&attr))
9245 part_die->locdesc = DW_BLOCK (&attr);
9247 else if (attr_form_is_section_offset (&attr))
9249 dwarf2_complex_location_expr_complaint ();
9253 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9254 "partial symbol information");
9257 case DW_AT_external:
9258 part_die->is_external = DW_UNSND (&attr);
9260 case DW_AT_declaration:
9261 part_die->is_declaration = DW_UNSND (&attr);
9264 part_die->has_type = 1;
9266 case DW_AT_abstract_origin:
9267 case DW_AT_specification:
9268 case DW_AT_extension:
9269 part_die->has_specification = 1;
9270 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9273 /* Ignore absolute siblings, they might point outside of
9274 the current compile unit. */
9275 if (attr.form == DW_FORM_ref_addr)
9276 complaint (&symfile_complaints,
9277 _("ignoring absolute DW_AT_sibling"));
9279 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9281 case DW_AT_byte_size:
9282 part_die->has_byte_size = 1;
9284 case DW_AT_calling_convention:
9285 /* DWARF doesn't provide a way to identify a program's source-level
9286 entry point. DW_AT_calling_convention attributes are only meant
9287 to describe functions' calling conventions.
9289 However, because it's a necessary piece of information in
9290 Fortran, and because DW_CC_program is the only piece of debugging
9291 information whose definition refers to a 'main program' at all,
9292 several compilers have begun marking Fortran main programs with
9293 DW_CC_program --- even when those functions use the standard
9294 calling conventions.
9296 So until DWARF specifies a way to provide this information and
9297 compilers pick up the new representation, we'll support this
9299 if (DW_UNSND (&attr) == DW_CC_program
9300 && cu->language == language_fortran)
9302 set_main_name (part_die->name);
9304 /* As this DIE has a static linkage the name would be difficult
9305 to look up later. */
9306 language_of_main = language_fortran;
9314 if (has_low_pc_attr && has_high_pc_attr)
9316 /* When using the GNU linker, .gnu.linkonce. sections are used to
9317 eliminate duplicate copies of functions and vtables and such.
9318 The linker will arbitrarily choose one and discard the others.
9319 The AT_*_pc values for such functions refer to local labels in
9320 these sections. If the section from that file was discarded, the
9321 labels are not in the output, so the relocs get a value of 0.
9322 If this is a discarded function, mark the pc bounds as invalid,
9323 so that GDB will ignore it. */
9324 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9326 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9328 complaint (&symfile_complaints,
9329 _("DW_AT_low_pc %s is zero "
9330 "for DIE at 0x%x [in module %s]"),
9331 paddress (gdbarch, part_die->lowpc),
9332 part_die->offset, cu->objfile->name);
9334 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9335 else if (part_die->lowpc >= part_die->highpc)
9337 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9339 complaint (&symfile_complaints,
9340 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9341 "for DIE at 0x%x [in module %s]"),
9342 paddress (gdbarch, part_die->lowpc),
9343 paddress (gdbarch, part_die->highpc),
9344 part_die->offset, cu->objfile->name);
9347 part_die->has_pc_info = 1;
9353 /* Find a cached partial DIE at OFFSET in CU. */
9355 static struct partial_die_info *
9356 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9358 struct partial_die_info *lookup_die = NULL;
9359 struct partial_die_info part_die;
9361 part_die.offset = offset;
9362 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9367 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9368 except in the case of .debug_types DIEs which do not reference
9369 outside their CU (they do however referencing other types via
9370 DW_FORM_ref_sig8). */
9372 static struct partial_die_info *
9373 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9375 struct dwarf2_per_cu_data *per_cu = NULL;
9376 struct partial_die_info *pd = NULL;
9378 if (cu->per_cu->from_debug_types)
9380 pd = find_partial_die_in_comp_unit (offset, cu);
9386 if (offset_in_cu_p (&cu->header, offset))
9388 pd = find_partial_die_in_comp_unit (offset, cu);
9393 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9395 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9396 load_partial_comp_unit (per_cu, cu->objfile);
9398 per_cu->cu->last_used = 0;
9399 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9401 if (pd == NULL && per_cu->load_all_dies == 0)
9403 struct cleanup *back_to;
9404 struct partial_die_info comp_unit_die;
9405 struct abbrev_info *abbrev;
9406 unsigned int bytes_read;
9409 per_cu->load_all_dies = 1;
9411 /* Re-read the DIEs. */
9412 back_to = make_cleanup (null_cleanup, 0);
9413 if (per_cu->cu->dwarf2_abbrevs == NULL)
9415 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
9416 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9418 info_ptr = (dwarf2_per_objfile->info.buffer
9419 + per_cu->cu->header.offset
9420 + per_cu->cu->header.first_die_offset);
9421 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9422 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9423 per_cu->cu->objfile->obfd,
9424 dwarf2_per_objfile->info.buffer, info_ptr,
9426 if (comp_unit_die.has_children)
9427 load_partial_dies (per_cu->cu->objfile->obfd,
9428 dwarf2_per_objfile->info.buffer, info_ptr,
9430 do_cleanups (back_to);
9432 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9438 internal_error (__FILE__, __LINE__,
9439 _("could not find partial DIE 0x%x "
9440 "in cache [from module %s]\n"),
9441 offset, bfd_get_filename (cu->objfile->obfd));
9445 /* See if we can figure out if the class lives in a namespace. We do
9446 this by looking for a member function; its demangled name will
9447 contain namespace info, if there is any. */
9450 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9451 struct dwarf2_cu *cu)
9453 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9454 what template types look like, because the demangler
9455 frequently doesn't give the same name as the debug info. We
9456 could fix this by only using the demangled name to get the
9457 prefix (but see comment in read_structure_type). */
9459 struct partial_die_info *real_pdi;
9460 struct partial_die_info *child_pdi;
9462 /* If this DIE (this DIE's specification, if any) has a parent, then
9463 we should not do this. We'll prepend the parent's fully qualified
9464 name when we create the partial symbol. */
9466 real_pdi = struct_pdi;
9467 while (real_pdi->has_specification)
9468 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9470 if (real_pdi->die_parent != NULL)
9473 for (child_pdi = struct_pdi->die_child;
9475 child_pdi = child_pdi->die_sibling)
9477 if (child_pdi->tag == DW_TAG_subprogram
9478 && child_pdi->linkage_name != NULL)
9480 char *actual_class_name
9481 = language_class_name_from_physname (cu->language_defn,
9482 child_pdi->linkage_name);
9483 if (actual_class_name != NULL)
9486 = obsavestring (actual_class_name,
9487 strlen (actual_class_name),
9488 &cu->objfile->objfile_obstack);
9489 xfree (actual_class_name);
9496 /* Adjust PART_DIE before generating a symbol for it. This function
9497 may set the is_external flag or change the DIE's name. */
9500 fixup_partial_die (struct partial_die_info *part_die,
9501 struct dwarf2_cu *cu)
9503 /* Once we've fixed up a die, there's no point in doing so again.
9504 This also avoids a memory leak if we were to call
9505 guess_partial_die_structure_name multiple times. */
9506 if (part_die->fixup_called)
9509 /* If we found a reference attribute and the DIE has no name, try
9510 to find a name in the referred to DIE. */
9512 if (part_die->name == NULL && part_die->has_specification)
9514 struct partial_die_info *spec_die;
9516 spec_die = find_partial_die (part_die->spec_offset, cu);
9518 fixup_partial_die (spec_die, cu);
9522 part_die->name = spec_die->name;
9524 /* Copy DW_AT_external attribute if it is set. */
9525 if (spec_die->is_external)
9526 part_die->is_external = spec_die->is_external;
9530 /* Set default names for some unnamed DIEs. */
9532 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
9533 part_die->name = "(anonymous namespace)";
9535 /* If there is no parent die to provide a namespace, and there are
9536 children, see if we can determine the namespace from their linkage
9538 NOTE: We need to do this even if cu->has_namespace_info != 0.
9539 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9540 if (cu->language == language_cplus
9541 && dwarf2_per_objfile->types.asection != NULL
9542 && part_die->die_parent == NULL
9543 && part_die->has_children
9544 && (part_die->tag == DW_TAG_class_type
9545 || part_die->tag == DW_TAG_structure_type
9546 || part_die->tag == DW_TAG_union_type))
9547 guess_partial_die_structure_name (part_die, cu);
9549 /* GCC might emit a nameless struct or union that has a linkage
9550 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9551 if (part_die->name == NULL
9552 && (part_die->tag == DW_TAG_structure_type
9553 || part_die->tag == DW_TAG_union_type
9554 || part_die->tag == DW_TAG_class_type)
9555 && part_die->linkage_name != NULL)
9559 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
9562 part_die->name = obsavestring (demangled, strlen (demangled),
9563 &cu->objfile->objfile_obstack);
9568 part_die->fixup_called = 1;
9571 /* Read an attribute value described by an attribute form. */
9574 read_attribute_value (struct attribute *attr, unsigned form,
9575 bfd *abfd, gdb_byte *info_ptr,
9576 struct dwarf2_cu *cu)
9578 struct comp_unit_head *cu_header = &cu->header;
9579 unsigned int bytes_read;
9580 struct dwarf_block *blk;
9585 case DW_FORM_ref_addr:
9586 if (cu->header.version == 2)
9587 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9589 DW_ADDR (attr) = read_offset (abfd, info_ptr,
9590 &cu->header, &bytes_read);
9591 info_ptr += bytes_read;
9594 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9595 info_ptr += bytes_read;
9597 case DW_FORM_block2:
9598 blk = dwarf_alloc_block (cu);
9599 blk->size = read_2_bytes (abfd, info_ptr);
9601 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9602 info_ptr += blk->size;
9603 DW_BLOCK (attr) = blk;
9605 case DW_FORM_block4:
9606 blk = dwarf_alloc_block (cu);
9607 blk->size = read_4_bytes (abfd, info_ptr);
9609 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9610 info_ptr += blk->size;
9611 DW_BLOCK (attr) = blk;
9614 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9618 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9622 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9625 case DW_FORM_sec_offset:
9626 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9627 info_ptr += bytes_read;
9629 case DW_FORM_string:
9630 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9631 DW_STRING_IS_CANONICAL (attr) = 0;
9632 info_ptr += bytes_read;
9635 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9637 DW_STRING_IS_CANONICAL (attr) = 0;
9638 info_ptr += bytes_read;
9640 case DW_FORM_exprloc:
9642 blk = dwarf_alloc_block (cu);
9643 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9644 info_ptr += bytes_read;
9645 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9646 info_ptr += blk->size;
9647 DW_BLOCK (attr) = blk;
9649 case DW_FORM_block1:
9650 blk = dwarf_alloc_block (cu);
9651 blk->size = read_1_byte (abfd, info_ptr);
9653 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9654 info_ptr += blk->size;
9655 DW_BLOCK (attr) = blk;
9658 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9662 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9665 case DW_FORM_flag_present:
9666 DW_UNSND (attr) = 1;
9669 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9670 info_ptr += bytes_read;
9673 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9674 info_ptr += bytes_read;
9677 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9681 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9685 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9689 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9692 case DW_FORM_ref_sig8:
9693 /* Convert the signature to something we can record in DW_UNSND
9695 NOTE: This is NULL if the type wasn't found. */
9696 DW_SIGNATURED_TYPE (attr) =
9697 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9700 case DW_FORM_ref_udata:
9701 DW_ADDR (attr) = (cu->header.offset
9702 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9703 info_ptr += bytes_read;
9705 case DW_FORM_indirect:
9706 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9707 info_ptr += bytes_read;
9708 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9711 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9712 dwarf_form_name (form),
9713 bfd_get_filename (abfd));
9716 /* We have seen instances where the compiler tried to emit a byte
9717 size attribute of -1 which ended up being encoded as an unsigned
9718 0xffffffff. Although 0xffffffff is technically a valid size value,
9719 an object of this size seems pretty unlikely so we can relatively
9720 safely treat these cases as if the size attribute was invalid and
9721 treat them as zero by default. */
9722 if (attr->name == DW_AT_byte_size
9723 && form == DW_FORM_data4
9724 && DW_UNSND (attr) >= 0xffffffff)
9727 (&symfile_complaints,
9728 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9729 hex_string (DW_UNSND (attr)));
9730 DW_UNSND (attr) = 0;
9736 /* Read an attribute described by an abbreviated attribute. */
9739 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
9740 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
9742 attr->name = abbrev->name;
9743 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
9746 /* Read dwarf information from a buffer. */
9749 read_1_byte (bfd *abfd, gdb_byte *buf)
9751 return bfd_get_8 (abfd, buf);
9755 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
9757 return bfd_get_signed_8 (abfd, buf);
9761 read_2_bytes (bfd *abfd, gdb_byte *buf)
9763 return bfd_get_16 (abfd, buf);
9767 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
9769 return bfd_get_signed_16 (abfd, buf);
9773 read_4_bytes (bfd *abfd, gdb_byte *buf)
9775 return bfd_get_32 (abfd, buf);
9779 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
9781 return bfd_get_signed_32 (abfd, buf);
9785 read_8_bytes (bfd *abfd, gdb_byte *buf)
9787 return bfd_get_64 (abfd, buf);
9791 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
9792 unsigned int *bytes_read)
9794 struct comp_unit_head *cu_header = &cu->header;
9795 CORE_ADDR retval = 0;
9797 if (cu_header->signed_addr_p)
9799 switch (cu_header->addr_size)
9802 retval = bfd_get_signed_16 (abfd, buf);
9805 retval = bfd_get_signed_32 (abfd, buf);
9808 retval = bfd_get_signed_64 (abfd, buf);
9811 internal_error (__FILE__, __LINE__,
9812 _("read_address: bad switch, signed [in module %s]"),
9813 bfd_get_filename (abfd));
9818 switch (cu_header->addr_size)
9821 retval = bfd_get_16 (abfd, buf);
9824 retval = bfd_get_32 (abfd, buf);
9827 retval = bfd_get_64 (abfd, buf);
9830 internal_error (__FILE__, __LINE__,
9831 _("read_address: bad switch, "
9832 "unsigned [in module %s]"),
9833 bfd_get_filename (abfd));
9837 *bytes_read = cu_header->addr_size;
9841 /* Read the initial length from a section. The (draft) DWARF 3
9842 specification allows the initial length to take up either 4 bytes
9843 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9844 bytes describe the length and all offsets will be 8 bytes in length
9847 An older, non-standard 64-bit format is also handled by this
9848 function. The older format in question stores the initial length
9849 as an 8-byte quantity without an escape value. Lengths greater
9850 than 2^32 aren't very common which means that the initial 4 bytes
9851 is almost always zero. Since a length value of zero doesn't make
9852 sense for the 32-bit format, this initial zero can be considered to
9853 be an escape value which indicates the presence of the older 64-bit
9854 format. As written, the code can't detect (old format) lengths
9855 greater than 4GB. If it becomes necessary to handle lengths
9856 somewhat larger than 4GB, we could allow other small values (such
9857 as the non-sensical values of 1, 2, and 3) to also be used as
9858 escape values indicating the presence of the old format.
9860 The value returned via bytes_read should be used to increment the
9861 relevant pointer after calling read_initial_length().
9863 [ Note: read_initial_length() and read_offset() are based on the
9864 document entitled "DWARF Debugging Information Format", revision
9865 3, draft 8, dated November 19, 2001. This document was obtained
9868 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9870 This document is only a draft and is subject to change. (So beware.)
9872 Details regarding the older, non-standard 64-bit format were
9873 determined empirically by examining 64-bit ELF files produced by
9874 the SGI toolchain on an IRIX 6.5 machine.
9876 - Kevin, July 16, 2002
9880 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
9882 LONGEST length = bfd_get_32 (abfd, buf);
9884 if (length == 0xffffffff)
9886 length = bfd_get_64 (abfd, buf + 4);
9889 else if (length == 0)
9891 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9892 length = bfd_get_64 (abfd, buf);
9903 /* Cover function for read_initial_length.
9904 Returns the length of the object at BUF, and stores the size of the
9905 initial length in *BYTES_READ and stores the size that offsets will be in
9907 If the initial length size is not equivalent to that specified in
9908 CU_HEADER then issue a complaint.
9909 This is useful when reading non-comp-unit headers. */
9912 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
9913 const struct comp_unit_head *cu_header,
9914 unsigned int *bytes_read,
9915 unsigned int *offset_size)
9917 LONGEST length = read_initial_length (abfd, buf, bytes_read);
9919 gdb_assert (cu_header->initial_length_size == 4
9920 || cu_header->initial_length_size == 8
9921 || cu_header->initial_length_size == 12);
9923 if (cu_header->initial_length_size != *bytes_read)
9924 complaint (&symfile_complaints,
9925 _("intermixed 32-bit and 64-bit DWARF sections"));
9927 *offset_size = (*bytes_read == 4) ? 4 : 8;
9931 /* Read an offset from the data stream. The size of the offset is
9932 given by cu_header->offset_size. */
9935 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
9936 unsigned int *bytes_read)
9938 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
9940 *bytes_read = cu_header->offset_size;
9944 /* Read an offset from the data stream. */
9947 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
9951 switch (offset_size)
9954 retval = bfd_get_32 (abfd, buf);
9957 retval = bfd_get_64 (abfd, buf);
9960 internal_error (__FILE__, __LINE__,
9961 _("read_offset_1: bad switch [in module %s]"),
9962 bfd_get_filename (abfd));
9969 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
9971 /* If the size of a host char is 8 bits, we can return a pointer
9972 to the buffer, otherwise we have to copy the data to a buffer
9973 allocated on the temporary obstack. */
9974 gdb_assert (HOST_CHAR_BIT == 8);
9979 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9981 /* If the size of a host char is 8 bits, we can return a pointer
9982 to the string, otherwise we have to copy the string to a buffer
9983 allocated on the temporary obstack. */
9984 gdb_assert (HOST_CHAR_BIT == 8);
9987 *bytes_read_ptr = 1;
9990 *bytes_read_ptr = strlen ((char *) buf) + 1;
9991 return (char *) buf;
9995 read_indirect_string (bfd *abfd, gdb_byte *buf,
9996 const struct comp_unit_head *cu_header,
9997 unsigned int *bytes_read_ptr)
9999 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10001 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10002 if (dwarf2_per_objfile->str.buffer == NULL)
10004 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10005 bfd_get_filename (abfd));
10008 if (str_offset >= dwarf2_per_objfile->str.size)
10010 error (_("DW_FORM_strp pointing outside of "
10011 ".debug_str section [in module %s]"),
10012 bfd_get_filename (abfd));
10015 gdb_assert (HOST_CHAR_BIT == 8);
10016 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10018 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10021 static unsigned long
10022 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10024 unsigned long result;
10025 unsigned int num_read;
10027 unsigned char byte;
10035 byte = bfd_get_8 (abfd, buf);
10038 result |= ((unsigned long)(byte & 127) << shift);
10039 if ((byte & 128) == 0)
10045 *bytes_read_ptr = num_read;
10050 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10053 int i, shift, num_read;
10054 unsigned char byte;
10062 byte = bfd_get_8 (abfd, buf);
10065 result |= ((long)(byte & 127) << shift);
10067 if ((byte & 128) == 0)
10072 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10073 result |= -(((long)1) << shift);
10074 *bytes_read_ptr = num_read;
10078 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10081 skip_leb128 (bfd *abfd, gdb_byte *buf)
10087 byte = bfd_get_8 (abfd, buf);
10089 if ((byte & 128) == 0)
10095 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10102 cu->language = language_c;
10104 case DW_LANG_C_plus_plus:
10105 cu->language = language_cplus;
10108 cu->language = language_d;
10110 case DW_LANG_Fortran77:
10111 case DW_LANG_Fortran90:
10112 case DW_LANG_Fortran95:
10113 cu->language = language_fortran;
10115 case DW_LANG_Mips_Assembler:
10116 cu->language = language_asm;
10119 cu->language = language_java;
10121 case DW_LANG_Ada83:
10122 case DW_LANG_Ada95:
10123 cu->language = language_ada;
10125 case DW_LANG_Modula2:
10126 cu->language = language_m2;
10128 case DW_LANG_Pascal83:
10129 cu->language = language_pascal;
10132 cu->language = language_objc;
10134 case DW_LANG_Cobol74:
10135 case DW_LANG_Cobol85:
10137 cu->language = language_minimal;
10140 cu->language_defn = language_def (cu->language);
10143 /* Return the named attribute or NULL if not there. */
10145 static struct attribute *
10146 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10149 struct attribute *spec = NULL;
10151 for (i = 0; i < die->num_attrs; ++i)
10153 if (die->attrs[i].name == name)
10154 return &die->attrs[i];
10155 if (die->attrs[i].name == DW_AT_specification
10156 || die->attrs[i].name == DW_AT_abstract_origin)
10157 spec = &die->attrs[i];
10162 die = follow_die_ref (die, spec, &cu);
10163 return dwarf2_attr (die, name, cu);
10169 /* Return the named attribute or NULL if not there,
10170 but do not follow DW_AT_specification, etc.
10171 This is for use in contexts where we're reading .debug_types dies.
10172 Following DW_AT_specification, DW_AT_abstract_origin will take us
10173 back up the chain, and we want to go down. */
10175 static struct attribute *
10176 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10177 struct dwarf2_cu *cu)
10181 for (i = 0; i < die->num_attrs; ++i)
10182 if (die->attrs[i].name == name)
10183 return &die->attrs[i];
10188 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10189 and holds a non-zero value. This function should only be used for
10190 DW_FORM_flag or DW_FORM_flag_present attributes. */
10193 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10195 struct attribute *attr = dwarf2_attr (die, name, cu);
10197 return (attr && DW_UNSND (attr));
10201 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10203 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10204 which value is non-zero. However, we have to be careful with
10205 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10206 (via dwarf2_flag_true_p) follows this attribute. So we may
10207 end up accidently finding a declaration attribute that belongs
10208 to a different DIE referenced by the specification attribute,
10209 even though the given DIE does not have a declaration attribute. */
10210 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10211 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10214 /* Return the die giving the specification for DIE, if there is
10215 one. *SPEC_CU is the CU containing DIE on input, and the CU
10216 containing the return value on output. If there is no
10217 specification, but there is an abstract origin, that is
10220 static struct die_info *
10221 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10223 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10226 if (spec_attr == NULL)
10227 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10229 if (spec_attr == NULL)
10232 return follow_die_ref (die, spec_attr, spec_cu);
10235 /* Free the line_header structure *LH, and any arrays and strings it
10237 NOTE: This is also used as a "cleanup" function. */
10240 free_line_header (struct line_header *lh)
10242 if (lh->standard_opcode_lengths)
10243 xfree (lh->standard_opcode_lengths);
10245 /* Remember that all the lh->file_names[i].name pointers are
10246 pointers into debug_line_buffer, and don't need to be freed. */
10247 if (lh->file_names)
10248 xfree (lh->file_names);
10250 /* Similarly for the include directory names. */
10251 if (lh->include_dirs)
10252 xfree (lh->include_dirs);
10257 /* Add an entry to LH's include directory table. */
10260 add_include_dir (struct line_header *lh, char *include_dir)
10262 /* Grow the array if necessary. */
10263 if (lh->include_dirs_size == 0)
10265 lh->include_dirs_size = 1; /* for testing */
10266 lh->include_dirs = xmalloc (lh->include_dirs_size
10267 * sizeof (*lh->include_dirs));
10269 else if (lh->num_include_dirs >= lh->include_dirs_size)
10271 lh->include_dirs_size *= 2;
10272 lh->include_dirs = xrealloc (lh->include_dirs,
10273 (lh->include_dirs_size
10274 * sizeof (*lh->include_dirs)));
10277 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10280 /* Add an entry to LH's file name table. */
10283 add_file_name (struct line_header *lh,
10285 unsigned int dir_index,
10286 unsigned int mod_time,
10287 unsigned int length)
10289 struct file_entry *fe;
10291 /* Grow the array if necessary. */
10292 if (lh->file_names_size == 0)
10294 lh->file_names_size = 1; /* for testing */
10295 lh->file_names = xmalloc (lh->file_names_size
10296 * sizeof (*lh->file_names));
10298 else if (lh->num_file_names >= lh->file_names_size)
10300 lh->file_names_size *= 2;
10301 lh->file_names = xrealloc (lh->file_names,
10302 (lh->file_names_size
10303 * sizeof (*lh->file_names)));
10306 fe = &lh->file_names[lh->num_file_names++];
10308 fe->dir_index = dir_index;
10309 fe->mod_time = mod_time;
10310 fe->length = length;
10311 fe->included_p = 0;
10315 /* Read the statement program header starting at OFFSET in
10316 .debug_line, according to the endianness of ABFD. Return a pointer
10317 to a struct line_header, allocated using xmalloc.
10319 NOTE: the strings in the include directory and file name tables of
10320 the returned object point into debug_line_buffer, and must not be
10323 static struct line_header *
10324 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10325 struct dwarf2_cu *cu)
10327 struct cleanup *back_to;
10328 struct line_header *lh;
10329 gdb_byte *line_ptr;
10330 unsigned int bytes_read, offset_size;
10332 char *cur_dir, *cur_file;
10334 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10335 if (dwarf2_per_objfile->line.buffer == NULL)
10337 complaint (&symfile_complaints, _("missing .debug_line section"));
10341 /* Make sure that at least there's room for the total_length field.
10342 That could be 12 bytes long, but we're just going to fudge that. */
10343 if (offset + 4 >= dwarf2_per_objfile->line.size)
10345 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10349 lh = xmalloc (sizeof (*lh));
10350 memset (lh, 0, sizeof (*lh));
10351 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10354 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10356 /* Read in the header. */
10358 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10359 &bytes_read, &offset_size);
10360 line_ptr += bytes_read;
10361 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10362 + dwarf2_per_objfile->line.size))
10364 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10367 lh->statement_program_end = line_ptr + lh->total_length;
10368 lh->version = read_2_bytes (abfd, line_ptr);
10370 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10371 line_ptr += offset_size;
10372 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10374 if (lh->version >= 4)
10376 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10380 lh->maximum_ops_per_instruction = 1;
10382 if (lh->maximum_ops_per_instruction == 0)
10384 lh->maximum_ops_per_instruction = 1;
10385 complaint (&symfile_complaints,
10386 _("invalid maximum_ops_per_instruction "
10387 "in `.debug_line' section"));
10390 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10392 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10394 lh->line_range = read_1_byte (abfd, line_ptr);
10396 lh->opcode_base = read_1_byte (abfd, line_ptr);
10398 lh->standard_opcode_lengths
10399 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10401 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10402 for (i = 1; i < lh->opcode_base; ++i)
10404 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10408 /* Read directory table. */
10409 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10411 line_ptr += bytes_read;
10412 add_include_dir (lh, cur_dir);
10414 line_ptr += bytes_read;
10416 /* Read file name table. */
10417 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10419 unsigned int dir_index, mod_time, length;
10421 line_ptr += bytes_read;
10422 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10423 line_ptr += bytes_read;
10424 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10425 line_ptr += bytes_read;
10426 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10427 line_ptr += bytes_read;
10429 add_file_name (lh, cur_file, dir_index, mod_time, length);
10431 line_ptr += bytes_read;
10432 lh->statement_program_start = line_ptr;
10434 if (line_ptr > (dwarf2_per_objfile->line.buffer
10435 + dwarf2_per_objfile->line.size))
10436 complaint (&symfile_complaints,
10437 _("line number info header doesn't "
10438 "fit in `.debug_line' section"));
10440 discard_cleanups (back_to);
10444 /* This function exists to work around a bug in certain compilers
10445 (particularly GCC 2.95), in which the first line number marker of a
10446 function does not show up until after the prologue, right before
10447 the second line number marker. This function shifts ADDRESS down
10448 to the beginning of the function if necessary, and is called on
10449 addresses passed to record_line. */
10452 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
10454 struct function_range *fn;
10456 /* Find the function_range containing address. */
10460 if (!cu->cached_fn)
10461 cu->cached_fn = cu->first_fn;
10463 fn = cu->cached_fn;
10465 if (fn->lowpc <= address && fn->highpc > address)
10471 while (fn && fn != cu->cached_fn)
10472 if (fn->lowpc <= address && fn->highpc > address)
10482 if (address != fn->lowpc)
10483 complaint (&symfile_complaints,
10484 _("misplaced first line number at 0x%lx for '%s'"),
10485 (unsigned long) address, fn->name);
10490 /* Subroutine of dwarf_decode_lines to simplify it.
10491 Return the file name of the psymtab for included file FILE_INDEX
10492 in line header LH of PST.
10493 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10494 If space for the result is malloc'd, it will be freed by a cleanup.
10495 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10498 psymtab_include_file_name (const struct line_header *lh, int file_index,
10499 const struct partial_symtab *pst,
10500 const char *comp_dir)
10502 const struct file_entry fe = lh->file_names [file_index];
10503 char *include_name = fe.name;
10504 char *include_name_to_compare = include_name;
10505 char *dir_name = NULL;
10506 const char *pst_filename;
10507 char *copied_name = NULL;
10511 dir_name = lh->include_dirs[fe.dir_index - 1];
10513 if (!IS_ABSOLUTE_PATH (include_name)
10514 && (dir_name != NULL || comp_dir != NULL))
10516 /* Avoid creating a duplicate psymtab for PST.
10517 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10518 Before we do the comparison, however, we need to account
10519 for DIR_NAME and COMP_DIR.
10520 First prepend dir_name (if non-NULL). If we still don't
10521 have an absolute path prepend comp_dir (if non-NULL).
10522 However, the directory we record in the include-file's
10523 psymtab does not contain COMP_DIR (to match the
10524 corresponding symtab(s)).
10529 bash$ gcc -g ./hello.c
10530 include_name = "hello.c"
10532 DW_AT_comp_dir = comp_dir = "/tmp"
10533 DW_AT_name = "./hello.c" */
10535 if (dir_name != NULL)
10537 include_name = concat (dir_name, SLASH_STRING,
10538 include_name, (char *)NULL);
10539 include_name_to_compare = include_name;
10540 make_cleanup (xfree, include_name);
10542 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
10544 include_name_to_compare = concat (comp_dir, SLASH_STRING,
10545 include_name, (char *)NULL);
10549 pst_filename = pst->filename;
10550 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
10552 copied_name = concat (pst->dirname, SLASH_STRING,
10553 pst_filename, (char *)NULL);
10554 pst_filename = copied_name;
10557 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
10559 if (include_name_to_compare != include_name)
10560 xfree (include_name_to_compare);
10561 if (copied_name != NULL)
10562 xfree (copied_name);
10566 return include_name;
10569 /* Ignore this record_line request. */
10572 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
10577 /* Decode the Line Number Program (LNP) for the given line_header
10578 structure and CU. The actual information extracted and the type
10579 of structures created from the LNP depends on the value of PST.
10581 1. If PST is NULL, then this procedure uses the data from the program
10582 to create all necessary symbol tables, and their linetables.
10584 2. If PST is not NULL, this procedure reads the program to determine
10585 the list of files included by the unit represented by PST, and
10586 builds all the associated partial symbol tables.
10588 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10589 It is used for relative paths in the line table.
10590 NOTE: When processing partial symtabs (pst != NULL),
10591 comp_dir == pst->dirname.
10593 NOTE: It is important that psymtabs have the same file name (via strcmp)
10594 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10595 symtab we don't use it in the name of the psymtabs we create.
10596 E.g. expand_line_sal requires this when finding psymtabs to expand.
10597 A good testcase for this is mb-inline.exp. */
10600 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
10601 struct dwarf2_cu *cu, struct partial_symtab *pst)
10603 gdb_byte *line_ptr, *extended_end;
10604 gdb_byte *line_end;
10605 unsigned int bytes_read, extended_len;
10606 unsigned char op_code, extended_op, adj_opcode;
10607 CORE_ADDR baseaddr;
10608 struct objfile *objfile = cu->objfile;
10609 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10610 const int decode_for_pst_p = (pst != NULL);
10611 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10612 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
10615 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10617 line_ptr = lh->statement_program_start;
10618 line_end = lh->statement_program_end;
10620 /* Read the statement sequences until there's nothing left. */
10621 while (line_ptr < line_end)
10623 /* state machine registers */
10624 CORE_ADDR address = 0;
10625 unsigned int file = 1;
10626 unsigned int line = 1;
10627 unsigned int column = 0;
10628 int is_stmt = lh->default_is_stmt;
10629 int basic_block = 0;
10630 int end_sequence = 0;
10632 unsigned char op_index = 0;
10634 if (!decode_for_pst_p && lh->num_file_names >= file)
10636 /* Start a subfile for the current file of the state machine. */
10637 /* lh->include_dirs and lh->file_names are 0-based, but the
10638 directory and file name numbers in the statement program
10640 struct file_entry *fe = &lh->file_names[file - 1];
10644 dir = lh->include_dirs[fe->dir_index - 1];
10646 dwarf2_start_subfile (fe->name, dir, comp_dir);
10649 /* Decode the table. */
10650 while (!end_sequence)
10652 op_code = read_1_byte (abfd, line_ptr);
10654 if (line_ptr > line_end)
10656 dwarf2_debug_line_missing_end_sequence_complaint ();
10660 if (op_code >= lh->opcode_base)
10662 /* Special operand. */
10663 adj_opcode = op_code - lh->opcode_base;
10664 address += (((op_index + (adj_opcode / lh->line_range))
10665 / lh->maximum_ops_per_instruction)
10666 * lh->minimum_instruction_length);
10667 op_index = ((op_index + (adj_opcode / lh->line_range))
10668 % lh->maximum_ops_per_instruction);
10669 line += lh->line_base + (adj_opcode % lh->line_range);
10670 if (lh->num_file_names < file || file == 0)
10671 dwarf2_debug_line_missing_file_complaint ();
10672 /* For now we ignore lines not starting on an
10673 instruction boundary. */
10674 else if (op_index == 0)
10676 lh->file_names[file - 1].included_p = 1;
10677 if (!decode_for_pst_p && is_stmt)
10679 if (last_subfile != current_subfile)
10681 addr = gdbarch_addr_bits_remove (gdbarch, address);
10683 (*p_record_line) (last_subfile, 0, addr);
10684 last_subfile = current_subfile;
10686 /* Append row to matrix using current values. */
10687 addr = check_cu_functions (address, cu);
10688 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10689 (*p_record_line) (current_subfile, line, addr);
10694 else switch (op_code)
10696 case DW_LNS_extended_op:
10697 extended_len = read_unsigned_leb128 (abfd, line_ptr,
10699 line_ptr += bytes_read;
10700 extended_end = line_ptr + extended_len;
10701 extended_op = read_1_byte (abfd, line_ptr);
10703 switch (extended_op)
10705 case DW_LNE_end_sequence:
10706 p_record_line = record_line;
10709 case DW_LNE_set_address:
10710 address = read_address (abfd, line_ptr, cu, &bytes_read);
10712 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
10714 /* This line table is for a function which has been
10715 GCd by the linker. Ignore it. PR gdb/12528 */
10718 = line_ptr - dwarf2_per_objfile->line.buffer;
10720 complaint (&symfile_complaints,
10721 _(".debug_line address at offset 0x%lx is 0 "
10723 line_offset, cu->objfile->name);
10724 p_record_line = noop_record_line;
10728 line_ptr += bytes_read;
10729 address += baseaddr;
10731 case DW_LNE_define_file:
10734 unsigned int dir_index, mod_time, length;
10736 cur_file = read_direct_string (abfd, line_ptr,
10738 line_ptr += bytes_read;
10740 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10741 line_ptr += bytes_read;
10743 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10744 line_ptr += bytes_read;
10746 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10747 line_ptr += bytes_read;
10748 add_file_name (lh, cur_file, dir_index, mod_time, length);
10751 case DW_LNE_set_discriminator:
10752 /* The discriminator is not interesting to the debugger;
10754 line_ptr = extended_end;
10757 complaint (&symfile_complaints,
10758 _("mangled .debug_line section"));
10761 /* Make sure that we parsed the extended op correctly. If e.g.
10762 we expected a different address size than the producer used,
10763 we may have read the wrong number of bytes. */
10764 if (line_ptr != extended_end)
10766 complaint (&symfile_complaints,
10767 _("mangled .debug_line section"));
10772 if (lh->num_file_names < file || file == 0)
10773 dwarf2_debug_line_missing_file_complaint ();
10776 lh->file_names[file - 1].included_p = 1;
10777 if (!decode_for_pst_p && is_stmt)
10779 if (last_subfile != current_subfile)
10781 addr = gdbarch_addr_bits_remove (gdbarch, address);
10783 (*p_record_line) (last_subfile, 0, addr);
10784 last_subfile = current_subfile;
10786 addr = check_cu_functions (address, cu);
10787 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10788 (*p_record_line) (current_subfile, line, addr);
10793 case DW_LNS_advance_pc:
10796 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10798 address += (((op_index + adjust)
10799 / lh->maximum_ops_per_instruction)
10800 * lh->minimum_instruction_length);
10801 op_index = ((op_index + adjust)
10802 % lh->maximum_ops_per_instruction);
10803 line_ptr += bytes_read;
10806 case DW_LNS_advance_line:
10807 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
10808 line_ptr += bytes_read;
10810 case DW_LNS_set_file:
10812 /* The arrays lh->include_dirs and lh->file_names are
10813 0-based, but the directory and file name numbers in
10814 the statement program are 1-based. */
10815 struct file_entry *fe;
10818 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10819 line_ptr += bytes_read;
10820 if (lh->num_file_names < file || file == 0)
10821 dwarf2_debug_line_missing_file_complaint ();
10824 fe = &lh->file_names[file - 1];
10826 dir = lh->include_dirs[fe->dir_index - 1];
10827 if (!decode_for_pst_p)
10829 last_subfile = current_subfile;
10830 dwarf2_start_subfile (fe->name, dir, comp_dir);
10835 case DW_LNS_set_column:
10836 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10837 line_ptr += bytes_read;
10839 case DW_LNS_negate_stmt:
10840 is_stmt = (!is_stmt);
10842 case DW_LNS_set_basic_block:
10845 /* Add to the address register of the state machine the
10846 address increment value corresponding to special opcode
10847 255. I.e., this value is scaled by the minimum
10848 instruction length since special opcode 255 would have
10849 scaled the increment. */
10850 case DW_LNS_const_add_pc:
10852 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
10854 address += (((op_index + adjust)
10855 / lh->maximum_ops_per_instruction)
10856 * lh->minimum_instruction_length);
10857 op_index = ((op_index + adjust)
10858 % lh->maximum_ops_per_instruction);
10861 case DW_LNS_fixed_advance_pc:
10862 address += read_2_bytes (abfd, line_ptr);
10868 /* Unknown standard opcode, ignore it. */
10871 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
10873 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10874 line_ptr += bytes_read;
10879 if (lh->num_file_names < file || file == 0)
10880 dwarf2_debug_line_missing_file_complaint ();
10883 lh->file_names[file - 1].included_p = 1;
10884 if (!decode_for_pst_p)
10886 addr = gdbarch_addr_bits_remove (gdbarch, address);
10887 (*p_record_line) (current_subfile, 0, addr);
10892 if (decode_for_pst_p)
10896 /* Now that we're done scanning the Line Header Program, we can
10897 create the psymtab of each included file. */
10898 for (file_index = 0; file_index < lh->num_file_names; file_index++)
10899 if (lh->file_names[file_index].included_p == 1)
10901 char *include_name =
10902 psymtab_include_file_name (lh, file_index, pst, comp_dir);
10903 if (include_name != NULL)
10904 dwarf2_create_include_psymtab (include_name, pst, objfile);
10909 /* Make sure a symtab is created for every file, even files
10910 which contain only variables (i.e. no code with associated
10914 struct file_entry *fe;
10916 for (i = 0; i < lh->num_file_names; i++)
10920 fe = &lh->file_names[i];
10922 dir = lh->include_dirs[fe->dir_index - 1];
10923 dwarf2_start_subfile (fe->name, dir, comp_dir);
10925 /* Skip the main file; we don't need it, and it must be
10926 allocated last, so that it will show up before the
10927 non-primary symtabs in the objfile's symtab list. */
10928 if (current_subfile == first_subfile)
10931 if (current_subfile->symtab == NULL)
10932 current_subfile->symtab = allocate_symtab (current_subfile->name,
10934 fe->symtab = current_subfile->symtab;
10939 /* Start a subfile for DWARF. FILENAME is the name of the file and
10940 DIRNAME the name of the source directory which contains FILENAME
10941 or NULL if not known. COMP_DIR is the compilation directory for the
10942 linetable's compilation unit or NULL if not known.
10943 This routine tries to keep line numbers from identical absolute and
10944 relative file names in a common subfile.
10946 Using the `list' example from the GDB testsuite, which resides in
10947 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10948 of /srcdir/list0.c yields the following debugging information for list0.c:
10950 DW_AT_name: /srcdir/list0.c
10951 DW_AT_comp_dir: /compdir
10952 files.files[0].name: list0.h
10953 files.files[0].dir: /srcdir
10954 files.files[1].name: list0.c
10955 files.files[1].dir: /srcdir
10957 The line number information for list0.c has to end up in a single
10958 subfile, so that `break /srcdir/list0.c:1' works as expected.
10959 start_subfile will ensure that this happens provided that we pass the
10960 concatenation of files.files[1].dir and files.files[1].name as the
10964 dwarf2_start_subfile (char *filename, const char *dirname,
10965 const char *comp_dir)
10969 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10970 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10971 second argument to start_subfile. To be consistent, we do the
10972 same here. In order not to lose the line information directory,
10973 we concatenate it to the filename when it makes sense.
10974 Note that the Dwarf3 standard says (speaking of filenames in line
10975 information): ``The directory index is ignored for file names
10976 that represent full path names''. Thus ignoring dirname in the
10977 `else' branch below isn't an issue. */
10979 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
10980 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
10982 fullname = filename;
10984 start_subfile (fullname, comp_dir);
10986 if (fullname != filename)
10991 var_decode_location (struct attribute *attr, struct symbol *sym,
10992 struct dwarf2_cu *cu)
10994 struct objfile *objfile = cu->objfile;
10995 struct comp_unit_head *cu_header = &cu->header;
10997 /* NOTE drow/2003-01-30: There used to be a comment and some special
10998 code here to turn a symbol with DW_AT_external and a
10999 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11000 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11001 with some versions of binutils) where shared libraries could have
11002 relocations against symbols in their debug information - the
11003 minimal symbol would have the right address, but the debug info
11004 would not. It's no longer necessary, because we will explicitly
11005 apply relocations when we read in the debug information now. */
11007 /* A DW_AT_location attribute with no contents indicates that a
11008 variable has been optimized away. */
11009 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11011 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11015 /* Handle one degenerate form of location expression specially, to
11016 preserve GDB's previous behavior when section offsets are
11017 specified. If this is just a DW_OP_addr then mark this symbol
11020 if (attr_form_is_block (attr)
11021 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11022 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11024 unsigned int dummy;
11026 SYMBOL_VALUE_ADDRESS (sym) =
11027 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11028 SYMBOL_CLASS (sym) = LOC_STATIC;
11029 fixup_symbol_section (sym, objfile);
11030 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11031 SYMBOL_SECTION (sym));
11035 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11036 expression evaluator, and use LOC_COMPUTED only when necessary
11037 (i.e. when the value of a register or memory location is
11038 referenced, or a thread-local block, etc.). Then again, it might
11039 not be worthwhile. I'm assuming that it isn't unless performance
11040 or memory numbers show me otherwise. */
11042 dwarf2_symbol_mark_computed (attr, sym, cu);
11043 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11045 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11046 cu->has_loclist = 1;
11049 /* Given a pointer to a DWARF information entry, figure out if we need
11050 to make a symbol table entry for it, and if so, create a new entry
11051 and return a pointer to it.
11052 If TYPE is NULL, determine symbol type from the die, otherwise
11053 used the passed type.
11054 If SPACE is not NULL, use it to hold the new symbol. If it is
11055 NULL, allocate a new symbol on the objfile's obstack. */
11057 static struct symbol *
11058 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11059 struct symbol *space)
11061 struct objfile *objfile = cu->objfile;
11062 struct symbol *sym = NULL;
11064 struct attribute *attr = NULL;
11065 struct attribute *attr2 = NULL;
11066 CORE_ADDR baseaddr;
11067 struct pending **list_to_add = NULL;
11069 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11071 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11073 name = dwarf2_name (die, cu);
11076 const char *linkagename;
11077 int suppress_add = 0;
11082 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11083 OBJSTAT (objfile, n_syms++);
11085 /* Cache this symbol's name and the name's demangled form (if any). */
11086 SYMBOL_SET_LANGUAGE (sym, cu->language);
11087 linkagename = dwarf2_physname (name, die, cu);
11088 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11090 /* Fortran does not have mangling standard and the mangling does differ
11091 between gfortran, iFort etc. */
11092 if (cu->language == language_fortran
11093 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11094 symbol_set_demangled_name (&(sym->ginfo),
11095 (char *) dwarf2_full_name (name, die, cu),
11098 /* Default assumptions.
11099 Use the passed type or decode it from the die. */
11100 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11101 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11103 SYMBOL_TYPE (sym) = type;
11105 SYMBOL_TYPE (sym) = die_type (die, cu);
11106 attr = dwarf2_attr (die,
11107 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11111 SYMBOL_LINE (sym) = DW_UNSND (attr);
11114 attr = dwarf2_attr (die,
11115 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11119 int file_index = DW_UNSND (attr);
11121 if (cu->line_header == NULL
11122 || file_index > cu->line_header->num_file_names)
11123 complaint (&symfile_complaints,
11124 _("file index out of range"));
11125 else if (file_index > 0)
11127 struct file_entry *fe;
11129 fe = &cu->line_header->file_names[file_index - 1];
11130 SYMBOL_SYMTAB (sym) = fe->symtab;
11137 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11140 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11142 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11143 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11144 SYMBOL_CLASS (sym) = LOC_LABEL;
11145 add_symbol_to_list (sym, cu->list_in_scope);
11147 case DW_TAG_subprogram:
11148 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11150 SYMBOL_CLASS (sym) = LOC_BLOCK;
11151 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11152 if ((attr2 && (DW_UNSND (attr2) != 0))
11153 || cu->language == language_ada)
11155 /* Subprograms marked external are stored as a global symbol.
11156 Ada subprograms, whether marked external or not, are always
11157 stored as a global symbol, because we want to be able to
11158 access them globally. For instance, we want to be able
11159 to break on a nested subprogram without having to
11160 specify the context. */
11161 list_to_add = &global_symbols;
11165 list_to_add = cu->list_in_scope;
11168 case DW_TAG_inlined_subroutine:
11169 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11171 SYMBOL_CLASS (sym) = LOC_BLOCK;
11172 SYMBOL_INLINED (sym) = 1;
11173 /* Do not add the symbol to any lists. It will be found via
11174 BLOCK_FUNCTION from the blockvector. */
11176 case DW_TAG_template_value_param:
11178 /* Fall through. */
11179 case DW_TAG_constant:
11180 case DW_TAG_variable:
11181 case DW_TAG_member:
11182 /* Compilation with minimal debug info may result in
11183 variables with missing type entries. Change the
11184 misleading `void' type to something sensible. */
11185 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11187 = objfile_type (objfile)->nodebug_data_symbol;
11189 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11190 /* In the case of DW_TAG_member, we should only be called for
11191 static const members. */
11192 if (die->tag == DW_TAG_member)
11194 /* dwarf2_add_field uses die_is_declaration,
11195 so we do the same. */
11196 gdb_assert (die_is_declaration (die, cu));
11201 dwarf2_const_value (attr, sym, cu);
11202 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11205 if (attr2 && (DW_UNSND (attr2) != 0))
11206 list_to_add = &global_symbols;
11208 list_to_add = cu->list_in_scope;
11212 attr = dwarf2_attr (die, DW_AT_location, cu);
11215 var_decode_location (attr, sym, cu);
11216 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11217 if (SYMBOL_CLASS (sym) == LOC_STATIC
11218 && SYMBOL_VALUE_ADDRESS (sym) == 0
11219 && !dwarf2_per_objfile->has_section_at_zero)
11221 /* When a static variable is eliminated by the linker,
11222 the corresponding debug information is not stripped
11223 out, but the variable address is set to null;
11224 do not add such variables into symbol table. */
11226 else if (attr2 && (DW_UNSND (attr2) != 0))
11228 /* Workaround gfortran PR debug/40040 - it uses
11229 DW_AT_location for variables in -fPIC libraries which may
11230 get overriden by other libraries/executable and get
11231 a different address. Resolve it by the minimal symbol
11232 which may come from inferior's executable using copy
11233 relocation. Make this workaround only for gfortran as for
11234 other compilers GDB cannot guess the minimal symbol
11235 Fortran mangling kind. */
11236 if (cu->language == language_fortran && die->parent
11237 && die->parent->tag == DW_TAG_module
11239 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11240 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11242 /* A variable with DW_AT_external is never static,
11243 but it may be block-scoped. */
11244 list_to_add = (cu->list_in_scope == &file_symbols
11245 ? &global_symbols : cu->list_in_scope);
11248 list_to_add = cu->list_in_scope;
11252 /* We do not know the address of this symbol.
11253 If it is an external symbol and we have type information
11254 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11255 The address of the variable will then be determined from
11256 the minimal symbol table whenever the variable is
11258 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11259 if (attr2 && (DW_UNSND (attr2) != 0)
11260 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11262 /* A variable with DW_AT_external is never static, but it
11263 may be block-scoped. */
11264 list_to_add = (cu->list_in_scope == &file_symbols
11265 ? &global_symbols : cu->list_in_scope);
11267 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11269 else if (!die_is_declaration (die, cu))
11271 /* Use the default LOC_OPTIMIZED_OUT class. */
11272 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11274 list_to_add = cu->list_in_scope;
11278 case DW_TAG_formal_parameter:
11279 /* If we are inside a function, mark this as an argument. If
11280 not, we might be looking at an argument to an inlined function
11281 when we do not have enough information to show inlined frames;
11282 pretend it's a local variable in that case so that the user can
11284 if (context_stack_depth > 0
11285 && context_stack[context_stack_depth - 1].name != NULL)
11286 SYMBOL_IS_ARGUMENT (sym) = 1;
11287 attr = dwarf2_attr (die, DW_AT_location, cu);
11290 var_decode_location (attr, sym, cu);
11292 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11295 dwarf2_const_value (attr, sym, cu);
11297 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
11298 if (attr && DW_UNSND (attr))
11300 struct type *ref_type;
11302 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
11303 SYMBOL_TYPE (sym) = ref_type;
11306 list_to_add = cu->list_in_scope;
11308 case DW_TAG_unspecified_parameters:
11309 /* From varargs functions; gdb doesn't seem to have any
11310 interest in this information, so just ignore it for now.
11313 case DW_TAG_template_type_param:
11315 /* Fall through. */
11316 case DW_TAG_class_type:
11317 case DW_TAG_interface_type:
11318 case DW_TAG_structure_type:
11319 case DW_TAG_union_type:
11320 case DW_TAG_set_type:
11321 case DW_TAG_enumeration_type:
11322 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11323 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11326 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11327 really ever be static objects: otherwise, if you try
11328 to, say, break of a class's method and you're in a file
11329 which doesn't mention that class, it won't work unless
11330 the check for all static symbols in lookup_symbol_aux
11331 saves you. See the OtherFileClass tests in
11332 gdb.c++/namespace.exp. */
11336 list_to_add = (cu->list_in_scope == &file_symbols
11337 && (cu->language == language_cplus
11338 || cu->language == language_java)
11339 ? &global_symbols : cu->list_in_scope);
11341 /* The semantics of C++ state that "struct foo {
11342 ... }" also defines a typedef for "foo". A Java
11343 class declaration also defines a typedef for the
11345 if (cu->language == language_cplus
11346 || cu->language == language_java
11347 || cu->language == language_ada)
11349 /* The symbol's name is already allocated along
11350 with this objfile, so we don't need to
11351 duplicate it for the type. */
11352 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11353 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11358 case DW_TAG_typedef:
11359 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11360 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11361 list_to_add = cu->list_in_scope;
11363 case DW_TAG_base_type:
11364 case DW_TAG_subrange_type:
11365 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11366 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11367 list_to_add = cu->list_in_scope;
11369 case DW_TAG_enumerator:
11370 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11373 dwarf2_const_value (attr, sym, cu);
11376 /* NOTE: carlton/2003-11-10: See comment above in the
11377 DW_TAG_class_type, etc. block. */
11379 list_to_add = (cu->list_in_scope == &file_symbols
11380 && (cu->language == language_cplus
11381 || cu->language == language_java)
11382 ? &global_symbols : cu->list_in_scope);
11385 case DW_TAG_namespace:
11386 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11387 list_to_add = &global_symbols;
11390 /* Not a tag we recognize. Hopefully we aren't processing
11391 trash data, but since we must specifically ignore things
11392 we don't recognize, there is nothing else we should do at
11394 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11395 dwarf_tag_name (die->tag));
11401 sym->hash_next = objfile->template_symbols;
11402 objfile->template_symbols = sym;
11403 list_to_add = NULL;
11406 if (list_to_add != NULL)
11407 add_symbol_to_list (sym, list_to_add);
11409 /* For the benefit of old versions of GCC, check for anonymous
11410 namespaces based on the demangled name. */
11411 if (!processing_has_namespace_info
11412 && cu->language == language_cplus)
11413 cp_scan_for_anonymous_namespaces (sym);
11418 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11420 static struct symbol *
11421 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11423 return new_symbol_full (die, type, cu, NULL);
11426 /* Given an attr with a DW_FORM_dataN value in host byte order,
11427 zero-extend it as appropriate for the symbol's type. The DWARF
11428 standard (v4) is not entirely clear about the meaning of using
11429 DW_FORM_dataN for a constant with a signed type, where the type is
11430 wider than the data. The conclusion of a discussion on the DWARF
11431 list was that this is unspecified. We choose to always zero-extend
11432 because that is the interpretation long in use by GCC. */
11435 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11436 const char *name, struct obstack *obstack,
11437 struct dwarf2_cu *cu, long *value, int bits)
11439 struct objfile *objfile = cu->objfile;
11440 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11441 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11442 LONGEST l = DW_UNSND (attr);
11444 if (bits < sizeof (*value) * 8)
11446 l &= ((LONGEST) 1 << bits) - 1;
11449 else if (bits == sizeof (*value) * 8)
11453 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11454 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11461 /* Read a constant value from an attribute. Either set *VALUE, or if
11462 the value does not fit in *VALUE, set *BYTES - either already
11463 allocated on the objfile obstack, or newly allocated on OBSTACK,
11464 or, set *BATON, if we translated the constant to a location
11468 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11469 const char *name, struct obstack *obstack,
11470 struct dwarf2_cu *cu,
11471 long *value, gdb_byte **bytes,
11472 struct dwarf2_locexpr_baton **baton)
11474 struct objfile *objfile = cu->objfile;
11475 struct comp_unit_head *cu_header = &cu->header;
11476 struct dwarf_block *blk;
11477 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11478 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11484 switch (attr->form)
11490 if (TYPE_LENGTH (type) != cu_header->addr_size)
11491 dwarf2_const_value_length_mismatch_complaint (name,
11492 cu_header->addr_size,
11493 TYPE_LENGTH (type));
11494 /* Symbols of this form are reasonably rare, so we just
11495 piggyback on the existing location code rather than writing
11496 a new implementation of symbol_computed_ops. */
11497 *baton = obstack_alloc (&objfile->objfile_obstack,
11498 sizeof (struct dwarf2_locexpr_baton));
11499 (*baton)->per_cu = cu->per_cu;
11500 gdb_assert ((*baton)->per_cu);
11502 (*baton)->size = 2 + cu_header->addr_size;
11503 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11504 (*baton)->data = data;
11506 data[0] = DW_OP_addr;
11507 store_unsigned_integer (&data[1], cu_header->addr_size,
11508 byte_order, DW_ADDR (attr));
11509 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11512 case DW_FORM_string:
11514 /* DW_STRING is already allocated on the objfile obstack, point
11516 *bytes = (gdb_byte *) DW_STRING (attr);
11518 case DW_FORM_block1:
11519 case DW_FORM_block2:
11520 case DW_FORM_block4:
11521 case DW_FORM_block:
11522 case DW_FORM_exprloc:
11523 blk = DW_BLOCK (attr);
11524 if (TYPE_LENGTH (type) != blk->size)
11525 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11526 TYPE_LENGTH (type));
11527 *bytes = blk->data;
11530 /* The DW_AT_const_value attributes are supposed to carry the
11531 symbol's value "represented as it would be on the target
11532 architecture." By the time we get here, it's already been
11533 converted to host endianness, so we just need to sign- or
11534 zero-extend it as appropriate. */
11535 case DW_FORM_data1:
11536 *bytes = dwarf2_const_value_data (attr, type, name,
11537 obstack, cu, value, 8);
11539 case DW_FORM_data2:
11540 *bytes = dwarf2_const_value_data (attr, type, name,
11541 obstack, cu, value, 16);
11543 case DW_FORM_data4:
11544 *bytes = dwarf2_const_value_data (attr, type, name,
11545 obstack, cu, value, 32);
11547 case DW_FORM_data8:
11548 *bytes = dwarf2_const_value_data (attr, type, name,
11549 obstack, cu, value, 64);
11552 case DW_FORM_sdata:
11553 *value = DW_SND (attr);
11556 case DW_FORM_udata:
11557 *value = DW_UNSND (attr);
11561 complaint (&symfile_complaints,
11562 _("unsupported const value attribute form: '%s'"),
11563 dwarf_form_name (attr->form));
11570 /* Copy constant value from an attribute to a symbol. */
11573 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
11574 struct dwarf2_cu *cu)
11576 struct objfile *objfile = cu->objfile;
11577 struct comp_unit_head *cu_header = &cu->header;
11580 struct dwarf2_locexpr_baton *baton;
11582 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
11583 SYMBOL_PRINT_NAME (sym),
11584 &objfile->objfile_obstack, cu,
11585 &value, &bytes, &baton);
11589 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11590 SYMBOL_LOCATION_BATON (sym) = baton;
11591 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11593 else if (bytes != NULL)
11595 SYMBOL_VALUE_BYTES (sym) = bytes;
11596 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
11600 SYMBOL_VALUE (sym) = value;
11601 SYMBOL_CLASS (sym) = LOC_CONST;
11605 /* Return the type of the die in question using its DW_AT_type attribute. */
11607 static struct type *
11608 die_type (struct die_info *die, struct dwarf2_cu *cu)
11610 struct attribute *type_attr;
11612 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11615 /* A missing DW_AT_type represents a void type. */
11616 return objfile_type (cu->objfile)->builtin_void;
11619 return lookup_die_type (die, type_attr, cu);
11622 /* True iff CU's producer generates GNAT Ada auxiliary information
11623 that allows to find parallel types through that information instead
11624 of having to do expensive parallel lookups by type name. */
11627 need_gnat_info (struct dwarf2_cu *cu)
11629 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11630 of GNAT produces this auxiliary information, without any indication
11631 that it is produced. Part of enhancing the FSF version of GNAT
11632 to produce that information will be to put in place an indicator
11633 that we can use in order to determine whether the descriptive type
11634 info is available or not. One suggestion that has been made is
11635 to use a new attribute, attached to the CU die. For now, assume
11636 that the descriptive type info is not available. */
11640 /* Return the auxiliary type of the die in question using its
11641 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11642 attribute is not present. */
11644 static struct type *
11645 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11647 struct attribute *type_attr;
11649 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11653 return lookup_die_type (die, type_attr, cu);
11656 /* If DIE has a descriptive_type attribute, then set the TYPE's
11657 descriptive type accordingly. */
11660 set_descriptive_type (struct type *type, struct die_info *die,
11661 struct dwarf2_cu *cu)
11663 struct type *descriptive_type = die_descriptive_type (die, cu);
11665 if (descriptive_type)
11667 ALLOCATE_GNAT_AUX_TYPE (type);
11668 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11672 /* Return the containing type of the die in question using its
11673 DW_AT_containing_type attribute. */
11675 static struct type *
11676 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11678 struct attribute *type_attr;
11680 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11682 error (_("Dwarf Error: Problem turning containing type into gdb type "
11683 "[in module %s]"), cu->objfile->name);
11685 return lookup_die_type (die, type_attr, cu);
11688 /* Look up the type of DIE in CU using its type attribute ATTR.
11689 If there is no type substitute an error marker. */
11691 static struct type *
11692 lookup_die_type (struct die_info *die, struct attribute *attr,
11693 struct dwarf2_cu *cu)
11695 struct type *this_type;
11697 /* First see if we have it cached. */
11699 if (is_ref_attr (attr))
11701 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11703 this_type = get_die_type_at_offset (offset, cu->per_cu);
11705 else if (attr->form == DW_FORM_ref_sig8)
11707 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11708 struct dwarf2_cu *sig_cu;
11709 unsigned int offset;
11711 /* sig_type will be NULL if the signatured type is missing from
11713 if (sig_type == NULL)
11714 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11715 "at 0x%x [in module %s]"),
11716 die->offset, cu->objfile->name);
11718 gdb_assert (sig_type->per_cu.from_debug_types);
11719 offset = sig_type->per_cu.offset + sig_type->type_offset;
11720 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11724 dump_die_for_error (die);
11725 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11726 dwarf_attr_name (attr->name), cu->objfile->name);
11729 /* If not cached we need to read it in. */
11731 if (this_type == NULL)
11733 struct die_info *type_die;
11734 struct dwarf2_cu *type_cu = cu;
11736 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11737 /* If the type is cached, we should have found it above. */
11738 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11739 this_type = read_type_die_1 (type_die, type_cu);
11742 /* If we still don't have a type use an error marker. */
11744 if (this_type == NULL)
11746 char *message, *saved;
11748 /* read_type_die already issued a complaint. */
11749 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11753 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
11754 message, strlen (message));
11757 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
11763 /* Return the type in DIE, CU.
11764 Returns NULL for invalid types.
11766 This first does a lookup in the appropriate type_hash table,
11767 and only reads the die in if necessary.
11769 NOTE: This can be called when reading in partial or full symbols. */
11771 static struct type *
11772 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
11774 struct type *this_type;
11776 this_type = get_die_type (die, cu);
11780 return read_type_die_1 (die, cu);
11783 /* Read the type in DIE, CU.
11784 Returns NULL for invalid types. */
11786 static struct type *
11787 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11789 struct type *this_type = NULL;
11793 case DW_TAG_class_type:
11794 case DW_TAG_interface_type:
11795 case DW_TAG_structure_type:
11796 case DW_TAG_union_type:
11797 this_type = read_structure_type (die, cu);
11799 case DW_TAG_enumeration_type:
11800 this_type = read_enumeration_type (die, cu);
11802 case DW_TAG_subprogram:
11803 case DW_TAG_subroutine_type:
11804 case DW_TAG_inlined_subroutine:
11805 this_type = read_subroutine_type (die, cu);
11807 case DW_TAG_array_type:
11808 this_type = read_array_type (die, cu);
11810 case DW_TAG_set_type:
11811 this_type = read_set_type (die, cu);
11813 case DW_TAG_pointer_type:
11814 this_type = read_tag_pointer_type (die, cu);
11816 case DW_TAG_ptr_to_member_type:
11817 this_type = read_tag_ptr_to_member_type (die, cu);
11819 case DW_TAG_reference_type:
11820 this_type = read_tag_reference_type (die, cu);
11822 case DW_TAG_const_type:
11823 this_type = read_tag_const_type (die, cu);
11825 case DW_TAG_volatile_type:
11826 this_type = read_tag_volatile_type (die, cu);
11828 case DW_TAG_string_type:
11829 this_type = read_tag_string_type (die, cu);
11831 case DW_TAG_typedef:
11832 this_type = read_typedef (die, cu);
11834 case DW_TAG_subrange_type:
11835 this_type = read_subrange_type (die, cu);
11837 case DW_TAG_base_type:
11838 this_type = read_base_type (die, cu);
11840 case DW_TAG_unspecified_type:
11841 this_type = read_unspecified_type (die, cu);
11843 case DW_TAG_namespace:
11844 this_type = read_namespace_type (die, cu);
11846 case DW_TAG_module:
11847 this_type = read_module_type (die, cu);
11850 complaint (&symfile_complaints,
11851 _("unexpected tag in read_type_die: '%s'"),
11852 dwarf_tag_name (die->tag));
11859 /* See if we can figure out if the class lives in a namespace. We do
11860 this by looking for a member function; its demangled name will
11861 contain namespace info, if there is any.
11862 Return the computed name or NULL.
11863 Space for the result is allocated on the objfile's obstack.
11864 This is the full-die version of guess_partial_die_structure_name.
11865 In this case we know DIE has no useful parent. */
11868 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
11870 struct die_info *spec_die;
11871 struct dwarf2_cu *spec_cu;
11872 struct die_info *child;
11875 spec_die = die_specification (die, &spec_cu);
11876 if (spec_die != NULL)
11882 for (child = die->child;
11884 child = child->sibling)
11886 if (child->tag == DW_TAG_subprogram)
11888 struct attribute *attr;
11890 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
11892 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
11896 = language_class_name_from_physname (cu->language_defn,
11900 if (actual_name != NULL)
11902 char *die_name = dwarf2_name (die, cu);
11904 if (die_name != NULL
11905 && strcmp (die_name, actual_name) != 0)
11907 /* Strip off the class name from the full name.
11908 We want the prefix. */
11909 int die_name_len = strlen (die_name);
11910 int actual_name_len = strlen (actual_name);
11912 /* Test for '::' as a sanity check. */
11913 if (actual_name_len > die_name_len + 2
11914 && actual_name[actual_name_len
11915 - die_name_len - 1] == ':')
11917 obsavestring (actual_name,
11918 actual_name_len - die_name_len - 2,
11919 &cu->objfile->objfile_obstack);
11922 xfree (actual_name);
11931 /* Return the name of the namespace/class that DIE is defined within,
11932 or "" if we can't tell. The caller should not xfree the result.
11934 For example, if we're within the method foo() in the following
11944 then determine_prefix on foo's die will return "N::C". */
11947 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
11949 struct die_info *parent, *spec_die;
11950 struct dwarf2_cu *spec_cu;
11951 struct type *parent_type;
11953 if (cu->language != language_cplus && cu->language != language_java
11954 && cu->language != language_fortran)
11957 /* We have to be careful in the presence of DW_AT_specification.
11958 For example, with GCC 3.4, given the code
11962 // Definition of N::foo.
11966 then we'll have a tree of DIEs like this:
11968 1: DW_TAG_compile_unit
11969 2: DW_TAG_namespace // N
11970 3: DW_TAG_subprogram // declaration of N::foo
11971 4: DW_TAG_subprogram // definition of N::foo
11972 DW_AT_specification // refers to die #3
11974 Thus, when processing die #4, we have to pretend that we're in
11975 the context of its DW_AT_specification, namely the contex of die
11978 spec_die = die_specification (die, &spec_cu);
11979 if (spec_die == NULL)
11980 parent = die->parent;
11983 parent = spec_die->parent;
11987 if (parent == NULL)
11989 else if (parent->building_fullname)
11992 const char *parent_name;
11994 /* It has been seen on RealView 2.2 built binaries,
11995 DW_TAG_template_type_param types actually _defined_ as
11996 children of the parent class:
11999 template class <class Enum> Class{};
12000 Class<enum E> class_e;
12002 1: DW_TAG_class_type (Class)
12003 2: DW_TAG_enumeration_type (E)
12004 3: DW_TAG_enumerator (enum1:0)
12005 3: DW_TAG_enumerator (enum2:1)
12007 2: DW_TAG_template_type_param
12008 DW_AT_type DW_FORM_ref_udata (E)
12010 Besides being broken debug info, it can put GDB into an
12011 infinite loop. Consider:
12013 When we're building the full name for Class<E>, we'll start
12014 at Class, and go look over its template type parameters,
12015 finding E. We'll then try to build the full name of E, and
12016 reach here. We're now trying to build the full name of E,
12017 and look over the parent DIE for containing scope. In the
12018 broken case, if we followed the parent DIE of E, we'd again
12019 find Class, and once again go look at its template type
12020 arguments, etc., etc. Simply don't consider such parent die
12021 as source-level parent of this die (it can't be, the language
12022 doesn't allow it), and break the loop here. */
12023 name = dwarf2_name (die, cu);
12024 parent_name = dwarf2_name (parent, cu);
12025 complaint (&symfile_complaints,
12026 _("template param type '%s' defined within parent '%s'"),
12027 name ? name : "<unknown>",
12028 parent_name ? parent_name : "<unknown>");
12032 switch (parent->tag)
12034 case DW_TAG_namespace:
12035 parent_type = read_type_die (parent, cu);
12036 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12037 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12038 Work around this problem here. */
12039 if (cu->language == language_cplus
12040 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12042 /* We give a name to even anonymous namespaces. */
12043 return TYPE_TAG_NAME (parent_type);
12044 case DW_TAG_class_type:
12045 case DW_TAG_interface_type:
12046 case DW_TAG_structure_type:
12047 case DW_TAG_union_type:
12048 case DW_TAG_module:
12049 parent_type = read_type_die (parent, cu);
12050 if (TYPE_TAG_NAME (parent_type) != NULL)
12051 return TYPE_TAG_NAME (parent_type);
12053 /* An anonymous structure is only allowed non-static data
12054 members; no typedefs, no member functions, et cetera.
12055 So it does not need a prefix. */
12057 case DW_TAG_compile_unit:
12058 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12059 if (cu->language == language_cplus
12060 && dwarf2_per_objfile->types.asection != NULL
12061 && die->child != NULL
12062 && (die->tag == DW_TAG_class_type
12063 || die->tag == DW_TAG_structure_type
12064 || die->tag == DW_TAG_union_type))
12066 char *name = guess_full_die_structure_name (die, cu);
12072 return determine_prefix (parent, cu);
12076 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12077 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12078 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12079 an obconcat, otherwise allocate storage for the result. The CU argument is
12080 used to determine the language and hence, the appropriate separator. */
12082 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12085 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12086 int physname, struct dwarf2_cu *cu)
12088 const char *lead = "";
12091 if (suffix == NULL || suffix[0] == '\0'
12092 || prefix == NULL || prefix[0] == '\0')
12094 else if (cu->language == language_java)
12096 else if (cu->language == language_fortran && physname)
12098 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12099 DW_AT_MIPS_linkage_name is preferred and used instead. */
12107 if (prefix == NULL)
12109 if (suffix == NULL)
12115 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12117 strcpy (retval, lead);
12118 strcat (retval, prefix);
12119 strcat (retval, sep);
12120 strcat (retval, suffix);
12125 /* We have an obstack. */
12126 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12130 /* Return sibling of die, NULL if no sibling. */
12132 static struct die_info *
12133 sibling_die (struct die_info *die)
12135 return die->sibling;
12138 /* Get name of a die, return NULL if not found. */
12141 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12142 struct obstack *obstack)
12144 if (name && cu->language == language_cplus)
12146 char *canon_name = cp_canonicalize_string (name);
12148 if (canon_name != NULL)
12150 if (strcmp (canon_name, name) != 0)
12151 name = obsavestring (canon_name, strlen (canon_name),
12153 xfree (canon_name);
12160 /* Get name of a die, return NULL if not found. */
12163 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12165 struct attribute *attr;
12167 attr = dwarf2_attr (die, DW_AT_name, cu);
12168 if ((!attr || !DW_STRING (attr))
12169 && die->tag != DW_TAG_class_type
12170 && die->tag != DW_TAG_interface_type
12171 && die->tag != DW_TAG_structure_type
12172 && die->tag != DW_TAG_union_type)
12177 case DW_TAG_compile_unit:
12178 /* Compilation units have a DW_AT_name that is a filename, not
12179 a source language identifier. */
12180 case DW_TAG_enumeration_type:
12181 case DW_TAG_enumerator:
12182 /* These tags always have simple identifiers already; no need
12183 to canonicalize them. */
12184 return DW_STRING (attr);
12186 case DW_TAG_subprogram:
12187 /* Java constructors will all be named "<init>", so return
12188 the class name when we see this special case. */
12189 if (cu->language == language_java
12190 && DW_STRING (attr) != NULL
12191 && strcmp (DW_STRING (attr), "<init>") == 0)
12193 struct dwarf2_cu *spec_cu = cu;
12194 struct die_info *spec_die;
12196 /* GCJ will output '<init>' for Java constructor names.
12197 For this special case, return the name of the parent class. */
12199 /* GCJ may output suprogram DIEs with AT_specification set.
12200 If so, use the name of the specified DIE. */
12201 spec_die = die_specification (die, &spec_cu);
12202 if (spec_die != NULL)
12203 return dwarf2_name (spec_die, spec_cu);
12208 if (die->tag == DW_TAG_class_type)
12209 return dwarf2_name (die, cu);
12211 while (die->tag != DW_TAG_compile_unit);
12215 case DW_TAG_class_type:
12216 case DW_TAG_interface_type:
12217 case DW_TAG_structure_type:
12218 case DW_TAG_union_type:
12219 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12220 structures or unions. These were of the form "._%d" in GCC 4.1,
12221 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12222 and GCC 4.4. We work around this problem by ignoring these. */
12223 if (attr && DW_STRING (attr)
12224 && (strncmp (DW_STRING (attr), "._", 2) == 0
12225 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12228 /* GCC might emit a nameless typedef that has a linkage name. See
12229 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12230 if (!attr || DW_STRING (attr) == NULL)
12232 char *demangled = NULL;
12234 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12236 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12238 if (attr == NULL || DW_STRING (attr) == NULL)
12241 /* Avoid demangling DW_STRING (attr) the second time on a second
12242 call for the same DIE. */
12243 if (!DW_STRING_IS_CANONICAL (attr))
12244 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12248 /* FIXME: we already did this for the partial symbol... */
12250 = obsavestring (demangled, strlen (demangled),
12251 &cu->objfile->objfile_obstack);
12252 DW_STRING_IS_CANONICAL (attr) = 1;
12262 if (!DW_STRING_IS_CANONICAL (attr))
12265 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12266 &cu->objfile->objfile_obstack);
12267 DW_STRING_IS_CANONICAL (attr) = 1;
12269 return DW_STRING (attr);
12272 /* Return the die that this die in an extension of, or NULL if there
12273 is none. *EXT_CU is the CU containing DIE on input, and the CU
12274 containing the return value on output. */
12276 static struct die_info *
12277 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12279 struct attribute *attr;
12281 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12285 return follow_die_ref (die, attr, ext_cu);
12288 /* Convert a DIE tag into its string name. */
12291 dwarf_tag_name (unsigned tag)
12295 case DW_TAG_padding:
12296 return "DW_TAG_padding";
12297 case DW_TAG_array_type:
12298 return "DW_TAG_array_type";
12299 case DW_TAG_class_type:
12300 return "DW_TAG_class_type";
12301 case DW_TAG_entry_point:
12302 return "DW_TAG_entry_point";
12303 case DW_TAG_enumeration_type:
12304 return "DW_TAG_enumeration_type";
12305 case DW_TAG_formal_parameter:
12306 return "DW_TAG_formal_parameter";
12307 case DW_TAG_imported_declaration:
12308 return "DW_TAG_imported_declaration";
12310 return "DW_TAG_label";
12311 case DW_TAG_lexical_block:
12312 return "DW_TAG_lexical_block";
12313 case DW_TAG_member:
12314 return "DW_TAG_member";
12315 case DW_TAG_pointer_type:
12316 return "DW_TAG_pointer_type";
12317 case DW_TAG_reference_type:
12318 return "DW_TAG_reference_type";
12319 case DW_TAG_compile_unit:
12320 return "DW_TAG_compile_unit";
12321 case DW_TAG_string_type:
12322 return "DW_TAG_string_type";
12323 case DW_TAG_structure_type:
12324 return "DW_TAG_structure_type";
12325 case DW_TAG_subroutine_type:
12326 return "DW_TAG_subroutine_type";
12327 case DW_TAG_typedef:
12328 return "DW_TAG_typedef";
12329 case DW_TAG_union_type:
12330 return "DW_TAG_union_type";
12331 case DW_TAG_unspecified_parameters:
12332 return "DW_TAG_unspecified_parameters";
12333 case DW_TAG_variant:
12334 return "DW_TAG_variant";
12335 case DW_TAG_common_block:
12336 return "DW_TAG_common_block";
12337 case DW_TAG_common_inclusion:
12338 return "DW_TAG_common_inclusion";
12339 case DW_TAG_inheritance:
12340 return "DW_TAG_inheritance";
12341 case DW_TAG_inlined_subroutine:
12342 return "DW_TAG_inlined_subroutine";
12343 case DW_TAG_module:
12344 return "DW_TAG_module";
12345 case DW_TAG_ptr_to_member_type:
12346 return "DW_TAG_ptr_to_member_type";
12347 case DW_TAG_set_type:
12348 return "DW_TAG_set_type";
12349 case DW_TAG_subrange_type:
12350 return "DW_TAG_subrange_type";
12351 case DW_TAG_with_stmt:
12352 return "DW_TAG_with_stmt";
12353 case DW_TAG_access_declaration:
12354 return "DW_TAG_access_declaration";
12355 case DW_TAG_base_type:
12356 return "DW_TAG_base_type";
12357 case DW_TAG_catch_block:
12358 return "DW_TAG_catch_block";
12359 case DW_TAG_const_type:
12360 return "DW_TAG_const_type";
12361 case DW_TAG_constant:
12362 return "DW_TAG_constant";
12363 case DW_TAG_enumerator:
12364 return "DW_TAG_enumerator";
12365 case DW_TAG_file_type:
12366 return "DW_TAG_file_type";
12367 case DW_TAG_friend:
12368 return "DW_TAG_friend";
12369 case DW_TAG_namelist:
12370 return "DW_TAG_namelist";
12371 case DW_TAG_namelist_item:
12372 return "DW_TAG_namelist_item";
12373 case DW_TAG_packed_type:
12374 return "DW_TAG_packed_type";
12375 case DW_TAG_subprogram:
12376 return "DW_TAG_subprogram";
12377 case DW_TAG_template_type_param:
12378 return "DW_TAG_template_type_param";
12379 case DW_TAG_template_value_param:
12380 return "DW_TAG_template_value_param";
12381 case DW_TAG_thrown_type:
12382 return "DW_TAG_thrown_type";
12383 case DW_TAG_try_block:
12384 return "DW_TAG_try_block";
12385 case DW_TAG_variant_part:
12386 return "DW_TAG_variant_part";
12387 case DW_TAG_variable:
12388 return "DW_TAG_variable";
12389 case DW_TAG_volatile_type:
12390 return "DW_TAG_volatile_type";
12391 case DW_TAG_dwarf_procedure:
12392 return "DW_TAG_dwarf_procedure";
12393 case DW_TAG_restrict_type:
12394 return "DW_TAG_restrict_type";
12395 case DW_TAG_interface_type:
12396 return "DW_TAG_interface_type";
12397 case DW_TAG_namespace:
12398 return "DW_TAG_namespace";
12399 case DW_TAG_imported_module:
12400 return "DW_TAG_imported_module";
12401 case DW_TAG_unspecified_type:
12402 return "DW_TAG_unspecified_type";
12403 case DW_TAG_partial_unit:
12404 return "DW_TAG_partial_unit";
12405 case DW_TAG_imported_unit:
12406 return "DW_TAG_imported_unit";
12407 case DW_TAG_condition:
12408 return "DW_TAG_condition";
12409 case DW_TAG_shared_type:
12410 return "DW_TAG_shared_type";
12411 case DW_TAG_type_unit:
12412 return "DW_TAG_type_unit";
12413 case DW_TAG_MIPS_loop:
12414 return "DW_TAG_MIPS_loop";
12415 case DW_TAG_HP_array_descriptor:
12416 return "DW_TAG_HP_array_descriptor";
12417 case DW_TAG_format_label:
12418 return "DW_TAG_format_label";
12419 case DW_TAG_function_template:
12420 return "DW_TAG_function_template";
12421 case DW_TAG_class_template:
12422 return "DW_TAG_class_template";
12423 case DW_TAG_GNU_BINCL:
12424 return "DW_TAG_GNU_BINCL";
12425 case DW_TAG_GNU_EINCL:
12426 return "DW_TAG_GNU_EINCL";
12427 case DW_TAG_upc_shared_type:
12428 return "DW_TAG_upc_shared_type";
12429 case DW_TAG_upc_strict_type:
12430 return "DW_TAG_upc_strict_type";
12431 case DW_TAG_upc_relaxed_type:
12432 return "DW_TAG_upc_relaxed_type";
12433 case DW_TAG_PGI_kanji_type:
12434 return "DW_TAG_PGI_kanji_type";
12435 case DW_TAG_PGI_interface_block:
12436 return "DW_TAG_PGI_interface_block";
12438 return "DW_TAG_<unknown>";
12442 /* Convert a DWARF attribute code into its string name. */
12445 dwarf_attr_name (unsigned attr)
12449 case DW_AT_sibling:
12450 return "DW_AT_sibling";
12451 case DW_AT_location:
12452 return "DW_AT_location";
12454 return "DW_AT_name";
12455 case DW_AT_ordering:
12456 return "DW_AT_ordering";
12457 case DW_AT_subscr_data:
12458 return "DW_AT_subscr_data";
12459 case DW_AT_byte_size:
12460 return "DW_AT_byte_size";
12461 case DW_AT_bit_offset:
12462 return "DW_AT_bit_offset";
12463 case DW_AT_bit_size:
12464 return "DW_AT_bit_size";
12465 case DW_AT_element_list:
12466 return "DW_AT_element_list";
12467 case DW_AT_stmt_list:
12468 return "DW_AT_stmt_list";
12470 return "DW_AT_low_pc";
12471 case DW_AT_high_pc:
12472 return "DW_AT_high_pc";
12473 case DW_AT_language:
12474 return "DW_AT_language";
12476 return "DW_AT_member";
12478 return "DW_AT_discr";
12479 case DW_AT_discr_value:
12480 return "DW_AT_discr_value";
12481 case DW_AT_visibility:
12482 return "DW_AT_visibility";
12484 return "DW_AT_import";
12485 case DW_AT_string_length:
12486 return "DW_AT_string_length";
12487 case DW_AT_common_reference:
12488 return "DW_AT_common_reference";
12489 case DW_AT_comp_dir:
12490 return "DW_AT_comp_dir";
12491 case DW_AT_const_value:
12492 return "DW_AT_const_value";
12493 case DW_AT_containing_type:
12494 return "DW_AT_containing_type";
12495 case DW_AT_default_value:
12496 return "DW_AT_default_value";
12498 return "DW_AT_inline";
12499 case DW_AT_is_optional:
12500 return "DW_AT_is_optional";
12501 case DW_AT_lower_bound:
12502 return "DW_AT_lower_bound";
12503 case DW_AT_producer:
12504 return "DW_AT_producer";
12505 case DW_AT_prototyped:
12506 return "DW_AT_prototyped";
12507 case DW_AT_return_addr:
12508 return "DW_AT_return_addr";
12509 case DW_AT_start_scope:
12510 return "DW_AT_start_scope";
12511 case DW_AT_bit_stride:
12512 return "DW_AT_bit_stride";
12513 case DW_AT_upper_bound:
12514 return "DW_AT_upper_bound";
12515 case DW_AT_abstract_origin:
12516 return "DW_AT_abstract_origin";
12517 case DW_AT_accessibility:
12518 return "DW_AT_accessibility";
12519 case DW_AT_address_class:
12520 return "DW_AT_address_class";
12521 case DW_AT_artificial:
12522 return "DW_AT_artificial";
12523 case DW_AT_base_types:
12524 return "DW_AT_base_types";
12525 case DW_AT_calling_convention:
12526 return "DW_AT_calling_convention";
12528 return "DW_AT_count";
12529 case DW_AT_data_member_location:
12530 return "DW_AT_data_member_location";
12531 case DW_AT_decl_column:
12532 return "DW_AT_decl_column";
12533 case DW_AT_decl_file:
12534 return "DW_AT_decl_file";
12535 case DW_AT_decl_line:
12536 return "DW_AT_decl_line";
12537 case DW_AT_declaration:
12538 return "DW_AT_declaration";
12539 case DW_AT_discr_list:
12540 return "DW_AT_discr_list";
12541 case DW_AT_encoding:
12542 return "DW_AT_encoding";
12543 case DW_AT_external:
12544 return "DW_AT_external";
12545 case DW_AT_frame_base:
12546 return "DW_AT_frame_base";
12548 return "DW_AT_friend";
12549 case DW_AT_identifier_case:
12550 return "DW_AT_identifier_case";
12551 case DW_AT_macro_info:
12552 return "DW_AT_macro_info";
12553 case DW_AT_namelist_items:
12554 return "DW_AT_namelist_items";
12555 case DW_AT_priority:
12556 return "DW_AT_priority";
12557 case DW_AT_segment:
12558 return "DW_AT_segment";
12559 case DW_AT_specification:
12560 return "DW_AT_specification";
12561 case DW_AT_static_link:
12562 return "DW_AT_static_link";
12564 return "DW_AT_type";
12565 case DW_AT_use_location:
12566 return "DW_AT_use_location";
12567 case DW_AT_variable_parameter:
12568 return "DW_AT_variable_parameter";
12569 case DW_AT_virtuality:
12570 return "DW_AT_virtuality";
12571 case DW_AT_vtable_elem_location:
12572 return "DW_AT_vtable_elem_location";
12573 /* DWARF 3 values. */
12574 case DW_AT_allocated:
12575 return "DW_AT_allocated";
12576 case DW_AT_associated:
12577 return "DW_AT_associated";
12578 case DW_AT_data_location:
12579 return "DW_AT_data_location";
12580 case DW_AT_byte_stride:
12581 return "DW_AT_byte_stride";
12582 case DW_AT_entry_pc:
12583 return "DW_AT_entry_pc";
12584 case DW_AT_use_UTF8:
12585 return "DW_AT_use_UTF8";
12586 case DW_AT_extension:
12587 return "DW_AT_extension";
12589 return "DW_AT_ranges";
12590 case DW_AT_trampoline:
12591 return "DW_AT_trampoline";
12592 case DW_AT_call_column:
12593 return "DW_AT_call_column";
12594 case DW_AT_call_file:
12595 return "DW_AT_call_file";
12596 case DW_AT_call_line:
12597 return "DW_AT_call_line";
12598 case DW_AT_description:
12599 return "DW_AT_description";
12600 case DW_AT_binary_scale:
12601 return "DW_AT_binary_scale";
12602 case DW_AT_decimal_scale:
12603 return "DW_AT_decimal_scale";
12605 return "DW_AT_small";
12606 case DW_AT_decimal_sign:
12607 return "DW_AT_decimal_sign";
12608 case DW_AT_digit_count:
12609 return "DW_AT_digit_count";
12610 case DW_AT_picture_string:
12611 return "DW_AT_picture_string";
12612 case DW_AT_mutable:
12613 return "DW_AT_mutable";
12614 case DW_AT_threads_scaled:
12615 return "DW_AT_threads_scaled";
12616 case DW_AT_explicit:
12617 return "DW_AT_explicit";
12618 case DW_AT_object_pointer:
12619 return "DW_AT_object_pointer";
12620 case DW_AT_endianity:
12621 return "DW_AT_endianity";
12622 case DW_AT_elemental:
12623 return "DW_AT_elemental";
12625 return "DW_AT_pure";
12626 case DW_AT_recursive:
12627 return "DW_AT_recursive";
12628 /* DWARF 4 values. */
12629 case DW_AT_signature:
12630 return "DW_AT_signature";
12631 case DW_AT_linkage_name:
12632 return "DW_AT_linkage_name";
12633 /* SGI/MIPS extensions. */
12634 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12635 case DW_AT_MIPS_fde:
12636 return "DW_AT_MIPS_fde";
12638 case DW_AT_MIPS_loop_begin:
12639 return "DW_AT_MIPS_loop_begin";
12640 case DW_AT_MIPS_tail_loop_begin:
12641 return "DW_AT_MIPS_tail_loop_begin";
12642 case DW_AT_MIPS_epilog_begin:
12643 return "DW_AT_MIPS_epilog_begin";
12644 case DW_AT_MIPS_loop_unroll_factor:
12645 return "DW_AT_MIPS_loop_unroll_factor";
12646 case DW_AT_MIPS_software_pipeline_depth:
12647 return "DW_AT_MIPS_software_pipeline_depth";
12648 case DW_AT_MIPS_linkage_name:
12649 return "DW_AT_MIPS_linkage_name";
12650 case DW_AT_MIPS_stride:
12651 return "DW_AT_MIPS_stride";
12652 case DW_AT_MIPS_abstract_name:
12653 return "DW_AT_MIPS_abstract_name";
12654 case DW_AT_MIPS_clone_origin:
12655 return "DW_AT_MIPS_clone_origin";
12656 case DW_AT_MIPS_has_inlines:
12657 return "DW_AT_MIPS_has_inlines";
12658 /* HP extensions. */
12659 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12660 case DW_AT_HP_block_index:
12661 return "DW_AT_HP_block_index";
12663 case DW_AT_HP_unmodifiable:
12664 return "DW_AT_HP_unmodifiable";
12665 case DW_AT_HP_actuals_stmt_list:
12666 return "DW_AT_HP_actuals_stmt_list";
12667 case DW_AT_HP_proc_per_section:
12668 return "DW_AT_HP_proc_per_section";
12669 case DW_AT_HP_raw_data_ptr:
12670 return "DW_AT_HP_raw_data_ptr";
12671 case DW_AT_HP_pass_by_reference:
12672 return "DW_AT_HP_pass_by_reference";
12673 case DW_AT_HP_opt_level:
12674 return "DW_AT_HP_opt_level";
12675 case DW_AT_HP_prof_version_id:
12676 return "DW_AT_HP_prof_version_id";
12677 case DW_AT_HP_opt_flags:
12678 return "DW_AT_HP_opt_flags";
12679 case DW_AT_HP_cold_region_low_pc:
12680 return "DW_AT_HP_cold_region_low_pc";
12681 case DW_AT_HP_cold_region_high_pc:
12682 return "DW_AT_HP_cold_region_high_pc";
12683 case DW_AT_HP_all_variables_modifiable:
12684 return "DW_AT_HP_all_variables_modifiable";
12685 case DW_AT_HP_linkage_name:
12686 return "DW_AT_HP_linkage_name";
12687 case DW_AT_HP_prof_flags:
12688 return "DW_AT_HP_prof_flags";
12689 /* GNU extensions. */
12690 case DW_AT_sf_names:
12691 return "DW_AT_sf_names";
12692 case DW_AT_src_info:
12693 return "DW_AT_src_info";
12694 case DW_AT_mac_info:
12695 return "DW_AT_mac_info";
12696 case DW_AT_src_coords:
12697 return "DW_AT_src_coords";
12698 case DW_AT_body_begin:
12699 return "DW_AT_body_begin";
12700 case DW_AT_body_end:
12701 return "DW_AT_body_end";
12702 case DW_AT_GNU_vector:
12703 return "DW_AT_GNU_vector";
12704 case DW_AT_GNU_odr_signature:
12705 return "DW_AT_GNU_odr_signature";
12706 /* VMS extensions. */
12707 case DW_AT_VMS_rtnbeg_pd_address:
12708 return "DW_AT_VMS_rtnbeg_pd_address";
12709 /* UPC extension. */
12710 case DW_AT_upc_threads_scaled:
12711 return "DW_AT_upc_threads_scaled";
12712 /* PGI (STMicroelectronics) extensions. */
12713 case DW_AT_PGI_lbase:
12714 return "DW_AT_PGI_lbase";
12715 case DW_AT_PGI_soffset:
12716 return "DW_AT_PGI_soffset";
12717 case DW_AT_PGI_lstride:
12718 return "DW_AT_PGI_lstride";
12720 return "DW_AT_<unknown>";
12724 /* Convert a DWARF value form code into its string name. */
12727 dwarf_form_name (unsigned form)
12732 return "DW_FORM_addr";
12733 case DW_FORM_block2:
12734 return "DW_FORM_block2";
12735 case DW_FORM_block4:
12736 return "DW_FORM_block4";
12737 case DW_FORM_data2:
12738 return "DW_FORM_data2";
12739 case DW_FORM_data4:
12740 return "DW_FORM_data4";
12741 case DW_FORM_data8:
12742 return "DW_FORM_data8";
12743 case DW_FORM_string:
12744 return "DW_FORM_string";
12745 case DW_FORM_block:
12746 return "DW_FORM_block";
12747 case DW_FORM_block1:
12748 return "DW_FORM_block1";
12749 case DW_FORM_data1:
12750 return "DW_FORM_data1";
12752 return "DW_FORM_flag";
12753 case DW_FORM_sdata:
12754 return "DW_FORM_sdata";
12756 return "DW_FORM_strp";
12757 case DW_FORM_udata:
12758 return "DW_FORM_udata";
12759 case DW_FORM_ref_addr:
12760 return "DW_FORM_ref_addr";
12762 return "DW_FORM_ref1";
12764 return "DW_FORM_ref2";
12766 return "DW_FORM_ref4";
12768 return "DW_FORM_ref8";
12769 case DW_FORM_ref_udata:
12770 return "DW_FORM_ref_udata";
12771 case DW_FORM_indirect:
12772 return "DW_FORM_indirect";
12773 case DW_FORM_sec_offset:
12774 return "DW_FORM_sec_offset";
12775 case DW_FORM_exprloc:
12776 return "DW_FORM_exprloc";
12777 case DW_FORM_flag_present:
12778 return "DW_FORM_flag_present";
12779 case DW_FORM_ref_sig8:
12780 return "DW_FORM_ref_sig8";
12782 return "DW_FORM_<unknown>";
12786 /* Convert a DWARF stack opcode into its string name. */
12789 dwarf_stack_op_name (unsigned op)
12794 return "DW_OP_addr";
12796 return "DW_OP_deref";
12797 case DW_OP_const1u:
12798 return "DW_OP_const1u";
12799 case DW_OP_const1s:
12800 return "DW_OP_const1s";
12801 case DW_OP_const2u:
12802 return "DW_OP_const2u";
12803 case DW_OP_const2s:
12804 return "DW_OP_const2s";
12805 case DW_OP_const4u:
12806 return "DW_OP_const4u";
12807 case DW_OP_const4s:
12808 return "DW_OP_const4s";
12809 case DW_OP_const8u:
12810 return "DW_OP_const8u";
12811 case DW_OP_const8s:
12812 return "DW_OP_const8s";
12814 return "DW_OP_constu";
12816 return "DW_OP_consts";
12818 return "DW_OP_dup";
12820 return "DW_OP_drop";
12822 return "DW_OP_over";
12824 return "DW_OP_pick";
12826 return "DW_OP_swap";
12828 return "DW_OP_rot";
12830 return "DW_OP_xderef";
12832 return "DW_OP_abs";
12834 return "DW_OP_and";
12836 return "DW_OP_div";
12838 return "DW_OP_minus";
12840 return "DW_OP_mod";
12842 return "DW_OP_mul";
12844 return "DW_OP_neg";
12846 return "DW_OP_not";
12850 return "DW_OP_plus";
12851 case DW_OP_plus_uconst:
12852 return "DW_OP_plus_uconst";
12854 return "DW_OP_shl";
12856 return "DW_OP_shr";
12858 return "DW_OP_shra";
12860 return "DW_OP_xor";
12862 return "DW_OP_bra";
12876 return "DW_OP_skip";
12878 return "DW_OP_lit0";
12880 return "DW_OP_lit1";
12882 return "DW_OP_lit2";
12884 return "DW_OP_lit3";
12886 return "DW_OP_lit4";
12888 return "DW_OP_lit5";
12890 return "DW_OP_lit6";
12892 return "DW_OP_lit7";
12894 return "DW_OP_lit8";
12896 return "DW_OP_lit9";
12898 return "DW_OP_lit10";
12900 return "DW_OP_lit11";
12902 return "DW_OP_lit12";
12904 return "DW_OP_lit13";
12906 return "DW_OP_lit14";
12908 return "DW_OP_lit15";
12910 return "DW_OP_lit16";
12912 return "DW_OP_lit17";
12914 return "DW_OP_lit18";
12916 return "DW_OP_lit19";
12918 return "DW_OP_lit20";
12920 return "DW_OP_lit21";
12922 return "DW_OP_lit22";
12924 return "DW_OP_lit23";
12926 return "DW_OP_lit24";
12928 return "DW_OP_lit25";
12930 return "DW_OP_lit26";
12932 return "DW_OP_lit27";
12934 return "DW_OP_lit28";
12936 return "DW_OP_lit29";
12938 return "DW_OP_lit30";
12940 return "DW_OP_lit31";
12942 return "DW_OP_reg0";
12944 return "DW_OP_reg1";
12946 return "DW_OP_reg2";
12948 return "DW_OP_reg3";
12950 return "DW_OP_reg4";
12952 return "DW_OP_reg5";
12954 return "DW_OP_reg6";
12956 return "DW_OP_reg7";
12958 return "DW_OP_reg8";
12960 return "DW_OP_reg9";
12962 return "DW_OP_reg10";
12964 return "DW_OP_reg11";
12966 return "DW_OP_reg12";
12968 return "DW_OP_reg13";
12970 return "DW_OP_reg14";
12972 return "DW_OP_reg15";
12974 return "DW_OP_reg16";
12976 return "DW_OP_reg17";
12978 return "DW_OP_reg18";
12980 return "DW_OP_reg19";
12982 return "DW_OP_reg20";
12984 return "DW_OP_reg21";
12986 return "DW_OP_reg22";
12988 return "DW_OP_reg23";
12990 return "DW_OP_reg24";
12992 return "DW_OP_reg25";
12994 return "DW_OP_reg26";
12996 return "DW_OP_reg27";
12998 return "DW_OP_reg28";
13000 return "DW_OP_reg29";
13002 return "DW_OP_reg30";
13004 return "DW_OP_reg31";
13006 return "DW_OP_breg0";
13008 return "DW_OP_breg1";
13010 return "DW_OP_breg2";
13012 return "DW_OP_breg3";
13014 return "DW_OP_breg4";
13016 return "DW_OP_breg5";
13018 return "DW_OP_breg6";
13020 return "DW_OP_breg7";
13022 return "DW_OP_breg8";
13024 return "DW_OP_breg9";
13026 return "DW_OP_breg10";
13028 return "DW_OP_breg11";
13030 return "DW_OP_breg12";
13032 return "DW_OP_breg13";
13034 return "DW_OP_breg14";
13036 return "DW_OP_breg15";
13038 return "DW_OP_breg16";
13040 return "DW_OP_breg17";
13042 return "DW_OP_breg18";
13044 return "DW_OP_breg19";
13046 return "DW_OP_breg20";
13048 return "DW_OP_breg21";
13050 return "DW_OP_breg22";
13052 return "DW_OP_breg23";
13054 return "DW_OP_breg24";
13056 return "DW_OP_breg25";
13058 return "DW_OP_breg26";
13060 return "DW_OP_breg27";
13062 return "DW_OP_breg28";
13064 return "DW_OP_breg29";
13066 return "DW_OP_breg30";
13068 return "DW_OP_breg31";
13070 return "DW_OP_regx";
13072 return "DW_OP_fbreg";
13074 return "DW_OP_bregx";
13076 return "DW_OP_piece";
13077 case DW_OP_deref_size:
13078 return "DW_OP_deref_size";
13079 case DW_OP_xderef_size:
13080 return "DW_OP_xderef_size";
13082 return "DW_OP_nop";
13083 /* DWARF 3 extensions. */
13084 case DW_OP_push_object_address:
13085 return "DW_OP_push_object_address";
13087 return "DW_OP_call2";
13089 return "DW_OP_call4";
13090 case DW_OP_call_ref:
13091 return "DW_OP_call_ref";
13092 case DW_OP_form_tls_address:
13093 return "DW_OP_form_tls_address";
13094 case DW_OP_call_frame_cfa:
13095 return "DW_OP_call_frame_cfa";
13096 case DW_OP_bit_piece:
13097 return "DW_OP_bit_piece";
13098 /* DWARF 4 extensions. */
13099 case DW_OP_implicit_value:
13100 return "DW_OP_implicit_value";
13101 case DW_OP_stack_value:
13102 return "DW_OP_stack_value";
13103 /* GNU extensions. */
13104 case DW_OP_GNU_push_tls_address:
13105 return "DW_OP_GNU_push_tls_address";
13106 case DW_OP_GNU_uninit:
13107 return "DW_OP_GNU_uninit";
13108 case DW_OP_GNU_implicit_pointer:
13109 return "DW_OP_GNU_implicit_pointer";
13110 case DW_OP_GNU_entry_value:
13111 return "DW_OP_GNU_entry_value";
13112 case DW_OP_GNU_const_type:
13113 return "DW_OP_GNU_const_type";
13114 case DW_OP_GNU_regval_type:
13115 return "DW_OP_GNU_regval_type";
13116 case DW_OP_GNU_deref_type:
13117 return "DW_OP_GNU_deref_type";
13118 case DW_OP_GNU_convert:
13119 return "DW_OP_GNU_convert";
13120 case DW_OP_GNU_reinterpret:
13121 return "DW_OP_GNU_reinterpret";
13128 dwarf_bool_name (unsigned mybool)
13136 /* Convert a DWARF type code into its string name. */
13139 dwarf_type_encoding_name (unsigned enc)
13144 return "DW_ATE_void";
13145 case DW_ATE_address:
13146 return "DW_ATE_address";
13147 case DW_ATE_boolean:
13148 return "DW_ATE_boolean";
13149 case DW_ATE_complex_float:
13150 return "DW_ATE_complex_float";
13152 return "DW_ATE_float";
13153 case DW_ATE_signed:
13154 return "DW_ATE_signed";
13155 case DW_ATE_signed_char:
13156 return "DW_ATE_signed_char";
13157 case DW_ATE_unsigned:
13158 return "DW_ATE_unsigned";
13159 case DW_ATE_unsigned_char:
13160 return "DW_ATE_unsigned_char";
13162 case DW_ATE_imaginary_float:
13163 return "DW_ATE_imaginary_float";
13164 case DW_ATE_packed_decimal:
13165 return "DW_ATE_packed_decimal";
13166 case DW_ATE_numeric_string:
13167 return "DW_ATE_numeric_string";
13168 case DW_ATE_edited:
13169 return "DW_ATE_edited";
13170 case DW_ATE_signed_fixed:
13171 return "DW_ATE_signed_fixed";
13172 case DW_ATE_unsigned_fixed:
13173 return "DW_ATE_unsigned_fixed";
13174 case DW_ATE_decimal_float:
13175 return "DW_ATE_decimal_float";
13178 return "DW_ATE_UTF";
13179 /* HP extensions. */
13180 case DW_ATE_HP_float80:
13181 return "DW_ATE_HP_float80";
13182 case DW_ATE_HP_complex_float80:
13183 return "DW_ATE_HP_complex_float80";
13184 case DW_ATE_HP_float128:
13185 return "DW_ATE_HP_float128";
13186 case DW_ATE_HP_complex_float128:
13187 return "DW_ATE_HP_complex_float128";
13188 case DW_ATE_HP_floathpintel:
13189 return "DW_ATE_HP_floathpintel";
13190 case DW_ATE_HP_imaginary_float80:
13191 return "DW_ATE_HP_imaginary_float80";
13192 case DW_ATE_HP_imaginary_float128:
13193 return "DW_ATE_HP_imaginary_float128";
13195 return "DW_ATE_<unknown>";
13199 /* Convert a DWARF call frame info operation to its string name. */
13203 dwarf_cfi_name (unsigned cfi_opc)
13207 case DW_CFA_advance_loc:
13208 return "DW_CFA_advance_loc";
13209 case DW_CFA_offset:
13210 return "DW_CFA_offset";
13211 case DW_CFA_restore:
13212 return "DW_CFA_restore";
13214 return "DW_CFA_nop";
13215 case DW_CFA_set_loc:
13216 return "DW_CFA_set_loc";
13217 case DW_CFA_advance_loc1:
13218 return "DW_CFA_advance_loc1";
13219 case DW_CFA_advance_loc2:
13220 return "DW_CFA_advance_loc2";
13221 case DW_CFA_advance_loc4:
13222 return "DW_CFA_advance_loc4";
13223 case DW_CFA_offset_extended:
13224 return "DW_CFA_offset_extended";
13225 case DW_CFA_restore_extended:
13226 return "DW_CFA_restore_extended";
13227 case DW_CFA_undefined:
13228 return "DW_CFA_undefined";
13229 case DW_CFA_same_value:
13230 return "DW_CFA_same_value";
13231 case DW_CFA_register:
13232 return "DW_CFA_register";
13233 case DW_CFA_remember_state:
13234 return "DW_CFA_remember_state";
13235 case DW_CFA_restore_state:
13236 return "DW_CFA_restore_state";
13237 case DW_CFA_def_cfa:
13238 return "DW_CFA_def_cfa";
13239 case DW_CFA_def_cfa_register:
13240 return "DW_CFA_def_cfa_register";
13241 case DW_CFA_def_cfa_offset:
13242 return "DW_CFA_def_cfa_offset";
13244 case DW_CFA_def_cfa_expression:
13245 return "DW_CFA_def_cfa_expression";
13246 case DW_CFA_expression:
13247 return "DW_CFA_expression";
13248 case DW_CFA_offset_extended_sf:
13249 return "DW_CFA_offset_extended_sf";
13250 case DW_CFA_def_cfa_sf:
13251 return "DW_CFA_def_cfa_sf";
13252 case DW_CFA_def_cfa_offset_sf:
13253 return "DW_CFA_def_cfa_offset_sf";
13254 case DW_CFA_val_offset:
13255 return "DW_CFA_val_offset";
13256 case DW_CFA_val_offset_sf:
13257 return "DW_CFA_val_offset_sf";
13258 case DW_CFA_val_expression:
13259 return "DW_CFA_val_expression";
13260 /* SGI/MIPS specific. */
13261 case DW_CFA_MIPS_advance_loc8:
13262 return "DW_CFA_MIPS_advance_loc8";
13263 /* GNU extensions. */
13264 case DW_CFA_GNU_window_save:
13265 return "DW_CFA_GNU_window_save";
13266 case DW_CFA_GNU_args_size:
13267 return "DW_CFA_GNU_args_size";
13268 case DW_CFA_GNU_negative_offset_extended:
13269 return "DW_CFA_GNU_negative_offset_extended";
13271 return "DW_CFA_<unknown>";
13277 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13281 print_spaces (indent, f);
13282 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13283 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13285 if (die->parent != NULL)
13287 print_spaces (indent, f);
13288 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13289 die->parent->offset);
13292 print_spaces (indent, f);
13293 fprintf_unfiltered (f, " has children: %s\n",
13294 dwarf_bool_name (die->child != NULL));
13296 print_spaces (indent, f);
13297 fprintf_unfiltered (f, " attributes:\n");
13299 for (i = 0; i < die->num_attrs; ++i)
13301 print_spaces (indent, f);
13302 fprintf_unfiltered (f, " %s (%s) ",
13303 dwarf_attr_name (die->attrs[i].name),
13304 dwarf_form_name (die->attrs[i].form));
13306 switch (die->attrs[i].form)
13308 case DW_FORM_ref_addr:
13310 fprintf_unfiltered (f, "address: ");
13311 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13313 case DW_FORM_block2:
13314 case DW_FORM_block4:
13315 case DW_FORM_block:
13316 case DW_FORM_block1:
13317 fprintf_unfiltered (f, "block: size %d",
13318 DW_BLOCK (&die->attrs[i])->size);
13320 case DW_FORM_exprloc:
13321 fprintf_unfiltered (f, "expression: size %u",
13322 DW_BLOCK (&die->attrs[i])->size);
13327 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13328 (long) (DW_ADDR (&die->attrs[i])));
13330 case DW_FORM_data1:
13331 case DW_FORM_data2:
13332 case DW_FORM_data4:
13333 case DW_FORM_data8:
13334 case DW_FORM_udata:
13335 case DW_FORM_sdata:
13336 fprintf_unfiltered (f, "constant: %s",
13337 pulongest (DW_UNSND (&die->attrs[i])));
13339 case DW_FORM_sec_offset:
13340 fprintf_unfiltered (f, "section offset: %s",
13341 pulongest (DW_UNSND (&die->attrs[i])));
13343 case DW_FORM_ref_sig8:
13344 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13345 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13346 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13348 fprintf_unfiltered (f, "signatured type, offset: unknown");
13350 case DW_FORM_string:
13352 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13353 DW_STRING (&die->attrs[i])
13354 ? DW_STRING (&die->attrs[i]) : "",
13355 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13358 if (DW_UNSND (&die->attrs[i]))
13359 fprintf_unfiltered (f, "flag: TRUE");
13361 fprintf_unfiltered (f, "flag: FALSE");
13363 case DW_FORM_flag_present:
13364 fprintf_unfiltered (f, "flag: TRUE");
13366 case DW_FORM_indirect:
13367 /* The reader will have reduced the indirect form to
13368 the "base form" so this form should not occur. */
13369 fprintf_unfiltered (f,
13370 "unexpected attribute form: DW_FORM_indirect");
13373 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13374 die->attrs[i].form);
13377 fprintf_unfiltered (f, "\n");
13382 dump_die_for_error (struct die_info *die)
13384 dump_die_shallow (gdb_stderr, 0, die);
13388 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13390 int indent = level * 4;
13392 gdb_assert (die != NULL);
13394 if (level >= max_level)
13397 dump_die_shallow (f, indent, die);
13399 if (die->child != NULL)
13401 print_spaces (indent, f);
13402 fprintf_unfiltered (f, " Children:");
13403 if (level + 1 < max_level)
13405 fprintf_unfiltered (f, "\n");
13406 dump_die_1 (f, level + 1, max_level, die->child);
13410 fprintf_unfiltered (f,
13411 " [not printed, max nesting level reached]\n");
13415 if (die->sibling != NULL && level > 0)
13417 dump_die_1 (f, level, max_level, die->sibling);
13421 /* This is called from the pdie macro in gdbinit.in.
13422 It's not static so gcc will keep a copy callable from gdb. */
13425 dump_die (struct die_info *die, int max_level)
13427 dump_die_1 (gdb_stdlog, 0, max_level, die);
13431 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13435 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13441 is_ref_attr (struct attribute *attr)
13443 switch (attr->form)
13445 case DW_FORM_ref_addr:
13450 case DW_FORM_ref_udata:
13457 static unsigned int
13458 dwarf2_get_ref_die_offset (struct attribute *attr)
13460 if (is_ref_attr (attr))
13461 return DW_ADDR (attr);
13463 complaint (&symfile_complaints,
13464 _("unsupported die ref attribute form: '%s'"),
13465 dwarf_form_name (attr->form));
13469 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13470 * the value held by the attribute is not constant. */
13473 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13475 if (attr->form == DW_FORM_sdata)
13476 return DW_SND (attr);
13477 else if (attr->form == DW_FORM_udata
13478 || attr->form == DW_FORM_data1
13479 || attr->form == DW_FORM_data2
13480 || attr->form == DW_FORM_data4
13481 || attr->form == DW_FORM_data8)
13482 return DW_UNSND (attr);
13485 complaint (&symfile_complaints,
13486 _("Attribute value is not a constant (%s)"),
13487 dwarf_form_name (attr->form));
13488 return default_value;
13492 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13493 unit and add it to our queue.
13494 The result is non-zero if PER_CU was queued, otherwise the result is zero
13495 meaning either PER_CU is already queued or it is already loaded. */
13498 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
13499 struct dwarf2_per_cu_data *per_cu)
13501 /* We may arrive here during partial symbol reading, if we need full
13502 DIEs to process an unusual case (e.g. template arguments). Do
13503 not queue PER_CU, just tell our caller to load its DIEs. */
13504 if (dwarf2_per_objfile->reading_partial_symbols)
13506 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
13511 /* Mark the dependence relation so that we don't flush PER_CU
13513 dwarf2_add_dependence (this_cu, per_cu);
13515 /* If it's already on the queue, we have nothing to do. */
13516 if (per_cu->queued)
13519 /* If the compilation unit is already loaded, just mark it as
13521 if (per_cu->cu != NULL)
13523 per_cu->cu->last_used = 0;
13527 /* Add it to the queue. */
13528 queue_comp_unit (per_cu, this_cu->objfile);
13533 /* Follow reference or signature attribute ATTR of SRC_DIE.
13534 On entry *REF_CU is the CU of SRC_DIE.
13535 On exit *REF_CU is the CU of the result. */
13537 static struct die_info *
13538 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
13539 struct dwarf2_cu **ref_cu)
13541 struct die_info *die;
13543 if (is_ref_attr (attr))
13544 die = follow_die_ref (src_die, attr, ref_cu);
13545 else if (attr->form == DW_FORM_ref_sig8)
13546 die = follow_die_sig (src_die, attr, ref_cu);
13549 dump_die_for_error (src_die);
13550 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13551 (*ref_cu)->objfile->name);
13557 /* Follow reference OFFSET.
13558 On entry *REF_CU is the CU of the source die referencing OFFSET.
13559 On exit *REF_CU is the CU of the result.
13560 Returns NULL if OFFSET is invalid. */
13562 static struct die_info *
13563 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
13565 struct die_info temp_die;
13566 struct dwarf2_cu *target_cu, *cu = *ref_cu;
13568 gdb_assert (cu->per_cu != NULL);
13572 if (cu->per_cu->from_debug_types)
13574 /* .debug_types CUs cannot reference anything outside their CU.
13575 If they need to, they have to reference a signatured type via
13576 DW_FORM_ref_sig8. */
13577 if (! offset_in_cu_p (&cu->header, offset))
13580 else if (! offset_in_cu_p (&cu->header, offset))
13582 struct dwarf2_per_cu_data *per_cu;
13584 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
13586 /* If necessary, add it to the queue and load its DIEs. */
13587 if (maybe_queue_comp_unit (cu, per_cu))
13588 load_full_comp_unit (per_cu, cu->objfile);
13590 target_cu = per_cu->cu;
13592 else if (cu->dies == NULL)
13594 /* We're loading full DIEs during partial symbol reading. */
13595 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
13596 load_full_comp_unit (cu->per_cu, cu->objfile);
13599 *ref_cu = target_cu;
13600 temp_die.offset = offset;
13601 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
13604 /* Follow reference attribute ATTR of SRC_DIE.
13605 On entry *REF_CU is the CU of SRC_DIE.
13606 On exit *REF_CU is the CU of the result. */
13608 static struct die_info *
13609 follow_die_ref (struct die_info *src_die, struct attribute *attr,
13610 struct dwarf2_cu **ref_cu)
13612 unsigned int offset = dwarf2_get_ref_die_offset (attr);
13613 struct dwarf2_cu *cu = *ref_cu;
13614 struct die_info *die;
13616 die = follow_die_offset (offset, ref_cu);
13618 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13619 "at 0x%x [in module %s]"),
13620 offset, src_die->offset, cu->objfile->name);
13625 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13626 value is intended for DW_OP_call*. */
13628 struct dwarf2_locexpr_baton
13629 dwarf2_fetch_die_location_block (unsigned int offset,
13630 struct dwarf2_per_cu_data *per_cu,
13631 CORE_ADDR (*get_frame_pc) (void *baton),
13634 struct dwarf2_cu *cu = per_cu->cu;
13635 struct die_info *die;
13636 struct attribute *attr;
13637 struct dwarf2_locexpr_baton retval;
13639 dw2_setup (per_cu->objfile);
13641 die = follow_die_offset (offset, &cu);
13643 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13644 offset, per_cu->cu->objfile->name);
13646 attr = dwarf2_attr (die, DW_AT_location, cu);
13649 /* DWARF: "If there is no such attribute, then there is no effect.". */
13651 retval.data = NULL;
13654 else if (attr_form_is_section_offset (attr))
13656 struct dwarf2_loclist_baton loclist_baton;
13657 CORE_ADDR pc = (*get_frame_pc) (baton);
13660 fill_in_loclist_baton (cu, &loclist_baton, attr);
13662 retval.data = dwarf2_find_location_expression (&loclist_baton,
13664 retval.size = size;
13668 if (!attr_form_is_block (attr))
13669 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13670 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13671 offset, per_cu->cu->objfile->name);
13673 retval.data = DW_BLOCK (attr)->data;
13674 retval.size = DW_BLOCK (attr)->size;
13676 retval.per_cu = cu->per_cu;
13680 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13684 dwarf2_get_die_type (unsigned int die_offset,
13685 struct dwarf2_per_cu_data *per_cu)
13687 dw2_setup (per_cu->objfile);
13688 return get_die_type_at_offset (die_offset, per_cu);
13691 /* Follow the signature attribute ATTR in SRC_DIE.
13692 On entry *REF_CU is the CU of SRC_DIE.
13693 On exit *REF_CU is the CU of the result. */
13695 static struct die_info *
13696 follow_die_sig (struct die_info *src_die, struct attribute *attr,
13697 struct dwarf2_cu **ref_cu)
13699 struct objfile *objfile = (*ref_cu)->objfile;
13700 struct die_info temp_die;
13701 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
13702 struct dwarf2_cu *sig_cu;
13703 struct die_info *die;
13705 /* sig_type will be NULL if the signatured type is missing from
13707 if (sig_type == NULL)
13708 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13709 "at 0x%x [in module %s]"),
13710 src_die->offset, objfile->name);
13712 /* If necessary, add it to the queue and load its DIEs. */
13714 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
13715 read_signatured_type (objfile, sig_type);
13717 gdb_assert (sig_type->per_cu.cu != NULL);
13719 sig_cu = sig_type->per_cu.cu;
13720 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
13721 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
13728 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13729 "from DIE at 0x%x [in module %s]"),
13730 sig_type->type_offset, src_die->offset, objfile->name);
13733 /* Given an offset of a signatured type, return its signatured_type. */
13735 static struct signatured_type *
13736 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
13738 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
13739 unsigned int length, initial_length_size;
13740 unsigned int sig_offset;
13741 struct signatured_type find_entry, *type_sig;
13743 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
13744 sig_offset = (initial_length_size
13746 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
13747 + 1 /*address_size*/);
13748 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
13749 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
13751 /* This is only used to lookup previously recorded types.
13752 If we didn't find it, it's our bug. */
13753 gdb_assert (type_sig != NULL);
13754 gdb_assert (offset == type_sig->per_cu.offset);
13759 /* Read in signatured type at OFFSET and build its CU and die(s). */
13762 read_signatured_type_at_offset (struct objfile *objfile,
13763 unsigned int offset)
13765 struct signatured_type *type_sig;
13767 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13769 /* We have the section offset, but we need the signature to do the
13770 hash table lookup. */
13771 type_sig = lookup_signatured_type_at_offset (objfile, offset);
13773 gdb_assert (type_sig->per_cu.cu == NULL);
13775 read_signatured_type (objfile, type_sig);
13777 gdb_assert (type_sig->per_cu.cu != NULL);
13780 /* Read in a signatured type and build its CU and DIEs. */
13783 read_signatured_type (struct objfile *objfile,
13784 struct signatured_type *type_sig)
13786 gdb_byte *types_ptr;
13787 struct die_reader_specs reader_specs;
13788 struct dwarf2_cu *cu;
13789 ULONGEST signature;
13790 struct cleanup *back_to, *free_cu_cleanup;
13792 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13793 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->per_cu.offset;
13795 gdb_assert (type_sig->per_cu.cu == NULL);
13797 cu = xmalloc (sizeof (*cu));
13798 init_one_comp_unit (cu, objfile);
13800 type_sig->per_cu.cu = cu;
13801 cu->per_cu = &type_sig->per_cu;
13803 /* If an error occurs while loading, release our storage. */
13804 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
13806 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
13807 types_ptr, objfile->obfd);
13808 gdb_assert (signature == type_sig->signature);
13811 = htab_create_alloc_ex (cu->header.length / 12,
13815 &cu->comp_unit_obstack,
13816 hashtab_obstack_allocate,
13817 dummy_obstack_deallocate);
13819 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
13820 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
13822 init_cu_die_reader (&reader_specs, cu);
13824 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
13827 /* We try not to read any attributes in this function, because not
13828 all objfiles needed for references have been loaded yet, and symbol
13829 table processing isn't initialized. But we have to set the CU language,
13830 or we won't be able to build types correctly. */
13831 prepare_one_comp_unit (cu, cu->dies);
13833 do_cleanups (back_to);
13835 /* We've successfully allocated this compilation unit. Let our caller
13836 clean it up when finished with it. */
13837 discard_cleanups (free_cu_cleanup);
13839 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
13840 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
13843 /* Decode simple location descriptions.
13844 Given a pointer to a dwarf block that defines a location, compute
13845 the location and return the value.
13847 NOTE drow/2003-11-18: This function is called in two situations
13848 now: for the address of static or global variables (partial symbols
13849 only) and for offsets into structures which are expected to be
13850 (more or less) constant. The partial symbol case should go away,
13851 and only the constant case should remain. That will let this
13852 function complain more accurately. A few special modes are allowed
13853 without complaint for global variables (for instance, global
13854 register values and thread-local values).
13856 A location description containing no operations indicates that the
13857 object is optimized out. The return value is 0 for that case.
13858 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13859 callers will only want a very basic result and this can become a
13862 Note that stack[0] is unused except as a default error return. */
13865 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
13867 struct objfile *objfile = cu->objfile;
13869 int size = blk->size;
13870 gdb_byte *data = blk->data;
13871 CORE_ADDR stack[64];
13873 unsigned int bytes_read, unsnd;
13879 stack[++stacki] = 0;
13918 stack[++stacki] = op - DW_OP_lit0;
13953 stack[++stacki] = op - DW_OP_reg0;
13955 dwarf2_complex_location_expr_complaint ();
13959 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13961 stack[++stacki] = unsnd;
13963 dwarf2_complex_location_expr_complaint ();
13967 stack[++stacki] = read_address (objfile->obfd, &data[i],
13972 case DW_OP_const1u:
13973 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
13977 case DW_OP_const1s:
13978 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
13982 case DW_OP_const2u:
13983 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
13987 case DW_OP_const2s:
13988 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
13992 case DW_OP_const4u:
13993 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
13997 case DW_OP_const4s:
13998 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14003 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14009 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14014 stack[stacki + 1] = stack[stacki];
14019 stack[stacki - 1] += stack[stacki];
14023 case DW_OP_plus_uconst:
14024 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14030 stack[stacki - 1] -= stack[stacki];
14035 /* If we're not the last op, then we definitely can't encode
14036 this using GDB's address_class enum. This is valid for partial
14037 global symbols, although the variable's address will be bogus
14040 dwarf2_complex_location_expr_complaint ();
14043 case DW_OP_GNU_push_tls_address:
14044 /* The top of the stack has the offset from the beginning
14045 of the thread control block at which the variable is located. */
14046 /* Nothing should follow this operator, so the top of stack would
14048 /* This is valid for partial global symbols, but the variable's
14049 address will be bogus in the psymtab. */
14051 dwarf2_complex_location_expr_complaint ();
14054 case DW_OP_GNU_uninit:
14059 const char *name = dwarf_stack_op_name (op);
14062 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14065 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14069 return (stack[stacki]);
14072 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14073 outside of the allocated space. Also enforce minimum>0. */
14074 if (stacki >= ARRAY_SIZE (stack) - 1)
14076 complaint (&symfile_complaints,
14077 _("location description stack overflow"));
14083 complaint (&symfile_complaints,
14084 _("location description stack underflow"));
14088 return (stack[stacki]);
14091 /* memory allocation interface */
14093 static struct dwarf_block *
14094 dwarf_alloc_block (struct dwarf2_cu *cu)
14096 struct dwarf_block *blk;
14098 blk = (struct dwarf_block *)
14099 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14103 static struct abbrev_info *
14104 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14106 struct abbrev_info *abbrev;
14108 abbrev = (struct abbrev_info *)
14109 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14110 memset (abbrev, 0, sizeof (struct abbrev_info));
14114 static struct die_info *
14115 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14117 struct die_info *die;
14118 size_t size = sizeof (struct die_info);
14121 size += (num_attrs - 1) * sizeof (struct attribute);
14123 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14124 memset (die, 0, sizeof (struct die_info));
14129 /* Macro support. */
14131 /* Return the full name of file number I in *LH's file name table.
14132 Use COMP_DIR as the name of the current directory of the
14133 compilation. The result is allocated using xmalloc; the caller is
14134 responsible for freeing it. */
14136 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14138 /* Is the file number a valid index into the line header's file name
14139 table? Remember that file numbers start with one, not zero. */
14140 if (1 <= file && file <= lh->num_file_names)
14142 struct file_entry *fe = &lh->file_names[file - 1];
14144 if (IS_ABSOLUTE_PATH (fe->name))
14145 return xstrdup (fe->name);
14153 dir = lh->include_dirs[fe->dir_index - 1];
14159 dir_len = strlen (dir);
14160 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14161 strcpy (full_name, dir);
14162 full_name[dir_len] = '/';
14163 strcpy (full_name + dir_len + 1, fe->name);
14167 return xstrdup (fe->name);
14172 /* The compiler produced a bogus file number. We can at least
14173 record the macro definitions made in the file, even if we
14174 won't be able to find the file by name. */
14175 char fake_name[80];
14177 sprintf (fake_name, "<bad macro file number %d>", file);
14179 complaint (&symfile_complaints,
14180 _("bad file number in macro information (%d)"),
14183 return xstrdup (fake_name);
14188 static struct macro_source_file *
14189 macro_start_file (int file, int line,
14190 struct macro_source_file *current_file,
14191 const char *comp_dir,
14192 struct line_header *lh, struct objfile *objfile)
14194 /* The full name of this source file. */
14195 char *full_name = file_full_name (file, lh, comp_dir);
14197 /* We don't create a macro table for this compilation unit
14198 at all until we actually get a filename. */
14199 if (! pending_macros)
14200 pending_macros = new_macro_table (&objfile->objfile_obstack,
14201 objfile->macro_cache);
14203 if (! current_file)
14204 /* If we have no current file, then this must be the start_file
14205 directive for the compilation unit's main source file. */
14206 current_file = macro_set_main (pending_macros, full_name);
14208 current_file = macro_include (current_file, line, full_name);
14212 return current_file;
14216 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14217 followed by a null byte. */
14219 copy_string (const char *buf, int len)
14221 char *s = xmalloc (len + 1);
14223 memcpy (s, buf, len);
14229 static const char *
14230 consume_improper_spaces (const char *p, const char *body)
14234 complaint (&symfile_complaints,
14235 _("macro definition contains spaces "
14236 "in formal argument list:\n`%s'"),
14248 parse_macro_definition (struct macro_source_file *file, int line,
14253 /* The body string takes one of two forms. For object-like macro
14254 definitions, it should be:
14256 <macro name> " " <definition>
14258 For function-like macro definitions, it should be:
14260 <macro name> "() " <definition>
14262 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14264 Spaces may appear only where explicitly indicated, and in the
14267 The Dwarf 2 spec says that an object-like macro's name is always
14268 followed by a space, but versions of GCC around March 2002 omit
14269 the space when the macro's definition is the empty string.
14271 The Dwarf 2 spec says that there should be no spaces between the
14272 formal arguments in a function-like macro's formal argument list,
14273 but versions of GCC around March 2002 include spaces after the
14277 /* Find the extent of the macro name. The macro name is terminated
14278 by either a space or null character (for an object-like macro) or
14279 an opening paren (for a function-like macro). */
14280 for (p = body; *p; p++)
14281 if (*p == ' ' || *p == '(')
14284 if (*p == ' ' || *p == '\0')
14286 /* It's an object-like macro. */
14287 int name_len = p - body;
14288 char *name = copy_string (body, name_len);
14289 const char *replacement;
14292 replacement = body + name_len + 1;
14295 dwarf2_macro_malformed_definition_complaint (body);
14296 replacement = body + name_len;
14299 macro_define_object (file, line, name, replacement);
14303 else if (*p == '(')
14305 /* It's a function-like macro. */
14306 char *name = copy_string (body, p - body);
14309 char **argv = xmalloc (argv_size * sizeof (*argv));
14313 p = consume_improper_spaces (p, body);
14315 /* Parse the formal argument list. */
14316 while (*p && *p != ')')
14318 /* Find the extent of the current argument name. */
14319 const char *arg_start = p;
14321 while (*p && *p != ',' && *p != ')' && *p != ' ')
14324 if (! *p || p == arg_start)
14325 dwarf2_macro_malformed_definition_complaint (body);
14328 /* Make sure argv has room for the new argument. */
14329 if (argc >= argv_size)
14332 argv = xrealloc (argv, argv_size * sizeof (*argv));
14335 argv[argc++] = copy_string (arg_start, p - arg_start);
14338 p = consume_improper_spaces (p, body);
14340 /* Consume the comma, if present. */
14345 p = consume_improper_spaces (p, body);
14354 /* Perfectly formed definition, no complaints. */
14355 macro_define_function (file, line, name,
14356 argc, (const char **) argv,
14358 else if (*p == '\0')
14360 /* Complain, but do define it. */
14361 dwarf2_macro_malformed_definition_complaint (body);
14362 macro_define_function (file, line, name,
14363 argc, (const char **) argv,
14367 /* Just complain. */
14368 dwarf2_macro_malformed_definition_complaint (body);
14371 /* Just complain. */
14372 dwarf2_macro_malformed_definition_complaint (body);
14378 for (i = 0; i < argc; i++)
14384 dwarf2_macro_malformed_definition_complaint (body);
14389 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
14390 char *comp_dir, bfd *abfd,
14391 struct dwarf2_cu *cu)
14393 gdb_byte *mac_ptr, *mac_end;
14394 struct macro_source_file *current_file = 0;
14395 enum dwarf_macinfo_record_type macinfo_type;
14396 int at_commandline;
14398 dwarf2_read_section (dwarf2_per_objfile->objfile,
14399 &dwarf2_per_objfile->macinfo);
14400 if (dwarf2_per_objfile->macinfo.buffer == NULL)
14402 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
14406 /* First pass: Find the name of the base filename.
14407 This filename is needed in order to process all macros whose definition
14408 (or undefinition) comes from the command line. These macros are defined
14409 before the first DW_MACINFO_start_file entry, and yet still need to be
14410 associated to the base file.
14412 To determine the base file name, we scan the macro definitions until we
14413 reach the first DW_MACINFO_start_file entry. We then initialize
14414 CURRENT_FILE accordingly so that any macro definition found before the
14415 first DW_MACINFO_start_file can still be associated to the base file. */
14417 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14418 mac_end = dwarf2_per_objfile->macinfo.buffer
14419 + dwarf2_per_objfile->macinfo.size;
14423 /* Do we at least have room for a macinfo type byte? */
14424 if (mac_ptr >= mac_end)
14426 /* Complaint is printed during the second pass as GDB will probably
14427 stop the first pass earlier upon finding
14428 DW_MACINFO_start_file. */
14432 macinfo_type = read_1_byte (abfd, mac_ptr);
14435 switch (macinfo_type)
14437 /* A zero macinfo type indicates the end of the macro
14442 case DW_MACINFO_define:
14443 case DW_MACINFO_undef:
14444 /* Only skip the data by MAC_PTR. */
14446 unsigned int bytes_read;
14448 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14449 mac_ptr += bytes_read;
14450 read_direct_string (abfd, mac_ptr, &bytes_read);
14451 mac_ptr += bytes_read;
14455 case DW_MACINFO_start_file:
14457 unsigned int bytes_read;
14460 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14461 mac_ptr += bytes_read;
14462 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14463 mac_ptr += bytes_read;
14465 current_file = macro_start_file (file, line, current_file,
14466 comp_dir, lh, cu->objfile);
14470 case DW_MACINFO_end_file:
14471 /* No data to skip by MAC_PTR. */
14474 case DW_MACINFO_vendor_ext:
14475 /* Only skip the data by MAC_PTR. */
14477 unsigned int bytes_read;
14479 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14480 mac_ptr += bytes_read;
14481 read_direct_string (abfd, mac_ptr, &bytes_read);
14482 mac_ptr += bytes_read;
14489 } while (macinfo_type != 0 && current_file == NULL);
14491 /* Second pass: Process all entries.
14493 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14494 command-line macro definitions/undefinitions. This flag is unset when we
14495 reach the first DW_MACINFO_start_file entry. */
14497 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14499 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14500 GDB is still reading the definitions from command line. First
14501 DW_MACINFO_start_file will need to be ignored as it was already executed
14502 to create CURRENT_FILE for the main source holding also the command line
14503 definitions. On first met DW_MACINFO_start_file this flag is reset to
14504 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14506 at_commandline = 1;
14510 /* Do we at least have room for a macinfo type byte? */
14511 if (mac_ptr >= mac_end)
14513 dwarf2_macros_too_long_complaint ();
14517 macinfo_type = read_1_byte (abfd, mac_ptr);
14520 switch (macinfo_type)
14522 /* A zero macinfo type indicates the end of the macro
14527 case DW_MACINFO_define:
14528 case DW_MACINFO_undef:
14530 unsigned int bytes_read;
14534 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14535 mac_ptr += bytes_read;
14536 body = read_direct_string (abfd, mac_ptr, &bytes_read);
14537 mac_ptr += bytes_read;
14539 if (! current_file)
14541 /* DWARF violation as no main source is present. */
14542 complaint (&symfile_complaints,
14543 _("debug info with no main source gives macro %s "
14545 macinfo_type == DW_MACINFO_define ?
14547 macinfo_type == DW_MACINFO_undef ?
14548 _("undefinition") :
14549 _("something-or-other"), line, body);
14552 if ((line == 0 && !at_commandline)
14553 || (line != 0 && at_commandline))
14554 complaint (&symfile_complaints,
14555 _("debug info gives %s macro %s with %s line %d: %s"),
14556 at_commandline ? _("command-line") : _("in-file"),
14557 macinfo_type == DW_MACINFO_define ?
14559 macinfo_type == DW_MACINFO_undef ?
14560 _("undefinition") :
14561 _("something-or-other"),
14562 line == 0 ? _("zero") : _("non-zero"), line, body);
14564 if (macinfo_type == DW_MACINFO_define)
14565 parse_macro_definition (current_file, line, body);
14566 else if (macinfo_type == DW_MACINFO_undef)
14567 macro_undef (current_file, line, body);
14571 case DW_MACINFO_start_file:
14573 unsigned int bytes_read;
14576 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14577 mac_ptr += bytes_read;
14578 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14579 mac_ptr += bytes_read;
14581 if ((line == 0 && !at_commandline)
14582 || (line != 0 && at_commandline))
14583 complaint (&symfile_complaints,
14584 _("debug info gives source %d included "
14585 "from %s at %s line %d"),
14586 file, at_commandline ? _("command-line") : _("file"),
14587 line == 0 ? _("zero") : _("non-zero"), line);
14589 if (at_commandline)
14591 /* This DW_MACINFO_start_file was executed in the pass one. */
14592 at_commandline = 0;
14595 current_file = macro_start_file (file, line,
14596 current_file, comp_dir,
14601 case DW_MACINFO_end_file:
14602 if (! current_file)
14603 complaint (&symfile_complaints,
14604 _("macro debug info has an unmatched "
14605 "`close_file' directive"));
14608 current_file = current_file->included_by;
14609 if (! current_file)
14611 enum dwarf_macinfo_record_type next_type;
14613 /* GCC circa March 2002 doesn't produce the zero
14614 type byte marking the end of the compilation
14615 unit. Complain if it's not there, but exit no
14618 /* Do we at least have room for a macinfo type byte? */
14619 if (mac_ptr >= mac_end)
14621 dwarf2_macros_too_long_complaint ();
14625 /* We don't increment mac_ptr here, so this is just
14627 next_type = read_1_byte (abfd, mac_ptr);
14628 if (next_type != 0)
14629 complaint (&symfile_complaints,
14630 _("no terminating 0-type entry for "
14631 "macros in `.debug_macinfo' section"));
14638 case DW_MACINFO_vendor_ext:
14640 unsigned int bytes_read;
14643 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14644 mac_ptr += bytes_read;
14645 read_direct_string (abfd, mac_ptr, &bytes_read);
14646 mac_ptr += bytes_read;
14648 /* We don't recognize any vendor extensions. */
14652 } while (macinfo_type != 0);
14655 /* Check if the attribute's form is a DW_FORM_block*
14656 if so return true else false. */
14658 attr_form_is_block (struct attribute *attr)
14660 return (attr == NULL ? 0 :
14661 attr->form == DW_FORM_block1
14662 || attr->form == DW_FORM_block2
14663 || attr->form == DW_FORM_block4
14664 || attr->form == DW_FORM_block
14665 || attr->form == DW_FORM_exprloc);
14668 /* Return non-zero if ATTR's value is a section offset --- classes
14669 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14670 You may use DW_UNSND (attr) to retrieve such offsets.
14672 Section 7.5.4, "Attribute Encodings", explains that no attribute
14673 may have a value that belongs to more than one of these classes; it
14674 would be ambiguous if we did, because we use the same forms for all
14677 attr_form_is_section_offset (struct attribute *attr)
14679 return (attr->form == DW_FORM_data4
14680 || attr->form == DW_FORM_data8
14681 || attr->form == DW_FORM_sec_offset);
14685 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14686 zero otherwise. When this function returns true, you can apply
14687 dwarf2_get_attr_constant_value to it.
14689 However, note that for some attributes you must check
14690 attr_form_is_section_offset before using this test. DW_FORM_data4
14691 and DW_FORM_data8 are members of both the constant class, and of
14692 the classes that contain offsets into other debug sections
14693 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14694 that, if an attribute's can be either a constant or one of the
14695 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14696 taken as section offsets, not constants. */
14698 attr_form_is_constant (struct attribute *attr)
14700 switch (attr->form)
14702 case DW_FORM_sdata:
14703 case DW_FORM_udata:
14704 case DW_FORM_data1:
14705 case DW_FORM_data2:
14706 case DW_FORM_data4:
14707 case DW_FORM_data8:
14714 /* A helper function that fills in a dwarf2_loclist_baton. */
14717 fill_in_loclist_baton (struct dwarf2_cu *cu,
14718 struct dwarf2_loclist_baton *baton,
14719 struct attribute *attr)
14721 dwarf2_read_section (dwarf2_per_objfile->objfile,
14722 &dwarf2_per_objfile->loc);
14724 baton->per_cu = cu->per_cu;
14725 gdb_assert (baton->per_cu);
14726 /* We don't know how long the location list is, but make sure we
14727 don't run off the edge of the section. */
14728 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
14729 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
14730 baton->base_address = cu->base_address;
14734 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
14735 struct dwarf2_cu *cu)
14737 if (attr_form_is_section_offset (attr)
14738 /* ".debug_loc" may not exist at all, or the offset may be outside
14739 the section. If so, fall through to the complaint in the
14741 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
14742 &dwarf2_per_objfile->loc))
14744 struct dwarf2_loclist_baton *baton;
14746 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14747 sizeof (struct dwarf2_loclist_baton));
14749 fill_in_loclist_baton (cu, baton, attr);
14751 if (cu->base_known == 0)
14752 complaint (&symfile_complaints,
14753 _("Location list used without "
14754 "specifying the CU base address."));
14756 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
14757 SYMBOL_LOCATION_BATON (sym) = baton;
14761 struct dwarf2_locexpr_baton *baton;
14763 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14764 sizeof (struct dwarf2_locexpr_baton));
14765 baton->per_cu = cu->per_cu;
14766 gdb_assert (baton->per_cu);
14768 if (attr_form_is_block (attr))
14770 /* Note that we're just copying the block's data pointer
14771 here, not the actual data. We're still pointing into the
14772 info_buffer for SYM's objfile; right now we never release
14773 that buffer, but when we do clean up properly this may
14775 baton->size = DW_BLOCK (attr)->size;
14776 baton->data = DW_BLOCK (attr)->data;
14780 dwarf2_invalid_attrib_class_complaint ("location description",
14781 SYMBOL_NATURAL_NAME (sym));
14783 baton->data = NULL;
14786 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
14787 SYMBOL_LOCATION_BATON (sym) = baton;
14791 /* Return the OBJFILE associated with the compilation unit CU. If CU
14792 came from a separate debuginfo file, then the master objfile is
14796 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
14798 struct objfile *objfile = per_cu->objfile;
14800 /* Return the master objfile, so that we can report and look up the
14801 correct file containing this variable. */
14802 if (objfile->separate_debug_objfile_backlink)
14803 objfile = objfile->separate_debug_objfile_backlink;
14808 /* Return the address size given in the compilation unit header for CU. */
14811 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
14814 return per_cu->cu->header.addr_size;
14817 /* If the CU is not currently read in, we re-read its header. */
14818 struct objfile *objfile = per_cu->objfile;
14819 struct dwarf2_per_objfile *per_objfile
14820 = objfile_data (objfile, dwarf2_objfile_data_key);
14821 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14822 struct comp_unit_head cu_header;
14824 memset (&cu_header, 0, sizeof cu_header);
14825 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14826 return cu_header.addr_size;
14830 /* Return the offset size given in the compilation unit header for CU. */
14833 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
14836 return per_cu->cu->header.offset_size;
14839 /* If the CU is not currently read in, we re-read its header. */
14840 struct objfile *objfile = per_cu->objfile;
14841 struct dwarf2_per_objfile *per_objfile
14842 = objfile_data (objfile, dwarf2_objfile_data_key);
14843 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14844 struct comp_unit_head cu_header;
14846 memset (&cu_header, 0, sizeof cu_header);
14847 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14848 return cu_header.offset_size;
14852 /* Return the text offset of the CU. The returned offset comes from
14853 this CU's objfile. If this objfile came from a separate debuginfo
14854 file, then the offset may be different from the corresponding
14855 offset in the parent objfile. */
14858 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
14860 struct objfile *objfile = per_cu->objfile;
14862 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14865 /* Locate the .debug_info compilation unit from CU's objfile which contains
14866 the DIE at OFFSET. Raises an error on failure. */
14868 static struct dwarf2_per_cu_data *
14869 dwarf2_find_containing_comp_unit (unsigned int offset,
14870 struct objfile *objfile)
14872 struct dwarf2_per_cu_data *this_cu;
14876 high = dwarf2_per_objfile->n_comp_units - 1;
14879 int mid = low + (high - low) / 2;
14881 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
14886 gdb_assert (low == high);
14887 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
14890 error (_("Dwarf Error: could not find partial DIE containing "
14891 "offset 0x%lx [in module %s]"),
14892 (long) offset, bfd_get_filename (objfile->obfd));
14894 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
14895 return dwarf2_per_objfile->all_comp_units[low-1];
14899 this_cu = dwarf2_per_objfile->all_comp_units[low];
14900 if (low == dwarf2_per_objfile->n_comp_units - 1
14901 && offset >= this_cu->offset + this_cu->length)
14902 error (_("invalid dwarf2 offset %u"), offset);
14903 gdb_assert (offset < this_cu->offset + this_cu->length);
14908 /* Locate the compilation unit from OBJFILE which is located at exactly
14909 OFFSET. Raises an error on failure. */
14911 static struct dwarf2_per_cu_data *
14912 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
14914 struct dwarf2_per_cu_data *this_cu;
14916 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
14917 if (this_cu->offset != offset)
14918 error (_("no compilation unit with offset %u."), offset);
14922 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14925 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
14927 memset (cu, 0, sizeof (*cu));
14928 cu->objfile = objfile;
14929 obstack_init (&cu->comp_unit_obstack);
14932 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14935 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
14937 struct attribute *attr;
14939 /* Set the language we're debugging. */
14940 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
14942 set_cu_language (DW_UNSND (attr), cu);
14945 cu->language = language_minimal;
14946 cu->language_defn = language_def (cu->language);
14950 /* Release one cached compilation unit, CU. We unlink it from the tree
14951 of compilation units, but we don't remove it from the read_in_chain;
14952 the caller is responsible for that.
14953 NOTE: DATA is a void * because this function is also used as a
14954 cleanup routine. */
14957 free_one_comp_unit (void *data)
14959 struct dwarf2_cu *cu = data;
14961 if (cu->per_cu != NULL)
14962 cu->per_cu->cu = NULL;
14965 obstack_free (&cu->comp_unit_obstack, NULL);
14970 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14971 when we're finished with it. We can't free the pointer itself, but be
14972 sure to unlink it from the cache. Also release any associated storage
14973 and perform cache maintenance.
14975 Only used during partial symbol parsing. */
14978 free_stack_comp_unit (void *data)
14980 struct dwarf2_cu *cu = data;
14982 obstack_free (&cu->comp_unit_obstack, NULL);
14983 cu->partial_dies = NULL;
14985 if (cu->per_cu != NULL)
14987 /* This compilation unit is on the stack in our caller, so we
14988 should not xfree it. Just unlink it. */
14989 cu->per_cu->cu = NULL;
14992 /* If we had a per-cu pointer, then we may have other compilation
14993 units loaded, so age them now. */
14994 age_cached_comp_units ();
14998 /* Free all cached compilation units. */
15001 free_cached_comp_units (void *data)
15003 struct dwarf2_per_cu_data *per_cu, **last_chain;
15005 per_cu = dwarf2_per_objfile->read_in_chain;
15006 last_chain = &dwarf2_per_objfile->read_in_chain;
15007 while (per_cu != NULL)
15009 struct dwarf2_per_cu_data *next_cu;
15011 next_cu = per_cu->cu->read_in_chain;
15013 free_one_comp_unit (per_cu->cu);
15014 *last_chain = next_cu;
15020 /* Increase the age counter on each cached compilation unit, and free
15021 any that are too old. */
15024 age_cached_comp_units (void)
15026 struct dwarf2_per_cu_data *per_cu, **last_chain;
15028 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15029 per_cu = dwarf2_per_objfile->read_in_chain;
15030 while (per_cu != NULL)
15032 per_cu->cu->last_used ++;
15033 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15034 dwarf2_mark (per_cu->cu);
15035 per_cu = per_cu->cu->read_in_chain;
15038 per_cu = dwarf2_per_objfile->read_in_chain;
15039 last_chain = &dwarf2_per_objfile->read_in_chain;
15040 while (per_cu != NULL)
15042 struct dwarf2_per_cu_data *next_cu;
15044 next_cu = per_cu->cu->read_in_chain;
15046 if (!per_cu->cu->mark)
15048 free_one_comp_unit (per_cu->cu);
15049 *last_chain = next_cu;
15052 last_chain = &per_cu->cu->read_in_chain;
15058 /* Remove a single compilation unit from the cache. */
15061 free_one_cached_comp_unit (void *target_cu)
15063 struct dwarf2_per_cu_data *per_cu, **last_chain;
15065 per_cu = dwarf2_per_objfile->read_in_chain;
15066 last_chain = &dwarf2_per_objfile->read_in_chain;
15067 while (per_cu != NULL)
15069 struct dwarf2_per_cu_data *next_cu;
15071 next_cu = per_cu->cu->read_in_chain;
15073 if (per_cu->cu == target_cu)
15075 free_one_comp_unit (per_cu->cu);
15076 *last_chain = next_cu;
15080 last_chain = &per_cu->cu->read_in_chain;
15086 /* Release all extra memory associated with OBJFILE. */
15089 dwarf2_free_objfile (struct objfile *objfile)
15091 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15093 if (dwarf2_per_objfile == NULL)
15096 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15097 free_cached_comp_units (NULL);
15099 if (dwarf2_per_objfile->quick_file_names_table)
15100 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15102 /* Everything else should be on the objfile obstack. */
15105 /* A pair of DIE offset and GDB type pointer. We store these
15106 in a hash table separate from the DIEs, and preserve them
15107 when the DIEs are flushed out of cache. */
15109 struct dwarf2_offset_and_type
15111 unsigned int offset;
15115 /* Hash function for a dwarf2_offset_and_type. */
15118 offset_and_type_hash (const void *item)
15120 const struct dwarf2_offset_and_type *ofs = item;
15122 return ofs->offset;
15125 /* Equality function for a dwarf2_offset_and_type. */
15128 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15130 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15131 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15133 return ofs_lhs->offset == ofs_rhs->offset;
15136 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15137 table if necessary. For convenience, return TYPE.
15139 The DIEs reading must have careful ordering to:
15140 * Not cause infite loops trying to read in DIEs as a prerequisite for
15141 reading current DIE.
15142 * Not trying to dereference contents of still incompletely read in types
15143 while reading in other DIEs.
15144 * Enable referencing still incompletely read in types just by a pointer to
15145 the type without accessing its fields.
15147 Therefore caller should follow these rules:
15148 * Try to fetch any prerequisite types we may need to build this DIE type
15149 before building the type and calling set_die_type.
15150 * After building type call set_die_type for current DIE as soon as
15151 possible before fetching more types to complete the current type.
15152 * Make the type as complete as possible before fetching more types. */
15154 static struct type *
15155 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15157 struct dwarf2_offset_and_type **slot, ofs;
15158 struct objfile *objfile = cu->objfile;
15159 htab_t *type_hash_ptr;
15161 /* For Ada types, make sure that the gnat-specific data is always
15162 initialized (if not already set). There are a few types where
15163 we should not be doing so, because the type-specific area is
15164 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15165 where the type-specific area is used to store the floatformat).
15166 But this is not a problem, because the gnat-specific information
15167 is actually not needed for these types. */
15168 if (need_gnat_info (cu)
15169 && TYPE_CODE (type) != TYPE_CODE_FUNC
15170 && TYPE_CODE (type) != TYPE_CODE_FLT
15171 && !HAVE_GNAT_AUX_INFO (type))
15172 INIT_GNAT_SPECIFIC (type);
15174 if (cu->per_cu->from_debug_types)
15175 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
15177 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
15179 if (*type_hash_ptr == NULL)
15182 = htab_create_alloc_ex (127,
15183 offset_and_type_hash,
15184 offset_and_type_eq,
15186 &objfile->objfile_obstack,
15187 hashtab_obstack_allocate,
15188 dummy_obstack_deallocate);
15191 ofs.offset = die->offset;
15193 slot = (struct dwarf2_offset_and_type **)
15194 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
15196 complaint (&symfile_complaints,
15197 _("A problem internal to GDB: DIE 0x%x has type already set"),
15199 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
15204 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15205 table, or return NULL if the die does not have a saved type. */
15207 static struct type *
15208 get_die_type_at_offset (unsigned int offset,
15209 struct dwarf2_per_cu_data *per_cu)
15211 struct dwarf2_offset_and_type *slot, ofs;
15214 if (per_cu->from_debug_types)
15215 type_hash = dwarf2_per_objfile->debug_types_type_hash;
15217 type_hash = dwarf2_per_objfile->debug_info_type_hash;
15218 if (type_hash == NULL)
15221 ofs.offset = offset;
15222 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
15229 /* Look up the type for DIE in the appropriate type_hash table,
15230 or return NULL if DIE does not have a saved type. */
15232 static struct type *
15233 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
15235 return get_die_type_at_offset (die->offset, cu->per_cu);
15238 /* Add a dependence relationship from CU to REF_PER_CU. */
15241 dwarf2_add_dependence (struct dwarf2_cu *cu,
15242 struct dwarf2_per_cu_data *ref_per_cu)
15246 if (cu->dependencies == NULL)
15248 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
15249 NULL, &cu->comp_unit_obstack,
15250 hashtab_obstack_allocate,
15251 dummy_obstack_deallocate);
15253 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
15255 *slot = ref_per_cu;
15258 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15259 Set the mark field in every compilation unit in the
15260 cache that we must keep because we are keeping CU. */
15263 dwarf2_mark_helper (void **slot, void *data)
15265 struct dwarf2_per_cu_data *per_cu;
15267 per_cu = (struct dwarf2_per_cu_data *) *slot;
15268 if (per_cu->cu->mark)
15270 per_cu->cu->mark = 1;
15272 if (per_cu->cu->dependencies != NULL)
15273 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
15278 /* Set the mark field in CU and in every other compilation unit in the
15279 cache that we must keep because we are keeping CU. */
15282 dwarf2_mark (struct dwarf2_cu *cu)
15287 if (cu->dependencies != NULL)
15288 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
15292 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
15296 per_cu->cu->mark = 0;
15297 per_cu = per_cu->cu->read_in_chain;
15301 /* Trivial hash function for partial_die_info: the hash value of a DIE
15302 is its offset in .debug_info for this objfile. */
15305 partial_die_hash (const void *item)
15307 const struct partial_die_info *part_die = item;
15309 return part_die->offset;
15312 /* Trivial comparison function for partial_die_info structures: two DIEs
15313 are equal if they have the same offset. */
15316 partial_die_eq (const void *item_lhs, const void *item_rhs)
15318 const struct partial_die_info *part_die_lhs = item_lhs;
15319 const struct partial_die_info *part_die_rhs = item_rhs;
15321 return part_die_lhs->offset == part_die_rhs->offset;
15324 static struct cmd_list_element *set_dwarf2_cmdlist;
15325 static struct cmd_list_element *show_dwarf2_cmdlist;
15328 set_dwarf2_cmd (char *args, int from_tty)
15330 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
15334 show_dwarf2_cmd (char *args, int from_tty)
15336 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
15339 /* If section described by INFO was mmapped, munmap it now. */
15342 munmap_section_buffer (struct dwarf2_section_info *info)
15344 if (info->was_mmapped)
15347 intptr_t begin = (intptr_t) info->buffer;
15348 intptr_t map_begin = begin & ~(pagesize - 1);
15349 size_t map_length = info->size + begin - map_begin;
15351 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
15353 /* Without HAVE_MMAP, we should never be here to begin with. */
15354 gdb_assert_not_reached ("no mmap support");
15359 /* munmap debug sections for OBJFILE, if necessary. */
15362 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
15364 struct dwarf2_per_objfile *data = d;
15366 /* This is sorted according to the order they're defined in to make it easier
15367 to keep in sync. */
15368 munmap_section_buffer (&data->info);
15369 munmap_section_buffer (&data->abbrev);
15370 munmap_section_buffer (&data->line);
15371 munmap_section_buffer (&data->loc);
15372 munmap_section_buffer (&data->macinfo);
15373 munmap_section_buffer (&data->str);
15374 munmap_section_buffer (&data->ranges);
15375 munmap_section_buffer (&data->types);
15376 munmap_section_buffer (&data->frame);
15377 munmap_section_buffer (&data->eh_frame);
15378 munmap_section_buffer (&data->gdb_index);
15382 /* The "save gdb-index" command. */
15384 /* The contents of the hash table we create when building the string
15386 struct strtab_entry
15388 offset_type offset;
15392 /* Hash function for a strtab_entry.
15394 Function is used only during write_hash_table so no index format backward
15395 compatibility is needed. */
15398 hash_strtab_entry (const void *e)
15400 const struct strtab_entry *entry = e;
15401 return mapped_index_string_hash (INT_MAX, entry->str);
15404 /* Equality function for a strtab_entry. */
15407 eq_strtab_entry (const void *a, const void *b)
15409 const struct strtab_entry *ea = a;
15410 const struct strtab_entry *eb = b;
15411 return !strcmp (ea->str, eb->str);
15414 /* Create a strtab_entry hash table. */
15417 create_strtab (void)
15419 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
15420 xfree, xcalloc, xfree);
15423 /* Add a string to the constant pool. Return the string's offset in
15427 add_string (htab_t table, struct obstack *cpool, const char *str)
15430 struct strtab_entry entry;
15431 struct strtab_entry *result;
15434 slot = htab_find_slot (table, &entry, INSERT);
15439 result = XNEW (struct strtab_entry);
15440 result->offset = obstack_object_size (cpool);
15442 obstack_grow_str0 (cpool, str);
15445 return result->offset;
15448 /* An entry in the symbol table. */
15449 struct symtab_index_entry
15451 /* The name of the symbol. */
15453 /* The offset of the name in the constant pool. */
15454 offset_type index_offset;
15455 /* A sorted vector of the indices of all the CUs that hold an object
15457 VEC (offset_type) *cu_indices;
15460 /* The symbol table. This is a power-of-2-sized hash table. */
15461 struct mapped_symtab
15463 offset_type n_elements;
15465 struct symtab_index_entry **data;
15468 /* Hash function for a symtab_index_entry. */
15471 hash_symtab_entry (const void *e)
15473 const struct symtab_index_entry *entry = e;
15474 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
15475 sizeof (offset_type) * VEC_length (offset_type,
15476 entry->cu_indices),
15480 /* Equality function for a symtab_index_entry. */
15483 eq_symtab_entry (const void *a, const void *b)
15485 const struct symtab_index_entry *ea = a;
15486 const struct symtab_index_entry *eb = b;
15487 int len = VEC_length (offset_type, ea->cu_indices);
15488 if (len != VEC_length (offset_type, eb->cu_indices))
15490 return !memcmp (VEC_address (offset_type, ea->cu_indices),
15491 VEC_address (offset_type, eb->cu_indices),
15492 sizeof (offset_type) * len);
15495 /* Destroy a symtab_index_entry. */
15498 delete_symtab_entry (void *p)
15500 struct symtab_index_entry *entry = p;
15501 VEC_free (offset_type, entry->cu_indices);
15505 /* Create a hash table holding symtab_index_entry objects. */
15508 create_symbol_hash_table (void)
15510 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
15511 delete_symtab_entry, xcalloc, xfree);
15514 /* Create a new mapped symtab object. */
15516 static struct mapped_symtab *
15517 create_mapped_symtab (void)
15519 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
15520 symtab->n_elements = 0;
15521 symtab->size = 1024;
15522 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15526 /* Destroy a mapped_symtab. */
15529 cleanup_mapped_symtab (void *p)
15531 struct mapped_symtab *symtab = p;
15532 /* The contents of the array are freed when the other hash table is
15534 xfree (symtab->data);
15538 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15541 Function is used only during write_hash_table so no index format backward
15542 compatibility is needed. */
15544 static struct symtab_index_entry **
15545 find_slot (struct mapped_symtab *symtab, const char *name)
15547 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
15549 index = hash & (symtab->size - 1);
15550 step = ((hash * 17) & (symtab->size - 1)) | 1;
15554 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
15555 return &symtab->data[index];
15556 index = (index + step) & (symtab->size - 1);
15560 /* Expand SYMTAB's hash table. */
15563 hash_expand (struct mapped_symtab *symtab)
15565 offset_type old_size = symtab->size;
15567 struct symtab_index_entry **old_entries = symtab->data;
15570 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15572 for (i = 0; i < old_size; ++i)
15574 if (old_entries[i])
15576 struct symtab_index_entry **slot = find_slot (symtab,
15577 old_entries[i]->name);
15578 *slot = old_entries[i];
15582 xfree (old_entries);
15585 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15586 is the index of the CU in which the symbol appears. */
15589 add_index_entry (struct mapped_symtab *symtab, const char *name,
15590 offset_type cu_index)
15592 struct symtab_index_entry **slot;
15594 ++symtab->n_elements;
15595 if (4 * symtab->n_elements / 3 >= symtab->size)
15596 hash_expand (symtab);
15598 slot = find_slot (symtab, name);
15601 *slot = XNEW (struct symtab_index_entry);
15602 (*slot)->name = name;
15603 (*slot)->cu_indices = NULL;
15605 /* Don't push an index twice. Due to how we add entries we only
15606 have to check the last one. */
15607 if (VEC_empty (offset_type, (*slot)->cu_indices)
15608 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
15609 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
15612 /* Add a vector of indices to the constant pool. */
15615 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
15616 struct symtab_index_entry *entry)
15620 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
15623 offset_type len = VEC_length (offset_type, entry->cu_indices);
15624 offset_type val = MAYBE_SWAP (len);
15629 entry->index_offset = obstack_object_size (cpool);
15631 obstack_grow (cpool, &val, sizeof (val));
15633 VEC_iterate (offset_type, entry->cu_indices, i, iter);
15636 val = MAYBE_SWAP (iter);
15637 obstack_grow (cpool, &val, sizeof (val));
15642 struct symtab_index_entry *old_entry = *slot;
15643 entry->index_offset = old_entry->index_offset;
15646 return entry->index_offset;
15649 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15650 constant pool entries going into the obstack CPOOL. */
15653 write_hash_table (struct mapped_symtab *symtab,
15654 struct obstack *output, struct obstack *cpool)
15657 htab_t symbol_hash_table;
15660 symbol_hash_table = create_symbol_hash_table ();
15661 str_table = create_strtab ();
15663 /* We add all the index vectors to the constant pool first, to
15664 ensure alignment is ok. */
15665 for (i = 0; i < symtab->size; ++i)
15667 if (symtab->data[i])
15668 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
15671 /* Now write out the hash table. */
15672 for (i = 0; i < symtab->size; ++i)
15674 offset_type str_off, vec_off;
15676 if (symtab->data[i])
15678 str_off = add_string (str_table, cpool, symtab->data[i]->name);
15679 vec_off = symtab->data[i]->index_offset;
15683 /* While 0 is a valid constant pool index, it is not valid
15684 to have 0 for both offsets. */
15689 str_off = MAYBE_SWAP (str_off);
15690 vec_off = MAYBE_SWAP (vec_off);
15692 obstack_grow (output, &str_off, sizeof (str_off));
15693 obstack_grow (output, &vec_off, sizeof (vec_off));
15696 htab_delete (str_table);
15697 htab_delete (symbol_hash_table);
15700 /* Struct to map psymtab to CU index in the index file. */
15701 struct psymtab_cu_index_map
15703 struct partial_symtab *psymtab;
15704 unsigned int cu_index;
15708 hash_psymtab_cu_index (const void *item)
15710 const struct psymtab_cu_index_map *map = item;
15712 return htab_hash_pointer (map->psymtab);
15716 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
15718 const struct psymtab_cu_index_map *lhs = item_lhs;
15719 const struct psymtab_cu_index_map *rhs = item_rhs;
15721 return lhs->psymtab == rhs->psymtab;
15724 /* Helper struct for building the address table. */
15725 struct addrmap_index_data
15727 struct objfile *objfile;
15728 struct obstack *addr_obstack;
15729 htab_t cu_index_htab;
15731 /* Non-zero if the previous_* fields are valid.
15732 We can't write an entry until we see the next entry (since it is only then
15733 that we know the end of the entry). */
15734 int previous_valid;
15735 /* Index of the CU in the table of all CUs in the index file. */
15736 unsigned int previous_cu_index;
15737 /* Start address of the CU. */
15738 CORE_ADDR previous_cu_start;
15741 /* Write an address entry to OBSTACK. */
15744 add_address_entry (struct objfile *objfile, struct obstack *obstack,
15745 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
15747 offset_type cu_index_to_write;
15749 CORE_ADDR baseaddr;
15751 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15753 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
15754 obstack_grow (obstack, addr, 8);
15755 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
15756 obstack_grow (obstack, addr, 8);
15757 cu_index_to_write = MAYBE_SWAP (cu_index);
15758 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
15761 /* Worker function for traversing an addrmap to build the address table. */
15764 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
15766 struct addrmap_index_data *data = datap;
15767 struct partial_symtab *pst = obj;
15768 offset_type cu_index;
15771 if (data->previous_valid)
15772 add_address_entry (data->objfile, data->addr_obstack,
15773 data->previous_cu_start, start_addr,
15774 data->previous_cu_index);
15776 data->previous_cu_start = start_addr;
15779 struct psymtab_cu_index_map find_map, *map;
15780 find_map.psymtab = pst;
15781 map = htab_find (data->cu_index_htab, &find_map);
15782 gdb_assert (map != NULL);
15783 data->previous_cu_index = map->cu_index;
15784 data->previous_valid = 1;
15787 data->previous_valid = 0;
15792 /* Write OBJFILE's address map to OBSTACK.
15793 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15794 in the index file. */
15797 write_address_map (struct objfile *objfile, struct obstack *obstack,
15798 htab_t cu_index_htab)
15800 struct addrmap_index_data addrmap_index_data;
15802 /* When writing the address table, we have to cope with the fact that
15803 the addrmap iterator only provides the start of a region; we have to
15804 wait until the next invocation to get the start of the next region. */
15806 addrmap_index_data.objfile = objfile;
15807 addrmap_index_data.addr_obstack = obstack;
15808 addrmap_index_data.cu_index_htab = cu_index_htab;
15809 addrmap_index_data.previous_valid = 0;
15811 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
15812 &addrmap_index_data);
15814 /* It's highly unlikely the last entry (end address = 0xff...ff)
15815 is valid, but we should still handle it.
15816 The end address is recorded as the start of the next region, but that
15817 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15819 if (addrmap_index_data.previous_valid)
15820 add_address_entry (objfile, obstack,
15821 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
15822 addrmap_index_data.previous_cu_index);
15825 /* Add a list of partial symbols to SYMTAB. */
15828 write_psymbols (struct mapped_symtab *symtab,
15830 struct partial_symbol **psymp,
15832 offset_type cu_index,
15835 for (; count-- > 0; ++psymp)
15837 void **slot, *lookup;
15839 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
15840 error (_("Ada is not currently supported by the index"));
15842 /* We only want to add a given psymbol once. However, we also
15843 want to account for whether it is global or static. So, we
15844 may add it twice, using slightly different values. */
15847 uintptr_t val = 1 | (uintptr_t) *psymp;
15849 lookup = (void *) val;
15854 /* Only add a given psymbol once. */
15855 slot = htab_find_slot (psyms_seen, lookup, INSERT);
15859 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
15864 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15865 exception if there is an error. */
15868 write_obstack (FILE *file, struct obstack *obstack)
15870 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
15872 != obstack_object_size (obstack))
15873 error (_("couldn't data write to file"));
15876 /* Unlink a file if the argument is not NULL. */
15879 unlink_if_set (void *p)
15881 char **filename = p;
15883 unlink (*filename);
15886 /* A helper struct used when iterating over debug_types. */
15887 struct signatured_type_index_data
15889 struct objfile *objfile;
15890 struct mapped_symtab *symtab;
15891 struct obstack *types_list;
15896 /* A helper function that writes a single signatured_type to an
15900 write_one_signatured_type (void **slot, void *d)
15902 struct signatured_type_index_data *info = d;
15903 struct signatured_type *entry = (struct signatured_type *) *slot;
15904 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
15905 struct partial_symtab *psymtab = per_cu->v.psymtab;
15908 write_psymbols (info->symtab,
15910 info->objfile->global_psymbols.list
15911 + psymtab->globals_offset,
15912 psymtab->n_global_syms, info->cu_index,
15914 write_psymbols (info->symtab,
15916 info->objfile->static_psymbols.list
15917 + psymtab->statics_offset,
15918 psymtab->n_static_syms, info->cu_index,
15921 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
15922 obstack_grow (info->types_list, val, 8);
15923 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
15924 obstack_grow (info->types_list, val, 8);
15925 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
15926 obstack_grow (info->types_list, val, 8);
15933 /* A cleanup function for an htab_t. */
15936 cleanup_htab (void *arg)
15941 /* Create an index file for OBJFILE in the directory DIR. */
15944 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
15946 struct cleanup *cleanup;
15947 char *filename, *cleanup_filename;
15948 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
15949 struct obstack cu_list, types_cu_list;
15952 struct mapped_symtab *symtab;
15953 offset_type val, size_of_contents, total_len;
15957 htab_t cu_index_htab;
15958 struct psymtab_cu_index_map *psymtab_cu_index_map;
15960 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
15963 if (dwarf2_per_objfile->using_index)
15964 error (_("Cannot use an index to create the index"));
15966 if (stat (objfile->name, &st) < 0)
15967 perror_with_name (objfile->name);
15969 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
15970 INDEX_SUFFIX, (char *) NULL);
15971 cleanup = make_cleanup (xfree, filename);
15973 out_file = fopen (filename, "wb");
15975 error (_("Can't open `%s' for writing"), filename);
15977 cleanup_filename = filename;
15978 make_cleanup (unlink_if_set, &cleanup_filename);
15980 symtab = create_mapped_symtab ();
15981 make_cleanup (cleanup_mapped_symtab, symtab);
15983 obstack_init (&addr_obstack);
15984 make_cleanup_obstack_free (&addr_obstack);
15986 obstack_init (&cu_list);
15987 make_cleanup_obstack_free (&cu_list);
15989 obstack_init (&types_cu_list);
15990 make_cleanup_obstack_free (&types_cu_list);
15992 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
15993 NULL, xcalloc, xfree);
15994 make_cleanup (cleanup_htab, psyms_seen);
15996 /* While we're scanning CU's create a table that maps a psymtab pointer
15997 (which is what addrmap records) to its index (which is what is recorded
15998 in the index file). This will later be needed to write the address
16000 cu_index_htab = htab_create_alloc (100,
16001 hash_psymtab_cu_index,
16002 eq_psymtab_cu_index,
16003 NULL, xcalloc, xfree);
16004 make_cleanup (cleanup_htab, cu_index_htab);
16005 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16006 xmalloc (sizeof (struct psymtab_cu_index_map)
16007 * dwarf2_per_objfile->n_comp_units);
16008 make_cleanup (xfree, psymtab_cu_index_map);
16010 /* The CU list is already sorted, so we don't need to do additional
16011 work here. Also, the debug_types entries do not appear in
16012 all_comp_units, but only in their own hash table. */
16013 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16015 struct dwarf2_per_cu_data *per_cu
16016 = dwarf2_per_objfile->all_comp_units[i];
16017 struct partial_symtab *psymtab = per_cu->v.psymtab;
16019 struct psymtab_cu_index_map *map;
16022 write_psymbols (symtab,
16024 objfile->global_psymbols.list + psymtab->globals_offset,
16025 psymtab->n_global_syms, i,
16027 write_psymbols (symtab,
16029 objfile->static_psymbols.list + psymtab->statics_offset,
16030 psymtab->n_static_syms, i,
16033 map = &psymtab_cu_index_map[i];
16034 map->psymtab = psymtab;
16036 slot = htab_find_slot (cu_index_htab, map, INSERT);
16037 gdb_assert (slot != NULL);
16038 gdb_assert (*slot == NULL);
16041 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16042 obstack_grow (&cu_list, val, 8);
16043 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16044 obstack_grow (&cu_list, val, 8);
16047 /* Dump the address map. */
16048 write_address_map (objfile, &addr_obstack, cu_index_htab);
16050 /* Write out the .debug_type entries, if any. */
16051 if (dwarf2_per_objfile->signatured_types)
16053 struct signatured_type_index_data sig_data;
16055 sig_data.objfile = objfile;
16056 sig_data.symtab = symtab;
16057 sig_data.types_list = &types_cu_list;
16058 sig_data.psyms_seen = psyms_seen;
16059 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
16060 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
16061 write_one_signatured_type, &sig_data);
16064 obstack_init (&constant_pool);
16065 make_cleanup_obstack_free (&constant_pool);
16066 obstack_init (&symtab_obstack);
16067 make_cleanup_obstack_free (&symtab_obstack);
16068 write_hash_table (symtab, &symtab_obstack, &constant_pool);
16070 obstack_init (&contents);
16071 make_cleanup_obstack_free (&contents);
16072 size_of_contents = 6 * sizeof (offset_type);
16073 total_len = size_of_contents;
16075 /* The version number. */
16076 val = MAYBE_SWAP (5);
16077 obstack_grow (&contents, &val, sizeof (val));
16079 /* The offset of the CU list from the start of the file. */
16080 val = MAYBE_SWAP (total_len);
16081 obstack_grow (&contents, &val, sizeof (val));
16082 total_len += obstack_object_size (&cu_list);
16084 /* The offset of the types CU list from the start of the file. */
16085 val = MAYBE_SWAP (total_len);
16086 obstack_grow (&contents, &val, sizeof (val));
16087 total_len += obstack_object_size (&types_cu_list);
16089 /* The offset of the address table from the start of the file. */
16090 val = MAYBE_SWAP (total_len);
16091 obstack_grow (&contents, &val, sizeof (val));
16092 total_len += obstack_object_size (&addr_obstack);
16094 /* The offset of the symbol table from the start of the file. */
16095 val = MAYBE_SWAP (total_len);
16096 obstack_grow (&contents, &val, sizeof (val));
16097 total_len += obstack_object_size (&symtab_obstack);
16099 /* The offset of the constant pool from the start of the file. */
16100 val = MAYBE_SWAP (total_len);
16101 obstack_grow (&contents, &val, sizeof (val));
16102 total_len += obstack_object_size (&constant_pool);
16104 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16106 write_obstack (out_file, &contents);
16107 write_obstack (out_file, &cu_list);
16108 write_obstack (out_file, &types_cu_list);
16109 write_obstack (out_file, &addr_obstack);
16110 write_obstack (out_file, &symtab_obstack);
16111 write_obstack (out_file, &constant_pool);
16115 /* We want to keep the file, so we set cleanup_filename to NULL
16116 here. See unlink_if_set. */
16117 cleanup_filename = NULL;
16119 do_cleanups (cleanup);
16122 /* Implementation of the `save gdb-index' command.
16124 Note that the file format used by this command is documented in the
16125 GDB manual. Any changes here must be documented there. */
16128 save_gdb_index_command (char *arg, int from_tty)
16130 struct objfile *objfile;
16133 error (_("usage: save gdb-index DIRECTORY"));
16135 ALL_OBJFILES (objfile)
16139 /* If the objfile does not correspond to an actual file, skip it. */
16140 if (stat (objfile->name, &st) < 0)
16143 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16144 if (dwarf2_per_objfile)
16146 volatile struct gdb_exception except;
16148 TRY_CATCH (except, RETURN_MASK_ERROR)
16150 write_psymtabs_to_index (objfile, arg);
16152 if (except.reason < 0)
16153 exception_fprintf (gdb_stderr, except,
16154 _("Error while writing index for `%s': "),
16162 int dwarf2_always_disassemble;
16165 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
16166 struct cmd_list_element *c, const char *value)
16168 fprintf_filtered (file,
16169 _("Whether to always disassemble "
16170 "DWARF expressions is %s.\n"),
16174 void _initialize_dwarf2_read (void);
16177 _initialize_dwarf2_read (void)
16179 struct cmd_list_element *c;
16181 dwarf2_objfile_data_key
16182 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
16184 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
16185 Set DWARF 2 specific variables.\n\
16186 Configure DWARF 2 variables such as the cache size"),
16187 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
16188 0/*allow-unknown*/, &maintenance_set_cmdlist);
16190 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
16191 Show DWARF 2 specific variables\n\
16192 Show DWARF 2 variables such as the cache size"),
16193 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
16194 0/*allow-unknown*/, &maintenance_show_cmdlist);
16196 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
16197 &dwarf2_max_cache_age, _("\
16198 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16199 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16200 A higher limit means that cached compilation units will be stored\n\
16201 in memory longer, and more total memory will be used. Zero disables\n\
16202 caching, which can slow down startup."),
16204 show_dwarf2_max_cache_age,
16205 &set_dwarf2_cmdlist,
16206 &show_dwarf2_cmdlist);
16208 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
16209 &dwarf2_always_disassemble, _("\
16210 Set whether `info address' always disassembles DWARF expressions."), _("\
16211 Show whether `info address' always disassembles DWARF expressions."), _("\
16212 When enabled, DWARF expressions are always printed in an assembly-like\n\
16213 syntax. When disabled, expressions will be printed in a more\n\
16214 conversational style, when possible."),
16216 show_dwarf2_always_disassemble,
16217 &set_dwarf2_cmdlist,
16218 &show_dwarf2_cmdlist);
16220 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
16221 Set debugging of the dwarf2 DIE reader."), _("\
16222 Show debugging of the dwarf2 DIE reader."), _("\
16223 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16224 The value is the maximum depth to print."),
16227 &setdebuglist, &showdebuglist);
16229 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
16231 Save a gdb-index file.\n\
16232 Usage: save gdb-index DIRECTORY"),
16234 set_cmd_completer (c, filename_completer);