1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol *symbolp;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length; /* length of the .debug_info
87 unsigned short version; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
90 unsigned char addr_size; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length; /* byte length of the statement
103 unsigned short version; /* version number -- 2 for DWARF
105 unsigned int prologue_length; /* # bytes between prologue &
107 unsigned char minimum_instruction_length; /* byte size of
109 unsigned char default_is_stmt; /* initial value of is_stmt
112 unsigned char line_range;
113 unsigned char opcode_base; /* number assigned to first special
115 unsigned char *standard_opcode_lengths;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug = 0;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info;
130 static const struct objfile_data *dwarf2_objfile_data_key;
132 struct dwarf2_section_info
138 /* True if we have tried to read this section. */
142 /* All offsets in the index are of this type. It must be
143 architecture-independent. */
144 typedef uint32_t offset_type;
146 DEF_VEC_I (offset_type);
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* Index data format version. */
155 /* The total length of the buffer. */
158 /* A pointer to the address table data. */
159 const gdb_byte *address_table;
161 /* Size of the address table data in bytes. */
162 offset_type address_table_size;
164 /* The symbol table, implemented as a hash table. */
165 const offset_type *symbol_table;
167 /* Size in slots, each slot is 2 offset_types. */
168 offset_type symbol_table_slots;
170 /* A pointer to the constant pool. */
171 const char *constant_pool;
174 struct dwarf2_per_objfile
176 struct dwarf2_section_info info;
177 struct dwarf2_section_info abbrev;
178 struct dwarf2_section_info line;
179 struct dwarf2_section_info loc;
180 struct dwarf2_section_info macinfo;
181 struct dwarf2_section_info str;
182 struct dwarf2_section_info ranges;
183 struct dwarf2_section_info types;
184 struct dwarf2_section_info frame;
185 struct dwarf2_section_info eh_frame;
186 struct dwarf2_section_info gdb_index;
189 struct objfile *objfile;
191 /* A list of all the compilation units. This is used to locate
192 the target compilation unit of a particular reference. */
193 struct dwarf2_per_cu_data **all_comp_units;
195 /* The number of compilation units in ALL_COMP_UNITS. */
198 /* The number of .debug_types-related CUs. */
199 int n_type_comp_units;
201 /* The .debug_types-related CUs. */
202 struct dwarf2_per_cu_data **type_comp_units;
204 /* A chain of compilation units that are currently read in, so that
205 they can be freed later. */
206 struct dwarf2_per_cu_data *read_in_chain;
208 /* A table mapping .debug_types signatures to its signatured_type entry.
209 This is NULL if the .debug_types section hasn't been read in yet. */
210 htab_t signatured_types;
212 /* A flag indicating wether this objfile has a section loaded at a
214 int has_section_at_zero;
216 /* True if we are using the mapped index,
217 or we are faking it for OBJF_READNOW's sake. */
218 unsigned char using_index;
220 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
221 struct mapped_index *index_table;
223 /* When using index_table, this keeps track of all quick_file_names entries.
224 TUs can share line table entries with CUs or other TUs, and there can be
225 a lot more TUs than unique line tables, so we maintain a separate table
226 of all line table entries to support the sharing. */
227 htab_t quick_file_names_table;
229 /* Set during partial symbol reading, to prevent queueing of full
231 int reading_partial_symbols;
233 /* Table mapping type .debug_info DIE offsets to types.
234 This is NULL if not allocated yet.
235 It (currently) makes sense to allocate debug_types_type_hash lazily.
236 To keep things simple we allocate both lazily. */
237 htab_t debug_info_type_hash;
239 /* Table mapping type .debug_types DIE offsets to types.
240 This is NULL if not allocated yet. */
241 htab_t debug_types_type_hash;
244 static struct dwarf2_per_objfile *dwarf2_per_objfile;
246 /* names of the debugging sections */
248 /* Note that if the debugging section has been compressed, it might
249 have a name like .zdebug_info. */
251 #define INFO_SECTION "debug_info"
252 #define ABBREV_SECTION "debug_abbrev"
253 #define LINE_SECTION "debug_line"
254 #define LOC_SECTION "debug_loc"
255 #define MACINFO_SECTION "debug_macinfo"
256 #define STR_SECTION "debug_str"
257 #define RANGES_SECTION "debug_ranges"
258 #define TYPES_SECTION "debug_types"
259 #define FRAME_SECTION "debug_frame"
260 #define EH_FRAME_SECTION "eh_frame"
261 #define GDB_INDEX_SECTION "gdb_index"
263 /* local data types */
265 /* We hold several abbreviation tables in memory at the same time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
270 /* The data in a compilation unit header, after target2host
271 translation, looks like this. */
272 struct comp_unit_head
276 unsigned char addr_size;
277 unsigned char signed_addr_p;
278 unsigned int abbrev_offset;
280 /* Size of file offsets; either 4 or 8. */
281 unsigned int offset_size;
283 /* Size of the length field; either 4 or 12. */
284 unsigned int initial_length_size;
286 /* Offset to the first byte of this compilation unit header in the
287 .debug_info section, for resolving relative reference dies. */
290 /* Offset to first die in this cu from the start of the cu.
291 This will be the first byte following the compilation unit header. */
292 unsigned int first_die_offset;
295 /* Type used for delaying computation of method physnames.
296 See comments for compute_delayed_physnames. */
297 struct delayed_method_info
299 /* The type to which the method is attached, i.e., its parent class. */
302 /* The index of the method in the type's function fieldlists. */
305 /* The index of the method in the fieldlist. */
308 /* The name of the DIE. */
311 /* The DIE associated with this method. */
312 struct die_info *die;
315 typedef struct delayed_method_info delayed_method_info;
316 DEF_VEC_O (delayed_method_info);
318 /* Internal state when decoding a particular compilation unit. */
321 /* The objfile containing this compilation unit. */
322 struct objfile *objfile;
324 /* The header of the compilation unit. */
325 struct comp_unit_head header;
327 /* Base address of this compilation unit. */
328 CORE_ADDR base_address;
330 /* Non-zero if base_address has been set. */
333 struct function_range *first_fn, *last_fn, *cached_fn;
335 /* The language we are debugging. */
336 enum language language;
337 const struct language_defn *language_defn;
339 const char *producer;
341 /* The generic symbol table building routines have separate lists for
342 file scope symbols and all all other scopes (local scopes). So
343 we need to select the right one to pass to add_symbol_to_list().
344 We do it by keeping a pointer to the correct list in list_in_scope.
346 FIXME: The original dwarf code just treated the file scope as the
347 first local scope, and all other local scopes as nested local
348 scopes, and worked fine. Check to see if we really need to
349 distinguish these in buildsym.c. */
350 struct pending **list_in_scope;
352 /* DWARF abbreviation table associated with this compilation unit. */
353 struct abbrev_info **dwarf2_abbrevs;
355 /* Storage for the abbrev table. */
356 struct obstack abbrev_obstack;
358 /* Hash table holding all the loaded partial DIEs. */
361 /* Storage for things with the same lifetime as this read-in compilation
362 unit, including partial DIEs. */
363 struct obstack comp_unit_obstack;
365 /* When multiple dwarf2_cu structures are living in memory, this field
366 chains them all together, so that they can be released efficiently.
367 We will probably also want a generation counter so that most-recently-used
368 compilation units are cached... */
369 struct dwarf2_per_cu_data *read_in_chain;
371 /* Backchain to our per_cu entry if the tree has been built. */
372 struct dwarf2_per_cu_data *per_cu;
374 /* How many compilation units ago was this CU last referenced? */
377 /* A hash table of die offsets for following references. */
380 /* Full DIEs if read in. */
381 struct die_info *dies;
383 /* A set of pointers to dwarf2_per_cu_data objects for compilation
384 units referenced by this one. Only set during full symbol processing;
385 partial symbol tables do not have dependencies. */
388 /* Header data from the line table, during full symbol processing. */
389 struct line_header *line_header;
391 /* A list of methods which need to have physnames computed
392 after all type information has been read. */
393 VEC (delayed_method_info) *method_list;
395 /* Mark used when releasing cached dies. */
396 unsigned int mark : 1;
398 /* This flag will be set if this compilation unit might include
399 inter-compilation-unit references. */
400 unsigned int has_form_ref_addr : 1;
402 /* This flag will be set if this compilation unit includes any
403 DW_TAG_namespace DIEs. If we know that there are explicit
404 DIEs for namespaces, we don't need to try to infer them
405 from mangled names. */
406 unsigned int has_namespace_info : 1;
409 /* Persistent data held for a compilation unit, even when not
410 processing it. We put a pointer to this structure in the
411 read_symtab_private field of the psymtab. If we encounter
412 inter-compilation-unit references, we also maintain a sorted
413 list of all compilation units. */
415 struct dwarf2_per_cu_data
417 /* The start offset and length of this compilation unit. 2**29-1
418 bytes should suffice to store the length of any compilation unit
419 - if it doesn't, GDB will fall over anyway.
420 NOTE: Unlike comp_unit_head.length, this length includes
421 initial_length_size. */
423 unsigned int length : 29;
425 /* Flag indicating this compilation unit will be read in before
426 any of the current compilation units are processed. */
427 unsigned int queued : 1;
429 /* This flag will be set if we need to load absolutely all DIEs
430 for this compilation unit, instead of just the ones we think
431 are interesting. It gets set if we look for a DIE in the
432 hash table and don't find it. */
433 unsigned int load_all_dies : 1;
435 /* Non-zero if this CU is from .debug_types.
436 Otherwise it's from .debug_info. */
437 unsigned int from_debug_types : 1;
439 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
440 of the CU cache it gets reset to NULL again. */
441 struct dwarf2_cu *cu;
443 /* The corresponding objfile. */
444 struct objfile *objfile;
446 /* When using partial symbol tables, the 'psymtab' field is active.
447 Otherwise the 'quick' field is active. */
450 /* The partial symbol table associated with this compilation unit,
451 or NULL for partial units (which do not have an associated
453 struct partial_symtab *psymtab;
455 /* Data needed by the "quick" functions. */
456 struct dwarf2_per_cu_quick_data *quick;
460 /* Entry in the signatured_types hash table. */
462 struct signatured_type
466 /* Offset in .debug_types of the TU (type_unit) for this type. */
469 /* Offset in .debug_types of the type defined by this TU. */
470 unsigned int type_offset;
472 /* The CU(/TU) of this type. */
473 struct dwarf2_per_cu_data per_cu;
476 /* Struct used to pass misc. parameters to read_die_and_children, et
477 al. which are used for both .debug_info and .debug_types dies.
478 All parameters here are unchanging for the life of the call. This
479 struct exists to abstract away the constant parameters of die
482 struct die_reader_specs
484 /* The bfd of this objfile. */
487 /* The CU of the DIE we are parsing. */
488 struct dwarf2_cu *cu;
490 /* Pointer to start of section buffer.
491 This is either the start of .debug_info or .debug_types. */
492 const gdb_byte *buffer;
495 /* The line number information for a compilation unit (found in the
496 .debug_line section) begins with a "statement program header",
497 which contains the following information. */
500 unsigned int total_length;
501 unsigned short version;
502 unsigned int header_length;
503 unsigned char minimum_instruction_length;
504 unsigned char maximum_ops_per_instruction;
505 unsigned char default_is_stmt;
507 unsigned char line_range;
508 unsigned char opcode_base;
510 /* standard_opcode_lengths[i] is the number of operands for the
511 standard opcode whose value is i. This means that
512 standard_opcode_lengths[0] is unused, and the last meaningful
513 element is standard_opcode_lengths[opcode_base - 1]. */
514 unsigned char *standard_opcode_lengths;
516 /* The include_directories table. NOTE! These strings are not
517 allocated with xmalloc; instead, they are pointers into
518 debug_line_buffer. If you try to free them, `free' will get
520 unsigned int num_include_dirs, include_dirs_size;
523 /* The file_names table. NOTE! These strings are not allocated
524 with xmalloc; instead, they are pointers into debug_line_buffer.
525 Don't try to free them directly. */
526 unsigned int num_file_names, file_names_size;
530 unsigned int dir_index;
531 unsigned int mod_time;
533 int included_p; /* Non-zero if referenced by the Line Number Program. */
534 struct symtab *symtab; /* The associated symbol table, if any. */
537 /* The start and end of the statement program following this
538 header. These point into dwarf2_per_objfile->line_buffer. */
539 gdb_byte *statement_program_start, *statement_program_end;
542 /* When we construct a partial symbol table entry we only
543 need this much information. */
544 struct partial_die_info
546 /* Offset of this DIE. */
549 /* DWARF-2 tag for this DIE. */
550 ENUM_BITFIELD(dwarf_tag) tag : 16;
552 /* Assorted flags describing the data found in this DIE. */
553 unsigned int has_children : 1;
554 unsigned int is_external : 1;
555 unsigned int is_declaration : 1;
556 unsigned int has_type : 1;
557 unsigned int has_specification : 1;
558 unsigned int has_pc_info : 1;
560 /* Flag set if the SCOPE field of this structure has been
562 unsigned int scope_set : 1;
564 /* Flag set if the DIE has a byte_size attribute. */
565 unsigned int has_byte_size : 1;
567 /* Flag set if any of the DIE's children are template arguments. */
568 unsigned int has_template_arguments : 1;
570 /* Flag set if fixup_partial_die has been called on this die. */
571 unsigned int fixup_called : 1;
573 /* The name of this DIE. Normally the value of DW_AT_name, but
574 sometimes a default name for unnamed DIEs. */
577 /* The linkage name, if present. */
578 const char *linkage_name;
580 /* The scope to prepend to our children. This is generally
581 allocated on the comp_unit_obstack, so will disappear
582 when this compilation unit leaves the cache. */
585 /* The location description associated with this DIE, if any. */
586 struct dwarf_block *locdesc;
588 /* If HAS_PC_INFO, the PC range associated with this DIE. */
592 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
593 DW_AT_sibling, if any. */
594 /* NOTE: This member isn't strictly necessary, read_partial_die could
595 return DW_AT_sibling values to its caller load_partial_dies. */
598 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
599 DW_AT_specification (or DW_AT_abstract_origin or
601 unsigned int spec_offset;
603 /* Pointers to this DIE's parent, first child, and next sibling,
605 struct partial_die_info *die_parent, *die_child, *die_sibling;
608 /* This data structure holds the information of an abbrev. */
611 unsigned int number; /* number identifying abbrev */
612 enum dwarf_tag tag; /* dwarf tag */
613 unsigned short has_children; /* boolean */
614 unsigned short num_attrs; /* number of attributes */
615 struct attr_abbrev *attrs; /* an array of attribute descriptions */
616 struct abbrev_info *next; /* next in chain */
621 ENUM_BITFIELD(dwarf_attribute) name : 16;
622 ENUM_BITFIELD(dwarf_form) form : 16;
625 /* Attributes have a name and a value. */
628 ENUM_BITFIELD(dwarf_attribute) name : 16;
629 ENUM_BITFIELD(dwarf_form) form : 15;
631 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
632 field should be in u.str (existing only for DW_STRING) but it is kept
633 here for better struct attribute alignment. */
634 unsigned int string_is_canonical : 1;
639 struct dwarf_block *blk;
643 struct signatured_type *signatured_type;
648 /* This data structure holds a complete die structure. */
651 /* DWARF-2 tag for this DIE. */
652 ENUM_BITFIELD(dwarf_tag) tag : 16;
654 /* Number of attributes */
655 unsigned char num_attrs;
657 /* True if we're presently building the full type name for the
658 type derived from this DIE. */
659 unsigned char building_fullname : 1;
664 /* Offset in .debug_info or .debug_types section. */
667 /* The dies in a compilation unit form an n-ary tree. PARENT
668 points to this die's parent; CHILD points to the first child of
669 this node; and all the children of a given node are chained
670 together via their SIBLING fields. */
671 struct die_info *child; /* Its first child, if any. */
672 struct die_info *sibling; /* Its next sibling, if any. */
673 struct die_info *parent; /* Its parent, if any. */
675 /* An array of attributes, with NUM_ATTRS elements. There may be
676 zero, but it's not common and zero-sized arrays are not
677 sufficiently portable C. */
678 struct attribute attrs[1];
681 struct function_range
684 CORE_ADDR lowpc, highpc;
686 struct function_range *next;
689 /* Get at parts of an attribute structure. */
691 #define DW_STRING(attr) ((attr)->u.str)
692 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
693 #define DW_UNSND(attr) ((attr)->u.unsnd)
694 #define DW_BLOCK(attr) ((attr)->u.blk)
695 #define DW_SND(attr) ((attr)->u.snd)
696 #define DW_ADDR(attr) ((attr)->u.addr)
697 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
699 /* Blocks are a bunch of untyped bytes. */
706 #ifndef ATTR_ALLOC_CHUNK
707 #define ATTR_ALLOC_CHUNK 4
710 /* Allocate fields for structs, unions and enums in this size. */
711 #ifndef DW_FIELD_ALLOC_CHUNK
712 #define DW_FIELD_ALLOC_CHUNK 4
715 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
716 but this would require a corresponding change in unpack_field_as_long
718 static int bits_per_byte = 8;
720 /* The routines that read and process dies for a C struct or C++ class
721 pass lists of data member fields and lists of member function fields
722 in an instance of a field_info structure, as defined below. */
725 /* List of data member and baseclasses fields. */
728 struct nextfield *next;
733 *fields, *baseclasses;
735 /* Number of fields (including baseclasses). */
738 /* Number of baseclasses. */
741 /* Set if the accesibility of one of the fields is not public. */
742 int non_public_fields;
744 /* Member function fields array, entries are allocated in the order they
745 are encountered in the object file. */
748 struct nextfnfield *next;
749 struct fn_field fnfield;
753 /* Member function fieldlist array, contains name of possibly overloaded
754 member function, number of overloaded member functions and a pointer
755 to the head of the member function field chain. */
760 struct nextfnfield *head;
764 /* Number of entries in the fnfieldlists array. */
767 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
768 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
769 struct typedef_field_list
771 struct typedef_field field;
772 struct typedef_field_list *next;
775 unsigned typedef_field_list_count;
778 /* One item on the queue of compilation units to read in full symbols
780 struct dwarf2_queue_item
782 struct dwarf2_per_cu_data *per_cu;
783 struct dwarf2_queue_item *next;
786 /* The current queue. */
787 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
789 /* Loaded secondary compilation units are kept in memory until they
790 have not been referenced for the processing of this many
791 compilation units. Set this to zero to disable caching. Cache
792 sizes of up to at least twenty will improve startup time for
793 typical inter-CU-reference binaries, at an obvious memory cost. */
794 static int dwarf2_max_cache_age = 5;
796 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
797 struct cmd_list_element *c, const char *value)
799 fprintf_filtered (file, _("The upper bound on the age of cached "
800 "dwarf2 compilation units is %s.\n"),
805 /* Various complaints about symbol reading that don't abort the process. */
808 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
810 complaint (&symfile_complaints,
811 _("statement list doesn't fit in .debug_line section"));
815 dwarf2_debug_line_missing_file_complaint (void)
817 complaint (&symfile_complaints,
818 _(".debug_line section has line data without a file"));
822 dwarf2_debug_line_missing_end_sequence_complaint (void)
824 complaint (&symfile_complaints,
825 _(".debug_line section has line "
826 "program sequence without an end"));
830 dwarf2_complex_location_expr_complaint (void)
832 complaint (&symfile_complaints, _("location expression too complex"));
836 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
839 complaint (&symfile_complaints,
840 _("const value length mismatch for '%s', got %d, expected %d"),
845 dwarf2_macros_too_long_complaint (void)
847 complaint (&symfile_complaints,
848 _("macro info runs off end of `.debug_macinfo' section"));
852 dwarf2_macro_malformed_definition_complaint (const char *arg1)
854 complaint (&symfile_complaints,
855 _("macro debug info contains a "
856 "malformed macro definition:\n`%s'"),
861 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
863 complaint (&symfile_complaints,
864 _("invalid attribute class or form for '%s' in '%s'"),
868 /* local function prototypes */
870 static void dwarf2_locate_sections (bfd *, asection *, void *);
872 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
875 static void dwarf2_build_psymtabs_hard (struct objfile *);
877 static void scan_partial_symbols (struct partial_die_info *,
878 CORE_ADDR *, CORE_ADDR *,
879 int, struct dwarf2_cu *);
881 static void add_partial_symbol (struct partial_die_info *,
884 static void add_partial_namespace (struct partial_die_info *pdi,
885 CORE_ADDR *lowpc, CORE_ADDR *highpc,
886 int need_pc, struct dwarf2_cu *cu);
888 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
889 CORE_ADDR *highpc, int need_pc,
890 struct dwarf2_cu *cu);
892 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
893 struct dwarf2_cu *cu);
895 static void add_partial_subprogram (struct partial_die_info *pdi,
896 CORE_ADDR *lowpc, CORE_ADDR *highpc,
897 int need_pc, struct dwarf2_cu *cu);
899 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
900 gdb_byte *buffer, gdb_byte *info_ptr,
901 bfd *abfd, struct dwarf2_cu *cu);
903 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
905 static void psymtab_to_symtab_1 (struct partial_symtab *);
907 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
909 static void dwarf2_free_abbrev_table (void *);
911 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
914 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
917 static struct partial_die_info *load_partial_dies (bfd *,
918 gdb_byte *, gdb_byte *,
919 int, struct dwarf2_cu *);
921 static gdb_byte *read_partial_die (struct partial_die_info *,
922 struct abbrev_info *abbrev,
924 gdb_byte *, gdb_byte *,
927 static struct partial_die_info *find_partial_die (unsigned int,
930 static void fixup_partial_die (struct partial_die_info *,
933 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
934 bfd *, gdb_byte *, struct dwarf2_cu *);
936 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
937 bfd *, gdb_byte *, struct dwarf2_cu *);
939 static unsigned int read_1_byte (bfd *, gdb_byte *);
941 static int read_1_signed_byte (bfd *, gdb_byte *);
943 static unsigned int read_2_bytes (bfd *, gdb_byte *);
945 static unsigned int read_4_bytes (bfd *, gdb_byte *);
947 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
949 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
952 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
954 static LONGEST read_checked_initial_length_and_offset
955 (bfd *, gdb_byte *, const struct comp_unit_head *,
956 unsigned int *, unsigned int *);
958 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
961 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
963 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
965 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
967 static char *read_indirect_string (bfd *, gdb_byte *,
968 const struct comp_unit_head *,
971 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
973 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
975 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
977 static void set_cu_language (unsigned int, struct dwarf2_cu *);
979 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
982 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
986 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
987 struct dwarf2_cu *cu);
989 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
991 static struct die_info *die_specification (struct die_info *die,
992 struct dwarf2_cu **);
994 static void free_line_header (struct line_header *lh);
996 static void add_file_name (struct line_header *, char *, unsigned int,
997 unsigned int, unsigned int);
999 static struct line_header *(dwarf_decode_line_header
1000 (unsigned int offset,
1001 bfd *abfd, struct dwarf2_cu *cu));
1003 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
1004 struct dwarf2_cu *, struct partial_symtab *);
1006 static void dwarf2_start_subfile (char *, const char *, const char *);
1008 static struct symbol *new_symbol (struct die_info *, struct type *,
1009 struct dwarf2_cu *);
1011 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1012 struct dwarf2_cu *, struct symbol *);
1014 static void dwarf2_const_value (struct attribute *, struct symbol *,
1015 struct dwarf2_cu *);
1017 static void dwarf2_const_value_attr (struct attribute *attr,
1020 struct obstack *obstack,
1021 struct dwarf2_cu *cu, long *value,
1023 struct dwarf2_locexpr_baton **baton);
1025 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1027 static int need_gnat_info (struct dwarf2_cu *);
1029 static struct type *die_descriptive_type (struct die_info *,
1030 struct dwarf2_cu *);
1032 static void set_descriptive_type (struct type *, struct die_info *,
1033 struct dwarf2_cu *);
1035 static struct type *die_containing_type (struct die_info *,
1036 struct dwarf2_cu *);
1038 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1039 struct dwarf2_cu *);
1041 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1043 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1045 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1047 static char *typename_concat (struct obstack *obs, const char *prefix,
1048 const char *suffix, int physname,
1049 struct dwarf2_cu *cu);
1051 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1053 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1055 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1057 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1059 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1060 struct dwarf2_cu *, struct partial_symtab *);
1062 static int dwarf2_get_pc_bounds (struct die_info *,
1063 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1064 struct partial_symtab *);
1066 static void get_scope_pc_bounds (struct die_info *,
1067 CORE_ADDR *, CORE_ADDR *,
1068 struct dwarf2_cu *);
1070 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1071 CORE_ADDR, struct dwarf2_cu *);
1073 static void dwarf2_add_field (struct field_info *, struct die_info *,
1074 struct dwarf2_cu *);
1076 static void dwarf2_attach_fields_to_type (struct field_info *,
1077 struct type *, struct dwarf2_cu *);
1079 static void dwarf2_add_member_fn (struct field_info *,
1080 struct die_info *, struct type *,
1081 struct dwarf2_cu *);
1083 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1085 struct dwarf2_cu *);
1087 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1089 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1091 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1093 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1095 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1097 static struct type *read_module_type (struct die_info *die,
1098 struct dwarf2_cu *cu);
1100 static const char *namespace_name (struct die_info *die,
1101 int *is_anonymous, struct dwarf2_cu *);
1103 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1105 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1107 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1108 struct dwarf2_cu *);
1110 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1112 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1114 gdb_byte **new_info_ptr,
1115 struct die_info *parent);
1117 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1119 gdb_byte **new_info_ptr,
1120 struct die_info *parent);
1122 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1124 gdb_byte **new_info_ptr,
1125 struct die_info *parent);
1127 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1128 struct die_info **, gdb_byte *,
1131 static void process_die (struct die_info *, struct dwarf2_cu *);
1133 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1136 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1138 static const char *dwarf2_full_name (char *name,
1139 struct die_info *die,
1140 struct dwarf2_cu *cu);
1142 static struct die_info *dwarf2_extension (struct die_info *die,
1143 struct dwarf2_cu **);
1145 static char *dwarf_tag_name (unsigned int);
1147 static char *dwarf_attr_name (unsigned int);
1149 static char *dwarf_form_name (unsigned int);
1151 static char *dwarf_bool_name (unsigned int);
1153 static char *dwarf_type_encoding_name (unsigned int);
1156 static char *dwarf_cfi_name (unsigned int);
1159 static struct die_info *sibling_die (struct die_info *);
1161 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1163 static void dump_die_for_error (struct die_info *);
1165 static void dump_die_1 (struct ui_file *, int level, int max_level,
1168 /*static*/ void dump_die (struct die_info *, int max_level);
1170 static void store_in_ref_table (struct die_info *,
1171 struct dwarf2_cu *);
1173 static int is_ref_attr (struct attribute *);
1175 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1177 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1179 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1181 struct dwarf2_cu **);
1183 static struct die_info *follow_die_ref (struct die_info *,
1185 struct dwarf2_cu **);
1187 static struct die_info *follow_die_sig (struct die_info *,
1189 struct dwarf2_cu **);
1191 static void read_signatured_type_at_offset (struct objfile *objfile,
1192 unsigned int offset);
1194 static void read_signatured_type (struct objfile *,
1195 struct signatured_type *type_sig);
1197 /* memory allocation interface */
1199 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1201 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1203 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1205 static void initialize_cu_func_list (struct dwarf2_cu *);
1207 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1208 struct dwarf2_cu *);
1210 static void dwarf_decode_macros (struct line_header *, unsigned int,
1211 char *, bfd *, struct dwarf2_cu *);
1213 static int attr_form_is_block (struct attribute *);
1215 static int attr_form_is_section_offset (struct attribute *);
1217 static int attr_form_is_constant (struct attribute *);
1219 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1220 struct dwarf2_loclist_baton *baton,
1221 struct attribute *attr);
1223 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1225 struct dwarf2_cu *cu);
1227 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1228 struct abbrev_info *abbrev,
1229 struct dwarf2_cu *cu);
1231 static void free_stack_comp_unit (void *);
1233 static hashval_t partial_die_hash (const void *item);
1235 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1237 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1238 (unsigned int offset, struct objfile *objfile);
1240 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1241 (unsigned int offset, struct objfile *objfile);
1243 static void init_one_comp_unit (struct dwarf2_cu *cu,
1244 struct objfile *objfile);
1246 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1247 struct die_info *comp_unit_die);
1249 static void free_one_comp_unit (void *);
1251 static void free_cached_comp_units (void *);
1253 static void age_cached_comp_units (void);
1255 static void free_one_cached_comp_unit (void *);
1257 static struct type *set_die_type (struct die_info *, struct type *,
1258 struct dwarf2_cu *);
1260 static void create_all_comp_units (struct objfile *);
1262 static int create_debug_types_hash_table (struct objfile *objfile);
1264 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1267 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1269 static void dwarf2_add_dependence (struct dwarf2_cu *,
1270 struct dwarf2_per_cu_data *);
1272 static void dwarf2_mark (struct dwarf2_cu *);
1274 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1276 static struct type *get_die_type_at_offset (unsigned int,
1277 struct dwarf2_per_cu_data *per_cu);
1279 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1281 static void dwarf2_release_queue (void *dummy);
1283 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1284 struct objfile *objfile);
1286 static void process_queue (struct objfile *objfile);
1288 static void find_file_and_directory (struct die_info *die,
1289 struct dwarf2_cu *cu,
1290 char **name, char **comp_dir);
1292 static char *file_full_name (int file, struct line_header *lh,
1293 const char *comp_dir);
1295 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1298 unsigned int buffer_size,
1301 static void init_cu_die_reader (struct die_reader_specs *reader,
1302 struct dwarf2_cu *cu);
1304 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1308 /* Convert VALUE between big- and little-endian. */
1310 byte_swap (offset_type value)
1314 result = (value & 0xff) << 24;
1315 result |= (value & 0xff00) << 8;
1316 result |= (value & 0xff0000) >> 8;
1317 result |= (value & 0xff000000) >> 24;
1321 #define MAYBE_SWAP(V) byte_swap (V)
1324 #define MAYBE_SWAP(V) (V)
1325 #endif /* WORDS_BIGENDIAN */
1327 /* The suffix for an index file. */
1328 #define INDEX_SUFFIX ".gdb-index"
1330 static const char *dwarf2_physname (char *name, struct die_info *die,
1331 struct dwarf2_cu *cu);
1333 /* Try to locate the sections we need for DWARF 2 debugging
1334 information and return true if we have enough to do something. */
1337 dwarf2_has_info (struct objfile *objfile)
1339 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1340 if (!dwarf2_per_objfile)
1342 /* Initialize per-objfile state. */
1343 struct dwarf2_per_objfile *data
1344 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1346 memset (data, 0, sizeof (*data));
1347 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1348 dwarf2_per_objfile = data;
1350 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
1351 dwarf2_per_objfile->objfile = objfile;
1353 return (dwarf2_per_objfile->info.asection != NULL
1354 && dwarf2_per_objfile->abbrev.asection != NULL);
1357 /* When loading sections, we can either look for ".<name>", or for
1358 * ".z<name>", which indicates a compressed section. */
1361 section_is_p (const char *section_name, const char *name)
1363 return (section_name[0] == '.'
1364 && (strcmp (section_name + 1, name) == 0
1365 || (section_name[1] == 'z'
1366 && strcmp (section_name + 2, name) == 0)));
1369 /* This function is mapped across the sections and remembers the
1370 offset and size of each of the debugging sections we are interested
1374 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
1376 if (section_is_p (sectp->name, INFO_SECTION))
1378 dwarf2_per_objfile->info.asection = sectp;
1379 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1381 else if (section_is_p (sectp->name, ABBREV_SECTION))
1383 dwarf2_per_objfile->abbrev.asection = sectp;
1384 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1386 else if (section_is_p (sectp->name, LINE_SECTION))
1388 dwarf2_per_objfile->line.asection = sectp;
1389 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1391 else if (section_is_p (sectp->name, LOC_SECTION))
1393 dwarf2_per_objfile->loc.asection = sectp;
1394 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1396 else if (section_is_p (sectp->name, MACINFO_SECTION))
1398 dwarf2_per_objfile->macinfo.asection = sectp;
1399 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1401 else if (section_is_p (sectp->name, STR_SECTION))
1403 dwarf2_per_objfile->str.asection = sectp;
1404 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1406 else if (section_is_p (sectp->name, FRAME_SECTION))
1408 dwarf2_per_objfile->frame.asection = sectp;
1409 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1411 else if (section_is_p (sectp->name, EH_FRAME_SECTION))
1413 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1415 if (aflag & SEC_HAS_CONTENTS)
1417 dwarf2_per_objfile->eh_frame.asection = sectp;
1418 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1421 else if (section_is_p (sectp->name, RANGES_SECTION))
1423 dwarf2_per_objfile->ranges.asection = sectp;
1424 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1426 else if (section_is_p (sectp->name, TYPES_SECTION))
1428 dwarf2_per_objfile->types.asection = sectp;
1429 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
1431 else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
1433 dwarf2_per_objfile->gdb_index.asection = sectp;
1434 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1437 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1438 && bfd_section_vma (abfd, sectp) == 0)
1439 dwarf2_per_objfile->has_section_at_zero = 1;
1442 /* Decompress a section that was compressed using zlib. Store the
1443 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1446 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1447 gdb_byte **outbuf, bfd_size_type *outsize)
1449 bfd *abfd = objfile->obfd;
1451 error (_("Support for zlib-compressed DWARF data (from '%s') "
1452 "is disabled in this copy of GDB"),
1453 bfd_get_filename (abfd));
1455 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1456 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1457 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1458 bfd_size_type uncompressed_size;
1459 gdb_byte *uncompressed_buffer;
1462 int header_size = 12;
1464 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1465 || bfd_bread (compressed_buffer,
1466 compressed_size, abfd) != compressed_size)
1467 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1468 bfd_get_filename (abfd));
1470 /* Read the zlib header. In this case, it should be "ZLIB" followed
1471 by the uncompressed section size, 8 bytes in big-endian order. */
1472 if (compressed_size < header_size
1473 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1474 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1475 bfd_get_filename (abfd));
1476 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1477 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1478 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1479 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1480 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1481 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1482 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1483 uncompressed_size += compressed_buffer[11];
1485 /* It is possible the section consists of several compressed
1486 buffers concatenated together, so we uncompress in a loop. */
1490 strm.avail_in = compressed_size - header_size;
1491 strm.next_in = (Bytef*) compressed_buffer + header_size;
1492 strm.avail_out = uncompressed_size;
1493 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1495 rc = inflateInit (&strm);
1496 while (strm.avail_in > 0)
1499 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1500 bfd_get_filename (abfd), rc);
1501 strm.next_out = ((Bytef*) uncompressed_buffer
1502 + (uncompressed_size - strm.avail_out));
1503 rc = inflate (&strm, Z_FINISH);
1504 if (rc != Z_STREAM_END)
1505 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1506 bfd_get_filename (abfd), rc);
1507 rc = inflateReset (&strm);
1509 rc = inflateEnd (&strm);
1511 || strm.avail_out != 0)
1512 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1513 bfd_get_filename (abfd), rc);
1515 do_cleanups (cleanup);
1516 *outbuf = uncompressed_buffer;
1517 *outsize = uncompressed_size;
1521 /* A helper function that decides whether a section is empty. */
1524 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1526 return info->asection == NULL || info->size == 0;
1529 /* Read the contents of the section SECTP from object file specified by
1530 OBJFILE, store info about the section into INFO.
1531 If the section is compressed, uncompress it before returning. */
1534 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1536 bfd *abfd = objfile->obfd;
1537 asection *sectp = info->asection;
1538 gdb_byte *buf, *retbuf;
1539 unsigned char header[4];
1543 info->buffer = NULL;
1544 info->was_mmapped = 0;
1547 if (dwarf2_section_empty_p (info))
1550 /* Check if the file has a 4-byte header indicating compression. */
1551 if (info->size > sizeof (header)
1552 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1553 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1555 /* Upon decompression, update the buffer and its size. */
1556 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1558 zlib_decompress_section (objfile, sectp, &info->buffer,
1566 pagesize = getpagesize ();
1568 /* Only try to mmap sections which are large enough: we don't want to
1569 waste space due to fragmentation. Also, only try mmap for sections
1570 without relocations. */
1572 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1574 off_t pg_offset = sectp->filepos & ~(pagesize - 1);
1575 size_t map_length = info->size + sectp->filepos - pg_offset;
1576 caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
1577 MAP_PRIVATE, pg_offset);
1579 if (retbuf != MAP_FAILED)
1581 info->was_mmapped = 1;
1582 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
1583 #if HAVE_POSIX_MADVISE
1584 posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
1591 /* If we get here, we are a normal, not-compressed section. */
1593 = obstack_alloc (&objfile->objfile_obstack, info->size);
1595 /* When debugging .o files, we may need to apply relocations; see
1596 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1597 We never compress sections in .o files, so we only need to
1598 try this when the section is not compressed. */
1599 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1602 info->buffer = retbuf;
1606 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1607 || bfd_bread (buf, info->size, abfd) != info->size)
1608 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1609 bfd_get_filename (abfd));
1612 /* A helper function that returns the size of a section in a safe way.
1613 If you are positive that the section has been read before using the
1614 size, then it is safe to refer to the dwarf2_section_info object's
1615 "size" field directly. In other cases, you must call this
1616 function, because for compressed sections the size field is not set
1617 correctly until the section has been read. */
1619 static bfd_size_type
1620 dwarf2_section_size (struct objfile *objfile,
1621 struct dwarf2_section_info *info)
1624 dwarf2_read_section (objfile, info);
1628 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1632 dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
1633 asection **sectp, gdb_byte **bufp,
1634 bfd_size_type *sizep)
1636 struct dwarf2_per_objfile *data
1637 = objfile_data (objfile, dwarf2_objfile_data_key);
1638 struct dwarf2_section_info *info;
1640 /* We may see an objfile without any DWARF, in which case we just
1649 if (section_is_p (section_name, EH_FRAME_SECTION))
1650 info = &data->eh_frame;
1651 else if (section_is_p (section_name, FRAME_SECTION))
1652 info = &data->frame;
1654 gdb_assert_not_reached ("unexpected section");
1656 dwarf2_read_section (objfile, info);
1658 *sectp = info->asection;
1659 *bufp = info->buffer;
1660 *sizep = info->size;
1664 /* DWARF quick_symbols_functions support. */
1666 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1667 unique line tables, so we maintain a separate table of all .debug_line
1668 derived entries to support the sharing.
1669 All the quick functions need is the list of file names. We discard the
1670 line_header when we're done and don't need to record it here. */
1671 struct quick_file_names
1673 /* The offset in .debug_line of the line table. We hash on this. */
1674 unsigned int offset;
1676 /* The number of entries in file_names, real_names. */
1677 unsigned int num_file_names;
1679 /* The file names from the line table, after being run through
1681 const char **file_names;
1683 /* The file names from the line table after being run through
1684 gdb_realpath. These are computed lazily. */
1685 const char **real_names;
1688 /* When using the index (and thus not using psymtabs), each CU has an
1689 object of this type. This is used to hold information needed by
1690 the various "quick" methods. */
1691 struct dwarf2_per_cu_quick_data
1693 /* The file table. This can be NULL if there was no file table
1694 or it's currently not read in.
1695 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1696 struct quick_file_names *file_names;
1698 /* The corresponding symbol table. This is NULL if symbols for this
1699 CU have not yet been read. */
1700 struct symtab *symtab;
1702 /* A temporary mark bit used when iterating over all CUs in
1703 expand_symtabs_matching. */
1704 unsigned int mark : 1;
1706 /* True if we've tried to read the file table and found there isn't one.
1707 There will be no point in trying to read it again next time. */
1708 unsigned int no_file_data : 1;
1711 /* Hash function for a quick_file_names. */
1714 hash_file_name_entry (const void *e)
1716 const struct quick_file_names *file_data = e;
1718 return file_data->offset;
1721 /* Equality function for a quick_file_names. */
1724 eq_file_name_entry (const void *a, const void *b)
1726 const struct quick_file_names *ea = a;
1727 const struct quick_file_names *eb = b;
1729 return ea->offset == eb->offset;
1732 /* Delete function for a quick_file_names. */
1735 delete_file_name_entry (void *e)
1737 struct quick_file_names *file_data = e;
1740 for (i = 0; i < file_data->num_file_names; ++i)
1742 xfree ((void*) file_data->file_names[i]);
1743 if (file_data->real_names)
1744 xfree ((void*) file_data->real_names[i]);
1747 /* The space for the struct itself lives on objfile_obstack,
1748 so we don't free it here. */
1751 /* Create a quick_file_names hash table. */
1754 create_quick_file_names_table (unsigned int nr_initial_entries)
1756 return htab_create_alloc (nr_initial_entries,
1757 hash_file_name_entry, eq_file_name_entry,
1758 delete_file_name_entry, xcalloc, xfree);
1761 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1765 dw2_do_instantiate_symtab (struct objfile *objfile,
1766 struct dwarf2_per_cu_data *per_cu)
1768 struct cleanup *back_to;
1770 back_to = make_cleanup (dwarf2_release_queue, NULL);
1772 queue_comp_unit (per_cu, objfile);
1774 if (per_cu->from_debug_types)
1775 read_signatured_type_at_offset (objfile, per_cu->offset);
1777 load_full_comp_unit (per_cu, objfile);
1779 process_queue (objfile);
1781 /* Age the cache, releasing compilation units that have not
1782 been used recently. */
1783 age_cached_comp_units ();
1785 do_cleanups (back_to);
1788 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1789 the objfile from which this CU came. Returns the resulting symbol
1792 static struct symtab *
1793 dw2_instantiate_symtab (struct objfile *objfile,
1794 struct dwarf2_per_cu_data *per_cu)
1796 if (!per_cu->v.quick->symtab)
1798 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1799 increment_reading_symtab ();
1800 dw2_do_instantiate_symtab (objfile, per_cu);
1801 do_cleanups (back_to);
1803 return per_cu->v.quick->symtab;
1806 /* Return the CU given its index. */
1808 static struct dwarf2_per_cu_data *
1809 dw2_get_cu (int index)
1811 if (index >= dwarf2_per_objfile->n_comp_units)
1813 index -= dwarf2_per_objfile->n_comp_units;
1814 return dwarf2_per_objfile->type_comp_units[index];
1816 return dwarf2_per_objfile->all_comp_units[index];
1819 /* A helper function that knows how to read a 64-bit value in a way
1820 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1824 extract_cu_value (const char *bytes, ULONGEST *result)
1826 if (sizeof (ULONGEST) < 8)
1830 /* Ignore the upper 4 bytes if they are all zero. */
1831 for (i = 0; i < 4; ++i)
1832 if (bytes[i + 4] != 0)
1835 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1838 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1842 /* Read the CU list from the mapped index, and use it to create all
1843 the CU objects for this objfile. Return 0 if something went wrong,
1844 1 if everything went ok. */
1847 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1848 offset_type cu_list_elements)
1852 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1853 dwarf2_per_objfile->all_comp_units
1854 = obstack_alloc (&objfile->objfile_obstack,
1855 dwarf2_per_objfile->n_comp_units
1856 * sizeof (struct dwarf2_per_cu_data *));
1858 for (i = 0; i < cu_list_elements; i += 2)
1860 struct dwarf2_per_cu_data *the_cu;
1861 ULONGEST offset, length;
1863 if (!extract_cu_value (cu_list, &offset)
1864 || !extract_cu_value (cu_list + 8, &length))
1868 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1869 struct dwarf2_per_cu_data);
1870 the_cu->offset = offset;
1871 the_cu->length = length;
1872 the_cu->objfile = objfile;
1873 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1874 struct dwarf2_per_cu_quick_data);
1875 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1881 /* Create the signatured type hash table from the index. */
1884 create_signatured_type_table_from_index (struct objfile *objfile,
1885 const gdb_byte *bytes,
1886 offset_type elements)
1889 htab_t sig_types_hash;
1891 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1892 dwarf2_per_objfile->type_comp_units
1893 = obstack_alloc (&objfile->objfile_obstack,
1894 dwarf2_per_objfile->n_type_comp_units
1895 * sizeof (struct dwarf2_per_cu_data *));
1897 sig_types_hash = allocate_signatured_type_table (objfile);
1899 for (i = 0; i < elements; i += 3)
1901 struct signatured_type *type_sig;
1902 ULONGEST offset, type_offset, signature;
1905 if (!extract_cu_value (bytes, &offset)
1906 || !extract_cu_value (bytes + 8, &type_offset))
1908 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1911 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1912 struct signatured_type);
1913 type_sig->signature = signature;
1914 type_sig->offset = offset;
1915 type_sig->type_offset = type_offset;
1916 type_sig->per_cu.from_debug_types = 1;
1917 type_sig->per_cu.offset = offset;
1918 type_sig->per_cu.objfile = objfile;
1919 type_sig->per_cu.v.quick
1920 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1921 struct dwarf2_per_cu_quick_data);
1923 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
1926 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
1929 dwarf2_per_objfile->signatured_types = sig_types_hash;
1934 /* Read the address map data from the mapped index, and use it to
1935 populate the objfile's psymtabs_addrmap. */
1938 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
1940 const gdb_byte *iter, *end;
1941 struct obstack temp_obstack;
1942 struct addrmap *mutable_map;
1943 struct cleanup *cleanup;
1946 obstack_init (&temp_obstack);
1947 cleanup = make_cleanup_obstack_free (&temp_obstack);
1948 mutable_map = addrmap_create_mutable (&temp_obstack);
1950 iter = index->address_table;
1951 end = iter + index->address_table_size;
1953 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1957 ULONGEST hi, lo, cu_index;
1958 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1960 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
1962 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
1965 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
1966 dw2_get_cu (cu_index));
1969 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
1970 &objfile->objfile_obstack);
1971 do_cleanups (cleanup);
1974 /* The hash function for strings in the mapped index. This is the same as
1975 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1976 implementation. This is necessary because the hash function is tied to the
1977 format of the mapped index file. The hash values do not have to match with
1980 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
1983 mapped_index_string_hash (int index_version, const void *p)
1985 const unsigned char *str = (const unsigned char *) p;
1989 while ((c = *str++) != 0)
1991 if (index_version >= 5)
1993 r = r * 67 + c - 113;
1999 /* Find a slot in the mapped index INDEX for the object named NAME.
2000 If NAME is found, set *VEC_OUT to point to the CU vector in the
2001 constant pool and return 1. If NAME cannot be found, return 0. */
2004 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2005 offset_type **vec_out)
2007 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2009 offset_type slot, step;
2010 int (*cmp) (const char *, const char *);
2012 if (current_language->la_language == language_cplus
2013 || current_language->la_language == language_java
2014 || current_language->la_language == language_fortran)
2016 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2018 const char *paren = strchr (name, '(');
2024 dup = xmalloc (paren - name + 1);
2025 memcpy (dup, name, paren - name);
2026 dup[paren - name] = 0;
2028 make_cleanup (xfree, dup);
2033 /* Index version 4 did not support case insensitive searches. But the
2034 indexes for case insensitive languages are built in lowercase, therefore
2035 simulate our NAME being searched is also lowercased. */
2036 hash = mapped_index_string_hash ((index->version == 4
2037 && case_sensitivity == case_sensitive_off
2038 ? 5 : index->version),
2041 slot = hash & (index->symbol_table_slots - 1);
2042 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2043 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2047 /* Convert a slot number to an offset into the table. */
2048 offset_type i = 2 * slot;
2050 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2052 do_cleanups (back_to);
2056 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2057 if (!cmp (name, str))
2059 *vec_out = (offset_type *) (index->constant_pool
2060 + MAYBE_SWAP (index->symbol_table[i + 1]));
2061 do_cleanups (back_to);
2065 slot = (slot + step) & (index->symbol_table_slots - 1);
2069 /* Read the index file. If everything went ok, initialize the "quick"
2070 elements of all the CUs and return 1. Otherwise, return 0. */
2073 dwarf2_read_index (struct objfile *objfile)
2076 struct mapped_index *map;
2077 offset_type *metadata;
2078 const gdb_byte *cu_list;
2079 const gdb_byte *types_list = NULL;
2080 offset_type version, cu_list_elements;
2081 offset_type types_list_elements = 0;
2084 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2087 /* Older elfutils strip versions could keep the section in the main
2088 executable while splitting it for the separate debug info file. */
2089 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2090 & SEC_HAS_CONTENTS) == 0)
2093 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2095 addr = dwarf2_per_objfile->gdb_index.buffer;
2096 /* Version check. */
2097 version = MAYBE_SWAP (*(offset_type *) addr);
2098 /* Versions earlier than 3 emitted every copy of a psymbol. This
2099 causes the index to behave very poorly for certain requests. Version 3
2100 contained incomplete addrmap. So, it seems better to just ignore such
2101 indices. Index version 4 uses a different hash function than index
2102 version 5 and later. */
2105 /* Indexes with higher version than the one supported by GDB may be no
2106 longer backward compatible. */
2110 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2111 map->version = version;
2112 map->total_size = dwarf2_per_objfile->gdb_index.size;
2114 metadata = (offset_type *) (addr + sizeof (offset_type));
2117 cu_list = addr + MAYBE_SWAP (metadata[i]);
2118 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2122 types_list = addr + MAYBE_SWAP (metadata[i]);
2123 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2124 - MAYBE_SWAP (metadata[i]))
2128 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2129 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2130 - MAYBE_SWAP (metadata[i]));
2133 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2134 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2135 - MAYBE_SWAP (metadata[i]))
2136 / (2 * sizeof (offset_type)));
2139 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2141 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2144 if (types_list_elements
2145 && !create_signatured_type_table_from_index (objfile, types_list,
2146 types_list_elements))
2149 create_addrmap_from_index (objfile, map);
2151 dwarf2_per_objfile->index_table = map;
2152 dwarf2_per_objfile->using_index = 1;
2153 dwarf2_per_objfile->quick_file_names_table =
2154 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2159 /* A helper for the "quick" functions which sets the global
2160 dwarf2_per_objfile according to OBJFILE. */
2163 dw2_setup (struct objfile *objfile)
2165 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2166 gdb_assert (dwarf2_per_objfile);
2169 /* A helper for the "quick" functions which attempts to read the line
2170 table for THIS_CU. */
2172 static struct quick_file_names *
2173 dw2_get_file_names (struct objfile *objfile,
2174 struct dwarf2_per_cu_data *this_cu)
2176 bfd *abfd = objfile->obfd;
2177 struct line_header *lh;
2178 struct attribute *attr;
2179 struct cleanup *cleanups;
2180 struct die_info *comp_unit_die;
2181 struct dwarf2_section_info* sec;
2182 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2183 int has_children, i;
2184 struct dwarf2_cu cu;
2185 unsigned int bytes_read, buffer_size;
2186 struct die_reader_specs reader_specs;
2187 char *name, *comp_dir;
2189 struct quick_file_names *qfn;
2190 unsigned int line_offset;
2192 if (this_cu->v.quick->file_names != NULL)
2193 return this_cu->v.quick->file_names;
2194 /* If we know there is no line data, no point in looking again. */
2195 if (this_cu->v.quick->no_file_data)
2198 init_one_comp_unit (&cu, objfile);
2199 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2201 if (this_cu->from_debug_types)
2202 sec = &dwarf2_per_objfile->types;
2204 sec = &dwarf2_per_objfile->info;
2205 dwarf2_read_section (objfile, sec);
2206 buffer_size = sec->size;
2207 buffer = sec->buffer;
2208 info_ptr = buffer + this_cu->offset;
2209 beg_of_comp_unit = info_ptr;
2211 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2212 buffer, buffer_size,
2215 /* Complete the cu_header. */
2216 cu.header.offset = beg_of_comp_unit - buffer;
2217 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2220 cu.per_cu = this_cu;
2222 dwarf2_read_abbrevs (abfd, &cu);
2223 make_cleanup (dwarf2_free_abbrev_table, &cu);
2225 if (this_cu->from_debug_types)
2226 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2227 init_cu_die_reader (&reader_specs, &cu);
2228 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2234 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2237 struct quick_file_names find_entry;
2239 line_offset = DW_UNSND (attr);
2241 /* We may have already read in this line header (TU line header sharing).
2242 If we have we're done. */
2243 find_entry.offset = line_offset;
2244 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2245 &find_entry, INSERT);
2248 do_cleanups (cleanups);
2249 this_cu->v.quick->file_names = *slot;
2253 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2257 do_cleanups (cleanups);
2258 this_cu->v.quick->no_file_data = 1;
2262 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2263 qfn->offset = line_offset;
2264 gdb_assert (slot != NULL);
2267 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2269 qfn->num_file_names = lh->num_file_names;
2270 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2271 lh->num_file_names * sizeof (char *));
2272 for (i = 0; i < lh->num_file_names; ++i)
2273 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2274 qfn->real_names = NULL;
2276 free_line_header (lh);
2277 do_cleanups (cleanups);
2279 this_cu->v.quick->file_names = qfn;
2283 /* A helper for the "quick" functions which computes and caches the
2284 real path for a given file name from the line table. */
2287 dw2_get_real_path (struct objfile *objfile,
2288 struct quick_file_names *qfn, int index)
2290 if (qfn->real_names == NULL)
2291 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2292 qfn->num_file_names, sizeof (char *));
2294 if (qfn->real_names[index] == NULL)
2295 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2297 return qfn->real_names[index];
2300 static struct symtab *
2301 dw2_find_last_source_symtab (struct objfile *objfile)
2305 dw2_setup (objfile);
2306 index = dwarf2_per_objfile->n_comp_units - 1;
2307 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2310 /* Traversal function for dw2_forget_cached_source_info. */
2313 dw2_free_cached_file_names (void **slot, void *info)
2315 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2317 if (file_data->real_names)
2321 for (i = 0; i < file_data->num_file_names; ++i)
2323 xfree ((void*) file_data->real_names[i]);
2324 file_data->real_names[i] = NULL;
2332 dw2_forget_cached_source_info (struct objfile *objfile)
2334 dw2_setup (objfile);
2336 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2337 dw2_free_cached_file_names, NULL);
2341 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2342 const char *full_path, const char *real_path,
2343 struct symtab **result)
2346 int check_basename = lbasename (name) == name;
2347 struct dwarf2_per_cu_data *base_cu = NULL;
2349 dw2_setup (objfile);
2351 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2352 + dwarf2_per_objfile->n_type_comp_units); ++i)
2355 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2356 struct quick_file_names *file_data;
2358 if (per_cu->v.quick->symtab)
2361 file_data = dw2_get_file_names (objfile, per_cu);
2362 if (file_data == NULL)
2365 for (j = 0; j < file_data->num_file_names; ++j)
2367 const char *this_name = file_data->file_names[j];
2369 if (FILENAME_CMP (name, this_name) == 0)
2371 *result = dw2_instantiate_symtab (objfile, per_cu);
2375 if (check_basename && ! base_cu
2376 && FILENAME_CMP (lbasename (this_name), name) == 0)
2379 if (full_path != NULL)
2381 const char *this_real_name = dw2_get_real_path (objfile,
2384 if (this_real_name != NULL
2385 && FILENAME_CMP (full_path, this_real_name) == 0)
2387 *result = dw2_instantiate_symtab (objfile, per_cu);
2392 if (real_path != NULL)
2394 const char *this_real_name = dw2_get_real_path (objfile,
2397 if (this_real_name != NULL
2398 && FILENAME_CMP (real_path, this_real_name) == 0)
2400 *result = dw2_instantiate_symtab (objfile, per_cu);
2409 *result = dw2_instantiate_symtab (objfile, base_cu);
2416 static struct symtab *
2417 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2418 const char *name, domain_enum domain)
2420 /* We do all the work in the pre_expand_symtabs_matching hook
2425 /* A helper function that expands all symtabs that hold an object
2429 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2431 dw2_setup (objfile);
2433 /* index_table is NULL if OBJF_READNOW. */
2434 if (dwarf2_per_objfile->index_table)
2438 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2441 offset_type i, len = MAYBE_SWAP (*vec);
2442 for (i = 0; i < len; ++i)
2444 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2445 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2447 dw2_instantiate_symtab (objfile, per_cu);
2454 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2455 enum block_enum block_kind, const char *name,
2458 dw2_do_expand_symtabs_matching (objfile, name);
2462 dw2_print_stats (struct objfile *objfile)
2466 dw2_setup (objfile);
2468 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2469 + dwarf2_per_objfile->n_type_comp_units); ++i)
2471 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2473 if (!per_cu->v.quick->symtab)
2476 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2480 dw2_dump (struct objfile *objfile)
2482 /* Nothing worth printing. */
2486 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2487 struct section_offsets *delta)
2489 /* There's nothing to relocate here. */
2493 dw2_expand_symtabs_for_function (struct objfile *objfile,
2494 const char *func_name)
2496 dw2_do_expand_symtabs_matching (objfile, func_name);
2500 dw2_expand_all_symtabs (struct objfile *objfile)
2504 dw2_setup (objfile);
2506 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2507 + dwarf2_per_objfile->n_type_comp_units); ++i)
2509 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2511 dw2_instantiate_symtab (objfile, per_cu);
2516 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2517 const char *filename)
2521 dw2_setup (objfile);
2523 /* We don't need to consider type units here.
2524 This is only called for examining code, e.g. expand_line_sal.
2525 There can be an order of magnitude (or more) more type units
2526 than comp units, and we avoid them if we can. */
2528 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2531 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2532 struct quick_file_names *file_data;
2534 if (per_cu->v.quick->symtab)
2537 file_data = dw2_get_file_names (objfile, per_cu);
2538 if (file_data == NULL)
2541 for (j = 0; j < file_data->num_file_names; ++j)
2543 const char *this_name = file_data->file_names[j];
2544 if (FILENAME_CMP (this_name, filename) == 0)
2546 dw2_instantiate_symtab (objfile, per_cu);
2554 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2556 struct dwarf2_per_cu_data *per_cu;
2558 struct quick_file_names *file_data;
2560 dw2_setup (objfile);
2562 /* index_table is NULL if OBJF_READNOW. */
2563 if (!dwarf2_per_objfile->index_table)
2566 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2570 /* Note that this just looks at the very first one named NAME -- but
2571 actually we are looking for a function. find_main_filename
2572 should be rewritten so that it doesn't require a custom hook. It
2573 could just use the ordinary symbol tables. */
2574 /* vec[0] is the length, which must always be >0. */
2575 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2577 file_data = dw2_get_file_names (objfile, per_cu);
2578 if (file_data == NULL)
2581 return file_data->file_names[file_data->num_file_names - 1];
2585 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2586 struct objfile *objfile, int global,
2587 int (*callback) (struct block *,
2588 struct symbol *, void *),
2589 void *data, symbol_compare_ftype *match,
2590 symbol_compare_ftype *ordered_compare)
2592 /* Currently unimplemented; used for Ada. The function can be called if the
2593 current language is Ada for a non-Ada objfile using GNU index. As Ada
2594 does not look for non-Ada symbols this function should just return. */
2598 dw2_expand_symtabs_matching (struct objfile *objfile,
2599 int (*file_matcher) (const char *, void *),
2600 int (*name_matcher) (const char *, void *),
2601 enum search_domain kind,
2606 struct mapped_index *index;
2608 dw2_setup (objfile);
2610 /* index_table is NULL if OBJF_READNOW. */
2611 if (!dwarf2_per_objfile->index_table)
2613 index = dwarf2_per_objfile->index_table;
2615 if (file_matcher != NULL)
2616 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2617 + dwarf2_per_objfile->n_type_comp_units); ++i)
2620 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2621 struct quick_file_names *file_data;
2623 per_cu->v.quick->mark = 0;
2624 if (per_cu->v.quick->symtab)
2627 file_data = dw2_get_file_names (objfile, per_cu);
2628 if (file_data == NULL)
2631 for (j = 0; j < file_data->num_file_names; ++j)
2633 if (file_matcher (file_data->file_names[j], data))
2635 per_cu->v.quick->mark = 1;
2641 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2643 offset_type idx = 2 * iter;
2645 offset_type *vec, vec_len, vec_idx;
2647 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2650 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2652 if (! (*name_matcher) (name, data))
2655 /* The name was matched, now expand corresponding CUs that were
2657 vec = (offset_type *) (index->constant_pool
2658 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2659 vec_len = MAYBE_SWAP (vec[0]);
2660 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2662 struct dwarf2_per_cu_data *per_cu;
2664 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2665 if (file_matcher == NULL || per_cu->v.quick->mark)
2666 dw2_instantiate_symtab (objfile, per_cu);
2671 static struct symtab *
2672 dw2_find_pc_sect_symtab (struct objfile *objfile,
2673 struct minimal_symbol *msymbol,
2675 struct obj_section *section,
2678 struct dwarf2_per_cu_data *data;
2680 dw2_setup (objfile);
2682 if (!objfile->psymtabs_addrmap)
2685 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2689 if (warn_if_readin && data->v.quick->symtab)
2690 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2691 paddress (get_objfile_arch (objfile), pc));
2693 return dw2_instantiate_symtab (objfile, data);
2697 dw2_map_symbol_filenames (struct objfile *objfile,
2698 void (*fun) (const char *, const char *, void *),
2703 dw2_setup (objfile);
2705 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2706 + dwarf2_per_objfile->n_type_comp_units); ++i)
2709 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2710 struct quick_file_names *file_data;
2712 if (per_cu->v.quick->symtab)
2715 file_data = dw2_get_file_names (objfile, per_cu);
2716 if (file_data == NULL)
2719 for (j = 0; j < file_data->num_file_names; ++j)
2721 const char *this_real_name = dw2_get_real_path (objfile, file_data,
2723 (*fun) (file_data->file_names[j], this_real_name, data);
2729 dw2_has_symbols (struct objfile *objfile)
2734 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2737 dw2_find_last_source_symtab,
2738 dw2_forget_cached_source_info,
2741 dw2_pre_expand_symtabs_matching,
2745 dw2_expand_symtabs_for_function,
2746 dw2_expand_all_symtabs,
2747 dw2_expand_symtabs_with_filename,
2748 dw2_find_symbol_file,
2749 dw2_map_matching_symbols,
2750 dw2_expand_symtabs_matching,
2751 dw2_find_pc_sect_symtab,
2752 dw2_map_symbol_filenames
2755 /* Initialize for reading DWARF for this objfile. Return 0 if this
2756 file will use psymtabs, or 1 if using the GNU index. */
2759 dwarf2_initialize_objfile (struct objfile *objfile)
2761 /* If we're about to read full symbols, don't bother with the
2762 indices. In this case we also don't care if some other debug
2763 format is making psymtabs, because they are all about to be
2765 if ((objfile->flags & OBJF_READNOW))
2769 dwarf2_per_objfile->using_index = 1;
2770 create_all_comp_units (objfile);
2771 create_debug_types_hash_table (objfile);
2772 dwarf2_per_objfile->quick_file_names_table =
2773 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2775 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2776 + dwarf2_per_objfile->n_type_comp_units); ++i)
2778 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2780 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2781 struct dwarf2_per_cu_quick_data);
2784 /* Return 1 so that gdb sees the "quick" functions. However,
2785 these functions will be no-ops because we will have expanded
2790 if (dwarf2_read_index (objfile))
2798 /* Build a partial symbol table. */
2801 dwarf2_build_psymtabs (struct objfile *objfile)
2803 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2805 init_psymbol_list (objfile, 1024);
2808 dwarf2_build_psymtabs_hard (objfile);
2811 /* Return TRUE if OFFSET is within CU_HEADER. */
2814 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2816 unsigned int bottom = cu_header->offset;
2817 unsigned int top = (cu_header->offset
2819 + cu_header->initial_length_size);
2821 return (offset >= bottom && offset < top);
2824 /* Read in the comp unit header information from the debug_info at info_ptr.
2825 NOTE: This leaves members offset, first_die_offset to be filled in
2829 read_comp_unit_head (struct comp_unit_head *cu_header,
2830 gdb_byte *info_ptr, bfd *abfd)
2833 unsigned int bytes_read;
2835 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2836 cu_header->initial_length_size = bytes_read;
2837 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2838 info_ptr += bytes_read;
2839 cu_header->version = read_2_bytes (abfd, info_ptr);
2841 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2843 info_ptr += bytes_read;
2844 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2846 signed_addr = bfd_get_sign_extend_vma (abfd);
2847 if (signed_addr < 0)
2848 internal_error (__FILE__, __LINE__,
2849 _("read_comp_unit_head: dwarf from non elf file"));
2850 cu_header->signed_addr_p = signed_addr;
2856 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2857 gdb_byte *buffer, unsigned int buffer_size,
2860 gdb_byte *beg_of_comp_unit = info_ptr;
2862 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2864 if (header->version != 2 && header->version != 3 && header->version != 4)
2865 error (_("Dwarf Error: wrong version in compilation unit header "
2866 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2867 bfd_get_filename (abfd));
2869 if (header->abbrev_offset
2870 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2871 &dwarf2_per_objfile->abbrev))
2872 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2873 "(offset 0x%lx + 6) [in module %s]"),
2874 (long) header->abbrev_offset,
2875 (long) (beg_of_comp_unit - buffer),
2876 bfd_get_filename (abfd));
2878 if (beg_of_comp_unit + header->length + header->initial_length_size
2879 > buffer + buffer_size)
2880 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2881 "(offset 0x%lx + 0) [in module %s]"),
2882 (long) header->length,
2883 (long) (beg_of_comp_unit - buffer),
2884 bfd_get_filename (abfd));
2889 /* Read in the types comp unit header information from .debug_types entry at
2890 types_ptr. The result is a pointer to one past the end of the header. */
2893 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2894 ULONGEST *signature,
2895 gdb_byte *types_ptr, bfd *abfd)
2897 gdb_byte *initial_types_ptr = types_ptr;
2899 dwarf2_read_section (dwarf2_per_objfile->objfile,
2900 &dwarf2_per_objfile->types);
2901 cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer;
2903 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
2905 *signature = read_8_bytes (abfd, types_ptr);
2907 types_ptr += cu_header->offset_size;
2908 cu_header->first_die_offset = types_ptr - initial_types_ptr;
2913 /* Allocate a new partial symtab for file named NAME and mark this new
2914 partial symtab as being an include of PST. */
2917 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
2918 struct objfile *objfile)
2920 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
2922 subpst->section_offsets = pst->section_offsets;
2923 subpst->textlow = 0;
2924 subpst->texthigh = 0;
2926 subpst->dependencies = (struct partial_symtab **)
2927 obstack_alloc (&objfile->objfile_obstack,
2928 sizeof (struct partial_symtab *));
2929 subpst->dependencies[0] = pst;
2930 subpst->number_of_dependencies = 1;
2932 subpst->globals_offset = 0;
2933 subpst->n_global_syms = 0;
2934 subpst->statics_offset = 0;
2935 subpst->n_static_syms = 0;
2936 subpst->symtab = NULL;
2937 subpst->read_symtab = pst->read_symtab;
2940 /* No private part is necessary for include psymtabs. This property
2941 can be used to differentiate between such include psymtabs and
2942 the regular ones. */
2943 subpst->read_symtab_private = NULL;
2946 /* Read the Line Number Program data and extract the list of files
2947 included by the source file represented by PST. Build an include
2948 partial symtab for each of these included files. */
2951 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
2952 struct die_info *die,
2953 struct partial_symtab *pst)
2955 struct objfile *objfile = cu->objfile;
2956 bfd *abfd = objfile->obfd;
2957 struct line_header *lh = NULL;
2958 struct attribute *attr;
2960 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2963 unsigned int line_offset = DW_UNSND (attr);
2965 lh = dwarf_decode_line_header (line_offset, abfd, cu);
2968 return; /* No linetable, so no includes. */
2970 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2971 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
2973 free_line_header (lh);
2977 hash_type_signature (const void *item)
2979 const struct signatured_type *type_sig = item;
2981 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2982 return type_sig->signature;
2986 eq_type_signature (const void *item_lhs, const void *item_rhs)
2988 const struct signatured_type *lhs = item_lhs;
2989 const struct signatured_type *rhs = item_rhs;
2991 return lhs->signature == rhs->signature;
2994 /* Allocate a hash table for signatured types. */
2997 allocate_signatured_type_table (struct objfile *objfile)
2999 return htab_create_alloc_ex (41,
3000 hash_type_signature,
3003 &objfile->objfile_obstack,
3004 hashtab_obstack_allocate,
3005 dummy_obstack_deallocate);
3008 /* A helper function to add a signatured type CU to a list. */
3011 add_signatured_type_cu_to_list (void **slot, void *datum)
3013 struct signatured_type *sigt = *slot;
3014 struct dwarf2_per_cu_data ***datap = datum;
3016 **datap = &sigt->per_cu;
3022 /* Create the hash table of all entries in the .debug_types section.
3023 The result is zero if there is an error (e.g. missing .debug_types section),
3024 otherwise non-zero. */
3027 create_debug_types_hash_table (struct objfile *objfile)
3031 struct dwarf2_per_cu_data **iter;
3033 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
3034 info_ptr = dwarf2_per_objfile->types.buffer;
3036 if (info_ptr == NULL)
3038 dwarf2_per_objfile->signatured_types = NULL;
3042 types_htab = allocate_signatured_type_table (objfile);
3044 if (dwarf2_die_debug)
3045 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3047 while (info_ptr < dwarf2_per_objfile->types.buffer
3048 + dwarf2_per_objfile->types.size)
3050 unsigned int offset;
3051 unsigned int offset_size;
3052 unsigned int type_offset;
3053 unsigned int length, initial_length_size;
3054 unsigned short version;
3056 struct signatured_type *type_sig;
3058 gdb_byte *ptr = info_ptr;
3060 offset = ptr - dwarf2_per_objfile->types.buffer;
3062 /* We need to read the type's signature in order to build the hash
3063 table, but we don't need to read anything else just yet. */
3065 /* Sanity check to ensure entire cu is present. */
3066 length = read_initial_length (objfile->obfd, ptr, &initial_length_size);
3067 if (ptr + length + initial_length_size
3068 > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size)
3070 complaint (&symfile_complaints,
3071 _("debug type entry runs off end "
3072 "of `.debug_types' section, ignored"));
3076 offset_size = initial_length_size == 4 ? 4 : 8;
3077 ptr += initial_length_size;
3078 version = bfd_get_16 (objfile->obfd, ptr);
3080 ptr += offset_size; /* abbrev offset */
3081 ptr += 1; /* address size */
3082 signature = bfd_get_64 (objfile->obfd, ptr);
3084 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3086 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3087 memset (type_sig, 0, sizeof (*type_sig));
3088 type_sig->signature = signature;
3089 type_sig->offset = offset;
3090 type_sig->type_offset = type_offset;
3091 type_sig->per_cu.objfile = objfile;
3092 type_sig->per_cu.from_debug_types = 1;
3094 slot = htab_find_slot (types_htab, type_sig, INSERT);
3095 gdb_assert (slot != NULL);
3098 if (dwarf2_die_debug)
3099 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3100 offset, phex (signature, sizeof (signature)));
3102 info_ptr = info_ptr + initial_length_size + length;
3105 dwarf2_per_objfile->signatured_types = types_htab;
3107 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3108 dwarf2_per_objfile->type_comp_units
3109 = obstack_alloc (&objfile->objfile_obstack,
3110 dwarf2_per_objfile->n_type_comp_units
3111 * sizeof (struct dwarf2_per_cu_data *));
3112 iter = &dwarf2_per_objfile->type_comp_units[0];
3113 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3114 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3115 == dwarf2_per_objfile->n_type_comp_units);
3120 /* Lookup a signature based type.
3121 Returns NULL if SIG is not present in the table. */
3123 static struct signatured_type *
3124 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3126 struct signatured_type find_entry, *entry;
3128 if (dwarf2_per_objfile->signatured_types == NULL)
3130 complaint (&symfile_complaints,
3131 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3135 find_entry.signature = sig;
3136 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3140 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3143 init_cu_die_reader (struct die_reader_specs *reader,
3144 struct dwarf2_cu *cu)
3146 reader->abfd = cu->objfile->obfd;
3148 if (cu->per_cu->from_debug_types)
3150 gdb_assert (dwarf2_per_objfile->types.readin);
3151 reader->buffer = dwarf2_per_objfile->types.buffer;
3155 gdb_assert (dwarf2_per_objfile->info.readin);
3156 reader->buffer = dwarf2_per_objfile->info.buffer;
3160 /* Find the base address of the compilation unit for range lists and
3161 location lists. It will normally be specified by DW_AT_low_pc.
3162 In DWARF-3 draft 4, the base address could be overridden by
3163 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3164 compilation units with discontinuous ranges. */
3167 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3169 struct attribute *attr;
3172 cu->base_address = 0;
3174 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3177 cu->base_address = DW_ADDR (attr);
3182 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3185 cu->base_address = DW_ADDR (attr);
3191 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3192 to combine the common parts.
3193 Process a compilation unit for a psymtab.
3194 BUFFER is a pointer to the beginning of the dwarf section buffer,
3195 either .debug_info or debug_types.
3196 INFO_PTR is a pointer to the start of the CU.
3197 Returns a pointer to the next CU. */
3200 process_psymtab_comp_unit (struct objfile *objfile,
3201 struct dwarf2_per_cu_data *this_cu,
3202 gdb_byte *buffer, gdb_byte *info_ptr,
3203 unsigned int buffer_size)
3205 bfd *abfd = objfile->obfd;
3206 gdb_byte *beg_of_comp_unit = info_ptr;
3207 struct die_info *comp_unit_die;
3208 struct partial_symtab *pst;
3210 struct cleanup *back_to_inner;
3211 struct dwarf2_cu cu;
3212 int has_children, has_pc_info;
3213 struct attribute *attr;
3214 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3215 struct die_reader_specs reader_specs;
3216 const char *filename;
3218 init_one_comp_unit (&cu, objfile);
3219 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3221 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3222 buffer, buffer_size,
3225 /* Complete the cu_header. */
3226 cu.header.offset = beg_of_comp_unit - buffer;
3227 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3229 cu.list_in_scope = &file_symbols;
3231 /* If this compilation unit was already read in, free the
3232 cached copy in order to read it in again. This is
3233 necessary because we skipped some symbols when we first
3234 read in the compilation unit (see load_partial_dies).
3235 This problem could be avoided, but the benefit is
3237 if (this_cu->cu != NULL)
3238 free_one_cached_comp_unit (this_cu->cu);
3240 /* Note that this is a pointer to our stack frame, being
3241 added to a global data structure. It will be cleaned up
3242 in free_stack_comp_unit when we finish with this
3243 compilation unit. */
3245 cu.per_cu = this_cu;
3247 /* Read the abbrevs for this compilation unit into a table. */
3248 dwarf2_read_abbrevs (abfd, &cu);
3249 make_cleanup (dwarf2_free_abbrev_table, &cu);
3251 /* Read the compilation unit die. */
3252 if (this_cu->from_debug_types)
3253 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3254 init_cu_die_reader (&reader_specs, &cu);
3255 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3258 if (this_cu->from_debug_types)
3260 /* offset,length haven't been set yet for type units. */
3261 this_cu->offset = cu.header.offset;
3262 this_cu->length = cu.header.length + cu.header.initial_length_size;
3264 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3266 info_ptr = (beg_of_comp_unit + cu.header.length
3267 + cu.header.initial_length_size);
3268 do_cleanups (back_to_inner);
3272 prepare_one_comp_unit (&cu, comp_unit_die);
3274 /* Allocate a new partial symbol table structure. */
3275 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3276 if (attr == NULL || !DW_STRING (attr))
3279 filename = DW_STRING (attr);
3280 pst = start_psymtab_common (objfile, objfile->section_offsets,
3282 /* TEXTLOW and TEXTHIGH are set below. */
3284 objfile->global_psymbols.next,
3285 objfile->static_psymbols.next);
3287 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3289 pst->dirname = DW_STRING (attr);
3291 pst->read_symtab_private = this_cu;
3293 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3295 /* Store the function that reads in the rest of the symbol table. */
3296 pst->read_symtab = dwarf2_psymtab_to_symtab;
3298 this_cu->v.psymtab = pst;
3300 dwarf2_find_base_address (comp_unit_die, &cu);
3302 /* Possibly set the default values of LOWPC and HIGHPC from
3304 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3305 &best_highpc, &cu, pst);
3306 if (has_pc_info == 1 && best_lowpc < best_highpc)
3307 /* Store the contiguous range if it is not empty; it can be empty for
3308 CUs with no code. */
3309 addrmap_set_empty (objfile->psymtabs_addrmap,
3310 best_lowpc + baseaddr,
3311 best_highpc + baseaddr - 1, pst);
3313 /* Check if comp unit has_children.
3314 If so, read the rest of the partial symbols from this comp unit.
3315 If not, there's no more debug_info for this comp unit. */
3318 struct partial_die_info *first_die;
3319 CORE_ADDR lowpc, highpc;
3321 lowpc = ((CORE_ADDR) -1);
3322 highpc = ((CORE_ADDR) 0);
3324 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3326 scan_partial_symbols (first_die, &lowpc, &highpc,
3327 ! has_pc_info, &cu);
3329 /* If we didn't find a lowpc, set it to highpc to avoid
3330 complaints from `maint check'. */
3331 if (lowpc == ((CORE_ADDR) -1))
3334 /* If the compilation unit didn't have an explicit address range,
3335 then use the information extracted from its child dies. */
3339 best_highpc = highpc;
3342 pst->textlow = best_lowpc + baseaddr;
3343 pst->texthigh = best_highpc + baseaddr;
3345 pst->n_global_syms = objfile->global_psymbols.next -
3346 (objfile->global_psymbols.list + pst->globals_offset);
3347 pst->n_static_syms = objfile->static_psymbols.next -
3348 (objfile->static_psymbols.list + pst->statics_offset);
3349 sort_pst_symbols (pst);
3351 info_ptr = (beg_of_comp_unit + cu.header.length
3352 + cu.header.initial_length_size);
3354 if (this_cu->from_debug_types)
3356 /* It's not clear we want to do anything with stmt lists here.
3357 Waiting to see what gcc ultimately does. */
3361 /* Get the list of files included in the current compilation unit,
3362 and build a psymtab for each of them. */
3363 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3366 do_cleanups (back_to_inner);
3371 /* Traversal function for htab_traverse_noresize.
3372 Process one .debug_types comp-unit. */
3375 process_type_comp_unit (void **slot, void *info)
3377 struct signatured_type *entry = (struct signatured_type *) *slot;
3378 struct objfile *objfile = (struct objfile *) info;
3379 struct dwarf2_per_cu_data *this_cu;
3381 this_cu = &entry->per_cu;
3383 gdb_assert (dwarf2_per_objfile->types.readin);
3384 process_psymtab_comp_unit (objfile, this_cu,
3385 dwarf2_per_objfile->types.buffer,
3386 dwarf2_per_objfile->types.buffer + entry->offset,
3387 dwarf2_per_objfile->types.size);
3392 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3393 Build partial symbol tables for the .debug_types comp-units. */
3396 build_type_psymtabs (struct objfile *objfile)
3398 if (! create_debug_types_hash_table (objfile))
3401 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3402 process_type_comp_unit, objfile);
3405 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3408 psymtabs_addrmap_cleanup (void *o)
3410 struct objfile *objfile = o;
3412 objfile->psymtabs_addrmap = NULL;
3415 /* Build the partial symbol table by doing a quick pass through the
3416 .debug_info and .debug_abbrev sections. */
3419 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3422 struct cleanup *back_to, *addrmap_cleanup;
3423 struct obstack temp_obstack;
3425 dwarf2_per_objfile->reading_partial_symbols = 1;
3427 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3428 info_ptr = dwarf2_per_objfile->info.buffer;
3430 /* Any cached compilation units will be linked by the per-objfile
3431 read_in_chain. Make sure to free them when we're done. */
3432 back_to = make_cleanup (free_cached_comp_units, NULL);
3434 build_type_psymtabs (objfile);
3436 create_all_comp_units (objfile);
3438 /* Create a temporary address map on a temporary obstack. We later
3439 copy this to the final obstack. */
3440 obstack_init (&temp_obstack);
3441 make_cleanup_obstack_free (&temp_obstack);
3442 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3443 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3445 /* Since the objects we're extracting from .debug_info vary in
3446 length, only the individual functions to extract them (like
3447 read_comp_unit_head and load_partial_die) can really know whether
3448 the buffer is large enough to hold another complete object.
3450 At the moment, they don't actually check that. If .debug_info
3451 holds just one extra byte after the last compilation unit's dies,
3452 then read_comp_unit_head will happily read off the end of the
3453 buffer. read_partial_die is similarly casual. Those functions
3456 For this loop condition, simply checking whether there's any data
3457 left at all should be sufficient. */
3459 while (info_ptr < (dwarf2_per_objfile->info.buffer
3460 + dwarf2_per_objfile->info.size))
3462 struct dwarf2_per_cu_data *this_cu;
3464 this_cu = dwarf2_find_comp_unit (info_ptr
3465 - dwarf2_per_objfile->info.buffer,
3468 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3469 dwarf2_per_objfile->info.buffer,
3471 dwarf2_per_objfile->info.size);
3474 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3475 &objfile->objfile_obstack);
3476 discard_cleanups (addrmap_cleanup);
3478 do_cleanups (back_to);
3481 /* Load the partial DIEs for a secondary CU into memory. */
3484 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3485 struct objfile *objfile)
3487 bfd *abfd = objfile->obfd;
3488 gdb_byte *info_ptr, *beg_of_comp_unit;
3489 struct die_info *comp_unit_die;
3490 struct dwarf2_cu *cu;
3491 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3493 struct die_reader_specs reader_specs;
3496 gdb_assert (! this_cu->from_debug_types);
3498 gdb_assert (dwarf2_per_objfile->info.readin);
3499 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3500 beg_of_comp_unit = info_ptr;
3502 if (this_cu->cu == NULL)
3504 cu = xmalloc (sizeof (*cu));
3505 init_one_comp_unit (cu, objfile);
3509 /* If an error occurs while loading, release our storage. */
3510 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3512 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3513 dwarf2_per_objfile->info.buffer,
3514 dwarf2_per_objfile->info.size,
3517 /* Complete the cu_header. */
3518 cu->header.offset = this_cu->offset;
3519 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3521 /* Link this compilation unit into the compilation unit tree. */
3523 cu->per_cu = this_cu;
3525 /* Link this CU into read_in_chain. */
3526 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3527 dwarf2_per_objfile->read_in_chain = this_cu;
3532 info_ptr += cu->header.first_die_offset;
3535 /* Read the abbrevs for this compilation unit into a table. */
3536 gdb_assert (cu->dwarf2_abbrevs == NULL);
3537 dwarf2_read_abbrevs (abfd, cu);
3538 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3540 /* Read the compilation unit die. */
3541 init_cu_die_reader (&reader_specs, cu);
3542 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3545 prepare_one_comp_unit (cu, comp_unit_die);
3547 /* Check if comp unit has_children.
3548 If so, read the rest of the partial symbols from this comp unit.
3549 If not, there's no more debug_info for this comp unit. */
3551 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3553 do_cleanups (free_abbrevs_cleanup);
3557 /* We've successfully allocated this compilation unit. Let our
3558 caller clean it up when finished with it. */
3559 discard_cleanups (free_cu_cleanup);
3563 /* Create a list of all compilation units in OBJFILE. We do this only
3564 if an inter-comp-unit reference is found; presumably if there is one,
3565 there will be many, and one will occur early in the .debug_info section.
3566 So there's no point in building this list incrementally. */
3569 create_all_comp_units (struct objfile *objfile)
3573 struct dwarf2_per_cu_data **all_comp_units;
3576 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3577 info_ptr = dwarf2_per_objfile->info.buffer;
3581 all_comp_units = xmalloc (n_allocated
3582 * sizeof (struct dwarf2_per_cu_data *));
3584 while (info_ptr < dwarf2_per_objfile->info.buffer
3585 + dwarf2_per_objfile->info.size)
3587 unsigned int length, initial_length_size;
3588 struct dwarf2_per_cu_data *this_cu;
3589 unsigned int offset;
3591 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3593 /* Read just enough information to find out where the next
3594 compilation unit is. */
3595 length = read_initial_length (objfile->obfd, info_ptr,
3596 &initial_length_size);
3598 /* Save the compilation unit for later lookup. */
3599 this_cu = obstack_alloc (&objfile->objfile_obstack,
3600 sizeof (struct dwarf2_per_cu_data));
3601 memset (this_cu, 0, sizeof (*this_cu));
3602 this_cu->offset = offset;
3603 this_cu->length = length + initial_length_size;
3604 this_cu->objfile = objfile;
3606 if (n_comp_units == n_allocated)
3609 all_comp_units = xrealloc (all_comp_units,
3611 * sizeof (struct dwarf2_per_cu_data *));
3613 all_comp_units[n_comp_units++] = this_cu;
3615 info_ptr = info_ptr + this_cu->length;
3618 dwarf2_per_objfile->all_comp_units
3619 = obstack_alloc (&objfile->objfile_obstack,
3620 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3621 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3622 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3623 xfree (all_comp_units);
3624 dwarf2_per_objfile->n_comp_units = n_comp_units;
3627 /* Process all loaded DIEs for compilation unit CU, starting at
3628 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3629 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3630 DW_AT_ranges). If NEED_PC is set, then this function will set
3631 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3632 and record the covered ranges in the addrmap. */
3635 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3636 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3638 struct partial_die_info *pdi;
3640 /* Now, march along the PDI's, descending into ones which have
3641 interesting children but skipping the children of the other ones,
3642 until we reach the end of the compilation unit. */
3648 fixup_partial_die (pdi, cu);
3650 /* Anonymous namespaces or modules have no name but have interesting
3651 children, so we need to look at them. Ditto for anonymous
3654 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3655 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3659 case DW_TAG_subprogram:
3660 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3662 case DW_TAG_constant:
3663 case DW_TAG_variable:
3664 case DW_TAG_typedef:
3665 case DW_TAG_union_type:
3666 if (!pdi->is_declaration)
3668 add_partial_symbol (pdi, cu);
3671 case DW_TAG_class_type:
3672 case DW_TAG_interface_type:
3673 case DW_TAG_structure_type:
3674 if (!pdi->is_declaration)
3676 add_partial_symbol (pdi, cu);
3679 case DW_TAG_enumeration_type:
3680 if (!pdi->is_declaration)
3681 add_partial_enumeration (pdi, cu);
3683 case DW_TAG_base_type:
3684 case DW_TAG_subrange_type:
3685 /* File scope base type definitions are added to the partial
3687 add_partial_symbol (pdi, cu);
3689 case DW_TAG_namespace:
3690 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3693 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3700 /* If the die has a sibling, skip to the sibling. */
3702 pdi = pdi->die_sibling;
3706 /* Functions used to compute the fully scoped name of a partial DIE.
3708 Normally, this is simple. For C++, the parent DIE's fully scoped
3709 name is concatenated with "::" and the partial DIE's name. For
3710 Java, the same thing occurs except that "." is used instead of "::".
3711 Enumerators are an exception; they use the scope of their parent
3712 enumeration type, i.e. the name of the enumeration type is not
3713 prepended to the enumerator.
3715 There are two complexities. One is DW_AT_specification; in this
3716 case "parent" means the parent of the target of the specification,
3717 instead of the direct parent of the DIE. The other is compilers
3718 which do not emit DW_TAG_namespace; in this case we try to guess
3719 the fully qualified name of structure types from their members'
3720 linkage names. This must be done using the DIE's children rather
3721 than the children of any DW_AT_specification target. We only need
3722 to do this for structures at the top level, i.e. if the target of
3723 any DW_AT_specification (if any; otherwise the DIE itself) does not
3726 /* Compute the scope prefix associated with PDI's parent, in
3727 compilation unit CU. The result will be allocated on CU's
3728 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3729 field. NULL is returned if no prefix is necessary. */
3731 partial_die_parent_scope (struct partial_die_info *pdi,
3732 struct dwarf2_cu *cu)
3734 char *grandparent_scope;
3735 struct partial_die_info *parent, *real_pdi;
3737 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3738 then this means the parent of the specification DIE. */
3741 while (real_pdi->has_specification)
3742 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3744 parent = real_pdi->die_parent;
3748 if (parent->scope_set)
3749 return parent->scope;
3751 fixup_partial_die (parent, cu);
3753 grandparent_scope = partial_die_parent_scope (parent, cu);
3755 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3756 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3757 Work around this problem here. */
3758 if (cu->language == language_cplus
3759 && parent->tag == DW_TAG_namespace
3760 && strcmp (parent->name, "::") == 0
3761 && grandparent_scope == NULL)
3763 parent->scope = NULL;
3764 parent->scope_set = 1;
3768 if (parent->tag == DW_TAG_namespace
3769 || parent->tag == DW_TAG_module
3770 || parent->tag == DW_TAG_structure_type
3771 || parent->tag == DW_TAG_class_type
3772 || parent->tag == DW_TAG_interface_type
3773 || parent->tag == DW_TAG_union_type
3774 || parent->tag == DW_TAG_enumeration_type)
3776 if (grandparent_scope == NULL)
3777 parent->scope = parent->name;
3779 parent->scope = typename_concat (&cu->comp_unit_obstack,
3781 parent->name, 0, cu);
3783 else if (parent->tag == DW_TAG_enumerator)
3784 /* Enumerators should not get the name of the enumeration as a prefix. */
3785 parent->scope = grandparent_scope;
3788 /* FIXME drow/2004-04-01: What should we be doing with
3789 function-local names? For partial symbols, we should probably be
3791 complaint (&symfile_complaints,
3792 _("unhandled containing DIE tag %d for DIE at %d"),
3793 parent->tag, pdi->offset);
3794 parent->scope = grandparent_scope;
3797 parent->scope_set = 1;
3798 return parent->scope;
3801 /* Return the fully scoped name associated with PDI, from compilation unit
3802 CU. The result will be allocated with malloc. */
3804 partial_die_full_name (struct partial_die_info *pdi,
3805 struct dwarf2_cu *cu)
3809 /* If this is a template instantiation, we can not work out the
3810 template arguments from partial DIEs. So, unfortunately, we have
3811 to go through the full DIEs. At least any work we do building
3812 types here will be reused if full symbols are loaded later. */
3813 if (pdi->has_template_arguments)
3815 fixup_partial_die (pdi, cu);
3817 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3819 struct die_info *die;
3820 struct attribute attr;
3821 struct dwarf2_cu *ref_cu = cu;
3824 attr.form = DW_FORM_ref_addr;
3825 attr.u.addr = pdi->offset;
3826 die = follow_die_ref (NULL, &attr, &ref_cu);
3828 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3832 parent_scope = partial_die_parent_scope (pdi, cu);
3833 if (parent_scope == NULL)
3836 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3840 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3842 struct objfile *objfile = cu->objfile;
3844 char *actual_name = NULL;
3845 const struct partial_symbol *psym = NULL;
3847 int built_actual_name = 0;
3849 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3851 actual_name = partial_die_full_name (pdi, cu);
3853 built_actual_name = 1;
3855 if (actual_name == NULL)
3856 actual_name = pdi->name;
3860 case DW_TAG_subprogram:
3861 if (pdi->is_external || cu->language == language_ada)
3863 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3864 of the global scope. But in Ada, we want to be able to access
3865 nested procedures globally. So all Ada subprograms are stored
3866 in the global scope. */
3867 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3868 mst_text, objfile); */
3869 add_psymbol_to_list (actual_name, strlen (actual_name),
3871 VAR_DOMAIN, LOC_BLOCK,
3872 &objfile->global_psymbols,
3873 0, pdi->lowpc + baseaddr,
3874 cu->language, objfile);
3878 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3879 mst_file_text, objfile); */
3880 add_psymbol_to_list (actual_name, strlen (actual_name),
3882 VAR_DOMAIN, LOC_BLOCK,
3883 &objfile->static_psymbols,
3884 0, pdi->lowpc + baseaddr,
3885 cu->language, objfile);
3888 case DW_TAG_constant:
3890 struct psymbol_allocation_list *list;
3892 if (pdi->is_external)
3893 list = &objfile->global_psymbols;
3895 list = &objfile->static_psymbols;
3896 add_psymbol_to_list (actual_name, strlen (actual_name),
3897 built_actual_name, VAR_DOMAIN, LOC_STATIC,
3898 list, 0, 0, cu->language, objfile);
3901 case DW_TAG_variable:
3903 addr = decode_locdesc (pdi->locdesc, cu);
3907 && !dwarf2_per_objfile->has_section_at_zero)
3909 /* A global or static variable may also have been stripped
3910 out by the linker if unused, in which case its address
3911 will be nullified; do not add such variables into partial
3912 symbol table then. */
3914 else if (pdi->is_external)
3917 Don't enter into the minimal symbol tables as there is
3918 a minimal symbol table entry from the ELF symbols already.
3919 Enter into partial symbol table if it has a location
3920 descriptor or a type.
3921 If the location descriptor is missing, new_symbol will create
3922 a LOC_UNRESOLVED symbol, the address of the variable will then
3923 be determined from the minimal symbol table whenever the variable
3925 The address for the partial symbol table entry is not
3926 used by GDB, but it comes in handy for debugging partial symbol
3929 if (pdi->locdesc || pdi->has_type)
3930 add_psymbol_to_list (actual_name, strlen (actual_name),
3932 VAR_DOMAIN, LOC_STATIC,
3933 &objfile->global_psymbols,
3935 cu->language, objfile);
3939 /* Static Variable. Skip symbols without location descriptors. */
3940 if (pdi->locdesc == NULL)
3942 if (built_actual_name)
3943 xfree (actual_name);
3946 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3947 mst_file_data, objfile); */
3948 add_psymbol_to_list (actual_name, strlen (actual_name),
3950 VAR_DOMAIN, LOC_STATIC,
3951 &objfile->static_psymbols,
3953 cu->language, objfile);
3956 case DW_TAG_typedef:
3957 case DW_TAG_base_type:
3958 case DW_TAG_subrange_type:
3959 add_psymbol_to_list (actual_name, strlen (actual_name),
3961 VAR_DOMAIN, LOC_TYPEDEF,
3962 &objfile->static_psymbols,
3963 0, (CORE_ADDR) 0, cu->language, objfile);
3965 case DW_TAG_namespace:
3966 add_psymbol_to_list (actual_name, strlen (actual_name),
3968 VAR_DOMAIN, LOC_TYPEDEF,
3969 &objfile->global_psymbols,
3970 0, (CORE_ADDR) 0, cu->language, objfile);
3972 case DW_TAG_class_type:
3973 case DW_TAG_interface_type:
3974 case DW_TAG_structure_type:
3975 case DW_TAG_union_type:
3976 case DW_TAG_enumeration_type:
3977 /* Skip external references. The DWARF standard says in the section
3978 about "Structure, Union, and Class Type Entries": "An incomplete
3979 structure, union or class type is represented by a structure,
3980 union or class entry that does not have a byte size attribute
3981 and that has a DW_AT_declaration attribute." */
3982 if (!pdi->has_byte_size && pdi->is_declaration)
3984 if (built_actual_name)
3985 xfree (actual_name);
3989 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3990 static vs. global. */
3991 add_psymbol_to_list (actual_name, strlen (actual_name),
3993 STRUCT_DOMAIN, LOC_TYPEDEF,
3994 (cu->language == language_cplus
3995 || cu->language == language_java)
3996 ? &objfile->global_psymbols
3997 : &objfile->static_psymbols,
3998 0, (CORE_ADDR) 0, cu->language, objfile);
4001 case DW_TAG_enumerator:
4002 add_psymbol_to_list (actual_name, strlen (actual_name),
4004 VAR_DOMAIN, LOC_CONST,
4005 (cu->language == language_cplus
4006 || cu->language == language_java)
4007 ? &objfile->global_psymbols
4008 : &objfile->static_psymbols,
4009 0, (CORE_ADDR) 0, cu->language, objfile);
4015 if (built_actual_name)
4016 xfree (actual_name);
4019 /* Read a partial die corresponding to a namespace; also, add a symbol
4020 corresponding to that namespace to the symbol table. NAMESPACE is
4021 the name of the enclosing namespace. */
4024 add_partial_namespace (struct partial_die_info *pdi,
4025 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4026 int need_pc, struct dwarf2_cu *cu)
4028 /* Add a symbol for the namespace. */
4030 add_partial_symbol (pdi, cu);
4032 /* Now scan partial symbols in that namespace. */
4034 if (pdi->has_children)
4035 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4038 /* Read a partial die corresponding to a Fortran module. */
4041 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4042 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4044 /* Now scan partial symbols in that module. */
4046 if (pdi->has_children)
4047 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4050 /* Read a partial die corresponding to a subprogram and create a partial
4051 symbol for that subprogram. When the CU language allows it, this
4052 routine also defines a partial symbol for each nested subprogram
4053 that this subprogram contains.
4055 DIE my also be a lexical block, in which case we simply search
4056 recursively for suprograms defined inside that lexical block.
4057 Again, this is only performed when the CU language allows this
4058 type of definitions. */
4061 add_partial_subprogram (struct partial_die_info *pdi,
4062 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4063 int need_pc, struct dwarf2_cu *cu)
4065 if (pdi->tag == DW_TAG_subprogram)
4067 if (pdi->has_pc_info)
4069 if (pdi->lowpc < *lowpc)
4070 *lowpc = pdi->lowpc;
4071 if (pdi->highpc > *highpc)
4072 *highpc = pdi->highpc;
4076 struct objfile *objfile = cu->objfile;
4078 baseaddr = ANOFFSET (objfile->section_offsets,
4079 SECT_OFF_TEXT (objfile));
4080 addrmap_set_empty (objfile->psymtabs_addrmap,
4081 pdi->lowpc + baseaddr,
4082 pdi->highpc - 1 + baseaddr,
4083 cu->per_cu->v.psymtab);
4085 if (!pdi->is_declaration)
4086 /* Ignore subprogram DIEs that do not have a name, they are
4087 illegal. Do not emit a complaint at this point, we will
4088 do so when we convert this psymtab into a symtab. */
4090 add_partial_symbol (pdi, cu);
4094 if (! pdi->has_children)
4097 if (cu->language == language_ada)
4099 pdi = pdi->die_child;
4102 fixup_partial_die (pdi, cu);
4103 if (pdi->tag == DW_TAG_subprogram
4104 || pdi->tag == DW_TAG_lexical_block)
4105 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4106 pdi = pdi->die_sibling;
4111 /* Read a partial die corresponding to an enumeration type. */
4114 add_partial_enumeration (struct partial_die_info *enum_pdi,
4115 struct dwarf2_cu *cu)
4117 struct partial_die_info *pdi;
4119 if (enum_pdi->name != NULL)
4120 add_partial_symbol (enum_pdi, cu);
4122 pdi = enum_pdi->die_child;
4125 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4126 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4128 add_partial_symbol (pdi, cu);
4129 pdi = pdi->die_sibling;
4133 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4134 Return the corresponding abbrev, or NULL if the number is zero (indicating
4135 an empty DIE). In either case *BYTES_READ will be set to the length of
4136 the initial number. */
4138 static struct abbrev_info *
4139 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4140 struct dwarf2_cu *cu)
4142 bfd *abfd = cu->objfile->obfd;
4143 unsigned int abbrev_number;
4144 struct abbrev_info *abbrev;
4146 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4148 if (abbrev_number == 0)
4151 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4154 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4155 abbrev_number, bfd_get_filename (abfd));
4161 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4162 Returns a pointer to the end of a series of DIEs, terminated by an empty
4163 DIE. Any children of the skipped DIEs will also be skipped. */
4166 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4168 struct abbrev_info *abbrev;
4169 unsigned int bytes_read;
4173 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4175 return info_ptr + bytes_read;
4177 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4181 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4182 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4183 abbrev corresponding to that skipped uleb128 should be passed in
4184 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4188 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4189 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4191 unsigned int bytes_read;
4192 struct attribute attr;
4193 bfd *abfd = cu->objfile->obfd;
4194 unsigned int form, i;
4196 for (i = 0; i < abbrev->num_attrs; i++)
4198 /* The only abbrev we care about is DW_AT_sibling. */
4199 if (abbrev->attrs[i].name == DW_AT_sibling)
4201 read_attribute (&attr, &abbrev->attrs[i],
4202 abfd, info_ptr, cu);
4203 if (attr.form == DW_FORM_ref_addr)
4204 complaint (&symfile_complaints,
4205 _("ignoring absolute DW_AT_sibling"));
4207 return buffer + dwarf2_get_ref_die_offset (&attr);
4210 /* If it isn't DW_AT_sibling, skip this attribute. */
4211 form = abbrev->attrs[i].form;
4215 case DW_FORM_ref_addr:
4216 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4217 and later it is offset sized. */
4218 if (cu->header.version == 2)
4219 info_ptr += cu->header.addr_size;
4221 info_ptr += cu->header.offset_size;
4224 info_ptr += cu->header.addr_size;
4231 case DW_FORM_flag_present:
4243 case DW_FORM_ref_sig8:
4246 case DW_FORM_string:
4247 read_direct_string (abfd, info_ptr, &bytes_read);
4248 info_ptr += bytes_read;
4250 case DW_FORM_sec_offset:
4252 info_ptr += cu->header.offset_size;
4254 case DW_FORM_exprloc:
4256 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4257 info_ptr += bytes_read;
4259 case DW_FORM_block1:
4260 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4262 case DW_FORM_block2:
4263 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4265 case DW_FORM_block4:
4266 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4270 case DW_FORM_ref_udata:
4271 info_ptr = skip_leb128 (abfd, info_ptr);
4273 case DW_FORM_indirect:
4274 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4275 info_ptr += bytes_read;
4276 /* We need to continue parsing from here, so just go back to
4278 goto skip_attribute;
4281 error (_("Dwarf Error: Cannot handle %s "
4282 "in DWARF reader [in module %s]"),
4283 dwarf_form_name (form),
4284 bfd_get_filename (abfd));
4288 if (abbrev->has_children)
4289 return skip_children (buffer, info_ptr, cu);
4294 /* Locate ORIG_PDI's sibling.
4295 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4299 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4300 gdb_byte *buffer, gdb_byte *info_ptr,
4301 bfd *abfd, struct dwarf2_cu *cu)
4303 /* Do we know the sibling already? */
4305 if (orig_pdi->sibling)
4306 return orig_pdi->sibling;
4308 /* Are there any children to deal with? */
4310 if (!orig_pdi->has_children)
4313 /* Skip the children the long way. */
4315 return skip_children (buffer, info_ptr, cu);
4318 /* Expand this partial symbol table into a full symbol table. */
4321 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4327 warning (_("bug: psymtab for %s is already read in."),
4334 printf_filtered (_("Reading in symbols for %s..."),
4336 gdb_flush (gdb_stdout);
4339 /* Restore our global data. */
4340 dwarf2_per_objfile = objfile_data (pst->objfile,
4341 dwarf2_objfile_data_key);
4343 /* If this psymtab is constructed from a debug-only objfile, the
4344 has_section_at_zero flag will not necessarily be correct. We
4345 can get the correct value for this flag by looking at the data
4346 associated with the (presumably stripped) associated objfile. */
4347 if (pst->objfile->separate_debug_objfile_backlink)
4349 struct dwarf2_per_objfile *dpo_backlink
4350 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4351 dwarf2_objfile_data_key);
4353 dwarf2_per_objfile->has_section_at_zero
4354 = dpo_backlink->has_section_at_zero;
4357 dwarf2_per_objfile->reading_partial_symbols = 0;
4359 psymtab_to_symtab_1 (pst);
4361 /* Finish up the debug error message. */
4363 printf_filtered (_("done.\n"));
4368 /* Add PER_CU to the queue. */
4371 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4373 struct dwarf2_queue_item *item;
4376 item = xmalloc (sizeof (*item));
4377 item->per_cu = per_cu;
4380 if (dwarf2_queue == NULL)
4381 dwarf2_queue = item;
4383 dwarf2_queue_tail->next = item;
4385 dwarf2_queue_tail = item;
4388 /* Process the queue. */
4391 process_queue (struct objfile *objfile)
4393 struct dwarf2_queue_item *item, *next_item;
4395 /* The queue starts out with one item, but following a DIE reference
4396 may load a new CU, adding it to the end of the queue. */
4397 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4399 if (dwarf2_per_objfile->using_index
4400 ? !item->per_cu->v.quick->symtab
4401 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4402 process_full_comp_unit (item->per_cu);
4404 item->per_cu->queued = 0;
4405 next_item = item->next;
4409 dwarf2_queue_tail = NULL;
4412 /* Free all allocated queue entries. This function only releases anything if
4413 an error was thrown; if the queue was processed then it would have been
4414 freed as we went along. */
4417 dwarf2_release_queue (void *dummy)
4419 struct dwarf2_queue_item *item, *last;
4421 item = dwarf2_queue;
4424 /* Anything still marked queued is likely to be in an
4425 inconsistent state, so discard it. */
4426 if (item->per_cu->queued)
4428 if (item->per_cu->cu != NULL)
4429 free_one_cached_comp_unit (item->per_cu->cu);
4430 item->per_cu->queued = 0;
4438 dwarf2_queue = dwarf2_queue_tail = NULL;
4441 /* Read in full symbols for PST, and anything it depends on. */
4444 psymtab_to_symtab_1 (struct partial_symtab *pst)
4446 struct dwarf2_per_cu_data *per_cu;
4447 struct cleanup *back_to;
4450 for (i = 0; i < pst->number_of_dependencies; i++)
4451 if (!pst->dependencies[i]->readin)
4453 /* Inform about additional files that need to be read in. */
4456 /* FIXME: i18n: Need to make this a single string. */
4457 fputs_filtered (" ", gdb_stdout);
4459 fputs_filtered ("and ", gdb_stdout);
4461 printf_filtered ("%s...", pst->dependencies[i]->filename);
4462 wrap_here (""); /* Flush output. */
4463 gdb_flush (gdb_stdout);
4465 psymtab_to_symtab_1 (pst->dependencies[i]);
4468 per_cu = pst->read_symtab_private;
4472 /* It's an include file, no symbols to read for it.
4473 Everything is in the parent symtab. */
4478 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4481 /* Load the DIEs associated with PER_CU into memory. */
4484 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4485 struct objfile *objfile)
4487 bfd *abfd = objfile->obfd;
4488 struct dwarf2_cu *cu;
4489 unsigned int offset;
4490 gdb_byte *info_ptr, *beg_of_comp_unit;
4491 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4492 struct attribute *attr;
4495 gdb_assert (! per_cu->from_debug_types);
4497 /* Set local variables from the partial symbol table info. */
4498 offset = per_cu->offset;
4500 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4501 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4502 beg_of_comp_unit = info_ptr;
4504 if (per_cu->cu == NULL)
4506 cu = xmalloc (sizeof (*cu));
4507 init_one_comp_unit (cu, objfile);
4511 /* If an error occurs while loading, release our storage. */
4512 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4514 /* Read in the comp_unit header. */
4515 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4517 /* Complete the cu_header. */
4518 cu->header.offset = offset;
4519 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4521 /* Read the abbrevs for this compilation unit. */
4522 dwarf2_read_abbrevs (abfd, cu);
4523 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4525 /* Link this compilation unit into the compilation unit tree. */
4527 cu->per_cu = per_cu;
4529 /* Link this CU into read_in_chain. */
4530 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4531 dwarf2_per_objfile->read_in_chain = per_cu;
4536 info_ptr += cu->header.first_die_offset;
4539 cu->dies = read_comp_unit (info_ptr, cu);
4541 /* We try not to read any attributes in this function, because not
4542 all objfiles needed for references have been loaded yet, and symbol
4543 table processing isn't initialized. But we have to set the CU language,
4544 or we won't be able to build types correctly. */
4545 prepare_one_comp_unit (cu, cu->dies);
4547 /* Similarly, if we do not read the producer, we can not apply
4548 producer-specific interpretation. */
4549 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4551 cu->producer = DW_STRING (attr);
4555 do_cleanups (free_abbrevs_cleanup);
4557 /* We've successfully allocated this compilation unit. Let our
4558 caller clean it up when finished with it. */
4559 discard_cleanups (free_cu_cleanup);
4563 /* Add a DIE to the delayed physname list. */
4566 add_to_method_list (struct type *type, int fnfield_index, int index,
4567 const char *name, struct die_info *die,
4568 struct dwarf2_cu *cu)
4570 struct delayed_method_info mi;
4572 mi.fnfield_index = fnfield_index;
4576 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4579 /* A cleanup for freeing the delayed method list. */
4582 free_delayed_list (void *ptr)
4584 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4585 if (cu->method_list != NULL)
4587 VEC_free (delayed_method_info, cu->method_list);
4588 cu->method_list = NULL;
4592 /* Compute the physnames of any methods on the CU's method list.
4594 The computation of method physnames is delayed in order to avoid the
4595 (bad) condition that one of the method's formal parameters is of an as yet
4599 compute_delayed_physnames (struct dwarf2_cu *cu)
4602 struct delayed_method_info *mi;
4603 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4606 struct fn_fieldlist *fn_flp
4607 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4608 physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu);
4609 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4613 /* Generate full symbol information for PST and CU, whose DIEs have
4614 already been loaded into memory. */
4617 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4619 struct dwarf2_cu *cu = per_cu->cu;
4620 struct objfile *objfile = per_cu->objfile;
4621 CORE_ADDR lowpc, highpc;
4622 struct symtab *symtab;
4623 struct cleanup *back_to, *delayed_list_cleanup;
4626 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4629 back_to = make_cleanup (really_free_pendings, NULL);
4630 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4632 cu->list_in_scope = &file_symbols;
4634 dwarf2_find_base_address (cu->dies, cu);
4636 /* Do line number decoding in read_file_scope () */
4637 process_die (cu->dies, cu);
4639 /* Now that we have processed all the DIEs in the CU, all the types
4640 should be complete, and it should now be safe to compute all of the
4642 compute_delayed_physnames (cu);
4643 do_cleanups (delayed_list_cleanup);
4645 /* Some compilers don't define a DW_AT_high_pc attribute for the
4646 compilation unit. If the DW_AT_high_pc is missing, synthesize
4647 it, by scanning the DIE's below the compilation unit. */
4648 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4650 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4652 /* Set symtab language to language from DW_AT_language.
4653 If the compilation is from a C file generated by language preprocessors,
4654 do not set the language if it was already deduced by start_subfile. */
4656 && !(cu->language == language_c && symtab->language != language_c))
4658 symtab->language = cu->language;
4661 if (dwarf2_per_objfile->using_index)
4662 per_cu->v.quick->symtab = symtab;
4665 struct partial_symtab *pst = per_cu->v.psymtab;
4666 pst->symtab = symtab;
4670 do_cleanups (back_to);
4673 /* Process a die and its children. */
4676 process_die (struct die_info *die, struct dwarf2_cu *cu)
4680 case DW_TAG_padding:
4682 case DW_TAG_compile_unit:
4683 read_file_scope (die, cu);
4685 case DW_TAG_type_unit:
4686 read_type_unit_scope (die, cu);
4688 case DW_TAG_subprogram:
4689 case DW_TAG_inlined_subroutine:
4690 read_func_scope (die, cu);
4692 case DW_TAG_lexical_block:
4693 case DW_TAG_try_block:
4694 case DW_TAG_catch_block:
4695 read_lexical_block_scope (die, cu);
4697 case DW_TAG_class_type:
4698 case DW_TAG_interface_type:
4699 case DW_TAG_structure_type:
4700 case DW_TAG_union_type:
4701 process_structure_scope (die, cu);
4703 case DW_TAG_enumeration_type:
4704 process_enumeration_scope (die, cu);
4707 /* These dies have a type, but processing them does not create
4708 a symbol or recurse to process the children. Therefore we can
4709 read them on-demand through read_type_die. */
4710 case DW_TAG_subroutine_type:
4711 case DW_TAG_set_type:
4712 case DW_TAG_array_type:
4713 case DW_TAG_pointer_type:
4714 case DW_TAG_ptr_to_member_type:
4715 case DW_TAG_reference_type:
4716 case DW_TAG_string_type:
4719 case DW_TAG_base_type:
4720 case DW_TAG_subrange_type:
4721 case DW_TAG_typedef:
4722 /* Add a typedef symbol for the type definition, if it has a
4724 new_symbol (die, read_type_die (die, cu), cu);
4726 case DW_TAG_common_block:
4727 read_common_block (die, cu);
4729 case DW_TAG_common_inclusion:
4731 case DW_TAG_namespace:
4732 processing_has_namespace_info = 1;
4733 read_namespace (die, cu);
4736 processing_has_namespace_info = 1;
4737 read_module (die, cu);
4739 case DW_TAG_imported_declaration:
4740 case DW_TAG_imported_module:
4741 processing_has_namespace_info = 1;
4742 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4743 || cu->language != language_fortran))
4744 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4745 dwarf_tag_name (die->tag));
4746 read_import_statement (die, cu);
4749 new_symbol (die, NULL, cu);
4754 /* A helper function for dwarf2_compute_name which determines whether DIE
4755 needs to have the name of the scope prepended to the name listed in the
4759 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4761 struct attribute *attr;
4765 case DW_TAG_namespace:
4766 case DW_TAG_typedef:
4767 case DW_TAG_class_type:
4768 case DW_TAG_interface_type:
4769 case DW_TAG_structure_type:
4770 case DW_TAG_union_type:
4771 case DW_TAG_enumeration_type:
4772 case DW_TAG_enumerator:
4773 case DW_TAG_subprogram:
4777 case DW_TAG_variable:
4778 case DW_TAG_constant:
4779 /* We only need to prefix "globally" visible variables. These include
4780 any variable marked with DW_AT_external or any variable that
4781 lives in a namespace. [Variables in anonymous namespaces
4782 require prefixing, but they are not DW_AT_external.] */
4784 if (dwarf2_attr (die, DW_AT_specification, cu))
4786 struct dwarf2_cu *spec_cu = cu;
4788 return die_needs_namespace (die_specification (die, &spec_cu),
4792 attr = dwarf2_attr (die, DW_AT_external, cu);
4793 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4794 && die->parent->tag != DW_TAG_module)
4796 /* A variable in a lexical block of some kind does not need a
4797 namespace, even though in C++ such variables may be external
4798 and have a mangled name. */
4799 if (die->parent->tag == DW_TAG_lexical_block
4800 || die->parent->tag == DW_TAG_try_block
4801 || die->parent->tag == DW_TAG_catch_block
4802 || die->parent->tag == DW_TAG_subprogram)
4811 /* Retrieve the last character from a mem_file. */
4814 do_ui_file_peek_last (void *object, const char *buffer, long length)
4816 char *last_char_p = (char *) object;
4819 *last_char_p = buffer[length - 1];
4822 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4823 compute the physname for the object, which include a method's
4824 formal parameters (C++/Java) and return type (Java).
4826 For Ada, return the DIE's linkage name rather than the fully qualified
4827 name. PHYSNAME is ignored..
4829 The result is allocated on the objfile_obstack and canonicalized. */
4832 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4836 name = dwarf2_name (die, cu);
4838 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4839 compute it by typename_concat inside GDB. */
4840 if (cu->language == language_ada
4841 || (cu->language == language_fortran && physname))
4843 /* For Ada unit, we prefer the linkage name over the name, as
4844 the former contains the exported name, which the user expects
4845 to be able to reference. Ideally, we want the user to be able
4846 to reference this entity using either natural or linkage name,
4847 but we haven't started looking at this enhancement yet. */
4848 struct attribute *attr;
4850 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4852 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4853 if (attr && DW_STRING (attr))
4854 return DW_STRING (attr);
4857 /* These are the only languages we know how to qualify names in. */
4859 && (cu->language == language_cplus || cu->language == language_java
4860 || cu->language == language_fortran))
4862 if (die_needs_namespace (die, cu))
4866 struct ui_file *buf;
4868 prefix = determine_prefix (die, cu);
4869 buf = mem_fileopen ();
4870 if (*prefix != '\0')
4872 char *prefixed_name = typename_concat (NULL, prefix, name,
4875 fputs_unfiltered (prefixed_name, buf);
4876 xfree (prefixed_name);
4879 fputs_unfiltered (name, buf);
4881 /* Template parameters may be specified in the DIE's DW_AT_name, or
4882 as children with DW_TAG_template_type_param or
4883 DW_TAG_value_type_param. If the latter, add them to the name
4884 here. If the name already has template parameters, then
4885 skip this step; some versions of GCC emit both, and
4886 it is more efficient to use the pre-computed name.
4888 Something to keep in mind about this process: it is very
4889 unlikely, or in some cases downright impossible, to produce
4890 something that will match the mangled name of a function.
4891 If the definition of the function has the same debug info,
4892 we should be able to match up with it anyway. But fallbacks
4893 using the minimal symbol, for instance to find a method
4894 implemented in a stripped copy of libstdc++, will not work.
4895 If we do not have debug info for the definition, we will have to
4896 match them up some other way.
4898 When we do name matching there is a related problem with function
4899 templates; two instantiated function templates are allowed to
4900 differ only by their return types, which we do not add here. */
4902 if (cu->language == language_cplus && strchr (name, '<') == NULL)
4904 struct attribute *attr;
4905 struct die_info *child;
4908 die->building_fullname = 1;
4910 for (child = die->child; child != NULL; child = child->sibling)
4915 struct dwarf2_locexpr_baton *baton;
4918 if (child->tag != DW_TAG_template_type_param
4919 && child->tag != DW_TAG_template_value_param)
4924 fputs_unfiltered ("<", buf);
4928 fputs_unfiltered (", ", buf);
4930 attr = dwarf2_attr (child, DW_AT_type, cu);
4933 complaint (&symfile_complaints,
4934 _("template parameter missing DW_AT_type"));
4935 fputs_unfiltered ("UNKNOWN_TYPE", buf);
4938 type = die_type (child, cu);
4940 if (child->tag == DW_TAG_template_type_param)
4942 c_print_type (type, "", buf, -1, 0);
4946 attr = dwarf2_attr (child, DW_AT_const_value, cu);
4949 complaint (&symfile_complaints,
4950 _("template parameter missing "
4951 "DW_AT_const_value"));
4952 fputs_unfiltered ("UNKNOWN_VALUE", buf);
4956 dwarf2_const_value_attr (attr, type, name,
4957 &cu->comp_unit_obstack, cu,
4958 &value, &bytes, &baton);
4960 if (TYPE_NOSIGN (type))
4961 /* GDB prints characters as NUMBER 'CHAR'. If that's
4962 changed, this can use value_print instead. */
4963 c_printchar (value, type, buf);
4966 struct value_print_options opts;
4969 v = dwarf2_evaluate_loc_desc (type, NULL,
4973 else if (bytes != NULL)
4975 v = allocate_value (type);
4976 memcpy (value_contents_writeable (v), bytes,
4977 TYPE_LENGTH (type));
4980 v = value_from_longest (type, value);
4982 /* Specify decimal so that we do not depend on
4984 get_formatted_print_options (&opts, 'd');
4986 value_print (v, buf, &opts);
4992 die->building_fullname = 0;
4996 /* Close the argument list, with a space if necessary
4997 (nested templates). */
4998 char last_char = '\0';
4999 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5000 if (last_char == '>')
5001 fputs_unfiltered (" >", buf);
5003 fputs_unfiltered (">", buf);
5007 /* For Java and C++ methods, append formal parameter type
5008 information, if PHYSNAME. */
5010 if (physname && die->tag == DW_TAG_subprogram
5011 && (cu->language == language_cplus
5012 || cu->language == language_java))
5014 struct type *type = read_type_die (die, cu);
5016 c_type_print_args (type, buf, 1, cu->language);
5018 if (cu->language == language_java)
5020 /* For java, we must append the return type to method
5022 if (die->tag == DW_TAG_subprogram)
5023 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5026 else if (cu->language == language_cplus)
5028 /* Assume that an artificial first parameter is
5029 "this", but do not crash if it is not. RealView
5030 marks unnamed (and thus unused) parameters as
5031 artificial; there is no way to differentiate
5033 if (TYPE_NFIELDS (type) > 0
5034 && TYPE_FIELD_ARTIFICIAL (type, 0)
5035 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5036 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5038 fputs_unfiltered (" const", buf);
5042 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5044 ui_file_delete (buf);
5046 if (cu->language == language_cplus)
5049 = dwarf2_canonicalize_name (name, cu,
5050 &cu->objfile->objfile_obstack);
5061 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5062 If scope qualifiers are appropriate they will be added. The result
5063 will be allocated on the objfile_obstack, or NULL if the DIE does
5064 not have a name. NAME may either be from a previous call to
5065 dwarf2_name or NULL.
5067 The output string will be canonicalized (if C++/Java). */
5070 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5072 return dwarf2_compute_name (name, die, cu, 0);
5075 /* Construct a physname for the given DIE in CU. NAME may either be
5076 from a previous call to dwarf2_name or NULL. The result will be
5077 allocated on the objfile_objstack or NULL if the DIE does not have a
5080 The output string will be canonicalized (if C++/Java). */
5083 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5085 return dwarf2_compute_name (name, die, cu, 1);
5088 /* Read the import statement specified by the given die and record it. */
5091 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5093 struct attribute *import_attr;
5094 struct die_info *imported_die;
5095 struct dwarf2_cu *imported_cu;
5096 const char *imported_name;
5097 const char *imported_name_prefix;
5098 const char *canonical_name;
5099 const char *import_alias;
5100 const char *imported_declaration = NULL;
5101 const char *import_prefix;
5105 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5106 if (import_attr == NULL)
5108 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5109 dwarf_tag_name (die->tag));
5114 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5115 imported_name = dwarf2_name (imported_die, imported_cu);
5116 if (imported_name == NULL)
5118 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5120 The import in the following code:
5134 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5135 <52> DW_AT_decl_file : 1
5136 <53> DW_AT_decl_line : 6
5137 <54> DW_AT_import : <0x75>
5138 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5140 <5b> DW_AT_decl_file : 1
5141 <5c> DW_AT_decl_line : 2
5142 <5d> DW_AT_type : <0x6e>
5144 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5145 <76> DW_AT_byte_size : 4
5146 <77> DW_AT_encoding : 5 (signed)
5148 imports the wrong die ( 0x75 instead of 0x58 ).
5149 This case will be ignored until the gcc bug is fixed. */
5153 /* Figure out the local name after import. */
5154 import_alias = dwarf2_name (die, cu);
5156 /* Figure out where the statement is being imported to. */
5157 import_prefix = determine_prefix (die, cu);
5159 /* Figure out what the scope of the imported die is and prepend it
5160 to the name of the imported die. */
5161 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5163 if (imported_die->tag != DW_TAG_namespace
5164 && imported_die->tag != DW_TAG_module)
5166 imported_declaration = imported_name;
5167 canonical_name = imported_name_prefix;
5169 else if (strlen (imported_name_prefix) > 0)
5171 temp = alloca (strlen (imported_name_prefix)
5172 + 2 + strlen (imported_name) + 1);
5173 strcpy (temp, imported_name_prefix);
5174 strcat (temp, "::");
5175 strcat (temp, imported_name);
5176 canonical_name = temp;
5179 canonical_name = imported_name;
5181 cp_add_using_directive (import_prefix,
5184 imported_declaration,
5185 &cu->objfile->objfile_obstack);
5189 initialize_cu_func_list (struct dwarf2_cu *cu)
5191 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5194 /* Cleanup function for read_file_scope. */
5197 free_cu_line_header (void *arg)
5199 struct dwarf2_cu *cu = arg;
5201 free_line_header (cu->line_header);
5202 cu->line_header = NULL;
5206 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5207 char **name, char **comp_dir)
5209 struct attribute *attr;
5214 /* Find the filename. Do not use dwarf2_name here, since the filename
5215 is not a source language identifier. */
5216 attr = dwarf2_attr (die, DW_AT_name, cu);
5219 *name = DW_STRING (attr);
5222 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5224 *comp_dir = DW_STRING (attr);
5225 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5227 *comp_dir = ldirname (*name);
5228 if (*comp_dir != NULL)
5229 make_cleanup (xfree, *comp_dir);
5231 if (*comp_dir != NULL)
5233 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5234 directory, get rid of it. */
5235 char *cp = strchr (*comp_dir, ':');
5237 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5242 *name = "<unknown>";
5245 /* Process DW_TAG_compile_unit. */
5248 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5250 struct objfile *objfile = cu->objfile;
5251 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5252 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5253 CORE_ADDR highpc = ((CORE_ADDR) 0);
5254 struct attribute *attr;
5256 char *comp_dir = NULL;
5257 struct die_info *child_die;
5258 bfd *abfd = objfile->obfd;
5259 struct line_header *line_header = 0;
5262 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5264 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5266 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5267 from finish_block. */
5268 if (lowpc == ((CORE_ADDR) -1))
5273 find_file_and_directory (die, cu, &name, &comp_dir);
5275 attr = dwarf2_attr (die, DW_AT_language, cu);
5278 set_cu_language (DW_UNSND (attr), cu);
5281 attr = dwarf2_attr (die, DW_AT_producer, cu);
5283 cu->producer = DW_STRING (attr);
5285 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5286 standardised yet. As a workaround for the language detection we fall
5287 back to the DW_AT_producer string. */
5288 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5289 cu->language = language_opencl;
5291 /* We assume that we're processing GCC output. */
5292 processing_gcc_compilation = 2;
5294 processing_has_namespace_info = 0;
5296 start_symtab (name, comp_dir, lowpc);
5297 record_debugformat ("DWARF 2");
5298 record_producer (cu->producer);
5300 initialize_cu_func_list (cu);
5302 /* Decode line number information if present. We do this before
5303 processing child DIEs, so that the line header table is available
5304 for DW_AT_decl_file. */
5305 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5308 unsigned int line_offset = DW_UNSND (attr);
5309 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
5312 cu->line_header = line_header;
5313 make_cleanup (free_cu_line_header, cu);
5314 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5318 /* Process all dies in compilation unit. */
5319 if (die->child != NULL)
5321 child_die = die->child;
5322 while (child_die && child_die->tag)
5324 process_die (child_die, cu);
5325 child_die = sibling_die (child_die);
5329 /* Decode macro information, if present. Dwarf 2 macro information
5330 refers to information in the line number info statement program
5331 header, so we can only read it if we've read the header
5333 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5334 if (attr && line_header)
5336 unsigned int macro_offset = DW_UNSND (attr);
5338 dwarf_decode_macros (line_header, macro_offset,
5339 comp_dir, abfd, cu);
5341 do_cleanups (back_to);
5344 /* Process DW_TAG_type_unit.
5345 For TUs we want to skip the first top level sibling if it's not the
5346 actual type being defined by this TU. In this case the first top
5347 level sibling is there to provide context only. */
5350 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5352 struct objfile *objfile = cu->objfile;
5353 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5355 struct attribute *attr;
5357 char *comp_dir = NULL;
5358 struct die_info *child_die;
5359 bfd *abfd = objfile->obfd;
5361 /* start_symtab needs a low pc, but we don't really have one.
5362 Do what read_file_scope would do in the absence of such info. */
5363 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5365 /* Find the filename. Do not use dwarf2_name here, since the filename
5366 is not a source language identifier. */
5367 attr = dwarf2_attr (die, DW_AT_name, cu);
5369 name = DW_STRING (attr);
5371 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5373 comp_dir = DW_STRING (attr);
5374 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5376 comp_dir = ldirname (name);
5377 if (comp_dir != NULL)
5378 make_cleanup (xfree, comp_dir);
5384 attr = dwarf2_attr (die, DW_AT_language, cu);
5386 set_cu_language (DW_UNSND (attr), cu);
5388 /* This isn't technically needed today. It is done for symmetry
5389 with read_file_scope. */
5390 attr = dwarf2_attr (die, DW_AT_producer, cu);
5392 cu->producer = DW_STRING (attr);
5394 /* We assume that we're processing GCC output. */
5395 processing_gcc_compilation = 2;
5397 processing_has_namespace_info = 0;
5399 start_symtab (name, comp_dir, lowpc);
5400 record_debugformat ("DWARF 2");
5401 record_producer (cu->producer);
5403 /* Process the dies in the type unit. */
5404 if (die->child == NULL)
5406 dump_die_for_error (die);
5407 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5408 bfd_get_filename (abfd));
5411 child_die = die->child;
5413 while (child_die && child_die->tag)
5415 process_die (child_die, cu);
5417 child_die = sibling_die (child_die);
5420 do_cleanups (back_to);
5424 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5425 struct dwarf2_cu *cu)
5427 struct function_range *thisfn;
5429 thisfn = (struct function_range *)
5430 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5431 thisfn->name = name;
5432 thisfn->lowpc = lowpc;
5433 thisfn->highpc = highpc;
5434 thisfn->seen_line = 0;
5435 thisfn->next = NULL;
5437 if (cu->last_fn == NULL)
5438 cu->first_fn = thisfn;
5440 cu->last_fn->next = thisfn;
5442 cu->last_fn = thisfn;
5445 /* qsort helper for inherit_abstract_dies. */
5448 unsigned_int_compar (const void *ap, const void *bp)
5450 unsigned int a = *(unsigned int *) ap;
5451 unsigned int b = *(unsigned int *) bp;
5453 return (a > b) - (b > a);
5456 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5457 Inherit only the children of the DW_AT_abstract_origin DIE not being
5458 already referenced by DW_AT_abstract_origin from the children of the
5462 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5464 struct die_info *child_die;
5465 unsigned die_children_count;
5466 /* CU offsets which were referenced by children of the current DIE. */
5468 unsigned *offsets_end, *offsetp;
5469 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5470 struct die_info *origin_die;
5471 /* Iterator of the ORIGIN_DIE children. */
5472 struct die_info *origin_child_die;
5473 struct cleanup *cleanups;
5474 struct attribute *attr;
5475 struct dwarf2_cu *origin_cu;
5476 struct pending **origin_previous_list_in_scope;
5478 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5482 /* Note that following die references may follow to a die in a
5486 origin_die = follow_die_ref (die, attr, &origin_cu);
5488 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5490 origin_previous_list_in_scope = origin_cu->list_in_scope;
5491 origin_cu->list_in_scope = cu->list_in_scope;
5493 if (die->tag != origin_die->tag
5494 && !(die->tag == DW_TAG_inlined_subroutine
5495 && origin_die->tag == DW_TAG_subprogram))
5496 complaint (&symfile_complaints,
5497 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5498 die->offset, origin_die->offset);
5500 child_die = die->child;
5501 die_children_count = 0;
5502 while (child_die && child_die->tag)
5504 child_die = sibling_die (child_die);
5505 die_children_count++;
5507 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5508 cleanups = make_cleanup (xfree, offsets);
5510 offsets_end = offsets;
5511 child_die = die->child;
5512 while (child_die && child_die->tag)
5514 /* For each CHILD_DIE, find the corresponding child of
5515 ORIGIN_DIE. If there is more than one layer of
5516 DW_AT_abstract_origin, follow them all; there shouldn't be,
5517 but GCC versions at least through 4.4 generate this (GCC PR
5519 struct die_info *child_origin_die = child_die;
5520 struct dwarf2_cu *child_origin_cu = cu;
5524 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5528 child_origin_die = follow_die_ref (child_origin_die, attr,
5532 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5533 counterpart may exist. */
5534 if (child_origin_die != child_die)
5536 if (child_die->tag != child_origin_die->tag
5537 && !(child_die->tag == DW_TAG_inlined_subroutine
5538 && child_origin_die->tag == DW_TAG_subprogram))
5539 complaint (&symfile_complaints,
5540 _("Child DIE 0x%x and its abstract origin 0x%x have "
5541 "different tags"), child_die->offset,
5542 child_origin_die->offset);
5543 if (child_origin_die->parent != origin_die)
5544 complaint (&symfile_complaints,
5545 _("Child DIE 0x%x and its abstract origin 0x%x have "
5546 "different parents"), child_die->offset,
5547 child_origin_die->offset);
5549 *offsets_end++ = child_origin_die->offset;
5551 child_die = sibling_die (child_die);
5553 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5554 unsigned_int_compar);
5555 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5556 if (offsetp[-1] == *offsetp)
5557 complaint (&symfile_complaints,
5558 _("Multiple children of DIE 0x%x refer "
5559 "to DIE 0x%x as their abstract origin"),
5560 die->offset, *offsetp);
5563 origin_child_die = origin_die->child;
5564 while (origin_child_die && origin_child_die->tag)
5566 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5567 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5569 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5571 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5572 process_die (origin_child_die, origin_cu);
5574 origin_child_die = sibling_die (origin_child_die);
5576 origin_cu->list_in_scope = origin_previous_list_in_scope;
5578 do_cleanups (cleanups);
5582 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5584 struct objfile *objfile = cu->objfile;
5585 struct context_stack *new;
5588 struct die_info *child_die;
5589 struct attribute *attr, *call_line, *call_file;
5592 struct block *block;
5593 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5594 VEC (symbolp) *template_args = NULL;
5595 struct template_symbol *templ_func = NULL;
5599 /* If we do not have call site information, we can't show the
5600 caller of this inlined function. That's too confusing, so
5601 only use the scope for local variables. */
5602 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5603 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5604 if (call_line == NULL || call_file == NULL)
5606 read_lexical_block_scope (die, cu);
5611 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5613 name = dwarf2_name (die, cu);
5615 /* Ignore functions with missing or empty names. These are actually
5616 illegal according to the DWARF standard. */
5619 complaint (&symfile_complaints,
5620 _("missing name for subprogram DIE at %d"), die->offset);
5624 /* Ignore functions with missing or invalid low and high pc attributes. */
5625 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5627 attr = dwarf2_attr (die, DW_AT_external, cu);
5628 if (!attr || !DW_UNSND (attr))
5629 complaint (&symfile_complaints,
5630 _("cannot get low and high bounds "
5631 "for subprogram DIE at %d"),
5639 /* Record the function range for dwarf_decode_lines. */
5640 add_to_cu_func_list (name, lowpc, highpc, cu);
5642 /* If we have any template arguments, then we must allocate a
5643 different sort of symbol. */
5644 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5646 if (child_die->tag == DW_TAG_template_type_param
5647 || child_die->tag == DW_TAG_template_value_param)
5649 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5650 struct template_symbol);
5651 templ_func->base.is_cplus_template_function = 1;
5656 new = push_context (0, lowpc);
5657 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5658 (struct symbol *) templ_func);
5660 /* If there is a location expression for DW_AT_frame_base, record
5662 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5664 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5665 expression is being recorded directly in the function's symbol
5666 and not in a separate frame-base object. I guess this hack is
5667 to avoid adding some sort of frame-base adjunct/annex to the
5668 function's symbol :-(. The problem with doing this is that it
5669 results in a function symbol with a location expression that
5670 has nothing to do with the location of the function, ouch! The
5671 relationship should be: a function's symbol has-a frame base; a
5672 frame-base has-a location expression. */
5673 dwarf2_symbol_mark_computed (attr, new->name, cu);
5675 cu->list_in_scope = &local_symbols;
5677 if (die->child != NULL)
5679 child_die = die->child;
5680 while (child_die && child_die->tag)
5682 if (child_die->tag == DW_TAG_template_type_param
5683 || child_die->tag == DW_TAG_template_value_param)
5685 struct symbol *arg = new_symbol (child_die, NULL, cu);
5688 VEC_safe_push (symbolp, template_args, arg);
5691 process_die (child_die, cu);
5692 child_die = sibling_die (child_die);
5696 inherit_abstract_dies (die, cu);
5698 /* If we have a DW_AT_specification, we might need to import using
5699 directives from the context of the specification DIE. See the
5700 comment in determine_prefix. */
5701 if (cu->language == language_cplus
5702 && dwarf2_attr (die, DW_AT_specification, cu))
5704 struct dwarf2_cu *spec_cu = cu;
5705 struct die_info *spec_die = die_specification (die, &spec_cu);
5709 child_die = spec_die->child;
5710 while (child_die && child_die->tag)
5712 if (child_die->tag == DW_TAG_imported_module)
5713 process_die (child_die, spec_cu);
5714 child_die = sibling_die (child_die);
5717 /* In some cases, GCC generates specification DIEs that
5718 themselves contain DW_AT_specification attributes. */
5719 spec_die = die_specification (spec_die, &spec_cu);
5723 new = pop_context ();
5724 /* Make a block for the local symbols within. */
5725 block = finish_block (new->name, &local_symbols, new->old_blocks,
5726 lowpc, highpc, objfile);
5728 /* For C++, set the block's scope. */
5729 if (cu->language == language_cplus || cu->language == language_fortran)
5730 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
5731 determine_prefix (die, cu),
5732 processing_has_namespace_info);
5734 /* If we have address ranges, record them. */
5735 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5737 /* Attach template arguments to function. */
5738 if (! VEC_empty (symbolp, template_args))
5740 gdb_assert (templ_func != NULL);
5742 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
5743 templ_func->template_arguments
5744 = obstack_alloc (&objfile->objfile_obstack,
5745 (templ_func->n_template_arguments
5746 * sizeof (struct symbol *)));
5747 memcpy (templ_func->template_arguments,
5748 VEC_address (symbolp, template_args),
5749 (templ_func->n_template_arguments * sizeof (struct symbol *)));
5750 VEC_free (symbolp, template_args);
5753 /* In C++, we can have functions nested inside functions (e.g., when
5754 a function declares a class that has methods). This means that
5755 when we finish processing a function scope, we may need to go
5756 back to building a containing block's symbol lists. */
5757 local_symbols = new->locals;
5758 param_symbols = new->params;
5759 using_directives = new->using_directives;
5761 /* If we've finished processing a top-level function, subsequent
5762 symbols go in the file symbol list. */
5763 if (outermost_context_p ())
5764 cu->list_in_scope = &file_symbols;
5767 /* Process all the DIES contained within a lexical block scope. Start
5768 a new scope, process the dies, and then close the scope. */
5771 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5773 struct objfile *objfile = cu->objfile;
5774 struct context_stack *new;
5775 CORE_ADDR lowpc, highpc;
5776 struct die_info *child_die;
5779 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5781 /* Ignore blocks with missing or invalid low and high pc attributes. */
5782 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5783 as multiple lexical blocks? Handling children in a sane way would
5784 be nasty. Might be easier to properly extend generic blocks to
5786 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5791 push_context (0, lowpc);
5792 if (die->child != NULL)
5794 child_die = die->child;
5795 while (child_die && child_die->tag)
5797 process_die (child_die, cu);
5798 child_die = sibling_die (child_die);
5801 new = pop_context ();
5803 if (local_symbols != NULL || using_directives != NULL)
5806 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5809 /* Note that recording ranges after traversing children, as we
5810 do here, means that recording a parent's ranges entails
5811 walking across all its children's ranges as they appear in
5812 the address map, which is quadratic behavior.
5814 It would be nicer to record the parent's ranges before
5815 traversing its children, simply overriding whatever you find
5816 there. But since we don't even decide whether to create a
5817 block until after we've traversed its children, that's hard
5819 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5821 local_symbols = new->locals;
5822 using_directives = new->using_directives;
5825 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5826 Return 1 if the attributes are present and valid, otherwise, return 0.
5827 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5830 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5831 CORE_ADDR *high_return, struct dwarf2_cu *cu,
5832 struct partial_symtab *ranges_pst)
5834 struct objfile *objfile = cu->objfile;
5835 struct comp_unit_head *cu_header = &cu->header;
5836 bfd *obfd = objfile->obfd;
5837 unsigned int addr_size = cu_header->addr_size;
5838 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
5839 /* Base address selection entry. */
5850 found_base = cu->base_known;
5851 base = cu->base_address;
5853 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
5854 if (offset >= dwarf2_per_objfile->ranges.size)
5856 complaint (&symfile_complaints,
5857 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5861 buffer = dwarf2_per_objfile->ranges.buffer + offset;
5863 /* Read in the largest possible address. */
5864 marker = read_address (obfd, buffer, cu, &dummy);
5865 if ((marker & mask) == mask)
5867 /* If we found the largest possible address, then
5868 read the base address. */
5869 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5870 buffer += 2 * addr_size;
5871 offset += 2 * addr_size;
5877 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5881 CORE_ADDR range_beginning, range_end;
5883 range_beginning = read_address (obfd, buffer, cu, &dummy);
5884 buffer += addr_size;
5885 range_end = read_address (obfd, buffer, cu, &dummy);
5886 buffer += addr_size;
5887 offset += 2 * addr_size;
5889 /* An end of list marker is a pair of zero addresses. */
5890 if (range_beginning == 0 && range_end == 0)
5891 /* Found the end of list entry. */
5894 /* Each base address selection entry is a pair of 2 values.
5895 The first is the largest possible address, the second is
5896 the base address. Check for a base address here. */
5897 if ((range_beginning & mask) == mask)
5899 /* If we found the largest possible address, then
5900 read the base address. */
5901 base = read_address (obfd, buffer + addr_size, cu, &dummy);
5908 /* We have no valid base address for the ranges
5910 complaint (&symfile_complaints,
5911 _("Invalid .debug_ranges data (no base address)"));
5915 if (range_beginning > range_end)
5917 /* Inverted range entries are invalid. */
5918 complaint (&symfile_complaints,
5919 _("Invalid .debug_ranges data (inverted range)"));
5923 /* Empty range entries have no effect. */
5924 if (range_beginning == range_end)
5927 range_beginning += base;
5930 if (ranges_pst != NULL)
5931 addrmap_set_empty (objfile->psymtabs_addrmap,
5932 range_beginning + baseaddr,
5933 range_end - 1 + baseaddr,
5936 /* FIXME: This is recording everything as a low-high
5937 segment of consecutive addresses. We should have a
5938 data structure for discontiguous block ranges
5942 low = range_beginning;
5948 if (range_beginning < low)
5949 low = range_beginning;
5950 if (range_end > high)
5956 /* If the first entry is an end-of-list marker, the range
5957 describes an empty scope, i.e. no instructions. */
5963 *high_return = high;
5967 /* Get low and high pc attributes from a die. Return 1 if the attributes
5968 are present and valid, otherwise, return 0. Return -1 if the range is
5969 discontinuous, i.e. derived from DW_AT_ranges information. */
5971 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5972 CORE_ADDR *highpc, struct dwarf2_cu *cu,
5973 struct partial_symtab *pst)
5975 struct attribute *attr;
5980 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
5983 high = DW_ADDR (attr);
5984 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5986 low = DW_ADDR (attr);
5988 /* Found high w/o low attribute. */
5991 /* Found consecutive range of addresses. */
5996 attr = dwarf2_attr (die, DW_AT_ranges, cu);
5999 /* Value of the DW_AT_ranges attribute is the offset in the
6000 .debug_ranges section. */
6001 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6003 /* Found discontinuous range of addresses. */
6008 /* read_partial_die has also the strict LOW < HIGH requirement. */
6012 /* When using the GNU linker, .gnu.linkonce. sections are used to
6013 eliminate duplicate copies of functions and vtables and such.
6014 The linker will arbitrarily choose one and discard the others.
6015 The AT_*_pc values for such functions refer to local labels in
6016 these sections. If the section from that file was discarded, the
6017 labels are not in the output, so the relocs get a value of 0.
6018 If this is a discarded function, mark the pc bounds as invalid,
6019 so that GDB will ignore it. */
6020 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6028 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6029 its low and high PC addresses. Do nothing if these addresses could not
6030 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6031 and HIGHPC to the high address if greater than HIGHPC. */
6034 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6035 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6036 struct dwarf2_cu *cu)
6038 CORE_ADDR low, high;
6039 struct die_info *child = die->child;
6041 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6043 *lowpc = min (*lowpc, low);
6044 *highpc = max (*highpc, high);
6047 /* If the language does not allow nested subprograms (either inside
6048 subprograms or lexical blocks), we're done. */
6049 if (cu->language != language_ada)
6052 /* Check all the children of the given DIE. If it contains nested
6053 subprograms, then check their pc bounds. Likewise, we need to
6054 check lexical blocks as well, as they may also contain subprogram
6056 while (child && child->tag)
6058 if (child->tag == DW_TAG_subprogram
6059 || child->tag == DW_TAG_lexical_block)
6060 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6061 child = sibling_die (child);
6065 /* Get the low and high pc's represented by the scope DIE, and store
6066 them in *LOWPC and *HIGHPC. If the correct values can't be
6067 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6070 get_scope_pc_bounds (struct die_info *die,
6071 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6072 struct dwarf2_cu *cu)
6074 CORE_ADDR best_low = (CORE_ADDR) -1;
6075 CORE_ADDR best_high = (CORE_ADDR) 0;
6076 CORE_ADDR current_low, current_high;
6078 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6080 best_low = current_low;
6081 best_high = current_high;
6085 struct die_info *child = die->child;
6087 while (child && child->tag)
6089 switch (child->tag) {
6090 case DW_TAG_subprogram:
6091 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6093 case DW_TAG_namespace:
6095 /* FIXME: carlton/2004-01-16: Should we do this for
6096 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6097 that current GCC's always emit the DIEs corresponding
6098 to definitions of methods of classes as children of a
6099 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6100 the DIEs giving the declarations, which could be
6101 anywhere). But I don't see any reason why the
6102 standards says that they have to be there. */
6103 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
6105 if (current_low != ((CORE_ADDR) -1))
6107 best_low = min (best_low, current_low);
6108 best_high = max (best_high, current_high);
6116 child = sibling_die (child);
6121 *highpc = best_high;
6124 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6127 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6128 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6130 struct attribute *attr;
6132 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6135 CORE_ADDR high = DW_ADDR (attr);
6137 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6140 CORE_ADDR low = DW_ADDR (attr);
6142 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6146 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6149 bfd *obfd = cu->objfile->obfd;
6151 /* The value of the DW_AT_ranges attribute is the offset of the
6152 address range list in the .debug_ranges section. */
6153 unsigned long offset = DW_UNSND (attr);
6154 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6156 /* For some target architectures, but not others, the
6157 read_address function sign-extends the addresses it returns.
6158 To recognize base address selection entries, we need a
6160 unsigned int addr_size = cu->header.addr_size;
6161 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6163 /* The base address, to which the next pair is relative. Note
6164 that this 'base' is a DWARF concept: most entries in a range
6165 list are relative, to reduce the number of relocs against the
6166 debugging information. This is separate from this function's
6167 'baseaddr' argument, which GDB uses to relocate debugging
6168 information from a shared library based on the address at
6169 which the library was loaded. */
6170 CORE_ADDR base = cu->base_address;
6171 int base_known = cu->base_known;
6173 gdb_assert (dwarf2_per_objfile->ranges.readin);
6174 if (offset >= dwarf2_per_objfile->ranges.size)
6176 complaint (&symfile_complaints,
6177 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6184 unsigned int bytes_read;
6185 CORE_ADDR start, end;
6187 start = read_address (obfd, buffer, cu, &bytes_read);
6188 buffer += bytes_read;
6189 end = read_address (obfd, buffer, cu, &bytes_read);
6190 buffer += bytes_read;
6192 /* Did we find the end of the range list? */
6193 if (start == 0 && end == 0)
6196 /* Did we find a base address selection entry? */
6197 else if ((start & base_select_mask) == base_select_mask)
6203 /* We found an ordinary address range. */
6208 complaint (&symfile_complaints,
6209 _("Invalid .debug_ranges data "
6210 "(no base address)"));
6216 /* Inverted range entries are invalid. */
6217 complaint (&symfile_complaints,
6218 _("Invalid .debug_ranges data "
6219 "(inverted range)"));
6223 /* Empty range entries have no effect. */
6227 record_block_range (block,
6228 baseaddr + base + start,
6229 baseaddr + base + end - 1);
6235 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6236 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6237 during 4.6.0 experimental. */
6240 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6243 int major, minor, release;
6245 if (cu->producer == NULL)
6247 /* For unknown compilers expect their behavior is DWARF version
6250 GCC started to support .debug_types sections by -gdwarf-4 since
6251 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6252 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6253 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6254 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6259 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6261 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6263 /* For non-GCC compilers expect their behavior is DWARF version
6268 cs = &cu->producer[strlen ("GNU ")];
6269 while (*cs && !isdigit (*cs))
6271 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6273 /* Not recognized as GCC. */
6278 return major < 4 || (major == 4 && minor < 6);
6281 /* Return the default accessibility type if it is not overriden by
6282 DW_AT_accessibility. */
6284 static enum dwarf_access_attribute
6285 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6287 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6289 /* The default DWARF 2 accessibility for members is public, the default
6290 accessibility for inheritance is private. */
6292 if (die->tag != DW_TAG_inheritance)
6293 return DW_ACCESS_public;
6295 return DW_ACCESS_private;
6299 /* DWARF 3+ defines the default accessibility a different way. The same
6300 rules apply now for DW_TAG_inheritance as for the members and it only
6301 depends on the container kind. */
6303 if (die->parent->tag == DW_TAG_class_type)
6304 return DW_ACCESS_private;
6306 return DW_ACCESS_public;
6310 /* Add an aggregate field to the field list. */
6313 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6314 struct dwarf2_cu *cu)
6316 struct objfile *objfile = cu->objfile;
6317 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6318 struct nextfield *new_field;
6319 struct attribute *attr;
6321 char *fieldname = "";
6323 /* Allocate a new field list entry and link it in. */
6324 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6325 make_cleanup (xfree, new_field);
6326 memset (new_field, 0, sizeof (struct nextfield));
6328 if (die->tag == DW_TAG_inheritance)
6330 new_field->next = fip->baseclasses;
6331 fip->baseclasses = new_field;
6335 new_field->next = fip->fields;
6336 fip->fields = new_field;
6340 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6342 new_field->accessibility = DW_UNSND (attr);
6344 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6345 if (new_field->accessibility != DW_ACCESS_public)
6346 fip->non_public_fields = 1;
6348 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6350 new_field->virtuality = DW_UNSND (attr);
6352 new_field->virtuality = DW_VIRTUALITY_none;
6354 fp = &new_field->field;
6356 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6358 /* Data member other than a C++ static data member. */
6360 /* Get type of field. */
6361 fp->type = die_type (die, cu);
6363 SET_FIELD_BITPOS (*fp, 0);
6365 /* Get bit size of field (zero if none). */
6366 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6369 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6373 FIELD_BITSIZE (*fp) = 0;
6376 /* Get bit offset of field. */
6377 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6380 int byte_offset = 0;
6382 if (attr_form_is_section_offset (attr))
6383 dwarf2_complex_location_expr_complaint ();
6384 else if (attr_form_is_constant (attr))
6385 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6386 else if (attr_form_is_block (attr))
6387 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6389 dwarf2_complex_location_expr_complaint ();
6391 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
6393 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6396 if (gdbarch_bits_big_endian (gdbarch))
6398 /* For big endian bits, the DW_AT_bit_offset gives the
6399 additional bit offset from the MSB of the containing
6400 anonymous object to the MSB of the field. We don't
6401 have to do anything special since we don't need to
6402 know the size of the anonymous object. */
6403 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6407 /* For little endian bits, compute the bit offset to the
6408 MSB of the anonymous object, subtract off the number of
6409 bits from the MSB of the field to the MSB of the
6410 object, and then subtract off the number of bits of
6411 the field itself. The result is the bit offset of
6412 the LSB of the field. */
6414 int bit_offset = DW_UNSND (attr);
6416 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6419 /* The size of the anonymous object containing
6420 the bit field is explicit, so use the
6421 indicated size (in bytes). */
6422 anonymous_size = DW_UNSND (attr);
6426 /* The size of the anonymous object containing
6427 the bit field must be inferred from the type
6428 attribute of the data member containing the
6430 anonymous_size = TYPE_LENGTH (fp->type);
6432 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6433 - bit_offset - FIELD_BITSIZE (*fp);
6437 /* Get name of field. */
6438 fieldname = dwarf2_name (die, cu);
6439 if (fieldname == NULL)
6442 /* The name is already allocated along with this objfile, so we don't
6443 need to duplicate it for the type. */
6444 fp->name = fieldname;
6446 /* Change accessibility for artificial fields (e.g. virtual table
6447 pointer or virtual base class pointer) to private. */
6448 if (dwarf2_attr (die, DW_AT_artificial, cu))
6450 FIELD_ARTIFICIAL (*fp) = 1;
6451 new_field->accessibility = DW_ACCESS_private;
6452 fip->non_public_fields = 1;
6455 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6457 /* C++ static member. */
6459 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6460 is a declaration, but all versions of G++ as of this writing
6461 (so through at least 3.2.1) incorrectly generate
6462 DW_TAG_variable tags. */
6466 /* Get name of field. */
6467 fieldname = dwarf2_name (die, cu);
6468 if (fieldname == NULL)
6471 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6473 /* Only create a symbol if this is an external value.
6474 new_symbol checks this and puts the value in the global symbol
6475 table, which we want. If it is not external, new_symbol
6476 will try to put the value in cu->list_in_scope which is wrong. */
6477 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6479 /* A static const member, not much different than an enum as far as
6480 we're concerned, except that we can support more types. */
6481 new_symbol (die, NULL, cu);
6484 /* Get physical name. */
6485 physname = (char *) dwarf2_physname (fieldname, die, cu);
6487 /* The name is already allocated along with this objfile, so we don't
6488 need to duplicate it for the type. */
6489 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6490 FIELD_TYPE (*fp) = die_type (die, cu);
6491 FIELD_NAME (*fp) = fieldname;
6493 else if (die->tag == DW_TAG_inheritance)
6495 /* C++ base class field. */
6496 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6499 int byte_offset = 0;
6501 if (attr_form_is_section_offset (attr))
6502 dwarf2_complex_location_expr_complaint ();
6503 else if (attr_form_is_constant (attr))
6504 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
6505 else if (attr_form_is_block (attr))
6506 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
6508 dwarf2_complex_location_expr_complaint ();
6510 SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte);
6512 FIELD_BITSIZE (*fp) = 0;
6513 FIELD_TYPE (*fp) = die_type (die, cu);
6514 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6515 fip->nbaseclasses++;
6519 /* Add a typedef defined in the scope of the FIP's class. */
6522 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6523 struct dwarf2_cu *cu)
6525 struct objfile *objfile = cu->objfile;
6526 struct typedef_field_list *new_field;
6527 struct attribute *attr;
6528 struct typedef_field *fp;
6529 char *fieldname = "";
6531 /* Allocate a new field list entry and link it in. */
6532 new_field = xzalloc (sizeof (*new_field));
6533 make_cleanup (xfree, new_field);
6535 gdb_assert (die->tag == DW_TAG_typedef);
6537 fp = &new_field->field;
6539 /* Get name of field. */
6540 fp->name = dwarf2_name (die, cu);
6541 if (fp->name == NULL)
6544 fp->type = read_type_die (die, cu);
6546 new_field->next = fip->typedef_field_list;
6547 fip->typedef_field_list = new_field;
6548 fip->typedef_field_list_count++;
6551 /* Create the vector of fields, and attach it to the type. */
6554 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6555 struct dwarf2_cu *cu)
6557 int nfields = fip->nfields;
6559 /* Record the field count, allocate space for the array of fields,
6560 and create blank accessibility bitfields if necessary. */
6561 TYPE_NFIELDS (type) = nfields;
6562 TYPE_FIELDS (type) = (struct field *)
6563 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6564 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6566 if (fip->non_public_fields && cu->language != language_ada)
6568 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6570 TYPE_FIELD_PRIVATE_BITS (type) =
6571 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6572 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6574 TYPE_FIELD_PROTECTED_BITS (type) =
6575 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6576 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6578 TYPE_FIELD_IGNORE_BITS (type) =
6579 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6580 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
6583 /* If the type has baseclasses, allocate and clear a bit vector for
6584 TYPE_FIELD_VIRTUAL_BITS. */
6585 if (fip->nbaseclasses && cu->language != language_ada)
6587 int num_bytes = B_BYTES (fip->nbaseclasses);
6588 unsigned char *pointer;
6590 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6591 pointer = TYPE_ALLOC (type, num_bytes);
6592 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6593 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6594 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6597 /* Copy the saved-up fields into the field vector. Start from the head of
6598 the list, adding to the tail of the field array, so that they end up in
6599 the same order in the array in which they were added to the list. */
6600 while (nfields-- > 0)
6602 struct nextfield *fieldp;
6606 fieldp = fip->fields;
6607 fip->fields = fieldp->next;
6611 fieldp = fip->baseclasses;
6612 fip->baseclasses = fieldp->next;
6615 TYPE_FIELD (type, nfields) = fieldp->field;
6616 switch (fieldp->accessibility)
6618 case DW_ACCESS_private:
6619 if (cu->language != language_ada)
6620 SET_TYPE_FIELD_PRIVATE (type, nfields);
6623 case DW_ACCESS_protected:
6624 if (cu->language != language_ada)
6625 SET_TYPE_FIELD_PROTECTED (type, nfields);
6628 case DW_ACCESS_public:
6632 /* Unknown accessibility. Complain and treat it as public. */
6634 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6635 fieldp->accessibility);
6639 if (nfields < fip->nbaseclasses)
6641 switch (fieldp->virtuality)
6643 case DW_VIRTUALITY_virtual:
6644 case DW_VIRTUALITY_pure_virtual:
6645 if (cu->language == language_ada)
6646 error (_("unexpected virtuality in component of Ada type"));
6647 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6654 /* Add a member function to the proper fieldlist. */
6657 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6658 struct type *type, struct dwarf2_cu *cu)
6660 struct objfile *objfile = cu->objfile;
6661 struct attribute *attr;
6662 struct fnfieldlist *flp;
6664 struct fn_field *fnp;
6666 struct nextfnfield *new_fnfield;
6667 struct type *this_type;
6668 enum dwarf_access_attribute accessibility;
6670 if (cu->language == language_ada)
6671 error (_("unexpected member function in Ada type"));
6673 /* Get name of member function. */
6674 fieldname = dwarf2_name (die, cu);
6675 if (fieldname == NULL)
6678 /* Look up member function name in fieldlist. */
6679 for (i = 0; i < fip->nfnfields; i++)
6681 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
6685 /* Create new list element if necessary. */
6686 if (i < fip->nfnfields)
6687 flp = &fip->fnfieldlists[i];
6690 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
6692 fip->fnfieldlists = (struct fnfieldlist *)
6693 xrealloc (fip->fnfieldlists,
6694 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
6695 * sizeof (struct fnfieldlist));
6696 if (fip->nfnfields == 0)
6697 make_cleanup (free_current_contents, &fip->fnfieldlists);
6699 flp = &fip->fnfieldlists[fip->nfnfields];
6700 flp->name = fieldname;
6703 i = fip->nfnfields++;
6706 /* Create a new member function field and chain it to the field list
6708 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
6709 make_cleanup (xfree, new_fnfield);
6710 memset (new_fnfield, 0, sizeof (struct nextfnfield));
6711 new_fnfield->next = flp->head;
6712 flp->head = new_fnfield;
6715 /* Fill in the member function field info. */
6716 fnp = &new_fnfield->fnfield;
6718 /* Delay processing of the physname until later. */
6719 if (cu->language == language_cplus || cu->language == language_java)
6721 add_to_method_list (type, i, flp->length - 1, fieldname,
6726 char *physname = (char *) dwarf2_physname (fieldname, die, cu);
6727 fnp->physname = physname ? physname : "";
6730 fnp->type = alloc_type (objfile);
6731 this_type = read_type_die (die, cu);
6732 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6734 int nparams = TYPE_NFIELDS (this_type);
6736 /* TYPE is the domain of this method, and THIS_TYPE is the type
6737 of the method itself (TYPE_CODE_METHOD). */
6738 smash_to_method_type (fnp->type, type,
6739 TYPE_TARGET_TYPE (this_type),
6740 TYPE_FIELDS (this_type),
6741 TYPE_NFIELDS (this_type),
6742 TYPE_VARARGS (this_type));
6744 /* Handle static member functions.
6745 Dwarf2 has no clean way to discern C++ static and non-static
6746 member functions. G++ helps GDB by marking the first
6747 parameter for non-static member functions (which is the this
6748 pointer) as artificial. We obtain this information from
6749 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6750 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
6751 fnp->voffset = VOFFSET_STATIC;
6754 complaint (&symfile_complaints, _("member function type missing for '%s'"),
6755 dwarf2_full_name (fieldname, die, cu));
6757 /* Get fcontext from DW_AT_containing_type if present. */
6758 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
6759 fnp->fcontext = die_containing_type (die, cu);
6761 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6762 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6764 /* Get accessibility. */
6765 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6767 accessibility = DW_UNSND (attr);
6769 accessibility = dwarf2_default_access_attribute (die, cu);
6770 switch (accessibility)
6772 case DW_ACCESS_private:
6773 fnp->is_private = 1;
6775 case DW_ACCESS_protected:
6776 fnp->is_protected = 1;
6780 /* Check for artificial methods. */
6781 attr = dwarf2_attr (die, DW_AT_artificial, cu);
6782 if (attr && DW_UNSND (attr) != 0)
6783 fnp->is_artificial = 1;
6785 /* Get index in virtual function table if it is a virtual member
6786 function. For older versions of GCC, this is an offset in the
6787 appropriate virtual table, as specified by DW_AT_containing_type.
6788 For everyone else, it is an expression to be evaluated relative
6789 to the object address. */
6791 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
6794 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
6796 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
6798 /* Old-style GCC. */
6799 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6801 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
6802 || (DW_BLOCK (attr)->size > 1
6803 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
6804 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
6806 struct dwarf_block blk;
6809 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
6811 blk.size = DW_BLOCK (attr)->size - offset;
6812 blk.data = DW_BLOCK (attr)->data + offset;
6813 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
6814 if ((fnp->voffset % cu->header.addr_size) != 0)
6815 dwarf2_complex_location_expr_complaint ();
6817 fnp->voffset /= cu->header.addr_size;
6821 dwarf2_complex_location_expr_complaint ();
6824 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
6826 else if (attr_form_is_section_offset (attr))
6828 dwarf2_complex_location_expr_complaint ();
6832 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6838 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6839 if (attr && DW_UNSND (attr))
6841 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6842 complaint (&symfile_complaints,
6843 _("Member function \"%s\" (offset %d) is virtual "
6844 "but the vtable offset is not specified"),
6845 fieldname, die->offset);
6846 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6847 TYPE_CPLUS_DYNAMIC (type) = 1;
6852 /* Create the vector of member function fields, and attach it to the type. */
6855 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
6856 struct dwarf2_cu *cu)
6858 struct fnfieldlist *flp;
6859 int total_length = 0;
6862 if (cu->language == language_ada)
6863 error (_("unexpected member functions in Ada type"));
6865 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6866 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
6867 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
6869 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
6871 struct nextfnfield *nfp = flp->head;
6872 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
6875 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
6876 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
6877 fn_flp->fn_fields = (struct fn_field *)
6878 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
6879 for (k = flp->length; (k--, nfp); nfp = nfp->next)
6880 fn_flp->fn_fields[k] = nfp->fnfield;
6882 total_length += flp->length;
6885 TYPE_NFN_FIELDS (type) = fip->nfnfields;
6886 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
6889 /* Returns non-zero if NAME is the name of a vtable member in CU's
6890 language, zero otherwise. */
6892 is_vtable_name (const char *name, struct dwarf2_cu *cu)
6894 static const char vptr[] = "_vptr";
6895 static const char vtable[] = "vtable";
6897 /* Look for the C++ and Java forms of the vtable. */
6898 if ((cu->language == language_java
6899 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
6900 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
6901 && is_cplus_marker (name[sizeof (vptr) - 1])))
6907 /* GCC outputs unnamed structures that are really pointers to member
6908 functions, with the ABI-specified layout. If TYPE describes
6909 such a structure, smash it into a member function type.
6911 GCC shouldn't do this; it should just output pointer to member DIEs.
6912 This is GCC PR debug/28767. */
6915 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
6917 struct type *pfn_type, *domain_type, *new_type;
6919 /* Check for a structure with no name and two children. */
6920 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
6923 /* Check for __pfn and __delta members. */
6924 if (TYPE_FIELD_NAME (type, 0) == NULL
6925 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
6926 || TYPE_FIELD_NAME (type, 1) == NULL
6927 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
6930 /* Find the type of the method. */
6931 pfn_type = TYPE_FIELD_TYPE (type, 0);
6932 if (pfn_type == NULL
6933 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
6934 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
6937 /* Look for the "this" argument. */
6938 pfn_type = TYPE_TARGET_TYPE (pfn_type);
6939 if (TYPE_NFIELDS (pfn_type) == 0
6940 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6941 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
6944 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6945 new_type = alloc_type (objfile);
6946 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6947 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6948 TYPE_VARARGS (pfn_type));
6949 smash_to_methodptr_type (type, new_type);
6952 /* Called when we find the DIE that starts a structure or union scope
6953 (definition) to create a type for the structure or union. Fill in
6954 the type's name and general properties; the members will not be
6955 processed until process_structure_type.
6957 NOTE: we need to call these functions regardless of whether or not the
6958 DIE has a DW_AT_name attribute, since it might be an anonymous
6959 structure or union. This gets the type entered into our set of
6962 However, if the structure is incomplete (an opaque struct/union)
6963 then suppress creating a symbol table entry for it since gdb only
6964 wants to find the one with the complete definition. Note that if
6965 it is complete, we just call new_symbol, which does it's own
6966 checking about whether the struct/union is anonymous or not (and
6967 suppresses creating a symbol table entry itself). */
6969 static struct type *
6970 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6972 struct objfile *objfile = cu->objfile;
6974 struct attribute *attr;
6977 /* If the definition of this type lives in .debug_types, read that type.
6978 Don't follow DW_AT_specification though, that will take us back up
6979 the chain and we want to go down. */
6980 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
6983 struct dwarf2_cu *type_cu = cu;
6984 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
6986 /* We could just recurse on read_structure_type, but we need to call
6987 get_die_type to ensure only one type for this DIE is created.
6988 This is important, for example, because for c++ classes we need
6989 TYPE_NAME set which is only done by new_symbol. Blech. */
6990 type = read_type_die (type_die, type_cu);
6992 /* TYPE_CU may not be the same as CU.
6993 Ensure TYPE is recorded in CU's type_hash table. */
6994 return set_die_type (die, type, cu);
6997 type = alloc_type (objfile);
6998 INIT_CPLUS_SPECIFIC (type);
7000 name = dwarf2_name (die, cu);
7003 if (cu->language == language_cplus
7004 || cu->language == language_java)
7006 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7008 /* dwarf2_full_name might have already finished building the DIE's
7009 type. If so, there is no need to continue. */
7010 if (get_die_type (die, cu) != NULL)
7011 return get_die_type (die, cu);
7013 TYPE_TAG_NAME (type) = full_name;
7014 if (die->tag == DW_TAG_structure_type
7015 || die->tag == DW_TAG_class_type)
7016 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7020 /* The name is already allocated along with this objfile, so
7021 we don't need to duplicate it for the type. */
7022 TYPE_TAG_NAME (type) = (char *) name;
7023 if (die->tag == DW_TAG_class_type)
7024 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7028 if (die->tag == DW_TAG_structure_type)
7030 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7032 else if (die->tag == DW_TAG_union_type)
7034 TYPE_CODE (type) = TYPE_CODE_UNION;
7038 TYPE_CODE (type) = TYPE_CODE_CLASS;
7041 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7042 TYPE_DECLARED_CLASS (type) = 1;
7044 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7047 TYPE_LENGTH (type) = DW_UNSND (attr);
7051 TYPE_LENGTH (type) = 0;
7054 TYPE_STUB_SUPPORTED (type) = 1;
7055 if (die_is_declaration (die, cu))
7056 TYPE_STUB (type) = 1;
7057 else if (attr == NULL && die->child == NULL
7058 && producer_is_realview (cu->producer))
7059 /* RealView does not output the required DW_AT_declaration
7060 on incomplete types. */
7061 TYPE_STUB (type) = 1;
7063 /* We need to add the type field to the die immediately so we don't
7064 infinitely recurse when dealing with pointers to the structure
7065 type within the structure itself. */
7066 set_die_type (die, type, cu);
7068 /* set_die_type should be already done. */
7069 set_descriptive_type (type, die, cu);
7074 /* Finish creating a structure or union type, including filling in
7075 its members and creating a symbol for it. */
7078 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7080 struct objfile *objfile = cu->objfile;
7081 struct die_info *child_die = die->child;
7084 type = get_die_type (die, cu);
7086 type = read_structure_type (die, cu);
7088 if (die->child != NULL && ! die_is_declaration (die, cu))
7090 struct field_info fi;
7091 struct die_info *child_die;
7092 VEC (symbolp) *template_args = NULL;
7093 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7095 memset (&fi, 0, sizeof (struct field_info));
7097 child_die = die->child;
7099 while (child_die && child_die->tag)
7101 if (child_die->tag == DW_TAG_member
7102 || child_die->tag == DW_TAG_variable)
7104 /* NOTE: carlton/2002-11-05: A C++ static data member
7105 should be a DW_TAG_member that is a declaration, but
7106 all versions of G++ as of this writing (so through at
7107 least 3.2.1) incorrectly generate DW_TAG_variable
7108 tags for them instead. */
7109 dwarf2_add_field (&fi, child_die, cu);
7111 else if (child_die->tag == DW_TAG_subprogram)
7113 /* C++ member function. */
7114 dwarf2_add_member_fn (&fi, child_die, type, cu);
7116 else if (child_die->tag == DW_TAG_inheritance)
7118 /* C++ base class field. */
7119 dwarf2_add_field (&fi, child_die, cu);
7121 else if (child_die->tag == DW_TAG_typedef)
7122 dwarf2_add_typedef (&fi, child_die, cu);
7123 else if (child_die->tag == DW_TAG_template_type_param
7124 || child_die->tag == DW_TAG_template_value_param)
7126 struct symbol *arg = new_symbol (child_die, NULL, cu);
7129 VEC_safe_push (symbolp, template_args, arg);
7132 child_die = sibling_die (child_die);
7135 /* Attach template arguments to type. */
7136 if (! VEC_empty (symbolp, template_args))
7138 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7139 TYPE_N_TEMPLATE_ARGUMENTS (type)
7140 = VEC_length (symbolp, template_args);
7141 TYPE_TEMPLATE_ARGUMENTS (type)
7142 = obstack_alloc (&objfile->objfile_obstack,
7143 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7144 * sizeof (struct symbol *)));
7145 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7146 VEC_address (symbolp, template_args),
7147 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7148 * sizeof (struct symbol *)));
7149 VEC_free (symbolp, template_args);
7152 /* Attach fields and member functions to the type. */
7154 dwarf2_attach_fields_to_type (&fi, type, cu);
7157 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7159 /* Get the type which refers to the base class (possibly this
7160 class itself) which contains the vtable pointer for the current
7161 class from the DW_AT_containing_type attribute. This use of
7162 DW_AT_containing_type is a GNU extension. */
7164 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7166 struct type *t = die_containing_type (die, cu);
7168 TYPE_VPTR_BASETYPE (type) = t;
7173 /* Our own class provides vtbl ptr. */
7174 for (i = TYPE_NFIELDS (t) - 1;
7175 i >= TYPE_N_BASECLASSES (t);
7178 char *fieldname = TYPE_FIELD_NAME (t, i);
7180 if (is_vtable_name (fieldname, cu))
7182 TYPE_VPTR_FIELDNO (type) = i;
7187 /* Complain if virtual function table field not found. */
7188 if (i < TYPE_N_BASECLASSES (t))
7189 complaint (&symfile_complaints,
7190 _("virtual function table pointer "
7191 "not found when defining class '%s'"),
7192 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7197 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7200 else if (cu->producer
7201 && strncmp (cu->producer,
7202 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7204 /* The IBM XLC compiler does not provide direct indication
7205 of the containing type, but the vtable pointer is
7206 always named __vfp. */
7210 for (i = TYPE_NFIELDS (type) - 1;
7211 i >= TYPE_N_BASECLASSES (type);
7214 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7216 TYPE_VPTR_FIELDNO (type) = i;
7217 TYPE_VPTR_BASETYPE (type) = type;
7224 /* Copy fi.typedef_field_list linked list elements content into the
7225 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7226 if (fi.typedef_field_list)
7228 int i = fi.typedef_field_list_count;
7230 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7231 TYPE_TYPEDEF_FIELD_ARRAY (type)
7232 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7233 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7235 /* Reverse the list order to keep the debug info elements order. */
7238 struct typedef_field *dest, *src;
7240 dest = &TYPE_TYPEDEF_FIELD (type, i);
7241 src = &fi.typedef_field_list->field;
7242 fi.typedef_field_list = fi.typedef_field_list->next;
7247 do_cleanups (back_to);
7250 quirk_gcc_member_function_pointer (type, cu->objfile);
7252 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7253 snapshots) has been known to create a die giving a declaration
7254 for a class that has, as a child, a die giving a definition for a
7255 nested class. So we have to process our children even if the
7256 current die is a declaration. Normally, of course, a declaration
7257 won't have any children at all. */
7259 while (child_die != NULL && child_die->tag)
7261 if (child_die->tag == DW_TAG_member
7262 || child_die->tag == DW_TAG_variable
7263 || child_die->tag == DW_TAG_inheritance
7264 || child_die->tag == DW_TAG_template_value_param
7265 || child_die->tag == DW_TAG_template_type_param)
7270 process_die (child_die, cu);
7272 child_die = sibling_die (child_die);
7275 /* Do not consider external references. According to the DWARF standard,
7276 these DIEs are identified by the fact that they have no byte_size
7277 attribute, and a declaration attribute. */
7278 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7279 || !die_is_declaration (die, cu))
7280 new_symbol (die, type, cu);
7283 /* Given a DW_AT_enumeration_type die, set its type. We do not
7284 complete the type's fields yet, or create any symbols. */
7286 static struct type *
7287 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7289 struct objfile *objfile = cu->objfile;
7291 struct attribute *attr;
7294 /* If the definition of this type lives in .debug_types, read that type.
7295 Don't follow DW_AT_specification though, that will take us back up
7296 the chain and we want to go down. */
7297 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7300 struct dwarf2_cu *type_cu = cu;
7301 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7303 type = read_type_die (type_die, type_cu);
7305 /* TYPE_CU may not be the same as CU.
7306 Ensure TYPE is recorded in CU's type_hash table. */
7307 return set_die_type (die, type, cu);
7310 type = alloc_type (objfile);
7312 TYPE_CODE (type) = TYPE_CODE_ENUM;
7313 name = dwarf2_full_name (NULL, die, cu);
7315 TYPE_TAG_NAME (type) = (char *) name;
7317 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7320 TYPE_LENGTH (type) = DW_UNSND (attr);
7324 TYPE_LENGTH (type) = 0;
7327 /* The enumeration DIE can be incomplete. In Ada, any type can be
7328 declared as private in the package spec, and then defined only
7329 inside the package body. Such types are known as Taft Amendment
7330 Types. When another package uses such a type, an incomplete DIE
7331 may be generated by the compiler. */
7332 if (die_is_declaration (die, cu))
7333 TYPE_STUB (type) = 1;
7335 return set_die_type (die, type, cu);
7338 /* Given a pointer to a die which begins an enumeration, process all
7339 the dies that define the members of the enumeration, and create the
7340 symbol for the enumeration type.
7342 NOTE: We reverse the order of the element list. */
7345 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7347 struct type *this_type;
7349 this_type = get_die_type (die, cu);
7350 if (this_type == NULL)
7351 this_type = read_enumeration_type (die, cu);
7353 if (die->child != NULL)
7355 struct die_info *child_die;
7357 struct field *fields = NULL;
7359 int unsigned_enum = 1;
7362 child_die = die->child;
7363 while (child_die && child_die->tag)
7365 if (child_die->tag != DW_TAG_enumerator)
7367 process_die (child_die, cu);
7371 name = dwarf2_name (child_die, cu);
7374 sym = new_symbol (child_die, this_type, cu);
7375 if (SYMBOL_VALUE (sym) < 0)
7378 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7380 fields = (struct field *)
7382 (num_fields + DW_FIELD_ALLOC_CHUNK)
7383 * sizeof (struct field));
7386 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7387 FIELD_TYPE (fields[num_fields]) = NULL;
7388 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7389 FIELD_BITSIZE (fields[num_fields]) = 0;
7395 child_die = sibling_die (child_die);
7400 TYPE_NFIELDS (this_type) = num_fields;
7401 TYPE_FIELDS (this_type) = (struct field *)
7402 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7403 memcpy (TYPE_FIELDS (this_type), fields,
7404 sizeof (struct field) * num_fields);
7408 TYPE_UNSIGNED (this_type) = 1;
7411 new_symbol (die, this_type, cu);
7414 /* Extract all information from a DW_TAG_array_type DIE and put it in
7415 the DIE's type field. For now, this only handles one dimensional
7418 static struct type *
7419 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7421 struct objfile *objfile = cu->objfile;
7422 struct die_info *child_die;
7424 struct type *element_type, *range_type, *index_type;
7425 struct type **range_types = NULL;
7426 struct attribute *attr;
7428 struct cleanup *back_to;
7431 element_type = die_type (die, cu);
7433 /* The die_type call above may have already set the type for this DIE. */
7434 type = get_die_type (die, cu);
7438 /* Irix 6.2 native cc creates array types without children for
7439 arrays with unspecified length. */
7440 if (die->child == NULL)
7442 index_type = objfile_type (objfile)->builtin_int;
7443 range_type = create_range_type (NULL, index_type, 0, -1);
7444 type = create_array_type (NULL, element_type, range_type);
7445 return set_die_type (die, type, cu);
7448 back_to = make_cleanup (null_cleanup, NULL);
7449 child_die = die->child;
7450 while (child_die && child_die->tag)
7452 if (child_die->tag == DW_TAG_subrange_type)
7454 struct type *child_type = read_type_die (child_die, cu);
7456 if (child_type != NULL)
7458 /* The range type was succesfully read. Save it for the
7459 array type creation. */
7460 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7462 range_types = (struct type **)
7463 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7464 * sizeof (struct type *));
7466 make_cleanup (free_current_contents, &range_types);
7468 range_types[ndim++] = child_type;
7471 child_die = sibling_die (child_die);
7474 /* Dwarf2 dimensions are output from left to right, create the
7475 necessary array types in backwards order. */
7477 type = element_type;
7479 if (read_array_order (die, cu) == DW_ORD_col_major)
7484 type = create_array_type (NULL, type, range_types[i++]);
7489 type = create_array_type (NULL, type, range_types[ndim]);
7492 /* Understand Dwarf2 support for vector types (like they occur on
7493 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7494 array type. This is not part of the Dwarf2/3 standard yet, but a
7495 custom vendor extension. The main difference between a regular
7496 array and the vector variant is that vectors are passed by value
7498 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7500 make_vector_type (type);
7502 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7503 implementation may choose to implement triple vectors using this
7505 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7508 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
7509 TYPE_LENGTH (type) = DW_UNSND (attr);
7511 complaint (&symfile_complaints,
7512 _("DW_AT_byte_size for array type smaller "
7513 "than the total size of elements"));
7516 name = dwarf2_name (die, cu);
7518 TYPE_NAME (type) = name;
7520 /* Install the type in the die. */
7521 set_die_type (die, type, cu);
7523 /* set_die_type should be already done. */
7524 set_descriptive_type (type, die, cu);
7526 do_cleanups (back_to);
7531 static enum dwarf_array_dim_ordering
7532 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7534 struct attribute *attr;
7536 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7538 if (attr) return DW_SND (attr);
7540 /* GNU F77 is a special case, as at 08/2004 array type info is the
7541 opposite order to the dwarf2 specification, but data is still
7542 laid out as per normal fortran.
7544 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7545 version checking. */
7547 if (cu->language == language_fortran
7548 && cu->producer && strstr (cu->producer, "GNU F77"))
7550 return DW_ORD_row_major;
7553 switch (cu->language_defn->la_array_ordering)
7555 case array_column_major:
7556 return DW_ORD_col_major;
7557 case array_row_major:
7559 return DW_ORD_row_major;
7563 /* Extract all information from a DW_TAG_set_type DIE and put it in
7564 the DIE's type field. */
7566 static struct type *
7567 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7569 struct type *domain_type, *set_type;
7570 struct attribute *attr;
7572 domain_type = die_type (die, cu);
7574 /* The die_type call above may have already set the type for this DIE. */
7575 set_type = get_die_type (die, cu);
7579 set_type = create_set_type (NULL, domain_type);
7581 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7583 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7585 return set_die_type (die, set_type, cu);
7588 /* First cut: install each common block member as a global variable. */
7591 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7593 struct die_info *child_die;
7594 struct attribute *attr;
7596 CORE_ADDR base = (CORE_ADDR) 0;
7598 attr = dwarf2_attr (die, DW_AT_location, cu);
7601 /* Support the .debug_loc offsets. */
7602 if (attr_form_is_block (attr))
7604 base = decode_locdesc (DW_BLOCK (attr), cu);
7606 else if (attr_form_is_section_offset (attr))
7608 dwarf2_complex_location_expr_complaint ();
7612 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7613 "common block member");
7616 if (die->child != NULL)
7618 child_die = die->child;
7619 while (child_die && child_die->tag)
7621 sym = new_symbol (child_die, NULL, cu);
7622 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
7623 if (sym != NULL && attr != NULL)
7625 CORE_ADDR byte_offset = 0;
7627 if (attr_form_is_section_offset (attr))
7628 dwarf2_complex_location_expr_complaint ();
7629 else if (attr_form_is_constant (attr))
7630 byte_offset = dwarf2_get_attr_constant_value (attr, 0);
7631 else if (attr_form_is_block (attr))
7632 byte_offset = decode_locdesc (DW_BLOCK (attr), cu);
7634 dwarf2_complex_location_expr_complaint ();
7636 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
7637 add_symbol_to_list (sym, &global_symbols);
7639 child_die = sibling_die (child_die);
7644 /* Create a type for a C++ namespace. */
7646 static struct type *
7647 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7649 struct objfile *objfile = cu->objfile;
7650 const char *previous_prefix, *name;
7654 /* For extensions, reuse the type of the original namespace. */
7655 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7657 struct die_info *ext_die;
7658 struct dwarf2_cu *ext_cu = cu;
7660 ext_die = dwarf2_extension (die, &ext_cu);
7661 type = read_type_die (ext_die, ext_cu);
7663 /* EXT_CU may not be the same as CU.
7664 Ensure TYPE is recorded in CU's type_hash table. */
7665 return set_die_type (die, type, cu);
7668 name = namespace_name (die, &is_anonymous, cu);
7670 /* Now build the name of the current namespace. */
7672 previous_prefix = determine_prefix (die, cu);
7673 if (previous_prefix[0] != '\0')
7674 name = typename_concat (&objfile->objfile_obstack,
7675 previous_prefix, name, 0, cu);
7677 /* Create the type. */
7678 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
7680 TYPE_NAME (type) = (char *) name;
7681 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7683 return set_die_type (die, type, cu);
7686 /* Read a C++ namespace. */
7689 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
7691 struct objfile *objfile = cu->objfile;
7694 /* Add a symbol associated to this if we haven't seen the namespace
7695 before. Also, add a using directive if it's an anonymous
7698 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
7702 type = read_type_die (die, cu);
7703 new_symbol (die, type, cu);
7705 namespace_name (die, &is_anonymous, cu);
7708 const char *previous_prefix = determine_prefix (die, cu);
7710 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
7711 NULL, &objfile->objfile_obstack);
7715 if (die->child != NULL)
7717 struct die_info *child_die = die->child;
7719 while (child_die && child_die->tag)
7721 process_die (child_die, cu);
7722 child_die = sibling_die (child_die);
7727 /* Read a Fortran module as type. This DIE can be only a declaration used for
7728 imported module. Still we need that type as local Fortran "use ... only"
7729 declaration imports depend on the created type in determine_prefix. */
7731 static struct type *
7732 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
7734 struct objfile *objfile = cu->objfile;
7738 module_name = dwarf2_name (die, cu);
7740 complaint (&symfile_complaints,
7741 _("DW_TAG_module has no name, offset 0x%x"),
7743 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
7745 /* determine_prefix uses TYPE_TAG_NAME. */
7746 TYPE_TAG_NAME (type) = TYPE_NAME (type);
7748 return set_die_type (die, type, cu);
7751 /* Read a Fortran module. */
7754 read_module (struct die_info *die, struct dwarf2_cu *cu)
7756 struct die_info *child_die = die->child;
7758 while (child_die && child_die->tag)
7760 process_die (child_die, cu);
7761 child_die = sibling_die (child_die);
7765 /* Return the name of the namespace represented by DIE. Set
7766 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7770 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
7772 struct die_info *current_die;
7773 const char *name = NULL;
7775 /* Loop through the extensions until we find a name. */
7777 for (current_die = die;
7778 current_die != NULL;
7779 current_die = dwarf2_extension (die, &cu))
7781 name = dwarf2_name (current_die, cu);
7786 /* Is it an anonymous namespace? */
7788 *is_anonymous = (name == NULL);
7790 name = "(anonymous namespace)";
7795 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7796 the user defined type vector. */
7798 static struct type *
7799 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
7801 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
7802 struct comp_unit_head *cu_header = &cu->header;
7804 struct attribute *attr_byte_size;
7805 struct attribute *attr_address_class;
7806 int byte_size, addr_class;
7807 struct type *target_type;
7809 target_type = die_type (die, cu);
7811 /* The die_type call above may have already set the type for this DIE. */
7812 type = get_die_type (die, cu);
7816 type = lookup_pointer_type (target_type);
7818 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
7820 byte_size = DW_UNSND (attr_byte_size);
7822 byte_size = cu_header->addr_size;
7824 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
7825 if (attr_address_class)
7826 addr_class = DW_UNSND (attr_address_class);
7828 addr_class = DW_ADDR_none;
7830 /* If the pointer size or address class is different than the
7831 default, create a type variant marked as such and set the
7832 length accordingly. */
7833 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
7835 if (gdbarch_address_class_type_flags_p (gdbarch))
7839 type_flags = gdbarch_address_class_type_flags
7840 (gdbarch, byte_size, addr_class);
7841 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
7843 type = make_type_with_address_space (type, type_flags);
7845 else if (TYPE_LENGTH (type) != byte_size)
7847 complaint (&symfile_complaints,
7848 _("invalid pointer size %d"), byte_size);
7852 /* Should we also complain about unhandled address classes? */
7856 TYPE_LENGTH (type) = byte_size;
7857 return set_die_type (die, type, cu);
7860 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7861 the user defined type vector. */
7863 static struct type *
7864 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
7867 struct type *to_type;
7868 struct type *domain;
7870 to_type = die_type (die, cu);
7871 domain = die_containing_type (die, cu);
7873 /* The calls above may have already set the type for this DIE. */
7874 type = get_die_type (die, cu);
7878 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
7879 type = lookup_methodptr_type (to_type);
7881 type = lookup_memberptr_type (to_type, domain);
7883 return set_die_type (die, type, cu);
7886 /* Extract all information from a DW_TAG_reference_type DIE and add to
7887 the user defined type vector. */
7889 static struct type *
7890 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
7892 struct comp_unit_head *cu_header = &cu->header;
7893 struct type *type, *target_type;
7894 struct attribute *attr;
7896 target_type = die_type (die, cu);
7898 /* The die_type call above may have already set the type for this DIE. */
7899 type = get_die_type (die, cu);
7903 type = lookup_reference_type (target_type);
7904 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7907 TYPE_LENGTH (type) = DW_UNSND (attr);
7911 TYPE_LENGTH (type) = cu_header->addr_size;
7913 return set_die_type (die, type, cu);
7916 static struct type *
7917 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
7919 struct type *base_type, *cv_type;
7921 base_type = die_type (die, cu);
7923 /* The die_type call above may have already set the type for this DIE. */
7924 cv_type = get_die_type (die, cu);
7928 /* In case the const qualifier is applied to an array type, the element type
7929 is so qualified, not the array type (section 6.7.3 of C99). */
7930 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
7932 struct type *el_type, *inner_array;
7934 base_type = copy_type (base_type);
7935 inner_array = base_type;
7937 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
7939 TYPE_TARGET_TYPE (inner_array) =
7940 copy_type (TYPE_TARGET_TYPE (inner_array));
7941 inner_array = TYPE_TARGET_TYPE (inner_array);
7944 el_type = TYPE_TARGET_TYPE (inner_array);
7945 TYPE_TARGET_TYPE (inner_array) =
7946 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
7948 return set_die_type (die, base_type, cu);
7951 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
7952 return set_die_type (die, cv_type, cu);
7955 static struct type *
7956 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
7958 struct type *base_type, *cv_type;
7960 base_type = die_type (die, cu);
7962 /* The die_type call above may have already set the type for this DIE. */
7963 cv_type = get_die_type (die, cu);
7967 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
7968 return set_die_type (die, cv_type, cu);
7971 /* Extract all information from a DW_TAG_string_type DIE and add to
7972 the user defined type vector. It isn't really a user defined type,
7973 but it behaves like one, with other DIE's using an AT_user_def_type
7974 attribute to reference it. */
7976 static struct type *
7977 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
7979 struct objfile *objfile = cu->objfile;
7980 struct gdbarch *gdbarch = get_objfile_arch (objfile);
7981 struct type *type, *range_type, *index_type, *char_type;
7982 struct attribute *attr;
7983 unsigned int length;
7985 attr = dwarf2_attr (die, DW_AT_string_length, cu);
7988 length = DW_UNSND (attr);
7992 /* Check for the DW_AT_byte_size attribute. */
7993 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7996 length = DW_UNSND (attr);
8004 index_type = objfile_type (objfile)->builtin_int;
8005 range_type = create_range_type (NULL, index_type, 1, length);
8006 char_type = language_string_char_type (cu->language_defn, gdbarch);
8007 type = create_string_type (NULL, char_type, range_type);
8009 return set_die_type (die, type, cu);
8012 /* Handle DIES due to C code like:
8016 int (*funcp)(int a, long l);
8020 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8022 static struct type *
8023 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8025 struct type *type; /* Type that this function returns. */
8026 struct type *ftype; /* Function that returns above type. */
8027 struct attribute *attr;
8029 type = die_type (die, cu);
8031 /* The die_type call above may have already set the type for this DIE. */
8032 ftype = get_die_type (die, cu);
8036 ftype = lookup_function_type (type);
8038 /* All functions in C++, Pascal and Java have prototypes. */
8039 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8040 if ((attr && (DW_UNSND (attr) != 0))
8041 || cu->language == language_cplus
8042 || cu->language == language_java
8043 || cu->language == language_pascal)
8044 TYPE_PROTOTYPED (ftype) = 1;
8045 else if (producer_is_realview (cu->producer))
8046 /* RealView does not emit DW_AT_prototyped. We can not
8047 distinguish prototyped and unprototyped functions; default to
8048 prototyped, since that is more common in modern code (and
8049 RealView warns about unprototyped functions). */
8050 TYPE_PROTOTYPED (ftype) = 1;
8052 /* Store the calling convention in the type if it's available in
8053 the subroutine die. Otherwise set the calling convention to
8054 the default value DW_CC_normal. */
8055 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8057 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8058 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8059 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8061 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8063 /* We need to add the subroutine type to the die immediately so
8064 we don't infinitely recurse when dealing with parameters
8065 declared as the same subroutine type. */
8066 set_die_type (die, ftype, cu);
8068 if (die->child != NULL)
8070 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8071 struct die_info *child_die;
8072 int nparams, iparams;
8074 /* Count the number of parameters.
8075 FIXME: GDB currently ignores vararg functions, but knows about
8076 vararg member functions. */
8078 child_die = die->child;
8079 while (child_die && child_die->tag)
8081 if (child_die->tag == DW_TAG_formal_parameter)
8083 else if (child_die->tag == DW_TAG_unspecified_parameters)
8084 TYPE_VARARGS (ftype) = 1;
8085 child_die = sibling_die (child_die);
8088 /* Allocate storage for parameters and fill them in. */
8089 TYPE_NFIELDS (ftype) = nparams;
8090 TYPE_FIELDS (ftype) = (struct field *)
8091 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8093 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8094 even if we error out during the parameters reading below. */
8095 for (iparams = 0; iparams < nparams; iparams++)
8096 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8099 child_die = die->child;
8100 while (child_die && child_die->tag)
8102 if (child_die->tag == DW_TAG_formal_parameter)
8104 struct type *arg_type;
8106 /* DWARF version 2 has no clean way to discern C++
8107 static and non-static member functions. G++ helps
8108 GDB by marking the first parameter for non-static
8109 member functions (which is the this pointer) as
8110 artificial. We pass this information to
8111 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8113 DWARF version 3 added DW_AT_object_pointer, which GCC
8114 4.5 does not yet generate. */
8115 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8117 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8120 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8122 /* GCC/43521: In java, the formal parameter
8123 "this" is sometimes not marked with DW_AT_artificial. */
8124 if (cu->language == language_java)
8126 const char *name = dwarf2_name (child_die, cu);
8128 if (name && !strcmp (name, "this"))
8129 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8132 arg_type = die_type (child_die, cu);
8134 /* RealView does not mark THIS as const, which the testsuite
8135 expects. GCC marks THIS as const in method definitions,
8136 but not in the class specifications (GCC PR 43053). */
8137 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8138 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8141 struct dwarf2_cu *arg_cu = cu;
8142 const char *name = dwarf2_name (child_die, cu);
8144 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8147 /* If the compiler emits this, use it. */
8148 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8151 else if (name && strcmp (name, "this") == 0)
8152 /* Function definitions will have the argument names. */
8154 else if (name == NULL && iparams == 0)
8155 /* Declarations may not have the names, so like
8156 elsewhere in GDB, assume an artificial first
8157 argument is "this". */
8161 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8165 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8168 child_die = sibling_die (child_die);
8175 static struct type *
8176 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8178 struct objfile *objfile = cu->objfile;
8179 const char *name = NULL;
8180 struct type *this_type;
8182 name = dwarf2_full_name (NULL, die, cu);
8183 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8184 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8185 TYPE_NAME (this_type) = (char *) name;
8186 set_die_type (die, this_type, cu);
8187 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8191 /* Find a representation of a given base type and install
8192 it in the TYPE field of the die. */
8194 static struct type *
8195 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8197 struct objfile *objfile = cu->objfile;
8199 struct attribute *attr;
8200 int encoding = 0, size = 0;
8202 enum type_code code = TYPE_CODE_INT;
8204 struct type *target_type = NULL;
8206 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8209 encoding = DW_UNSND (attr);
8211 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8214 size = DW_UNSND (attr);
8216 name = dwarf2_name (die, cu);
8219 complaint (&symfile_complaints,
8220 _("DW_AT_name missing from DW_TAG_base_type"));
8225 case DW_ATE_address:
8226 /* Turn DW_ATE_address into a void * pointer. */
8227 code = TYPE_CODE_PTR;
8228 type_flags |= TYPE_FLAG_UNSIGNED;
8229 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8231 case DW_ATE_boolean:
8232 code = TYPE_CODE_BOOL;
8233 type_flags |= TYPE_FLAG_UNSIGNED;
8235 case DW_ATE_complex_float:
8236 code = TYPE_CODE_COMPLEX;
8237 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8239 case DW_ATE_decimal_float:
8240 code = TYPE_CODE_DECFLOAT;
8243 code = TYPE_CODE_FLT;
8247 case DW_ATE_unsigned:
8248 type_flags |= TYPE_FLAG_UNSIGNED;
8250 case DW_ATE_signed_char:
8251 if (cu->language == language_ada || cu->language == language_m2
8252 || cu->language == language_pascal)
8253 code = TYPE_CODE_CHAR;
8255 case DW_ATE_unsigned_char:
8256 if (cu->language == language_ada || cu->language == language_m2
8257 || cu->language == language_pascal)
8258 code = TYPE_CODE_CHAR;
8259 type_flags |= TYPE_FLAG_UNSIGNED;
8262 /* We just treat this as an integer and then recognize the
8263 type by name elsewhere. */
8267 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8268 dwarf_type_encoding_name (encoding));
8272 type = init_type (code, size, type_flags, NULL, objfile);
8273 TYPE_NAME (type) = name;
8274 TYPE_TARGET_TYPE (type) = target_type;
8276 if (name && strcmp (name, "char") == 0)
8277 TYPE_NOSIGN (type) = 1;
8279 return set_die_type (die, type, cu);
8282 /* Read the given DW_AT_subrange DIE. */
8284 static struct type *
8285 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8287 struct type *base_type;
8288 struct type *range_type;
8289 struct attribute *attr;
8293 LONGEST negative_mask;
8295 base_type = die_type (die, cu);
8296 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8297 check_typedef (base_type);
8299 /* The die_type call above may have already set the type for this DIE. */
8300 range_type = get_die_type (die, cu);
8304 if (cu->language == language_fortran)
8306 /* FORTRAN implies a lower bound of 1, if not given. */
8310 /* FIXME: For variable sized arrays either of these could be
8311 a variable rather than a constant value. We'll allow it,
8312 but we don't know how to handle it. */
8313 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8315 low = dwarf2_get_attr_constant_value (attr, 0);
8317 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8320 if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
8322 /* GCC encodes arrays with unspecified or dynamic length
8323 with a DW_FORM_block1 attribute or a reference attribute.
8324 FIXME: GDB does not yet know how to handle dynamic
8325 arrays properly, treat them as arrays with unspecified
8328 FIXME: jimb/2003-09-22: GDB does not really know
8329 how to handle arrays of unspecified length
8330 either; we just represent them as zero-length
8331 arrays. Choose an appropriate upper bound given
8332 the lower bound we've computed above. */
8336 high = dwarf2_get_attr_constant_value (attr, 1);
8340 attr = dwarf2_attr (die, DW_AT_count, cu);
8343 int count = dwarf2_get_attr_constant_value (attr, 1);
8344 high = low + count - 1;
8348 /* Unspecified array length. */
8353 /* Dwarf-2 specifications explicitly allows to create subrange types
8354 without specifying a base type.
8355 In that case, the base type must be set to the type of
8356 the lower bound, upper bound or count, in that order, if any of these
8357 three attributes references an object that has a type.
8358 If no base type is found, the Dwarf-2 specifications say that
8359 a signed integer type of size equal to the size of an address should
8361 For the following C code: `extern char gdb_int [];'
8362 GCC produces an empty range DIE.
8363 FIXME: muller/2010-05-28: Possible references to object for low bound,
8364 high bound or count are not yet handled by this code. */
8365 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8367 struct objfile *objfile = cu->objfile;
8368 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8369 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8370 struct type *int_type = objfile_type (objfile)->builtin_int;
8372 /* Test "int", "long int", and "long long int" objfile types,
8373 and select the first one having a size above or equal to the
8374 architecture address size. */
8375 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8376 base_type = int_type;
8379 int_type = objfile_type (objfile)->builtin_long;
8380 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8381 base_type = int_type;
8384 int_type = objfile_type (objfile)->builtin_long_long;
8385 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8386 base_type = int_type;
8392 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8393 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8394 low |= negative_mask;
8395 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8396 high |= negative_mask;
8398 range_type = create_range_type (NULL, base_type, low, high);
8400 /* Mark arrays with dynamic length at least as an array of unspecified
8401 length. GDB could check the boundary but before it gets implemented at
8402 least allow accessing the array elements. */
8403 if (attr && attr->form == DW_FORM_block1)
8404 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8406 /* Ada expects an empty array on no boundary attributes. */
8407 if (attr == NULL && cu->language != language_ada)
8408 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8410 name = dwarf2_name (die, cu);
8412 TYPE_NAME (range_type) = name;
8414 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8416 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8418 set_die_type (die, range_type, cu);
8420 /* set_die_type should be already done. */
8421 set_descriptive_type (range_type, die, cu);
8426 static struct type *
8427 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8431 /* For now, we only support the C meaning of an unspecified type: void. */
8433 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8434 TYPE_NAME (type) = dwarf2_name (die, cu);
8436 return set_die_type (die, type, cu);
8439 /* Trivial hash function for die_info: the hash value of a DIE
8440 is its offset in .debug_info for this objfile. */
8443 die_hash (const void *item)
8445 const struct die_info *die = item;
8450 /* Trivial comparison function for die_info structures: two DIEs
8451 are equal if they have the same offset. */
8454 die_eq (const void *item_lhs, const void *item_rhs)
8456 const struct die_info *die_lhs = item_lhs;
8457 const struct die_info *die_rhs = item_rhs;
8459 return die_lhs->offset == die_rhs->offset;
8462 /* Read a whole compilation unit into a linked list of dies. */
8464 static struct die_info *
8465 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8467 struct die_reader_specs reader_specs;
8468 int read_abbrevs = 0;
8469 struct cleanup *back_to = NULL;
8470 struct die_info *die;
8472 if (cu->dwarf2_abbrevs == NULL)
8474 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8475 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8479 gdb_assert (cu->die_hash == NULL);
8481 = htab_create_alloc_ex (cu->header.length / 12,
8485 &cu->comp_unit_obstack,
8486 hashtab_obstack_allocate,
8487 dummy_obstack_deallocate);
8489 init_cu_die_reader (&reader_specs, cu);
8491 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8494 do_cleanups (back_to);
8499 /* Main entry point for reading a DIE and all children.
8500 Read the DIE and dump it if requested. */
8502 static struct die_info *
8503 read_die_and_children (const struct die_reader_specs *reader,
8505 gdb_byte **new_info_ptr,
8506 struct die_info *parent)
8508 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8509 new_info_ptr, parent);
8511 if (dwarf2_die_debug)
8513 fprintf_unfiltered (gdb_stdlog,
8514 "\nRead die from %s of %s:\n",
8515 reader->buffer == dwarf2_per_objfile->info.buffer
8517 : reader->buffer == dwarf2_per_objfile->types.buffer
8519 : "unknown section",
8520 reader->abfd->filename);
8521 dump_die (result, dwarf2_die_debug);
8527 /* Read a single die and all its descendents. Set the die's sibling
8528 field to NULL; set other fields in the die correctly, and set all
8529 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8530 location of the info_ptr after reading all of those dies. PARENT
8531 is the parent of the die in question. */
8533 static struct die_info *
8534 read_die_and_children_1 (const struct die_reader_specs *reader,
8536 gdb_byte **new_info_ptr,
8537 struct die_info *parent)
8539 struct die_info *die;
8543 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8546 *new_info_ptr = cur_ptr;
8549 store_in_ref_table (die, reader->cu);
8552 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8556 *new_info_ptr = cur_ptr;
8559 die->sibling = NULL;
8560 die->parent = parent;
8564 /* Read a die, all of its descendents, and all of its siblings; set
8565 all of the fields of all of the dies correctly. Arguments are as
8566 in read_die_and_children. */
8568 static struct die_info *
8569 read_die_and_siblings (const struct die_reader_specs *reader,
8571 gdb_byte **new_info_ptr,
8572 struct die_info *parent)
8574 struct die_info *first_die, *last_sibling;
8578 first_die = last_sibling = NULL;
8582 struct die_info *die
8583 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8587 *new_info_ptr = cur_ptr;
8594 last_sibling->sibling = die;
8600 /* Read the die from the .debug_info section buffer. Set DIEP to
8601 point to a newly allocated die with its information, except for its
8602 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8603 whether the die has children or not. */
8606 read_full_die (const struct die_reader_specs *reader,
8607 struct die_info **diep, gdb_byte *info_ptr,
8610 unsigned int abbrev_number, bytes_read, i, offset;
8611 struct abbrev_info *abbrev;
8612 struct die_info *die;
8613 struct dwarf2_cu *cu = reader->cu;
8614 bfd *abfd = reader->abfd;
8616 offset = info_ptr - reader->buffer;
8617 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8618 info_ptr += bytes_read;
8626 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8628 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8630 bfd_get_filename (abfd));
8632 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8633 die->offset = offset;
8634 die->tag = abbrev->tag;
8635 die->abbrev = abbrev_number;
8637 die->num_attrs = abbrev->num_attrs;
8639 for (i = 0; i < abbrev->num_attrs; ++i)
8640 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8641 abfd, info_ptr, cu);
8644 *has_children = abbrev->has_children;
8648 /* In DWARF version 2, the description of the debugging information is
8649 stored in a separate .debug_abbrev section. Before we read any
8650 dies from a section we read in all abbreviations and install them
8651 in a hash table. This function also sets flags in CU describing
8652 the data found in the abbrev table. */
8655 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8657 struct comp_unit_head *cu_header = &cu->header;
8658 gdb_byte *abbrev_ptr;
8659 struct abbrev_info *cur_abbrev;
8660 unsigned int abbrev_number, bytes_read, abbrev_name;
8661 unsigned int abbrev_form, hash_number;
8662 struct attr_abbrev *cur_attrs;
8663 unsigned int allocated_attrs;
8665 /* Initialize dwarf2 abbrevs. */
8666 obstack_init (&cu->abbrev_obstack);
8667 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
8669 * sizeof (struct abbrev_info *)));
8670 memset (cu->dwarf2_abbrevs, 0,
8671 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
8673 dwarf2_read_section (dwarf2_per_objfile->objfile,
8674 &dwarf2_per_objfile->abbrev);
8675 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
8676 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8677 abbrev_ptr += bytes_read;
8679 allocated_attrs = ATTR_ALLOC_CHUNK;
8680 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
8682 /* Loop until we reach an abbrev number of 0. */
8683 while (abbrev_number)
8685 cur_abbrev = dwarf_alloc_abbrev (cu);
8687 /* read in abbrev header */
8688 cur_abbrev->number = abbrev_number;
8689 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8690 abbrev_ptr += bytes_read;
8691 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
8694 if (cur_abbrev->tag == DW_TAG_namespace)
8695 cu->has_namespace_info = 1;
8697 /* now read in declarations */
8698 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8699 abbrev_ptr += bytes_read;
8700 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8701 abbrev_ptr += bytes_read;
8704 if (cur_abbrev->num_attrs == allocated_attrs)
8706 allocated_attrs += ATTR_ALLOC_CHUNK;
8708 = xrealloc (cur_attrs, (allocated_attrs
8709 * sizeof (struct attr_abbrev)));
8712 /* Record whether this compilation unit might have
8713 inter-compilation-unit references. If we don't know what form
8714 this attribute will have, then it might potentially be a
8715 DW_FORM_ref_addr, so we conservatively expect inter-CU
8718 if (abbrev_form == DW_FORM_ref_addr
8719 || abbrev_form == DW_FORM_indirect)
8720 cu->has_form_ref_addr = 1;
8722 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
8723 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
8724 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8725 abbrev_ptr += bytes_read;
8726 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8727 abbrev_ptr += bytes_read;
8730 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
8731 (cur_abbrev->num_attrs
8732 * sizeof (struct attr_abbrev)));
8733 memcpy (cur_abbrev->attrs, cur_attrs,
8734 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
8736 hash_number = abbrev_number % ABBREV_HASH_SIZE;
8737 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
8738 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
8740 /* Get next abbreviation.
8741 Under Irix6 the abbreviations for a compilation unit are not
8742 always properly terminated with an abbrev number of 0.
8743 Exit loop if we encounter an abbreviation which we have
8744 already read (which means we are about to read the abbreviations
8745 for the next compile unit) or if the end of the abbreviation
8746 table is reached. */
8747 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
8748 >= dwarf2_per_objfile->abbrev.size)
8750 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
8751 abbrev_ptr += bytes_read;
8752 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
8759 /* Release the memory used by the abbrev table for a compilation unit. */
8762 dwarf2_free_abbrev_table (void *ptr_to_cu)
8764 struct dwarf2_cu *cu = ptr_to_cu;
8766 obstack_free (&cu->abbrev_obstack, NULL);
8767 cu->dwarf2_abbrevs = NULL;
8770 /* Lookup an abbrev_info structure in the abbrev hash table. */
8772 static struct abbrev_info *
8773 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
8775 unsigned int hash_number;
8776 struct abbrev_info *abbrev;
8778 hash_number = number % ABBREV_HASH_SIZE;
8779 abbrev = cu->dwarf2_abbrevs[hash_number];
8783 if (abbrev->number == number)
8786 abbrev = abbrev->next;
8791 /* Returns nonzero if TAG represents a type that we might generate a partial
8795 is_type_tag_for_partial (int tag)
8800 /* Some types that would be reasonable to generate partial symbols for,
8801 that we don't at present. */
8802 case DW_TAG_array_type:
8803 case DW_TAG_file_type:
8804 case DW_TAG_ptr_to_member_type:
8805 case DW_TAG_set_type:
8806 case DW_TAG_string_type:
8807 case DW_TAG_subroutine_type:
8809 case DW_TAG_base_type:
8810 case DW_TAG_class_type:
8811 case DW_TAG_interface_type:
8812 case DW_TAG_enumeration_type:
8813 case DW_TAG_structure_type:
8814 case DW_TAG_subrange_type:
8815 case DW_TAG_typedef:
8816 case DW_TAG_union_type:
8823 /* Load all DIEs that are interesting for partial symbols into memory. */
8825 static struct partial_die_info *
8826 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
8827 int building_psymtab, struct dwarf2_cu *cu)
8829 struct partial_die_info *part_die;
8830 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
8831 struct abbrev_info *abbrev;
8832 unsigned int bytes_read;
8833 unsigned int load_all = 0;
8835 int nesting_level = 1;
8840 if (cu->per_cu && cu->per_cu->load_all_dies)
8844 = htab_create_alloc_ex (cu->header.length / 12,
8848 &cu->comp_unit_obstack,
8849 hashtab_obstack_allocate,
8850 dummy_obstack_deallocate);
8852 part_die = obstack_alloc (&cu->comp_unit_obstack,
8853 sizeof (struct partial_die_info));
8857 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
8859 /* A NULL abbrev means the end of a series of children. */
8862 if (--nesting_level == 0)
8864 /* PART_DIE was probably the last thing allocated on the
8865 comp_unit_obstack, so we could call obstack_free
8866 here. We don't do that because the waste is small,
8867 and will be cleaned up when we're done with this
8868 compilation unit. This way, we're also more robust
8869 against other users of the comp_unit_obstack. */
8872 info_ptr += bytes_read;
8873 last_die = parent_die;
8874 parent_die = parent_die->die_parent;
8878 /* Check for template arguments. We never save these; if
8879 they're seen, we just mark the parent, and go on our way. */
8880 if (parent_die != NULL
8881 && cu->language == language_cplus
8882 && (abbrev->tag == DW_TAG_template_type_param
8883 || abbrev->tag == DW_TAG_template_value_param))
8885 parent_die->has_template_arguments = 1;
8889 /* We don't need a partial DIE for the template argument. */
8890 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
8896 /* We only recurse into subprograms looking for template arguments.
8897 Skip their other children. */
8899 && cu->language == language_cplus
8900 && parent_die != NULL
8901 && parent_die->tag == DW_TAG_subprogram)
8903 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8907 /* Check whether this DIE is interesting enough to save. Normally
8908 we would not be interested in members here, but there may be
8909 later variables referencing them via DW_AT_specification (for
8912 && !is_type_tag_for_partial (abbrev->tag)
8913 && abbrev->tag != DW_TAG_constant
8914 && abbrev->tag != DW_TAG_enumerator
8915 && abbrev->tag != DW_TAG_subprogram
8916 && abbrev->tag != DW_TAG_lexical_block
8917 && abbrev->tag != DW_TAG_variable
8918 && abbrev->tag != DW_TAG_namespace
8919 && abbrev->tag != DW_TAG_module
8920 && abbrev->tag != DW_TAG_member)
8922 /* Otherwise we skip to the next sibling, if any. */
8923 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
8927 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
8928 buffer, info_ptr, cu);
8930 /* This two-pass algorithm for processing partial symbols has a
8931 high cost in cache pressure. Thus, handle some simple cases
8932 here which cover the majority of C partial symbols. DIEs
8933 which neither have specification tags in them, nor could have
8934 specification tags elsewhere pointing at them, can simply be
8935 processed and discarded.
8937 This segment is also optional; scan_partial_symbols and
8938 add_partial_symbol will handle these DIEs if we chain
8939 them in normally. When compilers which do not emit large
8940 quantities of duplicate debug information are more common,
8941 this code can probably be removed. */
8943 /* Any complete simple types at the top level (pretty much all
8944 of them, for a language without namespaces), can be processed
8946 if (parent_die == NULL
8947 && part_die->has_specification == 0
8948 && part_die->is_declaration == 0
8949 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
8950 || part_die->tag == DW_TAG_base_type
8951 || part_die->tag == DW_TAG_subrange_type))
8953 if (building_psymtab && part_die->name != NULL)
8954 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8955 VAR_DOMAIN, LOC_TYPEDEF,
8956 &cu->objfile->static_psymbols,
8957 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8958 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
8962 /* The exception for DW_TAG_typedef with has_children above is
8963 a workaround of GCC PR debug/47510. In the case of this complaint
8964 type_name_no_tag_or_error will error on such types later.
8966 GDB skipped children of DW_TAG_typedef by the shortcut above and then
8967 it could not find the child DIEs referenced later, this is checked
8968 above. In correct DWARF DW_TAG_typedef should have no children. */
8970 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
8971 complaint (&symfile_complaints,
8972 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
8973 "- DIE at 0x%x [in module %s]"),
8974 part_die->offset, cu->objfile->name);
8976 /* If we're at the second level, and we're an enumerator, and
8977 our parent has no specification (meaning possibly lives in a
8978 namespace elsewhere), then we can add the partial symbol now
8979 instead of queueing it. */
8980 if (part_die->tag == DW_TAG_enumerator
8981 && parent_die != NULL
8982 && parent_die->die_parent == NULL
8983 && parent_die->tag == DW_TAG_enumeration_type
8984 && parent_die->has_specification == 0)
8986 if (part_die->name == NULL)
8987 complaint (&symfile_complaints,
8988 _("malformed enumerator DIE ignored"));
8989 else if (building_psymtab)
8990 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
8991 VAR_DOMAIN, LOC_CONST,
8992 (cu->language == language_cplus
8993 || cu->language == language_java)
8994 ? &cu->objfile->global_psymbols
8995 : &cu->objfile->static_psymbols,
8996 0, (CORE_ADDR) 0, cu->language, cu->objfile);
8998 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9002 /* We'll save this DIE so link it in. */
9003 part_die->die_parent = parent_die;
9004 part_die->die_sibling = NULL;
9005 part_die->die_child = NULL;
9007 if (last_die && last_die == parent_die)
9008 last_die->die_child = part_die;
9010 last_die->die_sibling = part_die;
9012 last_die = part_die;
9014 if (first_die == NULL)
9015 first_die = part_die;
9017 /* Maybe add the DIE to the hash table. Not all DIEs that we
9018 find interesting need to be in the hash table, because we
9019 also have the parent/sibling/child chains; only those that we
9020 might refer to by offset later during partial symbol reading.
9022 For now this means things that might have be the target of a
9023 DW_AT_specification, DW_AT_abstract_origin, or
9024 DW_AT_extension. DW_AT_extension will refer only to
9025 namespaces; DW_AT_abstract_origin refers to functions (and
9026 many things under the function DIE, but we do not recurse
9027 into function DIEs during partial symbol reading) and
9028 possibly variables as well; DW_AT_specification refers to
9029 declarations. Declarations ought to have the DW_AT_declaration
9030 flag. It happens that GCC forgets to put it in sometimes, but
9031 only for functions, not for types.
9033 Adding more things than necessary to the hash table is harmless
9034 except for the performance cost. Adding too few will result in
9035 wasted time in find_partial_die, when we reread the compilation
9036 unit with load_all_dies set. */
9039 || abbrev->tag == DW_TAG_constant
9040 || abbrev->tag == DW_TAG_subprogram
9041 || abbrev->tag == DW_TAG_variable
9042 || abbrev->tag == DW_TAG_namespace
9043 || part_die->is_declaration)
9047 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9048 part_die->offset, INSERT);
9052 part_die = obstack_alloc (&cu->comp_unit_obstack,
9053 sizeof (struct partial_die_info));
9055 /* For some DIEs we want to follow their children (if any). For C
9056 we have no reason to follow the children of structures; for other
9057 languages we have to, so that we can get at method physnames
9058 to infer fully qualified class names, for DW_AT_specification,
9059 and for C++ template arguments. For C++, we also look one level
9060 inside functions to find template arguments (if the name of the
9061 function does not already contain the template arguments).
9063 For Ada, we need to scan the children of subprograms and lexical
9064 blocks as well because Ada allows the definition of nested
9065 entities that could be interesting for the debugger, such as
9066 nested subprograms for instance. */
9067 if (last_die->has_children
9069 || last_die->tag == DW_TAG_namespace
9070 || last_die->tag == DW_TAG_module
9071 || last_die->tag == DW_TAG_enumeration_type
9072 || (cu->language == language_cplus
9073 && last_die->tag == DW_TAG_subprogram
9074 && (last_die->name == NULL
9075 || strchr (last_die->name, '<') == NULL))
9076 || (cu->language != language_c
9077 && (last_die->tag == DW_TAG_class_type
9078 || last_die->tag == DW_TAG_interface_type
9079 || last_die->tag == DW_TAG_structure_type
9080 || last_die->tag == DW_TAG_union_type))
9081 || (cu->language == language_ada
9082 && (last_die->tag == DW_TAG_subprogram
9083 || last_die->tag == DW_TAG_lexical_block))))
9086 parent_die = last_die;
9090 /* Otherwise we skip to the next sibling, if any. */
9091 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9093 /* Back to the top, do it again. */
9097 /* Read a minimal amount of information into the minimal die structure. */
9100 read_partial_die (struct partial_die_info *part_die,
9101 struct abbrev_info *abbrev,
9102 unsigned int abbrev_len, bfd *abfd,
9103 gdb_byte *buffer, gdb_byte *info_ptr,
9104 struct dwarf2_cu *cu)
9107 struct attribute attr;
9108 int has_low_pc_attr = 0;
9109 int has_high_pc_attr = 0;
9111 memset (part_die, 0, sizeof (struct partial_die_info));
9113 part_die->offset = info_ptr - buffer;
9115 info_ptr += abbrev_len;
9120 part_die->tag = abbrev->tag;
9121 part_die->has_children = abbrev->has_children;
9123 for (i = 0; i < abbrev->num_attrs; ++i)
9125 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9127 /* Store the data if it is of an attribute we want to keep in a
9128 partial symbol table. */
9132 switch (part_die->tag)
9134 case DW_TAG_compile_unit:
9135 case DW_TAG_type_unit:
9136 /* Compilation units have a DW_AT_name that is a filename, not
9137 a source language identifier. */
9138 case DW_TAG_enumeration_type:
9139 case DW_TAG_enumerator:
9140 /* These tags always have simple identifiers already; no need
9141 to canonicalize them. */
9142 part_die->name = DW_STRING (&attr);
9146 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9147 &cu->objfile->objfile_obstack);
9151 case DW_AT_linkage_name:
9152 case DW_AT_MIPS_linkage_name:
9153 /* Note that both forms of linkage name might appear. We
9154 assume they will be the same, and we only store the last
9156 if (cu->language == language_ada)
9157 part_die->name = DW_STRING (&attr);
9158 part_die->linkage_name = DW_STRING (&attr);
9161 has_low_pc_attr = 1;
9162 part_die->lowpc = DW_ADDR (&attr);
9165 has_high_pc_attr = 1;
9166 part_die->highpc = DW_ADDR (&attr);
9168 case DW_AT_location:
9169 /* Support the .debug_loc offsets. */
9170 if (attr_form_is_block (&attr))
9172 part_die->locdesc = DW_BLOCK (&attr);
9174 else if (attr_form_is_section_offset (&attr))
9176 dwarf2_complex_location_expr_complaint ();
9180 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9181 "partial symbol information");
9184 case DW_AT_external:
9185 part_die->is_external = DW_UNSND (&attr);
9187 case DW_AT_declaration:
9188 part_die->is_declaration = DW_UNSND (&attr);
9191 part_die->has_type = 1;
9193 case DW_AT_abstract_origin:
9194 case DW_AT_specification:
9195 case DW_AT_extension:
9196 part_die->has_specification = 1;
9197 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9200 /* Ignore absolute siblings, they might point outside of
9201 the current compile unit. */
9202 if (attr.form == DW_FORM_ref_addr)
9203 complaint (&symfile_complaints,
9204 _("ignoring absolute DW_AT_sibling"));
9206 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9208 case DW_AT_byte_size:
9209 part_die->has_byte_size = 1;
9211 case DW_AT_calling_convention:
9212 /* DWARF doesn't provide a way to identify a program's source-level
9213 entry point. DW_AT_calling_convention attributes are only meant
9214 to describe functions' calling conventions.
9216 However, because it's a necessary piece of information in
9217 Fortran, and because DW_CC_program is the only piece of debugging
9218 information whose definition refers to a 'main program' at all,
9219 several compilers have begun marking Fortran main programs with
9220 DW_CC_program --- even when those functions use the standard
9221 calling conventions.
9223 So until DWARF specifies a way to provide this information and
9224 compilers pick up the new representation, we'll support this
9226 if (DW_UNSND (&attr) == DW_CC_program
9227 && cu->language == language_fortran)
9229 set_main_name (part_die->name);
9231 /* As this DIE has a static linkage the name would be difficult
9232 to look up later. */
9233 language_of_main = language_fortran;
9241 if (has_low_pc_attr && has_high_pc_attr)
9243 /* When using the GNU linker, .gnu.linkonce. sections are used to
9244 eliminate duplicate copies of functions and vtables and such.
9245 The linker will arbitrarily choose one and discard the others.
9246 The AT_*_pc values for such functions refer to local labels in
9247 these sections. If the section from that file was discarded, the
9248 labels are not in the output, so the relocs get a value of 0.
9249 If this is a discarded function, mark the pc bounds as invalid,
9250 so that GDB will ignore it. */
9251 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9253 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9255 complaint (&symfile_complaints,
9256 _("DW_AT_low_pc %s is zero "
9257 "for DIE at 0x%x [in module %s]"),
9258 paddress (gdbarch, part_die->lowpc),
9259 part_die->offset, cu->objfile->name);
9261 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9262 else if (part_die->lowpc >= part_die->highpc)
9264 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9266 complaint (&symfile_complaints,
9267 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9268 "for DIE at 0x%x [in module %s]"),
9269 paddress (gdbarch, part_die->lowpc),
9270 paddress (gdbarch, part_die->highpc),
9271 part_die->offset, cu->objfile->name);
9274 part_die->has_pc_info = 1;
9280 /* Find a cached partial DIE at OFFSET in CU. */
9282 static struct partial_die_info *
9283 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9285 struct partial_die_info *lookup_die = NULL;
9286 struct partial_die_info part_die;
9288 part_die.offset = offset;
9289 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9294 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9295 except in the case of .debug_types DIEs which do not reference
9296 outside their CU (they do however referencing other types via
9297 DW_FORM_ref_sig8). */
9299 static struct partial_die_info *
9300 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9302 struct dwarf2_per_cu_data *per_cu = NULL;
9303 struct partial_die_info *pd = NULL;
9305 if (cu->per_cu->from_debug_types)
9307 pd = find_partial_die_in_comp_unit (offset, cu);
9313 if (offset_in_cu_p (&cu->header, offset))
9315 pd = find_partial_die_in_comp_unit (offset, cu);
9320 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9322 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9323 load_partial_comp_unit (per_cu, cu->objfile);
9325 per_cu->cu->last_used = 0;
9326 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9328 if (pd == NULL && per_cu->load_all_dies == 0)
9330 struct cleanup *back_to;
9331 struct partial_die_info comp_unit_die;
9332 struct abbrev_info *abbrev;
9333 unsigned int bytes_read;
9336 per_cu->load_all_dies = 1;
9338 /* Re-read the DIEs. */
9339 back_to = make_cleanup (null_cleanup, 0);
9340 if (per_cu->cu->dwarf2_abbrevs == NULL)
9342 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
9343 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9345 info_ptr = (dwarf2_per_objfile->info.buffer
9346 + per_cu->cu->header.offset
9347 + per_cu->cu->header.first_die_offset);
9348 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9349 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9350 per_cu->cu->objfile->obfd,
9351 dwarf2_per_objfile->info.buffer, info_ptr,
9353 if (comp_unit_die.has_children)
9354 load_partial_dies (per_cu->cu->objfile->obfd,
9355 dwarf2_per_objfile->info.buffer, info_ptr,
9357 do_cleanups (back_to);
9359 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9365 internal_error (__FILE__, __LINE__,
9366 _("could not find partial DIE 0x%x "
9367 "in cache [from module %s]\n"),
9368 offset, bfd_get_filename (cu->objfile->obfd));
9372 /* See if we can figure out if the class lives in a namespace. We do
9373 this by looking for a member function; its demangled name will
9374 contain namespace info, if there is any. */
9377 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9378 struct dwarf2_cu *cu)
9380 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9381 what template types look like, because the demangler
9382 frequently doesn't give the same name as the debug info. We
9383 could fix this by only using the demangled name to get the
9384 prefix (but see comment in read_structure_type). */
9386 struct partial_die_info *real_pdi;
9387 struct partial_die_info *child_pdi;
9389 /* If this DIE (this DIE's specification, if any) has a parent, then
9390 we should not do this. We'll prepend the parent's fully qualified
9391 name when we create the partial symbol. */
9393 real_pdi = struct_pdi;
9394 while (real_pdi->has_specification)
9395 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9397 if (real_pdi->die_parent != NULL)
9400 for (child_pdi = struct_pdi->die_child;
9402 child_pdi = child_pdi->die_sibling)
9404 if (child_pdi->tag == DW_TAG_subprogram
9405 && child_pdi->linkage_name != NULL)
9407 char *actual_class_name
9408 = language_class_name_from_physname (cu->language_defn,
9409 child_pdi->linkage_name);
9410 if (actual_class_name != NULL)
9413 = obsavestring (actual_class_name,
9414 strlen (actual_class_name),
9415 &cu->objfile->objfile_obstack);
9416 xfree (actual_class_name);
9423 /* Adjust PART_DIE before generating a symbol for it. This function
9424 may set the is_external flag or change the DIE's name. */
9427 fixup_partial_die (struct partial_die_info *part_die,
9428 struct dwarf2_cu *cu)
9430 /* Once we've fixed up a die, there's no point in doing so again.
9431 This also avoids a memory leak if we were to call
9432 guess_partial_die_structure_name multiple times. */
9433 if (part_die->fixup_called)
9436 /* If we found a reference attribute and the DIE has no name, try
9437 to find a name in the referred to DIE. */
9439 if (part_die->name == NULL && part_die->has_specification)
9441 struct partial_die_info *spec_die;
9443 spec_die = find_partial_die (part_die->spec_offset, cu);
9445 fixup_partial_die (spec_die, cu);
9449 part_die->name = spec_die->name;
9451 /* Copy DW_AT_external attribute if it is set. */
9452 if (spec_die->is_external)
9453 part_die->is_external = spec_die->is_external;
9457 /* Set default names for some unnamed DIEs. */
9459 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
9460 part_die->name = "(anonymous namespace)";
9462 /* If there is no parent die to provide a namespace, and there are
9463 children, see if we can determine the namespace from their linkage
9465 NOTE: We need to do this even if cu->has_namespace_info != 0.
9466 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9467 if (cu->language == language_cplus
9468 && dwarf2_per_objfile->types.asection != NULL
9469 && part_die->die_parent == NULL
9470 && part_die->has_children
9471 && (part_die->tag == DW_TAG_class_type
9472 || part_die->tag == DW_TAG_structure_type
9473 || part_die->tag == DW_TAG_union_type))
9474 guess_partial_die_structure_name (part_die, cu);
9476 /* GCC might emit a nameless struct or union that has a linkage
9477 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9478 if (part_die->name == NULL
9479 && (part_die->tag == DW_TAG_structure_type
9480 || part_die->tag == DW_TAG_union_type
9481 || part_die->tag == DW_TAG_class_type)
9482 && part_die->linkage_name != NULL)
9486 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
9489 part_die->name = obsavestring (demangled, strlen (demangled),
9490 &cu->objfile->objfile_obstack);
9495 part_die->fixup_called = 1;
9498 /* Read an attribute value described by an attribute form. */
9501 read_attribute_value (struct attribute *attr, unsigned form,
9502 bfd *abfd, gdb_byte *info_ptr,
9503 struct dwarf2_cu *cu)
9505 struct comp_unit_head *cu_header = &cu->header;
9506 unsigned int bytes_read;
9507 struct dwarf_block *blk;
9512 case DW_FORM_ref_addr:
9513 if (cu->header.version == 2)
9514 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9516 DW_ADDR (attr) = read_offset (abfd, info_ptr,
9517 &cu->header, &bytes_read);
9518 info_ptr += bytes_read;
9521 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9522 info_ptr += bytes_read;
9524 case DW_FORM_block2:
9525 blk = dwarf_alloc_block (cu);
9526 blk->size = read_2_bytes (abfd, info_ptr);
9528 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9529 info_ptr += blk->size;
9530 DW_BLOCK (attr) = blk;
9532 case DW_FORM_block4:
9533 blk = dwarf_alloc_block (cu);
9534 blk->size = read_4_bytes (abfd, info_ptr);
9536 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9537 info_ptr += blk->size;
9538 DW_BLOCK (attr) = blk;
9541 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9545 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9549 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9552 case DW_FORM_sec_offset:
9553 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9554 info_ptr += bytes_read;
9556 case DW_FORM_string:
9557 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9558 DW_STRING_IS_CANONICAL (attr) = 0;
9559 info_ptr += bytes_read;
9562 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9564 DW_STRING_IS_CANONICAL (attr) = 0;
9565 info_ptr += bytes_read;
9567 case DW_FORM_exprloc:
9569 blk = dwarf_alloc_block (cu);
9570 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9571 info_ptr += bytes_read;
9572 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9573 info_ptr += blk->size;
9574 DW_BLOCK (attr) = blk;
9576 case DW_FORM_block1:
9577 blk = dwarf_alloc_block (cu);
9578 blk->size = read_1_byte (abfd, info_ptr);
9580 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9581 info_ptr += blk->size;
9582 DW_BLOCK (attr) = blk;
9585 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9589 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9592 case DW_FORM_flag_present:
9593 DW_UNSND (attr) = 1;
9596 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9597 info_ptr += bytes_read;
9600 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9601 info_ptr += bytes_read;
9604 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9608 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9612 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9616 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9619 case DW_FORM_ref_sig8:
9620 /* Convert the signature to something we can record in DW_UNSND
9622 NOTE: This is NULL if the type wasn't found. */
9623 DW_SIGNATURED_TYPE (attr) =
9624 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9627 case DW_FORM_ref_udata:
9628 DW_ADDR (attr) = (cu->header.offset
9629 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9630 info_ptr += bytes_read;
9632 case DW_FORM_indirect:
9633 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9634 info_ptr += bytes_read;
9635 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9638 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9639 dwarf_form_name (form),
9640 bfd_get_filename (abfd));
9643 /* We have seen instances where the compiler tried to emit a byte
9644 size attribute of -1 which ended up being encoded as an unsigned
9645 0xffffffff. Although 0xffffffff is technically a valid size value,
9646 an object of this size seems pretty unlikely so we can relatively
9647 safely treat these cases as if the size attribute was invalid and
9648 treat them as zero by default. */
9649 if (attr->name == DW_AT_byte_size
9650 && form == DW_FORM_data4
9651 && DW_UNSND (attr) >= 0xffffffff)
9654 (&symfile_complaints,
9655 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9656 hex_string (DW_UNSND (attr)));
9657 DW_UNSND (attr) = 0;
9663 /* Read an attribute described by an abbreviated attribute. */
9666 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
9667 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
9669 attr->name = abbrev->name;
9670 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
9673 /* Read dwarf information from a buffer. */
9676 read_1_byte (bfd *abfd, gdb_byte *buf)
9678 return bfd_get_8 (abfd, buf);
9682 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
9684 return bfd_get_signed_8 (abfd, buf);
9688 read_2_bytes (bfd *abfd, gdb_byte *buf)
9690 return bfd_get_16 (abfd, buf);
9694 read_2_signed_bytes (bfd *abfd, gdb_byte *buf)
9696 return bfd_get_signed_16 (abfd, buf);
9700 read_4_bytes (bfd *abfd, gdb_byte *buf)
9702 return bfd_get_32 (abfd, buf);
9706 read_4_signed_bytes (bfd *abfd, gdb_byte *buf)
9708 return bfd_get_signed_32 (abfd, buf);
9712 read_8_bytes (bfd *abfd, gdb_byte *buf)
9714 return bfd_get_64 (abfd, buf);
9718 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
9719 unsigned int *bytes_read)
9721 struct comp_unit_head *cu_header = &cu->header;
9722 CORE_ADDR retval = 0;
9724 if (cu_header->signed_addr_p)
9726 switch (cu_header->addr_size)
9729 retval = bfd_get_signed_16 (abfd, buf);
9732 retval = bfd_get_signed_32 (abfd, buf);
9735 retval = bfd_get_signed_64 (abfd, buf);
9738 internal_error (__FILE__, __LINE__,
9739 _("read_address: bad switch, signed [in module %s]"),
9740 bfd_get_filename (abfd));
9745 switch (cu_header->addr_size)
9748 retval = bfd_get_16 (abfd, buf);
9751 retval = bfd_get_32 (abfd, buf);
9754 retval = bfd_get_64 (abfd, buf);
9757 internal_error (__FILE__, __LINE__,
9758 _("read_address: bad switch, "
9759 "unsigned [in module %s]"),
9760 bfd_get_filename (abfd));
9764 *bytes_read = cu_header->addr_size;
9768 /* Read the initial length from a section. The (draft) DWARF 3
9769 specification allows the initial length to take up either 4 bytes
9770 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9771 bytes describe the length and all offsets will be 8 bytes in length
9774 An older, non-standard 64-bit format is also handled by this
9775 function. The older format in question stores the initial length
9776 as an 8-byte quantity without an escape value. Lengths greater
9777 than 2^32 aren't very common which means that the initial 4 bytes
9778 is almost always zero. Since a length value of zero doesn't make
9779 sense for the 32-bit format, this initial zero can be considered to
9780 be an escape value which indicates the presence of the older 64-bit
9781 format. As written, the code can't detect (old format) lengths
9782 greater than 4GB. If it becomes necessary to handle lengths
9783 somewhat larger than 4GB, we could allow other small values (such
9784 as the non-sensical values of 1, 2, and 3) to also be used as
9785 escape values indicating the presence of the old format.
9787 The value returned via bytes_read should be used to increment the
9788 relevant pointer after calling read_initial_length().
9790 [ Note: read_initial_length() and read_offset() are based on the
9791 document entitled "DWARF Debugging Information Format", revision
9792 3, draft 8, dated November 19, 2001. This document was obtained
9795 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9797 This document is only a draft and is subject to change. (So beware.)
9799 Details regarding the older, non-standard 64-bit format were
9800 determined empirically by examining 64-bit ELF files produced by
9801 the SGI toolchain on an IRIX 6.5 machine.
9803 - Kevin, July 16, 2002
9807 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
9809 LONGEST length = bfd_get_32 (abfd, buf);
9811 if (length == 0xffffffff)
9813 length = bfd_get_64 (abfd, buf + 4);
9816 else if (length == 0)
9818 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9819 length = bfd_get_64 (abfd, buf);
9830 /* Cover function for read_initial_length.
9831 Returns the length of the object at BUF, and stores the size of the
9832 initial length in *BYTES_READ and stores the size that offsets will be in
9834 If the initial length size is not equivalent to that specified in
9835 CU_HEADER then issue a complaint.
9836 This is useful when reading non-comp-unit headers. */
9839 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
9840 const struct comp_unit_head *cu_header,
9841 unsigned int *bytes_read,
9842 unsigned int *offset_size)
9844 LONGEST length = read_initial_length (abfd, buf, bytes_read);
9846 gdb_assert (cu_header->initial_length_size == 4
9847 || cu_header->initial_length_size == 8
9848 || cu_header->initial_length_size == 12);
9850 if (cu_header->initial_length_size != *bytes_read)
9851 complaint (&symfile_complaints,
9852 _("intermixed 32-bit and 64-bit DWARF sections"));
9854 *offset_size = (*bytes_read == 4) ? 4 : 8;
9858 /* Read an offset from the data stream. The size of the offset is
9859 given by cu_header->offset_size. */
9862 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
9863 unsigned int *bytes_read)
9865 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
9867 *bytes_read = cu_header->offset_size;
9871 /* Read an offset from the data stream. */
9874 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
9878 switch (offset_size)
9881 retval = bfd_get_32 (abfd, buf);
9884 retval = bfd_get_64 (abfd, buf);
9887 internal_error (__FILE__, __LINE__,
9888 _("read_offset_1: bad switch [in module %s]"),
9889 bfd_get_filename (abfd));
9896 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
9898 /* If the size of a host char is 8 bits, we can return a pointer
9899 to the buffer, otherwise we have to copy the data to a buffer
9900 allocated on the temporary obstack. */
9901 gdb_assert (HOST_CHAR_BIT == 8);
9906 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9908 /* If the size of a host char is 8 bits, we can return a pointer
9909 to the string, otherwise we have to copy the string to a buffer
9910 allocated on the temporary obstack. */
9911 gdb_assert (HOST_CHAR_BIT == 8);
9914 *bytes_read_ptr = 1;
9917 *bytes_read_ptr = strlen ((char *) buf) + 1;
9918 return (char *) buf;
9922 read_indirect_string (bfd *abfd, gdb_byte *buf,
9923 const struct comp_unit_head *cu_header,
9924 unsigned int *bytes_read_ptr)
9926 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
9928 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
9929 if (dwarf2_per_objfile->str.buffer == NULL)
9931 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9932 bfd_get_filename (abfd));
9935 if (str_offset >= dwarf2_per_objfile->str.size)
9937 error (_("DW_FORM_strp pointing outside of "
9938 ".debug_str section [in module %s]"),
9939 bfd_get_filename (abfd));
9942 gdb_assert (HOST_CHAR_BIT == 8);
9943 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
9945 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
9948 static unsigned long
9949 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9951 unsigned long result;
9952 unsigned int num_read;
9962 byte = bfd_get_8 (abfd, buf);
9965 result |= ((unsigned long)(byte & 127) << shift);
9966 if ((byte & 128) == 0)
9972 *bytes_read_ptr = num_read;
9977 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
9980 int i, shift, num_read;
9989 byte = bfd_get_8 (abfd, buf);
9992 result |= ((long)(byte & 127) << shift);
9994 if ((byte & 128) == 0)
9999 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10000 result |= -(((long)1) << shift);
10001 *bytes_read_ptr = num_read;
10005 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10008 skip_leb128 (bfd *abfd, gdb_byte *buf)
10014 byte = bfd_get_8 (abfd, buf);
10016 if ((byte & 128) == 0)
10022 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10029 cu->language = language_c;
10031 case DW_LANG_C_plus_plus:
10032 cu->language = language_cplus;
10035 cu->language = language_d;
10037 case DW_LANG_Fortran77:
10038 case DW_LANG_Fortran90:
10039 case DW_LANG_Fortran95:
10040 cu->language = language_fortran;
10042 case DW_LANG_Mips_Assembler:
10043 cu->language = language_asm;
10046 cu->language = language_java;
10048 case DW_LANG_Ada83:
10049 case DW_LANG_Ada95:
10050 cu->language = language_ada;
10052 case DW_LANG_Modula2:
10053 cu->language = language_m2;
10055 case DW_LANG_Pascal83:
10056 cu->language = language_pascal;
10059 cu->language = language_objc;
10061 case DW_LANG_Cobol74:
10062 case DW_LANG_Cobol85:
10064 cu->language = language_minimal;
10067 cu->language_defn = language_def (cu->language);
10070 /* Return the named attribute or NULL if not there. */
10072 static struct attribute *
10073 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10076 struct attribute *spec = NULL;
10078 for (i = 0; i < die->num_attrs; ++i)
10080 if (die->attrs[i].name == name)
10081 return &die->attrs[i];
10082 if (die->attrs[i].name == DW_AT_specification
10083 || die->attrs[i].name == DW_AT_abstract_origin)
10084 spec = &die->attrs[i];
10089 die = follow_die_ref (die, spec, &cu);
10090 return dwarf2_attr (die, name, cu);
10096 /* Return the named attribute or NULL if not there,
10097 but do not follow DW_AT_specification, etc.
10098 This is for use in contexts where we're reading .debug_types dies.
10099 Following DW_AT_specification, DW_AT_abstract_origin will take us
10100 back up the chain, and we want to go down. */
10102 static struct attribute *
10103 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10104 struct dwarf2_cu *cu)
10108 for (i = 0; i < die->num_attrs; ++i)
10109 if (die->attrs[i].name == name)
10110 return &die->attrs[i];
10115 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10116 and holds a non-zero value. This function should only be used for
10117 DW_FORM_flag or DW_FORM_flag_present attributes. */
10120 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10122 struct attribute *attr = dwarf2_attr (die, name, cu);
10124 return (attr && DW_UNSND (attr));
10128 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10130 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10131 which value is non-zero. However, we have to be careful with
10132 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10133 (via dwarf2_flag_true_p) follows this attribute. So we may
10134 end up accidently finding a declaration attribute that belongs
10135 to a different DIE referenced by the specification attribute,
10136 even though the given DIE does not have a declaration attribute. */
10137 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10138 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10141 /* Return the die giving the specification for DIE, if there is
10142 one. *SPEC_CU is the CU containing DIE on input, and the CU
10143 containing the return value on output. If there is no
10144 specification, but there is an abstract origin, that is
10147 static struct die_info *
10148 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10150 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10153 if (spec_attr == NULL)
10154 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10156 if (spec_attr == NULL)
10159 return follow_die_ref (die, spec_attr, spec_cu);
10162 /* Free the line_header structure *LH, and any arrays and strings it
10164 NOTE: This is also used as a "cleanup" function. */
10167 free_line_header (struct line_header *lh)
10169 if (lh->standard_opcode_lengths)
10170 xfree (lh->standard_opcode_lengths);
10172 /* Remember that all the lh->file_names[i].name pointers are
10173 pointers into debug_line_buffer, and don't need to be freed. */
10174 if (lh->file_names)
10175 xfree (lh->file_names);
10177 /* Similarly for the include directory names. */
10178 if (lh->include_dirs)
10179 xfree (lh->include_dirs);
10184 /* Add an entry to LH's include directory table. */
10187 add_include_dir (struct line_header *lh, char *include_dir)
10189 /* Grow the array if necessary. */
10190 if (lh->include_dirs_size == 0)
10192 lh->include_dirs_size = 1; /* for testing */
10193 lh->include_dirs = xmalloc (lh->include_dirs_size
10194 * sizeof (*lh->include_dirs));
10196 else if (lh->num_include_dirs >= lh->include_dirs_size)
10198 lh->include_dirs_size *= 2;
10199 lh->include_dirs = xrealloc (lh->include_dirs,
10200 (lh->include_dirs_size
10201 * sizeof (*lh->include_dirs)));
10204 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10207 /* Add an entry to LH's file name table. */
10210 add_file_name (struct line_header *lh,
10212 unsigned int dir_index,
10213 unsigned int mod_time,
10214 unsigned int length)
10216 struct file_entry *fe;
10218 /* Grow the array if necessary. */
10219 if (lh->file_names_size == 0)
10221 lh->file_names_size = 1; /* for testing */
10222 lh->file_names = xmalloc (lh->file_names_size
10223 * sizeof (*lh->file_names));
10225 else if (lh->num_file_names >= lh->file_names_size)
10227 lh->file_names_size *= 2;
10228 lh->file_names = xrealloc (lh->file_names,
10229 (lh->file_names_size
10230 * sizeof (*lh->file_names)));
10233 fe = &lh->file_names[lh->num_file_names++];
10235 fe->dir_index = dir_index;
10236 fe->mod_time = mod_time;
10237 fe->length = length;
10238 fe->included_p = 0;
10242 /* Read the statement program header starting at OFFSET in
10243 .debug_line, according to the endianness of ABFD. Return a pointer
10244 to a struct line_header, allocated using xmalloc.
10246 NOTE: the strings in the include directory and file name tables of
10247 the returned object point into debug_line_buffer, and must not be
10250 static struct line_header *
10251 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10252 struct dwarf2_cu *cu)
10254 struct cleanup *back_to;
10255 struct line_header *lh;
10256 gdb_byte *line_ptr;
10257 unsigned int bytes_read, offset_size;
10259 char *cur_dir, *cur_file;
10261 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10262 if (dwarf2_per_objfile->line.buffer == NULL)
10264 complaint (&symfile_complaints, _("missing .debug_line section"));
10268 /* Make sure that at least there's room for the total_length field.
10269 That could be 12 bytes long, but we're just going to fudge that. */
10270 if (offset + 4 >= dwarf2_per_objfile->line.size)
10272 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10276 lh = xmalloc (sizeof (*lh));
10277 memset (lh, 0, sizeof (*lh));
10278 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10281 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10283 /* Read in the header. */
10285 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10286 &bytes_read, &offset_size);
10287 line_ptr += bytes_read;
10288 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10289 + dwarf2_per_objfile->line.size))
10291 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10294 lh->statement_program_end = line_ptr + lh->total_length;
10295 lh->version = read_2_bytes (abfd, line_ptr);
10297 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10298 line_ptr += offset_size;
10299 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10301 if (lh->version >= 4)
10303 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10307 lh->maximum_ops_per_instruction = 1;
10309 if (lh->maximum_ops_per_instruction == 0)
10311 lh->maximum_ops_per_instruction = 1;
10312 complaint (&symfile_complaints,
10313 _("invalid maximum_ops_per_instruction "
10314 "in `.debug_line' section"));
10317 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10319 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10321 lh->line_range = read_1_byte (abfd, line_ptr);
10323 lh->opcode_base = read_1_byte (abfd, line_ptr);
10325 lh->standard_opcode_lengths
10326 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10328 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10329 for (i = 1; i < lh->opcode_base; ++i)
10331 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10335 /* Read directory table. */
10336 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10338 line_ptr += bytes_read;
10339 add_include_dir (lh, cur_dir);
10341 line_ptr += bytes_read;
10343 /* Read file name table. */
10344 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10346 unsigned int dir_index, mod_time, length;
10348 line_ptr += bytes_read;
10349 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10350 line_ptr += bytes_read;
10351 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10352 line_ptr += bytes_read;
10353 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10354 line_ptr += bytes_read;
10356 add_file_name (lh, cur_file, dir_index, mod_time, length);
10358 line_ptr += bytes_read;
10359 lh->statement_program_start = line_ptr;
10361 if (line_ptr > (dwarf2_per_objfile->line.buffer
10362 + dwarf2_per_objfile->line.size))
10363 complaint (&symfile_complaints,
10364 _("line number info header doesn't "
10365 "fit in `.debug_line' section"));
10367 discard_cleanups (back_to);
10371 /* This function exists to work around a bug in certain compilers
10372 (particularly GCC 2.95), in which the first line number marker of a
10373 function does not show up until after the prologue, right before
10374 the second line number marker. This function shifts ADDRESS down
10375 to the beginning of the function if necessary, and is called on
10376 addresses passed to record_line. */
10379 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
10381 struct function_range *fn;
10383 /* Find the function_range containing address. */
10387 if (!cu->cached_fn)
10388 cu->cached_fn = cu->first_fn;
10390 fn = cu->cached_fn;
10392 if (fn->lowpc <= address && fn->highpc > address)
10398 while (fn && fn != cu->cached_fn)
10399 if (fn->lowpc <= address && fn->highpc > address)
10409 if (address != fn->lowpc)
10410 complaint (&symfile_complaints,
10411 _("misplaced first line number at 0x%lx for '%s'"),
10412 (unsigned long) address, fn->name);
10417 /* Subroutine of dwarf_decode_lines to simplify it.
10418 Return the file name of the psymtab for included file FILE_INDEX
10419 in line header LH of PST.
10420 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10421 If space for the result is malloc'd, it will be freed by a cleanup.
10422 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10425 psymtab_include_file_name (const struct line_header *lh, int file_index,
10426 const struct partial_symtab *pst,
10427 const char *comp_dir)
10429 const struct file_entry fe = lh->file_names [file_index];
10430 char *include_name = fe.name;
10431 char *include_name_to_compare = include_name;
10432 char *dir_name = NULL;
10433 const char *pst_filename;
10434 char *copied_name = NULL;
10438 dir_name = lh->include_dirs[fe.dir_index - 1];
10440 if (!IS_ABSOLUTE_PATH (include_name)
10441 && (dir_name != NULL || comp_dir != NULL))
10443 /* Avoid creating a duplicate psymtab for PST.
10444 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10445 Before we do the comparison, however, we need to account
10446 for DIR_NAME and COMP_DIR.
10447 First prepend dir_name (if non-NULL). If we still don't
10448 have an absolute path prepend comp_dir (if non-NULL).
10449 However, the directory we record in the include-file's
10450 psymtab does not contain COMP_DIR (to match the
10451 corresponding symtab(s)).
10456 bash$ gcc -g ./hello.c
10457 include_name = "hello.c"
10459 DW_AT_comp_dir = comp_dir = "/tmp"
10460 DW_AT_name = "./hello.c" */
10462 if (dir_name != NULL)
10464 include_name = concat (dir_name, SLASH_STRING,
10465 include_name, (char *)NULL);
10466 include_name_to_compare = include_name;
10467 make_cleanup (xfree, include_name);
10469 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
10471 include_name_to_compare = concat (comp_dir, SLASH_STRING,
10472 include_name, (char *)NULL);
10476 pst_filename = pst->filename;
10477 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
10479 copied_name = concat (pst->dirname, SLASH_STRING,
10480 pst_filename, (char *)NULL);
10481 pst_filename = copied_name;
10484 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
10486 if (include_name_to_compare != include_name)
10487 xfree (include_name_to_compare);
10488 if (copied_name != NULL)
10489 xfree (copied_name);
10493 return include_name;
10496 /* Ignore this record_line request. */
10499 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
10504 /* Decode the Line Number Program (LNP) for the given line_header
10505 structure and CU. The actual information extracted and the type
10506 of structures created from the LNP depends on the value of PST.
10508 1. If PST is NULL, then this procedure uses the data from the program
10509 to create all necessary symbol tables, and their linetables.
10511 2. If PST is not NULL, this procedure reads the program to determine
10512 the list of files included by the unit represented by PST, and
10513 builds all the associated partial symbol tables.
10515 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10516 It is used for relative paths in the line table.
10517 NOTE: When processing partial symtabs (pst != NULL),
10518 comp_dir == pst->dirname.
10520 NOTE: It is important that psymtabs have the same file name (via strcmp)
10521 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10522 symtab we don't use it in the name of the psymtabs we create.
10523 E.g. expand_line_sal requires this when finding psymtabs to expand.
10524 A good testcase for this is mb-inline.exp. */
10527 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
10528 struct dwarf2_cu *cu, struct partial_symtab *pst)
10530 gdb_byte *line_ptr, *extended_end;
10531 gdb_byte *line_end;
10532 unsigned int bytes_read, extended_len;
10533 unsigned char op_code, extended_op, adj_opcode;
10534 CORE_ADDR baseaddr;
10535 struct objfile *objfile = cu->objfile;
10536 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10537 const int decode_for_pst_p = (pst != NULL);
10538 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10539 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
10542 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10544 line_ptr = lh->statement_program_start;
10545 line_end = lh->statement_program_end;
10547 /* Read the statement sequences until there's nothing left. */
10548 while (line_ptr < line_end)
10550 /* state machine registers */
10551 CORE_ADDR address = 0;
10552 unsigned int file = 1;
10553 unsigned int line = 1;
10554 unsigned int column = 0;
10555 int is_stmt = lh->default_is_stmt;
10556 int basic_block = 0;
10557 int end_sequence = 0;
10559 unsigned char op_index = 0;
10561 if (!decode_for_pst_p && lh->num_file_names >= file)
10563 /* Start a subfile for the current file of the state machine. */
10564 /* lh->include_dirs and lh->file_names are 0-based, but the
10565 directory and file name numbers in the statement program
10567 struct file_entry *fe = &lh->file_names[file - 1];
10571 dir = lh->include_dirs[fe->dir_index - 1];
10573 dwarf2_start_subfile (fe->name, dir, comp_dir);
10576 /* Decode the table. */
10577 while (!end_sequence)
10579 op_code = read_1_byte (abfd, line_ptr);
10581 if (line_ptr > line_end)
10583 dwarf2_debug_line_missing_end_sequence_complaint ();
10587 if (op_code >= lh->opcode_base)
10589 /* Special operand. */
10590 adj_opcode = op_code - lh->opcode_base;
10591 address += (((op_index + (adj_opcode / lh->line_range))
10592 / lh->maximum_ops_per_instruction)
10593 * lh->minimum_instruction_length);
10594 op_index = ((op_index + (adj_opcode / lh->line_range))
10595 % lh->maximum_ops_per_instruction);
10596 line += lh->line_base + (adj_opcode % lh->line_range);
10597 if (lh->num_file_names < file || file == 0)
10598 dwarf2_debug_line_missing_file_complaint ();
10599 /* For now we ignore lines not starting on an
10600 instruction boundary. */
10601 else if (op_index == 0)
10603 lh->file_names[file - 1].included_p = 1;
10604 if (!decode_for_pst_p && is_stmt)
10606 if (last_subfile != current_subfile)
10608 addr = gdbarch_addr_bits_remove (gdbarch, address);
10610 (*p_record_line) (last_subfile, 0, addr);
10611 last_subfile = current_subfile;
10613 /* Append row to matrix using current values. */
10614 addr = check_cu_functions (address, cu);
10615 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10616 (*p_record_line) (current_subfile, line, addr);
10621 else switch (op_code)
10623 case DW_LNS_extended_op:
10624 extended_len = read_unsigned_leb128 (abfd, line_ptr,
10626 line_ptr += bytes_read;
10627 extended_end = line_ptr + extended_len;
10628 extended_op = read_1_byte (abfd, line_ptr);
10630 switch (extended_op)
10632 case DW_LNE_end_sequence:
10633 p_record_line = record_line;
10636 case DW_LNE_set_address:
10637 address = read_address (abfd, line_ptr, cu, &bytes_read);
10639 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
10641 /* This line table is for a function which has been
10642 GCd by the linker. Ignore it. PR gdb/12528 */
10645 = line_ptr - dwarf2_per_objfile->line.buffer;
10647 complaint (&symfile_complaints,
10648 _(".debug_line address at offset 0x%lx is 0 "
10650 line_offset, cu->objfile->name);
10651 p_record_line = noop_record_line;
10655 line_ptr += bytes_read;
10656 address += baseaddr;
10658 case DW_LNE_define_file:
10661 unsigned int dir_index, mod_time, length;
10663 cur_file = read_direct_string (abfd, line_ptr,
10665 line_ptr += bytes_read;
10667 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10668 line_ptr += bytes_read;
10670 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10671 line_ptr += bytes_read;
10673 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10674 line_ptr += bytes_read;
10675 add_file_name (lh, cur_file, dir_index, mod_time, length);
10678 case DW_LNE_set_discriminator:
10679 /* The discriminator is not interesting to the debugger;
10681 line_ptr = extended_end;
10684 complaint (&symfile_complaints,
10685 _("mangled .debug_line section"));
10688 /* Make sure that we parsed the extended op correctly. If e.g.
10689 we expected a different address size than the producer used,
10690 we may have read the wrong number of bytes. */
10691 if (line_ptr != extended_end)
10693 complaint (&symfile_complaints,
10694 _("mangled .debug_line section"));
10699 if (lh->num_file_names < file || file == 0)
10700 dwarf2_debug_line_missing_file_complaint ();
10703 lh->file_names[file - 1].included_p = 1;
10704 if (!decode_for_pst_p && is_stmt)
10706 if (last_subfile != current_subfile)
10708 addr = gdbarch_addr_bits_remove (gdbarch, address);
10710 (*p_record_line) (last_subfile, 0, addr);
10711 last_subfile = current_subfile;
10713 addr = check_cu_functions (address, cu);
10714 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10715 (*p_record_line) (current_subfile, line, addr);
10720 case DW_LNS_advance_pc:
10723 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10725 address += (((op_index + adjust)
10726 / lh->maximum_ops_per_instruction)
10727 * lh->minimum_instruction_length);
10728 op_index = ((op_index + adjust)
10729 % lh->maximum_ops_per_instruction);
10730 line_ptr += bytes_read;
10733 case DW_LNS_advance_line:
10734 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
10735 line_ptr += bytes_read;
10737 case DW_LNS_set_file:
10739 /* The arrays lh->include_dirs and lh->file_names are
10740 0-based, but the directory and file name numbers in
10741 the statement program are 1-based. */
10742 struct file_entry *fe;
10745 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10746 line_ptr += bytes_read;
10747 if (lh->num_file_names < file || file == 0)
10748 dwarf2_debug_line_missing_file_complaint ();
10751 fe = &lh->file_names[file - 1];
10753 dir = lh->include_dirs[fe->dir_index - 1];
10754 if (!decode_for_pst_p)
10756 last_subfile = current_subfile;
10757 dwarf2_start_subfile (fe->name, dir, comp_dir);
10762 case DW_LNS_set_column:
10763 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10764 line_ptr += bytes_read;
10766 case DW_LNS_negate_stmt:
10767 is_stmt = (!is_stmt);
10769 case DW_LNS_set_basic_block:
10772 /* Add to the address register of the state machine the
10773 address increment value corresponding to special opcode
10774 255. I.e., this value is scaled by the minimum
10775 instruction length since special opcode 255 would have
10776 scaled the increment. */
10777 case DW_LNS_const_add_pc:
10779 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
10781 address += (((op_index + adjust)
10782 / lh->maximum_ops_per_instruction)
10783 * lh->minimum_instruction_length);
10784 op_index = ((op_index + adjust)
10785 % lh->maximum_ops_per_instruction);
10788 case DW_LNS_fixed_advance_pc:
10789 address += read_2_bytes (abfd, line_ptr);
10795 /* Unknown standard opcode, ignore it. */
10798 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
10800 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10801 line_ptr += bytes_read;
10806 if (lh->num_file_names < file || file == 0)
10807 dwarf2_debug_line_missing_file_complaint ();
10810 lh->file_names[file - 1].included_p = 1;
10811 if (!decode_for_pst_p)
10813 addr = gdbarch_addr_bits_remove (gdbarch, address);
10814 (*p_record_line) (current_subfile, 0, addr);
10819 if (decode_for_pst_p)
10823 /* Now that we're done scanning the Line Header Program, we can
10824 create the psymtab of each included file. */
10825 for (file_index = 0; file_index < lh->num_file_names; file_index++)
10826 if (lh->file_names[file_index].included_p == 1)
10828 char *include_name =
10829 psymtab_include_file_name (lh, file_index, pst, comp_dir);
10830 if (include_name != NULL)
10831 dwarf2_create_include_psymtab (include_name, pst, objfile);
10836 /* Make sure a symtab is created for every file, even files
10837 which contain only variables (i.e. no code with associated
10841 struct file_entry *fe;
10843 for (i = 0; i < lh->num_file_names; i++)
10847 fe = &lh->file_names[i];
10849 dir = lh->include_dirs[fe->dir_index - 1];
10850 dwarf2_start_subfile (fe->name, dir, comp_dir);
10852 /* Skip the main file; we don't need it, and it must be
10853 allocated last, so that it will show up before the
10854 non-primary symtabs in the objfile's symtab list. */
10855 if (current_subfile == first_subfile)
10858 if (current_subfile->symtab == NULL)
10859 current_subfile->symtab = allocate_symtab (current_subfile->name,
10861 fe->symtab = current_subfile->symtab;
10866 /* Start a subfile for DWARF. FILENAME is the name of the file and
10867 DIRNAME the name of the source directory which contains FILENAME
10868 or NULL if not known. COMP_DIR is the compilation directory for the
10869 linetable's compilation unit or NULL if not known.
10870 This routine tries to keep line numbers from identical absolute and
10871 relative file names in a common subfile.
10873 Using the `list' example from the GDB testsuite, which resides in
10874 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10875 of /srcdir/list0.c yields the following debugging information for list0.c:
10877 DW_AT_name: /srcdir/list0.c
10878 DW_AT_comp_dir: /compdir
10879 files.files[0].name: list0.h
10880 files.files[0].dir: /srcdir
10881 files.files[1].name: list0.c
10882 files.files[1].dir: /srcdir
10884 The line number information for list0.c has to end up in a single
10885 subfile, so that `break /srcdir/list0.c:1' works as expected.
10886 start_subfile will ensure that this happens provided that we pass the
10887 concatenation of files.files[1].dir and files.files[1].name as the
10891 dwarf2_start_subfile (char *filename, const char *dirname,
10892 const char *comp_dir)
10896 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10897 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10898 second argument to start_subfile. To be consistent, we do the
10899 same here. In order not to lose the line information directory,
10900 we concatenate it to the filename when it makes sense.
10901 Note that the Dwarf3 standard says (speaking of filenames in line
10902 information): ``The directory index is ignored for file names
10903 that represent full path names''. Thus ignoring dirname in the
10904 `else' branch below isn't an issue. */
10906 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
10907 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
10909 fullname = filename;
10911 start_subfile (fullname, comp_dir);
10913 if (fullname != filename)
10918 var_decode_location (struct attribute *attr, struct symbol *sym,
10919 struct dwarf2_cu *cu)
10921 struct objfile *objfile = cu->objfile;
10922 struct comp_unit_head *cu_header = &cu->header;
10924 /* NOTE drow/2003-01-30: There used to be a comment and some special
10925 code here to turn a symbol with DW_AT_external and a
10926 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10927 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10928 with some versions of binutils) where shared libraries could have
10929 relocations against symbols in their debug information - the
10930 minimal symbol would have the right address, but the debug info
10931 would not. It's no longer necessary, because we will explicitly
10932 apply relocations when we read in the debug information now. */
10934 /* A DW_AT_location attribute with no contents indicates that a
10935 variable has been optimized away. */
10936 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
10938 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
10942 /* Handle one degenerate form of location expression specially, to
10943 preserve GDB's previous behavior when section offsets are
10944 specified. If this is just a DW_OP_addr then mark this symbol
10947 if (attr_form_is_block (attr)
10948 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
10949 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
10951 unsigned int dummy;
10953 SYMBOL_VALUE_ADDRESS (sym) =
10954 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
10955 SYMBOL_CLASS (sym) = LOC_STATIC;
10956 fixup_symbol_section (sym, objfile);
10957 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
10958 SYMBOL_SECTION (sym));
10962 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10963 expression evaluator, and use LOC_COMPUTED only when necessary
10964 (i.e. when the value of a register or memory location is
10965 referenced, or a thread-local block, etc.). Then again, it might
10966 not be worthwhile. I'm assuming that it isn't unless performance
10967 or memory numbers show me otherwise. */
10969 dwarf2_symbol_mark_computed (attr, sym, cu);
10970 SYMBOL_CLASS (sym) = LOC_COMPUTED;
10973 /* Given a pointer to a DWARF information entry, figure out if we need
10974 to make a symbol table entry for it, and if so, create a new entry
10975 and return a pointer to it.
10976 If TYPE is NULL, determine symbol type from the die, otherwise
10977 used the passed type.
10978 If SPACE is not NULL, use it to hold the new symbol. If it is
10979 NULL, allocate a new symbol on the objfile's obstack. */
10981 static struct symbol *
10982 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
10983 struct symbol *space)
10985 struct objfile *objfile = cu->objfile;
10986 struct symbol *sym = NULL;
10988 struct attribute *attr = NULL;
10989 struct attribute *attr2 = NULL;
10990 CORE_ADDR baseaddr;
10991 struct pending **list_to_add = NULL;
10993 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
10995 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10997 name = dwarf2_name (die, cu);
11000 const char *linkagename;
11001 int suppress_add = 0;
11006 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11007 OBJSTAT (objfile, n_syms++);
11009 /* Cache this symbol's name and the name's demangled form (if any). */
11010 SYMBOL_SET_LANGUAGE (sym, cu->language);
11011 linkagename = dwarf2_physname (name, die, cu);
11012 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11014 /* Fortran does not have mangling standard and the mangling does differ
11015 between gfortran, iFort etc. */
11016 if (cu->language == language_fortran
11017 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11018 symbol_set_demangled_name (&(sym->ginfo),
11019 (char *) dwarf2_full_name (name, die, cu),
11022 /* Default assumptions.
11023 Use the passed type or decode it from the die. */
11024 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11025 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11027 SYMBOL_TYPE (sym) = type;
11029 SYMBOL_TYPE (sym) = die_type (die, cu);
11030 attr = dwarf2_attr (die,
11031 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11035 SYMBOL_LINE (sym) = DW_UNSND (attr);
11038 attr = dwarf2_attr (die,
11039 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11043 int file_index = DW_UNSND (attr);
11045 if (cu->line_header == NULL
11046 || file_index > cu->line_header->num_file_names)
11047 complaint (&symfile_complaints,
11048 _("file index out of range"));
11049 else if (file_index > 0)
11051 struct file_entry *fe;
11053 fe = &cu->line_header->file_names[file_index - 1];
11054 SYMBOL_SYMTAB (sym) = fe->symtab;
11061 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11064 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11066 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11067 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11068 SYMBOL_CLASS (sym) = LOC_LABEL;
11069 add_symbol_to_list (sym, cu->list_in_scope);
11071 case DW_TAG_subprogram:
11072 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11074 SYMBOL_CLASS (sym) = LOC_BLOCK;
11075 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11076 if ((attr2 && (DW_UNSND (attr2) != 0))
11077 || cu->language == language_ada)
11079 /* Subprograms marked external are stored as a global symbol.
11080 Ada subprograms, whether marked external or not, are always
11081 stored as a global symbol, because we want to be able to
11082 access them globally. For instance, we want to be able
11083 to break on a nested subprogram without having to
11084 specify the context. */
11085 list_to_add = &global_symbols;
11089 list_to_add = cu->list_in_scope;
11092 case DW_TAG_inlined_subroutine:
11093 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11095 SYMBOL_CLASS (sym) = LOC_BLOCK;
11096 SYMBOL_INLINED (sym) = 1;
11097 /* Do not add the symbol to any lists. It will be found via
11098 BLOCK_FUNCTION from the blockvector. */
11100 case DW_TAG_template_value_param:
11102 /* Fall through. */
11103 case DW_TAG_constant:
11104 case DW_TAG_variable:
11105 case DW_TAG_member:
11106 /* Compilation with minimal debug info may result in
11107 variables with missing type entries. Change the
11108 misleading `void' type to something sensible. */
11109 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11111 = objfile_type (objfile)->nodebug_data_symbol;
11113 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11114 /* In the case of DW_TAG_member, we should only be called for
11115 static const members. */
11116 if (die->tag == DW_TAG_member)
11118 /* dwarf2_add_field uses die_is_declaration,
11119 so we do the same. */
11120 gdb_assert (die_is_declaration (die, cu));
11125 dwarf2_const_value (attr, sym, cu);
11126 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11129 if (attr2 && (DW_UNSND (attr2) != 0))
11130 list_to_add = &global_symbols;
11132 list_to_add = cu->list_in_scope;
11136 attr = dwarf2_attr (die, DW_AT_location, cu);
11139 var_decode_location (attr, sym, cu);
11140 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11141 if (SYMBOL_CLASS (sym) == LOC_STATIC
11142 && SYMBOL_VALUE_ADDRESS (sym) == 0
11143 && !dwarf2_per_objfile->has_section_at_zero)
11145 /* When a static variable is eliminated by the linker,
11146 the corresponding debug information is not stripped
11147 out, but the variable address is set to null;
11148 do not add such variables into symbol table. */
11150 else if (attr2 && (DW_UNSND (attr2) != 0))
11152 /* Workaround gfortran PR debug/40040 - it uses
11153 DW_AT_location for variables in -fPIC libraries which may
11154 get overriden by other libraries/executable and get
11155 a different address. Resolve it by the minimal symbol
11156 which may come from inferior's executable using copy
11157 relocation. Make this workaround only for gfortran as for
11158 other compilers GDB cannot guess the minimal symbol
11159 Fortran mangling kind. */
11160 if (cu->language == language_fortran && die->parent
11161 && die->parent->tag == DW_TAG_module
11163 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11164 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11166 /* A variable with DW_AT_external is never static,
11167 but it may be block-scoped. */
11168 list_to_add = (cu->list_in_scope == &file_symbols
11169 ? &global_symbols : cu->list_in_scope);
11172 list_to_add = cu->list_in_scope;
11176 /* We do not know the address of this symbol.
11177 If it is an external symbol and we have type information
11178 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11179 The address of the variable will then be determined from
11180 the minimal symbol table whenever the variable is
11182 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11183 if (attr2 && (DW_UNSND (attr2) != 0)
11184 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11186 /* A variable with DW_AT_external is never static, but it
11187 may be block-scoped. */
11188 list_to_add = (cu->list_in_scope == &file_symbols
11189 ? &global_symbols : cu->list_in_scope);
11191 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11193 else if (!die_is_declaration (die, cu))
11195 /* Use the default LOC_OPTIMIZED_OUT class. */
11196 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11198 list_to_add = cu->list_in_scope;
11202 case DW_TAG_formal_parameter:
11203 /* If we are inside a function, mark this as an argument. If
11204 not, we might be looking at an argument to an inlined function
11205 when we do not have enough information to show inlined frames;
11206 pretend it's a local variable in that case so that the user can
11208 if (context_stack_depth > 0
11209 && context_stack[context_stack_depth - 1].name != NULL)
11210 SYMBOL_IS_ARGUMENT (sym) = 1;
11211 attr = dwarf2_attr (die, DW_AT_location, cu);
11214 var_decode_location (attr, sym, cu);
11216 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11219 dwarf2_const_value (attr, sym, cu);
11221 attr = dwarf2_attr (die, DW_AT_variable_parameter, cu);
11222 if (attr && DW_UNSND (attr))
11224 struct type *ref_type;
11226 ref_type = lookup_reference_type (SYMBOL_TYPE (sym));
11227 SYMBOL_TYPE (sym) = ref_type;
11230 list_to_add = cu->list_in_scope;
11232 case DW_TAG_unspecified_parameters:
11233 /* From varargs functions; gdb doesn't seem to have any
11234 interest in this information, so just ignore it for now.
11237 case DW_TAG_template_type_param:
11239 /* Fall through. */
11240 case DW_TAG_class_type:
11241 case DW_TAG_interface_type:
11242 case DW_TAG_structure_type:
11243 case DW_TAG_union_type:
11244 case DW_TAG_set_type:
11245 case DW_TAG_enumeration_type:
11246 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11247 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11250 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11251 really ever be static objects: otherwise, if you try
11252 to, say, break of a class's method and you're in a file
11253 which doesn't mention that class, it won't work unless
11254 the check for all static symbols in lookup_symbol_aux
11255 saves you. See the OtherFileClass tests in
11256 gdb.c++/namespace.exp. */
11260 list_to_add = (cu->list_in_scope == &file_symbols
11261 && (cu->language == language_cplus
11262 || cu->language == language_java)
11263 ? &global_symbols : cu->list_in_scope);
11265 /* The semantics of C++ state that "struct foo {
11266 ... }" also defines a typedef for "foo". A Java
11267 class declaration also defines a typedef for the
11269 if (cu->language == language_cplus
11270 || cu->language == language_java
11271 || cu->language == language_ada)
11273 /* The symbol's name is already allocated along
11274 with this objfile, so we don't need to
11275 duplicate it for the type. */
11276 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11277 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11282 case DW_TAG_typedef:
11283 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11284 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11285 list_to_add = cu->list_in_scope;
11287 case DW_TAG_base_type:
11288 case DW_TAG_subrange_type:
11289 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11290 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11291 list_to_add = cu->list_in_scope;
11293 case DW_TAG_enumerator:
11294 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11297 dwarf2_const_value (attr, sym, cu);
11300 /* NOTE: carlton/2003-11-10: See comment above in the
11301 DW_TAG_class_type, etc. block. */
11303 list_to_add = (cu->list_in_scope == &file_symbols
11304 && (cu->language == language_cplus
11305 || cu->language == language_java)
11306 ? &global_symbols : cu->list_in_scope);
11309 case DW_TAG_namespace:
11310 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11311 list_to_add = &global_symbols;
11314 /* Not a tag we recognize. Hopefully we aren't processing
11315 trash data, but since we must specifically ignore things
11316 we don't recognize, there is nothing else we should do at
11318 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11319 dwarf_tag_name (die->tag));
11325 sym->hash_next = objfile->template_symbols;
11326 objfile->template_symbols = sym;
11327 list_to_add = NULL;
11330 if (list_to_add != NULL)
11331 add_symbol_to_list (sym, list_to_add);
11333 /* For the benefit of old versions of GCC, check for anonymous
11334 namespaces based on the demangled name. */
11335 if (!processing_has_namespace_info
11336 && cu->language == language_cplus)
11337 cp_scan_for_anonymous_namespaces (sym);
11342 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11344 static struct symbol *
11345 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11347 return new_symbol_full (die, type, cu, NULL);
11350 /* Given an attr with a DW_FORM_dataN value in host byte order,
11351 zero-extend it as appropriate for the symbol's type. The DWARF
11352 standard (v4) is not entirely clear about the meaning of using
11353 DW_FORM_dataN for a constant with a signed type, where the type is
11354 wider than the data. The conclusion of a discussion on the DWARF
11355 list was that this is unspecified. We choose to always zero-extend
11356 because that is the interpretation long in use by GCC. */
11359 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11360 const char *name, struct obstack *obstack,
11361 struct dwarf2_cu *cu, long *value, int bits)
11363 struct objfile *objfile = cu->objfile;
11364 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11365 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11366 LONGEST l = DW_UNSND (attr);
11368 if (bits < sizeof (*value) * 8)
11370 l &= ((LONGEST) 1 << bits) - 1;
11373 else if (bits == sizeof (*value) * 8)
11377 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11378 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11385 /* Read a constant value from an attribute. Either set *VALUE, or if
11386 the value does not fit in *VALUE, set *BYTES - either already
11387 allocated on the objfile obstack, or newly allocated on OBSTACK,
11388 or, set *BATON, if we translated the constant to a location
11392 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11393 const char *name, struct obstack *obstack,
11394 struct dwarf2_cu *cu,
11395 long *value, gdb_byte **bytes,
11396 struct dwarf2_locexpr_baton **baton)
11398 struct objfile *objfile = cu->objfile;
11399 struct comp_unit_head *cu_header = &cu->header;
11400 struct dwarf_block *blk;
11401 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11402 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11408 switch (attr->form)
11414 if (TYPE_LENGTH (type) != cu_header->addr_size)
11415 dwarf2_const_value_length_mismatch_complaint (name,
11416 cu_header->addr_size,
11417 TYPE_LENGTH (type));
11418 /* Symbols of this form are reasonably rare, so we just
11419 piggyback on the existing location code rather than writing
11420 a new implementation of symbol_computed_ops. */
11421 *baton = obstack_alloc (&objfile->objfile_obstack,
11422 sizeof (struct dwarf2_locexpr_baton));
11423 (*baton)->per_cu = cu->per_cu;
11424 gdb_assert ((*baton)->per_cu);
11426 (*baton)->size = 2 + cu_header->addr_size;
11427 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11428 (*baton)->data = data;
11430 data[0] = DW_OP_addr;
11431 store_unsigned_integer (&data[1], cu_header->addr_size,
11432 byte_order, DW_ADDR (attr));
11433 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11436 case DW_FORM_string:
11438 /* DW_STRING is already allocated on the objfile obstack, point
11440 *bytes = (gdb_byte *) DW_STRING (attr);
11442 case DW_FORM_block1:
11443 case DW_FORM_block2:
11444 case DW_FORM_block4:
11445 case DW_FORM_block:
11446 case DW_FORM_exprloc:
11447 blk = DW_BLOCK (attr);
11448 if (TYPE_LENGTH (type) != blk->size)
11449 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11450 TYPE_LENGTH (type));
11451 *bytes = blk->data;
11454 /* The DW_AT_const_value attributes are supposed to carry the
11455 symbol's value "represented as it would be on the target
11456 architecture." By the time we get here, it's already been
11457 converted to host endianness, so we just need to sign- or
11458 zero-extend it as appropriate. */
11459 case DW_FORM_data1:
11460 *bytes = dwarf2_const_value_data (attr, type, name,
11461 obstack, cu, value, 8);
11463 case DW_FORM_data2:
11464 *bytes = dwarf2_const_value_data (attr, type, name,
11465 obstack, cu, value, 16);
11467 case DW_FORM_data4:
11468 *bytes = dwarf2_const_value_data (attr, type, name,
11469 obstack, cu, value, 32);
11471 case DW_FORM_data8:
11472 *bytes = dwarf2_const_value_data (attr, type, name,
11473 obstack, cu, value, 64);
11476 case DW_FORM_sdata:
11477 *value = DW_SND (attr);
11480 case DW_FORM_udata:
11481 *value = DW_UNSND (attr);
11485 complaint (&symfile_complaints,
11486 _("unsupported const value attribute form: '%s'"),
11487 dwarf_form_name (attr->form));
11494 /* Copy constant value from an attribute to a symbol. */
11497 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
11498 struct dwarf2_cu *cu)
11500 struct objfile *objfile = cu->objfile;
11501 struct comp_unit_head *cu_header = &cu->header;
11504 struct dwarf2_locexpr_baton *baton;
11506 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
11507 SYMBOL_PRINT_NAME (sym),
11508 &objfile->objfile_obstack, cu,
11509 &value, &bytes, &baton);
11513 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11514 SYMBOL_LOCATION_BATON (sym) = baton;
11515 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11517 else if (bytes != NULL)
11519 SYMBOL_VALUE_BYTES (sym) = bytes;
11520 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
11524 SYMBOL_VALUE (sym) = value;
11525 SYMBOL_CLASS (sym) = LOC_CONST;
11529 /* Return the type of the die in question using its DW_AT_type attribute. */
11531 static struct type *
11532 die_type (struct die_info *die, struct dwarf2_cu *cu)
11534 struct attribute *type_attr;
11536 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11539 /* A missing DW_AT_type represents a void type. */
11540 return objfile_type (cu->objfile)->builtin_void;
11543 return lookup_die_type (die, type_attr, cu);
11546 /* True iff CU's producer generates GNAT Ada auxiliary information
11547 that allows to find parallel types through that information instead
11548 of having to do expensive parallel lookups by type name. */
11551 need_gnat_info (struct dwarf2_cu *cu)
11553 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11554 of GNAT produces this auxiliary information, without any indication
11555 that it is produced. Part of enhancing the FSF version of GNAT
11556 to produce that information will be to put in place an indicator
11557 that we can use in order to determine whether the descriptive type
11558 info is available or not. One suggestion that has been made is
11559 to use a new attribute, attached to the CU die. For now, assume
11560 that the descriptive type info is not available. */
11564 /* Return the auxiliary type of the die in question using its
11565 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11566 attribute is not present. */
11568 static struct type *
11569 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11571 struct attribute *type_attr;
11573 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11577 return lookup_die_type (die, type_attr, cu);
11580 /* If DIE has a descriptive_type attribute, then set the TYPE's
11581 descriptive type accordingly. */
11584 set_descriptive_type (struct type *type, struct die_info *die,
11585 struct dwarf2_cu *cu)
11587 struct type *descriptive_type = die_descriptive_type (die, cu);
11589 if (descriptive_type)
11591 ALLOCATE_GNAT_AUX_TYPE (type);
11592 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11596 /* Return the containing type of the die in question using its
11597 DW_AT_containing_type attribute. */
11599 static struct type *
11600 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11602 struct attribute *type_attr;
11604 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11606 error (_("Dwarf Error: Problem turning containing type into gdb type "
11607 "[in module %s]"), cu->objfile->name);
11609 return lookup_die_type (die, type_attr, cu);
11612 /* Look up the type of DIE in CU using its type attribute ATTR.
11613 If there is no type substitute an error marker. */
11615 static struct type *
11616 lookup_die_type (struct die_info *die, struct attribute *attr,
11617 struct dwarf2_cu *cu)
11619 struct type *this_type;
11621 /* First see if we have it cached. */
11623 if (is_ref_attr (attr))
11625 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11627 this_type = get_die_type_at_offset (offset, cu->per_cu);
11629 else if (attr->form == DW_FORM_ref_sig8)
11631 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11632 struct dwarf2_cu *sig_cu;
11633 unsigned int offset;
11635 /* sig_type will be NULL if the signatured type is missing from
11637 if (sig_type == NULL)
11638 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11639 "at 0x%x [in module %s]"),
11640 die->offset, cu->objfile->name);
11642 gdb_assert (sig_type->per_cu.from_debug_types);
11643 offset = sig_type->offset + sig_type->type_offset;
11644 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11648 dump_die_for_error (die);
11649 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11650 dwarf_attr_name (attr->name), cu->objfile->name);
11653 /* If not cached we need to read it in. */
11655 if (this_type == NULL)
11657 struct die_info *type_die;
11658 struct dwarf2_cu *type_cu = cu;
11660 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11661 /* If the type is cached, we should have found it above. */
11662 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11663 this_type = read_type_die_1 (type_die, type_cu);
11666 /* If we still don't have a type use an error marker. */
11668 if (this_type == NULL)
11670 char *message, *saved;
11672 /* read_type_die already issued a complaint. */
11673 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11677 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
11678 message, strlen (message));
11681 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
11687 /* Return the type in DIE, CU.
11688 Returns NULL for invalid types.
11690 This first does a lookup in the appropriate type_hash table,
11691 and only reads the die in if necessary.
11693 NOTE: This can be called when reading in partial or full symbols. */
11695 static struct type *
11696 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
11698 struct type *this_type;
11700 this_type = get_die_type (die, cu);
11704 return read_type_die_1 (die, cu);
11707 /* Read the type in DIE, CU.
11708 Returns NULL for invalid types. */
11710 static struct type *
11711 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11713 struct type *this_type = NULL;
11717 case DW_TAG_class_type:
11718 case DW_TAG_interface_type:
11719 case DW_TAG_structure_type:
11720 case DW_TAG_union_type:
11721 this_type = read_structure_type (die, cu);
11723 case DW_TAG_enumeration_type:
11724 this_type = read_enumeration_type (die, cu);
11726 case DW_TAG_subprogram:
11727 case DW_TAG_subroutine_type:
11728 case DW_TAG_inlined_subroutine:
11729 this_type = read_subroutine_type (die, cu);
11731 case DW_TAG_array_type:
11732 this_type = read_array_type (die, cu);
11734 case DW_TAG_set_type:
11735 this_type = read_set_type (die, cu);
11737 case DW_TAG_pointer_type:
11738 this_type = read_tag_pointer_type (die, cu);
11740 case DW_TAG_ptr_to_member_type:
11741 this_type = read_tag_ptr_to_member_type (die, cu);
11743 case DW_TAG_reference_type:
11744 this_type = read_tag_reference_type (die, cu);
11746 case DW_TAG_const_type:
11747 this_type = read_tag_const_type (die, cu);
11749 case DW_TAG_volatile_type:
11750 this_type = read_tag_volatile_type (die, cu);
11752 case DW_TAG_string_type:
11753 this_type = read_tag_string_type (die, cu);
11755 case DW_TAG_typedef:
11756 this_type = read_typedef (die, cu);
11758 case DW_TAG_subrange_type:
11759 this_type = read_subrange_type (die, cu);
11761 case DW_TAG_base_type:
11762 this_type = read_base_type (die, cu);
11764 case DW_TAG_unspecified_type:
11765 this_type = read_unspecified_type (die, cu);
11767 case DW_TAG_namespace:
11768 this_type = read_namespace_type (die, cu);
11770 case DW_TAG_module:
11771 this_type = read_module_type (die, cu);
11774 complaint (&symfile_complaints,
11775 _("unexpected tag in read_type_die: '%s'"),
11776 dwarf_tag_name (die->tag));
11783 /* See if we can figure out if the class lives in a namespace. We do
11784 this by looking for a member function; its demangled name will
11785 contain namespace info, if there is any.
11786 Return the computed name or NULL.
11787 Space for the result is allocated on the objfile's obstack.
11788 This is the full-die version of guess_partial_die_structure_name.
11789 In this case we know DIE has no useful parent. */
11792 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
11794 struct die_info *spec_die;
11795 struct dwarf2_cu *spec_cu;
11796 struct die_info *child;
11799 spec_die = die_specification (die, &spec_cu);
11800 if (spec_die != NULL)
11806 for (child = die->child;
11808 child = child->sibling)
11810 if (child->tag == DW_TAG_subprogram)
11812 struct attribute *attr;
11814 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
11816 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
11820 = language_class_name_from_physname (cu->language_defn,
11824 if (actual_name != NULL)
11826 char *die_name = dwarf2_name (die, cu);
11828 if (die_name != NULL
11829 && strcmp (die_name, actual_name) != 0)
11831 /* Strip off the class name from the full name.
11832 We want the prefix. */
11833 int die_name_len = strlen (die_name);
11834 int actual_name_len = strlen (actual_name);
11836 /* Test for '::' as a sanity check. */
11837 if (actual_name_len > die_name_len + 2
11838 && actual_name[actual_name_len
11839 - die_name_len - 1] == ':')
11841 obsavestring (actual_name,
11842 actual_name_len - die_name_len - 2,
11843 &cu->objfile->objfile_obstack);
11846 xfree (actual_name);
11855 /* Return the name of the namespace/class that DIE is defined within,
11856 or "" if we can't tell. The caller should not xfree the result.
11858 For example, if we're within the method foo() in the following
11868 then determine_prefix on foo's die will return "N::C". */
11871 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
11873 struct die_info *parent, *spec_die;
11874 struct dwarf2_cu *spec_cu;
11875 struct type *parent_type;
11877 if (cu->language != language_cplus && cu->language != language_java
11878 && cu->language != language_fortran)
11881 /* We have to be careful in the presence of DW_AT_specification.
11882 For example, with GCC 3.4, given the code
11886 // Definition of N::foo.
11890 then we'll have a tree of DIEs like this:
11892 1: DW_TAG_compile_unit
11893 2: DW_TAG_namespace // N
11894 3: DW_TAG_subprogram // declaration of N::foo
11895 4: DW_TAG_subprogram // definition of N::foo
11896 DW_AT_specification // refers to die #3
11898 Thus, when processing die #4, we have to pretend that we're in
11899 the context of its DW_AT_specification, namely the contex of die
11902 spec_die = die_specification (die, &spec_cu);
11903 if (spec_die == NULL)
11904 parent = die->parent;
11907 parent = spec_die->parent;
11911 if (parent == NULL)
11913 else if (parent->building_fullname)
11916 const char *parent_name;
11918 /* It has been seen on RealView 2.2 built binaries,
11919 DW_TAG_template_type_param types actually _defined_ as
11920 children of the parent class:
11923 template class <class Enum> Class{};
11924 Class<enum E> class_e;
11926 1: DW_TAG_class_type (Class)
11927 2: DW_TAG_enumeration_type (E)
11928 3: DW_TAG_enumerator (enum1:0)
11929 3: DW_TAG_enumerator (enum2:1)
11931 2: DW_TAG_template_type_param
11932 DW_AT_type DW_FORM_ref_udata (E)
11934 Besides being broken debug info, it can put GDB into an
11935 infinite loop. Consider:
11937 When we're building the full name for Class<E>, we'll start
11938 at Class, and go look over its template type parameters,
11939 finding E. We'll then try to build the full name of E, and
11940 reach here. We're now trying to build the full name of E,
11941 and look over the parent DIE for containing scope. In the
11942 broken case, if we followed the parent DIE of E, we'd again
11943 find Class, and once again go look at its template type
11944 arguments, etc., etc. Simply don't consider such parent die
11945 as source-level parent of this die (it can't be, the language
11946 doesn't allow it), and break the loop here. */
11947 name = dwarf2_name (die, cu);
11948 parent_name = dwarf2_name (parent, cu);
11949 complaint (&symfile_complaints,
11950 _("template param type '%s' defined within parent '%s'"),
11951 name ? name : "<unknown>",
11952 parent_name ? parent_name : "<unknown>");
11956 switch (parent->tag)
11958 case DW_TAG_namespace:
11959 parent_type = read_type_die (parent, cu);
11960 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11961 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11962 Work around this problem here. */
11963 if (cu->language == language_cplus
11964 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
11966 /* We give a name to even anonymous namespaces. */
11967 return TYPE_TAG_NAME (parent_type);
11968 case DW_TAG_class_type:
11969 case DW_TAG_interface_type:
11970 case DW_TAG_structure_type:
11971 case DW_TAG_union_type:
11972 case DW_TAG_module:
11973 parent_type = read_type_die (parent, cu);
11974 if (TYPE_TAG_NAME (parent_type) != NULL)
11975 return TYPE_TAG_NAME (parent_type);
11977 /* An anonymous structure is only allowed non-static data
11978 members; no typedefs, no member functions, et cetera.
11979 So it does not need a prefix. */
11981 case DW_TAG_compile_unit:
11982 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11983 if (cu->language == language_cplus
11984 && dwarf2_per_objfile->types.asection != NULL
11985 && die->child != NULL
11986 && (die->tag == DW_TAG_class_type
11987 || die->tag == DW_TAG_structure_type
11988 || die->tag == DW_TAG_union_type))
11990 char *name = guess_full_die_structure_name (die, cu);
11996 return determine_prefix (parent, cu);
12000 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12001 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12002 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12003 an obconcat, otherwise allocate storage for the result. The CU argument is
12004 used to determine the language and hence, the appropriate separator. */
12006 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12009 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12010 int physname, struct dwarf2_cu *cu)
12012 const char *lead = "";
12015 if (suffix == NULL || suffix[0] == '\0'
12016 || prefix == NULL || prefix[0] == '\0')
12018 else if (cu->language == language_java)
12020 else if (cu->language == language_fortran && physname)
12022 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12023 DW_AT_MIPS_linkage_name is preferred and used instead. */
12031 if (prefix == NULL)
12033 if (suffix == NULL)
12039 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12041 strcpy (retval, lead);
12042 strcat (retval, prefix);
12043 strcat (retval, sep);
12044 strcat (retval, suffix);
12049 /* We have an obstack. */
12050 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12054 /* Return sibling of die, NULL if no sibling. */
12056 static struct die_info *
12057 sibling_die (struct die_info *die)
12059 return die->sibling;
12062 /* Get name of a die, return NULL if not found. */
12065 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12066 struct obstack *obstack)
12068 if (name && cu->language == language_cplus)
12070 char *canon_name = cp_canonicalize_string (name);
12072 if (canon_name != NULL)
12074 if (strcmp (canon_name, name) != 0)
12075 name = obsavestring (canon_name, strlen (canon_name),
12077 xfree (canon_name);
12084 /* Get name of a die, return NULL if not found. */
12087 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12089 struct attribute *attr;
12091 attr = dwarf2_attr (die, DW_AT_name, cu);
12092 if ((!attr || !DW_STRING (attr))
12093 && die->tag != DW_TAG_class_type
12094 && die->tag != DW_TAG_interface_type
12095 && die->tag != DW_TAG_structure_type
12096 && die->tag != DW_TAG_union_type)
12101 case DW_TAG_compile_unit:
12102 /* Compilation units have a DW_AT_name that is a filename, not
12103 a source language identifier. */
12104 case DW_TAG_enumeration_type:
12105 case DW_TAG_enumerator:
12106 /* These tags always have simple identifiers already; no need
12107 to canonicalize them. */
12108 return DW_STRING (attr);
12110 case DW_TAG_subprogram:
12111 /* Java constructors will all be named "<init>", so return
12112 the class name when we see this special case. */
12113 if (cu->language == language_java
12114 && DW_STRING (attr) != NULL
12115 && strcmp (DW_STRING (attr), "<init>") == 0)
12117 struct dwarf2_cu *spec_cu = cu;
12118 struct die_info *spec_die;
12120 /* GCJ will output '<init>' for Java constructor names.
12121 For this special case, return the name of the parent class. */
12123 /* GCJ may output suprogram DIEs with AT_specification set.
12124 If so, use the name of the specified DIE. */
12125 spec_die = die_specification (die, &spec_cu);
12126 if (spec_die != NULL)
12127 return dwarf2_name (spec_die, spec_cu);
12132 if (die->tag == DW_TAG_class_type)
12133 return dwarf2_name (die, cu);
12135 while (die->tag != DW_TAG_compile_unit);
12139 case DW_TAG_class_type:
12140 case DW_TAG_interface_type:
12141 case DW_TAG_structure_type:
12142 case DW_TAG_union_type:
12143 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12144 structures or unions. These were of the form "._%d" in GCC 4.1,
12145 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12146 and GCC 4.4. We work around this problem by ignoring these. */
12147 if (attr && DW_STRING (attr)
12148 && (strncmp (DW_STRING (attr), "._", 2) == 0
12149 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12152 /* GCC might emit a nameless typedef that has a linkage name. See
12153 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12154 if (!attr || DW_STRING (attr) == NULL)
12156 char *demangled = NULL;
12158 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12160 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12162 if (attr == NULL || DW_STRING (attr) == NULL)
12165 /* Avoid demangling DW_STRING (attr) the second time on a second
12166 call for the same DIE. */
12167 if (!DW_STRING_IS_CANONICAL (attr))
12168 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12172 /* FIXME: we already did this for the partial symbol... */
12174 = obsavestring (demangled, strlen (demangled),
12175 &cu->objfile->objfile_obstack);
12176 DW_STRING_IS_CANONICAL (attr) = 1;
12186 if (!DW_STRING_IS_CANONICAL (attr))
12189 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12190 &cu->objfile->objfile_obstack);
12191 DW_STRING_IS_CANONICAL (attr) = 1;
12193 return DW_STRING (attr);
12196 /* Return the die that this die in an extension of, or NULL if there
12197 is none. *EXT_CU is the CU containing DIE on input, and the CU
12198 containing the return value on output. */
12200 static struct die_info *
12201 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12203 struct attribute *attr;
12205 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12209 return follow_die_ref (die, attr, ext_cu);
12212 /* Convert a DIE tag into its string name. */
12215 dwarf_tag_name (unsigned tag)
12219 case DW_TAG_padding:
12220 return "DW_TAG_padding";
12221 case DW_TAG_array_type:
12222 return "DW_TAG_array_type";
12223 case DW_TAG_class_type:
12224 return "DW_TAG_class_type";
12225 case DW_TAG_entry_point:
12226 return "DW_TAG_entry_point";
12227 case DW_TAG_enumeration_type:
12228 return "DW_TAG_enumeration_type";
12229 case DW_TAG_formal_parameter:
12230 return "DW_TAG_formal_parameter";
12231 case DW_TAG_imported_declaration:
12232 return "DW_TAG_imported_declaration";
12234 return "DW_TAG_label";
12235 case DW_TAG_lexical_block:
12236 return "DW_TAG_lexical_block";
12237 case DW_TAG_member:
12238 return "DW_TAG_member";
12239 case DW_TAG_pointer_type:
12240 return "DW_TAG_pointer_type";
12241 case DW_TAG_reference_type:
12242 return "DW_TAG_reference_type";
12243 case DW_TAG_compile_unit:
12244 return "DW_TAG_compile_unit";
12245 case DW_TAG_string_type:
12246 return "DW_TAG_string_type";
12247 case DW_TAG_structure_type:
12248 return "DW_TAG_structure_type";
12249 case DW_TAG_subroutine_type:
12250 return "DW_TAG_subroutine_type";
12251 case DW_TAG_typedef:
12252 return "DW_TAG_typedef";
12253 case DW_TAG_union_type:
12254 return "DW_TAG_union_type";
12255 case DW_TAG_unspecified_parameters:
12256 return "DW_TAG_unspecified_parameters";
12257 case DW_TAG_variant:
12258 return "DW_TAG_variant";
12259 case DW_TAG_common_block:
12260 return "DW_TAG_common_block";
12261 case DW_TAG_common_inclusion:
12262 return "DW_TAG_common_inclusion";
12263 case DW_TAG_inheritance:
12264 return "DW_TAG_inheritance";
12265 case DW_TAG_inlined_subroutine:
12266 return "DW_TAG_inlined_subroutine";
12267 case DW_TAG_module:
12268 return "DW_TAG_module";
12269 case DW_TAG_ptr_to_member_type:
12270 return "DW_TAG_ptr_to_member_type";
12271 case DW_TAG_set_type:
12272 return "DW_TAG_set_type";
12273 case DW_TAG_subrange_type:
12274 return "DW_TAG_subrange_type";
12275 case DW_TAG_with_stmt:
12276 return "DW_TAG_with_stmt";
12277 case DW_TAG_access_declaration:
12278 return "DW_TAG_access_declaration";
12279 case DW_TAG_base_type:
12280 return "DW_TAG_base_type";
12281 case DW_TAG_catch_block:
12282 return "DW_TAG_catch_block";
12283 case DW_TAG_const_type:
12284 return "DW_TAG_const_type";
12285 case DW_TAG_constant:
12286 return "DW_TAG_constant";
12287 case DW_TAG_enumerator:
12288 return "DW_TAG_enumerator";
12289 case DW_TAG_file_type:
12290 return "DW_TAG_file_type";
12291 case DW_TAG_friend:
12292 return "DW_TAG_friend";
12293 case DW_TAG_namelist:
12294 return "DW_TAG_namelist";
12295 case DW_TAG_namelist_item:
12296 return "DW_TAG_namelist_item";
12297 case DW_TAG_packed_type:
12298 return "DW_TAG_packed_type";
12299 case DW_TAG_subprogram:
12300 return "DW_TAG_subprogram";
12301 case DW_TAG_template_type_param:
12302 return "DW_TAG_template_type_param";
12303 case DW_TAG_template_value_param:
12304 return "DW_TAG_template_value_param";
12305 case DW_TAG_thrown_type:
12306 return "DW_TAG_thrown_type";
12307 case DW_TAG_try_block:
12308 return "DW_TAG_try_block";
12309 case DW_TAG_variant_part:
12310 return "DW_TAG_variant_part";
12311 case DW_TAG_variable:
12312 return "DW_TAG_variable";
12313 case DW_TAG_volatile_type:
12314 return "DW_TAG_volatile_type";
12315 case DW_TAG_dwarf_procedure:
12316 return "DW_TAG_dwarf_procedure";
12317 case DW_TAG_restrict_type:
12318 return "DW_TAG_restrict_type";
12319 case DW_TAG_interface_type:
12320 return "DW_TAG_interface_type";
12321 case DW_TAG_namespace:
12322 return "DW_TAG_namespace";
12323 case DW_TAG_imported_module:
12324 return "DW_TAG_imported_module";
12325 case DW_TAG_unspecified_type:
12326 return "DW_TAG_unspecified_type";
12327 case DW_TAG_partial_unit:
12328 return "DW_TAG_partial_unit";
12329 case DW_TAG_imported_unit:
12330 return "DW_TAG_imported_unit";
12331 case DW_TAG_condition:
12332 return "DW_TAG_condition";
12333 case DW_TAG_shared_type:
12334 return "DW_TAG_shared_type";
12335 case DW_TAG_type_unit:
12336 return "DW_TAG_type_unit";
12337 case DW_TAG_MIPS_loop:
12338 return "DW_TAG_MIPS_loop";
12339 case DW_TAG_HP_array_descriptor:
12340 return "DW_TAG_HP_array_descriptor";
12341 case DW_TAG_format_label:
12342 return "DW_TAG_format_label";
12343 case DW_TAG_function_template:
12344 return "DW_TAG_function_template";
12345 case DW_TAG_class_template:
12346 return "DW_TAG_class_template";
12347 case DW_TAG_GNU_BINCL:
12348 return "DW_TAG_GNU_BINCL";
12349 case DW_TAG_GNU_EINCL:
12350 return "DW_TAG_GNU_EINCL";
12351 case DW_TAG_upc_shared_type:
12352 return "DW_TAG_upc_shared_type";
12353 case DW_TAG_upc_strict_type:
12354 return "DW_TAG_upc_strict_type";
12355 case DW_TAG_upc_relaxed_type:
12356 return "DW_TAG_upc_relaxed_type";
12357 case DW_TAG_PGI_kanji_type:
12358 return "DW_TAG_PGI_kanji_type";
12359 case DW_TAG_PGI_interface_block:
12360 return "DW_TAG_PGI_interface_block";
12362 return "DW_TAG_<unknown>";
12366 /* Convert a DWARF attribute code into its string name. */
12369 dwarf_attr_name (unsigned attr)
12373 case DW_AT_sibling:
12374 return "DW_AT_sibling";
12375 case DW_AT_location:
12376 return "DW_AT_location";
12378 return "DW_AT_name";
12379 case DW_AT_ordering:
12380 return "DW_AT_ordering";
12381 case DW_AT_subscr_data:
12382 return "DW_AT_subscr_data";
12383 case DW_AT_byte_size:
12384 return "DW_AT_byte_size";
12385 case DW_AT_bit_offset:
12386 return "DW_AT_bit_offset";
12387 case DW_AT_bit_size:
12388 return "DW_AT_bit_size";
12389 case DW_AT_element_list:
12390 return "DW_AT_element_list";
12391 case DW_AT_stmt_list:
12392 return "DW_AT_stmt_list";
12394 return "DW_AT_low_pc";
12395 case DW_AT_high_pc:
12396 return "DW_AT_high_pc";
12397 case DW_AT_language:
12398 return "DW_AT_language";
12400 return "DW_AT_member";
12402 return "DW_AT_discr";
12403 case DW_AT_discr_value:
12404 return "DW_AT_discr_value";
12405 case DW_AT_visibility:
12406 return "DW_AT_visibility";
12408 return "DW_AT_import";
12409 case DW_AT_string_length:
12410 return "DW_AT_string_length";
12411 case DW_AT_common_reference:
12412 return "DW_AT_common_reference";
12413 case DW_AT_comp_dir:
12414 return "DW_AT_comp_dir";
12415 case DW_AT_const_value:
12416 return "DW_AT_const_value";
12417 case DW_AT_containing_type:
12418 return "DW_AT_containing_type";
12419 case DW_AT_default_value:
12420 return "DW_AT_default_value";
12422 return "DW_AT_inline";
12423 case DW_AT_is_optional:
12424 return "DW_AT_is_optional";
12425 case DW_AT_lower_bound:
12426 return "DW_AT_lower_bound";
12427 case DW_AT_producer:
12428 return "DW_AT_producer";
12429 case DW_AT_prototyped:
12430 return "DW_AT_prototyped";
12431 case DW_AT_return_addr:
12432 return "DW_AT_return_addr";
12433 case DW_AT_start_scope:
12434 return "DW_AT_start_scope";
12435 case DW_AT_bit_stride:
12436 return "DW_AT_bit_stride";
12437 case DW_AT_upper_bound:
12438 return "DW_AT_upper_bound";
12439 case DW_AT_abstract_origin:
12440 return "DW_AT_abstract_origin";
12441 case DW_AT_accessibility:
12442 return "DW_AT_accessibility";
12443 case DW_AT_address_class:
12444 return "DW_AT_address_class";
12445 case DW_AT_artificial:
12446 return "DW_AT_artificial";
12447 case DW_AT_base_types:
12448 return "DW_AT_base_types";
12449 case DW_AT_calling_convention:
12450 return "DW_AT_calling_convention";
12452 return "DW_AT_count";
12453 case DW_AT_data_member_location:
12454 return "DW_AT_data_member_location";
12455 case DW_AT_decl_column:
12456 return "DW_AT_decl_column";
12457 case DW_AT_decl_file:
12458 return "DW_AT_decl_file";
12459 case DW_AT_decl_line:
12460 return "DW_AT_decl_line";
12461 case DW_AT_declaration:
12462 return "DW_AT_declaration";
12463 case DW_AT_discr_list:
12464 return "DW_AT_discr_list";
12465 case DW_AT_encoding:
12466 return "DW_AT_encoding";
12467 case DW_AT_external:
12468 return "DW_AT_external";
12469 case DW_AT_frame_base:
12470 return "DW_AT_frame_base";
12472 return "DW_AT_friend";
12473 case DW_AT_identifier_case:
12474 return "DW_AT_identifier_case";
12475 case DW_AT_macro_info:
12476 return "DW_AT_macro_info";
12477 case DW_AT_namelist_items:
12478 return "DW_AT_namelist_items";
12479 case DW_AT_priority:
12480 return "DW_AT_priority";
12481 case DW_AT_segment:
12482 return "DW_AT_segment";
12483 case DW_AT_specification:
12484 return "DW_AT_specification";
12485 case DW_AT_static_link:
12486 return "DW_AT_static_link";
12488 return "DW_AT_type";
12489 case DW_AT_use_location:
12490 return "DW_AT_use_location";
12491 case DW_AT_variable_parameter:
12492 return "DW_AT_variable_parameter";
12493 case DW_AT_virtuality:
12494 return "DW_AT_virtuality";
12495 case DW_AT_vtable_elem_location:
12496 return "DW_AT_vtable_elem_location";
12497 /* DWARF 3 values. */
12498 case DW_AT_allocated:
12499 return "DW_AT_allocated";
12500 case DW_AT_associated:
12501 return "DW_AT_associated";
12502 case DW_AT_data_location:
12503 return "DW_AT_data_location";
12504 case DW_AT_byte_stride:
12505 return "DW_AT_byte_stride";
12506 case DW_AT_entry_pc:
12507 return "DW_AT_entry_pc";
12508 case DW_AT_use_UTF8:
12509 return "DW_AT_use_UTF8";
12510 case DW_AT_extension:
12511 return "DW_AT_extension";
12513 return "DW_AT_ranges";
12514 case DW_AT_trampoline:
12515 return "DW_AT_trampoline";
12516 case DW_AT_call_column:
12517 return "DW_AT_call_column";
12518 case DW_AT_call_file:
12519 return "DW_AT_call_file";
12520 case DW_AT_call_line:
12521 return "DW_AT_call_line";
12522 case DW_AT_description:
12523 return "DW_AT_description";
12524 case DW_AT_binary_scale:
12525 return "DW_AT_binary_scale";
12526 case DW_AT_decimal_scale:
12527 return "DW_AT_decimal_scale";
12529 return "DW_AT_small";
12530 case DW_AT_decimal_sign:
12531 return "DW_AT_decimal_sign";
12532 case DW_AT_digit_count:
12533 return "DW_AT_digit_count";
12534 case DW_AT_picture_string:
12535 return "DW_AT_picture_string";
12536 case DW_AT_mutable:
12537 return "DW_AT_mutable";
12538 case DW_AT_threads_scaled:
12539 return "DW_AT_threads_scaled";
12540 case DW_AT_explicit:
12541 return "DW_AT_explicit";
12542 case DW_AT_object_pointer:
12543 return "DW_AT_object_pointer";
12544 case DW_AT_endianity:
12545 return "DW_AT_endianity";
12546 case DW_AT_elemental:
12547 return "DW_AT_elemental";
12549 return "DW_AT_pure";
12550 case DW_AT_recursive:
12551 return "DW_AT_recursive";
12552 /* DWARF 4 values. */
12553 case DW_AT_signature:
12554 return "DW_AT_signature";
12555 case DW_AT_linkage_name:
12556 return "DW_AT_linkage_name";
12557 /* SGI/MIPS extensions. */
12558 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12559 case DW_AT_MIPS_fde:
12560 return "DW_AT_MIPS_fde";
12562 case DW_AT_MIPS_loop_begin:
12563 return "DW_AT_MIPS_loop_begin";
12564 case DW_AT_MIPS_tail_loop_begin:
12565 return "DW_AT_MIPS_tail_loop_begin";
12566 case DW_AT_MIPS_epilog_begin:
12567 return "DW_AT_MIPS_epilog_begin";
12568 case DW_AT_MIPS_loop_unroll_factor:
12569 return "DW_AT_MIPS_loop_unroll_factor";
12570 case DW_AT_MIPS_software_pipeline_depth:
12571 return "DW_AT_MIPS_software_pipeline_depth";
12572 case DW_AT_MIPS_linkage_name:
12573 return "DW_AT_MIPS_linkage_name";
12574 case DW_AT_MIPS_stride:
12575 return "DW_AT_MIPS_stride";
12576 case DW_AT_MIPS_abstract_name:
12577 return "DW_AT_MIPS_abstract_name";
12578 case DW_AT_MIPS_clone_origin:
12579 return "DW_AT_MIPS_clone_origin";
12580 case DW_AT_MIPS_has_inlines:
12581 return "DW_AT_MIPS_has_inlines";
12582 /* HP extensions. */
12583 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12584 case DW_AT_HP_block_index:
12585 return "DW_AT_HP_block_index";
12587 case DW_AT_HP_unmodifiable:
12588 return "DW_AT_HP_unmodifiable";
12589 case DW_AT_HP_actuals_stmt_list:
12590 return "DW_AT_HP_actuals_stmt_list";
12591 case DW_AT_HP_proc_per_section:
12592 return "DW_AT_HP_proc_per_section";
12593 case DW_AT_HP_raw_data_ptr:
12594 return "DW_AT_HP_raw_data_ptr";
12595 case DW_AT_HP_pass_by_reference:
12596 return "DW_AT_HP_pass_by_reference";
12597 case DW_AT_HP_opt_level:
12598 return "DW_AT_HP_opt_level";
12599 case DW_AT_HP_prof_version_id:
12600 return "DW_AT_HP_prof_version_id";
12601 case DW_AT_HP_opt_flags:
12602 return "DW_AT_HP_opt_flags";
12603 case DW_AT_HP_cold_region_low_pc:
12604 return "DW_AT_HP_cold_region_low_pc";
12605 case DW_AT_HP_cold_region_high_pc:
12606 return "DW_AT_HP_cold_region_high_pc";
12607 case DW_AT_HP_all_variables_modifiable:
12608 return "DW_AT_HP_all_variables_modifiable";
12609 case DW_AT_HP_linkage_name:
12610 return "DW_AT_HP_linkage_name";
12611 case DW_AT_HP_prof_flags:
12612 return "DW_AT_HP_prof_flags";
12613 /* GNU extensions. */
12614 case DW_AT_sf_names:
12615 return "DW_AT_sf_names";
12616 case DW_AT_src_info:
12617 return "DW_AT_src_info";
12618 case DW_AT_mac_info:
12619 return "DW_AT_mac_info";
12620 case DW_AT_src_coords:
12621 return "DW_AT_src_coords";
12622 case DW_AT_body_begin:
12623 return "DW_AT_body_begin";
12624 case DW_AT_body_end:
12625 return "DW_AT_body_end";
12626 case DW_AT_GNU_vector:
12627 return "DW_AT_GNU_vector";
12628 case DW_AT_GNU_odr_signature:
12629 return "DW_AT_GNU_odr_signature";
12630 /* VMS extensions. */
12631 case DW_AT_VMS_rtnbeg_pd_address:
12632 return "DW_AT_VMS_rtnbeg_pd_address";
12633 /* UPC extension. */
12634 case DW_AT_upc_threads_scaled:
12635 return "DW_AT_upc_threads_scaled";
12636 /* PGI (STMicroelectronics) extensions. */
12637 case DW_AT_PGI_lbase:
12638 return "DW_AT_PGI_lbase";
12639 case DW_AT_PGI_soffset:
12640 return "DW_AT_PGI_soffset";
12641 case DW_AT_PGI_lstride:
12642 return "DW_AT_PGI_lstride";
12644 return "DW_AT_<unknown>";
12648 /* Convert a DWARF value form code into its string name. */
12651 dwarf_form_name (unsigned form)
12656 return "DW_FORM_addr";
12657 case DW_FORM_block2:
12658 return "DW_FORM_block2";
12659 case DW_FORM_block4:
12660 return "DW_FORM_block4";
12661 case DW_FORM_data2:
12662 return "DW_FORM_data2";
12663 case DW_FORM_data4:
12664 return "DW_FORM_data4";
12665 case DW_FORM_data8:
12666 return "DW_FORM_data8";
12667 case DW_FORM_string:
12668 return "DW_FORM_string";
12669 case DW_FORM_block:
12670 return "DW_FORM_block";
12671 case DW_FORM_block1:
12672 return "DW_FORM_block1";
12673 case DW_FORM_data1:
12674 return "DW_FORM_data1";
12676 return "DW_FORM_flag";
12677 case DW_FORM_sdata:
12678 return "DW_FORM_sdata";
12680 return "DW_FORM_strp";
12681 case DW_FORM_udata:
12682 return "DW_FORM_udata";
12683 case DW_FORM_ref_addr:
12684 return "DW_FORM_ref_addr";
12686 return "DW_FORM_ref1";
12688 return "DW_FORM_ref2";
12690 return "DW_FORM_ref4";
12692 return "DW_FORM_ref8";
12693 case DW_FORM_ref_udata:
12694 return "DW_FORM_ref_udata";
12695 case DW_FORM_indirect:
12696 return "DW_FORM_indirect";
12697 case DW_FORM_sec_offset:
12698 return "DW_FORM_sec_offset";
12699 case DW_FORM_exprloc:
12700 return "DW_FORM_exprloc";
12701 case DW_FORM_flag_present:
12702 return "DW_FORM_flag_present";
12703 case DW_FORM_ref_sig8:
12704 return "DW_FORM_ref_sig8";
12706 return "DW_FORM_<unknown>";
12710 /* Convert a DWARF stack opcode into its string name. */
12713 dwarf_stack_op_name (unsigned op)
12718 return "DW_OP_addr";
12720 return "DW_OP_deref";
12721 case DW_OP_const1u:
12722 return "DW_OP_const1u";
12723 case DW_OP_const1s:
12724 return "DW_OP_const1s";
12725 case DW_OP_const2u:
12726 return "DW_OP_const2u";
12727 case DW_OP_const2s:
12728 return "DW_OP_const2s";
12729 case DW_OP_const4u:
12730 return "DW_OP_const4u";
12731 case DW_OP_const4s:
12732 return "DW_OP_const4s";
12733 case DW_OP_const8u:
12734 return "DW_OP_const8u";
12735 case DW_OP_const8s:
12736 return "DW_OP_const8s";
12738 return "DW_OP_constu";
12740 return "DW_OP_consts";
12742 return "DW_OP_dup";
12744 return "DW_OP_drop";
12746 return "DW_OP_over";
12748 return "DW_OP_pick";
12750 return "DW_OP_swap";
12752 return "DW_OP_rot";
12754 return "DW_OP_xderef";
12756 return "DW_OP_abs";
12758 return "DW_OP_and";
12760 return "DW_OP_div";
12762 return "DW_OP_minus";
12764 return "DW_OP_mod";
12766 return "DW_OP_mul";
12768 return "DW_OP_neg";
12770 return "DW_OP_not";
12774 return "DW_OP_plus";
12775 case DW_OP_plus_uconst:
12776 return "DW_OP_plus_uconst";
12778 return "DW_OP_shl";
12780 return "DW_OP_shr";
12782 return "DW_OP_shra";
12784 return "DW_OP_xor";
12786 return "DW_OP_bra";
12800 return "DW_OP_skip";
12802 return "DW_OP_lit0";
12804 return "DW_OP_lit1";
12806 return "DW_OP_lit2";
12808 return "DW_OP_lit3";
12810 return "DW_OP_lit4";
12812 return "DW_OP_lit5";
12814 return "DW_OP_lit6";
12816 return "DW_OP_lit7";
12818 return "DW_OP_lit8";
12820 return "DW_OP_lit9";
12822 return "DW_OP_lit10";
12824 return "DW_OP_lit11";
12826 return "DW_OP_lit12";
12828 return "DW_OP_lit13";
12830 return "DW_OP_lit14";
12832 return "DW_OP_lit15";
12834 return "DW_OP_lit16";
12836 return "DW_OP_lit17";
12838 return "DW_OP_lit18";
12840 return "DW_OP_lit19";
12842 return "DW_OP_lit20";
12844 return "DW_OP_lit21";
12846 return "DW_OP_lit22";
12848 return "DW_OP_lit23";
12850 return "DW_OP_lit24";
12852 return "DW_OP_lit25";
12854 return "DW_OP_lit26";
12856 return "DW_OP_lit27";
12858 return "DW_OP_lit28";
12860 return "DW_OP_lit29";
12862 return "DW_OP_lit30";
12864 return "DW_OP_lit31";
12866 return "DW_OP_reg0";
12868 return "DW_OP_reg1";
12870 return "DW_OP_reg2";
12872 return "DW_OP_reg3";
12874 return "DW_OP_reg4";
12876 return "DW_OP_reg5";
12878 return "DW_OP_reg6";
12880 return "DW_OP_reg7";
12882 return "DW_OP_reg8";
12884 return "DW_OP_reg9";
12886 return "DW_OP_reg10";
12888 return "DW_OP_reg11";
12890 return "DW_OP_reg12";
12892 return "DW_OP_reg13";
12894 return "DW_OP_reg14";
12896 return "DW_OP_reg15";
12898 return "DW_OP_reg16";
12900 return "DW_OP_reg17";
12902 return "DW_OP_reg18";
12904 return "DW_OP_reg19";
12906 return "DW_OP_reg20";
12908 return "DW_OP_reg21";
12910 return "DW_OP_reg22";
12912 return "DW_OP_reg23";
12914 return "DW_OP_reg24";
12916 return "DW_OP_reg25";
12918 return "DW_OP_reg26";
12920 return "DW_OP_reg27";
12922 return "DW_OP_reg28";
12924 return "DW_OP_reg29";
12926 return "DW_OP_reg30";
12928 return "DW_OP_reg31";
12930 return "DW_OP_breg0";
12932 return "DW_OP_breg1";
12934 return "DW_OP_breg2";
12936 return "DW_OP_breg3";
12938 return "DW_OP_breg4";
12940 return "DW_OP_breg5";
12942 return "DW_OP_breg6";
12944 return "DW_OP_breg7";
12946 return "DW_OP_breg8";
12948 return "DW_OP_breg9";
12950 return "DW_OP_breg10";
12952 return "DW_OP_breg11";
12954 return "DW_OP_breg12";
12956 return "DW_OP_breg13";
12958 return "DW_OP_breg14";
12960 return "DW_OP_breg15";
12962 return "DW_OP_breg16";
12964 return "DW_OP_breg17";
12966 return "DW_OP_breg18";
12968 return "DW_OP_breg19";
12970 return "DW_OP_breg20";
12972 return "DW_OP_breg21";
12974 return "DW_OP_breg22";
12976 return "DW_OP_breg23";
12978 return "DW_OP_breg24";
12980 return "DW_OP_breg25";
12982 return "DW_OP_breg26";
12984 return "DW_OP_breg27";
12986 return "DW_OP_breg28";
12988 return "DW_OP_breg29";
12990 return "DW_OP_breg30";
12992 return "DW_OP_breg31";
12994 return "DW_OP_regx";
12996 return "DW_OP_fbreg";
12998 return "DW_OP_bregx";
13000 return "DW_OP_piece";
13001 case DW_OP_deref_size:
13002 return "DW_OP_deref_size";
13003 case DW_OP_xderef_size:
13004 return "DW_OP_xderef_size";
13006 return "DW_OP_nop";
13007 /* DWARF 3 extensions. */
13008 case DW_OP_push_object_address:
13009 return "DW_OP_push_object_address";
13011 return "DW_OP_call2";
13013 return "DW_OP_call4";
13014 case DW_OP_call_ref:
13015 return "DW_OP_call_ref";
13016 case DW_OP_form_tls_address:
13017 return "DW_OP_form_tls_address";
13018 case DW_OP_call_frame_cfa:
13019 return "DW_OP_call_frame_cfa";
13020 case DW_OP_bit_piece:
13021 return "DW_OP_bit_piece";
13022 /* DWARF 4 extensions. */
13023 case DW_OP_implicit_value:
13024 return "DW_OP_implicit_value";
13025 case DW_OP_stack_value:
13026 return "DW_OP_stack_value";
13027 /* GNU extensions. */
13028 case DW_OP_GNU_push_tls_address:
13029 return "DW_OP_GNU_push_tls_address";
13030 case DW_OP_GNU_uninit:
13031 return "DW_OP_GNU_uninit";
13032 case DW_OP_GNU_implicit_pointer:
13033 return "DW_OP_GNU_implicit_pointer";
13040 dwarf_bool_name (unsigned mybool)
13048 /* Convert a DWARF type code into its string name. */
13051 dwarf_type_encoding_name (unsigned enc)
13056 return "DW_ATE_void";
13057 case DW_ATE_address:
13058 return "DW_ATE_address";
13059 case DW_ATE_boolean:
13060 return "DW_ATE_boolean";
13061 case DW_ATE_complex_float:
13062 return "DW_ATE_complex_float";
13064 return "DW_ATE_float";
13065 case DW_ATE_signed:
13066 return "DW_ATE_signed";
13067 case DW_ATE_signed_char:
13068 return "DW_ATE_signed_char";
13069 case DW_ATE_unsigned:
13070 return "DW_ATE_unsigned";
13071 case DW_ATE_unsigned_char:
13072 return "DW_ATE_unsigned_char";
13074 case DW_ATE_imaginary_float:
13075 return "DW_ATE_imaginary_float";
13076 case DW_ATE_packed_decimal:
13077 return "DW_ATE_packed_decimal";
13078 case DW_ATE_numeric_string:
13079 return "DW_ATE_numeric_string";
13080 case DW_ATE_edited:
13081 return "DW_ATE_edited";
13082 case DW_ATE_signed_fixed:
13083 return "DW_ATE_signed_fixed";
13084 case DW_ATE_unsigned_fixed:
13085 return "DW_ATE_unsigned_fixed";
13086 case DW_ATE_decimal_float:
13087 return "DW_ATE_decimal_float";
13090 return "DW_ATE_UTF";
13091 /* HP extensions. */
13092 case DW_ATE_HP_float80:
13093 return "DW_ATE_HP_float80";
13094 case DW_ATE_HP_complex_float80:
13095 return "DW_ATE_HP_complex_float80";
13096 case DW_ATE_HP_float128:
13097 return "DW_ATE_HP_float128";
13098 case DW_ATE_HP_complex_float128:
13099 return "DW_ATE_HP_complex_float128";
13100 case DW_ATE_HP_floathpintel:
13101 return "DW_ATE_HP_floathpintel";
13102 case DW_ATE_HP_imaginary_float80:
13103 return "DW_ATE_HP_imaginary_float80";
13104 case DW_ATE_HP_imaginary_float128:
13105 return "DW_ATE_HP_imaginary_float128";
13107 return "DW_ATE_<unknown>";
13111 /* Convert a DWARF call frame info operation to its string name. */
13115 dwarf_cfi_name (unsigned cfi_opc)
13119 case DW_CFA_advance_loc:
13120 return "DW_CFA_advance_loc";
13121 case DW_CFA_offset:
13122 return "DW_CFA_offset";
13123 case DW_CFA_restore:
13124 return "DW_CFA_restore";
13126 return "DW_CFA_nop";
13127 case DW_CFA_set_loc:
13128 return "DW_CFA_set_loc";
13129 case DW_CFA_advance_loc1:
13130 return "DW_CFA_advance_loc1";
13131 case DW_CFA_advance_loc2:
13132 return "DW_CFA_advance_loc2";
13133 case DW_CFA_advance_loc4:
13134 return "DW_CFA_advance_loc4";
13135 case DW_CFA_offset_extended:
13136 return "DW_CFA_offset_extended";
13137 case DW_CFA_restore_extended:
13138 return "DW_CFA_restore_extended";
13139 case DW_CFA_undefined:
13140 return "DW_CFA_undefined";
13141 case DW_CFA_same_value:
13142 return "DW_CFA_same_value";
13143 case DW_CFA_register:
13144 return "DW_CFA_register";
13145 case DW_CFA_remember_state:
13146 return "DW_CFA_remember_state";
13147 case DW_CFA_restore_state:
13148 return "DW_CFA_restore_state";
13149 case DW_CFA_def_cfa:
13150 return "DW_CFA_def_cfa";
13151 case DW_CFA_def_cfa_register:
13152 return "DW_CFA_def_cfa_register";
13153 case DW_CFA_def_cfa_offset:
13154 return "DW_CFA_def_cfa_offset";
13156 case DW_CFA_def_cfa_expression:
13157 return "DW_CFA_def_cfa_expression";
13158 case DW_CFA_expression:
13159 return "DW_CFA_expression";
13160 case DW_CFA_offset_extended_sf:
13161 return "DW_CFA_offset_extended_sf";
13162 case DW_CFA_def_cfa_sf:
13163 return "DW_CFA_def_cfa_sf";
13164 case DW_CFA_def_cfa_offset_sf:
13165 return "DW_CFA_def_cfa_offset_sf";
13166 case DW_CFA_val_offset:
13167 return "DW_CFA_val_offset";
13168 case DW_CFA_val_offset_sf:
13169 return "DW_CFA_val_offset_sf";
13170 case DW_CFA_val_expression:
13171 return "DW_CFA_val_expression";
13172 /* SGI/MIPS specific. */
13173 case DW_CFA_MIPS_advance_loc8:
13174 return "DW_CFA_MIPS_advance_loc8";
13175 /* GNU extensions. */
13176 case DW_CFA_GNU_window_save:
13177 return "DW_CFA_GNU_window_save";
13178 case DW_CFA_GNU_args_size:
13179 return "DW_CFA_GNU_args_size";
13180 case DW_CFA_GNU_negative_offset_extended:
13181 return "DW_CFA_GNU_negative_offset_extended";
13183 return "DW_CFA_<unknown>";
13189 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13193 print_spaces (indent, f);
13194 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13195 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13197 if (die->parent != NULL)
13199 print_spaces (indent, f);
13200 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13201 die->parent->offset);
13204 print_spaces (indent, f);
13205 fprintf_unfiltered (f, " has children: %s\n",
13206 dwarf_bool_name (die->child != NULL));
13208 print_spaces (indent, f);
13209 fprintf_unfiltered (f, " attributes:\n");
13211 for (i = 0; i < die->num_attrs; ++i)
13213 print_spaces (indent, f);
13214 fprintf_unfiltered (f, " %s (%s) ",
13215 dwarf_attr_name (die->attrs[i].name),
13216 dwarf_form_name (die->attrs[i].form));
13218 switch (die->attrs[i].form)
13220 case DW_FORM_ref_addr:
13222 fprintf_unfiltered (f, "address: ");
13223 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13225 case DW_FORM_block2:
13226 case DW_FORM_block4:
13227 case DW_FORM_block:
13228 case DW_FORM_block1:
13229 fprintf_unfiltered (f, "block: size %d",
13230 DW_BLOCK (&die->attrs[i])->size);
13232 case DW_FORM_exprloc:
13233 fprintf_unfiltered (f, "expression: size %u",
13234 DW_BLOCK (&die->attrs[i])->size);
13239 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13240 (long) (DW_ADDR (&die->attrs[i])));
13242 case DW_FORM_data1:
13243 case DW_FORM_data2:
13244 case DW_FORM_data4:
13245 case DW_FORM_data8:
13246 case DW_FORM_udata:
13247 case DW_FORM_sdata:
13248 fprintf_unfiltered (f, "constant: %s",
13249 pulongest (DW_UNSND (&die->attrs[i])));
13251 case DW_FORM_sec_offset:
13252 fprintf_unfiltered (f, "section offset: %s",
13253 pulongest (DW_UNSND (&die->attrs[i])));
13255 case DW_FORM_ref_sig8:
13256 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13257 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13258 DW_SIGNATURED_TYPE (&die->attrs[i])->offset);
13260 fprintf_unfiltered (f, "signatured type, offset: unknown");
13262 case DW_FORM_string:
13264 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13265 DW_STRING (&die->attrs[i])
13266 ? DW_STRING (&die->attrs[i]) : "",
13267 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13270 if (DW_UNSND (&die->attrs[i]))
13271 fprintf_unfiltered (f, "flag: TRUE");
13273 fprintf_unfiltered (f, "flag: FALSE");
13275 case DW_FORM_flag_present:
13276 fprintf_unfiltered (f, "flag: TRUE");
13278 case DW_FORM_indirect:
13279 /* The reader will have reduced the indirect form to
13280 the "base form" so this form should not occur. */
13281 fprintf_unfiltered (f,
13282 "unexpected attribute form: DW_FORM_indirect");
13285 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13286 die->attrs[i].form);
13289 fprintf_unfiltered (f, "\n");
13294 dump_die_for_error (struct die_info *die)
13296 dump_die_shallow (gdb_stderr, 0, die);
13300 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13302 int indent = level * 4;
13304 gdb_assert (die != NULL);
13306 if (level >= max_level)
13309 dump_die_shallow (f, indent, die);
13311 if (die->child != NULL)
13313 print_spaces (indent, f);
13314 fprintf_unfiltered (f, " Children:");
13315 if (level + 1 < max_level)
13317 fprintf_unfiltered (f, "\n");
13318 dump_die_1 (f, level + 1, max_level, die->child);
13322 fprintf_unfiltered (f,
13323 " [not printed, max nesting level reached]\n");
13327 if (die->sibling != NULL && level > 0)
13329 dump_die_1 (f, level, max_level, die->sibling);
13333 /* This is called from the pdie macro in gdbinit.in.
13334 It's not static so gcc will keep a copy callable from gdb. */
13337 dump_die (struct die_info *die, int max_level)
13339 dump_die_1 (gdb_stdlog, 0, max_level, die);
13343 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13347 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13353 is_ref_attr (struct attribute *attr)
13355 switch (attr->form)
13357 case DW_FORM_ref_addr:
13362 case DW_FORM_ref_udata:
13369 static unsigned int
13370 dwarf2_get_ref_die_offset (struct attribute *attr)
13372 if (is_ref_attr (attr))
13373 return DW_ADDR (attr);
13375 complaint (&symfile_complaints,
13376 _("unsupported die ref attribute form: '%s'"),
13377 dwarf_form_name (attr->form));
13381 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13382 * the value held by the attribute is not constant. */
13385 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13387 if (attr->form == DW_FORM_sdata)
13388 return DW_SND (attr);
13389 else if (attr->form == DW_FORM_udata
13390 || attr->form == DW_FORM_data1
13391 || attr->form == DW_FORM_data2
13392 || attr->form == DW_FORM_data4
13393 || attr->form == DW_FORM_data8)
13394 return DW_UNSND (attr);
13397 complaint (&symfile_complaints,
13398 _("Attribute value is not a constant (%s)"),
13399 dwarf_form_name (attr->form));
13400 return default_value;
13404 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13405 unit and add it to our queue.
13406 The result is non-zero if PER_CU was queued, otherwise the result is zero
13407 meaning either PER_CU is already queued or it is already loaded. */
13410 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
13411 struct dwarf2_per_cu_data *per_cu)
13413 /* We may arrive here during partial symbol reading, if we need full
13414 DIEs to process an unusual case (e.g. template arguments). Do
13415 not queue PER_CU, just tell our caller to load its DIEs. */
13416 if (dwarf2_per_objfile->reading_partial_symbols)
13418 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
13423 /* Mark the dependence relation so that we don't flush PER_CU
13425 dwarf2_add_dependence (this_cu, per_cu);
13427 /* If it's already on the queue, we have nothing to do. */
13428 if (per_cu->queued)
13431 /* If the compilation unit is already loaded, just mark it as
13433 if (per_cu->cu != NULL)
13435 per_cu->cu->last_used = 0;
13439 /* Add it to the queue. */
13440 queue_comp_unit (per_cu, this_cu->objfile);
13445 /* Follow reference or signature attribute ATTR of SRC_DIE.
13446 On entry *REF_CU is the CU of SRC_DIE.
13447 On exit *REF_CU is the CU of the result. */
13449 static struct die_info *
13450 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
13451 struct dwarf2_cu **ref_cu)
13453 struct die_info *die;
13455 if (is_ref_attr (attr))
13456 die = follow_die_ref (src_die, attr, ref_cu);
13457 else if (attr->form == DW_FORM_ref_sig8)
13458 die = follow_die_sig (src_die, attr, ref_cu);
13461 dump_die_for_error (src_die);
13462 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13463 (*ref_cu)->objfile->name);
13469 /* Follow reference OFFSET.
13470 On entry *REF_CU is the CU of the source die referencing OFFSET.
13471 On exit *REF_CU is the CU of the result.
13472 Returns NULL if OFFSET is invalid. */
13474 static struct die_info *
13475 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
13477 struct die_info temp_die;
13478 struct dwarf2_cu *target_cu, *cu = *ref_cu;
13480 gdb_assert (cu->per_cu != NULL);
13484 if (cu->per_cu->from_debug_types)
13486 /* .debug_types CUs cannot reference anything outside their CU.
13487 If they need to, they have to reference a signatured type via
13488 DW_FORM_ref_sig8. */
13489 if (! offset_in_cu_p (&cu->header, offset))
13492 else if (! offset_in_cu_p (&cu->header, offset))
13494 struct dwarf2_per_cu_data *per_cu;
13496 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
13498 /* If necessary, add it to the queue and load its DIEs. */
13499 if (maybe_queue_comp_unit (cu, per_cu))
13500 load_full_comp_unit (per_cu, cu->objfile);
13502 target_cu = per_cu->cu;
13504 else if (cu->dies == NULL)
13506 /* We're loading full DIEs during partial symbol reading. */
13507 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
13508 load_full_comp_unit (cu->per_cu, cu->objfile);
13511 *ref_cu = target_cu;
13512 temp_die.offset = offset;
13513 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
13516 /* Follow reference attribute ATTR of SRC_DIE.
13517 On entry *REF_CU is the CU of SRC_DIE.
13518 On exit *REF_CU is the CU of the result. */
13520 static struct die_info *
13521 follow_die_ref (struct die_info *src_die, struct attribute *attr,
13522 struct dwarf2_cu **ref_cu)
13524 unsigned int offset = dwarf2_get_ref_die_offset (attr);
13525 struct dwarf2_cu *cu = *ref_cu;
13526 struct die_info *die;
13528 die = follow_die_offset (offset, ref_cu);
13530 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13531 "at 0x%x [in module %s]"),
13532 offset, src_die->offset, cu->objfile->name);
13537 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13538 value is intended for DW_OP_call*. */
13540 struct dwarf2_locexpr_baton
13541 dwarf2_fetch_die_location_block (unsigned int offset,
13542 struct dwarf2_per_cu_data *per_cu,
13543 CORE_ADDR (*get_frame_pc) (void *baton),
13546 struct dwarf2_cu *cu = per_cu->cu;
13547 struct die_info *die;
13548 struct attribute *attr;
13549 struct dwarf2_locexpr_baton retval;
13551 dw2_setup (per_cu->objfile);
13553 die = follow_die_offset (offset, &cu);
13555 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13556 offset, per_cu->cu->objfile->name);
13558 attr = dwarf2_attr (die, DW_AT_location, cu);
13561 /* DWARF: "If there is no such attribute, then there is no effect.". */
13563 retval.data = NULL;
13566 else if (attr_form_is_section_offset (attr))
13568 struct dwarf2_loclist_baton loclist_baton;
13569 CORE_ADDR pc = (*get_frame_pc) (baton);
13572 fill_in_loclist_baton (cu, &loclist_baton, attr);
13574 retval.data = dwarf2_find_location_expression (&loclist_baton,
13576 retval.size = size;
13580 if (!attr_form_is_block (attr))
13581 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13582 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13583 offset, per_cu->cu->objfile->name);
13585 retval.data = DW_BLOCK (attr)->data;
13586 retval.size = DW_BLOCK (attr)->size;
13588 retval.per_cu = cu->per_cu;
13592 /* Follow the signature attribute ATTR in SRC_DIE.
13593 On entry *REF_CU is the CU of SRC_DIE.
13594 On exit *REF_CU is the CU of the result. */
13596 static struct die_info *
13597 follow_die_sig (struct die_info *src_die, struct attribute *attr,
13598 struct dwarf2_cu **ref_cu)
13600 struct objfile *objfile = (*ref_cu)->objfile;
13601 struct die_info temp_die;
13602 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
13603 struct dwarf2_cu *sig_cu;
13604 struct die_info *die;
13606 /* sig_type will be NULL if the signatured type is missing from
13608 if (sig_type == NULL)
13609 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13610 "at 0x%x [in module %s]"),
13611 src_die->offset, objfile->name);
13613 /* If necessary, add it to the queue and load its DIEs. */
13615 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
13616 read_signatured_type (objfile, sig_type);
13618 gdb_assert (sig_type->per_cu.cu != NULL);
13620 sig_cu = sig_type->per_cu.cu;
13621 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
13622 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
13629 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13630 "from DIE at 0x%x [in module %s]"),
13631 sig_type->type_offset, src_die->offset, objfile->name);
13634 /* Given an offset of a signatured type, return its signatured_type. */
13636 static struct signatured_type *
13637 lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset)
13639 gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset;
13640 unsigned int length, initial_length_size;
13641 unsigned int sig_offset;
13642 struct signatured_type find_entry, *type_sig;
13644 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
13645 sig_offset = (initial_length_size
13647 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
13648 + 1 /*address_size*/);
13649 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
13650 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
13652 /* This is only used to lookup previously recorded types.
13653 If we didn't find it, it's our bug. */
13654 gdb_assert (type_sig != NULL);
13655 gdb_assert (offset == type_sig->offset);
13660 /* Read in signatured type at OFFSET and build its CU and die(s). */
13663 read_signatured_type_at_offset (struct objfile *objfile,
13664 unsigned int offset)
13666 struct signatured_type *type_sig;
13668 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13670 /* We have the section offset, but we need the signature to do the
13671 hash table lookup. */
13672 type_sig = lookup_signatured_type_at_offset (objfile, offset);
13674 gdb_assert (type_sig->per_cu.cu == NULL);
13676 read_signatured_type (objfile, type_sig);
13678 gdb_assert (type_sig->per_cu.cu != NULL);
13681 /* Read in a signatured type and build its CU and DIEs. */
13684 read_signatured_type (struct objfile *objfile,
13685 struct signatured_type *type_sig)
13687 gdb_byte *types_ptr;
13688 struct die_reader_specs reader_specs;
13689 struct dwarf2_cu *cu;
13690 ULONGEST signature;
13691 struct cleanup *back_to, *free_cu_cleanup;
13693 dwarf2_read_section (objfile, &dwarf2_per_objfile->types);
13694 types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset;
13696 gdb_assert (type_sig->per_cu.cu == NULL);
13698 cu = xmalloc (sizeof (*cu));
13699 init_one_comp_unit (cu, objfile);
13701 type_sig->per_cu.cu = cu;
13702 cu->per_cu = &type_sig->per_cu;
13704 /* If an error occurs while loading, release our storage. */
13705 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
13707 types_ptr = read_type_comp_unit_head (&cu->header, &signature,
13708 types_ptr, objfile->obfd);
13709 gdb_assert (signature == type_sig->signature);
13712 = htab_create_alloc_ex (cu->header.length / 12,
13716 &cu->comp_unit_obstack,
13717 hashtab_obstack_allocate,
13718 dummy_obstack_deallocate);
13720 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
13721 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
13723 init_cu_die_reader (&reader_specs, cu);
13725 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
13728 /* We try not to read any attributes in this function, because not
13729 all objfiles needed for references have been loaded yet, and symbol
13730 table processing isn't initialized. But we have to set the CU language,
13731 or we won't be able to build types correctly. */
13732 prepare_one_comp_unit (cu, cu->dies);
13734 do_cleanups (back_to);
13736 /* We've successfully allocated this compilation unit. Let our caller
13737 clean it up when finished with it. */
13738 discard_cleanups (free_cu_cleanup);
13740 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
13741 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
13744 /* Decode simple location descriptions.
13745 Given a pointer to a dwarf block that defines a location, compute
13746 the location and return the value.
13748 NOTE drow/2003-11-18: This function is called in two situations
13749 now: for the address of static or global variables (partial symbols
13750 only) and for offsets into structures which are expected to be
13751 (more or less) constant. The partial symbol case should go away,
13752 and only the constant case should remain. That will let this
13753 function complain more accurately. A few special modes are allowed
13754 without complaint for global variables (for instance, global
13755 register values and thread-local values).
13757 A location description containing no operations indicates that the
13758 object is optimized out. The return value is 0 for that case.
13759 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13760 callers will only want a very basic result and this can become a
13763 Note that stack[0] is unused except as a default error return. */
13766 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
13768 struct objfile *objfile = cu->objfile;
13770 int size = blk->size;
13771 gdb_byte *data = blk->data;
13772 CORE_ADDR stack[64];
13774 unsigned int bytes_read, unsnd;
13780 stack[++stacki] = 0;
13819 stack[++stacki] = op - DW_OP_lit0;
13854 stack[++stacki] = op - DW_OP_reg0;
13856 dwarf2_complex_location_expr_complaint ();
13860 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
13862 stack[++stacki] = unsnd;
13864 dwarf2_complex_location_expr_complaint ();
13868 stack[++stacki] = read_address (objfile->obfd, &data[i],
13873 case DW_OP_const1u:
13874 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
13878 case DW_OP_const1s:
13879 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
13883 case DW_OP_const2u:
13884 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
13888 case DW_OP_const2s:
13889 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
13893 case DW_OP_const4u:
13894 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
13898 case DW_OP_const4s:
13899 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
13904 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
13910 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
13915 stack[stacki + 1] = stack[stacki];
13920 stack[stacki - 1] += stack[stacki];
13924 case DW_OP_plus_uconst:
13925 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
13931 stack[stacki - 1] -= stack[stacki];
13936 /* If we're not the last op, then we definitely can't encode
13937 this using GDB's address_class enum. This is valid for partial
13938 global symbols, although the variable's address will be bogus
13941 dwarf2_complex_location_expr_complaint ();
13944 case DW_OP_GNU_push_tls_address:
13945 /* The top of the stack has the offset from the beginning
13946 of the thread control block at which the variable is located. */
13947 /* Nothing should follow this operator, so the top of stack would
13949 /* This is valid for partial global symbols, but the variable's
13950 address will be bogus in the psymtab. */
13952 dwarf2_complex_location_expr_complaint ();
13955 case DW_OP_GNU_uninit:
13960 const char *name = dwarf_stack_op_name (op);
13963 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
13966 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
13970 return (stack[stacki]);
13973 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13974 outside of the allocated space. Also enforce minimum>0. */
13975 if (stacki >= ARRAY_SIZE (stack) - 1)
13977 complaint (&symfile_complaints,
13978 _("location description stack overflow"));
13984 complaint (&symfile_complaints,
13985 _("location description stack underflow"));
13989 return (stack[stacki]);
13992 /* memory allocation interface */
13994 static struct dwarf_block *
13995 dwarf_alloc_block (struct dwarf2_cu *cu)
13997 struct dwarf_block *blk;
13999 blk = (struct dwarf_block *)
14000 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14004 static struct abbrev_info *
14005 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14007 struct abbrev_info *abbrev;
14009 abbrev = (struct abbrev_info *)
14010 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14011 memset (abbrev, 0, sizeof (struct abbrev_info));
14015 static struct die_info *
14016 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14018 struct die_info *die;
14019 size_t size = sizeof (struct die_info);
14022 size += (num_attrs - 1) * sizeof (struct attribute);
14024 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14025 memset (die, 0, sizeof (struct die_info));
14030 /* Macro support. */
14032 /* Return the full name of file number I in *LH's file name table.
14033 Use COMP_DIR as the name of the current directory of the
14034 compilation. The result is allocated using xmalloc; the caller is
14035 responsible for freeing it. */
14037 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14039 /* Is the file number a valid index into the line header's file name
14040 table? Remember that file numbers start with one, not zero. */
14041 if (1 <= file && file <= lh->num_file_names)
14043 struct file_entry *fe = &lh->file_names[file - 1];
14045 if (IS_ABSOLUTE_PATH (fe->name))
14046 return xstrdup (fe->name);
14054 dir = lh->include_dirs[fe->dir_index - 1];
14060 dir_len = strlen (dir);
14061 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14062 strcpy (full_name, dir);
14063 full_name[dir_len] = '/';
14064 strcpy (full_name + dir_len + 1, fe->name);
14068 return xstrdup (fe->name);
14073 /* The compiler produced a bogus file number. We can at least
14074 record the macro definitions made in the file, even if we
14075 won't be able to find the file by name. */
14076 char fake_name[80];
14078 sprintf (fake_name, "<bad macro file number %d>", file);
14080 complaint (&symfile_complaints,
14081 _("bad file number in macro information (%d)"),
14084 return xstrdup (fake_name);
14089 static struct macro_source_file *
14090 macro_start_file (int file, int line,
14091 struct macro_source_file *current_file,
14092 const char *comp_dir,
14093 struct line_header *lh, struct objfile *objfile)
14095 /* The full name of this source file. */
14096 char *full_name = file_full_name (file, lh, comp_dir);
14098 /* We don't create a macro table for this compilation unit
14099 at all until we actually get a filename. */
14100 if (! pending_macros)
14101 pending_macros = new_macro_table (&objfile->objfile_obstack,
14102 objfile->macro_cache);
14104 if (! current_file)
14105 /* If we have no current file, then this must be the start_file
14106 directive for the compilation unit's main source file. */
14107 current_file = macro_set_main (pending_macros, full_name);
14109 current_file = macro_include (current_file, line, full_name);
14113 return current_file;
14117 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14118 followed by a null byte. */
14120 copy_string (const char *buf, int len)
14122 char *s = xmalloc (len + 1);
14124 memcpy (s, buf, len);
14130 static const char *
14131 consume_improper_spaces (const char *p, const char *body)
14135 complaint (&symfile_complaints,
14136 _("macro definition contains spaces "
14137 "in formal argument list:\n`%s'"),
14149 parse_macro_definition (struct macro_source_file *file, int line,
14154 /* The body string takes one of two forms. For object-like macro
14155 definitions, it should be:
14157 <macro name> " " <definition>
14159 For function-like macro definitions, it should be:
14161 <macro name> "() " <definition>
14163 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14165 Spaces may appear only where explicitly indicated, and in the
14168 The Dwarf 2 spec says that an object-like macro's name is always
14169 followed by a space, but versions of GCC around March 2002 omit
14170 the space when the macro's definition is the empty string.
14172 The Dwarf 2 spec says that there should be no spaces between the
14173 formal arguments in a function-like macro's formal argument list,
14174 but versions of GCC around March 2002 include spaces after the
14178 /* Find the extent of the macro name. The macro name is terminated
14179 by either a space or null character (for an object-like macro) or
14180 an opening paren (for a function-like macro). */
14181 for (p = body; *p; p++)
14182 if (*p == ' ' || *p == '(')
14185 if (*p == ' ' || *p == '\0')
14187 /* It's an object-like macro. */
14188 int name_len = p - body;
14189 char *name = copy_string (body, name_len);
14190 const char *replacement;
14193 replacement = body + name_len + 1;
14196 dwarf2_macro_malformed_definition_complaint (body);
14197 replacement = body + name_len;
14200 macro_define_object (file, line, name, replacement);
14204 else if (*p == '(')
14206 /* It's a function-like macro. */
14207 char *name = copy_string (body, p - body);
14210 char **argv = xmalloc (argv_size * sizeof (*argv));
14214 p = consume_improper_spaces (p, body);
14216 /* Parse the formal argument list. */
14217 while (*p && *p != ')')
14219 /* Find the extent of the current argument name. */
14220 const char *arg_start = p;
14222 while (*p && *p != ',' && *p != ')' && *p != ' ')
14225 if (! *p || p == arg_start)
14226 dwarf2_macro_malformed_definition_complaint (body);
14229 /* Make sure argv has room for the new argument. */
14230 if (argc >= argv_size)
14233 argv = xrealloc (argv, argv_size * sizeof (*argv));
14236 argv[argc++] = copy_string (arg_start, p - arg_start);
14239 p = consume_improper_spaces (p, body);
14241 /* Consume the comma, if present. */
14246 p = consume_improper_spaces (p, body);
14255 /* Perfectly formed definition, no complaints. */
14256 macro_define_function (file, line, name,
14257 argc, (const char **) argv,
14259 else if (*p == '\0')
14261 /* Complain, but do define it. */
14262 dwarf2_macro_malformed_definition_complaint (body);
14263 macro_define_function (file, line, name,
14264 argc, (const char **) argv,
14268 /* Just complain. */
14269 dwarf2_macro_malformed_definition_complaint (body);
14272 /* Just complain. */
14273 dwarf2_macro_malformed_definition_complaint (body);
14279 for (i = 0; i < argc; i++)
14285 dwarf2_macro_malformed_definition_complaint (body);
14290 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
14291 char *comp_dir, bfd *abfd,
14292 struct dwarf2_cu *cu)
14294 gdb_byte *mac_ptr, *mac_end;
14295 struct macro_source_file *current_file = 0;
14296 enum dwarf_macinfo_record_type macinfo_type;
14297 int at_commandline;
14299 dwarf2_read_section (dwarf2_per_objfile->objfile,
14300 &dwarf2_per_objfile->macinfo);
14301 if (dwarf2_per_objfile->macinfo.buffer == NULL)
14303 complaint (&symfile_complaints, _("missing .debug_macinfo section"));
14307 /* First pass: Find the name of the base filename.
14308 This filename is needed in order to process all macros whose definition
14309 (or undefinition) comes from the command line. These macros are defined
14310 before the first DW_MACINFO_start_file entry, and yet still need to be
14311 associated to the base file.
14313 To determine the base file name, we scan the macro definitions until we
14314 reach the first DW_MACINFO_start_file entry. We then initialize
14315 CURRENT_FILE accordingly so that any macro definition found before the
14316 first DW_MACINFO_start_file can still be associated to the base file. */
14318 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14319 mac_end = dwarf2_per_objfile->macinfo.buffer
14320 + dwarf2_per_objfile->macinfo.size;
14324 /* Do we at least have room for a macinfo type byte? */
14325 if (mac_ptr >= mac_end)
14327 /* Complaint is printed during the second pass as GDB will probably
14328 stop the first pass earlier upon finding
14329 DW_MACINFO_start_file. */
14333 macinfo_type = read_1_byte (abfd, mac_ptr);
14336 switch (macinfo_type)
14338 /* A zero macinfo type indicates the end of the macro
14343 case DW_MACINFO_define:
14344 case DW_MACINFO_undef:
14345 /* Only skip the data by MAC_PTR. */
14347 unsigned int bytes_read;
14349 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14350 mac_ptr += bytes_read;
14351 read_direct_string (abfd, mac_ptr, &bytes_read);
14352 mac_ptr += bytes_read;
14356 case DW_MACINFO_start_file:
14358 unsigned int bytes_read;
14361 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14362 mac_ptr += bytes_read;
14363 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14364 mac_ptr += bytes_read;
14366 current_file = macro_start_file (file, line, current_file,
14367 comp_dir, lh, cu->objfile);
14371 case DW_MACINFO_end_file:
14372 /* No data to skip by MAC_PTR. */
14375 case DW_MACINFO_vendor_ext:
14376 /* Only skip the data by MAC_PTR. */
14378 unsigned int bytes_read;
14380 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14381 mac_ptr += bytes_read;
14382 read_direct_string (abfd, mac_ptr, &bytes_read);
14383 mac_ptr += bytes_read;
14390 } while (macinfo_type != 0 && current_file == NULL);
14392 /* Second pass: Process all entries.
14394 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14395 command-line macro definitions/undefinitions. This flag is unset when we
14396 reach the first DW_MACINFO_start_file entry. */
14398 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
14400 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14401 GDB is still reading the definitions from command line. First
14402 DW_MACINFO_start_file will need to be ignored as it was already executed
14403 to create CURRENT_FILE for the main source holding also the command line
14404 definitions. On first met DW_MACINFO_start_file this flag is reset to
14405 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14407 at_commandline = 1;
14411 /* Do we at least have room for a macinfo type byte? */
14412 if (mac_ptr >= mac_end)
14414 dwarf2_macros_too_long_complaint ();
14418 macinfo_type = read_1_byte (abfd, mac_ptr);
14421 switch (macinfo_type)
14423 /* A zero macinfo type indicates the end of the macro
14428 case DW_MACINFO_define:
14429 case DW_MACINFO_undef:
14431 unsigned int bytes_read;
14435 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14436 mac_ptr += bytes_read;
14437 body = read_direct_string (abfd, mac_ptr, &bytes_read);
14438 mac_ptr += bytes_read;
14440 if (! current_file)
14442 /* DWARF violation as no main source is present. */
14443 complaint (&symfile_complaints,
14444 _("debug info with no main source gives macro %s "
14446 macinfo_type == DW_MACINFO_define ?
14448 macinfo_type == DW_MACINFO_undef ?
14449 _("undefinition") :
14450 _("something-or-other"), line, body);
14453 if ((line == 0 && !at_commandline)
14454 || (line != 0 && at_commandline))
14455 complaint (&symfile_complaints,
14456 _("debug info gives %s macro %s with %s line %d: %s"),
14457 at_commandline ? _("command-line") : _("in-file"),
14458 macinfo_type == DW_MACINFO_define ?
14460 macinfo_type == DW_MACINFO_undef ?
14461 _("undefinition") :
14462 _("something-or-other"),
14463 line == 0 ? _("zero") : _("non-zero"), line, body);
14465 if (macinfo_type == DW_MACINFO_define)
14466 parse_macro_definition (current_file, line, body);
14467 else if (macinfo_type == DW_MACINFO_undef)
14468 macro_undef (current_file, line, body);
14472 case DW_MACINFO_start_file:
14474 unsigned int bytes_read;
14477 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14478 mac_ptr += bytes_read;
14479 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14480 mac_ptr += bytes_read;
14482 if ((line == 0 && !at_commandline)
14483 || (line != 0 && at_commandline))
14484 complaint (&symfile_complaints,
14485 _("debug info gives source %d included "
14486 "from %s at %s line %d"),
14487 file, at_commandline ? _("command-line") : _("file"),
14488 line == 0 ? _("zero") : _("non-zero"), line);
14490 if (at_commandline)
14492 /* This DW_MACINFO_start_file was executed in the pass one. */
14493 at_commandline = 0;
14496 current_file = macro_start_file (file, line,
14497 current_file, comp_dir,
14502 case DW_MACINFO_end_file:
14503 if (! current_file)
14504 complaint (&symfile_complaints,
14505 _("macro debug info has an unmatched "
14506 "`close_file' directive"));
14509 current_file = current_file->included_by;
14510 if (! current_file)
14512 enum dwarf_macinfo_record_type next_type;
14514 /* GCC circa March 2002 doesn't produce the zero
14515 type byte marking the end of the compilation
14516 unit. Complain if it's not there, but exit no
14519 /* Do we at least have room for a macinfo type byte? */
14520 if (mac_ptr >= mac_end)
14522 dwarf2_macros_too_long_complaint ();
14526 /* We don't increment mac_ptr here, so this is just
14528 next_type = read_1_byte (abfd, mac_ptr);
14529 if (next_type != 0)
14530 complaint (&symfile_complaints,
14531 _("no terminating 0-type entry for "
14532 "macros in `.debug_macinfo' section"));
14539 case DW_MACINFO_vendor_ext:
14541 unsigned int bytes_read;
14544 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14545 mac_ptr += bytes_read;
14546 read_direct_string (abfd, mac_ptr, &bytes_read);
14547 mac_ptr += bytes_read;
14549 /* We don't recognize any vendor extensions. */
14553 } while (macinfo_type != 0);
14556 /* Check if the attribute's form is a DW_FORM_block*
14557 if so return true else false. */
14559 attr_form_is_block (struct attribute *attr)
14561 return (attr == NULL ? 0 :
14562 attr->form == DW_FORM_block1
14563 || attr->form == DW_FORM_block2
14564 || attr->form == DW_FORM_block4
14565 || attr->form == DW_FORM_block
14566 || attr->form == DW_FORM_exprloc);
14569 /* Return non-zero if ATTR's value is a section offset --- classes
14570 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14571 You may use DW_UNSND (attr) to retrieve such offsets.
14573 Section 7.5.4, "Attribute Encodings", explains that no attribute
14574 may have a value that belongs to more than one of these classes; it
14575 would be ambiguous if we did, because we use the same forms for all
14578 attr_form_is_section_offset (struct attribute *attr)
14580 return (attr->form == DW_FORM_data4
14581 || attr->form == DW_FORM_data8
14582 || attr->form == DW_FORM_sec_offset);
14586 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14587 zero otherwise. When this function returns true, you can apply
14588 dwarf2_get_attr_constant_value to it.
14590 However, note that for some attributes you must check
14591 attr_form_is_section_offset before using this test. DW_FORM_data4
14592 and DW_FORM_data8 are members of both the constant class, and of
14593 the classes that contain offsets into other debug sections
14594 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14595 that, if an attribute's can be either a constant or one of the
14596 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14597 taken as section offsets, not constants. */
14599 attr_form_is_constant (struct attribute *attr)
14601 switch (attr->form)
14603 case DW_FORM_sdata:
14604 case DW_FORM_udata:
14605 case DW_FORM_data1:
14606 case DW_FORM_data2:
14607 case DW_FORM_data4:
14608 case DW_FORM_data8:
14615 /* A helper function that fills in a dwarf2_loclist_baton. */
14618 fill_in_loclist_baton (struct dwarf2_cu *cu,
14619 struct dwarf2_loclist_baton *baton,
14620 struct attribute *attr)
14622 dwarf2_read_section (dwarf2_per_objfile->objfile,
14623 &dwarf2_per_objfile->loc);
14625 baton->per_cu = cu->per_cu;
14626 gdb_assert (baton->per_cu);
14627 /* We don't know how long the location list is, but make sure we
14628 don't run off the edge of the section. */
14629 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
14630 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
14631 baton->base_address = cu->base_address;
14635 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
14636 struct dwarf2_cu *cu)
14638 if (attr_form_is_section_offset (attr)
14639 /* ".debug_loc" may not exist at all, or the offset may be outside
14640 the section. If so, fall through to the complaint in the
14642 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
14643 &dwarf2_per_objfile->loc))
14645 struct dwarf2_loclist_baton *baton;
14647 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14648 sizeof (struct dwarf2_loclist_baton));
14650 fill_in_loclist_baton (cu, baton, attr);
14652 if (cu->base_known == 0)
14653 complaint (&symfile_complaints,
14654 _("Location list used without "
14655 "specifying the CU base address."));
14657 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
14658 SYMBOL_LOCATION_BATON (sym) = baton;
14662 struct dwarf2_locexpr_baton *baton;
14664 baton = obstack_alloc (&cu->objfile->objfile_obstack,
14665 sizeof (struct dwarf2_locexpr_baton));
14666 baton->per_cu = cu->per_cu;
14667 gdb_assert (baton->per_cu);
14669 if (attr_form_is_block (attr))
14671 /* Note that we're just copying the block's data pointer
14672 here, not the actual data. We're still pointing into the
14673 info_buffer for SYM's objfile; right now we never release
14674 that buffer, but when we do clean up properly this may
14676 baton->size = DW_BLOCK (attr)->size;
14677 baton->data = DW_BLOCK (attr)->data;
14681 dwarf2_invalid_attrib_class_complaint ("location description",
14682 SYMBOL_NATURAL_NAME (sym));
14684 baton->data = NULL;
14687 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
14688 SYMBOL_LOCATION_BATON (sym) = baton;
14692 /* Return the OBJFILE associated with the compilation unit CU. If CU
14693 came from a separate debuginfo file, then the master objfile is
14697 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
14699 struct objfile *objfile = per_cu->objfile;
14701 /* Return the master objfile, so that we can report and look up the
14702 correct file containing this variable. */
14703 if (objfile->separate_debug_objfile_backlink)
14704 objfile = objfile->separate_debug_objfile_backlink;
14709 /* Return the address size given in the compilation unit header for CU. */
14712 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
14715 return per_cu->cu->header.addr_size;
14718 /* If the CU is not currently read in, we re-read its header. */
14719 struct objfile *objfile = per_cu->objfile;
14720 struct dwarf2_per_objfile *per_objfile
14721 = objfile_data (objfile, dwarf2_objfile_data_key);
14722 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14723 struct comp_unit_head cu_header;
14725 memset (&cu_header, 0, sizeof cu_header);
14726 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14727 return cu_header.addr_size;
14731 /* Return the offset size given in the compilation unit header for CU. */
14734 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
14737 return per_cu->cu->header.offset_size;
14740 /* If the CU is not currently read in, we re-read its header. */
14741 struct objfile *objfile = per_cu->objfile;
14742 struct dwarf2_per_objfile *per_objfile
14743 = objfile_data (objfile, dwarf2_objfile_data_key);
14744 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
14745 struct comp_unit_head cu_header;
14747 memset (&cu_header, 0, sizeof cu_header);
14748 read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
14749 return cu_header.offset_size;
14753 /* Return the text offset of the CU. The returned offset comes from
14754 this CU's objfile. If this objfile came from a separate debuginfo
14755 file, then the offset may be different from the corresponding
14756 offset in the parent objfile. */
14759 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
14761 struct objfile *objfile = per_cu->objfile;
14763 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14766 /* Locate the .debug_info compilation unit from CU's objfile which contains
14767 the DIE at OFFSET. Raises an error on failure. */
14769 static struct dwarf2_per_cu_data *
14770 dwarf2_find_containing_comp_unit (unsigned int offset,
14771 struct objfile *objfile)
14773 struct dwarf2_per_cu_data *this_cu;
14777 high = dwarf2_per_objfile->n_comp_units - 1;
14780 int mid = low + (high - low) / 2;
14782 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
14787 gdb_assert (low == high);
14788 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
14791 error (_("Dwarf Error: could not find partial DIE containing "
14792 "offset 0x%lx [in module %s]"),
14793 (long) offset, bfd_get_filename (objfile->obfd));
14795 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
14796 return dwarf2_per_objfile->all_comp_units[low-1];
14800 this_cu = dwarf2_per_objfile->all_comp_units[low];
14801 if (low == dwarf2_per_objfile->n_comp_units - 1
14802 && offset >= this_cu->offset + this_cu->length)
14803 error (_("invalid dwarf2 offset %u"), offset);
14804 gdb_assert (offset < this_cu->offset + this_cu->length);
14809 /* Locate the compilation unit from OBJFILE which is located at exactly
14810 OFFSET. Raises an error on failure. */
14812 static struct dwarf2_per_cu_data *
14813 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
14815 struct dwarf2_per_cu_data *this_cu;
14817 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
14818 if (this_cu->offset != offset)
14819 error (_("no compilation unit with offset %u."), offset);
14823 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14826 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
14828 memset (cu, 0, sizeof (*cu));
14829 cu->objfile = objfile;
14830 obstack_init (&cu->comp_unit_obstack);
14833 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14836 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
14838 struct attribute *attr;
14840 /* Set the language we're debugging. */
14841 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
14843 set_cu_language (DW_UNSND (attr), cu);
14846 cu->language = language_minimal;
14847 cu->language_defn = language_def (cu->language);
14851 /* Release one cached compilation unit, CU. We unlink it from the tree
14852 of compilation units, but we don't remove it from the read_in_chain;
14853 the caller is responsible for that.
14854 NOTE: DATA is a void * because this function is also used as a
14855 cleanup routine. */
14858 free_one_comp_unit (void *data)
14860 struct dwarf2_cu *cu = data;
14862 if (cu->per_cu != NULL)
14863 cu->per_cu->cu = NULL;
14866 obstack_free (&cu->comp_unit_obstack, NULL);
14871 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14872 when we're finished with it. We can't free the pointer itself, but be
14873 sure to unlink it from the cache. Also release any associated storage
14874 and perform cache maintenance.
14876 Only used during partial symbol parsing. */
14879 free_stack_comp_unit (void *data)
14881 struct dwarf2_cu *cu = data;
14883 obstack_free (&cu->comp_unit_obstack, NULL);
14884 cu->partial_dies = NULL;
14886 if (cu->per_cu != NULL)
14888 /* This compilation unit is on the stack in our caller, so we
14889 should not xfree it. Just unlink it. */
14890 cu->per_cu->cu = NULL;
14893 /* If we had a per-cu pointer, then we may have other compilation
14894 units loaded, so age them now. */
14895 age_cached_comp_units ();
14899 /* Free all cached compilation units. */
14902 free_cached_comp_units (void *data)
14904 struct dwarf2_per_cu_data *per_cu, **last_chain;
14906 per_cu = dwarf2_per_objfile->read_in_chain;
14907 last_chain = &dwarf2_per_objfile->read_in_chain;
14908 while (per_cu != NULL)
14910 struct dwarf2_per_cu_data *next_cu;
14912 next_cu = per_cu->cu->read_in_chain;
14914 free_one_comp_unit (per_cu->cu);
14915 *last_chain = next_cu;
14921 /* Increase the age counter on each cached compilation unit, and free
14922 any that are too old. */
14925 age_cached_comp_units (void)
14927 struct dwarf2_per_cu_data *per_cu, **last_chain;
14929 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
14930 per_cu = dwarf2_per_objfile->read_in_chain;
14931 while (per_cu != NULL)
14933 per_cu->cu->last_used ++;
14934 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
14935 dwarf2_mark (per_cu->cu);
14936 per_cu = per_cu->cu->read_in_chain;
14939 per_cu = dwarf2_per_objfile->read_in_chain;
14940 last_chain = &dwarf2_per_objfile->read_in_chain;
14941 while (per_cu != NULL)
14943 struct dwarf2_per_cu_data *next_cu;
14945 next_cu = per_cu->cu->read_in_chain;
14947 if (!per_cu->cu->mark)
14949 free_one_comp_unit (per_cu->cu);
14950 *last_chain = next_cu;
14953 last_chain = &per_cu->cu->read_in_chain;
14959 /* Remove a single compilation unit from the cache. */
14962 free_one_cached_comp_unit (void *target_cu)
14964 struct dwarf2_per_cu_data *per_cu, **last_chain;
14966 per_cu = dwarf2_per_objfile->read_in_chain;
14967 last_chain = &dwarf2_per_objfile->read_in_chain;
14968 while (per_cu != NULL)
14970 struct dwarf2_per_cu_data *next_cu;
14972 next_cu = per_cu->cu->read_in_chain;
14974 if (per_cu->cu == target_cu)
14976 free_one_comp_unit (per_cu->cu);
14977 *last_chain = next_cu;
14981 last_chain = &per_cu->cu->read_in_chain;
14987 /* Release all extra memory associated with OBJFILE. */
14990 dwarf2_free_objfile (struct objfile *objfile)
14992 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
14994 if (dwarf2_per_objfile == NULL)
14997 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14998 free_cached_comp_units (NULL);
15000 if (dwarf2_per_objfile->quick_file_names_table)
15001 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15003 /* Everything else should be on the objfile obstack. */
15006 /* A pair of DIE offset and GDB type pointer. We store these
15007 in a hash table separate from the DIEs, and preserve them
15008 when the DIEs are flushed out of cache. */
15010 struct dwarf2_offset_and_type
15012 unsigned int offset;
15016 /* Hash function for a dwarf2_offset_and_type. */
15019 offset_and_type_hash (const void *item)
15021 const struct dwarf2_offset_and_type *ofs = item;
15023 return ofs->offset;
15026 /* Equality function for a dwarf2_offset_and_type. */
15029 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15031 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15032 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15034 return ofs_lhs->offset == ofs_rhs->offset;
15037 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15038 table if necessary. For convenience, return TYPE.
15040 The DIEs reading must have careful ordering to:
15041 * Not cause infite loops trying to read in DIEs as a prerequisite for
15042 reading current DIE.
15043 * Not trying to dereference contents of still incompletely read in types
15044 while reading in other DIEs.
15045 * Enable referencing still incompletely read in types just by a pointer to
15046 the type without accessing its fields.
15048 Therefore caller should follow these rules:
15049 * Try to fetch any prerequisite types we may need to build this DIE type
15050 before building the type and calling set_die_type.
15051 * After building type call set_die_type for current DIE as soon as
15052 possible before fetching more types to complete the current type.
15053 * Make the type as complete as possible before fetching more types. */
15055 static struct type *
15056 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15058 struct dwarf2_offset_and_type **slot, ofs;
15059 struct objfile *objfile = cu->objfile;
15060 htab_t *type_hash_ptr;
15062 /* For Ada types, make sure that the gnat-specific data is always
15063 initialized (if not already set). There are a few types where
15064 we should not be doing so, because the type-specific area is
15065 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15066 where the type-specific area is used to store the floatformat).
15067 But this is not a problem, because the gnat-specific information
15068 is actually not needed for these types. */
15069 if (need_gnat_info (cu)
15070 && TYPE_CODE (type) != TYPE_CODE_FUNC
15071 && TYPE_CODE (type) != TYPE_CODE_FLT
15072 && !HAVE_GNAT_AUX_INFO (type))
15073 INIT_GNAT_SPECIFIC (type);
15075 if (cu->per_cu->from_debug_types)
15076 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
15078 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
15080 if (*type_hash_ptr == NULL)
15083 = htab_create_alloc_ex (127,
15084 offset_and_type_hash,
15085 offset_and_type_eq,
15087 &objfile->objfile_obstack,
15088 hashtab_obstack_allocate,
15089 dummy_obstack_deallocate);
15092 ofs.offset = die->offset;
15094 slot = (struct dwarf2_offset_and_type **)
15095 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
15097 complaint (&symfile_complaints,
15098 _("A problem internal to GDB: DIE 0x%x has type already set"),
15100 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
15105 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15106 table, or return NULL if the die does not have a saved type. */
15108 static struct type *
15109 get_die_type_at_offset (unsigned int offset,
15110 struct dwarf2_per_cu_data *per_cu)
15112 struct dwarf2_offset_and_type *slot, ofs;
15115 if (per_cu->from_debug_types)
15116 type_hash = dwarf2_per_objfile->debug_types_type_hash;
15118 type_hash = dwarf2_per_objfile->debug_info_type_hash;
15119 if (type_hash == NULL)
15122 ofs.offset = offset;
15123 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
15130 /* Look up the type for DIE in the appropriate type_hash table,
15131 or return NULL if DIE does not have a saved type. */
15133 static struct type *
15134 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
15136 return get_die_type_at_offset (die->offset, cu->per_cu);
15139 /* Add a dependence relationship from CU to REF_PER_CU. */
15142 dwarf2_add_dependence (struct dwarf2_cu *cu,
15143 struct dwarf2_per_cu_data *ref_per_cu)
15147 if (cu->dependencies == NULL)
15149 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
15150 NULL, &cu->comp_unit_obstack,
15151 hashtab_obstack_allocate,
15152 dummy_obstack_deallocate);
15154 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
15156 *slot = ref_per_cu;
15159 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15160 Set the mark field in every compilation unit in the
15161 cache that we must keep because we are keeping CU. */
15164 dwarf2_mark_helper (void **slot, void *data)
15166 struct dwarf2_per_cu_data *per_cu;
15168 per_cu = (struct dwarf2_per_cu_data *) *slot;
15169 if (per_cu->cu->mark)
15171 per_cu->cu->mark = 1;
15173 if (per_cu->cu->dependencies != NULL)
15174 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
15179 /* Set the mark field in CU and in every other compilation unit in the
15180 cache that we must keep because we are keeping CU. */
15183 dwarf2_mark (struct dwarf2_cu *cu)
15188 if (cu->dependencies != NULL)
15189 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
15193 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
15197 per_cu->cu->mark = 0;
15198 per_cu = per_cu->cu->read_in_chain;
15202 /* Trivial hash function for partial_die_info: the hash value of a DIE
15203 is its offset in .debug_info for this objfile. */
15206 partial_die_hash (const void *item)
15208 const struct partial_die_info *part_die = item;
15210 return part_die->offset;
15213 /* Trivial comparison function for partial_die_info structures: two DIEs
15214 are equal if they have the same offset. */
15217 partial_die_eq (const void *item_lhs, const void *item_rhs)
15219 const struct partial_die_info *part_die_lhs = item_lhs;
15220 const struct partial_die_info *part_die_rhs = item_rhs;
15222 return part_die_lhs->offset == part_die_rhs->offset;
15225 static struct cmd_list_element *set_dwarf2_cmdlist;
15226 static struct cmd_list_element *show_dwarf2_cmdlist;
15229 set_dwarf2_cmd (char *args, int from_tty)
15231 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
15235 show_dwarf2_cmd (char *args, int from_tty)
15237 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
15240 /* If section described by INFO was mmapped, munmap it now. */
15243 munmap_section_buffer (struct dwarf2_section_info *info)
15245 if (info->was_mmapped)
15248 intptr_t begin = (intptr_t) info->buffer;
15249 intptr_t map_begin = begin & ~(pagesize - 1);
15250 size_t map_length = info->size + begin - map_begin;
15252 gdb_assert (munmap ((void *) map_begin, map_length) == 0);
15254 /* Without HAVE_MMAP, we should never be here to begin with. */
15255 gdb_assert_not_reached ("no mmap support");
15260 /* munmap debug sections for OBJFILE, if necessary. */
15263 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
15265 struct dwarf2_per_objfile *data = d;
15267 /* This is sorted according to the order they're defined in to make it easier
15268 to keep in sync. */
15269 munmap_section_buffer (&data->info);
15270 munmap_section_buffer (&data->abbrev);
15271 munmap_section_buffer (&data->line);
15272 munmap_section_buffer (&data->loc);
15273 munmap_section_buffer (&data->macinfo);
15274 munmap_section_buffer (&data->str);
15275 munmap_section_buffer (&data->ranges);
15276 munmap_section_buffer (&data->types);
15277 munmap_section_buffer (&data->frame);
15278 munmap_section_buffer (&data->eh_frame);
15279 munmap_section_buffer (&data->gdb_index);
15283 /* The "save gdb-index" command. */
15285 /* The contents of the hash table we create when building the string
15287 struct strtab_entry
15289 offset_type offset;
15293 /* Hash function for a strtab_entry.
15295 Function is used only during write_hash_table so no index format backward
15296 compatibility is needed. */
15299 hash_strtab_entry (const void *e)
15301 const struct strtab_entry *entry = e;
15302 return mapped_index_string_hash (INT_MAX, entry->str);
15305 /* Equality function for a strtab_entry. */
15308 eq_strtab_entry (const void *a, const void *b)
15310 const struct strtab_entry *ea = a;
15311 const struct strtab_entry *eb = b;
15312 return !strcmp (ea->str, eb->str);
15315 /* Create a strtab_entry hash table. */
15318 create_strtab (void)
15320 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
15321 xfree, xcalloc, xfree);
15324 /* Add a string to the constant pool. Return the string's offset in
15328 add_string (htab_t table, struct obstack *cpool, const char *str)
15331 struct strtab_entry entry;
15332 struct strtab_entry *result;
15335 slot = htab_find_slot (table, &entry, INSERT);
15340 result = XNEW (struct strtab_entry);
15341 result->offset = obstack_object_size (cpool);
15343 obstack_grow_str0 (cpool, str);
15346 return result->offset;
15349 /* An entry in the symbol table. */
15350 struct symtab_index_entry
15352 /* The name of the symbol. */
15354 /* The offset of the name in the constant pool. */
15355 offset_type index_offset;
15356 /* A sorted vector of the indices of all the CUs that hold an object
15358 VEC (offset_type) *cu_indices;
15361 /* The symbol table. This is a power-of-2-sized hash table. */
15362 struct mapped_symtab
15364 offset_type n_elements;
15366 struct symtab_index_entry **data;
15369 /* Hash function for a symtab_index_entry. */
15372 hash_symtab_entry (const void *e)
15374 const struct symtab_index_entry *entry = e;
15375 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
15376 sizeof (offset_type) * VEC_length (offset_type,
15377 entry->cu_indices),
15381 /* Equality function for a symtab_index_entry. */
15384 eq_symtab_entry (const void *a, const void *b)
15386 const struct symtab_index_entry *ea = a;
15387 const struct symtab_index_entry *eb = b;
15388 int len = VEC_length (offset_type, ea->cu_indices);
15389 if (len != VEC_length (offset_type, eb->cu_indices))
15391 return !memcmp (VEC_address (offset_type, ea->cu_indices),
15392 VEC_address (offset_type, eb->cu_indices),
15393 sizeof (offset_type) * len);
15396 /* Destroy a symtab_index_entry. */
15399 delete_symtab_entry (void *p)
15401 struct symtab_index_entry *entry = p;
15402 VEC_free (offset_type, entry->cu_indices);
15406 /* Create a hash table holding symtab_index_entry objects. */
15409 create_symbol_hash_table (void)
15411 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
15412 delete_symtab_entry, xcalloc, xfree);
15415 /* Create a new mapped symtab object. */
15417 static struct mapped_symtab *
15418 create_mapped_symtab (void)
15420 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
15421 symtab->n_elements = 0;
15422 symtab->size = 1024;
15423 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15427 /* Destroy a mapped_symtab. */
15430 cleanup_mapped_symtab (void *p)
15432 struct mapped_symtab *symtab = p;
15433 /* The contents of the array are freed when the other hash table is
15435 xfree (symtab->data);
15439 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15442 Function is used only during write_hash_table so no index format backward
15443 compatibility is needed. */
15445 static struct symtab_index_entry **
15446 find_slot (struct mapped_symtab *symtab, const char *name)
15448 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
15450 index = hash & (symtab->size - 1);
15451 step = ((hash * 17) & (symtab->size - 1)) | 1;
15455 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
15456 return &symtab->data[index];
15457 index = (index + step) & (symtab->size - 1);
15461 /* Expand SYMTAB's hash table. */
15464 hash_expand (struct mapped_symtab *symtab)
15466 offset_type old_size = symtab->size;
15468 struct symtab_index_entry **old_entries = symtab->data;
15471 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
15473 for (i = 0; i < old_size; ++i)
15475 if (old_entries[i])
15477 struct symtab_index_entry **slot = find_slot (symtab,
15478 old_entries[i]->name);
15479 *slot = old_entries[i];
15483 xfree (old_entries);
15486 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15487 is the index of the CU in which the symbol appears. */
15490 add_index_entry (struct mapped_symtab *symtab, const char *name,
15491 offset_type cu_index)
15493 struct symtab_index_entry **slot;
15495 ++symtab->n_elements;
15496 if (4 * symtab->n_elements / 3 >= symtab->size)
15497 hash_expand (symtab);
15499 slot = find_slot (symtab, name);
15502 *slot = XNEW (struct symtab_index_entry);
15503 (*slot)->name = name;
15504 (*slot)->cu_indices = NULL;
15506 /* Don't push an index twice. Due to how we add entries we only
15507 have to check the last one. */
15508 if (VEC_empty (offset_type, (*slot)->cu_indices)
15509 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
15510 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
15513 /* Add a vector of indices to the constant pool. */
15516 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
15517 struct symtab_index_entry *entry)
15521 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
15524 offset_type len = VEC_length (offset_type, entry->cu_indices);
15525 offset_type val = MAYBE_SWAP (len);
15530 entry->index_offset = obstack_object_size (cpool);
15532 obstack_grow (cpool, &val, sizeof (val));
15534 VEC_iterate (offset_type, entry->cu_indices, i, iter);
15537 val = MAYBE_SWAP (iter);
15538 obstack_grow (cpool, &val, sizeof (val));
15543 struct symtab_index_entry *old_entry = *slot;
15544 entry->index_offset = old_entry->index_offset;
15547 return entry->index_offset;
15550 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15551 constant pool entries going into the obstack CPOOL. */
15554 write_hash_table (struct mapped_symtab *symtab,
15555 struct obstack *output, struct obstack *cpool)
15558 htab_t symbol_hash_table;
15561 symbol_hash_table = create_symbol_hash_table ();
15562 str_table = create_strtab ();
15564 /* We add all the index vectors to the constant pool first, to
15565 ensure alignment is ok. */
15566 for (i = 0; i < symtab->size; ++i)
15568 if (symtab->data[i])
15569 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
15572 /* Now write out the hash table. */
15573 for (i = 0; i < symtab->size; ++i)
15575 offset_type str_off, vec_off;
15577 if (symtab->data[i])
15579 str_off = add_string (str_table, cpool, symtab->data[i]->name);
15580 vec_off = symtab->data[i]->index_offset;
15584 /* While 0 is a valid constant pool index, it is not valid
15585 to have 0 for both offsets. */
15590 str_off = MAYBE_SWAP (str_off);
15591 vec_off = MAYBE_SWAP (vec_off);
15593 obstack_grow (output, &str_off, sizeof (str_off));
15594 obstack_grow (output, &vec_off, sizeof (vec_off));
15597 htab_delete (str_table);
15598 htab_delete (symbol_hash_table);
15601 /* Struct to map psymtab to CU index in the index file. */
15602 struct psymtab_cu_index_map
15604 struct partial_symtab *psymtab;
15605 unsigned int cu_index;
15609 hash_psymtab_cu_index (const void *item)
15611 const struct psymtab_cu_index_map *map = item;
15613 return htab_hash_pointer (map->psymtab);
15617 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
15619 const struct psymtab_cu_index_map *lhs = item_lhs;
15620 const struct psymtab_cu_index_map *rhs = item_rhs;
15622 return lhs->psymtab == rhs->psymtab;
15625 /* Helper struct for building the address table. */
15626 struct addrmap_index_data
15628 struct objfile *objfile;
15629 struct obstack *addr_obstack;
15630 htab_t cu_index_htab;
15632 /* Non-zero if the previous_* fields are valid.
15633 We can't write an entry until we see the next entry (since it is only then
15634 that we know the end of the entry). */
15635 int previous_valid;
15636 /* Index of the CU in the table of all CUs in the index file. */
15637 unsigned int previous_cu_index;
15638 /* Start address of the CU. */
15639 CORE_ADDR previous_cu_start;
15642 /* Write an address entry to OBSTACK. */
15645 add_address_entry (struct objfile *objfile, struct obstack *obstack,
15646 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
15648 offset_type cu_index_to_write;
15650 CORE_ADDR baseaddr;
15652 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15654 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
15655 obstack_grow (obstack, addr, 8);
15656 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
15657 obstack_grow (obstack, addr, 8);
15658 cu_index_to_write = MAYBE_SWAP (cu_index);
15659 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
15662 /* Worker function for traversing an addrmap to build the address table. */
15665 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
15667 struct addrmap_index_data *data = datap;
15668 struct partial_symtab *pst = obj;
15669 offset_type cu_index;
15672 if (data->previous_valid)
15673 add_address_entry (data->objfile, data->addr_obstack,
15674 data->previous_cu_start, start_addr,
15675 data->previous_cu_index);
15677 data->previous_cu_start = start_addr;
15680 struct psymtab_cu_index_map find_map, *map;
15681 find_map.psymtab = pst;
15682 map = htab_find (data->cu_index_htab, &find_map);
15683 gdb_assert (map != NULL);
15684 data->previous_cu_index = map->cu_index;
15685 data->previous_valid = 1;
15688 data->previous_valid = 0;
15693 /* Write OBJFILE's address map to OBSTACK.
15694 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15695 in the index file. */
15698 write_address_map (struct objfile *objfile, struct obstack *obstack,
15699 htab_t cu_index_htab)
15701 struct addrmap_index_data addrmap_index_data;
15703 /* When writing the address table, we have to cope with the fact that
15704 the addrmap iterator only provides the start of a region; we have to
15705 wait until the next invocation to get the start of the next region. */
15707 addrmap_index_data.objfile = objfile;
15708 addrmap_index_data.addr_obstack = obstack;
15709 addrmap_index_data.cu_index_htab = cu_index_htab;
15710 addrmap_index_data.previous_valid = 0;
15712 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
15713 &addrmap_index_data);
15715 /* It's highly unlikely the last entry (end address = 0xff...ff)
15716 is valid, but we should still handle it.
15717 The end address is recorded as the start of the next region, but that
15718 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15720 if (addrmap_index_data.previous_valid)
15721 add_address_entry (objfile, obstack,
15722 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
15723 addrmap_index_data.previous_cu_index);
15726 /* Add a list of partial symbols to SYMTAB. */
15729 write_psymbols (struct mapped_symtab *symtab,
15731 struct partial_symbol **psymp,
15733 offset_type cu_index,
15736 for (; count-- > 0; ++psymp)
15738 void **slot, *lookup;
15740 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
15741 error (_("Ada is not currently supported by the index"));
15743 /* We only want to add a given psymbol once. However, we also
15744 want to account for whether it is global or static. So, we
15745 may add it twice, using slightly different values. */
15748 uintptr_t val = 1 | (uintptr_t) *psymp;
15750 lookup = (void *) val;
15755 /* Only add a given psymbol once. */
15756 slot = htab_find_slot (psyms_seen, lookup, INSERT);
15760 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
15765 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15766 exception if there is an error. */
15769 write_obstack (FILE *file, struct obstack *obstack)
15771 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
15773 != obstack_object_size (obstack))
15774 error (_("couldn't data write to file"));
15777 /* Unlink a file if the argument is not NULL. */
15780 unlink_if_set (void *p)
15782 char **filename = p;
15784 unlink (*filename);
15787 /* A helper struct used when iterating over debug_types. */
15788 struct signatured_type_index_data
15790 struct objfile *objfile;
15791 struct mapped_symtab *symtab;
15792 struct obstack *types_list;
15797 /* A helper function that writes a single signatured_type to an
15801 write_one_signatured_type (void **slot, void *d)
15803 struct signatured_type_index_data *info = d;
15804 struct signatured_type *entry = (struct signatured_type *) *slot;
15805 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
15806 struct partial_symtab *psymtab = per_cu->v.psymtab;
15809 write_psymbols (info->symtab,
15811 info->objfile->global_psymbols.list
15812 + psymtab->globals_offset,
15813 psymtab->n_global_syms, info->cu_index,
15815 write_psymbols (info->symtab,
15817 info->objfile->static_psymbols.list
15818 + psymtab->statics_offset,
15819 psymtab->n_static_syms, info->cu_index,
15822 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset);
15823 obstack_grow (info->types_list, val, 8);
15824 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
15825 obstack_grow (info->types_list, val, 8);
15826 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
15827 obstack_grow (info->types_list, val, 8);
15834 /* A cleanup function for an htab_t. */
15837 cleanup_htab (void *arg)
15842 /* Create an index file for OBJFILE in the directory DIR. */
15845 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
15847 struct cleanup *cleanup;
15848 char *filename, *cleanup_filename;
15849 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
15850 struct obstack cu_list, types_cu_list;
15853 struct mapped_symtab *symtab;
15854 offset_type val, size_of_contents, total_len;
15858 htab_t cu_index_htab;
15859 struct psymtab_cu_index_map *psymtab_cu_index_map;
15861 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
15864 if (dwarf2_per_objfile->using_index)
15865 error (_("Cannot use an index to create the index"));
15867 if (stat (objfile->name, &st) < 0)
15868 perror_with_name (objfile->name);
15870 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
15871 INDEX_SUFFIX, (char *) NULL);
15872 cleanup = make_cleanup (xfree, filename);
15874 out_file = fopen (filename, "wb");
15876 error (_("Can't open `%s' for writing"), filename);
15878 cleanup_filename = filename;
15879 make_cleanup (unlink_if_set, &cleanup_filename);
15881 symtab = create_mapped_symtab ();
15882 make_cleanup (cleanup_mapped_symtab, symtab);
15884 obstack_init (&addr_obstack);
15885 make_cleanup_obstack_free (&addr_obstack);
15887 obstack_init (&cu_list);
15888 make_cleanup_obstack_free (&cu_list);
15890 obstack_init (&types_cu_list);
15891 make_cleanup_obstack_free (&types_cu_list);
15893 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
15894 NULL, xcalloc, xfree);
15895 make_cleanup (cleanup_htab, psyms_seen);
15897 /* While we're scanning CU's create a table that maps a psymtab pointer
15898 (which is what addrmap records) to its index (which is what is recorded
15899 in the index file). This will later be needed to write the address
15901 cu_index_htab = htab_create_alloc (100,
15902 hash_psymtab_cu_index,
15903 eq_psymtab_cu_index,
15904 NULL, xcalloc, xfree);
15905 make_cleanup (cleanup_htab, cu_index_htab);
15906 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
15907 xmalloc (sizeof (struct psymtab_cu_index_map)
15908 * dwarf2_per_objfile->n_comp_units);
15909 make_cleanup (xfree, psymtab_cu_index_map);
15911 /* The CU list is already sorted, so we don't need to do additional
15912 work here. Also, the debug_types entries do not appear in
15913 all_comp_units, but only in their own hash table. */
15914 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
15916 struct dwarf2_per_cu_data *per_cu
15917 = dwarf2_per_objfile->all_comp_units[i];
15918 struct partial_symtab *psymtab = per_cu->v.psymtab;
15920 struct psymtab_cu_index_map *map;
15923 write_psymbols (symtab,
15925 objfile->global_psymbols.list + psymtab->globals_offset,
15926 psymtab->n_global_syms, i,
15928 write_psymbols (symtab,
15930 objfile->static_psymbols.list + psymtab->statics_offset,
15931 psymtab->n_static_syms, i,
15934 map = &psymtab_cu_index_map[i];
15935 map->psymtab = psymtab;
15937 slot = htab_find_slot (cu_index_htab, map, INSERT);
15938 gdb_assert (slot != NULL);
15939 gdb_assert (*slot == NULL);
15942 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
15943 obstack_grow (&cu_list, val, 8);
15944 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
15945 obstack_grow (&cu_list, val, 8);
15948 /* Dump the address map. */
15949 write_address_map (objfile, &addr_obstack, cu_index_htab);
15951 /* Write out the .debug_type entries, if any. */
15952 if (dwarf2_per_objfile->signatured_types)
15954 struct signatured_type_index_data sig_data;
15956 sig_data.objfile = objfile;
15957 sig_data.symtab = symtab;
15958 sig_data.types_list = &types_cu_list;
15959 sig_data.psyms_seen = psyms_seen;
15960 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
15961 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
15962 write_one_signatured_type, &sig_data);
15965 obstack_init (&constant_pool);
15966 make_cleanup_obstack_free (&constant_pool);
15967 obstack_init (&symtab_obstack);
15968 make_cleanup_obstack_free (&symtab_obstack);
15969 write_hash_table (symtab, &symtab_obstack, &constant_pool);
15971 obstack_init (&contents);
15972 make_cleanup_obstack_free (&contents);
15973 size_of_contents = 6 * sizeof (offset_type);
15974 total_len = size_of_contents;
15976 /* The version number. */
15977 val = MAYBE_SWAP (5);
15978 obstack_grow (&contents, &val, sizeof (val));
15980 /* The offset of the CU list from the start of the file. */
15981 val = MAYBE_SWAP (total_len);
15982 obstack_grow (&contents, &val, sizeof (val));
15983 total_len += obstack_object_size (&cu_list);
15985 /* The offset of the types CU list from the start of the file. */
15986 val = MAYBE_SWAP (total_len);
15987 obstack_grow (&contents, &val, sizeof (val));
15988 total_len += obstack_object_size (&types_cu_list);
15990 /* The offset of the address table from the start of the file. */
15991 val = MAYBE_SWAP (total_len);
15992 obstack_grow (&contents, &val, sizeof (val));
15993 total_len += obstack_object_size (&addr_obstack);
15995 /* The offset of the symbol table from the start of the file. */
15996 val = MAYBE_SWAP (total_len);
15997 obstack_grow (&contents, &val, sizeof (val));
15998 total_len += obstack_object_size (&symtab_obstack);
16000 /* The offset of the constant pool from the start of the file. */
16001 val = MAYBE_SWAP (total_len);
16002 obstack_grow (&contents, &val, sizeof (val));
16003 total_len += obstack_object_size (&constant_pool);
16005 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16007 write_obstack (out_file, &contents);
16008 write_obstack (out_file, &cu_list);
16009 write_obstack (out_file, &types_cu_list);
16010 write_obstack (out_file, &addr_obstack);
16011 write_obstack (out_file, &symtab_obstack);
16012 write_obstack (out_file, &constant_pool);
16016 /* We want to keep the file, so we set cleanup_filename to NULL
16017 here. See unlink_if_set. */
16018 cleanup_filename = NULL;
16020 do_cleanups (cleanup);
16023 /* Implementation of the `save gdb-index' command.
16025 Note that the file format used by this command is documented in the
16026 GDB manual. Any changes here must be documented there. */
16029 save_gdb_index_command (char *arg, int from_tty)
16031 struct objfile *objfile;
16034 error (_("usage: save gdb-index DIRECTORY"));
16036 ALL_OBJFILES (objfile)
16040 /* If the objfile does not correspond to an actual file, skip it. */
16041 if (stat (objfile->name, &st) < 0)
16044 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16045 if (dwarf2_per_objfile)
16047 volatile struct gdb_exception except;
16049 TRY_CATCH (except, RETURN_MASK_ERROR)
16051 write_psymtabs_to_index (objfile, arg);
16053 if (except.reason < 0)
16054 exception_fprintf (gdb_stderr, except,
16055 _("Error while writing index for `%s': "),
16063 int dwarf2_always_disassemble;
16066 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
16067 struct cmd_list_element *c, const char *value)
16069 fprintf_filtered (file,
16070 _("Whether to always disassemble "
16071 "DWARF expressions is %s.\n"),
16075 void _initialize_dwarf2_read (void);
16078 _initialize_dwarf2_read (void)
16080 struct cmd_list_element *c;
16082 dwarf2_objfile_data_key
16083 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
16085 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
16086 Set DWARF 2 specific variables.\n\
16087 Configure DWARF 2 variables such as the cache size"),
16088 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
16089 0/*allow-unknown*/, &maintenance_set_cmdlist);
16091 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
16092 Show DWARF 2 specific variables\n\
16093 Show DWARF 2 variables such as the cache size"),
16094 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
16095 0/*allow-unknown*/, &maintenance_show_cmdlist);
16097 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
16098 &dwarf2_max_cache_age, _("\
16099 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16100 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16101 A higher limit means that cached compilation units will be stored\n\
16102 in memory longer, and more total memory will be used. Zero disables\n\
16103 caching, which can slow down startup."),
16105 show_dwarf2_max_cache_age,
16106 &set_dwarf2_cmdlist,
16107 &show_dwarf2_cmdlist);
16109 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
16110 &dwarf2_always_disassemble, _("\
16111 Set whether `info address' always disassembles DWARF expressions."), _("\
16112 Show whether `info address' always disassembles DWARF expressions."), _("\
16113 When enabled, DWARF expressions are always printed in an assembly-like\n\
16114 syntax. When disabled, expressions will be printed in a more\n\
16115 conversational style, when possible."),
16117 show_dwarf2_always_disassemble,
16118 &set_dwarf2_cmdlist,
16119 &show_dwarf2_cmdlist);
16121 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
16122 Set debugging of the dwarf2 DIE reader."), _("\
16123 Show debugging of the dwarf2 DIE reader."), _("\
16124 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16125 The value is the maximum depth to print."),
16128 &setdebuglist, &showdebuglist);
16130 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
16132 Save a gdb-index file.\n\
16133 Usage: save gdb-index DIRECTORY"),
16135 set_cmd_completer (c, filename_completer);