1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "gdb-demangle.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
50 #include "typeprint.h"
53 #include "exceptions.h"
55 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol *symbolp;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length; /* length of the .debug_info
86 unsigned short version; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
89 unsigned char addr_size; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length; /* byte length of the statement
102 unsigned short version; /* version number -- 2 for DWARF
104 unsigned int prologue_length; /* # bytes between prologue &
106 unsigned char minimum_instruction_length; /* byte size of
108 unsigned char default_is_stmt; /* initial value of is_stmt
111 unsigned char line_range;
112 unsigned char opcode_base; /* number assigned to first special
114 unsigned char *standard_opcode_lengths;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug = 0;
121 /* When non-zero, cross-check physname against demangler. */
122 static int check_physname = 0;
126 /* When set, the file that we're processing is known to have debugging
127 info for C++ namespaces. GCC 3.3.x did not produce this information,
128 but later versions do. */
130 static int processing_has_namespace_info;
132 static const struct objfile_data *dwarf2_objfile_data_key;
134 struct dwarf2_section_info
139 /* Not NULL if the section was actually mmapped. */
141 /* Page aligned size of mmapped area. */
142 bfd_size_type map_len;
143 /* True if we have tried to read this section. */
147 typedef struct dwarf2_section_info dwarf2_section_info_def;
148 DEF_VEC_O (dwarf2_section_info_def);
150 /* All offsets in the index are of this type. It must be
151 architecture-independent. */
152 typedef uint32_t offset_type;
154 DEF_VEC_I (offset_type);
156 /* A description of the mapped index. The file format is described in
157 a comment by the code that writes the index. */
160 /* Index data format version. */
163 /* The total length of the buffer. */
166 /* A pointer to the address table data. */
167 const gdb_byte *address_table;
169 /* Size of the address table data in bytes. */
170 offset_type address_table_size;
172 /* The symbol table, implemented as a hash table. */
173 const offset_type *symbol_table;
175 /* Size in slots, each slot is 2 offset_types. */
176 offset_type symbol_table_slots;
178 /* A pointer to the constant pool. */
179 const char *constant_pool;
182 struct dwarf2_per_objfile
184 struct dwarf2_section_info info;
185 struct dwarf2_section_info abbrev;
186 struct dwarf2_section_info line;
187 struct dwarf2_section_info loc;
188 struct dwarf2_section_info macinfo;
189 struct dwarf2_section_info macro;
190 struct dwarf2_section_info str;
191 struct dwarf2_section_info ranges;
192 struct dwarf2_section_info frame;
193 struct dwarf2_section_info eh_frame;
194 struct dwarf2_section_info gdb_index;
196 VEC (dwarf2_section_info_def) *types;
199 struct objfile *objfile;
201 /* A list of all the compilation units. This is used to locate
202 the target compilation unit of a particular reference. */
203 struct dwarf2_per_cu_data **all_comp_units;
205 /* The number of compilation units in ALL_COMP_UNITS. */
208 /* The number of .debug_types-related CUs. */
209 int n_type_comp_units;
211 /* The .debug_types-related CUs. */
212 struct dwarf2_per_cu_data **type_comp_units;
214 /* A chain of compilation units that are currently read in, so that
215 they can be freed later. */
216 struct dwarf2_per_cu_data *read_in_chain;
218 /* A table mapping .debug_types signatures to its signatured_type entry.
219 This is NULL if the .debug_types section hasn't been read in yet. */
220 htab_t signatured_types;
222 /* A flag indicating wether this objfile has a section loaded at a
224 int has_section_at_zero;
226 /* True if we are using the mapped index,
227 or we are faking it for OBJF_READNOW's sake. */
228 unsigned char using_index;
230 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
231 struct mapped_index *index_table;
233 /* When using index_table, this keeps track of all quick_file_names entries.
234 TUs can share line table entries with CUs or other TUs, and there can be
235 a lot more TUs than unique line tables, so we maintain a separate table
236 of all line table entries to support the sharing. */
237 htab_t quick_file_names_table;
239 /* Set during partial symbol reading, to prevent queueing of full
241 int reading_partial_symbols;
243 /* Table mapping type .debug_info DIE offsets to types.
244 This is NULL if not allocated yet.
245 It (currently) makes sense to allocate debug_types_type_hash lazily.
246 To keep things simple we allocate both lazily. */
247 htab_t debug_info_type_hash;
249 /* Table mapping type .debug_types DIE offsets to types.
250 This is NULL if not allocated yet. */
251 htab_t debug_types_type_hash;
254 static struct dwarf2_per_objfile *dwarf2_per_objfile;
256 /* Default names of the debugging sections. */
258 /* Note that if the debugging section has been compressed, it might
259 have a name like .zdebug_info. */
261 static const struct dwarf2_debug_sections dwarf2_elf_names = {
262 { ".debug_info", ".zdebug_info" },
263 { ".debug_abbrev", ".zdebug_abbrev" },
264 { ".debug_line", ".zdebug_line" },
265 { ".debug_loc", ".zdebug_loc" },
266 { ".debug_macinfo", ".zdebug_macinfo" },
267 { ".debug_macro", ".zdebug_macro" },
268 { ".debug_str", ".zdebug_str" },
269 { ".debug_ranges", ".zdebug_ranges" },
270 { ".debug_types", ".zdebug_types" },
271 { ".debug_frame", ".zdebug_frame" },
272 { ".eh_frame", NULL },
273 { ".gdb_index", ".zgdb_index" },
277 /* local data types */
279 /* We hold several abbreviation tables in memory at the same time. */
280 #ifndef ABBREV_HASH_SIZE
281 #define ABBREV_HASH_SIZE 121
284 /* The data in a compilation unit header, after target2host
285 translation, looks like this. */
286 struct comp_unit_head
290 unsigned char addr_size;
291 unsigned char signed_addr_p;
292 unsigned int abbrev_offset;
294 /* Size of file offsets; either 4 or 8. */
295 unsigned int offset_size;
297 /* Size of the length field; either 4 or 12. */
298 unsigned int initial_length_size;
300 /* Offset to the first byte of this compilation unit header in the
301 .debug_info section, for resolving relative reference dies. */
304 /* Offset to first die in this cu from the start of the cu.
305 This will be the first byte following the compilation unit header. */
306 unsigned int first_die_offset;
309 /* Type used for delaying computation of method physnames.
310 See comments for compute_delayed_physnames. */
311 struct delayed_method_info
313 /* The type to which the method is attached, i.e., its parent class. */
316 /* The index of the method in the type's function fieldlists. */
319 /* The index of the method in the fieldlist. */
322 /* The name of the DIE. */
325 /* The DIE associated with this method. */
326 struct die_info *die;
329 typedef struct delayed_method_info delayed_method_info;
330 DEF_VEC_O (delayed_method_info);
332 /* Internal state when decoding a particular compilation unit. */
335 /* The objfile containing this compilation unit. */
336 struct objfile *objfile;
338 /* The header of the compilation unit. */
339 struct comp_unit_head header;
341 /* Base address of this compilation unit. */
342 CORE_ADDR base_address;
344 /* Non-zero if base_address has been set. */
347 struct function_range *first_fn, *last_fn, *cached_fn;
349 /* The language we are debugging. */
350 enum language language;
351 const struct language_defn *language_defn;
353 const char *producer;
355 /* The generic symbol table building routines have separate lists for
356 file scope symbols and all all other scopes (local scopes). So
357 we need to select the right one to pass to add_symbol_to_list().
358 We do it by keeping a pointer to the correct list in list_in_scope.
360 FIXME: The original dwarf code just treated the file scope as the
361 first local scope, and all other local scopes as nested local
362 scopes, and worked fine. Check to see if we really need to
363 distinguish these in buildsym.c. */
364 struct pending **list_in_scope;
366 /* DWARF abbreviation table associated with this compilation unit. */
367 struct abbrev_info **dwarf2_abbrevs;
369 /* Storage for the abbrev table. */
370 struct obstack abbrev_obstack;
372 /* Hash table holding all the loaded partial DIEs. */
375 /* Storage for things with the same lifetime as this read-in compilation
376 unit, including partial DIEs. */
377 struct obstack comp_unit_obstack;
379 /* When multiple dwarf2_cu structures are living in memory, this field
380 chains them all together, so that they can be released efficiently.
381 We will probably also want a generation counter so that most-recently-used
382 compilation units are cached... */
383 struct dwarf2_per_cu_data *read_in_chain;
385 /* Backchain to our per_cu entry if the tree has been built. */
386 struct dwarf2_per_cu_data *per_cu;
388 /* How many compilation units ago was this CU last referenced? */
391 /* A hash table of die offsets for following references. */
394 /* Full DIEs if read in. */
395 struct die_info *dies;
397 /* A set of pointers to dwarf2_per_cu_data objects for compilation
398 units referenced by this one. Only set during full symbol processing;
399 partial symbol tables do not have dependencies. */
402 /* Header data from the line table, during full symbol processing. */
403 struct line_header *line_header;
405 /* A list of methods which need to have physnames computed
406 after all type information has been read. */
407 VEC (delayed_method_info) *method_list;
409 /* To be copied to symtab->call_site_htab. */
410 htab_t call_site_htab;
412 /* Mark used when releasing cached dies. */
413 unsigned int mark : 1;
415 /* This flag will be set if this compilation unit might include
416 inter-compilation-unit references. */
417 unsigned int has_form_ref_addr : 1;
419 /* This flag will be set if this compilation unit includes any
420 DW_TAG_namespace DIEs. If we know that there are explicit
421 DIEs for namespaces, we don't need to try to infer them
422 from mangled names. */
423 unsigned int has_namespace_info : 1;
425 /* This CU references .debug_loc. See the symtab->locations_valid field.
426 This test is imperfect as there may exist optimized debug code not using
427 any location list and still facing inlining issues if handled as
428 unoptimized code. For a future better test see GCC PR other/32998. */
430 unsigned int has_loclist : 1;
433 /* Persistent data held for a compilation unit, even when not
434 processing it. We put a pointer to this structure in the
435 read_symtab_private field of the psymtab. If we encounter
436 inter-compilation-unit references, we also maintain a sorted
437 list of all compilation units. */
439 struct dwarf2_per_cu_data
441 /* The start offset and length of this compilation unit. 2**29-1
442 bytes should suffice to store the length of any compilation unit
443 - if it doesn't, GDB will fall over anyway.
444 NOTE: Unlike comp_unit_head.length, this length includes
445 initial_length_size. */
447 unsigned int length : 29;
449 /* Flag indicating this compilation unit will be read in before
450 any of the current compilation units are processed. */
451 unsigned int queued : 1;
453 /* This flag will be set if we need to load absolutely all DIEs
454 for this compilation unit, instead of just the ones we think
455 are interesting. It gets set if we look for a DIE in the
456 hash table and don't find it. */
457 unsigned int load_all_dies : 1;
459 /* Non-null if this CU is from .debug_types; in which case it points
460 to the section. Otherwise it's from .debug_info. */
461 struct dwarf2_section_info *debug_types_section;
463 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
464 of the CU cache it gets reset to NULL again. */
465 struct dwarf2_cu *cu;
467 /* The corresponding objfile. */
468 struct objfile *objfile;
470 /* When using partial symbol tables, the 'psymtab' field is active.
471 Otherwise the 'quick' field is active. */
474 /* The partial symbol table associated with this compilation unit,
475 or NULL for partial units (which do not have an associated
477 struct partial_symtab *psymtab;
479 /* Data needed by the "quick" functions. */
480 struct dwarf2_per_cu_quick_data *quick;
484 /* Entry in the signatured_types hash table. */
486 struct signatured_type
490 /* Offset in .debug_types of the type defined by this TU. */
491 unsigned int type_offset;
493 /* The CU(/TU) of this type. */
494 struct dwarf2_per_cu_data per_cu;
497 /* Struct used to pass misc. parameters to read_die_and_children, et
498 al. which are used for both .debug_info and .debug_types dies.
499 All parameters here are unchanging for the life of the call. This
500 struct exists to abstract away the constant parameters of die
503 struct die_reader_specs
505 /* The bfd of this objfile. */
508 /* The CU of the DIE we are parsing. */
509 struct dwarf2_cu *cu;
511 /* Pointer to start of section buffer.
512 This is either the start of .debug_info or .debug_types. */
513 const gdb_byte *buffer;
516 /* The line number information for a compilation unit (found in the
517 .debug_line section) begins with a "statement program header",
518 which contains the following information. */
521 unsigned int total_length;
522 unsigned short version;
523 unsigned int header_length;
524 unsigned char minimum_instruction_length;
525 unsigned char maximum_ops_per_instruction;
526 unsigned char default_is_stmt;
528 unsigned char line_range;
529 unsigned char opcode_base;
531 /* standard_opcode_lengths[i] is the number of operands for the
532 standard opcode whose value is i. This means that
533 standard_opcode_lengths[0] is unused, and the last meaningful
534 element is standard_opcode_lengths[opcode_base - 1]. */
535 unsigned char *standard_opcode_lengths;
537 /* The include_directories table. NOTE! These strings are not
538 allocated with xmalloc; instead, they are pointers into
539 debug_line_buffer. If you try to free them, `free' will get
541 unsigned int num_include_dirs, include_dirs_size;
544 /* The file_names table. NOTE! These strings are not allocated
545 with xmalloc; instead, they are pointers into debug_line_buffer.
546 Don't try to free them directly. */
547 unsigned int num_file_names, file_names_size;
551 unsigned int dir_index;
552 unsigned int mod_time;
554 int included_p; /* Non-zero if referenced by the Line Number Program. */
555 struct symtab *symtab; /* The associated symbol table, if any. */
558 /* The start and end of the statement program following this
559 header. These point into dwarf2_per_objfile->line_buffer. */
560 gdb_byte *statement_program_start, *statement_program_end;
563 /* When we construct a partial symbol table entry we only
564 need this much information. */
565 struct partial_die_info
567 /* Offset of this DIE. */
570 /* DWARF-2 tag for this DIE. */
571 ENUM_BITFIELD(dwarf_tag) tag : 16;
573 /* Assorted flags describing the data found in this DIE. */
574 unsigned int has_children : 1;
575 unsigned int is_external : 1;
576 unsigned int is_declaration : 1;
577 unsigned int has_type : 1;
578 unsigned int has_specification : 1;
579 unsigned int has_pc_info : 1;
581 /* Flag set if the SCOPE field of this structure has been
583 unsigned int scope_set : 1;
585 /* Flag set if the DIE has a byte_size attribute. */
586 unsigned int has_byte_size : 1;
588 /* Flag set if any of the DIE's children are template arguments. */
589 unsigned int has_template_arguments : 1;
591 /* Flag set if fixup_partial_die has been called on this die. */
592 unsigned int fixup_called : 1;
594 /* The name of this DIE. Normally the value of DW_AT_name, but
595 sometimes a default name for unnamed DIEs. */
598 /* The linkage name, if present. */
599 const char *linkage_name;
601 /* The scope to prepend to our children. This is generally
602 allocated on the comp_unit_obstack, so will disappear
603 when this compilation unit leaves the cache. */
606 /* The location description associated with this DIE, if any. */
607 struct dwarf_block *locdesc;
609 /* If HAS_PC_INFO, the PC range associated with this DIE. */
613 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
614 DW_AT_sibling, if any. */
615 /* NOTE: This member isn't strictly necessary, read_partial_die could
616 return DW_AT_sibling values to its caller load_partial_dies. */
619 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
620 DW_AT_specification (or DW_AT_abstract_origin or
622 unsigned int spec_offset;
624 /* Pointers to this DIE's parent, first child, and next sibling,
626 struct partial_die_info *die_parent, *die_child, *die_sibling;
629 /* This data structure holds the information of an abbrev. */
632 unsigned int number; /* number identifying abbrev */
633 enum dwarf_tag tag; /* dwarf tag */
634 unsigned short has_children; /* boolean */
635 unsigned short num_attrs; /* number of attributes */
636 struct attr_abbrev *attrs; /* an array of attribute descriptions */
637 struct abbrev_info *next; /* next in chain */
642 ENUM_BITFIELD(dwarf_attribute) name : 16;
643 ENUM_BITFIELD(dwarf_form) form : 16;
646 /* Attributes have a name and a value. */
649 ENUM_BITFIELD(dwarf_attribute) name : 16;
650 ENUM_BITFIELD(dwarf_form) form : 15;
652 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
653 field should be in u.str (existing only for DW_STRING) but it is kept
654 here for better struct attribute alignment. */
655 unsigned int string_is_canonical : 1;
660 struct dwarf_block *blk;
664 struct signatured_type *signatured_type;
669 /* This data structure holds a complete die structure. */
672 /* DWARF-2 tag for this DIE. */
673 ENUM_BITFIELD(dwarf_tag) tag : 16;
675 /* Number of attributes */
676 unsigned char num_attrs;
678 /* True if we're presently building the full type name for the
679 type derived from this DIE. */
680 unsigned char building_fullname : 1;
685 /* Offset in .debug_info or .debug_types section. */
688 /* The dies in a compilation unit form an n-ary tree. PARENT
689 points to this die's parent; CHILD points to the first child of
690 this node; and all the children of a given node are chained
691 together via their SIBLING fields. */
692 struct die_info *child; /* Its first child, if any. */
693 struct die_info *sibling; /* Its next sibling, if any. */
694 struct die_info *parent; /* Its parent, if any. */
696 /* An array of attributes, with NUM_ATTRS elements. There may be
697 zero, but it's not common and zero-sized arrays are not
698 sufficiently portable C. */
699 struct attribute attrs[1];
702 struct function_range
705 CORE_ADDR lowpc, highpc;
707 struct function_range *next;
710 /* Get at parts of an attribute structure. */
712 #define DW_STRING(attr) ((attr)->u.str)
713 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
714 #define DW_UNSND(attr) ((attr)->u.unsnd)
715 #define DW_BLOCK(attr) ((attr)->u.blk)
716 #define DW_SND(attr) ((attr)->u.snd)
717 #define DW_ADDR(attr) ((attr)->u.addr)
718 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
720 /* Blocks are a bunch of untyped bytes. */
725 /* Valid only if SIZE is not zero. */
729 #ifndef ATTR_ALLOC_CHUNK
730 #define ATTR_ALLOC_CHUNK 4
733 /* Allocate fields for structs, unions and enums in this size. */
734 #ifndef DW_FIELD_ALLOC_CHUNK
735 #define DW_FIELD_ALLOC_CHUNK 4
738 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
739 but this would require a corresponding change in unpack_field_as_long
741 static int bits_per_byte = 8;
743 /* The routines that read and process dies for a C struct or C++ class
744 pass lists of data member fields and lists of member function fields
745 in an instance of a field_info structure, as defined below. */
748 /* List of data member and baseclasses fields. */
751 struct nextfield *next;
756 *fields, *baseclasses;
758 /* Number of fields (including baseclasses). */
761 /* Number of baseclasses. */
764 /* Set if the accesibility of one of the fields is not public. */
765 int non_public_fields;
767 /* Member function fields array, entries are allocated in the order they
768 are encountered in the object file. */
771 struct nextfnfield *next;
772 struct fn_field fnfield;
776 /* Member function fieldlist array, contains name of possibly overloaded
777 member function, number of overloaded member functions and a pointer
778 to the head of the member function field chain. */
783 struct nextfnfield *head;
787 /* Number of entries in the fnfieldlists array. */
790 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
791 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
792 struct typedef_field_list
794 struct typedef_field field;
795 struct typedef_field_list *next;
798 unsigned typedef_field_list_count;
801 /* One item on the queue of compilation units to read in full symbols
803 struct dwarf2_queue_item
805 struct dwarf2_per_cu_data *per_cu;
806 struct dwarf2_queue_item *next;
809 /* The current queue. */
810 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
812 /* Loaded secondary compilation units are kept in memory until they
813 have not been referenced for the processing of this many
814 compilation units. Set this to zero to disable caching. Cache
815 sizes of up to at least twenty will improve startup time for
816 typical inter-CU-reference binaries, at an obvious memory cost. */
817 static int dwarf2_max_cache_age = 5;
819 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
820 struct cmd_list_element *c, const char *value)
822 fprintf_filtered (file, _("The upper bound on the age of cached "
823 "dwarf2 compilation units is %s.\n"),
828 /* Various complaints about symbol reading that don't abort the process. */
831 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
833 complaint (&symfile_complaints,
834 _("statement list doesn't fit in .debug_line section"));
838 dwarf2_debug_line_missing_file_complaint (void)
840 complaint (&symfile_complaints,
841 _(".debug_line section has line data without a file"));
845 dwarf2_debug_line_missing_end_sequence_complaint (void)
847 complaint (&symfile_complaints,
848 _(".debug_line section has line "
849 "program sequence without an end"));
853 dwarf2_complex_location_expr_complaint (void)
855 complaint (&symfile_complaints, _("location expression too complex"));
859 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
862 complaint (&symfile_complaints,
863 _("const value length mismatch for '%s', got %d, expected %d"),
868 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
870 complaint (&symfile_complaints,
871 _("macro info runs off end of `%s' section"),
872 section->asection->name);
876 dwarf2_macro_malformed_definition_complaint (const char *arg1)
878 complaint (&symfile_complaints,
879 _("macro debug info contains a "
880 "malformed macro definition:\n`%s'"),
885 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
887 complaint (&symfile_complaints,
888 _("invalid attribute class or form for '%s' in '%s'"),
892 /* local function prototypes */
894 static void dwarf2_locate_sections (bfd *, asection *, void *);
896 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
899 static void dwarf2_find_base_address (struct die_info *die,
900 struct dwarf2_cu *cu);
902 static void dwarf2_build_psymtabs_hard (struct objfile *);
904 static void scan_partial_symbols (struct partial_die_info *,
905 CORE_ADDR *, CORE_ADDR *,
906 int, struct dwarf2_cu *);
908 static void add_partial_symbol (struct partial_die_info *,
911 static void add_partial_namespace (struct partial_die_info *pdi,
912 CORE_ADDR *lowpc, CORE_ADDR *highpc,
913 int need_pc, struct dwarf2_cu *cu);
915 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
916 CORE_ADDR *highpc, int need_pc,
917 struct dwarf2_cu *cu);
919 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
920 struct dwarf2_cu *cu);
922 static void add_partial_subprogram (struct partial_die_info *pdi,
923 CORE_ADDR *lowpc, CORE_ADDR *highpc,
924 int need_pc, struct dwarf2_cu *cu);
926 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
927 gdb_byte *buffer, gdb_byte *info_ptr,
928 bfd *abfd, struct dwarf2_cu *cu);
930 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
932 static void psymtab_to_symtab_1 (struct partial_symtab *);
934 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
936 static void dwarf2_free_abbrev_table (void *);
938 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
940 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
943 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
946 static struct partial_die_info *load_partial_dies (bfd *,
947 gdb_byte *, gdb_byte *,
948 int, struct dwarf2_cu *);
950 static gdb_byte *read_partial_die (struct partial_die_info *,
951 struct abbrev_info *abbrev,
953 gdb_byte *, gdb_byte *,
956 static struct partial_die_info *find_partial_die (unsigned int,
959 static void fixup_partial_die (struct partial_die_info *,
962 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
963 bfd *, gdb_byte *, struct dwarf2_cu *);
965 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
966 bfd *, gdb_byte *, struct dwarf2_cu *);
968 static unsigned int read_1_byte (bfd *, gdb_byte *);
970 static int read_1_signed_byte (bfd *, gdb_byte *);
972 static unsigned int read_2_bytes (bfd *, gdb_byte *);
974 static unsigned int read_4_bytes (bfd *, gdb_byte *);
976 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
978 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
981 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
983 static LONGEST read_checked_initial_length_and_offset
984 (bfd *, gdb_byte *, const struct comp_unit_head *,
985 unsigned int *, unsigned int *);
987 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
990 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
992 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
994 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
996 static char *read_indirect_string (bfd *, gdb_byte *,
997 const struct comp_unit_head *,
1000 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
1002 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
1004 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
1006 static void set_cu_language (unsigned int, struct dwarf2_cu *);
1008 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
1009 struct dwarf2_cu *);
1011 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
1013 struct dwarf2_cu *);
1015 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
1016 struct dwarf2_cu *cu);
1018 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
1020 static struct die_info *die_specification (struct die_info *die,
1021 struct dwarf2_cu **);
1023 static void free_line_header (struct line_header *lh);
1025 static void add_file_name (struct line_header *, char *, unsigned int,
1026 unsigned int, unsigned int);
1028 static struct line_header *(dwarf_decode_line_header
1029 (unsigned int offset,
1030 bfd *abfd, struct dwarf2_cu *cu));
1032 static void dwarf_decode_lines (struct line_header *, const char *,
1033 struct dwarf2_cu *, struct partial_symtab *,
1036 static void dwarf2_start_subfile (char *, const char *, const char *);
1038 static struct symbol *new_symbol (struct die_info *, struct type *,
1039 struct dwarf2_cu *);
1041 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1042 struct dwarf2_cu *, struct symbol *);
1044 static void dwarf2_const_value (struct attribute *, struct symbol *,
1045 struct dwarf2_cu *);
1047 static void dwarf2_const_value_attr (struct attribute *attr,
1050 struct obstack *obstack,
1051 struct dwarf2_cu *cu, long *value,
1053 struct dwarf2_locexpr_baton **baton);
1055 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1057 static int need_gnat_info (struct dwarf2_cu *);
1059 static struct type *die_descriptive_type (struct die_info *,
1060 struct dwarf2_cu *);
1062 static void set_descriptive_type (struct type *, struct die_info *,
1063 struct dwarf2_cu *);
1065 static struct type *die_containing_type (struct die_info *,
1066 struct dwarf2_cu *);
1068 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1069 struct dwarf2_cu *);
1071 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1073 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1075 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1077 static char *typename_concat (struct obstack *obs, const char *prefix,
1078 const char *suffix, int physname,
1079 struct dwarf2_cu *cu);
1081 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1083 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1085 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1087 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1089 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1091 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1092 struct dwarf2_cu *, struct partial_symtab *);
1094 static int dwarf2_get_pc_bounds (struct die_info *,
1095 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1096 struct partial_symtab *);
1098 static void get_scope_pc_bounds (struct die_info *,
1099 CORE_ADDR *, CORE_ADDR *,
1100 struct dwarf2_cu *);
1102 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1103 CORE_ADDR, struct dwarf2_cu *);
1105 static void dwarf2_add_field (struct field_info *, struct die_info *,
1106 struct dwarf2_cu *);
1108 static void dwarf2_attach_fields_to_type (struct field_info *,
1109 struct type *, struct dwarf2_cu *);
1111 static void dwarf2_add_member_fn (struct field_info *,
1112 struct die_info *, struct type *,
1113 struct dwarf2_cu *);
1115 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1117 struct dwarf2_cu *);
1119 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1121 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1123 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1125 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1127 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1129 static struct type *read_module_type (struct die_info *die,
1130 struct dwarf2_cu *cu);
1132 static const char *namespace_name (struct die_info *die,
1133 int *is_anonymous, struct dwarf2_cu *);
1135 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1137 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1139 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1140 struct dwarf2_cu *);
1142 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1144 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1146 gdb_byte **new_info_ptr,
1147 struct die_info *parent);
1149 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1151 gdb_byte **new_info_ptr,
1152 struct die_info *parent);
1154 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1156 gdb_byte **new_info_ptr,
1157 struct die_info *parent);
1159 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1160 struct die_info **, gdb_byte *,
1163 static void process_die (struct die_info *, struct dwarf2_cu *);
1165 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1168 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1170 static const char *dwarf2_full_name (char *name,
1171 struct die_info *die,
1172 struct dwarf2_cu *cu);
1174 static struct die_info *dwarf2_extension (struct die_info *die,
1175 struct dwarf2_cu **);
1177 static char *dwarf_tag_name (unsigned int);
1179 static char *dwarf_attr_name (unsigned int);
1181 static char *dwarf_form_name (unsigned int);
1183 static char *dwarf_bool_name (unsigned int);
1185 static char *dwarf_type_encoding_name (unsigned int);
1188 static char *dwarf_cfi_name (unsigned int);
1191 static struct die_info *sibling_die (struct die_info *);
1193 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1195 static void dump_die_for_error (struct die_info *);
1197 static void dump_die_1 (struct ui_file *, int level, int max_level,
1200 /*static*/ void dump_die (struct die_info *, int max_level);
1202 static void store_in_ref_table (struct die_info *,
1203 struct dwarf2_cu *);
1205 static int is_ref_attr (struct attribute *);
1207 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1209 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1211 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1213 struct dwarf2_cu **);
1215 static struct die_info *follow_die_ref (struct die_info *,
1217 struct dwarf2_cu **);
1219 static struct die_info *follow_die_sig (struct die_info *,
1221 struct dwarf2_cu **);
1223 static struct signatured_type *lookup_signatured_type_at_offset
1224 (struct objfile *objfile,
1225 struct dwarf2_section_info *section,
1226 unsigned int offset);
1228 static void read_signatured_type_at_offset (struct objfile *objfile,
1229 struct dwarf2_section_info *sect,
1230 unsigned int offset);
1232 static void read_signatured_type (struct objfile *,
1233 struct signatured_type *type_sig);
1235 /* memory allocation interface */
1237 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1239 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1241 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1243 static void initialize_cu_func_list (struct dwarf2_cu *);
1245 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1246 struct dwarf2_cu *);
1248 static void dwarf_decode_macros (struct line_header *, unsigned int,
1249 char *, bfd *, struct dwarf2_cu *,
1250 struct dwarf2_section_info *,
1253 static int attr_form_is_block (struct attribute *);
1255 static int attr_form_is_section_offset (struct attribute *);
1257 static int attr_form_is_constant (struct attribute *);
1259 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1260 struct dwarf2_loclist_baton *baton,
1261 struct attribute *attr);
1263 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1265 struct dwarf2_cu *cu);
1267 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1268 struct abbrev_info *abbrev,
1269 struct dwarf2_cu *cu);
1271 static void free_stack_comp_unit (void *);
1273 static hashval_t partial_die_hash (const void *item);
1275 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1277 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1278 (unsigned int offset, struct objfile *objfile);
1280 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1281 (unsigned int offset, struct objfile *objfile);
1283 static void init_one_comp_unit (struct dwarf2_cu *cu,
1284 struct objfile *objfile);
1286 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1287 struct die_info *comp_unit_die);
1289 static void free_one_comp_unit (void *);
1291 static void free_cached_comp_units (void *);
1293 static void age_cached_comp_units (void);
1295 static void free_one_cached_comp_unit (void *);
1297 static struct type *set_die_type (struct die_info *, struct type *,
1298 struct dwarf2_cu *);
1300 static void create_all_comp_units (struct objfile *);
1302 static int create_debug_types_hash_table (struct objfile *objfile);
1304 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1307 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1309 static void dwarf2_add_dependence (struct dwarf2_cu *,
1310 struct dwarf2_per_cu_data *);
1312 static void dwarf2_mark (struct dwarf2_cu *);
1314 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1316 static struct type *get_die_type_at_offset (unsigned int,
1317 struct dwarf2_per_cu_data *per_cu);
1319 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1321 static void dwarf2_release_queue (void *dummy);
1323 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1324 struct objfile *objfile);
1326 static void process_queue (struct objfile *objfile);
1328 static void find_file_and_directory (struct die_info *die,
1329 struct dwarf2_cu *cu,
1330 char **name, char **comp_dir);
1332 static char *file_full_name (int file, struct line_header *lh,
1333 const char *comp_dir);
1335 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1338 unsigned int buffer_size,
1340 int is_debug_types_section);
1342 static void init_cu_die_reader (struct die_reader_specs *reader,
1343 struct dwarf2_cu *cu);
1345 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1349 /* Convert VALUE between big- and little-endian. */
1351 byte_swap (offset_type value)
1355 result = (value & 0xff) << 24;
1356 result |= (value & 0xff00) << 8;
1357 result |= (value & 0xff0000) >> 8;
1358 result |= (value & 0xff000000) >> 24;
1362 #define MAYBE_SWAP(V) byte_swap (V)
1365 #define MAYBE_SWAP(V) (V)
1366 #endif /* WORDS_BIGENDIAN */
1368 /* The suffix for an index file. */
1369 #define INDEX_SUFFIX ".gdb-index"
1371 static const char *dwarf2_physname (char *name, struct die_info *die,
1372 struct dwarf2_cu *cu);
1374 /* Try to locate the sections we need for DWARF 2 debugging
1375 information and return true if we have enough to do something.
1376 NAMES points to the dwarf2 section names, or is NULL if the standard
1377 ELF names are used. */
1380 dwarf2_has_info (struct objfile *objfile,
1381 const struct dwarf2_debug_sections *names)
1383 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1384 if (!dwarf2_per_objfile)
1386 /* Initialize per-objfile state. */
1387 struct dwarf2_per_objfile *data
1388 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1390 memset (data, 0, sizeof (*data));
1391 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1392 dwarf2_per_objfile = data;
1394 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1396 dwarf2_per_objfile->objfile = objfile;
1398 return (dwarf2_per_objfile->info.asection != NULL
1399 && dwarf2_per_objfile->abbrev.asection != NULL);
1402 /* When loading sections, we look either for uncompressed section or for
1403 compressed section names. */
1406 section_is_p (const char *section_name,
1407 const struct dwarf2_section_names *names)
1409 if (names->normal != NULL
1410 && strcmp (section_name, names->normal) == 0)
1412 if (names->compressed != NULL
1413 && strcmp (section_name, names->compressed) == 0)
1418 /* This function is mapped across the sections and remembers the
1419 offset and size of each of the debugging sections we are interested
1423 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1425 const struct dwarf2_debug_sections *names;
1428 names = &dwarf2_elf_names;
1430 names = (const struct dwarf2_debug_sections *) vnames;
1432 if (section_is_p (sectp->name, &names->info))
1434 dwarf2_per_objfile->info.asection = sectp;
1435 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1437 else if (section_is_p (sectp->name, &names->abbrev))
1439 dwarf2_per_objfile->abbrev.asection = sectp;
1440 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1442 else if (section_is_p (sectp->name, &names->line))
1444 dwarf2_per_objfile->line.asection = sectp;
1445 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1447 else if (section_is_p (sectp->name, &names->loc))
1449 dwarf2_per_objfile->loc.asection = sectp;
1450 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1452 else if (section_is_p (sectp->name, &names->macinfo))
1454 dwarf2_per_objfile->macinfo.asection = sectp;
1455 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1457 else if (section_is_p (sectp->name, &names->macro))
1459 dwarf2_per_objfile->macro.asection = sectp;
1460 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1462 else if (section_is_p (sectp->name, &names->str))
1464 dwarf2_per_objfile->str.asection = sectp;
1465 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1467 else if (section_is_p (sectp->name, &names->frame))
1469 dwarf2_per_objfile->frame.asection = sectp;
1470 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1472 else if (section_is_p (sectp->name, &names->eh_frame))
1474 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1476 if (aflag & SEC_HAS_CONTENTS)
1478 dwarf2_per_objfile->eh_frame.asection = sectp;
1479 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1482 else if (section_is_p (sectp->name, &names->ranges))
1484 dwarf2_per_objfile->ranges.asection = sectp;
1485 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1487 else if (section_is_p (sectp->name, &names->types))
1489 struct dwarf2_section_info type_section;
1491 memset (&type_section, 0, sizeof (type_section));
1492 type_section.asection = sectp;
1493 type_section.size = bfd_get_section_size (sectp);
1495 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1498 else if (section_is_p (sectp->name, &names->gdb_index))
1500 dwarf2_per_objfile->gdb_index.asection = sectp;
1501 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1504 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1505 && bfd_section_vma (abfd, sectp) == 0)
1506 dwarf2_per_objfile->has_section_at_zero = 1;
1509 /* Decompress a section that was compressed using zlib. Store the
1510 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1513 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1514 gdb_byte **outbuf, bfd_size_type *outsize)
1516 bfd *abfd = objfile->obfd;
1518 error (_("Support for zlib-compressed DWARF data (from '%s') "
1519 "is disabled in this copy of GDB"),
1520 bfd_get_filename (abfd));
1522 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1523 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1524 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1525 bfd_size_type uncompressed_size;
1526 gdb_byte *uncompressed_buffer;
1529 int header_size = 12;
1531 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1532 || bfd_bread (compressed_buffer,
1533 compressed_size, abfd) != compressed_size)
1534 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1535 bfd_get_filename (abfd));
1537 /* Read the zlib header. In this case, it should be "ZLIB" followed
1538 by the uncompressed section size, 8 bytes in big-endian order. */
1539 if (compressed_size < header_size
1540 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1541 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1542 bfd_get_filename (abfd));
1543 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1544 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1545 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1546 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1547 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1548 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1549 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1550 uncompressed_size += compressed_buffer[11];
1552 /* It is possible the section consists of several compressed
1553 buffers concatenated together, so we uncompress in a loop. */
1557 strm.avail_in = compressed_size - header_size;
1558 strm.next_in = (Bytef*) compressed_buffer + header_size;
1559 strm.avail_out = uncompressed_size;
1560 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1562 rc = inflateInit (&strm);
1563 while (strm.avail_in > 0)
1566 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1567 bfd_get_filename (abfd), rc);
1568 strm.next_out = ((Bytef*) uncompressed_buffer
1569 + (uncompressed_size - strm.avail_out));
1570 rc = inflate (&strm, Z_FINISH);
1571 if (rc != Z_STREAM_END)
1572 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1573 bfd_get_filename (abfd), rc);
1574 rc = inflateReset (&strm);
1576 rc = inflateEnd (&strm);
1578 || strm.avail_out != 0)
1579 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1580 bfd_get_filename (abfd), rc);
1582 do_cleanups (cleanup);
1583 *outbuf = uncompressed_buffer;
1584 *outsize = uncompressed_size;
1588 /* A helper function that decides whether a section is empty. */
1591 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1593 return info->asection == NULL || info->size == 0;
1596 /* Read the contents of the section SECTP from object file specified by
1597 OBJFILE, store info about the section into INFO.
1598 If the section is compressed, uncompress it before returning. */
1601 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1603 bfd *abfd = objfile->obfd;
1604 asection *sectp = info->asection;
1605 gdb_byte *buf, *retbuf;
1606 unsigned char header[4];
1610 info->buffer = NULL;
1611 info->map_addr = NULL;
1614 if (dwarf2_section_empty_p (info))
1617 /* Check if the file has a 4-byte header indicating compression. */
1618 if (info->size > sizeof (header)
1619 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1620 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1622 /* Upon decompression, update the buffer and its size. */
1623 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1625 zlib_decompress_section (objfile, sectp, &info->buffer,
1633 pagesize = getpagesize ();
1635 /* Only try to mmap sections which are large enough: we don't want to
1636 waste space due to fragmentation. Also, only try mmap for sections
1637 without relocations. */
1639 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1641 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1642 MAP_PRIVATE, sectp->filepos,
1643 &info->map_addr, &info->map_len);
1645 if ((caddr_t)info->buffer != MAP_FAILED)
1647 #if HAVE_POSIX_MADVISE
1648 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1655 /* If we get here, we are a normal, not-compressed section. */
1657 = obstack_alloc (&objfile->objfile_obstack, info->size);
1659 /* When debugging .o files, we may need to apply relocations; see
1660 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1661 We never compress sections in .o files, so we only need to
1662 try this when the section is not compressed. */
1663 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1666 info->buffer = retbuf;
1670 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1671 || bfd_bread (buf, info->size, abfd) != info->size)
1672 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1673 bfd_get_filename (abfd));
1676 /* A helper function that returns the size of a section in a safe way.
1677 If you are positive that the section has been read before using the
1678 size, then it is safe to refer to the dwarf2_section_info object's
1679 "size" field directly. In other cases, you must call this
1680 function, because for compressed sections the size field is not set
1681 correctly until the section has been read. */
1683 static bfd_size_type
1684 dwarf2_section_size (struct objfile *objfile,
1685 struct dwarf2_section_info *info)
1688 dwarf2_read_section (objfile, info);
1692 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1696 dwarf2_get_section_info (struct objfile *objfile,
1697 enum dwarf2_section_enum sect,
1698 asection **sectp, gdb_byte **bufp,
1699 bfd_size_type *sizep)
1701 struct dwarf2_per_objfile *data
1702 = objfile_data (objfile, dwarf2_objfile_data_key);
1703 struct dwarf2_section_info *info;
1705 /* We may see an objfile without any DWARF, in which case we just
1716 case DWARF2_DEBUG_FRAME:
1717 info = &data->frame;
1719 case DWARF2_EH_FRAME:
1720 info = &data->eh_frame;
1723 gdb_assert_not_reached ("unexpected section");
1726 dwarf2_read_section (objfile, info);
1728 *sectp = info->asection;
1729 *bufp = info->buffer;
1730 *sizep = info->size;
1734 /* DWARF quick_symbols_functions support. */
1736 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1737 unique line tables, so we maintain a separate table of all .debug_line
1738 derived entries to support the sharing.
1739 All the quick functions need is the list of file names. We discard the
1740 line_header when we're done and don't need to record it here. */
1741 struct quick_file_names
1743 /* The offset in .debug_line of the line table. We hash on this. */
1744 unsigned int offset;
1746 /* The number of entries in file_names, real_names. */
1747 unsigned int num_file_names;
1749 /* The file names from the line table, after being run through
1751 const char **file_names;
1753 /* The file names from the line table after being run through
1754 gdb_realpath. These are computed lazily. */
1755 const char **real_names;
1758 /* When using the index (and thus not using psymtabs), each CU has an
1759 object of this type. This is used to hold information needed by
1760 the various "quick" methods. */
1761 struct dwarf2_per_cu_quick_data
1763 /* The file table. This can be NULL if there was no file table
1764 or it's currently not read in.
1765 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1766 struct quick_file_names *file_names;
1768 /* The corresponding symbol table. This is NULL if symbols for this
1769 CU have not yet been read. */
1770 struct symtab *symtab;
1772 /* A temporary mark bit used when iterating over all CUs in
1773 expand_symtabs_matching. */
1774 unsigned int mark : 1;
1776 /* True if we've tried to read the file table and found there isn't one.
1777 There will be no point in trying to read it again next time. */
1778 unsigned int no_file_data : 1;
1781 /* Hash function for a quick_file_names. */
1784 hash_file_name_entry (const void *e)
1786 const struct quick_file_names *file_data = e;
1788 return file_data->offset;
1791 /* Equality function for a quick_file_names. */
1794 eq_file_name_entry (const void *a, const void *b)
1796 const struct quick_file_names *ea = a;
1797 const struct quick_file_names *eb = b;
1799 return ea->offset == eb->offset;
1802 /* Delete function for a quick_file_names. */
1805 delete_file_name_entry (void *e)
1807 struct quick_file_names *file_data = e;
1810 for (i = 0; i < file_data->num_file_names; ++i)
1812 xfree ((void*) file_data->file_names[i]);
1813 if (file_data->real_names)
1814 xfree ((void*) file_data->real_names[i]);
1817 /* The space for the struct itself lives on objfile_obstack,
1818 so we don't free it here. */
1821 /* Create a quick_file_names hash table. */
1824 create_quick_file_names_table (unsigned int nr_initial_entries)
1826 return htab_create_alloc (nr_initial_entries,
1827 hash_file_name_entry, eq_file_name_entry,
1828 delete_file_name_entry, xcalloc, xfree);
1831 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1832 have to be created afterwards. You should call age_cached_comp_units after
1833 processing PER_CU->CU. dw2_setup must have been already called. */
1836 load_cu (struct dwarf2_per_cu_data *per_cu)
1838 if (per_cu->debug_types_section)
1839 read_signatured_type_at_offset (per_cu->objfile,
1840 per_cu->debug_types_section,
1843 load_full_comp_unit (per_cu, per_cu->objfile);
1845 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1847 gdb_assert (per_cu->cu != NULL);
1850 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1854 dw2_do_instantiate_symtab (struct objfile *objfile,
1855 struct dwarf2_per_cu_data *per_cu)
1857 struct cleanup *back_to;
1859 back_to = make_cleanup (dwarf2_release_queue, NULL);
1861 queue_comp_unit (per_cu, objfile);
1865 process_queue (objfile);
1867 /* Age the cache, releasing compilation units that have not
1868 been used recently. */
1869 age_cached_comp_units ();
1871 do_cleanups (back_to);
1874 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1875 the objfile from which this CU came. Returns the resulting symbol
1878 static struct symtab *
1879 dw2_instantiate_symtab (struct objfile *objfile,
1880 struct dwarf2_per_cu_data *per_cu)
1882 if (!per_cu->v.quick->symtab)
1884 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1885 increment_reading_symtab ();
1886 dw2_do_instantiate_symtab (objfile, per_cu);
1887 do_cleanups (back_to);
1889 return per_cu->v.quick->symtab;
1892 /* Return the CU given its index. */
1894 static struct dwarf2_per_cu_data *
1895 dw2_get_cu (int index)
1897 if (index >= dwarf2_per_objfile->n_comp_units)
1899 index -= dwarf2_per_objfile->n_comp_units;
1900 return dwarf2_per_objfile->type_comp_units[index];
1902 return dwarf2_per_objfile->all_comp_units[index];
1905 /* A helper function that knows how to read a 64-bit value in a way
1906 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1910 extract_cu_value (const char *bytes, ULONGEST *result)
1912 if (sizeof (ULONGEST) < 8)
1916 /* Ignore the upper 4 bytes if they are all zero. */
1917 for (i = 0; i < 4; ++i)
1918 if (bytes[i + 4] != 0)
1921 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1924 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1928 /* Read the CU list from the mapped index, and use it to create all
1929 the CU objects for this objfile. Return 0 if something went wrong,
1930 1 if everything went ok. */
1933 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1934 offset_type cu_list_elements)
1938 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1939 dwarf2_per_objfile->all_comp_units
1940 = obstack_alloc (&objfile->objfile_obstack,
1941 dwarf2_per_objfile->n_comp_units
1942 * sizeof (struct dwarf2_per_cu_data *));
1944 for (i = 0; i < cu_list_elements; i += 2)
1946 struct dwarf2_per_cu_data *the_cu;
1947 ULONGEST offset, length;
1949 if (!extract_cu_value (cu_list, &offset)
1950 || !extract_cu_value (cu_list + 8, &length))
1954 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1955 struct dwarf2_per_cu_data);
1956 the_cu->offset = offset;
1957 the_cu->length = length;
1958 the_cu->objfile = objfile;
1959 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1960 struct dwarf2_per_cu_quick_data);
1961 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1967 /* Create the signatured type hash table from the index. */
1970 create_signatured_type_table_from_index (struct objfile *objfile,
1971 struct dwarf2_section_info *section,
1972 const gdb_byte *bytes,
1973 offset_type elements)
1976 htab_t sig_types_hash;
1978 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1979 dwarf2_per_objfile->type_comp_units
1980 = obstack_alloc (&objfile->objfile_obstack,
1981 dwarf2_per_objfile->n_type_comp_units
1982 * sizeof (struct dwarf2_per_cu_data *));
1984 sig_types_hash = allocate_signatured_type_table (objfile);
1986 for (i = 0; i < elements; i += 3)
1988 struct signatured_type *type_sig;
1989 ULONGEST offset, type_offset, signature;
1992 if (!extract_cu_value (bytes, &offset)
1993 || !extract_cu_value (bytes + 8, &type_offset))
1995 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1998 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1999 struct signatured_type);
2000 type_sig->signature = signature;
2001 type_sig->type_offset = type_offset;
2002 type_sig->per_cu.debug_types_section = section;
2003 type_sig->per_cu.offset = offset;
2004 type_sig->per_cu.objfile = objfile;
2005 type_sig->per_cu.v.quick
2006 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2007 struct dwarf2_per_cu_quick_data);
2009 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
2012 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
2015 dwarf2_per_objfile->signatured_types = sig_types_hash;
2020 /* Read the address map data from the mapped index, and use it to
2021 populate the objfile's psymtabs_addrmap. */
2024 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2026 const gdb_byte *iter, *end;
2027 struct obstack temp_obstack;
2028 struct addrmap *mutable_map;
2029 struct cleanup *cleanup;
2032 obstack_init (&temp_obstack);
2033 cleanup = make_cleanup_obstack_free (&temp_obstack);
2034 mutable_map = addrmap_create_mutable (&temp_obstack);
2036 iter = index->address_table;
2037 end = iter + index->address_table_size;
2039 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2043 ULONGEST hi, lo, cu_index;
2044 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2046 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2048 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2051 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2052 dw2_get_cu (cu_index));
2055 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2056 &objfile->objfile_obstack);
2057 do_cleanups (cleanup);
2060 /* The hash function for strings in the mapped index. This is the same as
2061 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2062 implementation. This is necessary because the hash function is tied to the
2063 format of the mapped index file. The hash values do not have to match with
2066 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2069 mapped_index_string_hash (int index_version, const void *p)
2071 const unsigned char *str = (const unsigned char *) p;
2075 while ((c = *str++) != 0)
2077 if (index_version >= 5)
2079 r = r * 67 + c - 113;
2085 /* Find a slot in the mapped index INDEX for the object named NAME.
2086 If NAME is found, set *VEC_OUT to point to the CU vector in the
2087 constant pool and return 1. If NAME cannot be found, return 0. */
2090 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2091 offset_type **vec_out)
2093 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2095 offset_type slot, step;
2096 int (*cmp) (const char *, const char *);
2098 if (current_language->la_language == language_cplus
2099 || current_language->la_language == language_java
2100 || current_language->la_language == language_fortran)
2102 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2104 const char *paren = strchr (name, '(');
2110 dup = xmalloc (paren - name + 1);
2111 memcpy (dup, name, paren - name);
2112 dup[paren - name] = 0;
2114 make_cleanup (xfree, dup);
2119 /* Index version 4 did not support case insensitive searches. But the
2120 indexes for case insensitive languages are built in lowercase, therefore
2121 simulate our NAME being searched is also lowercased. */
2122 hash = mapped_index_string_hash ((index->version == 4
2123 && case_sensitivity == case_sensitive_off
2124 ? 5 : index->version),
2127 slot = hash & (index->symbol_table_slots - 1);
2128 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2129 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2133 /* Convert a slot number to an offset into the table. */
2134 offset_type i = 2 * slot;
2136 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2138 do_cleanups (back_to);
2142 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2143 if (!cmp (name, str))
2145 *vec_out = (offset_type *) (index->constant_pool
2146 + MAYBE_SWAP (index->symbol_table[i + 1]));
2147 do_cleanups (back_to);
2151 slot = (slot + step) & (index->symbol_table_slots - 1);
2155 /* Read the index file. If everything went ok, initialize the "quick"
2156 elements of all the CUs and return 1. Otherwise, return 0. */
2159 dwarf2_read_index (struct objfile *objfile)
2162 struct mapped_index *map;
2163 offset_type *metadata;
2164 const gdb_byte *cu_list;
2165 const gdb_byte *types_list = NULL;
2166 offset_type version, cu_list_elements;
2167 offset_type types_list_elements = 0;
2170 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2173 /* Older elfutils strip versions could keep the section in the main
2174 executable while splitting it for the separate debug info file. */
2175 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2176 & SEC_HAS_CONTENTS) == 0)
2179 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2181 addr = dwarf2_per_objfile->gdb_index.buffer;
2182 /* Version check. */
2183 version = MAYBE_SWAP (*(offset_type *) addr);
2184 /* Versions earlier than 3 emitted every copy of a psymbol. This
2185 causes the index to behave very poorly for certain requests. Version 3
2186 contained incomplete addrmap. So, it seems better to just ignore such
2187 indices. Index version 4 uses a different hash function than index
2188 version 5 and later. */
2191 /* Indexes with higher version than the one supported by GDB may be no
2192 longer backward compatible. */
2196 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2197 map->version = version;
2198 map->total_size = dwarf2_per_objfile->gdb_index.size;
2200 metadata = (offset_type *) (addr + sizeof (offset_type));
2203 cu_list = addr + MAYBE_SWAP (metadata[i]);
2204 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2208 types_list = addr + MAYBE_SWAP (metadata[i]);
2209 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2210 - MAYBE_SWAP (metadata[i]))
2214 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2215 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2216 - MAYBE_SWAP (metadata[i]));
2219 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2220 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2221 - MAYBE_SWAP (metadata[i]))
2222 / (2 * sizeof (offset_type)));
2225 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2227 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2230 if (types_list_elements)
2232 struct dwarf2_section_info *section;
2234 /* We can only handle a single .debug_types when we have an
2236 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2239 section = VEC_index (dwarf2_section_info_def,
2240 dwarf2_per_objfile->types, 0);
2242 if (!create_signatured_type_table_from_index (objfile, section,
2244 types_list_elements))
2248 create_addrmap_from_index (objfile, map);
2250 dwarf2_per_objfile->index_table = map;
2251 dwarf2_per_objfile->using_index = 1;
2252 dwarf2_per_objfile->quick_file_names_table =
2253 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2258 /* A helper for the "quick" functions which sets the global
2259 dwarf2_per_objfile according to OBJFILE. */
2262 dw2_setup (struct objfile *objfile)
2264 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2265 gdb_assert (dwarf2_per_objfile);
2268 /* A helper for the "quick" functions which attempts to read the line
2269 table for THIS_CU. */
2271 static struct quick_file_names *
2272 dw2_get_file_names (struct objfile *objfile,
2273 struct dwarf2_per_cu_data *this_cu)
2275 bfd *abfd = objfile->obfd;
2276 struct line_header *lh;
2277 struct attribute *attr;
2278 struct cleanup *cleanups;
2279 struct die_info *comp_unit_die;
2280 struct dwarf2_section_info* sec;
2281 gdb_byte *info_ptr, *buffer;
2282 int has_children, i;
2283 struct dwarf2_cu cu;
2284 unsigned int bytes_read, buffer_size;
2285 struct die_reader_specs reader_specs;
2286 char *name, *comp_dir;
2288 struct quick_file_names *qfn;
2289 unsigned int line_offset;
2291 if (this_cu->v.quick->file_names != NULL)
2292 return this_cu->v.quick->file_names;
2293 /* If we know there is no line data, no point in looking again. */
2294 if (this_cu->v.quick->no_file_data)
2297 init_one_comp_unit (&cu, objfile);
2298 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2300 if (this_cu->debug_types_section)
2301 sec = this_cu->debug_types_section;
2303 sec = &dwarf2_per_objfile->info;
2304 dwarf2_read_section (objfile, sec);
2305 buffer_size = sec->size;
2306 buffer = sec->buffer;
2307 info_ptr = buffer + this_cu->offset;
2309 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2310 buffer, buffer_size,
2312 this_cu->debug_types_section != NULL);
2314 /* Skip dummy compilation units. */
2315 if (info_ptr >= buffer + buffer_size
2316 || peek_abbrev_code (abfd, info_ptr) == 0)
2318 do_cleanups (cleanups);
2323 cu.per_cu = this_cu;
2325 dwarf2_read_abbrevs (abfd, &cu);
2326 make_cleanup (dwarf2_free_abbrev_table, &cu);
2328 init_cu_die_reader (&reader_specs, &cu);
2329 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2335 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2338 struct quick_file_names find_entry;
2340 line_offset = DW_UNSND (attr);
2342 /* We may have already read in this line header (TU line header sharing).
2343 If we have we're done. */
2344 find_entry.offset = line_offset;
2345 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2346 &find_entry, INSERT);
2349 do_cleanups (cleanups);
2350 this_cu->v.quick->file_names = *slot;
2354 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2358 do_cleanups (cleanups);
2359 this_cu->v.quick->no_file_data = 1;
2363 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2364 qfn->offset = line_offset;
2365 gdb_assert (slot != NULL);
2368 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2370 qfn->num_file_names = lh->num_file_names;
2371 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2372 lh->num_file_names * sizeof (char *));
2373 for (i = 0; i < lh->num_file_names; ++i)
2374 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2375 qfn->real_names = NULL;
2377 free_line_header (lh);
2378 do_cleanups (cleanups);
2380 this_cu->v.quick->file_names = qfn;
2384 /* A helper for the "quick" functions which computes and caches the
2385 real path for a given file name from the line table. */
2388 dw2_get_real_path (struct objfile *objfile,
2389 struct quick_file_names *qfn, int index)
2391 if (qfn->real_names == NULL)
2392 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2393 qfn->num_file_names, sizeof (char *));
2395 if (qfn->real_names[index] == NULL)
2396 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2398 return qfn->real_names[index];
2401 static struct symtab *
2402 dw2_find_last_source_symtab (struct objfile *objfile)
2406 dw2_setup (objfile);
2407 index = dwarf2_per_objfile->n_comp_units - 1;
2408 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2411 /* Traversal function for dw2_forget_cached_source_info. */
2414 dw2_free_cached_file_names (void **slot, void *info)
2416 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2418 if (file_data->real_names)
2422 for (i = 0; i < file_data->num_file_names; ++i)
2424 xfree ((void*) file_data->real_names[i]);
2425 file_data->real_names[i] = NULL;
2433 dw2_forget_cached_source_info (struct objfile *objfile)
2435 dw2_setup (objfile);
2437 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2438 dw2_free_cached_file_names, NULL);
2441 /* Helper function for dw2_map_symtabs_matching_filename that expands
2442 the symtabs and calls the iterator. */
2445 dw2_map_expand_apply (struct objfile *objfile,
2446 struct dwarf2_per_cu_data *per_cu,
2448 const char *full_path, const char *real_path,
2449 int (*callback) (struct symtab *, void *),
2452 struct symtab *last_made = objfile->symtabs;
2454 /* Don't visit already-expanded CUs. */
2455 if (per_cu->v.quick->symtab)
2458 /* This may expand more than one symtab, and we want to iterate over
2460 dw2_instantiate_symtab (objfile, per_cu);
2462 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
2463 objfile->symtabs, last_made);
2466 /* Implementation of the map_symtabs_matching_filename method. */
2469 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
2470 const char *full_path, const char *real_path,
2471 int (*callback) (struct symtab *, void *),
2475 const char *name_basename = lbasename (name);
2476 int check_basename = name_basename == name;
2477 struct dwarf2_per_cu_data *base_cu = NULL;
2479 dw2_setup (objfile);
2481 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2482 + dwarf2_per_objfile->n_type_comp_units); ++i)
2485 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2486 struct quick_file_names *file_data;
2488 /* We only need to look at symtabs not already expanded. */
2489 if (per_cu->v.quick->symtab)
2492 file_data = dw2_get_file_names (objfile, per_cu);
2493 if (file_data == NULL)
2496 for (j = 0; j < file_data->num_file_names; ++j)
2498 const char *this_name = file_data->file_names[j];
2500 if (FILENAME_CMP (name, this_name) == 0)
2502 if (dw2_map_expand_apply (objfile, per_cu,
2503 name, full_path, real_path,
2508 if (check_basename && ! base_cu
2509 && FILENAME_CMP (lbasename (this_name), name) == 0)
2512 /* Before we invoke realpath, which can get expensive when many
2513 files are involved, do a quick comparison of the basenames. */
2514 if (! basenames_may_differ
2515 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
2518 if (full_path != NULL)
2520 const char *this_real_name = dw2_get_real_path (objfile,
2523 if (this_real_name != NULL
2524 && FILENAME_CMP (full_path, this_real_name) == 0)
2526 if (dw2_map_expand_apply (objfile, per_cu,
2527 name, full_path, real_path,
2533 if (real_path != NULL)
2535 const char *this_real_name = dw2_get_real_path (objfile,
2538 if (this_real_name != NULL
2539 && FILENAME_CMP (real_path, this_real_name) == 0)
2541 if (dw2_map_expand_apply (objfile, per_cu,
2542 name, full_path, real_path,
2552 if (dw2_map_expand_apply (objfile, base_cu,
2553 name, full_path, real_path,
2561 static struct symtab *
2562 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2563 const char *name, domain_enum domain)
2565 /* We do all the work in the pre_expand_symtabs_matching hook
2570 /* A helper function that expands all symtabs that hold an object
2574 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2576 dw2_setup (objfile);
2578 /* index_table is NULL if OBJF_READNOW. */
2579 if (dwarf2_per_objfile->index_table)
2583 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2586 offset_type i, len = MAYBE_SWAP (*vec);
2587 for (i = 0; i < len; ++i)
2589 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2590 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2592 dw2_instantiate_symtab (objfile, per_cu);
2599 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2600 enum block_enum block_kind, const char *name,
2603 dw2_do_expand_symtabs_matching (objfile, name);
2607 dw2_print_stats (struct objfile *objfile)
2611 dw2_setup (objfile);
2613 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2614 + dwarf2_per_objfile->n_type_comp_units); ++i)
2616 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2618 if (!per_cu->v.quick->symtab)
2621 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2625 dw2_dump (struct objfile *objfile)
2627 /* Nothing worth printing. */
2631 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2632 struct section_offsets *delta)
2634 /* There's nothing to relocate here. */
2638 dw2_expand_symtabs_for_function (struct objfile *objfile,
2639 const char *func_name)
2641 dw2_do_expand_symtabs_matching (objfile, func_name);
2645 dw2_expand_all_symtabs (struct objfile *objfile)
2649 dw2_setup (objfile);
2651 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2652 + dwarf2_per_objfile->n_type_comp_units); ++i)
2654 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2656 dw2_instantiate_symtab (objfile, per_cu);
2661 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2662 const char *filename)
2666 dw2_setup (objfile);
2668 /* We don't need to consider type units here.
2669 This is only called for examining code, e.g. expand_line_sal.
2670 There can be an order of magnitude (or more) more type units
2671 than comp units, and we avoid them if we can. */
2673 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2676 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2677 struct quick_file_names *file_data;
2679 /* We only need to look at symtabs not already expanded. */
2680 if (per_cu->v.quick->symtab)
2683 file_data = dw2_get_file_names (objfile, per_cu);
2684 if (file_data == NULL)
2687 for (j = 0; j < file_data->num_file_names; ++j)
2689 const char *this_name = file_data->file_names[j];
2690 if (FILENAME_CMP (this_name, filename) == 0)
2692 dw2_instantiate_symtab (objfile, per_cu);
2700 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2702 struct dwarf2_per_cu_data *per_cu;
2704 struct quick_file_names *file_data;
2706 dw2_setup (objfile);
2708 /* index_table is NULL if OBJF_READNOW. */
2709 if (!dwarf2_per_objfile->index_table)
2713 ALL_OBJFILE_SYMTABS (objfile, s)
2716 struct blockvector *bv = BLOCKVECTOR (s);
2717 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2718 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2721 return sym->symtab->filename;
2726 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2730 /* Note that this just looks at the very first one named NAME -- but
2731 actually we are looking for a function. find_main_filename
2732 should be rewritten so that it doesn't require a custom hook. It
2733 could just use the ordinary symbol tables. */
2734 /* vec[0] is the length, which must always be >0. */
2735 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2737 file_data = dw2_get_file_names (objfile, per_cu);
2738 if (file_data == NULL)
2741 return file_data->file_names[file_data->num_file_names - 1];
2745 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2746 struct objfile *objfile, int global,
2747 int (*callback) (struct block *,
2748 struct symbol *, void *),
2749 void *data, symbol_compare_ftype *match,
2750 symbol_compare_ftype *ordered_compare)
2752 /* Currently unimplemented; used for Ada. The function can be called if the
2753 current language is Ada for a non-Ada objfile using GNU index. As Ada
2754 does not look for non-Ada symbols this function should just return. */
2758 dw2_expand_symtabs_matching
2759 (struct objfile *objfile,
2760 int (*file_matcher) (const char *, void *),
2761 int (*name_matcher) (const struct language_defn *, const char *, void *),
2762 enum search_domain kind,
2767 struct mapped_index *index;
2769 dw2_setup (objfile);
2771 /* index_table is NULL if OBJF_READNOW. */
2772 if (!dwarf2_per_objfile->index_table)
2774 index = dwarf2_per_objfile->index_table;
2776 if (file_matcher != NULL)
2777 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2778 + dwarf2_per_objfile->n_type_comp_units); ++i)
2781 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2782 struct quick_file_names *file_data;
2784 per_cu->v.quick->mark = 0;
2786 /* We only need to look at symtabs not already expanded. */
2787 if (per_cu->v.quick->symtab)
2790 file_data = dw2_get_file_names (objfile, per_cu);
2791 if (file_data == NULL)
2794 for (j = 0; j < file_data->num_file_names; ++j)
2796 if (file_matcher (file_data->file_names[j], data))
2798 per_cu->v.quick->mark = 1;
2804 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2806 offset_type idx = 2 * iter;
2808 offset_type *vec, vec_len, vec_idx;
2810 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2813 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2815 if (! (*name_matcher) (current_language, name, data))
2818 /* The name was matched, now expand corresponding CUs that were
2820 vec = (offset_type *) (index->constant_pool
2821 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2822 vec_len = MAYBE_SWAP (vec[0]);
2823 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2825 struct dwarf2_per_cu_data *per_cu;
2827 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2828 if (file_matcher == NULL || per_cu->v.quick->mark)
2829 dw2_instantiate_symtab (objfile, per_cu);
2834 static struct symtab *
2835 dw2_find_pc_sect_symtab (struct objfile *objfile,
2836 struct minimal_symbol *msymbol,
2838 struct obj_section *section,
2841 struct dwarf2_per_cu_data *data;
2843 dw2_setup (objfile);
2845 if (!objfile->psymtabs_addrmap)
2848 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2852 if (warn_if_readin && data->v.quick->symtab)
2853 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2854 paddress (get_objfile_arch (objfile), pc));
2856 return dw2_instantiate_symtab (objfile, data);
2860 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2861 void *data, int need_fullname)
2865 dw2_setup (objfile);
2867 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2868 + dwarf2_per_objfile->n_type_comp_units); ++i)
2871 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2872 struct quick_file_names *file_data;
2874 /* We only need to look at symtabs not already expanded. */
2875 if (per_cu->v.quick->symtab)
2878 file_data = dw2_get_file_names (objfile, per_cu);
2879 if (file_data == NULL)
2882 for (j = 0; j < file_data->num_file_names; ++j)
2884 const char *this_real_name;
2887 this_real_name = dw2_get_real_path (objfile, file_data, j);
2889 this_real_name = NULL;
2890 (*fun) (file_data->file_names[j], this_real_name, data);
2896 dw2_has_symbols (struct objfile *objfile)
2901 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2904 dw2_find_last_source_symtab,
2905 dw2_forget_cached_source_info,
2906 dw2_map_symtabs_matching_filename,
2908 dw2_pre_expand_symtabs_matching,
2912 dw2_expand_symtabs_for_function,
2913 dw2_expand_all_symtabs,
2914 dw2_expand_symtabs_with_filename,
2915 dw2_find_symbol_file,
2916 dw2_map_matching_symbols,
2917 dw2_expand_symtabs_matching,
2918 dw2_find_pc_sect_symtab,
2919 dw2_map_symbol_filenames
2922 /* Initialize for reading DWARF for this objfile. Return 0 if this
2923 file will use psymtabs, or 1 if using the GNU index. */
2926 dwarf2_initialize_objfile (struct objfile *objfile)
2928 /* If we're about to read full symbols, don't bother with the
2929 indices. In this case we also don't care if some other debug
2930 format is making psymtabs, because they are all about to be
2932 if ((objfile->flags & OBJF_READNOW))
2936 dwarf2_per_objfile->using_index = 1;
2937 create_all_comp_units (objfile);
2938 create_debug_types_hash_table (objfile);
2939 dwarf2_per_objfile->quick_file_names_table =
2940 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2942 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2943 + dwarf2_per_objfile->n_type_comp_units); ++i)
2945 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2947 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2948 struct dwarf2_per_cu_quick_data);
2951 /* Return 1 so that gdb sees the "quick" functions. However,
2952 these functions will be no-ops because we will have expanded
2957 if (dwarf2_read_index (objfile))
2965 /* Build a partial symbol table. */
2968 dwarf2_build_psymtabs (struct objfile *objfile)
2970 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2972 init_psymbol_list (objfile, 1024);
2975 dwarf2_build_psymtabs_hard (objfile);
2978 /* Return TRUE if OFFSET is within CU_HEADER. */
2981 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2983 unsigned int bottom = cu_header->offset;
2984 unsigned int top = (cu_header->offset
2986 + cu_header->initial_length_size);
2988 return (offset >= bottom && offset < top);
2991 /* Read in the comp unit header information from the debug_info at info_ptr.
2992 NOTE: This leaves members offset, first_die_offset to be filled in
2996 read_comp_unit_head (struct comp_unit_head *cu_header,
2997 gdb_byte *info_ptr, bfd *abfd)
3000 unsigned int bytes_read;
3002 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3003 cu_header->initial_length_size = bytes_read;
3004 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3005 info_ptr += bytes_read;
3006 cu_header->version = read_2_bytes (abfd, info_ptr);
3008 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
3010 info_ptr += bytes_read;
3011 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3013 signed_addr = bfd_get_sign_extend_vma (abfd);
3014 if (signed_addr < 0)
3015 internal_error (__FILE__, __LINE__,
3016 _("read_comp_unit_head: dwarf from non elf file"));
3017 cu_header->signed_addr_p = signed_addr;
3022 /* Read in a CU header and perform some basic error checking. */
3025 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
3026 gdb_byte *buffer, unsigned int buffer_size,
3027 bfd *abfd, int is_debug_types_section)
3029 gdb_byte *beg_of_comp_unit = info_ptr;
3031 header->offset = beg_of_comp_unit - buffer;
3033 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3035 /* If we're reading a type unit, skip over the signature and
3036 type_offset fields. */
3037 if (is_debug_types_section)
3038 info_ptr += 8 /*signature*/ + header->offset_size;
3040 header->first_die_offset = info_ptr - beg_of_comp_unit;
3042 if (header->version != 2 && header->version != 3 && header->version != 4)
3043 error (_("Dwarf Error: wrong version in compilation unit header "
3044 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3045 bfd_get_filename (abfd));
3047 if (header->abbrev_offset
3048 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
3049 &dwarf2_per_objfile->abbrev))
3050 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3051 "(offset 0x%lx + 6) [in module %s]"),
3052 (long) header->abbrev_offset,
3053 (long) (beg_of_comp_unit - buffer),
3054 bfd_get_filename (abfd));
3056 if (beg_of_comp_unit + header->length + header->initial_length_size
3057 > buffer + buffer_size)
3058 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3059 "(offset 0x%lx + 0) [in module %s]"),
3060 (long) header->length,
3061 (long) (beg_of_comp_unit - buffer),
3062 bfd_get_filename (abfd));
3067 /* Read in the types comp unit header information from .debug_types entry at
3068 types_ptr. The result is a pointer to one past the end of the header. */
3071 read_type_comp_unit_head (struct comp_unit_head *cu_header,
3072 struct dwarf2_section_info *section,
3073 ULONGEST *signature,
3074 gdb_byte *types_ptr, bfd *abfd)
3076 gdb_byte *initial_types_ptr = types_ptr;
3078 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
3079 cu_header->offset = types_ptr - section->buffer;
3081 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
3083 *signature = read_8_bytes (abfd, types_ptr);
3085 types_ptr += cu_header->offset_size;
3086 cu_header->first_die_offset = types_ptr - initial_types_ptr;
3091 /* Allocate a new partial symtab for file named NAME and mark this new
3092 partial symtab as being an include of PST. */
3095 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3096 struct objfile *objfile)
3098 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3100 subpst->section_offsets = pst->section_offsets;
3101 subpst->textlow = 0;
3102 subpst->texthigh = 0;
3104 subpst->dependencies = (struct partial_symtab **)
3105 obstack_alloc (&objfile->objfile_obstack,
3106 sizeof (struct partial_symtab *));
3107 subpst->dependencies[0] = pst;
3108 subpst->number_of_dependencies = 1;
3110 subpst->globals_offset = 0;
3111 subpst->n_global_syms = 0;
3112 subpst->statics_offset = 0;
3113 subpst->n_static_syms = 0;
3114 subpst->symtab = NULL;
3115 subpst->read_symtab = pst->read_symtab;
3118 /* No private part is necessary for include psymtabs. This property
3119 can be used to differentiate between such include psymtabs and
3120 the regular ones. */
3121 subpst->read_symtab_private = NULL;
3124 /* Read the Line Number Program data and extract the list of files
3125 included by the source file represented by PST. Build an include
3126 partial symtab for each of these included files. */
3129 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3130 struct die_info *die,
3131 struct partial_symtab *pst)
3133 struct objfile *objfile = cu->objfile;
3134 bfd *abfd = objfile->obfd;
3135 struct line_header *lh = NULL;
3136 struct attribute *attr;
3138 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3141 unsigned int line_offset = DW_UNSND (attr);
3143 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3146 return; /* No linetable, so no includes. */
3148 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3149 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
3151 free_line_header (lh);
3155 hash_type_signature (const void *item)
3157 const struct signatured_type *type_sig = item;
3159 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3160 return type_sig->signature;
3164 eq_type_signature (const void *item_lhs, const void *item_rhs)
3166 const struct signatured_type *lhs = item_lhs;
3167 const struct signatured_type *rhs = item_rhs;
3169 return lhs->signature == rhs->signature;
3172 /* Allocate a hash table for signatured types. */
3175 allocate_signatured_type_table (struct objfile *objfile)
3177 return htab_create_alloc_ex (41,
3178 hash_type_signature,
3181 &objfile->objfile_obstack,
3182 hashtab_obstack_allocate,
3183 dummy_obstack_deallocate);
3186 /* A helper function to add a signatured type CU to a list. */
3189 add_signatured_type_cu_to_list (void **slot, void *datum)
3191 struct signatured_type *sigt = *slot;
3192 struct dwarf2_per_cu_data ***datap = datum;
3194 **datap = &sigt->per_cu;
3200 /* Create the hash table of all entries in the .debug_types section.
3201 The result is zero if there is an error (e.g. missing .debug_types section),
3202 otherwise non-zero. */
3205 create_debug_types_hash_table (struct objfile *objfile)
3207 htab_t types_htab = NULL;
3208 struct dwarf2_per_cu_data **iter;
3210 struct dwarf2_section_info *section;
3212 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3214 dwarf2_per_objfile->signatured_types = NULL;
3219 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3223 gdb_byte *info_ptr, *end_ptr;
3225 dwarf2_read_section (objfile, section);
3226 info_ptr = section->buffer;
3228 if (info_ptr == NULL)
3231 if (types_htab == NULL)
3232 types_htab = allocate_signatured_type_table (objfile);
3234 if (dwarf2_die_debug)
3235 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3237 end_ptr = info_ptr + section->size;
3238 while (info_ptr < end_ptr)
3240 unsigned int offset;
3241 unsigned int offset_size;
3242 unsigned int type_offset;
3243 unsigned int length, initial_length_size;
3244 unsigned short version;
3246 struct signatured_type *type_sig;
3248 gdb_byte *ptr = info_ptr;
3250 offset = ptr - section->buffer;
3252 /* We need to read the type's signature in order to build the hash
3253 table, but we don't need to read anything else just yet. */
3255 /* Sanity check to ensure entire cu is present. */
3256 length = read_initial_length (objfile->obfd, ptr,
3257 &initial_length_size);
3258 if (ptr + length + initial_length_size > end_ptr)
3260 complaint (&symfile_complaints,
3261 _("debug type entry runs off end "
3262 "of `.debug_types' section, ignored"));
3266 offset_size = initial_length_size == 4 ? 4 : 8;
3267 ptr += initial_length_size;
3268 version = bfd_get_16 (objfile->obfd, ptr);
3270 ptr += offset_size; /* abbrev offset */
3271 ptr += 1; /* address size */
3272 signature = bfd_get_64 (objfile->obfd, ptr);
3274 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3277 /* Skip dummy type units. */
3278 if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0)
3280 info_ptr = info_ptr + initial_length_size + length;
3284 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3285 memset (type_sig, 0, sizeof (*type_sig));
3286 type_sig->signature = signature;
3287 type_sig->type_offset = type_offset;
3288 type_sig->per_cu.objfile = objfile;
3289 type_sig->per_cu.debug_types_section = section;
3290 type_sig->per_cu.offset = offset;
3292 slot = htab_find_slot (types_htab, type_sig, INSERT);
3293 gdb_assert (slot != NULL);
3296 const struct signatured_type *dup_sig = *slot;
3298 complaint (&symfile_complaints,
3299 _("debug type entry at offset 0x%x is duplicate to the "
3300 "entry at offset 0x%x, signature 0x%s"),
3301 offset, dup_sig->per_cu.offset,
3302 phex (signature, sizeof (signature)));
3303 gdb_assert (signature == dup_sig->signature);
3307 if (dwarf2_die_debug)
3308 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3309 offset, phex (signature, sizeof (signature)));
3311 info_ptr = info_ptr + initial_length_size + length;
3315 dwarf2_per_objfile->signatured_types = types_htab;
3317 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3318 dwarf2_per_objfile->type_comp_units
3319 = obstack_alloc (&objfile->objfile_obstack,
3320 dwarf2_per_objfile->n_type_comp_units
3321 * sizeof (struct dwarf2_per_cu_data *));
3322 iter = &dwarf2_per_objfile->type_comp_units[0];
3323 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3324 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3325 == dwarf2_per_objfile->n_type_comp_units);
3330 /* Lookup a signature based type.
3331 Returns NULL if SIG is not present in the table. */
3333 static struct signatured_type *
3334 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3336 struct signatured_type find_entry, *entry;
3338 if (dwarf2_per_objfile->signatured_types == NULL)
3340 complaint (&symfile_complaints,
3341 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3345 find_entry.signature = sig;
3346 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3350 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3353 init_cu_die_reader (struct die_reader_specs *reader,
3354 struct dwarf2_cu *cu)
3356 reader->abfd = cu->objfile->obfd;
3358 if (cu->per_cu->debug_types_section)
3360 gdb_assert (cu->per_cu->debug_types_section->readin);
3361 reader->buffer = cu->per_cu->debug_types_section->buffer;
3365 gdb_assert (dwarf2_per_objfile->info.readin);
3366 reader->buffer = dwarf2_per_objfile->info.buffer;
3370 /* Find the base address of the compilation unit for range lists and
3371 location lists. It will normally be specified by DW_AT_low_pc.
3372 In DWARF-3 draft 4, the base address could be overridden by
3373 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3374 compilation units with discontinuous ranges. */
3377 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3379 struct attribute *attr;
3382 cu->base_address = 0;
3384 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3387 cu->base_address = DW_ADDR (attr);
3392 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3395 cu->base_address = DW_ADDR (attr);
3401 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3402 to combine the common parts.
3403 Process a compilation unit for a psymtab.
3404 BUFFER is a pointer to the beginning of the dwarf section buffer,
3405 either .debug_info or debug_types.
3406 INFO_PTR is a pointer to the start of the CU.
3407 Returns a pointer to the next CU. */
3410 process_psymtab_comp_unit (struct objfile *objfile,
3411 struct dwarf2_per_cu_data *this_cu,
3412 gdb_byte *buffer, gdb_byte *info_ptr,
3413 unsigned int buffer_size)
3415 bfd *abfd = objfile->obfd;
3416 gdb_byte *beg_of_comp_unit = info_ptr;
3417 struct die_info *comp_unit_die;
3418 struct partial_symtab *pst;
3420 struct cleanup *back_to_inner;
3421 struct dwarf2_cu cu;
3422 int has_children, has_pc_info;
3423 struct attribute *attr;
3424 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3425 struct die_reader_specs reader_specs;
3426 const char *filename;
3428 init_one_comp_unit (&cu, objfile);
3429 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3431 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3432 buffer, buffer_size,
3434 this_cu->debug_types_section != NULL);
3436 /* Skip dummy compilation units. */
3437 if (info_ptr >= buffer + buffer_size
3438 || peek_abbrev_code (abfd, info_ptr) == 0)
3440 info_ptr = (beg_of_comp_unit + cu.header.length
3441 + cu.header.initial_length_size);
3442 do_cleanups (back_to_inner);
3446 cu.list_in_scope = &file_symbols;
3448 /* If this compilation unit was already read in, free the
3449 cached copy in order to read it in again. This is
3450 necessary because we skipped some symbols when we first
3451 read in the compilation unit (see load_partial_dies).
3452 This problem could be avoided, but the benefit is
3454 if (this_cu->cu != NULL)
3455 free_one_cached_comp_unit (this_cu->cu);
3457 /* Note that this is a pointer to our stack frame, being
3458 added to a global data structure. It will be cleaned up
3459 in free_stack_comp_unit when we finish with this
3460 compilation unit. */
3462 cu.per_cu = this_cu;
3464 /* Read the abbrevs for this compilation unit into a table. */
3465 dwarf2_read_abbrevs (abfd, &cu);
3466 make_cleanup (dwarf2_free_abbrev_table, &cu);
3468 /* Read the compilation unit die. */
3469 init_cu_die_reader (&reader_specs, &cu);
3470 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3473 if (this_cu->debug_types_section)
3475 /* LENGTH has not been set yet for type units. */
3476 gdb_assert (this_cu->offset == cu.header.offset);
3477 this_cu->length = cu.header.length + cu.header.initial_length_size;
3479 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3481 info_ptr = (beg_of_comp_unit + cu.header.length
3482 + cu.header.initial_length_size);
3483 do_cleanups (back_to_inner);
3487 prepare_one_comp_unit (&cu, comp_unit_die);
3489 /* Allocate a new partial symbol table structure. */
3490 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3491 if (attr == NULL || !DW_STRING (attr))
3494 filename = DW_STRING (attr);
3495 pst = start_psymtab_common (objfile, objfile->section_offsets,
3497 /* TEXTLOW and TEXTHIGH are set below. */
3499 objfile->global_psymbols.next,
3500 objfile->static_psymbols.next);
3501 pst->psymtabs_addrmap_supported = 1;
3503 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3505 pst->dirname = DW_STRING (attr);
3507 pst->read_symtab_private = this_cu;
3509 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3511 /* Store the function that reads in the rest of the symbol table. */
3512 pst->read_symtab = dwarf2_psymtab_to_symtab;
3514 this_cu->v.psymtab = pst;
3516 dwarf2_find_base_address (comp_unit_die, &cu);
3518 /* Possibly set the default values of LOWPC and HIGHPC from
3520 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3521 &best_highpc, &cu, pst);
3522 if (has_pc_info == 1 && best_lowpc < best_highpc)
3523 /* Store the contiguous range if it is not empty; it can be empty for
3524 CUs with no code. */
3525 addrmap_set_empty (objfile->psymtabs_addrmap,
3526 best_lowpc + baseaddr,
3527 best_highpc + baseaddr - 1, pst);
3529 /* Check if comp unit has_children.
3530 If so, read the rest of the partial symbols from this comp unit.
3531 If not, there's no more debug_info for this comp unit. */
3534 struct partial_die_info *first_die;
3535 CORE_ADDR lowpc, highpc;
3537 lowpc = ((CORE_ADDR) -1);
3538 highpc = ((CORE_ADDR) 0);
3540 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3542 scan_partial_symbols (first_die, &lowpc, &highpc,
3543 ! has_pc_info, &cu);
3545 /* If we didn't find a lowpc, set it to highpc to avoid
3546 complaints from `maint check'. */
3547 if (lowpc == ((CORE_ADDR) -1))
3550 /* If the compilation unit didn't have an explicit address range,
3551 then use the information extracted from its child dies. */
3555 best_highpc = highpc;
3558 pst->textlow = best_lowpc + baseaddr;
3559 pst->texthigh = best_highpc + baseaddr;
3561 pst->n_global_syms = objfile->global_psymbols.next -
3562 (objfile->global_psymbols.list + pst->globals_offset);
3563 pst->n_static_syms = objfile->static_psymbols.next -
3564 (objfile->static_psymbols.list + pst->statics_offset);
3565 sort_pst_symbols (pst);
3567 info_ptr = (beg_of_comp_unit + cu.header.length
3568 + cu.header.initial_length_size);
3570 if (this_cu->debug_types_section)
3572 /* It's not clear we want to do anything with stmt lists here.
3573 Waiting to see what gcc ultimately does. */
3577 /* Get the list of files included in the current compilation unit,
3578 and build a psymtab for each of them. */
3579 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3582 do_cleanups (back_to_inner);
3587 /* Traversal function for htab_traverse_noresize.
3588 Process one .debug_types comp-unit. */
3591 process_type_comp_unit (void **slot, void *info)
3593 struct signatured_type *entry = (struct signatured_type *) *slot;
3594 struct objfile *objfile = (struct objfile *) info;
3595 struct dwarf2_per_cu_data *this_cu;
3597 this_cu = &entry->per_cu;
3599 gdb_assert (this_cu->debug_types_section->readin);
3600 process_psymtab_comp_unit (objfile, this_cu,
3601 this_cu->debug_types_section->buffer,
3602 (this_cu->debug_types_section->buffer
3604 this_cu->debug_types_section->size);
3609 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3610 Build partial symbol tables for the .debug_types comp-units. */
3613 build_type_psymtabs (struct objfile *objfile)
3615 if (! create_debug_types_hash_table (objfile))
3618 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3619 process_type_comp_unit, objfile);
3622 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3625 psymtabs_addrmap_cleanup (void *o)
3627 struct objfile *objfile = o;
3629 objfile->psymtabs_addrmap = NULL;
3632 /* Build the partial symbol table by doing a quick pass through the
3633 .debug_info and .debug_abbrev sections. */
3636 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3639 struct cleanup *back_to, *addrmap_cleanup;
3640 struct obstack temp_obstack;
3642 dwarf2_per_objfile->reading_partial_symbols = 1;
3644 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3645 info_ptr = dwarf2_per_objfile->info.buffer;
3647 /* Any cached compilation units will be linked by the per-objfile
3648 read_in_chain. Make sure to free them when we're done. */
3649 back_to = make_cleanup (free_cached_comp_units, NULL);
3651 build_type_psymtabs (objfile);
3653 create_all_comp_units (objfile);
3655 /* Create a temporary address map on a temporary obstack. We later
3656 copy this to the final obstack. */
3657 obstack_init (&temp_obstack);
3658 make_cleanup_obstack_free (&temp_obstack);
3659 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3660 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3662 /* Since the objects we're extracting from .debug_info vary in
3663 length, only the individual functions to extract them (like
3664 read_comp_unit_head and load_partial_die) can really know whether
3665 the buffer is large enough to hold another complete object.
3667 At the moment, they don't actually check that. If .debug_info
3668 holds just one extra byte after the last compilation unit's dies,
3669 then read_comp_unit_head will happily read off the end of the
3670 buffer. read_partial_die is similarly casual. Those functions
3673 For this loop condition, simply checking whether there's any data
3674 left at all should be sufficient. */
3676 while (info_ptr < (dwarf2_per_objfile->info.buffer
3677 + dwarf2_per_objfile->info.size))
3679 struct dwarf2_per_cu_data *this_cu;
3681 this_cu = dwarf2_find_comp_unit (info_ptr
3682 - dwarf2_per_objfile->info.buffer,
3685 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3686 dwarf2_per_objfile->info.buffer,
3688 dwarf2_per_objfile->info.size);
3691 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3692 &objfile->objfile_obstack);
3693 discard_cleanups (addrmap_cleanup);
3695 do_cleanups (back_to);
3698 /* Load the partial DIEs for a secondary CU into memory. */
3701 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3702 struct objfile *objfile)
3704 bfd *abfd = objfile->obfd;
3706 struct die_info *comp_unit_die;
3707 struct dwarf2_cu *cu;
3708 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3710 struct die_reader_specs reader_specs;
3713 gdb_assert (! this_cu->debug_types_section);
3715 gdb_assert (dwarf2_per_objfile->info.readin);
3716 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3718 if (this_cu->cu == NULL)
3720 cu = xmalloc (sizeof (*cu));
3721 init_one_comp_unit (cu, objfile);
3725 /* If an error occurs while loading, release our storage. */
3726 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3728 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3729 dwarf2_per_objfile->info.buffer,
3730 dwarf2_per_objfile->info.size,
3733 /* Skip dummy compilation units. */
3734 if (info_ptr >= (dwarf2_per_objfile->info.buffer
3735 + dwarf2_per_objfile->info.size)
3736 || peek_abbrev_code (abfd, info_ptr) == 0)
3738 do_cleanups (free_cu_cleanup);
3742 /* Link this compilation unit into the compilation unit tree. */
3744 cu->per_cu = this_cu;
3746 /* Link this CU into read_in_chain. */
3747 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3748 dwarf2_per_objfile->read_in_chain = this_cu;
3753 info_ptr += cu->header.first_die_offset;
3756 /* Read the abbrevs for this compilation unit into a table. */
3757 gdb_assert (cu->dwarf2_abbrevs == NULL);
3758 dwarf2_read_abbrevs (abfd, cu);
3759 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3761 /* Read the compilation unit die. */
3762 init_cu_die_reader (&reader_specs, cu);
3763 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3766 prepare_one_comp_unit (cu, comp_unit_die);
3768 /* Check if comp unit has_children.
3769 If so, read the rest of the partial symbols from this comp unit.
3770 If not, there's no more debug_info for this comp unit. */
3772 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3774 do_cleanups (free_abbrevs_cleanup);
3778 /* We've successfully allocated this compilation unit. Let our
3779 caller clean it up when finished with it. */
3780 discard_cleanups (free_cu_cleanup);
3784 /* Create a list of all compilation units in OBJFILE. We do this only
3785 if an inter-comp-unit reference is found; presumably if there is one,
3786 there will be many, and one will occur early in the .debug_info section.
3787 So there's no point in building this list incrementally. */
3790 create_all_comp_units (struct objfile *objfile)
3794 struct dwarf2_per_cu_data **all_comp_units;
3797 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3798 info_ptr = dwarf2_per_objfile->info.buffer;
3802 all_comp_units = xmalloc (n_allocated
3803 * sizeof (struct dwarf2_per_cu_data *));
3805 while (info_ptr < dwarf2_per_objfile->info.buffer
3806 + dwarf2_per_objfile->info.size)
3808 unsigned int length, initial_length_size;
3809 struct dwarf2_per_cu_data *this_cu;
3810 unsigned int offset;
3812 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3814 /* Read just enough information to find out where the next
3815 compilation unit is. */
3816 length = read_initial_length (objfile->obfd, info_ptr,
3817 &initial_length_size);
3819 /* Save the compilation unit for later lookup. */
3820 this_cu = obstack_alloc (&objfile->objfile_obstack,
3821 sizeof (struct dwarf2_per_cu_data));
3822 memset (this_cu, 0, sizeof (*this_cu));
3823 this_cu->offset = offset;
3824 this_cu->length = length + initial_length_size;
3825 this_cu->objfile = objfile;
3827 if (n_comp_units == n_allocated)
3830 all_comp_units = xrealloc (all_comp_units,
3832 * sizeof (struct dwarf2_per_cu_data *));
3834 all_comp_units[n_comp_units++] = this_cu;
3836 info_ptr = info_ptr + this_cu->length;
3839 dwarf2_per_objfile->all_comp_units
3840 = obstack_alloc (&objfile->objfile_obstack,
3841 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3842 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3843 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3844 xfree (all_comp_units);
3845 dwarf2_per_objfile->n_comp_units = n_comp_units;
3848 /* Process all loaded DIEs for compilation unit CU, starting at
3849 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3850 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3851 DW_AT_ranges). If NEED_PC is set, then this function will set
3852 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3853 and record the covered ranges in the addrmap. */
3856 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3857 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3859 struct partial_die_info *pdi;
3861 /* Now, march along the PDI's, descending into ones which have
3862 interesting children but skipping the children of the other ones,
3863 until we reach the end of the compilation unit. */
3869 fixup_partial_die (pdi, cu);
3871 /* Anonymous namespaces or modules have no name but have interesting
3872 children, so we need to look at them. Ditto for anonymous
3875 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3876 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3880 case DW_TAG_subprogram:
3881 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3883 case DW_TAG_constant:
3884 case DW_TAG_variable:
3885 case DW_TAG_typedef:
3886 case DW_TAG_union_type:
3887 if (!pdi->is_declaration)
3889 add_partial_symbol (pdi, cu);
3892 case DW_TAG_class_type:
3893 case DW_TAG_interface_type:
3894 case DW_TAG_structure_type:
3895 if (!pdi->is_declaration)
3897 add_partial_symbol (pdi, cu);
3900 case DW_TAG_enumeration_type:
3901 if (!pdi->is_declaration)
3902 add_partial_enumeration (pdi, cu);
3904 case DW_TAG_base_type:
3905 case DW_TAG_subrange_type:
3906 /* File scope base type definitions are added to the partial
3908 add_partial_symbol (pdi, cu);
3910 case DW_TAG_namespace:
3911 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3914 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3921 /* If the die has a sibling, skip to the sibling. */
3923 pdi = pdi->die_sibling;
3927 /* Functions used to compute the fully scoped name of a partial DIE.
3929 Normally, this is simple. For C++, the parent DIE's fully scoped
3930 name is concatenated with "::" and the partial DIE's name. For
3931 Java, the same thing occurs except that "." is used instead of "::".
3932 Enumerators are an exception; they use the scope of their parent
3933 enumeration type, i.e. the name of the enumeration type is not
3934 prepended to the enumerator.
3936 There are two complexities. One is DW_AT_specification; in this
3937 case "parent" means the parent of the target of the specification,
3938 instead of the direct parent of the DIE. The other is compilers
3939 which do not emit DW_TAG_namespace; in this case we try to guess
3940 the fully qualified name of structure types from their members'
3941 linkage names. This must be done using the DIE's children rather
3942 than the children of any DW_AT_specification target. We only need
3943 to do this for structures at the top level, i.e. if the target of
3944 any DW_AT_specification (if any; otherwise the DIE itself) does not
3947 /* Compute the scope prefix associated with PDI's parent, in
3948 compilation unit CU. The result will be allocated on CU's
3949 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3950 field. NULL is returned if no prefix is necessary. */
3952 partial_die_parent_scope (struct partial_die_info *pdi,
3953 struct dwarf2_cu *cu)
3955 char *grandparent_scope;
3956 struct partial_die_info *parent, *real_pdi;
3958 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3959 then this means the parent of the specification DIE. */
3962 while (real_pdi->has_specification)
3963 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3965 parent = real_pdi->die_parent;
3969 if (parent->scope_set)
3970 return parent->scope;
3972 fixup_partial_die (parent, cu);
3974 grandparent_scope = partial_die_parent_scope (parent, cu);
3976 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3977 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3978 Work around this problem here. */
3979 if (cu->language == language_cplus
3980 && parent->tag == DW_TAG_namespace
3981 && strcmp (parent->name, "::") == 0
3982 && grandparent_scope == NULL)
3984 parent->scope = NULL;
3985 parent->scope_set = 1;
3989 if (pdi->tag == DW_TAG_enumerator)
3990 /* Enumerators should not get the name of the enumeration as a prefix. */
3991 parent->scope = grandparent_scope;
3992 else if (parent->tag == DW_TAG_namespace
3993 || parent->tag == DW_TAG_module
3994 || parent->tag == DW_TAG_structure_type
3995 || parent->tag == DW_TAG_class_type
3996 || parent->tag == DW_TAG_interface_type
3997 || parent->tag == DW_TAG_union_type
3998 || parent->tag == DW_TAG_enumeration_type)
4000 if (grandparent_scope == NULL)
4001 parent->scope = parent->name;
4003 parent->scope = typename_concat (&cu->comp_unit_obstack,
4005 parent->name, 0, cu);
4009 /* FIXME drow/2004-04-01: What should we be doing with
4010 function-local names? For partial symbols, we should probably be
4012 complaint (&symfile_complaints,
4013 _("unhandled containing DIE tag %d for DIE at %d"),
4014 parent->tag, pdi->offset);
4015 parent->scope = grandparent_scope;
4018 parent->scope_set = 1;
4019 return parent->scope;
4022 /* Return the fully scoped name associated with PDI, from compilation unit
4023 CU. The result will be allocated with malloc. */
4025 partial_die_full_name (struct partial_die_info *pdi,
4026 struct dwarf2_cu *cu)
4030 /* If this is a template instantiation, we can not work out the
4031 template arguments from partial DIEs. So, unfortunately, we have
4032 to go through the full DIEs. At least any work we do building
4033 types here will be reused if full symbols are loaded later. */
4034 if (pdi->has_template_arguments)
4036 fixup_partial_die (pdi, cu);
4038 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
4040 struct die_info *die;
4041 struct attribute attr;
4042 struct dwarf2_cu *ref_cu = cu;
4045 attr.form = DW_FORM_ref_addr;
4046 attr.u.addr = pdi->offset;
4047 die = follow_die_ref (NULL, &attr, &ref_cu);
4049 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
4053 parent_scope = partial_die_parent_scope (pdi, cu);
4054 if (parent_scope == NULL)
4057 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
4061 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
4063 struct objfile *objfile = cu->objfile;
4065 char *actual_name = NULL;
4066 const struct partial_symbol *psym = NULL;
4068 int built_actual_name = 0;
4070 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4072 actual_name = partial_die_full_name (pdi, cu);
4074 built_actual_name = 1;
4076 if (actual_name == NULL)
4077 actual_name = pdi->name;
4081 case DW_TAG_subprogram:
4082 if (pdi->is_external || cu->language == language_ada)
4084 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4085 of the global scope. But in Ada, we want to be able to access
4086 nested procedures globally. So all Ada subprograms are stored
4087 in the global scope. */
4088 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4089 mst_text, objfile); */
4090 add_psymbol_to_list (actual_name, strlen (actual_name),
4092 VAR_DOMAIN, LOC_BLOCK,
4093 &objfile->global_psymbols,
4094 0, pdi->lowpc + baseaddr,
4095 cu->language, objfile);
4099 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4100 mst_file_text, objfile); */
4101 add_psymbol_to_list (actual_name, strlen (actual_name),
4103 VAR_DOMAIN, LOC_BLOCK,
4104 &objfile->static_psymbols,
4105 0, pdi->lowpc + baseaddr,
4106 cu->language, objfile);
4109 case DW_TAG_constant:
4111 struct psymbol_allocation_list *list;
4113 if (pdi->is_external)
4114 list = &objfile->global_psymbols;
4116 list = &objfile->static_psymbols;
4117 add_psymbol_to_list (actual_name, strlen (actual_name),
4118 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4119 list, 0, 0, cu->language, objfile);
4122 case DW_TAG_variable:
4124 addr = decode_locdesc (pdi->locdesc, cu);
4128 && !dwarf2_per_objfile->has_section_at_zero)
4130 /* A global or static variable may also have been stripped
4131 out by the linker if unused, in which case its address
4132 will be nullified; do not add such variables into partial
4133 symbol table then. */
4135 else if (pdi->is_external)
4138 Don't enter into the minimal symbol tables as there is
4139 a minimal symbol table entry from the ELF symbols already.
4140 Enter into partial symbol table if it has a location
4141 descriptor or a type.
4142 If the location descriptor is missing, new_symbol will create
4143 a LOC_UNRESOLVED symbol, the address of the variable will then
4144 be determined from the minimal symbol table whenever the variable
4146 The address for the partial symbol table entry is not
4147 used by GDB, but it comes in handy for debugging partial symbol
4150 if (pdi->locdesc || pdi->has_type)
4151 add_psymbol_to_list (actual_name, strlen (actual_name),
4153 VAR_DOMAIN, LOC_STATIC,
4154 &objfile->global_psymbols,
4156 cu->language, objfile);
4160 /* Static Variable. Skip symbols without location descriptors. */
4161 if (pdi->locdesc == NULL)
4163 if (built_actual_name)
4164 xfree (actual_name);
4167 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4168 mst_file_data, objfile); */
4169 add_psymbol_to_list (actual_name, strlen (actual_name),
4171 VAR_DOMAIN, LOC_STATIC,
4172 &objfile->static_psymbols,
4174 cu->language, objfile);
4177 case DW_TAG_typedef:
4178 case DW_TAG_base_type:
4179 case DW_TAG_subrange_type:
4180 add_psymbol_to_list (actual_name, strlen (actual_name),
4182 VAR_DOMAIN, LOC_TYPEDEF,
4183 &objfile->static_psymbols,
4184 0, (CORE_ADDR) 0, cu->language, objfile);
4186 case DW_TAG_namespace:
4187 add_psymbol_to_list (actual_name, strlen (actual_name),
4189 VAR_DOMAIN, LOC_TYPEDEF,
4190 &objfile->global_psymbols,
4191 0, (CORE_ADDR) 0, cu->language, objfile);
4193 case DW_TAG_class_type:
4194 case DW_TAG_interface_type:
4195 case DW_TAG_structure_type:
4196 case DW_TAG_union_type:
4197 case DW_TAG_enumeration_type:
4198 /* Skip external references. The DWARF standard says in the section
4199 about "Structure, Union, and Class Type Entries": "An incomplete
4200 structure, union or class type is represented by a structure,
4201 union or class entry that does not have a byte size attribute
4202 and that has a DW_AT_declaration attribute." */
4203 if (!pdi->has_byte_size && pdi->is_declaration)
4205 if (built_actual_name)
4206 xfree (actual_name);
4210 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4211 static vs. global. */
4212 add_psymbol_to_list (actual_name, strlen (actual_name),
4214 STRUCT_DOMAIN, LOC_TYPEDEF,
4215 (cu->language == language_cplus
4216 || cu->language == language_java)
4217 ? &objfile->global_psymbols
4218 : &objfile->static_psymbols,
4219 0, (CORE_ADDR) 0, cu->language, objfile);
4222 case DW_TAG_enumerator:
4223 add_psymbol_to_list (actual_name, strlen (actual_name),
4225 VAR_DOMAIN, LOC_CONST,
4226 (cu->language == language_cplus
4227 || cu->language == language_java)
4228 ? &objfile->global_psymbols
4229 : &objfile->static_psymbols,
4230 0, (CORE_ADDR) 0, cu->language, objfile);
4236 if (built_actual_name)
4237 xfree (actual_name);
4240 /* Read a partial die corresponding to a namespace; also, add a symbol
4241 corresponding to that namespace to the symbol table. NAMESPACE is
4242 the name of the enclosing namespace. */
4245 add_partial_namespace (struct partial_die_info *pdi,
4246 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4247 int need_pc, struct dwarf2_cu *cu)
4249 /* Add a symbol for the namespace. */
4251 add_partial_symbol (pdi, cu);
4253 /* Now scan partial symbols in that namespace. */
4255 if (pdi->has_children)
4256 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4259 /* Read a partial die corresponding to a Fortran module. */
4262 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4263 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4265 /* Now scan partial symbols in that module. */
4267 if (pdi->has_children)
4268 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4271 /* Read a partial die corresponding to a subprogram and create a partial
4272 symbol for that subprogram. When the CU language allows it, this
4273 routine also defines a partial symbol for each nested subprogram
4274 that this subprogram contains.
4276 DIE my also be a lexical block, in which case we simply search
4277 recursively for suprograms defined inside that lexical block.
4278 Again, this is only performed when the CU language allows this
4279 type of definitions. */
4282 add_partial_subprogram (struct partial_die_info *pdi,
4283 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4284 int need_pc, struct dwarf2_cu *cu)
4286 if (pdi->tag == DW_TAG_subprogram)
4288 if (pdi->has_pc_info)
4290 if (pdi->lowpc < *lowpc)
4291 *lowpc = pdi->lowpc;
4292 if (pdi->highpc > *highpc)
4293 *highpc = pdi->highpc;
4297 struct objfile *objfile = cu->objfile;
4299 baseaddr = ANOFFSET (objfile->section_offsets,
4300 SECT_OFF_TEXT (objfile));
4301 addrmap_set_empty (objfile->psymtabs_addrmap,
4302 pdi->lowpc + baseaddr,
4303 pdi->highpc - 1 + baseaddr,
4304 cu->per_cu->v.psymtab);
4306 if (!pdi->is_declaration)
4307 /* Ignore subprogram DIEs that do not have a name, they are
4308 illegal. Do not emit a complaint at this point, we will
4309 do so when we convert this psymtab into a symtab. */
4311 add_partial_symbol (pdi, cu);
4315 if (! pdi->has_children)
4318 if (cu->language == language_ada)
4320 pdi = pdi->die_child;
4323 fixup_partial_die (pdi, cu);
4324 if (pdi->tag == DW_TAG_subprogram
4325 || pdi->tag == DW_TAG_lexical_block)
4326 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4327 pdi = pdi->die_sibling;
4332 /* Read a partial die corresponding to an enumeration type. */
4335 add_partial_enumeration (struct partial_die_info *enum_pdi,
4336 struct dwarf2_cu *cu)
4338 struct partial_die_info *pdi;
4340 if (enum_pdi->name != NULL)
4341 add_partial_symbol (enum_pdi, cu);
4343 pdi = enum_pdi->die_child;
4346 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4347 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4349 add_partial_symbol (pdi, cu);
4350 pdi = pdi->die_sibling;
4354 /* Return the initial uleb128 in the die at INFO_PTR. */
4357 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
4359 unsigned int bytes_read;
4361 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4364 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4365 Return the corresponding abbrev, or NULL if the number is zero (indicating
4366 an empty DIE). In either case *BYTES_READ will be set to the length of
4367 the initial number. */
4369 static struct abbrev_info *
4370 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4371 struct dwarf2_cu *cu)
4373 bfd *abfd = cu->objfile->obfd;
4374 unsigned int abbrev_number;
4375 struct abbrev_info *abbrev;
4377 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4379 if (abbrev_number == 0)
4382 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4385 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4386 abbrev_number, bfd_get_filename (abfd));
4392 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4393 Returns a pointer to the end of a series of DIEs, terminated by an empty
4394 DIE. Any children of the skipped DIEs will also be skipped. */
4397 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4399 struct abbrev_info *abbrev;
4400 unsigned int bytes_read;
4404 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4406 return info_ptr + bytes_read;
4408 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4412 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4413 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4414 abbrev corresponding to that skipped uleb128 should be passed in
4415 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4419 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4420 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4422 unsigned int bytes_read;
4423 struct attribute attr;
4424 bfd *abfd = cu->objfile->obfd;
4425 unsigned int form, i;
4427 for (i = 0; i < abbrev->num_attrs; i++)
4429 /* The only abbrev we care about is DW_AT_sibling. */
4430 if (abbrev->attrs[i].name == DW_AT_sibling)
4432 read_attribute (&attr, &abbrev->attrs[i],
4433 abfd, info_ptr, cu);
4434 if (attr.form == DW_FORM_ref_addr)
4435 complaint (&symfile_complaints,
4436 _("ignoring absolute DW_AT_sibling"));
4438 return buffer + dwarf2_get_ref_die_offset (&attr);
4441 /* If it isn't DW_AT_sibling, skip this attribute. */
4442 form = abbrev->attrs[i].form;
4446 case DW_FORM_ref_addr:
4447 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4448 and later it is offset sized. */
4449 if (cu->header.version == 2)
4450 info_ptr += cu->header.addr_size;
4452 info_ptr += cu->header.offset_size;
4455 info_ptr += cu->header.addr_size;
4462 case DW_FORM_flag_present:
4474 case DW_FORM_ref_sig8:
4477 case DW_FORM_string:
4478 read_direct_string (abfd, info_ptr, &bytes_read);
4479 info_ptr += bytes_read;
4481 case DW_FORM_sec_offset:
4483 info_ptr += cu->header.offset_size;
4485 case DW_FORM_exprloc:
4487 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4488 info_ptr += bytes_read;
4490 case DW_FORM_block1:
4491 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4493 case DW_FORM_block2:
4494 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4496 case DW_FORM_block4:
4497 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4501 case DW_FORM_ref_udata:
4502 info_ptr = skip_leb128 (abfd, info_ptr);
4504 case DW_FORM_indirect:
4505 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4506 info_ptr += bytes_read;
4507 /* We need to continue parsing from here, so just go back to
4509 goto skip_attribute;
4512 error (_("Dwarf Error: Cannot handle %s "
4513 "in DWARF reader [in module %s]"),
4514 dwarf_form_name (form),
4515 bfd_get_filename (abfd));
4519 if (abbrev->has_children)
4520 return skip_children (buffer, info_ptr, cu);
4525 /* Locate ORIG_PDI's sibling.
4526 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4530 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4531 gdb_byte *buffer, gdb_byte *info_ptr,
4532 bfd *abfd, struct dwarf2_cu *cu)
4534 /* Do we know the sibling already? */
4536 if (orig_pdi->sibling)
4537 return orig_pdi->sibling;
4539 /* Are there any children to deal with? */
4541 if (!orig_pdi->has_children)
4544 /* Skip the children the long way. */
4546 return skip_children (buffer, info_ptr, cu);
4549 /* Expand this partial symbol table into a full symbol table. */
4552 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4558 warning (_("bug: psymtab for %s is already read in."),
4565 printf_filtered (_("Reading in symbols for %s..."),
4567 gdb_flush (gdb_stdout);
4570 /* Restore our global data. */
4571 dwarf2_per_objfile = objfile_data (pst->objfile,
4572 dwarf2_objfile_data_key);
4574 /* If this psymtab is constructed from a debug-only objfile, the
4575 has_section_at_zero flag will not necessarily be correct. We
4576 can get the correct value for this flag by looking at the data
4577 associated with the (presumably stripped) associated objfile. */
4578 if (pst->objfile->separate_debug_objfile_backlink)
4580 struct dwarf2_per_objfile *dpo_backlink
4581 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4582 dwarf2_objfile_data_key);
4584 dwarf2_per_objfile->has_section_at_zero
4585 = dpo_backlink->has_section_at_zero;
4588 dwarf2_per_objfile->reading_partial_symbols = 0;
4590 psymtab_to_symtab_1 (pst);
4592 /* Finish up the debug error message. */
4594 printf_filtered (_("done.\n"));
4599 /* Add PER_CU to the queue. */
4602 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4604 struct dwarf2_queue_item *item;
4607 item = xmalloc (sizeof (*item));
4608 item->per_cu = per_cu;
4611 if (dwarf2_queue == NULL)
4612 dwarf2_queue = item;
4614 dwarf2_queue_tail->next = item;
4616 dwarf2_queue_tail = item;
4619 /* Process the queue. */
4622 process_queue (struct objfile *objfile)
4624 struct dwarf2_queue_item *item, *next_item;
4626 /* The queue starts out with one item, but following a DIE reference
4627 may load a new CU, adding it to the end of the queue. */
4628 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4630 if (dwarf2_per_objfile->using_index
4631 ? !item->per_cu->v.quick->symtab
4632 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4633 process_full_comp_unit (item->per_cu);
4635 item->per_cu->queued = 0;
4636 next_item = item->next;
4640 dwarf2_queue_tail = NULL;
4643 /* Free all allocated queue entries. This function only releases anything if
4644 an error was thrown; if the queue was processed then it would have been
4645 freed as we went along. */
4648 dwarf2_release_queue (void *dummy)
4650 struct dwarf2_queue_item *item, *last;
4652 item = dwarf2_queue;
4655 /* Anything still marked queued is likely to be in an
4656 inconsistent state, so discard it. */
4657 if (item->per_cu->queued)
4659 if (item->per_cu->cu != NULL)
4660 free_one_cached_comp_unit (item->per_cu->cu);
4661 item->per_cu->queued = 0;
4669 dwarf2_queue = dwarf2_queue_tail = NULL;
4672 /* Read in full symbols for PST, and anything it depends on. */
4675 psymtab_to_symtab_1 (struct partial_symtab *pst)
4677 struct dwarf2_per_cu_data *per_cu;
4678 struct cleanup *back_to;
4681 for (i = 0; i < pst->number_of_dependencies; i++)
4682 if (!pst->dependencies[i]->readin)
4684 /* Inform about additional files that need to be read in. */
4687 /* FIXME: i18n: Need to make this a single string. */
4688 fputs_filtered (" ", gdb_stdout);
4690 fputs_filtered ("and ", gdb_stdout);
4692 printf_filtered ("%s...", pst->dependencies[i]->filename);
4693 wrap_here (""); /* Flush output. */
4694 gdb_flush (gdb_stdout);
4696 psymtab_to_symtab_1 (pst->dependencies[i]);
4699 per_cu = pst->read_symtab_private;
4703 /* It's an include file, no symbols to read for it.
4704 Everything is in the parent symtab. */
4709 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4712 /* Load the DIEs associated with PER_CU into memory. */
4715 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4716 struct objfile *objfile)
4718 bfd *abfd = objfile->obfd;
4719 struct dwarf2_cu *cu;
4720 unsigned int offset;
4721 gdb_byte *info_ptr, *beg_of_comp_unit;
4722 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4723 struct attribute *attr;
4726 gdb_assert (! per_cu->debug_types_section);
4728 /* Set local variables from the partial symbol table info. */
4729 offset = per_cu->offset;
4731 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4732 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4733 beg_of_comp_unit = info_ptr;
4735 if (per_cu->cu == NULL)
4737 cu = xmalloc (sizeof (*cu));
4738 init_one_comp_unit (cu, objfile);
4742 /* If an error occurs while loading, release our storage. */
4743 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4745 /* Read in the comp_unit header. */
4746 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4748 /* Skip dummy compilation units. */
4749 if (info_ptr >= (dwarf2_per_objfile->info.buffer
4750 + dwarf2_per_objfile->info.size)
4751 || peek_abbrev_code (abfd, info_ptr) == 0)
4753 do_cleanups (free_cu_cleanup);
4757 /* Complete the cu_header. */
4758 cu->header.offset = offset;
4759 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4761 /* Read the abbrevs for this compilation unit. */
4762 dwarf2_read_abbrevs (abfd, cu);
4763 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4765 /* Link this compilation unit into the compilation unit tree. */
4767 cu->per_cu = per_cu;
4769 /* Link this CU into read_in_chain. */
4770 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4771 dwarf2_per_objfile->read_in_chain = per_cu;
4776 info_ptr += cu->header.first_die_offset;
4779 cu->dies = read_comp_unit (info_ptr, cu);
4781 /* We try not to read any attributes in this function, because not
4782 all objfiles needed for references have been loaded yet, and symbol
4783 table processing isn't initialized. But we have to set the CU language,
4784 or we won't be able to build types correctly. */
4785 prepare_one_comp_unit (cu, cu->dies);
4787 /* Similarly, if we do not read the producer, we can not apply
4788 producer-specific interpretation. */
4789 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4791 cu->producer = DW_STRING (attr);
4795 do_cleanups (free_abbrevs_cleanup);
4797 /* We've successfully allocated this compilation unit. Let our
4798 caller clean it up when finished with it. */
4799 discard_cleanups (free_cu_cleanup);
4803 /* Add a DIE to the delayed physname list. */
4806 add_to_method_list (struct type *type, int fnfield_index, int index,
4807 const char *name, struct die_info *die,
4808 struct dwarf2_cu *cu)
4810 struct delayed_method_info mi;
4812 mi.fnfield_index = fnfield_index;
4816 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4819 /* A cleanup for freeing the delayed method list. */
4822 free_delayed_list (void *ptr)
4824 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4825 if (cu->method_list != NULL)
4827 VEC_free (delayed_method_info, cu->method_list);
4828 cu->method_list = NULL;
4832 /* Compute the physnames of any methods on the CU's method list.
4834 The computation of method physnames is delayed in order to avoid the
4835 (bad) condition that one of the method's formal parameters is of an as yet
4839 compute_delayed_physnames (struct dwarf2_cu *cu)
4842 struct delayed_method_info *mi;
4843 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4845 const char *physname;
4846 struct fn_fieldlist *fn_flp
4847 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4848 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4849 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4853 /* Generate full symbol information for PST and CU, whose DIEs have
4854 already been loaded into memory. */
4857 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4859 struct dwarf2_cu *cu = per_cu->cu;
4860 struct objfile *objfile = per_cu->objfile;
4861 CORE_ADDR lowpc, highpc;
4862 struct symtab *symtab;
4863 struct cleanup *back_to, *delayed_list_cleanup;
4866 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4869 back_to = make_cleanup (really_free_pendings, NULL);
4870 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4872 cu->list_in_scope = &file_symbols;
4874 /* Do line number decoding in read_file_scope () */
4875 process_die (cu->dies, cu);
4877 /* Now that we have processed all the DIEs in the CU, all the types
4878 should be complete, and it should now be safe to compute all of the
4880 compute_delayed_physnames (cu);
4881 do_cleanups (delayed_list_cleanup);
4883 /* Some compilers don't define a DW_AT_high_pc attribute for the
4884 compilation unit. If the DW_AT_high_pc is missing, synthesize
4885 it, by scanning the DIE's below the compilation unit. */
4886 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4888 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4892 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4894 /* Set symtab language to language from DW_AT_language. If the
4895 compilation is from a C file generated by language preprocessors, do
4896 not set the language if it was already deduced by start_subfile. */
4897 if (!(cu->language == language_c && symtab->language != language_c))
4898 symtab->language = cu->language;
4900 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4901 produce DW_AT_location with location lists but it can be possibly
4902 invalid without -fvar-tracking.
4904 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4905 needed, it would be wrong due to missing DW_AT_producer there.
4907 Still one can confuse GDB by using non-standard GCC compilation
4908 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4910 if (cu->has_loclist && gcc_4_minor >= 0)
4911 symtab->locations_valid = 1;
4913 if (gcc_4_minor >= 5)
4914 symtab->epilogue_unwind_valid = 1;
4916 symtab->call_site_htab = cu->call_site_htab;
4919 if (dwarf2_per_objfile->using_index)
4920 per_cu->v.quick->symtab = symtab;
4923 struct partial_symtab *pst = per_cu->v.psymtab;
4924 pst->symtab = symtab;
4928 do_cleanups (back_to);
4931 /* Process a die and its children. */
4934 process_die (struct die_info *die, struct dwarf2_cu *cu)
4938 case DW_TAG_padding:
4940 case DW_TAG_compile_unit:
4941 read_file_scope (die, cu);
4943 case DW_TAG_type_unit:
4944 read_type_unit_scope (die, cu);
4946 case DW_TAG_subprogram:
4947 case DW_TAG_inlined_subroutine:
4948 read_func_scope (die, cu);
4950 case DW_TAG_lexical_block:
4951 case DW_TAG_try_block:
4952 case DW_TAG_catch_block:
4953 read_lexical_block_scope (die, cu);
4955 case DW_TAG_GNU_call_site:
4956 read_call_site_scope (die, cu);
4958 case DW_TAG_class_type:
4959 case DW_TAG_interface_type:
4960 case DW_TAG_structure_type:
4961 case DW_TAG_union_type:
4962 process_structure_scope (die, cu);
4964 case DW_TAG_enumeration_type:
4965 process_enumeration_scope (die, cu);
4968 /* These dies have a type, but processing them does not create
4969 a symbol or recurse to process the children. Therefore we can
4970 read them on-demand through read_type_die. */
4971 case DW_TAG_subroutine_type:
4972 case DW_TAG_set_type:
4973 case DW_TAG_array_type:
4974 case DW_TAG_pointer_type:
4975 case DW_TAG_ptr_to_member_type:
4976 case DW_TAG_reference_type:
4977 case DW_TAG_string_type:
4980 case DW_TAG_base_type:
4981 case DW_TAG_subrange_type:
4982 case DW_TAG_typedef:
4983 /* Add a typedef symbol for the type definition, if it has a
4985 new_symbol (die, read_type_die (die, cu), cu);
4987 case DW_TAG_common_block:
4988 read_common_block (die, cu);
4990 case DW_TAG_common_inclusion:
4992 case DW_TAG_namespace:
4993 processing_has_namespace_info = 1;
4994 read_namespace (die, cu);
4997 processing_has_namespace_info = 1;
4998 read_module (die, cu);
5000 case DW_TAG_imported_declaration:
5001 case DW_TAG_imported_module:
5002 processing_has_namespace_info = 1;
5003 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
5004 || cu->language != language_fortran))
5005 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
5006 dwarf_tag_name (die->tag));
5007 read_import_statement (die, cu);
5010 new_symbol (die, NULL, cu);
5015 /* A helper function for dwarf2_compute_name which determines whether DIE
5016 needs to have the name of the scope prepended to the name listed in the
5020 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
5022 struct attribute *attr;
5026 case DW_TAG_namespace:
5027 case DW_TAG_typedef:
5028 case DW_TAG_class_type:
5029 case DW_TAG_interface_type:
5030 case DW_TAG_structure_type:
5031 case DW_TAG_union_type:
5032 case DW_TAG_enumeration_type:
5033 case DW_TAG_enumerator:
5034 case DW_TAG_subprogram:
5038 case DW_TAG_variable:
5039 case DW_TAG_constant:
5040 /* We only need to prefix "globally" visible variables. These include
5041 any variable marked with DW_AT_external or any variable that
5042 lives in a namespace. [Variables in anonymous namespaces
5043 require prefixing, but they are not DW_AT_external.] */
5045 if (dwarf2_attr (die, DW_AT_specification, cu))
5047 struct dwarf2_cu *spec_cu = cu;
5049 return die_needs_namespace (die_specification (die, &spec_cu),
5053 attr = dwarf2_attr (die, DW_AT_external, cu);
5054 if (attr == NULL && die->parent->tag != DW_TAG_namespace
5055 && die->parent->tag != DW_TAG_module)
5057 /* A variable in a lexical block of some kind does not need a
5058 namespace, even though in C++ such variables may be external
5059 and have a mangled name. */
5060 if (die->parent->tag == DW_TAG_lexical_block
5061 || die->parent->tag == DW_TAG_try_block
5062 || die->parent->tag == DW_TAG_catch_block
5063 || die->parent->tag == DW_TAG_subprogram)
5072 /* Retrieve the last character from a mem_file. */
5075 do_ui_file_peek_last (void *object, const char *buffer, long length)
5077 char *last_char_p = (char *) object;
5080 *last_char_p = buffer[length - 1];
5083 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5084 compute the physname for the object, which include a method's
5085 formal parameters (C++/Java) and return type (Java).
5087 For Ada, return the DIE's linkage name rather than the fully qualified
5088 name. PHYSNAME is ignored..
5090 The result is allocated on the objfile_obstack and canonicalized. */
5093 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
5097 name = dwarf2_name (die, cu);
5099 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5100 compute it by typename_concat inside GDB. */
5101 if (cu->language == language_ada
5102 || (cu->language == language_fortran && physname))
5104 /* For Ada unit, we prefer the linkage name over the name, as
5105 the former contains the exported name, which the user expects
5106 to be able to reference. Ideally, we want the user to be able
5107 to reference this entity using either natural or linkage name,
5108 but we haven't started looking at this enhancement yet. */
5109 struct attribute *attr;
5111 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5113 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5114 if (attr && DW_STRING (attr))
5115 return DW_STRING (attr);
5118 /* These are the only languages we know how to qualify names in. */
5120 && (cu->language == language_cplus || cu->language == language_java
5121 || cu->language == language_fortran))
5123 if (die_needs_namespace (die, cu))
5127 struct ui_file *buf;
5129 prefix = determine_prefix (die, cu);
5130 buf = mem_fileopen ();
5131 if (*prefix != '\0')
5133 char *prefixed_name = typename_concat (NULL, prefix, name,
5136 fputs_unfiltered (prefixed_name, buf);
5137 xfree (prefixed_name);
5140 fputs_unfiltered (name, buf);
5142 /* Template parameters may be specified in the DIE's DW_AT_name, or
5143 as children with DW_TAG_template_type_param or
5144 DW_TAG_value_type_param. If the latter, add them to the name
5145 here. If the name already has template parameters, then
5146 skip this step; some versions of GCC emit both, and
5147 it is more efficient to use the pre-computed name.
5149 Something to keep in mind about this process: it is very
5150 unlikely, or in some cases downright impossible, to produce
5151 something that will match the mangled name of a function.
5152 If the definition of the function has the same debug info,
5153 we should be able to match up with it anyway. But fallbacks
5154 using the minimal symbol, for instance to find a method
5155 implemented in a stripped copy of libstdc++, will not work.
5156 If we do not have debug info for the definition, we will have to
5157 match them up some other way.
5159 When we do name matching there is a related problem with function
5160 templates; two instantiated function templates are allowed to
5161 differ only by their return types, which we do not add here. */
5163 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5165 struct attribute *attr;
5166 struct die_info *child;
5169 die->building_fullname = 1;
5171 for (child = die->child; child != NULL; child = child->sibling)
5176 struct dwarf2_locexpr_baton *baton;
5179 if (child->tag != DW_TAG_template_type_param
5180 && child->tag != DW_TAG_template_value_param)
5185 fputs_unfiltered ("<", buf);
5189 fputs_unfiltered (", ", buf);
5191 attr = dwarf2_attr (child, DW_AT_type, cu);
5194 complaint (&symfile_complaints,
5195 _("template parameter missing DW_AT_type"));
5196 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5199 type = die_type (child, cu);
5201 if (child->tag == DW_TAG_template_type_param)
5203 c_print_type (type, "", buf, -1, 0);
5207 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5210 complaint (&symfile_complaints,
5211 _("template parameter missing "
5212 "DW_AT_const_value"));
5213 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5217 dwarf2_const_value_attr (attr, type, name,
5218 &cu->comp_unit_obstack, cu,
5219 &value, &bytes, &baton);
5221 if (TYPE_NOSIGN (type))
5222 /* GDB prints characters as NUMBER 'CHAR'. If that's
5223 changed, this can use value_print instead. */
5224 c_printchar (value, type, buf);
5227 struct value_print_options opts;
5230 v = dwarf2_evaluate_loc_desc (type, NULL,
5234 else if (bytes != NULL)
5236 v = allocate_value (type);
5237 memcpy (value_contents_writeable (v), bytes,
5238 TYPE_LENGTH (type));
5241 v = value_from_longest (type, value);
5243 /* Specify decimal so that we do not depend on
5245 get_formatted_print_options (&opts, 'd');
5247 value_print (v, buf, &opts);
5253 die->building_fullname = 0;
5257 /* Close the argument list, with a space if necessary
5258 (nested templates). */
5259 char last_char = '\0';
5260 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5261 if (last_char == '>')
5262 fputs_unfiltered (" >", buf);
5264 fputs_unfiltered (">", buf);
5268 /* For Java and C++ methods, append formal parameter type
5269 information, if PHYSNAME. */
5271 if (physname && die->tag == DW_TAG_subprogram
5272 && (cu->language == language_cplus
5273 || cu->language == language_java))
5275 struct type *type = read_type_die (die, cu);
5277 c_type_print_args (type, buf, 1, cu->language);
5279 if (cu->language == language_java)
5281 /* For java, we must append the return type to method
5283 if (die->tag == DW_TAG_subprogram)
5284 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5287 else if (cu->language == language_cplus)
5289 /* Assume that an artificial first parameter is
5290 "this", but do not crash if it is not. RealView
5291 marks unnamed (and thus unused) parameters as
5292 artificial; there is no way to differentiate
5294 if (TYPE_NFIELDS (type) > 0
5295 && TYPE_FIELD_ARTIFICIAL (type, 0)
5296 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5297 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5299 fputs_unfiltered (" const", buf);
5303 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5305 ui_file_delete (buf);
5307 if (cu->language == language_cplus)
5310 = dwarf2_canonicalize_name (name, cu,
5311 &cu->objfile->objfile_obstack);
5322 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5323 If scope qualifiers are appropriate they will be added. The result
5324 will be allocated on the objfile_obstack, or NULL if the DIE does
5325 not have a name. NAME may either be from a previous call to
5326 dwarf2_name or NULL.
5328 The output string will be canonicalized (if C++/Java). */
5331 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5333 return dwarf2_compute_name (name, die, cu, 0);
5336 /* Construct a physname for the given DIE in CU. NAME may either be
5337 from a previous call to dwarf2_name or NULL. The result will be
5338 allocated on the objfile_objstack or NULL if the DIE does not have a
5341 The output string will be canonicalized (if C++/Java). */
5344 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5346 struct attribute *attr;
5347 const char *retval, *mangled = NULL, *canon = NULL;
5348 struct cleanup *back_to;
5351 /* In this case dwarf2_compute_name is just a shortcut not building anything
5353 if (!die_needs_namespace (die, cu))
5354 return dwarf2_compute_name (name, die, cu, 1);
5356 back_to = make_cleanup (null_cleanup, NULL);
5358 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5360 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5362 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5364 if (attr && DW_STRING (attr))
5368 mangled = DW_STRING (attr);
5370 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5371 type. It is easier for GDB users to search for such functions as
5372 `name(params)' than `long name(params)'. In such case the minimal
5373 symbol names do not match the full symbol names but for template
5374 functions there is never a need to look up their definition from their
5375 declaration so the only disadvantage remains the minimal symbol
5376 variant `long name(params)' does not have the proper inferior type.
5379 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5380 | (cu->language == language_java
5381 ? DMGL_JAVA | DMGL_RET_POSTFIX
5385 make_cleanup (xfree, demangled);
5395 if (canon == NULL || check_physname)
5397 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5399 if (canon != NULL && strcmp (physname, canon) != 0)
5401 /* It may not mean a bug in GDB. The compiler could also
5402 compute DW_AT_linkage_name incorrectly. But in such case
5403 GDB would need to be bug-to-bug compatible. */
5405 complaint (&symfile_complaints,
5406 _("Computed physname <%s> does not match demangled <%s> "
5407 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5408 physname, canon, mangled, die->offset, cu->objfile->name);
5410 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5411 is available here - over computed PHYSNAME. It is safer
5412 against both buggy GDB and buggy compilers. */
5426 retval = obsavestring (retval, strlen (retval),
5427 &cu->objfile->objfile_obstack);
5429 do_cleanups (back_to);
5433 /* Read the import statement specified by the given die and record it. */
5436 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5438 struct attribute *import_attr;
5439 struct die_info *imported_die, *child_die;
5440 struct dwarf2_cu *imported_cu;
5441 const char *imported_name;
5442 const char *imported_name_prefix;
5443 const char *canonical_name;
5444 const char *import_alias;
5445 const char *imported_declaration = NULL;
5446 const char *import_prefix;
5447 VEC (const_char_ptr) *excludes = NULL;
5448 struct cleanup *cleanups;
5452 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5453 if (import_attr == NULL)
5455 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5456 dwarf_tag_name (die->tag));
5461 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5462 imported_name = dwarf2_name (imported_die, imported_cu);
5463 if (imported_name == NULL)
5465 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5467 The import in the following code:
5481 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5482 <52> DW_AT_decl_file : 1
5483 <53> DW_AT_decl_line : 6
5484 <54> DW_AT_import : <0x75>
5485 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5487 <5b> DW_AT_decl_file : 1
5488 <5c> DW_AT_decl_line : 2
5489 <5d> DW_AT_type : <0x6e>
5491 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5492 <76> DW_AT_byte_size : 4
5493 <77> DW_AT_encoding : 5 (signed)
5495 imports the wrong die ( 0x75 instead of 0x58 ).
5496 This case will be ignored until the gcc bug is fixed. */
5500 /* Figure out the local name after import. */
5501 import_alias = dwarf2_name (die, cu);
5503 /* Figure out where the statement is being imported to. */
5504 import_prefix = determine_prefix (die, cu);
5506 /* Figure out what the scope of the imported die is and prepend it
5507 to the name of the imported die. */
5508 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5510 if (imported_die->tag != DW_TAG_namespace
5511 && imported_die->tag != DW_TAG_module)
5513 imported_declaration = imported_name;
5514 canonical_name = imported_name_prefix;
5516 else if (strlen (imported_name_prefix) > 0)
5518 temp = alloca (strlen (imported_name_prefix)
5519 + 2 + strlen (imported_name) + 1);
5520 strcpy (temp, imported_name_prefix);
5521 strcat (temp, "::");
5522 strcat (temp, imported_name);
5523 canonical_name = temp;
5526 canonical_name = imported_name;
5528 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5530 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5531 for (child_die = die->child; child_die && child_die->tag;
5532 child_die = sibling_die (child_die))
5534 /* DWARF-4: A Fortran use statement with a “rename list” may be
5535 represented by an imported module entry with an import attribute
5536 referring to the module and owned entries corresponding to those
5537 entities that are renamed as part of being imported. */
5539 if (child_die->tag != DW_TAG_imported_declaration)
5541 complaint (&symfile_complaints,
5542 _("child DW_TAG_imported_declaration expected "
5543 "- DIE at 0x%x [in module %s]"),
5544 child_die->offset, cu->objfile->name);
5548 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5549 if (import_attr == NULL)
5551 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5552 dwarf_tag_name (child_die->tag));
5557 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5559 imported_name = dwarf2_name (imported_die, imported_cu);
5560 if (imported_name == NULL)
5562 complaint (&symfile_complaints,
5563 _("child DW_TAG_imported_declaration has unknown "
5564 "imported name - DIE at 0x%x [in module %s]"),
5565 child_die->offset, cu->objfile->name);
5569 VEC_safe_push (const_char_ptr, excludes, imported_name);
5571 process_die (child_die, cu);
5574 cp_add_using_directive (import_prefix,
5577 imported_declaration,
5579 &cu->objfile->objfile_obstack);
5581 do_cleanups (cleanups);
5585 initialize_cu_func_list (struct dwarf2_cu *cu)
5587 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5590 /* Cleanup function for read_file_scope. */
5593 free_cu_line_header (void *arg)
5595 struct dwarf2_cu *cu = arg;
5597 free_line_header (cu->line_header);
5598 cu->line_header = NULL;
5602 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5603 char **name, char **comp_dir)
5605 struct attribute *attr;
5610 /* Find the filename. Do not use dwarf2_name here, since the filename
5611 is not a source language identifier. */
5612 attr = dwarf2_attr (die, DW_AT_name, cu);
5615 *name = DW_STRING (attr);
5618 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5620 *comp_dir = DW_STRING (attr);
5621 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5623 *comp_dir = ldirname (*name);
5624 if (*comp_dir != NULL)
5625 make_cleanup (xfree, *comp_dir);
5627 if (*comp_dir != NULL)
5629 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5630 directory, get rid of it. */
5631 char *cp = strchr (*comp_dir, ':');
5633 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5638 *name = "<unknown>";
5641 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5642 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5643 COMP_DIR is the compilation directory.
5644 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5647 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5648 const char *comp_dir, int want_line_info)
5650 struct attribute *attr;
5651 struct objfile *objfile = cu->objfile;
5652 bfd *abfd = objfile->obfd;
5654 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5657 unsigned int line_offset = DW_UNSND (attr);
5658 struct line_header *line_header
5659 = dwarf_decode_line_header (line_offset, abfd, cu);
5663 cu->line_header = line_header;
5664 make_cleanup (free_cu_line_header, cu);
5665 dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info);
5670 /* Process DW_TAG_compile_unit. */
5673 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5675 struct objfile *objfile = cu->objfile;
5676 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5677 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5678 CORE_ADDR highpc = ((CORE_ADDR) 0);
5679 struct attribute *attr;
5681 char *comp_dir = NULL;
5682 struct die_info *child_die;
5683 bfd *abfd = objfile->obfd;
5686 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5688 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5690 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5691 from finish_block. */
5692 if (lowpc == ((CORE_ADDR) -1))
5697 find_file_and_directory (die, cu, &name, &comp_dir);
5699 attr = dwarf2_attr (die, DW_AT_language, cu);
5702 set_cu_language (DW_UNSND (attr), cu);
5705 attr = dwarf2_attr (die, DW_AT_producer, cu);
5707 cu->producer = DW_STRING (attr);
5709 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5710 standardised yet. As a workaround for the language detection we fall
5711 back to the DW_AT_producer string. */
5712 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5713 cu->language = language_opencl;
5715 /* We assume that we're processing GCC output. */
5716 processing_gcc_compilation = 2;
5718 processing_has_namespace_info = 0;
5720 start_symtab (name, comp_dir, lowpc);
5721 record_debugformat ("DWARF 2");
5722 record_producer (cu->producer);
5724 initialize_cu_func_list (cu);
5726 /* Decode line number information if present. We do this before
5727 processing child DIEs, so that the line header table is available
5728 for DW_AT_decl_file. */
5729 handle_DW_AT_stmt_list (die, cu, comp_dir, 1);
5731 /* Process all dies in compilation unit. */
5732 if (die->child != NULL)
5734 child_die = die->child;
5735 while (child_die && child_die->tag)
5737 process_die (child_die, cu);
5738 child_die = sibling_die (child_die);
5742 /* Decode macro information, if present. Dwarf 2 macro information
5743 refers to information in the line number info statement program
5744 header, so we can only read it if we've read the header
5746 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5747 if (attr && cu->line_header)
5749 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5750 complaint (&symfile_complaints,
5751 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5753 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5755 &dwarf2_per_objfile->macro, 1);
5759 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5760 if (attr && cu->line_header)
5762 unsigned int macro_offset = DW_UNSND (attr);
5764 dwarf_decode_macros (cu->line_header, macro_offset,
5766 &dwarf2_per_objfile->macinfo, 0);
5769 do_cleanups (back_to);
5772 /* Process DW_TAG_type_unit.
5773 For TUs we want to skip the first top level sibling if it's not the
5774 actual type being defined by this TU. In this case the first top
5775 level sibling is there to provide context only. */
5778 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5780 struct objfile *objfile = cu->objfile;
5781 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5783 struct attribute *attr;
5785 char *comp_dir = NULL;
5786 struct die_info *child_die;
5787 bfd *abfd = objfile->obfd;
5789 /* start_symtab needs a low pc, but we don't really have one.
5790 Do what read_file_scope would do in the absence of such info. */
5791 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5793 /* Find the filename. Do not use dwarf2_name here, since the filename
5794 is not a source language identifier. */
5795 attr = dwarf2_attr (die, DW_AT_name, cu);
5797 name = DW_STRING (attr);
5799 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5801 comp_dir = DW_STRING (attr);
5802 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5804 comp_dir = ldirname (name);
5805 if (comp_dir != NULL)
5806 make_cleanup (xfree, comp_dir);
5812 attr = dwarf2_attr (die, DW_AT_language, cu);
5814 set_cu_language (DW_UNSND (attr), cu);
5816 /* This isn't technically needed today. It is done for symmetry
5817 with read_file_scope. */
5818 attr = dwarf2_attr (die, DW_AT_producer, cu);
5820 cu->producer = DW_STRING (attr);
5822 /* We assume that we're processing GCC output. */
5823 processing_gcc_compilation = 2;
5825 processing_has_namespace_info = 0;
5827 start_symtab (name, comp_dir, lowpc);
5828 record_debugformat ("DWARF 2");
5829 record_producer (cu->producer);
5831 /* Decode line number information if present. We do this before
5832 processing child DIEs, so that the line header table is available
5833 for DW_AT_decl_file.
5834 We don't need the pc/line-number mapping for type units. */
5835 handle_DW_AT_stmt_list (die, cu, comp_dir, 0);
5837 /* Process the dies in the type unit. */
5838 if (die->child == NULL)
5840 dump_die_for_error (die);
5841 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5842 bfd_get_filename (abfd));
5845 child_die = die->child;
5847 while (child_die && child_die->tag)
5849 process_die (child_die, cu);
5851 child_die = sibling_die (child_die);
5854 do_cleanups (back_to);
5858 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5859 struct dwarf2_cu *cu)
5861 struct function_range *thisfn;
5863 thisfn = (struct function_range *)
5864 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5865 thisfn->name = name;
5866 thisfn->lowpc = lowpc;
5867 thisfn->highpc = highpc;
5868 thisfn->seen_line = 0;
5869 thisfn->next = NULL;
5871 if (cu->last_fn == NULL)
5872 cu->first_fn = thisfn;
5874 cu->last_fn->next = thisfn;
5876 cu->last_fn = thisfn;
5879 /* qsort helper for inherit_abstract_dies. */
5882 unsigned_int_compar (const void *ap, const void *bp)
5884 unsigned int a = *(unsigned int *) ap;
5885 unsigned int b = *(unsigned int *) bp;
5887 return (a > b) - (b > a);
5890 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5891 Inherit only the children of the DW_AT_abstract_origin DIE not being
5892 already referenced by DW_AT_abstract_origin from the children of the
5896 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5898 struct die_info *child_die;
5899 unsigned die_children_count;
5900 /* CU offsets which were referenced by children of the current DIE. */
5902 unsigned *offsets_end, *offsetp;
5903 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5904 struct die_info *origin_die;
5905 /* Iterator of the ORIGIN_DIE children. */
5906 struct die_info *origin_child_die;
5907 struct cleanup *cleanups;
5908 struct attribute *attr;
5909 struct dwarf2_cu *origin_cu;
5910 struct pending **origin_previous_list_in_scope;
5912 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5916 /* Note that following die references may follow to a die in a
5920 origin_die = follow_die_ref (die, attr, &origin_cu);
5922 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5924 origin_previous_list_in_scope = origin_cu->list_in_scope;
5925 origin_cu->list_in_scope = cu->list_in_scope;
5927 if (die->tag != origin_die->tag
5928 && !(die->tag == DW_TAG_inlined_subroutine
5929 && origin_die->tag == DW_TAG_subprogram))
5930 complaint (&symfile_complaints,
5931 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5932 die->offset, origin_die->offset);
5934 child_die = die->child;
5935 die_children_count = 0;
5936 while (child_die && child_die->tag)
5938 child_die = sibling_die (child_die);
5939 die_children_count++;
5941 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5942 cleanups = make_cleanup (xfree, offsets);
5944 offsets_end = offsets;
5945 child_die = die->child;
5946 while (child_die && child_die->tag)
5948 /* For each CHILD_DIE, find the corresponding child of
5949 ORIGIN_DIE. If there is more than one layer of
5950 DW_AT_abstract_origin, follow them all; there shouldn't be,
5951 but GCC versions at least through 4.4 generate this (GCC PR
5953 struct die_info *child_origin_die = child_die;
5954 struct dwarf2_cu *child_origin_cu = cu;
5958 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5962 child_origin_die = follow_die_ref (child_origin_die, attr,
5966 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5967 counterpart may exist. */
5968 if (child_origin_die != child_die)
5970 if (child_die->tag != child_origin_die->tag
5971 && !(child_die->tag == DW_TAG_inlined_subroutine
5972 && child_origin_die->tag == DW_TAG_subprogram))
5973 complaint (&symfile_complaints,
5974 _("Child DIE 0x%x and its abstract origin 0x%x have "
5975 "different tags"), child_die->offset,
5976 child_origin_die->offset);
5977 if (child_origin_die->parent != origin_die)
5978 complaint (&symfile_complaints,
5979 _("Child DIE 0x%x and its abstract origin 0x%x have "
5980 "different parents"), child_die->offset,
5981 child_origin_die->offset);
5983 *offsets_end++ = child_origin_die->offset;
5985 child_die = sibling_die (child_die);
5987 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5988 unsigned_int_compar);
5989 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5990 if (offsetp[-1] == *offsetp)
5991 complaint (&symfile_complaints,
5992 _("Multiple children of DIE 0x%x refer "
5993 "to DIE 0x%x as their abstract origin"),
5994 die->offset, *offsetp);
5997 origin_child_die = origin_die->child;
5998 while (origin_child_die && origin_child_die->tag)
6000 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
6001 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
6003 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
6005 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
6006 process_die (origin_child_die, origin_cu);
6008 origin_child_die = sibling_die (origin_child_die);
6010 origin_cu->list_in_scope = origin_previous_list_in_scope;
6012 do_cleanups (cleanups);
6016 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
6018 struct objfile *objfile = cu->objfile;
6019 struct context_stack *new;
6022 struct die_info *child_die;
6023 struct attribute *attr, *call_line, *call_file;
6026 struct block *block;
6027 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
6028 VEC (symbolp) *template_args = NULL;
6029 struct template_symbol *templ_func = NULL;
6033 /* If we do not have call site information, we can't show the
6034 caller of this inlined function. That's too confusing, so
6035 only use the scope for local variables. */
6036 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
6037 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
6038 if (call_line == NULL || call_file == NULL)
6040 read_lexical_block_scope (die, cu);
6045 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6047 name = dwarf2_name (die, cu);
6049 /* Ignore functions with missing or empty names. These are actually
6050 illegal according to the DWARF standard. */
6053 complaint (&symfile_complaints,
6054 _("missing name for subprogram DIE at %d"), die->offset);
6058 /* Ignore functions with missing or invalid low and high pc attributes. */
6059 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6061 attr = dwarf2_attr (die, DW_AT_external, cu);
6062 if (!attr || !DW_UNSND (attr))
6063 complaint (&symfile_complaints,
6064 _("cannot get low and high bounds "
6065 "for subprogram DIE at %d"),
6073 /* Record the function range for dwarf_decode_lines. */
6074 add_to_cu_func_list (name, lowpc, highpc, cu);
6076 /* If we have any template arguments, then we must allocate a
6077 different sort of symbol. */
6078 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
6080 if (child_die->tag == DW_TAG_template_type_param
6081 || child_die->tag == DW_TAG_template_value_param)
6083 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
6084 struct template_symbol);
6085 templ_func->base.is_cplus_template_function = 1;
6090 new = push_context (0, lowpc);
6091 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
6092 (struct symbol *) templ_func);
6094 /* If there is a location expression for DW_AT_frame_base, record
6096 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
6098 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6099 expression is being recorded directly in the function's symbol
6100 and not in a separate frame-base object. I guess this hack is
6101 to avoid adding some sort of frame-base adjunct/annex to the
6102 function's symbol :-(. The problem with doing this is that it
6103 results in a function symbol with a location expression that
6104 has nothing to do with the location of the function, ouch! The
6105 relationship should be: a function's symbol has-a frame base; a
6106 frame-base has-a location expression. */
6107 dwarf2_symbol_mark_computed (attr, new->name, cu);
6109 cu->list_in_scope = &local_symbols;
6111 if (die->child != NULL)
6113 child_die = die->child;
6114 while (child_die && child_die->tag)
6116 if (child_die->tag == DW_TAG_template_type_param
6117 || child_die->tag == DW_TAG_template_value_param)
6119 struct symbol *arg = new_symbol (child_die, NULL, cu);
6122 VEC_safe_push (symbolp, template_args, arg);
6125 process_die (child_die, cu);
6126 child_die = sibling_die (child_die);
6130 inherit_abstract_dies (die, cu);
6132 /* If we have a DW_AT_specification, we might need to import using
6133 directives from the context of the specification DIE. See the
6134 comment in determine_prefix. */
6135 if (cu->language == language_cplus
6136 && dwarf2_attr (die, DW_AT_specification, cu))
6138 struct dwarf2_cu *spec_cu = cu;
6139 struct die_info *spec_die = die_specification (die, &spec_cu);
6143 child_die = spec_die->child;
6144 while (child_die && child_die->tag)
6146 if (child_die->tag == DW_TAG_imported_module)
6147 process_die (child_die, spec_cu);
6148 child_die = sibling_die (child_die);
6151 /* In some cases, GCC generates specification DIEs that
6152 themselves contain DW_AT_specification attributes. */
6153 spec_die = die_specification (spec_die, &spec_cu);
6157 new = pop_context ();
6158 /* Make a block for the local symbols within. */
6159 block = finish_block (new->name, &local_symbols, new->old_blocks,
6160 lowpc, highpc, objfile);
6162 /* For C++, set the block's scope. */
6163 if (cu->language == language_cplus || cu->language == language_fortran)
6164 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6165 determine_prefix (die, cu),
6166 processing_has_namespace_info);
6168 /* If we have address ranges, record them. */
6169 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6171 /* Attach template arguments to function. */
6172 if (! VEC_empty (symbolp, template_args))
6174 gdb_assert (templ_func != NULL);
6176 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6177 templ_func->template_arguments
6178 = obstack_alloc (&objfile->objfile_obstack,
6179 (templ_func->n_template_arguments
6180 * sizeof (struct symbol *)));
6181 memcpy (templ_func->template_arguments,
6182 VEC_address (symbolp, template_args),
6183 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6184 VEC_free (symbolp, template_args);
6187 /* In C++, we can have functions nested inside functions (e.g., when
6188 a function declares a class that has methods). This means that
6189 when we finish processing a function scope, we may need to go
6190 back to building a containing block's symbol lists. */
6191 local_symbols = new->locals;
6192 param_symbols = new->params;
6193 using_directives = new->using_directives;
6195 /* If we've finished processing a top-level function, subsequent
6196 symbols go in the file symbol list. */
6197 if (outermost_context_p ())
6198 cu->list_in_scope = &file_symbols;
6201 /* Process all the DIES contained within a lexical block scope. Start
6202 a new scope, process the dies, and then close the scope. */
6205 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6207 struct objfile *objfile = cu->objfile;
6208 struct context_stack *new;
6209 CORE_ADDR lowpc, highpc;
6210 struct die_info *child_die;
6213 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6215 /* Ignore blocks with missing or invalid low and high pc attributes. */
6216 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6217 as multiple lexical blocks? Handling children in a sane way would
6218 be nasty. Might be easier to properly extend generic blocks to
6220 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6225 push_context (0, lowpc);
6226 if (die->child != NULL)
6228 child_die = die->child;
6229 while (child_die && child_die->tag)
6231 process_die (child_die, cu);
6232 child_die = sibling_die (child_die);
6235 new = pop_context ();
6237 if (local_symbols != NULL || using_directives != NULL)
6240 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6243 /* Note that recording ranges after traversing children, as we
6244 do here, means that recording a parent's ranges entails
6245 walking across all its children's ranges as they appear in
6246 the address map, which is quadratic behavior.
6248 It would be nicer to record the parent's ranges before
6249 traversing its children, simply overriding whatever you find
6250 there. But since we don't even decide whether to create a
6251 block until after we've traversed its children, that's hard
6253 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6255 local_symbols = new->locals;
6256 using_directives = new->using_directives;
6259 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6262 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
6264 struct objfile *objfile = cu->objfile;
6265 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6266 CORE_ADDR pc, baseaddr;
6267 struct attribute *attr;
6268 struct call_site *call_site, call_site_local;
6271 struct die_info *child_die;
6273 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6275 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6278 complaint (&symfile_complaints,
6279 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6280 "DIE 0x%x [in module %s]"),
6281 die->offset, cu->objfile->name);
6284 pc = DW_ADDR (attr) + baseaddr;
6286 if (cu->call_site_htab == NULL)
6287 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
6288 NULL, &objfile->objfile_obstack,
6289 hashtab_obstack_allocate, NULL);
6290 call_site_local.pc = pc;
6291 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
6294 complaint (&symfile_complaints,
6295 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6296 "DIE 0x%x [in module %s]"),
6297 paddress (gdbarch, pc), die->offset, cu->objfile->name);
6301 /* Count parameters at the caller. */
6304 for (child_die = die->child; child_die && child_die->tag;
6305 child_die = sibling_die (child_die))
6307 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6309 complaint (&symfile_complaints,
6310 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6311 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6312 child_die->tag, child_die->offset, cu->objfile->name);
6319 call_site = obstack_alloc (&objfile->objfile_obstack,
6320 (sizeof (*call_site)
6321 + (sizeof (*call_site->parameter)
6324 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
6327 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
6329 struct die_info *func_die;
6331 /* Skip also over DW_TAG_inlined_subroutine. */
6332 for (func_die = die->parent;
6333 func_die && func_die->tag != DW_TAG_subprogram
6334 && func_die->tag != DW_TAG_subroutine_type;
6335 func_die = func_die->parent);
6337 /* DW_AT_GNU_all_call_sites is a superset
6338 of DW_AT_GNU_all_tail_call_sites. */
6340 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
6341 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
6343 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6344 not complete. But keep CALL_SITE for look ups via call_site_htab,
6345 both the initial caller containing the real return address PC and
6346 the final callee containing the current PC of a chain of tail
6347 calls do not need to have the tail call list complete. But any
6348 function candidate for a virtual tail call frame searched via
6349 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6350 determined unambiguously. */
6354 struct type *func_type = NULL;
6357 func_type = get_die_type (func_die, cu);
6358 if (func_type != NULL)
6360 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
6362 /* Enlist this call site to the function. */
6363 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
6364 TYPE_TAIL_CALL_LIST (func_type) = call_site;
6367 complaint (&symfile_complaints,
6368 _("Cannot find function owning DW_TAG_GNU_call_site "
6369 "DIE 0x%x [in module %s]"),
6370 die->offset, cu->objfile->name);
6374 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
6376 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
6377 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
6378 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
6379 /* Keep NULL DWARF_BLOCK. */;
6380 else if (attr_form_is_block (attr))
6382 struct dwarf2_locexpr_baton *dlbaton;
6384 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
6385 dlbaton->data = DW_BLOCK (attr)->data;
6386 dlbaton->size = DW_BLOCK (attr)->size;
6387 dlbaton->per_cu = cu->per_cu;
6389 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
6391 else if (is_ref_attr (attr))
6393 struct objfile *objfile = cu->objfile;
6394 struct dwarf2_cu *target_cu = cu;
6395 struct die_info *target_die;
6397 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
6398 gdb_assert (target_cu->objfile == objfile);
6399 if (die_is_declaration (target_die, target_cu))
6401 const char *target_physname;
6403 target_physname = dwarf2_physname (NULL, target_die, target_cu);
6404 if (target_physname == NULL)
6405 complaint (&symfile_complaints,
6406 _("DW_AT_GNU_call_site_target target DIE has invalid "
6407 "physname, for referencing DIE 0x%x [in module %s]"),
6408 die->offset, cu->objfile->name);
6410 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
6416 /* DW_AT_entry_pc should be preferred. */
6417 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
6418 complaint (&symfile_complaints,
6419 _("DW_AT_GNU_call_site_target target DIE has invalid "
6420 "low pc, for referencing DIE 0x%x [in module %s]"),
6421 die->offset, cu->objfile->name);
6423 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
6427 complaint (&symfile_complaints,
6428 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6429 "block nor reference, for DIE 0x%x [in module %s]"),
6430 die->offset, cu->objfile->name);
6432 call_site->per_cu = cu->per_cu;
6434 for (child_die = die->child;
6435 child_die && child_die->tag;
6436 child_die = sibling_die (child_die))
6438 struct dwarf2_locexpr_baton *dlbaton;
6439 struct call_site_parameter *parameter;
6441 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
6443 /* Already printed the complaint above. */
6447 gdb_assert (call_site->parameter_count < nparams);
6448 parameter = &call_site->parameter[call_site->parameter_count];
6450 /* DW_AT_location specifies the register number. Value of the data
6451 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6453 attr = dwarf2_attr (child_die, DW_AT_location, cu);
6454 if (!attr || !attr_form_is_block (attr))
6456 complaint (&symfile_complaints,
6457 _("No DW_FORM_block* DW_AT_location for "
6458 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6459 child_die->offset, cu->objfile->name);
6462 parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
6463 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]);
6464 if (parameter->dwarf_reg == -1
6465 && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data,
6466 &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size],
6467 ¶meter->fb_offset))
6469 complaint (&symfile_complaints,
6470 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6471 "for DW_FORM_block* DW_AT_location for "
6472 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6473 child_die->offset, cu->objfile->name);
6477 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
6478 if (!attr_form_is_block (attr))
6480 complaint (&symfile_complaints,
6481 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6482 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6483 child_die->offset, cu->objfile->name);
6486 parameter->value = DW_BLOCK (attr)->data;
6487 parameter->value_size = DW_BLOCK (attr)->size;
6489 /* Parameters are not pre-cleared by memset above. */
6490 parameter->data_value = NULL;
6491 parameter->data_value_size = 0;
6492 call_site->parameter_count++;
6494 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
6497 if (!attr_form_is_block (attr))
6498 complaint (&symfile_complaints,
6499 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6500 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6501 child_die->offset, cu->objfile->name);
6504 parameter->data_value = DW_BLOCK (attr)->data;
6505 parameter->data_value_size = DW_BLOCK (attr)->size;
6511 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6512 Return 1 if the attributes are present and valid, otherwise, return 0.
6513 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6516 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6517 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6518 struct partial_symtab *ranges_pst)
6520 struct objfile *objfile = cu->objfile;
6521 struct comp_unit_head *cu_header = &cu->header;
6522 bfd *obfd = objfile->obfd;
6523 unsigned int addr_size = cu_header->addr_size;
6524 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6525 /* Base address selection entry. */
6536 found_base = cu->base_known;
6537 base = cu->base_address;
6539 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6540 if (offset >= dwarf2_per_objfile->ranges.size)
6542 complaint (&symfile_complaints,
6543 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6547 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6549 /* Read in the largest possible address. */
6550 marker = read_address (obfd, buffer, cu, &dummy);
6551 if ((marker & mask) == mask)
6553 /* If we found the largest possible address, then
6554 read the base address. */
6555 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6556 buffer += 2 * addr_size;
6557 offset += 2 * addr_size;
6563 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6567 CORE_ADDR range_beginning, range_end;
6569 range_beginning = read_address (obfd, buffer, cu, &dummy);
6570 buffer += addr_size;
6571 range_end = read_address (obfd, buffer, cu, &dummy);
6572 buffer += addr_size;
6573 offset += 2 * addr_size;
6575 /* An end of list marker is a pair of zero addresses. */
6576 if (range_beginning == 0 && range_end == 0)
6577 /* Found the end of list entry. */
6580 /* Each base address selection entry is a pair of 2 values.
6581 The first is the largest possible address, the second is
6582 the base address. Check for a base address here. */
6583 if ((range_beginning & mask) == mask)
6585 /* If we found the largest possible address, then
6586 read the base address. */
6587 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6594 /* We have no valid base address for the ranges
6596 complaint (&symfile_complaints,
6597 _("Invalid .debug_ranges data (no base address)"));
6601 if (range_beginning > range_end)
6603 /* Inverted range entries are invalid. */
6604 complaint (&symfile_complaints,
6605 _("Invalid .debug_ranges data (inverted range)"));
6609 /* Empty range entries have no effect. */
6610 if (range_beginning == range_end)
6613 range_beginning += base;
6616 if (ranges_pst != NULL)
6617 addrmap_set_empty (objfile->psymtabs_addrmap,
6618 range_beginning + baseaddr,
6619 range_end - 1 + baseaddr,
6622 /* FIXME: This is recording everything as a low-high
6623 segment of consecutive addresses. We should have a
6624 data structure for discontiguous block ranges
6628 low = range_beginning;
6634 if (range_beginning < low)
6635 low = range_beginning;
6636 if (range_end > high)
6642 /* If the first entry is an end-of-list marker, the range
6643 describes an empty scope, i.e. no instructions. */
6649 *high_return = high;
6653 /* Get low and high pc attributes from a die. Return 1 if the attributes
6654 are present and valid, otherwise, return 0. Return -1 if the range is
6655 discontinuous, i.e. derived from DW_AT_ranges information. */
6657 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6658 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6659 struct partial_symtab *pst)
6661 struct attribute *attr;
6666 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6669 high = DW_ADDR (attr);
6670 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6672 low = DW_ADDR (attr);
6674 /* Found high w/o low attribute. */
6677 /* Found consecutive range of addresses. */
6682 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6685 /* Value of the DW_AT_ranges attribute is the offset in the
6686 .debug_ranges section. */
6687 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6689 /* Found discontinuous range of addresses. */
6694 /* read_partial_die has also the strict LOW < HIGH requirement. */
6698 /* When using the GNU linker, .gnu.linkonce. sections are used to
6699 eliminate duplicate copies of functions and vtables and such.
6700 The linker will arbitrarily choose one and discard the others.
6701 The AT_*_pc values for such functions refer to local labels in
6702 these sections. If the section from that file was discarded, the
6703 labels are not in the output, so the relocs get a value of 0.
6704 If this is a discarded function, mark the pc bounds as invalid,
6705 so that GDB will ignore it. */
6706 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6715 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6716 its low and high PC addresses. Do nothing if these addresses could not
6717 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6718 and HIGHPC to the high address if greater than HIGHPC. */
6721 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6722 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6723 struct dwarf2_cu *cu)
6725 CORE_ADDR low, high;
6726 struct die_info *child = die->child;
6728 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6730 *lowpc = min (*lowpc, low);
6731 *highpc = max (*highpc, high);
6734 /* If the language does not allow nested subprograms (either inside
6735 subprograms or lexical blocks), we're done. */
6736 if (cu->language != language_ada)
6739 /* Check all the children of the given DIE. If it contains nested
6740 subprograms, then check their pc bounds. Likewise, we need to
6741 check lexical blocks as well, as they may also contain subprogram
6743 while (child && child->tag)
6745 if (child->tag == DW_TAG_subprogram
6746 || child->tag == DW_TAG_lexical_block)
6747 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6748 child = sibling_die (child);
6752 /* Get the low and high pc's represented by the scope DIE, and store
6753 them in *LOWPC and *HIGHPC. If the correct values can't be
6754 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6757 get_scope_pc_bounds (struct die_info *die,
6758 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6759 struct dwarf2_cu *cu)
6761 CORE_ADDR best_low = (CORE_ADDR) -1;
6762 CORE_ADDR best_high = (CORE_ADDR) 0;
6763 CORE_ADDR current_low, current_high;
6765 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6767 best_low = current_low;
6768 best_high = current_high;
6772 struct die_info *child = die->child;
6774 while (child && child->tag)
6776 switch (child->tag) {
6777 case DW_TAG_subprogram:
6778 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6780 case DW_TAG_namespace:
6782 /* FIXME: carlton/2004-01-16: Should we do this for
6783 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6784 that current GCC's always emit the DIEs corresponding
6785 to definitions of methods of classes as children of a
6786 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6787 the DIEs giving the declarations, which could be
6788 anywhere). But I don't see any reason why the
6789 standards says that they have to be there. */
6790 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6792 if (current_low != ((CORE_ADDR) -1))
6794 best_low = min (best_low, current_low);
6795 best_high = max (best_high, current_high);
6803 child = sibling_die (child);
6808 *highpc = best_high;
6811 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6814 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6815 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6817 struct attribute *attr;
6819 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6822 CORE_ADDR high = DW_ADDR (attr);
6824 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6827 CORE_ADDR low = DW_ADDR (attr);
6829 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6833 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6836 bfd *obfd = cu->objfile->obfd;
6838 /* The value of the DW_AT_ranges attribute is the offset of the
6839 address range list in the .debug_ranges section. */
6840 unsigned long offset = DW_UNSND (attr);
6841 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6843 /* For some target architectures, but not others, the
6844 read_address function sign-extends the addresses it returns.
6845 To recognize base address selection entries, we need a
6847 unsigned int addr_size = cu->header.addr_size;
6848 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6850 /* The base address, to which the next pair is relative. Note
6851 that this 'base' is a DWARF concept: most entries in a range
6852 list are relative, to reduce the number of relocs against the
6853 debugging information. This is separate from this function's
6854 'baseaddr' argument, which GDB uses to relocate debugging
6855 information from a shared library based on the address at
6856 which the library was loaded. */
6857 CORE_ADDR base = cu->base_address;
6858 int base_known = cu->base_known;
6860 gdb_assert (dwarf2_per_objfile->ranges.readin);
6861 if (offset >= dwarf2_per_objfile->ranges.size)
6863 complaint (&symfile_complaints,
6864 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6871 unsigned int bytes_read;
6872 CORE_ADDR start, end;
6874 start = read_address (obfd, buffer, cu, &bytes_read);
6875 buffer += bytes_read;
6876 end = read_address (obfd, buffer, cu, &bytes_read);
6877 buffer += bytes_read;
6879 /* Did we find the end of the range list? */
6880 if (start == 0 && end == 0)
6883 /* Did we find a base address selection entry? */
6884 else if ((start & base_select_mask) == base_select_mask)
6890 /* We found an ordinary address range. */
6895 complaint (&symfile_complaints,
6896 _("Invalid .debug_ranges data "
6897 "(no base address)"));
6903 /* Inverted range entries are invalid. */
6904 complaint (&symfile_complaints,
6905 _("Invalid .debug_ranges data "
6906 "(inverted range)"));
6910 /* Empty range entries have no effect. */
6914 record_block_range (block,
6915 baseaddr + base + start,
6916 baseaddr + base + end - 1);
6922 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6923 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6924 during 4.6.0 experimental. */
6927 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6930 int major, minor, release;
6932 if (cu->producer == NULL)
6934 /* For unknown compilers expect their behavior is DWARF version
6937 GCC started to support .debug_types sections by -gdwarf-4 since
6938 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6939 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6940 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6941 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6946 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6948 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6950 /* For non-GCC compilers expect their behavior is DWARF version
6955 cs = &cu->producer[strlen ("GNU ")];
6956 while (*cs && !isdigit (*cs))
6958 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6960 /* Not recognized as GCC. */
6965 return major < 4 || (major == 4 && minor < 6);
6968 /* Return the default accessibility type if it is not overriden by
6969 DW_AT_accessibility. */
6971 static enum dwarf_access_attribute
6972 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6974 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6976 /* The default DWARF 2 accessibility for members is public, the default
6977 accessibility for inheritance is private. */
6979 if (die->tag != DW_TAG_inheritance)
6980 return DW_ACCESS_public;
6982 return DW_ACCESS_private;
6986 /* DWARF 3+ defines the default accessibility a different way. The same
6987 rules apply now for DW_TAG_inheritance as for the members and it only
6988 depends on the container kind. */
6990 if (die->parent->tag == DW_TAG_class_type)
6991 return DW_ACCESS_private;
6993 return DW_ACCESS_public;
6997 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6998 offset. If the attribute was not found return 0, otherwise return
6999 1. If it was found but could not properly be handled, set *OFFSET
7003 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
7006 struct attribute *attr;
7008 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
7013 /* Note that we do not check for a section offset first here.
7014 This is because DW_AT_data_member_location is new in DWARF 4,
7015 so if we see it, we can assume that a constant form is really
7016 a constant and not a section offset. */
7017 if (attr_form_is_constant (attr))
7018 *offset = dwarf2_get_attr_constant_value (attr, 0);
7019 else if (attr_form_is_section_offset (attr))
7020 dwarf2_complex_location_expr_complaint ();
7021 else if (attr_form_is_block (attr))
7022 *offset = decode_locdesc (DW_BLOCK (attr), cu);
7024 dwarf2_complex_location_expr_complaint ();
7032 /* Add an aggregate field to the field list. */
7035 dwarf2_add_field (struct field_info *fip, struct die_info *die,
7036 struct dwarf2_cu *cu)
7038 struct objfile *objfile = cu->objfile;
7039 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7040 struct nextfield *new_field;
7041 struct attribute *attr;
7043 char *fieldname = "";
7045 /* Allocate a new field list entry and link it in. */
7046 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
7047 make_cleanup (xfree, new_field);
7048 memset (new_field, 0, sizeof (struct nextfield));
7050 if (die->tag == DW_TAG_inheritance)
7052 new_field->next = fip->baseclasses;
7053 fip->baseclasses = new_field;
7057 new_field->next = fip->fields;
7058 fip->fields = new_field;
7062 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7064 new_field->accessibility = DW_UNSND (attr);
7066 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
7067 if (new_field->accessibility != DW_ACCESS_public)
7068 fip->non_public_fields = 1;
7070 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7072 new_field->virtuality = DW_UNSND (attr);
7074 new_field->virtuality = DW_VIRTUALITY_none;
7076 fp = &new_field->field;
7078 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
7082 /* Data member other than a C++ static data member. */
7084 /* Get type of field. */
7085 fp->type = die_type (die, cu);
7087 SET_FIELD_BITPOS (*fp, 0);
7089 /* Get bit size of field (zero if none). */
7090 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
7093 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
7097 FIELD_BITSIZE (*fp) = 0;
7100 /* Get bit offset of field. */
7101 if (handle_data_member_location (die, cu, &offset))
7102 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7103 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
7106 if (gdbarch_bits_big_endian (gdbarch))
7108 /* For big endian bits, the DW_AT_bit_offset gives the
7109 additional bit offset from the MSB of the containing
7110 anonymous object to the MSB of the field. We don't
7111 have to do anything special since we don't need to
7112 know the size of the anonymous object. */
7113 FIELD_BITPOS (*fp) += DW_UNSND (attr);
7117 /* For little endian bits, compute the bit offset to the
7118 MSB of the anonymous object, subtract off the number of
7119 bits from the MSB of the field to the MSB of the
7120 object, and then subtract off the number of bits of
7121 the field itself. The result is the bit offset of
7122 the LSB of the field. */
7124 int bit_offset = DW_UNSND (attr);
7126 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7129 /* The size of the anonymous object containing
7130 the bit field is explicit, so use the
7131 indicated size (in bytes). */
7132 anonymous_size = DW_UNSND (attr);
7136 /* The size of the anonymous object containing
7137 the bit field must be inferred from the type
7138 attribute of the data member containing the
7140 anonymous_size = TYPE_LENGTH (fp->type);
7142 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
7143 - bit_offset - FIELD_BITSIZE (*fp);
7147 /* Get name of field. */
7148 fieldname = dwarf2_name (die, cu);
7149 if (fieldname == NULL)
7152 /* The name is already allocated along with this objfile, so we don't
7153 need to duplicate it for the type. */
7154 fp->name = fieldname;
7156 /* Change accessibility for artificial fields (e.g. virtual table
7157 pointer or virtual base class pointer) to private. */
7158 if (dwarf2_attr (die, DW_AT_artificial, cu))
7160 FIELD_ARTIFICIAL (*fp) = 1;
7161 new_field->accessibility = DW_ACCESS_private;
7162 fip->non_public_fields = 1;
7165 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
7167 /* C++ static member. */
7169 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7170 is a declaration, but all versions of G++ as of this writing
7171 (so through at least 3.2.1) incorrectly generate
7172 DW_TAG_variable tags. */
7174 const char *physname;
7176 /* Get name of field. */
7177 fieldname = dwarf2_name (die, cu);
7178 if (fieldname == NULL)
7181 attr = dwarf2_attr (die, DW_AT_const_value, cu);
7183 /* Only create a symbol if this is an external value.
7184 new_symbol checks this and puts the value in the global symbol
7185 table, which we want. If it is not external, new_symbol
7186 will try to put the value in cu->list_in_scope which is wrong. */
7187 && dwarf2_flag_true_p (die, DW_AT_external, cu))
7189 /* A static const member, not much different than an enum as far as
7190 we're concerned, except that we can support more types. */
7191 new_symbol (die, NULL, cu);
7194 /* Get physical name. */
7195 physname = dwarf2_physname (fieldname, die, cu);
7197 /* The name is already allocated along with this objfile, so we don't
7198 need to duplicate it for the type. */
7199 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
7200 FIELD_TYPE (*fp) = die_type (die, cu);
7201 FIELD_NAME (*fp) = fieldname;
7203 else if (die->tag == DW_TAG_inheritance)
7207 /* C++ base class field. */
7208 if (handle_data_member_location (die, cu, &offset))
7209 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
7210 FIELD_BITSIZE (*fp) = 0;
7211 FIELD_TYPE (*fp) = die_type (die, cu);
7212 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
7213 fip->nbaseclasses++;
7217 /* Add a typedef defined in the scope of the FIP's class. */
7220 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
7221 struct dwarf2_cu *cu)
7223 struct objfile *objfile = cu->objfile;
7224 struct typedef_field_list *new_field;
7225 struct attribute *attr;
7226 struct typedef_field *fp;
7227 char *fieldname = "";
7229 /* Allocate a new field list entry and link it in. */
7230 new_field = xzalloc (sizeof (*new_field));
7231 make_cleanup (xfree, new_field);
7233 gdb_assert (die->tag == DW_TAG_typedef);
7235 fp = &new_field->field;
7237 /* Get name of field. */
7238 fp->name = dwarf2_name (die, cu);
7239 if (fp->name == NULL)
7242 fp->type = read_type_die (die, cu);
7244 new_field->next = fip->typedef_field_list;
7245 fip->typedef_field_list = new_field;
7246 fip->typedef_field_list_count++;
7249 /* Create the vector of fields, and attach it to the type. */
7252 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
7253 struct dwarf2_cu *cu)
7255 int nfields = fip->nfields;
7257 /* Record the field count, allocate space for the array of fields,
7258 and create blank accessibility bitfields if necessary. */
7259 TYPE_NFIELDS (type) = nfields;
7260 TYPE_FIELDS (type) = (struct field *)
7261 TYPE_ALLOC (type, sizeof (struct field) * nfields);
7262 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
7264 if (fip->non_public_fields && cu->language != language_ada)
7266 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7268 TYPE_FIELD_PRIVATE_BITS (type) =
7269 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7270 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
7272 TYPE_FIELD_PROTECTED_BITS (type) =
7273 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7274 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
7276 TYPE_FIELD_IGNORE_BITS (type) =
7277 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
7278 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
7281 /* If the type has baseclasses, allocate and clear a bit vector for
7282 TYPE_FIELD_VIRTUAL_BITS. */
7283 if (fip->nbaseclasses && cu->language != language_ada)
7285 int num_bytes = B_BYTES (fip->nbaseclasses);
7286 unsigned char *pointer;
7288 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7289 pointer = TYPE_ALLOC (type, num_bytes);
7290 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
7291 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
7292 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
7295 /* Copy the saved-up fields into the field vector. Start from the head of
7296 the list, adding to the tail of the field array, so that they end up in
7297 the same order in the array in which they were added to the list. */
7298 while (nfields-- > 0)
7300 struct nextfield *fieldp;
7304 fieldp = fip->fields;
7305 fip->fields = fieldp->next;
7309 fieldp = fip->baseclasses;
7310 fip->baseclasses = fieldp->next;
7313 TYPE_FIELD (type, nfields) = fieldp->field;
7314 switch (fieldp->accessibility)
7316 case DW_ACCESS_private:
7317 if (cu->language != language_ada)
7318 SET_TYPE_FIELD_PRIVATE (type, nfields);
7321 case DW_ACCESS_protected:
7322 if (cu->language != language_ada)
7323 SET_TYPE_FIELD_PROTECTED (type, nfields);
7326 case DW_ACCESS_public:
7330 /* Unknown accessibility. Complain and treat it as public. */
7332 complaint (&symfile_complaints, _("unsupported accessibility %d"),
7333 fieldp->accessibility);
7337 if (nfields < fip->nbaseclasses)
7339 switch (fieldp->virtuality)
7341 case DW_VIRTUALITY_virtual:
7342 case DW_VIRTUALITY_pure_virtual:
7343 if (cu->language == language_ada)
7344 error (_("unexpected virtuality in component of Ada type"));
7345 SET_TYPE_FIELD_VIRTUAL (type, nfields);
7352 /* Add a member function to the proper fieldlist. */
7355 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
7356 struct type *type, struct dwarf2_cu *cu)
7358 struct objfile *objfile = cu->objfile;
7359 struct attribute *attr;
7360 struct fnfieldlist *flp;
7362 struct fn_field *fnp;
7364 struct nextfnfield *new_fnfield;
7365 struct type *this_type;
7366 enum dwarf_access_attribute accessibility;
7368 if (cu->language == language_ada)
7369 error (_("unexpected member function in Ada type"));
7371 /* Get name of member function. */
7372 fieldname = dwarf2_name (die, cu);
7373 if (fieldname == NULL)
7376 /* Look up member function name in fieldlist. */
7377 for (i = 0; i < fip->nfnfields; i++)
7379 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7383 /* Create new list element if necessary. */
7384 if (i < fip->nfnfields)
7385 flp = &fip->fnfieldlists[i];
7388 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7390 fip->fnfieldlists = (struct fnfieldlist *)
7391 xrealloc (fip->fnfieldlists,
7392 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7393 * sizeof (struct fnfieldlist));
7394 if (fip->nfnfields == 0)
7395 make_cleanup (free_current_contents, &fip->fnfieldlists);
7397 flp = &fip->fnfieldlists[fip->nfnfields];
7398 flp->name = fieldname;
7401 i = fip->nfnfields++;
7404 /* Create a new member function field and chain it to the field list
7406 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7407 make_cleanup (xfree, new_fnfield);
7408 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7409 new_fnfield->next = flp->head;
7410 flp->head = new_fnfield;
7413 /* Fill in the member function field info. */
7414 fnp = &new_fnfield->fnfield;
7416 /* Delay processing of the physname until later. */
7417 if (cu->language == language_cplus || cu->language == language_java)
7419 add_to_method_list (type, i, flp->length - 1, fieldname,
7424 const char *physname = dwarf2_physname (fieldname, die, cu);
7425 fnp->physname = physname ? physname : "";
7428 fnp->type = alloc_type (objfile);
7429 this_type = read_type_die (die, cu);
7430 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7432 int nparams = TYPE_NFIELDS (this_type);
7434 /* TYPE is the domain of this method, and THIS_TYPE is the type
7435 of the method itself (TYPE_CODE_METHOD). */
7436 smash_to_method_type (fnp->type, type,
7437 TYPE_TARGET_TYPE (this_type),
7438 TYPE_FIELDS (this_type),
7439 TYPE_NFIELDS (this_type),
7440 TYPE_VARARGS (this_type));
7442 /* Handle static member functions.
7443 Dwarf2 has no clean way to discern C++ static and non-static
7444 member functions. G++ helps GDB by marking the first
7445 parameter for non-static member functions (which is the this
7446 pointer) as artificial. We obtain this information from
7447 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7448 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7449 fnp->voffset = VOFFSET_STATIC;
7452 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7453 dwarf2_full_name (fieldname, die, cu));
7455 /* Get fcontext from DW_AT_containing_type if present. */
7456 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7457 fnp->fcontext = die_containing_type (die, cu);
7459 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7460 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7462 /* Get accessibility. */
7463 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7465 accessibility = DW_UNSND (attr);
7467 accessibility = dwarf2_default_access_attribute (die, cu);
7468 switch (accessibility)
7470 case DW_ACCESS_private:
7471 fnp->is_private = 1;
7473 case DW_ACCESS_protected:
7474 fnp->is_protected = 1;
7478 /* Check for artificial methods. */
7479 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7480 if (attr && DW_UNSND (attr) != 0)
7481 fnp->is_artificial = 1;
7483 /* Get index in virtual function table if it is a virtual member
7484 function. For older versions of GCC, this is an offset in the
7485 appropriate virtual table, as specified by DW_AT_containing_type.
7486 For everyone else, it is an expression to be evaluated relative
7487 to the object address. */
7489 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7492 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7494 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7496 /* Old-style GCC. */
7497 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7499 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7500 || (DW_BLOCK (attr)->size > 1
7501 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7502 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7504 struct dwarf_block blk;
7507 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7509 blk.size = DW_BLOCK (attr)->size - offset;
7510 blk.data = DW_BLOCK (attr)->data + offset;
7511 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7512 if ((fnp->voffset % cu->header.addr_size) != 0)
7513 dwarf2_complex_location_expr_complaint ();
7515 fnp->voffset /= cu->header.addr_size;
7519 dwarf2_complex_location_expr_complaint ();
7522 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7524 else if (attr_form_is_section_offset (attr))
7526 dwarf2_complex_location_expr_complaint ();
7530 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7536 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7537 if (attr && DW_UNSND (attr))
7539 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7540 complaint (&symfile_complaints,
7541 _("Member function \"%s\" (offset %d) is virtual "
7542 "but the vtable offset is not specified"),
7543 fieldname, die->offset);
7544 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7545 TYPE_CPLUS_DYNAMIC (type) = 1;
7550 /* Create the vector of member function fields, and attach it to the type. */
7553 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7554 struct dwarf2_cu *cu)
7556 struct fnfieldlist *flp;
7557 int total_length = 0;
7560 if (cu->language == language_ada)
7561 error (_("unexpected member functions in Ada type"));
7563 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7564 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7565 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7567 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7569 struct nextfnfield *nfp = flp->head;
7570 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7573 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7574 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7575 fn_flp->fn_fields = (struct fn_field *)
7576 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7577 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7578 fn_flp->fn_fields[k] = nfp->fnfield;
7580 total_length += flp->length;
7583 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7584 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
7587 /* Returns non-zero if NAME is the name of a vtable member in CU's
7588 language, zero otherwise. */
7590 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7592 static const char vptr[] = "_vptr";
7593 static const char vtable[] = "vtable";
7595 /* Look for the C++ and Java forms of the vtable. */
7596 if ((cu->language == language_java
7597 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7598 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7599 && is_cplus_marker (name[sizeof (vptr) - 1])))
7605 /* GCC outputs unnamed structures that are really pointers to member
7606 functions, with the ABI-specified layout. If TYPE describes
7607 such a structure, smash it into a member function type.
7609 GCC shouldn't do this; it should just output pointer to member DIEs.
7610 This is GCC PR debug/28767. */
7613 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7615 struct type *pfn_type, *domain_type, *new_type;
7617 /* Check for a structure with no name and two children. */
7618 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7621 /* Check for __pfn and __delta members. */
7622 if (TYPE_FIELD_NAME (type, 0) == NULL
7623 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7624 || TYPE_FIELD_NAME (type, 1) == NULL
7625 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7628 /* Find the type of the method. */
7629 pfn_type = TYPE_FIELD_TYPE (type, 0);
7630 if (pfn_type == NULL
7631 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7632 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7635 /* Look for the "this" argument. */
7636 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7637 if (TYPE_NFIELDS (pfn_type) == 0
7638 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7639 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7642 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7643 new_type = alloc_type (objfile);
7644 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7645 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7646 TYPE_VARARGS (pfn_type));
7647 smash_to_methodptr_type (type, new_type);
7650 /* Called when we find the DIE that starts a structure or union scope
7651 (definition) to create a type for the structure or union. Fill in
7652 the type's name and general properties; the members will not be
7653 processed until process_structure_type.
7655 NOTE: we need to call these functions regardless of whether or not the
7656 DIE has a DW_AT_name attribute, since it might be an anonymous
7657 structure or union. This gets the type entered into our set of
7660 However, if the structure is incomplete (an opaque struct/union)
7661 then suppress creating a symbol table entry for it since gdb only
7662 wants to find the one with the complete definition. Note that if
7663 it is complete, we just call new_symbol, which does it's own
7664 checking about whether the struct/union is anonymous or not (and
7665 suppresses creating a symbol table entry itself). */
7667 static struct type *
7668 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7670 struct objfile *objfile = cu->objfile;
7672 struct attribute *attr;
7675 /* If the definition of this type lives in .debug_types, read that type.
7676 Don't follow DW_AT_specification though, that will take us back up
7677 the chain and we want to go down. */
7678 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7681 struct dwarf2_cu *type_cu = cu;
7682 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7684 /* We could just recurse on read_structure_type, but we need to call
7685 get_die_type to ensure only one type for this DIE is created.
7686 This is important, for example, because for c++ classes we need
7687 TYPE_NAME set which is only done by new_symbol. Blech. */
7688 type = read_type_die (type_die, type_cu);
7690 /* TYPE_CU may not be the same as CU.
7691 Ensure TYPE is recorded in CU's type_hash table. */
7692 return set_die_type (die, type, cu);
7695 type = alloc_type (objfile);
7696 INIT_CPLUS_SPECIFIC (type);
7698 name = dwarf2_name (die, cu);
7701 if (cu->language == language_cplus
7702 || cu->language == language_java)
7704 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7706 /* dwarf2_full_name might have already finished building the DIE's
7707 type. If so, there is no need to continue. */
7708 if (get_die_type (die, cu) != NULL)
7709 return get_die_type (die, cu);
7711 TYPE_TAG_NAME (type) = full_name;
7712 if (die->tag == DW_TAG_structure_type
7713 || die->tag == DW_TAG_class_type)
7714 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7718 /* The name is already allocated along with this objfile, so
7719 we don't need to duplicate it for the type. */
7720 TYPE_TAG_NAME (type) = (char *) name;
7721 if (die->tag == DW_TAG_class_type)
7722 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7726 if (die->tag == DW_TAG_structure_type)
7728 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7730 else if (die->tag == DW_TAG_union_type)
7732 TYPE_CODE (type) = TYPE_CODE_UNION;
7736 TYPE_CODE (type) = TYPE_CODE_CLASS;
7739 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7740 TYPE_DECLARED_CLASS (type) = 1;
7742 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7745 TYPE_LENGTH (type) = DW_UNSND (attr);
7749 TYPE_LENGTH (type) = 0;
7752 TYPE_STUB_SUPPORTED (type) = 1;
7753 if (die_is_declaration (die, cu))
7754 TYPE_STUB (type) = 1;
7755 else if (attr == NULL && die->child == NULL
7756 && producer_is_realview (cu->producer))
7757 /* RealView does not output the required DW_AT_declaration
7758 on incomplete types. */
7759 TYPE_STUB (type) = 1;
7761 /* We need to add the type field to the die immediately so we don't
7762 infinitely recurse when dealing with pointers to the structure
7763 type within the structure itself. */
7764 set_die_type (die, type, cu);
7766 /* set_die_type should be already done. */
7767 set_descriptive_type (type, die, cu);
7772 /* Finish creating a structure or union type, including filling in
7773 its members and creating a symbol for it. */
7776 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7778 struct objfile *objfile = cu->objfile;
7779 struct die_info *child_die = die->child;
7782 type = get_die_type (die, cu);
7784 type = read_structure_type (die, cu);
7786 if (die->child != NULL && ! die_is_declaration (die, cu))
7788 struct field_info fi;
7789 struct die_info *child_die;
7790 VEC (symbolp) *template_args = NULL;
7791 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7793 memset (&fi, 0, sizeof (struct field_info));
7795 child_die = die->child;
7797 while (child_die && child_die->tag)
7799 if (child_die->tag == DW_TAG_member
7800 || child_die->tag == DW_TAG_variable)
7802 /* NOTE: carlton/2002-11-05: A C++ static data member
7803 should be a DW_TAG_member that is a declaration, but
7804 all versions of G++ as of this writing (so through at
7805 least 3.2.1) incorrectly generate DW_TAG_variable
7806 tags for them instead. */
7807 dwarf2_add_field (&fi, child_die, cu);
7809 else if (child_die->tag == DW_TAG_subprogram)
7811 /* C++ member function. */
7812 dwarf2_add_member_fn (&fi, child_die, type, cu);
7814 else if (child_die->tag == DW_TAG_inheritance)
7816 /* C++ base class field. */
7817 dwarf2_add_field (&fi, child_die, cu);
7819 else if (child_die->tag == DW_TAG_typedef)
7820 dwarf2_add_typedef (&fi, child_die, cu);
7821 else if (child_die->tag == DW_TAG_template_type_param
7822 || child_die->tag == DW_TAG_template_value_param)
7824 struct symbol *arg = new_symbol (child_die, NULL, cu);
7827 VEC_safe_push (symbolp, template_args, arg);
7830 child_die = sibling_die (child_die);
7833 /* Attach template arguments to type. */
7834 if (! VEC_empty (symbolp, template_args))
7836 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7837 TYPE_N_TEMPLATE_ARGUMENTS (type)
7838 = VEC_length (symbolp, template_args);
7839 TYPE_TEMPLATE_ARGUMENTS (type)
7840 = obstack_alloc (&objfile->objfile_obstack,
7841 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7842 * sizeof (struct symbol *)));
7843 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7844 VEC_address (symbolp, template_args),
7845 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7846 * sizeof (struct symbol *)));
7847 VEC_free (symbolp, template_args);
7850 /* Attach fields and member functions to the type. */
7852 dwarf2_attach_fields_to_type (&fi, type, cu);
7855 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7857 /* Get the type which refers to the base class (possibly this
7858 class itself) which contains the vtable pointer for the current
7859 class from the DW_AT_containing_type attribute. This use of
7860 DW_AT_containing_type is a GNU extension. */
7862 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7864 struct type *t = die_containing_type (die, cu);
7866 TYPE_VPTR_BASETYPE (type) = t;
7871 /* Our own class provides vtbl ptr. */
7872 for (i = TYPE_NFIELDS (t) - 1;
7873 i >= TYPE_N_BASECLASSES (t);
7876 char *fieldname = TYPE_FIELD_NAME (t, i);
7878 if (is_vtable_name (fieldname, cu))
7880 TYPE_VPTR_FIELDNO (type) = i;
7885 /* Complain if virtual function table field not found. */
7886 if (i < TYPE_N_BASECLASSES (t))
7887 complaint (&symfile_complaints,
7888 _("virtual function table pointer "
7889 "not found when defining class '%s'"),
7890 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7895 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7898 else if (cu->producer
7899 && strncmp (cu->producer,
7900 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7902 /* The IBM XLC compiler does not provide direct indication
7903 of the containing type, but the vtable pointer is
7904 always named __vfp. */
7908 for (i = TYPE_NFIELDS (type) - 1;
7909 i >= TYPE_N_BASECLASSES (type);
7912 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7914 TYPE_VPTR_FIELDNO (type) = i;
7915 TYPE_VPTR_BASETYPE (type) = type;
7922 /* Copy fi.typedef_field_list linked list elements content into the
7923 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7924 if (fi.typedef_field_list)
7926 int i = fi.typedef_field_list_count;
7928 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7929 TYPE_TYPEDEF_FIELD_ARRAY (type)
7930 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7931 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7933 /* Reverse the list order to keep the debug info elements order. */
7936 struct typedef_field *dest, *src;
7938 dest = &TYPE_TYPEDEF_FIELD (type, i);
7939 src = &fi.typedef_field_list->field;
7940 fi.typedef_field_list = fi.typedef_field_list->next;
7945 do_cleanups (back_to);
7947 if (HAVE_CPLUS_STRUCT (type))
7948 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
7951 quirk_gcc_member_function_pointer (type, cu->objfile);
7953 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7954 snapshots) has been known to create a die giving a declaration
7955 for a class that has, as a child, a die giving a definition for a
7956 nested class. So we have to process our children even if the
7957 current die is a declaration. Normally, of course, a declaration
7958 won't have any children at all. */
7960 while (child_die != NULL && child_die->tag)
7962 if (child_die->tag == DW_TAG_member
7963 || child_die->tag == DW_TAG_variable
7964 || child_die->tag == DW_TAG_inheritance
7965 || child_die->tag == DW_TAG_template_value_param
7966 || child_die->tag == DW_TAG_template_type_param)
7971 process_die (child_die, cu);
7973 child_die = sibling_die (child_die);
7976 /* Do not consider external references. According to the DWARF standard,
7977 these DIEs are identified by the fact that they have no byte_size
7978 attribute, and a declaration attribute. */
7979 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7980 || !die_is_declaration (die, cu))
7981 new_symbol (die, type, cu);
7984 /* Given a DW_AT_enumeration_type die, set its type. We do not
7985 complete the type's fields yet, or create any symbols. */
7987 static struct type *
7988 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7990 struct objfile *objfile = cu->objfile;
7992 struct attribute *attr;
7995 /* If the definition of this type lives in .debug_types, read that type.
7996 Don't follow DW_AT_specification though, that will take us back up
7997 the chain and we want to go down. */
7998 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
8001 struct dwarf2_cu *type_cu = cu;
8002 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
8004 type = read_type_die (type_die, type_cu);
8006 /* TYPE_CU may not be the same as CU.
8007 Ensure TYPE is recorded in CU's type_hash table. */
8008 return set_die_type (die, type, cu);
8011 type = alloc_type (objfile);
8013 TYPE_CODE (type) = TYPE_CODE_ENUM;
8014 name = dwarf2_full_name (NULL, die, cu);
8016 TYPE_TAG_NAME (type) = (char *) name;
8018 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8021 TYPE_LENGTH (type) = DW_UNSND (attr);
8025 TYPE_LENGTH (type) = 0;
8028 /* The enumeration DIE can be incomplete. In Ada, any type can be
8029 declared as private in the package spec, and then defined only
8030 inside the package body. Such types are known as Taft Amendment
8031 Types. When another package uses such a type, an incomplete DIE
8032 may be generated by the compiler. */
8033 if (die_is_declaration (die, cu))
8034 TYPE_STUB (type) = 1;
8036 return set_die_type (die, type, cu);
8039 /* Given a pointer to a die which begins an enumeration, process all
8040 the dies that define the members of the enumeration, and create the
8041 symbol for the enumeration type.
8043 NOTE: We reverse the order of the element list. */
8046 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
8048 struct type *this_type;
8050 this_type = get_die_type (die, cu);
8051 if (this_type == NULL)
8052 this_type = read_enumeration_type (die, cu);
8054 if (die->child != NULL)
8056 struct die_info *child_die;
8058 struct field *fields = NULL;
8060 int unsigned_enum = 1;
8063 child_die = die->child;
8064 while (child_die && child_die->tag)
8066 if (child_die->tag != DW_TAG_enumerator)
8068 process_die (child_die, cu);
8072 name = dwarf2_name (child_die, cu);
8075 sym = new_symbol (child_die, this_type, cu);
8076 if (SYMBOL_VALUE (sym) < 0)
8079 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
8081 fields = (struct field *)
8083 (num_fields + DW_FIELD_ALLOC_CHUNK)
8084 * sizeof (struct field));
8087 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
8088 FIELD_TYPE (fields[num_fields]) = NULL;
8089 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
8090 FIELD_BITSIZE (fields[num_fields]) = 0;
8096 child_die = sibling_die (child_die);
8101 TYPE_NFIELDS (this_type) = num_fields;
8102 TYPE_FIELDS (this_type) = (struct field *)
8103 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
8104 memcpy (TYPE_FIELDS (this_type), fields,
8105 sizeof (struct field) * num_fields);
8109 TYPE_UNSIGNED (this_type) = 1;
8112 /* If we are reading an enum from a .debug_types unit, and the enum
8113 is a declaration, and the enum is not the signatured type in the
8114 unit, then we do not want to add a symbol for it. Adding a
8115 symbol would in some cases obscure the true definition of the
8116 enum, giving users an incomplete type when the definition is
8117 actually available. Note that we do not want to do this for all
8118 enums which are just declarations, because C++0x allows forward
8119 enum declarations. */
8120 if (cu->per_cu->debug_types_section
8121 && die_is_declaration (die, cu))
8123 struct signatured_type *type_sig;
8126 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
8127 cu->per_cu->debug_types_section,
8128 cu->per_cu->offset);
8129 if (type_sig->type_offset != die->offset)
8133 new_symbol (die, this_type, cu);
8136 /* Extract all information from a DW_TAG_array_type DIE and put it in
8137 the DIE's type field. For now, this only handles one dimensional
8140 static struct type *
8141 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
8143 struct objfile *objfile = cu->objfile;
8144 struct die_info *child_die;
8146 struct type *element_type, *range_type, *index_type;
8147 struct type **range_types = NULL;
8148 struct attribute *attr;
8150 struct cleanup *back_to;
8153 element_type = die_type (die, cu);
8155 /* The die_type call above may have already set the type for this DIE. */
8156 type = get_die_type (die, cu);
8160 /* Irix 6.2 native cc creates array types without children for
8161 arrays with unspecified length. */
8162 if (die->child == NULL)
8164 index_type = objfile_type (objfile)->builtin_int;
8165 range_type = create_range_type (NULL, index_type, 0, -1);
8166 type = create_array_type (NULL, element_type, range_type);
8167 return set_die_type (die, type, cu);
8170 back_to = make_cleanup (null_cleanup, NULL);
8171 child_die = die->child;
8172 while (child_die && child_die->tag)
8174 if (child_die->tag == DW_TAG_subrange_type)
8176 struct type *child_type = read_type_die (child_die, cu);
8178 if (child_type != NULL)
8180 /* The range type was succesfully read. Save it for the
8181 array type creation. */
8182 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
8184 range_types = (struct type **)
8185 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
8186 * sizeof (struct type *));
8188 make_cleanup (free_current_contents, &range_types);
8190 range_types[ndim++] = child_type;
8193 child_die = sibling_die (child_die);
8196 /* Dwarf2 dimensions are output from left to right, create the
8197 necessary array types in backwards order. */
8199 type = element_type;
8201 if (read_array_order (die, cu) == DW_ORD_col_major)
8206 type = create_array_type (NULL, type, range_types[i++]);
8211 type = create_array_type (NULL, type, range_types[ndim]);
8214 /* Understand Dwarf2 support for vector types (like they occur on
8215 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8216 array type. This is not part of the Dwarf2/3 standard yet, but a
8217 custom vendor extension. The main difference between a regular
8218 array and the vector variant is that vectors are passed by value
8220 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
8222 make_vector_type (type);
8224 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8225 implementation may choose to implement triple vectors using this
8227 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8230 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
8231 TYPE_LENGTH (type) = DW_UNSND (attr);
8233 complaint (&symfile_complaints,
8234 _("DW_AT_byte_size for array type smaller "
8235 "than the total size of elements"));
8238 name = dwarf2_name (die, cu);
8240 TYPE_NAME (type) = name;
8242 /* Install the type in the die. */
8243 set_die_type (die, type, cu);
8245 /* set_die_type should be already done. */
8246 set_descriptive_type (type, die, cu);
8248 do_cleanups (back_to);
8253 static enum dwarf_array_dim_ordering
8254 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
8256 struct attribute *attr;
8258 attr = dwarf2_attr (die, DW_AT_ordering, cu);
8260 if (attr) return DW_SND (attr);
8262 /* GNU F77 is a special case, as at 08/2004 array type info is the
8263 opposite order to the dwarf2 specification, but data is still
8264 laid out as per normal fortran.
8266 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8267 version checking. */
8269 if (cu->language == language_fortran
8270 && cu->producer && strstr (cu->producer, "GNU F77"))
8272 return DW_ORD_row_major;
8275 switch (cu->language_defn->la_array_ordering)
8277 case array_column_major:
8278 return DW_ORD_col_major;
8279 case array_row_major:
8281 return DW_ORD_row_major;
8285 /* Extract all information from a DW_TAG_set_type DIE and put it in
8286 the DIE's type field. */
8288 static struct type *
8289 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
8291 struct type *domain_type, *set_type;
8292 struct attribute *attr;
8294 domain_type = die_type (die, cu);
8296 /* The die_type call above may have already set the type for this DIE. */
8297 set_type = get_die_type (die, cu);
8301 set_type = create_set_type (NULL, domain_type);
8303 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8305 TYPE_LENGTH (set_type) = DW_UNSND (attr);
8307 return set_die_type (die, set_type, cu);
8310 /* First cut: install each common block member as a global variable. */
8313 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
8315 struct die_info *child_die;
8316 struct attribute *attr;
8318 CORE_ADDR base = (CORE_ADDR) 0;
8320 attr = dwarf2_attr (die, DW_AT_location, cu);
8323 /* Support the .debug_loc offsets. */
8324 if (attr_form_is_block (attr))
8326 base = decode_locdesc (DW_BLOCK (attr), cu);
8328 else if (attr_form_is_section_offset (attr))
8330 dwarf2_complex_location_expr_complaint ();
8334 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8335 "common block member");
8338 if (die->child != NULL)
8340 child_die = die->child;
8341 while (child_die && child_die->tag)
8345 sym = new_symbol (child_die, NULL, cu);
8347 && handle_data_member_location (child_die, cu, &offset))
8349 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
8350 add_symbol_to_list (sym, &global_symbols);
8352 child_die = sibling_die (child_die);
8357 /* Create a type for a C++ namespace. */
8359 static struct type *
8360 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
8362 struct objfile *objfile = cu->objfile;
8363 const char *previous_prefix, *name;
8367 /* For extensions, reuse the type of the original namespace. */
8368 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
8370 struct die_info *ext_die;
8371 struct dwarf2_cu *ext_cu = cu;
8373 ext_die = dwarf2_extension (die, &ext_cu);
8374 type = read_type_die (ext_die, ext_cu);
8376 /* EXT_CU may not be the same as CU.
8377 Ensure TYPE is recorded in CU's type_hash table. */
8378 return set_die_type (die, type, cu);
8381 name = namespace_name (die, &is_anonymous, cu);
8383 /* Now build the name of the current namespace. */
8385 previous_prefix = determine_prefix (die, cu);
8386 if (previous_prefix[0] != '\0')
8387 name = typename_concat (&objfile->objfile_obstack,
8388 previous_prefix, name, 0, cu);
8390 /* Create the type. */
8391 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8393 TYPE_NAME (type) = (char *) name;
8394 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8396 return set_die_type (die, type, cu);
8399 /* Read a C++ namespace. */
8402 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8404 struct objfile *objfile = cu->objfile;
8407 /* Add a symbol associated to this if we haven't seen the namespace
8408 before. Also, add a using directive if it's an anonymous
8411 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8415 type = read_type_die (die, cu);
8416 new_symbol (die, type, cu);
8418 namespace_name (die, &is_anonymous, cu);
8421 const char *previous_prefix = determine_prefix (die, cu);
8423 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8424 NULL, NULL, &objfile->objfile_obstack);
8428 if (die->child != NULL)
8430 struct die_info *child_die = die->child;
8432 while (child_die && child_die->tag)
8434 process_die (child_die, cu);
8435 child_die = sibling_die (child_die);
8440 /* Read a Fortran module as type. This DIE can be only a declaration used for
8441 imported module. Still we need that type as local Fortran "use ... only"
8442 declaration imports depend on the created type in determine_prefix. */
8444 static struct type *
8445 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8447 struct objfile *objfile = cu->objfile;
8451 module_name = dwarf2_name (die, cu);
8453 complaint (&symfile_complaints,
8454 _("DW_TAG_module has no name, offset 0x%x"),
8456 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8458 /* determine_prefix uses TYPE_TAG_NAME. */
8459 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8461 return set_die_type (die, type, cu);
8464 /* Read a Fortran module. */
8467 read_module (struct die_info *die, struct dwarf2_cu *cu)
8469 struct die_info *child_die = die->child;
8471 while (child_die && child_die->tag)
8473 process_die (child_die, cu);
8474 child_die = sibling_die (child_die);
8478 /* Return the name of the namespace represented by DIE. Set
8479 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8483 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8485 struct die_info *current_die;
8486 const char *name = NULL;
8488 /* Loop through the extensions until we find a name. */
8490 for (current_die = die;
8491 current_die != NULL;
8492 current_die = dwarf2_extension (die, &cu))
8494 name = dwarf2_name (current_die, cu);
8499 /* Is it an anonymous namespace? */
8501 *is_anonymous = (name == NULL);
8503 name = CP_ANONYMOUS_NAMESPACE_STR;
8508 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8509 the user defined type vector. */
8511 static struct type *
8512 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8514 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8515 struct comp_unit_head *cu_header = &cu->header;
8517 struct attribute *attr_byte_size;
8518 struct attribute *attr_address_class;
8519 int byte_size, addr_class;
8520 struct type *target_type;
8522 target_type = die_type (die, cu);
8524 /* The die_type call above may have already set the type for this DIE. */
8525 type = get_die_type (die, cu);
8529 type = lookup_pointer_type (target_type);
8531 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8533 byte_size = DW_UNSND (attr_byte_size);
8535 byte_size = cu_header->addr_size;
8537 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8538 if (attr_address_class)
8539 addr_class = DW_UNSND (attr_address_class);
8541 addr_class = DW_ADDR_none;
8543 /* If the pointer size or address class is different than the
8544 default, create a type variant marked as such and set the
8545 length accordingly. */
8546 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8548 if (gdbarch_address_class_type_flags_p (gdbarch))
8552 type_flags = gdbarch_address_class_type_flags
8553 (gdbarch, byte_size, addr_class);
8554 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8556 type = make_type_with_address_space (type, type_flags);
8558 else if (TYPE_LENGTH (type) != byte_size)
8560 complaint (&symfile_complaints,
8561 _("invalid pointer size %d"), byte_size);
8565 /* Should we also complain about unhandled address classes? */
8569 TYPE_LENGTH (type) = byte_size;
8570 return set_die_type (die, type, cu);
8573 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8574 the user defined type vector. */
8576 static struct type *
8577 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8580 struct type *to_type;
8581 struct type *domain;
8583 to_type = die_type (die, cu);
8584 domain = die_containing_type (die, cu);
8586 /* The calls above may have already set the type for this DIE. */
8587 type = get_die_type (die, cu);
8591 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8592 type = lookup_methodptr_type (to_type);
8594 type = lookup_memberptr_type (to_type, domain);
8596 return set_die_type (die, type, cu);
8599 /* Extract all information from a DW_TAG_reference_type DIE and add to
8600 the user defined type vector. */
8602 static struct type *
8603 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8605 struct comp_unit_head *cu_header = &cu->header;
8606 struct type *type, *target_type;
8607 struct attribute *attr;
8609 target_type = die_type (die, cu);
8611 /* The die_type call above may have already set the type for this DIE. */
8612 type = get_die_type (die, cu);
8616 type = lookup_reference_type (target_type);
8617 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8620 TYPE_LENGTH (type) = DW_UNSND (attr);
8624 TYPE_LENGTH (type) = cu_header->addr_size;
8626 return set_die_type (die, type, cu);
8629 static struct type *
8630 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8632 struct type *base_type, *cv_type;
8634 base_type = die_type (die, cu);
8636 /* The die_type call above may have already set the type for this DIE. */
8637 cv_type = get_die_type (die, cu);
8641 /* In case the const qualifier is applied to an array type, the element type
8642 is so qualified, not the array type (section 6.7.3 of C99). */
8643 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8645 struct type *el_type, *inner_array;
8647 base_type = copy_type (base_type);
8648 inner_array = base_type;
8650 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8652 TYPE_TARGET_TYPE (inner_array) =
8653 copy_type (TYPE_TARGET_TYPE (inner_array));
8654 inner_array = TYPE_TARGET_TYPE (inner_array);
8657 el_type = TYPE_TARGET_TYPE (inner_array);
8658 TYPE_TARGET_TYPE (inner_array) =
8659 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8661 return set_die_type (die, base_type, cu);
8664 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8665 return set_die_type (die, cv_type, cu);
8668 static struct type *
8669 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8671 struct type *base_type, *cv_type;
8673 base_type = die_type (die, cu);
8675 /* The die_type call above may have already set the type for this DIE. */
8676 cv_type = get_die_type (die, cu);
8680 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8681 return set_die_type (die, cv_type, cu);
8684 /* Extract all information from a DW_TAG_string_type DIE and add to
8685 the user defined type vector. It isn't really a user defined type,
8686 but it behaves like one, with other DIE's using an AT_user_def_type
8687 attribute to reference it. */
8689 static struct type *
8690 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8692 struct objfile *objfile = cu->objfile;
8693 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8694 struct type *type, *range_type, *index_type, *char_type;
8695 struct attribute *attr;
8696 unsigned int length;
8698 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8701 length = DW_UNSND (attr);
8705 /* Check for the DW_AT_byte_size attribute. */
8706 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8709 length = DW_UNSND (attr);
8717 index_type = objfile_type (objfile)->builtin_int;
8718 range_type = create_range_type (NULL, index_type, 1, length);
8719 char_type = language_string_char_type (cu->language_defn, gdbarch);
8720 type = create_string_type (NULL, char_type, range_type);
8722 return set_die_type (die, type, cu);
8725 /* Handle DIES due to C code like:
8729 int (*funcp)(int a, long l);
8733 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8735 static struct type *
8736 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8738 struct type *type; /* Type that this function returns. */
8739 struct type *ftype; /* Function that returns above type. */
8740 struct attribute *attr;
8742 type = die_type (die, cu);
8744 /* The die_type call above may have already set the type for this DIE. */
8745 ftype = get_die_type (die, cu);
8749 ftype = lookup_function_type (type);
8751 /* All functions in C++, Pascal and Java have prototypes. */
8752 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8753 if ((attr && (DW_UNSND (attr) != 0))
8754 || cu->language == language_cplus
8755 || cu->language == language_java
8756 || cu->language == language_pascal)
8757 TYPE_PROTOTYPED (ftype) = 1;
8758 else if (producer_is_realview (cu->producer))
8759 /* RealView does not emit DW_AT_prototyped. We can not
8760 distinguish prototyped and unprototyped functions; default to
8761 prototyped, since that is more common in modern code (and
8762 RealView warns about unprototyped functions). */
8763 TYPE_PROTOTYPED (ftype) = 1;
8765 /* Store the calling convention in the type if it's available in
8766 the subroutine die. Otherwise set the calling convention to
8767 the default value DW_CC_normal. */
8768 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8770 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8771 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8772 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8774 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8776 /* We need to add the subroutine type to the die immediately so
8777 we don't infinitely recurse when dealing with parameters
8778 declared as the same subroutine type. */
8779 set_die_type (die, ftype, cu);
8781 if (die->child != NULL)
8783 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8784 struct die_info *child_die;
8785 int nparams, iparams;
8787 /* Count the number of parameters.
8788 FIXME: GDB currently ignores vararg functions, but knows about
8789 vararg member functions. */
8791 child_die = die->child;
8792 while (child_die && child_die->tag)
8794 if (child_die->tag == DW_TAG_formal_parameter)
8796 else if (child_die->tag == DW_TAG_unspecified_parameters)
8797 TYPE_VARARGS (ftype) = 1;
8798 child_die = sibling_die (child_die);
8801 /* Allocate storage for parameters and fill them in. */
8802 TYPE_NFIELDS (ftype) = nparams;
8803 TYPE_FIELDS (ftype) = (struct field *)
8804 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8806 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8807 even if we error out during the parameters reading below. */
8808 for (iparams = 0; iparams < nparams; iparams++)
8809 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8812 child_die = die->child;
8813 while (child_die && child_die->tag)
8815 if (child_die->tag == DW_TAG_formal_parameter)
8817 struct type *arg_type;
8819 /* DWARF version 2 has no clean way to discern C++
8820 static and non-static member functions. G++ helps
8821 GDB by marking the first parameter for non-static
8822 member functions (which is the this pointer) as
8823 artificial. We pass this information to
8824 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8826 DWARF version 3 added DW_AT_object_pointer, which GCC
8827 4.5 does not yet generate. */
8828 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8830 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8833 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8835 /* GCC/43521: In java, the formal parameter
8836 "this" is sometimes not marked with DW_AT_artificial. */
8837 if (cu->language == language_java)
8839 const char *name = dwarf2_name (child_die, cu);
8841 if (name && !strcmp (name, "this"))
8842 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8845 arg_type = die_type (child_die, cu);
8847 /* RealView does not mark THIS as const, which the testsuite
8848 expects. GCC marks THIS as const in method definitions,
8849 but not in the class specifications (GCC PR 43053). */
8850 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8851 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8854 struct dwarf2_cu *arg_cu = cu;
8855 const char *name = dwarf2_name (child_die, cu);
8857 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8860 /* If the compiler emits this, use it. */
8861 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8864 else if (name && strcmp (name, "this") == 0)
8865 /* Function definitions will have the argument names. */
8867 else if (name == NULL && iparams == 0)
8868 /* Declarations may not have the names, so like
8869 elsewhere in GDB, assume an artificial first
8870 argument is "this". */
8874 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8878 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8881 child_die = sibling_die (child_die);
8888 static struct type *
8889 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8891 struct objfile *objfile = cu->objfile;
8892 const char *name = NULL;
8893 struct type *this_type;
8895 name = dwarf2_full_name (NULL, die, cu);
8896 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8897 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8898 TYPE_NAME (this_type) = (char *) name;
8899 set_die_type (die, this_type, cu);
8900 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8904 /* Find a representation of a given base type and install
8905 it in the TYPE field of the die. */
8907 static struct type *
8908 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8910 struct objfile *objfile = cu->objfile;
8912 struct attribute *attr;
8913 int encoding = 0, size = 0;
8915 enum type_code code = TYPE_CODE_INT;
8917 struct type *target_type = NULL;
8919 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8922 encoding = DW_UNSND (attr);
8924 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8927 size = DW_UNSND (attr);
8929 name = dwarf2_name (die, cu);
8932 complaint (&symfile_complaints,
8933 _("DW_AT_name missing from DW_TAG_base_type"));
8938 case DW_ATE_address:
8939 /* Turn DW_ATE_address into a void * pointer. */
8940 code = TYPE_CODE_PTR;
8941 type_flags |= TYPE_FLAG_UNSIGNED;
8942 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8944 case DW_ATE_boolean:
8945 code = TYPE_CODE_BOOL;
8946 type_flags |= TYPE_FLAG_UNSIGNED;
8948 case DW_ATE_complex_float:
8949 code = TYPE_CODE_COMPLEX;
8950 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8952 case DW_ATE_decimal_float:
8953 code = TYPE_CODE_DECFLOAT;
8956 code = TYPE_CODE_FLT;
8960 case DW_ATE_unsigned:
8961 type_flags |= TYPE_FLAG_UNSIGNED;
8962 if (cu->language == language_fortran
8964 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
8965 code = TYPE_CODE_CHAR;
8967 case DW_ATE_signed_char:
8968 if (cu->language == language_ada || cu->language == language_m2
8969 || cu->language == language_pascal
8970 || cu->language == language_fortran)
8971 code = TYPE_CODE_CHAR;
8973 case DW_ATE_unsigned_char:
8974 if (cu->language == language_ada || cu->language == language_m2
8975 || cu->language == language_pascal
8976 || cu->language == language_fortran)
8977 code = TYPE_CODE_CHAR;
8978 type_flags |= TYPE_FLAG_UNSIGNED;
8981 /* We just treat this as an integer and then recognize the
8982 type by name elsewhere. */
8986 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8987 dwarf_type_encoding_name (encoding));
8991 type = init_type (code, size, type_flags, NULL, objfile);
8992 TYPE_NAME (type) = name;
8993 TYPE_TARGET_TYPE (type) = target_type;
8995 if (name && strcmp (name, "char") == 0)
8996 TYPE_NOSIGN (type) = 1;
8998 return set_die_type (die, type, cu);
9001 /* Read the given DW_AT_subrange DIE. */
9003 static struct type *
9004 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
9006 struct type *base_type;
9007 struct type *range_type;
9008 struct attribute *attr;
9012 LONGEST negative_mask;
9014 base_type = die_type (die, cu);
9015 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9016 check_typedef (base_type);
9018 /* The die_type call above may have already set the type for this DIE. */
9019 range_type = get_die_type (die, cu);
9023 if (cu->language == language_fortran)
9025 /* FORTRAN implies a lower bound of 1, if not given. */
9029 /* FIXME: For variable sized arrays either of these could be
9030 a variable rather than a constant value. We'll allow it,
9031 but we don't know how to handle it. */
9032 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
9034 low = dwarf2_get_attr_constant_value (attr, 0);
9036 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
9039 if (attr_form_is_block (attr) || is_ref_attr (attr))
9041 /* GCC encodes arrays with unspecified or dynamic length
9042 with a DW_FORM_block1 attribute or a reference attribute.
9043 FIXME: GDB does not yet know how to handle dynamic
9044 arrays properly, treat them as arrays with unspecified
9047 FIXME: jimb/2003-09-22: GDB does not really know
9048 how to handle arrays of unspecified length
9049 either; we just represent them as zero-length
9050 arrays. Choose an appropriate upper bound given
9051 the lower bound we've computed above. */
9055 high = dwarf2_get_attr_constant_value (attr, 1);
9059 attr = dwarf2_attr (die, DW_AT_count, cu);
9062 int count = dwarf2_get_attr_constant_value (attr, 1);
9063 high = low + count - 1;
9067 /* Unspecified array length. */
9072 /* Dwarf-2 specifications explicitly allows to create subrange types
9073 without specifying a base type.
9074 In that case, the base type must be set to the type of
9075 the lower bound, upper bound or count, in that order, if any of these
9076 three attributes references an object that has a type.
9077 If no base type is found, the Dwarf-2 specifications say that
9078 a signed integer type of size equal to the size of an address should
9080 For the following C code: `extern char gdb_int [];'
9081 GCC produces an empty range DIE.
9082 FIXME: muller/2010-05-28: Possible references to object for low bound,
9083 high bound or count are not yet handled by this code. */
9084 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
9086 struct objfile *objfile = cu->objfile;
9087 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9088 int addr_size = gdbarch_addr_bit (gdbarch) /8;
9089 struct type *int_type = objfile_type (objfile)->builtin_int;
9091 /* Test "int", "long int", and "long long int" objfile types,
9092 and select the first one having a size above or equal to the
9093 architecture address size. */
9094 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9095 base_type = int_type;
9098 int_type = objfile_type (objfile)->builtin_long;
9099 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9100 base_type = int_type;
9103 int_type = objfile_type (objfile)->builtin_long_long;
9104 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
9105 base_type = int_type;
9111 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
9112 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
9113 low |= negative_mask;
9114 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
9115 high |= negative_mask;
9117 range_type = create_range_type (NULL, base_type, low, high);
9119 /* Mark arrays with dynamic length at least as an array of unspecified
9120 length. GDB could check the boundary but before it gets implemented at
9121 least allow accessing the array elements. */
9122 if (attr && attr_form_is_block (attr))
9123 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9125 /* Ada expects an empty array on no boundary attributes. */
9126 if (attr == NULL && cu->language != language_ada)
9127 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
9129 name = dwarf2_name (die, cu);
9131 TYPE_NAME (range_type) = name;
9133 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
9135 TYPE_LENGTH (range_type) = DW_UNSND (attr);
9137 set_die_type (die, range_type, cu);
9139 /* set_die_type should be already done. */
9140 set_descriptive_type (range_type, die, cu);
9145 static struct type *
9146 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
9150 /* For now, we only support the C meaning of an unspecified type: void. */
9152 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
9153 TYPE_NAME (type) = dwarf2_name (die, cu);
9155 return set_die_type (die, type, cu);
9158 /* Trivial hash function for die_info: the hash value of a DIE
9159 is its offset in .debug_info for this objfile. */
9162 die_hash (const void *item)
9164 const struct die_info *die = item;
9169 /* Trivial comparison function for die_info structures: two DIEs
9170 are equal if they have the same offset. */
9173 die_eq (const void *item_lhs, const void *item_rhs)
9175 const struct die_info *die_lhs = item_lhs;
9176 const struct die_info *die_rhs = item_rhs;
9178 return die_lhs->offset == die_rhs->offset;
9181 /* Read a whole compilation unit into a linked list of dies. */
9183 static struct die_info *
9184 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
9186 struct die_reader_specs reader_specs;
9187 int read_abbrevs = 0;
9188 struct cleanup *back_to = NULL;
9189 struct die_info *die;
9191 if (cu->dwarf2_abbrevs == NULL)
9193 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
9194 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
9198 gdb_assert (cu->die_hash == NULL);
9200 = htab_create_alloc_ex (cu->header.length / 12,
9204 &cu->comp_unit_obstack,
9205 hashtab_obstack_allocate,
9206 dummy_obstack_deallocate);
9208 init_cu_die_reader (&reader_specs, cu);
9210 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
9213 do_cleanups (back_to);
9218 /* Main entry point for reading a DIE and all children.
9219 Read the DIE and dump it if requested. */
9221 static struct die_info *
9222 read_die_and_children (const struct die_reader_specs *reader,
9224 gdb_byte **new_info_ptr,
9225 struct die_info *parent)
9227 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
9228 new_info_ptr, parent);
9230 if (dwarf2_die_debug)
9232 fprintf_unfiltered (gdb_stdlog,
9233 "\nRead die from %s of %s:\n",
9234 (reader->cu->per_cu->debug_types_section
9237 reader->abfd->filename);
9238 dump_die (result, dwarf2_die_debug);
9244 /* Read a single die and all its descendents. Set the die's sibling
9245 field to NULL; set other fields in the die correctly, and set all
9246 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9247 location of the info_ptr after reading all of those dies. PARENT
9248 is the parent of the die in question. */
9250 static struct die_info *
9251 read_die_and_children_1 (const struct die_reader_specs *reader,
9253 gdb_byte **new_info_ptr,
9254 struct die_info *parent)
9256 struct die_info *die;
9260 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
9263 *new_info_ptr = cur_ptr;
9266 store_in_ref_table (die, reader->cu);
9269 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
9273 *new_info_ptr = cur_ptr;
9276 die->sibling = NULL;
9277 die->parent = parent;
9281 /* Read a die, all of its descendents, and all of its siblings; set
9282 all of the fields of all of the dies correctly. Arguments are as
9283 in read_die_and_children. */
9285 static struct die_info *
9286 read_die_and_siblings (const struct die_reader_specs *reader,
9288 gdb_byte **new_info_ptr,
9289 struct die_info *parent)
9291 struct die_info *first_die, *last_sibling;
9295 first_die = last_sibling = NULL;
9299 struct die_info *die
9300 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
9304 *new_info_ptr = cur_ptr;
9311 last_sibling->sibling = die;
9317 /* Read the die from the .debug_info section buffer. Set DIEP to
9318 point to a newly allocated die with its information, except for its
9319 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9320 whether the die has children or not. */
9323 read_full_die (const struct die_reader_specs *reader,
9324 struct die_info **diep, gdb_byte *info_ptr,
9327 unsigned int abbrev_number, bytes_read, i, offset;
9328 struct abbrev_info *abbrev;
9329 struct die_info *die;
9330 struct dwarf2_cu *cu = reader->cu;
9331 bfd *abfd = reader->abfd;
9333 offset = info_ptr - reader->buffer;
9334 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9335 info_ptr += bytes_read;
9343 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
9345 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9347 bfd_get_filename (abfd));
9349 die = dwarf_alloc_die (cu, abbrev->num_attrs);
9350 die->offset = offset;
9351 die->tag = abbrev->tag;
9352 die->abbrev = abbrev_number;
9354 die->num_attrs = abbrev->num_attrs;
9356 for (i = 0; i < abbrev->num_attrs; ++i)
9357 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
9358 abfd, info_ptr, cu);
9361 *has_children = abbrev->has_children;
9365 /* In DWARF version 2, the description of the debugging information is
9366 stored in a separate .debug_abbrev section. Before we read any
9367 dies from a section we read in all abbreviations and install them
9368 in a hash table. This function also sets flags in CU describing
9369 the data found in the abbrev table. */
9372 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
9374 struct comp_unit_head *cu_header = &cu->header;
9375 gdb_byte *abbrev_ptr;
9376 struct abbrev_info *cur_abbrev;
9377 unsigned int abbrev_number, bytes_read, abbrev_name;
9378 unsigned int abbrev_form, hash_number;
9379 struct attr_abbrev *cur_attrs;
9380 unsigned int allocated_attrs;
9382 /* Initialize dwarf2 abbrevs. */
9383 obstack_init (&cu->abbrev_obstack);
9384 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9386 * sizeof (struct abbrev_info *)));
9387 memset (cu->dwarf2_abbrevs, 0,
9388 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9390 dwarf2_read_section (dwarf2_per_objfile->objfile,
9391 &dwarf2_per_objfile->abbrev);
9392 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
9393 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9394 abbrev_ptr += bytes_read;
9396 allocated_attrs = ATTR_ALLOC_CHUNK;
9397 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9399 /* Loop until we reach an abbrev number of 0. */
9400 while (abbrev_number)
9402 cur_abbrev = dwarf_alloc_abbrev (cu);
9404 /* read in abbrev header */
9405 cur_abbrev->number = abbrev_number;
9406 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9407 abbrev_ptr += bytes_read;
9408 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9411 if (cur_abbrev->tag == DW_TAG_namespace)
9412 cu->has_namespace_info = 1;
9414 /* now read in declarations */
9415 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9416 abbrev_ptr += bytes_read;
9417 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9418 abbrev_ptr += bytes_read;
9421 if (cur_abbrev->num_attrs == allocated_attrs)
9423 allocated_attrs += ATTR_ALLOC_CHUNK;
9425 = xrealloc (cur_attrs, (allocated_attrs
9426 * sizeof (struct attr_abbrev)));
9429 /* Record whether this compilation unit might have
9430 inter-compilation-unit references. If we don't know what form
9431 this attribute will have, then it might potentially be a
9432 DW_FORM_ref_addr, so we conservatively expect inter-CU
9435 if (abbrev_form == DW_FORM_ref_addr
9436 || abbrev_form == DW_FORM_indirect)
9437 cu->has_form_ref_addr = 1;
9439 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9440 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9441 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9442 abbrev_ptr += bytes_read;
9443 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9444 abbrev_ptr += bytes_read;
9447 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9448 (cur_abbrev->num_attrs
9449 * sizeof (struct attr_abbrev)));
9450 memcpy (cur_abbrev->attrs, cur_attrs,
9451 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9453 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9454 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9455 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9457 /* Get next abbreviation.
9458 Under Irix6 the abbreviations for a compilation unit are not
9459 always properly terminated with an abbrev number of 0.
9460 Exit loop if we encounter an abbreviation which we have
9461 already read (which means we are about to read the abbreviations
9462 for the next compile unit) or if the end of the abbreviation
9463 table is reached. */
9464 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9465 >= dwarf2_per_objfile->abbrev.size)
9467 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9468 abbrev_ptr += bytes_read;
9469 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9476 /* Release the memory used by the abbrev table for a compilation unit. */
9479 dwarf2_free_abbrev_table (void *ptr_to_cu)
9481 struct dwarf2_cu *cu = ptr_to_cu;
9483 obstack_free (&cu->abbrev_obstack, NULL);
9484 cu->dwarf2_abbrevs = NULL;
9487 /* Lookup an abbrev_info structure in the abbrev hash table. */
9489 static struct abbrev_info *
9490 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9492 unsigned int hash_number;
9493 struct abbrev_info *abbrev;
9495 hash_number = number % ABBREV_HASH_SIZE;
9496 abbrev = cu->dwarf2_abbrevs[hash_number];
9500 if (abbrev->number == number)
9503 abbrev = abbrev->next;
9508 /* Returns nonzero if TAG represents a type that we might generate a partial
9512 is_type_tag_for_partial (int tag)
9517 /* Some types that would be reasonable to generate partial symbols for,
9518 that we don't at present. */
9519 case DW_TAG_array_type:
9520 case DW_TAG_file_type:
9521 case DW_TAG_ptr_to_member_type:
9522 case DW_TAG_set_type:
9523 case DW_TAG_string_type:
9524 case DW_TAG_subroutine_type:
9526 case DW_TAG_base_type:
9527 case DW_TAG_class_type:
9528 case DW_TAG_interface_type:
9529 case DW_TAG_enumeration_type:
9530 case DW_TAG_structure_type:
9531 case DW_TAG_subrange_type:
9532 case DW_TAG_typedef:
9533 case DW_TAG_union_type:
9540 /* Load all DIEs that are interesting for partial symbols into memory. */
9542 static struct partial_die_info *
9543 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9544 int building_psymtab, struct dwarf2_cu *cu)
9546 struct partial_die_info *part_die;
9547 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9548 struct abbrev_info *abbrev;
9549 unsigned int bytes_read;
9550 unsigned int load_all = 0;
9552 int nesting_level = 1;
9557 if (cu->per_cu && cu->per_cu->load_all_dies)
9561 = htab_create_alloc_ex (cu->header.length / 12,
9565 &cu->comp_unit_obstack,
9566 hashtab_obstack_allocate,
9567 dummy_obstack_deallocate);
9569 part_die = obstack_alloc (&cu->comp_unit_obstack,
9570 sizeof (struct partial_die_info));
9574 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9576 /* A NULL abbrev means the end of a series of children. */
9579 if (--nesting_level == 0)
9581 /* PART_DIE was probably the last thing allocated on the
9582 comp_unit_obstack, so we could call obstack_free
9583 here. We don't do that because the waste is small,
9584 and will be cleaned up when we're done with this
9585 compilation unit. This way, we're also more robust
9586 against other users of the comp_unit_obstack. */
9589 info_ptr += bytes_read;
9590 last_die = parent_die;
9591 parent_die = parent_die->die_parent;
9595 /* Check for template arguments. We never save these; if
9596 they're seen, we just mark the parent, and go on our way. */
9597 if (parent_die != NULL
9598 && cu->language == language_cplus
9599 && (abbrev->tag == DW_TAG_template_type_param
9600 || abbrev->tag == DW_TAG_template_value_param))
9602 parent_die->has_template_arguments = 1;
9606 /* We don't need a partial DIE for the template argument. */
9607 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9613 /* We only recurse into subprograms looking for template arguments.
9614 Skip their other children. */
9616 && cu->language == language_cplus
9617 && parent_die != NULL
9618 && parent_die->tag == DW_TAG_subprogram)
9620 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9624 /* Check whether this DIE is interesting enough to save. Normally
9625 we would not be interested in members here, but there may be
9626 later variables referencing them via DW_AT_specification (for
9629 && !is_type_tag_for_partial (abbrev->tag)
9630 && abbrev->tag != DW_TAG_constant
9631 && abbrev->tag != DW_TAG_enumerator
9632 && abbrev->tag != DW_TAG_subprogram
9633 && abbrev->tag != DW_TAG_lexical_block
9634 && abbrev->tag != DW_TAG_variable
9635 && abbrev->tag != DW_TAG_namespace
9636 && abbrev->tag != DW_TAG_module
9637 && abbrev->tag != DW_TAG_member)
9639 /* Otherwise we skip to the next sibling, if any. */
9640 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9644 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9645 buffer, info_ptr, cu);
9647 /* This two-pass algorithm for processing partial symbols has a
9648 high cost in cache pressure. Thus, handle some simple cases
9649 here which cover the majority of C partial symbols. DIEs
9650 which neither have specification tags in them, nor could have
9651 specification tags elsewhere pointing at them, can simply be
9652 processed and discarded.
9654 This segment is also optional; scan_partial_symbols and
9655 add_partial_symbol will handle these DIEs if we chain
9656 them in normally. When compilers which do not emit large
9657 quantities of duplicate debug information are more common,
9658 this code can probably be removed. */
9660 /* Any complete simple types at the top level (pretty much all
9661 of them, for a language without namespaces), can be processed
9663 if (parent_die == NULL
9664 && part_die->has_specification == 0
9665 && part_die->is_declaration == 0
9666 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9667 || part_die->tag == DW_TAG_base_type
9668 || part_die->tag == DW_TAG_subrange_type))
9670 if (building_psymtab && part_die->name != NULL)
9671 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9672 VAR_DOMAIN, LOC_TYPEDEF,
9673 &cu->objfile->static_psymbols,
9674 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9675 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9679 /* The exception for DW_TAG_typedef with has_children above is
9680 a workaround of GCC PR debug/47510. In the case of this complaint
9681 type_name_no_tag_or_error will error on such types later.
9683 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9684 it could not find the child DIEs referenced later, this is checked
9685 above. In correct DWARF DW_TAG_typedef should have no children. */
9687 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9688 complaint (&symfile_complaints,
9689 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9690 "- DIE at 0x%x [in module %s]"),
9691 part_die->offset, cu->objfile->name);
9693 /* If we're at the second level, and we're an enumerator, and
9694 our parent has no specification (meaning possibly lives in a
9695 namespace elsewhere), then we can add the partial symbol now
9696 instead of queueing it. */
9697 if (part_die->tag == DW_TAG_enumerator
9698 && parent_die != NULL
9699 && parent_die->die_parent == NULL
9700 && parent_die->tag == DW_TAG_enumeration_type
9701 && parent_die->has_specification == 0)
9703 if (part_die->name == NULL)
9704 complaint (&symfile_complaints,
9705 _("malformed enumerator DIE ignored"));
9706 else if (building_psymtab)
9707 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9708 VAR_DOMAIN, LOC_CONST,
9709 (cu->language == language_cplus
9710 || cu->language == language_java)
9711 ? &cu->objfile->global_psymbols
9712 : &cu->objfile->static_psymbols,
9713 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9715 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9719 /* We'll save this DIE so link it in. */
9720 part_die->die_parent = parent_die;
9721 part_die->die_sibling = NULL;
9722 part_die->die_child = NULL;
9724 if (last_die && last_die == parent_die)
9725 last_die->die_child = part_die;
9727 last_die->die_sibling = part_die;
9729 last_die = part_die;
9731 if (first_die == NULL)
9732 first_die = part_die;
9734 /* Maybe add the DIE to the hash table. Not all DIEs that we
9735 find interesting need to be in the hash table, because we
9736 also have the parent/sibling/child chains; only those that we
9737 might refer to by offset later during partial symbol reading.
9739 For now this means things that might have be the target of a
9740 DW_AT_specification, DW_AT_abstract_origin, or
9741 DW_AT_extension. DW_AT_extension will refer only to
9742 namespaces; DW_AT_abstract_origin refers to functions (and
9743 many things under the function DIE, but we do not recurse
9744 into function DIEs during partial symbol reading) and
9745 possibly variables as well; DW_AT_specification refers to
9746 declarations. Declarations ought to have the DW_AT_declaration
9747 flag. It happens that GCC forgets to put it in sometimes, but
9748 only for functions, not for types.
9750 Adding more things than necessary to the hash table is harmless
9751 except for the performance cost. Adding too few will result in
9752 wasted time in find_partial_die, when we reread the compilation
9753 unit with load_all_dies set. */
9756 || abbrev->tag == DW_TAG_constant
9757 || abbrev->tag == DW_TAG_subprogram
9758 || abbrev->tag == DW_TAG_variable
9759 || abbrev->tag == DW_TAG_namespace
9760 || part_die->is_declaration)
9764 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9765 part_die->offset, INSERT);
9769 part_die = obstack_alloc (&cu->comp_unit_obstack,
9770 sizeof (struct partial_die_info));
9772 /* For some DIEs we want to follow their children (if any). For C
9773 we have no reason to follow the children of structures; for other
9774 languages we have to, so that we can get at method physnames
9775 to infer fully qualified class names, for DW_AT_specification,
9776 and for C++ template arguments. For C++, we also look one level
9777 inside functions to find template arguments (if the name of the
9778 function does not already contain the template arguments).
9780 For Ada, we need to scan the children of subprograms and lexical
9781 blocks as well because Ada allows the definition of nested
9782 entities that could be interesting for the debugger, such as
9783 nested subprograms for instance. */
9784 if (last_die->has_children
9786 || last_die->tag == DW_TAG_namespace
9787 || last_die->tag == DW_TAG_module
9788 || last_die->tag == DW_TAG_enumeration_type
9789 || (cu->language == language_cplus
9790 && last_die->tag == DW_TAG_subprogram
9791 && (last_die->name == NULL
9792 || strchr (last_die->name, '<') == NULL))
9793 || (cu->language != language_c
9794 && (last_die->tag == DW_TAG_class_type
9795 || last_die->tag == DW_TAG_interface_type
9796 || last_die->tag == DW_TAG_structure_type
9797 || last_die->tag == DW_TAG_union_type))
9798 || (cu->language == language_ada
9799 && (last_die->tag == DW_TAG_subprogram
9800 || last_die->tag == DW_TAG_lexical_block))))
9803 parent_die = last_die;
9807 /* Otherwise we skip to the next sibling, if any. */
9808 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9810 /* Back to the top, do it again. */
9814 /* Read a minimal amount of information into the minimal die structure. */
9817 read_partial_die (struct partial_die_info *part_die,
9818 struct abbrev_info *abbrev,
9819 unsigned int abbrev_len, bfd *abfd,
9820 gdb_byte *buffer, gdb_byte *info_ptr,
9821 struct dwarf2_cu *cu)
9824 struct attribute attr;
9825 int has_low_pc_attr = 0;
9826 int has_high_pc_attr = 0;
9828 memset (part_die, 0, sizeof (struct partial_die_info));
9830 part_die->offset = info_ptr - buffer;
9832 info_ptr += abbrev_len;
9837 part_die->tag = abbrev->tag;
9838 part_die->has_children = abbrev->has_children;
9840 for (i = 0; i < abbrev->num_attrs; ++i)
9842 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9844 /* Store the data if it is of an attribute we want to keep in a
9845 partial symbol table. */
9849 switch (part_die->tag)
9851 case DW_TAG_compile_unit:
9852 case DW_TAG_type_unit:
9853 /* Compilation units have a DW_AT_name that is a filename, not
9854 a source language identifier. */
9855 case DW_TAG_enumeration_type:
9856 case DW_TAG_enumerator:
9857 /* These tags always have simple identifiers already; no need
9858 to canonicalize them. */
9859 part_die->name = DW_STRING (&attr);
9863 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9864 &cu->objfile->objfile_obstack);
9868 case DW_AT_linkage_name:
9869 case DW_AT_MIPS_linkage_name:
9870 /* Note that both forms of linkage name might appear. We
9871 assume they will be the same, and we only store the last
9873 if (cu->language == language_ada)
9874 part_die->name = DW_STRING (&attr);
9875 part_die->linkage_name = DW_STRING (&attr);
9878 has_low_pc_attr = 1;
9879 part_die->lowpc = DW_ADDR (&attr);
9882 has_high_pc_attr = 1;
9883 part_die->highpc = DW_ADDR (&attr);
9885 case DW_AT_location:
9886 /* Support the .debug_loc offsets. */
9887 if (attr_form_is_block (&attr))
9889 part_die->locdesc = DW_BLOCK (&attr);
9891 else if (attr_form_is_section_offset (&attr))
9893 dwarf2_complex_location_expr_complaint ();
9897 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9898 "partial symbol information");
9901 case DW_AT_external:
9902 part_die->is_external = DW_UNSND (&attr);
9904 case DW_AT_declaration:
9905 part_die->is_declaration = DW_UNSND (&attr);
9908 part_die->has_type = 1;
9910 case DW_AT_abstract_origin:
9911 case DW_AT_specification:
9912 case DW_AT_extension:
9913 part_die->has_specification = 1;
9914 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9917 /* Ignore absolute siblings, they might point outside of
9918 the current compile unit. */
9919 if (attr.form == DW_FORM_ref_addr)
9920 complaint (&symfile_complaints,
9921 _("ignoring absolute DW_AT_sibling"));
9923 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9925 case DW_AT_byte_size:
9926 part_die->has_byte_size = 1;
9928 case DW_AT_calling_convention:
9929 /* DWARF doesn't provide a way to identify a program's source-level
9930 entry point. DW_AT_calling_convention attributes are only meant
9931 to describe functions' calling conventions.
9933 However, because it's a necessary piece of information in
9934 Fortran, and because DW_CC_program is the only piece of debugging
9935 information whose definition refers to a 'main program' at all,
9936 several compilers have begun marking Fortran main programs with
9937 DW_CC_program --- even when those functions use the standard
9938 calling conventions.
9940 So until DWARF specifies a way to provide this information and
9941 compilers pick up the new representation, we'll support this
9943 if (DW_UNSND (&attr) == DW_CC_program
9944 && cu->language == language_fortran)
9946 set_main_name (part_die->name);
9948 /* As this DIE has a static linkage the name would be difficult
9949 to look up later. */
9950 language_of_main = language_fortran;
9958 if (has_low_pc_attr && has_high_pc_attr)
9960 /* When using the GNU linker, .gnu.linkonce. sections are used to
9961 eliminate duplicate copies of functions and vtables and such.
9962 The linker will arbitrarily choose one and discard the others.
9963 The AT_*_pc values for such functions refer to local labels in
9964 these sections. If the section from that file was discarded, the
9965 labels are not in the output, so the relocs get a value of 0.
9966 If this is a discarded function, mark the pc bounds as invalid,
9967 so that GDB will ignore it. */
9968 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9970 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9972 complaint (&symfile_complaints,
9973 _("DW_AT_low_pc %s is zero "
9974 "for DIE at 0x%x [in module %s]"),
9975 paddress (gdbarch, part_die->lowpc),
9976 part_die->offset, cu->objfile->name);
9978 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9979 else if (part_die->lowpc >= part_die->highpc)
9981 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9983 complaint (&symfile_complaints,
9984 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9985 "for DIE at 0x%x [in module %s]"),
9986 paddress (gdbarch, part_die->lowpc),
9987 paddress (gdbarch, part_die->highpc),
9988 part_die->offset, cu->objfile->name);
9991 part_die->has_pc_info = 1;
9997 /* Find a cached partial DIE at OFFSET in CU. */
9999 static struct partial_die_info *
10000 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
10002 struct partial_die_info *lookup_die = NULL;
10003 struct partial_die_info part_die;
10005 part_die.offset = offset;
10006 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
10011 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10012 except in the case of .debug_types DIEs which do not reference
10013 outside their CU (they do however referencing other types via
10014 DW_FORM_ref_sig8). */
10016 static struct partial_die_info *
10017 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
10019 struct dwarf2_per_cu_data *per_cu = NULL;
10020 struct partial_die_info *pd = NULL;
10022 if (cu->per_cu->debug_types_section)
10024 pd = find_partial_die_in_comp_unit (offset, cu);
10030 if (offset_in_cu_p (&cu->header, offset))
10032 pd = find_partial_die_in_comp_unit (offset, cu);
10037 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
10039 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
10040 load_partial_comp_unit (per_cu, cu->objfile);
10042 per_cu->cu->last_used = 0;
10043 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10045 if (pd == NULL && per_cu->load_all_dies == 0)
10047 struct cleanup *back_to;
10048 struct partial_die_info comp_unit_die;
10049 struct abbrev_info *abbrev;
10050 unsigned int bytes_read;
10053 per_cu->load_all_dies = 1;
10055 /* Re-read the DIEs. */
10056 back_to = make_cleanup (null_cleanup, 0);
10057 if (per_cu->cu->dwarf2_abbrevs == NULL)
10059 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
10060 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
10062 info_ptr = (dwarf2_per_objfile->info.buffer
10063 + per_cu->cu->header.offset
10064 + per_cu->cu->header.first_die_offset);
10065 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
10066 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
10067 per_cu->cu->objfile->obfd,
10068 dwarf2_per_objfile->info.buffer, info_ptr,
10070 if (comp_unit_die.has_children)
10071 load_partial_dies (per_cu->cu->objfile->obfd,
10072 dwarf2_per_objfile->info.buffer, info_ptr,
10074 do_cleanups (back_to);
10076 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
10082 internal_error (__FILE__, __LINE__,
10083 _("could not find partial DIE 0x%x "
10084 "in cache [from module %s]\n"),
10085 offset, bfd_get_filename (cu->objfile->obfd));
10089 /* See if we can figure out if the class lives in a namespace. We do
10090 this by looking for a member function; its demangled name will
10091 contain namespace info, if there is any. */
10094 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
10095 struct dwarf2_cu *cu)
10097 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10098 what template types look like, because the demangler
10099 frequently doesn't give the same name as the debug info. We
10100 could fix this by only using the demangled name to get the
10101 prefix (but see comment in read_structure_type). */
10103 struct partial_die_info *real_pdi;
10104 struct partial_die_info *child_pdi;
10106 /* If this DIE (this DIE's specification, if any) has a parent, then
10107 we should not do this. We'll prepend the parent's fully qualified
10108 name when we create the partial symbol. */
10110 real_pdi = struct_pdi;
10111 while (real_pdi->has_specification)
10112 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
10114 if (real_pdi->die_parent != NULL)
10117 for (child_pdi = struct_pdi->die_child;
10119 child_pdi = child_pdi->die_sibling)
10121 if (child_pdi->tag == DW_TAG_subprogram
10122 && child_pdi->linkage_name != NULL)
10124 char *actual_class_name
10125 = language_class_name_from_physname (cu->language_defn,
10126 child_pdi->linkage_name);
10127 if (actual_class_name != NULL)
10130 = obsavestring (actual_class_name,
10131 strlen (actual_class_name),
10132 &cu->objfile->objfile_obstack);
10133 xfree (actual_class_name);
10140 /* Adjust PART_DIE before generating a symbol for it. This function
10141 may set the is_external flag or change the DIE's name. */
10144 fixup_partial_die (struct partial_die_info *part_die,
10145 struct dwarf2_cu *cu)
10147 /* Once we've fixed up a die, there's no point in doing so again.
10148 This also avoids a memory leak if we were to call
10149 guess_partial_die_structure_name multiple times. */
10150 if (part_die->fixup_called)
10153 /* If we found a reference attribute and the DIE has no name, try
10154 to find a name in the referred to DIE. */
10156 if (part_die->name == NULL && part_die->has_specification)
10158 struct partial_die_info *spec_die;
10160 spec_die = find_partial_die (part_die->spec_offset, cu);
10162 fixup_partial_die (spec_die, cu);
10164 if (spec_die->name)
10166 part_die->name = spec_die->name;
10168 /* Copy DW_AT_external attribute if it is set. */
10169 if (spec_die->is_external)
10170 part_die->is_external = spec_die->is_external;
10174 /* Set default names for some unnamed DIEs. */
10176 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
10177 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
10179 /* If there is no parent die to provide a namespace, and there are
10180 children, see if we can determine the namespace from their linkage
10182 NOTE: We need to do this even if cu->has_namespace_info != 0.
10183 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10184 if (cu->language == language_cplus
10185 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
10186 && part_die->die_parent == NULL
10187 && part_die->has_children
10188 && (part_die->tag == DW_TAG_class_type
10189 || part_die->tag == DW_TAG_structure_type
10190 || part_die->tag == DW_TAG_union_type))
10191 guess_partial_die_structure_name (part_die, cu);
10193 /* GCC might emit a nameless struct or union that has a linkage
10194 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10195 if (part_die->name == NULL
10196 && (part_die->tag == DW_TAG_class_type
10197 || part_die->tag == DW_TAG_interface_type
10198 || part_die->tag == DW_TAG_structure_type
10199 || part_die->tag == DW_TAG_union_type)
10200 && part_die->linkage_name != NULL)
10204 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
10209 /* Strip any leading namespaces/classes, keep only the base name.
10210 DW_AT_name for named DIEs does not contain the prefixes. */
10211 base = strrchr (demangled, ':');
10212 if (base && base > demangled && base[-1] == ':')
10217 part_die->name = obsavestring (base, strlen (base),
10218 &cu->objfile->objfile_obstack);
10223 part_die->fixup_called = 1;
10226 /* Read an attribute value described by an attribute form. */
10229 read_attribute_value (struct attribute *attr, unsigned form,
10230 bfd *abfd, gdb_byte *info_ptr,
10231 struct dwarf2_cu *cu)
10233 struct comp_unit_head *cu_header = &cu->header;
10234 unsigned int bytes_read;
10235 struct dwarf_block *blk;
10240 case DW_FORM_ref_addr:
10241 if (cu->header.version == 2)
10242 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10244 DW_ADDR (attr) = read_offset (abfd, info_ptr,
10245 &cu->header, &bytes_read);
10246 info_ptr += bytes_read;
10249 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
10250 info_ptr += bytes_read;
10252 case DW_FORM_block2:
10253 blk = dwarf_alloc_block (cu);
10254 blk->size = read_2_bytes (abfd, info_ptr);
10256 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10257 info_ptr += blk->size;
10258 DW_BLOCK (attr) = blk;
10260 case DW_FORM_block4:
10261 blk = dwarf_alloc_block (cu);
10262 blk->size = read_4_bytes (abfd, info_ptr);
10264 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10265 info_ptr += blk->size;
10266 DW_BLOCK (attr) = blk;
10268 case DW_FORM_data2:
10269 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
10272 case DW_FORM_data4:
10273 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
10276 case DW_FORM_data8:
10277 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
10280 case DW_FORM_sec_offset:
10281 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
10282 info_ptr += bytes_read;
10284 case DW_FORM_string:
10285 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
10286 DW_STRING_IS_CANONICAL (attr) = 0;
10287 info_ptr += bytes_read;
10290 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
10292 DW_STRING_IS_CANONICAL (attr) = 0;
10293 info_ptr += bytes_read;
10295 case DW_FORM_exprloc:
10296 case DW_FORM_block:
10297 blk = dwarf_alloc_block (cu);
10298 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10299 info_ptr += bytes_read;
10300 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10301 info_ptr += blk->size;
10302 DW_BLOCK (attr) = blk;
10304 case DW_FORM_block1:
10305 blk = dwarf_alloc_block (cu);
10306 blk->size = read_1_byte (abfd, info_ptr);
10308 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
10309 info_ptr += blk->size;
10310 DW_BLOCK (attr) = blk;
10312 case DW_FORM_data1:
10313 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10317 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
10320 case DW_FORM_flag_present:
10321 DW_UNSND (attr) = 1;
10323 case DW_FORM_sdata:
10324 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
10325 info_ptr += bytes_read;
10327 case DW_FORM_udata:
10328 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10329 info_ptr += bytes_read;
10332 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
10336 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
10340 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
10344 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
10347 case DW_FORM_ref_sig8:
10348 /* Convert the signature to something we can record in DW_UNSND
10350 NOTE: This is NULL if the type wasn't found. */
10351 DW_SIGNATURED_TYPE (attr) =
10352 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
10355 case DW_FORM_ref_udata:
10356 DW_ADDR (attr) = (cu->header.offset
10357 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
10358 info_ptr += bytes_read;
10360 case DW_FORM_indirect:
10361 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
10362 info_ptr += bytes_read;
10363 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
10366 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10367 dwarf_form_name (form),
10368 bfd_get_filename (abfd));
10371 /* We have seen instances where the compiler tried to emit a byte
10372 size attribute of -1 which ended up being encoded as an unsigned
10373 0xffffffff. Although 0xffffffff is technically a valid size value,
10374 an object of this size seems pretty unlikely so we can relatively
10375 safely treat these cases as if the size attribute was invalid and
10376 treat them as zero by default. */
10377 if (attr->name == DW_AT_byte_size
10378 && form == DW_FORM_data4
10379 && DW_UNSND (attr) >= 0xffffffff)
10382 (&symfile_complaints,
10383 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10384 hex_string (DW_UNSND (attr)));
10385 DW_UNSND (attr) = 0;
10391 /* Read an attribute described by an abbreviated attribute. */
10394 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10395 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10397 attr->name = abbrev->name;
10398 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10401 /* Read dwarf information from a buffer. */
10403 static unsigned int
10404 read_1_byte (bfd *abfd, gdb_byte *buf)
10406 return bfd_get_8 (abfd, buf);
10410 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10412 return bfd_get_signed_8 (abfd, buf);
10415 static unsigned int
10416 read_2_bytes (bfd *abfd, gdb_byte *buf)
10418 return bfd_get_16 (abfd, buf);
10422 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
10424 return bfd_get_signed_16 (abfd, buf);
10427 static unsigned int
10428 read_4_bytes (bfd *abfd, gdb_byte *buf)
10430 return bfd_get_32 (abfd, buf);
10434 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
10436 return bfd_get_signed_32 (abfd, buf);
10440 read_8_bytes (bfd *abfd, gdb_byte *buf)
10442 return bfd_get_64 (abfd, buf);
10446 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10447 unsigned int *bytes_read)
10449 struct comp_unit_head *cu_header = &cu->header;
10450 CORE_ADDR retval = 0;
10452 if (cu_header->signed_addr_p)
10454 switch (cu_header->addr_size)
10457 retval = bfd_get_signed_16 (abfd, buf);
10460 retval = bfd_get_signed_32 (abfd, buf);
10463 retval = bfd_get_signed_64 (abfd, buf);
10466 internal_error (__FILE__, __LINE__,
10467 _("read_address: bad switch, signed [in module %s]"),
10468 bfd_get_filename (abfd));
10473 switch (cu_header->addr_size)
10476 retval = bfd_get_16 (abfd, buf);
10479 retval = bfd_get_32 (abfd, buf);
10482 retval = bfd_get_64 (abfd, buf);
10485 internal_error (__FILE__, __LINE__,
10486 _("read_address: bad switch, "
10487 "unsigned [in module %s]"),
10488 bfd_get_filename (abfd));
10492 *bytes_read = cu_header->addr_size;
10496 /* Read the initial length from a section. The (draft) DWARF 3
10497 specification allows the initial length to take up either 4 bytes
10498 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10499 bytes describe the length and all offsets will be 8 bytes in length
10502 An older, non-standard 64-bit format is also handled by this
10503 function. The older format in question stores the initial length
10504 as an 8-byte quantity without an escape value. Lengths greater
10505 than 2^32 aren't very common which means that the initial 4 bytes
10506 is almost always zero. Since a length value of zero doesn't make
10507 sense for the 32-bit format, this initial zero can be considered to
10508 be an escape value which indicates the presence of the older 64-bit
10509 format. As written, the code can't detect (old format) lengths
10510 greater than 4GB. If it becomes necessary to handle lengths
10511 somewhat larger than 4GB, we could allow other small values (such
10512 as the non-sensical values of 1, 2, and 3) to also be used as
10513 escape values indicating the presence of the old format.
10515 The value returned via bytes_read should be used to increment the
10516 relevant pointer after calling read_initial_length().
10518 [ Note: read_initial_length() and read_offset() are based on the
10519 document entitled "DWARF Debugging Information Format", revision
10520 3, draft 8, dated November 19, 2001. This document was obtained
10523 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10525 This document is only a draft and is subject to change. (So beware.)
10527 Details regarding the older, non-standard 64-bit format were
10528 determined empirically by examining 64-bit ELF files produced by
10529 the SGI toolchain on an IRIX 6.5 machine.
10531 - Kevin, July 16, 2002
10535 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10537 LONGEST length = bfd_get_32 (abfd, buf);
10539 if (length == 0xffffffff)
10541 length = bfd_get_64 (abfd, buf + 4);
10544 else if (length == 0)
10546 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10547 length = bfd_get_64 (abfd, buf);
10558 /* Cover function for read_initial_length.
10559 Returns the length of the object at BUF, and stores the size of the
10560 initial length in *BYTES_READ and stores the size that offsets will be in
10562 If the initial length size is not equivalent to that specified in
10563 CU_HEADER then issue a complaint.
10564 This is useful when reading non-comp-unit headers. */
10567 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10568 const struct comp_unit_head *cu_header,
10569 unsigned int *bytes_read,
10570 unsigned int *offset_size)
10572 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10574 gdb_assert (cu_header->initial_length_size == 4
10575 || cu_header->initial_length_size == 8
10576 || cu_header->initial_length_size == 12);
10578 if (cu_header->initial_length_size != *bytes_read)
10579 complaint (&symfile_complaints,
10580 _("intermixed 32-bit and 64-bit DWARF sections"));
10582 *offset_size = (*bytes_read == 4) ? 4 : 8;
10586 /* Read an offset from the data stream. The size of the offset is
10587 given by cu_header->offset_size. */
10590 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10591 unsigned int *bytes_read)
10593 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10595 *bytes_read = cu_header->offset_size;
10599 /* Read an offset from the data stream. */
10602 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10604 LONGEST retval = 0;
10606 switch (offset_size)
10609 retval = bfd_get_32 (abfd, buf);
10612 retval = bfd_get_64 (abfd, buf);
10615 internal_error (__FILE__, __LINE__,
10616 _("read_offset_1: bad switch [in module %s]"),
10617 bfd_get_filename (abfd));
10624 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10626 /* If the size of a host char is 8 bits, we can return a pointer
10627 to the buffer, otherwise we have to copy the data to a buffer
10628 allocated on the temporary obstack. */
10629 gdb_assert (HOST_CHAR_BIT == 8);
10634 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10636 /* If the size of a host char is 8 bits, we can return a pointer
10637 to the string, otherwise we have to copy the string to a buffer
10638 allocated on the temporary obstack. */
10639 gdb_assert (HOST_CHAR_BIT == 8);
10642 *bytes_read_ptr = 1;
10645 *bytes_read_ptr = strlen ((char *) buf) + 1;
10646 return (char *) buf;
10650 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10652 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10653 if (dwarf2_per_objfile->str.buffer == NULL)
10654 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10655 bfd_get_filename (abfd));
10656 if (str_offset >= dwarf2_per_objfile->str.size)
10657 error (_("DW_FORM_strp pointing outside of "
10658 ".debug_str section [in module %s]"),
10659 bfd_get_filename (abfd));
10660 gdb_assert (HOST_CHAR_BIT == 8);
10661 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10663 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10667 read_indirect_string (bfd *abfd, gdb_byte *buf,
10668 const struct comp_unit_head *cu_header,
10669 unsigned int *bytes_read_ptr)
10671 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10673 return read_indirect_string_at_offset (abfd, str_offset);
10676 static unsigned long
10677 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10679 unsigned long result;
10680 unsigned int num_read;
10682 unsigned char byte;
10690 byte = bfd_get_8 (abfd, buf);
10693 result |= ((unsigned long)(byte & 127) << shift);
10694 if ((byte & 128) == 0)
10700 *bytes_read_ptr = num_read;
10705 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10708 int i, shift, num_read;
10709 unsigned char byte;
10717 byte = bfd_get_8 (abfd, buf);
10720 result |= ((long)(byte & 127) << shift);
10722 if ((byte & 128) == 0)
10727 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10728 result |= -(((long)1) << shift);
10729 *bytes_read_ptr = num_read;
10733 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10736 skip_leb128 (bfd *abfd, gdb_byte *buf)
10742 byte = bfd_get_8 (abfd, buf);
10744 if ((byte & 128) == 0)
10750 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10757 cu->language = language_c;
10759 case DW_LANG_C_plus_plus:
10760 cu->language = language_cplus;
10763 cu->language = language_d;
10765 case DW_LANG_Fortran77:
10766 case DW_LANG_Fortran90:
10767 case DW_LANG_Fortran95:
10768 cu->language = language_fortran;
10770 case DW_LANG_Mips_Assembler:
10771 cu->language = language_asm;
10774 cu->language = language_java;
10776 case DW_LANG_Ada83:
10777 case DW_LANG_Ada95:
10778 cu->language = language_ada;
10780 case DW_LANG_Modula2:
10781 cu->language = language_m2;
10783 case DW_LANG_Pascal83:
10784 cu->language = language_pascal;
10787 cu->language = language_objc;
10789 case DW_LANG_Cobol74:
10790 case DW_LANG_Cobol85:
10792 cu->language = language_minimal;
10795 cu->language_defn = language_def (cu->language);
10798 /* Return the named attribute or NULL if not there. */
10800 static struct attribute *
10801 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10804 struct attribute *spec = NULL;
10806 for (i = 0; i < die->num_attrs; ++i)
10808 if (die->attrs[i].name == name)
10809 return &die->attrs[i];
10810 if (die->attrs[i].name == DW_AT_specification
10811 || die->attrs[i].name == DW_AT_abstract_origin)
10812 spec = &die->attrs[i];
10817 die = follow_die_ref (die, spec, &cu);
10818 return dwarf2_attr (die, name, cu);
10824 /* Return the named attribute or NULL if not there,
10825 but do not follow DW_AT_specification, etc.
10826 This is for use in contexts where we're reading .debug_types dies.
10827 Following DW_AT_specification, DW_AT_abstract_origin will take us
10828 back up the chain, and we want to go down. */
10830 static struct attribute *
10831 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10832 struct dwarf2_cu *cu)
10836 for (i = 0; i < die->num_attrs; ++i)
10837 if (die->attrs[i].name == name)
10838 return &die->attrs[i];
10843 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10844 and holds a non-zero value. This function should only be used for
10845 DW_FORM_flag or DW_FORM_flag_present attributes. */
10848 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10850 struct attribute *attr = dwarf2_attr (die, name, cu);
10852 return (attr && DW_UNSND (attr));
10856 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10858 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10859 which value is non-zero. However, we have to be careful with
10860 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10861 (via dwarf2_flag_true_p) follows this attribute. So we may
10862 end up accidently finding a declaration attribute that belongs
10863 to a different DIE referenced by the specification attribute,
10864 even though the given DIE does not have a declaration attribute. */
10865 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10866 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10869 /* Return the die giving the specification for DIE, if there is
10870 one. *SPEC_CU is the CU containing DIE on input, and the CU
10871 containing the return value on output. If there is no
10872 specification, but there is an abstract origin, that is
10875 static struct die_info *
10876 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10878 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10881 if (spec_attr == NULL)
10882 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10884 if (spec_attr == NULL)
10887 return follow_die_ref (die, spec_attr, spec_cu);
10890 /* Free the line_header structure *LH, and any arrays and strings it
10892 NOTE: This is also used as a "cleanup" function. */
10895 free_line_header (struct line_header *lh)
10897 if (lh->standard_opcode_lengths)
10898 xfree (lh->standard_opcode_lengths);
10900 /* Remember that all the lh->file_names[i].name pointers are
10901 pointers into debug_line_buffer, and don't need to be freed. */
10902 if (lh->file_names)
10903 xfree (lh->file_names);
10905 /* Similarly for the include directory names. */
10906 if (lh->include_dirs)
10907 xfree (lh->include_dirs);
10912 /* Add an entry to LH's include directory table. */
10915 add_include_dir (struct line_header *lh, char *include_dir)
10917 /* Grow the array if necessary. */
10918 if (lh->include_dirs_size == 0)
10920 lh->include_dirs_size = 1; /* for testing */
10921 lh->include_dirs = xmalloc (lh->include_dirs_size
10922 * sizeof (*lh->include_dirs));
10924 else if (lh->num_include_dirs >= lh->include_dirs_size)
10926 lh->include_dirs_size *= 2;
10927 lh->include_dirs = xrealloc (lh->include_dirs,
10928 (lh->include_dirs_size
10929 * sizeof (*lh->include_dirs)));
10932 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10935 /* Add an entry to LH's file name table. */
10938 add_file_name (struct line_header *lh,
10940 unsigned int dir_index,
10941 unsigned int mod_time,
10942 unsigned int length)
10944 struct file_entry *fe;
10946 /* Grow the array if necessary. */
10947 if (lh->file_names_size == 0)
10949 lh->file_names_size = 1; /* for testing */
10950 lh->file_names = xmalloc (lh->file_names_size
10951 * sizeof (*lh->file_names));
10953 else if (lh->num_file_names >= lh->file_names_size)
10955 lh->file_names_size *= 2;
10956 lh->file_names = xrealloc (lh->file_names,
10957 (lh->file_names_size
10958 * sizeof (*lh->file_names)));
10961 fe = &lh->file_names[lh->num_file_names++];
10963 fe->dir_index = dir_index;
10964 fe->mod_time = mod_time;
10965 fe->length = length;
10966 fe->included_p = 0;
10970 /* Read the statement program header starting at OFFSET in
10971 .debug_line, according to the endianness of ABFD. Return a pointer
10972 to a struct line_header, allocated using xmalloc.
10974 NOTE: the strings in the include directory and file name tables of
10975 the returned object point into debug_line_buffer, and must not be
10978 static struct line_header *
10979 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10980 struct dwarf2_cu *cu)
10982 struct cleanup *back_to;
10983 struct line_header *lh;
10984 gdb_byte *line_ptr;
10985 unsigned int bytes_read, offset_size;
10987 char *cur_dir, *cur_file;
10989 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10990 if (dwarf2_per_objfile->line.buffer == NULL)
10992 complaint (&symfile_complaints, _("missing .debug_line section"));
10996 /* Make sure that at least there's room for the total_length field.
10997 That could be 12 bytes long, but we're just going to fudge that. */
10998 if (offset + 4 >= dwarf2_per_objfile->line.size)
11000 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11004 lh = xmalloc (sizeof (*lh));
11005 memset (lh, 0, sizeof (*lh));
11006 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
11009 line_ptr = dwarf2_per_objfile->line.buffer + offset;
11011 /* Read in the header. */
11013 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
11014 &bytes_read, &offset_size);
11015 line_ptr += bytes_read;
11016 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
11017 + dwarf2_per_objfile->line.size))
11019 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11022 lh->statement_program_end = line_ptr + lh->total_length;
11023 lh->version = read_2_bytes (abfd, line_ptr);
11025 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
11026 line_ptr += offset_size;
11027 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
11029 if (lh->version >= 4)
11031 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
11035 lh->maximum_ops_per_instruction = 1;
11037 if (lh->maximum_ops_per_instruction == 0)
11039 lh->maximum_ops_per_instruction = 1;
11040 complaint (&symfile_complaints,
11041 _("invalid maximum_ops_per_instruction "
11042 "in `.debug_line' section"));
11045 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
11047 lh->line_base = read_1_signed_byte (abfd, line_ptr);
11049 lh->line_range = read_1_byte (abfd, line_ptr);
11051 lh->opcode_base = read_1_byte (abfd, line_ptr);
11053 lh->standard_opcode_lengths
11054 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
11056 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
11057 for (i = 1; i < lh->opcode_base; ++i)
11059 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
11063 /* Read directory table. */
11064 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11066 line_ptr += bytes_read;
11067 add_include_dir (lh, cur_dir);
11069 line_ptr += bytes_read;
11071 /* Read file name table. */
11072 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
11074 unsigned int dir_index, mod_time, length;
11076 line_ptr += bytes_read;
11077 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11078 line_ptr += bytes_read;
11079 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11080 line_ptr += bytes_read;
11081 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11082 line_ptr += bytes_read;
11084 add_file_name (lh, cur_file, dir_index, mod_time, length);
11086 line_ptr += bytes_read;
11087 lh->statement_program_start = line_ptr;
11089 if (line_ptr > (dwarf2_per_objfile->line.buffer
11090 + dwarf2_per_objfile->line.size))
11091 complaint (&symfile_complaints,
11092 _("line number info header doesn't "
11093 "fit in `.debug_line' section"));
11095 discard_cleanups (back_to);
11099 /* This function exists to work around a bug in certain compilers
11100 (particularly GCC 2.95), in which the first line number marker of a
11101 function does not show up until after the prologue, right before
11102 the second line number marker. This function shifts ADDRESS down
11103 to the beginning of the function if necessary, and is called on
11104 addresses passed to record_line. */
11107 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
11109 struct function_range *fn;
11111 /* Find the function_range containing address. */
11115 if (!cu->cached_fn)
11116 cu->cached_fn = cu->first_fn;
11118 fn = cu->cached_fn;
11120 if (fn->lowpc <= address && fn->highpc > address)
11126 while (fn && fn != cu->cached_fn)
11127 if (fn->lowpc <= address && fn->highpc > address)
11137 if (address != fn->lowpc)
11138 complaint (&symfile_complaints,
11139 _("misplaced first line number at 0x%lx for '%s'"),
11140 (unsigned long) address, fn->name);
11145 /* Subroutine of dwarf_decode_lines to simplify it.
11146 Return the file name of the psymtab for included file FILE_INDEX
11147 in line header LH of PST.
11148 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11149 If space for the result is malloc'd, it will be freed by a cleanup.
11150 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11153 psymtab_include_file_name (const struct line_header *lh, int file_index,
11154 const struct partial_symtab *pst,
11155 const char *comp_dir)
11157 const struct file_entry fe = lh->file_names [file_index];
11158 char *include_name = fe.name;
11159 char *include_name_to_compare = include_name;
11160 char *dir_name = NULL;
11161 const char *pst_filename;
11162 char *copied_name = NULL;
11166 dir_name = lh->include_dirs[fe.dir_index - 1];
11168 if (!IS_ABSOLUTE_PATH (include_name)
11169 && (dir_name != NULL || comp_dir != NULL))
11171 /* Avoid creating a duplicate psymtab for PST.
11172 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11173 Before we do the comparison, however, we need to account
11174 for DIR_NAME and COMP_DIR.
11175 First prepend dir_name (if non-NULL). If we still don't
11176 have an absolute path prepend comp_dir (if non-NULL).
11177 However, the directory we record in the include-file's
11178 psymtab does not contain COMP_DIR (to match the
11179 corresponding symtab(s)).
11184 bash$ gcc -g ./hello.c
11185 include_name = "hello.c"
11187 DW_AT_comp_dir = comp_dir = "/tmp"
11188 DW_AT_name = "./hello.c" */
11190 if (dir_name != NULL)
11192 include_name = concat (dir_name, SLASH_STRING,
11193 include_name, (char *)NULL);
11194 include_name_to_compare = include_name;
11195 make_cleanup (xfree, include_name);
11197 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
11199 include_name_to_compare = concat (comp_dir, SLASH_STRING,
11200 include_name, (char *)NULL);
11204 pst_filename = pst->filename;
11205 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
11207 copied_name = concat (pst->dirname, SLASH_STRING,
11208 pst_filename, (char *)NULL);
11209 pst_filename = copied_name;
11212 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
11214 if (include_name_to_compare != include_name)
11215 xfree (include_name_to_compare);
11216 if (copied_name != NULL)
11217 xfree (copied_name);
11221 return include_name;
11224 /* Ignore this record_line request. */
11227 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
11232 /* Subroutine of dwarf_decode_lines to simplify it.
11233 Process the line number information in LH. */
11236 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
11237 struct dwarf2_cu *cu, struct partial_symtab *pst)
11239 gdb_byte *line_ptr, *extended_end;
11240 gdb_byte *line_end;
11241 unsigned int bytes_read, extended_len;
11242 unsigned char op_code, extended_op, adj_opcode;
11243 CORE_ADDR baseaddr;
11244 struct objfile *objfile = cu->objfile;
11245 bfd *abfd = objfile->obfd;
11246 struct gdbarch *gdbarch = get_objfile_arch (objfile);
11247 const int decode_for_pst_p = (pst != NULL);
11248 struct subfile *last_subfile = NULL;
11249 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
11252 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11254 line_ptr = lh->statement_program_start;
11255 line_end = lh->statement_program_end;
11257 /* Read the statement sequences until there's nothing left. */
11258 while (line_ptr < line_end)
11260 /* state machine registers */
11261 CORE_ADDR address = 0;
11262 unsigned int file = 1;
11263 unsigned int line = 1;
11264 unsigned int column = 0;
11265 int is_stmt = lh->default_is_stmt;
11266 int basic_block = 0;
11267 int end_sequence = 0;
11269 unsigned char op_index = 0;
11271 if (!decode_for_pst_p && lh->num_file_names >= file)
11273 /* Start a subfile for the current file of the state machine. */
11274 /* lh->include_dirs and lh->file_names are 0-based, but the
11275 directory and file name numbers in the statement program
11277 struct file_entry *fe = &lh->file_names[file - 1];
11281 dir = lh->include_dirs[fe->dir_index - 1];
11283 dwarf2_start_subfile (fe->name, dir, comp_dir);
11286 /* Decode the table. */
11287 while (!end_sequence)
11289 op_code = read_1_byte (abfd, line_ptr);
11291 if (line_ptr > line_end)
11293 dwarf2_debug_line_missing_end_sequence_complaint ();
11297 if (op_code >= lh->opcode_base)
11299 /* Special operand. */
11300 adj_opcode = op_code - lh->opcode_base;
11301 address += (((op_index + (adj_opcode / lh->line_range))
11302 / lh->maximum_ops_per_instruction)
11303 * lh->minimum_instruction_length);
11304 op_index = ((op_index + (adj_opcode / lh->line_range))
11305 % lh->maximum_ops_per_instruction);
11306 line += lh->line_base + (adj_opcode % lh->line_range);
11307 if (lh->num_file_names < file || file == 0)
11308 dwarf2_debug_line_missing_file_complaint ();
11309 /* For now we ignore lines not starting on an
11310 instruction boundary. */
11311 else if (op_index == 0)
11313 lh->file_names[file - 1].included_p = 1;
11314 if (!decode_for_pst_p && is_stmt)
11316 if (last_subfile != current_subfile)
11318 addr = gdbarch_addr_bits_remove (gdbarch, address);
11320 (*p_record_line) (last_subfile, 0, addr);
11321 last_subfile = current_subfile;
11323 /* Append row to matrix using current values. */
11324 addr = check_cu_functions (address, cu);
11325 addr = gdbarch_addr_bits_remove (gdbarch, addr);
11326 (*p_record_line) (current_subfile, line, addr);
11331 else switch (op_code)
11333 case DW_LNS_extended_op:
11334 extended_len = read_unsigned_leb128 (abfd, line_ptr,
11336 line_ptr += bytes_read;
11337 extended_end = line_ptr + extended_len;
11338 extended_op = read_1_byte (abfd, line_ptr);
11340 switch (extended_op)
11342 case DW_LNE_end_sequence:
11343 p_record_line = record_line;
11346 case DW_LNE_set_address:
11347 address = read_address (abfd, line_ptr, cu, &bytes_read);
11349 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
11351 /* This line table is for a function which has been
11352 GCd by the linker. Ignore it. PR gdb/12528 */
11355 = line_ptr - dwarf2_per_objfile->line.buffer;
11357 complaint (&symfile_complaints,
11358 _(".debug_line address at offset 0x%lx is 0 "
11360 line_offset, cu->objfile->name);
11361 p_record_line = noop_record_line;
11365 line_ptr += bytes_read;
11366 address += baseaddr;
11368 case DW_LNE_define_file:
11371 unsigned int dir_index, mod_time, length;
11373 cur_file = read_direct_string (abfd, line_ptr,
11375 line_ptr += bytes_read;
11377 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11378 line_ptr += bytes_read;
11380 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11381 line_ptr += bytes_read;
11383 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11384 line_ptr += bytes_read;
11385 add_file_name (lh, cur_file, dir_index, mod_time, length);
11388 case DW_LNE_set_discriminator:
11389 /* The discriminator is not interesting to the debugger;
11391 line_ptr = extended_end;
11394 complaint (&symfile_complaints,
11395 _("mangled .debug_line section"));
11398 /* Make sure that we parsed the extended op correctly. If e.g.
11399 we expected a different address size than the producer used,
11400 we may have read the wrong number of bytes. */
11401 if (line_ptr != extended_end)
11403 complaint (&symfile_complaints,
11404 _("mangled .debug_line section"));
11409 if (lh->num_file_names < file || file == 0)
11410 dwarf2_debug_line_missing_file_complaint ();
11413 lh->file_names[file - 1].included_p = 1;
11414 if (!decode_for_pst_p && is_stmt)
11416 if (last_subfile != current_subfile)
11418 addr = gdbarch_addr_bits_remove (gdbarch, address);
11420 (*p_record_line) (last_subfile, 0, addr);
11421 last_subfile = current_subfile;
11423 addr = check_cu_functions (address, cu);
11424 addr = gdbarch_addr_bits_remove (gdbarch, addr);
11425 (*p_record_line) (current_subfile, line, addr);
11430 case DW_LNS_advance_pc:
11433 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11435 address += (((op_index + adjust)
11436 / lh->maximum_ops_per_instruction)
11437 * lh->minimum_instruction_length);
11438 op_index = ((op_index + adjust)
11439 % lh->maximum_ops_per_instruction);
11440 line_ptr += bytes_read;
11443 case DW_LNS_advance_line:
11444 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11445 line_ptr += bytes_read;
11447 case DW_LNS_set_file:
11449 /* The arrays lh->include_dirs and lh->file_names are
11450 0-based, but the directory and file name numbers in
11451 the statement program are 1-based. */
11452 struct file_entry *fe;
11455 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11456 line_ptr += bytes_read;
11457 if (lh->num_file_names < file || file == 0)
11458 dwarf2_debug_line_missing_file_complaint ();
11461 fe = &lh->file_names[file - 1];
11463 dir = lh->include_dirs[fe->dir_index - 1];
11464 if (!decode_for_pst_p)
11466 last_subfile = current_subfile;
11467 dwarf2_start_subfile (fe->name, dir, comp_dir);
11472 case DW_LNS_set_column:
11473 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11474 line_ptr += bytes_read;
11476 case DW_LNS_negate_stmt:
11477 is_stmt = (!is_stmt);
11479 case DW_LNS_set_basic_block:
11482 /* Add to the address register of the state machine the
11483 address increment value corresponding to special opcode
11484 255. I.e., this value is scaled by the minimum
11485 instruction length since special opcode 255 would have
11486 scaled the increment. */
11487 case DW_LNS_const_add_pc:
11489 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11491 address += (((op_index + adjust)
11492 / lh->maximum_ops_per_instruction)
11493 * lh->minimum_instruction_length);
11494 op_index = ((op_index + adjust)
11495 % lh->maximum_ops_per_instruction);
11498 case DW_LNS_fixed_advance_pc:
11499 address += read_2_bytes (abfd, line_ptr);
11505 /* Unknown standard opcode, ignore it. */
11508 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11510 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11511 line_ptr += bytes_read;
11516 if (lh->num_file_names < file || file == 0)
11517 dwarf2_debug_line_missing_file_complaint ();
11520 lh->file_names[file - 1].included_p = 1;
11521 if (!decode_for_pst_p)
11523 addr = gdbarch_addr_bits_remove (gdbarch, address);
11524 (*p_record_line) (current_subfile, 0, addr);
11530 /* Decode the Line Number Program (LNP) for the given line_header
11531 structure and CU. The actual information extracted and the type
11532 of structures created from the LNP depends on the value of PST.
11534 1. If PST is NULL, then this procedure uses the data from the program
11535 to create all necessary symbol tables, and their linetables.
11537 2. If PST is not NULL, this procedure reads the program to determine
11538 the list of files included by the unit represented by PST, and
11539 builds all the associated partial symbol tables.
11541 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11542 It is used for relative paths in the line table.
11543 NOTE: When processing partial symtabs (pst != NULL),
11544 comp_dir == pst->dirname.
11546 NOTE: It is important that psymtabs have the same file name (via strcmp)
11547 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11548 symtab we don't use it in the name of the psymtabs we create.
11549 E.g. expand_line_sal requires this when finding psymtabs to expand.
11550 A good testcase for this is mb-inline.exp. */
11553 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
11554 struct dwarf2_cu *cu, struct partial_symtab *pst,
11555 int want_line_info)
11557 struct objfile *objfile = cu->objfile;
11558 const int decode_for_pst_p = (pst != NULL);
11559 struct subfile *first_subfile = current_subfile;
11561 if (want_line_info)
11562 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
11564 if (decode_for_pst_p)
11568 /* Now that we're done scanning the Line Header Program, we can
11569 create the psymtab of each included file. */
11570 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11571 if (lh->file_names[file_index].included_p == 1)
11573 char *include_name =
11574 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11575 if (include_name != NULL)
11576 dwarf2_create_include_psymtab (include_name, pst, objfile);
11581 /* Make sure a symtab is created for every file, even files
11582 which contain only variables (i.e. no code with associated
11586 for (i = 0; i < lh->num_file_names; i++)
11589 struct file_entry *fe;
11591 fe = &lh->file_names[i];
11593 dir = lh->include_dirs[fe->dir_index - 1];
11594 dwarf2_start_subfile (fe->name, dir, comp_dir);
11596 /* Skip the main file; we don't need it, and it must be
11597 allocated last, so that it will show up before the
11598 non-primary symtabs in the objfile's symtab list. */
11599 if (current_subfile == first_subfile)
11602 if (current_subfile->symtab == NULL)
11603 current_subfile->symtab = allocate_symtab (current_subfile->name,
11605 fe->symtab = current_subfile->symtab;
11610 /* Start a subfile for DWARF. FILENAME is the name of the file and
11611 DIRNAME the name of the source directory which contains FILENAME
11612 or NULL if not known. COMP_DIR is the compilation directory for the
11613 linetable's compilation unit or NULL if not known.
11614 This routine tries to keep line numbers from identical absolute and
11615 relative file names in a common subfile.
11617 Using the `list' example from the GDB testsuite, which resides in
11618 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11619 of /srcdir/list0.c yields the following debugging information for list0.c:
11621 DW_AT_name: /srcdir/list0.c
11622 DW_AT_comp_dir: /compdir
11623 files.files[0].name: list0.h
11624 files.files[0].dir: /srcdir
11625 files.files[1].name: list0.c
11626 files.files[1].dir: /srcdir
11628 The line number information for list0.c has to end up in a single
11629 subfile, so that `break /srcdir/list0.c:1' works as expected.
11630 start_subfile will ensure that this happens provided that we pass the
11631 concatenation of files.files[1].dir and files.files[1].name as the
11635 dwarf2_start_subfile (char *filename, const char *dirname,
11636 const char *comp_dir)
11640 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11641 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11642 second argument to start_subfile. To be consistent, we do the
11643 same here. In order not to lose the line information directory,
11644 we concatenate it to the filename when it makes sense.
11645 Note that the Dwarf3 standard says (speaking of filenames in line
11646 information): ``The directory index is ignored for file names
11647 that represent full path names''. Thus ignoring dirname in the
11648 `else' branch below isn't an issue. */
11650 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11651 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11653 fullname = filename;
11655 start_subfile (fullname, comp_dir);
11657 if (fullname != filename)
11662 var_decode_location (struct attribute *attr, struct symbol *sym,
11663 struct dwarf2_cu *cu)
11665 struct objfile *objfile = cu->objfile;
11666 struct comp_unit_head *cu_header = &cu->header;
11668 /* NOTE drow/2003-01-30: There used to be a comment and some special
11669 code here to turn a symbol with DW_AT_external and a
11670 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11671 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11672 with some versions of binutils) where shared libraries could have
11673 relocations against symbols in their debug information - the
11674 minimal symbol would have the right address, but the debug info
11675 would not. It's no longer necessary, because we will explicitly
11676 apply relocations when we read in the debug information now. */
11678 /* A DW_AT_location attribute with no contents indicates that a
11679 variable has been optimized away. */
11680 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11682 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11686 /* Handle one degenerate form of location expression specially, to
11687 preserve GDB's previous behavior when section offsets are
11688 specified. If this is just a DW_OP_addr then mark this symbol
11691 if (attr_form_is_block (attr)
11692 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11693 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11695 unsigned int dummy;
11697 SYMBOL_VALUE_ADDRESS (sym) =
11698 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11699 SYMBOL_CLASS (sym) = LOC_STATIC;
11700 fixup_symbol_section (sym, objfile);
11701 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11702 SYMBOL_SECTION (sym));
11706 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11707 expression evaluator, and use LOC_COMPUTED only when necessary
11708 (i.e. when the value of a register or memory location is
11709 referenced, or a thread-local block, etc.). Then again, it might
11710 not be worthwhile. I'm assuming that it isn't unless performance
11711 or memory numbers show me otherwise. */
11713 dwarf2_symbol_mark_computed (attr, sym, cu);
11714 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11716 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11717 cu->has_loclist = 1;
11720 /* Given a pointer to a DWARF information entry, figure out if we need
11721 to make a symbol table entry for it, and if so, create a new entry
11722 and return a pointer to it.
11723 If TYPE is NULL, determine symbol type from the die, otherwise
11724 used the passed type.
11725 If SPACE is not NULL, use it to hold the new symbol. If it is
11726 NULL, allocate a new symbol on the objfile's obstack. */
11728 static struct symbol *
11729 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11730 struct symbol *space)
11732 struct objfile *objfile = cu->objfile;
11733 struct symbol *sym = NULL;
11735 struct attribute *attr = NULL;
11736 struct attribute *attr2 = NULL;
11737 CORE_ADDR baseaddr;
11738 struct pending **list_to_add = NULL;
11740 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11742 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11744 name = dwarf2_name (die, cu);
11747 const char *linkagename;
11748 int suppress_add = 0;
11753 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11754 OBJSTAT (objfile, n_syms++);
11756 /* Cache this symbol's name and the name's demangled form (if any). */
11757 SYMBOL_SET_LANGUAGE (sym, cu->language);
11758 linkagename = dwarf2_physname (name, die, cu);
11759 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11761 /* Fortran does not have mangling standard and the mangling does differ
11762 between gfortran, iFort etc. */
11763 if (cu->language == language_fortran
11764 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11765 symbol_set_demangled_name (&(sym->ginfo),
11766 (char *) dwarf2_full_name (name, die, cu),
11769 /* Default assumptions.
11770 Use the passed type or decode it from the die. */
11771 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11772 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11774 SYMBOL_TYPE (sym) = type;
11776 SYMBOL_TYPE (sym) = die_type (die, cu);
11777 attr = dwarf2_attr (die,
11778 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11782 SYMBOL_LINE (sym) = DW_UNSND (attr);
11785 attr = dwarf2_attr (die,
11786 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11790 int file_index = DW_UNSND (attr);
11792 if (cu->line_header == NULL
11793 || file_index > cu->line_header->num_file_names)
11794 complaint (&symfile_complaints,
11795 _("file index out of range"));
11796 else if (file_index > 0)
11798 struct file_entry *fe;
11800 fe = &cu->line_header->file_names[file_index - 1];
11801 SYMBOL_SYMTAB (sym) = fe->symtab;
11808 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11811 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11813 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11814 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11815 SYMBOL_CLASS (sym) = LOC_LABEL;
11816 add_symbol_to_list (sym, cu->list_in_scope);
11818 case DW_TAG_subprogram:
11819 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11821 SYMBOL_CLASS (sym) = LOC_BLOCK;
11822 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11823 if ((attr2 && (DW_UNSND (attr2) != 0))
11824 || cu->language == language_ada)
11826 /* Subprograms marked external are stored as a global symbol.
11827 Ada subprograms, whether marked external or not, are always
11828 stored as a global symbol, because we want to be able to
11829 access them globally. For instance, we want to be able
11830 to break on a nested subprogram without having to
11831 specify the context. */
11832 list_to_add = &global_symbols;
11836 list_to_add = cu->list_in_scope;
11839 case DW_TAG_inlined_subroutine:
11840 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11842 SYMBOL_CLASS (sym) = LOC_BLOCK;
11843 SYMBOL_INLINED (sym) = 1;
11844 /* Do not add the symbol to any lists. It will be found via
11845 BLOCK_FUNCTION from the blockvector. */
11847 case DW_TAG_template_value_param:
11849 /* Fall through. */
11850 case DW_TAG_constant:
11851 case DW_TAG_variable:
11852 case DW_TAG_member:
11853 /* Compilation with minimal debug info may result in
11854 variables with missing type entries. Change the
11855 misleading `void' type to something sensible. */
11856 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11858 = objfile_type (objfile)->nodebug_data_symbol;
11860 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11861 /* In the case of DW_TAG_member, we should only be called for
11862 static const members. */
11863 if (die->tag == DW_TAG_member)
11865 /* dwarf2_add_field uses die_is_declaration,
11866 so we do the same. */
11867 gdb_assert (die_is_declaration (die, cu));
11872 dwarf2_const_value (attr, sym, cu);
11873 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11876 if (attr2 && (DW_UNSND (attr2) != 0))
11877 list_to_add = &global_symbols;
11879 list_to_add = cu->list_in_scope;
11883 attr = dwarf2_attr (die, DW_AT_location, cu);
11886 var_decode_location (attr, sym, cu);
11887 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11888 if (SYMBOL_CLASS (sym) == LOC_STATIC
11889 && SYMBOL_VALUE_ADDRESS (sym) == 0
11890 && !dwarf2_per_objfile->has_section_at_zero)
11892 /* When a static variable is eliminated by the linker,
11893 the corresponding debug information is not stripped
11894 out, but the variable address is set to null;
11895 do not add such variables into symbol table. */
11897 else if (attr2 && (DW_UNSND (attr2) != 0))
11899 /* Workaround gfortran PR debug/40040 - it uses
11900 DW_AT_location for variables in -fPIC libraries which may
11901 get overriden by other libraries/executable and get
11902 a different address. Resolve it by the minimal symbol
11903 which may come from inferior's executable using copy
11904 relocation. Make this workaround only for gfortran as for
11905 other compilers GDB cannot guess the minimal symbol
11906 Fortran mangling kind. */
11907 if (cu->language == language_fortran && die->parent
11908 && die->parent->tag == DW_TAG_module
11910 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11911 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11913 /* A variable with DW_AT_external is never static,
11914 but it may be block-scoped. */
11915 list_to_add = (cu->list_in_scope == &file_symbols
11916 ? &global_symbols : cu->list_in_scope);
11919 list_to_add = cu->list_in_scope;
11923 /* We do not know the address of this symbol.
11924 If it is an external symbol and we have type information
11925 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11926 The address of the variable will then be determined from
11927 the minimal symbol table whenever the variable is
11929 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11930 if (attr2 && (DW_UNSND (attr2) != 0)
11931 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11933 /* A variable with DW_AT_external is never static, but it
11934 may be block-scoped. */
11935 list_to_add = (cu->list_in_scope == &file_symbols
11936 ? &global_symbols : cu->list_in_scope);
11938 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11940 else if (!die_is_declaration (die, cu))
11942 /* Use the default LOC_OPTIMIZED_OUT class. */
11943 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11945 list_to_add = cu->list_in_scope;
11949 case DW_TAG_formal_parameter:
11950 /* If we are inside a function, mark this as an argument. If
11951 not, we might be looking at an argument to an inlined function
11952 when we do not have enough information to show inlined frames;
11953 pretend it's a local variable in that case so that the user can
11955 if (context_stack_depth > 0
11956 && context_stack[context_stack_depth - 1].name != NULL)
11957 SYMBOL_IS_ARGUMENT (sym) = 1;
11958 attr = dwarf2_attr (die, DW_AT_location, cu);
11961 var_decode_location (attr, sym, cu);
11963 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11966 dwarf2_const_value (attr, sym, cu);
11969 list_to_add = cu->list_in_scope;
11971 case DW_TAG_unspecified_parameters:
11972 /* From varargs functions; gdb doesn't seem to have any
11973 interest in this information, so just ignore it for now.
11976 case DW_TAG_template_type_param:
11978 /* Fall through. */
11979 case DW_TAG_class_type:
11980 case DW_TAG_interface_type:
11981 case DW_TAG_structure_type:
11982 case DW_TAG_union_type:
11983 case DW_TAG_set_type:
11984 case DW_TAG_enumeration_type:
11985 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11986 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11989 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11990 really ever be static objects: otherwise, if you try
11991 to, say, break of a class's method and you're in a file
11992 which doesn't mention that class, it won't work unless
11993 the check for all static symbols in lookup_symbol_aux
11994 saves you. See the OtherFileClass tests in
11995 gdb.c++/namespace.exp. */
11999 list_to_add = (cu->list_in_scope == &file_symbols
12000 && (cu->language == language_cplus
12001 || cu->language == language_java)
12002 ? &global_symbols : cu->list_in_scope);
12004 /* The semantics of C++ state that "struct foo {
12005 ... }" also defines a typedef for "foo". A Java
12006 class declaration also defines a typedef for the
12008 if (cu->language == language_cplus
12009 || cu->language == language_java
12010 || cu->language == language_ada)
12012 /* The symbol's name is already allocated along
12013 with this objfile, so we don't need to
12014 duplicate it for the type. */
12015 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
12016 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
12021 case DW_TAG_typedef:
12022 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12023 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
12024 list_to_add = cu->list_in_scope;
12026 case DW_TAG_base_type:
12027 case DW_TAG_subrange_type:
12028 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12029 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
12030 list_to_add = cu->list_in_scope;
12032 case DW_TAG_enumerator:
12033 attr = dwarf2_attr (die, DW_AT_const_value, cu);
12036 dwarf2_const_value (attr, sym, cu);
12039 /* NOTE: carlton/2003-11-10: See comment above in the
12040 DW_TAG_class_type, etc. block. */
12042 list_to_add = (cu->list_in_scope == &file_symbols
12043 && (cu->language == language_cplus
12044 || cu->language == language_java)
12045 ? &global_symbols : cu->list_in_scope);
12048 case DW_TAG_namespace:
12049 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12050 list_to_add = &global_symbols;
12053 /* Not a tag we recognize. Hopefully we aren't processing
12054 trash data, but since we must specifically ignore things
12055 we don't recognize, there is nothing else we should do at
12057 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
12058 dwarf_tag_name (die->tag));
12064 sym->hash_next = objfile->template_symbols;
12065 objfile->template_symbols = sym;
12066 list_to_add = NULL;
12069 if (list_to_add != NULL)
12070 add_symbol_to_list (sym, list_to_add);
12072 /* For the benefit of old versions of GCC, check for anonymous
12073 namespaces based on the demangled name. */
12074 if (!processing_has_namespace_info
12075 && cu->language == language_cplus)
12076 cp_scan_for_anonymous_namespaces (sym, objfile);
12081 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12083 static struct symbol *
12084 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
12086 return new_symbol_full (die, type, cu, NULL);
12089 /* Given an attr with a DW_FORM_dataN value in host byte order,
12090 zero-extend it as appropriate for the symbol's type. The DWARF
12091 standard (v4) is not entirely clear about the meaning of using
12092 DW_FORM_dataN for a constant with a signed type, where the type is
12093 wider than the data. The conclusion of a discussion on the DWARF
12094 list was that this is unspecified. We choose to always zero-extend
12095 because that is the interpretation long in use by GCC. */
12098 dwarf2_const_value_data (struct attribute *attr, struct type *type,
12099 const char *name, struct obstack *obstack,
12100 struct dwarf2_cu *cu, long *value, int bits)
12102 struct objfile *objfile = cu->objfile;
12103 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
12104 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
12105 LONGEST l = DW_UNSND (attr);
12107 if (bits < sizeof (*value) * 8)
12109 l &= ((LONGEST) 1 << bits) - 1;
12112 else if (bits == sizeof (*value) * 8)
12116 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
12117 store_unsigned_integer (bytes, bits / 8, byte_order, l);
12124 /* Read a constant value from an attribute. Either set *VALUE, or if
12125 the value does not fit in *VALUE, set *BYTES - either already
12126 allocated on the objfile obstack, or newly allocated on OBSTACK,
12127 or, set *BATON, if we translated the constant to a location
12131 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
12132 const char *name, struct obstack *obstack,
12133 struct dwarf2_cu *cu,
12134 long *value, gdb_byte **bytes,
12135 struct dwarf2_locexpr_baton **baton)
12137 struct objfile *objfile = cu->objfile;
12138 struct comp_unit_head *cu_header = &cu->header;
12139 struct dwarf_block *blk;
12140 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
12141 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
12147 switch (attr->form)
12153 if (TYPE_LENGTH (type) != cu_header->addr_size)
12154 dwarf2_const_value_length_mismatch_complaint (name,
12155 cu_header->addr_size,
12156 TYPE_LENGTH (type));
12157 /* Symbols of this form are reasonably rare, so we just
12158 piggyback on the existing location code rather than writing
12159 a new implementation of symbol_computed_ops. */
12160 *baton = obstack_alloc (&objfile->objfile_obstack,
12161 sizeof (struct dwarf2_locexpr_baton));
12162 (*baton)->per_cu = cu->per_cu;
12163 gdb_assert ((*baton)->per_cu);
12165 (*baton)->size = 2 + cu_header->addr_size;
12166 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
12167 (*baton)->data = data;
12169 data[0] = DW_OP_addr;
12170 store_unsigned_integer (&data[1], cu_header->addr_size,
12171 byte_order, DW_ADDR (attr));
12172 data[cu_header->addr_size + 1] = DW_OP_stack_value;
12175 case DW_FORM_string:
12177 /* DW_STRING is already allocated on the objfile obstack, point
12179 *bytes = (gdb_byte *) DW_STRING (attr);
12181 case DW_FORM_block1:
12182 case DW_FORM_block2:
12183 case DW_FORM_block4:
12184 case DW_FORM_block:
12185 case DW_FORM_exprloc:
12186 blk = DW_BLOCK (attr);
12187 if (TYPE_LENGTH (type) != blk->size)
12188 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
12189 TYPE_LENGTH (type));
12190 *bytes = blk->data;
12193 /* The DW_AT_const_value attributes are supposed to carry the
12194 symbol's value "represented as it would be on the target
12195 architecture." By the time we get here, it's already been
12196 converted to host endianness, so we just need to sign- or
12197 zero-extend it as appropriate. */
12198 case DW_FORM_data1:
12199 *bytes = dwarf2_const_value_data (attr, type, name,
12200 obstack, cu, value, 8);
12202 case DW_FORM_data2:
12203 *bytes = dwarf2_const_value_data (attr, type, name,
12204 obstack, cu, value, 16);
12206 case DW_FORM_data4:
12207 *bytes = dwarf2_const_value_data (attr, type, name,
12208 obstack, cu, value, 32);
12210 case DW_FORM_data8:
12211 *bytes = dwarf2_const_value_data (attr, type, name,
12212 obstack, cu, value, 64);
12215 case DW_FORM_sdata:
12216 *value = DW_SND (attr);
12219 case DW_FORM_udata:
12220 *value = DW_UNSND (attr);
12224 complaint (&symfile_complaints,
12225 _("unsupported const value attribute form: '%s'"),
12226 dwarf_form_name (attr->form));
12233 /* Copy constant value from an attribute to a symbol. */
12236 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
12237 struct dwarf2_cu *cu)
12239 struct objfile *objfile = cu->objfile;
12240 struct comp_unit_head *cu_header = &cu->header;
12243 struct dwarf2_locexpr_baton *baton;
12245 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
12246 SYMBOL_PRINT_NAME (sym),
12247 &objfile->objfile_obstack, cu,
12248 &value, &bytes, &baton);
12252 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
12253 SYMBOL_LOCATION_BATON (sym) = baton;
12254 SYMBOL_CLASS (sym) = LOC_COMPUTED;
12256 else if (bytes != NULL)
12258 SYMBOL_VALUE_BYTES (sym) = bytes;
12259 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
12263 SYMBOL_VALUE (sym) = value;
12264 SYMBOL_CLASS (sym) = LOC_CONST;
12268 /* Return the type of the die in question using its DW_AT_type attribute. */
12270 static struct type *
12271 die_type (struct die_info *die, struct dwarf2_cu *cu)
12273 struct attribute *type_attr;
12275 type_attr = dwarf2_attr (die, DW_AT_type, cu);
12278 /* A missing DW_AT_type represents a void type. */
12279 return objfile_type (cu->objfile)->builtin_void;
12282 return lookup_die_type (die, type_attr, cu);
12285 /* True iff CU's producer generates GNAT Ada auxiliary information
12286 that allows to find parallel types through that information instead
12287 of having to do expensive parallel lookups by type name. */
12290 need_gnat_info (struct dwarf2_cu *cu)
12292 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12293 of GNAT produces this auxiliary information, without any indication
12294 that it is produced. Part of enhancing the FSF version of GNAT
12295 to produce that information will be to put in place an indicator
12296 that we can use in order to determine whether the descriptive type
12297 info is available or not. One suggestion that has been made is
12298 to use a new attribute, attached to the CU die. For now, assume
12299 that the descriptive type info is not available. */
12303 /* Return the auxiliary type of the die in question using its
12304 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12305 attribute is not present. */
12307 static struct type *
12308 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
12310 struct attribute *type_attr;
12312 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
12316 return lookup_die_type (die, type_attr, cu);
12319 /* If DIE has a descriptive_type attribute, then set the TYPE's
12320 descriptive type accordingly. */
12323 set_descriptive_type (struct type *type, struct die_info *die,
12324 struct dwarf2_cu *cu)
12326 struct type *descriptive_type = die_descriptive_type (die, cu);
12328 if (descriptive_type)
12330 ALLOCATE_GNAT_AUX_TYPE (type);
12331 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
12335 /* Return the containing type of the die in question using its
12336 DW_AT_containing_type attribute. */
12338 static struct type *
12339 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12341 struct attribute *type_attr;
12343 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
12345 error (_("Dwarf Error: Problem turning containing type into gdb type "
12346 "[in module %s]"), cu->objfile->name);
12348 return lookup_die_type (die, type_attr, cu);
12351 /* Look up the type of DIE in CU using its type attribute ATTR.
12352 If there is no type substitute an error marker. */
12354 static struct type *
12355 lookup_die_type (struct die_info *die, struct attribute *attr,
12356 struct dwarf2_cu *cu)
12358 struct type *this_type;
12360 /* First see if we have it cached. */
12362 if (is_ref_attr (attr))
12364 unsigned int offset = dwarf2_get_ref_die_offset (attr);
12366 this_type = get_die_type_at_offset (offset, cu->per_cu);
12368 else if (attr->form == DW_FORM_ref_sig8)
12370 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
12371 struct dwarf2_cu *sig_cu;
12372 unsigned int offset;
12374 /* sig_type will be NULL if the signatured type is missing from
12376 if (sig_type == NULL)
12377 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12378 "at 0x%x [in module %s]"),
12379 die->offset, cu->objfile->name);
12381 gdb_assert (sig_type->per_cu.debug_types_section);
12382 offset = sig_type->per_cu.offset + sig_type->type_offset;
12383 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
12387 dump_die_for_error (die);
12388 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12389 dwarf_attr_name (attr->name), cu->objfile->name);
12392 /* If not cached we need to read it in. */
12394 if (this_type == NULL)
12396 struct die_info *type_die;
12397 struct dwarf2_cu *type_cu = cu;
12399 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
12400 /* If the type is cached, we should have found it above. */
12401 gdb_assert (get_die_type (type_die, type_cu) == NULL);
12402 this_type = read_type_die_1 (type_die, type_cu);
12405 /* If we still don't have a type use an error marker. */
12407 if (this_type == NULL)
12409 char *message, *saved;
12411 /* read_type_die already issued a complaint. */
12412 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12416 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
12417 message, strlen (message));
12420 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
12426 /* Return the type in DIE, CU.
12427 Returns NULL for invalid types.
12429 This first does a lookup in the appropriate type_hash table,
12430 and only reads the die in if necessary.
12432 NOTE: This can be called when reading in partial or full symbols. */
12434 static struct type *
12435 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12437 struct type *this_type;
12439 this_type = get_die_type (die, cu);
12443 return read_type_die_1 (die, cu);
12446 /* Read the type in DIE, CU.
12447 Returns NULL for invalid types. */
12449 static struct type *
12450 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12452 struct type *this_type = NULL;
12456 case DW_TAG_class_type:
12457 case DW_TAG_interface_type:
12458 case DW_TAG_structure_type:
12459 case DW_TAG_union_type:
12460 this_type = read_structure_type (die, cu);
12462 case DW_TAG_enumeration_type:
12463 this_type = read_enumeration_type (die, cu);
12465 case DW_TAG_subprogram:
12466 case DW_TAG_subroutine_type:
12467 case DW_TAG_inlined_subroutine:
12468 this_type = read_subroutine_type (die, cu);
12470 case DW_TAG_array_type:
12471 this_type = read_array_type (die, cu);
12473 case DW_TAG_set_type:
12474 this_type = read_set_type (die, cu);
12476 case DW_TAG_pointer_type:
12477 this_type = read_tag_pointer_type (die, cu);
12479 case DW_TAG_ptr_to_member_type:
12480 this_type = read_tag_ptr_to_member_type (die, cu);
12482 case DW_TAG_reference_type:
12483 this_type = read_tag_reference_type (die, cu);
12485 case DW_TAG_const_type:
12486 this_type = read_tag_const_type (die, cu);
12488 case DW_TAG_volatile_type:
12489 this_type = read_tag_volatile_type (die, cu);
12491 case DW_TAG_string_type:
12492 this_type = read_tag_string_type (die, cu);
12494 case DW_TAG_typedef:
12495 this_type = read_typedef (die, cu);
12497 case DW_TAG_subrange_type:
12498 this_type = read_subrange_type (die, cu);
12500 case DW_TAG_base_type:
12501 this_type = read_base_type (die, cu);
12503 case DW_TAG_unspecified_type:
12504 this_type = read_unspecified_type (die, cu);
12506 case DW_TAG_namespace:
12507 this_type = read_namespace_type (die, cu);
12509 case DW_TAG_module:
12510 this_type = read_module_type (die, cu);
12513 complaint (&symfile_complaints,
12514 _("unexpected tag in read_type_die: '%s'"),
12515 dwarf_tag_name (die->tag));
12522 /* See if we can figure out if the class lives in a namespace. We do
12523 this by looking for a member function; its demangled name will
12524 contain namespace info, if there is any.
12525 Return the computed name or NULL.
12526 Space for the result is allocated on the objfile's obstack.
12527 This is the full-die version of guess_partial_die_structure_name.
12528 In this case we know DIE has no useful parent. */
12531 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12533 struct die_info *spec_die;
12534 struct dwarf2_cu *spec_cu;
12535 struct die_info *child;
12538 spec_die = die_specification (die, &spec_cu);
12539 if (spec_die != NULL)
12545 for (child = die->child;
12547 child = child->sibling)
12549 if (child->tag == DW_TAG_subprogram)
12551 struct attribute *attr;
12553 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12555 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12559 = language_class_name_from_physname (cu->language_defn,
12563 if (actual_name != NULL)
12565 char *die_name = dwarf2_name (die, cu);
12567 if (die_name != NULL
12568 && strcmp (die_name, actual_name) != 0)
12570 /* Strip off the class name from the full name.
12571 We want the prefix. */
12572 int die_name_len = strlen (die_name);
12573 int actual_name_len = strlen (actual_name);
12575 /* Test for '::' as a sanity check. */
12576 if (actual_name_len > die_name_len + 2
12577 && actual_name[actual_name_len
12578 - die_name_len - 1] == ':')
12580 obsavestring (actual_name,
12581 actual_name_len - die_name_len - 2,
12582 &cu->objfile->objfile_obstack);
12585 xfree (actual_name);
12594 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12595 prefix part in such case. See
12596 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12599 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12601 struct attribute *attr;
12604 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12605 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12608 attr = dwarf2_attr (die, DW_AT_name, cu);
12609 if (attr != NULL && DW_STRING (attr) != NULL)
12612 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12614 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12615 if (attr == NULL || DW_STRING (attr) == NULL)
12618 /* dwarf2_name had to be already called. */
12619 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12621 /* Strip the base name, keep any leading namespaces/classes. */
12622 base = strrchr (DW_STRING (attr), ':');
12623 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12626 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12627 &cu->objfile->objfile_obstack);
12630 /* Return the name of the namespace/class that DIE is defined within,
12631 or "" if we can't tell. The caller should not xfree the result.
12633 For example, if we're within the method foo() in the following
12643 then determine_prefix on foo's die will return "N::C". */
12646 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12648 struct die_info *parent, *spec_die;
12649 struct dwarf2_cu *spec_cu;
12650 struct type *parent_type;
12653 if (cu->language != language_cplus && cu->language != language_java
12654 && cu->language != language_fortran)
12657 retval = anonymous_struct_prefix (die, cu);
12661 /* We have to be careful in the presence of DW_AT_specification.
12662 For example, with GCC 3.4, given the code
12666 // Definition of N::foo.
12670 then we'll have a tree of DIEs like this:
12672 1: DW_TAG_compile_unit
12673 2: DW_TAG_namespace // N
12674 3: DW_TAG_subprogram // declaration of N::foo
12675 4: DW_TAG_subprogram // definition of N::foo
12676 DW_AT_specification // refers to die #3
12678 Thus, when processing die #4, we have to pretend that we're in
12679 the context of its DW_AT_specification, namely the contex of die
12682 spec_die = die_specification (die, &spec_cu);
12683 if (spec_die == NULL)
12684 parent = die->parent;
12687 parent = spec_die->parent;
12691 if (parent == NULL)
12693 else if (parent->building_fullname)
12696 const char *parent_name;
12698 /* It has been seen on RealView 2.2 built binaries,
12699 DW_TAG_template_type_param types actually _defined_ as
12700 children of the parent class:
12703 template class <class Enum> Class{};
12704 Class<enum E> class_e;
12706 1: DW_TAG_class_type (Class)
12707 2: DW_TAG_enumeration_type (E)
12708 3: DW_TAG_enumerator (enum1:0)
12709 3: DW_TAG_enumerator (enum2:1)
12711 2: DW_TAG_template_type_param
12712 DW_AT_type DW_FORM_ref_udata (E)
12714 Besides being broken debug info, it can put GDB into an
12715 infinite loop. Consider:
12717 When we're building the full name for Class<E>, we'll start
12718 at Class, and go look over its template type parameters,
12719 finding E. We'll then try to build the full name of E, and
12720 reach here. We're now trying to build the full name of E,
12721 and look over the parent DIE for containing scope. In the
12722 broken case, if we followed the parent DIE of E, we'd again
12723 find Class, and once again go look at its template type
12724 arguments, etc., etc. Simply don't consider such parent die
12725 as source-level parent of this die (it can't be, the language
12726 doesn't allow it), and break the loop here. */
12727 name = dwarf2_name (die, cu);
12728 parent_name = dwarf2_name (parent, cu);
12729 complaint (&symfile_complaints,
12730 _("template param type '%s' defined within parent '%s'"),
12731 name ? name : "<unknown>",
12732 parent_name ? parent_name : "<unknown>");
12736 switch (parent->tag)
12738 case DW_TAG_namespace:
12739 parent_type = read_type_die (parent, cu);
12740 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12741 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12742 Work around this problem here. */
12743 if (cu->language == language_cplus
12744 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12746 /* We give a name to even anonymous namespaces. */
12747 return TYPE_TAG_NAME (parent_type);
12748 case DW_TAG_class_type:
12749 case DW_TAG_interface_type:
12750 case DW_TAG_structure_type:
12751 case DW_TAG_union_type:
12752 case DW_TAG_module:
12753 parent_type = read_type_die (parent, cu);
12754 if (TYPE_TAG_NAME (parent_type) != NULL)
12755 return TYPE_TAG_NAME (parent_type);
12757 /* An anonymous structure is only allowed non-static data
12758 members; no typedefs, no member functions, et cetera.
12759 So it does not need a prefix. */
12761 case DW_TAG_compile_unit:
12762 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12763 if (cu->language == language_cplus
12764 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12765 && die->child != NULL
12766 && (die->tag == DW_TAG_class_type
12767 || die->tag == DW_TAG_structure_type
12768 || die->tag == DW_TAG_union_type))
12770 char *name = guess_full_die_structure_name (die, cu);
12776 return determine_prefix (parent, cu);
12780 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12781 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12782 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12783 an obconcat, otherwise allocate storage for the result. The CU argument is
12784 used to determine the language and hence, the appropriate separator. */
12786 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12789 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12790 int physname, struct dwarf2_cu *cu)
12792 const char *lead = "";
12795 if (suffix == NULL || suffix[0] == '\0'
12796 || prefix == NULL || prefix[0] == '\0')
12798 else if (cu->language == language_java)
12800 else if (cu->language == language_fortran && physname)
12802 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12803 DW_AT_MIPS_linkage_name is preferred and used instead. */
12811 if (prefix == NULL)
12813 if (suffix == NULL)
12819 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12821 strcpy (retval, lead);
12822 strcat (retval, prefix);
12823 strcat (retval, sep);
12824 strcat (retval, suffix);
12829 /* We have an obstack. */
12830 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12834 /* Return sibling of die, NULL if no sibling. */
12836 static struct die_info *
12837 sibling_die (struct die_info *die)
12839 return die->sibling;
12842 /* Get name of a die, return NULL if not found. */
12845 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12846 struct obstack *obstack)
12848 if (name && cu->language == language_cplus)
12850 char *canon_name = cp_canonicalize_string (name);
12852 if (canon_name != NULL)
12854 if (strcmp (canon_name, name) != 0)
12855 name = obsavestring (canon_name, strlen (canon_name),
12857 xfree (canon_name);
12864 /* Get name of a die, return NULL if not found. */
12867 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12869 struct attribute *attr;
12871 attr = dwarf2_attr (die, DW_AT_name, cu);
12872 if ((!attr || !DW_STRING (attr))
12873 && die->tag != DW_TAG_class_type
12874 && die->tag != DW_TAG_interface_type
12875 && die->tag != DW_TAG_structure_type
12876 && die->tag != DW_TAG_union_type)
12881 case DW_TAG_compile_unit:
12882 /* Compilation units have a DW_AT_name that is a filename, not
12883 a source language identifier. */
12884 case DW_TAG_enumeration_type:
12885 case DW_TAG_enumerator:
12886 /* These tags always have simple identifiers already; no need
12887 to canonicalize them. */
12888 return DW_STRING (attr);
12890 case DW_TAG_subprogram:
12891 /* Java constructors will all be named "<init>", so return
12892 the class name when we see this special case. */
12893 if (cu->language == language_java
12894 && DW_STRING (attr) != NULL
12895 && strcmp (DW_STRING (attr), "<init>") == 0)
12897 struct dwarf2_cu *spec_cu = cu;
12898 struct die_info *spec_die;
12900 /* GCJ will output '<init>' for Java constructor names.
12901 For this special case, return the name of the parent class. */
12903 /* GCJ may output suprogram DIEs with AT_specification set.
12904 If so, use the name of the specified DIE. */
12905 spec_die = die_specification (die, &spec_cu);
12906 if (spec_die != NULL)
12907 return dwarf2_name (spec_die, spec_cu);
12912 if (die->tag == DW_TAG_class_type)
12913 return dwarf2_name (die, cu);
12915 while (die->tag != DW_TAG_compile_unit);
12919 case DW_TAG_class_type:
12920 case DW_TAG_interface_type:
12921 case DW_TAG_structure_type:
12922 case DW_TAG_union_type:
12923 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12924 structures or unions. These were of the form "._%d" in GCC 4.1,
12925 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12926 and GCC 4.4. We work around this problem by ignoring these. */
12927 if (attr && DW_STRING (attr)
12928 && (strncmp (DW_STRING (attr), "._", 2) == 0
12929 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12932 /* GCC might emit a nameless typedef that has a linkage name. See
12933 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12934 if (!attr || DW_STRING (attr) == NULL)
12936 char *demangled = NULL;
12938 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12940 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12942 if (attr == NULL || DW_STRING (attr) == NULL)
12945 /* Avoid demangling DW_STRING (attr) the second time on a second
12946 call for the same DIE. */
12947 if (!DW_STRING_IS_CANONICAL (attr))
12948 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12954 /* FIXME: we already did this for the partial symbol... */
12955 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
12956 &cu->objfile->objfile_obstack);
12957 DW_STRING_IS_CANONICAL (attr) = 1;
12960 /* Strip any leading namespaces/classes, keep only the base name.
12961 DW_AT_name for named DIEs does not contain the prefixes. */
12962 base = strrchr (DW_STRING (attr), ':');
12963 if (base && base > DW_STRING (attr) && base[-1] == ':')
12966 return DW_STRING (attr);
12975 if (!DW_STRING_IS_CANONICAL (attr))
12978 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12979 &cu->objfile->objfile_obstack);
12980 DW_STRING_IS_CANONICAL (attr) = 1;
12982 return DW_STRING (attr);
12985 /* Return the die that this die in an extension of, or NULL if there
12986 is none. *EXT_CU is the CU containing DIE on input, and the CU
12987 containing the return value on output. */
12989 static struct die_info *
12990 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12992 struct attribute *attr;
12994 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12998 return follow_die_ref (die, attr, ext_cu);
13001 /* Convert a DIE tag into its string name. */
13004 dwarf_tag_name (unsigned tag)
13008 case DW_TAG_padding:
13009 return "DW_TAG_padding";
13010 case DW_TAG_array_type:
13011 return "DW_TAG_array_type";
13012 case DW_TAG_class_type:
13013 return "DW_TAG_class_type";
13014 case DW_TAG_entry_point:
13015 return "DW_TAG_entry_point";
13016 case DW_TAG_enumeration_type:
13017 return "DW_TAG_enumeration_type";
13018 case DW_TAG_formal_parameter:
13019 return "DW_TAG_formal_parameter";
13020 case DW_TAG_imported_declaration:
13021 return "DW_TAG_imported_declaration";
13023 return "DW_TAG_label";
13024 case DW_TAG_lexical_block:
13025 return "DW_TAG_lexical_block";
13026 case DW_TAG_member:
13027 return "DW_TAG_member";
13028 case DW_TAG_pointer_type:
13029 return "DW_TAG_pointer_type";
13030 case DW_TAG_reference_type:
13031 return "DW_TAG_reference_type";
13032 case DW_TAG_compile_unit:
13033 return "DW_TAG_compile_unit";
13034 case DW_TAG_string_type:
13035 return "DW_TAG_string_type";
13036 case DW_TAG_structure_type:
13037 return "DW_TAG_structure_type";
13038 case DW_TAG_subroutine_type:
13039 return "DW_TAG_subroutine_type";
13040 case DW_TAG_typedef:
13041 return "DW_TAG_typedef";
13042 case DW_TAG_union_type:
13043 return "DW_TAG_union_type";
13044 case DW_TAG_unspecified_parameters:
13045 return "DW_TAG_unspecified_parameters";
13046 case DW_TAG_variant:
13047 return "DW_TAG_variant";
13048 case DW_TAG_common_block:
13049 return "DW_TAG_common_block";
13050 case DW_TAG_common_inclusion:
13051 return "DW_TAG_common_inclusion";
13052 case DW_TAG_inheritance:
13053 return "DW_TAG_inheritance";
13054 case DW_TAG_inlined_subroutine:
13055 return "DW_TAG_inlined_subroutine";
13056 case DW_TAG_module:
13057 return "DW_TAG_module";
13058 case DW_TAG_ptr_to_member_type:
13059 return "DW_TAG_ptr_to_member_type";
13060 case DW_TAG_set_type:
13061 return "DW_TAG_set_type";
13062 case DW_TAG_subrange_type:
13063 return "DW_TAG_subrange_type";
13064 case DW_TAG_with_stmt:
13065 return "DW_TAG_with_stmt";
13066 case DW_TAG_access_declaration:
13067 return "DW_TAG_access_declaration";
13068 case DW_TAG_base_type:
13069 return "DW_TAG_base_type";
13070 case DW_TAG_catch_block:
13071 return "DW_TAG_catch_block";
13072 case DW_TAG_const_type:
13073 return "DW_TAG_const_type";
13074 case DW_TAG_constant:
13075 return "DW_TAG_constant";
13076 case DW_TAG_enumerator:
13077 return "DW_TAG_enumerator";
13078 case DW_TAG_file_type:
13079 return "DW_TAG_file_type";
13080 case DW_TAG_friend:
13081 return "DW_TAG_friend";
13082 case DW_TAG_namelist:
13083 return "DW_TAG_namelist";
13084 case DW_TAG_namelist_item:
13085 return "DW_TAG_namelist_item";
13086 case DW_TAG_packed_type:
13087 return "DW_TAG_packed_type";
13088 case DW_TAG_subprogram:
13089 return "DW_TAG_subprogram";
13090 case DW_TAG_template_type_param:
13091 return "DW_TAG_template_type_param";
13092 case DW_TAG_template_value_param:
13093 return "DW_TAG_template_value_param";
13094 case DW_TAG_thrown_type:
13095 return "DW_TAG_thrown_type";
13096 case DW_TAG_try_block:
13097 return "DW_TAG_try_block";
13098 case DW_TAG_variant_part:
13099 return "DW_TAG_variant_part";
13100 case DW_TAG_variable:
13101 return "DW_TAG_variable";
13102 case DW_TAG_volatile_type:
13103 return "DW_TAG_volatile_type";
13104 case DW_TAG_dwarf_procedure:
13105 return "DW_TAG_dwarf_procedure";
13106 case DW_TAG_restrict_type:
13107 return "DW_TAG_restrict_type";
13108 case DW_TAG_interface_type:
13109 return "DW_TAG_interface_type";
13110 case DW_TAG_namespace:
13111 return "DW_TAG_namespace";
13112 case DW_TAG_imported_module:
13113 return "DW_TAG_imported_module";
13114 case DW_TAG_unspecified_type:
13115 return "DW_TAG_unspecified_type";
13116 case DW_TAG_partial_unit:
13117 return "DW_TAG_partial_unit";
13118 case DW_TAG_imported_unit:
13119 return "DW_TAG_imported_unit";
13120 case DW_TAG_condition:
13121 return "DW_TAG_condition";
13122 case DW_TAG_shared_type:
13123 return "DW_TAG_shared_type";
13124 case DW_TAG_type_unit:
13125 return "DW_TAG_type_unit";
13126 case DW_TAG_MIPS_loop:
13127 return "DW_TAG_MIPS_loop";
13128 case DW_TAG_HP_array_descriptor:
13129 return "DW_TAG_HP_array_descriptor";
13130 case DW_TAG_format_label:
13131 return "DW_TAG_format_label";
13132 case DW_TAG_function_template:
13133 return "DW_TAG_function_template";
13134 case DW_TAG_class_template:
13135 return "DW_TAG_class_template";
13136 case DW_TAG_GNU_BINCL:
13137 return "DW_TAG_GNU_BINCL";
13138 case DW_TAG_GNU_EINCL:
13139 return "DW_TAG_GNU_EINCL";
13140 case DW_TAG_upc_shared_type:
13141 return "DW_TAG_upc_shared_type";
13142 case DW_TAG_upc_strict_type:
13143 return "DW_TAG_upc_strict_type";
13144 case DW_TAG_upc_relaxed_type:
13145 return "DW_TAG_upc_relaxed_type";
13146 case DW_TAG_PGI_kanji_type:
13147 return "DW_TAG_PGI_kanji_type";
13148 case DW_TAG_PGI_interface_block:
13149 return "DW_TAG_PGI_interface_block";
13150 case DW_TAG_GNU_call_site:
13151 return "DW_TAG_GNU_call_site";
13153 return "DW_TAG_<unknown>";
13157 /* Convert a DWARF attribute code into its string name. */
13160 dwarf_attr_name (unsigned attr)
13164 case DW_AT_sibling:
13165 return "DW_AT_sibling";
13166 case DW_AT_location:
13167 return "DW_AT_location";
13169 return "DW_AT_name";
13170 case DW_AT_ordering:
13171 return "DW_AT_ordering";
13172 case DW_AT_subscr_data:
13173 return "DW_AT_subscr_data";
13174 case DW_AT_byte_size:
13175 return "DW_AT_byte_size";
13176 case DW_AT_bit_offset:
13177 return "DW_AT_bit_offset";
13178 case DW_AT_bit_size:
13179 return "DW_AT_bit_size";
13180 case DW_AT_element_list:
13181 return "DW_AT_element_list";
13182 case DW_AT_stmt_list:
13183 return "DW_AT_stmt_list";
13185 return "DW_AT_low_pc";
13186 case DW_AT_high_pc:
13187 return "DW_AT_high_pc";
13188 case DW_AT_language:
13189 return "DW_AT_language";
13191 return "DW_AT_member";
13193 return "DW_AT_discr";
13194 case DW_AT_discr_value:
13195 return "DW_AT_discr_value";
13196 case DW_AT_visibility:
13197 return "DW_AT_visibility";
13199 return "DW_AT_import";
13200 case DW_AT_string_length:
13201 return "DW_AT_string_length";
13202 case DW_AT_common_reference:
13203 return "DW_AT_common_reference";
13204 case DW_AT_comp_dir:
13205 return "DW_AT_comp_dir";
13206 case DW_AT_const_value:
13207 return "DW_AT_const_value";
13208 case DW_AT_containing_type:
13209 return "DW_AT_containing_type";
13210 case DW_AT_default_value:
13211 return "DW_AT_default_value";
13213 return "DW_AT_inline";
13214 case DW_AT_is_optional:
13215 return "DW_AT_is_optional";
13216 case DW_AT_lower_bound:
13217 return "DW_AT_lower_bound";
13218 case DW_AT_producer:
13219 return "DW_AT_producer";
13220 case DW_AT_prototyped:
13221 return "DW_AT_prototyped";
13222 case DW_AT_return_addr:
13223 return "DW_AT_return_addr";
13224 case DW_AT_start_scope:
13225 return "DW_AT_start_scope";
13226 case DW_AT_bit_stride:
13227 return "DW_AT_bit_stride";
13228 case DW_AT_upper_bound:
13229 return "DW_AT_upper_bound";
13230 case DW_AT_abstract_origin:
13231 return "DW_AT_abstract_origin";
13232 case DW_AT_accessibility:
13233 return "DW_AT_accessibility";
13234 case DW_AT_address_class:
13235 return "DW_AT_address_class";
13236 case DW_AT_artificial:
13237 return "DW_AT_artificial";
13238 case DW_AT_base_types:
13239 return "DW_AT_base_types";
13240 case DW_AT_calling_convention:
13241 return "DW_AT_calling_convention";
13243 return "DW_AT_count";
13244 case DW_AT_data_member_location:
13245 return "DW_AT_data_member_location";
13246 case DW_AT_decl_column:
13247 return "DW_AT_decl_column";
13248 case DW_AT_decl_file:
13249 return "DW_AT_decl_file";
13250 case DW_AT_decl_line:
13251 return "DW_AT_decl_line";
13252 case DW_AT_declaration:
13253 return "DW_AT_declaration";
13254 case DW_AT_discr_list:
13255 return "DW_AT_discr_list";
13256 case DW_AT_encoding:
13257 return "DW_AT_encoding";
13258 case DW_AT_external:
13259 return "DW_AT_external";
13260 case DW_AT_frame_base:
13261 return "DW_AT_frame_base";
13263 return "DW_AT_friend";
13264 case DW_AT_identifier_case:
13265 return "DW_AT_identifier_case";
13266 case DW_AT_macro_info:
13267 return "DW_AT_macro_info";
13268 case DW_AT_namelist_items:
13269 return "DW_AT_namelist_items";
13270 case DW_AT_priority:
13271 return "DW_AT_priority";
13272 case DW_AT_segment:
13273 return "DW_AT_segment";
13274 case DW_AT_specification:
13275 return "DW_AT_specification";
13276 case DW_AT_static_link:
13277 return "DW_AT_static_link";
13279 return "DW_AT_type";
13280 case DW_AT_use_location:
13281 return "DW_AT_use_location";
13282 case DW_AT_variable_parameter:
13283 return "DW_AT_variable_parameter";
13284 case DW_AT_virtuality:
13285 return "DW_AT_virtuality";
13286 case DW_AT_vtable_elem_location:
13287 return "DW_AT_vtable_elem_location";
13288 /* DWARF 3 values. */
13289 case DW_AT_allocated:
13290 return "DW_AT_allocated";
13291 case DW_AT_associated:
13292 return "DW_AT_associated";
13293 case DW_AT_data_location:
13294 return "DW_AT_data_location";
13295 case DW_AT_byte_stride:
13296 return "DW_AT_byte_stride";
13297 case DW_AT_entry_pc:
13298 return "DW_AT_entry_pc";
13299 case DW_AT_use_UTF8:
13300 return "DW_AT_use_UTF8";
13301 case DW_AT_extension:
13302 return "DW_AT_extension";
13304 return "DW_AT_ranges";
13305 case DW_AT_trampoline:
13306 return "DW_AT_trampoline";
13307 case DW_AT_call_column:
13308 return "DW_AT_call_column";
13309 case DW_AT_call_file:
13310 return "DW_AT_call_file";
13311 case DW_AT_call_line:
13312 return "DW_AT_call_line";
13313 case DW_AT_description:
13314 return "DW_AT_description";
13315 case DW_AT_binary_scale:
13316 return "DW_AT_binary_scale";
13317 case DW_AT_decimal_scale:
13318 return "DW_AT_decimal_scale";
13320 return "DW_AT_small";
13321 case DW_AT_decimal_sign:
13322 return "DW_AT_decimal_sign";
13323 case DW_AT_digit_count:
13324 return "DW_AT_digit_count";
13325 case DW_AT_picture_string:
13326 return "DW_AT_picture_string";
13327 case DW_AT_mutable:
13328 return "DW_AT_mutable";
13329 case DW_AT_threads_scaled:
13330 return "DW_AT_threads_scaled";
13331 case DW_AT_explicit:
13332 return "DW_AT_explicit";
13333 case DW_AT_object_pointer:
13334 return "DW_AT_object_pointer";
13335 case DW_AT_endianity:
13336 return "DW_AT_endianity";
13337 case DW_AT_elemental:
13338 return "DW_AT_elemental";
13340 return "DW_AT_pure";
13341 case DW_AT_recursive:
13342 return "DW_AT_recursive";
13343 /* DWARF 4 values. */
13344 case DW_AT_signature:
13345 return "DW_AT_signature";
13346 case DW_AT_linkage_name:
13347 return "DW_AT_linkage_name";
13348 /* SGI/MIPS extensions. */
13349 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13350 case DW_AT_MIPS_fde:
13351 return "DW_AT_MIPS_fde";
13353 case DW_AT_MIPS_loop_begin:
13354 return "DW_AT_MIPS_loop_begin";
13355 case DW_AT_MIPS_tail_loop_begin:
13356 return "DW_AT_MIPS_tail_loop_begin";
13357 case DW_AT_MIPS_epilog_begin:
13358 return "DW_AT_MIPS_epilog_begin";
13359 case DW_AT_MIPS_loop_unroll_factor:
13360 return "DW_AT_MIPS_loop_unroll_factor";
13361 case DW_AT_MIPS_software_pipeline_depth:
13362 return "DW_AT_MIPS_software_pipeline_depth";
13363 case DW_AT_MIPS_linkage_name:
13364 return "DW_AT_MIPS_linkage_name";
13365 case DW_AT_MIPS_stride:
13366 return "DW_AT_MIPS_stride";
13367 case DW_AT_MIPS_abstract_name:
13368 return "DW_AT_MIPS_abstract_name";
13369 case DW_AT_MIPS_clone_origin:
13370 return "DW_AT_MIPS_clone_origin";
13371 case DW_AT_MIPS_has_inlines:
13372 return "DW_AT_MIPS_has_inlines";
13373 /* HP extensions. */
13374 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13375 case DW_AT_HP_block_index:
13376 return "DW_AT_HP_block_index";
13378 case DW_AT_HP_unmodifiable:
13379 return "DW_AT_HP_unmodifiable";
13380 case DW_AT_HP_actuals_stmt_list:
13381 return "DW_AT_HP_actuals_stmt_list";
13382 case DW_AT_HP_proc_per_section:
13383 return "DW_AT_HP_proc_per_section";
13384 case DW_AT_HP_raw_data_ptr:
13385 return "DW_AT_HP_raw_data_ptr";
13386 case DW_AT_HP_pass_by_reference:
13387 return "DW_AT_HP_pass_by_reference";
13388 case DW_AT_HP_opt_level:
13389 return "DW_AT_HP_opt_level";
13390 case DW_AT_HP_prof_version_id:
13391 return "DW_AT_HP_prof_version_id";
13392 case DW_AT_HP_opt_flags:
13393 return "DW_AT_HP_opt_flags";
13394 case DW_AT_HP_cold_region_low_pc:
13395 return "DW_AT_HP_cold_region_low_pc";
13396 case DW_AT_HP_cold_region_high_pc:
13397 return "DW_AT_HP_cold_region_high_pc";
13398 case DW_AT_HP_all_variables_modifiable:
13399 return "DW_AT_HP_all_variables_modifiable";
13400 case DW_AT_HP_linkage_name:
13401 return "DW_AT_HP_linkage_name";
13402 case DW_AT_HP_prof_flags:
13403 return "DW_AT_HP_prof_flags";
13404 /* GNU extensions. */
13405 case DW_AT_sf_names:
13406 return "DW_AT_sf_names";
13407 case DW_AT_src_info:
13408 return "DW_AT_src_info";
13409 case DW_AT_mac_info:
13410 return "DW_AT_mac_info";
13411 case DW_AT_src_coords:
13412 return "DW_AT_src_coords";
13413 case DW_AT_body_begin:
13414 return "DW_AT_body_begin";
13415 case DW_AT_body_end:
13416 return "DW_AT_body_end";
13417 case DW_AT_GNU_vector:
13418 return "DW_AT_GNU_vector";
13419 case DW_AT_GNU_odr_signature:
13420 return "DW_AT_GNU_odr_signature";
13421 /* VMS extensions. */
13422 case DW_AT_VMS_rtnbeg_pd_address:
13423 return "DW_AT_VMS_rtnbeg_pd_address";
13424 /* UPC extension. */
13425 case DW_AT_upc_threads_scaled:
13426 return "DW_AT_upc_threads_scaled";
13427 /* PGI (STMicroelectronics) extensions. */
13428 case DW_AT_PGI_lbase:
13429 return "DW_AT_PGI_lbase";
13430 case DW_AT_PGI_soffset:
13431 return "DW_AT_PGI_soffset";
13432 case DW_AT_PGI_lstride:
13433 return "DW_AT_PGI_lstride";
13435 return "DW_AT_<unknown>";
13439 /* Convert a DWARF value form code into its string name. */
13442 dwarf_form_name (unsigned form)
13447 return "DW_FORM_addr";
13448 case DW_FORM_block2:
13449 return "DW_FORM_block2";
13450 case DW_FORM_block4:
13451 return "DW_FORM_block4";
13452 case DW_FORM_data2:
13453 return "DW_FORM_data2";
13454 case DW_FORM_data4:
13455 return "DW_FORM_data4";
13456 case DW_FORM_data8:
13457 return "DW_FORM_data8";
13458 case DW_FORM_string:
13459 return "DW_FORM_string";
13460 case DW_FORM_block:
13461 return "DW_FORM_block";
13462 case DW_FORM_block1:
13463 return "DW_FORM_block1";
13464 case DW_FORM_data1:
13465 return "DW_FORM_data1";
13467 return "DW_FORM_flag";
13468 case DW_FORM_sdata:
13469 return "DW_FORM_sdata";
13471 return "DW_FORM_strp";
13472 case DW_FORM_udata:
13473 return "DW_FORM_udata";
13474 case DW_FORM_ref_addr:
13475 return "DW_FORM_ref_addr";
13477 return "DW_FORM_ref1";
13479 return "DW_FORM_ref2";
13481 return "DW_FORM_ref4";
13483 return "DW_FORM_ref8";
13484 case DW_FORM_ref_udata:
13485 return "DW_FORM_ref_udata";
13486 case DW_FORM_indirect:
13487 return "DW_FORM_indirect";
13488 case DW_FORM_sec_offset:
13489 return "DW_FORM_sec_offset";
13490 case DW_FORM_exprloc:
13491 return "DW_FORM_exprloc";
13492 case DW_FORM_flag_present:
13493 return "DW_FORM_flag_present";
13494 case DW_FORM_ref_sig8:
13495 return "DW_FORM_ref_sig8";
13497 return "DW_FORM_<unknown>";
13501 /* Convert a DWARF stack opcode into its string name. */
13504 dwarf_stack_op_name (unsigned op)
13509 return "DW_OP_addr";
13511 return "DW_OP_deref";
13512 case DW_OP_const1u:
13513 return "DW_OP_const1u";
13514 case DW_OP_const1s:
13515 return "DW_OP_const1s";
13516 case DW_OP_const2u:
13517 return "DW_OP_const2u";
13518 case DW_OP_const2s:
13519 return "DW_OP_const2s";
13520 case DW_OP_const4u:
13521 return "DW_OP_const4u";
13522 case DW_OP_const4s:
13523 return "DW_OP_const4s";
13524 case DW_OP_const8u:
13525 return "DW_OP_const8u";
13526 case DW_OP_const8s:
13527 return "DW_OP_const8s";
13529 return "DW_OP_constu";
13531 return "DW_OP_consts";
13533 return "DW_OP_dup";
13535 return "DW_OP_drop";
13537 return "DW_OP_over";
13539 return "DW_OP_pick";
13541 return "DW_OP_swap";
13543 return "DW_OP_rot";
13545 return "DW_OP_xderef";
13547 return "DW_OP_abs";
13549 return "DW_OP_and";
13551 return "DW_OP_div";
13553 return "DW_OP_minus";
13555 return "DW_OP_mod";
13557 return "DW_OP_mul";
13559 return "DW_OP_neg";
13561 return "DW_OP_not";
13565 return "DW_OP_plus";
13566 case DW_OP_plus_uconst:
13567 return "DW_OP_plus_uconst";
13569 return "DW_OP_shl";
13571 return "DW_OP_shr";
13573 return "DW_OP_shra";
13575 return "DW_OP_xor";
13577 return "DW_OP_bra";
13591 return "DW_OP_skip";
13593 return "DW_OP_lit0";
13595 return "DW_OP_lit1";
13597 return "DW_OP_lit2";
13599 return "DW_OP_lit3";
13601 return "DW_OP_lit4";
13603 return "DW_OP_lit5";
13605 return "DW_OP_lit6";
13607 return "DW_OP_lit7";
13609 return "DW_OP_lit8";
13611 return "DW_OP_lit9";
13613 return "DW_OP_lit10";
13615 return "DW_OP_lit11";
13617 return "DW_OP_lit12";
13619 return "DW_OP_lit13";
13621 return "DW_OP_lit14";
13623 return "DW_OP_lit15";
13625 return "DW_OP_lit16";
13627 return "DW_OP_lit17";
13629 return "DW_OP_lit18";
13631 return "DW_OP_lit19";
13633 return "DW_OP_lit20";
13635 return "DW_OP_lit21";
13637 return "DW_OP_lit22";
13639 return "DW_OP_lit23";
13641 return "DW_OP_lit24";
13643 return "DW_OP_lit25";
13645 return "DW_OP_lit26";
13647 return "DW_OP_lit27";
13649 return "DW_OP_lit28";
13651 return "DW_OP_lit29";
13653 return "DW_OP_lit30";
13655 return "DW_OP_lit31";
13657 return "DW_OP_reg0";
13659 return "DW_OP_reg1";
13661 return "DW_OP_reg2";
13663 return "DW_OP_reg3";
13665 return "DW_OP_reg4";
13667 return "DW_OP_reg5";
13669 return "DW_OP_reg6";
13671 return "DW_OP_reg7";
13673 return "DW_OP_reg8";
13675 return "DW_OP_reg9";
13677 return "DW_OP_reg10";
13679 return "DW_OP_reg11";
13681 return "DW_OP_reg12";
13683 return "DW_OP_reg13";
13685 return "DW_OP_reg14";
13687 return "DW_OP_reg15";
13689 return "DW_OP_reg16";
13691 return "DW_OP_reg17";
13693 return "DW_OP_reg18";
13695 return "DW_OP_reg19";
13697 return "DW_OP_reg20";
13699 return "DW_OP_reg21";
13701 return "DW_OP_reg22";
13703 return "DW_OP_reg23";
13705 return "DW_OP_reg24";
13707 return "DW_OP_reg25";
13709 return "DW_OP_reg26";
13711 return "DW_OP_reg27";
13713 return "DW_OP_reg28";
13715 return "DW_OP_reg29";
13717 return "DW_OP_reg30";
13719 return "DW_OP_reg31";
13721 return "DW_OP_breg0";
13723 return "DW_OP_breg1";
13725 return "DW_OP_breg2";
13727 return "DW_OP_breg3";
13729 return "DW_OP_breg4";
13731 return "DW_OP_breg5";
13733 return "DW_OP_breg6";
13735 return "DW_OP_breg7";
13737 return "DW_OP_breg8";
13739 return "DW_OP_breg9";
13741 return "DW_OP_breg10";
13743 return "DW_OP_breg11";
13745 return "DW_OP_breg12";
13747 return "DW_OP_breg13";
13749 return "DW_OP_breg14";
13751 return "DW_OP_breg15";
13753 return "DW_OP_breg16";
13755 return "DW_OP_breg17";
13757 return "DW_OP_breg18";
13759 return "DW_OP_breg19";
13761 return "DW_OP_breg20";
13763 return "DW_OP_breg21";
13765 return "DW_OP_breg22";
13767 return "DW_OP_breg23";
13769 return "DW_OP_breg24";
13771 return "DW_OP_breg25";
13773 return "DW_OP_breg26";
13775 return "DW_OP_breg27";
13777 return "DW_OP_breg28";
13779 return "DW_OP_breg29";
13781 return "DW_OP_breg30";
13783 return "DW_OP_breg31";
13785 return "DW_OP_regx";
13787 return "DW_OP_fbreg";
13789 return "DW_OP_bregx";
13791 return "DW_OP_piece";
13792 case DW_OP_deref_size:
13793 return "DW_OP_deref_size";
13794 case DW_OP_xderef_size:
13795 return "DW_OP_xderef_size";
13797 return "DW_OP_nop";
13798 /* DWARF 3 extensions. */
13799 case DW_OP_push_object_address:
13800 return "DW_OP_push_object_address";
13802 return "DW_OP_call2";
13804 return "DW_OP_call4";
13805 case DW_OP_call_ref:
13806 return "DW_OP_call_ref";
13807 case DW_OP_form_tls_address:
13808 return "DW_OP_form_tls_address";
13809 case DW_OP_call_frame_cfa:
13810 return "DW_OP_call_frame_cfa";
13811 case DW_OP_bit_piece:
13812 return "DW_OP_bit_piece";
13813 /* DWARF 4 extensions. */
13814 case DW_OP_implicit_value:
13815 return "DW_OP_implicit_value";
13816 case DW_OP_stack_value:
13817 return "DW_OP_stack_value";
13818 /* GNU extensions. */
13819 case DW_OP_GNU_push_tls_address:
13820 return "DW_OP_GNU_push_tls_address";
13821 case DW_OP_GNU_uninit:
13822 return "DW_OP_GNU_uninit";
13823 case DW_OP_GNU_implicit_pointer:
13824 return "DW_OP_GNU_implicit_pointer";
13825 case DW_OP_GNU_entry_value:
13826 return "DW_OP_GNU_entry_value";
13827 case DW_OP_GNU_const_type:
13828 return "DW_OP_GNU_const_type";
13829 case DW_OP_GNU_regval_type:
13830 return "DW_OP_GNU_regval_type";
13831 case DW_OP_GNU_deref_type:
13832 return "DW_OP_GNU_deref_type";
13833 case DW_OP_GNU_convert:
13834 return "DW_OP_GNU_convert";
13835 case DW_OP_GNU_reinterpret:
13836 return "DW_OP_GNU_reinterpret";
13843 dwarf_bool_name (unsigned mybool)
13851 /* Convert a DWARF type code into its string name. */
13854 dwarf_type_encoding_name (unsigned enc)
13859 return "DW_ATE_void";
13860 case DW_ATE_address:
13861 return "DW_ATE_address";
13862 case DW_ATE_boolean:
13863 return "DW_ATE_boolean";
13864 case DW_ATE_complex_float:
13865 return "DW_ATE_complex_float";
13867 return "DW_ATE_float";
13868 case DW_ATE_signed:
13869 return "DW_ATE_signed";
13870 case DW_ATE_signed_char:
13871 return "DW_ATE_signed_char";
13872 case DW_ATE_unsigned:
13873 return "DW_ATE_unsigned";
13874 case DW_ATE_unsigned_char:
13875 return "DW_ATE_unsigned_char";
13877 case DW_ATE_imaginary_float:
13878 return "DW_ATE_imaginary_float";
13879 case DW_ATE_packed_decimal:
13880 return "DW_ATE_packed_decimal";
13881 case DW_ATE_numeric_string:
13882 return "DW_ATE_numeric_string";
13883 case DW_ATE_edited:
13884 return "DW_ATE_edited";
13885 case DW_ATE_signed_fixed:
13886 return "DW_ATE_signed_fixed";
13887 case DW_ATE_unsigned_fixed:
13888 return "DW_ATE_unsigned_fixed";
13889 case DW_ATE_decimal_float:
13890 return "DW_ATE_decimal_float";
13893 return "DW_ATE_UTF";
13894 /* HP extensions. */
13895 case DW_ATE_HP_float80:
13896 return "DW_ATE_HP_float80";
13897 case DW_ATE_HP_complex_float80:
13898 return "DW_ATE_HP_complex_float80";
13899 case DW_ATE_HP_float128:
13900 return "DW_ATE_HP_float128";
13901 case DW_ATE_HP_complex_float128:
13902 return "DW_ATE_HP_complex_float128";
13903 case DW_ATE_HP_floathpintel:
13904 return "DW_ATE_HP_floathpintel";
13905 case DW_ATE_HP_imaginary_float80:
13906 return "DW_ATE_HP_imaginary_float80";
13907 case DW_ATE_HP_imaginary_float128:
13908 return "DW_ATE_HP_imaginary_float128";
13910 return "DW_ATE_<unknown>";
13914 /* Convert a DWARF call frame info operation to its string name. */
13918 dwarf_cfi_name (unsigned cfi_opc)
13922 case DW_CFA_advance_loc:
13923 return "DW_CFA_advance_loc";
13924 case DW_CFA_offset:
13925 return "DW_CFA_offset";
13926 case DW_CFA_restore:
13927 return "DW_CFA_restore";
13929 return "DW_CFA_nop";
13930 case DW_CFA_set_loc:
13931 return "DW_CFA_set_loc";
13932 case DW_CFA_advance_loc1:
13933 return "DW_CFA_advance_loc1";
13934 case DW_CFA_advance_loc2:
13935 return "DW_CFA_advance_loc2";
13936 case DW_CFA_advance_loc4:
13937 return "DW_CFA_advance_loc4";
13938 case DW_CFA_offset_extended:
13939 return "DW_CFA_offset_extended";
13940 case DW_CFA_restore_extended:
13941 return "DW_CFA_restore_extended";
13942 case DW_CFA_undefined:
13943 return "DW_CFA_undefined";
13944 case DW_CFA_same_value:
13945 return "DW_CFA_same_value";
13946 case DW_CFA_register:
13947 return "DW_CFA_register";
13948 case DW_CFA_remember_state:
13949 return "DW_CFA_remember_state";
13950 case DW_CFA_restore_state:
13951 return "DW_CFA_restore_state";
13952 case DW_CFA_def_cfa:
13953 return "DW_CFA_def_cfa";
13954 case DW_CFA_def_cfa_register:
13955 return "DW_CFA_def_cfa_register";
13956 case DW_CFA_def_cfa_offset:
13957 return "DW_CFA_def_cfa_offset";
13959 case DW_CFA_def_cfa_expression:
13960 return "DW_CFA_def_cfa_expression";
13961 case DW_CFA_expression:
13962 return "DW_CFA_expression";
13963 case DW_CFA_offset_extended_sf:
13964 return "DW_CFA_offset_extended_sf";
13965 case DW_CFA_def_cfa_sf:
13966 return "DW_CFA_def_cfa_sf";
13967 case DW_CFA_def_cfa_offset_sf:
13968 return "DW_CFA_def_cfa_offset_sf";
13969 case DW_CFA_val_offset:
13970 return "DW_CFA_val_offset";
13971 case DW_CFA_val_offset_sf:
13972 return "DW_CFA_val_offset_sf";
13973 case DW_CFA_val_expression:
13974 return "DW_CFA_val_expression";
13975 /* SGI/MIPS specific. */
13976 case DW_CFA_MIPS_advance_loc8:
13977 return "DW_CFA_MIPS_advance_loc8";
13978 /* GNU extensions. */
13979 case DW_CFA_GNU_window_save:
13980 return "DW_CFA_GNU_window_save";
13981 case DW_CFA_GNU_args_size:
13982 return "DW_CFA_GNU_args_size";
13983 case DW_CFA_GNU_negative_offset_extended:
13984 return "DW_CFA_GNU_negative_offset_extended";
13986 return "DW_CFA_<unknown>";
13992 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13996 print_spaces (indent, f);
13997 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13998 dwarf_tag_name (die->tag), die->abbrev, die->offset);
14000 if (die->parent != NULL)
14002 print_spaces (indent, f);
14003 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
14004 die->parent->offset);
14007 print_spaces (indent, f);
14008 fprintf_unfiltered (f, " has children: %s\n",
14009 dwarf_bool_name (die->child != NULL));
14011 print_spaces (indent, f);
14012 fprintf_unfiltered (f, " attributes:\n");
14014 for (i = 0; i < die->num_attrs; ++i)
14016 print_spaces (indent, f);
14017 fprintf_unfiltered (f, " %s (%s) ",
14018 dwarf_attr_name (die->attrs[i].name),
14019 dwarf_form_name (die->attrs[i].form));
14021 switch (die->attrs[i].form)
14023 case DW_FORM_ref_addr:
14025 fprintf_unfiltered (f, "address: ");
14026 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
14028 case DW_FORM_block2:
14029 case DW_FORM_block4:
14030 case DW_FORM_block:
14031 case DW_FORM_block1:
14032 fprintf_unfiltered (f, "block: size %d",
14033 DW_BLOCK (&die->attrs[i])->size);
14035 case DW_FORM_exprloc:
14036 fprintf_unfiltered (f, "expression: size %u",
14037 DW_BLOCK (&die->attrs[i])->size);
14042 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
14043 (long) (DW_ADDR (&die->attrs[i])));
14045 case DW_FORM_data1:
14046 case DW_FORM_data2:
14047 case DW_FORM_data4:
14048 case DW_FORM_data8:
14049 case DW_FORM_udata:
14050 case DW_FORM_sdata:
14051 fprintf_unfiltered (f, "constant: %s",
14052 pulongest (DW_UNSND (&die->attrs[i])));
14054 case DW_FORM_sec_offset:
14055 fprintf_unfiltered (f, "section offset: %s",
14056 pulongest (DW_UNSND (&die->attrs[i])));
14058 case DW_FORM_ref_sig8:
14059 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
14060 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
14061 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
14063 fprintf_unfiltered (f, "signatured type, offset: unknown");
14065 case DW_FORM_string:
14067 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
14068 DW_STRING (&die->attrs[i])
14069 ? DW_STRING (&die->attrs[i]) : "",
14070 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
14073 if (DW_UNSND (&die->attrs[i]))
14074 fprintf_unfiltered (f, "flag: TRUE");
14076 fprintf_unfiltered (f, "flag: FALSE");
14078 case DW_FORM_flag_present:
14079 fprintf_unfiltered (f, "flag: TRUE");
14081 case DW_FORM_indirect:
14082 /* The reader will have reduced the indirect form to
14083 the "base form" so this form should not occur. */
14084 fprintf_unfiltered (f,
14085 "unexpected attribute form: DW_FORM_indirect");
14088 fprintf_unfiltered (f, "unsupported attribute form: %d.",
14089 die->attrs[i].form);
14092 fprintf_unfiltered (f, "\n");
14097 dump_die_for_error (struct die_info *die)
14099 dump_die_shallow (gdb_stderr, 0, die);
14103 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
14105 int indent = level * 4;
14107 gdb_assert (die != NULL);
14109 if (level >= max_level)
14112 dump_die_shallow (f, indent, die);
14114 if (die->child != NULL)
14116 print_spaces (indent, f);
14117 fprintf_unfiltered (f, " Children:");
14118 if (level + 1 < max_level)
14120 fprintf_unfiltered (f, "\n");
14121 dump_die_1 (f, level + 1, max_level, die->child);
14125 fprintf_unfiltered (f,
14126 " [not printed, max nesting level reached]\n");
14130 if (die->sibling != NULL && level > 0)
14132 dump_die_1 (f, level, max_level, die->sibling);
14136 /* This is called from the pdie macro in gdbinit.in.
14137 It's not static so gcc will keep a copy callable from gdb. */
14140 dump_die (struct die_info *die, int max_level)
14142 dump_die_1 (gdb_stdlog, 0, max_level, die);
14146 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
14150 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
14156 is_ref_attr (struct attribute *attr)
14158 switch (attr->form)
14160 case DW_FORM_ref_addr:
14165 case DW_FORM_ref_udata:
14172 static unsigned int
14173 dwarf2_get_ref_die_offset (struct attribute *attr)
14175 if (is_ref_attr (attr))
14176 return DW_ADDR (attr);
14178 complaint (&symfile_complaints,
14179 _("unsupported die ref attribute form: '%s'"),
14180 dwarf_form_name (attr->form));
14184 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14185 * the value held by the attribute is not constant. */
14188 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
14190 if (attr->form == DW_FORM_sdata)
14191 return DW_SND (attr);
14192 else if (attr->form == DW_FORM_udata
14193 || attr->form == DW_FORM_data1
14194 || attr->form == DW_FORM_data2
14195 || attr->form == DW_FORM_data4
14196 || attr->form == DW_FORM_data8)
14197 return DW_UNSND (attr);
14200 complaint (&symfile_complaints,
14201 _("Attribute value is not a constant (%s)"),
14202 dwarf_form_name (attr->form));
14203 return default_value;
14207 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14208 unit and add it to our queue.
14209 The result is non-zero if PER_CU was queued, otherwise the result is zero
14210 meaning either PER_CU is already queued or it is already loaded. */
14213 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
14214 struct dwarf2_per_cu_data *per_cu)
14216 /* We may arrive here during partial symbol reading, if we need full
14217 DIEs to process an unusual case (e.g. template arguments). Do
14218 not queue PER_CU, just tell our caller to load its DIEs. */
14219 if (dwarf2_per_objfile->reading_partial_symbols)
14221 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
14226 /* Mark the dependence relation so that we don't flush PER_CU
14228 dwarf2_add_dependence (this_cu, per_cu);
14230 /* If it's already on the queue, we have nothing to do. */
14231 if (per_cu->queued)
14234 /* If the compilation unit is already loaded, just mark it as
14236 if (per_cu->cu != NULL)
14238 per_cu->cu->last_used = 0;
14242 /* Add it to the queue. */
14243 queue_comp_unit (per_cu, this_cu->objfile);
14248 /* Follow reference or signature attribute ATTR of SRC_DIE.
14249 On entry *REF_CU is the CU of SRC_DIE.
14250 On exit *REF_CU is the CU of the result. */
14252 static struct die_info *
14253 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
14254 struct dwarf2_cu **ref_cu)
14256 struct die_info *die;
14258 if (is_ref_attr (attr))
14259 die = follow_die_ref (src_die, attr, ref_cu);
14260 else if (attr->form == DW_FORM_ref_sig8)
14261 die = follow_die_sig (src_die, attr, ref_cu);
14264 dump_die_for_error (src_die);
14265 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14266 (*ref_cu)->objfile->name);
14272 /* Follow reference OFFSET.
14273 On entry *REF_CU is the CU of the source die referencing OFFSET.
14274 On exit *REF_CU is the CU of the result.
14275 Returns NULL if OFFSET is invalid. */
14277 static struct die_info *
14278 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
14280 struct die_info temp_die;
14281 struct dwarf2_cu *target_cu, *cu = *ref_cu;
14283 gdb_assert (cu->per_cu != NULL);
14287 if (cu->per_cu->debug_types_section)
14289 /* .debug_types CUs cannot reference anything outside their CU.
14290 If they need to, they have to reference a signatured type via
14291 DW_FORM_ref_sig8. */
14292 if (! offset_in_cu_p (&cu->header, offset))
14295 else if (! offset_in_cu_p (&cu->header, offset))
14297 struct dwarf2_per_cu_data *per_cu;
14299 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
14301 /* If necessary, add it to the queue and load its DIEs. */
14302 if (maybe_queue_comp_unit (cu, per_cu))
14303 load_full_comp_unit (per_cu, cu->objfile);
14305 target_cu = per_cu->cu;
14307 else if (cu->dies == NULL)
14309 /* We're loading full DIEs during partial symbol reading. */
14310 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
14311 load_full_comp_unit (cu->per_cu, cu->objfile);
14314 *ref_cu = target_cu;
14315 temp_die.offset = offset;
14316 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
14319 /* Follow reference attribute ATTR of SRC_DIE.
14320 On entry *REF_CU is the CU of SRC_DIE.
14321 On exit *REF_CU is the CU of the result. */
14323 static struct die_info *
14324 follow_die_ref (struct die_info *src_die, struct attribute *attr,
14325 struct dwarf2_cu **ref_cu)
14327 unsigned int offset = dwarf2_get_ref_die_offset (attr);
14328 struct dwarf2_cu *cu = *ref_cu;
14329 struct die_info *die;
14331 die = follow_die_offset (offset, ref_cu);
14333 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14334 "at 0x%x [in module %s]"),
14335 offset, src_die->offset, cu->objfile->name);
14340 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14341 Returned value is intended for DW_OP_call*. Returned
14342 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14344 struct dwarf2_locexpr_baton
14345 dwarf2_fetch_die_location_block (unsigned int offset,
14346 struct dwarf2_per_cu_data *per_cu,
14347 CORE_ADDR (*get_frame_pc) (void *baton),
14350 struct dwarf2_cu *cu;
14351 struct die_info *die;
14352 struct attribute *attr;
14353 struct dwarf2_locexpr_baton retval;
14355 dw2_setup (per_cu->objfile);
14357 if (per_cu->cu == NULL)
14361 die = follow_die_offset (offset, &cu);
14363 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14364 offset, per_cu->cu->objfile->name);
14366 attr = dwarf2_attr (die, DW_AT_location, cu);
14369 /* DWARF: "If there is no such attribute, then there is no effect.".
14370 DATA is ignored if SIZE is 0. */
14372 retval.data = NULL;
14375 else if (attr_form_is_section_offset (attr))
14377 struct dwarf2_loclist_baton loclist_baton;
14378 CORE_ADDR pc = (*get_frame_pc) (baton);
14381 fill_in_loclist_baton (cu, &loclist_baton, attr);
14383 retval.data = dwarf2_find_location_expression (&loclist_baton,
14385 retval.size = size;
14389 if (!attr_form_is_block (attr))
14390 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14391 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14392 offset, per_cu->cu->objfile->name);
14394 retval.data = DW_BLOCK (attr)->data;
14395 retval.size = DW_BLOCK (attr)->size;
14397 retval.per_cu = cu->per_cu;
14399 age_cached_comp_units ();
14404 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14408 dwarf2_get_die_type (unsigned int die_offset,
14409 struct dwarf2_per_cu_data *per_cu)
14411 dw2_setup (per_cu->objfile);
14412 return get_die_type_at_offset (die_offset, per_cu);
14415 /* Follow the signature attribute ATTR in SRC_DIE.
14416 On entry *REF_CU is the CU of SRC_DIE.
14417 On exit *REF_CU is the CU of the result. */
14419 static struct die_info *
14420 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14421 struct dwarf2_cu **ref_cu)
14423 struct objfile *objfile = (*ref_cu)->objfile;
14424 struct die_info temp_die;
14425 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14426 struct dwarf2_cu *sig_cu;
14427 struct die_info *die;
14429 /* sig_type will be NULL if the signatured type is missing from
14431 if (sig_type == NULL)
14432 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14433 "at 0x%x [in module %s]"),
14434 src_die->offset, objfile->name);
14436 /* If necessary, add it to the queue and load its DIEs. */
14438 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14439 read_signatured_type (objfile, sig_type);
14441 gdb_assert (sig_type->per_cu.cu != NULL);
14443 sig_cu = sig_type->per_cu.cu;
14444 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
14445 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
14452 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14453 "from DIE at 0x%x [in module %s]"),
14454 sig_type->type_offset, src_die->offset, objfile->name);
14457 /* Given an offset of a signatured type, return its signatured_type. */
14459 static struct signatured_type *
14460 lookup_signatured_type_at_offset (struct objfile *objfile,
14461 struct dwarf2_section_info *section,
14462 unsigned int offset)
14464 gdb_byte *info_ptr = section->buffer + offset;
14465 unsigned int length, initial_length_size;
14466 unsigned int sig_offset;
14467 struct signatured_type find_entry, *type_sig;
14469 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14470 sig_offset = (initial_length_size
14472 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14473 + 1 /*address_size*/);
14474 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14475 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14477 /* This is only used to lookup previously recorded types.
14478 If we didn't find it, it's our bug. */
14479 gdb_assert (type_sig != NULL);
14480 gdb_assert (offset == type_sig->per_cu.offset);
14485 /* Read in signatured type at OFFSET and build its CU and die(s). */
14488 read_signatured_type_at_offset (struct objfile *objfile,
14489 struct dwarf2_section_info *sect,
14490 unsigned int offset)
14492 struct signatured_type *type_sig;
14494 dwarf2_read_section (objfile, sect);
14496 /* We have the section offset, but we need the signature to do the
14497 hash table lookup. */
14498 type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
14500 gdb_assert (type_sig->per_cu.cu == NULL);
14502 read_signatured_type (objfile, type_sig);
14504 gdb_assert (type_sig->per_cu.cu != NULL);
14507 /* Read in a signatured type and build its CU and DIEs. */
14510 read_signatured_type (struct objfile *objfile,
14511 struct signatured_type *type_sig)
14513 gdb_byte *types_ptr;
14514 struct die_reader_specs reader_specs;
14515 struct dwarf2_cu *cu;
14516 ULONGEST signature;
14517 struct cleanup *back_to, *free_cu_cleanup;
14518 struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section;
14520 dwarf2_read_section (objfile, section);
14521 types_ptr = section->buffer + type_sig->per_cu.offset;
14523 gdb_assert (type_sig->per_cu.cu == NULL);
14525 cu = xmalloc (sizeof (*cu));
14526 init_one_comp_unit (cu, objfile);
14528 type_sig->per_cu.cu = cu;
14529 cu->per_cu = &type_sig->per_cu;
14531 /* If an error occurs while loading, release our storage. */
14532 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
14534 types_ptr = read_type_comp_unit_head (&cu->header, section, &signature,
14535 types_ptr, objfile->obfd);
14536 gdb_assert (signature == type_sig->signature);
14539 = htab_create_alloc_ex (cu->header.length / 12,
14543 &cu->comp_unit_obstack,
14544 hashtab_obstack_allocate,
14545 dummy_obstack_deallocate);
14547 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
14548 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14550 init_cu_die_reader (&reader_specs, cu);
14552 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14555 /* We try not to read any attributes in this function, because not
14556 all objfiles needed for references have been loaded yet, and symbol
14557 table processing isn't initialized. But we have to set the CU language,
14558 or we won't be able to build types correctly. */
14559 prepare_one_comp_unit (cu, cu->dies);
14561 do_cleanups (back_to);
14563 /* We've successfully allocated this compilation unit. Let our caller
14564 clean it up when finished with it. */
14565 discard_cleanups (free_cu_cleanup);
14567 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14568 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
14571 /* Decode simple location descriptions.
14572 Given a pointer to a dwarf block that defines a location, compute
14573 the location and return the value.
14575 NOTE drow/2003-11-18: This function is called in two situations
14576 now: for the address of static or global variables (partial symbols
14577 only) and for offsets into structures which are expected to be
14578 (more or less) constant. The partial symbol case should go away,
14579 and only the constant case should remain. That will let this
14580 function complain more accurately. A few special modes are allowed
14581 without complaint for global variables (for instance, global
14582 register values and thread-local values).
14584 A location description containing no operations indicates that the
14585 object is optimized out. The return value is 0 for that case.
14586 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14587 callers will only want a very basic result and this can become a
14590 Note that stack[0] is unused except as a default error return. */
14593 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14595 struct objfile *objfile = cu->objfile;
14597 int size = blk->size;
14598 gdb_byte *data = blk->data;
14599 CORE_ADDR stack[64];
14601 unsigned int bytes_read, unsnd;
14607 stack[++stacki] = 0;
14646 stack[++stacki] = op - DW_OP_lit0;
14681 stack[++stacki] = op - DW_OP_reg0;
14683 dwarf2_complex_location_expr_complaint ();
14687 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
14689 stack[++stacki] = unsnd;
14691 dwarf2_complex_location_expr_complaint ();
14695 stack[++stacki] = read_address (objfile->obfd, &data[i],
14700 case DW_OP_const1u:
14701 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
14705 case DW_OP_const1s:
14706 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
14710 case DW_OP_const2u:
14711 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
14715 case DW_OP_const2s:
14716 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
14720 case DW_OP_const4u:
14721 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
14725 case DW_OP_const4s:
14726 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
14730 case DW_OP_const8u:
14731 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
14736 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
14742 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
14747 stack[stacki + 1] = stack[stacki];
14752 stack[stacki - 1] += stack[stacki];
14756 case DW_OP_plus_uconst:
14757 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
14763 stack[stacki - 1] -= stack[stacki];
14768 /* If we're not the last op, then we definitely can't encode
14769 this using GDB's address_class enum. This is valid for partial
14770 global symbols, although the variable's address will be bogus
14773 dwarf2_complex_location_expr_complaint ();
14776 case DW_OP_GNU_push_tls_address:
14777 /* The top of the stack has the offset from the beginning
14778 of the thread control block at which the variable is located. */
14779 /* Nothing should follow this operator, so the top of stack would
14781 /* This is valid for partial global symbols, but the variable's
14782 address will be bogus in the psymtab. Make it always at least
14783 non-zero to not look as a variable garbage collected by linker
14784 which have DW_OP_addr 0. */
14786 dwarf2_complex_location_expr_complaint ();
14790 case DW_OP_GNU_uninit:
14795 const char *name = dwarf_stack_op_name (op);
14798 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
14801 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
14805 return (stack[stacki]);
14808 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14809 outside of the allocated space. Also enforce minimum>0. */
14810 if (stacki >= ARRAY_SIZE (stack) - 1)
14812 complaint (&symfile_complaints,
14813 _("location description stack overflow"));
14819 complaint (&symfile_complaints,
14820 _("location description stack underflow"));
14824 return (stack[stacki]);
14827 /* memory allocation interface */
14829 static struct dwarf_block *
14830 dwarf_alloc_block (struct dwarf2_cu *cu)
14832 struct dwarf_block *blk;
14834 blk = (struct dwarf_block *)
14835 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14839 static struct abbrev_info *
14840 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14842 struct abbrev_info *abbrev;
14844 abbrev = (struct abbrev_info *)
14845 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14846 memset (abbrev, 0, sizeof (struct abbrev_info));
14850 static struct die_info *
14851 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14853 struct die_info *die;
14854 size_t size = sizeof (struct die_info);
14857 size += (num_attrs - 1) * sizeof (struct attribute);
14859 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14860 memset (die, 0, sizeof (struct die_info));
14865 /* Macro support. */
14867 /* Return the full name of file number I in *LH's file name table.
14868 Use COMP_DIR as the name of the current directory of the
14869 compilation. The result is allocated using xmalloc; the caller is
14870 responsible for freeing it. */
14872 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14874 /* Is the file number a valid index into the line header's file name
14875 table? Remember that file numbers start with one, not zero. */
14876 if (1 <= file && file <= lh->num_file_names)
14878 struct file_entry *fe = &lh->file_names[file - 1];
14880 if (IS_ABSOLUTE_PATH (fe->name))
14881 return xstrdup (fe->name);
14889 dir = lh->include_dirs[fe->dir_index - 1];
14895 dir_len = strlen (dir);
14896 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14897 strcpy (full_name, dir);
14898 full_name[dir_len] = '/';
14899 strcpy (full_name + dir_len + 1, fe->name);
14903 return xstrdup (fe->name);
14908 /* The compiler produced a bogus file number. We can at least
14909 record the macro definitions made in the file, even if we
14910 won't be able to find the file by name. */
14911 char fake_name[80];
14913 sprintf (fake_name, "<bad macro file number %d>", file);
14915 complaint (&symfile_complaints,
14916 _("bad file number in macro information (%d)"),
14919 return xstrdup (fake_name);
14924 static struct macro_source_file *
14925 macro_start_file (int file, int line,
14926 struct macro_source_file *current_file,
14927 const char *comp_dir,
14928 struct line_header *lh, struct objfile *objfile)
14930 /* The full name of this source file. */
14931 char *full_name = file_full_name (file, lh, comp_dir);
14933 /* We don't create a macro table for this compilation unit
14934 at all until we actually get a filename. */
14935 if (! pending_macros)
14936 pending_macros = new_macro_table (&objfile->objfile_obstack,
14937 objfile->macro_cache);
14939 if (! current_file)
14940 /* If we have no current file, then this must be the start_file
14941 directive for the compilation unit's main source file. */
14942 current_file = macro_set_main (pending_macros, full_name);
14944 current_file = macro_include (current_file, line, full_name);
14948 return current_file;
14952 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14953 followed by a null byte. */
14955 copy_string (const char *buf, int len)
14957 char *s = xmalloc (len + 1);
14959 memcpy (s, buf, len);
14965 static const char *
14966 consume_improper_spaces (const char *p, const char *body)
14970 complaint (&symfile_complaints,
14971 _("macro definition contains spaces "
14972 "in formal argument list:\n`%s'"),
14984 parse_macro_definition (struct macro_source_file *file, int line,
14989 /* The body string takes one of two forms. For object-like macro
14990 definitions, it should be:
14992 <macro name> " " <definition>
14994 For function-like macro definitions, it should be:
14996 <macro name> "() " <definition>
14998 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15000 Spaces may appear only where explicitly indicated, and in the
15003 The Dwarf 2 spec says that an object-like macro's name is always
15004 followed by a space, but versions of GCC around March 2002 omit
15005 the space when the macro's definition is the empty string.
15007 The Dwarf 2 spec says that there should be no spaces between the
15008 formal arguments in a function-like macro's formal argument list,
15009 but versions of GCC around March 2002 include spaces after the
15013 /* Find the extent of the macro name. The macro name is terminated
15014 by either a space or null character (for an object-like macro) or
15015 an opening paren (for a function-like macro). */
15016 for (p = body; *p; p++)
15017 if (*p == ' ' || *p == '(')
15020 if (*p == ' ' || *p == '\0')
15022 /* It's an object-like macro. */
15023 int name_len = p - body;
15024 char *name = copy_string (body, name_len);
15025 const char *replacement;
15028 replacement = body + name_len + 1;
15031 dwarf2_macro_malformed_definition_complaint (body);
15032 replacement = body + name_len;
15035 macro_define_object (file, line, name, replacement);
15039 else if (*p == '(')
15041 /* It's a function-like macro. */
15042 char *name = copy_string (body, p - body);
15045 char **argv = xmalloc (argv_size * sizeof (*argv));
15049 p = consume_improper_spaces (p, body);
15051 /* Parse the formal argument list. */
15052 while (*p && *p != ')')
15054 /* Find the extent of the current argument name. */
15055 const char *arg_start = p;
15057 while (*p && *p != ',' && *p != ')' && *p != ' ')
15060 if (! *p || p == arg_start)
15061 dwarf2_macro_malformed_definition_complaint (body);
15064 /* Make sure argv has room for the new argument. */
15065 if (argc >= argv_size)
15068 argv = xrealloc (argv, argv_size * sizeof (*argv));
15071 argv[argc++] = copy_string (arg_start, p - arg_start);
15074 p = consume_improper_spaces (p, body);
15076 /* Consume the comma, if present. */
15081 p = consume_improper_spaces (p, body);
15090 /* Perfectly formed definition, no complaints. */
15091 macro_define_function (file, line, name,
15092 argc, (const char **) argv,
15094 else if (*p == '\0')
15096 /* Complain, but do define it. */
15097 dwarf2_macro_malformed_definition_complaint (body);
15098 macro_define_function (file, line, name,
15099 argc, (const char **) argv,
15103 /* Just complain. */
15104 dwarf2_macro_malformed_definition_complaint (body);
15107 /* Just complain. */
15108 dwarf2_macro_malformed_definition_complaint (body);
15114 for (i = 0; i < argc; i++)
15120 dwarf2_macro_malformed_definition_complaint (body);
15123 /* Skip some bytes from BYTES according to the form given in FORM.
15124 Returns the new pointer. */
15127 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
15128 enum dwarf_form form,
15129 unsigned int offset_size,
15130 struct dwarf2_section_info *section)
15132 unsigned int bytes_read;
15136 case DW_FORM_data1:
15141 case DW_FORM_data2:
15145 case DW_FORM_data4:
15149 case DW_FORM_data8:
15153 case DW_FORM_string:
15154 read_direct_string (abfd, bytes, &bytes_read);
15155 bytes += bytes_read;
15158 case DW_FORM_sec_offset:
15160 bytes += offset_size;
15163 case DW_FORM_block:
15164 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
15165 bytes += bytes_read;
15168 case DW_FORM_block1:
15169 bytes += 1 + read_1_byte (abfd, bytes);
15171 case DW_FORM_block2:
15172 bytes += 2 + read_2_bytes (abfd, bytes);
15174 case DW_FORM_block4:
15175 bytes += 4 + read_4_bytes (abfd, bytes);
15178 case DW_FORM_sdata:
15179 case DW_FORM_udata:
15180 bytes = skip_leb128 (abfd, bytes);
15186 complaint (&symfile_complaints,
15187 _("invalid form 0x%x in `%s'"),
15189 section->asection->name);
15197 /* A helper for dwarf_decode_macros that handles skipping an unknown
15198 opcode. Returns an updated pointer to the macro data buffer; or,
15199 on error, issues a complaint and returns NULL. */
15202 skip_unknown_opcode (unsigned int opcode,
15203 gdb_byte **opcode_definitions,
15206 unsigned int offset_size,
15207 struct dwarf2_section_info *section)
15209 unsigned int bytes_read, i;
15213 if (opcode_definitions[opcode] == NULL)
15215 complaint (&symfile_complaints,
15216 _("unrecognized DW_MACFINO opcode 0x%x"),
15221 defn = opcode_definitions[opcode];
15222 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
15223 defn += bytes_read;
15225 for (i = 0; i < arg; ++i)
15227 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
15228 if (mac_ptr == NULL)
15230 /* skip_form_bytes already issued the complaint. */
15238 /* A helper function which parses the header of a macro section.
15239 If the macro section is the extended (for now called "GNU") type,
15240 then this updates *OFFSET_SIZE. Returns a pointer to just after
15241 the header, or issues a complaint and returns NULL on error. */
15244 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
15247 unsigned int *offset_size,
15248 int section_is_gnu)
15250 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
15252 if (section_is_gnu)
15254 unsigned int version, flags;
15256 version = read_2_bytes (abfd, mac_ptr);
15259 complaint (&symfile_complaints,
15260 _("unrecognized version `%d' in .debug_macro section"),
15266 flags = read_1_byte (abfd, mac_ptr);
15268 *offset_size = (flags & 1) ? 8 : 4;
15270 if ((flags & 2) != 0)
15271 /* We don't need the line table offset. */
15272 mac_ptr += *offset_size;
15274 /* Vendor opcode descriptions. */
15275 if ((flags & 4) != 0)
15277 unsigned int i, count;
15279 count = read_1_byte (abfd, mac_ptr);
15281 for (i = 0; i < count; ++i)
15283 unsigned int opcode, bytes_read;
15286 opcode = read_1_byte (abfd, mac_ptr);
15288 opcode_definitions[opcode] = mac_ptr;
15289 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15290 mac_ptr += bytes_read;
15299 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15300 including DW_GNU_MACINFO_transparent_include. */
15303 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
15304 struct macro_source_file *current_file,
15305 struct line_header *lh, char *comp_dir,
15306 struct dwarf2_section_info *section,
15307 int section_is_gnu,
15308 unsigned int offset_size,
15309 struct objfile *objfile)
15311 enum dwarf_macro_record_type macinfo_type;
15312 int at_commandline;
15313 gdb_byte *opcode_definitions[256];
15315 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15316 &offset_size, section_is_gnu);
15317 if (mac_ptr == NULL)
15319 /* We already issued a complaint. */
15323 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15324 GDB is still reading the definitions from command line. First
15325 DW_MACINFO_start_file will need to be ignored as it was already executed
15326 to create CURRENT_FILE for the main source holding also the command line
15327 definitions. On first met DW_MACINFO_start_file this flag is reset to
15328 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15330 at_commandline = 1;
15334 /* Do we at least have room for a macinfo type byte? */
15335 if (mac_ptr >= mac_end)
15337 dwarf2_macros_too_long_complaint (section);
15341 macinfo_type = read_1_byte (abfd, mac_ptr);
15344 /* Note that we rely on the fact that the corresponding GNU and
15345 DWARF constants are the same. */
15346 switch (macinfo_type)
15348 /* A zero macinfo type indicates the end of the macro
15353 case DW_MACRO_GNU_define:
15354 case DW_MACRO_GNU_undef:
15355 case DW_MACRO_GNU_define_indirect:
15356 case DW_MACRO_GNU_undef_indirect:
15358 unsigned int bytes_read;
15363 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15364 mac_ptr += bytes_read;
15366 if (macinfo_type == DW_MACRO_GNU_define
15367 || macinfo_type == DW_MACRO_GNU_undef)
15369 body = read_direct_string (abfd, mac_ptr, &bytes_read);
15370 mac_ptr += bytes_read;
15374 LONGEST str_offset;
15376 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
15377 mac_ptr += offset_size;
15379 body = read_indirect_string_at_offset (abfd, str_offset);
15382 is_define = (macinfo_type == DW_MACRO_GNU_define
15383 || macinfo_type == DW_MACRO_GNU_define_indirect);
15384 if (! current_file)
15386 /* DWARF violation as no main source is present. */
15387 complaint (&symfile_complaints,
15388 _("debug info with no main source gives macro %s "
15390 is_define ? _("definition") : _("undefinition"),
15394 if ((line == 0 && !at_commandline)
15395 || (line != 0 && at_commandline))
15396 complaint (&symfile_complaints,
15397 _("debug info gives %s macro %s with %s line %d: %s"),
15398 at_commandline ? _("command-line") : _("in-file"),
15399 is_define ? _("definition") : _("undefinition"),
15400 line == 0 ? _("zero") : _("non-zero"), line, body);
15403 parse_macro_definition (current_file, line, body);
15406 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
15407 || macinfo_type == DW_MACRO_GNU_undef_indirect);
15408 macro_undef (current_file, line, body);
15413 case DW_MACRO_GNU_start_file:
15415 unsigned int bytes_read;
15418 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15419 mac_ptr += bytes_read;
15420 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15421 mac_ptr += bytes_read;
15423 if ((line == 0 && !at_commandline)
15424 || (line != 0 && at_commandline))
15425 complaint (&symfile_complaints,
15426 _("debug info gives source %d included "
15427 "from %s at %s line %d"),
15428 file, at_commandline ? _("command-line") : _("file"),
15429 line == 0 ? _("zero") : _("non-zero"), line);
15431 if (at_commandline)
15433 /* This DW_MACRO_GNU_start_file was executed in the
15435 at_commandline = 0;
15438 current_file = macro_start_file (file, line,
15439 current_file, comp_dir,
15444 case DW_MACRO_GNU_end_file:
15445 if (! current_file)
15446 complaint (&symfile_complaints,
15447 _("macro debug info has an unmatched "
15448 "`close_file' directive"));
15451 current_file = current_file->included_by;
15452 if (! current_file)
15454 enum dwarf_macro_record_type next_type;
15456 /* GCC circa March 2002 doesn't produce the zero
15457 type byte marking the end of the compilation
15458 unit. Complain if it's not there, but exit no
15461 /* Do we at least have room for a macinfo type byte? */
15462 if (mac_ptr >= mac_end)
15464 dwarf2_macros_too_long_complaint (section);
15468 /* We don't increment mac_ptr here, so this is just
15470 next_type = read_1_byte (abfd, mac_ptr);
15471 if (next_type != 0)
15472 complaint (&symfile_complaints,
15473 _("no terminating 0-type entry for "
15474 "macros in `.debug_macinfo' section"));
15481 case DW_MACRO_GNU_transparent_include:
15485 offset = read_offset_1 (abfd, mac_ptr, offset_size);
15486 mac_ptr += offset_size;
15488 dwarf_decode_macro_bytes (abfd,
15489 section->buffer + offset,
15490 mac_end, current_file,
15492 section, section_is_gnu,
15493 offset_size, objfile);
15497 case DW_MACINFO_vendor_ext:
15498 if (!section_is_gnu)
15500 unsigned int bytes_read;
15503 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15504 mac_ptr += bytes_read;
15505 read_direct_string (abfd, mac_ptr, &bytes_read);
15506 mac_ptr += bytes_read;
15508 /* We don't recognize any vendor extensions. */
15514 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15515 mac_ptr, abfd, offset_size,
15517 if (mac_ptr == NULL)
15521 } while (macinfo_type != 0);
15525 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
15526 char *comp_dir, bfd *abfd,
15527 struct dwarf2_cu *cu,
15528 struct dwarf2_section_info *section,
15529 int section_is_gnu)
15531 gdb_byte *mac_ptr, *mac_end;
15532 struct macro_source_file *current_file = 0;
15533 enum dwarf_macro_record_type macinfo_type;
15534 unsigned int offset_size = cu->header.offset_size;
15535 gdb_byte *opcode_definitions[256];
15537 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
15538 if (section->buffer == NULL)
15540 complaint (&symfile_complaints, _("missing %s section"),
15541 section->asection->name);
15545 /* First pass: Find the name of the base filename.
15546 This filename is needed in order to process all macros whose definition
15547 (or undefinition) comes from the command line. These macros are defined
15548 before the first DW_MACINFO_start_file entry, and yet still need to be
15549 associated to the base file.
15551 To determine the base file name, we scan the macro definitions until we
15552 reach the first DW_MACINFO_start_file entry. We then initialize
15553 CURRENT_FILE accordingly so that any macro definition found before the
15554 first DW_MACINFO_start_file can still be associated to the base file. */
15556 mac_ptr = section->buffer + offset;
15557 mac_end = section->buffer + section->size;
15559 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
15560 &offset_size, section_is_gnu);
15561 if (mac_ptr == NULL)
15563 /* We already issued a complaint. */
15569 /* Do we at least have room for a macinfo type byte? */
15570 if (mac_ptr >= mac_end)
15572 /* Complaint is printed during the second pass as GDB will probably
15573 stop the first pass earlier upon finding
15574 DW_MACINFO_start_file. */
15578 macinfo_type = read_1_byte (abfd, mac_ptr);
15581 /* Note that we rely on the fact that the corresponding GNU and
15582 DWARF constants are the same. */
15583 switch (macinfo_type)
15585 /* A zero macinfo type indicates the end of the macro
15590 case DW_MACRO_GNU_define:
15591 case DW_MACRO_GNU_undef:
15592 /* Only skip the data by MAC_PTR. */
15594 unsigned int bytes_read;
15596 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15597 mac_ptr += bytes_read;
15598 read_direct_string (abfd, mac_ptr, &bytes_read);
15599 mac_ptr += bytes_read;
15603 case DW_MACRO_GNU_start_file:
15605 unsigned int bytes_read;
15608 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15609 mac_ptr += bytes_read;
15610 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15611 mac_ptr += bytes_read;
15613 current_file = macro_start_file (file, line, current_file,
15614 comp_dir, lh, cu->objfile);
15618 case DW_MACRO_GNU_end_file:
15619 /* No data to skip by MAC_PTR. */
15622 case DW_MACRO_GNU_define_indirect:
15623 case DW_MACRO_GNU_undef_indirect:
15625 unsigned int bytes_read;
15627 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15628 mac_ptr += bytes_read;
15629 mac_ptr += offset_size;
15633 case DW_MACRO_GNU_transparent_include:
15634 /* Note that, according to the spec, a transparent include
15635 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15636 skip this opcode. */
15637 mac_ptr += offset_size;
15640 case DW_MACINFO_vendor_ext:
15641 /* Only skip the data by MAC_PTR. */
15642 if (!section_is_gnu)
15644 unsigned int bytes_read;
15646 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15647 mac_ptr += bytes_read;
15648 read_direct_string (abfd, mac_ptr, &bytes_read);
15649 mac_ptr += bytes_read;
15654 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15655 mac_ptr, abfd, offset_size,
15657 if (mac_ptr == NULL)
15661 } while (macinfo_type != 0 && current_file == NULL);
15663 /* Second pass: Process all entries.
15665 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15666 command-line macro definitions/undefinitions. This flag is unset when we
15667 reach the first DW_MACINFO_start_file entry. */
15669 dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end,
15670 current_file, lh, comp_dir, section, section_is_gnu,
15671 offset_size, cu->objfile);
15674 /* Check if the attribute's form is a DW_FORM_block*
15675 if so return true else false. */
15677 attr_form_is_block (struct attribute *attr)
15679 return (attr == NULL ? 0 :
15680 attr->form == DW_FORM_block1
15681 || attr->form == DW_FORM_block2
15682 || attr->form == DW_FORM_block4
15683 || attr->form == DW_FORM_block
15684 || attr->form == DW_FORM_exprloc);
15687 /* Return non-zero if ATTR's value is a section offset --- classes
15688 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15689 You may use DW_UNSND (attr) to retrieve such offsets.
15691 Section 7.5.4, "Attribute Encodings", explains that no attribute
15692 may have a value that belongs to more than one of these classes; it
15693 would be ambiguous if we did, because we use the same forms for all
15696 attr_form_is_section_offset (struct attribute *attr)
15698 return (attr->form == DW_FORM_data4
15699 || attr->form == DW_FORM_data8
15700 || attr->form == DW_FORM_sec_offset);
15704 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15705 zero otherwise. When this function returns true, you can apply
15706 dwarf2_get_attr_constant_value to it.
15708 However, note that for some attributes you must check
15709 attr_form_is_section_offset before using this test. DW_FORM_data4
15710 and DW_FORM_data8 are members of both the constant class, and of
15711 the classes that contain offsets into other debug sections
15712 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15713 that, if an attribute's can be either a constant or one of the
15714 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15715 taken as section offsets, not constants. */
15717 attr_form_is_constant (struct attribute *attr)
15719 switch (attr->form)
15721 case DW_FORM_sdata:
15722 case DW_FORM_udata:
15723 case DW_FORM_data1:
15724 case DW_FORM_data2:
15725 case DW_FORM_data4:
15726 case DW_FORM_data8:
15733 /* A helper function that fills in a dwarf2_loclist_baton. */
15736 fill_in_loclist_baton (struct dwarf2_cu *cu,
15737 struct dwarf2_loclist_baton *baton,
15738 struct attribute *attr)
15740 dwarf2_read_section (dwarf2_per_objfile->objfile,
15741 &dwarf2_per_objfile->loc);
15743 baton->per_cu = cu->per_cu;
15744 gdb_assert (baton->per_cu);
15745 /* We don't know how long the location list is, but make sure we
15746 don't run off the edge of the section. */
15747 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15748 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15749 baton->base_address = cu->base_address;
15753 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15754 struct dwarf2_cu *cu)
15756 if (attr_form_is_section_offset (attr)
15757 /* ".debug_loc" may not exist at all, or the offset may be outside
15758 the section. If so, fall through to the complaint in the
15760 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
15761 &dwarf2_per_objfile->loc))
15763 struct dwarf2_loclist_baton *baton;
15765 baton = obstack_alloc (&cu->objfile->objfile_obstack,
15766 sizeof (struct dwarf2_loclist_baton));
15768 fill_in_loclist_baton (cu, baton, attr);
15770 if (cu->base_known == 0)
15771 complaint (&symfile_complaints,
15772 _("Location list used without "
15773 "specifying the CU base address."));
15775 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15776 SYMBOL_LOCATION_BATON (sym) = baton;
15780 struct dwarf2_locexpr_baton *baton;
15782 baton = obstack_alloc (&cu->objfile->objfile_obstack,
15783 sizeof (struct dwarf2_locexpr_baton));
15784 baton->per_cu = cu->per_cu;
15785 gdb_assert (baton->per_cu);
15787 if (attr_form_is_block (attr))
15789 /* Note that we're just copying the block's data pointer
15790 here, not the actual data. We're still pointing into the
15791 info_buffer for SYM's objfile; right now we never release
15792 that buffer, but when we do clean up properly this may
15794 baton->size = DW_BLOCK (attr)->size;
15795 baton->data = DW_BLOCK (attr)->data;
15799 dwarf2_invalid_attrib_class_complaint ("location description",
15800 SYMBOL_NATURAL_NAME (sym));
15804 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15805 SYMBOL_LOCATION_BATON (sym) = baton;
15809 /* Return the OBJFILE associated with the compilation unit CU. If CU
15810 came from a separate debuginfo file, then the master objfile is
15814 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15816 struct objfile *objfile = per_cu->objfile;
15818 /* Return the master objfile, so that we can report and look up the
15819 correct file containing this variable. */
15820 if (objfile->separate_debug_objfile_backlink)
15821 objfile = objfile->separate_debug_objfile_backlink;
15826 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15827 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15828 CU_HEADERP first. */
15830 static const struct comp_unit_head *
15831 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15832 struct dwarf2_per_cu_data *per_cu)
15834 struct objfile *objfile;
15835 struct dwarf2_per_objfile *per_objfile;
15836 gdb_byte *info_ptr;
15839 return &per_cu->cu->header;
15841 objfile = per_cu->objfile;
15842 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15843 info_ptr = per_objfile->info.buffer + per_cu->offset;
15845 memset (cu_headerp, 0, sizeof (*cu_headerp));
15846 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15851 /* Return the address size given in the compilation unit header for CU. */
15854 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15856 struct comp_unit_head cu_header_local;
15857 const struct comp_unit_head *cu_headerp;
15859 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15861 return cu_headerp->addr_size;
15864 /* Return the offset size given in the compilation unit header for CU. */
15867 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15869 struct comp_unit_head cu_header_local;
15870 const struct comp_unit_head *cu_headerp;
15872 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15874 return cu_headerp->offset_size;
15877 /* See its dwarf2loc.h declaration. */
15880 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
15882 struct comp_unit_head cu_header_local;
15883 const struct comp_unit_head *cu_headerp;
15885 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15887 if (cu_headerp->version == 2)
15888 return cu_headerp->addr_size;
15890 return cu_headerp->offset_size;
15893 /* Return the text offset of the CU. The returned offset comes from
15894 this CU's objfile. If this objfile came from a separate debuginfo
15895 file, then the offset may be different from the corresponding
15896 offset in the parent objfile. */
15899 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
15901 struct objfile *objfile = per_cu->objfile;
15903 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15906 /* Locate the .debug_info compilation unit from CU's objfile which contains
15907 the DIE at OFFSET. Raises an error on failure. */
15909 static struct dwarf2_per_cu_data *
15910 dwarf2_find_containing_comp_unit (unsigned int offset,
15911 struct objfile *objfile)
15913 struct dwarf2_per_cu_data *this_cu;
15917 high = dwarf2_per_objfile->n_comp_units - 1;
15920 int mid = low + (high - low) / 2;
15922 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
15927 gdb_assert (low == high);
15928 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
15931 error (_("Dwarf Error: could not find partial DIE containing "
15932 "offset 0x%lx [in module %s]"),
15933 (long) offset, bfd_get_filename (objfile->obfd));
15935 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
15936 return dwarf2_per_objfile->all_comp_units[low-1];
15940 this_cu = dwarf2_per_objfile->all_comp_units[low];
15941 if (low == dwarf2_per_objfile->n_comp_units - 1
15942 && offset >= this_cu->offset + this_cu->length)
15943 error (_("invalid dwarf2 offset %u"), offset);
15944 gdb_assert (offset < this_cu->offset + this_cu->length);
15949 /* Locate the compilation unit from OBJFILE which is located at exactly
15950 OFFSET. Raises an error on failure. */
15952 static struct dwarf2_per_cu_data *
15953 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
15955 struct dwarf2_per_cu_data *this_cu;
15957 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
15958 if (this_cu->offset != offset)
15959 error (_("no compilation unit with offset %u."), offset);
15963 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15966 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
15968 memset (cu, 0, sizeof (*cu));
15969 cu->objfile = objfile;
15970 obstack_init (&cu->comp_unit_obstack);
15973 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15976 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
15978 struct attribute *attr;
15980 /* Set the language we're debugging. */
15981 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
15983 set_cu_language (DW_UNSND (attr), cu);
15986 cu->language = language_minimal;
15987 cu->language_defn = language_def (cu->language);
15991 /* Release one cached compilation unit, CU. We unlink it from the tree
15992 of compilation units, but we don't remove it from the read_in_chain;
15993 the caller is responsible for that.
15994 NOTE: DATA is a void * because this function is also used as a
15995 cleanup routine. */
15998 free_one_comp_unit (void *data)
16000 struct dwarf2_cu *cu = data;
16002 if (cu->per_cu != NULL)
16003 cu->per_cu->cu = NULL;
16006 obstack_free (&cu->comp_unit_obstack, NULL);
16011 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16012 when we're finished with it. We can't free the pointer itself, but be
16013 sure to unlink it from the cache. Also release any associated storage
16014 and perform cache maintenance.
16016 Only used during partial symbol parsing. */
16019 free_stack_comp_unit (void *data)
16021 struct dwarf2_cu *cu = data;
16023 obstack_free (&cu->comp_unit_obstack, NULL);
16024 cu->partial_dies = NULL;
16026 if (cu->per_cu != NULL)
16028 /* This compilation unit is on the stack in our caller, so we
16029 should not xfree it. Just unlink it. */
16030 cu->per_cu->cu = NULL;
16033 /* If we had a per-cu pointer, then we may have other compilation
16034 units loaded, so age them now. */
16035 age_cached_comp_units ();
16039 /* Free all cached compilation units. */
16042 free_cached_comp_units (void *data)
16044 struct dwarf2_per_cu_data *per_cu, **last_chain;
16046 per_cu = dwarf2_per_objfile->read_in_chain;
16047 last_chain = &dwarf2_per_objfile->read_in_chain;
16048 while (per_cu != NULL)
16050 struct dwarf2_per_cu_data *next_cu;
16052 next_cu = per_cu->cu->read_in_chain;
16054 free_one_comp_unit (per_cu->cu);
16055 *last_chain = next_cu;
16061 /* Increase the age counter on each cached compilation unit, and free
16062 any that are too old. */
16065 age_cached_comp_units (void)
16067 struct dwarf2_per_cu_data *per_cu, **last_chain;
16069 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
16070 per_cu = dwarf2_per_objfile->read_in_chain;
16071 while (per_cu != NULL)
16073 per_cu->cu->last_used ++;
16074 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
16075 dwarf2_mark (per_cu->cu);
16076 per_cu = per_cu->cu->read_in_chain;
16079 per_cu = dwarf2_per_objfile->read_in_chain;
16080 last_chain = &dwarf2_per_objfile->read_in_chain;
16081 while (per_cu != NULL)
16083 struct dwarf2_per_cu_data *next_cu;
16085 next_cu = per_cu->cu->read_in_chain;
16087 if (!per_cu->cu->mark)
16089 free_one_comp_unit (per_cu->cu);
16090 *last_chain = next_cu;
16093 last_chain = &per_cu->cu->read_in_chain;
16099 /* Remove a single compilation unit from the cache. */
16102 free_one_cached_comp_unit (void *target_cu)
16104 struct dwarf2_per_cu_data *per_cu, **last_chain;
16106 per_cu = dwarf2_per_objfile->read_in_chain;
16107 last_chain = &dwarf2_per_objfile->read_in_chain;
16108 while (per_cu != NULL)
16110 struct dwarf2_per_cu_data *next_cu;
16112 next_cu = per_cu->cu->read_in_chain;
16114 if (per_cu->cu == target_cu)
16116 free_one_comp_unit (per_cu->cu);
16117 *last_chain = next_cu;
16121 last_chain = &per_cu->cu->read_in_chain;
16127 /* Release all extra memory associated with OBJFILE. */
16130 dwarf2_free_objfile (struct objfile *objfile)
16132 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16134 if (dwarf2_per_objfile == NULL)
16137 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16138 free_cached_comp_units (NULL);
16140 if (dwarf2_per_objfile->quick_file_names_table)
16141 htab_delete (dwarf2_per_objfile->quick_file_names_table);
16143 /* Everything else should be on the objfile obstack. */
16146 /* A pair of DIE offset and GDB type pointer. We store these
16147 in a hash table separate from the DIEs, and preserve them
16148 when the DIEs are flushed out of cache. */
16150 struct dwarf2_offset_and_type
16152 unsigned int offset;
16156 /* Hash function for a dwarf2_offset_and_type. */
16159 offset_and_type_hash (const void *item)
16161 const struct dwarf2_offset_and_type *ofs = item;
16163 return ofs->offset;
16166 /* Equality function for a dwarf2_offset_and_type. */
16169 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
16171 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
16172 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
16174 return ofs_lhs->offset == ofs_rhs->offset;
16177 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16178 table if necessary. For convenience, return TYPE.
16180 The DIEs reading must have careful ordering to:
16181 * Not cause infite loops trying to read in DIEs as a prerequisite for
16182 reading current DIE.
16183 * Not trying to dereference contents of still incompletely read in types
16184 while reading in other DIEs.
16185 * Enable referencing still incompletely read in types just by a pointer to
16186 the type without accessing its fields.
16188 Therefore caller should follow these rules:
16189 * Try to fetch any prerequisite types we may need to build this DIE type
16190 before building the type and calling set_die_type.
16191 * After building type call set_die_type for current DIE as soon as
16192 possible before fetching more types to complete the current type.
16193 * Make the type as complete as possible before fetching more types. */
16195 static struct type *
16196 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16198 struct dwarf2_offset_and_type **slot, ofs;
16199 struct objfile *objfile = cu->objfile;
16200 htab_t *type_hash_ptr;
16202 /* For Ada types, make sure that the gnat-specific data is always
16203 initialized (if not already set). There are a few types where
16204 we should not be doing so, because the type-specific area is
16205 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16206 where the type-specific area is used to store the floatformat).
16207 But this is not a problem, because the gnat-specific information
16208 is actually not needed for these types. */
16209 if (need_gnat_info (cu)
16210 && TYPE_CODE (type) != TYPE_CODE_FUNC
16211 && TYPE_CODE (type) != TYPE_CODE_FLT
16212 && !HAVE_GNAT_AUX_INFO (type))
16213 INIT_GNAT_SPECIFIC (type);
16215 if (cu->per_cu->debug_types_section)
16216 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
16218 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
16220 if (*type_hash_ptr == NULL)
16223 = htab_create_alloc_ex (127,
16224 offset_and_type_hash,
16225 offset_and_type_eq,
16227 &objfile->objfile_obstack,
16228 hashtab_obstack_allocate,
16229 dummy_obstack_deallocate);
16232 ofs.offset = die->offset;
16234 slot = (struct dwarf2_offset_and_type **)
16235 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
16237 complaint (&symfile_complaints,
16238 _("A problem internal to GDB: DIE 0x%x has type already set"),
16240 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
16245 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16246 table, or return NULL if the die does not have a saved type. */
16248 static struct type *
16249 get_die_type_at_offset (unsigned int offset,
16250 struct dwarf2_per_cu_data *per_cu)
16252 struct dwarf2_offset_and_type *slot, ofs;
16255 if (per_cu->debug_types_section)
16256 type_hash = dwarf2_per_objfile->debug_types_type_hash;
16258 type_hash = dwarf2_per_objfile->debug_info_type_hash;
16259 if (type_hash == NULL)
16262 ofs.offset = offset;
16263 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
16270 /* Look up the type for DIE in the appropriate type_hash table,
16271 or return NULL if DIE does not have a saved type. */
16273 static struct type *
16274 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
16276 return get_die_type_at_offset (die->offset, cu->per_cu);
16279 /* Add a dependence relationship from CU to REF_PER_CU. */
16282 dwarf2_add_dependence (struct dwarf2_cu *cu,
16283 struct dwarf2_per_cu_data *ref_per_cu)
16287 if (cu->dependencies == NULL)
16289 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
16290 NULL, &cu->comp_unit_obstack,
16291 hashtab_obstack_allocate,
16292 dummy_obstack_deallocate);
16294 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
16296 *slot = ref_per_cu;
16299 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16300 Set the mark field in every compilation unit in the
16301 cache that we must keep because we are keeping CU. */
16304 dwarf2_mark_helper (void **slot, void *data)
16306 struct dwarf2_per_cu_data *per_cu;
16308 per_cu = (struct dwarf2_per_cu_data *) *slot;
16310 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16311 reading of the chain. As such dependencies remain valid it is not much
16312 useful to track and undo them during QUIT cleanups. */
16313 if (per_cu->cu == NULL)
16316 if (per_cu->cu->mark)
16318 per_cu->cu->mark = 1;
16320 if (per_cu->cu->dependencies != NULL)
16321 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
16326 /* Set the mark field in CU and in every other compilation unit in the
16327 cache that we must keep because we are keeping CU. */
16330 dwarf2_mark (struct dwarf2_cu *cu)
16335 if (cu->dependencies != NULL)
16336 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
16340 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
16344 per_cu->cu->mark = 0;
16345 per_cu = per_cu->cu->read_in_chain;
16349 /* Trivial hash function for partial_die_info: the hash value of a DIE
16350 is its offset in .debug_info for this objfile. */
16353 partial_die_hash (const void *item)
16355 const struct partial_die_info *part_die = item;
16357 return part_die->offset;
16360 /* Trivial comparison function for partial_die_info structures: two DIEs
16361 are equal if they have the same offset. */
16364 partial_die_eq (const void *item_lhs, const void *item_rhs)
16366 const struct partial_die_info *part_die_lhs = item_lhs;
16367 const struct partial_die_info *part_die_rhs = item_rhs;
16369 return part_die_lhs->offset == part_die_rhs->offset;
16372 static struct cmd_list_element *set_dwarf2_cmdlist;
16373 static struct cmd_list_element *show_dwarf2_cmdlist;
16376 set_dwarf2_cmd (char *args, int from_tty)
16378 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
16382 show_dwarf2_cmd (char *args, int from_tty)
16384 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
16387 /* If section described by INFO was mmapped, munmap it now. */
16390 munmap_section_buffer (struct dwarf2_section_info *info)
16392 if (info->map_addr != NULL)
16397 res = munmap (info->map_addr, info->map_len);
16398 gdb_assert (res == 0);
16400 /* Without HAVE_MMAP, we should never be here to begin with. */
16401 gdb_assert_not_reached ("no mmap support");
16406 /* munmap debug sections for OBJFILE, if necessary. */
16409 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
16411 struct dwarf2_per_objfile *data = d;
16413 struct dwarf2_section_info *section;
16415 /* This is sorted according to the order they're defined in to make it easier
16416 to keep in sync. */
16417 munmap_section_buffer (&data->info);
16418 munmap_section_buffer (&data->abbrev);
16419 munmap_section_buffer (&data->line);
16420 munmap_section_buffer (&data->loc);
16421 munmap_section_buffer (&data->macinfo);
16422 munmap_section_buffer (&data->macro);
16423 munmap_section_buffer (&data->str);
16424 munmap_section_buffer (&data->ranges);
16425 munmap_section_buffer (&data->frame);
16426 munmap_section_buffer (&data->eh_frame);
16427 munmap_section_buffer (&data->gdb_index);
16430 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
16432 munmap_section_buffer (section);
16434 VEC_free (dwarf2_section_info_def, data->types);
16438 /* The "save gdb-index" command. */
16440 /* The contents of the hash table we create when building the string
16442 struct strtab_entry
16444 offset_type offset;
16448 /* Hash function for a strtab_entry.
16450 Function is used only during write_hash_table so no index format backward
16451 compatibility is needed. */
16454 hash_strtab_entry (const void *e)
16456 const struct strtab_entry *entry = e;
16457 return mapped_index_string_hash (INT_MAX, entry->str);
16460 /* Equality function for a strtab_entry. */
16463 eq_strtab_entry (const void *a, const void *b)
16465 const struct strtab_entry *ea = a;
16466 const struct strtab_entry *eb = b;
16467 return !strcmp (ea->str, eb->str);
16470 /* Create a strtab_entry hash table. */
16473 create_strtab (void)
16475 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
16476 xfree, xcalloc, xfree);
16479 /* Add a string to the constant pool. Return the string's offset in
16483 add_string (htab_t table, struct obstack *cpool, const char *str)
16486 struct strtab_entry entry;
16487 struct strtab_entry *result;
16490 slot = htab_find_slot (table, &entry, INSERT);
16495 result = XNEW (struct strtab_entry);
16496 result->offset = obstack_object_size (cpool);
16498 obstack_grow_str0 (cpool, str);
16501 return result->offset;
16504 /* An entry in the symbol table. */
16505 struct symtab_index_entry
16507 /* The name of the symbol. */
16509 /* The offset of the name in the constant pool. */
16510 offset_type index_offset;
16511 /* A sorted vector of the indices of all the CUs that hold an object
16513 VEC (offset_type) *cu_indices;
16516 /* The symbol table. This is a power-of-2-sized hash table. */
16517 struct mapped_symtab
16519 offset_type n_elements;
16521 struct symtab_index_entry **data;
16524 /* Hash function for a symtab_index_entry. */
16527 hash_symtab_entry (const void *e)
16529 const struct symtab_index_entry *entry = e;
16530 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
16531 sizeof (offset_type) * VEC_length (offset_type,
16532 entry->cu_indices),
16536 /* Equality function for a symtab_index_entry. */
16539 eq_symtab_entry (const void *a, const void *b)
16541 const struct symtab_index_entry *ea = a;
16542 const struct symtab_index_entry *eb = b;
16543 int len = VEC_length (offset_type, ea->cu_indices);
16544 if (len != VEC_length (offset_type, eb->cu_indices))
16546 return !memcmp (VEC_address (offset_type, ea->cu_indices),
16547 VEC_address (offset_type, eb->cu_indices),
16548 sizeof (offset_type) * len);
16551 /* Destroy a symtab_index_entry. */
16554 delete_symtab_entry (void *p)
16556 struct symtab_index_entry *entry = p;
16557 VEC_free (offset_type, entry->cu_indices);
16561 /* Create a hash table holding symtab_index_entry objects. */
16564 create_symbol_hash_table (void)
16566 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
16567 delete_symtab_entry, xcalloc, xfree);
16570 /* Create a new mapped symtab object. */
16572 static struct mapped_symtab *
16573 create_mapped_symtab (void)
16575 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
16576 symtab->n_elements = 0;
16577 symtab->size = 1024;
16578 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16582 /* Destroy a mapped_symtab. */
16585 cleanup_mapped_symtab (void *p)
16587 struct mapped_symtab *symtab = p;
16588 /* The contents of the array are freed when the other hash table is
16590 xfree (symtab->data);
16594 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16597 Function is used only during write_hash_table so no index format backward
16598 compatibility is needed. */
16600 static struct symtab_index_entry **
16601 find_slot (struct mapped_symtab *symtab, const char *name)
16603 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16605 index = hash & (symtab->size - 1);
16606 step = ((hash * 17) & (symtab->size - 1)) | 1;
16610 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16611 return &symtab->data[index];
16612 index = (index + step) & (symtab->size - 1);
16616 /* Expand SYMTAB's hash table. */
16619 hash_expand (struct mapped_symtab *symtab)
16621 offset_type old_size = symtab->size;
16623 struct symtab_index_entry **old_entries = symtab->data;
16626 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16628 for (i = 0; i < old_size; ++i)
16630 if (old_entries[i])
16632 struct symtab_index_entry **slot = find_slot (symtab,
16633 old_entries[i]->name);
16634 *slot = old_entries[i];
16638 xfree (old_entries);
16641 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16642 is the index of the CU in which the symbol appears. */
16645 add_index_entry (struct mapped_symtab *symtab, const char *name,
16646 offset_type cu_index)
16648 struct symtab_index_entry **slot;
16650 ++symtab->n_elements;
16651 if (4 * symtab->n_elements / 3 >= symtab->size)
16652 hash_expand (symtab);
16654 slot = find_slot (symtab, name);
16657 *slot = XNEW (struct symtab_index_entry);
16658 (*slot)->name = name;
16659 (*slot)->cu_indices = NULL;
16661 /* Don't push an index twice. Due to how we add entries we only
16662 have to check the last one. */
16663 if (VEC_empty (offset_type, (*slot)->cu_indices)
16664 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16665 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16668 /* Add a vector of indices to the constant pool. */
16671 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16672 struct symtab_index_entry *entry)
16676 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16679 offset_type len = VEC_length (offset_type, entry->cu_indices);
16680 offset_type val = MAYBE_SWAP (len);
16685 entry->index_offset = obstack_object_size (cpool);
16687 obstack_grow (cpool, &val, sizeof (val));
16689 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16692 val = MAYBE_SWAP (iter);
16693 obstack_grow (cpool, &val, sizeof (val));
16698 struct symtab_index_entry *old_entry = *slot;
16699 entry->index_offset = old_entry->index_offset;
16702 return entry->index_offset;
16705 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16706 constant pool entries going into the obstack CPOOL. */
16709 write_hash_table (struct mapped_symtab *symtab,
16710 struct obstack *output, struct obstack *cpool)
16713 htab_t symbol_hash_table;
16716 symbol_hash_table = create_symbol_hash_table ();
16717 str_table = create_strtab ();
16719 /* We add all the index vectors to the constant pool first, to
16720 ensure alignment is ok. */
16721 for (i = 0; i < symtab->size; ++i)
16723 if (symtab->data[i])
16724 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16727 /* Now write out the hash table. */
16728 for (i = 0; i < symtab->size; ++i)
16730 offset_type str_off, vec_off;
16732 if (symtab->data[i])
16734 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16735 vec_off = symtab->data[i]->index_offset;
16739 /* While 0 is a valid constant pool index, it is not valid
16740 to have 0 for both offsets. */
16745 str_off = MAYBE_SWAP (str_off);
16746 vec_off = MAYBE_SWAP (vec_off);
16748 obstack_grow (output, &str_off, sizeof (str_off));
16749 obstack_grow (output, &vec_off, sizeof (vec_off));
16752 htab_delete (str_table);
16753 htab_delete (symbol_hash_table);
16756 /* Struct to map psymtab to CU index in the index file. */
16757 struct psymtab_cu_index_map
16759 struct partial_symtab *psymtab;
16760 unsigned int cu_index;
16764 hash_psymtab_cu_index (const void *item)
16766 const struct psymtab_cu_index_map *map = item;
16768 return htab_hash_pointer (map->psymtab);
16772 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16774 const struct psymtab_cu_index_map *lhs = item_lhs;
16775 const struct psymtab_cu_index_map *rhs = item_rhs;
16777 return lhs->psymtab == rhs->psymtab;
16780 /* Helper struct for building the address table. */
16781 struct addrmap_index_data
16783 struct objfile *objfile;
16784 struct obstack *addr_obstack;
16785 htab_t cu_index_htab;
16787 /* Non-zero if the previous_* fields are valid.
16788 We can't write an entry until we see the next entry (since it is only then
16789 that we know the end of the entry). */
16790 int previous_valid;
16791 /* Index of the CU in the table of all CUs in the index file. */
16792 unsigned int previous_cu_index;
16793 /* Start address of the CU. */
16794 CORE_ADDR previous_cu_start;
16797 /* Write an address entry to OBSTACK. */
16800 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16801 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16803 offset_type cu_index_to_write;
16805 CORE_ADDR baseaddr;
16807 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16809 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16810 obstack_grow (obstack, addr, 8);
16811 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16812 obstack_grow (obstack, addr, 8);
16813 cu_index_to_write = MAYBE_SWAP (cu_index);
16814 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16817 /* Worker function for traversing an addrmap to build the address table. */
16820 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16822 struct addrmap_index_data *data = datap;
16823 struct partial_symtab *pst = obj;
16824 offset_type cu_index;
16827 if (data->previous_valid)
16828 add_address_entry (data->objfile, data->addr_obstack,
16829 data->previous_cu_start, start_addr,
16830 data->previous_cu_index);
16832 data->previous_cu_start = start_addr;
16835 struct psymtab_cu_index_map find_map, *map;
16836 find_map.psymtab = pst;
16837 map = htab_find (data->cu_index_htab, &find_map);
16838 gdb_assert (map != NULL);
16839 data->previous_cu_index = map->cu_index;
16840 data->previous_valid = 1;
16843 data->previous_valid = 0;
16848 /* Write OBJFILE's address map to OBSTACK.
16849 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16850 in the index file. */
16853 write_address_map (struct objfile *objfile, struct obstack *obstack,
16854 htab_t cu_index_htab)
16856 struct addrmap_index_data addrmap_index_data;
16858 /* When writing the address table, we have to cope with the fact that
16859 the addrmap iterator only provides the start of a region; we have to
16860 wait until the next invocation to get the start of the next region. */
16862 addrmap_index_data.objfile = objfile;
16863 addrmap_index_data.addr_obstack = obstack;
16864 addrmap_index_data.cu_index_htab = cu_index_htab;
16865 addrmap_index_data.previous_valid = 0;
16867 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16868 &addrmap_index_data);
16870 /* It's highly unlikely the last entry (end address = 0xff...ff)
16871 is valid, but we should still handle it.
16872 The end address is recorded as the start of the next region, but that
16873 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16875 if (addrmap_index_data.previous_valid)
16876 add_address_entry (objfile, obstack,
16877 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16878 addrmap_index_data.previous_cu_index);
16881 /* Add a list of partial symbols to SYMTAB. */
16884 write_psymbols (struct mapped_symtab *symtab,
16886 struct partial_symbol **psymp,
16888 offset_type cu_index,
16891 for (; count-- > 0; ++psymp)
16893 void **slot, *lookup;
16895 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16896 error (_("Ada is not currently supported by the index"));
16898 /* We only want to add a given psymbol once. However, we also
16899 want to account for whether it is global or static. So, we
16900 may add it twice, using slightly different values. */
16903 uintptr_t val = 1 | (uintptr_t) *psymp;
16905 lookup = (void *) val;
16910 /* Only add a given psymbol once. */
16911 slot = htab_find_slot (psyms_seen, lookup, INSERT);
16915 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
16920 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16921 exception if there is an error. */
16924 write_obstack (FILE *file, struct obstack *obstack)
16926 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
16928 != obstack_object_size (obstack))
16929 error (_("couldn't data write to file"));
16932 /* Unlink a file if the argument is not NULL. */
16935 unlink_if_set (void *p)
16937 char **filename = p;
16939 unlink (*filename);
16942 /* A helper struct used when iterating over debug_types. */
16943 struct signatured_type_index_data
16945 struct objfile *objfile;
16946 struct mapped_symtab *symtab;
16947 struct obstack *types_list;
16952 /* A helper function that writes a single signatured_type to an
16956 write_one_signatured_type (void **slot, void *d)
16958 struct signatured_type_index_data *info = d;
16959 struct signatured_type *entry = (struct signatured_type *) *slot;
16960 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
16961 struct partial_symtab *psymtab = per_cu->v.psymtab;
16964 write_psymbols (info->symtab,
16966 info->objfile->global_psymbols.list
16967 + psymtab->globals_offset,
16968 psymtab->n_global_syms, info->cu_index,
16970 write_psymbols (info->symtab,
16972 info->objfile->static_psymbols.list
16973 + psymtab->statics_offset,
16974 psymtab->n_static_syms, info->cu_index,
16977 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
16978 obstack_grow (info->types_list, val, 8);
16979 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
16980 obstack_grow (info->types_list, val, 8);
16981 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
16982 obstack_grow (info->types_list, val, 8);
16989 /* Create an index file for OBJFILE in the directory DIR. */
16992 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
16994 struct cleanup *cleanup;
16995 char *filename, *cleanup_filename;
16996 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
16997 struct obstack cu_list, types_cu_list;
17000 struct mapped_symtab *symtab;
17001 offset_type val, size_of_contents, total_len;
17005 htab_t cu_index_htab;
17006 struct psymtab_cu_index_map *psymtab_cu_index_map;
17008 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
17011 if (dwarf2_per_objfile->using_index)
17012 error (_("Cannot use an index to create the index"));
17014 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
17015 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17017 if (stat (objfile->name, &st) < 0)
17018 perror_with_name (objfile->name);
17020 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
17021 INDEX_SUFFIX, (char *) NULL);
17022 cleanup = make_cleanup (xfree, filename);
17024 out_file = fopen (filename, "wb");
17026 error (_("Can't open `%s' for writing"), filename);
17028 cleanup_filename = filename;
17029 make_cleanup (unlink_if_set, &cleanup_filename);
17031 symtab = create_mapped_symtab ();
17032 make_cleanup (cleanup_mapped_symtab, symtab);
17034 obstack_init (&addr_obstack);
17035 make_cleanup_obstack_free (&addr_obstack);
17037 obstack_init (&cu_list);
17038 make_cleanup_obstack_free (&cu_list);
17040 obstack_init (&types_cu_list);
17041 make_cleanup_obstack_free (&types_cu_list);
17043 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
17044 NULL, xcalloc, xfree);
17045 make_cleanup_htab_delete (psyms_seen);
17047 /* While we're scanning CU's create a table that maps a psymtab pointer
17048 (which is what addrmap records) to its index (which is what is recorded
17049 in the index file). This will later be needed to write the address
17051 cu_index_htab = htab_create_alloc (100,
17052 hash_psymtab_cu_index,
17053 eq_psymtab_cu_index,
17054 NULL, xcalloc, xfree);
17055 make_cleanup_htab_delete (cu_index_htab);
17056 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
17057 xmalloc (sizeof (struct psymtab_cu_index_map)
17058 * dwarf2_per_objfile->n_comp_units);
17059 make_cleanup (xfree, psymtab_cu_index_map);
17061 /* The CU list is already sorted, so we don't need to do additional
17062 work here. Also, the debug_types entries do not appear in
17063 all_comp_units, but only in their own hash table. */
17064 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
17066 struct dwarf2_per_cu_data *per_cu
17067 = dwarf2_per_objfile->all_comp_units[i];
17068 struct partial_symtab *psymtab = per_cu->v.psymtab;
17070 struct psymtab_cu_index_map *map;
17073 write_psymbols (symtab,
17075 objfile->global_psymbols.list + psymtab->globals_offset,
17076 psymtab->n_global_syms, i,
17078 write_psymbols (symtab,
17080 objfile->static_psymbols.list + psymtab->statics_offset,
17081 psymtab->n_static_syms, i,
17084 map = &psymtab_cu_index_map[i];
17085 map->psymtab = psymtab;
17087 slot = htab_find_slot (cu_index_htab, map, INSERT);
17088 gdb_assert (slot != NULL);
17089 gdb_assert (*slot == NULL);
17092 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
17093 obstack_grow (&cu_list, val, 8);
17094 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
17095 obstack_grow (&cu_list, val, 8);
17098 /* Dump the address map. */
17099 write_address_map (objfile, &addr_obstack, cu_index_htab);
17101 /* Write out the .debug_type entries, if any. */
17102 if (dwarf2_per_objfile->signatured_types)
17104 struct signatured_type_index_data sig_data;
17106 sig_data.objfile = objfile;
17107 sig_data.symtab = symtab;
17108 sig_data.types_list = &types_cu_list;
17109 sig_data.psyms_seen = psyms_seen;
17110 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
17111 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
17112 write_one_signatured_type, &sig_data);
17115 obstack_init (&constant_pool);
17116 make_cleanup_obstack_free (&constant_pool);
17117 obstack_init (&symtab_obstack);
17118 make_cleanup_obstack_free (&symtab_obstack);
17119 write_hash_table (symtab, &symtab_obstack, &constant_pool);
17121 obstack_init (&contents);
17122 make_cleanup_obstack_free (&contents);
17123 size_of_contents = 6 * sizeof (offset_type);
17124 total_len = size_of_contents;
17126 /* The version number. */
17127 val = MAYBE_SWAP (5);
17128 obstack_grow (&contents, &val, sizeof (val));
17130 /* The offset of the CU list from the start of the file. */
17131 val = MAYBE_SWAP (total_len);
17132 obstack_grow (&contents, &val, sizeof (val));
17133 total_len += obstack_object_size (&cu_list);
17135 /* The offset of the types CU list from the start of the file. */
17136 val = MAYBE_SWAP (total_len);
17137 obstack_grow (&contents, &val, sizeof (val));
17138 total_len += obstack_object_size (&types_cu_list);
17140 /* The offset of the address table from the start of the file. */
17141 val = MAYBE_SWAP (total_len);
17142 obstack_grow (&contents, &val, sizeof (val));
17143 total_len += obstack_object_size (&addr_obstack);
17145 /* The offset of the symbol table from the start of the file. */
17146 val = MAYBE_SWAP (total_len);
17147 obstack_grow (&contents, &val, sizeof (val));
17148 total_len += obstack_object_size (&symtab_obstack);
17150 /* The offset of the constant pool from the start of the file. */
17151 val = MAYBE_SWAP (total_len);
17152 obstack_grow (&contents, &val, sizeof (val));
17153 total_len += obstack_object_size (&constant_pool);
17155 gdb_assert (obstack_object_size (&contents) == size_of_contents);
17157 write_obstack (out_file, &contents);
17158 write_obstack (out_file, &cu_list);
17159 write_obstack (out_file, &types_cu_list);
17160 write_obstack (out_file, &addr_obstack);
17161 write_obstack (out_file, &symtab_obstack);
17162 write_obstack (out_file, &constant_pool);
17166 /* We want to keep the file, so we set cleanup_filename to NULL
17167 here. See unlink_if_set. */
17168 cleanup_filename = NULL;
17170 do_cleanups (cleanup);
17173 /* Implementation of the `save gdb-index' command.
17175 Note that the file format used by this command is documented in the
17176 GDB manual. Any changes here must be documented there. */
17179 save_gdb_index_command (char *arg, int from_tty)
17181 struct objfile *objfile;
17184 error (_("usage: save gdb-index DIRECTORY"));
17186 ALL_OBJFILES (objfile)
17190 /* If the objfile does not correspond to an actual file, skip it. */
17191 if (stat (objfile->name, &st) < 0)
17194 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
17195 if (dwarf2_per_objfile)
17197 volatile struct gdb_exception except;
17199 TRY_CATCH (except, RETURN_MASK_ERROR)
17201 write_psymtabs_to_index (objfile, arg);
17203 if (except.reason < 0)
17204 exception_fprintf (gdb_stderr, except,
17205 _("Error while writing index for `%s': "),
17213 int dwarf2_always_disassemble;
17216 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
17217 struct cmd_list_element *c, const char *value)
17219 fprintf_filtered (file,
17220 _("Whether to always disassemble "
17221 "DWARF expressions is %s.\n"),
17226 show_check_physname (struct ui_file *file, int from_tty,
17227 struct cmd_list_element *c, const char *value)
17229 fprintf_filtered (file,
17230 _("Whether to check \"physname\" is %s.\n"),
17234 void _initialize_dwarf2_read (void);
17237 _initialize_dwarf2_read (void)
17239 struct cmd_list_element *c;
17241 dwarf2_objfile_data_key
17242 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
17244 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
17245 Set DWARF 2 specific variables.\n\
17246 Configure DWARF 2 variables such as the cache size"),
17247 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
17248 0/*allow-unknown*/, &maintenance_set_cmdlist);
17250 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
17251 Show DWARF 2 specific variables\n\
17252 Show DWARF 2 variables such as the cache size"),
17253 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
17254 0/*allow-unknown*/, &maintenance_show_cmdlist);
17256 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
17257 &dwarf2_max_cache_age, _("\
17258 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17259 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17260 A higher limit means that cached compilation units will be stored\n\
17261 in memory longer, and more total memory will be used. Zero disables\n\
17262 caching, which can slow down startup."),
17264 show_dwarf2_max_cache_age,
17265 &set_dwarf2_cmdlist,
17266 &show_dwarf2_cmdlist);
17268 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
17269 &dwarf2_always_disassemble, _("\
17270 Set whether `info address' always disassembles DWARF expressions."), _("\
17271 Show whether `info address' always disassembles DWARF expressions."), _("\
17272 When enabled, DWARF expressions are always printed in an assembly-like\n\
17273 syntax. When disabled, expressions will be printed in a more\n\
17274 conversational style, when possible."),
17276 show_dwarf2_always_disassemble,
17277 &set_dwarf2_cmdlist,
17278 &show_dwarf2_cmdlist);
17280 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
17281 Set debugging of the dwarf2 DIE reader."), _("\
17282 Show debugging of the dwarf2 DIE reader."), _("\
17283 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17284 The value is the maximum depth to print."),
17287 &setdebuglist, &showdebuglist);
17289 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
17290 Set cross-checking of \"physname\" code against demangler."), _("\
17291 Show cross-checking of \"physname\" code against demangler."), _("\
17292 When enabled, GDB's internal \"physname\" code is checked against\n\
17294 NULL, show_check_physname,
17295 &setdebuglist, &showdebuglist);
17297 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
17299 Save a gdb-index file.\n\
17300 Usage: save gdb-index DIRECTORY"),
17302 set_cmd_completer (c, filename_completer);