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 /* Default 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 static const struct dwarf2_debug_sections dwarf2_elf_names = {
252 { ".debug_info", ".zdebug_info" },
253 { ".debug_abbrev", ".zdebug_abbrev" },
254 { ".debug_line", ".zdebug_line" },
255 { ".debug_loc", ".zdebug_loc" },
256 { ".debug_macinfo", ".zdebug_macinfo" },
257 { ".debug_str", ".zdebug_str" },
258 { ".debug_ranges", ".zdebug_ranges" },
259 { ".debug_types", ".zdebug_types" },
260 { ".debug_frame", ".zdebug_frame" },
261 { ".eh_frame", NULL },
262 { ".gdb_index", ".zgdb_index" }
265 /* local data types */
267 /* We hold several abbreviation tables in memory at the same time. */
268 #ifndef ABBREV_HASH_SIZE
269 #define ABBREV_HASH_SIZE 121
272 /* The data in a compilation unit header, after target2host
273 translation, looks like this. */
274 struct comp_unit_head
278 unsigned char addr_size;
279 unsigned char signed_addr_p;
280 unsigned int abbrev_offset;
282 /* Size of file offsets; either 4 or 8. */
283 unsigned int offset_size;
285 /* Size of the length field; either 4 or 12. */
286 unsigned int initial_length_size;
288 /* Offset to the first byte of this compilation unit header in the
289 .debug_info section, for resolving relative reference dies. */
292 /* Offset to first die in this cu from the start of the cu.
293 This will be the first byte following the compilation unit header. */
294 unsigned int first_die_offset;
297 /* Type used for delaying computation of method physnames.
298 See comments for compute_delayed_physnames. */
299 struct delayed_method_info
301 /* The type to which the method is attached, i.e., its parent class. */
304 /* The index of the method in the type's function fieldlists. */
307 /* The index of the method in the fieldlist. */
310 /* The name of the DIE. */
313 /* The DIE associated with this method. */
314 struct die_info *die;
317 typedef struct delayed_method_info delayed_method_info;
318 DEF_VEC_O (delayed_method_info);
320 /* Internal state when decoding a particular compilation unit. */
323 /* The objfile containing this compilation unit. */
324 struct objfile *objfile;
326 /* The header of the compilation unit. */
327 struct comp_unit_head header;
329 /* Base address of this compilation unit. */
330 CORE_ADDR base_address;
332 /* Non-zero if base_address has been set. */
335 struct function_range *first_fn, *last_fn, *cached_fn;
337 /* The language we are debugging. */
338 enum language language;
339 const struct language_defn *language_defn;
341 const char *producer;
343 /* The generic symbol table building routines have separate lists for
344 file scope symbols and all all other scopes (local scopes). So
345 we need to select the right one to pass to add_symbol_to_list().
346 We do it by keeping a pointer to the correct list in list_in_scope.
348 FIXME: The original dwarf code just treated the file scope as the
349 first local scope, and all other local scopes as nested local
350 scopes, and worked fine. Check to see if we really need to
351 distinguish these in buildsym.c. */
352 struct pending **list_in_scope;
354 /* DWARF abbreviation table associated with this compilation unit. */
355 struct abbrev_info **dwarf2_abbrevs;
357 /* Storage for the abbrev table. */
358 struct obstack abbrev_obstack;
360 /* Hash table holding all the loaded partial DIEs. */
363 /* Storage for things with the same lifetime as this read-in compilation
364 unit, including partial DIEs. */
365 struct obstack comp_unit_obstack;
367 /* When multiple dwarf2_cu structures are living in memory, this field
368 chains them all together, so that they can be released efficiently.
369 We will probably also want a generation counter so that most-recently-used
370 compilation units are cached... */
371 struct dwarf2_per_cu_data *read_in_chain;
373 /* Backchain to our per_cu entry if the tree has been built. */
374 struct dwarf2_per_cu_data *per_cu;
376 /* How many compilation units ago was this CU last referenced? */
379 /* A hash table of die offsets for following references. */
382 /* Full DIEs if read in. */
383 struct die_info *dies;
385 /* A set of pointers to dwarf2_per_cu_data objects for compilation
386 units referenced by this one. Only set during full symbol processing;
387 partial symbol tables do not have dependencies. */
390 /* Header data from the line table, during full symbol processing. */
391 struct line_header *line_header;
393 /* A list of methods which need to have physnames computed
394 after all type information has been read. */
395 VEC (delayed_method_info) *method_list;
397 /* Mark used when releasing cached dies. */
398 unsigned int mark : 1;
400 /* This flag will be set if this compilation unit might include
401 inter-compilation-unit references. */
402 unsigned int has_form_ref_addr : 1;
404 /* This flag will be set if this compilation unit includes any
405 DW_TAG_namespace DIEs. If we know that there are explicit
406 DIEs for namespaces, we don't need to try to infer them
407 from mangled names. */
408 unsigned int has_namespace_info : 1;
410 /* This CU references .debug_loc. See the symtab->locations_valid field.
411 This test is imperfect as there may exist optimized debug code not using
412 any location list and still facing inlining issues if handled as
413 unoptimized code. For a future better test see GCC PR other/32998. */
415 unsigned int has_loclist : 1;
418 /* Persistent data held for a compilation unit, even when not
419 processing it. We put a pointer to this structure in the
420 read_symtab_private field of the psymtab. If we encounter
421 inter-compilation-unit references, we also maintain a sorted
422 list of all compilation units. */
424 struct dwarf2_per_cu_data
426 /* The start offset and length of this compilation unit. 2**29-1
427 bytes should suffice to store the length of any compilation unit
428 - if it doesn't, GDB will fall over anyway.
429 NOTE: Unlike comp_unit_head.length, this length includes
430 initial_length_size. */
432 unsigned int length : 29;
434 /* Flag indicating this compilation unit will be read in before
435 any of the current compilation units are processed. */
436 unsigned int queued : 1;
438 /* This flag will be set if we need to load absolutely all DIEs
439 for this compilation unit, instead of just the ones we think
440 are interesting. It gets set if we look for a DIE in the
441 hash table and don't find it. */
442 unsigned int load_all_dies : 1;
444 /* Non-zero if this CU is from .debug_types.
445 Otherwise it's from .debug_info. */
446 unsigned int from_debug_types : 1;
448 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
449 of the CU cache it gets reset to NULL again. */
450 struct dwarf2_cu *cu;
452 /* The corresponding objfile. */
453 struct objfile *objfile;
455 /* When using partial symbol tables, the 'psymtab' field is active.
456 Otherwise the 'quick' field is active. */
459 /* The partial symbol table associated with this compilation unit,
460 or NULL for partial units (which do not have an associated
462 struct partial_symtab *psymtab;
464 /* Data needed by the "quick" functions. */
465 struct dwarf2_per_cu_quick_data *quick;
469 /* Entry in the signatured_types hash table. */
471 struct signatured_type
475 /* Offset in .debug_types of the type defined by this TU. */
476 unsigned int type_offset;
478 /* The CU(/TU) of this type. */
479 struct dwarf2_per_cu_data per_cu;
482 /* Struct used to pass misc. parameters to read_die_and_children, et
483 al. which are used for both .debug_info and .debug_types dies.
484 All parameters here are unchanging for the life of the call. This
485 struct exists to abstract away the constant parameters of die
488 struct die_reader_specs
490 /* The bfd of this objfile. */
493 /* The CU of the DIE we are parsing. */
494 struct dwarf2_cu *cu;
496 /* Pointer to start of section buffer.
497 This is either the start of .debug_info or .debug_types. */
498 const gdb_byte *buffer;
501 /* The line number information for a compilation unit (found in the
502 .debug_line section) begins with a "statement program header",
503 which contains the following information. */
506 unsigned int total_length;
507 unsigned short version;
508 unsigned int header_length;
509 unsigned char minimum_instruction_length;
510 unsigned char maximum_ops_per_instruction;
511 unsigned char default_is_stmt;
513 unsigned char line_range;
514 unsigned char opcode_base;
516 /* standard_opcode_lengths[i] is the number of operands for the
517 standard opcode whose value is i. This means that
518 standard_opcode_lengths[0] is unused, and the last meaningful
519 element is standard_opcode_lengths[opcode_base - 1]. */
520 unsigned char *standard_opcode_lengths;
522 /* The include_directories table. NOTE! These strings are not
523 allocated with xmalloc; instead, they are pointers into
524 debug_line_buffer. If you try to free them, `free' will get
526 unsigned int num_include_dirs, include_dirs_size;
529 /* The file_names table. NOTE! These strings are not allocated
530 with xmalloc; instead, they are pointers into debug_line_buffer.
531 Don't try to free them directly. */
532 unsigned int num_file_names, file_names_size;
536 unsigned int dir_index;
537 unsigned int mod_time;
539 int included_p; /* Non-zero if referenced by the Line Number Program. */
540 struct symtab *symtab; /* The associated symbol table, if any. */
543 /* The start and end of the statement program following this
544 header. These point into dwarf2_per_objfile->line_buffer. */
545 gdb_byte *statement_program_start, *statement_program_end;
548 /* When we construct a partial symbol table entry we only
549 need this much information. */
550 struct partial_die_info
552 /* Offset of this DIE. */
555 /* DWARF-2 tag for this DIE. */
556 ENUM_BITFIELD(dwarf_tag) tag : 16;
558 /* Assorted flags describing the data found in this DIE. */
559 unsigned int has_children : 1;
560 unsigned int is_external : 1;
561 unsigned int is_declaration : 1;
562 unsigned int has_type : 1;
563 unsigned int has_specification : 1;
564 unsigned int has_pc_info : 1;
566 /* Flag set if the SCOPE field of this structure has been
568 unsigned int scope_set : 1;
570 /* Flag set if the DIE has a byte_size attribute. */
571 unsigned int has_byte_size : 1;
573 /* Flag set if any of the DIE's children are template arguments. */
574 unsigned int has_template_arguments : 1;
576 /* Flag set if fixup_partial_die has been called on this die. */
577 unsigned int fixup_called : 1;
579 /* The name of this DIE. Normally the value of DW_AT_name, but
580 sometimes a default name for unnamed DIEs. */
583 /* The linkage name, if present. */
584 const char *linkage_name;
586 /* The scope to prepend to our children. This is generally
587 allocated on the comp_unit_obstack, so will disappear
588 when this compilation unit leaves the cache. */
591 /* The location description associated with this DIE, if any. */
592 struct dwarf_block *locdesc;
594 /* If HAS_PC_INFO, the PC range associated with this DIE. */
598 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
599 DW_AT_sibling, if any. */
600 /* NOTE: This member isn't strictly necessary, read_partial_die could
601 return DW_AT_sibling values to its caller load_partial_dies. */
604 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
605 DW_AT_specification (or DW_AT_abstract_origin or
607 unsigned int spec_offset;
609 /* Pointers to this DIE's parent, first child, and next sibling,
611 struct partial_die_info *die_parent, *die_child, *die_sibling;
614 /* This data structure holds the information of an abbrev. */
617 unsigned int number; /* number identifying abbrev */
618 enum dwarf_tag tag; /* dwarf tag */
619 unsigned short has_children; /* boolean */
620 unsigned short num_attrs; /* number of attributes */
621 struct attr_abbrev *attrs; /* an array of attribute descriptions */
622 struct abbrev_info *next; /* next in chain */
627 ENUM_BITFIELD(dwarf_attribute) name : 16;
628 ENUM_BITFIELD(dwarf_form) form : 16;
631 /* Attributes have a name and a value. */
634 ENUM_BITFIELD(dwarf_attribute) name : 16;
635 ENUM_BITFIELD(dwarf_form) form : 15;
637 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
638 field should be in u.str (existing only for DW_STRING) but it is kept
639 here for better struct attribute alignment. */
640 unsigned int string_is_canonical : 1;
645 struct dwarf_block *blk;
649 struct signatured_type *signatured_type;
654 /* This data structure holds a complete die structure. */
657 /* DWARF-2 tag for this DIE. */
658 ENUM_BITFIELD(dwarf_tag) tag : 16;
660 /* Number of attributes */
661 unsigned char num_attrs;
663 /* True if we're presently building the full type name for the
664 type derived from this DIE. */
665 unsigned char building_fullname : 1;
670 /* Offset in .debug_info or .debug_types section. */
673 /* The dies in a compilation unit form an n-ary tree. PARENT
674 points to this die's parent; CHILD points to the first child of
675 this node; and all the children of a given node are chained
676 together via their SIBLING fields. */
677 struct die_info *child; /* Its first child, if any. */
678 struct die_info *sibling; /* Its next sibling, if any. */
679 struct die_info *parent; /* Its parent, if any. */
681 /* An array of attributes, with NUM_ATTRS elements. There may be
682 zero, but it's not common and zero-sized arrays are not
683 sufficiently portable C. */
684 struct attribute attrs[1];
687 struct function_range
690 CORE_ADDR lowpc, highpc;
692 struct function_range *next;
695 /* Get at parts of an attribute structure. */
697 #define DW_STRING(attr) ((attr)->u.str)
698 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
699 #define DW_UNSND(attr) ((attr)->u.unsnd)
700 #define DW_BLOCK(attr) ((attr)->u.blk)
701 #define DW_SND(attr) ((attr)->u.snd)
702 #define DW_ADDR(attr) ((attr)->u.addr)
703 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
705 /* Blocks are a bunch of untyped bytes. */
712 #ifndef ATTR_ALLOC_CHUNK
713 #define ATTR_ALLOC_CHUNK 4
716 /* Allocate fields for structs, unions and enums in this size. */
717 #ifndef DW_FIELD_ALLOC_CHUNK
718 #define DW_FIELD_ALLOC_CHUNK 4
721 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
722 but this would require a corresponding change in unpack_field_as_long
724 static int bits_per_byte = 8;
726 /* The routines that read and process dies for a C struct or C++ class
727 pass lists of data member fields and lists of member function fields
728 in an instance of a field_info structure, as defined below. */
731 /* List of data member and baseclasses fields. */
734 struct nextfield *next;
739 *fields, *baseclasses;
741 /* Number of fields (including baseclasses). */
744 /* Number of baseclasses. */
747 /* Set if the accesibility of one of the fields is not public. */
748 int non_public_fields;
750 /* Member function fields array, entries are allocated in the order they
751 are encountered in the object file. */
754 struct nextfnfield *next;
755 struct fn_field fnfield;
759 /* Member function fieldlist array, contains name of possibly overloaded
760 member function, number of overloaded member functions and a pointer
761 to the head of the member function field chain. */
766 struct nextfnfield *head;
770 /* Number of entries in the fnfieldlists array. */
773 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
774 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
775 struct typedef_field_list
777 struct typedef_field field;
778 struct typedef_field_list *next;
781 unsigned typedef_field_list_count;
784 /* One item on the queue of compilation units to read in full symbols
786 struct dwarf2_queue_item
788 struct dwarf2_per_cu_data *per_cu;
789 struct dwarf2_queue_item *next;
792 /* The current queue. */
793 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
795 /* Loaded secondary compilation units are kept in memory until they
796 have not been referenced for the processing of this many
797 compilation units. Set this to zero to disable caching. Cache
798 sizes of up to at least twenty will improve startup time for
799 typical inter-CU-reference binaries, at an obvious memory cost. */
800 static int dwarf2_max_cache_age = 5;
802 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
803 struct cmd_list_element *c, const char *value)
805 fprintf_filtered (file, _("The upper bound on the age of cached "
806 "dwarf2 compilation units is %s.\n"),
811 /* Various complaints about symbol reading that don't abort the process. */
814 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
816 complaint (&symfile_complaints,
817 _("statement list doesn't fit in .debug_line section"));
821 dwarf2_debug_line_missing_file_complaint (void)
823 complaint (&symfile_complaints,
824 _(".debug_line section has line data without a file"));
828 dwarf2_debug_line_missing_end_sequence_complaint (void)
830 complaint (&symfile_complaints,
831 _(".debug_line section has line "
832 "program sequence without an end"));
836 dwarf2_complex_location_expr_complaint (void)
838 complaint (&symfile_complaints, _("location expression too complex"));
842 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
845 complaint (&symfile_complaints,
846 _("const value length mismatch for '%s', got %d, expected %d"),
851 dwarf2_macros_too_long_complaint (void)
853 complaint (&symfile_complaints,
854 _("macro info runs off end of `.debug_macinfo' section"));
858 dwarf2_macro_malformed_definition_complaint (const char *arg1)
860 complaint (&symfile_complaints,
861 _("macro debug info contains a "
862 "malformed macro definition:\n`%s'"),
867 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
869 complaint (&symfile_complaints,
870 _("invalid attribute class or form for '%s' in '%s'"),
874 /* local function prototypes */
876 static void dwarf2_locate_sections (bfd *, asection *, void *);
878 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
881 static void dwarf2_build_psymtabs_hard (struct objfile *);
883 static void scan_partial_symbols (struct partial_die_info *,
884 CORE_ADDR *, CORE_ADDR *,
885 int, struct dwarf2_cu *);
887 static void add_partial_symbol (struct partial_die_info *,
890 static void add_partial_namespace (struct partial_die_info *pdi,
891 CORE_ADDR *lowpc, CORE_ADDR *highpc,
892 int need_pc, struct dwarf2_cu *cu);
894 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
895 CORE_ADDR *highpc, int need_pc,
896 struct dwarf2_cu *cu);
898 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
899 struct dwarf2_cu *cu);
901 static void add_partial_subprogram (struct partial_die_info *pdi,
902 CORE_ADDR *lowpc, CORE_ADDR *highpc,
903 int need_pc, struct dwarf2_cu *cu);
905 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
906 gdb_byte *buffer, gdb_byte *info_ptr,
907 bfd *abfd, struct dwarf2_cu *cu);
909 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
911 static void psymtab_to_symtab_1 (struct partial_symtab *);
913 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
915 static void dwarf2_free_abbrev_table (void *);
917 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
920 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
923 static struct partial_die_info *load_partial_dies (bfd *,
924 gdb_byte *, gdb_byte *,
925 int, struct dwarf2_cu *);
927 static gdb_byte *read_partial_die (struct partial_die_info *,
928 struct abbrev_info *abbrev,
930 gdb_byte *, gdb_byte *,
933 static struct partial_die_info *find_partial_die (unsigned int,
936 static void fixup_partial_die (struct partial_die_info *,
939 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
940 bfd *, gdb_byte *, struct dwarf2_cu *);
942 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
943 bfd *, gdb_byte *, struct dwarf2_cu *);
945 static unsigned int read_1_byte (bfd *, gdb_byte *);
947 static int read_1_signed_byte (bfd *, gdb_byte *);
949 static unsigned int read_2_bytes (bfd *, gdb_byte *);
951 static unsigned int read_4_bytes (bfd *, gdb_byte *);
953 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
955 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
958 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
960 static LONGEST read_checked_initial_length_and_offset
961 (bfd *, gdb_byte *, const struct comp_unit_head *,
962 unsigned int *, unsigned int *);
964 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
967 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
969 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
971 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
973 static char *read_indirect_string (bfd *, gdb_byte *,
974 const struct comp_unit_head *,
977 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
979 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
981 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
983 static void set_cu_language (unsigned int, struct dwarf2_cu *);
985 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
988 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
992 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
993 struct dwarf2_cu *cu);
995 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
997 static struct die_info *die_specification (struct die_info *die,
998 struct dwarf2_cu **);
1000 static void free_line_header (struct line_header *lh);
1002 static void add_file_name (struct line_header *, char *, unsigned int,
1003 unsigned int, unsigned int);
1005 static struct line_header *(dwarf_decode_line_header
1006 (unsigned int offset,
1007 bfd *abfd, struct dwarf2_cu *cu));
1009 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
1010 struct dwarf2_cu *, struct partial_symtab *);
1012 static void dwarf2_start_subfile (char *, const char *, const char *);
1014 static struct symbol *new_symbol (struct die_info *, struct type *,
1015 struct dwarf2_cu *);
1017 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1018 struct dwarf2_cu *, struct symbol *);
1020 static void dwarf2_const_value (struct attribute *, struct symbol *,
1021 struct dwarf2_cu *);
1023 static void dwarf2_const_value_attr (struct attribute *attr,
1026 struct obstack *obstack,
1027 struct dwarf2_cu *cu, long *value,
1029 struct dwarf2_locexpr_baton **baton);
1031 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1033 static int need_gnat_info (struct dwarf2_cu *);
1035 static struct type *die_descriptive_type (struct die_info *,
1036 struct dwarf2_cu *);
1038 static void set_descriptive_type (struct type *, struct die_info *,
1039 struct dwarf2_cu *);
1041 static struct type *die_containing_type (struct die_info *,
1042 struct dwarf2_cu *);
1044 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1045 struct dwarf2_cu *);
1047 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1049 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1051 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1053 static char *typename_concat (struct obstack *obs, const char *prefix,
1054 const char *suffix, int physname,
1055 struct dwarf2_cu *cu);
1057 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1059 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1061 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1063 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1065 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1066 struct dwarf2_cu *, struct partial_symtab *);
1068 static int dwarf2_get_pc_bounds (struct die_info *,
1069 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1070 struct partial_symtab *);
1072 static void get_scope_pc_bounds (struct die_info *,
1073 CORE_ADDR *, CORE_ADDR *,
1074 struct dwarf2_cu *);
1076 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1077 CORE_ADDR, struct dwarf2_cu *);
1079 static void dwarf2_add_field (struct field_info *, struct die_info *,
1080 struct dwarf2_cu *);
1082 static void dwarf2_attach_fields_to_type (struct field_info *,
1083 struct type *, struct dwarf2_cu *);
1085 static void dwarf2_add_member_fn (struct field_info *,
1086 struct die_info *, struct type *,
1087 struct dwarf2_cu *);
1089 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1091 struct dwarf2_cu *);
1093 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1095 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1097 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1099 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1101 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1103 static struct type *read_module_type (struct die_info *die,
1104 struct dwarf2_cu *cu);
1106 static const char *namespace_name (struct die_info *die,
1107 int *is_anonymous, struct dwarf2_cu *);
1109 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1111 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1113 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1114 struct dwarf2_cu *);
1116 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1118 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1120 gdb_byte **new_info_ptr,
1121 struct die_info *parent);
1123 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1125 gdb_byte **new_info_ptr,
1126 struct die_info *parent);
1128 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1130 gdb_byte **new_info_ptr,
1131 struct die_info *parent);
1133 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1134 struct die_info **, gdb_byte *,
1137 static void process_die (struct die_info *, struct dwarf2_cu *);
1139 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1142 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1144 static const char *dwarf2_full_name (char *name,
1145 struct die_info *die,
1146 struct dwarf2_cu *cu);
1148 static struct die_info *dwarf2_extension (struct die_info *die,
1149 struct dwarf2_cu **);
1151 static char *dwarf_tag_name (unsigned int);
1153 static char *dwarf_attr_name (unsigned int);
1155 static char *dwarf_form_name (unsigned int);
1157 static char *dwarf_bool_name (unsigned int);
1159 static char *dwarf_type_encoding_name (unsigned int);
1162 static char *dwarf_cfi_name (unsigned int);
1165 static struct die_info *sibling_die (struct die_info *);
1167 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1169 static void dump_die_for_error (struct die_info *);
1171 static void dump_die_1 (struct ui_file *, int level, int max_level,
1174 /*static*/ void dump_die (struct die_info *, int max_level);
1176 static void store_in_ref_table (struct die_info *,
1177 struct dwarf2_cu *);
1179 static int is_ref_attr (struct attribute *);
1181 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1183 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1185 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1187 struct dwarf2_cu **);
1189 static struct die_info *follow_die_ref (struct die_info *,
1191 struct dwarf2_cu **);
1193 static struct die_info *follow_die_sig (struct die_info *,
1195 struct dwarf2_cu **);
1197 static void read_signatured_type_at_offset (struct objfile *objfile,
1198 unsigned int offset);
1200 static void read_signatured_type (struct objfile *,
1201 struct signatured_type *type_sig);
1203 /* memory allocation interface */
1205 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1207 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1209 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1211 static void initialize_cu_func_list (struct dwarf2_cu *);
1213 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1214 struct dwarf2_cu *);
1216 static void dwarf_decode_macros (struct line_header *, unsigned int,
1217 char *, bfd *, struct dwarf2_cu *);
1219 static int attr_form_is_block (struct attribute *);
1221 static int attr_form_is_section_offset (struct attribute *);
1223 static int attr_form_is_constant (struct attribute *);
1225 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1226 struct dwarf2_loclist_baton *baton,
1227 struct attribute *attr);
1229 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1231 struct dwarf2_cu *cu);
1233 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1234 struct abbrev_info *abbrev,
1235 struct dwarf2_cu *cu);
1237 static void free_stack_comp_unit (void *);
1239 static hashval_t partial_die_hash (const void *item);
1241 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1243 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1244 (unsigned int offset, struct objfile *objfile);
1246 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1247 (unsigned int offset, struct objfile *objfile);
1249 static void init_one_comp_unit (struct dwarf2_cu *cu,
1250 struct objfile *objfile);
1252 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1253 struct die_info *comp_unit_die);
1255 static void free_one_comp_unit (void *);
1257 static void free_cached_comp_units (void *);
1259 static void age_cached_comp_units (void);
1261 static void free_one_cached_comp_unit (void *);
1263 static struct type *set_die_type (struct die_info *, struct type *,
1264 struct dwarf2_cu *);
1266 static void create_all_comp_units (struct objfile *);
1268 static int create_debug_types_hash_table (struct objfile *objfile);
1270 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1273 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1275 static void dwarf2_add_dependence (struct dwarf2_cu *,
1276 struct dwarf2_per_cu_data *);
1278 static void dwarf2_mark (struct dwarf2_cu *);
1280 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1282 static struct type *get_die_type_at_offset (unsigned int,
1283 struct dwarf2_per_cu_data *per_cu);
1285 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1287 static void dwarf2_release_queue (void *dummy);
1289 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1290 struct objfile *objfile);
1292 static void process_queue (struct objfile *objfile);
1294 static void find_file_and_directory (struct die_info *die,
1295 struct dwarf2_cu *cu,
1296 char **name, char **comp_dir);
1298 static char *file_full_name (int file, struct line_header *lh,
1299 const char *comp_dir);
1301 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1304 unsigned int buffer_size,
1307 static void init_cu_die_reader (struct die_reader_specs *reader,
1308 struct dwarf2_cu *cu);
1310 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1314 /* Convert VALUE between big- and little-endian. */
1316 byte_swap (offset_type value)
1320 result = (value & 0xff) << 24;
1321 result |= (value & 0xff00) << 8;
1322 result |= (value & 0xff0000) >> 8;
1323 result |= (value & 0xff000000) >> 24;
1327 #define MAYBE_SWAP(V) byte_swap (V)
1330 #define MAYBE_SWAP(V) (V)
1331 #endif /* WORDS_BIGENDIAN */
1333 /* The suffix for an index file. */
1334 #define INDEX_SUFFIX ".gdb-index"
1336 static const char *dwarf2_physname (char *name, struct die_info *die,
1337 struct dwarf2_cu *cu);
1339 /* Try to locate the sections we need for DWARF 2 debugging
1340 information and return true if we have enough to do something.
1341 NAMES points to the dwarf2 section names, or is NULL if the standard
1342 ELF names are used. */
1345 dwarf2_has_info (struct objfile *objfile,
1346 const struct dwarf2_debug_sections *names)
1348 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1349 if (!dwarf2_per_objfile)
1351 /* Initialize per-objfile state. */
1352 struct dwarf2_per_objfile *data
1353 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1355 memset (data, 0, sizeof (*data));
1356 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1357 dwarf2_per_objfile = data;
1359 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1361 dwarf2_per_objfile->objfile = objfile;
1363 return (dwarf2_per_objfile->info.asection != NULL
1364 && dwarf2_per_objfile->abbrev.asection != NULL);
1367 /* When loading sections, we look either for uncompressed section or for
1368 compressed section names. */
1371 section_is_p (const char *section_name,
1372 const struct dwarf2_section_names *names)
1374 if (names->normal != NULL
1375 && strcmp (section_name, names->normal) == 0)
1377 if (names->compressed != NULL
1378 && strcmp (section_name, names->compressed) == 0)
1383 /* This function is mapped across the sections and remembers the
1384 offset and size of each of the debugging sections we are interested
1388 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1390 const struct dwarf2_debug_sections *names;
1393 names = &dwarf2_elf_names;
1395 names = (const struct dwarf2_debug_sections *) vnames;
1397 if (section_is_p (sectp->name, &names->info))
1399 dwarf2_per_objfile->info.asection = sectp;
1400 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1402 else if (section_is_p (sectp->name, &names->abbrev))
1404 dwarf2_per_objfile->abbrev.asection = sectp;
1405 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1407 else if (section_is_p (sectp->name, &names->line))
1409 dwarf2_per_objfile->line.asection = sectp;
1410 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1412 else if (section_is_p (sectp->name, &names->loc))
1414 dwarf2_per_objfile->loc.asection = sectp;
1415 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1417 else if (section_is_p (sectp->name, &names->macinfo))
1419 dwarf2_per_objfile->macinfo.asection = sectp;
1420 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1422 else if (section_is_p (sectp->name, &names->str))
1424 dwarf2_per_objfile->str.asection = sectp;
1425 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1427 else if (section_is_p (sectp->name, &names->frame))
1429 dwarf2_per_objfile->frame.asection = sectp;
1430 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1432 else if (section_is_p (sectp->name, &names->eh_frame))
1434 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1436 if (aflag & SEC_HAS_CONTENTS)
1438 dwarf2_per_objfile->eh_frame.asection = sectp;
1439 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1442 else if (section_is_p (sectp->name, &names->ranges))
1444 dwarf2_per_objfile->ranges.asection = sectp;
1445 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1447 else if (section_is_p (sectp->name, &names->types))
1449 dwarf2_per_objfile->types.asection = sectp;
1450 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1452 else if (section_is_p (sectp->name, &names->gdb_index))
1454 dwarf2_per_objfile->gdb_index.asection = sectp;
1455 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1458 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1459 && bfd_section_vma (abfd, sectp) == 0)
1460 dwarf2_per_objfile->has_section_at_zero = 1;
1463 /* Decompress a section that was compressed using zlib. Store the
1464 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1467 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1468 gdb_byte **outbuf, bfd_size_type *outsize)
1470 bfd *abfd = objfile->obfd;
1472 error (_("Support for zlib-compressed DWARF data (from '%s') "
1473 "is disabled in this copy of GDB"),
1474 bfd_get_filename (abfd));
1476 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1477 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1478 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1479 bfd_size_type uncompressed_size;
1480 gdb_byte *uncompressed_buffer;
1483 int header_size = 12;
1485 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1486 || bfd_bread (compressed_buffer,
1487 compressed_size, abfd) != compressed_size)
1488 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1489 bfd_get_filename (abfd));
1491 /* Read the zlib header. In this case, it should be "ZLIB" followed
1492 by the uncompressed section size, 8 bytes in big-endian order. */
1493 if (compressed_size < header_size
1494 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1495 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1496 bfd_get_filename (abfd));
1497 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1498 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1499 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1500 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1501 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1502 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1503 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1504 uncompressed_size += compressed_buffer[11];
1506 /* It is possible the section consists of several compressed
1507 buffers concatenated together, so we uncompress in a loop. */
1511 strm.avail_in = compressed_size - header_size;
1512 strm.next_in = (Bytef*) compressed_buffer + header_size;
1513 strm.avail_out = uncompressed_size;
1514 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1516 rc = inflateInit (&strm);
1517 while (strm.avail_in > 0)
1520 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1521 bfd_get_filename (abfd), rc);
1522 strm.next_out = ((Bytef*) uncompressed_buffer
1523 + (uncompressed_size - strm.avail_out));
1524 rc = inflate (&strm, Z_FINISH);
1525 if (rc != Z_STREAM_END)
1526 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1527 bfd_get_filename (abfd), rc);
1528 rc = inflateReset (&strm);
1530 rc = inflateEnd (&strm);
1532 || strm.avail_out != 0)
1533 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1534 bfd_get_filename (abfd), rc);
1536 do_cleanups (cleanup);
1537 *outbuf = uncompressed_buffer;
1538 *outsize = uncompressed_size;
1542 /* A helper function that decides whether a section is empty. */
1545 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1547 return info->asection == NULL || info->size == 0;
1550 /* Read the contents of the section SECTP from object file specified by
1551 OBJFILE, store info about the section into INFO.
1552 If the section is compressed, uncompress it before returning. */
1555 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1557 bfd *abfd = objfile->obfd;
1558 asection *sectp = info->asection;
1559 gdb_byte *buf, *retbuf;
1560 unsigned char header[4];
1564 info->buffer = NULL;
1565 info->was_mmapped = 0;
1568 if (dwarf2_section_empty_p (info))
1571 /* Check if the file has a 4-byte header indicating compression. */
1572 if (info->size > sizeof (header)
1573 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1574 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1576 /* Upon decompression, update the buffer and its size. */
1577 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1579 zlib_decompress_section (objfile, sectp, &info->buffer,
1587 pagesize = getpagesize ();
1589 /* Only try to mmap sections which are large enough: we don't want to
1590 waste space due to fragmentation. Also, only try mmap for sections
1591 without relocations. */
1593 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1595 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1596 size_t map_length = info->size + sectp->filepos - pg_offset;
1597 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1598 MAP_PRIVATE, pg_offset);
1600 if (retbuf != MAP_FAILED)
1602 info->was_mmapped = 1;
1603 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1604 #if HAVE_POSIX_MADVISE
1605 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1612 /* If we get here, we are a normal, not-compressed section. */
1614 = obstack_alloc (&objfile->objfile_obstack, info->size);
1616 /* When debugging .o files, we may need to apply relocations; see
1617 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1618 We never compress sections in .o files, so we only need to
1619 try this when the section is not compressed. */
1620 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1623 info->buffer = retbuf;
1627 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1628 || bfd_bread (buf, info->size, abfd) != info->size)
1629 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1630 bfd_get_filename (abfd));
1633 /* A helper function that returns the size of a section in a safe way.
1634 If you are positive that the section has been read before using the
1635 size, then it is safe to refer to the dwarf2_section_info object's
1636 "size" field directly. In other cases, you must call this
1637 function, because for compressed sections the size field is not set
1638 correctly until the section has been read. */
1640 static bfd_size_type
1641 dwarf2_section_size (struct objfile *objfile,
1642 struct dwarf2_section_info *info)
1645 dwarf2_read_section (objfile, info);
1649 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1653 dwarf2_get_section_info (struct objfile *objfile,
1654 enum dwarf2_section_enum sect,
1655 asection **sectp, gdb_byte **bufp,
1656 bfd_size_type *sizep)
1658 struct dwarf2_per_objfile *data
1659 = objfile_data (objfile, dwarf2_objfile_data_key);
1660 struct dwarf2_section_info *info;
1662 /* We may see an objfile without any DWARF, in which case we just
1673 case DWARF2_DEBUG_FRAME:
1674 info = &data->frame;
1676 case DWARF2_EH_FRAME:
1677 info = &data->eh_frame;
1680 gdb_assert_not_reached ("unexpected section");
1683 dwarf2_read_section (objfile, info);
1685 *sectp = info->asection;
1686 *bufp = info->buffer;
1687 *sizep = info->size;
1691 /* DWARF quick_symbols_functions support. */
1693 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1694 unique line tables, so we maintain a separate table of all .debug_line
1695 derived entries to support the sharing.
1696 All the quick functions need is the list of file names. We discard the
1697 line_header when we're done and don't need to record it here. */
1698 struct quick_file_names
1700 /* The offset in .debug_line of the line table. We hash on this. */
1701 unsigned int offset;
1703 /* The number of entries in file_names, real_names. */
1704 unsigned int num_file_names;
1706 /* The file names from the line table, after being run through
1708 const char **file_names;
1710 /* The file names from the line table after being run through
1711 gdb_realpath. These are computed lazily. */
1712 const char **real_names;
1715 /* When using the index (and thus not using psymtabs), each CU has an
1716 object of this type. This is used to hold information needed by
1717 the various "quick" methods. */
1718 struct dwarf2_per_cu_quick_data
1720 /* The file table. This can be NULL if there was no file table
1721 or it's currently not read in.
1722 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1723 struct quick_file_names *file_names;
1725 /* The corresponding symbol table. This is NULL if symbols for this
1726 CU have not yet been read. */
1727 struct symtab *symtab;
1729 /* A temporary mark bit used when iterating over all CUs in
1730 expand_symtabs_matching. */
1731 unsigned int mark : 1;
1733 /* True if we've tried to read the file table and found there isn't one.
1734 There will be no point in trying to read it again next time. */
1735 unsigned int no_file_data : 1;
1738 /* Hash function for a quick_file_names. */
1741 hash_file_name_entry (const void *e)
1743 const struct quick_file_names *file_data = e;
1745 return file_data->offset;
1748 /* Equality function for a quick_file_names. */
1751 eq_file_name_entry (const void *a, const void *b)
1753 const struct quick_file_names *ea = a;
1754 const struct quick_file_names *eb = b;
1756 return ea->offset == eb->offset;
1759 /* Delete function for a quick_file_names. */
1762 delete_file_name_entry (void *e)
1764 struct quick_file_names *file_data = e;
1767 for (i = 0; i < file_data->num_file_names; ++i)
1769 xfree ((void*) file_data->file_names[i]);
1770 if (file_data->real_names)
1771 xfree ((void*) file_data->real_names[i]);
1774 /* The space for the struct itself lives on objfile_obstack,
1775 so we don't free it here. */
1778 /* Create a quick_file_names hash table. */
1781 create_quick_file_names_table (unsigned int nr_initial_entries)
1783 return htab_create_alloc (nr_initial_entries,
1784 hash_file_name_entry, eq_file_name_entry,
1785 delete_file_name_entry, xcalloc, xfree);
1788 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1792 dw2_do_instantiate_symtab (struct objfile *objfile,
1793 struct dwarf2_per_cu_data *per_cu)
1795 struct cleanup *back_to;
1797 back_to = make_cleanup (dwarf2_release_queue, NULL);
1799 queue_comp_unit (per_cu, objfile);
1801 if (per_cu->from_debug_types)
1802 read_signatured_type_at_offset (objfile, per_cu->offset);
1804 load_full_comp_unit (per_cu, objfile);
1806 process_queue (objfile);
1808 /* Age the cache, releasing compilation units that have not
1809 been used recently. */
1810 age_cached_comp_units ();
1812 do_cleanups (back_to);
1815 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1816 the objfile from which this CU came. Returns the resulting symbol
1819 static struct symtab *
1820 dw2_instantiate_symtab (struct objfile *objfile,
1821 struct dwarf2_per_cu_data *per_cu)
1823 if (!per_cu->v.quick->symtab)
1825 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1826 increment_reading_symtab ();
1827 dw2_do_instantiate_symtab (objfile, per_cu);
1828 do_cleanups (back_to);
1830 return per_cu->v.quick->symtab;
1833 /* Return the CU given its index. */
1835 static struct dwarf2_per_cu_data *
1836 dw2_get_cu (int index)
1838 if (index >= dwarf2_per_objfile->n_comp_units)
1840 index -= dwarf2_per_objfile->n_comp_units;
1841 return dwarf2_per_objfile->type_comp_units[index];
1843 return dwarf2_per_objfile->all_comp_units[index];
1846 /* A helper function that knows how to read a 64-bit value in a way
1847 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1851 extract_cu_value (const char *bytes, ULONGEST *result)
1853 if (sizeof (ULONGEST) < 8)
1857 /* Ignore the upper 4 bytes if they are all zero. */
1858 for (i = 0; i < 4; ++i)
1859 if (bytes[i + 4] != 0)
1862 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1865 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1869 /* Read the CU list from the mapped index, and use it to create all
1870 the CU objects for this objfile. Return 0 if something went wrong,
1871 1 if everything went ok. */
1874 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1875 offset_type cu_list_elements)
1879 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1880 dwarf2_per_objfile->all_comp_units
1881 = obstack_alloc (&objfile->objfile_obstack,
1882 dwarf2_per_objfile->n_comp_units
1883 * sizeof (struct dwarf2_per_cu_data *));
1885 for (i = 0; i < cu_list_elements; i += 2)
1887 struct dwarf2_per_cu_data *the_cu;
1888 ULONGEST offset, length;
1890 if (!extract_cu_value (cu_list, &offset)
1891 || !extract_cu_value (cu_list + 8, &length))
1895 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1896 struct dwarf2_per_cu_data);
1897 the_cu->offset = offset;
1898 the_cu->length = length;
1899 the_cu->objfile = objfile;
1900 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1901 struct dwarf2_per_cu_quick_data);
1902 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1908 /* Create the signatured type hash table from the index. */
1911 create_signatured_type_table_from_index (struct objfile *objfile,
1912 const gdb_byte *bytes,
1913 offset_type elements)
1916 htab_t sig_types_hash;
1918 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1919 dwarf2_per_objfile->type_comp_units
1920 = obstack_alloc (&objfile->objfile_obstack,
1921 dwarf2_per_objfile->n_type_comp_units
1922 * sizeof (struct dwarf2_per_cu_data *));
1924 sig_types_hash = allocate_signatured_type_table (objfile);
1926 for (i = 0; i < elements; i += 3)
1928 struct signatured_type *type_sig;
1929 ULONGEST offset, type_offset, signature;
1932 if (!extract_cu_value (bytes, &offset)
1933 || !extract_cu_value (bytes + 8, &type_offset))
1935 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1938 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1939 struct signatured_type);
1940 type_sig->signature = signature;
1941 type_sig->type_offset = type_offset;
1942 type_sig->per_cu.from_debug_types = 1;
1943 type_sig->per_cu.offset = offset;
1944 type_sig->per_cu.objfile = objfile;
1945 type_sig->per_cu.v.quick
1946 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1947 struct dwarf2_per_cu_quick_data);
1949 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1952 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1955 dwarf2_per_objfile->signatured_types = sig_types_hash;
1960 /* Read the address map data from the mapped index, and use it to
1961 populate the objfile's psymtabs_addrmap. */
1964 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1966 const gdb_byte *iter, *end;
1967 struct obstack temp_obstack;
1968 struct addrmap *mutable_map;
1969 struct cleanup *cleanup;
1972 obstack_init (&temp_obstack);
1973 cleanup = make_cleanup_obstack_free (&temp_obstack);
1974 mutable_map = addrmap_create_mutable (&temp_obstack);
1976 iter = index->address_table;
1977 end = iter + index->address_table_size;
1979 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1983 ULONGEST hi, lo, cu_index;
1984 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1986 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1988 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1991 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1992 dw2_get_cu (cu_index));
1995 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1996 &objfile->objfile_obstack);
1997 do_cleanups (cleanup);
2000 /* The hash function for strings in the mapped index. This is the same as
2001 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2002 implementation. This is necessary because the hash function is tied to the
2003 format of the mapped index file. The hash values do not have to match with
2006 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2009 mapped_index_string_hash (int index_version, const void *p)
2011 const unsigned char *str = (const unsigned char *) p;
2015 while ((c = *str++) != 0)
2017 if (index_version >= 5)
2019 r = r * 67 + c - 113;
2025 /* Find a slot in the mapped index INDEX for the object named NAME.
2026 If NAME is found, set *VEC_OUT to point to the CU vector in the
2027 constant pool and return 1. If NAME cannot be found, return 0. */
2030 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2031 offset_type **vec_out)
2033 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2035 offset_type slot, step;
2036 int (*cmp) (const char *, const char *);
2038 if (current_language->la_language == language_cplus
2039 || current_language->la_language == language_java
2040 || current_language->la_language == language_fortran)
2042 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2044 const char *paren = strchr (name, '(');
2050 dup = xmalloc (paren - name + 1);
2051 memcpy (dup, name, paren - name);
2052 dup[paren - name] = 0;
2054 make_cleanup (xfree, dup);
2059 /* Index version 4 did not support case insensitive searches. But the
2060 indexes for case insensitive languages are built in lowercase, therefore
2061 simulate our NAME being searched is also lowercased. */
2062 hash = mapped_index_string_hash ((index->version == 4
2063 && case_sensitivity == case_sensitive_off
2064 ? 5 : index->version),
2067 slot = hash & (index->symbol_table_slots - 1);
2068 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2069 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2073 /* Convert a slot number to an offset into the table. */
2074 offset_type i = 2 * slot;
2076 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2078 do_cleanups (back_to);
2082 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2083 if (!cmp (name, str))
2085 *vec_out = (offset_type *) (index->constant_pool
2086 + MAYBE_SWAP (index->symbol_table[i + 1]));
2087 do_cleanups (back_to);
2091 slot = (slot + step) & (index->symbol_table_slots - 1);
2095 /* Read the index file. If everything went ok, initialize the "quick"
2096 elements of all the CUs and return 1. Otherwise, return 0. */
2099 dwarf2_read_index (struct objfile *objfile)
2102 struct mapped_index *map;
2103 offset_type *metadata;
2104 const gdb_byte *cu_list;
2105 const gdb_byte *types_list = NULL;
2106 offset_type version, cu_list_elements;
2107 offset_type types_list_elements = 0;
2110 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2113 /* Older elfutils strip versions could keep the section in the main
2114 executable while splitting it for the separate debug info file. */
2115 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2116 & SEC_HAS_CONTENTS) == 0)
2119 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2121 addr = dwarf2_per_objfile->gdb_index.buffer;
2122 /* Version check. */
2123 version = MAYBE_SWAP (*(offset_type *) addr);
2124 /* Versions earlier than 3 emitted every copy of a psymbol. This
2125 causes the index to behave very poorly for certain requests. Version 3
2126 contained incomplete addrmap. So, it seems better to just ignore such
2127 indices. Index version 4 uses a different hash function than index
2128 version 5 and later. */
2131 /* Indexes with higher version than the one supported by GDB may be no
2132 longer backward compatible. */
2136 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2137 map->version = version;
2138 map->total_size = dwarf2_per_objfile->gdb_index.size;
2140 metadata = (offset_type *) (addr + sizeof (offset_type));
2143 cu_list = addr + MAYBE_SWAP (metadata[i]);
2144 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2148 types_list = addr + MAYBE_SWAP (metadata[i]);
2149 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2150 - MAYBE_SWAP (metadata[i]))
2154 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2155 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2156 - MAYBE_SWAP (metadata[i]));
2159 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2160 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2161 - MAYBE_SWAP (metadata[i]))
2162 / (2 * sizeof (offset_type)));
2165 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2167 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2170 if (types_list_elements
2171 && !create_signatured_type_table_from_index (objfile, types_list,
2172 types_list_elements))
2175 create_addrmap_from_index (objfile, map);
2177 dwarf2_per_objfile->index_table = map;
2178 dwarf2_per_objfile->using_index = 1;
2179 dwarf2_per_objfile->quick_file_names_table =
2180 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2185 /* A helper for the "quick" functions which sets the global
2186 dwarf2_per_objfile according to OBJFILE. */
2189 dw2_setup (struct objfile *objfile)
2191 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2192 gdb_assert (dwarf2_per_objfile);
2195 /* A helper for the "quick" functions which attempts to read the line
2196 table for THIS_CU. */
2198 static struct quick_file_names *
2199 dw2_get_file_names (struct objfile *objfile,
2200 struct dwarf2_per_cu_data *this_cu)
2202 bfd *abfd = objfile->obfd;
2203 struct line_header *lh;
2204 struct attribute *attr;
2205 struct cleanup *cleanups;
2206 struct die_info *comp_unit_die;
2207 struct dwarf2_section_info* sec;
2208 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2209 int has_children, i;
2210 struct dwarf2_cu cu;
2211 unsigned int bytes_read, buffer_size;
2212 struct die_reader_specs reader_specs;
2213 char *name, *comp_dir;
2215 struct quick_file_names *qfn;
2216 unsigned int line_offset;
2218 if (this_cu->v.quick->file_names != NULL)
2219 return this_cu->v.quick->file_names;
2220 /* If we know there is no line data, no point in looking again. */
2221 if (this_cu->v.quick->no_file_data)
2224 init_one_comp_unit (&cu, objfile);
2225 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2227 if (this_cu->from_debug_types)
2228 sec = &dwarf2_per_objfile->types;
2230 sec = &dwarf2_per_objfile->info;
2231 dwarf2_read_section (objfile, sec);
2232 buffer_size = sec->size;
2233 buffer = sec->buffer;
2234 info_ptr = buffer + this_cu->offset;
2235 beg_of_comp_unit = info_ptr;
2237 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2238 buffer, buffer_size,
2241 /* Complete the cu_header. */
2242 cu.header.offset = beg_of_comp_unit - buffer;
2243 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2246 cu.per_cu = this_cu;
2248 dwarf2_read_abbrevs (abfd, &cu);
2249 make_cleanup (dwarf2_free_abbrev_table, &cu);
2251 if (this_cu->from_debug_types)
2252 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2253 init_cu_die_reader (&reader_specs, &cu);
2254 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2260 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2263 struct quick_file_names find_entry;
2265 line_offset = DW_UNSND (attr);
2267 /* We may have already read in this line header (TU line header sharing).
2268 If we have we're done. */
2269 find_entry.offset = line_offset;
2270 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2271 &find_entry, INSERT);
2274 do_cleanups (cleanups);
2275 this_cu->v.quick->file_names = *slot;
2279 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2283 do_cleanups (cleanups);
2284 this_cu->v.quick->no_file_data = 1;
2288 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2289 qfn->offset = line_offset;
2290 gdb_assert (slot != NULL);
2293 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2295 qfn->num_file_names = lh->num_file_names;
2296 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2297 lh->num_file_names * sizeof (char *));
2298 for (i = 0; i < lh->num_file_names; ++i)
2299 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2300 qfn->real_names = NULL;
2302 free_line_header (lh);
2303 do_cleanups (cleanups);
2305 this_cu->v.quick->file_names = qfn;
2309 /* A helper for the "quick" functions which computes and caches the
2310 real path for a given file name from the line table. */
2313 dw2_get_real_path (struct objfile *objfile,
2314 struct quick_file_names *qfn, int index)
2316 if (qfn->real_names == NULL)
2317 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2318 qfn->num_file_names, sizeof (char *));
2320 if (qfn->real_names[index] == NULL)
2321 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2323 return qfn->real_names[index];
2326 static struct symtab *
2327 dw2_find_last_source_symtab (struct objfile *objfile)
2331 dw2_setup (objfile);
2332 index = dwarf2_per_objfile->n_comp_units - 1;
2333 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2336 /* Traversal function for dw2_forget_cached_source_info. */
2339 dw2_free_cached_file_names (void **slot, void *info)
2341 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2343 if (file_data->real_names)
2347 for (i = 0; i < file_data->num_file_names; ++i)
2349 xfree ((void*) file_data->real_names[i]);
2350 file_data->real_names[i] = NULL;
2358 dw2_forget_cached_source_info (struct objfile *objfile)
2360 dw2_setup (objfile);
2362 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2363 dw2_free_cached_file_names, NULL);
2367 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2368 const char *full_path, const char *real_path,
2369 struct symtab **result)
2372 int check_basename = lbasename (name) == name;
2373 struct dwarf2_per_cu_data *base_cu = NULL;
2375 dw2_setup (objfile);
2377 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2378 + dwarf2_per_objfile->n_type_comp_units); ++i)
2381 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2382 struct quick_file_names *file_data;
2384 if (per_cu->v.quick->symtab)
2387 file_data = dw2_get_file_names (objfile, per_cu);
2388 if (file_data == NULL)
2391 for (j = 0; j < file_data->num_file_names; ++j)
2393 const char *this_name = file_data->file_names[j];
2395 if (FILENAME_CMP (name, this_name) == 0)
2397 *result = dw2_instantiate_symtab (objfile, per_cu);
2401 if (check_basename && ! base_cu
2402 && FILENAME_CMP (lbasename (this_name), name) == 0)
2405 if (full_path != NULL)
2407 const char *this_real_name = dw2_get_real_path (objfile,
2410 if (this_real_name != NULL
2411 && FILENAME_CMP (full_path, this_real_name) == 0)
2413 *result = dw2_instantiate_symtab (objfile, per_cu);
2418 if (real_path != NULL)
2420 const char *this_real_name = dw2_get_real_path (objfile,
2423 if (this_real_name != NULL
2424 && FILENAME_CMP (real_path, this_real_name) == 0)
2426 *result = dw2_instantiate_symtab (objfile, per_cu);
2435 *result = dw2_instantiate_symtab (objfile, base_cu);
2442 static struct symtab *
2443 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2444 const char *name, domain_enum domain)
2446 /* We do all the work in the pre_expand_symtabs_matching hook
2451 /* A helper function that expands all symtabs that hold an object
2455 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2457 dw2_setup (objfile);
2459 /* index_table is NULL if OBJF_READNOW. */
2460 if (dwarf2_per_objfile->index_table)
2464 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2467 offset_type i, len = MAYBE_SWAP (*vec);
2468 for (i = 0; i < len; ++i)
2470 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2471 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2473 dw2_instantiate_symtab (objfile, per_cu);
2480 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2481 enum block_enum block_kind, const char *name,
2484 dw2_do_expand_symtabs_matching (objfile, name);
2488 dw2_print_stats (struct objfile *objfile)
2492 dw2_setup (objfile);
2494 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2495 + dwarf2_per_objfile->n_type_comp_units); ++i)
2497 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2499 if (!per_cu->v.quick->symtab)
2502 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2506 dw2_dump (struct objfile *objfile)
2508 /* Nothing worth printing. */
2512 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2513 struct section_offsets *delta)
2515 /* There's nothing to relocate here. */
2519 dw2_expand_symtabs_for_function (struct objfile *objfile,
2520 const char *func_name)
2522 dw2_do_expand_symtabs_matching (objfile, func_name);
2526 dw2_expand_all_symtabs (struct objfile *objfile)
2530 dw2_setup (objfile);
2532 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2533 + dwarf2_per_objfile->n_type_comp_units); ++i)
2535 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2537 dw2_instantiate_symtab (objfile, per_cu);
2542 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2543 const char *filename)
2547 dw2_setup (objfile);
2549 /* We don't need to consider type units here.
2550 This is only called for examining code, e.g. expand_line_sal.
2551 There can be an order of magnitude (or more) more type units
2552 than comp units, and we avoid them if we can. */
2554 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2557 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2558 struct quick_file_names *file_data;
2560 if (per_cu->v.quick->symtab)
2563 file_data = dw2_get_file_names (objfile, per_cu);
2564 if (file_data == NULL)
2567 for (j = 0; j < file_data->num_file_names; ++j)
2569 const char *this_name = file_data->file_names[j];
2570 if (FILENAME_CMP (this_name, filename) == 0)
2572 dw2_instantiate_symtab (objfile, per_cu);
2580 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2582 struct dwarf2_per_cu_data *per_cu;
2584 struct quick_file_names *file_data;
2586 dw2_setup (objfile);
2588 /* index_table is NULL if OBJF_READNOW. */
2589 if (!dwarf2_per_objfile->index_table)
2592 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2596 /* Note that this just looks at the very first one named NAME -- but
2597 actually we are looking for a function. find_main_filename
2598 should be rewritten so that it doesn't require a custom hook. It
2599 could just use the ordinary symbol tables. */
2600 /* vec[0] is the length, which must always be >0. */
2601 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2603 file_data = dw2_get_file_names (objfile, per_cu);
2604 if (file_data == NULL)
2607 return file_data->file_names[file_data->num_file_names - 1];
2611 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2612 struct objfile *objfile, int global,
2613 int (*callback) (struct block *,
2614 struct symbol *, void *),
2615 void *data, symbol_compare_ftype *match,
2616 symbol_compare_ftype *ordered_compare)
2618 /* Currently unimplemented; used for Ada. The function can be called if the
2619 current language is Ada for a non-Ada objfile using GNU index. As Ada
2620 does not look for non-Ada symbols this function should just return. */
2624 dw2_expand_symtabs_matching (struct objfile *objfile,
2625 int (*file_matcher) (const char *, void *),
2626 int (*name_matcher) (const char *, void *),
2627 enum search_domain kind,
2632 struct mapped_index *index;
2634 dw2_setup (objfile);
2636 /* index_table is NULL if OBJF_READNOW. */
2637 if (!dwarf2_per_objfile->index_table)
2639 index = dwarf2_per_objfile->index_table;
2641 if (file_matcher != NULL)
2642 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2643 + dwarf2_per_objfile->n_type_comp_units); ++i)
2646 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2647 struct quick_file_names *file_data;
2649 per_cu->v.quick->mark = 0;
2650 if (per_cu->v.quick->symtab)
2653 file_data = dw2_get_file_names (objfile, per_cu);
2654 if (file_data == NULL)
2657 for (j = 0; j < file_data->num_file_names; ++j)
2659 if (file_matcher (file_data->file_names[j], data))
2661 per_cu->v.quick->mark = 1;
2667 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2669 offset_type idx = 2 * iter;
2671 offset_type *vec, vec_len, vec_idx;
2673 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2676 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2678 if (! (*name_matcher) (name, data))
2681 /* The name was matched, now expand corresponding CUs that were
2683 vec = (offset_type *) (index->constant_pool
2684 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2685 vec_len = MAYBE_SWAP (vec[0]);
2686 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2688 struct dwarf2_per_cu_data *per_cu;
2690 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2691 if (file_matcher == NULL || per_cu->v.quick->mark)
2692 dw2_instantiate_symtab (objfile, per_cu);
2697 static struct symtab *
2698 dw2_find_pc_sect_symtab (struct objfile *objfile,
2699 struct minimal_symbol *msymbol,
2701 struct obj_section *section,
2704 struct dwarf2_per_cu_data *data;
2706 dw2_setup (objfile);
2708 if (!objfile->psymtabs_addrmap)
2711 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2715 if (warn_if_readin && data->v.quick->symtab)
2716 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2717 paddress (get_objfile_arch (objfile), pc));
2719 return dw2_instantiate_symtab (objfile, data);
2723 dw2_map_symbol_filenames (struct objfile *objfile,
2724 void (*fun) (const char *, const char *, void *),
2729 dw2_setup (objfile);
2731 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2732 + dwarf2_per_objfile->n_type_comp_units); ++i)
2735 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2736 struct quick_file_names *file_data;
2738 if (per_cu->v.quick->symtab)
2741 file_data = dw2_get_file_names (objfile, per_cu);
2742 if (file_data == NULL)
2745 for (j = 0; j < file_data->num_file_names; ++j)
2747 const char *this_real_name = dw2_get_real_path (objfile, file_data,
2749 (*fun) (file_data->file_names[j], this_real_name, data);
2755 dw2_has_symbols (struct objfile *objfile)
2760 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2763 dw2_find_last_source_symtab,
2764 dw2_forget_cached_source_info,
2767 dw2_pre_expand_symtabs_matching,
2771 dw2_expand_symtabs_for_function,
2772 dw2_expand_all_symtabs,
2773 dw2_expand_symtabs_with_filename,
2774 dw2_find_symbol_file,
2775 dw2_map_matching_symbols,
2776 dw2_expand_symtabs_matching,
2777 dw2_find_pc_sect_symtab,
2778 dw2_map_symbol_filenames
2781 /* Initialize for reading DWARF for this objfile. Return 0 if this
2782 file will use psymtabs, or 1 if using the GNU index. */
2785 dwarf2_initialize_objfile (struct objfile *objfile)
2787 /* If we're about to read full symbols, don't bother with the
2788 indices. In this case we also don't care if some other debug
2789 format is making psymtabs, because they are all about to be
2791 if ((objfile->flags & OBJF_READNOW))
2795 dwarf2_per_objfile->using_index = 1;
2796 create_all_comp_units (objfile);
2797 create_debug_types_hash_table (objfile);
2798 dwarf2_per_objfile->quick_file_names_table =
2799 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2801 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2802 + dwarf2_per_objfile->n_type_comp_units); ++i)
2804 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2806 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2807 struct dwarf2_per_cu_quick_data);
2810 /* Return 1 so that gdb sees the "quick" functions. However,
2811 these functions will be no-ops because we will have expanded
2816 if (dwarf2_read_index (objfile))
2824 /* Build a partial symbol table. */
2827 dwarf2_build_psymtabs (struct objfile *objfile)
2829 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2831 init_psymbol_list (objfile, 1024);
2834 dwarf2_build_psymtabs_hard (objfile);
2837 /* Return TRUE if OFFSET is within CU_HEADER. */
2840 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2842 unsigned int bottom = cu_header->offset;
2843 unsigned int top = (cu_header->offset
2845 + cu_header->initial_length_size);
2847 return (offset >= bottom && offset < top);
2850 /* Read in the comp unit header information from the debug_info at info_ptr.
2851 NOTE: This leaves members offset, first_die_offset to be filled in
2855 read_comp_unit_head (struct comp_unit_head *cu_header,
2856 gdb_byte *info_ptr, bfd *abfd)
2859 unsigned int bytes_read;
2861 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2862 cu_header->initial_length_size = bytes_read;
2863 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2864 info_ptr += bytes_read;
2865 cu_header->version = read_2_bytes (abfd, info_ptr);
2867 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2869 info_ptr += bytes_read;
2870 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2872 signed_addr = bfd_get_sign_extend_vma (abfd);
2873 if (signed_addr < 0)
2874 internal_error (__FILE__, __LINE__,
2875 _("read_comp_unit_head: dwarf from non elf file"));
2876 cu_header->signed_addr_p = signed_addr;
2882 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2883 gdb_byte *buffer, unsigned int buffer_size,
2886 gdb_byte *beg_of_comp_unit = info_ptr;
2888 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2890 if (header->version != 2 && header->version != 3 && header->version != 4)
2891 error (_("Dwarf Error: wrong version in compilation unit header "
2892 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2893 bfd_get_filename (abfd));
2895 if (header->abbrev_offset
2896 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2897 &dwarf2_per_objfile->abbrev))
2898 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2899 "(offset 0x%lx + 6) [in module %s]"),
2900 (long) header->abbrev_offset,
2901 (long) (beg_of_comp_unit - buffer),
2902 bfd_get_filename (abfd));
2904 if (beg_of_comp_unit + header->length + header->initial_length_size
2905 > buffer + buffer_size)
2906 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2907 "(offset 0x%lx + 0) [in module %s]"),
2908 (long) header->length,
2909 (long) (beg_of_comp_unit - buffer),
2910 bfd_get_filename (abfd));
2915 /* Read in the types comp unit header information from .debug_types entry at
2916 types_ptr. The result is a pointer to one past the end of the header. */
2919 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2920 ULONGEST *signature,
2921 gdb_byte *types_ptr, bfd *abfd)
2923 gdb_byte *initial_types_ptr = types_ptr;
2925 dwarf2_read_section (dwarf2_per_objfile->objfile,
2926 &dwarf2_per_objfile->types);
2927 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2929 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2931 *signature = read_8_bytes (abfd, types_ptr);
2933 types_ptr += cu_header->offset_size;
2934 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2939 /* Allocate a new partial symtab for file named NAME and mark this new
2940 partial symtab as being an include of PST. */
2943 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2944 struct objfile *objfile)
2946 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2948 subpst->section_offsets = pst->section_offsets;
2949 subpst->textlow = 0;
2950 subpst->texthigh = 0;
2952 subpst->dependencies = (struct partial_symtab **)
2953 obstack_alloc (&objfile->objfile_obstack,
2954 sizeof (struct partial_symtab *));
2955 subpst->dependencies[0] = pst;
2956 subpst->number_of_dependencies = 1;
2958 subpst->globals_offset = 0;
2959 subpst->n_global_syms = 0;
2960 subpst->statics_offset = 0;
2961 subpst->n_static_syms = 0;
2962 subpst->symtab = NULL;
2963 subpst->read_symtab = pst->read_symtab;
2966 /* No private part is necessary for include psymtabs. This property
2967 can be used to differentiate between such include psymtabs and
2968 the regular ones. */
2969 subpst->read_symtab_private = NULL;
2972 /* Read the Line Number Program data and extract the list of files
2973 included by the source file represented by PST. Build an include
2974 partial symtab for each of these included files. */
2977 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2978 struct die_info *die,
2979 struct partial_symtab *pst)
2981 struct objfile *objfile = cu->objfile;
2982 bfd *abfd = objfile->obfd;
2983 struct line_header *lh = NULL;
2984 struct attribute *attr;
2986 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2989 unsigned int line_offset = DW_UNSND (attr);
2991 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2994 return; /* No linetable, so no includes. */
2996 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2997 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
2999 free_line_header (lh);
3003 hash_type_signature (const void *item)
3005 const struct signatured_type *type_sig = item;
3007 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3008 return type_sig->signature;
3012 eq_type_signature (const void *item_lhs, const void *item_rhs)
3014 const struct signatured_type *lhs = item_lhs;
3015 const struct signatured_type *rhs = item_rhs;
3017 return lhs->signature == rhs->signature;
3020 /* Allocate a hash table for signatured types. */
3023 allocate_signatured_type_table (struct objfile *objfile)
3025 return htab_create_alloc_ex (41,
3026 hash_type_signature,
3029 &objfile->objfile_obstack,
3030 hashtab_obstack_allocate,
3031 dummy_obstack_deallocate);
3034 /* A helper function to add a signatured type CU to a list. */
3037 add_signatured_type_cu_to_list (void **slot, void *datum)
3039 struct signatured_type *sigt = *slot;
3040 struct dwarf2_per_cu_data ***datap = datum;
3042 **datap = &sigt->per_cu;
3048 /* Create the hash table of all entries in the .debug_types section.
3049 The result is zero if there is an error (e.g. missing .debug_types section),
3050 otherwise non-zero. */
3053 create_debug_types_hash_table (struct objfile *objfile)
3057 struct dwarf2_per_cu_data **iter;
3059 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
3060 info_ptr = dwarf2_per_objfile->types.buffer;
3062 if (info_ptr == NULL)
3064 dwarf2_per_objfile->signatured_types = NULL;
3068 types_htab = allocate_signatured_type_table (objfile);
3070 if (dwarf2_die_debug)
3071 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3073 while (info_ptr < dwarf2_per_objfile->types.buffer
3074 + dwarf2_per_objfile->types.size)
3076 unsigned int offset;
3077 unsigned int offset_size;
3078 unsigned int type_offset;
3079 unsigned int length, initial_length_size;
3080 unsigned short version;
3082 struct signatured_type *type_sig;
3084 gdb_byte *ptr = info_ptr;
3086 offset = ptr - dwarf2_per_objfile->types.buffer;
3088 /* We need to read the type's signature in order to build the hash
3089 table, but we don't need to read anything else just yet. */
3091 /* Sanity check to ensure entire cu is present. */
3092 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
3093 if (ptr + length + initial_length_size
3094 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
3096 complaint (&symfile_complaints,
3097 _("debug type entry runs off end "
3098 "of `.debug_types' section, ignored"));
3102 offset_size = initial_length_size == 4 ? 4 : 8;
3103 ptr += initial_length_size;
3104 version = bfd_get_16 (objfile->obfd, ptr);
3106 ptr += offset_size; /* abbrev offset */
3107 ptr += 1; /* address size */
3108 signature = bfd_get_64 (objfile->obfd, ptr);
3110 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3112 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3113 memset (type_sig, 0, sizeof (*type_sig));
3114 type_sig->signature = signature;
3115 type_sig->type_offset = type_offset;
3116 type_sig->per_cu.objfile = objfile;
3117 type_sig->per_cu.from_debug_types = 1;
3118 type_sig->per_cu.offset = offset;
3120 slot = htab_find_slot (types_htab, type_sig, INSERT);
3121 gdb_assert (slot != NULL);
3124 const struct signatured_type *dup_sig = *slot;
3126 complaint (&symfile_complaints,
3127 _("debug type entry at offset 0x%x is duplicate to the "
3128 "entry at offset 0x%x, signature 0x%s"),
3129 offset, dup_sig->per_cu.offset,
3130 phex (signature, sizeof (signature)));
3131 gdb_assert (signature == dup_sig->signature);
3135 if (dwarf2_die_debug)
3136 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3137 offset, phex (signature, sizeof (signature)));
3139 info_ptr = info_ptr + initial_length_size + length;
3142 dwarf2_per_objfile->signatured_types = types_htab;
3144 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3145 dwarf2_per_objfile->type_comp_units
3146 = obstack_alloc (&objfile->objfile_obstack,
3147 dwarf2_per_objfile->n_type_comp_units
3148 * sizeof (struct dwarf2_per_cu_data *));
3149 iter = &dwarf2_per_objfile->type_comp_units[0];
3150 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3151 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3152 == dwarf2_per_objfile->n_type_comp_units);
3157 /* Lookup a signature based type.
3158 Returns NULL if SIG is not present in the table. */
3160 static struct signatured_type *
3161 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3163 struct signatured_type find_entry, *entry;
3165 if (dwarf2_per_objfile->signatured_types == NULL)
3167 complaint (&symfile_complaints,
3168 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3172 find_entry.signature = sig;
3173 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3177 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3180 init_cu_die_reader (struct die_reader_specs *reader,
3181 struct dwarf2_cu *cu)
3183 reader->abfd = cu->objfile->obfd;
3185 if (cu->per_cu->from_debug_types)
3187 gdb_assert (dwarf2_per_objfile->types.readin);
3188 reader->buffer = dwarf2_per_objfile->types.buffer;
3192 gdb_assert (dwarf2_per_objfile->info.readin);
3193 reader->buffer = dwarf2_per_objfile->info.buffer;
3197 /* Find the base address of the compilation unit for range lists and
3198 location lists. It will normally be specified by DW_AT_low_pc.
3199 In DWARF-3 draft 4, the base address could be overridden by
3200 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3201 compilation units with discontinuous ranges. */
3204 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3206 struct attribute *attr;
3209 cu->base_address = 0;
3211 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3214 cu->base_address = DW_ADDR (attr);
3219 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3222 cu->base_address = DW_ADDR (attr);
3228 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3229 to combine the common parts.
3230 Process a compilation unit for a psymtab.
3231 BUFFER is a pointer to the beginning of the dwarf section buffer,
3232 either .debug_info or debug_types.
3233 INFO_PTR is a pointer to the start of the CU.
3234 Returns a pointer to the next CU. */
3237 process_psymtab_comp_unit (struct objfile *objfile,
3238 struct dwarf2_per_cu_data *this_cu,
3239 gdb_byte *buffer, gdb_byte *info_ptr,
3240 unsigned int buffer_size)
3242 bfd *abfd = objfile->obfd;
3243 gdb_byte *beg_of_comp_unit = info_ptr;
3244 struct die_info *comp_unit_die;
3245 struct partial_symtab *pst;
3247 struct cleanup *back_to_inner;
3248 struct dwarf2_cu cu;
3249 int has_children, has_pc_info;
3250 struct attribute *attr;
3251 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3252 struct die_reader_specs reader_specs;
3253 const char *filename;
3255 init_one_comp_unit (&cu, objfile);
3256 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3258 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3259 buffer, buffer_size,
3262 /* Complete the cu_header. */
3263 cu.header.offset = beg_of_comp_unit - buffer;
3264 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3266 cu.list_in_scope = &file_symbols;
3268 /* If this compilation unit was already read in, free the
3269 cached copy in order to read it in again. This is
3270 necessary because we skipped some symbols when we first
3271 read in the compilation unit (see load_partial_dies).
3272 This problem could be avoided, but the benefit is
3274 if (this_cu->cu != NULL)
3275 free_one_cached_comp_unit (this_cu->cu);
3277 /* Note that this is a pointer to our stack frame, being
3278 added to a global data structure. It will be cleaned up
3279 in free_stack_comp_unit when we finish with this
3280 compilation unit. */
3282 cu.per_cu = this_cu;
3284 /* Read the abbrevs for this compilation unit into a table. */
3285 dwarf2_read_abbrevs (abfd, &cu);
3286 make_cleanup (dwarf2_free_abbrev_table, &cu);
3288 /* Read the compilation unit die. */
3289 if (this_cu->from_debug_types)
3290 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3291 init_cu_die_reader (&reader_specs, &cu);
3292 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3295 if (this_cu->from_debug_types)
3297 /* LENGTH has not been set yet for type units. */
3298 gdb_assert (this_cu->offset == cu.header.offset);
3299 this_cu->length = cu.header.length + cu.header.initial_length_size;
3301 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3303 info_ptr = (beg_of_comp_unit + cu.header.length
3304 + cu.header.initial_length_size);
3305 do_cleanups (back_to_inner);
3309 prepare_one_comp_unit (&cu, comp_unit_die);
3311 /* Allocate a new partial symbol table structure. */
3312 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3313 if (attr == NULL || !DW_STRING (attr))
3316 filename = DW_STRING (attr);
3317 pst = start_psymtab_common (objfile, objfile->section_offsets,
3319 /* TEXTLOW and TEXTHIGH are set below. */
3321 objfile->global_psymbols.next,
3322 objfile->static_psymbols.next);
3324 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3326 pst->dirname = DW_STRING (attr);
3328 pst->read_symtab_private = this_cu;
3330 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3332 /* Store the function that reads in the rest of the symbol table. */
3333 pst->read_symtab = dwarf2_psymtab_to_symtab;
3335 this_cu->v.psymtab = pst;
3337 dwarf2_find_base_address (comp_unit_die, &cu);
3339 /* Possibly set the default values of LOWPC and HIGHPC from
3341 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3342 &best_highpc, &cu, pst);
3343 if (has_pc_info == 1 && best_lowpc < best_highpc)
3344 /* Store the contiguous range if it is not empty; it can be empty for
3345 CUs with no code. */
3346 addrmap_set_empty (objfile->psymtabs_addrmap,
3347 best_lowpc + baseaddr,
3348 best_highpc + baseaddr - 1, pst);
3350 /* Check if comp unit has_children.
3351 If so, read the rest of the partial symbols from this comp unit.
3352 If not, there's no more debug_info for this comp unit. */
3355 struct partial_die_info *first_die;
3356 CORE_ADDR lowpc, highpc;
3358 lowpc = ((CORE_ADDR) -1);
3359 highpc = ((CORE_ADDR) 0);
3361 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3363 scan_partial_symbols (first_die, &lowpc, &highpc,
3364 ! has_pc_info, &cu);
3366 /* If we didn't find a lowpc, set it to highpc to avoid
3367 complaints from `maint check'. */
3368 if (lowpc == ((CORE_ADDR) -1))
3371 /* If the compilation unit didn't have an explicit address range,
3372 then use the information extracted from its child dies. */
3376 best_highpc = highpc;
3379 pst->textlow = best_lowpc + baseaddr;
3380 pst->texthigh = best_highpc + baseaddr;
3382 pst->n_global_syms = objfile->global_psymbols.next -
3383 (objfile->global_psymbols.list + pst->globals_offset);
3384 pst->n_static_syms = objfile->static_psymbols.next -
3385 (objfile->static_psymbols.list + pst->statics_offset);
3386 sort_pst_symbols (pst);
3388 info_ptr = (beg_of_comp_unit + cu.header.length
3389 + cu.header.initial_length_size);
3391 if (this_cu->from_debug_types)
3393 /* It's not clear we want to do anything with stmt lists here.
3394 Waiting to see what gcc ultimately does. */
3398 /* Get the list of files included in the current compilation unit,
3399 and build a psymtab for each of them. */
3400 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3403 do_cleanups (back_to_inner);
3408 /* Traversal function for htab_traverse_noresize.
3409 Process one .debug_types comp-unit. */
3412 process_type_comp_unit (void **slot, void *info)
3414 struct signatured_type *entry = (struct signatured_type *) *slot;
3415 struct objfile *objfile = (struct objfile *) info;
3416 struct dwarf2_per_cu_data *this_cu;
3418 this_cu = &entry->per_cu;
3420 gdb_assert (dwarf2_per_objfile->types.readin);
3421 process_psymtab_comp_unit (objfile, this_cu,
3422 dwarf2_per_objfile->types.buffer,
3423 dwarf2_per_objfile->types.buffer + this_cu->offset,
3424 dwarf2_per_objfile->types.size);
3429 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3430 Build partial symbol tables for the .debug_types comp-units. */
3433 build_type_psymtabs (struct objfile *objfile)
3435 if (! create_debug_types_hash_table (objfile))
3438 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3439 process_type_comp_unit, objfile);
3442 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3445 psymtabs_addrmap_cleanup (void *o)
3447 struct objfile *objfile = o;
3449 objfile->psymtabs_addrmap = NULL;
3452 /* Build the partial symbol table by doing a quick pass through the
3453 .debug_info and .debug_abbrev sections. */
3456 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3459 struct cleanup *back_to, *addrmap_cleanup;
3460 struct obstack temp_obstack;
3462 dwarf2_per_objfile->reading_partial_symbols = 1;
3464 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3465 info_ptr = dwarf2_per_objfile->info.buffer;
3467 /* Any cached compilation units will be linked by the per-objfile
3468 read_in_chain. Make sure to free them when we're done. */
3469 back_to = make_cleanup (free_cached_comp_units, NULL);
3471 build_type_psymtabs (objfile);
3473 create_all_comp_units (objfile);
3475 /* Create a temporary address map on a temporary obstack. We later
3476 copy this to the final obstack. */
3477 obstack_init (&temp_obstack);
3478 make_cleanup_obstack_free (&temp_obstack);
3479 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3480 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3482 /* Since the objects we're extracting from .debug_info vary in
3483 length, only the individual functions to extract them (like
3484 read_comp_unit_head and load_partial_die) can really know whether
3485 the buffer is large enough to hold another complete object.
3487 At the moment, they don't actually check that. If .debug_info
3488 holds just one extra byte after the last compilation unit's dies,
3489 then read_comp_unit_head will happily read off the end of the
3490 buffer. read_partial_die is similarly casual. Those functions
3493 For this loop condition, simply checking whether there's any data
3494 left at all should be sufficient. */
3496 while (info_ptr < (dwarf2_per_objfile->info.buffer
3497 + dwarf2_per_objfile->info.size))
3499 struct dwarf2_per_cu_data *this_cu;
3501 this_cu = dwarf2_find_comp_unit (info_ptr
3502 - dwarf2_per_objfile->info.buffer,
3505 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3506 dwarf2_per_objfile->info.buffer,
3508 dwarf2_per_objfile->info.size);
3511 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3512 &objfile->objfile_obstack);
3513 discard_cleanups (addrmap_cleanup);
3515 do_cleanups (back_to);
3518 /* Load the partial DIEs for a secondary CU into memory. */
3521 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3522 struct objfile *objfile)
3524 bfd *abfd = objfile->obfd;
3525 gdb_byte *info_ptr, *beg_of_comp_unit;
3526 struct die_info *comp_unit_die;
3527 struct dwarf2_cu *cu;
3528 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3530 struct die_reader_specs reader_specs;
3533 gdb_assert (! this_cu->from_debug_types);
3535 gdb_assert (dwarf2_per_objfile->info.readin);
3536 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3537 beg_of_comp_unit = info_ptr;
3539 if (this_cu->cu == NULL)
3541 cu = xmalloc (sizeof (*cu));
3542 init_one_comp_unit (cu, objfile);
3546 /* If an error occurs while loading, release our storage. */
3547 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3549 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3550 dwarf2_per_objfile->info.buffer,
3551 dwarf2_per_objfile->info.size,
3554 /* Complete the cu_header. */
3555 cu->header.offset = this_cu->offset;
3556 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3558 /* Link this compilation unit into the compilation unit tree. */
3560 cu->per_cu = this_cu;
3562 /* Link this CU into read_in_chain. */
3563 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3564 dwarf2_per_objfile->read_in_chain = this_cu;
3569 info_ptr += cu->header.first_die_offset;
3572 /* Read the abbrevs for this compilation unit into a table. */
3573 gdb_assert (cu->dwarf2_abbrevs == NULL);
3574 dwarf2_read_abbrevs (abfd, cu);
3575 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3577 /* Read the compilation unit die. */
3578 init_cu_die_reader (&reader_specs, cu);
3579 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3582 prepare_one_comp_unit (cu, comp_unit_die);
3584 /* Check if comp unit has_children.
3585 If so, read the rest of the partial symbols from this comp unit.
3586 If not, there's no more debug_info for this comp unit. */
3588 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3590 do_cleanups (free_abbrevs_cleanup);
3594 /* We've successfully allocated this compilation unit. Let our
3595 caller clean it up when finished with it. */
3596 discard_cleanups (free_cu_cleanup);
3600 /* Create a list of all compilation units in OBJFILE. We do this only
3601 if an inter-comp-unit reference is found; presumably if there is one,
3602 there will be many, and one will occur early in the .debug_info section.
3603 So there's no point in building this list incrementally. */
3606 create_all_comp_units (struct objfile *objfile)
3610 struct dwarf2_per_cu_data **all_comp_units;
3613 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3614 info_ptr = dwarf2_per_objfile->info.buffer;
3618 all_comp_units = xmalloc (n_allocated
3619 * sizeof (struct dwarf2_per_cu_data *));
3621 while (info_ptr < dwarf2_per_objfile->info.buffer
3622 + dwarf2_per_objfile->info.size)
3624 unsigned int length, initial_length_size;
3625 struct dwarf2_per_cu_data *this_cu;
3626 unsigned int offset;
3628 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3630 /* Read just enough information to find out where the next
3631 compilation unit is. */
3632 length = read_initial_length (objfile->obfd, info_ptr,
3633 &initial_length_size);
3635 /* Save the compilation unit for later lookup. */
3636 this_cu = obstack_alloc (&objfile->objfile_obstack,
3637 sizeof (struct dwarf2_per_cu_data));
3638 memset (this_cu, 0, sizeof (*this_cu));
3639 this_cu->offset = offset;
3640 this_cu->length = length + initial_length_size;
3641 this_cu->objfile = objfile;
3643 if (n_comp_units == n_allocated)
3646 all_comp_units = xrealloc (all_comp_units,
3648 * sizeof (struct dwarf2_per_cu_data *));
3650 all_comp_units[n_comp_units++] = this_cu;
3652 info_ptr = info_ptr + this_cu->length;
3655 dwarf2_per_objfile->all_comp_units
3656 = obstack_alloc (&objfile->objfile_obstack,
3657 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3658 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3659 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3660 xfree (all_comp_units);
3661 dwarf2_per_objfile->n_comp_units = n_comp_units;
3664 /* Process all loaded DIEs for compilation unit CU, starting at
3665 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3666 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3667 DW_AT_ranges). If NEED_PC is set, then this function will set
3668 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3669 and record the covered ranges in the addrmap. */
3672 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3673 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3675 struct partial_die_info *pdi;
3677 /* Now, march along the PDI's, descending into ones which have
3678 interesting children but skipping the children of the other ones,
3679 until we reach the end of the compilation unit. */
3685 fixup_partial_die (pdi, cu);
3687 /* Anonymous namespaces or modules have no name but have interesting
3688 children, so we need to look at them. Ditto for anonymous
3691 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3692 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3696 case DW_TAG_subprogram:
3697 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3699 case DW_TAG_constant:
3700 case DW_TAG_variable:
3701 case DW_TAG_typedef:
3702 case DW_TAG_union_type:
3703 if (!pdi->is_declaration)
3705 add_partial_symbol (pdi, cu);
3708 case DW_TAG_class_type:
3709 case DW_TAG_interface_type:
3710 case DW_TAG_structure_type:
3711 if (!pdi->is_declaration)
3713 add_partial_symbol (pdi, cu);
3716 case DW_TAG_enumeration_type:
3717 if (!pdi->is_declaration)
3718 add_partial_enumeration (pdi, cu);
3720 case DW_TAG_base_type:
3721 case DW_TAG_subrange_type:
3722 /* File scope base type definitions are added to the partial
3724 add_partial_symbol (pdi, cu);
3726 case DW_TAG_namespace:
3727 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3730 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3737 /* If the die has a sibling, skip to the sibling. */
3739 pdi = pdi->die_sibling;
3743 /* Functions used to compute the fully scoped name of a partial DIE.
3745 Normally, this is simple. For C++, the parent DIE's fully scoped
3746 name is concatenated with "::" and the partial DIE's name. For
3747 Java, the same thing occurs except that "." is used instead of "::".
3748 Enumerators are an exception; they use the scope of their parent
3749 enumeration type, i.e. the name of the enumeration type is not
3750 prepended to the enumerator.
3752 There are two complexities. One is DW_AT_specification; in this
3753 case "parent" means the parent of the target of the specification,
3754 instead of the direct parent of the DIE. The other is compilers
3755 which do not emit DW_TAG_namespace; in this case we try to guess
3756 the fully qualified name of structure types from their members'
3757 linkage names. This must be done using the DIE's children rather
3758 than the children of any DW_AT_specification target. We only need
3759 to do this for structures at the top level, i.e. if the target of
3760 any DW_AT_specification (if any; otherwise the DIE itself) does not
3763 /* Compute the scope prefix associated with PDI's parent, in
3764 compilation unit CU. The result will be allocated on CU's
3765 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3766 field. NULL is returned if no prefix is necessary. */
3768 partial_die_parent_scope (struct partial_die_info *pdi,
3769 struct dwarf2_cu *cu)
3771 char *grandparent_scope;
3772 struct partial_die_info *parent, *real_pdi;
3774 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3775 then this means the parent of the specification DIE. */
3778 while (real_pdi->has_specification)
3779 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3781 parent = real_pdi->die_parent;
3785 if (parent->scope_set)
3786 return parent->scope;
3788 fixup_partial_die (parent, cu);
3790 grandparent_scope = partial_die_parent_scope (parent, cu);
3792 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3793 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3794 Work around this problem here. */
3795 if (cu->language == language_cplus
3796 && parent->tag == DW_TAG_namespace
3797 && strcmp (parent->name, "::") == 0
3798 && grandparent_scope == NULL)
3800 parent->scope = NULL;
3801 parent->scope_set = 1;
3805 if (parent->tag == DW_TAG_namespace
3806 || parent->tag == DW_TAG_module
3807 || parent->tag == DW_TAG_structure_type
3808 || parent->tag == DW_TAG_class_type
3809 || parent->tag == DW_TAG_interface_type
3810 || parent->tag == DW_TAG_union_type
3811 || parent->tag == DW_TAG_enumeration_type)
3813 if (grandparent_scope == NULL)
3814 parent->scope = parent->name;
3816 parent->scope = typename_concat (&cu->comp_unit_obstack,
3818 parent->name, 0, cu);
3820 else if (parent->tag == DW_TAG_enumerator)
3821 /* Enumerators should not get the name of the enumeration as a prefix. */
3822 parent->scope = grandparent_scope;
3825 /* FIXME drow/2004-04-01: What should we be doing with
3826 function-local names? For partial symbols, we should probably be
3828 complaint (&symfile_complaints,
3829 _("unhandled containing DIE tag %d for DIE at %d"),
3830 parent->tag, pdi->offset);
3831 parent->scope = grandparent_scope;
3834 parent->scope_set = 1;
3835 return parent->scope;
3838 /* Return the fully scoped name associated with PDI, from compilation unit
3839 CU. The result will be allocated with malloc. */
3841 partial_die_full_name (struct partial_die_info *pdi,
3842 struct dwarf2_cu *cu)
3846 /* If this is a template instantiation, we can not work out the
3847 template arguments from partial DIEs. So, unfortunately, we have
3848 to go through the full DIEs. At least any work we do building
3849 types here will be reused if full symbols are loaded later. */
3850 if (pdi->has_template_arguments)
3852 fixup_partial_die (pdi, cu);
3854 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3856 struct die_info *die;
3857 struct attribute attr;
3858 struct dwarf2_cu *ref_cu = cu;
3861 attr.form = DW_FORM_ref_addr;
3862 attr.u.addr = pdi->offset;
3863 die = follow_die_ref (NULL, &attr, &ref_cu);
3865 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3869 parent_scope = partial_die_parent_scope (pdi, cu);
3870 if (parent_scope == NULL)
3873 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3877 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3879 struct objfile *objfile = cu->objfile;
3881 char *actual_name = NULL;
3882 const struct partial_symbol *psym = NULL;
3884 int built_actual_name = 0;
3886 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3888 actual_name = partial_die_full_name (pdi, cu);
3890 built_actual_name = 1;
3892 if (actual_name == NULL)
3893 actual_name = pdi->name;
3897 case DW_TAG_subprogram:
3898 if (pdi->is_external || cu->language == language_ada)
3900 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3901 of the global scope. But in Ada, we want to be able to access
3902 nested procedures globally. So all Ada subprograms are stored
3903 in the global scope. */
3904 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3905 mst_text, objfile); */
3906 add_psymbol_to_list (actual_name, strlen (actual_name),
3908 VAR_DOMAIN, LOC_BLOCK,
3909 &objfile->global_psymbols,
3910 0, pdi->lowpc + baseaddr,
3911 cu->language, objfile);
3915 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3916 mst_file_text, objfile); */
3917 add_psymbol_to_list (actual_name, strlen (actual_name),
3919 VAR_DOMAIN, LOC_BLOCK,
3920 &objfile->static_psymbols,
3921 0, pdi->lowpc + baseaddr,
3922 cu->language, objfile);
3925 case DW_TAG_constant:
3927 struct psymbol_allocation_list *list;
3929 if (pdi->is_external)
3930 list = &objfile->global_psymbols;
3932 list = &objfile->static_psymbols;
3933 add_psymbol_to_list (actual_name, strlen (actual_name),
3934 built_actual_name, VAR_DOMAIN, LOC_STATIC,
3935 list, 0, 0, cu->language, objfile);
3938 case DW_TAG_variable:
3940 addr = decode_locdesc (pdi->locdesc, cu);
3944 && !dwarf2_per_objfile->has_section_at_zero)
3946 /* A global or static variable may also have been stripped
3947 out by the linker if unused, in which case its address
3948 will be nullified; do not add such variables into partial
3949 symbol table then. */
3951 else if (pdi->is_external)
3954 Don't enter into the minimal symbol tables as there is
3955 a minimal symbol table entry from the ELF symbols already.
3956 Enter into partial symbol table if it has a location
3957 descriptor or a type.
3958 If the location descriptor is missing, new_symbol will create
3959 a LOC_UNRESOLVED symbol, the address of the variable will then
3960 be determined from the minimal symbol table whenever the variable
3962 The address for the partial symbol table entry is not
3963 used by GDB, but it comes in handy for debugging partial symbol
3966 if (pdi->locdesc || pdi->has_type)
3967 add_psymbol_to_list (actual_name, strlen (actual_name),
3969 VAR_DOMAIN, LOC_STATIC,
3970 &objfile->global_psymbols,
3972 cu->language, objfile);
3976 /* Static Variable. Skip symbols without location descriptors. */
3977 if (pdi->locdesc == NULL)
3979 if (built_actual_name)
3980 xfree (actual_name);
3983 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3984 mst_file_data, objfile); */
3985 add_psymbol_to_list (actual_name, strlen (actual_name),
3987 VAR_DOMAIN, LOC_STATIC,
3988 &objfile->static_psymbols,
3990 cu->language, objfile);
3993 case DW_TAG_typedef:
3994 case DW_TAG_base_type:
3995 case DW_TAG_subrange_type:
3996 add_psymbol_to_list (actual_name, strlen (actual_name),
3998 VAR_DOMAIN, LOC_TYPEDEF,
3999 &objfile->static_psymbols,
4000 0, (CORE_ADDR) 0, cu->language, objfile);
4002 case DW_TAG_namespace:
4003 add_psymbol_to_list (actual_name, strlen (actual_name),
4005 VAR_DOMAIN, LOC_TYPEDEF,
4006 &objfile->global_psymbols,
4007 0, (CORE_ADDR) 0, cu->language, objfile);
4009 case DW_TAG_class_type:
4010 case DW_TAG_interface_type:
4011 case DW_TAG_structure_type:
4012 case DW_TAG_union_type:
4013 case DW_TAG_enumeration_type:
4014 /* Skip external references. The DWARF standard says in the section
4015 about "Structure, Union, and Class Type Entries": "An incomplete
4016 structure, union or class type is represented by a structure,
4017 union or class entry that does not have a byte size attribute
4018 and that has a DW_AT_declaration attribute." */
4019 if (!pdi->has_byte_size && pdi->is_declaration)
4021 if (built_actual_name)
4022 xfree (actual_name);
4026 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4027 static vs. global. */
4028 add_psymbol_to_list (actual_name, strlen (actual_name),
4030 STRUCT_DOMAIN, LOC_TYPEDEF,
4031 (cu->language == language_cplus
4032 || cu->language == language_java)
4033 ? &objfile->global_psymbols
4034 : &objfile->static_psymbols,
4035 0, (CORE_ADDR) 0, cu->language, objfile);
4038 case DW_TAG_enumerator:
4039 add_psymbol_to_list (actual_name, strlen (actual_name),
4041 VAR_DOMAIN, LOC_CONST,
4042 (cu->language == language_cplus
4043 || cu->language == language_java)
4044 ? &objfile->global_psymbols
4045 : &objfile->static_psymbols,
4046 0, (CORE_ADDR) 0, cu->language, objfile);
4052 if (built_actual_name)
4053 xfree (actual_name);
4056 /* Read a partial die corresponding to a namespace; also, add a symbol
4057 corresponding to that namespace to the symbol table. NAMESPACE is
4058 the name of the enclosing namespace. */
4061 add_partial_namespace (struct partial_die_info *pdi,
4062 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4063 int need_pc, struct dwarf2_cu *cu)
4065 /* Add a symbol for the namespace. */
4067 add_partial_symbol (pdi, cu);
4069 /* Now scan partial symbols in that namespace. */
4071 if (pdi->has_children)
4072 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4075 /* Read a partial die corresponding to a Fortran module. */
4078 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4079 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4081 /* Now scan partial symbols in that module. */
4083 if (pdi->has_children)
4084 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4087 /* Read a partial die corresponding to a subprogram and create a partial
4088 symbol for that subprogram. When the CU language allows it, this
4089 routine also defines a partial symbol for each nested subprogram
4090 that this subprogram contains.
4092 DIE my also be a lexical block, in which case we simply search
4093 recursively for suprograms defined inside that lexical block.
4094 Again, this is only performed when the CU language allows this
4095 type of definitions. */
4098 add_partial_subprogram (struct partial_die_info *pdi,
4099 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4100 int need_pc, struct dwarf2_cu *cu)
4102 if (pdi->tag == DW_TAG_subprogram)
4104 if (pdi->has_pc_info)
4106 if (pdi->lowpc < *lowpc)
4107 *lowpc = pdi->lowpc;
4108 if (pdi->highpc > *highpc)
4109 *highpc = pdi->highpc;
4113 struct objfile *objfile = cu->objfile;
4115 baseaddr = ANOFFSET (objfile->section_offsets,
4116 SECT_OFF_TEXT (objfile));
4117 addrmap_set_empty (objfile->psymtabs_addrmap,
4118 pdi->lowpc + baseaddr,
4119 pdi->highpc - 1 + baseaddr,
4120 cu->per_cu->v.psymtab);
4122 if (!pdi->is_declaration)
4123 /* Ignore subprogram DIEs that do not have a name, they are
4124 illegal. Do not emit a complaint at this point, we will
4125 do so when we convert this psymtab into a symtab. */
4127 add_partial_symbol (pdi, cu);
4131 if (! pdi->has_children)
4134 if (cu->language == language_ada)
4136 pdi = pdi->die_child;
4139 fixup_partial_die (pdi, cu);
4140 if (pdi->tag == DW_TAG_subprogram
4141 || pdi->tag == DW_TAG_lexical_block)
4142 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4143 pdi = pdi->die_sibling;
4148 /* Read a partial die corresponding to an enumeration type. */
4151 add_partial_enumeration (struct partial_die_info *enum_pdi,
4152 struct dwarf2_cu *cu)
4154 struct partial_die_info *pdi;
4156 if (enum_pdi->name != NULL)
4157 add_partial_symbol (enum_pdi, cu);
4159 pdi = enum_pdi->die_child;
4162 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4163 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4165 add_partial_symbol (pdi, cu);
4166 pdi = pdi->die_sibling;
4170 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4171 Return the corresponding abbrev, or NULL if the number is zero (indicating
4172 an empty DIE). In either case *BYTES_READ will be set to the length of
4173 the initial number. */
4175 static struct abbrev_info *
4176 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4177 struct dwarf2_cu *cu)
4179 bfd *abfd = cu->objfile->obfd;
4180 unsigned int abbrev_number;
4181 struct abbrev_info *abbrev;
4183 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4185 if (abbrev_number == 0)
4188 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4191 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4192 abbrev_number, bfd_get_filename (abfd));
4198 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4199 Returns a pointer to the end of a series of DIEs, terminated by an empty
4200 DIE. Any children of the skipped DIEs will also be skipped. */
4203 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4205 struct abbrev_info *abbrev;
4206 unsigned int bytes_read;
4210 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4212 return info_ptr + bytes_read;
4214 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4218 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4219 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4220 abbrev corresponding to that skipped uleb128 should be passed in
4221 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4225 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4226 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4228 unsigned int bytes_read;
4229 struct attribute attr;
4230 bfd *abfd = cu->objfile->obfd;
4231 unsigned int form, i;
4233 for (i = 0; i < abbrev->num_attrs; i++)
4235 /* The only abbrev we care about is DW_AT_sibling. */
4236 if (abbrev->attrs[i].name == DW_AT_sibling)
4238 read_attribute (&attr, &abbrev->attrs[i],
4239 abfd, info_ptr, cu);
4240 if (attr.form == DW_FORM_ref_addr)
4241 complaint (&symfile_complaints,
4242 _("ignoring absolute DW_AT_sibling"));
4244 return buffer + dwarf2_get_ref_die_offset (&attr);
4247 /* If it isn't DW_AT_sibling, skip this attribute. */
4248 form = abbrev->attrs[i].form;
4252 case DW_FORM_ref_addr:
4253 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4254 and later it is offset sized. */
4255 if (cu->header.version == 2)
4256 info_ptr += cu->header.addr_size;
4258 info_ptr += cu->header.offset_size;
4261 info_ptr += cu->header.addr_size;
4268 case DW_FORM_flag_present:
4280 case DW_FORM_ref_sig8:
4283 case DW_FORM_string:
4284 read_direct_string (abfd, info_ptr, &bytes_read);
4285 info_ptr += bytes_read;
4287 case DW_FORM_sec_offset:
4289 info_ptr += cu->header.offset_size;
4291 case DW_FORM_exprloc:
4293 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4294 info_ptr += bytes_read;
4296 case DW_FORM_block1:
4297 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4299 case DW_FORM_block2:
4300 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4302 case DW_FORM_block4:
4303 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4307 case DW_FORM_ref_udata:
4308 info_ptr = skip_leb128 (abfd, info_ptr);
4310 case DW_FORM_indirect:
4311 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4312 info_ptr += bytes_read;
4313 /* We need to continue parsing from here, so just go back to
4315 goto skip_attribute;
4318 error (_("Dwarf Error: Cannot handle %s "
4319 "in DWARF reader [in module %s]"),
4320 dwarf_form_name (form),
4321 bfd_get_filename (abfd));
4325 if (abbrev->has_children)
4326 return skip_children (buffer, info_ptr, cu);
4331 /* Locate ORIG_PDI's sibling.
4332 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4336 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4337 gdb_byte *buffer, gdb_byte *info_ptr,
4338 bfd *abfd, struct dwarf2_cu *cu)
4340 /* Do we know the sibling already? */
4342 if (orig_pdi->sibling)
4343 return orig_pdi->sibling;
4345 /* Are there any children to deal with? */
4347 if (!orig_pdi->has_children)
4350 /* Skip the children the long way. */
4352 return skip_children (buffer, info_ptr, cu);
4355 /* Expand this partial symbol table into a full symbol table. */
4358 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4364 warning (_("bug: psymtab for %s is already read in."),
4371 printf_filtered (_("Reading in symbols for %s..."),
4373 gdb_flush (gdb_stdout);
4376 /* Restore our global data. */
4377 dwarf2_per_objfile = objfile_data (pst->objfile,
4378 dwarf2_objfile_data_key);
4380 /* If this psymtab is constructed from a debug-only objfile, the
4381 has_section_at_zero flag will not necessarily be correct. We
4382 can get the correct value for this flag by looking at the data
4383 associated with the (presumably stripped) associated objfile. */
4384 if (pst->objfile->separate_debug_objfile_backlink)
4386 struct dwarf2_per_objfile *dpo_backlink
4387 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4388 dwarf2_objfile_data_key);
4390 dwarf2_per_objfile->has_section_at_zero
4391 = dpo_backlink->has_section_at_zero;
4394 dwarf2_per_objfile->reading_partial_symbols = 0;
4396 psymtab_to_symtab_1 (pst);
4398 /* Finish up the debug error message. */
4400 printf_filtered (_("done.\n"));
4405 /* Add PER_CU to the queue. */
4408 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4410 struct dwarf2_queue_item *item;
4413 item = xmalloc (sizeof (*item));
4414 item->per_cu = per_cu;
4417 if (dwarf2_queue == NULL)
4418 dwarf2_queue = item;
4420 dwarf2_queue_tail->next = item;
4422 dwarf2_queue_tail = item;
4425 /* Process the queue. */
4428 process_queue (struct objfile *objfile)
4430 struct dwarf2_queue_item *item, *next_item;
4432 /* The queue starts out with one item, but following a DIE reference
4433 may load a new CU, adding it to the end of the queue. */
4434 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4436 if (dwarf2_per_objfile->using_index
4437 ? !item->per_cu->v.quick->symtab
4438 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4439 process_full_comp_unit (item->per_cu);
4441 item->per_cu->queued = 0;
4442 next_item = item->next;
4446 dwarf2_queue_tail = NULL;
4449 /* Free all allocated queue entries. This function only releases anything if
4450 an error was thrown; if the queue was processed then it would have been
4451 freed as we went along. */
4454 dwarf2_release_queue (void *dummy)
4456 struct dwarf2_queue_item *item, *last;
4458 item = dwarf2_queue;
4461 /* Anything still marked queued is likely to be in an
4462 inconsistent state, so discard it. */
4463 if (item->per_cu->queued)
4465 if (item->per_cu->cu != NULL)
4466 free_one_cached_comp_unit (item->per_cu->cu);
4467 item->per_cu->queued = 0;
4475 dwarf2_queue = dwarf2_queue_tail = NULL;
4478 /* Read in full symbols for PST, and anything it depends on. */
4481 psymtab_to_symtab_1 (struct partial_symtab *pst)
4483 struct dwarf2_per_cu_data *per_cu;
4484 struct cleanup *back_to;
4487 for (i = 0; i < pst->number_of_dependencies; i++)
4488 if (!pst->dependencies[i]->readin)
4490 /* Inform about additional files that need to be read in. */
4493 /* FIXME: i18n: Need to make this a single string. */
4494 fputs_filtered (" ", gdb_stdout);
4496 fputs_filtered ("and ", gdb_stdout);
4498 printf_filtered ("%s...", pst->dependencies[i]->filename);
4499 wrap_here (""); /* Flush output. */
4500 gdb_flush (gdb_stdout);
4502 psymtab_to_symtab_1 (pst->dependencies[i]);
4505 per_cu = pst->read_symtab_private;
4509 /* It's an include file, no symbols to read for it.
4510 Everything is in the parent symtab. */
4515 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4518 /* Load the DIEs associated with PER_CU into memory. */
4521 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4522 struct objfile *objfile)
4524 bfd *abfd = objfile->obfd;
4525 struct dwarf2_cu *cu;
4526 unsigned int offset;
4527 gdb_byte *info_ptr, *beg_of_comp_unit;
4528 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4529 struct attribute *attr;
4532 gdb_assert (! per_cu->from_debug_types);
4534 /* Set local variables from the partial symbol table info. */
4535 offset = per_cu->offset;
4537 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4538 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4539 beg_of_comp_unit = info_ptr;
4541 if (per_cu->cu == NULL)
4543 cu = xmalloc (sizeof (*cu));
4544 init_one_comp_unit (cu, objfile);
4548 /* If an error occurs while loading, release our storage. */
4549 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4551 /* Read in the comp_unit header. */
4552 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4554 /* Complete the cu_header. */
4555 cu->header.offset = offset;
4556 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4558 /* Read the abbrevs for this compilation unit. */
4559 dwarf2_read_abbrevs (abfd, cu);
4560 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4562 /* Link this compilation unit into the compilation unit tree. */
4564 cu->per_cu = per_cu;
4566 /* Link this CU into read_in_chain. */
4567 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4568 dwarf2_per_objfile->read_in_chain = per_cu;
4573 info_ptr += cu->header.first_die_offset;
4576 cu->dies = read_comp_unit (info_ptr, cu);
4578 /* We try not to read any attributes in this function, because not
4579 all objfiles needed for references have been loaded yet, and symbol
4580 table processing isn't initialized. But we have to set the CU language,
4581 or we won't be able to build types correctly. */
4582 prepare_one_comp_unit (cu, cu->dies);
4584 /* Similarly, if we do not read the producer, we can not apply
4585 producer-specific interpretation. */
4586 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4588 cu->producer = DW_STRING (attr);
4592 do_cleanups (free_abbrevs_cleanup);
4594 /* We've successfully allocated this compilation unit. Let our
4595 caller clean it up when finished with it. */
4596 discard_cleanups (free_cu_cleanup);
4600 /* Add a DIE to the delayed physname list. */
4603 add_to_method_list (struct type *type, int fnfield_index, int index,
4604 const char *name, struct die_info *die,
4605 struct dwarf2_cu *cu)
4607 struct delayed_method_info mi;
4609 mi.fnfield_index = fnfield_index;
4613 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4616 /* A cleanup for freeing the delayed method list. */
4619 free_delayed_list (void *ptr)
4621 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4622 if (cu->method_list != NULL)
4624 VEC_free (delayed_method_info, cu->method_list);
4625 cu->method_list = NULL;
4629 /* Compute the physnames of any methods on the CU's method list.
4631 The computation of method physnames is delayed in order to avoid the
4632 (bad) condition that one of the method's formal parameters is of an as yet
4636 compute_delayed_physnames (struct dwarf2_cu *cu)
4639 struct delayed_method_info *mi;
4640 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4642 const char *physname;
4643 struct fn_fieldlist *fn_flp
4644 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4645 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4646 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4650 /* Check for GCC >= 4.0. */
4653 producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu)
4658 if (cu->producer == NULL)
4660 /* For unknown compilers expect their behavior is not compliant. For GCC
4661 this case can also happen for -gdwarf-4 type units supported since
4667 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4669 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
4671 /* For non-GCC compilers expect their behavior is not compliant. */
4675 cs = &cu->producer[strlen ("GNU ")];
4676 while (*cs && !isdigit (*cs))
4678 if (sscanf (cs, "%d.%d", &major, &minor) != 2)
4680 /* Not recognized as GCC. */
4688 /* Generate full symbol information for PST and CU, whose DIEs have
4689 already been loaded into memory. */
4692 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4694 struct dwarf2_cu *cu = per_cu->cu;
4695 struct objfile *objfile = per_cu->objfile;
4696 CORE_ADDR lowpc, highpc;
4697 struct symtab *symtab;
4698 struct cleanup *back_to, *delayed_list_cleanup;
4701 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4704 back_to = make_cleanup (really_free_pendings, NULL);
4705 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4707 cu->list_in_scope = &file_symbols;
4709 dwarf2_find_base_address (cu->dies, cu);
4711 /* Do line number decoding in read_file_scope () */
4712 process_die (cu->dies, cu);
4714 /* Now that we have processed all the DIEs in the CU, all the types
4715 should be complete, and it should now be safe to compute all of the
4717 compute_delayed_physnames (cu);
4718 do_cleanups (delayed_list_cleanup);
4720 /* Some compilers don't define a DW_AT_high_pc attribute for the
4721 compilation unit. If the DW_AT_high_pc is missing, synthesize
4722 it, by scanning the DIE's below the compilation unit. */
4723 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4725 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4729 /* Set symtab language to language from DW_AT_language. If the
4730 compilation is from a C file generated by language preprocessors, do
4731 not set the language if it was already deduced by start_subfile. */
4732 if (!(cu->language == language_c && symtab->language != language_c))
4733 symtab->language = cu->language;
4735 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4736 produce DW_AT_location with location lists but it can be possibly
4737 invalid without -fvar-tracking.
4739 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4740 needed, it would be wrong due to missing DW_AT_producer there.
4742 Still one can confuse GDB by using non-standard GCC compilation
4743 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4745 if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu))
4746 symtab->locations_valid = 1;
4749 if (dwarf2_per_objfile->using_index)
4750 per_cu->v.quick->symtab = symtab;
4753 struct partial_symtab *pst = per_cu->v.psymtab;
4754 pst->symtab = symtab;
4758 do_cleanups (back_to);
4761 /* Process a die and its children. */
4764 process_die (struct die_info *die, struct dwarf2_cu *cu)
4768 case DW_TAG_padding:
4770 case DW_TAG_compile_unit:
4771 read_file_scope (die, cu);
4773 case DW_TAG_type_unit:
4774 read_type_unit_scope (die, cu);
4776 case DW_TAG_subprogram:
4777 case DW_TAG_inlined_subroutine:
4778 read_func_scope (die, cu);
4780 case DW_TAG_lexical_block:
4781 case DW_TAG_try_block:
4782 case DW_TAG_catch_block:
4783 read_lexical_block_scope (die, cu);
4785 case DW_TAG_class_type:
4786 case DW_TAG_interface_type:
4787 case DW_TAG_structure_type:
4788 case DW_TAG_union_type:
4789 process_structure_scope (die, cu);
4791 case DW_TAG_enumeration_type:
4792 process_enumeration_scope (die, cu);
4795 /* These dies have a type, but processing them does not create
4796 a symbol or recurse to process the children. Therefore we can
4797 read them on-demand through read_type_die. */
4798 case DW_TAG_subroutine_type:
4799 case DW_TAG_set_type:
4800 case DW_TAG_array_type:
4801 case DW_TAG_pointer_type:
4802 case DW_TAG_ptr_to_member_type:
4803 case DW_TAG_reference_type:
4804 case DW_TAG_string_type:
4807 case DW_TAG_base_type:
4808 case DW_TAG_subrange_type:
4809 case DW_TAG_typedef:
4810 /* Add a typedef symbol for the type definition, if it has a
4812 new_symbol (die, read_type_die (die, cu), cu);
4814 case DW_TAG_common_block:
4815 read_common_block (die, cu);
4817 case DW_TAG_common_inclusion:
4819 case DW_TAG_namespace:
4820 processing_has_namespace_info = 1;
4821 read_namespace (die, cu);
4824 processing_has_namespace_info = 1;
4825 read_module (die, cu);
4827 case DW_TAG_imported_declaration:
4828 case DW_TAG_imported_module:
4829 processing_has_namespace_info = 1;
4830 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4831 || cu->language != language_fortran))
4832 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4833 dwarf_tag_name (die->tag));
4834 read_import_statement (die, cu);
4837 new_symbol (die, NULL, cu);
4842 /* A helper function for dwarf2_compute_name which determines whether DIE
4843 needs to have the name of the scope prepended to the name listed in the
4847 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4849 struct attribute *attr;
4853 case DW_TAG_namespace:
4854 case DW_TAG_typedef:
4855 case DW_TAG_class_type:
4856 case DW_TAG_interface_type:
4857 case DW_TAG_structure_type:
4858 case DW_TAG_union_type:
4859 case DW_TAG_enumeration_type:
4860 case DW_TAG_enumerator:
4861 case DW_TAG_subprogram:
4865 case DW_TAG_variable:
4866 case DW_TAG_constant:
4867 /* We only need to prefix "globally" visible variables. These include
4868 any variable marked with DW_AT_external or any variable that
4869 lives in a namespace. [Variables in anonymous namespaces
4870 require prefixing, but they are not DW_AT_external.] */
4872 if (dwarf2_attr (die, DW_AT_specification, cu))
4874 struct dwarf2_cu *spec_cu = cu;
4876 return die_needs_namespace (die_specification (die, &spec_cu),
4880 attr = dwarf2_attr (die, DW_AT_external, cu);
4881 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4882 && die->parent->tag != DW_TAG_module)
4884 /* A variable in a lexical block of some kind does not need a
4885 namespace, even though in C++ such variables may be external
4886 and have a mangled name. */
4887 if (die->parent->tag == DW_TAG_lexical_block
4888 || die->parent->tag == DW_TAG_try_block
4889 || die->parent->tag == DW_TAG_catch_block
4890 || die->parent->tag == DW_TAG_subprogram)
4899 /* Retrieve the last character from a mem_file. */
4902 do_ui_file_peek_last (void *object, const char *buffer, long length)
4904 char *last_char_p = (char *) object;
4907 *last_char_p = buffer[length - 1];
4910 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4911 compute the physname for the object, which include a method's
4912 formal parameters (C++/Java) and return type (Java).
4914 For Ada, return the DIE's linkage name rather than the fully qualified
4915 name. PHYSNAME is ignored..
4917 The result is allocated on the objfile_obstack and canonicalized. */
4920 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4924 name = dwarf2_name (die, cu);
4926 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4927 compute it by typename_concat inside GDB. */
4928 if (cu->language == language_ada
4929 || (cu->language == language_fortran && physname))
4931 /* For Ada unit, we prefer the linkage name over the name, as
4932 the former contains the exported name, which the user expects
4933 to be able to reference. Ideally, we want the user to be able
4934 to reference this entity using either natural or linkage name,
4935 but we haven't started looking at this enhancement yet. */
4936 struct attribute *attr;
4938 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4940 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4941 if (attr && DW_STRING (attr))
4942 return DW_STRING (attr);
4945 /* These are the only languages we know how to qualify names in. */
4947 && (cu->language == language_cplus || cu->language == language_java
4948 || cu->language == language_fortran))
4950 if (die_needs_namespace (die, cu))
4954 struct ui_file *buf;
4956 prefix = determine_prefix (die, cu);
4957 buf = mem_fileopen ();
4958 if (*prefix != '\0')
4960 char *prefixed_name = typename_concat (NULL, prefix, name,
4963 fputs_unfiltered (prefixed_name, buf);
4964 xfree (prefixed_name);
4967 fputs_unfiltered (name, buf);
4969 /* Template parameters may be specified in the DIE's DW_AT_name, or
4970 as children with DW_TAG_template_type_param or
4971 DW_TAG_value_type_param. If the latter, add them to the name
4972 here. If the name already has template parameters, then
4973 skip this step; some versions of GCC emit both, and
4974 it is more efficient to use the pre-computed name.
4976 Something to keep in mind about this process: it is very
4977 unlikely, or in some cases downright impossible, to produce
4978 something that will match the mangled name of a function.
4979 If the definition of the function has the same debug info,
4980 we should be able to match up with it anyway. But fallbacks
4981 using the minimal symbol, for instance to find a method
4982 implemented in a stripped copy of libstdc++, will not work.
4983 If we do not have debug info for the definition, we will have to
4984 match them up some other way.
4986 When we do name matching there is a related problem with function
4987 templates; two instantiated function templates are allowed to
4988 differ only by their return types, which we do not add here. */
4990 if (cu->language == language_cplus && strchr (name, '<') == NULL)
4992 struct attribute *attr;
4993 struct die_info *child;
4996 die->building_fullname = 1;
4998 for (child = die->child; child != NULL; child = child->sibling)
5003 struct dwarf2_locexpr_baton *baton;
5006 if (child->tag != DW_TAG_template_type_param
5007 && child->tag != DW_TAG_template_value_param)
5012 fputs_unfiltered ("<", buf);
5016 fputs_unfiltered (", ", buf);
5018 attr = dwarf2_attr (child, DW_AT_type, cu);
5021 complaint (&symfile_complaints,
5022 _("template parameter missing DW_AT_type"));
5023 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5026 type = die_type (child, cu);
5028 if (child->tag == DW_TAG_template_type_param)
5030 c_print_type (type, "", buf, -1, 0);
5034 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5037 complaint (&symfile_complaints,
5038 _("template parameter missing "
5039 "DW_AT_const_value"));
5040 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5044 dwarf2_const_value_attr (attr, type, name,
5045 &cu->comp_unit_obstack, cu,
5046 &value, &bytes, &baton);
5048 if (TYPE_NOSIGN (type))
5049 /* GDB prints characters as NUMBER 'CHAR'. If that's
5050 changed, this can use value_print instead. */
5051 c_printchar (value, type, buf);
5054 struct value_print_options opts;
5057 v = dwarf2_evaluate_loc_desc (type, NULL,
5061 else if (bytes != NULL)
5063 v = allocate_value (type);
5064 memcpy (value_contents_writeable (v), bytes,
5065 TYPE_LENGTH (type));
5068 v = value_from_longest (type, value);
5070 /* Specify decimal so that we do not depend on
5072 get_formatted_print_options (&opts, 'd');
5074 value_print (v, buf, &opts);
5080 die->building_fullname = 0;
5084 /* Close the argument list, with a space if necessary
5085 (nested templates). */
5086 char last_char = '\0';
5087 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5088 if (last_char == '>')
5089 fputs_unfiltered (" >", buf);
5091 fputs_unfiltered (">", buf);
5095 /* For Java and C++ methods, append formal parameter type
5096 information, if PHYSNAME. */
5098 if (physname && die->tag == DW_TAG_subprogram
5099 && (cu->language == language_cplus
5100 || cu->language == language_java))
5102 struct type *type = read_type_die (die, cu);
5104 c_type_print_args (type, buf, 1, cu->language);
5106 if (cu->language == language_java)
5108 /* For java, we must append the return type to method
5110 if (die->tag == DW_TAG_subprogram)
5111 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5114 else if (cu->language == language_cplus)
5116 /* Assume that an artificial first parameter is
5117 "this", but do not crash if it is not. RealView
5118 marks unnamed (and thus unused) parameters as
5119 artificial; there is no way to differentiate
5121 if (TYPE_NFIELDS (type) > 0
5122 && TYPE_FIELD_ARTIFICIAL (type, 0)
5123 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5124 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5126 fputs_unfiltered (" const", buf);
5130 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5132 ui_file_delete (buf);
5134 if (cu->language == language_cplus)
5137 = dwarf2_canonicalize_name (name, cu,
5138 &cu->objfile->objfile_obstack);
5149 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5150 If scope qualifiers are appropriate they will be added. The result
5151 will be allocated on the objfile_obstack, or NULL if the DIE does
5152 not have a name. NAME may either be from a previous call to
5153 dwarf2_name or NULL.
5155 The output string will be canonicalized (if C++/Java). */
5158 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5160 return dwarf2_compute_name (name, die, cu, 0);
5163 /* Construct a physname for the given DIE in CU. NAME may either be
5164 from a previous call to dwarf2_name or NULL. The result will be
5165 allocated on the objfile_objstack or NULL if the DIE does not have a
5168 The output string will be canonicalized (if C++/Java). */
5171 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5173 return dwarf2_compute_name (name, die, cu, 1);
5176 /* Read the import statement specified by the given die and record it. */
5179 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5181 struct attribute *import_attr;
5182 struct die_info *imported_die;
5183 struct dwarf2_cu *imported_cu;
5184 const char *imported_name;
5185 const char *imported_name_prefix;
5186 const char *canonical_name;
5187 const char *import_alias;
5188 const char *imported_declaration = NULL;
5189 const char *import_prefix;
5193 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5194 if (import_attr == NULL)
5196 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5197 dwarf_tag_name (die->tag));
5202 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5203 imported_name = dwarf2_name (imported_die, imported_cu);
5204 if (imported_name == NULL)
5206 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5208 The import in the following code:
5222 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5223 <52> DW_AT_decl_file : 1
5224 <53> DW_AT_decl_line : 6
5225 <54> DW_AT_import : <0x75>
5226 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5228 <5b> DW_AT_decl_file : 1
5229 <5c> DW_AT_decl_line : 2
5230 <5d> DW_AT_type : <0x6e>
5232 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5233 <76> DW_AT_byte_size : 4
5234 <77> DW_AT_encoding : 5 (signed)
5236 imports the wrong die ( 0x75 instead of 0x58 ).
5237 This case will be ignored until the gcc bug is fixed. */
5241 /* Figure out the local name after import. */
5242 import_alias = dwarf2_name (die, cu);
5244 /* Figure out where the statement is being imported to. */
5245 import_prefix = determine_prefix (die, cu);
5247 /* Figure out what the scope of the imported die is and prepend it
5248 to the name of the imported die. */
5249 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5251 if (imported_die->tag != DW_TAG_namespace
5252 && imported_die->tag != DW_TAG_module)
5254 imported_declaration = imported_name;
5255 canonical_name = imported_name_prefix;
5257 else if (strlen (imported_name_prefix) > 0)
5259 temp = alloca (strlen (imported_name_prefix)
5260 + 2 + strlen (imported_name) + 1);
5261 strcpy (temp, imported_name_prefix);
5262 strcat (temp, "::");
5263 strcat (temp, imported_name);
5264 canonical_name = temp;
5267 canonical_name = imported_name;
5269 cp_add_using_directive (import_prefix,
5272 imported_declaration,
5273 &cu->objfile->objfile_obstack);
5277 initialize_cu_func_list (struct dwarf2_cu *cu)
5279 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5282 /* Cleanup function for read_file_scope. */
5285 free_cu_line_header (void *arg)
5287 struct dwarf2_cu *cu = arg;
5289 free_line_header (cu->line_header);
5290 cu->line_header = NULL;
5294 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5295 char **name, char **comp_dir)
5297 struct attribute *attr;
5302 /* Find the filename. Do not use dwarf2_name here, since the filename
5303 is not a source language identifier. */
5304 attr = dwarf2_attr (die, DW_AT_name, cu);
5307 *name = DW_STRING (attr);
5310 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5312 *comp_dir = DW_STRING (attr);
5313 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5315 *comp_dir = ldirname (*name);
5316 if (*comp_dir != NULL)
5317 make_cleanup (xfree, *comp_dir);
5319 if (*comp_dir != NULL)
5321 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5322 directory, get rid of it. */
5323 char *cp = strchr (*comp_dir, ':');
5325 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5330 *name = "<unknown>";
5333 /* Process DW_TAG_compile_unit. */
5336 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5338 struct objfile *objfile = cu->objfile;
5339 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5340 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5341 CORE_ADDR highpc = ((CORE_ADDR) 0);
5342 struct attribute *attr;
5344 char *comp_dir = NULL;
5345 struct die_info *child_die;
5346 bfd *abfd = objfile->obfd;
5347 struct line_header *line_header = 0;
5350 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5352 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5354 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5355 from finish_block. */
5356 if (lowpc == ((CORE_ADDR) -1))
5361 find_file_and_directory (die, cu, &name, &comp_dir);
5363 attr = dwarf2_attr (die, DW_AT_language, cu);
5366 set_cu_language (DW_UNSND (attr), cu);
5369 attr = dwarf2_attr (die, DW_AT_producer, cu);
5371 cu->producer = DW_STRING (attr);
5373 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5374 standardised yet. As a workaround for the language detection we fall
5375 back to the DW_AT_producer string. */
5376 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5377 cu->language = language_opencl;
5379 /* We assume that we're processing GCC output. */
5380 processing_gcc_compilation = 2;
5382 processing_has_namespace_info = 0;
5384 start_symtab (name, comp_dir, lowpc);
5385 record_debugformat ("DWARF 2");
5386 record_producer (cu->producer);
5388 initialize_cu_func_list (cu);
5390 /* Decode line number information if present. We do this before
5391 processing child DIEs, so that the line header table is available
5392 for DW_AT_decl_file. */
5393 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5396 unsigned int line_offset = DW_UNSND (attr);
5397 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
5400 cu->line_header = line_header;
5401 make_cleanup (free_cu_line_header, cu);
5402 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5406 /* Process all dies in compilation unit. */
5407 if (die->child != NULL)
5409 child_die = die->child;
5410 while (child_die && child_die->tag)
5412 process_die (child_die, cu);
5413 child_die = sibling_die (child_die);
5417 /* Decode macro information, if present. Dwarf 2 macro information
5418 refers to information in the line number info statement program
5419 header, so we can only read it if we've read the header
5421 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5422 if (attr && line_header)
5424 unsigned int macro_offset = DW_UNSND (attr);
5426 dwarf_decode_macros (line_header, macro_offset,
5427 comp_dir, abfd, cu);
5429 do_cleanups (back_to);
5432 /* Process DW_TAG_type_unit.
5433 For TUs we want to skip the first top level sibling if it's not the
5434 actual type being defined by this TU. In this case the first top
5435 level sibling is there to provide context only. */
5438 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5440 struct objfile *objfile = cu->objfile;
5441 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5443 struct attribute *attr;
5445 char *comp_dir = NULL;
5446 struct die_info *child_die;
5447 bfd *abfd = objfile->obfd;
5449 /* start_symtab needs a low pc, but we don't really have one.
5450 Do what read_file_scope would do in the absence of such info. */
5451 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5453 /* Find the filename. Do not use dwarf2_name here, since the filename
5454 is not a source language identifier. */
5455 attr = dwarf2_attr (die, DW_AT_name, cu);
5457 name = DW_STRING (attr);
5459 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5461 comp_dir = DW_STRING (attr);
5462 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5464 comp_dir = ldirname (name);
5465 if (comp_dir != NULL)
5466 make_cleanup (xfree, comp_dir);
5472 attr = dwarf2_attr (die, DW_AT_language, cu);
5474 set_cu_language (DW_UNSND (attr), cu);
5476 /* This isn't technically needed today. It is done for symmetry
5477 with read_file_scope. */
5478 attr = dwarf2_attr (die, DW_AT_producer, cu);
5480 cu->producer = DW_STRING (attr);
5482 /* We assume that we're processing GCC output. */
5483 processing_gcc_compilation = 2;
5485 processing_has_namespace_info = 0;
5487 start_symtab (name, comp_dir, lowpc);
5488 record_debugformat ("DWARF 2");
5489 record_producer (cu->producer);
5491 /* Process the dies in the type unit. */
5492 if (die->child == NULL)
5494 dump_die_for_error (die);
5495 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5496 bfd_get_filename (abfd));
5499 child_die = die->child;
5501 while (child_die && child_die->tag)
5503 process_die (child_die, cu);
5505 child_die = sibling_die (child_die);
5508 do_cleanups (back_to);
5512 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5513 struct dwarf2_cu *cu)
5515 struct function_range *thisfn;
5517 thisfn = (struct function_range *)
5518 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5519 thisfn->name = name;
5520 thisfn->lowpc = lowpc;
5521 thisfn->highpc = highpc;
5522 thisfn->seen_line = 0;
5523 thisfn->next = NULL;
5525 if (cu->last_fn == NULL)
5526 cu->first_fn = thisfn;
5528 cu->last_fn->next = thisfn;
5530 cu->last_fn = thisfn;
5533 /* qsort helper for inherit_abstract_dies. */
5536 unsigned_int_compar (const void *ap, const void *bp)
5538 unsigned int a = *(unsigned int *) ap;
5539 unsigned int b = *(unsigned int *) bp;
5541 return (a > b) - (b > a);
5544 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5545 Inherit only the children of the DW_AT_abstract_origin DIE not being
5546 already referenced by DW_AT_abstract_origin from the children of the
5550 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5552 struct die_info *child_die;
5553 unsigned die_children_count;
5554 /* CU offsets which were referenced by children of the current DIE. */
5556 unsigned *offsets_end, *offsetp;
5557 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5558 struct die_info *origin_die;
5559 /* Iterator of the ORIGIN_DIE children. */
5560 struct die_info *origin_child_die;
5561 struct cleanup *cleanups;
5562 struct attribute *attr;
5563 struct dwarf2_cu *origin_cu;
5564 struct pending **origin_previous_list_in_scope;
5566 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5570 /* Note that following die references may follow to a die in a
5574 origin_die = follow_die_ref (die, attr, &origin_cu);
5576 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5578 origin_previous_list_in_scope = origin_cu->list_in_scope;
5579 origin_cu->list_in_scope = cu->list_in_scope;
5581 if (die->tag != origin_die->tag
5582 && !(die->tag == DW_TAG_inlined_subroutine
5583 && origin_die->tag == DW_TAG_subprogram))
5584 complaint (&symfile_complaints,
5585 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5586 die->offset, origin_die->offset);
5588 child_die = die->child;
5589 die_children_count = 0;
5590 while (child_die && child_die->tag)
5592 child_die = sibling_die (child_die);
5593 die_children_count++;
5595 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5596 cleanups = make_cleanup (xfree, offsets);
5598 offsets_end = offsets;
5599 child_die = die->child;
5600 while (child_die && child_die->tag)
5602 /* For each CHILD_DIE, find the corresponding child of
5603 ORIGIN_DIE. If there is more than one layer of
5604 DW_AT_abstract_origin, follow them all; there shouldn't be,
5605 but GCC versions at least through 4.4 generate this (GCC PR
5607 struct die_info *child_origin_die = child_die;
5608 struct dwarf2_cu *child_origin_cu = cu;
5612 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5616 child_origin_die = follow_die_ref (child_origin_die, attr,
5620 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5621 counterpart may exist. */
5622 if (child_origin_die != child_die)
5624 if (child_die->tag != child_origin_die->tag
5625 && !(child_die->tag == DW_TAG_inlined_subroutine
5626 && child_origin_die->tag == DW_TAG_subprogram))
5627 complaint (&symfile_complaints,
5628 _("Child DIE 0x%x and its abstract origin 0x%x have "
5629 "different tags"), child_die->offset,
5630 child_origin_die->offset);
5631 if (child_origin_die->parent != origin_die)
5632 complaint (&symfile_complaints,
5633 _("Child DIE 0x%x and its abstract origin 0x%x have "
5634 "different parents"), child_die->offset,
5635 child_origin_die->offset);
5637 *offsets_end++ = child_origin_die->offset;
5639 child_die = sibling_die (child_die);
5641 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5642 unsigned_int_compar);
5643 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5644 if (offsetp[-1] == *offsetp)
5645 complaint (&symfile_complaints,
5646 _("Multiple children of DIE 0x%x refer "
5647 "to DIE 0x%x as their abstract origin"),
5648 die->offset, *offsetp);
5651 origin_child_die = origin_die->child;
5652 while (origin_child_die && origin_child_die->tag)
5654 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5655 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5657 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5659 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5660 process_die (origin_child_die, origin_cu);
5662 origin_child_die = sibling_die (origin_child_die);
5664 origin_cu->list_in_scope = origin_previous_list_in_scope;
5666 do_cleanups (cleanups);
5670 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5672 struct objfile *objfile = cu->objfile;
5673 struct context_stack *new;
5676 struct die_info *child_die;
5677 struct attribute *attr, *call_line, *call_file;
5680 struct block *block;
5681 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5682 VEC (symbolp) *template_args = NULL;
5683 struct template_symbol *templ_func = NULL;
5687 /* If we do not have call site information, we can't show the
5688 caller of this inlined function. That's too confusing, so
5689 only use the scope for local variables. */
5690 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5691 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5692 if (call_line == NULL || call_file == NULL)
5694 read_lexical_block_scope (die, cu);
5699 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5701 name = dwarf2_name (die, cu);
5703 /* Ignore functions with missing or empty names. These are actually
5704 illegal according to the DWARF standard. */
5707 complaint (&symfile_complaints,
5708 _("missing name for subprogram DIE at %d"), die->offset);
5712 /* Ignore functions with missing or invalid low and high pc attributes. */
5713 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5715 attr = dwarf2_attr (die, DW_AT_external, cu);
5716 if (!attr || !DW_UNSND (attr))
5717 complaint (&symfile_complaints,
5718 _("cannot get low and high bounds "
5719 "for subprogram DIE at %d"),
5727 /* Record the function range for dwarf_decode_lines. */
5728 add_to_cu_func_list (name, lowpc, highpc, cu);
5730 /* If we have any template arguments, then we must allocate a
5731 different sort of symbol. */
5732 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5734 if (child_die->tag == DW_TAG_template_type_param
5735 || child_die->tag == DW_TAG_template_value_param)
5737 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5738 struct template_symbol);
5739 templ_func->base.is_cplus_template_function = 1;
5744 new = push_context (0, lowpc);
5745 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5746 (struct symbol *) templ_func);
5748 /* If there is a location expression for DW_AT_frame_base, record
5750 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5752 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5753 expression is being recorded directly in the function's symbol
5754 and not in a separate frame-base object. I guess this hack is
5755 to avoid adding some sort of frame-base adjunct/annex to the
5756 function's symbol :-(. The problem with doing this is that it
5757 results in a function symbol with a location expression that
5758 has nothing to do with the location of the function, ouch! The
5759 relationship should be: a function's symbol has-a frame base; a
5760 frame-base has-a location expression. */
5761 dwarf2_symbol_mark_computed (attr, new->name, cu);
5763 cu->list_in_scope = &local_symbols;
5765 if (die->child != NULL)
5767 child_die = die->child;
5768 while (child_die && child_die->tag)
5770 if (child_die->tag == DW_TAG_template_type_param
5771 || child_die->tag == DW_TAG_template_value_param)
5773 struct symbol *arg = new_symbol (child_die, NULL, cu);
5776 VEC_safe_push (symbolp, template_args, arg);
5779 process_die (child_die, cu);
5780 child_die = sibling_die (child_die);
5784 inherit_abstract_dies (die, cu);
5786 /* If we have a DW_AT_specification, we might need to import using
5787 directives from the context of the specification DIE. See the
5788 comment in determine_prefix. */
5789 if (cu->language == language_cplus
5790 && dwarf2_attr (die, DW_AT_specification, cu))
5792 struct dwarf2_cu *spec_cu = cu;
5793 struct die_info *spec_die = die_specification (die, &spec_cu);
5797 child_die = spec_die->child;
5798 while (child_die && child_die->tag)
5800 if (child_die->tag == DW_TAG_imported_module)
5801 process_die (child_die, spec_cu);
5802 child_die = sibling_die (child_die);
5805 /* In some cases, GCC generates specification DIEs that
5806 themselves contain DW_AT_specification attributes. */
5807 spec_die = die_specification (spec_die, &spec_cu);
5811 new = pop_context ();
5812 /* Make a block for the local symbols within. */
5813 block = finish_block (new->name, &local_symbols, new->old_blocks,
5814 lowpc, highpc, objfile);
5816 /* For C++, set the block's scope. */
5817 if (cu->language == language_cplus || cu->language == language_fortran)
5818 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5819 determine_prefix (die, cu),
5820 processing_has_namespace_info);
5822 /* If we have address ranges, record them. */
5823 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5825 /* Attach template arguments to function. */
5826 if (! VEC_empty (symbolp, template_args))
5828 gdb_assert (templ_func != NULL);
5830 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
5831 templ_func->template_arguments
5832 = obstack_alloc (&objfile->objfile_obstack,
5833 (templ_func->n_template_arguments
5834 * sizeof (struct symbol *)));
5835 memcpy (templ_func->template_arguments,
5836 VEC_address (symbolp, template_args),
5837 (templ_func->n_template_arguments * sizeof (struct symbol *)));
5838 VEC_free (symbolp, template_args);
5841 /* In C++, we can have functions nested inside functions (e.g., when
5842 a function declares a class that has methods). This means that
5843 when we finish processing a function scope, we may need to go
5844 back to building a containing block's symbol lists. */
5845 local_symbols = new->locals;
5846 param_symbols = new->params;
5847 using_directives = new->using_directives;
5849 /* If we've finished processing a top-level function, subsequent
5850 symbols go in the file symbol list. */
5851 if (outermost_context_p ())
5852 cu->list_in_scope = &file_symbols;
5855 /* Process all the DIES contained within a lexical block scope. Start
5856 a new scope, process the dies, and then close the scope. */
5859 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5861 struct objfile *objfile = cu->objfile;
5862 struct context_stack *new;
5863 CORE_ADDR lowpc, highpc;
5864 struct die_info *child_die;
5867 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5869 /* Ignore blocks with missing or invalid low and high pc attributes. */
5870 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5871 as multiple lexical blocks? Handling children in a sane way would
5872 be nasty. Might be easier to properly extend generic blocks to
5874 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5879 push_context (0, lowpc);
5880 if (die->child != NULL)
5882 child_die = die->child;
5883 while (child_die && child_die->tag)
5885 process_die (child_die, cu);
5886 child_die = sibling_die (child_die);
5889 new = pop_context ();
5891 if (local_symbols != NULL || using_directives != NULL)
5894 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5897 /* Note that recording ranges after traversing children, as we
5898 do here, means that recording a parent's ranges entails
5899 walking across all its children's ranges as they appear in
5900 the address map, which is quadratic behavior.
5902 It would be nicer to record the parent's ranges before
5903 traversing its children, simply overriding whatever you find
5904 there. But since we don't even decide whether to create a
5905 block until after we've traversed its children, that's hard
5907 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5909 local_symbols = new->locals;
5910 using_directives = new->using_directives;
5913 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5914 Return 1 if the attributes are present and valid, otherwise, return 0.
5915 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5918 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5919 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5920 struct partial_symtab *ranges_pst)
5922 struct objfile *objfile = cu->objfile;
5923 struct comp_unit_head *cu_header = &cu->header;
5924 bfd *obfd = objfile->obfd;
5925 unsigned int addr_size = cu_header->addr_size;
5926 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5927 /* Base address selection entry. */
5938 found_base = cu->base_known;
5939 base = cu->base_address;
5941 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5942 if (offset >= dwarf2_per_objfile->ranges.size)
5944 complaint (&symfile_complaints,
5945 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5949 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5951 /* Read in the largest possible address. */
5952 marker = read_address (obfd, buffer, cu, &dummy);
5953 if ((marker & mask) == mask)
5955 /* If we found the largest possible address, then
5956 read the base address. */
5957 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5958 buffer += 2 * addr_size;
5959 offset += 2 * addr_size;
5965 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5969 CORE_ADDR range_beginning, range_end;
5971 range_beginning = read_address (obfd, buffer, cu, &dummy);
5972 buffer += addr_size;
5973 range_end = read_address (obfd, buffer, cu, &dummy);
5974 buffer += addr_size;
5975 offset += 2 * addr_size;
5977 /* An end of list marker is a pair of zero addresses. */
5978 if (range_beginning == 0 && range_end == 0)
5979 /* Found the end of list entry. */
5982 /* Each base address selection entry is a pair of 2 values.
5983 The first is the largest possible address, the second is
5984 the base address. Check for a base address here. */
5985 if ((range_beginning & mask) == mask)
5987 /* If we found the largest possible address, then
5988 read the base address. */
5989 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5996 /* We have no valid base address for the ranges
5998 complaint (&symfile_complaints,
5999 _("Invalid .debug_ranges data (no base address)"));
6003 if (range_beginning > range_end)
6005 /* Inverted range entries are invalid. */
6006 complaint (&symfile_complaints,
6007 _("Invalid .debug_ranges data (inverted range)"));
6011 /* Empty range entries have no effect. */
6012 if (range_beginning == range_end)
6015 range_beginning += base;
6018 if (ranges_pst != NULL)
6019 addrmap_set_empty (objfile->psymtabs_addrmap,
6020 range_beginning + baseaddr,
6021 range_end - 1 + baseaddr,
6024 /* FIXME: This is recording everything as a low-high
6025 segment of consecutive addresses. We should have a
6026 data structure for discontiguous block ranges
6030 low = range_beginning;
6036 if (range_beginning < low)
6037 low = range_beginning;
6038 if (range_end > high)
6044 /* If the first entry is an end-of-list marker, the range
6045 describes an empty scope, i.e. no instructions. */
6051 *high_return = high;
6055 /* Get low and high pc attributes from a die. Return 1 if the attributes
6056 are present and valid, otherwise, return 0. Return -1 if the range is
6057 discontinuous, i.e. derived from DW_AT_ranges information. */
6059 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6060 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6061 struct partial_symtab *pst)
6063 struct attribute *attr;
6068 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6071 high = DW_ADDR (attr);
6072 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6074 low = DW_ADDR (attr);
6076 /* Found high w/o low attribute. */
6079 /* Found consecutive range of addresses. */
6084 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6087 /* Value of the DW_AT_ranges attribute is the offset in the
6088 .debug_ranges section. */
6089 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6091 /* Found discontinuous range of addresses. */
6096 /* read_partial_die has also the strict LOW < HIGH requirement. */
6100 /* When using the GNU linker, .gnu.linkonce. sections are used to
6101 eliminate duplicate copies of functions and vtables and such.
6102 The linker will arbitrarily choose one and discard the others.
6103 The AT_*_pc values for such functions refer to local labels in
6104 these sections. If the section from that file was discarded, the
6105 labels are not in the output, so the relocs get a value of 0.
6106 If this is a discarded function, mark the pc bounds as invalid,
6107 so that GDB will ignore it. */
6108 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6116 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6117 its low and high PC addresses. Do nothing if these addresses could not
6118 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6119 and HIGHPC to the high address if greater than HIGHPC. */
6122 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6123 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6124 struct dwarf2_cu *cu)
6126 CORE_ADDR low, high;
6127 struct die_info *child = die->child;
6129 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6131 *lowpc = min (*lowpc, low);
6132 *highpc = max (*highpc, high);
6135 /* If the language does not allow nested subprograms (either inside
6136 subprograms or lexical blocks), we're done. */
6137 if (cu->language != language_ada)
6140 /* Check all the children of the given DIE. If it contains nested
6141 subprograms, then check their pc bounds. Likewise, we need to
6142 check lexical blocks as well, as they may also contain subprogram
6144 while (child && child->tag)
6146 if (child->tag == DW_TAG_subprogram
6147 || child->tag == DW_TAG_lexical_block)
6148 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6149 child = sibling_die (child);
6153 /* Get the low and high pc's represented by the scope DIE, and store
6154 them in *LOWPC and *HIGHPC. If the correct values can't be
6155 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6158 get_scope_pc_bounds (struct die_info *die,
6159 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6160 struct dwarf2_cu *cu)
6162 CORE_ADDR best_low = (CORE_ADDR) -1;
6163 CORE_ADDR best_high = (CORE_ADDR) 0;
6164 CORE_ADDR current_low, current_high;
6166 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6168 best_low = current_low;
6169 best_high = current_high;
6173 struct die_info *child = die->child;
6175 while (child && child->tag)
6177 switch (child->tag) {
6178 case DW_TAG_subprogram:
6179 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6181 case DW_TAG_namespace:
6183 /* FIXME: carlton/2004-01-16: Should we do this for
6184 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6185 that current GCC's always emit the DIEs corresponding
6186 to definitions of methods of classes as children of a
6187 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6188 the DIEs giving the declarations, which could be
6189 anywhere). But I don't see any reason why the
6190 standards says that they have to be there. */
6191 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6193 if (current_low != ((CORE_ADDR) -1))
6195 best_low = min (best_low, current_low);
6196 best_high = max (best_high, current_high);
6204 child = sibling_die (child);
6209 *highpc = best_high;
6212 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6215 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6216 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6218 struct attribute *attr;
6220 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6223 CORE_ADDR high = DW_ADDR (attr);
6225 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6228 CORE_ADDR low = DW_ADDR (attr);
6230 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6234 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6237 bfd *obfd = cu->objfile->obfd;
6239 /* The value of the DW_AT_ranges attribute is the offset of the
6240 address range list in the .debug_ranges section. */
6241 unsigned long offset = DW_UNSND (attr);
6242 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6244 /* For some target architectures, but not others, the
6245 read_address function sign-extends the addresses it returns.
6246 To recognize base address selection entries, we need a
6248 unsigned int addr_size = cu->header.addr_size;
6249 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6251 /* The base address, to which the next pair is relative. Note
6252 that this 'base' is a DWARF concept: most entries in a range
6253 list are relative, to reduce the number of relocs against the
6254 debugging information. This is separate from this function's
6255 'baseaddr' argument, which GDB uses to relocate debugging
6256 information from a shared library based on the address at
6257 which the library was loaded. */
6258 CORE_ADDR base = cu->base_address;
6259 int base_known = cu->base_known;
6261 gdb_assert (dwarf2_per_objfile->ranges.readin);
6262 if (offset >= dwarf2_per_objfile->ranges.size)
6264 complaint (&symfile_complaints,
6265 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6272 unsigned int bytes_read;
6273 CORE_ADDR start, end;
6275 start = read_address (obfd, buffer, cu, &bytes_read);
6276 buffer += bytes_read;
6277 end = read_address (obfd, buffer, cu, &bytes_read);
6278 buffer += bytes_read;
6280 /* Did we find the end of the range list? */
6281 if (start == 0 && end == 0)
6284 /* Did we find a base address selection entry? */
6285 else if ((start & base_select_mask) == base_select_mask)
6291 /* We found an ordinary address range. */
6296 complaint (&symfile_complaints,
6297 _("Invalid .debug_ranges data "
6298 "(no base address)"));
6304 /* Inverted range entries are invalid. */
6305 complaint (&symfile_complaints,
6306 _("Invalid .debug_ranges data "
6307 "(inverted range)"));
6311 /* Empty range entries have no effect. */
6315 record_block_range (block,
6316 baseaddr + base + start,
6317 baseaddr + base + end - 1);
6323 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6324 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6325 during 4.6.0 experimental. */
6328 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6331 int major, minor, release;
6333 if (cu->producer == NULL)
6335 /* For unknown compilers expect their behavior is DWARF version
6338 GCC started to support .debug_types sections by -gdwarf-4 since
6339 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6340 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6341 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6342 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6347 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6349 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6351 /* For non-GCC compilers expect their behavior is DWARF version
6356 cs = &cu->producer[strlen ("GNU ")];
6357 while (*cs && !isdigit (*cs))
6359 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6361 /* Not recognized as GCC. */
6366 return major < 4 || (major == 4 && minor < 6);
6369 /* Return the default accessibility type if it is not overriden by
6370 DW_AT_accessibility. */
6372 static enum dwarf_access_attribute
6373 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6375 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6377 /* The default DWARF 2 accessibility for members is public, the default
6378 accessibility for inheritance is private. */
6380 if (die->tag != DW_TAG_inheritance)
6381 return DW_ACCESS_public;
6383 return DW_ACCESS_private;
6387 /* DWARF 3+ defines the default accessibility a different way. The same
6388 rules apply now for DW_TAG_inheritance as for the members and it only
6389 depends on the container kind. */
6391 if (die->parent->tag == DW_TAG_class_type)
6392 return DW_ACCESS_private;
6394 return DW_ACCESS_public;
6398 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6399 offset. If the attribute was not found return 0, otherwise return
6400 1. If it was found but could not properly be handled, set *OFFSET
6404 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6407 struct attribute *attr;
6409 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6414 /* Note that we do not check for a section offset first here.
6415 This is because DW_AT_data_member_location is new in DWARF 4,
6416 so if we see it, we can assume that a constant form is really
6417 a constant and not a section offset. */
6418 if (attr_form_is_constant (attr))
6419 *offset = dwarf2_get_attr_constant_value (attr, 0);
6420 else if (attr_form_is_section_offset (attr))
6421 dwarf2_complex_location_expr_complaint ();
6422 else if (attr_form_is_block (attr))
6423 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6425 dwarf2_complex_location_expr_complaint ();
6433 /* Add an aggregate field to the field list. */
6436 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6437 struct dwarf2_cu *cu)
6439 struct objfile *objfile = cu->objfile;
6440 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6441 struct nextfield *new_field;
6442 struct attribute *attr;
6444 char *fieldname = "";
6446 /* Allocate a new field list entry and link it in. */
6447 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6448 make_cleanup (xfree, new_field);
6449 memset (new_field, 0, sizeof (struct nextfield));
6451 if (die->tag == DW_TAG_inheritance)
6453 new_field->next = fip->baseclasses;
6454 fip->baseclasses = new_field;
6458 new_field->next = fip->fields;
6459 fip->fields = new_field;
6463 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6465 new_field->accessibility = DW_UNSND (attr);
6467 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6468 if (new_field->accessibility != DW_ACCESS_public)
6469 fip->non_public_fields = 1;
6471 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6473 new_field->virtuality = DW_UNSND (attr);
6475 new_field->virtuality = DW_VIRTUALITY_none;
6477 fp = &new_field->field;
6479 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6483 /* Data member other than a C++ static data member. */
6485 /* Get type of field. */
6486 fp->type = die_type (die, cu);
6488 SET_FIELD_BITPOS (*fp, 0);
6490 /* Get bit size of field (zero if none). */
6491 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6494 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6498 FIELD_BITSIZE (*fp) = 0;
6501 /* Get bit offset of field. */
6502 if (handle_data_member_location (die, cu, &offset))
6503 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6504 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6507 if (gdbarch_bits_big_endian (gdbarch))
6509 /* For big endian bits, the DW_AT_bit_offset gives the
6510 additional bit offset from the MSB of the containing
6511 anonymous object to the MSB of the field. We don't
6512 have to do anything special since we don't need to
6513 know the size of the anonymous object. */
6514 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6518 /* For little endian bits, compute the bit offset to the
6519 MSB of the anonymous object, subtract off the number of
6520 bits from the MSB of the field to the MSB of the
6521 object, and then subtract off the number of bits of
6522 the field itself. The result is the bit offset of
6523 the LSB of the field. */
6525 int bit_offset = DW_UNSND (attr);
6527 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6530 /* The size of the anonymous object containing
6531 the bit field is explicit, so use the
6532 indicated size (in bytes). */
6533 anonymous_size = DW_UNSND (attr);
6537 /* The size of the anonymous object containing
6538 the bit field must be inferred from the type
6539 attribute of the data member containing the
6541 anonymous_size = TYPE_LENGTH (fp->type);
6543 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6544 - bit_offset - FIELD_BITSIZE (*fp);
6548 /* Get name of field. */
6549 fieldname = dwarf2_name (die, cu);
6550 if (fieldname == NULL)
6553 /* The name is already allocated along with this objfile, so we don't
6554 need to duplicate it for the type. */
6555 fp->name = fieldname;
6557 /* Change accessibility for artificial fields (e.g. virtual table
6558 pointer or virtual base class pointer) to private. */
6559 if (dwarf2_attr (die, DW_AT_artificial, cu))
6561 FIELD_ARTIFICIAL (*fp) = 1;
6562 new_field->accessibility = DW_ACCESS_private;
6563 fip->non_public_fields = 1;
6566 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6568 /* C++ static member. */
6570 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6571 is a declaration, but all versions of G++ as of this writing
6572 (so through at least 3.2.1) incorrectly generate
6573 DW_TAG_variable tags. */
6575 const char *physname;
6577 /* Get name of field. */
6578 fieldname = dwarf2_name (die, cu);
6579 if (fieldname == NULL)
6582 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6584 /* Only create a symbol if this is an external value.
6585 new_symbol checks this and puts the value in the global symbol
6586 table, which we want. If it is not external, new_symbol
6587 will try to put the value in cu->list_in_scope which is wrong. */
6588 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6590 /* A static const member, not much different than an enum as far as
6591 we're concerned, except that we can support more types. */
6592 new_symbol (die, NULL, cu);
6595 /* Get physical name. */
6596 physname = dwarf2_physname (fieldname, die, cu);
6598 /* The name is already allocated along with this objfile, so we don't
6599 need to duplicate it for the type. */
6600 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6601 FIELD_TYPE (*fp) = die_type (die, cu);
6602 FIELD_NAME (*fp) = fieldname;
6604 else if (die->tag == DW_TAG_inheritance)
6608 /* C++ base class field. */
6609 if (handle_data_member_location (die, cu, &offset))
6610 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6611 FIELD_BITSIZE (*fp) = 0;
6612 FIELD_TYPE (*fp) = die_type (die, cu);
6613 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6614 fip->nbaseclasses++;
6618 /* Add a typedef defined in the scope of the FIP's class. */
6621 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6622 struct dwarf2_cu *cu)
6624 struct objfile *objfile = cu->objfile;
6625 struct typedef_field_list *new_field;
6626 struct attribute *attr;
6627 struct typedef_field *fp;
6628 char *fieldname = "";
6630 /* Allocate a new field list entry and link it in. */
6631 new_field = xzalloc (sizeof (*new_field));
6632 make_cleanup (xfree, new_field);
6634 gdb_assert (die->tag == DW_TAG_typedef);
6636 fp = &new_field->field;
6638 /* Get name of field. */
6639 fp->name = dwarf2_name (die, cu);
6640 if (fp->name == NULL)
6643 fp->type = read_type_die (die, cu);
6645 new_field->next = fip->typedef_field_list;
6646 fip->typedef_field_list = new_field;
6647 fip->typedef_field_list_count++;
6650 /* Create the vector of fields, and attach it to the type. */
6653 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6654 struct dwarf2_cu *cu)
6656 int nfields = fip->nfields;
6658 /* Record the field count, allocate space for the array of fields,
6659 and create blank accessibility bitfields if necessary. */
6660 TYPE_NFIELDS (type) = nfields;
6661 TYPE_FIELDS (type) = (struct field *)
6662 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6663 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6665 if (fip->non_public_fields && cu->language != language_ada)
6667 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6669 TYPE_FIELD_PRIVATE_BITS (type) =
6670 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6671 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6673 TYPE_FIELD_PROTECTED_BITS (type) =
6674 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6675 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6677 TYPE_FIELD_IGNORE_BITS (type) =
6678 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6679 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
6682 /* If the type has baseclasses, allocate and clear a bit vector for
6683 TYPE_FIELD_VIRTUAL_BITS. */
6684 if (fip->nbaseclasses && cu->language != language_ada)
6686 int num_bytes = B_BYTES (fip->nbaseclasses);
6687 unsigned char *pointer;
6689 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6690 pointer = TYPE_ALLOC (type, num_bytes);
6691 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6692 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6693 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6696 /* Copy the saved-up fields into the field vector. Start from the head of
6697 the list, adding to the tail of the field array, so that they end up in
6698 the same order in the array in which they were added to the list. */
6699 while (nfields-- > 0)
6701 struct nextfield *fieldp;
6705 fieldp = fip->fields;
6706 fip->fields = fieldp->next;
6710 fieldp = fip->baseclasses;
6711 fip->baseclasses = fieldp->next;
6714 TYPE_FIELD (type, nfields) = fieldp->field;
6715 switch (fieldp->accessibility)
6717 case DW_ACCESS_private:
6718 if (cu->language != language_ada)
6719 SET_TYPE_FIELD_PRIVATE (type, nfields);
6722 case DW_ACCESS_protected:
6723 if (cu->language != language_ada)
6724 SET_TYPE_FIELD_PROTECTED (type, nfields);
6727 case DW_ACCESS_public:
6731 /* Unknown accessibility. Complain and treat it as public. */
6733 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6734 fieldp->accessibility);
6738 if (nfields < fip->nbaseclasses)
6740 switch (fieldp->virtuality)
6742 case DW_VIRTUALITY_virtual:
6743 case DW_VIRTUALITY_pure_virtual:
6744 if (cu->language == language_ada)
6745 error (_("unexpected virtuality in component of Ada type"));
6746 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6753 /* Add a member function to the proper fieldlist. */
6756 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6757 struct type *type, struct dwarf2_cu *cu)
6759 struct objfile *objfile = cu->objfile;
6760 struct attribute *attr;
6761 struct fnfieldlist *flp;
6763 struct fn_field *fnp;
6765 struct nextfnfield *new_fnfield;
6766 struct type *this_type;
6767 enum dwarf_access_attribute accessibility;
6769 if (cu->language == language_ada)
6770 error (_("unexpected member function in Ada type"));
6772 /* Get name of member function. */
6773 fieldname = dwarf2_name (die, cu);
6774 if (fieldname == NULL)
6777 /* Look up member function name in fieldlist. */
6778 for (i = 0; i < fip->nfnfields; i++)
6780 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6784 /* Create new list element if necessary. */
6785 if (i < fip->nfnfields)
6786 flp = &fip->fnfieldlists[i];
6789 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6791 fip->fnfieldlists = (struct fnfieldlist *)
6792 xrealloc (fip->fnfieldlists,
6793 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6794 * sizeof (struct fnfieldlist));
6795 if (fip->nfnfields == 0)
6796 make_cleanup (free_current_contents, &fip->fnfieldlists);
6798 flp = &fip->fnfieldlists[fip->nfnfields];
6799 flp->name = fieldname;
6802 i = fip->nfnfields++;
6805 /* Create a new member function field and chain it to the field list
6807 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6808 make_cleanup (xfree, new_fnfield);
6809 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6810 new_fnfield->next = flp->head;
6811 flp->head = new_fnfield;
6814 /* Fill in the member function field info. */
6815 fnp = &new_fnfield->fnfield;
6817 /* Delay processing of the physname until later. */
6818 if (cu->language == language_cplus || cu->language == language_java)
6820 add_to_method_list (type, i, flp->length - 1, fieldname,
6825 const char *physname = dwarf2_physname (fieldname, die, cu);
6826 fnp->physname = physname ? physname : "";
6829 fnp->type = alloc_type (objfile);
6830 this_type = read_type_die (die, cu);
6831 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6833 int nparams = TYPE_NFIELDS (this_type);
6835 /* TYPE is the domain of this method, and THIS_TYPE is the type
6836 of the method itself (TYPE_CODE_METHOD). */
6837 smash_to_method_type (fnp->type, type,
6838 TYPE_TARGET_TYPE (this_type),
6839 TYPE_FIELDS (this_type),
6840 TYPE_NFIELDS (this_type),
6841 TYPE_VARARGS (this_type));
6843 /* Handle static member functions.
6844 Dwarf2 has no clean way to discern C++ static and non-static
6845 member functions. G++ helps GDB by marking the first
6846 parameter for non-static member functions (which is the this
6847 pointer) as artificial. We obtain this information from
6848 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6849 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6850 fnp->voffset = VOFFSET_STATIC;
6853 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6854 dwarf2_full_name (fieldname, die, cu));
6856 /* Get fcontext from DW_AT_containing_type if present. */
6857 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6858 fnp->fcontext = die_containing_type (die, cu);
6860 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6861 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6863 /* Get accessibility. */
6864 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6866 accessibility = DW_UNSND (attr);
6868 accessibility = dwarf2_default_access_attribute (die, cu);
6869 switch (accessibility)
6871 case DW_ACCESS_private:
6872 fnp->is_private = 1;
6874 case DW_ACCESS_protected:
6875 fnp->is_protected = 1;
6879 /* Check for artificial methods. */
6880 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6881 if (attr && DW_UNSND (attr) != 0)
6882 fnp->is_artificial = 1;
6884 /* Get index in virtual function table if it is a virtual member
6885 function. For older versions of GCC, this is an offset in the
6886 appropriate virtual table, as specified by DW_AT_containing_type.
6887 For everyone else, it is an expression to be evaluated relative
6888 to the object address. */
6890 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6893 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6895 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6897 /* Old-style GCC. */
6898 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6900 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6901 || (DW_BLOCK (attr)->size > 1
6902 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6903 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6905 struct dwarf_block blk;
6908 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6910 blk.size = DW_BLOCK (attr)->size - offset;
6911 blk.data = DW_BLOCK (attr)->data + offset;
6912 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6913 if ((fnp->voffset % cu->header.addr_size) != 0)
6914 dwarf2_complex_location_expr_complaint ();
6916 fnp->voffset /= cu->header.addr_size;
6920 dwarf2_complex_location_expr_complaint ();
6923 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6925 else if (attr_form_is_section_offset (attr))
6927 dwarf2_complex_location_expr_complaint ();
6931 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6937 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6938 if (attr && DW_UNSND (attr))
6940 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6941 complaint (&symfile_complaints,
6942 _("Member function \"%s\" (offset %d) is virtual "
6943 "but the vtable offset is not specified"),
6944 fieldname, die->offset);
6945 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6946 TYPE_CPLUS_DYNAMIC (type) = 1;
6951 /* Create the vector of member function fields, and attach it to the type. */
6954 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6955 struct dwarf2_cu *cu)
6957 struct fnfieldlist *flp;
6958 int total_length = 0;
6961 if (cu->language == language_ada)
6962 error (_("unexpected member functions in Ada type"));
6964 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6965 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6966 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6968 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6970 struct nextfnfield *nfp = flp->head;
6971 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6974 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6975 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6976 fn_flp->fn_fields = (struct fn_field *)
6977 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6978 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6979 fn_flp->fn_fields[k] = nfp->fnfield;
6981 total_length += flp->length;
6984 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6985 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6988 /* Returns non-zero if NAME is the name of a vtable member in CU's
6989 language, zero otherwise. */
6991 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6993 static const char vptr[] = "_vptr";
6994 static const char vtable[] = "vtable";
6996 /* Look for the C++ and Java forms of the vtable. */
6997 if ((cu->language == language_java
6998 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6999 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7000 && is_cplus_marker (name[sizeof (vptr) - 1])))
7006 /* GCC outputs unnamed structures that are really pointers to member
7007 functions, with the ABI-specified layout. If TYPE describes
7008 such a structure, smash it into a member function type.
7010 GCC shouldn't do this; it should just output pointer to member DIEs.
7011 This is GCC PR debug/28767. */
7014 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7016 struct type *pfn_type, *domain_type, *new_type;
7018 /* Check for a structure with no name and two children. */
7019 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7022 /* Check for __pfn and __delta members. */
7023 if (TYPE_FIELD_NAME (type, 0) == NULL
7024 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7025 || TYPE_FIELD_NAME (type, 1) == NULL
7026 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7029 /* Find the type of the method. */
7030 pfn_type = TYPE_FIELD_TYPE (type, 0);
7031 if (pfn_type == NULL
7032 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7033 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7036 /* Look for the "this" argument. */
7037 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7038 if (TYPE_NFIELDS (pfn_type) == 0
7039 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7040 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7043 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7044 new_type = alloc_type (objfile);
7045 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7046 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7047 TYPE_VARARGS (pfn_type));
7048 smash_to_methodptr_type (type, new_type);
7051 /* Called when we find the DIE that starts a structure or union scope
7052 (definition) to create a type for the structure or union. Fill in
7053 the type's name and general properties; the members will not be
7054 processed until process_structure_type.
7056 NOTE: we need to call these functions regardless of whether or not the
7057 DIE has a DW_AT_name attribute, since it might be an anonymous
7058 structure or union. This gets the type entered into our set of
7061 However, if the structure is incomplete (an opaque struct/union)
7062 then suppress creating a symbol table entry for it since gdb only
7063 wants to find the one with the complete definition. Note that if
7064 it is complete, we just call new_symbol, which does it's own
7065 checking about whether the struct/union is anonymous or not (and
7066 suppresses creating a symbol table entry itself). */
7068 static struct type *
7069 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7071 struct objfile *objfile = cu->objfile;
7073 struct attribute *attr;
7076 /* If the definition of this type lives in .debug_types, read that type.
7077 Don't follow DW_AT_specification though, that will take us back up
7078 the chain and we want to go down. */
7079 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7082 struct dwarf2_cu *type_cu = cu;
7083 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7085 /* We could just recurse on read_structure_type, but we need to call
7086 get_die_type to ensure only one type for this DIE is created.
7087 This is important, for example, because for c++ classes we need
7088 TYPE_NAME set which is only done by new_symbol. Blech. */
7089 type = read_type_die (type_die, type_cu);
7091 /* TYPE_CU may not be the same as CU.
7092 Ensure TYPE is recorded in CU's type_hash table. */
7093 return set_die_type (die, type, cu);
7096 type = alloc_type (objfile);
7097 INIT_CPLUS_SPECIFIC (type);
7099 name = dwarf2_name (die, cu);
7102 if (cu->language == language_cplus
7103 || cu->language == language_java)
7105 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7107 /* dwarf2_full_name might have already finished building the DIE's
7108 type. If so, there is no need to continue. */
7109 if (get_die_type (die, cu) != NULL)
7110 return get_die_type (die, cu);
7112 TYPE_TAG_NAME (type) = full_name;
7113 if (die->tag == DW_TAG_structure_type
7114 || die->tag == DW_TAG_class_type)
7115 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7119 /* The name is already allocated along with this objfile, so
7120 we don't need to duplicate it for the type. */
7121 TYPE_TAG_NAME (type) = (char *) name;
7122 if (die->tag == DW_TAG_class_type)
7123 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7127 if (die->tag == DW_TAG_structure_type)
7129 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7131 else if (die->tag == DW_TAG_union_type)
7133 TYPE_CODE (type) = TYPE_CODE_UNION;
7137 TYPE_CODE (type) = TYPE_CODE_CLASS;
7140 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7141 TYPE_DECLARED_CLASS (type) = 1;
7143 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7146 TYPE_LENGTH (type) = DW_UNSND (attr);
7150 TYPE_LENGTH (type) = 0;
7153 TYPE_STUB_SUPPORTED (type) = 1;
7154 if (die_is_declaration (die, cu))
7155 TYPE_STUB (type) = 1;
7156 else if (attr == NULL && die->child == NULL
7157 && producer_is_realview (cu->producer))
7158 /* RealView does not output the required DW_AT_declaration
7159 on incomplete types. */
7160 TYPE_STUB (type) = 1;
7162 /* We need to add the type field to the die immediately so we don't
7163 infinitely recurse when dealing with pointers to the structure
7164 type within the structure itself. */
7165 set_die_type (die, type, cu);
7167 /* set_die_type should be already done. */
7168 set_descriptive_type (type, die, cu);
7173 /* Finish creating a structure or union type, including filling in
7174 its members and creating a symbol for it. */
7177 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7179 struct objfile *objfile = cu->objfile;
7180 struct die_info *child_die = die->child;
7183 type = get_die_type (die, cu);
7185 type = read_structure_type (die, cu);
7187 if (die->child != NULL && ! die_is_declaration (die, cu))
7189 struct field_info fi;
7190 struct die_info *child_die;
7191 VEC (symbolp) *template_args = NULL;
7192 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7194 memset (&fi, 0, sizeof (struct field_info));
7196 child_die = die->child;
7198 while (child_die && child_die->tag)
7200 if (child_die->tag == DW_TAG_member
7201 || child_die->tag == DW_TAG_variable)
7203 /* NOTE: carlton/2002-11-05: A C++ static data member
7204 should be a DW_TAG_member that is a declaration, but
7205 all versions of G++ as of this writing (so through at
7206 least 3.2.1) incorrectly generate DW_TAG_variable
7207 tags for them instead. */
7208 dwarf2_add_field (&fi, child_die, cu);
7210 else if (child_die->tag == DW_TAG_subprogram)
7212 /* C++ member function. */
7213 dwarf2_add_member_fn (&fi, child_die, type, cu);
7215 else if (child_die->tag == DW_TAG_inheritance)
7217 /* C++ base class field. */
7218 dwarf2_add_field (&fi, child_die, cu);
7220 else if (child_die->tag == DW_TAG_typedef)
7221 dwarf2_add_typedef (&fi, child_die, cu);
7222 else if (child_die->tag == DW_TAG_template_type_param
7223 || child_die->tag == DW_TAG_template_value_param)
7225 struct symbol *arg = new_symbol (child_die, NULL, cu);
7228 VEC_safe_push (symbolp, template_args, arg);
7231 child_die = sibling_die (child_die);
7234 /* Attach template arguments to type. */
7235 if (! VEC_empty (symbolp, template_args))
7237 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7238 TYPE_N_TEMPLATE_ARGUMENTS (type)
7239 = VEC_length (symbolp, template_args);
7240 TYPE_TEMPLATE_ARGUMENTS (type)
7241 = obstack_alloc (&objfile->objfile_obstack,
7242 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7243 * sizeof (struct symbol *)));
7244 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7245 VEC_address (symbolp, template_args),
7246 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7247 * sizeof (struct symbol *)));
7248 VEC_free (symbolp, template_args);
7251 /* Attach fields and member functions to the type. */
7253 dwarf2_attach_fields_to_type (&fi, type, cu);
7256 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7258 /* Get the type which refers to the base class (possibly this
7259 class itself) which contains the vtable pointer for the current
7260 class from the DW_AT_containing_type attribute. This use of
7261 DW_AT_containing_type is a GNU extension. */
7263 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7265 struct type *t = die_containing_type (die, cu);
7267 TYPE_VPTR_BASETYPE (type) = t;
7272 /* Our own class provides vtbl ptr. */
7273 for (i = TYPE_NFIELDS (t) - 1;
7274 i >= TYPE_N_BASECLASSES (t);
7277 char *fieldname = TYPE_FIELD_NAME (t, i);
7279 if (is_vtable_name (fieldname, cu))
7281 TYPE_VPTR_FIELDNO (type) = i;
7286 /* Complain if virtual function table field not found. */
7287 if (i < TYPE_N_BASECLASSES (t))
7288 complaint (&symfile_complaints,
7289 _("virtual function table pointer "
7290 "not found when defining class '%s'"),
7291 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7296 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7299 else if (cu->producer
7300 && strncmp (cu->producer,
7301 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7303 /* The IBM XLC compiler does not provide direct indication
7304 of the containing type, but the vtable pointer is
7305 always named __vfp. */
7309 for (i = TYPE_NFIELDS (type) - 1;
7310 i >= TYPE_N_BASECLASSES (type);
7313 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7315 TYPE_VPTR_FIELDNO (type) = i;
7316 TYPE_VPTR_BASETYPE (type) = type;
7323 /* Copy fi.typedef_field_list linked list elements content into the
7324 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7325 if (fi.typedef_field_list)
7327 int i = fi.typedef_field_list_count;
7329 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7330 TYPE_TYPEDEF_FIELD_ARRAY (type)
7331 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7332 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7334 /* Reverse the list order to keep the debug info elements order. */
7337 struct typedef_field *dest, *src;
7339 dest = &TYPE_TYPEDEF_FIELD (type, i);
7340 src = &fi.typedef_field_list->field;
7341 fi.typedef_field_list = fi.typedef_field_list->next;
7346 do_cleanups (back_to);
7349 quirk_gcc_member_function_pointer (type, cu->objfile);
7351 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7352 snapshots) has been known to create a die giving a declaration
7353 for a class that has, as a child, a die giving a definition for a
7354 nested class. So we have to process our children even if the
7355 current die is a declaration. Normally, of course, a declaration
7356 won't have any children at all. */
7358 while (child_die != NULL && child_die->tag)
7360 if (child_die->tag == DW_TAG_member
7361 || child_die->tag == DW_TAG_variable
7362 || child_die->tag == DW_TAG_inheritance
7363 || child_die->tag == DW_TAG_template_value_param
7364 || child_die->tag == DW_TAG_template_type_param)
7369 process_die (child_die, cu);
7371 child_die = sibling_die (child_die);
7374 /* Do not consider external references. According to the DWARF standard,
7375 these DIEs are identified by the fact that they have no byte_size
7376 attribute, and a declaration attribute. */
7377 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7378 || !die_is_declaration (die, cu))
7379 new_symbol (die, type, cu);
7382 /* Given a DW_AT_enumeration_type die, set its type. We do not
7383 complete the type's fields yet, or create any symbols. */
7385 static struct type *
7386 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7388 struct objfile *objfile = cu->objfile;
7390 struct attribute *attr;
7393 /* If the definition of this type lives in .debug_types, read that type.
7394 Don't follow DW_AT_specification though, that will take us back up
7395 the chain and we want to go down. */
7396 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7399 struct dwarf2_cu *type_cu = cu;
7400 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7402 type = read_type_die (type_die, type_cu);
7404 /* TYPE_CU may not be the same as CU.
7405 Ensure TYPE is recorded in CU's type_hash table. */
7406 return set_die_type (die, type, cu);
7409 type = alloc_type (objfile);
7411 TYPE_CODE (type) = TYPE_CODE_ENUM;
7412 name = dwarf2_full_name (NULL, die, cu);
7414 TYPE_TAG_NAME (type) = (char *) name;
7416 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7419 TYPE_LENGTH (type) = DW_UNSND (attr);
7423 TYPE_LENGTH (type) = 0;
7426 /* The enumeration DIE can be incomplete. In Ada, any type can be
7427 declared as private in the package spec, and then defined only
7428 inside the package body. Such types are known as Taft Amendment
7429 Types. When another package uses such a type, an incomplete DIE
7430 may be generated by the compiler. */
7431 if (die_is_declaration (die, cu))
7432 TYPE_STUB (type) = 1;
7434 return set_die_type (die, type, cu);
7437 /* Given a pointer to a die which begins an enumeration, process all
7438 the dies that define the members of the enumeration, and create the
7439 symbol for the enumeration type.
7441 NOTE: We reverse the order of the element list. */
7444 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7446 struct type *this_type;
7448 this_type = get_die_type (die, cu);
7449 if (this_type == NULL)
7450 this_type = read_enumeration_type (die, cu);
7452 if (die->child != NULL)
7454 struct die_info *child_die;
7456 struct field *fields = NULL;
7458 int unsigned_enum = 1;
7461 child_die = die->child;
7462 while (child_die && child_die->tag)
7464 if (child_die->tag != DW_TAG_enumerator)
7466 process_die (child_die, cu);
7470 name = dwarf2_name (child_die, cu);
7473 sym = new_symbol (child_die, this_type, cu);
7474 if (SYMBOL_VALUE (sym) < 0)
7477 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7479 fields = (struct field *)
7481 (num_fields + DW_FIELD_ALLOC_CHUNK)
7482 * sizeof (struct field));
7485 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7486 FIELD_TYPE (fields[num_fields]) = NULL;
7487 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7488 FIELD_BITSIZE (fields[num_fields]) = 0;
7494 child_die = sibling_die (child_die);
7499 TYPE_NFIELDS (this_type) = num_fields;
7500 TYPE_FIELDS (this_type) = (struct field *)
7501 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7502 memcpy (TYPE_FIELDS (this_type), fields,
7503 sizeof (struct field) * num_fields);
7507 TYPE_UNSIGNED (this_type) = 1;
7510 new_symbol (die, this_type, cu);
7513 /* Extract all information from a DW_TAG_array_type DIE and put it in
7514 the DIE's type field. For now, this only handles one dimensional
7517 static struct type *
7518 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7520 struct objfile *objfile = cu->objfile;
7521 struct die_info *child_die;
7523 struct type *element_type, *range_type, *index_type;
7524 struct type **range_types = NULL;
7525 struct attribute *attr;
7527 struct cleanup *back_to;
7530 element_type = die_type (die, cu);
7532 /* The die_type call above may have already set the type for this DIE. */
7533 type = get_die_type (die, cu);
7537 /* Irix 6.2 native cc creates array types without children for
7538 arrays with unspecified length. */
7539 if (die->child == NULL)
7541 index_type = objfile_type (objfile)->builtin_int;
7542 range_type = create_range_type (NULL, index_type, 0, -1);
7543 type = create_array_type (NULL, element_type, range_type);
7544 return set_die_type (die, type, cu);
7547 back_to = make_cleanup (null_cleanup, NULL);
7548 child_die = die->child;
7549 while (child_die && child_die->tag)
7551 if (child_die->tag == DW_TAG_subrange_type)
7553 struct type *child_type = read_type_die (child_die, cu);
7555 if (child_type != NULL)
7557 /* The range type was succesfully read. Save it for the
7558 array type creation. */
7559 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7561 range_types = (struct type **)
7562 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7563 * sizeof (struct type *));
7565 make_cleanup (free_current_contents, &range_types);
7567 range_types[ndim++] = child_type;
7570 child_die = sibling_die (child_die);
7573 /* Dwarf2 dimensions are output from left to right, create the
7574 necessary array types in backwards order. */
7576 type = element_type;
7578 if (read_array_order (die, cu) == DW_ORD_col_major)
7583 type = create_array_type (NULL, type, range_types[i++]);
7588 type = create_array_type (NULL, type, range_types[ndim]);
7591 /* Understand Dwarf2 support for vector types (like they occur on
7592 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7593 array type. This is not part of the Dwarf2/3 standard yet, but a
7594 custom vendor extension. The main difference between a regular
7595 array and the vector variant is that vectors are passed by value
7597 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7599 make_vector_type (type);
7601 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7602 implementation may choose to implement triple vectors using this
7604 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7607 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
7608 TYPE_LENGTH (type) = DW_UNSND (attr);
7610 complaint (&symfile_complaints,
7611 _("DW_AT_byte_size for array type smaller "
7612 "than the total size of elements"));
7615 name = dwarf2_name (die, cu);
7617 TYPE_NAME (type) = name;
7619 /* Install the type in the die. */
7620 set_die_type (die, type, cu);
7622 /* set_die_type should be already done. */
7623 set_descriptive_type (type, die, cu);
7625 do_cleanups (back_to);
7630 static enum dwarf_array_dim_ordering
7631 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7633 struct attribute *attr;
7635 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7637 if (attr) return DW_SND (attr);
7639 /* GNU F77 is a special case, as at 08/2004 array type info is the
7640 opposite order to the dwarf2 specification, but data is still
7641 laid out as per normal fortran.
7643 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7644 version checking. */
7646 if (cu->language == language_fortran
7647 && cu->producer && strstr (cu->producer, "GNU F77"))
7649 return DW_ORD_row_major;
7652 switch (cu->language_defn->la_array_ordering)
7654 case array_column_major:
7655 return DW_ORD_col_major;
7656 case array_row_major:
7658 return DW_ORD_row_major;
7662 /* Extract all information from a DW_TAG_set_type DIE and put it in
7663 the DIE's type field. */
7665 static struct type *
7666 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7668 struct type *domain_type, *set_type;
7669 struct attribute *attr;
7671 domain_type = die_type (die, cu);
7673 /* The die_type call above may have already set the type for this DIE. */
7674 set_type = get_die_type (die, cu);
7678 set_type = create_set_type (NULL, domain_type);
7680 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7682 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7684 return set_die_type (die, set_type, cu);
7687 /* First cut: install each common block member as a global variable. */
7690 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7692 struct die_info *child_die;
7693 struct attribute *attr;
7695 CORE_ADDR base = (CORE_ADDR) 0;
7697 attr = dwarf2_attr (die, DW_AT_location, cu);
7700 /* Support the .debug_loc offsets. */
7701 if (attr_form_is_block (attr))
7703 base = decode_locdesc (DW_BLOCK (attr), cu);
7705 else if (attr_form_is_section_offset (attr))
7707 dwarf2_complex_location_expr_complaint ();
7711 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7712 "common block member");
7715 if (die->child != NULL)
7717 child_die = die->child;
7718 while (child_die && child_die->tag)
7722 sym = new_symbol (child_die, NULL, cu);
7724 && handle_data_member_location (child_die, cu, &offset))
7726 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
7727 add_symbol_to_list (sym, &global_symbols);
7729 child_die = sibling_die (child_die);
7734 /* Create a type for a C++ namespace. */
7736 static struct type *
7737 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7739 struct objfile *objfile = cu->objfile;
7740 const char *previous_prefix, *name;
7744 /* For extensions, reuse the type of the original namespace. */
7745 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7747 struct die_info *ext_die;
7748 struct dwarf2_cu *ext_cu = cu;
7750 ext_die = dwarf2_extension (die, &ext_cu);
7751 type = read_type_die (ext_die, ext_cu);
7753 /* EXT_CU may not be the same as CU.
7754 Ensure TYPE is recorded in CU's type_hash table. */
7755 return set_die_type (die, type, cu);
7758 name = namespace_name (die, &is_anonymous, cu);
7760 /* Now build the name of the current namespace. */
7762 previous_prefix = determine_prefix (die, cu);
7763 if (previous_prefix[0] != '\0')
7764 name = typename_concat (&objfile->objfile_obstack,
7765 previous_prefix, name, 0, cu);
7767 /* Create the type. */
7768 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
7770 TYPE_NAME (type) = (char *) name;
7771 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7773 return set_die_type (die, type, cu);
7776 /* Read a C++ namespace. */
7779 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
7781 struct objfile *objfile = cu->objfile;
7784 /* Add a symbol associated to this if we haven't seen the namespace
7785 before. Also, add a using directive if it's an anonymous
7788 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
7792 type = read_type_die (die, cu);
7793 new_symbol (die, type, cu);
7795 namespace_name (die, &is_anonymous, cu);
7798 const char *previous_prefix = determine_prefix (die, cu);
7800 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
7801 NULL, &objfile->objfile_obstack);
7805 if (die->child != NULL)
7807 struct die_info *child_die = die->child;
7809 while (child_die && child_die->tag)
7811 process_die (child_die, cu);
7812 child_die = sibling_die (child_die);
7817 /* Read a Fortran module as type. This DIE can be only a declaration used for
7818 imported module. Still we need that type as local Fortran "use ... only"
7819 declaration imports depend on the created type in determine_prefix. */
7821 static struct type *
7822 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
7824 struct objfile *objfile = cu->objfile;
7828 module_name = dwarf2_name (die, cu);
7830 complaint (&symfile_complaints,
7831 _("DW_TAG_module has no name, offset 0x%x"),
7833 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
7835 /* determine_prefix uses TYPE_TAG_NAME. */
7836 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7838 return set_die_type (die, type, cu);
7841 /* Read a Fortran module. */
7844 read_module (struct die_info *die, struct dwarf2_cu *cu)
7846 struct die_info *child_die = die->child;
7848 while (child_die && child_die->tag)
7850 process_die (child_die, cu);
7851 child_die = sibling_die (child_die);
7855 /* Return the name of the namespace represented by DIE. Set
7856 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7860 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7862 struct die_info *current_die;
7863 const char *name = NULL;
7865 /* Loop through the extensions until we find a name. */
7867 for (current_die = die;
7868 current_die != NULL;
7869 current_die = dwarf2_extension (die, &cu))
7871 name = dwarf2_name (current_die, cu);
7876 /* Is it an anonymous namespace? */
7878 *is_anonymous = (name == NULL);
7880 name = "(anonymous namespace)";
7885 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7886 the user defined type vector. */
7888 static struct type *
7889 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7891 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7892 struct comp_unit_head *cu_header = &cu->header;
7894 struct attribute *attr_byte_size;
7895 struct attribute *attr_address_class;
7896 int byte_size, addr_class;
7897 struct type *target_type;
7899 target_type = die_type (die, cu);
7901 /* The die_type call above may have already set the type for this DIE. */
7902 type = get_die_type (die, cu);
7906 type = lookup_pointer_type (target_type);
7908 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7910 byte_size = DW_UNSND (attr_byte_size);
7912 byte_size = cu_header->addr_size;
7914 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7915 if (attr_address_class)
7916 addr_class = DW_UNSND (attr_address_class);
7918 addr_class = DW_ADDR_none;
7920 /* If the pointer size or address class is different than the
7921 default, create a type variant marked as such and set the
7922 length accordingly. */
7923 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7925 if (gdbarch_address_class_type_flags_p (gdbarch))
7929 type_flags = gdbarch_address_class_type_flags
7930 (gdbarch, byte_size, addr_class);
7931 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7933 type = make_type_with_address_space (type, type_flags);
7935 else if (TYPE_LENGTH (type) != byte_size)
7937 complaint (&symfile_complaints,
7938 _("invalid pointer size %d"), byte_size);
7942 /* Should we also complain about unhandled address classes? */
7946 TYPE_LENGTH (type) = byte_size;
7947 return set_die_type (die, type, cu);
7950 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7951 the user defined type vector. */
7953 static struct type *
7954 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7957 struct type *to_type;
7958 struct type *domain;
7960 to_type = die_type (die, cu);
7961 domain = die_containing_type (die, cu);
7963 /* The calls above may have already set the type for this DIE. */
7964 type = get_die_type (die, cu);
7968 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7969 type = lookup_methodptr_type (to_type);
7971 type = lookup_memberptr_type (to_type, domain);
7973 return set_die_type (die, type, cu);
7976 /* Extract all information from a DW_TAG_reference_type DIE and add to
7977 the user defined type vector. */
7979 static struct type *
7980 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7982 struct comp_unit_head *cu_header = &cu->header;
7983 struct type *type, *target_type;
7984 struct attribute *attr;
7986 target_type = die_type (die, cu);
7988 /* The die_type call above may have already set the type for this DIE. */
7989 type = get_die_type (die, cu);
7993 type = lookup_reference_type (target_type);
7994 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7997 TYPE_LENGTH (type) = DW_UNSND (attr);
8001 TYPE_LENGTH (type) = cu_header->addr_size;
8003 return set_die_type (die, type, cu);
8006 static struct type *
8007 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8009 struct type *base_type, *cv_type;
8011 base_type = die_type (die, cu);
8013 /* The die_type call above may have already set the type for this DIE. */
8014 cv_type = get_die_type (die, cu);
8018 /* In case the const qualifier is applied to an array type, the element type
8019 is so qualified, not the array type (section 6.7.3 of C99). */
8020 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8022 struct type *el_type, *inner_array;
8024 base_type = copy_type (base_type);
8025 inner_array = base_type;
8027 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8029 TYPE_TARGET_TYPE (inner_array) =
8030 copy_type (TYPE_TARGET_TYPE (inner_array));
8031 inner_array = TYPE_TARGET_TYPE (inner_array);
8034 el_type = TYPE_TARGET_TYPE (inner_array);
8035 TYPE_TARGET_TYPE (inner_array) =
8036 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8038 return set_die_type (die, base_type, cu);
8041 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8042 return set_die_type (die, cv_type, cu);
8045 static struct type *
8046 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8048 struct type *base_type, *cv_type;
8050 base_type = die_type (die, cu);
8052 /* The die_type call above may have already set the type for this DIE. */
8053 cv_type = get_die_type (die, cu);
8057 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8058 return set_die_type (die, cv_type, cu);
8061 /* Extract all information from a DW_TAG_string_type DIE and add to
8062 the user defined type vector. It isn't really a user defined type,
8063 but it behaves like one, with other DIE's using an AT_user_def_type
8064 attribute to reference it. */
8066 static struct type *
8067 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8069 struct objfile *objfile = cu->objfile;
8070 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8071 struct type *type, *range_type, *index_type, *char_type;
8072 struct attribute *attr;
8073 unsigned int length;
8075 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8078 length = DW_UNSND (attr);
8082 /* Check for the DW_AT_byte_size attribute. */
8083 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8086 length = DW_UNSND (attr);
8094 index_type = objfile_type (objfile)->builtin_int;
8095 range_type = create_range_type (NULL, index_type, 1, length);
8096 char_type = language_string_char_type (cu->language_defn, gdbarch);
8097 type = create_string_type (NULL, char_type, range_type);
8099 return set_die_type (die, type, cu);
8102 /* Handle DIES due to C code like:
8106 int (*funcp)(int a, long l);
8110 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8112 static struct type *
8113 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8115 struct type *type; /* Type that this function returns. */
8116 struct type *ftype; /* Function that returns above type. */
8117 struct attribute *attr;
8119 type = die_type (die, cu);
8121 /* The die_type call above may have already set the type for this DIE. */
8122 ftype = get_die_type (die, cu);
8126 ftype = lookup_function_type (type);
8128 /* All functions in C++, Pascal and Java have prototypes. */
8129 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8130 if ((attr && (DW_UNSND (attr) != 0))
8131 || cu->language == language_cplus
8132 || cu->language == language_java
8133 || cu->language == language_pascal)
8134 TYPE_PROTOTYPED (ftype) = 1;
8135 else if (producer_is_realview (cu->producer))
8136 /* RealView does not emit DW_AT_prototyped. We can not
8137 distinguish prototyped and unprototyped functions; default to
8138 prototyped, since that is more common in modern code (and
8139 RealView warns about unprototyped functions). */
8140 TYPE_PROTOTYPED (ftype) = 1;
8142 /* Store the calling convention in the type if it's available in
8143 the subroutine die. Otherwise set the calling convention to
8144 the default value DW_CC_normal. */
8145 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8147 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8148 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8149 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8151 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8153 /* We need to add the subroutine type to the die immediately so
8154 we don't infinitely recurse when dealing with parameters
8155 declared as the same subroutine type. */
8156 set_die_type (die, ftype, cu);
8158 if (die->child != NULL)
8160 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8161 struct die_info *child_die;
8162 int nparams, iparams;
8164 /* Count the number of parameters.
8165 FIXME: GDB currently ignores vararg functions, but knows about
8166 vararg member functions. */
8168 child_die = die->child;
8169 while (child_die && child_die->tag)
8171 if (child_die->tag == DW_TAG_formal_parameter)
8173 else if (child_die->tag == DW_TAG_unspecified_parameters)
8174 TYPE_VARARGS (ftype) = 1;
8175 child_die = sibling_die (child_die);
8178 /* Allocate storage for parameters and fill them in. */
8179 TYPE_NFIELDS (ftype) = nparams;
8180 TYPE_FIELDS (ftype) = (struct field *)
8181 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8183 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8184 even if we error out during the parameters reading below. */
8185 for (iparams = 0; iparams < nparams; iparams++)
8186 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8189 child_die = die->child;
8190 while (child_die && child_die->tag)
8192 if (child_die->tag == DW_TAG_formal_parameter)
8194 struct type *arg_type;
8196 /* DWARF version 2 has no clean way to discern C++
8197 static and non-static member functions. G++ helps
8198 GDB by marking the first parameter for non-static
8199 member functions (which is the this pointer) as
8200 artificial. We pass this information to
8201 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8203 DWARF version 3 added DW_AT_object_pointer, which GCC
8204 4.5 does not yet generate. */
8205 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8207 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8210 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8212 /* GCC/43521: In java, the formal parameter
8213 "this" is sometimes not marked with DW_AT_artificial. */
8214 if (cu->language == language_java)
8216 const char *name = dwarf2_name (child_die, cu);
8218 if (name && !strcmp (name, "this"))
8219 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8222 arg_type = die_type (child_die, cu);
8224 /* RealView does not mark THIS as const, which the testsuite
8225 expects. GCC marks THIS as const in method definitions,
8226 but not in the class specifications (GCC PR 43053). */
8227 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8228 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8231 struct dwarf2_cu *arg_cu = cu;
8232 const char *name = dwarf2_name (child_die, cu);
8234 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8237 /* If the compiler emits this, use it. */
8238 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8241 else if (name && strcmp (name, "this") == 0)
8242 /* Function definitions will have the argument names. */
8244 else if (name == NULL && iparams == 0)
8245 /* Declarations may not have the names, so like
8246 elsewhere in GDB, assume an artificial first
8247 argument is "this". */
8251 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8255 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8258 child_die = sibling_die (child_die);
8265 static struct type *
8266 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8268 struct objfile *objfile = cu->objfile;
8269 const char *name = NULL;
8270 struct type *this_type;
8272 name = dwarf2_full_name (NULL, die, cu);
8273 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8274 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8275 TYPE_NAME (this_type) = (char *) name;
8276 set_die_type (die, this_type, cu);
8277 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8281 /* Find a representation of a given base type and install
8282 it in the TYPE field of the die. */
8284 static struct type *
8285 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8287 struct objfile *objfile = cu->objfile;
8289 struct attribute *attr;
8290 int encoding = 0, size = 0;
8292 enum type_code code = TYPE_CODE_INT;
8294 struct type *target_type = NULL;
8296 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8299 encoding = DW_UNSND (attr);
8301 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8304 size = DW_UNSND (attr);
8306 name = dwarf2_name (die, cu);
8309 complaint (&symfile_complaints,
8310 _("DW_AT_name missing from DW_TAG_base_type"));
8315 case DW_ATE_address:
8316 /* Turn DW_ATE_address into a void * pointer. */
8317 code = TYPE_CODE_PTR;
8318 type_flags |= TYPE_FLAG_UNSIGNED;
8319 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8321 case DW_ATE_boolean:
8322 code = TYPE_CODE_BOOL;
8323 type_flags |= TYPE_FLAG_UNSIGNED;
8325 case DW_ATE_complex_float:
8326 code = TYPE_CODE_COMPLEX;
8327 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8329 case DW_ATE_decimal_float:
8330 code = TYPE_CODE_DECFLOAT;
8333 code = TYPE_CODE_FLT;
8337 case DW_ATE_unsigned:
8338 type_flags |= TYPE_FLAG_UNSIGNED;
8340 case DW_ATE_signed_char:
8341 if (cu->language == language_ada || cu->language == language_m2
8342 || cu->language == language_pascal)
8343 code = TYPE_CODE_CHAR;
8345 case DW_ATE_unsigned_char:
8346 if (cu->language == language_ada || cu->language == language_m2
8347 || cu->language == language_pascal)
8348 code = TYPE_CODE_CHAR;
8349 type_flags |= TYPE_FLAG_UNSIGNED;
8352 /* We just treat this as an integer and then recognize the
8353 type by name elsewhere. */
8357 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8358 dwarf_type_encoding_name (encoding));
8362 type = init_type (code, size, type_flags, NULL, objfile);
8363 TYPE_NAME (type) = name;
8364 TYPE_TARGET_TYPE (type) = target_type;
8366 if (name && strcmp (name, "char") == 0)
8367 TYPE_NOSIGN (type) = 1;
8369 return set_die_type (die, type, cu);
8372 /* Read the given DW_AT_subrange DIE. */
8374 static struct type *
8375 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8377 struct type *base_type;
8378 struct type *range_type;
8379 struct attribute *attr;
8383 LONGEST negative_mask;
8385 base_type = die_type (die, cu);
8386 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8387 check_typedef (base_type);
8389 /* The die_type call above may have already set the type for this DIE. */
8390 range_type = get_die_type (die, cu);
8394 if (cu->language == language_fortran)
8396 /* FORTRAN implies a lower bound of 1, if not given. */
8400 /* FIXME: For variable sized arrays either of these could be
8401 a variable rather than a constant value. We'll allow it,
8402 but we don't know how to handle it. */
8403 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8405 low = dwarf2_get_attr_constant_value (attr, 0);
8407 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8410 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
8412 /* GCC encodes arrays with unspecified or dynamic length
8413 with a DW_FORM_block1 attribute or a reference attribute.
8414 FIXME: GDB does not yet know how to handle dynamic
8415 arrays properly, treat them as arrays with unspecified
8418 FIXME: jimb/2003-09-22: GDB does not really know
8419 how to handle arrays of unspecified length
8420 either; we just represent them as zero-length
8421 arrays. Choose an appropriate upper bound given
8422 the lower bound we've computed above. */
8426 high = dwarf2_get_attr_constant_value (attr, 1);
8430 attr = dwarf2_attr (die, DW_AT_count, cu);
8433 int count = dwarf2_get_attr_constant_value (attr, 1);
8434 high = low + count - 1;
8438 /* Unspecified array length. */
8443 /* Dwarf-2 specifications explicitly allows to create subrange types
8444 without specifying a base type.
8445 In that case, the base type must be set to the type of
8446 the lower bound, upper bound or count, in that order, if any of these
8447 three attributes references an object that has a type.
8448 If no base type is found, the Dwarf-2 specifications say that
8449 a signed integer type of size equal to the size of an address should
8451 For the following C code: `extern char gdb_int [];'
8452 GCC produces an empty range DIE.
8453 FIXME: muller/2010-05-28: Possible references to object for low bound,
8454 high bound or count are not yet handled by this code. */
8455 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8457 struct objfile *objfile = cu->objfile;
8458 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8459 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8460 struct type *int_type = objfile_type (objfile)->builtin_int;
8462 /* Test "int", "long int", and "long long int" objfile types,
8463 and select the first one having a size above or equal to the
8464 architecture address size. */
8465 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8466 base_type = int_type;
8469 int_type = objfile_type (objfile)->builtin_long;
8470 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8471 base_type = int_type;
8474 int_type = objfile_type (objfile)->builtin_long_long;
8475 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8476 base_type = int_type;
8482 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8483 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8484 low |= negative_mask;
8485 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8486 high |= negative_mask;
8488 range_type = create_range_type (NULL, base_type, low, high);
8490 /* Mark arrays with dynamic length at least as an array of unspecified
8491 length. GDB could check the boundary but before it gets implemented at
8492 least allow accessing the array elements. */
8493 if (attr && attr->form == DW_FORM_block1)
8494 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8496 /* Ada expects an empty array on no boundary attributes. */
8497 if (attr == NULL && cu->language != language_ada)
8498 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8500 name = dwarf2_name (die, cu);
8502 TYPE_NAME (range_type) = name;
8504 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8506 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8508 set_die_type (die, range_type, cu);
8510 /* set_die_type should be already done. */
8511 set_descriptive_type (range_type, die, cu);
8516 static struct type *
8517 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8521 /* For now, we only support the C meaning of an unspecified type: void. */
8523 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8524 TYPE_NAME (type) = dwarf2_name (die, cu);
8526 return set_die_type (die, type, cu);
8529 /* Trivial hash function for die_info: the hash value of a DIE
8530 is its offset in .debug_info for this objfile. */
8533 die_hash (const void *item)
8535 const struct die_info *die = item;
8540 /* Trivial comparison function for die_info structures: two DIEs
8541 are equal if they have the same offset. */
8544 die_eq (const void *item_lhs, const void *item_rhs)
8546 const struct die_info *die_lhs = item_lhs;
8547 const struct die_info *die_rhs = item_rhs;
8549 return die_lhs->offset == die_rhs->offset;
8552 /* Read a whole compilation unit into a linked list of dies. */
8554 static struct die_info *
8555 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8557 struct die_reader_specs reader_specs;
8558 int read_abbrevs = 0;
8559 struct cleanup *back_to = NULL;
8560 struct die_info *die;
8562 if (cu->dwarf2_abbrevs == NULL)
8564 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8565 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8569 gdb_assert (cu->die_hash == NULL);
8571 = htab_create_alloc_ex (cu->header.length / 12,
8575 &cu->comp_unit_obstack,
8576 hashtab_obstack_allocate,
8577 dummy_obstack_deallocate);
8579 init_cu_die_reader (&reader_specs, cu);
8581 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8584 do_cleanups (back_to);
8589 /* Main entry point for reading a DIE and all children.
8590 Read the DIE and dump it if requested. */
8592 static struct die_info *
8593 read_die_and_children (const struct die_reader_specs *reader,
8595 gdb_byte **new_info_ptr,
8596 struct die_info *parent)
8598 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8599 new_info_ptr, parent);
8601 if (dwarf2_die_debug)
8603 fprintf_unfiltered (gdb_stdlog,
8604 "\nRead die from %s of %s:\n",
8605 reader->buffer == dwarf2_per_objfile->info.buffer
8607 : reader->buffer == dwarf2_per_objfile->types.buffer
8609 : "unknown section",
8610 reader->abfd->filename);
8611 dump_die (result, dwarf2_die_debug);
8617 /* Read a single die and all its descendents. Set the die's sibling
8618 field to NULL; set other fields in the die correctly, and set all
8619 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8620 location of the info_ptr after reading all of those dies. PARENT
8621 is the parent of the die in question. */
8623 static struct die_info *
8624 read_die_and_children_1 (const struct die_reader_specs *reader,
8626 gdb_byte **new_info_ptr,
8627 struct die_info *parent)
8629 struct die_info *die;
8633 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8636 *new_info_ptr = cur_ptr;
8639 store_in_ref_table (die, reader->cu);
8642 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8646 *new_info_ptr = cur_ptr;
8649 die->sibling = NULL;
8650 die->parent = parent;
8654 /* Read a die, all of its descendents, and all of its siblings; set
8655 all of the fields of all of the dies correctly. Arguments are as
8656 in read_die_and_children. */
8658 static struct die_info *
8659 read_die_and_siblings (const struct die_reader_specs *reader,
8661 gdb_byte **new_info_ptr,
8662 struct die_info *parent)
8664 struct die_info *first_die, *last_sibling;
8668 first_die = last_sibling = NULL;
8672 struct die_info *die
8673 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8677 *new_info_ptr = cur_ptr;
8684 last_sibling->sibling = die;
8690 /* Read the die from the .debug_info section buffer. Set DIEP to
8691 point to a newly allocated die with its information, except for its
8692 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8693 whether the die has children or not. */
8696 read_full_die (const struct die_reader_specs *reader,
8697 struct die_info **diep, gdb_byte *info_ptr,
8700 unsigned int abbrev_number, bytes_read, i, offset;
8701 struct abbrev_info *abbrev;
8702 struct die_info *die;
8703 struct dwarf2_cu *cu = reader->cu;
8704 bfd *abfd = reader->abfd;
8706 offset = info_ptr - reader->buffer;
8707 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8708 info_ptr += bytes_read;
8716 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8718 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8720 bfd_get_filename (abfd));
8722 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8723 die->offset = offset;
8724 die->tag = abbrev->tag;
8725 die->abbrev = abbrev_number;
8727 die->num_attrs = abbrev->num_attrs;
8729 for (i = 0; i < abbrev->num_attrs; ++i)
8730 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8731 abfd, info_ptr, cu);
8734 *has_children = abbrev->has_children;
8738 /* In DWARF version 2, the description of the debugging information is
8739 stored in a separate .debug_abbrev section. Before we read any
8740 dies from a section we read in all abbreviations and install them
8741 in a hash table. This function also sets flags in CU describing
8742 the data found in the abbrev table. */
8745 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8747 struct comp_unit_head *cu_header = &cu->header;
8748 gdb_byte *abbrev_ptr;
8749 struct abbrev_info *cur_abbrev;
8750 unsigned int abbrev_number, bytes_read, abbrev_name;
8751 unsigned int abbrev_form, hash_number;
8752 struct attr_abbrev *cur_attrs;
8753 unsigned int allocated_attrs;
8755 /* Initialize dwarf2 abbrevs. */
8756 obstack_init (&cu->abbrev_obstack);
8757 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
8759 * sizeof (struct abbrev_info *)));
8760 memset (cu->dwarf2_abbrevs, 0,
8761 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
8763 dwarf2_read_section (dwarf2_per_objfile->objfile,
8764 &dwarf2_per_objfile->abbrev);
8765 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
8766 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8767 abbrev_ptr += bytes_read;
8769 allocated_attrs = ATTR_ALLOC_CHUNK;
8770 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
8772 /* Loop until we reach an abbrev number of 0. */
8773 while (abbrev_number)
8775 cur_abbrev = dwarf_alloc_abbrev (cu);
8777 /* read in abbrev header */
8778 cur_abbrev->number = abbrev_number;
8779 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8780 abbrev_ptr += bytes_read;
8781 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
8784 if (cur_abbrev->tag == DW_TAG_namespace)
8785 cu->has_namespace_info = 1;
8787 /* now read in declarations */
8788 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8789 abbrev_ptr += bytes_read;
8790 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8791 abbrev_ptr += bytes_read;
8794 if (cur_abbrev->num_attrs == allocated_attrs)
8796 allocated_attrs += ATTR_ALLOC_CHUNK;
8798 = xrealloc (cur_attrs, (allocated_attrs
8799 * sizeof (struct attr_abbrev)));
8802 /* Record whether this compilation unit might have
8803 inter-compilation-unit references. If we don't know what form
8804 this attribute will have, then it might potentially be a
8805 DW_FORM_ref_addr, so we conservatively expect inter-CU
8808 if (abbrev_form == DW_FORM_ref_addr
8809 || abbrev_form == DW_FORM_indirect)
8810 cu->has_form_ref_addr = 1;
8812 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
8813 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
8814 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8815 abbrev_ptr += bytes_read;
8816 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8817 abbrev_ptr += bytes_read;
8820 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
8821 (cur_abbrev->num_attrs
8822 * sizeof (struct attr_abbrev)));
8823 memcpy (cur_abbrev->attrs, cur_attrs,
8824 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
8826 hash_number = abbrev_number % ABBREV_HASH_SIZE;
8827 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
8828 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
8830 /* Get next abbreviation.
8831 Under Irix6 the abbreviations for a compilation unit are not
8832 always properly terminated with an abbrev number of 0.
8833 Exit loop if we encounter an abbreviation which we have
8834 already read (which means we are about to read the abbreviations
8835 for the next compile unit) or if the end of the abbreviation
8836 table is reached. */
8837 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
8838 >= dwarf2_per_objfile->abbrev.size)
8840 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8841 abbrev_ptr += bytes_read;
8842 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
8849 /* Release the memory used by the abbrev table for a compilation unit. */
8852 dwarf2_free_abbrev_table (void *ptr_to_cu)
8854 struct dwarf2_cu *cu = ptr_to_cu;
8856 obstack_free (&cu->abbrev_obstack, NULL);
8857 cu->dwarf2_abbrevs = NULL;
8860 /* Lookup an abbrev_info structure in the abbrev hash table. */
8862 static struct abbrev_info *
8863 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
8865 unsigned int hash_number;
8866 struct abbrev_info *abbrev;
8868 hash_number = number % ABBREV_HASH_SIZE;
8869 abbrev = cu->dwarf2_abbrevs[hash_number];
8873 if (abbrev->number == number)
8876 abbrev = abbrev->next;
8881 /* Returns nonzero if TAG represents a type that we might generate a partial
8885 is_type_tag_for_partial (int tag)
8890 /* Some types that would be reasonable to generate partial symbols for,
8891 that we don't at present. */
8892 case DW_TAG_array_type:
8893 case DW_TAG_file_type:
8894 case DW_TAG_ptr_to_member_type:
8895 case DW_TAG_set_type:
8896 case DW_TAG_string_type:
8897 case DW_TAG_subroutine_type:
8899 case DW_TAG_base_type:
8900 case DW_TAG_class_type:
8901 case DW_TAG_interface_type:
8902 case DW_TAG_enumeration_type:
8903 case DW_TAG_structure_type:
8904 case DW_TAG_subrange_type:
8905 case DW_TAG_typedef:
8906 case DW_TAG_union_type:
8913 /* Load all DIEs that are interesting for partial symbols into memory. */
8915 static struct partial_die_info *
8916 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
8917 int building_psymtab, struct dwarf2_cu *cu)
8919 struct partial_die_info *part_die;
8920 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
8921 struct abbrev_info *abbrev;
8922 unsigned int bytes_read;
8923 unsigned int load_all = 0;
8925 int nesting_level = 1;
8930 if (cu->per_cu && cu->per_cu->load_all_dies)
8934 = htab_create_alloc_ex (cu->header.length / 12,
8938 &cu->comp_unit_obstack,
8939 hashtab_obstack_allocate,
8940 dummy_obstack_deallocate);
8942 part_die = obstack_alloc (&cu->comp_unit_obstack,
8943 sizeof (struct partial_die_info));
8947 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8949 /* A NULL abbrev means the end of a series of children. */
8952 if (--nesting_level == 0)
8954 /* PART_DIE was probably the last thing allocated on the
8955 comp_unit_obstack, so we could call obstack_free
8956 here. We don't do that because the waste is small,
8957 and will be cleaned up when we're done with this
8958 compilation unit. This way, we're also more robust
8959 against other users of the comp_unit_obstack. */
8962 info_ptr += bytes_read;
8963 last_die = parent_die;
8964 parent_die = parent_die->die_parent;
8968 /* Check for template arguments. We never save these; if
8969 they're seen, we just mark the parent, and go on our way. */
8970 if (parent_die != NULL
8971 && cu->language == language_cplus
8972 && (abbrev->tag == DW_TAG_template_type_param
8973 || abbrev->tag == DW_TAG_template_value_param))
8975 parent_die->has_template_arguments = 1;
8979 /* We don't need a partial DIE for the template argument. */
8980 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
8986 /* We only recurse into subprograms looking for template arguments.
8987 Skip their other children. */
8989 && cu->language == language_cplus
8990 && parent_die != NULL
8991 && parent_die->tag == DW_TAG_subprogram)
8993 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8997 /* Check whether this DIE is interesting enough to save. Normally
8998 we would not be interested in members here, but there may be
8999 later variables referencing them via DW_AT_specification (for
9002 && !is_type_tag_for_partial (abbrev->tag)
9003 && abbrev->tag != DW_TAG_constant
9004 && abbrev->tag != DW_TAG_enumerator
9005 && abbrev->tag != DW_TAG_subprogram
9006 && abbrev->tag != DW_TAG_lexical_block
9007 && abbrev->tag != DW_TAG_variable
9008 && abbrev->tag != DW_TAG_namespace
9009 && abbrev->tag != DW_TAG_module
9010 && abbrev->tag != DW_TAG_member)
9012 /* Otherwise we skip to the next sibling, if any. */
9013 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9017 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9018 buffer, info_ptr, cu);
9020 /* This two-pass algorithm for processing partial symbols has a
9021 high cost in cache pressure. Thus, handle some simple cases
9022 here which cover the majority of C partial symbols. DIEs
9023 which neither have specification tags in them, nor could have
9024 specification tags elsewhere pointing at them, can simply be
9025 processed and discarded.
9027 This segment is also optional; scan_partial_symbols and
9028 add_partial_symbol will handle these DIEs if we chain
9029 them in normally. When compilers which do not emit large
9030 quantities of duplicate debug information are more common,
9031 this code can probably be removed. */
9033 /* Any complete simple types at the top level (pretty much all
9034 of them, for a language without namespaces), can be processed
9036 if (parent_die == NULL
9037 && part_die->has_specification == 0
9038 && part_die->is_declaration == 0
9039 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9040 || part_die->tag == DW_TAG_base_type
9041 || part_die->tag == DW_TAG_subrange_type))
9043 if (building_psymtab && part_die->name != NULL)
9044 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9045 VAR_DOMAIN, LOC_TYPEDEF,
9046 &cu->objfile->static_psymbols,
9047 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9048 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9052 /* The exception for DW_TAG_typedef with has_children above is
9053 a workaround of GCC PR debug/47510. In the case of this complaint
9054 type_name_no_tag_or_error will error on such types later.
9056 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9057 it could not find the child DIEs referenced later, this is checked
9058 above. In correct DWARF DW_TAG_typedef should have no children. */
9060 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9061 complaint (&symfile_complaints,
9062 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9063 "- DIE at 0x%x [in module %s]"),
9064 part_die->offset, cu->objfile->name);
9066 /* If we're at the second level, and we're an enumerator, and
9067 our parent has no specification (meaning possibly lives in a
9068 namespace elsewhere), then we can add the partial symbol now
9069 instead of queueing it. */
9070 if (part_die->tag == DW_TAG_enumerator
9071 && parent_die != NULL
9072 && parent_die->die_parent == NULL
9073 && parent_die->tag == DW_TAG_enumeration_type
9074 && parent_die->has_specification == 0)
9076 if (part_die->name == NULL)
9077 complaint (&symfile_complaints,
9078 _("malformed enumerator DIE ignored"));
9079 else if (building_psymtab)
9080 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9081 VAR_DOMAIN, LOC_CONST,
9082 (cu->language == language_cplus
9083 || cu->language == language_java)
9084 ? &cu->objfile->global_psymbols
9085 : &cu->objfile->static_psymbols,
9086 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9088 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9092 /* We'll save this DIE so link it in. */
9093 part_die->die_parent = parent_die;
9094 part_die->die_sibling = NULL;
9095 part_die->die_child = NULL;
9097 if (last_die && last_die == parent_die)
9098 last_die->die_child = part_die;
9100 last_die->die_sibling = part_die;
9102 last_die = part_die;
9104 if (first_die == NULL)
9105 first_die = part_die;
9107 /* Maybe add the DIE to the hash table. Not all DIEs that we
9108 find interesting need to be in the hash table, because we
9109 also have the parent/sibling/child chains; only those that we
9110 might refer to by offset later during partial symbol reading.
9112 For now this means things that might have be the target of a
9113 DW_AT_specification, DW_AT_abstract_origin, or
9114 DW_AT_extension. DW_AT_extension will refer only to
9115 namespaces; DW_AT_abstract_origin refers to functions (and
9116 many things under the function DIE, but we do not recurse
9117 into function DIEs during partial symbol reading) and
9118 possibly variables as well; DW_AT_specification refers to
9119 declarations. Declarations ought to have the DW_AT_declaration
9120 flag. It happens that GCC forgets to put it in sometimes, but
9121 only for functions, not for types.
9123 Adding more things than necessary to the hash table is harmless
9124 except for the performance cost. Adding too few will result in
9125 wasted time in find_partial_die, when we reread the compilation
9126 unit with load_all_dies set. */
9129 || abbrev->tag == DW_TAG_constant
9130 || abbrev->tag == DW_TAG_subprogram
9131 || abbrev->tag == DW_TAG_variable
9132 || abbrev->tag == DW_TAG_namespace
9133 || part_die->is_declaration)
9137 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9138 part_die->offset, INSERT);
9142 part_die = obstack_alloc (&cu->comp_unit_obstack,
9143 sizeof (struct partial_die_info));
9145 /* For some DIEs we want to follow their children (if any). For C
9146 we have no reason to follow the children of structures; for other
9147 languages we have to, so that we can get at method physnames
9148 to infer fully qualified class names, for DW_AT_specification,
9149 and for C++ template arguments. For C++, we also look one level
9150 inside functions to find template arguments (if the name of the
9151 function does not already contain the template arguments).
9153 For Ada, we need to scan the children of subprograms and lexical
9154 blocks as well because Ada allows the definition of nested
9155 entities that could be interesting for the debugger, such as
9156 nested subprograms for instance. */
9157 if (last_die->has_children
9159 || last_die->tag == DW_TAG_namespace
9160 || last_die->tag == DW_TAG_module
9161 || last_die->tag == DW_TAG_enumeration_type
9162 || (cu->language == language_cplus
9163 && last_die->tag == DW_TAG_subprogram
9164 && (last_die->name == NULL
9165 || strchr (last_die->name, '<') == NULL))
9166 || (cu->language != language_c
9167 && (last_die->tag == DW_TAG_class_type
9168 || last_die->tag == DW_TAG_interface_type
9169 || last_die->tag == DW_TAG_structure_type
9170 || last_die->tag == DW_TAG_union_type))
9171 || (cu->language == language_ada
9172 && (last_die->tag == DW_TAG_subprogram
9173 || last_die->tag == DW_TAG_lexical_block))))
9176 parent_die = last_die;
9180 /* Otherwise we skip to the next sibling, if any. */
9181 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9183 /* Back to the top, do it again. */
9187 /* Read a minimal amount of information into the minimal die structure. */
9190 read_partial_die (struct partial_die_info *part_die,
9191 struct abbrev_info *abbrev,
9192 unsigned int abbrev_len, bfd *abfd,
9193 gdb_byte *buffer, gdb_byte *info_ptr,
9194 struct dwarf2_cu *cu)
9197 struct attribute attr;
9198 int has_low_pc_attr = 0;
9199 int has_high_pc_attr = 0;
9201 memset (part_die, 0, sizeof (struct partial_die_info));
9203 part_die->offset = info_ptr - buffer;
9205 info_ptr += abbrev_len;
9210 part_die->tag = abbrev->tag;
9211 part_die->has_children = abbrev->has_children;
9213 for (i = 0; i < abbrev->num_attrs; ++i)
9215 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9217 /* Store the data if it is of an attribute we want to keep in a
9218 partial symbol table. */
9222 switch (part_die->tag)
9224 case DW_TAG_compile_unit:
9225 case DW_TAG_type_unit:
9226 /* Compilation units have a DW_AT_name that is a filename, not
9227 a source language identifier. */
9228 case DW_TAG_enumeration_type:
9229 case DW_TAG_enumerator:
9230 /* These tags always have simple identifiers already; no need
9231 to canonicalize them. */
9232 part_die->name = DW_STRING (&attr);
9236 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9237 &cu->objfile->objfile_obstack);
9241 case DW_AT_linkage_name:
9242 case DW_AT_MIPS_linkage_name:
9243 /* Note that both forms of linkage name might appear. We
9244 assume they will be the same, and we only store the last
9246 if (cu->language == language_ada)
9247 part_die->name = DW_STRING (&attr);
9248 part_die->linkage_name = DW_STRING (&attr);
9251 has_low_pc_attr = 1;
9252 part_die->lowpc = DW_ADDR (&attr);
9255 has_high_pc_attr = 1;
9256 part_die->highpc = DW_ADDR (&attr);
9258 case DW_AT_location:
9259 /* Support the .debug_loc offsets. */
9260 if (attr_form_is_block (&attr))
9262 part_die->locdesc = DW_BLOCK (&attr);
9264 else if (attr_form_is_section_offset (&attr))
9266 dwarf2_complex_location_expr_complaint ();
9270 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9271 "partial symbol information");
9274 case DW_AT_external:
9275 part_die->is_external = DW_UNSND (&attr);
9277 case DW_AT_declaration:
9278 part_die->is_declaration = DW_UNSND (&attr);
9281 part_die->has_type = 1;
9283 case DW_AT_abstract_origin:
9284 case DW_AT_specification:
9285 case DW_AT_extension:
9286 part_die->has_specification = 1;
9287 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9290 /* Ignore absolute siblings, they might point outside of
9291 the current compile unit. */
9292 if (attr.form == DW_FORM_ref_addr)
9293 complaint (&symfile_complaints,
9294 _("ignoring absolute DW_AT_sibling"));
9296 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9298 case DW_AT_byte_size:
9299 part_die->has_byte_size = 1;
9301 case DW_AT_calling_convention:
9302 /* DWARF doesn't provide a way to identify a program's source-level
9303 entry point. DW_AT_calling_convention attributes are only meant
9304 to describe functions' calling conventions.
9306 However, because it's a necessary piece of information in
9307 Fortran, and because DW_CC_program is the only piece of debugging
9308 information whose definition refers to a 'main program' at all,
9309 several compilers have begun marking Fortran main programs with
9310 DW_CC_program --- even when those functions use the standard
9311 calling conventions.
9313 So until DWARF specifies a way to provide this information and
9314 compilers pick up the new representation, we'll support this
9316 if (DW_UNSND (&attr) == DW_CC_program
9317 && cu->language == language_fortran)
9319 set_main_name (part_die->name);
9321 /* As this DIE has a static linkage the name would be difficult
9322 to look up later. */
9323 language_of_main = language_fortran;
9331 if (has_low_pc_attr && has_high_pc_attr)
9333 /* When using the GNU linker, .gnu.linkonce. sections are used to
9334 eliminate duplicate copies of functions and vtables and such.
9335 The linker will arbitrarily choose one and discard the others.
9336 The AT_*_pc values for such functions refer to local labels in
9337 these sections. If the section from that file was discarded, the
9338 labels are not in the output, so the relocs get a value of 0.
9339 If this is a discarded function, mark the pc bounds as invalid,
9340 so that GDB will ignore it. */
9341 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9343 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9345 complaint (&symfile_complaints,
9346 _("DW_AT_low_pc %s is zero "
9347 "for DIE at 0x%x [in module %s]"),
9348 paddress (gdbarch, part_die->lowpc),
9349 part_die->offset, cu->objfile->name);
9351 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9352 else if (part_die->lowpc >= part_die->highpc)
9354 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9356 complaint (&symfile_complaints,
9357 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9358 "for DIE at 0x%x [in module %s]"),
9359 paddress (gdbarch, part_die->lowpc),
9360 paddress (gdbarch, part_die->highpc),
9361 part_die->offset, cu->objfile->name);
9364 part_die->has_pc_info = 1;
9370 /* Find a cached partial DIE at OFFSET in CU. */
9372 static struct partial_die_info *
9373 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9375 struct partial_die_info *lookup_die = NULL;
9376 struct partial_die_info part_die;
9378 part_die.offset = offset;
9379 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9384 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9385 except in the case of .debug_types DIEs which do not reference
9386 outside their CU (they do however referencing other types via
9387 DW_FORM_ref_sig8). */
9389 static struct partial_die_info *
9390 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9392 struct dwarf2_per_cu_data *per_cu = NULL;
9393 struct partial_die_info *pd = NULL;
9395 if (cu->per_cu->from_debug_types)
9397 pd = find_partial_die_in_comp_unit (offset, cu);
9403 if (offset_in_cu_p (&cu->header, offset))
9405 pd = find_partial_die_in_comp_unit (offset, cu);
9410 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9412 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9413 load_partial_comp_unit (per_cu, cu->objfile);
9415 per_cu->cu->last_used = 0;
9416 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9418 if (pd == NULL && per_cu->load_all_dies == 0)
9420 struct cleanup *back_to;
9421 struct partial_die_info comp_unit_die;
9422 struct abbrev_info *abbrev;
9423 unsigned int bytes_read;
9426 per_cu->load_all_dies = 1;
9428 /* Re-read the DIEs. */
9429 back_to = make_cleanup (null_cleanup, 0);
9430 if (per_cu->cu->dwarf2_abbrevs == NULL)
9432 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
9433 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9435 info_ptr = (dwarf2_per_objfile->info.buffer
9436 + per_cu->cu->header.offset
9437 + per_cu->cu->header.first_die_offset);
9438 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9439 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9440 per_cu->cu->objfile->obfd,
9441 dwarf2_per_objfile->info.buffer, info_ptr,
9443 if (comp_unit_die.has_children)
9444 load_partial_dies (per_cu->cu->objfile->obfd,
9445 dwarf2_per_objfile->info.buffer, info_ptr,
9447 do_cleanups (back_to);
9449 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9455 internal_error (__FILE__, __LINE__,
9456 _("could not find partial DIE 0x%x "
9457 "in cache [from module %s]\n"),
9458 offset, bfd_get_filename (cu->objfile->obfd));
9462 /* See if we can figure out if the class lives in a namespace. We do
9463 this by looking for a member function; its demangled name will
9464 contain namespace info, if there is any. */
9467 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9468 struct dwarf2_cu *cu)
9470 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9471 what template types look like, because the demangler
9472 frequently doesn't give the same name as the debug info. We
9473 could fix this by only using the demangled name to get the
9474 prefix (but see comment in read_structure_type). */
9476 struct partial_die_info *real_pdi;
9477 struct partial_die_info *child_pdi;
9479 /* If this DIE (this DIE's specification, if any) has a parent, then
9480 we should not do this. We'll prepend the parent's fully qualified
9481 name when we create the partial symbol. */
9483 real_pdi = struct_pdi;
9484 while (real_pdi->has_specification)
9485 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9487 if (real_pdi->die_parent != NULL)
9490 for (child_pdi = struct_pdi->die_child;
9492 child_pdi = child_pdi->die_sibling)
9494 if (child_pdi->tag == DW_TAG_subprogram
9495 && child_pdi->linkage_name != NULL)
9497 char *actual_class_name
9498 = language_class_name_from_physname (cu->language_defn,
9499 child_pdi->linkage_name);
9500 if (actual_class_name != NULL)
9503 = obsavestring (actual_class_name,
9504 strlen (actual_class_name),
9505 &cu->objfile->objfile_obstack);
9506 xfree (actual_class_name);
9513 /* Adjust PART_DIE before generating a symbol for it. This function
9514 may set the is_external flag or change the DIE's name. */
9517 fixup_partial_die (struct partial_die_info *part_die,
9518 struct dwarf2_cu *cu)
9520 /* Once we've fixed up a die, there's no point in doing so again.
9521 This also avoids a memory leak if we were to call
9522 guess_partial_die_structure_name multiple times. */
9523 if (part_die->fixup_called)
9526 /* If we found a reference attribute and the DIE has no name, try
9527 to find a name in the referred to DIE. */
9529 if (part_die->name == NULL && part_die->has_specification)
9531 struct partial_die_info *spec_die;
9533 spec_die = find_partial_die (part_die->spec_offset, cu);
9535 fixup_partial_die (spec_die, cu);
9539 part_die->name = spec_die->name;
9541 /* Copy DW_AT_external attribute if it is set. */
9542 if (spec_die->is_external)
9543 part_die->is_external = spec_die->is_external;
9547 /* Set default names for some unnamed DIEs. */
9549 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
9550 part_die->name = "(anonymous namespace)";
9552 /* If there is no parent die to provide a namespace, and there are
9553 children, see if we can determine the namespace from their linkage
9555 NOTE: We need to do this even if cu->has_namespace_info != 0.
9556 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9557 if (cu->language == language_cplus
9558 && dwarf2_per_objfile->types.asection != NULL
9559 && part_die->die_parent == NULL
9560 && part_die->has_children
9561 && (part_die->tag == DW_TAG_class_type
9562 || part_die->tag == DW_TAG_structure_type
9563 || part_die->tag == DW_TAG_union_type))
9564 guess_partial_die_structure_name (part_die, cu);
9566 /* GCC might emit a nameless struct or union that has a linkage
9567 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9568 if (part_die->name == NULL
9569 && (part_die->tag == DW_TAG_structure_type
9570 || part_die->tag == DW_TAG_union_type
9571 || part_die->tag == DW_TAG_class_type)
9572 && part_die->linkage_name != NULL)
9576 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
9579 part_die->name = obsavestring (demangled, strlen (demangled),
9580 &cu->objfile->objfile_obstack);
9585 part_die->fixup_called = 1;
9588 /* Read an attribute value described by an attribute form. */
9591 read_attribute_value (struct attribute *attr, unsigned form,
9592 bfd *abfd, gdb_byte *info_ptr,
9593 struct dwarf2_cu *cu)
9595 struct comp_unit_head *cu_header = &cu->header;
9596 unsigned int bytes_read;
9597 struct dwarf_block *blk;
9602 case DW_FORM_ref_addr:
9603 if (cu->header.version == 2)
9604 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9606 DW_ADDR (attr) = read_offset (abfd, info_ptr,
9607 &cu->header, &bytes_read);
9608 info_ptr += bytes_read;
9611 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9612 info_ptr += bytes_read;
9614 case DW_FORM_block2:
9615 blk = dwarf_alloc_block (cu);
9616 blk->size = read_2_bytes (abfd, info_ptr);
9618 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9619 info_ptr += blk->size;
9620 DW_BLOCK (attr) = blk;
9622 case DW_FORM_block4:
9623 blk = dwarf_alloc_block (cu);
9624 blk->size = read_4_bytes (abfd, info_ptr);
9626 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9627 info_ptr += blk->size;
9628 DW_BLOCK (attr) = blk;
9631 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9635 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9639 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9642 case DW_FORM_sec_offset:
9643 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9644 info_ptr += bytes_read;
9646 case DW_FORM_string:
9647 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9648 DW_STRING_IS_CANONICAL (attr) = 0;
9649 info_ptr += bytes_read;
9652 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9654 DW_STRING_IS_CANONICAL (attr) = 0;
9655 info_ptr += bytes_read;
9657 case DW_FORM_exprloc:
9659 blk = dwarf_alloc_block (cu);
9660 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9661 info_ptr += bytes_read;
9662 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9663 info_ptr += blk->size;
9664 DW_BLOCK (attr) = blk;
9666 case DW_FORM_block1:
9667 blk = dwarf_alloc_block (cu);
9668 blk->size = read_1_byte (abfd, info_ptr);
9670 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9671 info_ptr += blk->size;
9672 DW_BLOCK (attr) = blk;
9675 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9679 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9682 case DW_FORM_flag_present:
9683 DW_UNSND (attr) = 1;
9686 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9687 info_ptr += bytes_read;
9690 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9691 info_ptr += bytes_read;
9694 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9698 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9702 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9706 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9709 case DW_FORM_ref_sig8:
9710 /* Convert the signature to something we can record in DW_UNSND
9712 NOTE: This is NULL if the type wasn't found. */
9713 DW_SIGNATURED_TYPE (attr) =
9714 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9717 case DW_FORM_ref_udata:
9718 DW_ADDR (attr) = (cu->header.offset
9719 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9720 info_ptr += bytes_read;
9722 case DW_FORM_indirect:
9723 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9724 info_ptr += bytes_read;
9725 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9728 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9729 dwarf_form_name (form),
9730 bfd_get_filename (abfd));
9733 /* We have seen instances where the compiler tried to emit a byte
9734 size attribute of -1 which ended up being encoded as an unsigned
9735 0xffffffff. Although 0xffffffff is technically a valid size value,
9736 an object of this size seems pretty unlikely so we can relatively
9737 safely treat these cases as if the size attribute was invalid and
9738 treat them as zero by default. */
9739 if (attr->name == DW_AT_byte_size
9740 && form == DW_FORM_data4
9741 && DW_UNSND (attr) >= 0xffffffff)
9744 (&symfile_complaints,
9745 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9746 hex_string (DW_UNSND (attr)));
9747 DW_UNSND (attr) = 0;
9753 /* Read an attribute described by an abbreviated attribute. */
9756 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
9757 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
9759 attr->name = abbrev->name;
9760 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
9763 /* Read dwarf information from a buffer. */
9766 read_1_byte (bfd *abfd, gdb_byte *buf)
9768 return bfd_get_8 (abfd, buf);
9772 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
9774 return bfd_get_signed_8 (abfd, buf);
9778 read_2_bytes (bfd *abfd, gdb_byte *buf)
9780 return bfd_get_16 (abfd, buf);
9784 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
9786 return bfd_get_signed_16 (abfd, buf);
9790 read_4_bytes (bfd *abfd, gdb_byte *buf)
9792 return bfd_get_32 (abfd, buf);
9796 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
9798 return bfd_get_signed_32 (abfd, buf);
9802 read_8_bytes (bfd *abfd, gdb_byte *buf)
9804 return bfd_get_64 (abfd, buf);
9808 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
9809 unsigned int *bytes_read)
9811 struct comp_unit_head *cu_header = &cu->header;
9812 CORE_ADDR retval = 0;
9814 if (cu_header->signed_addr_p)
9816 switch (cu_header->addr_size)
9819 retval = bfd_get_signed_16 (abfd, buf);
9822 retval = bfd_get_signed_32 (abfd, buf);
9825 retval = bfd_get_signed_64 (abfd, buf);
9828 internal_error (__FILE__, __LINE__,
9829 _("read_address: bad switch, signed [in module %s]"),
9830 bfd_get_filename (abfd));
9835 switch (cu_header->addr_size)
9838 retval = bfd_get_16 (abfd, buf);
9841 retval = bfd_get_32 (abfd, buf);
9844 retval = bfd_get_64 (abfd, buf);
9847 internal_error (__FILE__, __LINE__,
9848 _("read_address: bad switch, "
9849 "unsigned [in module %s]"),
9850 bfd_get_filename (abfd));
9854 *bytes_read = cu_header->addr_size;
9858 /* Read the initial length from a section. The (draft) DWARF 3
9859 specification allows the initial length to take up either 4 bytes
9860 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9861 bytes describe the length and all offsets will be 8 bytes in length
9864 An older, non-standard 64-bit format is also handled by this
9865 function. The older format in question stores the initial length
9866 as an 8-byte quantity without an escape value. Lengths greater
9867 than 2^32 aren't very common which means that the initial 4 bytes
9868 is almost always zero. Since a length value of zero doesn't make
9869 sense for the 32-bit format, this initial zero can be considered to
9870 be an escape value which indicates the presence of the older 64-bit
9871 format. As written, the code can't detect (old format) lengths
9872 greater than 4GB. If it becomes necessary to handle lengths
9873 somewhat larger than 4GB, we could allow other small values (such
9874 as the non-sensical values of 1, 2, and 3) to also be used as
9875 escape values indicating the presence of the old format.
9877 The value returned via bytes_read should be used to increment the
9878 relevant pointer after calling read_initial_length().
9880 [ Note: read_initial_length() and read_offset() are based on the
9881 document entitled "DWARF Debugging Information Format", revision
9882 3, draft 8, dated November 19, 2001. This document was obtained
9885 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9887 This document is only a draft and is subject to change. (So beware.)
9889 Details regarding the older, non-standard 64-bit format were
9890 determined empirically by examining 64-bit ELF files produced by
9891 the SGI toolchain on an IRIX 6.5 machine.
9893 - Kevin, July 16, 2002
9897 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
9899 LONGEST length = bfd_get_32 (abfd, buf);
9901 if (length == 0xffffffff)
9903 length = bfd_get_64 (abfd, buf + 4);
9906 else if (length == 0)
9908 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9909 length = bfd_get_64 (abfd, buf);
9920 /* Cover function for read_initial_length.
9921 Returns the length of the object at BUF, and stores the size of the
9922 initial length in *BYTES_READ and stores the size that offsets will be in
9924 If the initial length size is not equivalent to that specified in
9925 CU_HEADER then issue a complaint.
9926 This is useful when reading non-comp-unit headers. */
9929 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
9930 const struct comp_unit_head *cu_header,
9931 unsigned int *bytes_read,
9932 unsigned int *offset_size)
9934 LONGEST length = read_initial_length (abfd, buf, bytes_read);
9936 gdb_assert (cu_header->initial_length_size == 4
9937 || cu_header->initial_length_size == 8
9938 || cu_header->initial_length_size == 12);
9940 if (cu_header->initial_length_size != *bytes_read)
9941 complaint (&symfile_complaints,
9942 _("intermixed 32-bit and 64-bit DWARF sections"));
9944 *offset_size = (*bytes_read == 4) ? 4 : 8;
9948 /* Read an offset from the data stream. The size of the offset is
9949 given by cu_header->offset_size. */
9952 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
9953 unsigned int *bytes_read)
9955 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
9957 *bytes_read = cu_header->offset_size;
9961 /* Read an offset from the data stream. */
9964 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
9968 switch (offset_size)
9971 retval = bfd_get_32 (abfd, buf);
9974 retval = bfd_get_64 (abfd, buf);
9977 internal_error (__FILE__, __LINE__,
9978 _("read_offset_1: bad switch [in module %s]"),
9979 bfd_get_filename (abfd));
9986 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
9988 /* If the size of a host char is 8 bits, we can return a pointer
9989 to the buffer, otherwise we have to copy the data to a buffer
9990 allocated on the temporary obstack. */
9991 gdb_assert (HOST_CHAR_BIT == 8);
9996 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9998 /* If the size of a host char is 8 bits, we can return a pointer
9999 to the string, otherwise we have to copy the string to a buffer
10000 allocated on the temporary obstack. */
10001 gdb_assert (HOST_CHAR_BIT == 8);
10004 *bytes_read_ptr = 1;
10007 *bytes_read_ptr = strlen ((char *) buf) + 1;
10008 return (char *) buf;
10012 read_indirect_string (bfd *abfd, gdb_byte *buf,
10013 const struct comp_unit_head *cu_header,
10014 unsigned int *bytes_read_ptr)
10016 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10018 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10019 if (dwarf2_per_objfile->str.buffer == NULL)
10021 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10022 bfd_get_filename (abfd));
10025 if (str_offset >= dwarf2_per_objfile->str.size)
10027 error (_("DW_FORM_strp pointing outside of "
10028 ".debug_str section [in module %s]"),
10029 bfd_get_filename (abfd));
10032 gdb_assert (HOST_CHAR_BIT == 8);
10033 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10035 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10038 static unsigned long
10039 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10041 unsigned long result;
10042 unsigned int num_read;
10044 unsigned char byte;
10052 byte = bfd_get_8 (abfd, buf);
10055 result |= ((unsigned long)(byte & 127) << shift);
10056 if ((byte & 128) == 0)
10062 *bytes_read_ptr = num_read;
10067 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10070 int i, shift, num_read;
10071 unsigned char byte;
10079 byte = bfd_get_8 (abfd, buf);
10082 result |= ((long)(byte & 127) << shift);
10084 if ((byte & 128) == 0)
10089 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10090 result |= -(((long)1) << shift);
10091 *bytes_read_ptr = num_read;
10095 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10098 skip_leb128 (bfd *abfd, gdb_byte *buf)
10104 byte = bfd_get_8 (abfd, buf);
10106 if ((byte & 128) == 0)
10112 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10119 cu->language = language_c;
10121 case DW_LANG_C_plus_plus:
10122 cu->language = language_cplus;
10125 cu->language = language_d;
10127 case DW_LANG_Fortran77:
10128 case DW_LANG_Fortran90:
10129 case DW_LANG_Fortran95:
10130 cu->language = language_fortran;
10132 case DW_LANG_Mips_Assembler:
10133 cu->language = language_asm;
10136 cu->language = language_java;
10138 case DW_LANG_Ada83:
10139 case DW_LANG_Ada95:
10140 cu->language = language_ada;
10142 case DW_LANG_Modula2:
10143 cu->language = language_m2;
10145 case DW_LANG_Pascal83:
10146 cu->language = language_pascal;
10149 cu->language = language_objc;
10151 case DW_LANG_Cobol74:
10152 case DW_LANG_Cobol85:
10154 cu->language = language_minimal;
10157 cu->language_defn = language_def (cu->language);
10160 /* Return the named attribute or NULL if not there. */
10162 static struct attribute *
10163 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10166 struct attribute *spec = NULL;
10168 for (i = 0; i < die->num_attrs; ++i)
10170 if (die->attrs[i].name == name)
10171 return &die->attrs[i];
10172 if (die->attrs[i].name == DW_AT_specification
10173 || die->attrs[i].name == DW_AT_abstract_origin)
10174 spec = &die->attrs[i];
10179 die = follow_die_ref (die, spec, &cu);
10180 return dwarf2_attr (die, name, cu);
10186 /* Return the named attribute or NULL if not there,
10187 but do not follow DW_AT_specification, etc.
10188 This is for use in contexts where we're reading .debug_types dies.
10189 Following DW_AT_specification, DW_AT_abstract_origin will take us
10190 back up the chain, and we want to go down. */
10192 static struct attribute *
10193 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10194 struct dwarf2_cu *cu)
10198 for (i = 0; i < die->num_attrs; ++i)
10199 if (die->attrs[i].name == name)
10200 return &die->attrs[i];
10205 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10206 and holds a non-zero value. This function should only be used for
10207 DW_FORM_flag or DW_FORM_flag_present attributes. */
10210 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10212 struct attribute *attr = dwarf2_attr (die, name, cu);
10214 return (attr && DW_UNSND (attr));
10218 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10220 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10221 which value is non-zero. However, we have to be careful with
10222 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10223 (via dwarf2_flag_true_p) follows this attribute. So we may
10224 end up accidently finding a declaration attribute that belongs
10225 to a different DIE referenced by the specification attribute,
10226 even though the given DIE does not have a declaration attribute. */
10227 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10228 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10231 /* Return the die giving the specification for DIE, if there is
10232 one. *SPEC_CU is the CU containing DIE on input, and the CU
10233 containing the return value on output. If there is no
10234 specification, but there is an abstract origin, that is
10237 static struct die_info *
10238 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10240 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10243 if (spec_attr == NULL)
10244 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10246 if (spec_attr == NULL)
10249 return follow_die_ref (die, spec_attr, spec_cu);
10252 /* Free the line_header structure *LH, and any arrays and strings it
10254 NOTE: This is also used as a "cleanup" function. */
10257 free_line_header (struct line_header *lh)
10259 if (lh->standard_opcode_lengths)
10260 xfree (lh->standard_opcode_lengths);
10262 /* Remember that all the lh->file_names[i].name pointers are
10263 pointers into debug_line_buffer, and don't need to be freed. */
10264 if (lh->file_names)
10265 xfree (lh->file_names);
10267 /* Similarly for the include directory names. */
10268 if (lh->include_dirs)
10269 xfree (lh->include_dirs);
10274 /* Add an entry to LH's include directory table. */
10277 add_include_dir (struct line_header *lh, char *include_dir)
10279 /* Grow the array if necessary. */
10280 if (lh->include_dirs_size == 0)
10282 lh->include_dirs_size = 1; /* for testing */
10283 lh->include_dirs = xmalloc (lh->include_dirs_size
10284 * sizeof (*lh->include_dirs));
10286 else if (lh->num_include_dirs >= lh->include_dirs_size)
10288 lh->include_dirs_size *= 2;
10289 lh->include_dirs = xrealloc (lh->include_dirs,
10290 (lh->include_dirs_size
10291 * sizeof (*lh->include_dirs)));
10294 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10297 /* Add an entry to LH's file name table. */
10300 add_file_name (struct line_header *lh,
10302 unsigned int dir_index,
10303 unsigned int mod_time,
10304 unsigned int length)
10306 struct file_entry *fe;
10308 /* Grow the array if necessary. */
10309 if (lh->file_names_size == 0)
10311 lh->file_names_size = 1; /* for testing */
10312 lh->file_names = xmalloc (lh->file_names_size
10313 * sizeof (*lh->file_names));
10315 else if (lh->num_file_names >= lh->file_names_size)
10317 lh->file_names_size *= 2;
10318 lh->file_names = xrealloc (lh->file_names,
10319 (lh->file_names_size
10320 * sizeof (*lh->file_names)));
10323 fe = &lh->file_names[lh->num_file_names++];
10325 fe->dir_index = dir_index;
10326 fe->mod_time = mod_time;
10327 fe->length = length;
10328 fe->included_p = 0;
10332 /* Read the statement program header starting at OFFSET in
10333 .debug_line, according to the endianness of ABFD. Return a pointer
10334 to a struct line_header, allocated using xmalloc.
10336 NOTE: the strings in the include directory and file name tables of
10337 the returned object point into debug_line_buffer, and must not be
10340 static struct line_header *
10341 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10342 struct dwarf2_cu *cu)
10344 struct cleanup *back_to;
10345 struct line_header *lh;
10346 gdb_byte *line_ptr;
10347 unsigned int bytes_read, offset_size;
10349 char *cur_dir, *cur_file;
10351 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10352 if (dwarf2_per_objfile->line.buffer == NULL)
10354 complaint (&symfile_complaints, _("missing .debug_line section"));
10358 /* Make sure that at least there's room for the total_length field.
10359 That could be 12 bytes long, but we're just going to fudge that. */
10360 if (offset + 4 >= dwarf2_per_objfile->line.size)
10362 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10366 lh = xmalloc (sizeof (*lh));
10367 memset (lh, 0, sizeof (*lh));
10368 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10371 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10373 /* Read in the header. */
10375 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10376 &bytes_read, &offset_size);
10377 line_ptr += bytes_read;
10378 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10379 + dwarf2_per_objfile->line.size))
10381 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10384 lh->statement_program_end = line_ptr + lh->total_length;
10385 lh->version = read_2_bytes (abfd, line_ptr);
10387 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10388 line_ptr += offset_size;
10389 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10391 if (lh->version >= 4)
10393 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10397 lh->maximum_ops_per_instruction = 1;
10399 if (lh->maximum_ops_per_instruction == 0)
10401 lh->maximum_ops_per_instruction = 1;
10402 complaint (&symfile_complaints,
10403 _("invalid maximum_ops_per_instruction "
10404 "in `.debug_line' section"));
10407 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10409 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10411 lh->line_range = read_1_byte (abfd, line_ptr);
10413 lh->opcode_base = read_1_byte (abfd, line_ptr);
10415 lh->standard_opcode_lengths
10416 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10418 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10419 for (i = 1; i < lh->opcode_base; ++i)
10421 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10425 /* Read directory table. */
10426 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10428 line_ptr += bytes_read;
10429 add_include_dir (lh, cur_dir);
10431 line_ptr += bytes_read;
10433 /* Read file name table. */
10434 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10436 unsigned int dir_index, mod_time, length;
10438 line_ptr += bytes_read;
10439 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10440 line_ptr += bytes_read;
10441 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10442 line_ptr += bytes_read;
10443 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10444 line_ptr += bytes_read;
10446 add_file_name (lh, cur_file, dir_index, mod_time, length);
10448 line_ptr += bytes_read;
10449 lh->statement_program_start = line_ptr;
10451 if (line_ptr > (dwarf2_per_objfile->line.buffer
10452 + dwarf2_per_objfile->line.size))
10453 complaint (&symfile_complaints,
10454 _("line number info header doesn't "
10455 "fit in `.debug_line' section"));
10457 discard_cleanups (back_to);
10461 /* This function exists to work around a bug in certain compilers
10462 (particularly GCC 2.95), in which the first line number marker of a
10463 function does not show up until after the prologue, right before
10464 the second line number marker. This function shifts ADDRESS down
10465 to the beginning of the function if necessary, and is called on
10466 addresses passed to record_line. */
10469 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
10471 struct function_range *fn;
10473 /* Find the function_range containing address. */
10477 if (!cu->cached_fn)
10478 cu->cached_fn = cu->first_fn;
10480 fn = cu->cached_fn;
10482 if (fn->lowpc <= address && fn->highpc > address)
10488 while (fn && fn != cu->cached_fn)
10489 if (fn->lowpc <= address && fn->highpc > address)
10499 if (address != fn->lowpc)
10500 complaint (&symfile_complaints,
10501 _("misplaced first line number at 0x%lx for '%s'"),
10502 (unsigned long) address, fn->name);
10507 /* Subroutine of dwarf_decode_lines to simplify it.
10508 Return the file name of the psymtab for included file FILE_INDEX
10509 in line header LH of PST.
10510 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10511 If space for the result is malloc'd, it will be freed by a cleanup.
10512 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10515 psymtab_include_file_name (const struct line_header *lh, int file_index,
10516 const struct partial_symtab *pst,
10517 const char *comp_dir)
10519 const struct file_entry fe = lh->file_names [file_index];
10520 char *include_name = fe.name;
10521 char *include_name_to_compare = include_name;
10522 char *dir_name = NULL;
10523 const char *pst_filename;
10524 char *copied_name = NULL;
10528 dir_name = lh->include_dirs[fe.dir_index - 1];
10530 if (!IS_ABSOLUTE_PATH (include_name)
10531 && (dir_name != NULL || comp_dir != NULL))
10533 /* Avoid creating a duplicate psymtab for PST.
10534 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10535 Before we do the comparison, however, we need to account
10536 for DIR_NAME and COMP_DIR.
10537 First prepend dir_name (if non-NULL). If we still don't
10538 have an absolute path prepend comp_dir (if non-NULL).
10539 However, the directory we record in the include-file's
10540 psymtab does not contain COMP_DIR (to match the
10541 corresponding symtab(s)).
10546 bash$ gcc -g ./hello.c
10547 include_name = "hello.c"
10549 DW_AT_comp_dir = comp_dir = "/tmp"
10550 DW_AT_name = "./hello.c" */
10552 if (dir_name != NULL)
10554 include_name = concat (dir_name, SLASH_STRING,
10555 include_name, (char *)NULL);
10556 include_name_to_compare = include_name;
10557 make_cleanup (xfree, include_name);
10559 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
10561 include_name_to_compare = concat (comp_dir, SLASH_STRING,
10562 include_name, (char *)NULL);
10566 pst_filename = pst->filename;
10567 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
10569 copied_name = concat (pst->dirname, SLASH_STRING,
10570 pst_filename, (char *)NULL);
10571 pst_filename = copied_name;
10574 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
10576 if (include_name_to_compare != include_name)
10577 xfree (include_name_to_compare);
10578 if (copied_name != NULL)
10579 xfree (copied_name);
10583 return include_name;
10586 /* Ignore this record_line request. */
10589 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
10594 /* Decode the Line Number Program (LNP) for the given line_header
10595 structure and CU. The actual information extracted and the type
10596 of structures created from the LNP depends on the value of PST.
10598 1. If PST is NULL, then this procedure uses the data from the program
10599 to create all necessary symbol tables, and their linetables.
10601 2. If PST is not NULL, this procedure reads the program to determine
10602 the list of files included by the unit represented by PST, and
10603 builds all the associated partial symbol tables.
10605 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10606 It is used for relative paths in the line table.
10607 NOTE: When processing partial symtabs (pst != NULL),
10608 comp_dir == pst->dirname.
10610 NOTE: It is important that psymtabs have the same file name (via strcmp)
10611 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10612 symtab we don't use it in the name of the psymtabs we create.
10613 E.g. expand_line_sal requires this when finding psymtabs to expand.
10614 A good testcase for this is mb-inline.exp. */
10617 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
10618 struct dwarf2_cu *cu, struct partial_symtab *pst)
10620 gdb_byte *line_ptr, *extended_end;
10621 gdb_byte *line_end;
10622 unsigned int bytes_read, extended_len;
10623 unsigned char op_code, extended_op, adj_opcode;
10624 CORE_ADDR baseaddr;
10625 struct objfile *objfile = cu->objfile;
10626 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10627 const int decode_for_pst_p = (pst != NULL);
10628 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10629 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
10632 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10634 line_ptr = lh->statement_program_start;
10635 line_end = lh->statement_program_end;
10637 /* Read the statement sequences until there's nothing left. */
10638 while (line_ptr < line_end)
10640 /* state machine registers */
10641 CORE_ADDR address = 0;
10642 unsigned int file = 1;
10643 unsigned int line = 1;
10644 unsigned int column = 0;
10645 int is_stmt = lh->default_is_stmt;
10646 int basic_block = 0;
10647 int end_sequence = 0;
10649 unsigned char op_index = 0;
10651 if (!decode_for_pst_p && lh->num_file_names >= file)
10653 /* Start a subfile for the current file of the state machine. */
10654 /* lh->include_dirs and lh->file_names are 0-based, but the
10655 directory and file name numbers in the statement program
10657 struct file_entry *fe = &lh->file_names[file - 1];
10661 dir = lh->include_dirs[fe->dir_index - 1];
10663 dwarf2_start_subfile (fe->name, dir, comp_dir);
10666 /* Decode the table. */
10667 while (!end_sequence)
10669 op_code = read_1_byte (abfd, line_ptr);
10671 if (line_ptr > line_end)
10673 dwarf2_debug_line_missing_end_sequence_complaint ();
10677 if (op_code >= lh->opcode_base)
10679 /* Special operand. */
10680 adj_opcode = op_code - lh->opcode_base;
10681 address += (((op_index + (adj_opcode / lh->line_range))
10682 / lh->maximum_ops_per_instruction)
10683 * lh->minimum_instruction_length);
10684 op_index = ((op_index + (adj_opcode / lh->line_range))
10685 % lh->maximum_ops_per_instruction);
10686 line += lh->line_base + (adj_opcode % lh->line_range);
10687 if (lh->num_file_names < file || file == 0)
10688 dwarf2_debug_line_missing_file_complaint ();
10689 /* For now we ignore lines not starting on an
10690 instruction boundary. */
10691 else if (op_index == 0)
10693 lh->file_names[file - 1].included_p = 1;
10694 if (!decode_for_pst_p && is_stmt)
10696 if (last_subfile != current_subfile)
10698 addr = gdbarch_addr_bits_remove (gdbarch, address);
10700 (*p_record_line) (last_subfile, 0, addr);
10701 last_subfile = current_subfile;
10703 /* Append row to matrix using current values. */
10704 addr = check_cu_functions (address, cu);
10705 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10706 (*p_record_line) (current_subfile, line, addr);
10711 else switch (op_code)
10713 case DW_LNS_extended_op:
10714 extended_len = read_unsigned_leb128 (abfd, line_ptr,
10716 line_ptr += bytes_read;
10717 extended_end = line_ptr + extended_len;
10718 extended_op = read_1_byte (abfd, line_ptr);
10720 switch (extended_op)
10722 case DW_LNE_end_sequence:
10723 p_record_line = record_line;
10726 case DW_LNE_set_address:
10727 address = read_address (abfd, line_ptr, cu, &bytes_read);
10729 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
10731 /* This line table is for a function which has been
10732 GCd by the linker. Ignore it. PR gdb/12528 */
10735 = line_ptr - dwarf2_per_objfile->line.buffer;
10737 complaint (&symfile_complaints,
10738 _(".debug_line address at offset 0x%lx is 0 "
10740 line_offset, cu->objfile->name);
10741 p_record_line = noop_record_line;
10745 line_ptr += bytes_read;
10746 address += baseaddr;
10748 case DW_LNE_define_file:
10751 unsigned int dir_index, mod_time, length;
10753 cur_file = read_direct_string (abfd, line_ptr,
10755 line_ptr += bytes_read;
10757 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10758 line_ptr += bytes_read;
10760 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10761 line_ptr += bytes_read;
10763 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10764 line_ptr += bytes_read;
10765 add_file_name (lh, cur_file, dir_index, mod_time, length);
10768 case DW_LNE_set_discriminator:
10769 /* The discriminator is not interesting to the debugger;
10771 line_ptr = extended_end;
10774 complaint (&symfile_complaints,
10775 _("mangled .debug_line section"));
10778 /* Make sure that we parsed the extended op correctly. If e.g.
10779 we expected a different address size than the producer used,
10780 we may have read the wrong number of bytes. */
10781 if (line_ptr != extended_end)
10783 complaint (&symfile_complaints,
10784 _("mangled .debug_line section"));
10789 if (lh->num_file_names < file || file == 0)
10790 dwarf2_debug_line_missing_file_complaint ();
10793 lh->file_names[file - 1].included_p = 1;
10794 if (!decode_for_pst_p && is_stmt)
10796 if (last_subfile != current_subfile)
10798 addr = gdbarch_addr_bits_remove (gdbarch, address);
10800 (*p_record_line) (last_subfile, 0, addr);
10801 last_subfile = current_subfile;
10803 addr = check_cu_functions (address, cu);
10804 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10805 (*p_record_line) (current_subfile, line, addr);
10810 case DW_LNS_advance_pc:
10813 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10815 address += (((op_index + adjust)
10816 / lh->maximum_ops_per_instruction)
10817 * lh->minimum_instruction_length);
10818 op_index = ((op_index + adjust)
10819 % lh->maximum_ops_per_instruction);
10820 line_ptr += bytes_read;
10823 case DW_LNS_advance_line:
10824 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
10825 line_ptr += bytes_read;
10827 case DW_LNS_set_file:
10829 /* The arrays lh->include_dirs and lh->file_names are
10830 0-based, but the directory and file name numbers in
10831 the statement program are 1-based. */
10832 struct file_entry *fe;
10835 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10836 line_ptr += bytes_read;
10837 if (lh->num_file_names < file || file == 0)
10838 dwarf2_debug_line_missing_file_complaint ();
10841 fe = &lh->file_names[file - 1];
10843 dir = lh->include_dirs[fe->dir_index - 1];
10844 if (!decode_for_pst_p)
10846 last_subfile = current_subfile;
10847 dwarf2_start_subfile (fe->name, dir, comp_dir);
10852 case DW_LNS_set_column:
10853 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10854 line_ptr += bytes_read;
10856 case DW_LNS_negate_stmt:
10857 is_stmt = (!is_stmt);
10859 case DW_LNS_set_basic_block:
10862 /* Add to the address register of the state machine the
10863 address increment value corresponding to special opcode
10864 255. I.e., this value is scaled by the minimum
10865 instruction length since special opcode 255 would have
10866 scaled the increment. */
10867 case DW_LNS_const_add_pc:
10869 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
10871 address += (((op_index + adjust)
10872 / lh->maximum_ops_per_instruction)
10873 * lh->minimum_instruction_length);
10874 op_index = ((op_index + adjust)
10875 % lh->maximum_ops_per_instruction);
10878 case DW_LNS_fixed_advance_pc:
10879 address += read_2_bytes (abfd, line_ptr);
10885 /* Unknown standard opcode, ignore it. */
10888 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
10890 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10891 line_ptr += bytes_read;
10896 if (lh->num_file_names < file || file == 0)
10897 dwarf2_debug_line_missing_file_complaint ();
10900 lh->file_names[file - 1].included_p = 1;
10901 if (!decode_for_pst_p)
10903 addr = gdbarch_addr_bits_remove (gdbarch, address);
10904 (*p_record_line) (current_subfile, 0, addr);
10909 if (decode_for_pst_p)
10913 /* Now that we're done scanning the Line Header Program, we can
10914 create the psymtab of each included file. */
10915 for (file_index = 0; file_index < lh->num_file_names; file_index++)
10916 if (lh->file_names[file_index].included_p == 1)
10918 char *include_name =
10919 psymtab_include_file_name (lh, file_index, pst, comp_dir);
10920 if (include_name != NULL)
10921 dwarf2_create_include_psymtab (include_name, pst, objfile);
10926 /* Make sure a symtab is created for every file, even files
10927 which contain only variables (i.e. no code with associated
10931 struct file_entry *fe;
10933 for (i = 0; i < lh->num_file_names; i++)
10937 fe = &lh->file_names[i];
10939 dir = lh->include_dirs[fe->dir_index - 1];
10940 dwarf2_start_subfile (fe->name, dir, comp_dir);
10942 /* Skip the main file; we don't need it, and it must be
10943 allocated last, so that it will show up before the
10944 non-primary symtabs in the objfile's symtab list. */
10945 if (current_subfile == first_subfile)
10948 if (current_subfile->symtab == NULL)
10949 current_subfile->symtab = allocate_symtab (current_subfile->name,
10951 fe->symtab = current_subfile->symtab;
10956 /* Start a subfile for DWARF. FILENAME is the name of the file and
10957 DIRNAME the name of the source directory which contains FILENAME
10958 or NULL if not known. COMP_DIR is the compilation directory for the
10959 linetable's compilation unit or NULL if not known.
10960 This routine tries to keep line numbers from identical absolute and
10961 relative file names in a common subfile.
10963 Using the `list' example from the GDB testsuite, which resides in
10964 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10965 of /srcdir/list0.c yields the following debugging information for list0.c:
10967 DW_AT_name: /srcdir/list0.c
10968 DW_AT_comp_dir: /compdir
10969 files.files[0].name: list0.h
10970 files.files[0].dir: /srcdir
10971 files.files[1].name: list0.c
10972 files.files[1].dir: /srcdir
10974 The line number information for list0.c has to end up in a single
10975 subfile, so that `break /srcdir/list0.c:1' works as expected.
10976 start_subfile will ensure that this happens provided that we pass the
10977 concatenation of files.files[1].dir and files.files[1].name as the
10981 dwarf2_start_subfile (char *filename, const char *dirname,
10982 const char *comp_dir)
10986 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10987 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10988 second argument to start_subfile. To be consistent, we do the
10989 same here. In order not to lose the line information directory,
10990 we concatenate it to the filename when it makes sense.
10991 Note that the Dwarf3 standard says (speaking of filenames in line
10992 information): ``The directory index is ignored for file names
10993 that represent full path names''. Thus ignoring dirname in the
10994 `else' branch below isn't an issue. */
10996 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
10997 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
10999 fullname = filename;
11001 start_subfile (fullname, comp_dir);
11003 if (fullname != filename)
11008 var_decode_location (struct attribute *attr, struct symbol *sym,
11009 struct dwarf2_cu *cu)
11011 struct objfile *objfile = cu->objfile;
11012 struct comp_unit_head *cu_header = &cu->header;
11014 /* NOTE drow/2003-01-30: There used to be a comment and some special
11015 code here to turn a symbol with DW_AT_external and a
11016 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11017 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11018 with some versions of binutils) where shared libraries could have
11019 relocations against symbols in their debug information - the
11020 minimal symbol would have the right address, but the debug info
11021 would not. It's no longer necessary, because we will explicitly
11022 apply relocations when we read in the debug information now. */
11024 /* A DW_AT_location attribute with no contents indicates that a
11025 variable has been optimized away. */
11026 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11028 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11032 /* Handle one degenerate form of location expression specially, to
11033 preserve GDB's previous behavior when section offsets are
11034 specified. If this is just a DW_OP_addr then mark this symbol
11037 if (attr_form_is_block (attr)
11038 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11039 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11041 unsigned int dummy;
11043 SYMBOL_VALUE_ADDRESS (sym) =
11044 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11045 SYMBOL_CLASS (sym) = LOC_STATIC;
11046 fixup_symbol_section (sym, objfile);
11047 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11048 SYMBOL_SECTION (sym));
11052 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11053 expression evaluator, and use LOC_COMPUTED only when necessary
11054 (i.e. when the value of a register or memory location is
11055 referenced, or a thread-local block, etc.). Then again, it might
11056 not be worthwhile. I'm assuming that it isn't unless performance
11057 or memory numbers show me otherwise. */
11059 dwarf2_symbol_mark_computed (attr, sym, cu);
11060 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11062 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11063 cu->has_loclist = 1;
11066 /* Given a pointer to a DWARF information entry, figure out if we need
11067 to make a symbol table entry for it, and if so, create a new entry
11068 and return a pointer to it.
11069 If TYPE is NULL, determine symbol type from the die, otherwise
11070 used the passed type.
11071 If SPACE is not NULL, use it to hold the new symbol. If it is
11072 NULL, allocate a new symbol on the objfile's obstack. */
11074 static struct symbol *
11075 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11076 struct symbol *space)
11078 struct objfile *objfile = cu->objfile;
11079 struct symbol *sym = NULL;
11081 struct attribute *attr = NULL;
11082 struct attribute *attr2 = NULL;
11083 CORE_ADDR baseaddr;
11084 struct pending **list_to_add = NULL;
11086 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11088 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11090 name = dwarf2_name (die, cu);
11093 const char *linkagename;
11094 int suppress_add = 0;
11099 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11100 OBJSTAT (objfile, n_syms++);
11102 /* Cache this symbol's name and the name's demangled form (if any). */
11103 SYMBOL_SET_LANGUAGE (sym, cu->language);
11104 linkagename = dwarf2_physname (name, die, cu);
11105 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11107 /* Fortran does not have mangling standard and the mangling does differ
11108 between gfortran, iFort etc. */
11109 if (cu->language == language_fortran
11110 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11111 symbol_set_demangled_name (&(sym->ginfo),
11112 (char *) dwarf2_full_name (name, die, cu),
11115 /* Default assumptions.
11116 Use the passed type or decode it from the die. */
11117 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11118 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11120 SYMBOL_TYPE (sym) = type;
11122 SYMBOL_TYPE (sym) = die_type (die, cu);
11123 attr = dwarf2_attr (die,
11124 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11128 SYMBOL_LINE (sym) = DW_UNSND (attr);
11131 attr = dwarf2_attr (die,
11132 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11136 int file_index = DW_UNSND (attr);
11138 if (cu->line_header == NULL
11139 || file_index > cu->line_header->num_file_names)
11140 complaint (&symfile_complaints,
11141 _("file index out of range"));
11142 else if (file_index > 0)
11144 struct file_entry *fe;
11146 fe = &cu->line_header->file_names[file_index - 1];
11147 SYMBOL_SYMTAB (sym) = fe->symtab;
11154 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11157 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11159 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11160 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11161 SYMBOL_CLASS (sym) = LOC_LABEL;
11162 add_symbol_to_list (sym, cu->list_in_scope);
11164 case DW_TAG_subprogram:
11165 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11167 SYMBOL_CLASS (sym) = LOC_BLOCK;
11168 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11169 if ((attr2 && (DW_UNSND (attr2) != 0))
11170 || cu->language == language_ada)
11172 /* Subprograms marked external are stored as a global symbol.
11173 Ada subprograms, whether marked external or not, are always
11174 stored as a global symbol, because we want to be able to
11175 access them globally. For instance, we want to be able
11176 to break on a nested subprogram without having to
11177 specify the context. */
11178 list_to_add = &global_symbols;
11182 list_to_add = cu->list_in_scope;
11185 case DW_TAG_inlined_subroutine:
11186 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11188 SYMBOL_CLASS (sym) = LOC_BLOCK;
11189 SYMBOL_INLINED (sym) = 1;
11190 /* Do not add the symbol to any lists. It will be found via
11191 BLOCK_FUNCTION from the blockvector. */
11193 case DW_TAG_template_value_param:
11195 /* Fall through. */
11196 case DW_TAG_constant:
11197 case DW_TAG_variable:
11198 case DW_TAG_member:
11199 /* Compilation with minimal debug info may result in
11200 variables with missing type entries. Change the
11201 misleading `void' type to something sensible. */
11202 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11204 = objfile_type (objfile)->nodebug_data_symbol;
11206 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11207 /* In the case of DW_TAG_member, we should only be called for
11208 static const members. */
11209 if (die->tag == DW_TAG_member)
11211 /* dwarf2_add_field uses die_is_declaration,
11212 so we do the same. */
11213 gdb_assert (die_is_declaration (die, cu));
11218 dwarf2_const_value (attr, sym, cu);
11219 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11222 if (attr2 && (DW_UNSND (attr2) != 0))
11223 list_to_add = &global_symbols;
11225 list_to_add = cu->list_in_scope;
11229 attr = dwarf2_attr (die, DW_AT_location, cu);
11232 var_decode_location (attr, sym, cu);
11233 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11234 if (SYMBOL_CLASS (sym) == LOC_STATIC
11235 && SYMBOL_VALUE_ADDRESS (sym) == 0
11236 && !dwarf2_per_objfile->has_section_at_zero)
11238 /* When a static variable is eliminated by the linker,
11239 the corresponding debug information is not stripped
11240 out, but the variable address is set to null;
11241 do not add such variables into symbol table. */
11243 else if (attr2 && (DW_UNSND (attr2) != 0))
11245 /* Workaround gfortran PR debug/40040 - it uses
11246 DW_AT_location for variables in -fPIC libraries which may
11247 get overriden by other libraries/executable and get
11248 a different address. Resolve it by the minimal symbol
11249 which may come from inferior's executable using copy
11250 relocation. Make this workaround only for gfortran as for
11251 other compilers GDB cannot guess the minimal symbol
11252 Fortran mangling kind. */
11253 if (cu->language == language_fortran && die->parent
11254 && die->parent->tag == DW_TAG_module
11256 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11257 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11259 /* A variable with DW_AT_external is never static,
11260 but it may be block-scoped. */
11261 list_to_add = (cu->list_in_scope == &file_symbols
11262 ? &global_symbols : cu->list_in_scope);
11265 list_to_add = cu->list_in_scope;
11269 /* We do not know the address of this symbol.
11270 If it is an external symbol and we have type information
11271 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11272 The address of the variable will then be determined from
11273 the minimal symbol table whenever the variable is
11275 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11276 if (attr2 && (DW_UNSND (attr2) != 0)
11277 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11279 /* A variable with DW_AT_external is never static, but it
11280 may be block-scoped. */
11281 list_to_add = (cu->list_in_scope == &file_symbols
11282 ? &global_symbols : cu->list_in_scope);
11284 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11286 else if (!die_is_declaration (die, cu))
11288 /* Use the default LOC_OPTIMIZED_OUT class. */
11289 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11291 list_to_add = cu->list_in_scope;
11295 case DW_TAG_formal_parameter:
11296 /* If we are inside a function, mark this as an argument. If
11297 not, we might be looking at an argument to an inlined function
11298 when we do not have enough information to show inlined frames;
11299 pretend it's a local variable in that case so that the user can
11301 if (context_stack_depth > 0
11302 && context_stack[context_stack_depth - 1].name != NULL)
11303 SYMBOL_IS_ARGUMENT (sym) = 1;
11304 attr = dwarf2_attr (die, DW_AT_location, cu);
11307 var_decode_location (attr, sym, cu);
11309 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11312 dwarf2_const_value (attr, sym, cu);
11314 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
11315 if (attr && DW_UNSND (attr))
11317 struct type *ref_type;
11319 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
11320 SYMBOL_TYPE (sym) = ref_type;
11323 list_to_add = cu->list_in_scope;
11325 case DW_TAG_unspecified_parameters:
11326 /* From varargs functions; gdb doesn't seem to have any
11327 interest in this information, so just ignore it for now.
11330 case DW_TAG_template_type_param:
11332 /* Fall through. */
11333 case DW_TAG_class_type:
11334 case DW_TAG_interface_type:
11335 case DW_TAG_structure_type:
11336 case DW_TAG_union_type:
11337 case DW_TAG_set_type:
11338 case DW_TAG_enumeration_type:
11339 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11340 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11343 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11344 really ever be static objects: otherwise, if you try
11345 to, say, break of a class's method and you're in a file
11346 which doesn't mention that class, it won't work unless
11347 the check for all static symbols in lookup_symbol_aux
11348 saves you. See the OtherFileClass tests in
11349 gdb.c++/namespace.exp. */
11353 list_to_add = (cu->list_in_scope == &file_symbols
11354 && (cu->language == language_cplus
11355 || cu->language == language_java)
11356 ? &global_symbols : cu->list_in_scope);
11358 /* The semantics of C++ state that "struct foo {
11359 ... }" also defines a typedef for "foo". A Java
11360 class declaration also defines a typedef for the
11362 if (cu->language == language_cplus
11363 || cu->language == language_java
11364 || cu->language == language_ada)
11366 /* The symbol's name is already allocated along
11367 with this objfile, so we don't need to
11368 duplicate it for the type. */
11369 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11370 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11375 case DW_TAG_typedef:
11376 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11377 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11378 list_to_add = cu->list_in_scope;
11380 case DW_TAG_base_type:
11381 case DW_TAG_subrange_type:
11382 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11383 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11384 list_to_add = cu->list_in_scope;
11386 case DW_TAG_enumerator:
11387 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11390 dwarf2_const_value (attr, sym, cu);
11393 /* NOTE: carlton/2003-11-10: See comment above in the
11394 DW_TAG_class_type, etc. block. */
11396 list_to_add = (cu->list_in_scope == &file_symbols
11397 && (cu->language == language_cplus
11398 || cu->language == language_java)
11399 ? &global_symbols : cu->list_in_scope);
11402 case DW_TAG_namespace:
11403 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11404 list_to_add = &global_symbols;
11407 /* Not a tag we recognize. Hopefully we aren't processing
11408 trash data, but since we must specifically ignore things
11409 we don't recognize, there is nothing else we should do at
11411 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11412 dwarf_tag_name (die->tag));
11418 sym->hash_next = objfile->template_symbols;
11419 objfile->template_symbols = sym;
11420 list_to_add = NULL;
11423 if (list_to_add != NULL)
11424 add_symbol_to_list (sym, list_to_add);
11426 /* For the benefit of old versions of GCC, check for anonymous
11427 namespaces based on the demangled name. */
11428 if (!processing_has_namespace_info
11429 && cu->language == language_cplus)
11430 cp_scan_for_anonymous_namespaces (sym);
11435 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11437 static struct symbol *
11438 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11440 return new_symbol_full (die, type, cu, NULL);
11443 /* Given an attr with a DW_FORM_dataN value in host byte order,
11444 zero-extend it as appropriate for the symbol's type. The DWARF
11445 standard (v4) is not entirely clear about the meaning of using
11446 DW_FORM_dataN for a constant with a signed type, where the type is
11447 wider than the data. The conclusion of a discussion on the DWARF
11448 list was that this is unspecified. We choose to always zero-extend
11449 because that is the interpretation long in use by GCC. */
11452 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11453 const char *name, struct obstack *obstack,
11454 struct dwarf2_cu *cu, long *value, int bits)
11456 struct objfile *objfile = cu->objfile;
11457 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11458 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11459 LONGEST l = DW_UNSND (attr);
11461 if (bits < sizeof (*value) * 8)
11463 l &= ((LONGEST) 1 << bits) - 1;
11466 else if (bits == sizeof (*value) * 8)
11470 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11471 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11478 /* Read a constant value from an attribute. Either set *VALUE, or if
11479 the value does not fit in *VALUE, set *BYTES - either already
11480 allocated on the objfile obstack, or newly allocated on OBSTACK,
11481 or, set *BATON, if we translated the constant to a location
11485 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11486 const char *name, struct obstack *obstack,
11487 struct dwarf2_cu *cu,
11488 long *value, gdb_byte **bytes,
11489 struct dwarf2_locexpr_baton **baton)
11491 struct objfile *objfile = cu->objfile;
11492 struct comp_unit_head *cu_header = &cu->header;
11493 struct dwarf_block *blk;
11494 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11495 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11501 switch (attr->form)
11507 if (TYPE_LENGTH (type) != cu_header->addr_size)
11508 dwarf2_const_value_length_mismatch_complaint (name,
11509 cu_header->addr_size,
11510 TYPE_LENGTH (type));
11511 /* Symbols of this form are reasonably rare, so we just
11512 piggyback on the existing location code rather than writing
11513 a new implementation of symbol_computed_ops. */
11514 *baton = obstack_alloc (&objfile->objfile_obstack,
11515 sizeof (struct dwarf2_locexpr_baton));
11516 (*baton)->per_cu = cu->per_cu;
11517 gdb_assert ((*baton)->per_cu);
11519 (*baton)->size = 2 + cu_header->addr_size;
11520 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11521 (*baton)->data = data;
11523 data[0] = DW_OP_addr;
11524 store_unsigned_integer (&data[1], cu_header->addr_size,
11525 byte_order, DW_ADDR (attr));
11526 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11529 case DW_FORM_string:
11531 /* DW_STRING is already allocated on the objfile obstack, point
11533 *bytes = (gdb_byte *) DW_STRING (attr);
11535 case DW_FORM_block1:
11536 case DW_FORM_block2:
11537 case DW_FORM_block4:
11538 case DW_FORM_block:
11539 case DW_FORM_exprloc:
11540 blk = DW_BLOCK (attr);
11541 if (TYPE_LENGTH (type) != blk->size)
11542 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11543 TYPE_LENGTH (type));
11544 *bytes = blk->data;
11547 /* The DW_AT_const_value attributes are supposed to carry the
11548 symbol's value "represented as it would be on the target
11549 architecture." By the time we get here, it's already been
11550 converted to host endianness, so we just need to sign- or
11551 zero-extend it as appropriate. */
11552 case DW_FORM_data1:
11553 *bytes = dwarf2_const_value_data (attr, type, name,
11554 obstack, cu, value, 8);
11556 case DW_FORM_data2:
11557 *bytes = dwarf2_const_value_data (attr, type, name,
11558 obstack, cu, value, 16);
11560 case DW_FORM_data4:
11561 *bytes = dwarf2_const_value_data (attr, type, name,
11562 obstack, cu, value, 32);
11564 case DW_FORM_data8:
11565 *bytes = dwarf2_const_value_data (attr, type, name,
11566 obstack, cu, value, 64);
11569 case DW_FORM_sdata:
11570 *value = DW_SND (attr);
11573 case DW_FORM_udata:
11574 *value = DW_UNSND (attr);
11578 complaint (&symfile_complaints,
11579 _("unsupported const value attribute form: '%s'"),
11580 dwarf_form_name (attr->form));
11587 /* Copy constant value from an attribute to a symbol. */
11590 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
11591 struct dwarf2_cu *cu)
11593 struct objfile *objfile = cu->objfile;
11594 struct comp_unit_head *cu_header = &cu->header;
11597 struct dwarf2_locexpr_baton *baton;
11599 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
11600 SYMBOL_PRINT_NAME (sym),
11601 &objfile->objfile_obstack, cu,
11602 &value, &bytes, &baton);
11606 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11607 SYMBOL_LOCATION_BATON (sym) = baton;
11608 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11610 else if (bytes != NULL)
11612 SYMBOL_VALUE_BYTES (sym) = bytes;
11613 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
11617 SYMBOL_VALUE (sym) = value;
11618 SYMBOL_CLASS (sym) = LOC_CONST;
11622 /* Return the type of the die in question using its DW_AT_type attribute. */
11624 static struct type *
11625 die_type (struct die_info *die, struct dwarf2_cu *cu)
11627 struct attribute *type_attr;
11629 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11632 /* A missing DW_AT_type represents a void type. */
11633 return objfile_type (cu->objfile)->builtin_void;
11636 return lookup_die_type (die, type_attr, cu);
11639 /* True iff CU's producer generates GNAT Ada auxiliary information
11640 that allows to find parallel types through that information instead
11641 of having to do expensive parallel lookups by type name. */
11644 need_gnat_info (struct dwarf2_cu *cu)
11646 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11647 of GNAT produces this auxiliary information, without any indication
11648 that it is produced. Part of enhancing the FSF version of GNAT
11649 to produce that information will be to put in place an indicator
11650 that we can use in order to determine whether the descriptive type
11651 info is available or not. One suggestion that has been made is
11652 to use a new attribute, attached to the CU die. For now, assume
11653 that the descriptive type info is not available. */
11657 /* Return the auxiliary type of the die in question using its
11658 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11659 attribute is not present. */
11661 static struct type *
11662 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11664 struct attribute *type_attr;
11666 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11670 return lookup_die_type (die, type_attr, cu);
11673 /* If DIE has a descriptive_type attribute, then set the TYPE's
11674 descriptive type accordingly. */
11677 set_descriptive_type (struct type *type, struct die_info *die,
11678 struct dwarf2_cu *cu)
11680 struct type *descriptive_type = die_descriptive_type (die, cu);
11682 if (descriptive_type)
11684 ALLOCATE_GNAT_AUX_TYPE (type);
11685 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11689 /* Return the containing type of the die in question using its
11690 DW_AT_containing_type attribute. */
11692 static struct type *
11693 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11695 struct attribute *type_attr;
11697 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11699 error (_("Dwarf Error: Problem turning containing type into gdb type "
11700 "[in module %s]"), cu->objfile->name);
11702 return lookup_die_type (die, type_attr, cu);
11705 /* Look up the type of DIE in CU using its type attribute ATTR.
11706 If there is no type substitute an error marker. */
11708 static struct type *
11709 lookup_die_type (struct die_info *die, struct attribute *attr,
11710 struct dwarf2_cu *cu)
11712 struct type *this_type;
11714 /* First see if we have it cached. */
11716 if (is_ref_attr (attr))
11718 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11720 this_type = get_die_type_at_offset (offset, cu->per_cu);
11722 else if (attr->form == DW_FORM_ref_sig8)
11724 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11725 struct dwarf2_cu *sig_cu;
11726 unsigned int offset;
11728 /* sig_type will be NULL if the signatured type is missing from
11730 if (sig_type == NULL)
11731 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11732 "at 0x%x [in module %s]"),
11733 die->offset, cu->objfile->name);
11735 gdb_assert (sig_type->per_cu.from_debug_types);
11736 offset = sig_type->per_cu.offset + sig_type->type_offset;
11737 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11741 dump_die_for_error (die);
11742 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11743 dwarf_attr_name (attr->name), cu->objfile->name);
11746 /* If not cached we need to read it in. */
11748 if (this_type == NULL)
11750 struct die_info *type_die;
11751 struct dwarf2_cu *type_cu = cu;
11753 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11754 /* If the type is cached, we should have found it above. */
11755 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11756 this_type = read_type_die_1 (type_die, type_cu);
11759 /* If we still don't have a type use an error marker. */
11761 if (this_type == NULL)
11763 char *message, *saved;
11765 /* read_type_die already issued a complaint. */
11766 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11770 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
11771 message, strlen (message));
11774 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
11780 /* Return the type in DIE, CU.
11781 Returns NULL for invalid types.
11783 This first does a lookup in the appropriate type_hash table,
11784 and only reads the die in if necessary.
11786 NOTE: This can be called when reading in partial or full symbols. */
11788 static struct type *
11789 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
11791 struct type *this_type;
11793 this_type = get_die_type (die, cu);
11797 return read_type_die_1 (die, cu);
11800 /* Read the type in DIE, CU.
11801 Returns NULL for invalid types. */
11803 static struct type *
11804 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11806 struct type *this_type = NULL;
11810 case DW_TAG_class_type:
11811 case DW_TAG_interface_type:
11812 case DW_TAG_structure_type:
11813 case DW_TAG_union_type:
11814 this_type = read_structure_type (die, cu);
11816 case DW_TAG_enumeration_type:
11817 this_type = read_enumeration_type (die, cu);
11819 case DW_TAG_subprogram:
11820 case DW_TAG_subroutine_type:
11821 case DW_TAG_inlined_subroutine:
11822 this_type = read_subroutine_type (die, cu);
11824 case DW_TAG_array_type:
11825 this_type = read_array_type (die, cu);
11827 case DW_TAG_set_type:
11828 this_type = read_set_type (die, cu);
11830 case DW_TAG_pointer_type:
11831 this_type = read_tag_pointer_type (die, cu);
11833 case DW_TAG_ptr_to_member_type:
11834 this_type = read_tag_ptr_to_member_type (die, cu);
11836 case DW_TAG_reference_type:
11837 this_type = read_tag_reference_type (die, cu);
11839 case DW_TAG_const_type:
11840 this_type = read_tag_const_type (die, cu);
11842 case DW_TAG_volatile_type:
11843 this_type = read_tag_volatile_type (die, cu);
11845 case DW_TAG_string_type:
11846 this_type = read_tag_string_type (die, cu);
11848 case DW_TAG_typedef:
11849 this_type = read_typedef (die, cu);
11851 case DW_TAG_subrange_type:
11852 this_type = read_subrange_type (die, cu);
11854 case DW_TAG_base_type:
11855 this_type = read_base_type (die, cu);
11857 case DW_TAG_unspecified_type:
11858 this_type = read_unspecified_type (die, cu);
11860 case DW_TAG_namespace:
11861 this_type = read_namespace_type (die, cu);
11863 case DW_TAG_module:
11864 this_type = read_module_type (die, cu);
11867 complaint (&symfile_complaints,
11868 _("unexpected tag in read_type_die: '%s'"),
11869 dwarf_tag_name (die->tag));
11876 /* See if we can figure out if the class lives in a namespace. We do
11877 this by looking for a member function; its demangled name will
11878 contain namespace info, if there is any.
11879 Return the computed name or NULL.
11880 Space for the result is allocated on the objfile's obstack.
11881 This is the full-die version of guess_partial_die_structure_name.
11882 In this case we know DIE has no useful parent. */
11885 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
11887 struct die_info *spec_die;
11888 struct dwarf2_cu *spec_cu;
11889 struct die_info *child;
11892 spec_die = die_specification (die, &spec_cu);
11893 if (spec_die != NULL)
11899 for (child = die->child;
11901 child = child->sibling)
11903 if (child->tag == DW_TAG_subprogram)
11905 struct attribute *attr;
11907 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
11909 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
11913 = language_class_name_from_physname (cu->language_defn,
11917 if (actual_name != NULL)
11919 char *die_name = dwarf2_name (die, cu);
11921 if (die_name != NULL
11922 && strcmp (die_name, actual_name) != 0)
11924 /* Strip off the class name from the full name.
11925 We want the prefix. */
11926 int die_name_len = strlen (die_name);
11927 int actual_name_len = strlen (actual_name);
11929 /* Test for '::' as a sanity check. */
11930 if (actual_name_len > die_name_len + 2
11931 && actual_name[actual_name_len
11932 - die_name_len - 1] == ':')
11934 obsavestring (actual_name,
11935 actual_name_len - die_name_len - 2,
11936 &cu->objfile->objfile_obstack);
11939 xfree (actual_name);
11948 /* Return the name of the namespace/class that DIE is defined within,
11949 or "" if we can't tell. The caller should not xfree the result.
11951 For example, if we're within the method foo() in the following
11961 then determine_prefix on foo's die will return "N::C". */
11964 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
11966 struct die_info *parent, *spec_die;
11967 struct dwarf2_cu *spec_cu;
11968 struct type *parent_type;
11970 if (cu->language != language_cplus && cu->language != language_java
11971 && cu->language != language_fortran)
11974 /* We have to be careful in the presence of DW_AT_specification.
11975 For example, with GCC 3.4, given the code
11979 // Definition of N::foo.
11983 then we'll have a tree of DIEs like this:
11985 1: DW_TAG_compile_unit
11986 2: DW_TAG_namespace // N
11987 3: DW_TAG_subprogram // declaration of N::foo
11988 4: DW_TAG_subprogram // definition of N::foo
11989 DW_AT_specification // refers to die #3
11991 Thus, when processing die #4, we have to pretend that we're in
11992 the context of its DW_AT_specification, namely the contex of die
11995 spec_die = die_specification (die, &spec_cu);
11996 if (spec_die == NULL)
11997 parent = die->parent;
12000 parent = spec_die->parent;
12004 if (parent == NULL)
12006 else if (parent->building_fullname)
12009 const char *parent_name;
12011 /* It has been seen on RealView 2.2 built binaries,
12012 DW_TAG_template_type_param types actually _defined_ as
12013 children of the parent class:
12016 template class <class Enum> Class{};
12017 Class<enum E> class_e;
12019 1: DW_TAG_class_type (Class)
12020 2: DW_TAG_enumeration_type (E)
12021 3: DW_TAG_enumerator (enum1:0)
12022 3: DW_TAG_enumerator (enum2:1)
12024 2: DW_TAG_template_type_param
12025 DW_AT_type DW_FORM_ref_udata (E)
12027 Besides being broken debug info, it can put GDB into an
12028 infinite loop. Consider:
12030 When we're building the full name for Class<E>, we'll start
12031 at Class, and go look over its template type parameters,
12032 finding E. We'll then try to build the full name of E, and
12033 reach here. We're now trying to build the full name of E,
12034 and look over the parent DIE for containing scope. In the
12035 broken case, if we followed the parent DIE of E, we'd again
12036 find Class, and once again go look at its template type
12037 arguments, etc., etc. Simply don't consider such parent die
12038 as source-level parent of this die (it can't be, the language
12039 doesn't allow it), and break the loop here. */
12040 name = dwarf2_name (die, cu);
12041 parent_name = dwarf2_name (parent, cu);
12042 complaint (&symfile_complaints,
12043 _("template param type '%s' defined within parent '%s'"),
12044 name ? name : "<unknown>",
12045 parent_name ? parent_name : "<unknown>");
12049 switch (parent->tag)
12051 case DW_TAG_namespace:
12052 parent_type = read_type_die (parent, cu);
12053 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12054 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12055 Work around this problem here. */
12056 if (cu->language == language_cplus
12057 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12059 /* We give a name to even anonymous namespaces. */
12060 return TYPE_TAG_NAME (parent_type);
12061 case DW_TAG_class_type:
12062 case DW_TAG_interface_type:
12063 case DW_TAG_structure_type:
12064 case DW_TAG_union_type:
12065 case DW_TAG_module:
12066 parent_type = read_type_die (parent, cu);
12067 if (TYPE_TAG_NAME (parent_type) != NULL)
12068 return TYPE_TAG_NAME (parent_type);
12070 /* An anonymous structure is only allowed non-static data
12071 members; no typedefs, no member functions, et cetera.
12072 So it does not need a prefix. */
12074 case DW_TAG_compile_unit:
12075 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12076 if (cu->language == language_cplus
12077 && dwarf2_per_objfile->types.asection != NULL
12078 && die->child != NULL
12079 && (die->tag == DW_TAG_class_type
12080 || die->tag == DW_TAG_structure_type
12081 || die->tag == DW_TAG_union_type))
12083 char *name = guess_full_die_structure_name (die, cu);
12089 return determine_prefix (parent, cu);
12093 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12094 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12095 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12096 an obconcat, otherwise allocate storage for the result. The CU argument is
12097 used to determine the language and hence, the appropriate separator. */
12099 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12102 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12103 int physname, struct dwarf2_cu *cu)
12105 const char *lead = "";
12108 if (suffix == NULL || suffix[0] == '\0'
12109 || prefix == NULL || prefix[0] == '\0')
12111 else if (cu->language == language_java)
12113 else if (cu->language == language_fortran && physname)
12115 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12116 DW_AT_MIPS_linkage_name is preferred and used instead. */
12124 if (prefix == NULL)
12126 if (suffix == NULL)
12132 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12134 strcpy (retval, lead);
12135 strcat (retval, prefix);
12136 strcat (retval, sep);
12137 strcat (retval, suffix);
12142 /* We have an obstack. */
12143 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12147 /* Return sibling of die, NULL if no sibling. */
12149 static struct die_info *
12150 sibling_die (struct die_info *die)
12152 return die->sibling;
12155 /* Get name of a die, return NULL if not found. */
12158 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12159 struct obstack *obstack)
12161 if (name && cu->language == language_cplus)
12163 char *canon_name = cp_canonicalize_string (name);
12165 if (canon_name != NULL)
12167 if (strcmp (canon_name, name) != 0)
12168 name = obsavestring (canon_name, strlen (canon_name),
12170 xfree (canon_name);
12177 /* Get name of a die, return NULL if not found. */
12180 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12182 struct attribute *attr;
12184 attr = dwarf2_attr (die, DW_AT_name, cu);
12185 if ((!attr || !DW_STRING (attr))
12186 && die->tag != DW_TAG_class_type
12187 && die->tag != DW_TAG_interface_type
12188 && die->tag != DW_TAG_structure_type
12189 && die->tag != DW_TAG_union_type)
12194 case DW_TAG_compile_unit:
12195 /* Compilation units have a DW_AT_name that is a filename, not
12196 a source language identifier. */
12197 case DW_TAG_enumeration_type:
12198 case DW_TAG_enumerator:
12199 /* These tags always have simple identifiers already; no need
12200 to canonicalize them. */
12201 return DW_STRING (attr);
12203 case DW_TAG_subprogram:
12204 /* Java constructors will all be named "<init>", so return
12205 the class name when we see this special case. */
12206 if (cu->language == language_java
12207 && DW_STRING (attr) != NULL
12208 && strcmp (DW_STRING (attr), "<init>") == 0)
12210 struct dwarf2_cu *spec_cu = cu;
12211 struct die_info *spec_die;
12213 /* GCJ will output '<init>' for Java constructor names.
12214 For this special case, return the name of the parent class. */
12216 /* GCJ may output suprogram DIEs with AT_specification set.
12217 If so, use the name of the specified DIE. */
12218 spec_die = die_specification (die, &spec_cu);
12219 if (spec_die != NULL)
12220 return dwarf2_name (spec_die, spec_cu);
12225 if (die->tag == DW_TAG_class_type)
12226 return dwarf2_name (die, cu);
12228 while (die->tag != DW_TAG_compile_unit);
12232 case DW_TAG_class_type:
12233 case DW_TAG_interface_type:
12234 case DW_TAG_structure_type:
12235 case DW_TAG_union_type:
12236 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12237 structures or unions. These were of the form "._%d" in GCC 4.1,
12238 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12239 and GCC 4.4. We work around this problem by ignoring these. */
12240 if (attr && DW_STRING (attr)
12241 && (strncmp (DW_STRING (attr), "._", 2) == 0
12242 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12245 /* GCC might emit a nameless typedef that has a linkage name. See
12246 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12247 if (!attr || DW_STRING (attr) == NULL)
12249 char *demangled = NULL;
12251 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12253 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12255 if (attr == NULL || DW_STRING (attr) == NULL)
12258 /* Avoid demangling DW_STRING (attr) the second time on a second
12259 call for the same DIE. */
12260 if (!DW_STRING_IS_CANONICAL (attr))
12261 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12265 /* FIXME: we already did this for the partial symbol... */
12267 = obsavestring (demangled, strlen (demangled),
12268 &cu->objfile->objfile_obstack);
12269 DW_STRING_IS_CANONICAL (attr) = 1;
12279 if (!DW_STRING_IS_CANONICAL (attr))
12282 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12283 &cu->objfile->objfile_obstack);
12284 DW_STRING_IS_CANONICAL (attr) = 1;
12286 return DW_STRING (attr);
12289 /* Return the die that this die in an extension of, or NULL if there
12290 is none. *EXT_CU is the CU containing DIE on input, and the CU
12291 containing the return value on output. */
12293 static struct die_info *
12294 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12296 struct attribute *attr;
12298 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12302 return follow_die_ref (die, attr, ext_cu);
12305 /* Convert a DIE tag into its string name. */
12308 dwarf_tag_name (unsigned tag)
12312 case DW_TAG_padding:
12313 return "DW_TAG_padding";
12314 case DW_TAG_array_type:
12315 return "DW_TAG_array_type";
12316 case DW_TAG_class_type:
12317 return "DW_TAG_class_type";
12318 case DW_TAG_entry_point:
12319 return "DW_TAG_entry_point";
12320 case DW_TAG_enumeration_type:
12321 return "DW_TAG_enumeration_type";
12322 case DW_TAG_formal_parameter:
12323 return "DW_TAG_formal_parameter";
12324 case DW_TAG_imported_declaration:
12325 return "DW_TAG_imported_declaration";
12327 return "DW_TAG_label";
12328 case DW_TAG_lexical_block:
12329 return "DW_TAG_lexical_block";
12330 case DW_TAG_member:
12331 return "DW_TAG_member";
12332 case DW_TAG_pointer_type:
12333 return "DW_TAG_pointer_type";
12334 case DW_TAG_reference_type:
12335 return "DW_TAG_reference_type";
12336 case DW_TAG_compile_unit:
12337 return "DW_TAG_compile_unit";
12338 case DW_TAG_string_type:
12339 return "DW_TAG_string_type";
12340 case DW_TAG_structure_type:
12341 return "DW_TAG_structure_type";
12342 case DW_TAG_subroutine_type:
12343 return "DW_TAG_subroutine_type";
12344 case DW_TAG_typedef:
12345 return "DW_TAG_typedef";
12346 case DW_TAG_union_type:
12347 return "DW_TAG_union_type";
12348 case DW_TAG_unspecified_parameters:
12349 return "DW_TAG_unspecified_parameters";
12350 case DW_TAG_variant:
12351 return "DW_TAG_variant";
12352 case DW_TAG_common_block:
12353 return "DW_TAG_common_block";
12354 case DW_TAG_common_inclusion:
12355 return "DW_TAG_common_inclusion";
12356 case DW_TAG_inheritance:
12357 return "DW_TAG_inheritance";
12358 case DW_TAG_inlined_subroutine:
12359 return "DW_TAG_inlined_subroutine";
12360 case DW_TAG_module:
12361 return "DW_TAG_module";
12362 case DW_TAG_ptr_to_member_type:
12363 return "DW_TAG_ptr_to_member_type";
12364 case DW_TAG_set_type:
12365 return "DW_TAG_set_type";
12366 case DW_TAG_subrange_type:
12367 return "DW_TAG_subrange_type";
12368 case DW_TAG_with_stmt:
12369 return "DW_TAG_with_stmt";
12370 case DW_TAG_access_declaration:
12371 return "DW_TAG_access_declaration";
12372 case DW_TAG_base_type:
12373 return "DW_TAG_base_type";
12374 case DW_TAG_catch_block:
12375 return "DW_TAG_catch_block";
12376 case DW_TAG_const_type:
12377 return "DW_TAG_const_type";
12378 case DW_TAG_constant:
12379 return "DW_TAG_constant";
12380 case DW_TAG_enumerator:
12381 return "DW_TAG_enumerator";
12382 case DW_TAG_file_type:
12383 return "DW_TAG_file_type";
12384 case DW_TAG_friend:
12385 return "DW_TAG_friend";
12386 case DW_TAG_namelist:
12387 return "DW_TAG_namelist";
12388 case DW_TAG_namelist_item:
12389 return "DW_TAG_namelist_item";
12390 case DW_TAG_packed_type:
12391 return "DW_TAG_packed_type";
12392 case DW_TAG_subprogram:
12393 return "DW_TAG_subprogram";
12394 case DW_TAG_template_type_param:
12395 return "DW_TAG_template_type_param";
12396 case DW_TAG_template_value_param:
12397 return "DW_TAG_template_value_param";
12398 case DW_TAG_thrown_type:
12399 return "DW_TAG_thrown_type";
12400 case DW_TAG_try_block:
12401 return "DW_TAG_try_block";
12402 case DW_TAG_variant_part:
12403 return "DW_TAG_variant_part";
12404 case DW_TAG_variable:
12405 return "DW_TAG_variable";
12406 case DW_TAG_volatile_type:
12407 return "DW_TAG_volatile_type";
12408 case DW_TAG_dwarf_procedure:
12409 return "DW_TAG_dwarf_procedure";
12410 case DW_TAG_restrict_type:
12411 return "DW_TAG_restrict_type";
12412 case DW_TAG_interface_type:
12413 return "DW_TAG_interface_type";
12414 case DW_TAG_namespace:
12415 return "DW_TAG_namespace";
12416 case DW_TAG_imported_module:
12417 return "DW_TAG_imported_module";
12418 case DW_TAG_unspecified_type:
12419 return "DW_TAG_unspecified_type";
12420 case DW_TAG_partial_unit:
12421 return "DW_TAG_partial_unit";
12422 case DW_TAG_imported_unit:
12423 return "DW_TAG_imported_unit";
12424 case DW_TAG_condition:
12425 return "DW_TAG_condition";
12426 case DW_TAG_shared_type:
12427 return "DW_TAG_shared_type";
12428 case DW_TAG_type_unit:
12429 return "DW_TAG_type_unit";
12430 case DW_TAG_MIPS_loop:
12431 return "DW_TAG_MIPS_loop";
12432 case DW_TAG_HP_array_descriptor:
12433 return "DW_TAG_HP_array_descriptor";
12434 case DW_TAG_format_label:
12435 return "DW_TAG_format_label";
12436 case DW_TAG_function_template:
12437 return "DW_TAG_function_template";
12438 case DW_TAG_class_template:
12439 return "DW_TAG_class_template";
12440 case DW_TAG_GNU_BINCL:
12441 return "DW_TAG_GNU_BINCL";
12442 case DW_TAG_GNU_EINCL:
12443 return "DW_TAG_GNU_EINCL";
12444 case DW_TAG_upc_shared_type:
12445 return "DW_TAG_upc_shared_type";
12446 case DW_TAG_upc_strict_type:
12447 return "DW_TAG_upc_strict_type";
12448 case DW_TAG_upc_relaxed_type:
12449 return "DW_TAG_upc_relaxed_type";
12450 case DW_TAG_PGI_kanji_type:
12451 return "DW_TAG_PGI_kanji_type";
12452 case DW_TAG_PGI_interface_block:
12453 return "DW_TAG_PGI_interface_block";
12455 return "DW_TAG_<unknown>";
12459 /* Convert a DWARF attribute code into its string name. */
12462 dwarf_attr_name (unsigned attr)
12466 case DW_AT_sibling:
12467 return "DW_AT_sibling";
12468 case DW_AT_location:
12469 return "DW_AT_location";
12471 return "DW_AT_name";
12472 case DW_AT_ordering:
12473 return "DW_AT_ordering";
12474 case DW_AT_subscr_data:
12475 return "DW_AT_subscr_data";
12476 case DW_AT_byte_size:
12477 return "DW_AT_byte_size";
12478 case DW_AT_bit_offset:
12479 return "DW_AT_bit_offset";
12480 case DW_AT_bit_size:
12481 return "DW_AT_bit_size";
12482 case DW_AT_element_list:
12483 return "DW_AT_element_list";
12484 case DW_AT_stmt_list:
12485 return "DW_AT_stmt_list";
12487 return "DW_AT_low_pc";
12488 case DW_AT_high_pc:
12489 return "DW_AT_high_pc";
12490 case DW_AT_language:
12491 return "DW_AT_language";
12493 return "DW_AT_member";
12495 return "DW_AT_discr";
12496 case DW_AT_discr_value:
12497 return "DW_AT_discr_value";
12498 case DW_AT_visibility:
12499 return "DW_AT_visibility";
12501 return "DW_AT_import";
12502 case DW_AT_string_length:
12503 return "DW_AT_string_length";
12504 case DW_AT_common_reference:
12505 return "DW_AT_common_reference";
12506 case DW_AT_comp_dir:
12507 return "DW_AT_comp_dir";
12508 case DW_AT_const_value:
12509 return "DW_AT_const_value";
12510 case DW_AT_containing_type:
12511 return "DW_AT_containing_type";
12512 case DW_AT_default_value:
12513 return "DW_AT_default_value";
12515 return "DW_AT_inline";
12516 case DW_AT_is_optional:
12517 return "DW_AT_is_optional";
12518 case DW_AT_lower_bound:
12519 return "DW_AT_lower_bound";
12520 case DW_AT_producer:
12521 return "DW_AT_producer";
12522 case DW_AT_prototyped:
12523 return "DW_AT_prototyped";
12524 case DW_AT_return_addr:
12525 return "DW_AT_return_addr";
12526 case DW_AT_start_scope:
12527 return "DW_AT_start_scope";
12528 case DW_AT_bit_stride:
12529 return "DW_AT_bit_stride";
12530 case DW_AT_upper_bound:
12531 return "DW_AT_upper_bound";
12532 case DW_AT_abstract_origin:
12533 return "DW_AT_abstract_origin";
12534 case DW_AT_accessibility:
12535 return "DW_AT_accessibility";
12536 case DW_AT_address_class:
12537 return "DW_AT_address_class";
12538 case DW_AT_artificial:
12539 return "DW_AT_artificial";
12540 case DW_AT_base_types:
12541 return "DW_AT_base_types";
12542 case DW_AT_calling_convention:
12543 return "DW_AT_calling_convention";
12545 return "DW_AT_count";
12546 case DW_AT_data_member_location:
12547 return "DW_AT_data_member_location";
12548 case DW_AT_decl_column:
12549 return "DW_AT_decl_column";
12550 case DW_AT_decl_file:
12551 return "DW_AT_decl_file";
12552 case DW_AT_decl_line:
12553 return "DW_AT_decl_line";
12554 case DW_AT_declaration:
12555 return "DW_AT_declaration";
12556 case DW_AT_discr_list:
12557 return "DW_AT_discr_list";
12558 case DW_AT_encoding:
12559 return "DW_AT_encoding";
12560 case DW_AT_external:
12561 return "DW_AT_external";
12562 case DW_AT_frame_base:
12563 return "DW_AT_frame_base";
12565 return "DW_AT_friend";
12566 case DW_AT_identifier_case:
12567 return "DW_AT_identifier_case";
12568 case DW_AT_macro_info:
12569 return "DW_AT_macro_info";
12570 case DW_AT_namelist_items:
12571 return "DW_AT_namelist_items";
12572 case DW_AT_priority:
12573 return "DW_AT_priority";
12574 case DW_AT_segment:
12575 return "DW_AT_segment";
12576 case DW_AT_specification:
12577 return "DW_AT_specification";
12578 case DW_AT_static_link:
12579 return "DW_AT_static_link";
12581 return "DW_AT_type";
12582 case DW_AT_use_location:
12583 return "DW_AT_use_location";
12584 case DW_AT_variable_parameter:
12585 return "DW_AT_variable_parameter";
12586 case DW_AT_virtuality:
12587 return "DW_AT_virtuality";
12588 case DW_AT_vtable_elem_location:
12589 return "DW_AT_vtable_elem_location";
12590 /* DWARF 3 values. */
12591 case DW_AT_allocated:
12592 return "DW_AT_allocated";
12593 case DW_AT_associated:
12594 return "DW_AT_associated";
12595 case DW_AT_data_location:
12596 return "DW_AT_data_location";
12597 case DW_AT_byte_stride:
12598 return "DW_AT_byte_stride";
12599 case DW_AT_entry_pc:
12600 return "DW_AT_entry_pc";
12601 case DW_AT_use_UTF8:
12602 return "DW_AT_use_UTF8";
12603 case DW_AT_extension:
12604 return "DW_AT_extension";
12606 return "DW_AT_ranges";
12607 case DW_AT_trampoline:
12608 return "DW_AT_trampoline";
12609 case DW_AT_call_column:
12610 return "DW_AT_call_column";
12611 case DW_AT_call_file:
12612 return "DW_AT_call_file";
12613 case DW_AT_call_line:
12614 return "DW_AT_call_line";
12615 case DW_AT_description:
12616 return "DW_AT_description";
12617 case DW_AT_binary_scale:
12618 return "DW_AT_binary_scale";
12619 case DW_AT_decimal_scale:
12620 return "DW_AT_decimal_scale";
12622 return "DW_AT_small";
12623 case DW_AT_decimal_sign:
12624 return "DW_AT_decimal_sign";
12625 case DW_AT_digit_count:
12626 return "DW_AT_digit_count";
12627 case DW_AT_picture_string:
12628 return "DW_AT_picture_string";
12629 case DW_AT_mutable:
12630 return "DW_AT_mutable";
12631 case DW_AT_threads_scaled:
12632 return "DW_AT_threads_scaled";
12633 case DW_AT_explicit:
12634 return "DW_AT_explicit";
12635 case DW_AT_object_pointer:
12636 return "DW_AT_object_pointer";
12637 case DW_AT_endianity:
12638 return "DW_AT_endianity";
12639 case DW_AT_elemental:
12640 return "DW_AT_elemental";
12642 return "DW_AT_pure";
12643 case DW_AT_recursive:
12644 return "DW_AT_recursive";
12645 /* DWARF 4 values. */
12646 case DW_AT_signature:
12647 return "DW_AT_signature";
12648 case DW_AT_linkage_name:
12649 return "DW_AT_linkage_name";
12650 /* SGI/MIPS extensions. */
12651 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12652 case DW_AT_MIPS_fde:
12653 return "DW_AT_MIPS_fde";
12655 case DW_AT_MIPS_loop_begin:
12656 return "DW_AT_MIPS_loop_begin";
12657 case DW_AT_MIPS_tail_loop_begin:
12658 return "DW_AT_MIPS_tail_loop_begin";
12659 case DW_AT_MIPS_epilog_begin:
12660 return "DW_AT_MIPS_epilog_begin";
12661 case DW_AT_MIPS_loop_unroll_factor:
12662 return "DW_AT_MIPS_loop_unroll_factor";
12663 case DW_AT_MIPS_software_pipeline_depth:
12664 return "DW_AT_MIPS_software_pipeline_depth";
12665 case DW_AT_MIPS_linkage_name:
12666 return "DW_AT_MIPS_linkage_name";
12667 case DW_AT_MIPS_stride:
12668 return "DW_AT_MIPS_stride";
12669 case DW_AT_MIPS_abstract_name:
12670 return "DW_AT_MIPS_abstract_name";
12671 case DW_AT_MIPS_clone_origin:
12672 return "DW_AT_MIPS_clone_origin";
12673 case DW_AT_MIPS_has_inlines:
12674 return "DW_AT_MIPS_has_inlines";
12675 /* HP extensions. */
12676 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12677 case DW_AT_HP_block_index:
12678 return "DW_AT_HP_block_index";
12680 case DW_AT_HP_unmodifiable:
12681 return "DW_AT_HP_unmodifiable";
12682 case DW_AT_HP_actuals_stmt_list:
12683 return "DW_AT_HP_actuals_stmt_list";
12684 case DW_AT_HP_proc_per_section:
12685 return "DW_AT_HP_proc_per_section";
12686 case DW_AT_HP_raw_data_ptr:
12687 return "DW_AT_HP_raw_data_ptr";
12688 case DW_AT_HP_pass_by_reference:
12689 return "DW_AT_HP_pass_by_reference";
12690 case DW_AT_HP_opt_level:
12691 return "DW_AT_HP_opt_level";
12692 case DW_AT_HP_prof_version_id:
12693 return "DW_AT_HP_prof_version_id";
12694 case DW_AT_HP_opt_flags:
12695 return "DW_AT_HP_opt_flags";
12696 case DW_AT_HP_cold_region_low_pc:
12697 return "DW_AT_HP_cold_region_low_pc";
12698 case DW_AT_HP_cold_region_high_pc:
12699 return "DW_AT_HP_cold_region_high_pc";
12700 case DW_AT_HP_all_variables_modifiable:
12701 return "DW_AT_HP_all_variables_modifiable";
12702 case DW_AT_HP_linkage_name:
12703 return "DW_AT_HP_linkage_name";
12704 case DW_AT_HP_prof_flags:
12705 return "DW_AT_HP_prof_flags";
12706 /* GNU extensions. */
12707 case DW_AT_sf_names:
12708 return "DW_AT_sf_names";
12709 case DW_AT_src_info:
12710 return "DW_AT_src_info";
12711 case DW_AT_mac_info:
12712 return "DW_AT_mac_info";
12713 case DW_AT_src_coords:
12714 return "DW_AT_src_coords";
12715 case DW_AT_body_begin:
12716 return "DW_AT_body_begin";
12717 case DW_AT_body_end:
12718 return "DW_AT_body_end";
12719 case DW_AT_GNU_vector:
12720 return "DW_AT_GNU_vector";
12721 case DW_AT_GNU_odr_signature:
12722 return "DW_AT_GNU_odr_signature";
12723 /* VMS extensions. */
12724 case DW_AT_VMS_rtnbeg_pd_address:
12725 return "DW_AT_VMS_rtnbeg_pd_address";
12726 /* UPC extension. */
12727 case DW_AT_upc_threads_scaled:
12728 return "DW_AT_upc_threads_scaled";
12729 /* PGI (STMicroelectronics) extensions. */
12730 case DW_AT_PGI_lbase:
12731 return "DW_AT_PGI_lbase";
12732 case DW_AT_PGI_soffset:
12733 return "DW_AT_PGI_soffset";
12734 case DW_AT_PGI_lstride:
12735 return "DW_AT_PGI_lstride";
12737 return "DW_AT_<unknown>";
12741 /* Convert a DWARF value form code into its string name. */
12744 dwarf_form_name (unsigned form)
12749 return "DW_FORM_addr";
12750 case DW_FORM_block2:
12751 return "DW_FORM_block2";
12752 case DW_FORM_block4:
12753 return "DW_FORM_block4";
12754 case DW_FORM_data2:
12755 return "DW_FORM_data2";
12756 case DW_FORM_data4:
12757 return "DW_FORM_data4";
12758 case DW_FORM_data8:
12759 return "DW_FORM_data8";
12760 case DW_FORM_string:
12761 return "DW_FORM_string";
12762 case DW_FORM_block:
12763 return "DW_FORM_block";
12764 case DW_FORM_block1:
12765 return "DW_FORM_block1";
12766 case DW_FORM_data1:
12767 return "DW_FORM_data1";
12769 return "DW_FORM_flag";
12770 case DW_FORM_sdata:
12771 return "DW_FORM_sdata";
12773 return "DW_FORM_strp";
12774 case DW_FORM_udata:
12775 return "DW_FORM_udata";
12776 case DW_FORM_ref_addr:
12777 return "DW_FORM_ref_addr";
12779 return "DW_FORM_ref1";
12781 return "DW_FORM_ref2";
12783 return "DW_FORM_ref4";
12785 return "DW_FORM_ref8";
12786 case DW_FORM_ref_udata:
12787 return "DW_FORM_ref_udata";
12788 case DW_FORM_indirect:
12789 return "DW_FORM_indirect";
12790 case DW_FORM_sec_offset:
12791 return "DW_FORM_sec_offset";
12792 case DW_FORM_exprloc:
12793 return "DW_FORM_exprloc";
12794 case DW_FORM_flag_present:
12795 return "DW_FORM_flag_present";
12796 case DW_FORM_ref_sig8:
12797 return "DW_FORM_ref_sig8";
12799 return "DW_FORM_<unknown>";
12803 /* Convert a DWARF stack opcode into its string name. */
12806 dwarf_stack_op_name (unsigned op)
12811 return "DW_OP_addr";
12813 return "DW_OP_deref";
12814 case DW_OP_const1u:
12815 return "DW_OP_const1u";
12816 case DW_OP_const1s:
12817 return "DW_OP_const1s";
12818 case DW_OP_const2u:
12819 return "DW_OP_const2u";
12820 case DW_OP_const2s:
12821 return "DW_OP_const2s";
12822 case DW_OP_const4u:
12823 return "DW_OP_const4u";
12824 case DW_OP_const4s:
12825 return "DW_OP_const4s";
12826 case DW_OP_const8u:
12827 return "DW_OP_const8u";
12828 case DW_OP_const8s:
12829 return "DW_OP_const8s";
12831 return "DW_OP_constu";
12833 return "DW_OP_consts";
12835 return "DW_OP_dup";
12837 return "DW_OP_drop";
12839 return "DW_OP_over";
12841 return "DW_OP_pick";
12843 return "DW_OP_swap";
12845 return "DW_OP_rot";
12847 return "DW_OP_xderef";
12849 return "DW_OP_abs";
12851 return "DW_OP_and";
12853 return "DW_OP_div";
12855 return "DW_OP_minus";
12857 return "DW_OP_mod";
12859 return "DW_OP_mul";
12861 return "DW_OP_neg";
12863 return "DW_OP_not";
12867 return "DW_OP_plus";
12868 case DW_OP_plus_uconst:
12869 return "DW_OP_plus_uconst";
12871 return "DW_OP_shl";
12873 return "DW_OP_shr";
12875 return "DW_OP_shra";
12877 return "DW_OP_xor";
12879 return "DW_OP_bra";
12893 return "DW_OP_skip";
12895 return "DW_OP_lit0";
12897 return "DW_OP_lit1";
12899 return "DW_OP_lit2";
12901 return "DW_OP_lit3";
12903 return "DW_OP_lit4";
12905 return "DW_OP_lit5";
12907 return "DW_OP_lit6";
12909 return "DW_OP_lit7";
12911 return "DW_OP_lit8";
12913 return "DW_OP_lit9";
12915 return "DW_OP_lit10";
12917 return "DW_OP_lit11";
12919 return "DW_OP_lit12";
12921 return "DW_OP_lit13";
12923 return "DW_OP_lit14";
12925 return "DW_OP_lit15";
12927 return "DW_OP_lit16";
12929 return "DW_OP_lit17";
12931 return "DW_OP_lit18";
12933 return "DW_OP_lit19";
12935 return "DW_OP_lit20";
12937 return "DW_OP_lit21";
12939 return "DW_OP_lit22";
12941 return "DW_OP_lit23";
12943 return "DW_OP_lit24";
12945 return "DW_OP_lit25";
12947 return "DW_OP_lit26";
12949 return "DW_OP_lit27";
12951 return "DW_OP_lit28";
12953 return "DW_OP_lit29";
12955 return "DW_OP_lit30";
12957 return "DW_OP_lit31";
12959 return "DW_OP_reg0";
12961 return "DW_OP_reg1";
12963 return "DW_OP_reg2";
12965 return "DW_OP_reg3";
12967 return "DW_OP_reg4";
12969 return "DW_OP_reg5";
12971 return "DW_OP_reg6";
12973 return "DW_OP_reg7";
12975 return "DW_OP_reg8";
12977 return "DW_OP_reg9";
12979 return "DW_OP_reg10";
12981 return "DW_OP_reg11";
12983 return "DW_OP_reg12";
12985 return "DW_OP_reg13";
12987 return "DW_OP_reg14";
12989 return "DW_OP_reg15";
12991 return "DW_OP_reg16";
12993 return "DW_OP_reg17";
12995 return "DW_OP_reg18";
12997 return "DW_OP_reg19";
12999 return "DW_OP_reg20";
13001 return "DW_OP_reg21";
13003 return "DW_OP_reg22";
13005 return "DW_OP_reg23";
13007 return "DW_OP_reg24";
13009 return "DW_OP_reg25";
13011 return "DW_OP_reg26";
13013 return "DW_OP_reg27";
13015 return "DW_OP_reg28";
13017 return "DW_OP_reg29";
13019 return "DW_OP_reg30";
13021 return "DW_OP_reg31";
13023 return "DW_OP_breg0";
13025 return "DW_OP_breg1";
13027 return "DW_OP_breg2";
13029 return "DW_OP_breg3";
13031 return "DW_OP_breg4";
13033 return "DW_OP_breg5";
13035 return "DW_OP_breg6";
13037 return "DW_OP_breg7";
13039 return "DW_OP_breg8";
13041 return "DW_OP_breg9";
13043 return "DW_OP_breg10";
13045 return "DW_OP_breg11";
13047 return "DW_OP_breg12";
13049 return "DW_OP_breg13";
13051 return "DW_OP_breg14";
13053 return "DW_OP_breg15";
13055 return "DW_OP_breg16";
13057 return "DW_OP_breg17";
13059 return "DW_OP_breg18";
13061 return "DW_OP_breg19";
13063 return "DW_OP_breg20";
13065 return "DW_OP_breg21";
13067 return "DW_OP_breg22";
13069 return "DW_OP_breg23";
13071 return "DW_OP_breg24";
13073 return "DW_OP_breg25";
13075 return "DW_OP_breg26";
13077 return "DW_OP_breg27";
13079 return "DW_OP_breg28";
13081 return "DW_OP_breg29";
13083 return "DW_OP_breg30";
13085 return "DW_OP_breg31";
13087 return "DW_OP_regx";
13089 return "DW_OP_fbreg";
13091 return "DW_OP_bregx";
13093 return "DW_OP_piece";
13094 case DW_OP_deref_size:
13095 return "DW_OP_deref_size";
13096 case DW_OP_xderef_size:
13097 return "DW_OP_xderef_size";
13099 return "DW_OP_nop";
13100 /* DWARF 3 extensions. */
13101 case DW_OP_push_object_address:
13102 return "DW_OP_push_object_address";
13104 return "DW_OP_call2";
13106 return "DW_OP_call4";
13107 case DW_OP_call_ref:
13108 return "DW_OP_call_ref";
13109 case DW_OP_form_tls_address:
13110 return "DW_OP_form_tls_address";
13111 case DW_OP_call_frame_cfa:
13112 return "DW_OP_call_frame_cfa";
13113 case DW_OP_bit_piece:
13114 return "DW_OP_bit_piece";
13115 /* DWARF 4 extensions. */
13116 case DW_OP_implicit_value:
13117 return "DW_OP_implicit_value";
13118 case DW_OP_stack_value:
13119 return "DW_OP_stack_value";
13120 /* GNU extensions. */
13121 case DW_OP_GNU_push_tls_address:
13122 return "DW_OP_GNU_push_tls_address";
13123 case DW_OP_GNU_uninit:
13124 return "DW_OP_GNU_uninit";
13125 case DW_OP_GNU_implicit_pointer:
13126 return "DW_OP_GNU_implicit_pointer";
13127 case DW_OP_GNU_entry_value:
13128 return "DW_OP_GNU_entry_value";
13129 case DW_OP_GNU_const_type:
13130 return "DW_OP_GNU_const_type";
13131 case DW_OP_GNU_regval_type:
13132 return "DW_OP_GNU_regval_type";
13133 case DW_OP_GNU_deref_type:
13134 return "DW_OP_GNU_deref_type";
13135 case DW_OP_GNU_convert:
13136 return "DW_OP_GNU_convert";
13137 case DW_OP_GNU_reinterpret:
13138 return "DW_OP_GNU_reinterpret";
13145 dwarf_bool_name (unsigned mybool)
13153 /* Convert a DWARF type code into its string name. */
13156 dwarf_type_encoding_name (unsigned enc)
13161 return "DW_ATE_void";
13162 case DW_ATE_address:
13163 return "DW_ATE_address";
13164 case DW_ATE_boolean:
13165 return "DW_ATE_boolean";
13166 case DW_ATE_complex_float:
13167 return "DW_ATE_complex_float";
13169 return "DW_ATE_float";
13170 case DW_ATE_signed:
13171 return "DW_ATE_signed";
13172 case DW_ATE_signed_char:
13173 return "DW_ATE_signed_char";
13174 case DW_ATE_unsigned:
13175 return "DW_ATE_unsigned";
13176 case DW_ATE_unsigned_char:
13177 return "DW_ATE_unsigned_char";
13179 case DW_ATE_imaginary_float:
13180 return "DW_ATE_imaginary_float";
13181 case DW_ATE_packed_decimal:
13182 return "DW_ATE_packed_decimal";
13183 case DW_ATE_numeric_string:
13184 return "DW_ATE_numeric_string";
13185 case DW_ATE_edited:
13186 return "DW_ATE_edited";
13187 case DW_ATE_signed_fixed:
13188 return "DW_ATE_signed_fixed";
13189 case DW_ATE_unsigned_fixed:
13190 return "DW_ATE_unsigned_fixed";
13191 case DW_ATE_decimal_float:
13192 return "DW_ATE_decimal_float";
13195 return "DW_ATE_UTF";
13196 /* HP extensions. */
13197 case DW_ATE_HP_float80:
13198 return "DW_ATE_HP_float80";
13199 case DW_ATE_HP_complex_float80:
13200 return "DW_ATE_HP_complex_float80";
13201 case DW_ATE_HP_float128:
13202 return "DW_ATE_HP_float128";
13203 case DW_ATE_HP_complex_float128:
13204 return "DW_ATE_HP_complex_float128";
13205 case DW_ATE_HP_floathpintel:
13206 return "DW_ATE_HP_floathpintel";
13207 case DW_ATE_HP_imaginary_float80:
13208 return "DW_ATE_HP_imaginary_float80";
13209 case DW_ATE_HP_imaginary_float128:
13210 return "DW_ATE_HP_imaginary_float128";
13212 return "DW_ATE_<unknown>";
13216 /* Convert a DWARF call frame info operation to its string name. */
13220 dwarf_cfi_name (unsigned cfi_opc)
13224 case DW_CFA_advance_loc:
13225 return "DW_CFA_advance_loc";
13226 case DW_CFA_offset:
13227 return "DW_CFA_offset";
13228 case DW_CFA_restore:
13229 return "DW_CFA_restore";
13231 return "DW_CFA_nop";
13232 case DW_CFA_set_loc:
13233 return "DW_CFA_set_loc";
13234 case DW_CFA_advance_loc1:
13235 return "DW_CFA_advance_loc1";
13236 case DW_CFA_advance_loc2:
13237 return "DW_CFA_advance_loc2";
13238 case DW_CFA_advance_loc4:
13239 return "DW_CFA_advance_loc4";
13240 case DW_CFA_offset_extended:
13241 return "DW_CFA_offset_extended";
13242 case DW_CFA_restore_extended:
13243 return "DW_CFA_restore_extended";
13244 case DW_CFA_undefined:
13245 return "DW_CFA_undefined";
13246 case DW_CFA_same_value:
13247 return "DW_CFA_same_value";
13248 case DW_CFA_register:
13249 return "DW_CFA_register";
13250 case DW_CFA_remember_state:
13251 return "DW_CFA_remember_state";
13252 case DW_CFA_restore_state:
13253 return "DW_CFA_restore_state";
13254 case DW_CFA_def_cfa:
13255 return "DW_CFA_def_cfa";
13256 case DW_CFA_def_cfa_register:
13257 return "DW_CFA_def_cfa_register";
13258 case DW_CFA_def_cfa_offset:
13259 return "DW_CFA_def_cfa_offset";
13261 case DW_CFA_def_cfa_expression:
13262 return "DW_CFA_def_cfa_expression";
13263 case DW_CFA_expression:
13264 return "DW_CFA_expression";
13265 case DW_CFA_offset_extended_sf:
13266 return "DW_CFA_offset_extended_sf";
13267 case DW_CFA_def_cfa_sf:
13268 return "DW_CFA_def_cfa_sf";
13269 case DW_CFA_def_cfa_offset_sf:
13270 return "DW_CFA_def_cfa_offset_sf";
13271 case DW_CFA_val_offset:
13272 return "DW_CFA_val_offset";
13273 case DW_CFA_val_offset_sf:
13274 return "DW_CFA_val_offset_sf";
13275 case DW_CFA_val_expression:
13276 return "DW_CFA_val_expression";
13277 /* SGI/MIPS specific. */
13278 case DW_CFA_MIPS_advance_loc8:
13279 return "DW_CFA_MIPS_advance_loc8";
13280 /* GNU extensions. */
13281 case DW_CFA_GNU_window_save:
13282 return "DW_CFA_GNU_window_save";
13283 case DW_CFA_GNU_args_size:
13284 return "DW_CFA_GNU_args_size";
13285 case DW_CFA_GNU_negative_offset_extended:
13286 return "DW_CFA_GNU_negative_offset_extended";
13288 return "DW_CFA_<unknown>";
13294 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13298 print_spaces (indent, f);
13299 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13300 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13302 if (die->parent != NULL)
13304 print_spaces (indent, f);
13305 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13306 die->parent->offset);
13309 print_spaces (indent, f);
13310 fprintf_unfiltered (f, " has children: %s\n",
13311 dwarf_bool_name (die->child != NULL));
13313 print_spaces (indent, f);
13314 fprintf_unfiltered (f, " attributes:\n");
13316 for (i = 0; i < die->num_attrs; ++i)
13318 print_spaces (indent, f);
13319 fprintf_unfiltered (f, " %s (%s) ",
13320 dwarf_attr_name (die->attrs[i].name),
13321 dwarf_form_name (die->attrs[i].form));
13323 switch (die->attrs[i].form)
13325 case DW_FORM_ref_addr:
13327 fprintf_unfiltered (f, "address: ");
13328 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13330 case DW_FORM_block2:
13331 case DW_FORM_block4:
13332 case DW_FORM_block:
13333 case DW_FORM_block1:
13334 fprintf_unfiltered (f, "block: size %d",
13335 DW_BLOCK (&die->attrs[i])->size);
13337 case DW_FORM_exprloc:
13338 fprintf_unfiltered (f, "expression: size %u",
13339 DW_BLOCK (&die->attrs[i])->size);
13344 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13345 (long) (DW_ADDR (&die->attrs[i])));
13347 case DW_FORM_data1:
13348 case DW_FORM_data2:
13349 case DW_FORM_data4:
13350 case DW_FORM_data8:
13351 case DW_FORM_udata:
13352 case DW_FORM_sdata:
13353 fprintf_unfiltered (f, "constant: %s",
13354 pulongest (DW_UNSND (&die->attrs[i])));
13356 case DW_FORM_sec_offset:
13357 fprintf_unfiltered (f, "section offset: %s",
13358 pulongest (DW_UNSND (&die->attrs[i])));
13360 case DW_FORM_ref_sig8:
13361 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13362 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13363 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13365 fprintf_unfiltered (f, "signatured type, offset: unknown");
13367 case DW_FORM_string:
13369 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13370 DW_STRING (&die->attrs[i])
13371 ? DW_STRING (&die->attrs[i]) : "",
13372 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13375 if (DW_UNSND (&die->attrs[i]))
13376 fprintf_unfiltered (f, "flag: TRUE");
13378 fprintf_unfiltered (f, "flag: FALSE");
13380 case DW_FORM_flag_present:
13381 fprintf_unfiltered (f, "flag: TRUE");
13383 case DW_FORM_indirect:
13384 /* The reader will have reduced the indirect form to
13385 the "base form" so this form should not occur. */
13386 fprintf_unfiltered (f,
13387 "unexpected attribute form: DW_FORM_indirect");
13390 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13391 die->attrs[i].form);
13394 fprintf_unfiltered (f, "\n");
13399 dump_die_for_error (struct die_info *die)
13401 dump_die_shallow (gdb_stderr, 0, die);
13405 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13407 int indent = level * 4;
13409 gdb_assert (die != NULL);
13411 if (level >= max_level)
13414 dump_die_shallow (f, indent, die);
13416 if (die->child != NULL)
13418 print_spaces (indent, f);
13419 fprintf_unfiltered (f, " Children:");
13420 if (level + 1 < max_level)
13422 fprintf_unfiltered (f, "\n");
13423 dump_die_1 (f, level + 1, max_level, die->child);
13427 fprintf_unfiltered (f,
13428 " [not printed, max nesting level reached]\n");
13432 if (die->sibling != NULL && level > 0)
13434 dump_die_1 (f, level, max_level, die->sibling);
13438 /* This is called from the pdie macro in gdbinit.in.
13439 It's not static so gcc will keep a copy callable from gdb. */
13442 dump_die (struct die_info *die, int max_level)
13444 dump_die_1 (gdb_stdlog, 0, max_level, die);
13448 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13452 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13458 is_ref_attr (struct attribute *attr)
13460 switch (attr->form)
13462 case DW_FORM_ref_addr:
13467 case DW_FORM_ref_udata:
13474 static unsigned int
13475 dwarf2_get_ref_die_offset (struct attribute *attr)
13477 if (is_ref_attr (attr))
13478 return DW_ADDR (attr);
13480 complaint (&symfile_complaints,
13481 _("unsupported die ref attribute form: '%s'"),
13482 dwarf_form_name (attr->form));
13486 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13487 * the value held by the attribute is not constant. */
13490 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13492 if (attr->form == DW_FORM_sdata)
13493 return DW_SND (attr);
13494 else if (attr->form == DW_FORM_udata
13495 || attr->form == DW_FORM_data1
13496 || attr->form == DW_FORM_data2
13497 || attr->form == DW_FORM_data4
13498 || attr->form == DW_FORM_data8)
13499 return DW_UNSND (attr);
13502 complaint (&symfile_complaints,
13503 _("Attribute value is not a constant (%s)"),
13504 dwarf_form_name (attr->form));
13505 return default_value;
13509 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13510 unit and add it to our queue.
13511 The result is non-zero if PER_CU was queued, otherwise the result is zero
13512 meaning either PER_CU is already queued or it is already loaded. */
13515 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
13516 struct dwarf2_per_cu_data *per_cu)
13518 /* We may arrive here during partial symbol reading, if we need full
13519 DIEs to process an unusual case (e.g. template arguments). Do
13520 not queue PER_CU, just tell our caller to load its DIEs. */
13521 if (dwarf2_per_objfile->reading_partial_symbols)
13523 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
13528 /* Mark the dependence relation so that we don't flush PER_CU
13530 dwarf2_add_dependence (this_cu, per_cu);
13532 /* If it's already on the queue, we have nothing to do. */
13533 if (per_cu->queued)
13536 /* If the compilation unit is already loaded, just mark it as
13538 if (per_cu->cu != NULL)
13540 per_cu->cu->last_used = 0;
13544 /* Add it to the queue. */
13545 queue_comp_unit (per_cu, this_cu->objfile);
13550 /* Follow reference or signature attribute ATTR of SRC_DIE.
13551 On entry *REF_CU is the CU of SRC_DIE.
13552 On exit *REF_CU is the CU of the result. */
13554 static struct die_info *
13555 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
13556 struct dwarf2_cu **ref_cu)
13558 struct die_info *die;
13560 if (is_ref_attr (attr))
13561 die = follow_die_ref (src_die, attr, ref_cu);
13562 else if (attr->form == DW_FORM_ref_sig8)
13563 die = follow_die_sig (src_die, attr, ref_cu);
13566 dump_die_for_error (src_die);
13567 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13568 (*ref_cu)->objfile->name);
13574 /* Follow reference OFFSET.
13575 On entry *REF_CU is the CU of the source die referencing OFFSET.
13576 On exit *REF_CU is the CU of the result.
13577 Returns NULL if OFFSET is invalid. */
13579 static struct die_info *
13580 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
13582 struct die_info temp_die;
13583 struct dwarf2_cu *target_cu, *cu = *ref_cu;
13585 gdb_assert (cu->per_cu != NULL);
13589 if (cu->per_cu->from_debug_types)
13591 /* .debug_types CUs cannot reference anything outside their CU.
13592 If they need to, they have to reference a signatured type via
13593 DW_FORM_ref_sig8. */
13594 if (! offset_in_cu_p (&cu->header, offset))
13597 else if (! offset_in_cu_p (&cu->header, offset))
13599 struct dwarf2_per_cu_data *per_cu;
13601 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
13603 /* If necessary, add it to the queue and load its DIEs. */
13604 if (maybe_queue_comp_unit (cu, per_cu))
13605 load_full_comp_unit (per_cu, cu->objfile);
13607 target_cu = per_cu->cu;
13609 else if (cu->dies == NULL)
13611 /* We're loading full DIEs during partial symbol reading. */
13612 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
13613 load_full_comp_unit (cu->per_cu, cu->objfile);
13616 *ref_cu = target_cu;
13617 temp_die.offset = offset;
13618 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
13621 /* Follow reference attribute ATTR of SRC_DIE.
13622 On entry *REF_CU is the CU of SRC_DIE.
13623 On exit *REF_CU is the CU of the result. */
13625 static struct die_info *
13626 follow_die_ref (struct die_info *src_die, struct attribute *attr,
13627 struct dwarf2_cu **ref_cu)
13629 unsigned int offset = dwarf2_get_ref_die_offset (attr);
13630 struct dwarf2_cu *cu = *ref_cu;
13631 struct die_info *die;
13633 die = follow_die_offset (offset, ref_cu);
13635 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13636 "at 0x%x [in module %s]"),
13637 offset, src_die->offset, cu->objfile->name);
13642 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13643 value is intended for DW_OP_call*. */
13645 struct dwarf2_locexpr_baton
13646 dwarf2_fetch_die_location_block (unsigned int offset,
13647 struct dwarf2_per_cu_data *per_cu,
13648 CORE_ADDR (*get_frame_pc) (void *baton),
13651 struct dwarf2_cu *cu = per_cu->cu;
13652 struct die_info *die;
13653 struct attribute *attr;
13654 struct dwarf2_locexpr_baton retval;
13656 dw2_setup (per_cu->objfile);
13658 die = follow_die_offset (offset, &cu);
13660 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13661 offset, per_cu->cu->objfile->name);
13663 attr = dwarf2_attr (die, DW_AT_location, cu);
13666 /* DWARF: "If there is no such attribute, then there is no effect.". */
13668 retval.data = NULL;
13671 else if (attr_form_is_section_offset (attr))
13673 struct dwarf2_loclist_baton loclist_baton;
13674 CORE_ADDR pc = (*get_frame_pc) (baton);
13677 fill_in_loclist_baton (cu, &loclist_baton, attr);
13679 retval.data = dwarf2_find_location_expression (&loclist_baton,
13681 retval.size = size;
13685 if (!attr_form_is_block (attr))
13686 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13687 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13688 offset, per_cu->cu->objfile->name);
13690 retval.data = DW_BLOCK (attr)->data;
13691 retval.size = DW_BLOCK (attr)->size;
13693 retval.per_cu = cu->per_cu;
13697 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13701 dwarf2_get_die_type (unsigned int die_offset,
13702 struct dwarf2_per_cu_data *per_cu)
13704 dw2_setup (per_cu->objfile);
13705 return get_die_type_at_offset (die_offset, per_cu);
13708 /* Follow the signature attribute ATTR in SRC_DIE.
13709 On entry *REF_CU is the CU of SRC_DIE.
13710 On exit *REF_CU is the CU of the result. */
13712 static struct die_info *
13713 follow_die_sig (struct die_info *src_die, struct attribute *attr,
13714 struct dwarf2_cu **ref_cu)
13716 struct objfile *objfile = (*ref_cu)->objfile;
13717 struct die_info temp_die;
13718 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
13719 struct dwarf2_cu *sig_cu;
13720 struct die_info *die;
13722 /* sig_type will be NULL if the signatured type is missing from
13724 if (sig_type == NULL)
13725 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13726 "at 0x%x [in module %s]"),
13727 src_die->offset, objfile->name);
13729 /* If necessary, add it to the queue and load its DIEs. */
13731 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
13732 read_signatured_type (objfile, sig_type);
13734 gdb_assert (sig_type->per_cu.cu != NULL);
13736 sig_cu = sig_type->per_cu.cu;
13737 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
13738 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
13745 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13746 "from DIE at 0x%x [in module %s]"),
13747 sig_type->type_offset, src_die->offset, objfile->name);
13750 /* Given an offset of a signatured type, return its signatured_type. */
13752 static struct signatured_type *
13753 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
13755 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
13756 unsigned int length, initial_length_size;
13757 unsigned int sig_offset;
13758 struct signatured_type find_entry, *type_sig;
13760 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
13761 sig_offset = (initial_length_size
13763 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
13764 + 1 /*address_size*/);
13765 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
13766 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
13768 /* This is only used to lookup previously recorded types.
13769 If we didn't find it, it's our bug. */
13770 gdb_assert (type_sig != NULL);
13771 gdb_assert (offset == type_sig->per_cu.offset);
13776 /* Read in signatured type at OFFSET and build its CU and die(s). */
13779 read_signatured_type_at_offset (struct objfile *objfile,
13780 unsigned int offset)
13782 struct signatured_type *type_sig;
13784 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13786 /* We have the section offset, but we need the signature to do the
13787 hash table lookup. */
13788 type_sig = lookup_signatured_type_at_offset (objfile, offset);
13790 gdb_assert (type_sig->per_cu.cu == NULL);
13792 read_signatured_type (objfile, type_sig);
13794 gdb_assert (type_sig->per_cu.cu != NULL);
13797 /* Read in a signatured type and build its CU and DIEs. */
13800 read_signatured_type (struct objfile *objfile,
13801 struct signatured_type *type_sig)
13803 gdb_byte *types_ptr;
13804 struct die_reader_specs reader_specs;
13805 struct dwarf2_cu *cu;
13806 ULONGEST signature;
13807 struct cleanup *back_to, *free_cu_cleanup;
13809 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13810 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->per_cu.offset;
13812 gdb_assert (type_sig->per_cu.cu == NULL);
13814 cu = xmalloc (sizeof (*cu));
13815 init_one_comp_unit (cu, objfile);
13817 type_sig->per_cu.cu = cu;
13818 cu->per_cu = &type_sig->per_cu;
13820 /* If an error occurs while loading, release our storage. */
13821 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
13823 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
13824 types_ptr, objfile->obfd);
13825 gdb_assert (signature == type_sig->signature);
13828 = htab_create_alloc_ex (cu->header.length / 12,
13832 &cu->comp_unit_obstack,
13833 hashtab_obstack_allocate,
13834 dummy_obstack_deallocate);
13836 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
13837 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
13839 init_cu_die_reader (&reader_specs, cu);
13841 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
13844 /* We try not to read any attributes in this function, because not
13845 all objfiles needed for references have been loaded yet, and symbol
13846 table processing isn't initialized. But we have to set the CU language,
13847 or we won't be able to build types correctly. */
13848 prepare_one_comp_unit (cu, cu->dies);
13850 do_cleanups (back_to);
13852 /* We've successfully allocated this compilation unit. Let our caller
13853 clean it up when finished with it. */
13854 discard_cleanups (free_cu_cleanup);
13856 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
13857 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
13860 /* Decode simple location descriptions.
13861 Given a pointer to a dwarf block that defines a location, compute
13862 the location and return the value.
13864 NOTE drow/2003-11-18: This function is called in two situations
13865 now: for the address of static or global variables (partial symbols
13866 only) and for offsets into structures which are expected to be
13867 (more or less) constant. The partial symbol case should go away,
13868 and only the constant case should remain. That will let this
13869 function complain more accurately. A few special modes are allowed
13870 without complaint for global variables (for instance, global
13871 register values and thread-local values).
13873 A location description containing no operations indicates that the
13874 object is optimized out. The return value is 0 for that case.
13875 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13876 callers will only want a very basic result and this can become a
13879 Note that stack[0] is unused except as a default error return. */
13882 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
13884 struct objfile *objfile = cu->objfile;
13886 int size = blk->size;
13887 gdb_byte *data = blk->data;
13888 CORE_ADDR stack[64];
13890 unsigned int bytes_read, unsnd;
13896 stack[++stacki] = 0;
13935 stack[++stacki] = op - DW_OP_lit0;
13970 stack[++stacki] = op - DW_OP_reg0;
13972 dwarf2_complex_location_expr_complaint ();
13976 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13978 stack[++stacki] = unsnd;
13980 dwarf2_complex_location_expr_complaint ();
13984 stack[++stacki] = read_address (objfile->obfd, &data[i],
13989 case DW_OP_const1u:
13990 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
13994 case DW_OP_const1s:
13995 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
13999 case DW_OP_const2u:
14000 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14004 case DW_OP_const2s:
14005 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14009 case DW_OP_const4u:
14010 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14014 case DW_OP_const4s:
14015 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14020 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14026 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14031 stack[stacki + 1] = stack[stacki];
14036 stack[stacki - 1] += stack[stacki];
14040 case DW_OP_plus_uconst:
14041 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14047 stack[stacki - 1] -= stack[stacki];
14052 /* If we're not the last op, then we definitely can't encode
14053 this using GDB's address_class enum. This is valid for partial
14054 global symbols, although the variable's address will be bogus
14057 dwarf2_complex_location_expr_complaint ();
14060 case DW_OP_GNU_push_tls_address:
14061 /* The top of the stack has the offset from the beginning
14062 of the thread control block at which the variable is located. */
14063 /* Nothing should follow this operator, so the top of stack would
14065 /* This is valid for partial global symbols, but the variable's
14066 address will be bogus in the psymtab. */
14068 dwarf2_complex_location_expr_complaint ();
14071 case DW_OP_GNU_uninit:
14076 const char *name = dwarf_stack_op_name (op);
14079 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14082 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14086 return (stack[stacki]);
14089 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14090 outside of the allocated space. Also enforce minimum>0. */
14091 if (stacki >= ARRAY_SIZE (stack) - 1)
14093 complaint (&symfile_complaints,
14094 _("location description stack overflow"));
14100 complaint (&symfile_complaints,
14101 _("location description stack underflow"));
14105 return (stack[stacki]);
14108 /* memory allocation interface */
14110 static struct dwarf_block *
14111 dwarf_alloc_block (struct dwarf2_cu *cu)
14113 struct dwarf_block *blk;
14115 blk = (struct dwarf_block *)
14116 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14120 static struct abbrev_info *
14121 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14123 struct abbrev_info *abbrev;
14125 abbrev = (struct abbrev_info *)
14126 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14127 memset (abbrev, 0, sizeof (struct abbrev_info));
14131 static struct die_info *
14132 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14134 struct die_info *die;
14135 size_t size = sizeof (struct die_info);
14138 size += (num_attrs - 1) * sizeof (struct attribute);
14140 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14141 memset (die, 0, sizeof (struct die_info));
14146 /* Macro support. */
14148 /* Return the full name of file number I in *LH's file name table.
14149 Use COMP_DIR as the name of the current directory of the
14150 compilation. The result is allocated using xmalloc; the caller is
14151 responsible for freeing it. */
14153 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14155 /* Is the file number a valid index into the line header's file name
14156 table? Remember that file numbers start with one, not zero. */
14157 if (1 <= file && file <= lh->num_file_names)
14159 struct file_entry *fe = &lh->file_names[file - 1];
14161 if (IS_ABSOLUTE_PATH (fe->name))
14162 return xstrdup (fe->name);
14170 dir = lh->include_dirs[fe->dir_index - 1];
14176 dir_len = strlen (dir);
14177 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14178 strcpy (full_name, dir);
14179 full_name[dir_len] = '/';
14180 strcpy (full_name + dir_len + 1, fe->name);
14184 return xstrdup (fe->name);
14189 /* The compiler produced a bogus file number. We can at least
14190 record the macro definitions made in the file, even if we
14191 won't be able to find the file by name. */
14192 char fake_name[80];
14194 sprintf (fake_name, "<bad macro file number %d>", file);
14196 complaint (&symfile_complaints,
14197 _("bad file number in macro information (%d)"),
14200 return xstrdup (fake_name);
14205 static struct macro_source_file *
14206 macro_start_file (int file, int line,
14207 struct macro_source_file *current_file,
14208 const char *comp_dir,
14209 struct line_header *lh, struct objfile *objfile)
14211 /* The full name of this source file. */
14212 char *full_name = file_full_name (file, lh, comp_dir);
14214 /* We don't create a macro table for this compilation unit
14215 at all until we actually get a filename. */
14216 if (! pending_macros)
14217 pending_macros = new_macro_table (&objfile->objfile_obstack,
14218 objfile->macro_cache);
14220 if (! current_file)
14221 /* If we have no current file, then this must be the start_file
14222 directive for the compilation unit's main source file. */
14223 current_file = macro_set_main (pending_macros, full_name);
14225 current_file = macro_include (current_file, line, full_name);
14229 return current_file;
14233 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14234 followed by a null byte. */
14236 copy_string (const char *buf, int len)
14238 char *s = xmalloc (len + 1);
14240 memcpy (s, buf, len);
14246 static const char *
14247 consume_improper_spaces (const char *p, const char *body)
14251 complaint (&symfile_complaints,
14252 _("macro definition contains spaces "
14253 "in formal argument list:\n`%s'"),
14265 parse_macro_definition (struct macro_source_file *file, int line,
14270 /* The body string takes one of two forms. For object-like macro
14271 definitions, it should be:
14273 <macro name> " " <definition>
14275 For function-like macro definitions, it should be:
14277 <macro name> "() " <definition>
14279 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14281 Spaces may appear only where explicitly indicated, and in the
14284 The Dwarf 2 spec says that an object-like macro's name is always
14285 followed by a space, but versions of GCC around March 2002 omit
14286 the space when the macro's definition is the empty string.
14288 The Dwarf 2 spec says that there should be no spaces between the
14289 formal arguments in a function-like macro's formal argument list,
14290 but versions of GCC around March 2002 include spaces after the
14294 /* Find the extent of the macro name. The macro name is terminated
14295 by either a space or null character (for an object-like macro) or
14296 an opening paren (for a function-like macro). */
14297 for (p = body; *p; p++)
14298 if (*p == ' ' || *p == '(')
14301 if (*p == ' ' || *p == '\0')
14303 /* It's an object-like macro. */
14304 int name_len = p - body;
14305 char *name = copy_string (body, name_len);
14306 const char *replacement;
14309 replacement = body + name_len + 1;
14312 dwarf2_macro_malformed_definition_complaint (body);
14313 replacement = body + name_len;
14316 macro_define_object (file, line, name, replacement);
14320 else if (*p == '(')
14322 /* It's a function-like macro. */
14323 char *name = copy_string (body, p - body);
14326 char **argv = xmalloc (argv_size * sizeof (*argv));
14330 p = consume_improper_spaces (p, body);
14332 /* Parse the formal argument list. */
14333 while (*p && *p != ')')
14335 /* Find the extent of the current argument name. */
14336 const char *arg_start = p;
14338 while (*p && *p != ',' && *p != ')' && *p != ' ')
14341 if (! *p || p == arg_start)
14342 dwarf2_macro_malformed_definition_complaint (body);
14345 /* Make sure argv has room for the new argument. */
14346 if (argc >= argv_size)
14349 argv = xrealloc (argv, argv_size * sizeof (*argv));
14352 argv[argc++] = copy_string (arg_start, p - arg_start);
14355 p = consume_improper_spaces (p, body);
14357 /* Consume the comma, if present. */
14362 p = consume_improper_spaces (p, body);
14371 /* Perfectly formed definition, no complaints. */
14372 macro_define_function (file, line, name,
14373 argc, (const char **) argv,
14375 else if (*p == '\0')
14377 /* Complain, but do define it. */
14378 dwarf2_macro_malformed_definition_complaint (body);
14379 macro_define_function (file, line, name,
14380 argc, (const char **) argv,
14384 /* Just complain. */
14385 dwarf2_macro_malformed_definition_complaint (body);
14388 /* Just complain. */
14389 dwarf2_macro_malformed_definition_complaint (body);
14395 for (i = 0; i < argc; i++)
14401 dwarf2_macro_malformed_definition_complaint (body);
14406 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
14407 char *comp_dir, bfd *abfd,
14408 struct dwarf2_cu *cu)
14410 gdb_byte *mac_ptr, *mac_end;
14411 struct macro_source_file *current_file = 0;
14412 enum dwarf_macinfo_record_type macinfo_type;
14413 int at_commandline;
14415 dwarf2_read_section (dwarf2_per_objfile->objfile,
14416 &dwarf2_per_objfile->macinfo);
14417 if (dwarf2_per_objfile->macinfo.buffer == NULL)
14419 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
14423 /* First pass: Find the name of the base filename.
14424 This filename is needed in order to process all macros whose definition
14425 (or undefinition) comes from the command line. These macros are defined
14426 before the first DW_MACINFO_start_file entry, and yet still need to be
14427 associated to the base file.
14429 To determine the base file name, we scan the macro definitions until we
14430 reach the first DW_MACINFO_start_file entry. We then initialize
14431 CURRENT_FILE accordingly so that any macro definition found before the
14432 first DW_MACINFO_start_file can still be associated to the base file. */
14434 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14435 mac_end = dwarf2_per_objfile->macinfo.buffer
14436 + dwarf2_per_objfile->macinfo.size;
14440 /* Do we at least have room for a macinfo type byte? */
14441 if (mac_ptr >= mac_end)
14443 /* Complaint is printed during the second pass as GDB will probably
14444 stop the first pass earlier upon finding
14445 DW_MACINFO_start_file. */
14449 macinfo_type = read_1_byte (abfd, mac_ptr);
14452 switch (macinfo_type)
14454 /* A zero macinfo type indicates the end of the macro
14459 case DW_MACINFO_define:
14460 case DW_MACINFO_undef:
14461 /* Only skip the data by MAC_PTR. */
14463 unsigned int bytes_read;
14465 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14466 mac_ptr += bytes_read;
14467 read_direct_string (abfd, mac_ptr, &bytes_read);
14468 mac_ptr += bytes_read;
14472 case DW_MACINFO_start_file:
14474 unsigned int bytes_read;
14477 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14478 mac_ptr += bytes_read;
14479 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14480 mac_ptr += bytes_read;
14482 current_file = macro_start_file (file, line, current_file,
14483 comp_dir, lh, cu->objfile);
14487 case DW_MACINFO_end_file:
14488 /* No data to skip by MAC_PTR. */
14491 case DW_MACINFO_vendor_ext:
14492 /* Only skip the data by MAC_PTR. */
14494 unsigned int bytes_read;
14496 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14497 mac_ptr += bytes_read;
14498 read_direct_string (abfd, mac_ptr, &bytes_read);
14499 mac_ptr += bytes_read;
14506 } while (macinfo_type != 0 && current_file == NULL);
14508 /* Second pass: Process all entries.
14510 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14511 command-line macro definitions/undefinitions. This flag is unset when we
14512 reach the first DW_MACINFO_start_file entry. */
14514 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14516 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14517 GDB is still reading the definitions from command line. First
14518 DW_MACINFO_start_file will need to be ignored as it was already executed
14519 to create CURRENT_FILE for the main source holding also the command line
14520 definitions. On first met DW_MACINFO_start_file this flag is reset to
14521 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14523 at_commandline = 1;
14527 /* Do we at least have room for a macinfo type byte? */
14528 if (mac_ptr >= mac_end)
14530 dwarf2_macros_too_long_complaint ();
14534 macinfo_type = read_1_byte (abfd, mac_ptr);
14537 switch (macinfo_type)
14539 /* A zero macinfo type indicates the end of the macro
14544 case DW_MACINFO_define:
14545 case DW_MACINFO_undef:
14547 unsigned int bytes_read;
14551 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14552 mac_ptr += bytes_read;
14553 body = read_direct_string (abfd, mac_ptr, &bytes_read);
14554 mac_ptr += bytes_read;
14556 if (! current_file)
14558 /* DWARF violation as no main source is present. */
14559 complaint (&symfile_complaints,
14560 _("debug info with no main source gives macro %s "
14562 macinfo_type == DW_MACINFO_define ?
14564 macinfo_type == DW_MACINFO_undef ?
14565 _("undefinition") :
14566 _("something-or-other"), line, body);
14569 if ((line == 0 && !at_commandline)
14570 || (line != 0 && at_commandline))
14571 complaint (&symfile_complaints,
14572 _("debug info gives %s macro %s with %s line %d: %s"),
14573 at_commandline ? _("command-line") : _("in-file"),
14574 macinfo_type == DW_MACINFO_define ?
14576 macinfo_type == DW_MACINFO_undef ?
14577 _("undefinition") :
14578 _("something-or-other"),
14579 line == 0 ? _("zero") : _("non-zero"), line, body);
14581 if (macinfo_type == DW_MACINFO_define)
14582 parse_macro_definition (current_file, line, body);
14583 else if (macinfo_type == DW_MACINFO_undef)
14584 macro_undef (current_file, line, body);
14588 case DW_MACINFO_start_file:
14590 unsigned int bytes_read;
14593 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14594 mac_ptr += bytes_read;
14595 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14596 mac_ptr += bytes_read;
14598 if ((line == 0 && !at_commandline)
14599 || (line != 0 && at_commandline))
14600 complaint (&symfile_complaints,
14601 _("debug info gives source %d included "
14602 "from %s at %s line %d"),
14603 file, at_commandline ? _("command-line") : _("file"),
14604 line == 0 ? _("zero") : _("non-zero"), line);
14606 if (at_commandline)
14608 /* This DW_MACINFO_start_file was executed in the pass one. */
14609 at_commandline = 0;
14612 current_file = macro_start_file (file, line,
14613 current_file, comp_dir,
14618 case DW_MACINFO_end_file:
14619 if (! current_file)
14620 complaint (&symfile_complaints,
14621 _("macro debug info has an unmatched "
14622 "`close_file' directive"));
14625 current_file = current_file->included_by;
14626 if (! current_file)
14628 enum dwarf_macinfo_record_type next_type;
14630 /* GCC circa March 2002 doesn't produce the zero
14631 type byte marking the end of the compilation
14632 unit. Complain if it's not there, but exit no
14635 /* Do we at least have room for a macinfo type byte? */
14636 if (mac_ptr >= mac_end)
14638 dwarf2_macros_too_long_complaint ();
14642 /* We don't increment mac_ptr here, so this is just
14644 next_type = read_1_byte (abfd, mac_ptr);
14645 if (next_type != 0)
14646 complaint (&symfile_complaints,
14647 _("no terminating 0-type entry for "
14648 "macros in `.debug_macinfo' section"));
14655 case DW_MACINFO_vendor_ext:
14657 unsigned int bytes_read;
14660 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14661 mac_ptr += bytes_read;
14662 read_direct_string (abfd, mac_ptr, &bytes_read);
14663 mac_ptr += bytes_read;
14665 /* We don't recognize any vendor extensions. */
14669 } while (macinfo_type != 0);
14672 /* Check if the attribute's form is a DW_FORM_block*
14673 if so return true else false. */
14675 attr_form_is_block (struct attribute *attr)
14677 return (attr == NULL ? 0 :
14678 attr->form == DW_FORM_block1
14679 || attr->form == DW_FORM_block2
14680 || attr->form == DW_FORM_block4
14681 || attr->form == DW_FORM_block
14682 || attr->form == DW_FORM_exprloc);
14685 /* Return non-zero if ATTR's value is a section offset --- classes
14686 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14687 You may use DW_UNSND (attr) to retrieve such offsets.
14689 Section 7.5.4, "Attribute Encodings", explains that no attribute
14690 may have a value that belongs to more than one of these classes; it
14691 would be ambiguous if we did, because we use the same forms for all
14694 attr_form_is_section_offset (struct attribute *attr)
14696 return (attr->form == DW_FORM_data4
14697 || attr->form == DW_FORM_data8
14698 || attr->form == DW_FORM_sec_offset);
14702 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14703 zero otherwise. When this function returns true, you can apply
14704 dwarf2_get_attr_constant_value to it.
14706 However, note that for some attributes you must check
14707 attr_form_is_section_offset before using this test. DW_FORM_data4
14708 and DW_FORM_data8 are members of both the constant class, and of
14709 the classes that contain offsets into other debug sections
14710 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14711 that, if an attribute's can be either a constant or one of the
14712 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14713 taken as section offsets, not constants. */
14715 attr_form_is_constant (struct attribute *attr)
14717 switch (attr->form)
14719 case DW_FORM_sdata:
14720 case DW_FORM_udata:
14721 case DW_FORM_data1:
14722 case DW_FORM_data2:
14723 case DW_FORM_data4:
14724 case DW_FORM_data8:
14731 /* A helper function that fills in a dwarf2_loclist_baton. */
14734 fill_in_loclist_baton (struct dwarf2_cu *cu,
14735 struct dwarf2_loclist_baton *baton,
14736 struct attribute *attr)
14738 dwarf2_read_section (dwarf2_per_objfile->objfile,
14739 &dwarf2_per_objfile->loc);
14741 baton->per_cu = cu->per_cu;
14742 gdb_assert (baton->per_cu);
14743 /* We don't know how long the location list is, but make sure we
14744 don't run off the edge of the section. */
14745 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
14746 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
14747 baton->base_address = cu->base_address;
14751 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
14752 struct dwarf2_cu *cu)
14754 if (attr_form_is_section_offset (attr)
14755 /* ".debug_loc" may not exist at all, or the offset may be outside
14756 the section. If so, fall through to the complaint in the
14758 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
14759 &dwarf2_per_objfile->loc))
14761 struct dwarf2_loclist_baton *baton;
14763 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14764 sizeof (struct dwarf2_loclist_baton));
14766 fill_in_loclist_baton (cu, baton, attr);
14768 if (cu->base_known == 0)
14769 complaint (&symfile_complaints,
14770 _("Location list used without "
14771 "specifying the CU base address."));
14773 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
14774 SYMBOL_LOCATION_BATON (sym) = baton;
14778 struct dwarf2_locexpr_baton *baton;
14780 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14781 sizeof (struct dwarf2_locexpr_baton));
14782 baton->per_cu = cu->per_cu;
14783 gdb_assert (baton->per_cu);
14785 if (attr_form_is_block (attr))
14787 /* Note that we're just copying the block's data pointer
14788 here, not the actual data. We're still pointing into the
14789 info_buffer for SYM's objfile; right now we never release
14790 that buffer, but when we do clean up properly this may
14792 baton->size = DW_BLOCK (attr)->size;
14793 baton->data = DW_BLOCK (attr)->data;
14797 dwarf2_invalid_attrib_class_complaint ("location description",
14798 SYMBOL_NATURAL_NAME (sym));
14800 baton->data = NULL;
14803 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
14804 SYMBOL_LOCATION_BATON (sym) = baton;
14808 /* Return the OBJFILE associated with the compilation unit CU. If CU
14809 came from a separate debuginfo file, then the master objfile is
14813 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
14815 struct objfile *objfile = per_cu->objfile;
14817 /* Return the master objfile, so that we can report and look up the
14818 correct file containing this variable. */
14819 if (objfile->separate_debug_objfile_backlink)
14820 objfile = objfile->separate_debug_objfile_backlink;
14825 /* Return the address size given in the compilation unit header for CU. */
14828 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
14831 return per_cu->cu->header.addr_size;
14834 /* If the CU is not currently read in, we re-read its header. */
14835 struct objfile *objfile = per_cu->objfile;
14836 struct dwarf2_per_objfile *per_objfile
14837 = objfile_data (objfile, dwarf2_objfile_data_key);
14838 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14839 struct comp_unit_head cu_header;
14841 memset (&cu_header, 0, sizeof cu_header);
14842 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14843 return cu_header.addr_size;
14847 /* Return the offset size given in the compilation unit header for CU. */
14850 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
14853 return per_cu->cu->header.offset_size;
14856 /* If the CU is not currently read in, we re-read its header. */
14857 struct objfile *objfile = per_cu->objfile;
14858 struct dwarf2_per_objfile *per_objfile
14859 = objfile_data (objfile, dwarf2_objfile_data_key);
14860 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14861 struct comp_unit_head cu_header;
14863 memset (&cu_header, 0, sizeof cu_header);
14864 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14865 return cu_header.offset_size;
14869 /* Return the text offset of the CU. The returned offset comes from
14870 this CU's objfile. If this objfile came from a separate debuginfo
14871 file, then the offset may be different from the corresponding
14872 offset in the parent objfile. */
14875 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
14877 struct objfile *objfile = per_cu->objfile;
14879 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14882 /* Locate the .debug_info compilation unit from CU's objfile which contains
14883 the DIE at OFFSET. Raises an error on failure. */
14885 static struct dwarf2_per_cu_data *
14886 dwarf2_find_containing_comp_unit (unsigned int offset,
14887 struct objfile *objfile)
14889 struct dwarf2_per_cu_data *this_cu;
14893 high = dwarf2_per_objfile->n_comp_units - 1;
14896 int mid = low + (high - low) / 2;
14898 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
14903 gdb_assert (low == high);
14904 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
14907 error (_("Dwarf Error: could not find partial DIE containing "
14908 "offset 0x%lx [in module %s]"),
14909 (long) offset, bfd_get_filename (objfile->obfd));
14911 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
14912 return dwarf2_per_objfile->all_comp_units[low-1];
14916 this_cu = dwarf2_per_objfile->all_comp_units[low];
14917 if (low == dwarf2_per_objfile->n_comp_units - 1
14918 && offset >= this_cu->offset + this_cu->length)
14919 error (_("invalid dwarf2 offset %u"), offset);
14920 gdb_assert (offset < this_cu->offset + this_cu->length);
14925 /* Locate the compilation unit from OBJFILE which is located at exactly
14926 OFFSET. Raises an error on failure. */
14928 static struct dwarf2_per_cu_data *
14929 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
14931 struct dwarf2_per_cu_data *this_cu;
14933 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
14934 if (this_cu->offset != offset)
14935 error (_("no compilation unit with offset %u."), offset);
14939 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14942 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
14944 memset (cu, 0, sizeof (*cu));
14945 cu->objfile = objfile;
14946 obstack_init (&cu->comp_unit_obstack);
14949 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14952 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
14954 struct attribute *attr;
14956 /* Set the language we're debugging. */
14957 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
14959 set_cu_language (DW_UNSND (attr), cu);
14962 cu->language = language_minimal;
14963 cu->language_defn = language_def (cu->language);
14967 /* Release one cached compilation unit, CU. We unlink it from the tree
14968 of compilation units, but we don't remove it from the read_in_chain;
14969 the caller is responsible for that.
14970 NOTE: DATA is a void * because this function is also used as a
14971 cleanup routine. */
14974 free_one_comp_unit (void *data)
14976 struct dwarf2_cu *cu = data;
14978 if (cu->per_cu != NULL)
14979 cu->per_cu->cu = NULL;
14982 obstack_free (&cu->comp_unit_obstack, NULL);
14987 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14988 when we're finished with it. We can't free the pointer itself, but be
14989 sure to unlink it from the cache. Also release any associated storage
14990 and perform cache maintenance.
14992 Only used during partial symbol parsing. */
14995 free_stack_comp_unit (void *data)
14997 struct dwarf2_cu *cu = data;
14999 obstack_free (&cu->comp_unit_obstack, NULL);
15000 cu->partial_dies = NULL;
15002 if (cu->per_cu != NULL)
15004 /* This compilation unit is on the stack in our caller, so we
15005 should not xfree it. Just unlink it. */
15006 cu->per_cu->cu = NULL;
15009 /* If we had a per-cu pointer, then we may have other compilation
15010 units loaded, so age them now. */
15011 age_cached_comp_units ();
15015 /* Free all cached compilation units. */
15018 free_cached_comp_units (void *data)
15020 struct dwarf2_per_cu_data *per_cu, **last_chain;
15022 per_cu = dwarf2_per_objfile->read_in_chain;
15023 last_chain = &dwarf2_per_objfile->read_in_chain;
15024 while (per_cu != NULL)
15026 struct dwarf2_per_cu_data *next_cu;
15028 next_cu = per_cu->cu->read_in_chain;
15030 free_one_comp_unit (per_cu->cu);
15031 *last_chain = next_cu;
15037 /* Increase the age counter on each cached compilation unit, and free
15038 any that are too old. */
15041 age_cached_comp_units (void)
15043 struct dwarf2_per_cu_data *per_cu, **last_chain;
15045 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15046 per_cu = dwarf2_per_objfile->read_in_chain;
15047 while (per_cu != NULL)
15049 per_cu->cu->last_used ++;
15050 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15051 dwarf2_mark (per_cu->cu);
15052 per_cu = per_cu->cu->read_in_chain;
15055 per_cu = dwarf2_per_objfile->read_in_chain;
15056 last_chain = &dwarf2_per_objfile->read_in_chain;
15057 while (per_cu != NULL)
15059 struct dwarf2_per_cu_data *next_cu;
15061 next_cu = per_cu->cu->read_in_chain;
15063 if (!per_cu->cu->mark)
15065 free_one_comp_unit (per_cu->cu);
15066 *last_chain = next_cu;
15069 last_chain = &per_cu->cu->read_in_chain;
15075 /* Remove a single compilation unit from the cache. */
15078 free_one_cached_comp_unit (void *target_cu)
15080 struct dwarf2_per_cu_data *per_cu, **last_chain;
15082 per_cu = dwarf2_per_objfile->read_in_chain;
15083 last_chain = &dwarf2_per_objfile->read_in_chain;
15084 while (per_cu != NULL)
15086 struct dwarf2_per_cu_data *next_cu;
15088 next_cu = per_cu->cu->read_in_chain;
15090 if (per_cu->cu == target_cu)
15092 free_one_comp_unit (per_cu->cu);
15093 *last_chain = next_cu;
15097 last_chain = &per_cu->cu->read_in_chain;
15103 /* Release all extra memory associated with OBJFILE. */
15106 dwarf2_free_objfile (struct objfile *objfile)
15108 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15110 if (dwarf2_per_objfile == NULL)
15113 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15114 free_cached_comp_units (NULL);
15116 if (dwarf2_per_objfile->quick_file_names_table)
15117 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15119 /* Everything else should be on the objfile obstack. */
15122 /* A pair of DIE offset and GDB type pointer. We store these
15123 in a hash table separate from the DIEs, and preserve them
15124 when the DIEs are flushed out of cache. */
15126 struct dwarf2_offset_and_type
15128 unsigned int offset;
15132 /* Hash function for a dwarf2_offset_and_type. */
15135 offset_and_type_hash (const void *item)
15137 const struct dwarf2_offset_and_type *ofs = item;
15139 return ofs->offset;
15142 /* Equality function for a dwarf2_offset_and_type. */
15145 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15147 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15148 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15150 return ofs_lhs->offset == ofs_rhs->offset;
15153 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15154 table if necessary. For convenience, return TYPE.
15156 The DIEs reading must have careful ordering to:
15157 * Not cause infite loops trying to read in DIEs as a prerequisite for
15158 reading current DIE.
15159 * Not trying to dereference contents of still incompletely read in types
15160 while reading in other DIEs.
15161 * Enable referencing still incompletely read in types just by a pointer to
15162 the type without accessing its fields.
15164 Therefore caller should follow these rules:
15165 * Try to fetch any prerequisite types we may need to build this DIE type
15166 before building the type and calling set_die_type.
15167 * After building type call set_die_type for current DIE as soon as
15168 possible before fetching more types to complete the current type.
15169 * Make the type as complete as possible before fetching more types. */
15171 static struct type *
15172 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15174 struct dwarf2_offset_and_type **slot, ofs;
15175 struct objfile *objfile = cu->objfile;
15176 htab_t *type_hash_ptr;
15178 /* For Ada types, make sure that the gnat-specific data is always
15179 initialized (if not already set). There are a few types where
15180 we should not be doing so, because the type-specific area is
15181 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15182 where the type-specific area is used to store the floatformat).
15183 But this is not a problem, because the gnat-specific information
15184 is actually not needed for these types. */
15185 if (need_gnat_info (cu)
15186 && TYPE_CODE (type) != TYPE_CODE_FUNC
15187 && TYPE_CODE (type) != TYPE_CODE_FLT
15188 && !HAVE_GNAT_AUX_INFO (type))
15189 INIT_GNAT_SPECIFIC (type);
15191 if (cu->per_cu->from_debug_types)
15192 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
15194 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
15196 if (*type_hash_ptr == NULL)
15199 = htab_create_alloc_ex (127,
15200 offset_and_type_hash,
15201 offset_and_type_eq,
15203 &objfile->objfile_obstack,
15204 hashtab_obstack_allocate,
15205 dummy_obstack_deallocate);
15208 ofs.offset = die->offset;
15210 slot = (struct dwarf2_offset_and_type **)
15211 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
15213 complaint (&symfile_complaints,
15214 _("A problem internal to GDB: DIE 0x%x has type already set"),
15216 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
15221 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15222 table, or return NULL if the die does not have a saved type. */
15224 static struct type *
15225 get_die_type_at_offset (unsigned int offset,
15226 struct dwarf2_per_cu_data *per_cu)
15228 struct dwarf2_offset_and_type *slot, ofs;
15231 if (per_cu->from_debug_types)
15232 type_hash = dwarf2_per_objfile->debug_types_type_hash;
15234 type_hash = dwarf2_per_objfile->debug_info_type_hash;
15235 if (type_hash == NULL)
15238 ofs.offset = offset;
15239 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
15246 /* Look up the type for DIE in the appropriate type_hash table,
15247 or return NULL if DIE does not have a saved type. */
15249 static struct type *
15250 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
15252 return get_die_type_at_offset (die->offset, cu->per_cu);
15255 /* Add a dependence relationship from CU to REF_PER_CU. */
15258 dwarf2_add_dependence (struct dwarf2_cu *cu,
15259 struct dwarf2_per_cu_data *ref_per_cu)
15263 if (cu->dependencies == NULL)
15265 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
15266 NULL, &cu->comp_unit_obstack,
15267 hashtab_obstack_allocate,
15268 dummy_obstack_deallocate);
15270 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
15272 *slot = ref_per_cu;
15275 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15276 Set the mark field in every compilation unit in the
15277 cache that we must keep because we are keeping CU. */
15280 dwarf2_mark_helper (void **slot, void *data)
15282 struct dwarf2_per_cu_data *per_cu;
15284 per_cu = (struct dwarf2_per_cu_data *) *slot;
15285 if (per_cu->cu->mark)
15287 per_cu->cu->mark = 1;
15289 if (per_cu->cu->dependencies != NULL)
15290 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
15295 /* Set the mark field in CU and in every other compilation unit in the
15296 cache that we must keep because we are keeping CU. */
15299 dwarf2_mark (struct dwarf2_cu *cu)
15304 if (cu->dependencies != NULL)
15305 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
15309 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
15313 per_cu->cu->mark = 0;
15314 per_cu = per_cu->cu->read_in_chain;
15318 /* Trivial hash function for partial_die_info: the hash value of a DIE
15319 is its offset in .debug_info for this objfile. */
15322 partial_die_hash (const void *item)
15324 const struct partial_die_info *part_die = item;
15326 return part_die->offset;
15329 /* Trivial comparison function for partial_die_info structures: two DIEs
15330 are equal if they have the same offset. */
15333 partial_die_eq (const void *item_lhs, const void *item_rhs)
15335 const struct partial_die_info *part_die_lhs = item_lhs;
15336 const struct partial_die_info *part_die_rhs = item_rhs;
15338 return part_die_lhs->offset == part_die_rhs->offset;
15341 static struct cmd_list_element *set_dwarf2_cmdlist;
15342 static struct cmd_list_element *show_dwarf2_cmdlist;
15345 set_dwarf2_cmd (char *args, int from_tty)
15347 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
15351 show_dwarf2_cmd (char *args, int from_tty)
15353 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
15356 /* If section described by INFO was mmapped, munmap it now. */
15359 munmap_section_buffer (struct dwarf2_section_info *info)
15361 if (info->was_mmapped)
15364 intptr_t begin = (intptr_t) info->buffer;
15365 intptr_t map_begin = begin & ~(pagesize - 1);
15366 size_t map_length = info->size + begin - map_begin;
15368 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
15370 /* Without HAVE_MMAP, we should never be here to begin with. */
15371 gdb_assert_not_reached ("no mmap support");
15376 /* munmap debug sections for OBJFILE, if necessary. */
15379 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
15381 struct dwarf2_per_objfile *data = d;
15383 /* This is sorted according to the order they're defined in to make it easier
15384 to keep in sync. */
15385 munmap_section_buffer (&data->info);
15386 munmap_section_buffer (&data->abbrev);
15387 munmap_section_buffer (&data->line);
15388 munmap_section_buffer (&data->loc);
15389 munmap_section_buffer (&data->macinfo);
15390 munmap_section_buffer (&data->str);
15391 munmap_section_buffer (&data->ranges);
15392 munmap_section_buffer (&data->types);
15393 munmap_section_buffer (&data->frame);
15394 munmap_section_buffer (&data->eh_frame);
15395 munmap_section_buffer (&data->gdb_index);
15399 /* The "save gdb-index" command. */
15401 /* The contents of the hash table we create when building the string
15403 struct strtab_entry
15405 offset_type offset;
15409 /* Hash function for a strtab_entry.
15411 Function is used only during write_hash_table so no index format backward
15412 compatibility is needed. */
15415 hash_strtab_entry (const void *e)
15417 const struct strtab_entry *entry = e;
15418 return mapped_index_string_hash (INT_MAX, entry->str);
15421 /* Equality function for a strtab_entry. */
15424 eq_strtab_entry (const void *a, const void *b)
15426 const struct strtab_entry *ea = a;
15427 const struct strtab_entry *eb = b;
15428 return !strcmp (ea->str, eb->str);
15431 /* Create a strtab_entry hash table. */
15434 create_strtab (void)
15436 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
15437 xfree, xcalloc, xfree);
15440 /* Add a string to the constant pool. Return the string's offset in
15444 add_string (htab_t table, struct obstack *cpool, const char *str)
15447 struct strtab_entry entry;
15448 struct strtab_entry *result;
15451 slot = htab_find_slot (table, &entry, INSERT);
15456 result = XNEW (struct strtab_entry);
15457 result->offset = obstack_object_size (cpool);
15459 obstack_grow_str0 (cpool, str);
15462 return result->offset;
15465 /* An entry in the symbol table. */
15466 struct symtab_index_entry
15468 /* The name of the symbol. */
15470 /* The offset of the name in the constant pool. */
15471 offset_type index_offset;
15472 /* A sorted vector of the indices of all the CUs that hold an object
15474 VEC (offset_type) *cu_indices;
15477 /* The symbol table. This is a power-of-2-sized hash table. */
15478 struct mapped_symtab
15480 offset_type n_elements;
15482 struct symtab_index_entry **data;
15485 /* Hash function for a symtab_index_entry. */
15488 hash_symtab_entry (const void *e)
15490 const struct symtab_index_entry *entry = e;
15491 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
15492 sizeof (offset_type) * VEC_length (offset_type,
15493 entry->cu_indices),
15497 /* Equality function for a symtab_index_entry. */
15500 eq_symtab_entry (const void *a, const void *b)
15502 const struct symtab_index_entry *ea = a;
15503 const struct symtab_index_entry *eb = b;
15504 int len = VEC_length (offset_type, ea->cu_indices);
15505 if (len != VEC_length (offset_type, eb->cu_indices))
15507 return !memcmp (VEC_address (offset_type, ea->cu_indices),
15508 VEC_address (offset_type, eb->cu_indices),
15509 sizeof (offset_type) * len);
15512 /* Destroy a symtab_index_entry. */
15515 delete_symtab_entry (void *p)
15517 struct symtab_index_entry *entry = p;
15518 VEC_free (offset_type, entry->cu_indices);
15522 /* Create a hash table holding symtab_index_entry objects. */
15525 create_symbol_hash_table (void)
15527 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
15528 delete_symtab_entry, xcalloc, xfree);
15531 /* Create a new mapped symtab object. */
15533 static struct mapped_symtab *
15534 create_mapped_symtab (void)
15536 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
15537 symtab->n_elements = 0;
15538 symtab->size = 1024;
15539 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15543 /* Destroy a mapped_symtab. */
15546 cleanup_mapped_symtab (void *p)
15548 struct mapped_symtab *symtab = p;
15549 /* The contents of the array are freed when the other hash table is
15551 xfree (symtab->data);
15555 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15558 Function is used only during write_hash_table so no index format backward
15559 compatibility is needed. */
15561 static struct symtab_index_entry **
15562 find_slot (struct mapped_symtab *symtab, const char *name)
15564 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
15566 index = hash & (symtab->size - 1);
15567 step = ((hash * 17) & (symtab->size - 1)) | 1;
15571 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
15572 return &symtab->data[index];
15573 index = (index + step) & (symtab->size - 1);
15577 /* Expand SYMTAB's hash table. */
15580 hash_expand (struct mapped_symtab *symtab)
15582 offset_type old_size = symtab->size;
15584 struct symtab_index_entry **old_entries = symtab->data;
15587 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15589 for (i = 0; i < old_size; ++i)
15591 if (old_entries[i])
15593 struct symtab_index_entry **slot = find_slot (symtab,
15594 old_entries[i]->name);
15595 *slot = old_entries[i];
15599 xfree (old_entries);
15602 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15603 is the index of the CU in which the symbol appears. */
15606 add_index_entry (struct mapped_symtab *symtab, const char *name,
15607 offset_type cu_index)
15609 struct symtab_index_entry **slot;
15611 ++symtab->n_elements;
15612 if (4 * symtab->n_elements / 3 >= symtab->size)
15613 hash_expand (symtab);
15615 slot = find_slot (symtab, name);
15618 *slot = XNEW (struct symtab_index_entry);
15619 (*slot)->name = name;
15620 (*slot)->cu_indices = NULL;
15622 /* Don't push an index twice. Due to how we add entries we only
15623 have to check the last one. */
15624 if (VEC_empty (offset_type, (*slot)->cu_indices)
15625 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
15626 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
15629 /* Add a vector of indices to the constant pool. */
15632 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
15633 struct symtab_index_entry *entry)
15637 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
15640 offset_type len = VEC_length (offset_type, entry->cu_indices);
15641 offset_type val = MAYBE_SWAP (len);
15646 entry->index_offset = obstack_object_size (cpool);
15648 obstack_grow (cpool, &val, sizeof (val));
15650 VEC_iterate (offset_type, entry->cu_indices, i, iter);
15653 val = MAYBE_SWAP (iter);
15654 obstack_grow (cpool, &val, sizeof (val));
15659 struct symtab_index_entry *old_entry = *slot;
15660 entry->index_offset = old_entry->index_offset;
15663 return entry->index_offset;
15666 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15667 constant pool entries going into the obstack CPOOL. */
15670 write_hash_table (struct mapped_symtab *symtab,
15671 struct obstack *output, struct obstack *cpool)
15674 htab_t symbol_hash_table;
15677 symbol_hash_table = create_symbol_hash_table ();
15678 str_table = create_strtab ();
15680 /* We add all the index vectors to the constant pool first, to
15681 ensure alignment is ok. */
15682 for (i = 0; i < symtab->size; ++i)
15684 if (symtab->data[i])
15685 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
15688 /* Now write out the hash table. */
15689 for (i = 0; i < symtab->size; ++i)
15691 offset_type str_off, vec_off;
15693 if (symtab->data[i])
15695 str_off = add_string (str_table, cpool, symtab->data[i]->name);
15696 vec_off = symtab->data[i]->index_offset;
15700 /* While 0 is a valid constant pool index, it is not valid
15701 to have 0 for both offsets. */
15706 str_off = MAYBE_SWAP (str_off);
15707 vec_off = MAYBE_SWAP (vec_off);
15709 obstack_grow (output, &str_off, sizeof (str_off));
15710 obstack_grow (output, &vec_off, sizeof (vec_off));
15713 htab_delete (str_table);
15714 htab_delete (symbol_hash_table);
15717 /* Struct to map psymtab to CU index in the index file. */
15718 struct psymtab_cu_index_map
15720 struct partial_symtab *psymtab;
15721 unsigned int cu_index;
15725 hash_psymtab_cu_index (const void *item)
15727 const struct psymtab_cu_index_map *map = item;
15729 return htab_hash_pointer (map->psymtab);
15733 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
15735 const struct psymtab_cu_index_map *lhs = item_lhs;
15736 const struct psymtab_cu_index_map *rhs = item_rhs;
15738 return lhs->psymtab == rhs->psymtab;
15741 /* Helper struct for building the address table. */
15742 struct addrmap_index_data
15744 struct objfile *objfile;
15745 struct obstack *addr_obstack;
15746 htab_t cu_index_htab;
15748 /* Non-zero if the previous_* fields are valid.
15749 We can't write an entry until we see the next entry (since it is only then
15750 that we know the end of the entry). */
15751 int previous_valid;
15752 /* Index of the CU in the table of all CUs in the index file. */
15753 unsigned int previous_cu_index;
15754 /* Start address of the CU. */
15755 CORE_ADDR previous_cu_start;
15758 /* Write an address entry to OBSTACK. */
15761 add_address_entry (struct objfile *objfile, struct obstack *obstack,
15762 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
15764 offset_type cu_index_to_write;
15766 CORE_ADDR baseaddr;
15768 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15770 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
15771 obstack_grow (obstack, addr, 8);
15772 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
15773 obstack_grow (obstack, addr, 8);
15774 cu_index_to_write = MAYBE_SWAP (cu_index);
15775 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
15778 /* Worker function for traversing an addrmap to build the address table. */
15781 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
15783 struct addrmap_index_data *data = datap;
15784 struct partial_symtab *pst = obj;
15785 offset_type cu_index;
15788 if (data->previous_valid)
15789 add_address_entry (data->objfile, data->addr_obstack,
15790 data->previous_cu_start, start_addr,
15791 data->previous_cu_index);
15793 data->previous_cu_start = start_addr;
15796 struct psymtab_cu_index_map find_map, *map;
15797 find_map.psymtab = pst;
15798 map = htab_find (data->cu_index_htab, &find_map);
15799 gdb_assert (map != NULL);
15800 data->previous_cu_index = map->cu_index;
15801 data->previous_valid = 1;
15804 data->previous_valid = 0;
15809 /* Write OBJFILE's address map to OBSTACK.
15810 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15811 in the index file. */
15814 write_address_map (struct objfile *objfile, struct obstack *obstack,
15815 htab_t cu_index_htab)
15817 struct addrmap_index_data addrmap_index_data;
15819 /* When writing the address table, we have to cope with the fact that
15820 the addrmap iterator only provides the start of a region; we have to
15821 wait until the next invocation to get the start of the next region. */
15823 addrmap_index_data.objfile = objfile;
15824 addrmap_index_data.addr_obstack = obstack;
15825 addrmap_index_data.cu_index_htab = cu_index_htab;
15826 addrmap_index_data.previous_valid = 0;
15828 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
15829 &addrmap_index_data);
15831 /* It's highly unlikely the last entry (end address = 0xff...ff)
15832 is valid, but we should still handle it.
15833 The end address is recorded as the start of the next region, but that
15834 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15836 if (addrmap_index_data.previous_valid)
15837 add_address_entry (objfile, obstack,
15838 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
15839 addrmap_index_data.previous_cu_index);
15842 /* Add a list of partial symbols to SYMTAB. */
15845 write_psymbols (struct mapped_symtab *symtab,
15847 struct partial_symbol **psymp,
15849 offset_type cu_index,
15852 for (; count-- > 0; ++psymp)
15854 void **slot, *lookup;
15856 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
15857 error (_("Ada is not currently supported by the index"));
15859 /* We only want to add a given psymbol once. However, we also
15860 want to account for whether it is global or static. So, we
15861 may add it twice, using slightly different values. */
15864 uintptr_t val = 1 | (uintptr_t) *psymp;
15866 lookup = (void *) val;
15871 /* Only add a given psymbol once. */
15872 slot = htab_find_slot (psyms_seen, lookup, INSERT);
15876 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
15881 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15882 exception if there is an error. */
15885 write_obstack (FILE *file, struct obstack *obstack)
15887 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
15889 != obstack_object_size (obstack))
15890 error (_("couldn't data write to file"));
15893 /* Unlink a file if the argument is not NULL. */
15896 unlink_if_set (void *p)
15898 char **filename = p;
15900 unlink (*filename);
15903 /* A helper struct used when iterating over debug_types. */
15904 struct signatured_type_index_data
15906 struct objfile *objfile;
15907 struct mapped_symtab *symtab;
15908 struct obstack *types_list;
15913 /* A helper function that writes a single signatured_type to an
15917 write_one_signatured_type (void **slot, void *d)
15919 struct signatured_type_index_data *info = d;
15920 struct signatured_type *entry = (struct signatured_type *) *slot;
15921 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
15922 struct partial_symtab *psymtab = per_cu->v.psymtab;
15925 write_psymbols (info->symtab,
15927 info->objfile->global_psymbols.list
15928 + psymtab->globals_offset,
15929 psymtab->n_global_syms, info->cu_index,
15931 write_psymbols (info->symtab,
15933 info->objfile->static_psymbols.list
15934 + psymtab->statics_offset,
15935 psymtab->n_static_syms, info->cu_index,
15938 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
15939 obstack_grow (info->types_list, val, 8);
15940 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
15941 obstack_grow (info->types_list, val, 8);
15942 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
15943 obstack_grow (info->types_list, val, 8);
15950 /* A cleanup function for an htab_t. */
15953 cleanup_htab (void *arg)
15958 /* Create an index file for OBJFILE in the directory DIR. */
15961 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
15963 struct cleanup *cleanup;
15964 char *filename, *cleanup_filename;
15965 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
15966 struct obstack cu_list, types_cu_list;
15969 struct mapped_symtab *symtab;
15970 offset_type val, size_of_contents, total_len;
15974 htab_t cu_index_htab;
15975 struct psymtab_cu_index_map *psymtab_cu_index_map;
15977 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
15980 if (dwarf2_per_objfile->using_index)
15981 error (_("Cannot use an index to create the index"));
15983 if (stat (objfile->name, &st) < 0)
15984 perror_with_name (objfile->name);
15986 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
15987 INDEX_SUFFIX, (char *) NULL);
15988 cleanup = make_cleanup (xfree, filename);
15990 out_file = fopen (filename, "wb");
15992 error (_("Can't open `%s' for writing"), filename);
15994 cleanup_filename = filename;
15995 make_cleanup (unlink_if_set, &cleanup_filename);
15997 symtab = create_mapped_symtab ();
15998 make_cleanup (cleanup_mapped_symtab, symtab);
16000 obstack_init (&addr_obstack);
16001 make_cleanup_obstack_free (&addr_obstack);
16003 obstack_init (&cu_list);
16004 make_cleanup_obstack_free (&cu_list);
16006 obstack_init (&types_cu_list);
16007 make_cleanup_obstack_free (&types_cu_list);
16009 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16010 NULL, xcalloc, xfree);
16011 make_cleanup (cleanup_htab, psyms_seen);
16013 /* While we're scanning CU's create a table that maps a psymtab pointer
16014 (which is what addrmap records) to its index (which is what is recorded
16015 in the index file). This will later be needed to write the address
16017 cu_index_htab = htab_create_alloc (100,
16018 hash_psymtab_cu_index,
16019 eq_psymtab_cu_index,
16020 NULL, xcalloc, xfree);
16021 make_cleanup (cleanup_htab, cu_index_htab);
16022 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16023 xmalloc (sizeof (struct psymtab_cu_index_map)
16024 * dwarf2_per_objfile->n_comp_units);
16025 make_cleanup (xfree, psymtab_cu_index_map);
16027 /* The CU list is already sorted, so we don't need to do additional
16028 work here. Also, the debug_types entries do not appear in
16029 all_comp_units, but only in their own hash table. */
16030 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16032 struct dwarf2_per_cu_data *per_cu
16033 = dwarf2_per_objfile->all_comp_units[i];
16034 struct partial_symtab *psymtab = per_cu->v.psymtab;
16036 struct psymtab_cu_index_map *map;
16039 write_psymbols (symtab,
16041 objfile->global_psymbols.list + psymtab->globals_offset,
16042 psymtab->n_global_syms, i,
16044 write_psymbols (symtab,
16046 objfile->static_psymbols.list + psymtab->statics_offset,
16047 psymtab->n_static_syms, i,
16050 map = &psymtab_cu_index_map[i];
16051 map->psymtab = psymtab;
16053 slot = htab_find_slot (cu_index_htab, map, INSERT);
16054 gdb_assert (slot != NULL);
16055 gdb_assert (*slot == NULL);
16058 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16059 obstack_grow (&cu_list, val, 8);
16060 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16061 obstack_grow (&cu_list, val, 8);
16064 /* Dump the address map. */
16065 write_address_map (objfile, &addr_obstack, cu_index_htab);
16067 /* Write out the .debug_type entries, if any. */
16068 if (dwarf2_per_objfile->signatured_types)
16070 struct signatured_type_index_data sig_data;
16072 sig_data.objfile = objfile;
16073 sig_data.symtab = symtab;
16074 sig_data.types_list = &types_cu_list;
16075 sig_data.psyms_seen = psyms_seen;
16076 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
16077 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
16078 write_one_signatured_type, &sig_data);
16081 obstack_init (&constant_pool);
16082 make_cleanup_obstack_free (&constant_pool);
16083 obstack_init (&symtab_obstack);
16084 make_cleanup_obstack_free (&symtab_obstack);
16085 write_hash_table (symtab, &symtab_obstack, &constant_pool);
16087 obstack_init (&contents);
16088 make_cleanup_obstack_free (&contents);
16089 size_of_contents = 6 * sizeof (offset_type);
16090 total_len = size_of_contents;
16092 /* The version number. */
16093 val = MAYBE_SWAP (5);
16094 obstack_grow (&contents, &val, sizeof (val));
16096 /* The offset of the CU list from the start of the file. */
16097 val = MAYBE_SWAP (total_len);
16098 obstack_grow (&contents, &val, sizeof (val));
16099 total_len += obstack_object_size (&cu_list);
16101 /* The offset of the types CU list from the start of the file. */
16102 val = MAYBE_SWAP (total_len);
16103 obstack_grow (&contents, &val, sizeof (val));
16104 total_len += obstack_object_size (&types_cu_list);
16106 /* The offset of the address table from the start of the file. */
16107 val = MAYBE_SWAP (total_len);
16108 obstack_grow (&contents, &val, sizeof (val));
16109 total_len += obstack_object_size (&addr_obstack);
16111 /* The offset of the symbol table from the start of the file. */
16112 val = MAYBE_SWAP (total_len);
16113 obstack_grow (&contents, &val, sizeof (val));
16114 total_len += obstack_object_size (&symtab_obstack);
16116 /* The offset of the constant pool from the start of the file. */
16117 val = MAYBE_SWAP (total_len);
16118 obstack_grow (&contents, &val, sizeof (val));
16119 total_len += obstack_object_size (&constant_pool);
16121 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16123 write_obstack (out_file, &contents);
16124 write_obstack (out_file, &cu_list);
16125 write_obstack (out_file, &types_cu_list);
16126 write_obstack (out_file, &addr_obstack);
16127 write_obstack (out_file, &symtab_obstack);
16128 write_obstack (out_file, &constant_pool);
16132 /* We want to keep the file, so we set cleanup_filename to NULL
16133 here. See unlink_if_set. */
16134 cleanup_filename = NULL;
16136 do_cleanups (cleanup);
16139 /* Implementation of the `save gdb-index' command.
16141 Note that the file format used by this command is documented in the
16142 GDB manual. Any changes here must be documented there. */
16145 save_gdb_index_command (char *arg, int from_tty)
16147 struct objfile *objfile;
16150 error (_("usage: save gdb-index DIRECTORY"));
16152 ALL_OBJFILES (objfile)
16156 /* If the objfile does not correspond to an actual file, skip it. */
16157 if (stat (objfile->name, &st) < 0)
16160 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16161 if (dwarf2_per_objfile)
16163 volatile struct gdb_exception except;
16165 TRY_CATCH (except, RETURN_MASK_ERROR)
16167 write_psymtabs_to_index (objfile, arg);
16169 if (except.reason < 0)
16170 exception_fprintf (gdb_stderr, except,
16171 _("Error while writing index for `%s': "),
16179 int dwarf2_always_disassemble;
16182 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
16183 struct cmd_list_element *c, const char *value)
16185 fprintf_filtered (file,
16186 _("Whether to always disassemble "
16187 "DWARF expressions is %s.\n"),
16191 void _initialize_dwarf2_read (void);
16194 _initialize_dwarf2_read (void)
16196 struct cmd_list_element *c;
16198 dwarf2_objfile_data_key
16199 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
16201 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
16202 Set DWARF 2 specific variables.\n\
16203 Configure DWARF 2 variables such as the cache size"),
16204 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
16205 0/*allow-unknown*/, &maintenance_set_cmdlist);
16207 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
16208 Show DWARF 2 specific variables\n\
16209 Show DWARF 2 variables such as the cache size"),
16210 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
16211 0/*allow-unknown*/, &maintenance_show_cmdlist);
16213 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
16214 &dwarf2_max_cache_age, _("\
16215 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16216 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16217 A higher limit means that cached compilation units will be stored\n\
16218 in memory longer, and more total memory will be used. Zero disables\n\
16219 caching, which can slow down startup."),
16221 show_dwarf2_max_cache_age,
16222 &set_dwarf2_cmdlist,
16223 &show_dwarf2_cmdlist);
16225 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
16226 &dwarf2_always_disassemble, _("\
16227 Set whether `info address' always disassembles DWARF expressions."), _("\
16228 Show whether `info address' always disassembles DWARF expressions."), _("\
16229 When enabled, DWARF expressions are always printed in an assembly-like\n\
16230 syntax. When disabled, expressions will be printed in a more\n\
16231 conversational style, when possible."),
16233 show_dwarf2_always_disassemble,
16234 &set_dwarf2_cmdlist,
16235 &show_dwarf2_cmdlist);
16237 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
16238 Set debugging of the dwarf2 DIE reader."), _("\
16239 Show debugging of the dwarf2 DIE reader."), _("\
16240 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16241 The value is the maximum depth to print."),
16244 &setdebuglist, &showdebuglist);
16246 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
16248 Save a gdb-index file.\n\
16249 Usage: save gdb-index DIRECTORY"),
16251 set_cmd_completer (c, filename_completer);