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 "gdb-demangle.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
52 #include "typeprint.h"
55 #include "exceptions.h"
57 #include "completer.h"
64 #include "gdb_string.h"
65 #include "gdb_assert.h"
66 #include <sys/types.h>
73 #define MAP_FAILED ((void *) -1)
77 typedef struct symbol
*symbolp
;
81 /* .debug_info header for a compilation unit
82 Because of alignment constraints, this structure has padding and cannot
83 be mapped directly onto the beginning of the .debug_info section. */
84 typedef struct comp_unit_header
86 unsigned int length
; /* length of the .debug_info
88 unsigned short version
; /* version number -- 2 for DWARF
90 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
91 unsigned char addr_size
; /* byte size of an address -- 4 */
94 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
97 /* .debug_line statement program prologue
98 Because of alignment constraints, this structure has padding and cannot
99 be mapped directly onto the beginning of the .debug_info section. */
100 typedef struct statement_prologue
102 unsigned int total_length
; /* byte length of the statement
104 unsigned short version
; /* version number -- 2 for DWARF
106 unsigned int prologue_length
; /* # bytes between prologue &
108 unsigned char minimum_instruction_length
; /* byte size of
110 unsigned char default_is_stmt
; /* initial value of is_stmt
113 unsigned char line_range
;
114 unsigned char opcode_base
; /* number assigned to first special
116 unsigned char *standard_opcode_lengths
;
120 /* When non-zero, dump DIEs after they are read in. */
121 static int dwarf2_die_debug
= 0;
123 /* When non-zero, cross-check physname against demangler. */
124 static int check_physname
= 0;
128 /* When set, the file that we're processing is known to have debugging
129 info for C++ namespaces. GCC 3.3.x did not produce this information,
130 but later versions do. */
132 static int processing_has_namespace_info
;
134 static const struct objfile_data
*dwarf2_objfile_data_key
;
136 struct dwarf2_section_info
141 /* Not NULL if the section was actually mmapped. */
143 /* Page aligned size of mmapped area. */
144 bfd_size_type map_len
;
145 /* True if we have tried to read this section. */
149 typedef struct dwarf2_section_info dwarf2_section_info_def
;
150 DEF_VEC_O (dwarf2_section_info_def
);
152 /* All offsets in the index are of this type. It must be
153 architecture-independent. */
154 typedef uint32_t offset_type
;
156 DEF_VEC_I (offset_type
);
158 /* A description of the mapped index. The file format is described in
159 a comment by the code that writes the index. */
162 /* Index data format version. */
165 /* The total length of the buffer. */
168 /* A pointer to the address table data. */
169 const gdb_byte
*address_table
;
171 /* Size of the address table data in bytes. */
172 offset_type address_table_size
;
174 /* The symbol table, implemented as a hash table. */
175 const offset_type
*symbol_table
;
177 /* Size in slots, each slot is 2 offset_types. */
178 offset_type symbol_table_slots
;
180 /* A pointer to the constant pool. */
181 const char *constant_pool
;
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info frame
;
195 struct dwarf2_section_info eh_frame
;
196 struct dwarf2_section_info gdb_index
;
198 VEC (dwarf2_section_info_def
) *types
;
201 struct objfile
*objfile
;
203 /* A list of all the compilation units. This is used to locate
204 the target compilation unit of a particular reference. */
205 struct dwarf2_per_cu_data
**all_comp_units
;
207 /* The number of compilation units in ALL_COMP_UNITS. */
210 /* The number of .debug_types-related CUs. */
211 int n_type_comp_units
;
213 /* The .debug_types-related CUs. */
214 struct dwarf2_per_cu_data
**type_comp_units
;
216 /* A chain of compilation units that are currently read in, so that
217 they can be freed later. */
218 struct dwarf2_per_cu_data
*read_in_chain
;
220 /* A table mapping .debug_types signatures to its signatured_type entry.
221 This is NULL if the .debug_types section hasn't been read in yet. */
222 htab_t signatured_types
;
224 /* A flag indicating wether this objfile has a section loaded at a
226 int has_section_at_zero
;
228 /* True if we are using the mapped index,
229 or we are faking it for OBJF_READNOW's sake. */
230 unsigned char using_index
;
232 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
233 struct mapped_index
*index_table
;
235 /* When using index_table, this keeps track of all quick_file_names entries.
236 TUs can share line table entries with CUs or other TUs, and there can be
237 a lot more TUs than unique line tables, so we maintain a separate table
238 of all line table entries to support the sharing. */
239 htab_t quick_file_names_table
;
241 /* Set during partial symbol reading, to prevent queueing of full
243 int reading_partial_symbols
;
245 /* Table mapping type .debug_info DIE offsets to types.
246 This is NULL if not allocated yet.
247 It (currently) makes sense to allocate debug_types_type_hash lazily.
248 To keep things simple we allocate both lazily. */
249 htab_t debug_info_type_hash
;
251 /* Table mapping type .debug_types DIE offsets to types.
252 This is NULL if not allocated yet. */
253 htab_t debug_types_type_hash
;
256 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
258 /* Default names of the debugging sections. */
260 /* Note that if the debugging section has been compressed, it might
261 have a name like .zdebug_info. */
263 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
264 { ".debug_info", ".zdebug_info" },
265 { ".debug_abbrev", ".zdebug_abbrev" },
266 { ".debug_line", ".zdebug_line" },
267 { ".debug_loc", ".zdebug_loc" },
268 { ".debug_macinfo", ".zdebug_macinfo" },
269 { ".debug_macro", ".zdebug_macro" },
270 { ".debug_str", ".zdebug_str" },
271 { ".debug_ranges", ".zdebug_ranges" },
272 { ".debug_types", ".zdebug_types" },
273 { ".debug_frame", ".zdebug_frame" },
274 { ".eh_frame", NULL
},
275 { ".gdb_index", ".zgdb_index" },
279 /* local data types */
281 /* We hold several abbreviation tables in memory at the same time. */
282 #ifndef ABBREV_HASH_SIZE
283 #define ABBREV_HASH_SIZE 121
286 /* The data in a compilation unit header, after target2host
287 translation, looks like this. */
288 struct comp_unit_head
292 unsigned char addr_size
;
293 unsigned char signed_addr_p
;
294 unsigned int abbrev_offset
;
296 /* Size of file offsets; either 4 or 8. */
297 unsigned int offset_size
;
299 /* Size of the length field; either 4 or 12. */
300 unsigned int initial_length_size
;
302 /* Offset to the first byte of this compilation unit header in the
303 .debug_info section, for resolving relative reference dies. */
306 /* Offset to first die in this cu from the start of the cu.
307 This will be the first byte following the compilation unit header. */
308 unsigned int first_die_offset
;
311 /* Type used for delaying computation of method physnames.
312 See comments for compute_delayed_physnames. */
313 struct delayed_method_info
315 /* The type to which the method is attached, i.e., its parent class. */
318 /* The index of the method in the type's function fieldlists. */
321 /* The index of the method in the fieldlist. */
324 /* The name of the DIE. */
327 /* The DIE associated with this method. */
328 struct die_info
*die
;
331 typedef struct delayed_method_info delayed_method_info
;
332 DEF_VEC_O (delayed_method_info
);
334 /* Internal state when decoding a particular compilation unit. */
337 /* The objfile containing this compilation unit. */
338 struct objfile
*objfile
;
340 /* The header of the compilation unit. */
341 struct comp_unit_head header
;
343 /* Base address of this compilation unit. */
344 CORE_ADDR base_address
;
346 /* Non-zero if base_address has been set. */
349 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
351 /* The language we are debugging. */
352 enum language language
;
353 const struct language_defn
*language_defn
;
355 const char *producer
;
357 /* The generic symbol table building routines have separate lists for
358 file scope symbols and all all other scopes (local scopes). So
359 we need to select the right one to pass to add_symbol_to_list().
360 We do it by keeping a pointer to the correct list in list_in_scope.
362 FIXME: The original dwarf code just treated the file scope as the
363 first local scope, and all other local scopes as nested local
364 scopes, and worked fine. Check to see if we really need to
365 distinguish these in buildsym.c. */
366 struct pending
**list_in_scope
;
368 /* DWARF abbreviation table associated with this compilation unit. */
369 struct abbrev_info
**dwarf2_abbrevs
;
371 /* Storage for the abbrev table. */
372 struct obstack abbrev_obstack
;
374 /* Hash table holding all the loaded partial DIEs. */
377 /* Storage for things with the same lifetime as this read-in compilation
378 unit, including partial DIEs. */
379 struct obstack comp_unit_obstack
;
381 /* When multiple dwarf2_cu structures are living in memory, this field
382 chains them all together, so that they can be released efficiently.
383 We will probably also want a generation counter so that most-recently-used
384 compilation units are cached... */
385 struct dwarf2_per_cu_data
*read_in_chain
;
387 /* Backchain to our per_cu entry if the tree has been built. */
388 struct dwarf2_per_cu_data
*per_cu
;
390 /* How many compilation units ago was this CU last referenced? */
393 /* A hash table of die offsets for following references. */
396 /* Full DIEs if read in. */
397 struct die_info
*dies
;
399 /* A set of pointers to dwarf2_per_cu_data objects for compilation
400 units referenced by this one. Only set during full symbol processing;
401 partial symbol tables do not have dependencies. */
404 /* Header data from the line table, during full symbol processing. */
405 struct line_header
*line_header
;
407 /* A list of methods which need to have physnames computed
408 after all type information has been read. */
409 VEC (delayed_method_info
) *method_list
;
411 /* To be copied to symtab->call_site_htab. */
412 htab_t call_site_htab
;
414 /* Mark used when releasing cached dies. */
415 unsigned int mark
: 1;
417 /* This flag will be set if this compilation unit might include
418 inter-compilation-unit references. */
419 unsigned int has_form_ref_addr
: 1;
421 /* This flag will be set if this compilation unit includes any
422 DW_TAG_namespace DIEs. If we know that there are explicit
423 DIEs for namespaces, we don't need to try to infer them
424 from mangled names. */
425 unsigned int has_namespace_info
: 1;
427 /* This CU references .debug_loc. See the symtab->locations_valid field.
428 This test is imperfect as there may exist optimized debug code not using
429 any location list and still facing inlining issues if handled as
430 unoptimized code. For a future better test see GCC PR other/32998. */
432 unsigned int has_loclist
: 1;
435 /* Persistent data held for a compilation unit, even when not
436 processing it. We put a pointer to this structure in the
437 read_symtab_private field of the psymtab. If we encounter
438 inter-compilation-unit references, we also maintain a sorted
439 list of all compilation units. */
441 struct dwarf2_per_cu_data
443 /* The start offset and length of this compilation unit. 2**29-1
444 bytes should suffice to store the length of any compilation unit
445 - if it doesn't, GDB will fall over anyway.
446 NOTE: Unlike comp_unit_head.length, this length includes
447 initial_length_size. */
449 unsigned int length
: 29;
451 /* Flag indicating this compilation unit will be read in before
452 any of the current compilation units are processed. */
453 unsigned int queued
: 1;
455 /* This flag will be set if we need to load absolutely all DIEs
456 for this compilation unit, instead of just the ones we think
457 are interesting. It gets set if we look for a DIE in the
458 hash table and don't find it. */
459 unsigned int load_all_dies
: 1;
461 /* Non-null if this CU is from .debug_types; in which case it points
462 to the section. Otherwise it's from .debug_info. */
463 struct dwarf2_section_info
*debug_type_section
;
465 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
466 of the CU cache it gets reset to NULL again. */
467 struct dwarf2_cu
*cu
;
469 /* The corresponding objfile. */
470 struct objfile
*objfile
;
472 /* When using partial symbol tables, the 'psymtab' field is active.
473 Otherwise the 'quick' field is active. */
476 /* The partial symbol table associated with this compilation unit,
477 or NULL for partial units (which do not have an associated
479 struct partial_symtab
*psymtab
;
481 /* Data needed by the "quick" functions. */
482 struct dwarf2_per_cu_quick_data
*quick
;
486 /* Entry in the signatured_types hash table. */
488 struct signatured_type
492 /* Offset in .debug_types of the type defined by this TU. */
493 unsigned int type_offset
;
495 /* The CU(/TU) of this type. */
496 struct dwarf2_per_cu_data per_cu
;
499 /* Struct used to pass misc. parameters to read_die_and_children, et
500 al. which are used for both .debug_info and .debug_types dies.
501 All parameters here are unchanging for the life of the call. This
502 struct exists to abstract away the constant parameters of die
505 struct die_reader_specs
507 /* The bfd of this objfile. */
510 /* The CU of the DIE we are parsing. */
511 struct dwarf2_cu
*cu
;
513 /* Pointer to start of section buffer.
514 This is either the start of .debug_info or .debug_types. */
515 const gdb_byte
*buffer
;
518 /* The line number information for a compilation unit (found in the
519 .debug_line section) begins with a "statement program header",
520 which contains the following information. */
523 unsigned int total_length
;
524 unsigned short version
;
525 unsigned int header_length
;
526 unsigned char minimum_instruction_length
;
527 unsigned char maximum_ops_per_instruction
;
528 unsigned char default_is_stmt
;
530 unsigned char line_range
;
531 unsigned char opcode_base
;
533 /* standard_opcode_lengths[i] is the number of operands for the
534 standard opcode whose value is i. This means that
535 standard_opcode_lengths[0] is unused, and the last meaningful
536 element is standard_opcode_lengths[opcode_base - 1]. */
537 unsigned char *standard_opcode_lengths
;
539 /* The include_directories table. NOTE! These strings are not
540 allocated with xmalloc; instead, they are pointers into
541 debug_line_buffer. If you try to free them, `free' will get
543 unsigned int num_include_dirs
, include_dirs_size
;
546 /* The file_names table. NOTE! These strings are not allocated
547 with xmalloc; instead, they are pointers into debug_line_buffer.
548 Don't try to free them directly. */
549 unsigned int num_file_names
, file_names_size
;
553 unsigned int dir_index
;
554 unsigned int mod_time
;
556 int included_p
; /* Non-zero if referenced by the Line Number Program. */
557 struct symtab
*symtab
; /* The associated symbol table, if any. */
560 /* The start and end of the statement program following this
561 header. These point into dwarf2_per_objfile->line_buffer. */
562 gdb_byte
*statement_program_start
, *statement_program_end
;
565 /* When we construct a partial symbol table entry we only
566 need this much information. */
567 struct partial_die_info
569 /* Offset of this DIE. */
572 /* DWARF-2 tag for this DIE. */
573 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
575 /* Assorted flags describing the data found in this DIE. */
576 unsigned int has_children
: 1;
577 unsigned int is_external
: 1;
578 unsigned int is_declaration
: 1;
579 unsigned int has_type
: 1;
580 unsigned int has_specification
: 1;
581 unsigned int has_pc_info
: 1;
583 /* Flag set if the SCOPE field of this structure has been
585 unsigned int scope_set
: 1;
587 /* Flag set if the DIE has a byte_size attribute. */
588 unsigned int has_byte_size
: 1;
590 /* Flag set if any of the DIE's children are template arguments. */
591 unsigned int has_template_arguments
: 1;
593 /* Flag set if fixup_partial_die has been called on this die. */
594 unsigned int fixup_called
: 1;
596 /* The name of this DIE. Normally the value of DW_AT_name, but
597 sometimes a default name for unnamed DIEs. */
600 /* The linkage name, if present. */
601 const char *linkage_name
;
603 /* The scope to prepend to our children. This is generally
604 allocated on the comp_unit_obstack, so will disappear
605 when this compilation unit leaves the cache. */
608 /* The location description associated with this DIE, if any. */
609 struct dwarf_block
*locdesc
;
611 /* If HAS_PC_INFO, the PC range associated with this DIE. */
615 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
616 DW_AT_sibling, if any. */
617 /* NOTE: This member isn't strictly necessary, read_partial_die could
618 return DW_AT_sibling values to its caller load_partial_dies. */
621 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
622 DW_AT_specification (or DW_AT_abstract_origin or
624 unsigned int spec_offset
;
626 /* Pointers to this DIE's parent, first child, and next sibling,
628 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
631 /* This data structure holds the information of an abbrev. */
634 unsigned int number
; /* number identifying abbrev */
635 enum dwarf_tag tag
; /* dwarf tag */
636 unsigned short has_children
; /* boolean */
637 unsigned short num_attrs
; /* number of attributes */
638 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
639 struct abbrev_info
*next
; /* next in chain */
644 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
645 ENUM_BITFIELD(dwarf_form
) form
: 16;
648 /* Attributes have a name and a value. */
651 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
652 ENUM_BITFIELD(dwarf_form
) form
: 15;
654 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
655 field should be in u.str (existing only for DW_STRING) but it is kept
656 here for better struct attribute alignment. */
657 unsigned int string_is_canonical
: 1;
662 struct dwarf_block
*blk
;
666 struct signatured_type
*signatured_type
;
671 /* This data structure holds a complete die structure. */
674 /* DWARF-2 tag for this DIE. */
675 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
677 /* Number of attributes */
678 unsigned char num_attrs
;
680 /* True if we're presently building the full type name for the
681 type derived from this DIE. */
682 unsigned char building_fullname
: 1;
687 /* Offset in .debug_info or .debug_types section. */
690 /* The dies in a compilation unit form an n-ary tree. PARENT
691 points to this die's parent; CHILD points to the first child of
692 this node; and all the children of a given node are chained
693 together via their SIBLING fields. */
694 struct die_info
*child
; /* Its first child, if any. */
695 struct die_info
*sibling
; /* Its next sibling, if any. */
696 struct die_info
*parent
; /* Its parent, if any. */
698 /* An array of attributes, with NUM_ATTRS elements. There may be
699 zero, but it's not common and zero-sized arrays are not
700 sufficiently portable C. */
701 struct attribute attrs
[1];
704 struct function_range
707 CORE_ADDR lowpc
, highpc
;
709 struct function_range
*next
;
712 /* Get at parts of an attribute structure. */
714 #define DW_STRING(attr) ((attr)->u.str)
715 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
716 #define DW_UNSND(attr) ((attr)->u.unsnd)
717 #define DW_BLOCK(attr) ((attr)->u.blk)
718 #define DW_SND(attr) ((attr)->u.snd)
719 #define DW_ADDR(attr) ((attr)->u.addr)
720 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
722 /* Blocks are a bunch of untyped bytes. */
727 /* Valid only if SIZE is not zero. */
731 #ifndef ATTR_ALLOC_CHUNK
732 #define ATTR_ALLOC_CHUNK 4
735 /* Allocate fields for structs, unions and enums in this size. */
736 #ifndef DW_FIELD_ALLOC_CHUNK
737 #define DW_FIELD_ALLOC_CHUNK 4
740 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
741 but this would require a corresponding change in unpack_field_as_long
743 static int bits_per_byte
= 8;
745 /* The routines that read and process dies for a C struct or C++ class
746 pass lists of data member fields and lists of member function fields
747 in an instance of a field_info structure, as defined below. */
750 /* List of data member and baseclasses fields. */
753 struct nextfield
*next
;
758 *fields
, *baseclasses
;
760 /* Number of fields (including baseclasses). */
763 /* Number of baseclasses. */
766 /* Set if the accesibility of one of the fields is not public. */
767 int non_public_fields
;
769 /* Member function fields array, entries are allocated in the order they
770 are encountered in the object file. */
773 struct nextfnfield
*next
;
774 struct fn_field fnfield
;
778 /* Member function fieldlist array, contains name of possibly overloaded
779 member function, number of overloaded member functions and a pointer
780 to the head of the member function field chain. */
785 struct nextfnfield
*head
;
789 /* Number of entries in the fnfieldlists array. */
792 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
793 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
794 struct typedef_field_list
796 struct typedef_field field
;
797 struct typedef_field_list
*next
;
800 unsigned typedef_field_list_count
;
803 /* One item on the queue of compilation units to read in full symbols
805 struct dwarf2_queue_item
807 struct dwarf2_per_cu_data
*per_cu
;
808 struct dwarf2_queue_item
*next
;
811 /* The current queue. */
812 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
814 /* Loaded secondary compilation units are kept in memory until they
815 have not been referenced for the processing of this many
816 compilation units. Set this to zero to disable caching. Cache
817 sizes of up to at least twenty will improve startup time for
818 typical inter-CU-reference binaries, at an obvious memory cost. */
819 static int dwarf2_max_cache_age
= 5;
821 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
822 struct cmd_list_element
*c
, const char *value
)
824 fprintf_filtered (file
, _("The upper bound on the age of cached "
825 "dwarf2 compilation units is %s.\n"),
830 /* Various complaints about symbol reading that don't abort the process. */
833 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
835 complaint (&symfile_complaints
,
836 _("statement list doesn't fit in .debug_line section"));
840 dwarf2_debug_line_missing_file_complaint (void)
842 complaint (&symfile_complaints
,
843 _(".debug_line section has line data without a file"));
847 dwarf2_debug_line_missing_end_sequence_complaint (void)
849 complaint (&symfile_complaints
,
850 _(".debug_line section has line "
851 "program sequence without an end"));
855 dwarf2_complex_location_expr_complaint (void)
857 complaint (&symfile_complaints
, _("location expression too complex"));
861 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
864 complaint (&symfile_complaints
,
865 _("const value length mismatch for '%s', got %d, expected %d"),
870 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
872 complaint (&symfile_complaints
,
873 _("macro info runs off end of `%s' section"),
874 section
->asection
->name
);
878 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
880 complaint (&symfile_complaints
,
881 _("macro debug info contains a "
882 "malformed macro definition:\n`%s'"),
887 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
889 complaint (&symfile_complaints
,
890 _("invalid attribute class or form for '%s' in '%s'"),
894 /* local function prototypes */
896 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
898 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
901 static void dwarf2_find_base_address (struct die_info
*die
,
902 struct dwarf2_cu
*cu
);
904 static void dwarf2_build_psymtabs_hard (struct objfile
*);
906 static void scan_partial_symbols (struct partial_die_info
*,
907 CORE_ADDR
*, CORE_ADDR
*,
908 int, struct dwarf2_cu
*);
910 static void add_partial_symbol (struct partial_die_info
*,
913 static void add_partial_namespace (struct partial_die_info
*pdi
,
914 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
915 int need_pc
, struct dwarf2_cu
*cu
);
917 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
918 CORE_ADDR
*highpc
, int need_pc
,
919 struct dwarf2_cu
*cu
);
921 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
922 struct dwarf2_cu
*cu
);
924 static void add_partial_subprogram (struct partial_die_info
*pdi
,
925 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
926 int need_pc
, struct dwarf2_cu
*cu
);
928 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
929 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
930 bfd
*abfd
, struct dwarf2_cu
*cu
);
932 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
934 static void psymtab_to_symtab_1 (struct partial_symtab
*);
936 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
938 static void dwarf2_free_abbrev_table (void *);
940 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
942 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
945 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
948 static struct partial_die_info
*load_partial_dies (bfd
*,
949 gdb_byte
*, gdb_byte
*,
950 int, struct dwarf2_cu
*);
952 static gdb_byte
*read_partial_die (struct partial_die_info
*,
953 struct abbrev_info
*abbrev
,
955 gdb_byte
*, gdb_byte
*,
958 static struct partial_die_info
*find_partial_die (unsigned int,
961 static void fixup_partial_die (struct partial_die_info
*,
964 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
965 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
967 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
968 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
970 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
972 static int read_1_signed_byte (bfd
*, gdb_byte
*);
974 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
976 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
978 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
980 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
983 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
985 static LONGEST read_checked_initial_length_and_offset
986 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
987 unsigned int *, unsigned int *);
989 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
992 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
994 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
996 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
998 static char *read_indirect_string (bfd
*, gdb_byte
*,
999 const struct comp_unit_head
*,
1002 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1004 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1006 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1008 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1010 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1011 struct dwarf2_cu
*);
1013 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1015 struct dwarf2_cu
*);
1017 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1018 struct dwarf2_cu
*cu
);
1020 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1022 static struct die_info
*die_specification (struct die_info
*die
,
1023 struct dwarf2_cu
**);
1025 static void free_line_header (struct line_header
*lh
);
1027 static void add_file_name (struct line_header
*, char *, unsigned int,
1028 unsigned int, unsigned int);
1030 static struct line_header
*(dwarf_decode_line_header
1031 (unsigned int offset
,
1032 bfd
*abfd
, struct dwarf2_cu
*cu
));
1034 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1035 struct dwarf2_cu
*, struct partial_symtab
*);
1037 static void dwarf2_start_subfile (char *, const char *, const char *);
1039 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1040 struct dwarf2_cu
*);
1042 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1043 struct dwarf2_cu
*, struct symbol
*);
1045 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1046 struct dwarf2_cu
*);
1048 static void dwarf2_const_value_attr (struct attribute
*attr
,
1051 struct obstack
*obstack
,
1052 struct dwarf2_cu
*cu
, long *value
,
1054 struct dwarf2_locexpr_baton
**baton
);
1056 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1058 static int need_gnat_info (struct dwarf2_cu
*);
1060 static struct type
*die_descriptive_type (struct die_info
*,
1061 struct dwarf2_cu
*);
1063 static void set_descriptive_type (struct type
*, struct die_info
*,
1064 struct dwarf2_cu
*);
1066 static struct type
*die_containing_type (struct die_info
*,
1067 struct dwarf2_cu
*);
1069 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1070 struct dwarf2_cu
*);
1072 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1074 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1076 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1078 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1079 const char *suffix
, int physname
,
1080 struct dwarf2_cu
*cu
);
1082 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1084 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1086 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1088 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1090 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1092 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1093 struct dwarf2_cu
*, struct partial_symtab
*);
1095 static int dwarf2_get_pc_bounds (struct die_info
*,
1096 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1097 struct partial_symtab
*);
1099 static void get_scope_pc_bounds (struct die_info
*,
1100 CORE_ADDR
*, CORE_ADDR
*,
1101 struct dwarf2_cu
*);
1103 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1104 CORE_ADDR
, struct dwarf2_cu
*);
1106 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1107 struct dwarf2_cu
*);
1109 static void dwarf2_attach_fields_to_type (struct field_info
*,
1110 struct type
*, struct dwarf2_cu
*);
1112 static void dwarf2_add_member_fn (struct field_info
*,
1113 struct die_info
*, struct type
*,
1114 struct dwarf2_cu
*);
1116 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1118 struct dwarf2_cu
*);
1120 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1122 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1124 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1126 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1128 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1130 static struct type
*read_module_type (struct die_info
*die
,
1131 struct dwarf2_cu
*cu
);
1133 static const char *namespace_name (struct die_info
*die
,
1134 int *is_anonymous
, struct dwarf2_cu
*);
1136 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1138 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1140 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1141 struct dwarf2_cu
*);
1143 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1145 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1147 gdb_byte
**new_info_ptr
,
1148 struct die_info
*parent
);
1150 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1152 gdb_byte
**new_info_ptr
,
1153 struct die_info
*parent
);
1155 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1157 gdb_byte
**new_info_ptr
,
1158 struct die_info
*parent
);
1160 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1161 struct die_info
**, gdb_byte
*,
1164 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1166 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1169 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1171 static const char *dwarf2_full_name (char *name
,
1172 struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1176 struct dwarf2_cu
**);
1178 static char *dwarf_tag_name (unsigned int);
1180 static char *dwarf_attr_name (unsigned int);
1182 static char *dwarf_form_name (unsigned int);
1184 static char *dwarf_bool_name (unsigned int);
1186 static char *dwarf_type_encoding_name (unsigned int);
1189 static char *dwarf_cfi_name (unsigned int);
1192 static struct die_info
*sibling_die (struct die_info
*);
1194 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1196 static void dump_die_for_error (struct die_info
*);
1198 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1201 /*static*/ void dump_die (struct die_info
*, int max_level
);
1203 static void store_in_ref_table (struct die_info
*,
1204 struct dwarf2_cu
*);
1206 static int is_ref_attr (struct attribute
*);
1208 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1210 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1212 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1214 struct dwarf2_cu
**);
1216 static struct die_info
*follow_die_ref (struct die_info
*,
1218 struct dwarf2_cu
**);
1220 static struct die_info
*follow_die_sig (struct die_info
*,
1222 struct dwarf2_cu
**);
1224 static struct signatured_type
*lookup_signatured_type_at_offset
1225 (struct objfile
*objfile
,
1226 struct dwarf2_section_info
*section
,
1227 unsigned int offset
);
1229 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1230 struct dwarf2_section_info
*sect
,
1231 unsigned int offset
);
1233 static void read_signatured_type (struct objfile
*,
1234 struct signatured_type
*type_sig
);
1236 /* memory allocation interface */
1238 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1240 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1242 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1244 static void initialize_cu_func_list (struct dwarf2_cu
*);
1246 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1247 struct dwarf2_cu
*);
1249 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1250 char *, bfd
*, struct dwarf2_cu
*,
1251 struct dwarf2_section_info
*,
1254 static int attr_form_is_block (struct attribute
*);
1256 static int attr_form_is_section_offset (struct attribute
*);
1258 static int attr_form_is_constant (struct attribute
*);
1260 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1261 struct dwarf2_loclist_baton
*baton
,
1262 struct attribute
*attr
);
1264 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1266 struct dwarf2_cu
*cu
);
1268 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1269 struct abbrev_info
*abbrev
,
1270 struct dwarf2_cu
*cu
);
1272 static void free_stack_comp_unit (void *);
1274 static hashval_t
partial_die_hash (const void *item
);
1276 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1278 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1279 (unsigned int offset
, struct objfile
*objfile
);
1281 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1282 (unsigned int offset
, struct objfile
*objfile
);
1284 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1285 struct objfile
*objfile
);
1287 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1288 struct die_info
*comp_unit_die
);
1290 static void free_one_comp_unit (void *);
1292 static void free_cached_comp_units (void *);
1294 static void age_cached_comp_units (void);
1296 static void free_one_cached_comp_unit (void *);
1298 static struct type
*set_die_type (struct die_info
*, struct type
*,
1299 struct dwarf2_cu
*);
1301 static void create_all_comp_units (struct objfile
*);
1303 static int create_debug_types_hash_table (struct objfile
*objfile
);
1305 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1308 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1310 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1311 struct dwarf2_per_cu_data
*);
1313 static void dwarf2_mark (struct dwarf2_cu
*);
1315 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1317 static struct type
*get_die_type_at_offset (unsigned int,
1318 struct dwarf2_per_cu_data
*per_cu
);
1320 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1322 static void dwarf2_release_queue (void *dummy
);
1324 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1325 struct objfile
*objfile
);
1327 static void process_queue (struct objfile
*objfile
);
1329 static void find_file_and_directory (struct die_info
*die
,
1330 struct dwarf2_cu
*cu
,
1331 char **name
, char **comp_dir
);
1333 static char *file_full_name (int file
, struct line_header
*lh
,
1334 const char *comp_dir
);
1336 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1339 unsigned int buffer_size
,
1341 int is_debug_type_section
);
1343 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1344 struct dwarf2_cu
*cu
);
1346 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1350 /* Convert VALUE between big- and little-endian. */
1352 byte_swap (offset_type value
)
1356 result
= (value
& 0xff) << 24;
1357 result
|= (value
& 0xff00) << 8;
1358 result
|= (value
& 0xff0000) >> 8;
1359 result
|= (value
& 0xff000000) >> 24;
1363 #define MAYBE_SWAP(V) byte_swap (V)
1366 #define MAYBE_SWAP(V) (V)
1367 #endif /* WORDS_BIGENDIAN */
1369 /* The suffix for an index file. */
1370 #define INDEX_SUFFIX ".gdb-index"
1372 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1373 struct dwarf2_cu
*cu
);
1375 /* Try to locate the sections we need for DWARF 2 debugging
1376 information and return true if we have enough to do something.
1377 NAMES points to the dwarf2 section names, or is NULL if the standard
1378 ELF names are used. */
1381 dwarf2_has_info (struct objfile
*objfile
,
1382 const struct dwarf2_debug_sections
*names
)
1384 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1385 if (!dwarf2_per_objfile
)
1387 /* Initialize per-objfile state. */
1388 struct dwarf2_per_objfile
*data
1389 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1391 memset (data
, 0, sizeof (*data
));
1392 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1393 dwarf2_per_objfile
= data
;
1395 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1397 dwarf2_per_objfile
->objfile
= objfile
;
1399 return (dwarf2_per_objfile
->info
.asection
!= NULL
1400 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1403 /* When loading sections, we look either for uncompressed section or for
1404 compressed section names. */
1407 section_is_p (const char *section_name
,
1408 const struct dwarf2_section_names
*names
)
1410 if (names
->normal
!= NULL
1411 && strcmp (section_name
, names
->normal
) == 0)
1413 if (names
->compressed
!= NULL
1414 && strcmp (section_name
, names
->compressed
) == 0)
1419 /* This function is mapped across the sections and remembers the
1420 offset and size of each of the debugging sections we are interested
1424 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1426 const struct dwarf2_debug_sections
*names
;
1429 names
= &dwarf2_elf_names
;
1431 names
= (const struct dwarf2_debug_sections
*) vnames
;
1433 if (section_is_p (sectp
->name
, &names
->info
))
1435 dwarf2_per_objfile
->info
.asection
= sectp
;
1436 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1438 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1440 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1441 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1443 else if (section_is_p (sectp
->name
, &names
->line
))
1445 dwarf2_per_objfile
->line
.asection
= sectp
;
1446 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1448 else if (section_is_p (sectp
->name
, &names
->loc
))
1450 dwarf2_per_objfile
->loc
.asection
= sectp
;
1451 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1453 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1455 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1456 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1458 else if (section_is_p (sectp
->name
, &names
->macro
))
1460 dwarf2_per_objfile
->macro
.asection
= sectp
;
1461 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1463 else if (section_is_p (sectp
->name
, &names
->str
))
1465 dwarf2_per_objfile
->str
.asection
= sectp
;
1466 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1468 else if (section_is_p (sectp
->name
, &names
->frame
))
1470 dwarf2_per_objfile
->frame
.asection
= sectp
;
1471 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1473 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1475 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1477 if (aflag
& SEC_HAS_CONTENTS
)
1479 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1480 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1483 else if (section_is_p (sectp
->name
, &names
->ranges
))
1485 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1486 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1488 else if (section_is_p (sectp
->name
, &names
->types
))
1490 struct dwarf2_section_info type_section
;
1492 memset (&type_section
, 0, sizeof (type_section
));
1493 type_section
.asection
= sectp
;
1494 type_section
.size
= bfd_get_section_size (sectp
);
1496 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1499 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1501 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1502 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1505 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1506 && bfd_section_vma (abfd
, sectp
) == 0)
1507 dwarf2_per_objfile
->has_section_at_zero
= 1;
1510 /* Decompress a section that was compressed using zlib. Store the
1511 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1514 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1515 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1517 bfd
*abfd
= objfile
->obfd
;
1519 error (_("Support for zlib-compressed DWARF data (from '%s') "
1520 "is disabled in this copy of GDB"),
1521 bfd_get_filename (abfd
));
1523 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1524 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1525 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1526 bfd_size_type uncompressed_size
;
1527 gdb_byte
*uncompressed_buffer
;
1530 int header_size
= 12;
1532 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1533 || bfd_bread (compressed_buffer
,
1534 compressed_size
, abfd
) != compressed_size
)
1535 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1536 bfd_get_filename (abfd
));
1538 /* Read the zlib header. In this case, it should be "ZLIB" followed
1539 by the uncompressed section size, 8 bytes in big-endian order. */
1540 if (compressed_size
< header_size
1541 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1542 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1543 bfd_get_filename (abfd
));
1544 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1545 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1546 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1547 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1548 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1549 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1550 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1551 uncompressed_size
+= compressed_buffer
[11];
1553 /* It is possible the section consists of several compressed
1554 buffers concatenated together, so we uncompress in a loop. */
1558 strm
.avail_in
= compressed_size
- header_size
;
1559 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1560 strm
.avail_out
= uncompressed_size
;
1561 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1563 rc
= inflateInit (&strm
);
1564 while (strm
.avail_in
> 0)
1567 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1568 bfd_get_filename (abfd
), rc
);
1569 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1570 + (uncompressed_size
- strm
.avail_out
));
1571 rc
= inflate (&strm
, Z_FINISH
);
1572 if (rc
!= Z_STREAM_END
)
1573 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1574 bfd_get_filename (abfd
), rc
);
1575 rc
= inflateReset (&strm
);
1577 rc
= inflateEnd (&strm
);
1579 || strm
.avail_out
!= 0)
1580 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1581 bfd_get_filename (abfd
), rc
);
1583 do_cleanups (cleanup
);
1584 *outbuf
= uncompressed_buffer
;
1585 *outsize
= uncompressed_size
;
1589 /* A helper function that decides whether a section is empty. */
1592 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1594 return info
->asection
== NULL
|| info
->size
== 0;
1597 /* Read the contents of the section SECTP from object file specified by
1598 OBJFILE, store info about the section into INFO.
1599 If the section is compressed, uncompress it before returning. */
1602 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1604 bfd
*abfd
= objfile
->obfd
;
1605 asection
*sectp
= info
->asection
;
1606 gdb_byte
*buf
, *retbuf
;
1607 unsigned char header
[4];
1611 info
->buffer
= NULL
;
1612 info
->map_addr
= NULL
;
1615 if (dwarf2_section_empty_p (info
))
1618 /* Check if the file has a 4-byte header indicating compression. */
1619 if (info
->size
> sizeof (header
)
1620 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1621 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1623 /* Upon decompression, update the buffer and its size. */
1624 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1626 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1634 pagesize
= getpagesize ();
1636 /* Only try to mmap sections which are large enough: we don't want to
1637 waste space due to fragmentation. Also, only try mmap for sections
1638 without relocations. */
1640 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1642 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1643 MAP_PRIVATE
, sectp
->filepos
,
1644 &info
->map_addr
, &info
->map_len
);
1646 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1648 #if HAVE_POSIX_MADVISE
1649 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1656 /* If we get here, we are a normal, not-compressed section. */
1658 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1660 /* When debugging .o files, we may need to apply relocations; see
1661 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1662 We never compress sections in .o files, so we only need to
1663 try this when the section is not compressed. */
1664 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1667 info
->buffer
= retbuf
;
1671 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1672 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1673 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1674 bfd_get_filename (abfd
));
1677 /* A helper function that returns the size of a section in a safe way.
1678 If you are positive that the section has been read before using the
1679 size, then it is safe to refer to the dwarf2_section_info object's
1680 "size" field directly. In other cases, you must call this
1681 function, because for compressed sections the size field is not set
1682 correctly until the section has been read. */
1684 static bfd_size_type
1685 dwarf2_section_size (struct objfile
*objfile
,
1686 struct dwarf2_section_info
*info
)
1689 dwarf2_read_section (objfile
, info
);
1693 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1697 dwarf2_get_section_info (struct objfile
*objfile
,
1698 enum dwarf2_section_enum sect
,
1699 asection
**sectp
, gdb_byte
**bufp
,
1700 bfd_size_type
*sizep
)
1702 struct dwarf2_per_objfile
*data
1703 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1704 struct dwarf2_section_info
*info
;
1706 /* We may see an objfile without any DWARF, in which case we just
1717 case DWARF2_DEBUG_FRAME
:
1718 info
= &data
->frame
;
1720 case DWARF2_EH_FRAME
:
1721 info
= &data
->eh_frame
;
1724 gdb_assert_not_reached ("unexpected section");
1727 dwarf2_read_section (objfile
, info
);
1729 *sectp
= info
->asection
;
1730 *bufp
= info
->buffer
;
1731 *sizep
= info
->size
;
1735 /* DWARF quick_symbols_functions support. */
1737 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1738 unique line tables, so we maintain a separate table of all .debug_line
1739 derived entries to support the sharing.
1740 All the quick functions need is the list of file names. We discard the
1741 line_header when we're done and don't need to record it here. */
1742 struct quick_file_names
1744 /* The offset in .debug_line of the line table. We hash on this. */
1745 unsigned int offset
;
1747 /* The number of entries in file_names, real_names. */
1748 unsigned int num_file_names
;
1750 /* The file names from the line table, after being run through
1752 const char **file_names
;
1754 /* The file names from the line table after being run through
1755 gdb_realpath. These are computed lazily. */
1756 const char **real_names
;
1759 /* When using the index (and thus not using psymtabs), each CU has an
1760 object of this type. This is used to hold information needed by
1761 the various "quick" methods. */
1762 struct dwarf2_per_cu_quick_data
1764 /* The file table. This can be NULL if there was no file table
1765 or it's currently not read in.
1766 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1767 struct quick_file_names
*file_names
;
1769 /* The corresponding symbol table. This is NULL if symbols for this
1770 CU have not yet been read. */
1771 struct symtab
*symtab
;
1773 /* A temporary mark bit used when iterating over all CUs in
1774 expand_symtabs_matching. */
1775 unsigned int mark
: 1;
1777 /* True if we've tried to read the file table and found there isn't one.
1778 There will be no point in trying to read it again next time. */
1779 unsigned int no_file_data
: 1;
1782 /* Hash function for a quick_file_names. */
1785 hash_file_name_entry (const void *e
)
1787 const struct quick_file_names
*file_data
= e
;
1789 return file_data
->offset
;
1792 /* Equality function for a quick_file_names. */
1795 eq_file_name_entry (const void *a
, const void *b
)
1797 const struct quick_file_names
*ea
= a
;
1798 const struct quick_file_names
*eb
= b
;
1800 return ea
->offset
== eb
->offset
;
1803 /* Delete function for a quick_file_names. */
1806 delete_file_name_entry (void *e
)
1808 struct quick_file_names
*file_data
= e
;
1811 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1813 xfree ((void*) file_data
->file_names
[i
]);
1814 if (file_data
->real_names
)
1815 xfree ((void*) file_data
->real_names
[i
]);
1818 /* The space for the struct itself lives on objfile_obstack,
1819 so we don't free it here. */
1822 /* Create a quick_file_names hash table. */
1825 create_quick_file_names_table (unsigned int nr_initial_entries
)
1827 return htab_create_alloc (nr_initial_entries
,
1828 hash_file_name_entry
, eq_file_name_entry
,
1829 delete_file_name_entry
, xcalloc
, xfree
);
1832 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1833 have to be created afterwards. You should call age_cached_comp_units after
1834 processing PER_CU->CU. dw2_setup must have been already called. */
1837 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1839 if (per_cu
->debug_type_section
)
1840 read_signatured_type_at_offset (per_cu
->objfile
,
1841 per_cu
->debug_type_section
,
1844 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1846 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1848 gdb_assert (per_cu
->cu
!= NULL
);
1851 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1855 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1856 struct dwarf2_per_cu_data
*per_cu
)
1858 struct cleanup
*back_to
;
1860 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1862 queue_comp_unit (per_cu
, objfile
);
1866 process_queue (objfile
);
1868 /* Age the cache, releasing compilation units that have not
1869 been used recently. */
1870 age_cached_comp_units ();
1872 do_cleanups (back_to
);
1875 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1876 the objfile from which this CU came. Returns the resulting symbol
1879 static struct symtab
*
1880 dw2_instantiate_symtab (struct objfile
*objfile
,
1881 struct dwarf2_per_cu_data
*per_cu
)
1883 if (!per_cu
->v
.quick
->symtab
)
1885 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1886 increment_reading_symtab ();
1887 dw2_do_instantiate_symtab (objfile
, per_cu
);
1888 do_cleanups (back_to
);
1890 return per_cu
->v
.quick
->symtab
;
1893 /* Return the CU given its index. */
1895 static struct dwarf2_per_cu_data
*
1896 dw2_get_cu (int index
)
1898 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1900 index
-= dwarf2_per_objfile
->n_comp_units
;
1901 return dwarf2_per_objfile
->type_comp_units
[index
];
1903 return dwarf2_per_objfile
->all_comp_units
[index
];
1906 /* A helper function that knows how to read a 64-bit value in a way
1907 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1911 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1913 if (sizeof (ULONGEST
) < 8)
1917 /* Ignore the upper 4 bytes if they are all zero. */
1918 for (i
= 0; i
< 4; ++i
)
1919 if (bytes
[i
+ 4] != 0)
1922 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1925 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1929 /* Read the CU list from the mapped index, and use it to create all
1930 the CU objects for this objfile. Return 0 if something went wrong,
1931 1 if everything went ok. */
1934 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1935 offset_type cu_list_elements
)
1939 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1940 dwarf2_per_objfile
->all_comp_units
1941 = obstack_alloc (&objfile
->objfile_obstack
,
1942 dwarf2_per_objfile
->n_comp_units
1943 * sizeof (struct dwarf2_per_cu_data
*));
1945 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1947 struct dwarf2_per_cu_data
*the_cu
;
1948 ULONGEST offset
, length
;
1950 if (!extract_cu_value (cu_list
, &offset
)
1951 || !extract_cu_value (cu_list
+ 8, &length
))
1955 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1956 struct dwarf2_per_cu_data
);
1957 the_cu
->offset
= offset
;
1958 the_cu
->length
= length
;
1959 the_cu
->objfile
= objfile
;
1960 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1961 struct dwarf2_per_cu_quick_data
);
1962 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1968 /* Create the signatured type hash table from the index. */
1971 create_signatured_type_table_from_index (struct objfile
*objfile
,
1972 struct dwarf2_section_info
*section
,
1973 const gdb_byte
*bytes
,
1974 offset_type elements
)
1977 htab_t sig_types_hash
;
1979 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1980 dwarf2_per_objfile
->type_comp_units
1981 = obstack_alloc (&objfile
->objfile_obstack
,
1982 dwarf2_per_objfile
->n_type_comp_units
1983 * sizeof (struct dwarf2_per_cu_data
*));
1985 sig_types_hash
= allocate_signatured_type_table (objfile
);
1987 for (i
= 0; i
< elements
; i
+= 3)
1989 struct signatured_type
*type_sig
;
1990 ULONGEST offset
, type_offset
, signature
;
1993 if (!extract_cu_value (bytes
, &offset
)
1994 || !extract_cu_value (bytes
+ 8, &type_offset
))
1996 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1999 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2000 struct signatured_type
);
2001 type_sig
->signature
= signature
;
2002 type_sig
->type_offset
= type_offset
;
2003 type_sig
->per_cu
.debug_type_section
= section
;
2004 type_sig
->per_cu
.offset
= offset
;
2005 type_sig
->per_cu
.objfile
= objfile
;
2006 type_sig
->per_cu
.v
.quick
2007 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2008 struct dwarf2_per_cu_quick_data
);
2010 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
2013 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
2016 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2021 /* Read the address map data from the mapped index, and use it to
2022 populate the objfile's psymtabs_addrmap. */
2025 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2027 const gdb_byte
*iter
, *end
;
2028 struct obstack temp_obstack
;
2029 struct addrmap
*mutable_map
;
2030 struct cleanup
*cleanup
;
2033 obstack_init (&temp_obstack
);
2034 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2035 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2037 iter
= index
->address_table
;
2038 end
= iter
+ index
->address_table_size
;
2040 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2044 ULONGEST hi
, lo
, cu_index
;
2045 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2047 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2049 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2052 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2053 dw2_get_cu (cu_index
));
2056 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2057 &objfile
->objfile_obstack
);
2058 do_cleanups (cleanup
);
2061 /* The hash function for strings in the mapped index. This is the same as
2062 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2063 implementation. This is necessary because the hash function is tied to the
2064 format of the mapped index file. The hash values do not have to match with
2067 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2070 mapped_index_string_hash (int index_version
, const void *p
)
2072 const unsigned char *str
= (const unsigned char *) p
;
2076 while ((c
= *str
++) != 0)
2078 if (index_version
>= 5)
2080 r
= r
* 67 + c
- 113;
2086 /* Find a slot in the mapped index INDEX for the object named NAME.
2087 If NAME is found, set *VEC_OUT to point to the CU vector in the
2088 constant pool and return 1. If NAME cannot be found, return 0. */
2091 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2092 offset_type
**vec_out
)
2094 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2096 offset_type slot
, step
;
2097 int (*cmp
) (const char *, const char *);
2099 if (current_language
->la_language
== language_cplus
2100 || current_language
->la_language
== language_java
2101 || current_language
->la_language
== language_fortran
)
2103 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2105 const char *paren
= strchr (name
, '(');
2111 dup
= xmalloc (paren
- name
+ 1);
2112 memcpy (dup
, name
, paren
- name
);
2113 dup
[paren
- name
] = 0;
2115 make_cleanup (xfree
, dup
);
2120 /* Index version 4 did not support case insensitive searches. But the
2121 indexes for case insensitive languages are built in lowercase, therefore
2122 simulate our NAME being searched is also lowercased. */
2123 hash
= mapped_index_string_hash ((index
->version
== 4
2124 && case_sensitivity
== case_sensitive_off
2125 ? 5 : index
->version
),
2128 slot
= hash
& (index
->symbol_table_slots
- 1);
2129 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2130 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2134 /* Convert a slot number to an offset into the table. */
2135 offset_type i
= 2 * slot
;
2137 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2139 do_cleanups (back_to
);
2143 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2144 if (!cmp (name
, str
))
2146 *vec_out
= (offset_type
*) (index
->constant_pool
2147 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2148 do_cleanups (back_to
);
2152 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2156 /* Read the index file. If everything went ok, initialize the "quick"
2157 elements of all the CUs and return 1. Otherwise, return 0. */
2160 dwarf2_read_index (struct objfile
*objfile
)
2163 struct mapped_index
*map
;
2164 offset_type
*metadata
;
2165 const gdb_byte
*cu_list
;
2166 const gdb_byte
*types_list
= NULL
;
2167 offset_type version
, cu_list_elements
;
2168 offset_type types_list_elements
= 0;
2171 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2174 /* Older elfutils strip versions could keep the section in the main
2175 executable while splitting it for the separate debug info file. */
2176 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2177 & SEC_HAS_CONTENTS
) == 0)
2180 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2182 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2183 /* Version check. */
2184 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2185 /* Versions earlier than 3 emitted every copy of a psymbol. This
2186 causes the index to behave very poorly for certain requests. Version 3
2187 contained incomplete addrmap. So, it seems better to just ignore such
2188 indices. Index version 4 uses a different hash function than index
2189 version 5 and later. */
2192 /* Indexes with higher version than the one supported by GDB may be no
2193 longer backward compatible. */
2197 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2198 map
->version
= version
;
2199 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2201 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2204 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2205 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2209 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2210 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2211 - MAYBE_SWAP (metadata
[i
]))
2215 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2216 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2217 - MAYBE_SWAP (metadata
[i
]));
2220 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2221 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2222 - MAYBE_SWAP (metadata
[i
]))
2223 / (2 * sizeof (offset_type
)));
2226 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2228 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2231 if (types_list_elements
)
2233 struct dwarf2_section_info
*section
;
2235 /* We can only handle a single .debug_types when we have an
2237 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2240 section
= VEC_index (dwarf2_section_info_def
,
2241 dwarf2_per_objfile
->types
, 0);
2243 if (!create_signatured_type_table_from_index (objfile
, section
,
2245 types_list_elements
))
2249 create_addrmap_from_index (objfile
, map
);
2251 dwarf2_per_objfile
->index_table
= map
;
2252 dwarf2_per_objfile
->using_index
= 1;
2253 dwarf2_per_objfile
->quick_file_names_table
=
2254 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2259 /* A helper for the "quick" functions which sets the global
2260 dwarf2_per_objfile according to OBJFILE. */
2263 dw2_setup (struct objfile
*objfile
)
2265 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2266 gdb_assert (dwarf2_per_objfile
);
2269 /* A helper for the "quick" functions which attempts to read the line
2270 table for THIS_CU. */
2272 static struct quick_file_names
*
2273 dw2_get_file_names (struct objfile
*objfile
,
2274 struct dwarf2_per_cu_data
*this_cu
)
2276 bfd
*abfd
= objfile
->obfd
;
2277 struct line_header
*lh
;
2278 struct attribute
*attr
;
2279 struct cleanup
*cleanups
;
2280 struct die_info
*comp_unit_die
;
2281 struct dwarf2_section_info
* sec
;
2282 gdb_byte
*info_ptr
, *buffer
;
2283 int has_children
, i
;
2284 struct dwarf2_cu cu
;
2285 unsigned int bytes_read
, buffer_size
;
2286 struct die_reader_specs reader_specs
;
2287 char *name
, *comp_dir
;
2289 struct quick_file_names
*qfn
;
2290 unsigned int line_offset
;
2292 if (this_cu
->v
.quick
->file_names
!= NULL
)
2293 return this_cu
->v
.quick
->file_names
;
2294 /* If we know there is no line data, no point in looking again. */
2295 if (this_cu
->v
.quick
->no_file_data
)
2298 init_one_comp_unit (&cu
, objfile
);
2299 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2301 if (this_cu
->debug_type_section
)
2302 sec
= this_cu
->debug_type_section
;
2304 sec
= &dwarf2_per_objfile
->info
;
2305 dwarf2_read_section (objfile
, sec
);
2306 buffer_size
= sec
->size
;
2307 buffer
= sec
->buffer
;
2308 info_ptr
= buffer
+ this_cu
->offset
;
2310 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2311 buffer
, buffer_size
,
2313 this_cu
->debug_type_section
!= NULL
);
2315 /* Skip dummy compilation units. */
2316 if (info_ptr
>= buffer
+ buffer_size
2317 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2319 do_cleanups (cleanups
);
2324 cu
.per_cu
= this_cu
;
2326 dwarf2_read_abbrevs (abfd
, &cu
);
2327 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2329 init_cu_die_reader (&reader_specs
, &cu
);
2330 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2336 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2339 struct quick_file_names find_entry
;
2341 line_offset
= DW_UNSND (attr
);
2343 /* We may have already read in this line header (TU line header sharing).
2344 If we have we're done. */
2345 find_entry
.offset
= line_offset
;
2346 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2347 &find_entry
, INSERT
);
2350 do_cleanups (cleanups
);
2351 this_cu
->v
.quick
->file_names
= *slot
;
2355 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2359 do_cleanups (cleanups
);
2360 this_cu
->v
.quick
->no_file_data
= 1;
2364 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2365 qfn
->offset
= line_offset
;
2366 gdb_assert (slot
!= NULL
);
2369 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2371 qfn
->num_file_names
= lh
->num_file_names
;
2372 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2373 lh
->num_file_names
* sizeof (char *));
2374 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2375 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2376 qfn
->real_names
= NULL
;
2378 free_line_header (lh
);
2379 do_cleanups (cleanups
);
2381 this_cu
->v
.quick
->file_names
= qfn
;
2385 /* A helper for the "quick" functions which computes and caches the
2386 real path for a given file name from the line table. */
2389 dw2_get_real_path (struct objfile
*objfile
,
2390 struct quick_file_names
*qfn
, int index
)
2392 if (qfn
->real_names
== NULL
)
2393 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2394 qfn
->num_file_names
, sizeof (char *));
2396 if (qfn
->real_names
[index
] == NULL
)
2397 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2399 return qfn
->real_names
[index
];
2402 static struct symtab
*
2403 dw2_find_last_source_symtab (struct objfile
*objfile
)
2407 dw2_setup (objfile
);
2408 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2409 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2412 /* Traversal function for dw2_forget_cached_source_info. */
2415 dw2_free_cached_file_names (void **slot
, void *info
)
2417 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2419 if (file_data
->real_names
)
2423 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2425 xfree ((void*) file_data
->real_names
[i
]);
2426 file_data
->real_names
[i
] = NULL
;
2434 dw2_forget_cached_source_info (struct objfile
*objfile
)
2436 dw2_setup (objfile
);
2438 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2439 dw2_free_cached_file_names
, NULL
);
2443 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2444 const char *full_path
, const char *real_path
,
2445 struct symtab
**result
)
2448 const char *name_basename
= lbasename (name
);
2449 int check_basename
= name_basename
== name
;
2450 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2452 dw2_setup (objfile
);
2454 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2455 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2458 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2459 struct quick_file_names
*file_data
;
2461 /* We only need to look at symtabs not already expanded. */
2462 if (per_cu
->v
.quick
->symtab
)
2465 file_data
= dw2_get_file_names (objfile
, per_cu
);
2466 if (file_data
== NULL
)
2469 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2471 const char *this_name
= file_data
->file_names
[j
];
2473 if (FILENAME_CMP (name
, this_name
) == 0)
2475 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2479 if (check_basename
&& ! base_cu
2480 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2483 /* Before we invoke realpath, which can get expensive when many
2484 files are involved, do a quick comparison of the basenames. */
2485 if (! basenames_may_differ
2486 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2489 if (full_path
!= NULL
)
2491 const char *this_real_name
= dw2_get_real_path (objfile
,
2494 if (this_real_name
!= NULL
2495 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2497 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2502 if (real_path
!= NULL
)
2504 const char *this_real_name
= dw2_get_real_path (objfile
,
2507 if (this_real_name
!= NULL
2508 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2510 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2519 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2526 static struct symtab
*
2527 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2528 const char *name
, domain_enum domain
)
2530 /* We do all the work in the pre_expand_symtabs_matching hook
2535 /* A helper function that expands all symtabs that hold an object
2539 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2541 dw2_setup (objfile
);
2543 /* index_table is NULL if OBJF_READNOW. */
2544 if (dwarf2_per_objfile
->index_table
)
2548 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2551 offset_type i
, len
= MAYBE_SWAP (*vec
);
2552 for (i
= 0; i
< len
; ++i
)
2554 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2555 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2557 dw2_instantiate_symtab (objfile
, per_cu
);
2564 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2565 enum block_enum block_kind
, const char *name
,
2568 dw2_do_expand_symtabs_matching (objfile
, name
);
2572 dw2_print_stats (struct objfile
*objfile
)
2576 dw2_setup (objfile
);
2578 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2579 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2581 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2583 if (!per_cu
->v
.quick
->symtab
)
2586 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2590 dw2_dump (struct objfile
*objfile
)
2592 /* Nothing worth printing. */
2596 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2597 struct section_offsets
*delta
)
2599 /* There's nothing to relocate here. */
2603 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2604 const char *func_name
)
2606 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2610 dw2_expand_all_symtabs (struct objfile
*objfile
)
2614 dw2_setup (objfile
);
2616 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2617 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2619 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2621 dw2_instantiate_symtab (objfile
, per_cu
);
2626 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2627 const char *filename
)
2631 dw2_setup (objfile
);
2633 /* We don't need to consider type units here.
2634 This is only called for examining code, e.g. expand_line_sal.
2635 There can be an order of magnitude (or more) more type units
2636 than comp units, and we avoid them if we can. */
2638 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2641 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2642 struct quick_file_names
*file_data
;
2644 /* We only need to look at symtabs not already expanded. */
2645 if (per_cu
->v
.quick
->symtab
)
2648 file_data
= dw2_get_file_names (objfile
, per_cu
);
2649 if (file_data
== NULL
)
2652 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2654 const char *this_name
= file_data
->file_names
[j
];
2655 if (FILENAME_CMP (this_name
, filename
) == 0)
2657 dw2_instantiate_symtab (objfile
, per_cu
);
2665 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2667 struct dwarf2_per_cu_data
*per_cu
;
2669 struct quick_file_names
*file_data
;
2671 dw2_setup (objfile
);
2673 /* index_table is NULL if OBJF_READNOW. */
2674 if (!dwarf2_per_objfile
->index_table
)
2678 ALL_OBJFILE_SYMTABS (objfile
, s
)
2681 struct blockvector
*bv
= BLOCKVECTOR (s
);
2682 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2683 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2686 return sym
->symtab
->filename
;
2691 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2695 /* Note that this just looks at the very first one named NAME -- but
2696 actually we are looking for a function. find_main_filename
2697 should be rewritten so that it doesn't require a custom hook. It
2698 could just use the ordinary symbol tables. */
2699 /* vec[0] is the length, which must always be >0. */
2700 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2702 file_data
= dw2_get_file_names (objfile
, per_cu
);
2703 if (file_data
== NULL
)
2706 return file_data
->file_names
[file_data
->num_file_names
- 1];
2710 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2711 struct objfile
*objfile
, int global
,
2712 int (*callback
) (struct block
*,
2713 struct symbol
*, void *),
2714 void *data
, symbol_compare_ftype
*match
,
2715 symbol_compare_ftype
*ordered_compare
)
2717 /* Currently unimplemented; used for Ada. The function can be called if the
2718 current language is Ada for a non-Ada objfile using GNU index. As Ada
2719 does not look for non-Ada symbols this function should just return. */
2723 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2724 int (*file_matcher
) (const char *, void *),
2725 int (*name_matcher
) (const char *, void *),
2726 enum search_domain kind
,
2731 struct mapped_index
*index
;
2733 dw2_setup (objfile
);
2735 /* index_table is NULL if OBJF_READNOW. */
2736 if (!dwarf2_per_objfile
->index_table
)
2738 index
= dwarf2_per_objfile
->index_table
;
2740 if (file_matcher
!= NULL
)
2741 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2742 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2745 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2746 struct quick_file_names
*file_data
;
2748 per_cu
->v
.quick
->mark
= 0;
2750 /* We only need to look at symtabs not already expanded. */
2751 if (per_cu
->v
.quick
->symtab
)
2754 file_data
= dw2_get_file_names (objfile
, per_cu
);
2755 if (file_data
== NULL
)
2758 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2760 if (file_matcher (file_data
->file_names
[j
], data
))
2762 per_cu
->v
.quick
->mark
= 1;
2768 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2770 offset_type idx
= 2 * iter
;
2772 offset_type
*vec
, vec_len
, vec_idx
;
2774 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2777 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2779 if (! (*name_matcher
) (name
, data
))
2782 /* The name was matched, now expand corresponding CUs that were
2784 vec
= (offset_type
*) (index
->constant_pool
2785 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2786 vec_len
= MAYBE_SWAP (vec
[0]);
2787 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2789 struct dwarf2_per_cu_data
*per_cu
;
2791 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2792 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2793 dw2_instantiate_symtab (objfile
, per_cu
);
2798 static struct symtab
*
2799 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2800 struct minimal_symbol
*msymbol
,
2802 struct obj_section
*section
,
2805 struct dwarf2_per_cu_data
*data
;
2807 dw2_setup (objfile
);
2809 if (!objfile
->psymtabs_addrmap
)
2812 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2816 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2817 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2818 paddress (get_objfile_arch (objfile
), pc
));
2820 return dw2_instantiate_symtab (objfile
, data
);
2824 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2825 void *data
, int need_fullname
)
2829 dw2_setup (objfile
);
2831 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2832 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2835 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2836 struct quick_file_names
*file_data
;
2838 /* We only need to look at symtabs not already expanded. */
2839 if (per_cu
->v
.quick
->symtab
)
2842 file_data
= dw2_get_file_names (objfile
, per_cu
);
2843 if (file_data
== NULL
)
2846 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2848 const char *this_real_name
;
2851 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2853 this_real_name
= NULL
;
2854 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2860 dw2_has_symbols (struct objfile
*objfile
)
2865 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2868 dw2_find_last_source_symtab
,
2869 dw2_forget_cached_source_info
,
2872 dw2_pre_expand_symtabs_matching
,
2876 dw2_expand_symtabs_for_function
,
2877 dw2_expand_all_symtabs
,
2878 dw2_expand_symtabs_with_filename
,
2879 dw2_find_symbol_file
,
2880 dw2_map_matching_symbols
,
2881 dw2_expand_symtabs_matching
,
2882 dw2_find_pc_sect_symtab
,
2883 dw2_map_symbol_filenames
2886 /* Initialize for reading DWARF for this objfile. Return 0 if this
2887 file will use psymtabs, or 1 if using the GNU index. */
2890 dwarf2_initialize_objfile (struct objfile
*objfile
)
2892 /* If we're about to read full symbols, don't bother with the
2893 indices. In this case we also don't care if some other debug
2894 format is making psymtabs, because they are all about to be
2896 if ((objfile
->flags
& OBJF_READNOW
))
2900 dwarf2_per_objfile
->using_index
= 1;
2901 create_all_comp_units (objfile
);
2902 create_debug_types_hash_table (objfile
);
2903 dwarf2_per_objfile
->quick_file_names_table
=
2904 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2906 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2907 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2909 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2911 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2912 struct dwarf2_per_cu_quick_data
);
2915 /* Return 1 so that gdb sees the "quick" functions. However,
2916 these functions will be no-ops because we will have expanded
2921 if (dwarf2_read_index (objfile
))
2929 /* Build a partial symbol table. */
2932 dwarf2_build_psymtabs (struct objfile
*objfile
)
2934 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2936 init_psymbol_list (objfile
, 1024);
2939 dwarf2_build_psymtabs_hard (objfile
);
2942 /* Return TRUE if OFFSET is within CU_HEADER. */
2945 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2947 unsigned int bottom
= cu_header
->offset
;
2948 unsigned int top
= (cu_header
->offset
2950 + cu_header
->initial_length_size
);
2952 return (offset
>= bottom
&& offset
< top
);
2955 /* Read in the comp unit header information from the debug_info at info_ptr.
2956 NOTE: This leaves members offset, first_die_offset to be filled in
2960 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2961 gdb_byte
*info_ptr
, bfd
*abfd
)
2964 unsigned int bytes_read
;
2966 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2967 cu_header
->initial_length_size
= bytes_read
;
2968 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2969 info_ptr
+= bytes_read
;
2970 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2972 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2974 info_ptr
+= bytes_read
;
2975 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2977 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2978 if (signed_addr
< 0)
2979 internal_error (__FILE__
, __LINE__
,
2980 _("read_comp_unit_head: dwarf from non elf file"));
2981 cu_header
->signed_addr_p
= signed_addr
;
2986 /* Read in a CU header and perform some basic error checking. */
2989 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2990 gdb_byte
*buffer
, unsigned int buffer_size
,
2991 bfd
*abfd
, int is_debug_type_section
)
2993 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2995 header
->offset
= beg_of_comp_unit
- buffer
;
2997 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2999 /* If we're reading a type unit, skip over the signature and
3000 type_offset fields. */
3001 if (is_debug_type_section
)
3002 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3004 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3006 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3007 error (_("Dwarf Error: wrong version in compilation unit header "
3008 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3009 bfd_get_filename (abfd
));
3011 if (header
->abbrev_offset
3012 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3013 &dwarf2_per_objfile
->abbrev
))
3014 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3015 "(offset 0x%lx + 6) [in module %s]"),
3016 (long) header
->abbrev_offset
,
3017 (long) (beg_of_comp_unit
- buffer
),
3018 bfd_get_filename (abfd
));
3020 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
3021 > buffer
+ buffer_size
)
3022 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3023 "(offset 0x%lx + 0) [in module %s]"),
3024 (long) header
->length
,
3025 (long) (beg_of_comp_unit
- buffer
),
3026 bfd_get_filename (abfd
));
3031 /* Read in the types comp unit header information from .debug_types entry at
3032 types_ptr. The result is a pointer to one past the end of the header. */
3035 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
3036 struct dwarf2_section_info
*section
,
3037 ULONGEST
*signature
,
3038 gdb_byte
*types_ptr
, bfd
*abfd
)
3040 gdb_byte
*initial_types_ptr
= types_ptr
;
3042 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3043 cu_header
->offset
= types_ptr
- section
->buffer
;
3045 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3047 *signature
= read_8_bytes (abfd
, types_ptr
);
3049 types_ptr
+= cu_header
->offset_size
;
3050 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3055 /* Allocate a new partial symtab for file named NAME and mark this new
3056 partial symtab as being an include of PST. */
3059 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3060 struct objfile
*objfile
)
3062 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3064 subpst
->section_offsets
= pst
->section_offsets
;
3065 subpst
->textlow
= 0;
3066 subpst
->texthigh
= 0;
3068 subpst
->dependencies
= (struct partial_symtab
**)
3069 obstack_alloc (&objfile
->objfile_obstack
,
3070 sizeof (struct partial_symtab
*));
3071 subpst
->dependencies
[0] = pst
;
3072 subpst
->number_of_dependencies
= 1;
3074 subpst
->globals_offset
= 0;
3075 subpst
->n_global_syms
= 0;
3076 subpst
->statics_offset
= 0;
3077 subpst
->n_static_syms
= 0;
3078 subpst
->symtab
= NULL
;
3079 subpst
->read_symtab
= pst
->read_symtab
;
3082 /* No private part is necessary for include psymtabs. This property
3083 can be used to differentiate between such include psymtabs and
3084 the regular ones. */
3085 subpst
->read_symtab_private
= NULL
;
3088 /* Read the Line Number Program data and extract the list of files
3089 included by the source file represented by PST. Build an include
3090 partial symtab for each of these included files. */
3093 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3094 struct die_info
*die
,
3095 struct partial_symtab
*pst
)
3097 struct objfile
*objfile
= cu
->objfile
;
3098 bfd
*abfd
= objfile
->obfd
;
3099 struct line_header
*lh
= NULL
;
3100 struct attribute
*attr
;
3102 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3105 unsigned int line_offset
= DW_UNSND (attr
);
3107 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3110 return; /* No linetable, so no includes. */
3112 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3113 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3115 free_line_header (lh
);
3119 hash_type_signature (const void *item
)
3121 const struct signatured_type
*type_sig
= item
;
3123 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3124 return type_sig
->signature
;
3128 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3130 const struct signatured_type
*lhs
= item_lhs
;
3131 const struct signatured_type
*rhs
= item_rhs
;
3133 return lhs
->signature
== rhs
->signature
;
3136 /* Allocate a hash table for signatured types. */
3139 allocate_signatured_type_table (struct objfile
*objfile
)
3141 return htab_create_alloc_ex (41,
3142 hash_type_signature
,
3145 &objfile
->objfile_obstack
,
3146 hashtab_obstack_allocate
,
3147 dummy_obstack_deallocate
);
3150 /* A helper function to add a signatured type CU to a list. */
3153 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3155 struct signatured_type
*sigt
= *slot
;
3156 struct dwarf2_per_cu_data
***datap
= datum
;
3158 **datap
= &sigt
->per_cu
;
3164 /* Create the hash table of all entries in the .debug_types section.
3165 The result is zero if there is an error (e.g. missing .debug_types section),
3166 otherwise non-zero. */
3169 create_debug_types_hash_table (struct objfile
*objfile
)
3171 htab_t types_htab
= NULL
;
3172 struct dwarf2_per_cu_data
**iter
;
3174 struct dwarf2_section_info
*section
;
3176 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3178 dwarf2_per_objfile
->signatured_types
= NULL
;
3183 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3187 gdb_byte
*info_ptr
, *end_ptr
;
3189 dwarf2_read_section (objfile
, section
);
3190 info_ptr
= section
->buffer
;
3192 if (info_ptr
== NULL
)
3195 if (types_htab
== NULL
)
3196 types_htab
= allocate_signatured_type_table (objfile
);
3198 if (dwarf2_die_debug
)
3199 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3201 end_ptr
= info_ptr
+ section
->size
;
3202 while (info_ptr
< end_ptr
)
3204 unsigned int offset
;
3205 unsigned int offset_size
;
3206 unsigned int type_offset
;
3207 unsigned int length
, initial_length_size
;
3208 unsigned short version
;
3210 struct signatured_type
*type_sig
;
3212 gdb_byte
*ptr
= info_ptr
;
3214 offset
= ptr
- section
->buffer
;
3216 /* We need to read the type's signature in order to build the hash
3217 table, but we don't need to read anything else just yet. */
3219 /* Sanity check to ensure entire cu is present. */
3220 length
= read_initial_length (objfile
->obfd
, ptr
,
3221 &initial_length_size
);
3222 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3224 complaint (&symfile_complaints
,
3225 _("debug type entry runs off end "
3226 "of `.debug_types' section, ignored"));
3230 offset_size
= initial_length_size
== 4 ? 4 : 8;
3231 ptr
+= initial_length_size
;
3232 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3234 ptr
+= offset_size
; /* abbrev offset */
3235 ptr
+= 1; /* address size */
3236 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3238 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3241 /* Skip dummy type units. */
3242 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3244 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3248 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3249 memset (type_sig
, 0, sizeof (*type_sig
));
3250 type_sig
->signature
= signature
;
3251 type_sig
->type_offset
= type_offset
;
3252 type_sig
->per_cu
.objfile
= objfile
;
3253 type_sig
->per_cu
.debug_type_section
= section
;
3254 type_sig
->per_cu
.offset
= offset
;
3256 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3257 gdb_assert (slot
!= NULL
);
3260 const struct signatured_type
*dup_sig
= *slot
;
3262 complaint (&symfile_complaints
,
3263 _("debug type entry at offset 0x%x is duplicate to the "
3264 "entry at offset 0x%x, signature 0x%s"),
3265 offset
, dup_sig
->per_cu
.offset
,
3266 phex (signature
, sizeof (signature
)));
3267 gdb_assert (signature
== dup_sig
->signature
);
3271 if (dwarf2_die_debug
)
3272 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3273 offset
, phex (signature
, sizeof (signature
)));
3275 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3279 dwarf2_per_objfile
->signatured_types
= types_htab
;
3281 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3282 dwarf2_per_objfile
->type_comp_units
3283 = obstack_alloc (&objfile
->objfile_obstack
,
3284 dwarf2_per_objfile
->n_type_comp_units
3285 * sizeof (struct dwarf2_per_cu_data
*));
3286 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3287 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3288 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3289 == dwarf2_per_objfile
->n_type_comp_units
);
3294 /* Lookup a signature based type.
3295 Returns NULL if SIG is not present in the table. */
3297 static struct signatured_type
*
3298 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3300 struct signatured_type find_entry
, *entry
;
3302 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3304 complaint (&symfile_complaints
,
3305 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3309 find_entry
.signature
= sig
;
3310 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3314 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3317 init_cu_die_reader (struct die_reader_specs
*reader
,
3318 struct dwarf2_cu
*cu
)
3320 reader
->abfd
= cu
->objfile
->obfd
;
3322 if (cu
->per_cu
->debug_type_section
)
3324 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3325 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3329 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3330 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3334 /* Find the base address of the compilation unit for range lists and
3335 location lists. It will normally be specified by DW_AT_low_pc.
3336 In DWARF-3 draft 4, the base address could be overridden by
3337 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3338 compilation units with discontinuous ranges. */
3341 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3343 struct attribute
*attr
;
3346 cu
->base_address
= 0;
3348 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3351 cu
->base_address
= DW_ADDR (attr
);
3356 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3359 cu
->base_address
= DW_ADDR (attr
);
3365 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3366 to combine the common parts.
3367 Process a compilation unit for a psymtab.
3368 BUFFER is a pointer to the beginning of the dwarf section buffer,
3369 either .debug_info or debug_types.
3370 INFO_PTR is a pointer to the start of the CU.
3371 Returns a pointer to the next CU. */
3374 process_psymtab_comp_unit (struct objfile
*objfile
,
3375 struct dwarf2_per_cu_data
*this_cu
,
3376 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3377 unsigned int buffer_size
)
3379 bfd
*abfd
= objfile
->obfd
;
3380 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3381 struct die_info
*comp_unit_die
;
3382 struct partial_symtab
*pst
;
3384 struct cleanup
*back_to_inner
;
3385 struct dwarf2_cu cu
;
3386 int has_children
, has_pc_info
;
3387 struct attribute
*attr
;
3388 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3389 struct die_reader_specs reader_specs
;
3390 const char *filename
;
3392 init_one_comp_unit (&cu
, objfile
);
3393 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3395 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3396 buffer
, buffer_size
,
3398 this_cu
->debug_type_section
!= NULL
);
3400 /* Skip dummy compilation units. */
3401 if (info_ptr
>= buffer
+ buffer_size
3402 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3404 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3405 + cu
.header
.initial_length_size
);
3406 do_cleanups (back_to_inner
);
3410 cu
.list_in_scope
= &file_symbols
;
3412 /* If this compilation unit was already read in, free the
3413 cached copy in order to read it in again. This is
3414 necessary because we skipped some symbols when we first
3415 read in the compilation unit (see load_partial_dies).
3416 This problem could be avoided, but the benefit is
3418 if (this_cu
->cu
!= NULL
)
3419 free_one_cached_comp_unit (this_cu
->cu
);
3421 /* Note that this is a pointer to our stack frame, being
3422 added to a global data structure. It will be cleaned up
3423 in free_stack_comp_unit when we finish with this
3424 compilation unit. */
3426 cu
.per_cu
= this_cu
;
3428 /* Read the abbrevs for this compilation unit into a table. */
3429 dwarf2_read_abbrevs (abfd
, &cu
);
3430 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3432 /* Read the compilation unit die. */
3433 init_cu_die_reader (&reader_specs
, &cu
);
3434 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3437 if (this_cu
->debug_type_section
)
3439 /* LENGTH has not been set yet for type units. */
3440 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3441 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3443 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3445 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3446 + cu
.header
.initial_length_size
);
3447 do_cleanups (back_to_inner
);
3451 prepare_one_comp_unit (&cu
, comp_unit_die
);
3453 /* Allocate a new partial symbol table structure. */
3454 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3455 if (attr
== NULL
|| !DW_STRING (attr
))
3458 filename
= DW_STRING (attr
);
3459 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3461 /* TEXTLOW and TEXTHIGH are set below. */
3463 objfile
->global_psymbols
.next
,
3464 objfile
->static_psymbols
.next
);
3465 pst
->psymtabs_addrmap_supported
= 1;
3467 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3469 pst
->dirname
= DW_STRING (attr
);
3471 pst
->read_symtab_private
= this_cu
;
3473 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3475 /* Store the function that reads in the rest of the symbol table. */
3476 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3478 this_cu
->v
.psymtab
= pst
;
3480 dwarf2_find_base_address (comp_unit_die
, &cu
);
3482 /* Possibly set the default values of LOWPC and HIGHPC from
3484 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3485 &best_highpc
, &cu
, pst
);
3486 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3487 /* Store the contiguous range if it is not empty; it can be empty for
3488 CUs with no code. */
3489 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3490 best_lowpc
+ baseaddr
,
3491 best_highpc
+ baseaddr
- 1, pst
);
3493 /* Check if comp unit has_children.
3494 If so, read the rest of the partial symbols from this comp unit.
3495 If not, there's no more debug_info for this comp unit. */
3498 struct partial_die_info
*first_die
;
3499 CORE_ADDR lowpc
, highpc
;
3501 lowpc
= ((CORE_ADDR
) -1);
3502 highpc
= ((CORE_ADDR
) 0);
3504 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3506 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3507 ! has_pc_info
, &cu
);
3509 /* If we didn't find a lowpc, set it to highpc to avoid
3510 complaints from `maint check'. */
3511 if (lowpc
== ((CORE_ADDR
) -1))
3514 /* If the compilation unit didn't have an explicit address range,
3515 then use the information extracted from its child dies. */
3519 best_highpc
= highpc
;
3522 pst
->textlow
= best_lowpc
+ baseaddr
;
3523 pst
->texthigh
= best_highpc
+ baseaddr
;
3525 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3526 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3527 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3528 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3529 sort_pst_symbols (pst
);
3531 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3532 + cu
.header
.initial_length_size
);
3534 if (this_cu
->debug_type_section
)
3536 /* It's not clear we want to do anything with stmt lists here.
3537 Waiting to see what gcc ultimately does. */
3541 /* Get the list of files included in the current compilation unit,
3542 and build a psymtab for each of them. */
3543 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3546 do_cleanups (back_to_inner
);
3551 /* Traversal function for htab_traverse_noresize.
3552 Process one .debug_types comp-unit. */
3555 process_type_comp_unit (void **slot
, void *info
)
3557 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3558 struct objfile
*objfile
= (struct objfile
*) info
;
3559 struct dwarf2_per_cu_data
*this_cu
;
3561 this_cu
= &entry
->per_cu
;
3563 gdb_assert (this_cu
->debug_type_section
->readin
);
3564 process_psymtab_comp_unit (objfile
, this_cu
,
3565 this_cu
->debug_type_section
->buffer
,
3566 (this_cu
->debug_type_section
->buffer
3568 this_cu
->debug_type_section
->size
);
3573 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3574 Build partial symbol tables for the .debug_types comp-units. */
3577 build_type_psymtabs (struct objfile
*objfile
)
3579 if (! create_debug_types_hash_table (objfile
))
3582 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3583 process_type_comp_unit
, objfile
);
3586 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3589 psymtabs_addrmap_cleanup (void *o
)
3591 struct objfile
*objfile
= o
;
3593 objfile
->psymtabs_addrmap
= NULL
;
3596 /* Build the partial symbol table by doing a quick pass through the
3597 .debug_info and .debug_abbrev sections. */
3600 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3603 struct cleanup
*back_to
, *addrmap_cleanup
;
3604 struct obstack temp_obstack
;
3606 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3608 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3609 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3611 /* Any cached compilation units will be linked by the per-objfile
3612 read_in_chain. Make sure to free them when we're done. */
3613 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3615 build_type_psymtabs (objfile
);
3617 create_all_comp_units (objfile
);
3619 /* Create a temporary address map on a temporary obstack. We later
3620 copy this to the final obstack. */
3621 obstack_init (&temp_obstack
);
3622 make_cleanup_obstack_free (&temp_obstack
);
3623 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3624 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3626 /* Since the objects we're extracting from .debug_info vary in
3627 length, only the individual functions to extract them (like
3628 read_comp_unit_head and load_partial_die) can really know whether
3629 the buffer is large enough to hold another complete object.
3631 At the moment, they don't actually check that. If .debug_info
3632 holds just one extra byte after the last compilation unit's dies,
3633 then read_comp_unit_head will happily read off the end of the
3634 buffer. read_partial_die is similarly casual. Those functions
3637 For this loop condition, simply checking whether there's any data
3638 left at all should be sufficient. */
3640 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3641 + dwarf2_per_objfile
->info
.size
))
3643 struct dwarf2_per_cu_data
*this_cu
;
3645 this_cu
= dwarf2_find_comp_unit (info_ptr
3646 - dwarf2_per_objfile
->info
.buffer
,
3649 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3650 dwarf2_per_objfile
->info
.buffer
,
3652 dwarf2_per_objfile
->info
.size
);
3655 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3656 &objfile
->objfile_obstack
);
3657 discard_cleanups (addrmap_cleanup
);
3659 do_cleanups (back_to
);
3662 /* Load the partial DIEs for a secondary CU into memory. */
3665 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3666 struct objfile
*objfile
)
3668 bfd
*abfd
= objfile
->obfd
;
3670 struct die_info
*comp_unit_die
;
3671 struct dwarf2_cu
*cu
;
3672 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3674 struct die_reader_specs reader_specs
;
3677 gdb_assert (! this_cu
->debug_type_section
);
3679 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3680 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3682 if (this_cu
->cu
== NULL
)
3684 cu
= xmalloc (sizeof (*cu
));
3685 init_one_comp_unit (cu
, objfile
);
3689 /* If an error occurs while loading, release our storage. */
3690 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3692 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3693 dwarf2_per_objfile
->info
.buffer
,
3694 dwarf2_per_objfile
->info
.size
,
3697 /* Skip dummy compilation units. */
3698 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
3699 + dwarf2_per_objfile
->info
.size
)
3700 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3702 do_cleanups (free_cu_cleanup
);
3706 /* Link this compilation unit into the compilation unit tree. */
3708 cu
->per_cu
= this_cu
;
3710 /* Link this CU into read_in_chain. */
3711 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3712 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3717 info_ptr
+= cu
->header
.first_die_offset
;
3720 /* Read the abbrevs for this compilation unit into a table. */
3721 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3722 dwarf2_read_abbrevs (abfd
, cu
);
3723 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3725 /* Read the compilation unit die. */
3726 init_cu_die_reader (&reader_specs
, cu
);
3727 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3730 prepare_one_comp_unit (cu
, comp_unit_die
);
3732 /* Check if comp unit has_children.
3733 If so, read the rest of the partial symbols from this comp unit.
3734 If not, there's no more debug_info for this comp unit. */
3736 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3738 do_cleanups (free_abbrevs_cleanup
);
3742 /* We've successfully allocated this compilation unit. Let our
3743 caller clean it up when finished with it. */
3744 discard_cleanups (free_cu_cleanup
);
3748 /* Create a list of all compilation units in OBJFILE. We do this only
3749 if an inter-comp-unit reference is found; presumably if there is one,
3750 there will be many, and one will occur early in the .debug_info section.
3751 So there's no point in building this list incrementally. */
3754 create_all_comp_units (struct objfile
*objfile
)
3758 struct dwarf2_per_cu_data
**all_comp_units
;
3761 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3762 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3766 all_comp_units
= xmalloc (n_allocated
3767 * sizeof (struct dwarf2_per_cu_data
*));
3769 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3770 + dwarf2_per_objfile
->info
.size
)
3772 unsigned int length
, initial_length_size
;
3773 struct dwarf2_per_cu_data
*this_cu
;
3774 unsigned int offset
;
3776 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3778 /* Read just enough information to find out where the next
3779 compilation unit is. */
3780 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3781 &initial_length_size
);
3783 /* Save the compilation unit for later lookup. */
3784 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3785 sizeof (struct dwarf2_per_cu_data
));
3786 memset (this_cu
, 0, sizeof (*this_cu
));
3787 this_cu
->offset
= offset
;
3788 this_cu
->length
= length
+ initial_length_size
;
3789 this_cu
->objfile
= objfile
;
3791 if (n_comp_units
== n_allocated
)
3794 all_comp_units
= xrealloc (all_comp_units
,
3796 * sizeof (struct dwarf2_per_cu_data
*));
3798 all_comp_units
[n_comp_units
++] = this_cu
;
3800 info_ptr
= info_ptr
+ this_cu
->length
;
3803 dwarf2_per_objfile
->all_comp_units
3804 = obstack_alloc (&objfile
->objfile_obstack
,
3805 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3806 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3807 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3808 xfree (all_comp_units
);
3809 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3812 /* Process all loaded DIEs for compilation unit CU, starting at
3813 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3814 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3815 DW_AT_ranges). If NEED_PC is set, then this function will set
3816 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3817 and record the covered ranges in the addrmap. */
3820 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3821 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3823 struct partial_die_info
*pdi
;
3825 /* Now, march along the PDI's, descending into ones which have
3826 interesting children but skipping the children of the other ones,
3827 until we reach the end of the compilation unit. */
3833 fixup_partial_die (pdi
, cu
);
3835 /* Anonymous namespaces or modules have no name but have interesting
3836 children, so we need to look at them. Ditto for anonymous
3839 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3840 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3844 case DW_TAG_subprogram
:
3845 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3847 case DW_TAG_constant
:
3848 case DW_TAG_variable
:
3849 case DW_TAG_typedef
:
3850 case DW_TAG_union_type
:
3851 if (!pdi
->is_declaration
)
3853 add_partial_symbol (pdi
, cu
);
3856 case DW_TAG_class_type
:
3857 case DW_TAG_interface_type
:
3858 case DW_TAG_structure_type
:
3859 if (!pdi
->is_declaration
)
3861 add_partial_symbol (pdi
, cu
);
3864 case DW_TAG_enumeration_type
:
3865 if (!pdi
->is_declaration
)
3866 add_partial_enumeration (pdi
, cu
);
3868 case DW_TAG_base_type
:
3869 case DW_TAG_subrange_type
:
3870 /* File scope base type definitions are added to the partial
3872 add_partial_symbol (pdi
, cu
);
3874 case DW_TAG_namespace
:
3875 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3878 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3885 /* If the die has a sibling, skip to the sibling. */
3887 pdi
= pdi
->die_sibling
;
3891 /* Functions used to compute the fully scoped name of a partial DIE.
3893 Normally, this is simple. For C++, the parent DIE's fully scoped
3894 name is concatenated with "::" and the partial DIE's name. For
3895 Java, the same thing occurs except that "." is used instead of "::".
3896 Enumerators are an exception; they use the scope of their parent
3897 enumeration type, i.e. the name of the enumeration type is not
3898 prepended to the enumerator.
3900 There are two complexities. One is DW_AT_specification; in this
3901 case "parent" means the parent of the target of the specification,
3902 instead of the direct parent of the DIE. The other is compilers
3903 which do not emit DW_TAG_namespace; in this case we try to guess
3904 the fully qualified name of structure types from their members'
3905 linkage names. This must be done using the DIE's children rather
3906 than the children of any DW_AT_specification target. We only need
3907 to do this for structures at the top level, i.e. if the target of
3908 any DW_AT_specification (if any; otherwise the DIE itself) does not
3911 /* Compute the scope prefix associated with PDI's parent, in
3912 compilation unit CU. The result will be allocated on CU's
3913 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3914 field. NULL is returned if no prefix is necessary. */
3916 partial_die_parent_scope (struct partial_die_info
*pdi
,
3917 struct dwarf2_cu
*cu
)
3919 char *grandparent_scope
;
3920 struct partial_die_info
*parent
, *real_pdi
;
3922 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3923 then this means the parent of the specification DIE. */
3926 while (real_pdi
->has_specification
)
3927 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3929 parent
= real_pdi
->die_parent
;
3933 if (parent
->scope_set
)
3934 return parent
->scope
;
3936 fixup_partial_die (parent
, cu
);
3938 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3940 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3941 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3942 Work around this problem here. */
3943 if (cu
->language
== language_cplus
3944 && parent
->tag
== DW_TAG_namespace
3945 && strcmp (parent
->name
, "::") == 0
3946 && grandparent_scope
== NULL
)
3948 parent
->scope
= NULL
;
3949 parent
->scope_set
= 1;
3953 if (pdi
->tag
== DW_TAG_enumerator
)
3954 /* Enumerators should not get the name of the enumeration as a prefix. */
3955 parent
->scope
= grandparent_scope
;
3956 else if (parent
->tag
== DW_TAG_namespace
3957 || parent
->tag
== DW_TAG_module
3958 || parent
->tag
== DW_TAG_structure_type
3959 || parent
->tag
== DW_TAG_class_type
3960 || parent
->tag
== DW_TAG_interface_type
3961 || parent
->tag
== DW_TAG_union_type
3962 || parent
->tag
== DW_TAG_enumeration_type
)
3964 if (grandparent_scope
== NULL
)
3965 parent
->scope
= parent
->name
;
3967 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3969 parent
->name
, 0, cu
);
3973 /* FIXME drow/2004-04-01: What should we be doing with
3974 function-local names? For partial symbols, we should probably be
3976 complaint (&symfile_complaints
,
3977 _("unhandled containing DIE tag %d for DIE at %d"),
3978 parent
->tag
, pdi
->offset
);
3979 parent
->scope
= grandparent_scope
;
3982 parent
->scope_set
= 1;
3983 return parent
->scope
;
3986 /* Return the fully scoped name associated with PDI, from compilation unit
3987 CU. The result will be allocated with malloc. */
3989 partial_die_full_name (struct partial_die_info
*pdi
,
3990 struct dwarf2_cu
*cu
)
3994 /* If this is a template instantiation, we can not work out the
3995 template arguments from partial DIEs. So, unfortunately, we have
3996 to go through the full DIEs. At least any work we do building
3997 types here will be reused if full symbols are loaded later. */
3998 if (pdi
->has_template_arguments
)
4000 fixup_partial_die (pdi
, cu
);
4002 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4004 struct die_info
*die
;
4005 struct attribute attr
;
4006 struct dwarf2_cu
*ref_cu
= cu
;
4009 attr
.form
= DW_FORM_ref_addr
;
4010 attr
.u
.addr
= pdi
->offset
;
4011 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4013 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4017 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4018 if (parent_scope
== NULL
)
4021 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4025 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4027 struct objfile
*objfile
= cu
->objfile
;
4029 char *actual_name
= NULL
;
4030 const struct partial_symbol
*psym
= NULL
;
4032 int built_actual_name
= 0;
4034 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4036 actual_name
= partial_die_full_name (pdi
, cu
);
4038 built_actual_name
= 1;
4040 if (actual_name
== NULL
)
4041 actual_name
= pdi
->name
;
4045 case DW_TAG_subprogram
:
4046 if (pdi
->is_external
|| cu
->language
== language_ada
)
4048 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4049 of the global scope. But in Ada, we want to be able to access
4050 nested procedures globally. So all Ada subprograms are stored
4051 in the global scope. */
4052 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4053 mst_text, objfile); */
4054 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4056 VAR_DOMAIN
, LOC_BLOCK
,
4057 &objfile
->global_psymbols
,
4058 0, pdi
->lowpc
+ baseaddr
,
4059 cu
->language
, objfile
);
4063 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4064 mst_file_text, objfile); */
4065 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4067 VAR_DOMAIN
, LOC_BLOCK
,
4068 &objfile
->static_psymbols
,
4069 0, pdi
->lowpc
+ baseaddr
,
4070 cu
->language
, objfile
);
4073 case DW_TAG_constant
:
4075 struct psymbol_allocation_list
*list
;
4077 if (pdi
->is_external
)
4078 list
= &objfile
->global_psymbols
;
4080 list
= &objfile
->static_psymbols
;
4081 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4082 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4083 list
, 0, 0, cu
->language
, objfile
);
4086 case DW_TAG_variable
:
4088 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4092 && !dwarf2_per_objfile
->has_section_at_zero
)
4094 /* A global or static variable may also have been stripped
4095 out by the linker if unused, in which case its address
4096 will be nullified; do not add such variables into partial
4097 symbol table then. */
4099 else if (pdi
->is_external
)
4102 Don't enter into the minimal symbol tables as there is
4103 a minimal symbol table entry from the ELF symbols already.
4104 Enter into partial symbol table if it has a location
4105 descriptor or a type.
4106 If the location descriptor is missing, new_symbol will create
4107 a LOC_UNRESOLVED symbol, the address of the variable will then
4108 be determined from the minimal symbol table whenever the variable
4110 The address for the partial symbol table entry is not
4111 used by GDB, but it comes in handy for debugging partial symbol
4114 if (pdi
->locdesc
|| pdi
->has_type
)
4115 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4117 VAR_DOMAIN
, LOC_STATIC
,
4118 &objfile
->global_psymbols
,
4120 cu
->language
, objfile
);
4124 /* Static Variable. Skip symbols without location descriptors. */
4125 if (pdi
->locdesc
== NULL
)
4127 if (built_actual_name
)
4128 xfree (actual_name
);
4131 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4132 mst_file_data, objfile); */
4133 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4135 VAR_DOMAIN
, LOC_STATIC
,
4136 &objfile
->static_psymbols
,
4138 cu
->language
, objfile
);
4141 case DW_TAG_typedef
:
4142 case DW_TAG_base_type
:
4143 case DW_TAG_subrange_type
:
4144 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4146 VAR_DOMAIN
, LOC_TYPEDEF
,
4147 &objfile
->static_psymbols
,
4148 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4150 case DW_TAG_namespace
:
4151 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4153 VAR_DOMAIN
, LOC_TYPEDEF
,
4154 &objfile
->global_psymbols
,
4155 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4157 case DW_TAG_class_type
:
4158 case DW_TAG_interface_type
:
4159 case DW_TAG_structure_type
:
4160 case DW_TAG_union_type
:
4161 case DW_TAG_enumeration_type
:
4162 /* Skip external references. The DWARF standard says in the section
4163 about "Structure, Union, and Class Type Entries": "An incomplete
4164 structure, union or class type is represented by a structure,
4165 union or class entry that does not have a byte size attribute
4166 and that has a DW_AT_declaration attribute." */
4167 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4169 if (built_actual_name
)
4170 xfree (actual_name
);
4174 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4175 static vs. global. */
4176 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4178 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4179 (cu
->language
== language_cplus
4180 || cu
->language
== language_java
)
4181 ? &objfile
->global_psymbols
4182 : &objfile
->static_psymbols
,
4183 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4186 case DW_TAG_enumerator
:
4187 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4189 VAR_DOMAIN
, LOC_CONST
,
4190 (cu
->language
== language_cplus
4191 || cu
->language
== language_java
)
4192 ? &objfile
->global_psymbols
4193 : &objfile
->static_psymbols
,
4194 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4200 if (built_actual_name
)
4201 xfree (actual_name
);
4204 /* Read a partial die corresponding to a namespace; also, add a symbol
4205 corresponding to that namespace to the symbol table. NAMESPACE is
4206 the name of the enclosing namespace. */
4209 add_partial_namespace (struct partial_die_info
*pdi
,
4210 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4211 int need_pc
, struct dwarf2_cu
*cu
)
4213 /* Add a symbol for the namespace. */
4215 add_partial_symbol (pdi
, cu
);
4217 /* Now scan partial symbols in that namespace. */
4219 if (pdi
->has_children
)
4220 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4223 /* Read a partial die corresponding to a Fortran module. */
4226 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4227 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4229 /* Now scan partial symbols in that module. */
4231 if (pdi
->has_children
)
4232 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4235 /* Read a partial die corresponding to a subprogram and create a partial
4236 symbol for that subprogram. When the CU language allows it, this
4237 routine also defines a partial symbol for each nested subprogram
4238 that this subprogram contains.
4240 DIE my also be a lexical block, in which case we simply search
4241 recursively for suprograms defined inside that lexical block.
4242 Again, this is only performed when the CU language allows this
4243 type of definitions. */
4246 add_partial_subprogram (struct partial_die_info
*pdi
,
4247 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4248 int need_pc
, struct dwarf2_cu
*cu
)
4250 if (pdi
->tag
== DW_TAG_subprogram
)
4252 if (pdi
->has_pc_info
)
4254 if (pdi
->lowpc
< *lowpc
)
4255 *lowpc
= pdi
->lowpc
;
4256 if (pdi
->highpc
> *highpc
)
4257 *highpc
= pdi
->highpc
;
4261 struct objfile
*objfile
= cu
->objfile
;
4263 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4264 SECT_OFF_TEXT (objfile
));
4265 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4266 pdi
->lowpc
+ baseaddr
,
4267 pdi
->highpc
- 1 + baseaddr
,
4268 cu
->per_cu
->v
.psymtab
);
4270 if (!pdi
->is_declaration
)
4271 /* Ignore subprogram DIEs that do not have a name, they are
4272 illegal. Do not emit a complaint at this point, we will
4273 do so when we convert this psymtab into a symtab. */
4275 add_partial_symbol (pdi
, cu
);
4279 if (! pdi
->has_children
)
4282 if (cu
->language
== language_ada
)
4284 pdi
= pdi
->die_child
;
4287 fixup_partial_die (pdi
, cu
);
4288 if (pdi
->tag
== DW_TAG_subprogram
4289 || pdi
->tag
== DW_TAG_lexical_block
)
4290 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4291 pdi
= pdi
->die_sibling
;
4296 /* Read a partial die corresponding to an enumeration type. */
4299 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4300 struct dwarf2_cu
*cu
)
4302 struct partial_die_info
*pdi
;
4304 if (enum_pdi
->name
!= NULL
)
4305 add_partial_symbol (enum_pdi
, cu
);
4307 pdi
= enum_pdi
->die_child
;
4310 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4311 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4313 add_partial_symbol (pdi
, cu
);
4314 pdi
= pdi
->die_sibling
;
4318 /* Return the initial uleb128 in the die at INFO_PTR. */
4321 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4323 unsigned int bytes_read
;
4325 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4328 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4329 Return the corresponding abbrev, or NULL if the number is zero (indicating
4330 an empty DIE). In either case *BYTES_READ will be set to the length of
4331 the initial number. */
4333 static struct abbrev_info
*
4334 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4335 struct dwarf2_cu
*cu
)
4337 bfd
*abfd
= cu
->objfile
->obfd
;
4338 unsigned int abbrev_number
;
4339 struct abbrev_info
*abbrev
;
4341 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4343 if (abbrev_number
== 0)
4346 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4349 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4350 abbrev_number
, bfd_get_filename (abfd
));
4356 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4357 Returns a pointer to the end of a series of DIEs, terminated by an empty
4358 DIE. Any children of the skipped DIEs will also be skipped. */
4361 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4363 struct abbrev_info
*abbrev
;
4364 unsigned int bytes_read
;
4368 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4370 return info_ptr
+ bytes_read
;
4372 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4376 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4377 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4378 abbrev corresponding to that skipped uleb128 should be passed in
4379 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4383 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4384 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4386 unsigned int bytes_read
;
4387 struct attribute attr
;
4388 bfd
*abfd
= cu
->objfile
->obfd
;
4389 unsigned int form
, i
;
4391 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4393 /* The only abbrev we care about is DW_AT_sibling. */
4394 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4396 read_attribute (&attr
, &abbrev
->attrs
[i
],
4397 abfd
, info_ptr
, cu
);
4398 if (attr
.form
== DW_FORM_ref_addr
)
4399 complaint (&symfile_complaints
,
4400 _("ignoring absolute DW_AT_sibling"));
4402 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4405 /* If it isn't DW_AT_sibling, skip this attribute. */
4406 form
= abbrev
->attrs
[i
].form
;
4410 case DW_FORM_ref_addr
:
4411 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4412 and later it is offset sized. */
4413 if (cu
->header
.version
== 2)
4414 info_ptr
+= cu
->header
.addr_size
;
4416 info_ptr
+= cu
->header
.offset_size
;
4419 info_ptr
+= cu
->header
.addr_size
;
4426 case DW_FORM_flag_present
:
4438 case DW_FORM_ref_sig8
:
4441 case DW_FORM_string
:
4442 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4443 info_ptr
+= bytes_read
;
4445 case DW_FORM_sec_offset
:
4447 info_ptr
+= cu
->header
.offset_size
;
4449 case DW_FORM_exprloc
:
4451 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4452 info_ptr
+= bytes_read
;
4454 case DW_FORM_block1
:
4455 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4457 case DW_FORM_block2
:
4458 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4460 case DW_FORM_block4
:
4461 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4465 case DW_FORM_ref_udata
:
4466 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4468 case DW_FORM_indirect
:
4469 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4470 info_ptr
+= bytes_read
;
4471 /* We need to continue parsing from here, so just go back to
4473 goto skip_attribute
;
4476 error (_("Dwarf Error: Cannot handle %s "
4477 "in DWARF reader [in module %s]"),
4478 dwarf_form_name (form
),
4479 bfd_get_filename (abfd
));
4483 if (abbrev
->has_children
)
4484 return skip_children (buffer
, info_ptr
, cu
);
4489 /* Locate ORIG_PDI's sibling.
4490 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4494 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4495 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4496 bfd
*abfd
, struct dwarf2_cu
*cu
)
4498 /* Do we know the sibling already? */
4500 if (orig_pdi
->sibling
)
4501 return orig_pdi
->sibling
;
4503 /* Are there any children to deal with? */
4505 if (!orig_pdi
->has_children
)
4508 /* Skip the children the long way. */
4510 return skip_children (buffer
, info_ptr
, cu
);
4513 /* Expand this partial symbol table into a full symbol table. */
4516 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4522 warning (_("bug: psymtab for %s is already read in."),
4529 printf_filtered (_("Reading in symbols for %s..."),
4531 gdb_flush (gdb_stdout
);
4534 /* Restore our global data. */
4535 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4536 dwarf2_objfile_data_key
);
4538 /* If this psymtab is constructed from a debug-only objfile, the
4539 has_section_at_zero flag will not necessarily be correct. We
4540 can get the correct value for this flag by looking at the data
4541 associated with the (presumably stripped) associated objfile. */
4542 if (pst
->objfile
->separate_debug_objfile_backlink
)
4544 struct dwarf2_per_objfile
*dpo_backlink
4545 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4546 dwarf2_objfile_data_key
);
4548 dwarf2_per_objfile
->has_section_at_zero
4549 = dpo_backlink
->has_section_at_zero
;
4552 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4554 psymtab_to_symtab_1 (pst
);
4556 /* Finish up the debug error message. */
4558 printf_filtered (_("done.\n"));
4563 /* Add PER_CU to the queue. */
4566 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4568 struct dwarf2_queue_item
*item
;
4571 item
= xmalloc (sizeof (*item
));
4572 item
->per_cu
= per_cu
;
4575 if (dwarf2_queue
== NULL
)
4576 dwarf2_queue
= item
;
4578 dwarf2_queue_tail
->next
= item
;
4580 dwarf2_queue_tail
= item
;
4583 /* Process the queue. */
4586 process_queue (struct objfile
*objfile
)
4588 struct dwarf2_queue_item
*item
, *next_item
;
4590 /* The queue starts out with one item, but following a DIE reference
4591 may load a new CU, adding it to the end of the queue. */
4592 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4594 if (dwarf2_per_objfile
->using_index
4595 ? !item
->per_cu
->v
.quick
->symtab
4596 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4597 process_full_comp_unit (item
->per_cu
);
4599 item
->per_cu
->queued
= 0;
4600 next_item
= item
->next
;
4604 dwarf2_queue_tail
= NULL
;
4607 /* Free all allocated queue entries. This function only releases anything if
4608 an error was thrown; if the queue was processed then it would have been
4609 freed as we went along. */
4612 dwarf2_release_queue (void *dummy
)
4614 struct dwarf2_queue_item
*item
, *last
;
4616 item
= dwarf2_queue
;
4619 /* Anything still marked queued is likely to be in an
4620 inconsistent state, so discard it. */
4621 if (item
->per_cu
->queued
)
4623 if (item
->per_cu
->cu
!= NULL
)
4624 free_one_cached_comp_unit (item
->per_cu
->cu
);
4625 item
->per_cu
->queued
= 0;
4633 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4636 /* Read in full symbols for PST, and anything it depends on. */
4639 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4641 struct dwarf2_per_cu_data
*per_cu
;
4642 struct cleanup
*back_to
;
4645 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4646 if (!pst
->dependencies
[i
]->readin
)
4648 /* Inform about additional files that need to be read in. */
4651 /* FIXME: i18n: Need to make this a single string. */
4652 fputs_filtered (" ", gdb_stdout
);
4654 fputs_filtered ("and ", gdb_stdout
);
4656 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4657 wrap_here (""); /* Flush output. */
4658 gdb_flush (gdb_stdout
);
4660 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4663 per_cu
= pst
->read_symtab_private
;
4667 /* It's an include file, no symbols to read for it.
4668 Everything is in the parent symtab. */
4673 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4676 /* Load the DIEs associated with PER_CU into memory. */
4679 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4680 struct objfile
*objfile
)
4682 bfd
*abfd
= objfile
->obfd
;
4683 struct dwarf2_cu
*cu
;
4684 unsigned int offset
;
4685 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4686 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4687 struct attribute
*attr
;
4690 gdb_assert (! per_cu
->debug_type_section
);
4692 /* Set local variables from the partial symbol table info. */
4693 offset
= per_cu
->offset
;
4695 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4696 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4697 beg_of_comp_unit
= info_ptr
;
4699 if (per_cu
->cu
== NULL
)
4701 cu
= xmalloc (sizeof (*cu
));
4702 init_one_comp_unit (cu
, objfile
);
4706 /* If an error occurs while loading, release our storage. */
4707 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4709 /* Read in the comp_unit header. */
4710 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4712 /* Skip dummy compilation units. */
4713 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4714 + dwarf2_per_objfile
->info
.size
)
4715 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4717 do_cleanups (free_cu_cleanup
);
4721 /* Complete the cu_header. */
4722 cu
->header
.offset
= offset
;
4723 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4725 /* Read the abbrevs for this compilation unit. */
4726 dwarf2_read_abbrevs (abfd
, cu
);
4727 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4729 /* Link this compilation unit into the compilation unit tree. */
4731 cu
->per_cu
= per_cu
;
4733 /* Link this CU into read_in_chain. */
4734 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4735 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4740 info_ptr
+= cu
->header
.first_die_offset
;
4743 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4745 /* We try not to read any attributes in this function, because not
4746 all objfiles needed for references have been loaded yet, and symbol
4747 table processing isn't initialized. But we have to set the CU language,
4748 or we won't be able to build types correctly. */
4749 prepare_one_comp_unit (cu
, cu
->dies
);
4751 /* Similarly, if we do not read the producer, we can not apply
4752 producer-specific interpretation. */
4753 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4755 cu
->producer
= DW_STRING (attr
);
4759 do_cleanups (free_abbrevs_cleanup
);
4761 /* We've successfully allocated this compilation unit. Let our
4762 caller clean it up when finished with it. */
4763 discard_cleanups (free_cu_cleanup
);
4767 /* Add a DIE to the delayed physname list. */
4770 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4771 const char *name
, struct die_info
*die
,
4772 struct dwarf2_cu
*cu
)
4774 struct delayed_method_info mi
;
4776 mi
.fnfield_index
= fnfield_index
;
4780 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4783 /* A cleanup for freeing the delayed method list. */
4786 free_delayed_list (void *ptr
)
4788 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4789 if (cu
->method_list
!= NULL
)
4791 VEC_free (delayed_method_info
, cu
->method_list
);
4792 cu
->method_list
= NULL
;
4796 /* Compute the physnames of any methods on the CU's method list.
4798 The computation of method physnames is delayed in order to avoid the
4799 (bad) condition that one of the method's formal parameters is of an as yet
4803 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4806 struct delayed_method_info
*mi
;
4807 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4809 const char *physname
;
4810 struct fn_fieldlist
*fn_flp
4811 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4812 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4813 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4817 /* Generate full symbol information for PST and CU, whose DIEs have
4818 already been loaded into memory. */
4821 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4823 struct dwarf2_cu
*cu
= per_cu
->cu
;
4824 struct objfile
*objfile
= per_cu
->objfile
;
4825 CORE_ADDR lowpc
, highpc
;
4826 struct symtab
*symtab
;
4827 struct cleanup
*back_to
, *delayed_list_cleanup
;
4830 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4833 back_to
= make_cleanup (really_free_pendings
, NULL
);
4834 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4836 cu
->list_in_scope
= &file_symbols
;
4838 /* Do line number decoding in read_file_scope () */
4839 process_die (cu
->dies
, cu
);
4841 /* Now that we have processed all the DIEs in the CU, all the types
4842 should be complete, and it should now be safe to compute all of the
4844 compute_delayed_physnames (cu
);
4845 do_cleanups (delayed_list_cleanup
);
4847 /* Some compilers don't define a DW_AT_high_pc attribute for the
4848 compilation unit. If the DW_AT_high_pc is missing, synthesize
4849 it, by scanning the DIE's below the compilation unit. */
4850 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4852 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4856 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4858 /* Set symtab language to language from DW_AT_language. If the
4859 compilation is from a C file generated by language preprocessors, do
4860 not set the language if it was already deduced by start_subfile. */
4861 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4862 symtab
->language
= cu
->language
;
4864 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4865 produce DW_AT_location with location lists but it can be possibly
4866 invalid without -fvar-tracking.
4868 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4869 needed, it would be wrong due to missing DW_AT_producer there.
4871 Still one can confuse GDB by using non-standard GCC compilation
4872 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4874 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4875 symtab
->locations_valid
= 1;
4877 if (gcc_4_minor
>= 5)
4878 symtab
->epilogue_unwind_valid
= 1;
4880 symtab
->call_site_htab
= cu
->call_site_htab
;
4883 if (dwarf2_per_objfile
->using_index
)
4884 per_cu
->v
.quick
->symtab
= symtab
;
4887 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4888 pst
->symtab
= symtab
;
4892 do_cleanups (back_to
);
4895 /* Process a die and its children. */
4898 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4902 case DW_TAG_padding
:
4904 case DW_TAG_compile_unit
:
4905 read_file_scope (die
, cu
);
4907 case DW_TAG_type_unit
:
4908 read_type_unit_scope (die
, cu
);
4910 case DW_TAG_subprogram
:
4911 case DW_TAG_inlined_subroutine
:
4912 read_func_scope (die
, cu
);
4914 case DW_TAG_lexical_block
:
4915 case DW_TAG_try_block
:
4916 case DW_TAG_catch_block
:
4917 read_lexical_block_scope (die
, cu
);
4919 case DW_TAG_GNU_call_site
:
4920 read_call_site_scope (die
, cu
);
4922 case DW_TAG_class_type
:
4923 case DW_TAG_interface_type
:
4924 case DW_TAG_structure_type
:
4925 case DW_TAG_union_type
:
4926 process_structure_scope (die
, cu
);
4928 case DW_TAG_enumeration_type
:
4929 process_enumeration_scope (die
, cu
);
4932 /* These dies have a type, but processing them does not create
4933 a symbol or recurse to process the children. Therefore we can
4934 read them on-demand through read_type_die. */
4935 case DW_TAG_subroutine_type
:
4936 case DW_TAG_set_type
:
4937 case DW_TAG_array_type
:
4938 case DW_TAG_pointer_type
:
4939 case DW_TAG_ptr_to_member_type
:
4940 case DW_TAG_reference_type
:
4941 case DW_TAG_string_type
:
4944 case DW_TAG_base_type
:
4945 case DW_TAG_subrange_type
:
4946 case DW_TAG_typedef
:
4947 /* Add a typedef symbol for the type definition, if it has a
4949 new_symbol (die
, read_type_die (die
, cu
), cu
);
4951 case DW_TAG_common_block
:
4952 read_common_block (die
, cu
);
4954 case DW_TAG_common_inclusion
:
4956 case DW_TAG_namespace
:
4957 processing_has_namespace_info
= 1;
4958 read_namespace (die
, cu
);
4961 processing_has_namespace_info
= 1;
4962 read_module (die
, cu
);
4964 case DW_TAG_imported_declaration
:
4965 case DW_TAG_imported_module
:
4966 processing_has_namespace_info
= 1;
4967 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4968 || cu
->language
!= language_fortran
))
4969 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4970 dwarf_tag_name (die
->tag
));
4971 read_import_statement (die
, cu
);
4974 new_symbol (die
, NULL
, cu
);
4979 /* A helper function for dwarf2_compute_name which determines whether DIE
4980 needs to have the name of the scope prepended to the name listed in the
4984 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4986 struct attribute
*attr
;
4990 case DW_TAG_namespace
:
4991 case DW_TAG_typedef
:
4992 case DW_TAG_class_type
:
4993 case DW_TAG_interface_type
:
4994 case DW_TAG_structure_type
:
4995 case DW_TAG_union_type
:
4996 case DW_TAG_enumeration_type
:
4997 case DW_TAG_enumerator
:
4998 case DW_TAG_subprogram
:
5002 case DW_TAG_variable
:
5003 case DW_TAG_constant
:
5004 /* We only need to prefix "globally" visible variables. These include
5005 any variable marked with DW_AT_external or any variable that
5006 lives in a namespace. [Variables in anonymous namespaces
5007 require prefixing, but they are not DW_AT_external.] */
5009 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5011 struct dwarf2_cu
*spec_cu
= cu
;
5013 return die_needs_namespace (die_specification (die
, &spec_cu
),
5017 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5018 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5019 && die
->parent
->tag
!= DW_TAG_module
)
5021 /* A variable in a lexical block of some kind does not need a
5022 namespace, even though in C++ such variables may be external
5023 and have a mangled name. */
5024 if (die
->parent
->tag
== DW_TAG_lexical_block
5025 || die
->parent
->tag
== DW_TAG_try_block
5026 || die
->parent
->tag
== DW_TAG_catch_block
5027 || die
->parent
->tag
== DW_TAG_subprogram
)
5036 /* Retrieve the last character from a mem_file. */
5039 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5041 char *last_char_p
= (char *) object
;
5044 *last_char_p
= buffer
[length
- 1];
5047 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5048 compute the physname for the object, which include a method's
5049 formal parameters (C++/Java) and return type (Java).
5051 For Ada, return the DIE's linkage name rather than the fully qualified
5052 name. PHYSNAME is ignored..
5054 The result is allocated on the objfile_obstack and canonicalized. */
5057 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5061 name
= dwarf2_name (die
, cu
);
5063 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5064 compute it by typename_concat inside GDB. */
5065 if (cu
->language
== language_ada
5066 || (cu
->language
== language_fortran
&& physname
))
5068 /* For Ada unit, we prefer the linkage name over the name, as
5069 the former contains the exported name, which the user expects
5070 to be able to reference. Ideally, we want the user to be able
5071 to reference this entity using either natural or linkage name,
5072 but we haven't started looking at this enhancement yet. */
5073 struct attribute
*attr
;
5075 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5077 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5078 if (attr
&& DW_STRING (attr
))
5079 return DW_STRING (attr
);
5082 /* These are the only languages we know how to qualify names in. */
5084 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5085 || cu
->language
== language_fortran
))
5087 if (die_needs_namespace (die
, cu
))
5091 struct ui_file
*buf
;
5093 prefix
= determine_prefix (die
, cu
);
5094 buf
= mem_fileopen ();
5095 if (*prefix
!= '\0')
5097 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5100 fputs_unfiltered (prefixed_name
, buf
);
5101 xfree (prefixed_name
);
5104 fputs_unfiltered (name
, buf
);
5106 /* Template parameters may be specified in the DIE's DW_AT_name, or
5107 as children with DW_TAG_template_type_param or
5108 DW_TAG_value_type_param. If the latter, add them to the name
5109 here. If the name already has template parameters, then
5110 skip this step; some versions of GCC emit both, and
5111 it is more efficient to use the pre-computed name.
5113 Something to keep in mind about this process: it is very
5114 unlikely, or in some cases downright impossible, to produce
5115 something that will match the mangled name of a function.
5116 If the definition of the function has the same debug info,
5117 we should be able to match up with it anyway. But fallbacks
5118 using the minimal symbol, for instance to find a method
5119 implemented in a stripped copy of libstdc++, will not work.
5120 If we do not have debug info for the definition, we will have to
5121 match them up some other way.
5123 When we do name matching there is a related problem with function
5124 templates; two instantiated function templates are allowed to
5125 differ only by their return types, which we do not add here. */
5127 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5129 struct attribute
*attr
;
5130 struct die_info
*child
;
5133 die
->building_fullname
= 1;
5135 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5140 struct dwarf2_locexpr_baton
*baton
;
5143 if (child
->tag
!= DW_TAG_template_type_param
5144 && child
->tag
!= DW_TAG_template_value_param
)
5149 fputs_unfiltered ("<", buf
);
5153 fputs_unfiltered (", ", buf
);
5155 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5158 complaint (&symfile_complaints
,
5159 _("template parameter missing DW_AT_type"));
5160 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5163 type
= die_type (child
, cu
);
5165 if (child
->tag
== DW_TAG_template_type_param
)
5167 c_print_type (type
, "", buf
, -1, 0);
5171 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5174 complaint (&symfile_complaints
,
5175 _("template parameter missing "
5176 "DW_AT_const_value"));
5177 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5181 dwarf2_const_value_attr (attr
, type
, name
,
5182 &cu
->comp_unit_obstack
, cu
,
5183 &value
, &bytes
, &baton
);
5185 if (TYPE_NOSIGN (type
))
5186 /* GDB prints characters as NUMBER 'CHAR'. If that's
5187 changed, this can use value_print instead. */
5188 c_printchar (value
, type
, buf
);
5191 struct value_print_options opts
;
5194 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5198 else if (bytes
!= NULL
)
5200 v
= allocate_value (type
);
5201 memcpy (value_contents_writeable (v
), bytes
,
5202 TYPE_LENGTH (type
));
5205 v
= value_from_longest (type
, value
);
5207 /* Specify decimal so that we do not depend on
5209 get_formatted_print_options (&opts
, 'd');
5211 value_print (v
, buf
, &opts
);
5217 die
->building_fullname
= 0;
5221 /* Close the argument list, with a space if necessary
5222 (nested templates). */
5223 char last_char
= '\0';
5224 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5225 if (last_char
== '>')
5226 fputs_unfiltered (" >", buf
);
5228 fputs_unfiltered (">", buf
);
5232 /* For Java and C++ methods, append formal parameter type
5233 information, if PHYSNAME. */
5235 if (physname
&& die
->tag
== DW_TAG_subprogram
5236 && (cu
->language
== language_cplus
5237 || cu
->language
== language_java
))
5239 struct type
*type
= read_type_die (die
, cu
);
5241 c_type_print_args (type
, buf
, 1, cu
->language
);
5243 if (cu
->language
== language_java
)
5245 /* For java, we must append the return type to method
5247 if (die
->tag
== DW_TAG_subprogram
)
5248 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5251 else if (cu
->language
== language_cplus
)
5253 /* Assume that an artificial first parameter is
5254 "this", but do not crash if it is not. RealView
5255 marks unnamed (and thus unused) parameters as
5256 artificial; there is no way to differentiate
5258 if (TYPE_NFIELDS (type
) > 0
5259 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5260 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5261 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5263 fputs_unfiltered (" const", buf
);
5267 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5269 ui_file_delete (buf
);
5271 if (cu
->language
== language_cplus
)
5274 = dwarf2_canonicalize_name (name
, cu
,
5275 &cu
->objfile
->objfile_obstack
);
5286 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5287 If scope qualifiers are appropriate they will be added. The result
5288 will be allocated on the objfile_obstack, or NULL if the DIE does
5289 not have a name. NAME may either be from a previous call to
5290 dwarf2_name or NULL.
5292 The output string will be canonicalized (if C++/Java). */
5295 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5297 return dwarf2_compute_name (name
, die
, cu
, 0);
5300 /* Construct a physname for the given DIE in CU. NAME may either be
5301 from a previous call to dwarf2_name or NULL. The result will be
5302 allocated on the objfile_objstack or NULL if the DIE does not have a
5305 The output string will be canonicalized (if C++/Java). */
5308 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5310 struct attribute
*attr
;
5311 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5312 struct cleanup
*back_to
;
5315 /* In this case dwarf2_compute_name is just a shortcut not building anything
5317 if (!die_needs_namespace (die
, cu
))
5318 return dwarf2_compute_name (name
, die
, cu
, 1);
5320 back_to
= make_cleanup (null_cleanup
, NULL
);
5322 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5324 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5326 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5328 if (attr
&& DW_STRING (attr
))
5332 mangled
= DW_STRING (attr
);
5334 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5335 type. It is easier for GDB users to search for such functions as
5336 `name(params)' than `long name(params)'. In such case the minimal
5337 symbol names do not match the full symbol names but for template
5338 functions there is never a need to look up their definition from their
5339 declaration so the only disadvantage remains the minimal symbol
5340 variant `long name(params)' does not have the proper inferior type.
5343 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5344 | (cu
->language
== language_java
5345 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5349 make_cleanup (xfree
, demangled
);
5359 if (canon
== NULL
|| check_physname
)
5361 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5363 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5365 /* It may not mean a bug in GDB. The compiler could also
5366 compute DW_AT_linkage_name incorrectly. But in such case
5367 GDB would need to be bug-to-bug compatible. */
5369 complaint (&symfile_complaints
,
5370 _("Computed physname <%s> does not match demangled <%s> "
5371 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5372 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5374 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5375 is available here - over computed PHYSNAME. It is safer
5376 against both buggy GDB and buggy compilers. */
5390 retval
= obsavestring (retval
, strlen (retval
),
5391 &cu
->objfile
->objfile_obstack
);
5393 do_cleanups (back_to
);
5397 /* Read the import statement specified by the given die and record it. */
5400 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5402 struct attribute
*import_attr
;
5403 struct die_info
*imported_die
, *child_die
;
5404 struct dwarf2_cu
*imported_cu
;
5405 const char *imported_name
;
5406 const char *imported_name_prefix
;
5407 const char *canonical_name
;
5408 const char *import_alias
;
5409 const char *imported_declaration
= NULL
;
5410 const char *import_prefix
;
5411 VEC (const_char_ptr
) *excludes
= NULL
;
5412 struct cleanup
*cleanups
;
5416 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5417 if (import_attr
== NULL
)
5419 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5420 dwarf_tag_name (die
->tag
));
5425 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5426 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5427 if (imported_name
== NULL
)
5429 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5431 The import in the following code:
5445 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5446 <52> DW_AT_decl_file : 1
5447 <53> DW_AT_decl_line : 6
5448 <54> DW_AT_import : <0x75>
5449 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5451 <5b> DW_AT_decl_file : 1
5452 <5c> DW_AT_decl_line : 2
5453 <5d> DW_AT_type : <0x6e>
5455 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5456 <76> DW_AT_byte_size : 4
5457 <77> DW_AT_encoding : 5 (signed)
5459 imports the wrong die ( 0x75 instead of 0x58 ).
5460 This case will be ignored until the gcc bug is fixed. */
5464 /* Figure out the local name after import. */
5465 import_alias
= dwarf2_name (die
, cu
);
5467 /* Figure out where the statement is being imported to. */
5468 import_prefix
= determine_prefix (die
, cu
);
5470 /* Figure out what the scope of the imported die is and prepend it
5471 to the name of the imported die. */
5472 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5474 if (imported_die
->tag
!= DW_TAG_namespace
5475 && imported_die
->tag
!= DW_TAG_module
)
5477 imported_declaration
= imported_name
;
5478 canonical_name
= imported_name_prefix
;
5480 else if (strlen (imported_name_prefix
) > 0)
5482 temp
= alloca (strlen (imported_name_prefix
)
5483 + 2 + strlen (imported_name
) + 1);
5484 strcpy (temp
, imported_name_prefix
);
5485 strcat (temp
, "::");
5486 strcat (temp
, imported_name
);
5487 canonical_name
= temp
;
5490 canonical_name
= imported_name
;
5492 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5494 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5495 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5496 child_die
= sibling_die (child_die
))
5498 /* DWARF-4: A Fortran use statement with a “rename list” may be
5499 represented by an imported module entry with an import attribute
5500 referring to the module and owned entries corresponding to those
5501 entities that are renamed as part of being imported. */
5503 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5505 complaint (&symfile_complaints
,
5506 _("child DW_TAG_imported_declaration expected "
5507 "- DIE at 0x%x [in module %s]"),
5508 child_die
->offset
, cu
->objfile
->name
);
5512 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5513 if (import_attr
== NULL
)
5515 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5516 dwarf_tag_name (child_die
->tag
));
5521 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5523 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5524 if (imported_name
== NULL
)
5526 complaint (&symfile_complaints
,
5527 _("child DW_TAG_imported_declaration has unknown "
5528 "imported name - DIE at 0x%x [in module %s]"),
5529 child_die
->offset
, cu
->objfile
->name
);
5533 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5535 process_die (child_die
, cu
);
5538 cp_add_using_directive (import_prefix
,
5541 imported_declaration
,
5543 &cu
->objfile
->objfile_obstack
);
5545 do_cleanups (cleanups
);
5549 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5551 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5554 /* Cleanup function for read_file_scope. */
5557 free_cu_line_header (void *arg
)
5559 struct dwarf2_cu
*cu
= arg
;
5561 free_line_header (cu
->line_header
);
5562 cu
->line_header
= NULL
;
5566 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5567 char **name
, char **comp_dir
)
5569 struct attribute
*attr
;
5574 /* Find the filename. Do not use dwarf2_name here, since the filename
5575 is not a source language identifier. */
5576 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5579 *name
= DW_STRING (attr
);
5582 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5584 *comp_dir
= DW_STRING (attr
);
5585 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5587 *comp_dir
= ldirname (*name
);
5588 if (*comp_dir
!= NULL
)
5589 make_cleanup (xfree
, *comp_dir
);
5591 if (*comp_dir
!= NULL
)
5593 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5594 directory, get rid of it. */
5595 char *cp
= strchr (*comp_dir
, ':');
5597 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5602 *name
= "<unknown>";
5605 /* Handle DW_AT_stmt_list for a compilation unit. */
5608 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5609 const char *comp_dir
)
5611 struct attribute
*attr
;
5612 struct objfile
*objfile
= cu
->objfile
;
5613 bfd
*abfd
= objfile
->obfd
;
5615 /* Decode line number information if present. We do this before
5616 processing child DIEs, so that the line header table is available
5617 for DW_AT_decl_file. */
5618 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5621 unsigned int line_offset
= DW_UNSND (attr
);
5622 struct line_header
*line_header
5623 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5627 cu
->line_header
= line_header
;
5628 make_cleanup (free_cu_line_header
, cu
);
5629 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5634 /* Process DW_TAG_compile_unit. */
5637 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5639 struct objfile
*objfile
= cu
->objfile
;
5640 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5641 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5642 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5643 struct attribute
*attr
;
5645 char *comp_dir
= NULL
;
5646 struct die_info
*child_die
;
5647 bfd
*abfd
= objfile
->obfd
;
5650 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5652 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5654 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5655 from finish_block. */
5656 if (lowpc
== ((CORE_ADDR
) -1))
5661 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5663 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5666 set_cu_language (DW_UNSND (attr
), cu
);
5669 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5671 cu
->producer
= DW_STRING (attr
);
5673 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5674 standardised yet. As a workaround for the language detection we fall
5675 back to the DW_AT_producer string. */
5676 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5677 cu
->language
= language_opencl
;
5679 /* We assume that we're processing GCC output. */
5680 processing_gcc_compilation
= 2;
5682 processing_has_namespace_info
= 0;
5684 start_symtab (name
, comp_dir
, lowpc
);
5685 record_debugformat ("DWARF 2");
5686 record_producer (cu
->producer
);
5688 initialize_cu_func_list (cu
);
5690 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5692 /* Process all dies in compilation unit. */
5693 if (die
->child
!= NULL
)
5695 child_die
= die
->child
;
5696 while (child_die
&& child_die
->tag
)
5698 process_die (child_die
, cu
);
5699 child_die
= sibling_die (child_die
);
5703 /* Decode macro information, if present. Dwarf 2 macro information
5704 refers to information in the line number info statement program
5705 header, so we can only read it if we've read the header
5707 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5708 if (attr
&& cu
->line_header
)
5710 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5711 complaint (&symfile_complaints
,
5712 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5714 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5716 &dwarf2_per_objfile
->macro
, 1);
5720 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5721 if (attr
&& cu
->line_header
)
5723 unsigned int macro_offset
= DW_UNSND (attr
);
5725 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5727 &dwarf2_per_objfile
->macinfo
, 0);
5730 do_cleanups (back_to
);
5733 /* Process DW_TAG_type_unit.
5734 For TUs we want to skip the first top level sibling if it's not the
5735 actual type being defined by this TU. In this case the first top
5736 level sibling is there to provide context only. */
5739 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5741 struct objfile
*objfile
= cu
->objfile
;
5742 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5744 struct attribute
*attr
;
5746 char *comp_dir
= NULL
;
5747 struct die_info
*child_die
;
5748 bfd
*abfd
= objfile
->obfd
;
5750 /* start_symtab needs a low pc, but we don't really have one.
5751 Do what read_file_scope would do in the absence of such info. */
5752 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5754 /* Find the filename. Do not use dwarf2_name here, since the filename
5755 is not a source language identifier. */
5756 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5758 name
= DW_STRING (attr
);
5760 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5762 comp_dir
= DW_STRING (attr
);
5763 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5765 comp_dir
= ldirname (name
);
5766 if (comp_dir
!= NULL
)
5767 make_cleanup (xfree
, comp_dir
);
5773 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5775 set_cu_language (DW_UNSND (attr
), cu
);
5777 /* This isn't technically needed today. It is done for symmetry
5778 with read_file_scope. */
5779 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5781 cu
->producer
= DW_STRING (attr
);
5783 /* We assume that we're processing GCC output. */
5784 processing_gcc_compilation
= 2;
5786 processing_has_namespace_info
= 0;
5788 start_symtab (name
, comp_dir
, lowpc
);
5789 record_debugformat ("DWARF 2");
5790 record_producer (cu
->producer
);
5792 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5794 /* Process the dies in the type unit. */
5795 if (die
->child
== NULL
)
5797 dump_die_for_error (die
);
5798 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5799 bfd_get_filename (abfd
));
5802 child_die
= die
->child
;
5804 while (child_die
&& child_die
->tag
)
5806 process_die (child_die
, cu
);
5808 child_die
= sibling_die (child_die
);
5811 do_cleanups (back_to
);
5815 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5816 struct dwarf2_cu
*cu
)
5818 struct function_range
*thisfn
;
5820 thisfn
= (struct function_range
*)
5821 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5822 thisfn
->name
= name
;
5823 thisfn
->lowpc
= lowpc
;
5824 thisfn
->highpc
= highpc
;
5825 thisfn
->seen_line
= 0;
5826 thisfn
->next
= NULL
;
5828 if (cu
->last_fn
== NULL
)
5829 cu
->first_fn
= thisfn
;
5831 cu
->last_fn
->next
= thisfn
;
5833 cu
->last_fn
= thisfn
;
5836 /* qsort helper for inherit_abstract_dies. */
5839 unsigned_int_compar (const void *ap
, const void *bp
)
5841 unsigned int a
= *(unsigned int *) ap
;
5842 unsigned int b
= *(unsigned int *) bp
;
5844 return (a
> b
) - (b
> a
);
5847 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5848 Inherit only the children of the DW_AT_abstract_origin DIE not being
5849 already referenced by DW_AT_abstract_origin from the children of the
5853 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5855 struct die_info
*child_die
;
5856 unsigned die_children_count
;
5857 /* CU offsets which were referenced by children of the current DIE. */
5859 unsigned *offsets_end
, *offsetp
;
5860 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5861 struct die_info
*origin_die
;
5862 /* Iterator of the ORIGIN_DIE children. */
5863 struct die_info
*origin_child_die
;
5864 struct cleanup
*cleanups
;
5865 struct attribute
*attr
;
5866 struct dwarf2_cu
*origin_cu
;
5867 struct pending
**origin_previous_list_in_scope
;
5869 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5873 /* Note that following die references may follow to a die in a
5877 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5879 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5881 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5882 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5884 if (die
->tag
!= origin_die
->tag
5885 && !(die
->tag
== DW_TAG_inlined_subroutine
5886 && origin_die
->tag
== DW_TAG_subprogram
))
5887 complaint (&symfile_complaints
,
5888 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5889 die
->offset
, origin_die
->offset
);
5891 child_die
= die
->child
;
5892 die_children_count
= 0;
5893 while (child_die
&& child_die
->tag
)
5895 child_die
= sibling_die (child_die
);
5896 die_children_count
++;
5898 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5899 cleanups
= make_cleanup (xfree
, offsets
);
5901 offsets_end
= offsets
;
5902 child_die
= die
->child
;
5903 while (child_die
&& child_die
->tag
)
5905 /* For each CHILD_DIE, find the corresponding child of
5906 ORIGIN_DIE. If there is more than one layer of
5907 DW_AT_abstract_origin, follow them all; there shouldn't be,
5908 but GCC versions at least through 4.4 generate this (GCC PR
5910 struct die_info
*child_origin_die
= child_die
;
5911 struct dwarf2_cu
*child_origin_cu
= cu
;
5915 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5919 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5923 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5924 counterpart may exist. */
5925 if (child_origin_die
!= child_die
)
5927 if (child_die
->tag
!= child_origin_die
->tag
5928 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5929 && child_origin_die
->tag
== DW_TAG_subprogram
))
5930 complaint (&symfile_complaints
,
5931 _("Child DIE 0x%x and its abstract origin 0x%x have "
5932 "different tags"), child_die
->offset
,
5933 child_origin_die
->offset
);
5934 if (child_origin_die
->parent
!= origin_die
)
5935 complaint (&symfile_complaints
,
5936 _("Child DIE 0x%x and its abstract origin 0x%x have "
5937 "different parents"), child_die
->offset
,
5938 child_origin_die
->offset
);
5940 *offsets_end
++ = child_origin_die
->offset
;
5942 child_die
= sibling_die (child_die
);
5944 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5945 unsigned_int_compar
);
5946 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5947 if (offsetp
[-1] == *offsetp
)
5948 complaint (&symfile_complaints
,
5949 _("Multiple children of DIE 0x%x refer "
5950 "to DIE 0x%x as their abstract origin"),
5951 die
->offset
, *offsetp
);
5954 origin_child_die
= origin_die
->child
;
5955 while (origin_child_die
&& origin_child_die
->tag
)
5957 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5958 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5960 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5962 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5963 process_die (origin_child_die
, origin_cu
);
5965 origin_child_die
= sibling_die (origin_child_die
);
5967 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5969 do_cleanups (cleanups
);
5973 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5975 struct objfile
*objfile
= cu
->objfile
;
5976 struct context_stack
*new;
5979 struct die_info
*child_die
;
5980 struct attribute
*attr
, *call_line
, *call_file
;
5983 struct block
*block
;
5984 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5985 VEC (symbolp
) *template_args
= NULL
;
5986 struct template_symbol
*templ_func
= NULL
;
5990 /* If we do not have call site information, we can't show the
5991 caller of this inlined function. That's too confusing, so
5992 only use the scope for local variables. */
5993 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5994 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5995 if (call_line
== NULL
|| call_file
== NULL
)
5997 read_lexical_block_scope (die
, cu
);
6002 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6004 name
= dwarf2_name (die
, cu
);
6006 /* Ignore functions with missing or empty names. These are actually
6007 illegal according to the DWARF standard. */
6010 complaint (&symfile_complaints
,
6011 _("missing name for subprogram DIE at %d"), die
->offset
);
6015 /* Ignore functions with missing or invalid low and high pc attributes. */
6016 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6018 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6019 if (!attr
|| !DW_UNSND (attr
))
6020 complaint (&symfile_complaints
,
6021 _("cannot get low and high bounds "
6022 "for subprogram DIE at %d"),
6030 /* Record the function range for dwarf_decode_lines. */
6031 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
6033 /* If we have any template arguments, then we must allocate a
6034 different sort of symbol. */
6035 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6037 if (child_die
->tag
== DW_TAG_template_type_param
6038 || child_die
->tag
== DW_TAG_template_value_param
)
6040 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6041 struct template_symbol
);
6042 templ_func
->base
.is_cplus_template_function
= 1;
6047 new = push_context (0, lowpc
);
6048 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6049 (struct symbol
*) templ_func
);
6051 /* If there is a location expression for DW_AT_frame_base, record
6053 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6055 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6056 expression is being recorded directly in the function's symbol
6057 and not in a separate frame-base object. I guess this hack is
6058 to avoid adding some sort of frame-base adjunct/annex to the
6059 function's symbol :-(. The problem with doing this is that it
6060 results in a function symbol with a location expression that
6061 has nothing to do with the location of the function, ouch! The
6062 relationship should be: a function's symbol has-a frame base; a
6063 frame-base has-a location expression. */
6064 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6066 cu
->list_in_scope
= &local_symbols
;
6068 if (die
->child
!= NULL
)
6070 child_die
= die
->child
;
6071 while (child_die
&& child_die
->tag
)
6073 if (child_die
->tag
== DW_TAG_template_type_param
6074 || child_die
->tag
== DW_TAG_template_value_param
)
6076 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6079 VEC_safe_push (symbolp
, template_args
, arg
);
6082 process_die (child_die
, cu
);
6083 child_die
= sibling_die (child_die
);
6087 inherit_abstract_dies (die
, cu
);
6089 /* If we have a DW_AT_specification, we might need to import using
6090 directives from the context of the specification DIE. See the
6091 comment in determine_prefix. */
6092 if (cu
->language
== language_cplus
6093 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6095 struct dwarf2_cu
*spec_cu
= cu
;
6096 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6100 child_die
= spec_die
->child
;
6101 while (child_die
&& child_die
->tag
)
6103 if (child_die
->tag
== DW_TAG_imported_module
)
6104 process_die (child_die
, spec_cu
);
6105 child_die
= sibling_die (child_die
);
6108 /* In some cases, GCC generates specification DIEs that
6109 themselves contain DW_AT_specification attributes. */
6110 spec_die
= die_specification (spec_die
, &spec_cu
);
6114 new = pop_context ();
6115 /* Make a block for the local symbols within. */
6116 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6117 lowpc
, highpc
, objfile
);
6119 /* For C++, set the block's scope. */
6120 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6121 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6122 determine_prefix (die
, cu
),
6123 processing_has_namespace_info
);
6125 /* If we have address ranges, record them. */
6126 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6128 /* Attach template arguments to function. */
6129 if (! VEC_empty (symbolp
, template_args
))
6131 gdb_assert (templ_func
!= NULL
);
6133 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6134 templ_func
->template_arguments
6135 = obstack_alloc (&objfile
->objfile_obstack
,
6136 (templ_func
->n_template_arguments
6137 * sizeof (struct symbol
*)));
6138 memcpy (templ_func
->template_arguments
,
6139 VEC_address (symbolp
, template_args
),
6140 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6141 VEC_free (symbolp
, template_args
);
6144 /* In C++, we can have functions nested inside functions (e.g., when
6145 a function declares a class that has methods). This means that
6146 when we finish processing a function scope, we may need to go
6147 back to building a containing block's symbol lists. */
6148 local_symbols
= new->locals
;
6149 param_symbols
= new->params
;
6150 using_directives
= new->using_directives
;
6152 /* If we've finished processing a top-level function, subsequent
6153 symbols go in the file symbol list. */
6154 if (outermost_context_p ())
6155 cu
->list_in_scope
= &file_symbols
;
6158 /* Process all the DIES contained within a lexical block scope. Start
6159 a new scope, process the dies, and then close the scope. */
6162 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6164 struct objfile
*objfile
= cu
->objfile
;
6165 struct context_stack
*new;
6166 CORE_ADDR lowpc
, highpc
;
6167 struct die_info
*child_die
;
6170 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6172 /* Ignore blocks with missing or invalid low and high pc attributes. */
6173 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6174 as multiple lexical blocks? Handling children in a sane way would
6175 be nasty. Might be easier to properly extend generic blocks to
6177 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6182 push_context (0, lowpc
);
6183 if (die
->child
!= NULL
)
6185 child_die
= die
->child
;
6186 while (child_die
&& child_die
->tag
)
6188 process_die (child_die
, cu
);
6189 child_die
= sibling_die (child_die
);
6192 new = pop_context ();
6194 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6197 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6200 /* Note that recording ranges after traversing children, as we
6201 do here, means that recording a parent's ranges entails
6202 walking across all its children's ranges as they appear in
6203 the address map, which is quadratic behavior.
6205 It would be nicer to record the parent's ranges before
6206 traversing its children, simply overriding whatever you find
6207 there. But since we don't even decide whether to create a
6208 block until after we've traversed its children, that's hard
6210 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6212 local_symbols
= new->locals
;
6213 using_directives
= new->using_directives
;
6216 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6219 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6221 struct objfile
*objfile
= cu
->objfile
;
6222 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6223 CORE_ADDR pc
, baseaddr
;
6224 struct attribute
*attr
;
6225 struct call_site
*call_site
, call_site_local
;
6228 struct die_info
*child_die
;
6230 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6232 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6235 complaint (&symfile_complaints
,
6236 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6237 "DIE 0x%x [in module %s]"),
6238 die
->offset
, cu
->objfile
->name
);
6241 pc
= DW_ADDR (attr
) + baseaddr
;
6243 if (cu
->call_site_htab
== NULL
)
6244 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6245 NULL
, &objfile
->objfile_obstack
,
6246 hashtab_obstack_allocate
, NULL
);
6247 call_site_local
.pc
= pc
;
6248 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6251 complaint (&symfile_complaints
,
6252 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6253 "DIE 0x%x [in module %s]"),
6254 paddress (gdbarch
, pc
), die
->offset
, cu
->objfile
->name
);
6258 /* Count parameters at the caller. */
6261 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6262 child_die
= sibling_die (child_die
))
6264 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6266 complaint (&symfile_complaints
,
6267 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6268 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6269 child_die
->tag
, child_die
->offset
, cu
->objfile
->name
);
6276 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6277 (sizeof (*call_site
)
6278 + (sizeof (*call_site
->parameter
)
6281 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6284 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6286 struct die_info
*func_die
;
6288 /* Skip also over DW_TAG_inlined_subroutine. */
6289 for (func_die
= die
->parent
;
6290 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6291 && func_die
->tag
!= DW_TAG_subroutine_type
;
6292 func_die
= func_die
->parent
);
6294 /* DW_AT_GNU_all_call_sites is a superset
6295 of DW_AT_GNU_all_tail_call_sites. */
6297 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6298 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6300 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6301 not complete. But keep CALL_SITE for look ups via call_site_htab,
6302 both the initial caller containing the real return address PC and
6303 the final callee containing the current PC of a chain of tail
6304 calls do not need to have the tail call list complete. But any
6305 function candidate for a virtual tail call frame searched via
6306 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6307 determined unambiguously. */
6311 struct type
*func_type
= NULL
;
6314 func_type
= get_die_type (func_die
, cu
);
6315 if (func_type
!= NULL
)
6317 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6319 /* Enlist this call site to the function. */
6320 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6321 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6324 complaint (&symfile_complaints
,
6325 _("Cannot find function owning DW_TAG_GNU_call_site "
6326 "DIE 0x%x [in module %s]"),
6327 die
->offset
, cu
->objfile
->name
);
6331 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6333 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6334 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6335 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6336 /* Keep NULL DWARF_BLOCK. */;
6337 else if (attr_form_is_block (attr
))
6339 struct dwarf2_locexpr_baton
*dlbaton
;
6341 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6342 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6343 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6344 dlbaton
->per_cu
= cu
->per_cu
;
6346 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6348 else if (is_ref_attr (attr
))
6350 struct objfile
*objfile
= cu
->objfile
;
6351 struct dwarf2_cu
*target_cu
= cu
;
6352 struct die_info
*target_die
;
6354 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6355 gdb_assert (target_cu
->objfile
== objfile
);
6356 if (die_is_declaration (target_die
, target_cu
))
6358 const char *target_physname
;
6360 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6361 if (target_physname
== NULL
)
6362 complaint (&symfile_complaints
,
6363 _("DW_AT_GNU_call_site_target target DIE has invalid "
6364 "physname, for referencing DIE 0x%x [in module %s]"),
6365 die
->offset
, cu
->objfile
->name
);
6367 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6373 /* DW_AT_entry_pc should be preferred. */
6374 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6375 complaint (&symfile_complaints
,
6376 _("DW_AT_GNU_call_site_target target DIE has invalid "
6377 "low pc, for referencing DIE 0x%x [in module %s]"),
6378 die
->offset
, cu
->objfile
->name
);
6380 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6384 complaint (&symfile_complaints
,
6385 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6386 "block nor reference, for DIE 0x%x [in module %s]"),
6387 die
->offset
, cu
->objfile
->name
);
6389 call_site
->per_cu
= cu
->per_cu
;
6391 for (child_die
= die
->child
;
6392 child_die
&& child_die
->tag
;
6393 child_die
= sibling_die (child_die
))
6395 struct dwarf2_locexpr_baton
*dlbaton
;
6396 struct call_site_parameter
*parameter
;
6398 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6400 /* Already printed the complaint above. */
6404 gdb_assert (call_site
->parameter_count
< nparams
);
6405 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6407 /* DW_AT_location specifies the register number. Value of the data
6408 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6410 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6411 if (!attr
|| !attr_form_is_block (attr
))
6413 complaint (&symfile_complaints
,
6414 _("No DW_FORM_block* DW_AT_location for "
6415 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6416 child_die
->offset
, cu
->objfile
->name
);
6419 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6420 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6421 if (parameter
->dwarf_reg
== -1
6422 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6423 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6424 ¶meter
->fb_offset
))
6426 complaint (&symfile_complaints
,
6427 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6428 "for DW_FORM_block* DW_AT_location for "
6429 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6430 child_die
->offset
, cu
->objfile
->name
);
6434 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6435 if (!attr_form_is_block (attr
))
6437 complaint (&symfile_complaints
,
6438 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6439 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6440 child_die
->offset
, cu
->objfile
->name
);
6443 parameter
->value
= DW_BLOCK (attr
)->data
;
6444 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6446 /* Parameters are not pre-cleared by memset above. */
6447 parameter
->data_value
= NULL
;
6448 parameter
->data_value_size
= 0;
6449 call_site
->parameter_count
++;
6451 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6454 if (!attr_form_is_block (attr
))
6455 complaint (&symfile_complaints
,
6456 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6457 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6458 child_die
->offset
, cu
->objfile
->name
);
6461 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6462 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6468 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6469 Return 1 if the attributes are present and valid, otherwise, return 0.
6470 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6473 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6474 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6475 struct partial_symtab
*ranges_pst
)
6477 struct objfile
*objfile
= cu
->objfile
;
6478 struct comp_unit_head
*cu_header
= &cu
->header
;
6479 bfd
*obfd
= objfile
->obfd
;
6480 unsigned int addr_size
= cu_header
->addr_size
;
6481 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6482 /* Base address selection entry. */
6493 found_base
= cu
->base_known
;
6494 base
= cu
->base_address
;
6496 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6497 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6499 complaint (&symfile_complaints
,
6500 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6504 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6506 /* Read in the largest possible address. */
6507 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6508 if ((marker
& mask
) == mask
)
6510 /* If we found the largest possible address, then
6511 read the base address. */
6512 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6513 buffer
+= 2 * addr_size
;
6514 offset
+= 2 * addr_size
;
6520 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6524 CORE_ADDR range_beginning
, range_end
;
6526 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6527 buffer
+= addr_size
;
6528 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6529 buffer
+= addr_size
;
6530 offset
+= 2 * addr_size
;
6532 /* An end of list marker is a pair of zero addresses. */
6533 if (range_beginning
== 0 && range_end
== 0)
6534 /* Found the end of list entry. */
6537 /* Each base address selection entry is a pair of 2 values.
6538 The first is the largest possible address, the second is
6539 the base address. Check for a base address here. */
6540 if ((range_beginning
& mask
) == mask
)
6542 /* If we found the largest possible address, then
6543 read the base address. */
6544 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6551 /* We have no valid base address for the ranges
6553 complaint (&symfile_complaints
,
6554 _("Invalid .debug_ranges data (no base address)"));
6558 if (range_beginning
> range_end
)
6560 /* Inverted range entries are invalid. */
6561 complaint (&symfile_complaints
,
6562 _("Invalid .debug_ranges data (inverted range)"));
6566 /* Empty range entries have no effect. */
6567 if (range_beginning
== range_end
)
6570 range_beginning
+= base
;
6573 if (ranges_pst
!= NULL
)
6574 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6575 range_beginning
+ baseaddr
,
6576 range_end
- 1 + baseaddr
,
6579 /* FIXME: This is recording everything as a low-high
6580 segment of consecutive addresses. We should have a
6581 data structure for discontiguous block ranges
6585 low
= range_beginning
;
6591 if (range_beginning
< low
)
6592 low
= range_beginning
;
6593 if (range_end
> high
)
6599 /* If the first entry is an end-of-list marker, the range
6600 describes an empty scope, i.e. no instructions. */
6606 *high_return
= high
;
6610 /* Get low and high pc attributes from a die. Return 1 if the attributes
6611 are present and valid, otherwise, return 0. Return -1 if the range is
6612 discontinuous, i.e. derived from DW_AT_ranges information. */
6614 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6615 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6616 struct partial_symtab
*pst
)
6618 struct attribute
*attr
;
6623 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6626 high
= DW_ADDR (attr
);
6627 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6629 low
= DW_ADDR (attr
);
6631 /* Found high w/o low attribute. */
6634 /* Found consecutive range of addresses. */
6639 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6642 /* Value of the DW_AT_ranges attribute is the offset in the
6643 .debug_ranges section. */
6644 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6646 /* Found discontinuous range of addresses. */
6651 /* read_partial_die has also the strict LOW < HIGH requirement. */
6655 /* When using the GNU linker, .gnu.linkonce. sections are used to
6656 eliminate duplicate copies of functions and vtables and such.
6657 The linker will arbitrarily choose one and discard the others.
6658 The AT_*_pc values for such functions refer to local labels in
6659 these sections. If the section from that file was discarded, the
6660 labels are not in the output, so the relocs get a value of 0.
6661 If this is a discarded function, mark the pc bounds as invalid,
6662 so that GDB will ignore it. */
6663 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6672 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6673 its low and high PC addresses. Do nothing if these addresses could not
6674 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6675 and HIGHPC to the high address if greater than HIGHPC. */
6678 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6679 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6680 struct dwarf2_cu
*cu
)
6682 CORE_ADDR low
, high
;
6683 struct die_info
*child
= die
->child
;
6685 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6687 *lowpc
= min (*lowpc
, low
);
6688 *highpc
= max (*highpc
, high
);
6691 /* If the language does not allow nested subprograms (either inside
6692 subprograms or lexical blocks), we're done. */
6693 if (cu
->language
!= language_ada
)
6696 /* Check all the children of the given DIE. If it contains nested
6697 subprograms, then check their pc bounds. Likewise, we need to
6698 check lexical blocks as well, as they may also contain subprogram
6700 while (child
&& child
->tag
)
6702 if (child
->tag
== DW_TAG_subprogram
6703 || child
->tag
== DW_TAG_lexical_block
)
6704 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6705 child
= sibling_die (child
);
6709 /* Get the low and high pc's represented by the scope DIE, and store
6710 them in *LOWPC and *HIGHPC. If the correct values can't be
6711 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6714 get_scope_pc_bounds (struct die_info
*die
,
6715 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6716 struct dwarf2_cu
*cu
)
6718 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6719 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6720 CORE_ADDR current_low
, current_high
;
6722 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6724 best_low
= current_low
;
6725 best_high
= current_high
;
6729 struct die_info
*child
= die
->child
;
6731 while (child
&& child
->tag
)
6733 switch (child
->tag
) {
6734 case DW_TAG_subprogram
:
6735 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6737 case DW_TAG_namespace
:
6739 /* FIXME: carlton/2004-01-16: Should we do this for
6740 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6741 that current GCC's always emit the DIEs corresponding
6742 to definitions of methods of classes as children of a
6743 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6744 the DIEs giving the declarations, which could be
6745 anywhere). But I don't see any reason why the
6746 standards says that they have to be there. */
6747 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6749 if (current_low
!= ((CORE_ADDR
) -1))
6751 best_low
= min (best_low
, current_low
);
6752 best_high
= max (best_high
, current_high
);
6760 child
= sibling_die (child
);
6765 *highpc
= best_high
;
6768 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6771 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6772 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6774 struct attribute
*attr
;
6776 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6779 CORE_ADDR high
= DW_ADDR (attr
);
6781 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6784 CORE_ADDR low
= DW_ADDR (attr
);
6786 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6790 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6793 bfd
*obfd
= cu
->objfile
->obfd
;
6795 /* The value of the DW_AT_ranges attribute is the offset of the
6796 address range list in the .debug_ranges section. */
6797 unsigned long offset
= DW_UNSND (attr
);
6798 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6800 /* For some target architectures, but not others, the
6801 read_address function sign-extends the addresses it returns.
6802 To recognize base address selection entries, we need a
6804 unsigned int addr_size
= cu
->header
.addr_size
;
6805 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6807 /* The base address, to which the next pair is relative. Note
6808 that this 'base' is a DWARF concept: most entries in a range
6809 list are relative, to reduce the number of relocs against the
6810 debugging information. This is separate from this function's
6811 'baseaddr' argument, which GDB uses to relocate debugging
6812 information from a shared library based on the address at
6813 which the library was loaded. */
6814 CORE_ADDR base
= cu
->base_address
;
6815 int base_known
= cu
->base_known
;
6817 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6818 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6820 complaint (&symfile_complaints
,
6821 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6828 unsigned int bytes_read
;
6829 CORE_ADDR start
, end
;
6831 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6832 buffer
+= bytes_read
;
6833 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6834 buffer
+= bytes_read
;
6836 /* Did we find the end of the range list? */
6837 if (start
== 0 && end
== 0)
6840 /* Did we find a base address selection entry? */
6841 else if ((start
& base_select_mask
) == base_select_mask
)
6847 /* We found an ordinary address range. */
6852 complaint (&symfile_complaints
,
6853 _("Invalid .debug_ranges data "
6854 "(no base address)"));
6860 /* Inverted range entries are invalid. */
6861 complaint (&symfile_complaints
,
6862 _("Invalid .debug_ranges data "
6863 "(inverted range)"));
6867 /* Empty range entries have no effect. */
6871 record_block_range (block
,
6872 baseaddr
+ base
+ start
,
6873 baseaddr
+ base
+ end
- 1);
6879 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6880 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6881 during 4.6.0 experimental. */
6884 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6887 int major
, minor
, release
;
6889 if (cu
->producer
== NULL
)
6891 /* For unknown compilers expect their behavior is DWARF version
6894 GCC started to support .debug_types sections by -gdwarf-4 since
6895 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6896 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6897 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6898 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6903 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6905 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6907 /* For non-GCC compilers expect their behavior is DWARF version
6912 cs
= &cu
->producer
[strlen ("GNU ")];
6913 while (*cs
&& !isdigit (*cs
))
6915 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6917 /* Not recognized as GCC. */
6922 return major
< 4 || (major
== 4 && minor
< 6);
6925 /* Return the default accessibility type if it is not overriden by
6926 DW_AT_accessibility. */
6928 static enum dwarf_access_attribute
6929 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6931 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6933 /* The default DWARF 2 accessibility for members is public, the default
6934 accessibility for inheritance is private. */
6936 if (die
->tag
!= DW_TAG_inheritance
)
6937 return DW_ACCESS_public
;
6939 return DW_ACCESS_private
;
6943 /* DWARF 3+ defines the default accessibility a different way. The same
6944 rules apply now for DW_TAG_inheritance as for the members and it only
6945 depends on the container kind. */
6947 if (die
->parent
->tag
== DW_TAG_class_type
)
6948 return DW_ACCESS_private
;
6950 return DW_ACCESS_public
;
6954 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6955 offset. If the attribute was not found return 0, otherwise return
6956 1. If it was found but could not properly be handled, set *OFFSET
6960 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6963 struct attribute
*attr
;
6965 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6970 /* Note that we do not check for a section offset first here.
6971 This is because DW_AT_data_member_location is new in DWARF 4,
6972 so if we see it, we can assume that a constant form is really
6973 a constant and not a section offset. */
6974 if (attr_form_is_constant (attr
))
6975 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6976 else if (attr_form_is_section_offset (attr
))
6977 dwarf2_complex_location_expr_complaint ();
6978 else if (attr_form_is_block (attr
))
6979 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6981 dwarf2_complex_location_expr_complaint ();
6989 /* Add an aggregate field to the field list. */
6992 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6993 struct dwarf2_cu
*cu
)
6995 struct objfile
*objfile
= cu
->objfile
;
6996 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6997 struct nextfield
*new_field
;
6998 struct attribute
*attr
;
7000 char *fieldname
= "";
7002 /* Allocate a new field list entry and link it in. */
7003 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7004 make_cleanup (xfree
, new_field
);
7005 memset (new_field
, 0, sizeof (struct nextfield
));
7007 if (die
->tag
== DW_TAG_inheritance
)
7009 new_field
->next
= fip
->baseclasses
;
7010 fip
->baseclasses
= new_field
;
7014 new_field
->next
= fip
->fields
;
7015 fip
->fields
= new_field
;
7019 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7021 new_field
->accessibility
= DW_UNSND (attr
);
7023 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7024 if (new_field
->accessibility
!= DW_ACCESS_public
)
7025 fip
->non_public_fields
= 1;
7027 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7029 new_field
->virtuality
= DW_UNSND (attr
);
7031 new_field
->virtuality
= DW_VIRTUALITY_none
;
7033 fp
= &new_field
->field
;
7035 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7039 /* Data member other than a C++ static data member. */
7041 /* Get type of field. */
7042 fp
->type
= die_type (die
, cu
);
7044 SET_FIELD_BITPOS (*fp
, 0);
7046 /* Get bit size of field (zero if none). */
7047 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7050 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7054 FIELD_BITSIZE (*fp
) = 0;
7057 /* Get bit offset of field. */
7058 if (handle_data_member_location (die
, cu
, &offset
))
7059 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7060 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7063 if (gdbarch_bits_big_endian (gdbarch
))
7065 /* For big endian bits, the DW_AT_bit_offset gives the
7066 additional bit offset from the MSB of the containing
7067 anonymous object to the MSB of the field. We don't
7068 have to do anything special since we don't need to
7069 know the size of the anonymous object. */
7070 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7074 /* For little endian bits, compute the bit offset to the
7075 MSB of the anonymous object, subtract off the number of
7076 bits from the MSB of the field to the MSB of the
7077 object, and then subtract off the number of bits of
7078 the field itself. The result is the bit offset of
7079 the LSB of the field. */
7081 int bit_offset
= DW_UNSND (attr
);
7083 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7086 /* The size of the anonymous object containing
7087 the bit field is explicit, so use the
7088 indicated size (in bytes). */
7089 anonymous_size
= DW_UNSND (attr
);
7093 /* The size of the anonymous object containing
7094 the bit field must be inferred from the type
7095 attribute of the data member containing the
7097 anonymous_size
= TYPE_LENGTH (fp
->type
);
7099 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7100 - bit_offset
- FIELD_BITSIZE (*fp
);
7104 /* Get name of field. */
7105 fieldname
= dwarf2_name (die
, cu
);
7106 if (fieldname
== NULL
)
7109 /* The name is already allocated along with this objfile, so we don't
7110 need to duplicate it for the type. */
7111 fp
->name
= fieldname
;
7113 /* Change accessibility for artificial fields (e.g. virtual table
7114 pointer or virtual base class pointer) to private. */
7115 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7117 FIELD_ARTIFICIAL (*fp
) = 1;
7118 new_field
->accessibility
= DW_ACCESS_private
;
7119 fip
->non_public_fields
= 1;
7122 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7124 /* C++ static member. */
7126 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7127 is a declaration, but all versions of G++ as of this writing
7128 (so through at least 3.2.1) incorrectly generate
7129 DW_TAG_variable tags. */
7131 const char *physname
;
7133 /* Get name of field. */
7134 fieldname
= dwarf2_name (die
, cu
);
7135 if (fieldname
== NULL
)
7138 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7140 /* Only create a symbol if this is an external value.
7141 new_symbol checks this and puts the value in the global symbol
7142 table, which we want. If it is not external, new_symbol
7143 will try to put the value in cu->list_in_scope which is wrong. */
7144 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7146 /* A static const member, not much different than an enum as far as
7147 we're concerned, except that we can support more types. */
7148 new_symbol (die
, NULL
, cu
);
7151 /* Get physical name. */
7152 physname
= dwarf2_physname (fieldname
, die
, cu
);
7154 /* The name is already allocated along with this objfile, so we don't
7155 need to duplicate it for the type. */
7156 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7157 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7158 FIELD_NAME (*fp
) = fieldname
;
7160 else if (die
->tag
== DW_TAG_inheritance
)
7164 /* C++ base class field. */
7165 if (handle_data_member_location (die
, cu
, &offset
))
7166 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7167 FIELD_BITSIZE (*fp
) = 0;
7168 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7169 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7170 fip
->nbaseclasses
++;
7174 /* Add a typedef defined in the scope of the FIP's class. */
7177 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7178 struct dwarf2_cu
*cu
)
7180 struct objfile
*objfile
= cu
->objfile
;
7181 struct typedef_field_list
*new_field
;
7182 struct attribute
*attr
;
7183 struct typedef_field
*fp
;
7184 char *fieldname
= "";
7186 /* Allocate a new field list entry and link it in. */
7187 new_field
= xzalloc (sizeof (*new_field
));
7188 make_cleanup (xfree
, new_field
);
7190 gdb_assert (die
->tag
== DW_TAG_typedef
);
7192 fp
= &new_field
->field
;
7194 /* Get name of field. */
7195 fp
->name
= dwarf2_name (die
, cu
);
7196 if (fp
->name
== NULL
)
7199 fp
->type
= read_type_die (die
, cu
);
7201 new_field
->next
= fip
->typedef_field_list
;
7202 fip
->typedef_field_list
= new_field
;
7203 fip
->typedef_field_list_count
++;
7206 /* Create the vector of fields, and attach it to the type. */
7209 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7210 struct dwarf2_cu
*cu
)
7212 int nfields
= fip
->nfields
;
7214 /* Record the field count, allocate space for the array of fields,
7215 and create blank accessibility bitfields if necessary. */
7216 TYPE_NFIELDS (type
) = nfields
;
7217 TYPE_FIELDS (type
) = (struct field
*)
7218 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7219 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7221 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7223 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7225 TYPE_FIELD_PRIVATE_BITS (type
) =
7226 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7227 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7229 TYPE_FIELD_PROTECTED_BITS (type
) =
7230 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7231 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7233 TYPE_FIELD_IGNORE_BITS (type
) =
7234 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7235 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7238 /* If the type has baseclasses, allocate and clear a bit vector for
7239 TYPE_FIELD_VIRTUAL_BITS. */
7240 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7242 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7243 unsigned char *pointer
;
7245 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7246 pointer
= TYPE_ALLOC (type
, num_bytes
);
7247 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7248 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7249 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7252 /* Copy the saved-up fields into the field vector. Start from the head of
7253 the list, adding to the tail of the field array, so that they end up in
7254 the same order in the array in which they were added to the list. */
7255 while (nfields
-- > 0)
7257 struct nextfield
*fieldp
;
7261 fieldp
= fip
->fields
;
7262 fip
->fields
= fieldp
->next
;
7266 fieldp
= fip
->baseclasses
;
7267 fip
->baseclasses
= fieldp
->next
;
7270 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7271 switch (fieldp
->accessibility
)
7273 case DW_ACCESS_private
:
7274 if (cu
->language
!= language_ada
)
7275 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7278 case DW_ACCESS_protected
:
7279 if (cu
->language
!= language_ada
)
7280 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7283 case DW_ACCESS_public
:
7287 /* Unknown accessibility. Complain and treat it as public. */
7289 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7290 fieldp
->accessibility
);
7294 if (nfields
< fip
->nbaseclasses
)
7296 switch (fieldp
->virtuality
)
7298 case DW_VIRTUALITY_virtual
:
7299 case DW_VIRTUALITY_pure_virtual
:
7300 if (cu
->language
== language_ada
)
7301 error (_("unexpected virtuality in component of Ada type"));
7302 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7309 /* Add a member function to the proper fieldlist. */
7312 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7313 struct type
*type
, struct dwarf2_cu
*cu
)
7315 struct objfile
*objfile
= cu
->objfile
;
7316 struct attribute
*attr
;
7317 struct fnfieldlist
*flp
;
7319 struct fn_field
*fnp
;
7321 struct nextfnfield
*new_fnfield
;
7322 struct type
*this_type
;
7323 enum dwarf_access_attribute accessibility
;
7325 if (cu
->language
== language_ada
)
7326 error (_("unexpected member function in Ada type"));
7328 /* Get name of member function. */
7329 fieldname
= dwarf2_name (die
, cu
);
7330 if (fieldname
== NULL
)
7333 /* Look up member function name in fieldlist. */
7334 for (i
= 0; i
< fip
->nfnfields
; i
++)
7336 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7340 /* Create new list element if necessary. */
7341 if (i
< fip
->nfnfields
)
7342 flp
= &fip
->fnfieldlists
[i
];
7345 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7347 fip
->fnfieldlists
= (struct fnfieldlist
*)
7348 xrealloc (fip
->fnfieldlists
,
7349 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7350 * sizeof (struct fnfieldlist
));
7351 if (fip
->nfnfields
== 0)
7352 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7354 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7355 flp
->name
= fieldname
;
7358 i
= fip
->nfnfields
++;
7361 /* Create a new member function field and chain it to the field list
7363 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7364 make_cleanup (xfree
, new_fnfield
);
7365 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7366 new_fnfield
->next
= flp
->head
;
7367 flp
->head
= new_fnfield
;
7370 /* Fill in the member function field info. */
7371 fnp
= &new_fnfield
->fnfield
;
7373 /* Delay processing of the physname until later. */
7374 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7376 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7381 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7382 fnp
->physname
= physname
? physname
: "";
7385 fnp
->type
= alloc_type (objfile
);
7386 this_type
= read_type_die (die
, cu
);
7387 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7389 int nparams
= TYPE_NFIELDS (this_type
);
7391 /* TYPE is the domain of this method, and THIS_TYPE is the type
7392 of the method itself (TYPE_CODE_METHOD). */
7393 smash_to_method_type (fnp
->type
, type
,
7394 TYPE_TARGET_TYPE (this_type
),
7395 TYPE_FIELDS (this_type
),
7396 TYPE_NFIELDS (this_type
),
7397 TYPE_VARARGS (this_type
));
7399 /* Handle static member functions.
7400 Dwarf2 has no clean way to discern C++ static and non-static
7401 member functions. G++ helps GDB by marking the first
7402 parameter for non-static member functions (which is the this
7403 pointer) as artificial. We obtain this information from
7404 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7405 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7406 fnp
->voffset
= VOFFSET_STATIC
;
7409 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7410 dwarf2_full_name (fieldname
, die
, cu
));
7412 /* Get fcontext from DW_AT_containing_type if present. */
7413 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7414 fnp
->fcontext
= die_containing_type (die
, cu
);
7416 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7417 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7419 /* Get accessibility. */
7420 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7422 accessibility
= DW_UNSND (attr
);
7424 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7425 switch (accessibility
)
7427 case DW_ACCESS_private
:
7428 fnp
->is_private
= 1;
7430 case DW_ACCESS_protected
:
7431 fnp
->is_protected
= 1;
7435 /* Check for artificial methods. */
7436 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7437 if (attr
&& DW_UNSND (attr
) != 0)
7438 fnp
->is_artificial
= 1;
7440 /* Get index in virtual function table if it is a virtual member
7441 function. For older versions of GCC, this is an offset in the
7442 appropriate virtual table, as specified by DW_AT_containing_type.
7443 For everyone else, it is an expression to be evaluated relative
7444 to the object address. */
7446 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7449 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7451 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7453 /* Old-style GCC. */
7454 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7456 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7457 || (DW_BLOCK (attr
)->size
> 1
7458 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7459 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7461 struct dwarf_block blk
;
7464 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7466 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7467 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7468 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7469 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7470 dwarf2_complex_location_expr_complaint ();
7472 fnp
->voffset
/= cu
->header
.addr_size
;
7476 dwarf2_complex_location_expr_complaint ();
7479 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7481 else if (attr_form_is_section_offset (attr
))
7483 dwarf2_complex_location_expr_complaint ();
7487 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7493 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7494 if (attr
&& DW_UNSND (attr
))
7496 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7497 complaint (&symfile_complaints
,
7498 _("Member function \"%s\" (offset %d) is virtual "
7499 "but the vtable offset is not specified"),
7500 fieldname
, die
->offset
);
7501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7502 TYPE_CPLUS_DYNAMIC (type
) = 1;
7507 /* Create the vector of member function fields, and attach it to the type. */
7510 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7511 struct dwarf2_cu
*cu
)
7513 struct fnfieldlist
*flp
;
7514 int total_length
= 0;
7517 if (cu
->language
== language_ada
)
7518 error (_("unexpected member functions in Ada type"));
7520 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7521 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7522 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7524 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7526 struct nextfnfield
*nfp
= flp
->head
;
7527 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7530 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7531 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7532 fn_flp
->fn_fields
= (struct fn_field
*)
7533 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7534 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7535 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7537 total_length
+= flp
->length
;
7540 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7541 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7544 /* Returns non-zero if NAME is the name of a vtable member in CU's
7545 language, zero otherwise. */
7547 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7549 static const char vptr
[] = "_vptr";
7550 static const char vtable
[] = "vtable";
7552 /* Look for the C++ and Java forms of the vtable. */
7553 if ((cu
->language
== language_java
7554 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7555 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7556 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7562 /* GCC outputs unnamed structures that are really pointers to member
7563 functions, with the ABI-specified layout. If TYPE describes
7564 such a structure, smash it into a member function type.
7566 GCC shouldn't do this; it should just output pointer to member DIEs.
7567 This is GCC PR debug/28767. */
7570 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7572 struct type
*pfn_type
, *domain_type
, *new_type
;
7574 /* Check for a structure with no name and two children. */
7575 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7578 /* Check for __pfn and __delta members. */
7579 if (TYPE_FIELD_NAME (type
, 0) == NULL
7580 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7581 || TYPE_FIELD_NAME (type
, 1) == NULL
7582 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7585 /* Find the type of the method. */
7586 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7587 if (pfn_type
== NULL
7588 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7589 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7592 /* Look for the "this" argument. */
7593 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7594 if (TYPE_NFIELDS (pfn_type
) == 0
7595 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7596 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7599 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7600 new_type
= alloc_type (objfile
);
7601 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7602 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7603 TYPE_VARARGS (pfn_type
));
7604 smash_to_methodptr_type (type
, new_type
);
7607 /* Called when we find the DIE that starts a structure or union scope
7608 (definition) to create a type for the structure or union. Fill in
7609 the type's name and general properties; the members will not be
7610 processed until process_structure_type.
7612 NOTE: we need to call these functions regardless of whether or not the
7613 DIE has a DW_AT_name attribute, since it might be an anonymous
7614 structure or union. This gets the type entered into our set of
7617 However, if the structure is incomplete (an opaque struct/union)
7618 then suppress creating a symbol table entry for it since gdb only
7619 wants to find the one with the complete definition. Note that if
7620 it is complete, we just call new_symbol, which does it's own
7621 checking about whether the struct/union is anonymous or not (and
7622 suppresses creating a symbol table entry itself). */
7624 static struct type
*
7625 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7627 struct objfile
*objfile
= cu
->objfile
;
7629 struct attribute
*attr
;
7632 /* If the definition of this type lives in .debug_types, read that type.
7633 Don't follow DW_AT_specification though, that will take us back up
7634 the chain and we want to go down. */
7635 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7638 struct dwarf2_cu
*type_cu
= cu
;
7639 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7641 /* We could just recurse on read_structure_type, but we need to call
7642 get_die_type to ensure only one type for this DIE is created.
7643 This is important, for example, because for c++ classes we need
7644 TYPE_NAME set which is only done by new_symbol. Blech. */
7645 type
= read_type_die (type_die
, type_cu
);
7647 /* TYPE_CU may not be the same as CU.
7648 Ensure TYPE is recorded in CU's type_hash table. */
7649 return set_die_type (die
, type
, cu
);
7652 type
= alloc_type (objfile
);
7653 INIT_CPLUS_SPECIFIC (type
);
7655 name
= dwarf2_name (die
, cu
);
7658 if (cu
->language
== language_cplus
7659 || cu
->language
== language_java
)
7661 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7663 /* dwarf2_full_name might have already finished building the DIE's
7664 type. If so, there is no need to continue. */
7665 if (get_die_type (die
, cu
) != NULL
)
7666 return get_die_type (die
, cu
);
7668 TYPE_TAG_NAME (type
) = full_name
;
7669 if (die
->tag
== DW_TAG_structure_type
7670 || die
->tag
== DW_TAG_class_type
)
7671 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7675 /* The name is already allocated along with this objfile, so
7676 we don't need to duplicate it for the type. */
7677 TYPE_TAG_NAME (type
) = (char *) name
;
7678 if (die
->tag
== DW_TAG_class_type
)
7679 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7683 if (die
->tag
== DW_TAG_structure_type
)
7685 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7687 else if (die
->tag
== DW_TAG_union_type
)
7689 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7693 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7696 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7697 TYPE_DECLARED_CLASS (type
) = 1;
7699 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7702 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7706 TYPE_LENGTH (type
) = 0;
7709 TYPE_STUB_SUPPORTED (type
) = 1;
7710 if (die_is_declaration (die
, cu
))
7711 TYPE_STUB (type
) = 1;
7712 else if (attr
== NULL
&& die
->child
== NULL
7713 && producer_is_realview (cu
->producer
))
7714 /* RealView does not output the required DW_AT_declaration
7715 on incomplete types. */
7716 TYPE_STUB (type
) = 1;
7718 /* We need to add the type field to the die immediately so we don't
7719 infinitely recurse when dealing with pointers to the structure
7720 type within the structure itself. */
7721 set_die_type (die
, type
, cu
);
7723 /* set_die_type should be already done. */
7724 set_descriptive_type (type
, die
, cu
);
7729 /* Finish creating a structure or union type, including filling in
7730 its members and creating a symbol for it. */
7733 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7735 struct objfile
*objfile
= cu
->objfile
;
7736 struct die_info
*child_die
= die
->child
;
7739 type
= get_die_type (die
, cu
);
7741 type
= read_structure_type (die
, cu
);
7743 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7745 struct field_info fi
;
7746 struct die_info
*child_die
;
7747 VEC (symbolp
) *template_args
= NULL
;
7748 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7750 memset (&fi
, 0, sizeof (struct field_info
));
7752 child_die
= die
->child
;
7754 while (child_die
&& child_die
->tag
)
7756 if (child_die
->tag
== DW_TAG_member
7757 || child_die
->tag
== DW_TAG_variable
)
7759 /* NOTE: carlton/2002-11-05: A C++ static data member
7760 should be a DW_TAG_member that is a declaration, but
7761 all versions of G++ as of this writing (so through at
7762 least 3.2.1) incorrectly generate DW_TAG_variable
7763 tags for them instead. */
7764 dwarf2_add_field (&fi
, child_die
, cu
);
7766 else if (child_die
->tag
== DW_TAG_subprogram
)
7768 /* C++ member function. */
7769 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7771 else if (child_die
->tag
== DW_TAG_inheritance
)
7773 /* C++ base class field. */
7774 dwarf2_add_field (&fi
, child_die
, cu
);
7776 else if (child_die
->tag
== DW_TAG_typedef
)
7777 dwarf2_add_typedef (&fi
, child_die
, cu
);
7778 else if (child_die
->tag
== DW_TAG_template_type_param
7779 || child_die
->tag
== DW_TAG_template_value_param
)
7781 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7784 VEC_safe_push (symbolp
, template_args
, arg
);
7787 child_die
= sibling_die (child_die
);
7790 /* Attach template arguments to type. */
7791 if (! VEC_empty (symbolp
, template_args
))
7793 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7794 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7795 = VEC_length (symbolp
, template_args
);
7796 TYPE_TEMPLATE_ARGUMENTS (type
)
7797 = obstack_alloc (&objfile
->objfile_obstack
,
7798 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7799 * sizeof (struct symbol
*)));
7800 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7801 VEC_address (symbolp
, template_args
),
7802 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7803 * sizeof (struct symbol
*)));
7804 VEC_free (symbolp
, template_args
);
7807 /* Attach fields and member functions to the type. */
7809 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7812 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7814 /* Get the type which refers to the base class (possibly this
7815 class itself) which contains the vtable pointer for the current
7816 class from the DW_AT_containing_type attribute. This use of
7817 DW_AT_containing_type is a GNU extension. */
7819 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7821 struct type
*t
= die_containing_type (die
, cu
);
7823 TYPE_VPTR_BASETYPE (type
) = t
;
7828 /* Our own class provides vtbl ptr. */
7829 for (i
= TYPE_NFIELDS (t
) - 1;
7830 i
>= TYPE_N_BASECLASSES (t
);
7833 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7835 if (is_vtable_name (fieldname
, cu
))
7837 TYPE_VPTR_FIELDNO (type
) = i
;
7842 /* Complain if virtual function table field not found. */
7843 if (i
< TYPE_N_BASECLASSES (t
))
7844 complaint (&symfile_complaints
,
7845 _("virtual function table pointer "
7846 "not found when defining class '%s'"),
7847 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7852 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7855 else if (cu
->producer
7856 && strncmp (cu
->producer
,
7857 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7859 /* The IBM XLC compiler does not provide direct indication
7860 of the containing type, but the vtable pointer is
7861 always named __vfp. */
7865 for (i
= TYPE_NFIELDS (type
) - 1;
7866 i
>= TYPE_N_BASECLASSES (type
);
7869 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7871 TYPE_VPTR_FIELDNO (type
) = i
;
7872 TYPE_VPTR_BASETYPE (type
) = type
;
7879 /* Copy fi.typedef_field_list linked list elements content into the
7880 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7881 if (fi
.typedef_field_list
)
7883 int i
= fi
.typedef_field_list_count
;
7885 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7886 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7887 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7888 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7890 /* Reverse the list order to keep the debug info elements order. */
7893 struct typedef_field
*dest
, *src
;
7895 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7896 src
= &fi
.typedef_field_list
->field
;
7897 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7902 do_cleanups (back_to
);
7904 if (HAVE_CPLUS_STRUCT (type
))
7905 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7908 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7910 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7911 snapshots) has been known to create a die giving a declaration
7912 for a class that has, as a child, a die giving a definition for a
7913 nested class. So we have to process our children even if the
7914 current die is a declaration. Normally, of course, a declaration
7915 won't have any children at all. */
7917 while (child_die
!= NULL
&& child_die
->tag
)
7919 if (child_die
->tag
== DW_TAG_member
7920 || child_die
->tag
== DW_TAG_variable
7921 || child_die
->tag
== DW_TAG_inheritance
7922 || child_die
->tag
== DW_TAG_template_value_param
7923 || child_die
->tag
== DW_TAG_template_type_param
)
7928 process_die (child_die
, cu
);
7930 child_die
= sibling_die (child_die
);
7933 /* Do not consider external references. According to the DWARF standard,
7934 these DIEs are identified by the fact that they have no byte_size
7935 attribute, and a declaration attribute. */
7936 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7937 || !die_is_declaration (die
, cu
))
7938 new_symbol (die
, type
, cu
);
7941 /* Given a DW_AT_enumeration_type die, set its type. We do not
7942 complete the type's fields yet, or create any symbols. */
7944 static struct type
*
7945 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7947 struct objfile
*objfile
= cu
->objfile
;
7949 struct attribute
*attr
;
7952 /* If the definition of this type lives in .debug_types, read that type.
7953 Don't follow DW_AT_specification though, that will take us back up
7954 the chain and we want to go down. */
7955 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7958 struct dwarf2_cu
*type_cu
= cu
;
7959 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7961 type
= read_type_die (type_die
, type_cu
);
7963 /* TYPE_CU may not be the same as CU.
7964 Ensure TYPE is recorded in CU's type_hash table. */
7965 return set_die_type (die
, type
, cu
);
7968 type
= alloc_type (objfile
);
7970 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7971 name
= dwarf2_full_name (NULL
, die
, cu
);
7973 TYPE_TAG_NAME (type
) = (char *) name
;
7975 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7978 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7982 TYPE_LENGTH (type
) = 0;
7985 /* The enumeration DIE can be incomplete. In Ada, any type can be
7986 declared as private in the package spec, and then defined only
7987 inside the package body. Such types are known as Taft Amendment
7988 Types. When another package uses such a type, an incomplete DIE
7989 may be generated by the compiler. */
7990 if (die_is_declaration (die
, cu
))
7991 TYPE_STUB (type
) = 1;
7993 return set_die_type (die
, type
, cu
);
7996 /* Given a pointer to a die which begins an enumeration, process all
7997 the dies that define the members of the enumeration, and create the
7998 symbol for the enumeration type.
8000 NOTE: We reverse the order of the element list. */
8003 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8005 struct type
*this_type
;
8007 this_type
= get_die_type (die
, cu
);
8008 if (this_type
== NULL
)
8009 this_type
= read_enumeration_type (die
, cu
);
8011 if (die
->child
!= NULL
)
8013 struct die_info
*child_die
;
8015 struct field
*fields
= NULL
;
8017 int unsigned_enum
= 1;
8020 child_die
= die
->child
;
8021 while (child_die
&& child_die
->tag
)
8023 if (child_die
->tag
!= DW_TAG_enumerator
)
8025 process_die (child_die
, cu
);
8029 name
= dwarf2_name (child_die
, cu
);
8032 sym
= new_symbol (child_die
, this_type
, cu
);
8033 if (SYMBOL_VALUE (sym
) < 0)
8036 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8038 fields
= (struct field
*)
8040 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8041 * sizeof (struct field
));
8044 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8045 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8046 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8047 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8053 child_die
= sibling_die (child_die
);
8058 TYPE_NFIELDS (this_type
) = num_fields
;
8059 TYPE_FIELDS (this_type
) = (struct field
*)
8060 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8061 memcpy (TYPE_FIELDS (this_type
), fields
,
8062 sizeof (struct field
) * num_fields
);
8066 TYPE_UNSIGNED (this_type
) = 1;
8069 /* If we are reading an enum from a .debug_types unit, and the enum
8070 is a declaration, and the enum is not the signatured type in the
8071 unit, then we do not want to add a symbol for it. Adding a
8072 symbol would in some cases obscure the true definition of the
8073 enum, giving users an incomplete type when the definition is
8074 actually available. Note that we do not want to do this for all
8075 enums which are just declarations, because C++0x allows forward
8076 enum declarations. */
8077 if (cu
->per_cu
->debug_type_section
8078 && die_is_declaration (die
, cu
))
8080 struct signatured_type
*type_sig
;
8083 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8084 cu
->per_cu
->debug_type_section
,
8085 cu
->per_cu
->offset
);
8086 if (type_sig
->type_offset
!= die
->offset
)
8090 new_symbol (die
, this_type
, cu
);
8093 /* Extract all information from a DW_TAG_array_type DIE and put it in
8094 the DIE's type field. For now, this only handles one dimensional
8097 static struct type
*
8098 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8100 struct objfile
*objfile
= cu
->objfile
;
8101 struct die_info
*child_die
;
8103 struct type
*element_type
, *range_type
, *index_type
;
8104 struct type
**range_types
= NULL
;
8105 struct attribute
*attr
;
8107 struct cleanup
*back_to
;
8110 element_type
= die_type (die
, cu
);
8112 /* The die_type call above may have already set the type for this DIE. */
8113 type
= get_die_type (die
, cu
);
8117 /* Irix 6.2 native cc creates array types without children for
8118 arrays with unspecified length. */
8119 if (die
->child
== NULL
)
8121 index_type
= objfile_type (objfile
)->builtin_int
;
8122 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8123 type
= create_array_type (NULL
, element_type
, range_type
);
8124 return set_die_type (die
, type
, cu
);
8127 back_to
= make_cleanup (null_cleanup
, NULL
);
8128 child_die
= die
->child
;
8129 while (child_die
&& child_die
->tag
)
8131 if (child_die
->tag
== DW_TAG_subrange_type
)
8133 struct type
*child_type
= read_type_die (child_die
, cu
);
8135 if (child_type
!= NULL
)
8137 /* The range type was succesfully read. Save it for the
8138 array type creation. */
8139 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8141 range_types
= (struct type
**)
8142 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8143 * sizeof (struct type
*));
8145 make_cleanup (free_current_contents
, &range_types
);
8147 range_types
[ndim
++] = child_type
;
8150 child_die
= sibling_die (child_die
);
8153 /* Dwarf2 dimensions are output from left to right, create the
8154 necessary array types in backwards order. */
8156 type
= element_type
;
8158 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8163 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8168 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8171 /* Understand Dwarf2 support for vector types (like they occur on
8172 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8173 array type. This is not part of the Dwarf2/3 standard yet, but a
8174 custom vendor extension. The main difference between a regular
8175 array and the vector variant is that vectors are passed by value
8177 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8179 make_vector_type (type
);
8181 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8182 implementation may choose to implement triple vectors using this
8184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8187 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8188 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8190 complaint (&symfile_complaints
,
8191 _("DW_AT_byte_size for array type smaller "
8192 "than the total size of elements"));
8195 name
= dwarf2_name (die
, cu
);
8197 TYPE_NAME (type
) = name
;
8199 /* Install the type in the die. */
8200 set_die_type (die
, type
, cu
);
8202 /* set_die_type should be already done. */
8203 set_descriptive_type (type
, die
, cu
);
8205 do_cleanups (back_to
);
8210 static enum dwarf_array_dim_ordering
8211 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8213 struct attribute
*attr
;
8215 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8217 if (attr
) return DW_SND (attr
);
8219 /* GNU F77 is a special case, as at 08/2004 array type info is the
8220 opposite order to the dwarf2 specification, but data is still
8221 laid out as per normal fortran.
8223 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8224 version checking. */
8226 if (cu
->language
== language_fortran
8227 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8229 return DW_ORD_row_major
;
8232 switch (cu
->language_defn
->la_array_ordering
)
8234 case array_column_major
:
8235 return DW_ORD_col_major
;
8236 case array_row_major
:
8238 return DW_ORD_row_major
;
8242 /* Extract all information from a DW_TAG_set_type DIE and put it in
8243 the DIE's type field. */
8245 static struct type
*
8246 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8248 struct type
*domain_type
, *set_type
;
8249 struct attribute
*attr
;
8251 domain_type
= die_type (die
, cu
);
8253 /* The die_type call above may have already set the type for this DIE. */
8254 set_type
= get_die_type (die
, cu
);
8258 set_type
= create_set_type (NULL
, domain_type
);
8260 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8262 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8264 return set_die_type (die
, set_type
, cu
);
8267 /* First cut: install each common block member as a global variable. */
8270 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8272 struct die_info
*child_die
;
8273 struct attribute
*attr
;
8275 CORE_ADDR base
= (CORE_ADDR
) 0;
8277 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8280 /* Support the .debug_loc offsets. */
8281 if (attr_form_is_block (attr
))
8283 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8285 else if (attr_form_is_section_offset (attr
))
8287 dwarf2_complex_location_expr_complaint ();
8291 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8292 "common block member");
8295 if (die
->child
!= NULL
)
8297 child_die
= die
->child
;
8298 while (child_die
&& child_die
->tag
)
8302 sym
= new_symbol (child_die
, NULL
, cu
);
8304 && handle_data_member_location (child_die
, cu
, &offset
))
8306 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8307 add_symbol_to_list (sym
, &global_symbols
);
8309 child_die
= sibling_die (child_die
);
8314 /* Create a type for a C++ namespace. */
8316 static struct type
*
8317 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8319 struct objfile
*objfile
= cu
->objfile
;
8320 const char *previous_prefix
, *name
;
8324 /* For extensions, reuse the type of the original namespace. */
8325 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8327 struct die_info
*ext_die
;
8328 struct dwarf2_cu
*ext_cu
= cu
;
8330 ext_die
= dwarf2_extension (die
, &ext_cu
);
8331 type
= read_type_die (ext_die
, ext_cu
);
8333 /* EXT_CU may not be the same as CU.
8334 Ensure TYPE is recorded in CU's type_hash table. */
8335 return set_die_type (die
, type
, cu
);
8338 name
= namespace_name (die
, &is_anonymous
, cu
);
8340 /* Now build the name of the current namespace. */
8342 previous_prefix
= determine_prefix (die
, cu
);
8343 if (previous_prefix
[0] != '\0')
8344 name
= typename_concat (&objfile
->objfile_obstack
,
8345 previous_prefix
, name
, 0, cu
);
8347 /* Create the type. */
8348 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8350 TYPE_NAME (type
) = (char *) name
;
8351 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8353 return set_die_type (die
, type
, cu
);
8356 /* Read a C++ namespace. */
8359 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8361 struct objfile
*objfile
= cu
->objfile
;
8364 /* Add a symbol associated to this if we haven't seen the namespace
8365 before. Also, add a using directive if it's an anonymous
8368 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8372 type
= read_type_die (die
, cu
);
8373 new_symbol (die
, type
, cu
);
8375 namespace_name (die
, &is_anonymous
, cu
);
8378 const char *previous_prefix
= determine_prefix (die
, cu
);
8380 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8381 NULL
, NULL
, &objfile
->objfile_obstack
);
8385 if (die
->child
!= NULL
)
8387 struct die_info
*child_die
= die
->child
;
8389 while (child_die
&& child_die
->tag
)
8391 process_die (child_die
, cu
);
8392 child_die
= sibling_die (child_die
);
8397 /* Read a Fortran module as type. This DIE can be only a declaration used for
8398 imported module. Still we need that type as local Fortran "use ... only"
8399 declaration imports depend on the created type in determine_prefix. */
8401 static struct type
*
8402 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8404 struct objfile
*objfile
= cu
->objfile
;
8408 module_name
= dwarf2_name (die
, cu
);
8410 complaint (&symfile_complaints
,
8411 _("DW_TAG_module has no name, offset 0x%x"),
8413 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8415 /* determine_prefix uses TYPE_TAG_NAME. */
8416 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8418 return set_die_type (die
, type
, cu
);
8421 /* Read a Fortran module. */
8424 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8426 struct die_info
*child_die
= die
->child
;
8428 while (child_die
&& child_die
->tag
)
8430 process_die (child_die
, cu
);
8431 child_die
= sibling_die (child_die
);
8435 /* Return the name of the namespace represented by DIE. Set
8436 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8440 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8442 struct die_info
*current_die
;
8443 const char *name
= NULL
;
8445 /* Loop through the extensions until we find a name. */
8447 for (current_die
= die
;
8448 current_die
!= NULL
;
8449 current_die
= dwarf2_extension (die
, &cu
))
8451 name
= dwarf2_name (current_die
, cu
);
8456 /* Is it an anonymous namespace? */
8458 *is_anonymous
= (name
== NULL
);
8460 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8465 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8466 the user defined type vector. */
8468 static struct type
*
8469 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8471 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8472 struct comp_unit_head
*cu_header
= &cu
->header
;
8474 struct attribute
*attr_byte_size
;
8475 struct attribute
*attr_address_class
;
8476 int byte_size
, addr_class
;
8477 struct type
*target_type
;
8479 target_type
= die_type (die
, cu
);
8481 /* The die_type call above may have already set the type for this DIE. */
8482 type
= get_die_type (die
, cu
);
8486 type
= lookup_pointer_type (target_type
);
8488 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8490 byte_size
= DW_UNSND (attr_byte_size
);
8492 byte_size
= cu_header
->addr_size
;
8494 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8495 if (attr_address_class
)
8496 addr_class
= DW_UNSND (attr_address_class
);
8498 addr_class
= DW_ADDR_none
;
8500 /* If the pointer size or address class is different than the
8501 default, create a type variant marked as such and set the
8502 length accordingly. */
8503 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8505 if (gdbarch_address_class_type_flags_p (gdbarch
))
8509 type_flags
= gdbarch_address_class_type_flags
8510 (gdbarch
, byte_size
, addr_class
);
8511 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8513 type
= make_type_with_address_space (type
, type_flags
);
8515 else if (TYPE_LENGTH (type
) != byte_size
)
8517 complaint (&symfile_complaints
,
8518 _("invalid pointer size %d"), byte_size
);
8522 /* Should we also complain about unhandled address classes? */
8526 TYPE_LENGTH (type
) = byte_size
;
8527 return set_die_type (die
, type
, cu
);
8530 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8531 the user defined type vector. */
8533 static struct type
*
8534 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8537 struct type
*to_type
;
8538 struct type
*domain
;
8540 to_type
= die_type (die
, cu
);
8541 domain
= die_containing_type (die
, cu
);
8543 /* The calls above may have already set the type for this DIE. */
8544 type
= get_die_type (die
, cu
);
8548 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8549 type
= lookup_methodptr_type (to_type
);
8551 type
= lookup_memberptr_type (to_type
, domain
);
8553 return set_die_type (die
, type
, cu
);
8556 /* Extract all information from a DW_TAG_reference_type DIE and add to
8557 the user defined type vector. */
8559 static struct type
*
8560 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8562 struct comp_unit_head
*cu_header
= &cu
->header
;
8563 struct type
*type
, *target_type
;
8564 struct attribute
*attr
;
8566 target_type
= die_type (die
, cu
);
8568 /* The die_type call above may have already set the type for this DIE. */
8569 type
= get_die_type (die
, cu
);
8573 type
= lookup_reference_type (target_type
);
8574 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8577 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8581 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8583 return set_die_type (die
, type
, cu
);
8586 static struct type
*
8587 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8589 struct type
*base_type
, *cv_type
;
8591 base_type
= die_type (die
, cu
);
8593 /* The die_type call above may have already set the type for this DIE. */
8594 cv_type
= get_die_type (die
, cu
);
8598 /* In case the const qualifier is applied to an array type, the element type
8599 is so qualified, not the array type (section 6.7.3 of C99). */
8600 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8602 struct type
*el_type
, *inner_array
;
8604 base_type
= copy_type (base_type
);
8605 inner_array
= base_type
;
8607 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8609 TYPE_TARGET_TYPE (inner_array
) =
8610 copy_type (TYPE_TARGET_TYPE (inner_array
));
8611 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8614 el_type
= TYPE_TARGET_TYPE (inner_array
);
8615 TYPE_TARGET_TYPE (inner_array
) =
8616 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8618 return set_die_type (die
, base_type
, cu
);
8621 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8622 return set_die_type (die
, cv_type
, cu
);
8625 static struct type
*
8626 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8628 struct type
*base_type
, *cv_type
;
8630 base_type
= die_type (die
, cu
);
8632 /* The die_type call above may have already set the type for this DIE. */
8633 cv_type
= get_die_type (die
, cu
);
8637 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8638 return set_die_type (die
, cv_type
, cu
);
8641 /* Extract all information from a DW_TAG_string_type DIE and add to
8642 the user defined type vector. It isn't really a user defined type,
8643 but it behaves like one, with other DIE's using an AT_user_def_type
8644 attribute to reference it. */
8646 static struct type
*
8647 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8649 struct objfile
*objfile
= cu
->objfile
;
8650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8651 struct type
*type
, *range_type
, *index_type
, *char_type
;
8652 struct attribute
*attr
;
8653 unsigned int length
;
8655 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8658 length
= DW_UNSND (attr
);
8662 /* Check for the DW_AT_byte_size attribute. */
8663 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8666 length
= DW_UNSND (attr
);
8674 index_type
= objfile_type (objfile
)->builtin_int
;
8675 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8676 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8677 type
= create_string_type (NULL
, char_type
, range_type
);
8679 return set_die_type (die
, type
, cu
);
8682 /* Handle DIES due to C code like:
8686 int (*funcp)(int a, long l);
8690 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8692 static struct type
*
8693 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8695 struct type
*type
; /* Type that this function returns. */
8696 struct type
*ftype
; /* Function that returns above type. */
8697 struct attribute
*attr
;
8699 type
= die_type (die
, cu
);
8701 /* The die_type call above may have already set the type for this DIE. */
8702 ftype
= get_die_type (die
, cu
);
8706 ftype
= lookup_function_type (type
);
8708 /* All functions in C++, Pascal and Java have prototypes. */
8709 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8710 if ((attr
&& (DW_UNSND (attr
) != 0))
8711 || cu
->language
== language_cplus
8712 || cu
->language
== language_java
8713 || cu
->language
== language_pascal
)
8714 TYPE_PROTOTYPED (ftype
) = 1;
8715 else if (producer_is_realview (cu
->producer
))
8716 /* RealView does not emit DW_AT_prototyped. We can not
8717 distinguish prototyped and unprototyped functions; default to
8718 prototyped, since that is more common in modern code (and
8719 RealView warns about unprototyped functions). */
8720 TYPE_PROTOTYPED (ftype
) = 1;
8722 /* Store the calling convention in the type if it's available in
8723 the subroutine die. Otherwise set the calling convention to
8724 the default value DW_CC_normal. */
8725 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8727 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8728 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8729 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8731 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8733 /* We need to add the subroutine type to the die immediately so
8734 we don't infinitely recurse when dealing with parameters
8735 declared as the same subroutine type. */
8736 set_die_type (die
, ftype
, cu
);
8738 if (die
->child
!= NULL
)
8740 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8741 struct die_info
*child_die
;
8742 int nparams
, iparams
;
8744 /* Count the number of parameters.
8745 FIXME: GDB currently ignores vararg functions, but knows about
8746 vararg member functions. */
8748 child_die
= die
->child
;
8749 while (child_die
&& child_die
->tag
)
8751 if (child_die
->tag
== DW_TAG_formal_parameter
)
8753 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8754 TYPE_VARARGS (ftype
) = 1;
8755 child_die
= sibling_die (child_die
);
8758 /* Allocate storage for parameters and fill them in. */
8759 TYPE_NFIELDS (ftype
) = nparams
;
8760 TYPE_FIELDS (ftype
) = (struct field
*)
8761 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8763 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8764 even if we error out during the parameters reading below. */
8765 for (iparams
= 0; iparams
< nparams
; iparams
++)
8766 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8769 child_die
= die
->child
;
8770 while (child_die
&& child_die
->tag
)
8772 if (child_die
->tag
== DW_TAG_formal_parameter
)
8774 struct type
*arg_type
;
8776 /* DWARF version 2 has no clean way to discern C++
8777 static and non-static member functions. G++ helps
8778 GDB by marking the first parameter for non-static
8779 member functions (which is the this pointer) as
8780 artificial. We pass this information to
8781 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8783 DWARF version 3 added DW_AT_object_pointer, which GCC
8784 4.5 does not yet generate. */
8785 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8787 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8790 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8792 /* GCC/43521: In java, the formal parameter
8793 "this" is sometimes not marked with DW_AT_artificial. */
8794 if (cu
->language
== language_java
)
8796 const char *name
= dwarf2_name (child_die
, cu
);
8798 if (name
&& !strcmp (name
, "this"))
8799 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8802 arg_type
= die_type (child_die
, cu
);
8804 /* RealView does not mark THIS as const, which the testsuite
8805 expects. GCC marks THIS as const in method definitions,
8806 but not in the class specifications (GCC PR 43053). */
8807 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8808 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8811 struct dwarf2_cu
*arg_cu
= cu
;
8812 const char *name
= dwarf2_name (child_die
, cu
);
8814 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8817 /* If the compiler emits this, use it. */
8818 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8821 else if (name
&& strcmp (name
, "this") == 0)
8822 /* Function definitions will have the argument names. */
8824 else if (name
== NULL
&& iparams
== 0)
8825 /* Declarations may not have the names, so like
8826 elsewhere in GDB, assume an artificial first
8827 argument is "this". */
8831 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8835 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8838 child_die
= sibling_die (child_die
);
8845 static struct type
*
8846 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8848 struct objfile
*objfile
= cu
->objfile
;
8849 const char *name
= NULL
;
8850 struct type
*this_type
;
8852 name
= dwarf2_full_name (NULL
, die
, cu
);
8853 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8854 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8855 TYPE_NAME (this_type
) = (char *) name
;
8856 set_die_type (die
, this_type
, cu
);
8857 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8861 /* Find a representation of a given base type and install
8862 it in the TYPE field of the die. */
8864 static struct type
*
8865 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8867 struct objfile
*objfile
= cu
->objfile
;
8869 struct attribute
*attr
;
8870 int encoding
= 0, size
= 0;
8872 enum type_code code
= TYPE_CODE_INT
;
8874 struct type
*target_type
= NULL
;
8876 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8879 encoding
= DW_UNSND (attr
);
8881 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8884 size
= DW_UNSND (attr
);
8886 name
= dwarf2_name (die
, cu
);
8889 complaint (&symfile_complaints
,
8890 _("DW_AT_name missing from DW_TAG_base_type"));
8895 case DW_ATE_address
:
8896 /* Turn DW_ATE_address into a void * pointer. */
8897 code
= TYPE_CODE_PTR
;
8898 type_flags
|= TYPE_FLAG_UNSIGNED
;
8899 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8901 case DW_ATE_boolean
:
8902 code
= TYPE_CODE_BOOL
;
8903 type_flags
|= TYPE_FLAG_UNSIGNED
;
8905 case DW_ATE_complex_float
:
8906 code
= TYPE_CODE_COMPLEX
;
8907 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8909 case DW_ATE_decimal_float
:
8910 code
= TYPE_CODE_DECFLOAT
;
8913 code
= TYPE_CODE_FLT
;
8917 case DW_ATE_unsigned
:
8918 type_flags
|= TYPE_FLAG_UNSIGNED
;
8919 if (cu
->language
== language_fortran
8921 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8922 code
= TYPE_CODE_CHAR
;
8924 case DW_ATE_signed_char
:
8925 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8926 || cu
->language
== language_pascal
8927 || cu
->language
== language_fortran
)
8928 code
= TYPE_CODE_CHAR
;
8930 case DW_ATE_unsigned_char
:
8931 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8932 || cu
->language
== language_pascal
8933 || cu
->language
== language_fortran
)
8934 code
= TYPE_CODE_CHAR
;
8935 type_flags
|= TYPE_FLAG_UNSIGNED
;
8938 /* We just treat this as an integer and then recognize the
8939 type by name elsewhere. */
8943 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8944 dwarf_type_encoding_name (encoding
));
8948 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8949 TYPE_NAME (type
) = name
;
8950 TYPE_TARGET_TYPE (type
) = target_type
;
8952 if (name
&& strcmp (name
, "char") == 0)
8953 TYPE_NOSIGN (type
) = 1;
8955 return set_die_type (die
, type
, cu
);
8958 /* Read the given DW_AT_subrange DIE. */
8960 static struct type
*
8961 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8963 struct type
*base_type
;
8964 struct type
*range_type
;
8965 struct attribute
*attr
;
8969 LONGEST negative_mask
;
8971 base_type
= die_type (die
, cu
);
8972 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8973 check_typedef (base_type
);
8975 /* The die_type call above may have already set the type for this DIE. */
8976 range_type
= get_die_type (die
, cu
);
8980 if (cu
->language
== language_fortran
)
8982 /* FORTRAN implies a lower bound of 1, if not given. */
8986 /* FIXME: For variable sized arrays either of these could be
8987 a variable rather than a constant value. We'll allow it,
8988 but we don't know how to handle it. */
8989 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8991 low
= dwarf2_get_attr_constant_value (attr
, 0);
8993 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8996 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8998 /* GCC encodes arrays with unspecified or dynamic length
8999 with a DW_FORM_block1 attribute or a reference attribute.
9000 FIXME: GDB does not yet know how to handle dynamic
9001 arrays properly, treat them as arrays with unspecified
9004 FIXME: jimb/2003-09-22: GDB does not really know
9005 how to handle arrays of unspecified length
9006 either; we just represent them as zero-length
9007 arrays. Choose an appropriate upper bound given
9008 the lower bound we've computed above. */
9012 high
= dwarf2_get_attr_constant_value (attr
, 1);
9016 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9019 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9020 high
= low
+ count
- 1;
9024 /* Unspecified array length. */
9029 /* Dwarf-2 specifications explicitly allows to create subrange types
9030 without specifying a base type.
9031 In that case, the base type must be set to the type of
9032 the lower bound, upper bound or count, in that order, if any of these
9033 three attributes references an object that has a type.
9034 If no base type is found, the Dwarf-2 specifications say that
9035 a signed integer type of size equal to the size of an address should
9037 For the following C code: `extern char gdb_int [];'
9038 GCC produces an empty range DIE.
9039 FIXME: muller/2010-05-28: Possible references to object for low bound,
9040 high bound or count are not yet handled by this code. */
9041 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9043 struct objfile
*objfile
= cu
->objfile
;
9044 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9045 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9046 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9048 /* Test "int", "long int", and "long long int" objfile types,
9049 and select the first one having a size above or equal to the
9050 architecture address size. */
9051 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9052 base_type
= int_type
;
9055 int_type
= objfile_type (objfile
)->builtin_long
;
9056 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9057 base_type
= int_type
;
9060 int_type
= objfile_type (objfile
)->builtin_long_long
;
9061 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9062 base_type
= int_type
;
9068 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9069 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9070 low
|= negative_mask
;
9071 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9072 high
|= negative_mask
;
9074 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9076 /* Mark arrays with dynamic length at least as an array of unspecified
9077 length. GDB could check the boundary but before it gets implemented at
9078 least allow accessing the array elements. */
9079 if (attr
&& attr_form_is_block (attr
))
9080 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9082 /* Ada expects an empty array on no boundary attributes. */
9083 if (attr
== NULL
&& cu
->language
!= language_ada
)
9084 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9086 name
= dwarf2_name (die
, cu
);
9088 TYPE_NAME (range_type
) = name
;
9090 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9092 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9094 set_die_type (die
, range_type
, cu
);
9096 /* set_die_type should be already done. */
9097 set_descriptive_type (range_type
, die
, cu
);
9102 static struct type
*
9103 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9107 /* For now, we only support the C meaning of an unspecified type: void. */
9109 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9110 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9112 return set_die_type (die
, type
, cu
);
9115 /* Trivial hash function for die_info: the hash value of a DIE
9116 is its offset in .debug_info for this objfile. */
9119 die_hash (const void *item
)
9121 const struct die_info
*die
= item
;
9126 /* Trivial comparison function for die_info structures: two DIEs
9127 are equal if they have the same offset. */
9130 die_eq (const void *item_lhs
, const void *item_rhs
)
9132 const struct die_info
*die_lhs
= item_lhs
;
9133 const struct die_info
*die_rhs
= item_rhs
;
9135 return die_lhs
->offset
== die_rhs
->offset
;
9138 /* Read a whole compilation unit into a linked list of dies. */
9140 static struct die_info
*
9141 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9143 struct die_reader_specs reader_specs
;
9144 int read_abbrevs
= 0;
9145 struct cleanup
*back_to
= NULL
;
9146 struct die_info
*die
;
9148 if (cu
->dwarf2_abbrevs
== NULL
)
9150 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
9151 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9155 gdb_assert (cu
->die_hash
== NULL
);
9157 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9161 &cu
->comp_unit_obstack
,
9162 hashtab_obstack_allocate
,
9163 dummy_obstack_deallocate
);
9165 init_cu_die_reader (&reader_specs
, cu
);
9167 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9170 do_cleanups (back_to
);
9175 /* Main entry point for reading a DIE and all children.
9176 Read the DIE and dump it if requested. */
9178 static struct die_info
*
9179 read_die_and_children (const struct die_reader_specs
*reader
,
9181 gdb_byte
**new_info_ptr
,
9182 struct die_info
*parent
)
9184 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9185 new_info_ptr
, parent
);
9187 if (dwarf2_die_debug
)
9189 fprintf_unfiltered (gdb_stdlog
,
9190 "\nRead die from %s of %s:\n",
9191 (reader
->cu
->per_cu
->debug_type_section
9194 reader
->abfd
->filename
);
9195 dump_die (result
, dwarf2_die_debug
);
9201 /* Read a single die and all its descendents. Set the die's sibling
9202 field to NULL; set other fields in the die correctly, and set all
9203 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9204 location of the info_ptr after reading all of those dies. PARENT
9205 is the parent of the die in question. */
9207 static struct die_info
*
9208 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9210 gdb_byte
**new_info_ptr
,
9211 struct die_info
*parent
)
9213 struct die_info
*die
;
9217 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9220 *new_info_ptr
= cur_ptr
;
9223 store_in_ref_table (die
, reader
->cu
);
9226 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9230 *new_info_ptr
= cur_ptr
;
9233 die
->sibling
= NULL
;
9234 die
->parent
= parent
;
9238 /* Read a die, all of its descendents, and all of its siblings; set
9239 all of the fields of all of the dies correctly. Arguments are as
9240 in read_die_and_children. */
9242 static struct die_info
*
9243 read_die_and_siblings (const struct die_reader_specs
*reader
,
9245 gdb_byte
**new_info_ptr
,
9246 struct die_info
*parent
)
9248 struct die_info
*first_die
, *last_sibling
;
9252 first_die
= last_sibling
= NULL
;
9256 struct die_info
*die
9257 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9261 *new_info_ptr
= cur_ptr
;
9268 last_sibling
->sibling
= die
;
9274 /* Read the die from the .debug_info section buffer. Set DIEP to
9275 point to a newly allocated die with its information, except for its
9276 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9277 whether the die has children or not. */
9280 read_full_die (const struct die_reader_specs
*reader
,
9281 struct die_info
**diep
, gdb_byte
*info_ptr
,
9284 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9285 struct abbrev_info
*abbrev
;
9286 struct die_info
*die
;
9287 struct dwarf2_cu
*cu
= reader
->cu
;
9288 bfd
*abfd
= reader
->abfd
;
9290 offset
= info_ptr
- reader
->buffer
;
9291 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9292 info_ptr
+= bytes_read
;
9300 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9302 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9304 bfd_get_filename (abfd
));
9306 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9307 die
->offset
= offset
;
9308 die
->tag
= abbrev
->tag
;
9309 die
->abbrev
= abbrev_number
;
9311 die
->num_attrs
= abbrev
->num_attrs
;
9313 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9314 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9315 abfd
, info_ptr
, cu
);
9318 *has_children
= abbrev
->has_children
;
9322 /* In DWARF version 2, the description of the debugging information is
9323 stored in a separate .debug_abbrev section. Before we read any
9324 dies from a section we read in all abbreviations and install them
9325 in a hash table. This function also sets flags in CU describing
9326 the data found in the abbrev table. */
9329 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9331 struct comp_unit_head
*cu_header
= &cu
->header
;
9332 gdb_byte
*abbrev_ptr
;
9333 struct abbrev_info
*cur_abbrev
;
9334 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9335 unsigned int abbrev_form
, hash_number
;
9336 struct attr_abbrev
*cur_attrs
;
9337 unsigned int allocated_attrs
;
9339 /* Initialize dwarf2 abbrevs. */
9340 obstack_init (&cu
->abbrev_obstack
);
9341 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9343 * sizeof (struct abbrev_info
*)));
9344 memset (cu
->dwarf2_abbrevs
, 0,
9345 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9347 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9348 &dwarf2_per_objfile
->abbrev
);
9349 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9350 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9351 abbrev_ptr
+= bytes_read
;
9353 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9354 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9356 /* Loop until we reach an abbrev number of 0. */
9357 while (abbrev_number
)
9359 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9361 /* read in abbrev header */
9362 cur_abbrev
->number
= abbrev_number
;
9363 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9364 abbrev_ptr
+= bytes_read
;
9365 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9368 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9369 cu
->has_namespace_info
= 1;
9371 /* now read in declarations */
9372 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9373 abbrev_ptr
+= bytes_read
;
9374 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9375 abbrev_ptr
+= bytes_read
;
9378 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9380 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9382 = xrealloc (cur_attrs
, (allocated_attrs
9383 * sizeof (struct attr_abbrev
)));
9386 /* Record whether this compilation unit might have
9387 inter-compilation-unit references. If we don't know what form
9388 this attribute will have, then it might potentially be a
9389 DW_FORM_ref_addr, so we conservatively expect inter-CU
9392 if (abbrev_form
== DW_FORM_ref_addr
9393 || abbrev_form
== DW_FORM_indirect
)
9394 cu
->has_form_ref_addr
= 1;
9396 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9397 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9398 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9399 abbrev_ptr
+= bytes_read
;
9400 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9401 abbrev_ptr
+= bytes_read
;
9404 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9405 (cur_abbrev
->num_attrs
9406 * sizeof (struct attr_abbrev
)));
9407 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9408 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9410 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9411 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9412 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9414 /* Get next abbreviation.
9415 Under Irix6 the abbreviations for a compilation unit are not
9416 always properly terminated with an abbrev number of 0.
9417 Exit loop if we encounter an abbreviation which we have
9418 already read (which means we are about to read the abbreviations
9419 for the next compile unit) or if the end of the abbreviation
9420 table is reached. */
9421 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9422 >= dwarf2_per_objfile
->abbrev
.size
)
9424 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9425 abbrev_ptr
+= bytes_read
;
9426 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9433 /* Release the memory used by the abbrev table for a compilation unit. */
9436 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9438 struct dwarf2_cu
*cu
= ptr_to_cu
;
9440 obstack_free (&cu
->abbrev_obstack
, NULL
);
9441 cu
->dwarf2_abbrevs
= NULL
;
9444 /* Lookup an abbrev_info structure in the abbrev hash table. */
9446 static struct abbrev_info
*
9447 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9449 unsigned int hash_number
;
9450 struct abbrev_info
*abbrev
;
9452 hash_number
= number
% ABBREV_HASH_SIZE
;
9453 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9457 if (abbrev
->number
== number
)
9460 abbrev
= abbrev
->next
;
9465 /* Returns nonzero if TAG represents a type that we might generate a partial
9469 is_type_tag_for_partial (int tag
)
9474 /* Some types that would be reasonable to generate partial symbols for,
9475 that we don't at present. */
9476 case DW_TAG_array_type
:
9477 case DW_TAG_file_type
:
9478 case DW_TAG_ptr_to_member_type
:
9479 case DW_TAG_set_type
:
9480 case DW_TAG_string_type
:
9481 case DW_TAG_subroutine_type
:
9483 case DW_TAG_base_type
:
9484 case DW_TAG_class_type
:
9485 case DW_TAG_interface_type
:
9486 case DW_TAG_enumeration_type
:
9487 case DW_TAG_structure_type
:
9488 case DW_TAG_subrange_type
:
9489 case DW_TAG_typedef
:
9490 case DW_TAG_union_type
:
9497 /* Load all DIEs that are interesting for partial symbols into memory. */
9499 static struct partial_die_info
*
9500 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9501 int building_psymtab
, struct dwarf2_cu
*cu
)
9503 struct partial_die_info
*part_die
;
9504 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9505 struct abbrev_info
*abbrev
;
9506 unsigned int bytes_read
;
9507 unsigned int load_all
= 0;
9509 int nesting_level
= 1;
9514 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9518 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9522 &cu
->comp_unit_obstack
,
9523 hashtab_obstack_allocate
,
9524 dummy_obstack_deallocate
);
9526 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9527 sizeof (struct partial_die_info
));
9531 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9533 /* A NULL abbrev means the end of a series of children. */
9536 if (--nesting_level
== 0)
9538 /* PART_DIE was probably the last thing allocated on the
9539 comp_unit_obstack, so we could call obstack_free
9540 here. We don't do that because the waste is small,
9541 and will be cleaned up when we're done with this
9542 compilation unit. This way, we're also more robust
9543 against other users of the comp_unit_obstack. */
9546 info_ptr
+= bytes_read
;
9547 last_die
= parent_die
;
9548 parent_die
= parent_die
->die_parent
;
9552 /* Check for template arguments. We never save these; if
9553 they're seen, we just mark the parent, and go on our way. */
9554 if (parent_die
!= NULL
9555 && cu
->language
== language_cplus
9556 && (abbrev
->tag
== DW_TAG_template_type_param
9557 || abbrev
->tag
== DW_TAG_template_value_param
))
9559 parent_die
->has_template_arguments
= 1;
9563 /* We don't need a partial DIE for the template argument. */
9564 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9570 /* We only recurse into subprograms looking for template arguments.
9571 Skip their other children. */
9573 && cu
->language
== language_cplus
9574 && parent_die
!= NULL
9575 && parent_die
->tag
== DW_TAG_subprogram
)
9577 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9581 /* Check whether this DIE is interesting enough to save. Normally
9582 we would not be interested in members here, but there may be
9583 later variables referencing them via DW_AT_specification (for
9586 && !is_type_tag_for_partial (abbrev
->tag
)
9587 && abbrev
->tag
!= DW_TAG_constant
9588 && abbrev
->tag
!= DW_TAG_enumerator
9589 && abbrev
->tag
!= DW_TAG_subprogram
9590 && abbrev
->tag
!= DW_TAG_lexical_block
9591 && abbrev
->tag
!= DW_TAG_variable
9592 && abbrev
->tag
!= DW_TAG_namespace
9593 && abbrev
->tag
!= DW_TAG_module
9594 && abbrev
->tag
!= DW_TAG_member
)
9596 /* Otherwise we skip to the next sibling, if any. */
9597 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9601 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9602 buffer
, info_ptr
, cu
);
9604 /* This two-pass algorithm for processing partial symbols has a
9605 high cost in cache pressure. Thus, handle some simple cases
9606 here which cover the majority of C partial symbols. DIEs
9607 which neither have specification tags in them, nor could have
9608 specification tags elsewhere pointing at them, can simply be
9609 processed and discarded.
9611 This segment is also optional; scan_partial_symbols and
9612 add_partial_symbol will handle these DIEs if we chain
9613 them in normally. When compilers which do not emit large
9614 quantities of duplicate debug information are more common,
9615 this code can probably be removed. */
9617 /* Any complete simple types at the top level (pretty much all
9618 of them, for a language without namespaces), can be processed
9620 if (parent_die
== NULL
9621 && part_die
->has_specification
== 0
9622 && part_die
->is_declaration
== 0
9623 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9624 || part_die
->tag
== DW_TAG_base_type
9625 || part_die
->tag
== DW_TAG_subrange_type
))
9627 if (building_psymtab
&& part_die
->name
!= NULL
)
9628 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9629 VAR_DOMAIN
, LOC_TYPEDEF
,
9630 &cu
->objfile
->static_psymbols
,
9631 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9632 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9636 /* The exception for DW_TAG_typedef with has_children above is
9637 a workaround of GCC PR debug/47510. In the case of this complaint
9638 type_name_no_tag_or_error will error on such types later.
9640 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9641 it could not find the child DIEs referenced later, this is checked
9642 above. In correct DWARF DW_TAG_typedef should have no children. */
9644 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9645 complaint (&symfile_complaints
,
9646 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9647 "- DIE at 0x%x [in module %s]"),
9648 part_die
->offset
, cu
->objfile
->name
);
9650 /* If we're at the second level, and we're an enumerator, and
9651 our parent has no specification (meaning possibly lives in a
9652 namespace elsewhere), then we can add the partial symbol now
9653 instead of queueing it. */
9654 if (part_die
->tag
== DW_TAG_enumerator
9655 && parent_die
!= NULL
9656 && parent_die
->die_parent
== NULL
9657 && parent_die
->tag
== DW_TAG_enumeration_type
9658 && parent_die
->has_specification
== 0)
9660 if (part_die
->name
== NULL
)
9661 complaint (&symfile_complaints
,
9662 _("malformed enumerator DIE ignored"));
9663 else if (building_psymtab
)
9664 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9665 VAR_DOMAIN
, LOC_CONST
,
9666 (cu
->language
== language_cplus
9667 || cu
->language
== language_java
)
9668 ? &cu
->objfile
->global_psymbols
9669 : &cu
->objfile
->static_psymbols
,
9670 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9672 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9676 /* We'll save this DIE so link it in. */
9677 part_die
->die_parent
= parent_die
;
9678 part_die
->die_sibling
= NULL
;
9679 part_die
->die_child
= NULL
;
9681 if (last_die
&& last_die
== parent_die
)
9682 last_die
->die_child
= part_die
;
9684 last_die
->die_sibling
= part_die
;
9686 last_die
= part_die
;
9688 if (first_die
== NULL
)
9689 first_die
= part_die
;
9691 /* Maybe add the DIE to the hash table. Not all DIEs that we
9692 find interesting need to be in the hash table, because we
9693 also have the parent/sibling/child chains; only those that we
9694 might refer to by offset later during partial symbol reading.
9696 For now this means things that might have be the target of a
9697 DW_AT_specification, DW_AT_abstract_origin, or
9698 DW_AT_extension. DW_AT_extension will refer only to
9699 namespaces; DW_AT_abstract_origin refers to functions (and
9700 many things under the function DIE, but we do not recurse
9701 into function DIEs during partial symbol reading) and
9702 possibly variables as well; DW_AT_specification refers to
9703 declarations. Declarations ought to have the DW_AT_declaration
9704 flag. It happens that GCC forgets to put it in sometimes, but
9705 only for functions, not for types.
9707 Adding more things than necessary to the hash table is harmless
9708 except for the performance cost. Adding too few will result in
9709 wasted time in find_partial_die, when we reread the compilation
9710 unit with load_all_dies set. */
9713 || abbrev
->tag
== DW_TAG_constant
9714 || abbrev
->tag
== DW_TAG_subprogram
9715 || abbrev
->tag
== DW_TAG_variable
9716 || abbrev
->tag
== DW_TAG_namespace
9717 || part_die
->is_declaration
)
9721 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9722 part_die
->offset
, INSERT
);
9726 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9727 sizeof (struct partial_die_info
));
9729 /* For some DIEs we want to follow their children (if any). For C
9730 we have no reason to follow the children of structures; for other
9731 languages we have to, so that we can get at method physnames
9732 to infer fully qualified class names, for DW_AT_specification,
9733 and for C++ template arguments. For C++, we also look one level
9734 inside functions to find template arguments (if the name of the
9735 function does not already contain the template arguments).
9737 For Ada, we need to scan the children of subprograms and lexical
9738 blocks as well because Ada allows the definition of nested
9739 entities that could be interesting for the debugger, such as
9740 nested subprograms for instance. */
9741 if (last_die
->has_children
9743 || last_die
->tag
== DW_TAG_namespace
9744 || last_die
->tag
== DW_TAG_module
9745 || last_die
->tag
== DW_TAG_enumeration_type
9746 || (cu
->language
== language_cplus
9747 && last_die
->tag
== DW_TAG_subprogram
9748 && (last_die
->name
== NULL
9749 || strchr (last_die
->name
, '<') == NULL
))
9750 || (cu
->language
!= language_c
9751 && (last_die
->tag
== DW_TAG_class_type
9752 || last_die
->tag
== DW_TAG_interface_type
9753 || last_die
->tag
== DW_TAG_structure_type
9754 || last_die
->tag
== DW_TAG_union_type
))
9755 || (cu
->language
== language_ada
9756 && (last_die
->tag
== DW_TAG_subprogram
9757 || last_die
->tag
== DW_TAG_lexical_block
))))
9760 parent_die
= last_die
;
9764 /* Otherwise we skip to the next sibling, if any. */
9765 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9767 /* Back to the top, do it again. */
9771 /* Read a minimal amount of information into the minimal die structure. */
9774 read_partial_die (struct partial_die_info
*part_die
,
9775 struct abbrev_info
*abbrev
,
9776 unsigned int abbrev_len
, bfd
*abfd
,
9777 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9778 struct dwarf2_cu
*cu
)
9781 struct attribute attr
;
9782 int has_low_pc_attr
= 0;
9783 int has_high_pc_attr
= 0;
9785 memset (part_die
, 0, sizeof (struct partial_die_info
));
9787 part_die
->offset
= info_ptr
- buffer
;
9789 info_ptr
+= abbrev_len
;
9794 part_die
->tag
= abbrev
->tag
;
9795 part_die
->has_children
= abbrev
->has_children
;
9797 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9799 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9801 /* Store the data if it is of an attribute we want to keep in a
9802 partial symbol table. */
9806 switch (part_die
->tag
)
9808 case DW_TAG_compile_unit
:
9809 case DW_TAG_type_unit
:
9810 /* Compilation units have a DW_AT_name that is a filename, not
9811 a source language identifier. */
9812 case DW_TAG_enumeration_type
:
9813 case DW_TAG_enumerator
:
9814 /* These tags always have simple identifiers already; no need
9815 to canonicalize them. */
9816 part_die
->name
= DW_STRING (&attr
);
9820 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9821 &cu
->objfile
->objfile_obstack
);
9825 case DW_AT_linkage_name
:
9826 case DW_AT_MIPS_linkage_name
:
9827 /* Note that both forms of linkage name might appear. We
9828 assume they will be the same, and we only store the last
9830 if (cu
->language
== language_ada
)
9831 part_die
->name
= DW_STRING (&attr
);
9832 part_die
->linkage_name
= DW_STRING (&attr
);
9835 has_low_pc_attr
= 1;
9836 part_die
->lowpc
= DW_ADDR (&attr
);
9839 has_high_pc_attr
= 1;
9840 part_die
->highpc
= DW_ADDR (&attr
);
9842 case DW_AT_location
:
9843 /* Support the .debug_loc offsets. */
9844 if (attr_form_is_block (&attr
))
9846 part_die
->locdesc
= DW_BLOCK (&attr
);
9848 else if (attr_form_is_section_offset (&attr
))
9850 dwarf2_complex_location_expr_complaint ();
9854 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9855 "partial symbol information");
9858 case DW_AT_external
:
9859 part_die
->is_external
= DW_UNSND (&attr
);
9861 case DW_AT_declaration
:
9862 part_die
->is_declaration
= DW_UNSND (&attr
);
9865 part_die
->has_type
= 1;
9867 case DW_AT_abstract_origin
:
9868 case DW_AT_specification
:
9869 case DW_AT_extension
:
9870 part_die
->has_specification
= 1;
9871 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9874 /* Ignore absolute siblings, they might point outside of
9875 the current compile unit. */
9876 if (attr
.form
== DW_FORM_ref_addr
)
9877 complaint (&symfile_complaints
,
9878 _("ignoring absolute DW_AT_sibling"));
9880 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9882 case DW_AT_byte_size
:
9883 part_die
->has_byte_size
= 1;
9885 case DW_AT_calling_convention
:
9886 /* DWARF doesn't provide a way to identify a program's source-level
9887 entry point. DW_AT_calling_convention attributes are only meant
9888 to describe functions' calling conventions.
9890 However, because it's a necessary piece of information in
9891 Fortran, and because DW_CC_program is the only piece of debugging
9892 information whose definition refers to a 'main program' at all,
9893 several compilers have begun marking Fortran main programs with
9894 DW_CC_program --- even when those functions use the standard
9895 calling conventions.
9897 So until DWARF specifies a way to provide this information and
9898 compilers pick up the new representation, we'll support this
9900 if (DW_UNSND (&attr
) == DW_CC_program
9901 && cu
->language
== language_fortran
)
9903 set_main_name (part_die
->name
);
9905 /* As this DIE has a static linkage the name would be difficult
9906 to look up later. */
9907 language_of_main
= language_fortran
;
9915 if (has_low_pc_attr
&& has_high_pc_attr
)
9917 /* When using the GNU linker, .gnu.linkonce. sections are used to
9918 eliminate duplicate copies of functions and vtables and such.
9919 The linker will arbitrarily choose one and discard the others.
9920 The AT_*_pc values for such functions refer to local labels in
9921 these sections. If the section from that file was discarded, the
9922 labels are not in the output, so the relocs get a value of 0.
9923 If this is a discarded function, mark the pc bounds as invalid,
9924 so that GDB will ignore it. */
9925 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9927 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9929 complaint (&symfile_complaints
,
9930 _("DW_AT_low_pc %s is zero "
9931 "for DIE at 0x%x [in module %s]"),
9932 paddress (gdbarch
, part_die
->lowpc
),
9933 part_die
->offset
, cu
->objfile
->name
);
9935 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9936 else if (part_die
->lowpc
>= part_die
->highpc
)
9938 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9940 complaint (&symfile_complaints
,
9941 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9942 "for DIE at 0x%x [in module %s]"),
9943 paddress (gdbarch
, part_die
->lowpc
),
9944 paddress (gdbarch
, part_die
->highpc
),
9945 part_die
->offset
, cu
->objfile
->name
);
9948 part_die
->has_pc_info
= 1;
9954 /* Find a cached partial DIE at OFFSET in CU. */
9956 static struct partial_die_info
*
9957 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9959 struct partial_die_info
*lookup_die
= NULL
;
9960 struct partial_die_info part_die
;
9962 part_die
.offset
= offset
;
9963 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9968 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9969 except in the case of .debug_types DIEs which do not reference
9970 outside their CU (they do however referencing other types via
9971 DW_FORM_ref_sig8). */
9973 static struct partial_die_info
*
9974 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9976 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9977 struct partial_die_info
*pd
= NULL
;
9979 if (cu
->per_cu
->debug_type_section
)
9981 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9987 if (offset_in_cu_p (&cu
->header
, offset
))
9989 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9994 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9996 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9997 load_partial_comp_unit (per_cu
, cu
->objfile
);
9999 per_cu
->cu
->last_used
= 0;
10000 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10002 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10004 struct cleanup
*back_to
;
10005 struct partial_die_info comp_unit_die
;
10006 struct abbrev_info
*abbrev
;
10007 unsigned int bytes_read
;
10010 per_cu
->load_all_dies
= 1;
10012 /* Re-read the DIEs. */
10013 back_to
= make_cleanup (null_cleanup
, 0);
10014 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10016 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
10017 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10019 info_ptr
= (dwarf2_per_objfile
->info
.buffer
10020 + per_cu
->cu
->header
.offset
10021 + per_cu
->cu
->header
.first_die_offset
);
10022 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10023 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10024 per_cu
->cu
->objfile
->obfd
,
10025 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10027 if (comp_unit_die
.has_children
)
10028 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
10029 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10031 do_cleanups (back_to
);
10033 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10039 internal_error (__FILE__
, __LINE__
,
10040 _("could not find partial DIE 0x%x "
10041 "in cache [from module %s]\n"),
10042 offset
, bfd_get_filename (cu
->objfile
->obfd
));
10046 /* See if we can figure out if the class lives in a namespace. We do
10047 this by looking for a member function; its demangled name will
10048 contain namespace info, if there is any. */
10051 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10052 struct dwarf2_cu
*cu
)
10054 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10055 what template types look like, because the demangler
10056 frequently doesn't give the same name as the debug info. We
10057 could fix this by only using the demangled name to get the
10058 prefix (but see comment in read_structure_type). */
10060 struct partial_die_info
*real_pdi
;
10061 struct partial_die_info
*child_pdi
;
10063 /* If this DIE (this DIE's specification, if any) has a parent, then
10064 we should not do this. We'll prepend the parent's fully qualified
10065 name when we create the partial symbol. */
10067 real_pdi
= struct_pdi
;
10068 while (real_pdi
->has_specification
)
10069 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10071 if (real_pdi
->die_parent
!= NULL
)
10074 for (child_pdi
= struct_pdi
->die_child
;
10076 child_pdi
= child_pdi
->die_sibling
)
10078 if (child_pdi
->tag
== DW_TAG_subprogram
10079 && child_pdi
->linkage_name
!= NULL
)
10081 char *actual_class_name
10082 = language_class_name_from_physname (cu
->language_defn
,
10083 child_pdi
->linkage_name
);
10084 if (actual_class_name
!= NULL
)
10087 = obsavestring (actual_class_name
,
10088 strlen (actual_class_name
),
10089 &cu
->objfile
->objfile_obstack
);
10090 xfree (actual_class_name
);
10097 /* Adjust PART_DIE before generating a symbol for it. This function
10098 may set the is_external flag or change the DIE's name. */
10101 fixup_partial_die (struct partial_die_info
*part_die
,
10102 struct dwarf2_cu
*cu
)
10104 /* Once we've fixed up a die, there's no point in doing so again.
10105 This also avoids a memory leak if we were to call
10106 guess_partial_die_structure_name multiple times. */
10107 if (part_die
->fixup_called
)
10110 /* If we found a reference attribute and the DIE has no name, try
10111 to find a name in the referred to DIE. */
10113 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10115 struct partial_die_info
*spec_die
;
10117 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10119 fixup_partial_die (spec_die
, cu
);
10121 if (spec_die
->name
)
10123 part_die
->name
= spec_die
->name
;
10125 /* Copy DW_AT_external attribute if it is set. */
10126 if (spec_die
->is_external
)
10127 part_die
->is_external
= spec_die
->is_external
;
10131 /* Set default names for some unnamed DIEs. */
10133 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10134 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10136 /* If there is no parent die to provide a namespace, and there are
10137 children, see if we can determine the namespace from their linkage
10139 NOTE: We need to do this even if cu->has_namespace_info != 0.
10140 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10141 if (cu
->language
== language_cplus
10142 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10143 && part_die
->die_parent
== NULL
10144 && part_die
->has_children
10145 && (part_die
->tag
== DW_TAG_class_type
10146 || part_die
->tag
== DW_TAG_structure_type
10147 || part_die
->tag
== DW_TAG_union_type
))
10148 guess_partial_die_structure_name (part_die
, cu
);
10150 /* GCC might emit a nameless struct or union that has a linkage
10151 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10152 if (part_die
->name
== NULL
10153 && (part_die
->tag
== DW_TAG_class_type
10154 || part_die
->tag
== DW_TAG_interface_type
10155 || part_die
->tag
== DW_TAG_structure_type
10156 || part_die
->tag
== DW_TAG_union_type
)
10157 && part_die
->linkage_name
!= NULL
)
10161 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10166 /* Strip any leading namespaces/classes, keep only the base name.
10167 DW_AT_name for named DIEs does not contain the prefixes. */
10168 base
= strrchr (demangled
, ':');
10169 if (base
&& base
> demangled
&& base
[-1] == ':')
10174 part_die
->name
= obsavestring (base
, strlen (base
),
10175 &cu
->objfile
->objfile_obstack
);
10180 part_die
->fixup_called
= 1;
10183 /* Read an attribute value described by an attribute form. */
10186 read_attribute_value (struct attribute
*attr
, unsigned form
,
10187 bfd
*abfd
, gdb_byte
*info_ptr
,
10188 struct dwarf2_cu
*cu
)
10190 struct comp_unit_head
*cu_header
= &cu
->header
;
10191 unsigned int bytes_read
;
10192 struct dwarf_block
*blk
;
10197 case DW_FORM_ref_addr
:
10198 if (cu
->header
.version
== 2)
10199 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10201 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10202 &cu
->header
, &bytes_read
);
10203 info_ptr
+= bytes_read
;
10206 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10207 info_ptr
+= bytes_read
;
10209 case DW_FORM_block2
:
10210 blk
= dwarf_alloc_block (cu
);
10211 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10213 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10214 info_ptr
+= blk
->size
;
10215 DW_BLOCK (attr
) = blk
;
10217 case DW_FORM_block4
:
10218 blk
= dwarf_alloc_block (cu
);
10219 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10221 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10222 info_ptr
+= blk
->size
;
10223 DW_BLOCK (attr
) = blk
;
10225 case DW_FORM_data2
:
10226 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10229 case DW_FORM_data4
:
10230 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10233 case DW_FORM_data8
:
10234 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10237 case DW_FORM_sec_offset
:
10238 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10239 info_ptr
+= bytes_read
;
10241 case DW_FORM_string
:
10242 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10243 DW_STRING_IS_CANONICAL (attr
) = 0;
10244 info_ptr
+= bytes_read
;
10247 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10249 DW_STRING_IS_CANONICAL (attr
) = 0;
10250 info_ptr
+= bytes_read
;
10252 case DW_FORM_exprloc
:
10253 case DW_FORM_block
:
10254 blk
= dwarf_alloc_block (cu
);
10255 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10256 info_ptr
+= bytes_read
;
10257 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10258 info_ptr
+= blk
->size
;
10259 DW_BLOCK (attr
) = blk
;
10261 case DW_FORM_block1
:
10262 blk
= dwarf_alloc_block (cu
);
10263 blk
->size
= read_1_byte (abfd
, info_ptr
);
10265 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10266 info_ptr
+= blk
->size
;
10267 DW_BLOCK (attr
) = blk
;
10269 case DW_FORM_data1
:
10270 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10274 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10277 case DW_FORM_flag_present
:
10278 DW_UNSND (attr
) = 1;
10280 case DW_FORM_sdata
:
10281 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10282 info_ptr
+= bytes_read
;
10284 case DW_FORM_udata
:
10285 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10286 info_ptr
+= bytes_read
;
10289 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10293 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10297 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10301 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10304 case DW_FORM_ref_sig8
:
10305 /* Convert the signature to something we can record in DW_UNSND
10307 NOTE: This is NULL if the type wasn't found. */
10308 DW_SIGNATURED_TYPE (attr
) =
10309 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10312 case DW_FORM_ref_udata
:
10313 DW_ADDR (attr
) = (cu
->header
.offset
10314 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10315 info_ptr
+= bytes_read
;
10317 case DW_FORM_indirect
:
10318 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10319 info_ptr
+= bytes_read
;
10320 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10323 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10324 dwarf_form_name (form
),
10325 bfd_get_filename (abfd
));
10328 /* We have seen instances where the compiler tried to emit a byte
10329 size attribute of -1 which ended up being encoded as an unsigned
10330 0xffffffff. Although 0xffffffff is technically a valid size value,
10331 an object of this size seems pretty unlikely so we can relatively
10332 safely treat these cases as if the size attribute was invalid and
10333 treat them as zero by default. */
10334 if (attr
->name
== DW_AT_byte_size
10335 && form
== DW_FORM_data4
10336 && DW_UNSND (attr
) >= 0xffffffff)
10339 (&symfile_complaints
,
10340 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10341 hex_string (DW_UNSND (attr
)));
10342 DW_UNSND (attr
) = 0;
10348 /* Read an attribute described by an abbreviated attribute. */
10351 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10352 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10354 attr
->name
= abbrev
->name
;
10355 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10358 /* Read dwarf information from a buffer. */
10360 static unsigned int
10361 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10363 return bfd_get_8 (abfd
, buf
);
10367 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10369 return bfd_get_signed_8 (abfd
, buf
);
10372 static unsigned int
10373 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10375 return bfd_get_16 (abfd
, buf
);
10379 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10381 return bfd_get_signed_16 (abfd
, buf
);
10384 static unsigned int
10385 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10387 return bfd_get_32 (abfd
, buf
);
10391 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10393 return bfd_get_signed_32 (abfd
, buf
);
10397 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10399 return bfd_get_64 (abfd
, buf
);
10403 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10404 unsigned int *bytes_read
)
10406 struct comp_unit_head
*cu_header
= &cu
->header
;
10407 CORE_ADDR retval
= 0;
10409 if (cu_header
->signed_addr_p
)
10411 switch (cu_header
->addr_size
)
10414 retval
= bfd_get_signed_16 (abfd
, buf
);
10417 retval
= bfd_get_signed_32 (abfd
, buf
);
10420 retval
= bfd_get_signed_64 (abfd
, buf
);
10423 internal_error (__FILE__
, __LINE__
,
10424 _("read_address: bad switch, signed [in module %s]"),
10425 bfd_get_filename (abfd
));
10430 switch (cu_header
->addr_size
)
10433 retval
= bfd_get_16 (abfd
, buf
);
10436 retval
= bfd_get_32 (abfd
, buf
);
10439 retval
= bfd_get_64 (abfd
, buf
);
10442 internal_error (__FILE__
, __LINE__
,
10443 _("read_address: bad switch, "
10444 "unsigned [in module %s]"),
10445 bfd_get_filename (abfd
));
10449 *bytes_read
= cu_header
->addr_size
;
10453 /* Read the initial length from a section. The (draft) DWARF 3
10454 specification allows the initial length to take up either 4 bytes
10455 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10456 bytes describe the length and all offsets will be 8 bytes in length
10459 An older, non-standard 64-bit format is also handled by this
10460 function. The older format in question stores the initial length
10461 as an 8-byte quantity without an escape value. Lengths greater
10462 than 2^32 aren't very common which means that the initial 4 bytes
10463 is almost always zero. Since a length value of zero doesn't make
10464 sense for the 32-bit format, this initial zero can be considered to
10465 be an escape value which indicates the presence of the older 64-bit
10466 format. As written, the code can't detect (old format) lengths
10467 greater than 4GB. If it becomes necessary to handle lengths
10468 somewhat larger than 4GB, we could allow other small values (such
10469 as the non-sensical values of 1, 2, and 3) to also be used as
10470 escape values indicating the presence of the old format.
10472 The value returned via bytes_read should be used to increment the
10473 relevant pointer after calling read_initial_length().
10475 [ Note: read_initial_length() and read_offset() are based on the
10476 document entitled "DWARF Debugging Information Format", revision
10477 3, draft 8, dated November 19, 2001. This document was obtained
10480 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10482 This document is only a draft and is subject to change. (So beware.)
10484 Details regarding the older, non-standard 64-bit format were
10485 determined empirically by examining 64-bit ELF files produced by
10486 the SGI toolchain on an IRIX 6.5 machine.
10488 - Kevin, July 16, 2002
10492 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10494 LONGEST length
= bfd_get_32 (abfd
, buf
);
10496 if (length
== 0xffffffff)
10498 length
= bfd_get_64 (abfd
, buf
+ 4);
10501 else if (length
== 0)
10503 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10504 length
= bfd_get_64 (abfd
, buf
);
10515 /* Cover function for read_initial_length.
10516 Returns the length of the object at BUF, and stores the size of the
10517 initial length in *BYTES_READ and stores the size that offsets will be in
10519 If the initial length size is not equivalent to that specified in
10520 CU_HEADER then issue a complaint.
10521 This is useful when reading non-comp-unit headers. */
10524 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10525 const struct comp_unit_head
*cu_header
,
10526 unsigned int *bytes_read
,
10527 unsigned int *offset_size
)
10529 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10531 gdb_assert (cu_header
->initial_length_size
== 4
10532 || cu_header
->initial_length_size
== 8
10533 || cu_header
->initial_length_size
== 12);
10535 if (cu_header
->initial_length_size
!= *bytes_read
)
10536 complaint (&symfile_complaints
,
10537 _("intermixed 32-bit and 64-bit DWARF sections"));
10539 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10543 /* Read an offset from the data stream. The size of the offset is
10544 given by cu_header->offset_size. */
10547 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10548 unsigned int *bytes_read
)
10550 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10552 *bytes_read
= cu_header
->offset_size
;
10556 /* Read an offset from the data stream. */
10559 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10561 LONGEST retval
= 0;
10563 switch (offset_size
)
10566 retval
= bfd_get_32 (abfd
, buf
);
10569 retval
= bfd_get_64 (abfd
, buf
);
10572 internal_error (__FILE__
, __LINE__
,
10573 _("read_offset_1: bad switch [in module %s]"),
10574 bfd_get_filename (abfd
));
10581 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10583 /* If the size of a host char is 8 bits, we can return a pointer
10584 to the buffer, otherwise we have to copy the data to a buffer
10585 allocated on the temporary obstack. */
10586 gdb_assert (HOST_CHAR_BIT
== 8);
10591 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10593 /* If the size of a host char is 8 bits, we can return a pointer
10594 to the string, otherwise we have to copy the string to a buffer
10595 allocated on the temporary obstack. */
10596 gdb_assert (HOST_CHAR_BIT
== 8);
10599 *bytes_read_ptr
= 1;
10602 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10603 return (char *) buf
;
10607 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10609 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10610 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10611 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10612 bfd_get_filename (abfd
));
10613 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10614 error (_("DW_FORM_strp pointing outside of "
10615 ".debug_str section [in module %s]"),
10616 bfd_get_filename (abfd
));
10617 gdb_assert (HOST_CHAR_BIT
== 8);
10618 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10620 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10624 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10625 const struct comp_unit_head
*cu_header
,
10626 unsigned int *bytes_read_ptr
)
10628 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10630 return read_indirect_string_at_offset (abfd
, str_offset
);
10633 static unsigned long
10634 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10636 unsigned long result
;
10637 unsigned int num_read
;
10639 unsigned char byte
;
10647 byte
= bfd_get_8 (abfd
, buf
);
10650 result
|= ((unsigned long)(byte
& 127) << shift
);
10651 if ((byte
& 128) == 0)
10657 *bytes_read_ptr
= num_read
;
10662 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10665 int i
, shift
, num_read
;
10666 unsigned char byte
;
10674 byte
= bfd_get_8 (abfd
, buf
);
10677 result
|= ((long)(byte
& 127) << shift
);
10679 if ((byte
& 128) == 0)
10684 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10685 result
|= -(((long)1) << shift
);
10686 *bytes_read_ptr
= num_read
;
10690 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10693 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10699 byte
= bfd_get_8 (abfd
, buf
);
10701 if ((byte
& 128) == 0)
10707 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10714 cu
->language
= language_c
;
10716 case DW_LANG_C_plus_plus
:
10717 cu
->language
= language_cplus
;
10720 cu
->language
= language_d
;
10722 case DW_LANG_Fortran77
:
10723 case DW_LANG_Fortran90
:
10724 case DW_LANG_Fortran95
:
10725 cu
->language
= language_fortran
;
10727 case DW_LANG_Mips_Assembler
:
10728 cu
->language
= language_asm
;
10731 cu
->language
= language_java
;
10733 case DW_LANG_Ada83
:
10734 case DW_LANG_Ada95
:
10735 cu
->language
= language_ada
;
10737 case DW_LANG_Modula2
:
10738 cu
->language
= language_m2
;
10740 case DW_LANG_Pascal83
:
10741 cu
->language
= language_pascal
;
10744 cu
->language
= language_objc
;
10746 case DW_LANG_Cobol74
:
10747 case DW_LANG_Cobol85
:
10749 cu
->language
= language_minimal
;
10752 cu
->language_defn
= language_def (cu
->language
);
10755 /* Return the named attribute or NULL if not there. */
10757 static struct attribute
*
10758 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10761 struct attribute
*spec
= NULL
;
10763 for (i
= 0; i
< die
->num_attrs
; ++i
)
10765 if (die
->attrs
[i
].name
== name
)
10766 return &die
->attrs
[i
];
10767 if (die
->attrs
[i
].name
== DW_AT_specification
10768 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10769 spec
= &die
->attrs
[i
];
10774 die
= follow_die_ref (die
, spec
, &cu
);
10775 return dwarf2_attr (die
, name
, cu
);
10781 /* Return the named attribute or NULL if not there,
10782 but do not follow DW_AT_specification, etc.
10783 This is for use in contexts where we're reading .debug_types dies.
10784 Following DW_AT_specification, DW_AT_abstract_origin will take us
10785 back up the chain, and we want to go down. */
10787 static struct attribute
*
10788 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10789 struct dwarf2_cu
*cu
)
10793 for (i
= 0; i
< die
->num_attrs
; ++i
)
10794 if (die
->attrs
[i
].name
== name
)
10795 return &die
->attrs
[i
];
10800 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10801 and holds a non-zero value. This function should only be used for
10802 DW_FORM_flag or DW_FORM_flag_present attributes. */
10805 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10807 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10809 return (attr
&& DW_UNSND (attr
));
10813 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10815 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10816 which value is non-zero. However, we have to be careful with
10817 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10818 (via dwarf2_flag_true_p) follows this attribute. So we may
10819 end up accidently finding a declaration attribute that belongs
10820 to a different DIE referenced by the specification attribute,
10821 even though the given DIE does not have a declaration attribute. */
10822 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10823 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10826 /* Return the die giving the specification for DIE, if there is
10827 one. *SPEC_CU is the CU containing DIE on input, and the CU
10828 containing the return value on output. If there is no
10829 specification, but there is an abstract origin, that is
10832 static struct die_info
*
10833 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10835 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10838 if (spec_attr
== NULL
)
10839 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10841 if (spec_attr
== NULL
)
10844 return follow_die_ref (die
, spec_attr
, spec_cu
);
10847 /* Free the line_header structure *LH, and any arrays and strings it
10849 NOTE: This is also used as a "cleanup" function. */
10852 free_line_header (struct line_header
*lh
)
10854 if (lh
->standard_opcode_lengths
)
10855 xfree (lh
->standard_opcode_lengths
);
10857 /* Remember that all the lh->file_names[i].name pointers are
10858 pointers into debug_line_buffer, and don't need to be freed. */
10859 if (lh
->file_names
)
10860 xfree (lh
->file_names
);
10862 /* Similarly for the include directory names. */
10863 if (lh
->include_dirs
)
10864 xfree (lh
->include_dirs
);
10869 /* Add an entry to LH's include directory table. */
10872 add_include_dir (struct line_header
*lh
, char *include_dir
)
10874 /* Grow the array if necessary. */
10875 if (lh
->include_dirs_size
== 0)
10877 lh
->include_dirs_size
= 1; /* for testing */
10878 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10879 * sizeof (*lh
->include_dirs
));
10881 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10883 lh
->include_dirs_size
*= 2;
10884 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10885 (lh
->include_dirs_size
10886 * sizeof (*lh
->include_dirs
)));
10889 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10892 /* Add an entry to LH's file name table. */
10895 add_file_name (struct line_header
*lh
,
10897 unsigned int dir_index
,
10898 unsigned int mod_time
,
10899 unsigned int length
)
10901 struct file_entry
*fe
;
10903 /* Grow the array if necessary. */
10904 if (lh
->file_names_size
== 0)
10906 lh
->file_names_size
= 1; /* for testing */
10907 lh
->file_names
= xmalloc (lh
->file_names_size
10908 * sizeof (*lh
->file_names
));
10910 else if (lh
->num_file_names
>= lh
->file_names_size
)
10912 lh
->file_names_size
*= 2;
10913 lh
->file_names
= xrealloc (lh
->file_names
,
10914 (lh
->file_names_size
10915 * sizeof (*lh
->file_names
)));
10918 fe
= &lh
->file_names
[lh
->num_file_names
++];
10920 fe
->dir_index
= dir_index
;
10921 fe
->mod_time
= mod_time
;
10922 fe
->length
= length
;
10923 fe
->included_p
= 0;
10927 /* Read the statement program header starting at OFFSET in
10928 .debug_line, according to the endianness of ABFD. Return a pointer
10929 to a struct line_header, allocated using xmalloc.
10931 NOTE: the strings in the include directory and file name tables of
10932 the returned object point into debug_line_buffer, and must not be
10935 static struct line_header
*
10936 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10937 struct dwarf2_cu
*cu
)
10939 struct cleanup
*back_to
;
10940 struct line_header
*lh
;
10941 gdb_byte
*line_ptr
;
10942 unsigned int bytes_read
, offset_size
;
10944 char *cur_dir
, *cur_file
;
10946 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10947 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10949 complaint (&symfile_complaints
, _("missing .debug_line section"));
10953 /* Make sure that at least there's room for the total_length field.
10954 That could be 12 bytes long, but we're just going to fudge that. */
10955 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10957 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10961 lh
= xmalloc (sizeof (*lh
));
10962 memset (lh
, 0, sizeof (*lh
));
10963 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10966 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10968 /* Read in the header. */
10970 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10971 &bytes_read
, &offset_size
);
10972 line_ptr
+= bytes_read
;
10973 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10974 + dwarf2_per_objfile
->line
.size
))
10976 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10979 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10980 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10982 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10983 line_ptr
+= offset_size
;
10984 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10986 if (lh
->version
>= 4)
10988 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10992 lh
->maximum_ops_per_instruction
= 1;
10994 if (lh
->maximum_ops_per_instruction
== 0)
10996 lh
->maximum_ops_per_instruction
= 1;
10997 complaint (&symfile_complaints
,
10998 _("invalid maximum_ops_per_instruction "
10999 "in `.debug_line' section"));
11002 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11004 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11006 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11008 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11010 lh
->standard_opcode_lengths
11011 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11013 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11014 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11016 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11020 /* Read directory table. */
11021 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11023 line_ptr
+= bytes_read
;
11024 add_include_dir (lh
, cur_dir
);
11026 line_ptr
+= bytes_read
;
11028 /* Read file name table. */
11029 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11031 unsigned int dir_index
, mod_time
, length
;
11033 line_ptr
+= bytes_read
;
11034 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11035 line_ptr
+= bytes_read
;
11036 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11037 line_ptr
+= bytes_read
;
11038 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11039 line_ptr
+= bytes_read
;
11041 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11043 line_ptr
+= bytes_read
;
11044 lh
->statement_program_start
= line_ptr
;
11046 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11047 + dwarf2_per_objfile
->line
.size
))
11048 complaint (&symfile_complaints
,
11049 _("line number info header doesn't "
11050 "fit in `.debug_line' section"));
11052 discard_cleanups (back_to
);
11056 /* This function exists to work around a bug in certain compilers
11057 (particularly GCC 2.95), in which the first line number marker of a
11058 function does not show up until after the prologue, right before
11059 the second line number marker. This function shifts ADDRESS down
11060 to the beginning of the function if necessary, and is called on
11061 addresses passed to record_line. */
11064 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
11066 struct function_range
*fn
;
11068 /* Find the function_range containing address. */
11072 if (!cu
->cached_fn
)
11073 cu
->cached_fn
= cu
->first_fn
;
11075 fn
= cu
->cached_fn
;
11077 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11083 while (fn
&& fn
!= cu
->cached_fn
)
11084 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11094 if (address
!= fn
->lowpc
)
11095 complaint (&symfile_complaints
,
11096 _("misplaced first line number at 0x%lx for '%s'"),
11097 (unsigned long) address
, fn
->name
);
11102 /* Subroutine of dwarf_decode_lines to simplify it.
11103 Return the file name of the psymtab for included file FILE_INDEX
11104 in line header LH of PST.
11105 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11106 If space for the result is malloc'd, it will be freed by a cleanup.
11107 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11110 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11111 const struct partial_symtab
*pst
,
11112 const char *comp_dir
)
11114 const struct file_entry fe
= lh
->file_names
[file_index
];
11115 char *include_name
= fe
.name
;
11116 char *include_name_to_compare
= include_name
;
11117 char *dir_name
= NULL
;
11118 const char *pst_filename
;
11119 char *copied_name
= NULL
;
11123 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11125 if (!IS_ABSOLUTE_PATH (include_name
)
11126 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11128 /* Avoid creating a duplicate psymtab for PST.
11129 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11130 Before we do the comparison, however, we need to account
11131 for DIR_NAME and COMP_DIR.
11132 First prepend dir_name (if non-NULL). If we still don't
11133 have an absolute path prepend comp_dir (if non-NULL).
11134 However, the directory we record in the include-file's
11135 psymtab does not contain COMP_DIR (to match the
11136 corresponding symtab(s)).
11141 bash$ gcc -g ./hello.c
11142 include_name = "hello.c"
11144 DW_AT_comp_dir = comp_dir = "/tmp"
11145 DW_AT_name = "./hello.c" */
11147 if (dir_name
!= NULL
)
11149 include_name
= concat (dir_name
, SLASH_STRING
,
11150 include_name
, (char *)NULL
);
11151 include_name_to_compare
= include_name
;
11152 make_cleanup (xfree
, include_name
);
11154 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11156 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11157 include_name
, (char *)NULL
);
11161 pst_filename
= pst
->filename
;
11162 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11164 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11165 pst_filename
, (char *)NULL
);
11166 pst_filename
= copied_name
;
11169 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11171 if (include_name_to_compare
!= include_name
)
11172 xfree (include_name_to_compare
);
11173 if (copied_name
!= NULL
)
11174 xfree (copied_name
);
11178 return include_name
;
11181 /* Ignore this record_line request. */
11184 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11189 /* Decode the Line Number Program (LNP) for the given line_header
11190 structure and CU. The actual information extracted and the type
11191 of structures created from the LNP depends on the value of PST.
11193 1. If PST is NULL, then this procedure uses the data from the program
11194 to create all necessary symbol tables, and their linetables.
11196 2. If PST is not NULL, this procedure reads the program to determine
11197 the list of files included by the unit represented by PST, and
11198 builds all the associated partial symbol tables.
11200 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11201 It is used for relative paths in the line table.
11202 NOTE: When processing partial symtabs (pst != NULL),
11203 comp_dir == pst->dirname.
11205 NOTE: It is important that psymtabs have the same file name (via strcmp)
11206 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11207 symtab we don't use it in the name of the psymtabs we create.
11208 E.g. expand_line_sal requires this when finding psymtabs to expand.
11209 A good testcase for this is mb-inline.exp. */
11212 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11213 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11215 gdb_byte
*line_ptr
, *extended_end
;
11216 gdb_byte
*line_end
;
11217 unsigned int bytes_read
, extended_len
;
11218 unsigned char op_code
, extended_op
, adj_opcode
;
11219 CORE_ADDR baseaddr
;
11220 struct objfile
*objfile
= cu
->objfile
;
11221 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11222 const int decode_for_pst_p
= (pst
!= NULL
);
11223 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11224 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11227 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11229 line_ptr
= lh
->statement_program_start
;
11230 line_end
= lh
->statement_program_end
;
11232 /* Read the statement sequences until there's nothing left. */
11233 while (line_ptr
< line_end
)
11235 /* state machine registers */
11236 CORE_ADDR address
= 0;
11237 unsigned int file
= 1;
11238 unsigned int line
= 1;
11239 unsigned int column
= 0;
11240 int is_stmt
= lh
->default_is_stmt
;
11241 int basic_block
= 0;
11242 int end_sequence
= 0;
11244 unsigned char op_index
= 0;
11246 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11248 /* Start a subfile for the current file of the state machine. */
11249 /* lh->include_dirs and lh->file_names are 0-based, but the
11250 directory and file name numbers in the statement program
11252 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11256 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11258 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11261 /* Decode the table. */
11262 while (!end_sequence
)
11264 op_code
= read_1_byte (abfd
, line_ptr
);
11266 if (line_ptr
> line_end
)
11268 dwarf2_debug_line_missing_end_sequence_complaint ();
11272 if (op_code
>= lh
->opcode_base
)
11274 /* Special operand. */
11275 adj_opcode
= op_code
- lh
->opcode_base
;
11276 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11277 / lh
->maximum_ops_per_instruction
)
11278 * lh
->minimum_instruction_length
);
11279 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11280 % lh
->maximum_ops_per_instruction
);
11281 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11282 if (lh
->num_file_names
< file
|| file
== 0)
11283 dwarf2_debug_line_missing_file_complaint ();
11284 /* For now we ignore lines not starting on an
11285 instruction boundary. */
11286 else if (op_index
== 0)
11288 lh
->file_names
[file
- 1].included_p
= 1;
11289 if (!decode_for_pst_p
&& is_stmt
)
11291 if (last_subfile
!= current_subfile
)
11293 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11295 (*p_record_line
) (last_subfile
, 0, addr
);
11296 last_subfile
= current_subfile
;
11298 /* Append row to matrix using current values. */
11299 addr
= check_cu_functions (address
, cu
);
11300 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11301 (*p_record_line
) (current_subfile
, line
, addr
);
11306 else switch (op_code
)
11308 case DW_LNS_extended_op
:
11309 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11311 line_ptr
+= bytes_read
;
11312 extended_end
= line_ptr
+ extended_len
;
11313 extended_op
= read_1_byte (abfd
, line_ptr
);
11315 switch (extended_op
)
11317 case DW_LNE_end_sequence
:
11318 p_record_line
= record_line
;
11321 case DW_LNE_set_address
:
11322 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11324 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11326 /* This line table is for a function which has been
11327 GCd by the linker. Ignore it. PR gdb/12528 */
11330 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11332 complaint (&symfile_complaints
,
11333 _(".debug_line address at offset 0x%lx is 0 "
11335 line_offset
, cu
->objfile
->name
);
11336 p_record_line
= noop_record_line
;
11340 line_ptr
+= bytes_read
;
11341 address
+= baseaddr
;
11343 case DW_LNE_define_file
:
11346 unsigned int dir_index
, mod_time
, length
;
11348 cur_file
= read_direct_string (abfd
, line_ptr
,
11350 line_ptr
+= bytes_read
;
11352 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11353 line_ptr
+= bytes_read
;
11355 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11356 line_ptr
+= bytes_read
;
11358 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11359 line_ptr
+= bytes_read
;
11360 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11363 case DW_LNE_set_discriminator
:
11364 /* The discriminator is not interesting to the debugger;
11366 line_ptr
= extended_end
;
11369 complaint (&symfile_complaints
,
11370 _("mangled .debug_line section"));
11373 /* Make sure that we parsed the extended op correctly. If e.g.
11374 we expected a different address size than the producer used,
11375 we may have read the wrong number of bytes. */
11376 if (line_ptr
!= extended_end
)
11378 complaint (&symfile_complaints
,
11379 _("mangled .debug_line section"));
11384 if (lh
->num_file_names
< file
|| file
== 0)
11385 dwarf2_debug_line_missing_file_complaint ();
11388 lh
->file_names
[file
- 1].included_p
= 1;
11389 if (!decode_for_pst_p
&& is_stmt
)
11391 if (last_subfile
!= current_subfile
)
11393 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11395 (*p_record_line
) (last_subfile
, 0, addr
);
11396 last_subfile
= current_subfile
;
11398 addr
= check_cu_functions (address
, cu
);
11399 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11400 (*p_record_line
) (current_subfile
, line
, addr
);
11405 case DW_LNS_advance_pc
:
11408 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11410 address
+= (((op_index
+ adjust
)
11411 / lh
->maximum_ops_per_instruction
)
11412 * lh
->minimum_instruction_length
);
11413 op_index
= ((op_index
+ adjust
)
11414 % lh
->maximum_ops_per_instruction
);
11415 line_ptr
+= bytes_read
;
11418 case DW_LNS_advance_line
:
11419 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11420 line_ptr
+= bytes_read
;
11422 case DW_LNS_set_file
:
11424 /* The arrays lh->include_dirs and lh->file_names are
11425 0-based, but the directory and file name numbers in
11426 the statement program are 1-based. */
11427 struct file_entry
*fe
;
11430 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11431 line_ptr
+= bytes_read
;
11432 if (lh
->num_file_names
< file
|| file
== 0)
11433 dwarf2_debug_line_missing_file_complaint ();
11436 fe
= &lh
->file_names
[file
- 1];
11438 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11439 if (!decode_for_pst_p
)
11441 last_subfile
= current_subfile
;
11442 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11447 case DW_LNS_set_column
:
11448 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11449 line_ptr
+= bytes_read
;
11451 case DW_LNS_negate_stmt
:
11452 is_stmt
= (!is_stmt
);
11454 case DW_LNS_set_basic_block
:
11457 /* Add to the address register of the state machine the
11458 address increment value corresponding to special opcode
11459 255. I.e., this value is scaled by the minimum
11460 instruction length since special opcode 255 would have
11461 scaled the increment. */
11462 case DW_LNS_const_add_pc
:
11464 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11466 address
+= (((op_index
+ adjust
)
11467 / lh
->maximum_ops_per_instruction
)
11468 * lh
->minimum_instruction_length
);
11469 op_index
= ((op_index
+ adjust
)
11470 % lh
->maximum_ops_per_instruction
);
11473 case DW_LNS_fixed_advance_pc
:
11474 address
+= read_2_bytes (abfd
, line_ptr
);
11480 /* Unknown standard opcode, ignore it. */
11483 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11485 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11486 line_ptr
+= bytes_read
;
11491 if (lh
->num_file_names
< file
|| file
== 0)
11492 dwarf2_debug_line_missing_file_complaint ();
11495 lh
->file_names
[file
- 1].included_p
= 1;
11496 if (!decode_for_pst_p
)
11498 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11499 (*p_record_line
) (current_subfile
, 0, addr
);
11504 if (decode_for_pst_p
)
11508 /* Now that we're done scanning the Line Header Program, we can
11509 create the psymtab of each included file. */
11510 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11511 if (lh
->file_names
[file_index
].included_p
== 1)
11513 char *include_name
=
11514 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11515 if (include_name
!= NULL
)
11516 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11521 /* Make sure a symtab is created for every file, even files
11522 which contain only variables (i.e. no code with associated
11526 struct file_entry
*fe
;
11528 for (i
= 0; i
< lh
->num_file_names
; i
++)
11532 fe
= &lh
->file_names
[i
];
11534 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11535 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11537 /* Skip the main file; we don't need it, and it must be
11538 allocated last, so that it will show up before the
11539 non-primary symtabs in the objfile's symtab list. */
11540 if (current_subfile
== first_subfile
)
11543 if (current_subfile
->symtab
== NULL
)
11544 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11546 fe
->symtab
= current_subfile
->symtab
;
11551 /* Start a subfile for DWARF. FILENAME is the name of the file and
11552 DIRNAME the name of the source directory which contains FILENAME
11553 or NULL if not known. COMP_DIR is the compilation directory for the
11554 linetable's compilation unit or NULL if not known.
11555 This routine tries to keep line numbers from identical absolute and
11556 relative file names in a common subfile.
11558 Using the `list' example from the GDB testsuite, which resides in
11559 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11560 of /srcdir/list0.c yields the following debugging information for list0.c:
11562 DW_AT_name: /srcdir/list0.c
11563 DW_AT_comp_dir: /compdir
11564 files.files[0].name: list0.h
11565 files.files[0].dir: /srcdir
11566 files.files[1].name: list0.c
11567 files.files[1].dir: /srcdir
11569 The line number information for list0.c has to end up in a single
11570 subfile, so that `break /srcdir/list0.c:1' works as expected.
11571 start_subfile will ensure that this happens provided that we pass the
11572 concatenation of files.files[1].dir and files.files[1].name as the
11576 dwarf2_start_subfile (char *filename
, const char *dirname
,
11577 const char *comp_dir
)
11581 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11582 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11583 second argument to start_subfile. To be consistent, we do the
11584 same here. In order not to lose the line information directory,
11585 we concatenate it to the filename when it makes sense.
11586 Note that the Dwarf3 standard says (speaking of filenames in line
11587 information): ``The directory index is ignored for file names
11588 that represent full path names''. Thus ignoring dirname in the
11589 `else' branch below isn't an issue. */
11591 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11592 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11594 fullname
= filename
;
11596 start_subfile (fullname
, comp_dir
);
11598 if (fullname
!= filename
)
11603 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11604 struct dwarf2_cu
*cu
)
11606 struct objfile
*objfile
= cu
->objfile
;
11607 struct comp_unit_head
*cu_header
= &cu
->header
;
11609 /* NOTE drow/2003-01-30: There used to be a comment and some special
11610 code here to turn a symbol with DW_AT_external and a
11611 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11612 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11613 with some versions of binutils) where shared libraries could have
11614 relocations against symbols in their debug information - the
11615 minimal symbol would have the right address, but the debug info
11616 would not. It's no longer necessary, because we will explicitly
11617 apply relocations when we read in the debug information now. */
11619 /* A DW_AT_location attribute with no contents indicates that a
11620 variable has been optimized away. */
11621 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11623 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11627 /* Handle one degenerate form of location expression specially, to
11628 preserve GDB's previous behavior when section offsets are
11629 specified. If this is just a DW_OP_addr then mark this symbol
11632 if (attr_form_is_block (attr
)
11633 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11634 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11636 unsigned int dummy
;
11638 SYMBOL_VALUE_ADDRESS (sym
) =
11639 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11640 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11641 fixup_symbol_section (sym
, objfile
);
11642 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11643 SYMBOL_SECTION (sym
));
11647 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11648 expression evaluator, and use LOC_COMPUTED only when necessary
11649 (i.e. when the value of a register or memory location is
11650 referenced, or a thread-local block, etc.). Then again, it might
11651 not be worthwhile. I'm assuming that it isn't unless performance
11652 or memory numbers show me otherwise. */
11654 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11655 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11657 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11658 cu
->has_loclist
= 1;
11661 /* Given a pointer to a DWARF information entry, figure out if we need
11662 to make a symbol table entry for it, and if so, create a new entry
11663 and return a pointer to it.
11664 If TYPE is NULL, determine symbol type from the die, otherwise
11665 used the passed type.
11666 If SPACE is not NULL, use it to hold the new symbol. If it is
11667 NULL, allocate a new symbol on the objfile's obstack. */
11669 static struct symbol
*
11670 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11671 struct symbol
*space
)
11673 struct objfile
*objfile
= cu
->objfile
;
11674 struct symbol
*sym
= NULL
;
11676 struct attribute
*attr
= NULL
;
11677 struct attribute
*attr2
= NULL
;
11678 CORE_ADDR baseaddr
;
11679 struct pending
**list_to_add
= NULL
;
11681 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11683 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11685 name
= dwarf2_name (die
, cu
);
11688 const char *linkagename
;
11689 int suppress_add
= 0;
11694 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11695 OBJSTAT (objfile
, n_syms
++);
11697 /* Cache this symbol's name and the name's demangled form (if any). */
11698 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11699 linkagename
= dwarf2_physname (name
, die
, cu
);
11700 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11702 /* Fortran does not have mangling standard and the mangling does differ
11703 between gfortran, iFort etc. */
11704 if (cu
->language
== language_fortran
11705 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11706 symbol_set_demangled_name (&(sym
->ginfo
),
11707 (char *) dwarf2_full_name (name
, die
, cu
),
11710 /* Default assumptions.
11711 Use the passed type or decode it from the die. */
11712 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11713 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11715 SYMBOL_TYPE (sym
) = type
;
11717 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11718 attr
= dwarf2_attr (die
,
11719 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11723 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11726 attr
= dwarf2_attr (die
,
11727 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11731 int file_index
= DW_UNSND (attr
);
11733 if (cu
->line_header
== NULL
11734 || file_index
> cu
->line_header
->num_file_names
)
11735 complaint (&symfile_complaints
,
11736 _("file index out of range"));
11737 else if (file_index
> 0)
11739 struct file_entry
*fe
;
11741 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11742 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11749 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11752 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11754 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11755 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11756 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11757 add_symbol_to_list (sym
, cu
->list_in_scope
);
11759 case DW_TAG_subprogram
:
11760 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11762 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11763 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11764 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11765 || cu
->language
== language_ada
)
11767 /* Subprograms marked external are stored as a global symbol.
11768 Ada subprograms, whether marked external or not, are always
11769 stored as a global symbol, because we want to be able to
11770 access them globally. For instance, we want to be able
11771 to break on a nested subprogram without having to
11772 specify the context. */
11773 list_to_add
= &global_symbols
;
11777 list_to_add
= cu
->list_in_scope
;
11780 case DW_TAG_inlined_subroutine
:
11781 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11783 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11784 SYMBOL_INLINED (sym
) = 1;
11785 /* Do not add the symbol to any lists. It will be found via
11786 BLOCK_FUNCTION from the blockvector. */
11788 case DW_TAG_template_value_param
:
11790 /* Fall through. */
11791 case DW_TAG_constant
:
11792 case DW_TAG_variable
:
11793 case DW_TAG_member
:
11794 /* Compilation with minimal debug info may result in
11795 variables with missing type entries. Change the
11796 misleading `void' type to something sensible. */
11797 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11799 = objfile_type (objfile
)->nodebug_data_symbol
;
11801 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11802 /* In the case of DW_TAG_member, we should only be called for
11803 static const members. */
11804 if (die
->tag
== DW_TAG_member
)
11806 /* dwarf2_add_field uses die_is_declaration,
11807 so we do the same. */
11808 gdb_assert (die_is_declaration (die
, cu
));
11813 dwarf2_const_value (attr
, sym
, cu
);
11814 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11817 if (attr2
&& (DW_UNSND (attr2
) != 0))
11818 list_to_add
= &global_symbols
;
11820 list_to_add
= cu
->list_in_scope
;
11824 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11827 var_decode_location (attr
, sym
, cu
);
11828 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11829 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11830 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11831 && !dwarf2_per_objfile
->has_section_at_zero
)
11833 /* When a static variable is eliminated by the linker,
11834 the corresponding debug information is not stripped
11835 out, but the variable address is set to null;
11836 do not add such variables into symbol table. */
11838 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11840 /* Workaround gfortran PR debug/40040 - it uses
11841 DW_AT_location for variables in -fPIC libraries which may
11842 get overriden by other libraries/executable and get
11843 a different address. Resolve it by the minimal symbol
11844 which may come from inferior's executable using copy
11845 relocation. Make this workaround only for gfortran as for
11846 other compilers GDB cannot guess the minimal symbol
11847 Fortran mangling kind. */
11848 if (cu
->language
== language_fortran
&& die
->parent
11849 && die
->parent
->tag
== DW_TAG_module
11851 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11852 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11854 /* A variable with DW_AT_external is never static,
11855 but it may be block-scoped. */
11856 list_to_add
= (cu
->list_in_scope
== &file_symbols
11857 ? &global_symbols
: cu
->list_in_scope
);
11860 list_to_add
= cu
->list_in_scope
;
11864 /* We do not know the address of this symbol.
11865 If it is an external symbol and we have type information
11866 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11867 The address of the variable will then be determined from
11868 the minimal symbol table whenever the variable is
11870 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11871 if (attr2
&& (DW_UNSND (attr2
) != 0)
11872 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11874 /* A variable with DW_AT_external is never static, but it
11875 may be block-scoped. */
11876 list_to_add
= (cu
->list_in_scope
== &file_symbols
11877 ? &global_symbols
: cu
->list_in_scope
);
11879 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11881 else if (!die_is_declaration (die
, cu
))
11883 /* Use the default LOC_OPTIMIZED_OUT class. */
11884 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11886 list_to_add
= cu
->list_in_scope
;
11890 case DW_TAG_formal_parameter
:
11891 /* If we are inside a function, mark this as an argument. If
11892 not, we might be looking at an argument to an inlined function
11893 when we do not have enough information to show inlined frames;
11894 pretend it's a local variable in that case so that the user can
11896 if (context_stack_depth
> 0
11897 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11898 SYMBOL_IS_ARGUMENT (sym
) = 1;
11899 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11902 var_decode_location (attr
, sym
, cu
);
11904 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11907 dwarf2_const_value (attr
, sym
, cu
);
11910 list_to_add
= cu
->list_in_scope
;
11912 case DW_TAG_unspecified_parameters
:
11913 /* From varargs functions; gdb doesn't seem to have any
11914 interest in this information, so just ignore it for now.
11917 case DW_TAG_template_type_param
:
11919 /* Fall through. */
11920 case DW_TAG_class_type
:
11921 case DW_TAG_interface_type
:
11922 case DW_TAG_structure_type
:
11923 case DW_TAG_union_type
:
11924 case DW_TAG_set_type
:
11925 case DW_TAG_enumeration_type
:
11926 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11927 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11930 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11931 really ever be static objects: otherwise, if you try
11932 to, say, break of a class's method and you're in a file
11933 which doesn't mention that class, it won't work unless
11934 the check for all static symbols in lookup_symbol_aux
11935 saves you. See the OtherFileClass tests in
11936 gdb.c++/namespace.exp. */
11940 list_to_add
= (cu
->list_in_scope
== &file_symbols
11941 && (cu
->language
== language_cplus
11942 || cu
->language
== language_java
)
11943 ? &global_symbols
: cu
->list_in_scope
);
11945 /* The semantics of C++ state that "struct foo {
11946 ... }" also defines a typedef for "foo". A Java
11947 class declaration also defines a typedef for the
11949 if (cu
->language
== language_cplus
11950 || cu
->language
== language_java
11951 || cu
->language
== language_ada
)
11953 /* The symbol's name is already allocated along
11954 with this objfile, so we don't need to
11955 duplicate it for the type. */
11956 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11957 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11962 case DW_TAG_typedef
:
11963 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11964 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11965 list_to_add
= cu
->list_in_scope
;
11967 case DW_TAG_base_type
:
11968 case DW_TAG_subrange_type
:
11969 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11970 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11971 list_to_add
= cu
->list_in_scope
;
11973 case DW_TAG_enumerator
:
11974 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11977 dwarf2_const_value (attr
, sym
, cu
);
11980 /* NOTE: carlton/2003-11-10: See comment above in the
11981 DW_TAG_class_type, etc. block. */
11983 list_to_add
= (cu
->list_in_scope
== &file_symbols
11984 && (cu
->language
== language_cplus
11985 || cu
->language
== language_java
)
11986 ? &global_symbols
: cu
->list_in_scope
);
11989 case DW_TAG_namespace
:
11990 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11991 list_to_add
= &global_symbols
;
11994 /* Not a tag we recognize. Hopefully we aren't processing
11995 trash data, but since we must specifically ignore things
11996 we don't recognize, there is nothing else we should do at
11998 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11999 dwarf_tag_name (die
->tag
));
12005 sym
->hash_next
= objfile
->template_symbols
;
12006 objfile
->template_symbols
= sym
;
12007 list_to_add
= NULL
;
12010 if (list_to_add
!= NULL
)
12011 add_symbol_to_list (sym
, list_to_add
);
12013 /* For the benefit of old versions of GCC, check for anonymous
12014 namespaces based on the demangled name. */
12015 if (!processing_has_namespace_info
12016 && cu
->language
== language_cplus
)
12017 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12022 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12024 static struct symbol
*
12025 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12027 return new_symbol_full (die
, type
, cu
, NULL
);
12030 /* Given an attr with a DW_FORM_dataN value in host byte order,
12031 zero-extend it as appropriate for the symbol's type. The DWARF
12032 standard (v4) is not entirely clear about the meaning of using
12033 DW_FORM_dataN for a constant with a signed type, where the type is
12034 wider than the data. The conclusion of a discussion on the DWARF
12035 list was that this is unspecified. We choose to always zero-extend
12036 because that is the interpretation long in use by GCC. */
12039 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12040 const char *name
, struct obstack
*obstack
,
12041 struct dwarf2_cu
*cu
, long *value
, int bits
)
12043 struct objfile
*objfile
= cu
->objfile
;
12044 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12045 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12046 LONGEST l
= DW_UNSND (attr
);
12048 if (bits
< sizeof (*value
) * 8)
12050 l
&= ((LONGEST
) 1 << bits
) - 1;
12053 else if (bits
== sizeof (*value
) * 8)
12057 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12058 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12065 /* Read a constant value from an attribute. Either set *VALUE, or if
12066 the value does not fit in *VALUE, set *BYTES - either already
12067 allocated on the objfile obstack, or newly allocated on OBSTACK,
12068 or, set *BATON, if we translated the constant to a location
12072 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12073 const char *name
, struct obstack
*obstack
,
12074 struct dwarf2_cu
*cu
,
12075 long *value
, gdb_byte
**bytes
,
12076 struct dwarf2_locexpr_baton
**baton
)
12078 struct objfile
*objfile
= cu
->objfile
;
12079 struct comp_unit_head
*cu_header
= &cu
->header
;
12080 struct dwarf_block
*blk
;
12081 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12082 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12088 switch (attr
->form
)
12094 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12095 dwarf2_const_value_length_mismatch_complaint (name
,
12096 cu_header
->addr_size
,
12097 TYPE_LENGTH (type
));
12098 /* Symbols of this form are reasonably rare, so we just
12099 piggyback on the existing location code rather than writing
12100 a new implementation of symbol_computed_ops. */
12101 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12102 sizeof (struct dwarf2_locexpr_baton
));
12103 (*baton
)->per_cu
= cu
->per_cu
;
12104 gdb_assert ((*baton
)->per_cu
);
12106 (*baton
)->size
= 2 + cu_header
->addr_size
;
12107 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12108 (*baton
)->data
= data
;
12110 data
[0] = DW_OP_addr
;
12111 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12112 byte_order
, DW_ADDR (attr
));
12113 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12116 case DW_FORM_string
:
12118 /* DW_STRING is already allocated on the objfile obstack, point
12120 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12122 case DW_FORM_block1
:
12123 case DW_FORM_block2
:
12124 case DW_FORM_block4
:
12125 case DW_FORM_block
:
12126 case DW_FORM_exprloc
:
12127 blk
= DW_BLOCK (attr
);
12128 if (TYPE_LENGTH (type
) != blk
->size
)
12129 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12130 TYPE_LENGTH (type
));
12131 *bytes
= blk
->data
;
12134 /* The DW_AT_const_value attributes are supposed to carry the
12135 symbol's value "represented as it would be on the target
12136 architecture." By the time we get here, it's already been
12137 converted to host endianness, so we just need to sign- or
12138 zero-extend it as appropriate. */
12139 case DW_FORM_data1
:
12140 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12141 obstack
, cu
, value
, 8);
12143 case DW_FORM_data2
:
12144 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12145 obstack
, cu
, value
, 16);
12147 case DW_FORM_data4
:
12148 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12149 obstack
, cu
, value
, 32);
12151 case DW_FORM_data8
:
12152 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12153 obstack
, cu
, value
, 64);
12156 case DW_FORM_sdata
:
12157 *value
= DW_SND (attr
);
12160 case DW_FORM_udata
:
12161 *value
= DW_UNSND (attr
);
12165 complaint (&symfile_complaints
,
12166 _("unsupported const value attribute form: '%s'"),
12167 dwarf_form_name (attr
->form
));
12174 /* Copy constant value from an attribute to a symbol. */
12177 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12178 struct dwarf2_cu
*cu
)
12180 struct objfile
*objfile
= cu
->objfile
;
12181 struct comp_unit_head
*cu_header
= &cu
->header
;
12184 struct dwarf2_locexpr_baton
*baton
;
12186 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12187 SYMBOL_PRINT_NAME (sym
),
12188 &objfile
->objfile_obstack
, cu
,
12189 &value
, &bytes
, &baton
);
12193 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12194 SYMBOL_LOCATION_BATON (sym
) = baton
;
12195 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12197 else if (bytes
!= NULL
)
12199 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12200 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12204 SYMBOL_VALUE (sym
) = value
;
12205 SYMBOL_CLASS (sym
) = LOC_CONST
;
12209 /* Return the type of the die in question using its DW_AT_type attribute. */
12211 static struct type
*
12212 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12214 struct attribute
*type_attr
;
12216 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12219 /* A missing DW_AT_type represents a void type. */
12220 return objfile_type (cu
->objfile
)->builtin_void
;
12223 return lookup_die_type (die
, type_attr
, cu
);
12226 /* True iff CU's producer generates GNAT Ada auxiliary information
12227 that allows to find parallel types through that information instead
12228 of having to do expensive parallel lookups by type name. */
12231 need_gnat_info (struct dwarf2_cu
*cu
)
12233 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12234 of GNAT produces this auxiliary information, without any indication
12235 that it is produced. Part of enhancing the FSF version of GNAT
12236 to produce that information will be to put in place an indicator
12237 that we can use in order to determine whether the descriptive type
12238 info is available or not. One suggestion that has been made is
12239 to use a new attribute, attached to the CU die. For now, assume
12240 that the descriptive type info is not available. */
12244 /* Return the auxiliary type of the die in question using its
12245 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12246 attribute is not present. */
12248 static struct type
*
12249 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12251 struct attribute
*type_attr
;
12253 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12257 return lookup_die_type (die
, type_attr
, cu
);
12260 /* If DIE has a descriptive_type attribute, then set the TYPE's
12261 descriptive type accordingly. */
12264 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12265 struct dwarf2_cu
*cu
)
12267 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12269 if (descriptive_type
)
12271 ALLOCATE_GNAT_AUX_TYPE (type
);
12272 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12276 /* Return the containing type of the die in question using its
12277 DW_AT_containing_type attribute. */
12279 static struct type
*
12280 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12282 struct attribute
*type_attr
;
12284 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12286 error (_("Dwarf Error: Problem turning containing type into gdb type "
12287 "[in module %s]"), cu
->objfile
->name
);
12289 return lookup_die_type (die
, type_attr
, cu
);
12292 /* Look up the type of DIE in CU using its type attribute ATTR.
12293 If there is no type substitute an error marker. */
12295 static struct type
*
12296 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12297 struct dwarf2_cu
*cu
)
12299 struct type
*this_type
;
12301 /* First see if we have it cached. */
12303 if (is_ref_attr (attr
))
12305 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12307 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12309 else if (attr
->form
== DW_FORM_ref_sig8
)
12311 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12312 struct dwarf2_cu
*sig_cu
;
12313 unsigned int offset
;
12315 /* sig_type will be NULL if the signatured type is missing from
12317 if (sig_type
== NULL
)
12318 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12319 "at 0x%x [in module %s]"),
12320 die
->offset
, cu
->objfile
->name
);
12322 gdb_assert (sig_type
->per_cu
.debug_type_section
);
12323 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12324 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12328 dump_die_for_error (die
);
12329 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12330 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
12333 /* If not cached we need to read it in. */
12335 if (this_type
== NULL
)
12337 struct die_info
*type_die
;
12338 struct dwarf2_cu
*type_cu
= cu
;
12340 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12341 /* If the type is cached, we should have found it above. */
12342 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12343 this_type
= read_type_die_1 (type_die
, type_cu
);
12346 /* If we still don't have a type use an error marker. */
12348 if (this_type
== NULL
)
12350 char *message
, *saved
;
12352 /* read_type_die already issued a complaint. */
12353 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12357 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12358 message
, strlen (message
));
12361 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12367 /* Return the type in DIE, CU.
12368 Returns NULL for invalid types.
12370 This first does a lookup in the appropriate type_hash table,
12371 and only reads the die in if necessary.
12373 NOTE: This can be called when reading in partial or full symbols. */
12375 static struct type
*
12376 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12378 struct type
*this_type
;
12380 this_type
= get_die_type (die
, cu
);
12384 return read_type_die_1 (die
, cu
);
12387 /* Read the type in DIE, CU.
12388 Returns NULL for invalid types. */
12390 static struct type
*
12391 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12393 struct type
*this_type
= NULL
;
12397 case DW_TAG_class_type
:
12398 case DW_TAG_interface_type
:
12399 case DW_TAG_structure_type
:
12400 case DW_TAG_union_type
:
12401 this_type
= read_structure_type (die
, cu
);
12403 case DW_TAG_enumeration_type
:
12404 this_type
= read_enumeration_type (die
, cu
);
12406 case DW_TAG_subprogram
:
12407 case DW_TAG_subroutine_type
:
12408 case DW_TAG_inlined_subroutine
:
12409 this_type
= read_subroutine_type (die
, cu
);
12411 case DW_TAG_array_type
:
12412 this_type
= read_array_type (die
, cu
);
12414 case DW_TAG_set_type
:
12415 this_type
= read_set_type (die
, cu
);
12417 case DW_TAG_pointer_type
:
12418 this_type
= read_tag_pointer_type (die
, cu
);
12420 case DW_TAG_ptr_to_member_type
:
12421 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12423 case DW_TAG_reference_type
:
12424 this_type
= read_tag_reference_type (die
, cu
);
12426 case DW_TAG_const_type
:
12427 this_type
= read_tag_const_type (die
, cu
);
12429 case DW_TAG_volatile_type
:
12430 this_type
= read_tag_volatile_type (die
, cu
);
12432 case DW_TAG_string_type
:
12433 this_type
= read_tag_string_type (die
, cu
);
12435 case DW_TAG_typedef
:
12436 this_type
= read_typedef (die
, cu
);
12438 case DW_TAG_subrange_type
:
12439 this_type
= read_subrange_type (die
, cu
);
12441 case DW_TAG_base_type
:
12442 this_type
= read_base_type (die
, cu
);
12444 case DW_TAG_unspecified_type
:
12445 this_type
= read_unspecified_type (die
, cu
);
12447 case DW_TAG_namespace
:
12448 this_type
= read_namespace_type (die
, cu
);
12450 case DW_TAG_module
:
12451 this_type
= read_module_type (die
, cu
);
12454 complaint (&symfile_complaints
,
12455 _("unexpected tag in read_type_die: '%s'"),
12456 dwarf_tag_name (die
->tag
));
12463 /* See if we can figure out if the class lives in a namespace. We do
12464 this by looking for a member function; its demangled name will
12465 contain namespace info, if there is any.
12466 Return the computed name or NULL.
12467 Space for the result is allocated on the objfile's obstack.
12468 This is the full-die version of guess_partial_die_structure_name.
12469 In this case we know DIE has no useful parent. */
12472 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12474 struct die_info
*spec_die
;
12475 struct dwarf2_cu
*spec_cu
;
12476 struct die_info
*child
;
12479 spec_die
= die_specification (die
, &spec_cu
);
12480 if (spec_die
!= NULL
)
12486 for (child
= die
->child
;
12488 child
= child
->sibling
)
12490 if (child
->tag
== DW_TAG_subprogram
)
12492 struct attribute
*attr
;
12494 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12496 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12500 = language_class_name_from_physname (cu
->language_defn
,
12504 if (actual_name
!= NULL
)
12506 char *die_name
= dwarf2_name (die
, cu
);
12508 if (die_name
!= NULL
12509 && strcmp (die_name
, actual_name
) != 0)
12511 /* Strip off the class name from the full name.
12512 We want the prefix. */
12513 int die_name_len
= strlen (die_name
);
12514 int actual_name_len
= strlen (actual_name
);
12516 /* Test for '::' as a sanity check. */
12517 if (actual_name_len
> die_name_len
+ 2
12518 && actual_name
[actual_name_len
12519 - die_name_len
- 1] == ':')
12521 obsavestring (actual_name
,
12522 actual_name_len
- die_name_len
- 2,
12523 &cu
->objfile
->objfile_obstack
);
12526 xfree (actual_name
);
12535 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12536 prefix part in such case. See
12537 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12540 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12542 struct attribute
*attr
;
12545 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12546 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12549 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12550 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12553 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12555 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12556 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12559 /* dwarf2_name had to be already called. */
12560 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12562 /* Strip the base name, keep any leading namespaces/classes. */
12563 base
= strrchr (DW_STRING (attr
), ':');
12564 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12567 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12568 &cu
->objfile
->objfile_obstack
);
12571 /* Return the name of the namespace/class that DIE is defined within,
12572 or "" if we can't tell. The caller should not xfree the result.
12574 For example, if we're within the method foo() in the following
12584 then determine_prefix on foo's die will return "N::C". */
12587 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12589 struct die_info
*parent
, *spec_die
;
12590 struct dwarf2_cu
*spec_cu
;
12591 struct type
*parent_type
;
12594 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12595 && cu
->language
!= language_fortran
)
12598 retval
= anonymous_struct_prefix (die
, cu
);
12602 /* We have to be careful in the presence of DW_AT_specification.
12603 For example, with GCC 3.4, given the code
12607 // Definition of N::foo.
12611 then we'll have a tree of DIEs like this:
12613 1: DW_TAG_compile_unit
12614 2: DW_TAG_namespace // N
12615 3: DW_TAG_subprogram // declaration of N::foo
12616 4: DW_TAG_subprogram // definition of N::foo
12617 DW_AT_specification // refers to die #3
12619 Thus, when processing die #4, we have to pretend that we're in
12620 the context of its DW_AT_specification, namely the contex of die
12623 spec_die
= die_specification (die
, &spec_cu
);
12624 if (spec_die
== NULL
)
12625 parent
= die
->parent
;
12628 parent
= spec_die
->parent
;
12632 if (parent
== NULL
)
12634 else if (parent
->building_fullname
)
12637 const char *parent_name
;
12639 /* It has been seen on RealView 2.2 built binaries,
12640 DW_TAG_template_type_param types actually _defined_ as
12641 children of the parent class:
12644 template class <class Enum> Class{};
12645 Class<enum E> class_e;
12647 1: DW_TAG_class_type (Class)
12648 2: DW_TAG_enumeration_type (E)
12649 3: DW_TAG_enumerator (enum1:0)
12650 3: DW_TAG_enumerator (enum2:1)
12652 2: DW_TAG_template_type_param
12653 DW_AT_type DW_FORM_ref_udata (E)
12655 Besides being broken debug info, it can put GDB into an
12656 infinite loop. Consider:
12658 When we're building the full name for Class<E>, we'll start
12659 at Class, and go look over its template type parameters,
12660 finding E. We'll then try to build the full name of E, and
12661 reach here. We're now trying to build the full name of E,
12662 and look over the parent DIE for containing scope. In the
12663 broken case, if we followed the parent DIE of E, we'd again
12664 find Class, and once again go look at its template type
12665 arguments, etc., etc. Simply don't consider such parent die
12666 as source-level parent of this die (it can't be, the language
12667 doesn't allow it), and break the loop here. */
12668 name
= dwarf2_name (die
, cu
);
12669 parent_name
= dwarf2_name (parent
, cu
);
12670 complaint (&symfile_complaints
,
12671 _("template param type '%s' defined within parent '%s'"),
12672 name
? name
: "<unknown>",
12673 parent_name
? parent_name
: "<unknown>");
12677 switch (parent
->tag
)
12679 case DW_TAG_namespace
:
12680 parent_type
= read_type_die (parent
, cu
);
12681 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12682 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12683 Work around this problem here. */
12684 if (cu
->language
== language_cplus
12685 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12687 /* We give a name to even anonymous namespaces. */
12688 return TYPE_TAG_NAME (parent_type
);
12689 case DW_TAG_class_type
:
12690 case DW_TAG_interface_type
:
12691 case DW_TAG_structure_type
:
12692 case DW_TAG_union_type
:
12693 case DW_TAG_module
:
12694 parent_type
= read_type_die (parent
, cu
);
12695 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12696 return TYPE_TAG_NAME (parent_type
);
12698 /* An anonymous structure is only allowed non-static data
12699 members; no typedefs, no member functions, et cetera.
12700 So it does not need a prefix. */
12702 case DW_TAG_compile_unit
:
12703 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12704 if (cu
->language
== language_cplus
12705 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12706 && die
->child
!= NULL
12707 && (die
->tag
== DW_TAG_class_type
12708 || die
->tag
== DW_TAG_structure_type
12709 || die
->tag
== DW_TAG_union_type
))
12711 char *name
= guess_full_die_structure_name (die
, cu
);
12717 return determine_prefix (parent
, cu
);
12721 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12722 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12723 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12724 an obconcat, otherwise allocate storage for the result. The CU argument is
12725 used to determine the language and hence, the appropriate separator. */
12727 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12730 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12731 int physname
, struct dwarf2_cu
*cu
)
12733 const char *lead
= "";
12736 if (suffix
== NULL
|| suffix
[0] == '\0'
12737 || prefix
== NULL
|| prefix
[0] == '\0')
12739 else if (cu
->language
== language_java
)
12741 else if (cu
->language
== language_fortran
&& physname
)
12743 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12744 DW_AT_MIPS_linkage_name is preferred and used instead. */
12752 if (prefix
== NULL
)
12754 if (suffix
== NULL
)
12760 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12762 strcpy (retval
, lead
);
12763 strcat (retval
, prefix
);
12764 strcat (retval
, sep
);
12765 strcat (retval
, suffix
);
12770 /* We have an obstack. */
12771 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12775 /* Return sibling of die, NULL if no sibling. */
12777 static struct die_info
*
12778 sibling_die (struct die_info
*die
)
12780 return die
->sibling
;
12783 /* Get name of a die, return NULL if not found. */
12786 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12787 struct obstack
*obstack
)
12789 if (name
&& cu
->language
== language_cplus
)
12791 char *canon_name
= cp_canonicalize_string (name
);
12793 if (canon_name
!= NULL
)
12795 if (strcmp (canon_name
, name
) != 0)
12796 name
= obsavestring (canon_name
, strlen (canon_name
),
12798 xfree (canon_name
);
12805 /* Get name of a die, return NULL if not found. */
12808 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12810 struct attribute
*attr
;
12812 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12813 if ((!attr
|| !DW_STRING (attr
))
12814 && die
->tag
!= DW_TAG_class_type
12815 && die
->tag
!= DW_TAG_interface_type
12816 && die
->tag
!= DW_TAG_structure_type
12817 && die
->tag
!= DW_TAG_union_type
)
12822 case DW_TAG_compile_unit
:
12823 /* Compilation units have a DW_AT_name that is a filename, not
12824 a source language identifier. */
12825 case DW_TAG_enumeration_type
:
12826 case DW_TAG_enumerator
:
12827 /* These tags always have simple identifiers already; no need
12828 to canonicalize them. */
12829 return DW_STRING (attr
);
12831 case DW_TAG_subprogram
:
12832 /* Java constructors will all be named "<init>", so return
12833 the class name when we see this special case. */
12834 if (cu
->language
== language_java
12835 && DW_STRING (attr
) != NULL
12836 && strcmp (DW_STRING (attr
), "<init>") == 0)
12838 struct dwarf2_cu
*spec_cu
= cu
;
12839 struct die_info
*spec_die
;
12841 /* GCJ will output '<init>' for Java constructor names.
12842 For this special case, return the name of the parent class. */
12844 /* GCJ may output suprogram DIEs with AT_specification set.
12845 If so, use the name of the specified DIE. */
12846 spec_die
= die_specification (die
, &spec_cu
);
12847 if (spec_die
!= NULL
)
12848 return dwarf2_name (spec_die
, spec_cu
);
12853 if (die
->tag
== DW_TAG_class_type
)
12854 return dwarf2_name (die
, cu
);
12856 while (die
->tag
!= DW_TAG_compile_unit
);
12860 case DW_TAG_class_type
:
12861 case DW_TAG_interface_type
:
12862 case DW_TAG_structure_type
:
12863 case DW_TAG_union_type
:
12864 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12865 structures or unions. These were of the form "._%d" in GCC 4.1,
12866 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12867 and GCC 4.4. We work around this problem by ignoring these. */
12868 if (attr
&& DW_STRING (attr
)
12869 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12870 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12873 /* GCC might emit a nameless typedef that has a linkage name. See
12874 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12875 if (!attr
|| DW_STRING (attr
) == NULL
)
12877 char *demangled
= NULL
;
12879 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12881 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12883 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12886 /* Avoid demangling DW_STRING (attr) the second time on a second
12887 call for the same DIE. */
12888 if (!DW_STRING_IS_CANONICAL (attr
))
12889 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12895 /* FIXME: we already did this for the partial symbol... */
12896 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12897 &cu
->objfile
->objfile_obstack
);
12898 DW_STRING_IS_CANONICAL (attr
) = 1;
12901 /* Strip any leading namespaces/classes, keep only the base name.
12902 DW_AT_name for named DIEs does not contain the prefixes. */
12903 base
= strrchr (DW_STRING (attr
), ':');
12904 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12907 return DW_STRING (attr
);
12916 if (!DW_STRING_IS_CANONICAL (attr
))
12919 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12920 &cu
->objfile
->objfile_obstack
);
12921 DW_STRING_IS_CANONICAL (attr
) = 1;
12923 return DW_STRING (attr
);
12926 /* Return the die that this die in an extension of, or NULL if there
12927 is none. *EXT_CU is the CU containing DIE on input, and the CU
12928 containing the return value on output. */
12930 static struct die_info
*
12931 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12933 struct attribute
*attr
;
12935 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12939 return follow_die_ref (die
, attr
, ext_cu
);
12942 /* Convert a DIE tag into its string name. */
12945 dwarf_tag_name (unsigned tag
)
12949 case DW_TAG_padding
:
12950 return "DW_TAG_padding";
12951 case DW_TAG_array_type
:
12952 return "DW_TAG_array_type";
12953 case DW_TAG_class_type
:
12954 return "DW_TAG_class_type";
12955 case DW_TAG_entry_point
:
12956 return "DW_TAG_entry_point";
12957 case DW_TAG_enumeration_type
:
12958 return "DW_TAG_enumeration_type";
12959 case DW_TAG_formal_parameter
:
12960 return "DW_TAG_formal_parameter";
12961 case DW_TAG_imported_declaration
:
12962 return "DW_TAG_imported_declaration";
12964 return "DW_TAG_label";
12965 case DW_TAG_lexical_block
:
12966 return "DW_TAG_lexical_block";
12967 case DW_TAG_member
:
12968 return "DW_TAG_member";
12969 case DW_TAG_pointer_type
:
12970 return "DW_TAG_pointer_type";
12971 case DW_TAG_reference_type
:
12972 return "DW_TAG_reference_type";
12973 case DW_TAG_compile_unit
:
12974 return "DW_TAG_compile_unit";
12975 case DW_TAG_string_type
:
12976 return "DW_TAG_string_type";
12977 case DW_TAG_structure_type
:
12978 return "DW_TAG_structure_type";
12979 case DW_TAG_subroutine_type
:
12980 return "DW_TAG_subroutine_type";
12981 case DW_TAG_typedef
:
12982 return "DW_TAG_typedef";
12983 case DW_TAG_union_type
:
12984 return "DW_TAG_union_type";
12985 case DW_TAG_unspecified_parameters
:
12986 return "DW_TAG_unspecified_parameters";
12987 case DW_TAG_variant
:
12988 return "DW_TAG_variant";
12989 case DW_TAG_common_block
:
12990 return "DW_TAG_common_block";
12991 case DW_TAG_common_inclusion
:
12992 return "DW_TAG_common_inclusion";
12993 case DW_TAG_inheritance
:
12994 return "DW_TAG_inheritance";
12995 case DW_TAG_inlined_subroutine
:
12996 return "DW_TAG_inlined_subroutine";
12997 case DW_TAG_module
:
12998 return "DW_TAG_module";
12999 case DW_TAG_ptr_to_member_type
:
13000 return "DW_TAG_ptr_to_member_type";
13001 case DW_TAG_set_type
:
13002 return "DW_TAG_set_type";
13003 case DW_TAG_subrange_type
:
13004 return "DW_TAG_subrange_type";
13005 case DW_TAG_with_stmt
:
13006 return "DW_TAG_with_stmt";
13007 case DW_TAG_access_declaration
:
13008 return "DW_TAG_access_declaration";
13009 case DW_TAG_base_type
:
13010 return "DW_TAG_base_type";
13011 case DW_TAG_catch_block
:
13012 return "DW_TAG_catch_block";
13013 case DW_TAG_const_type
:
13014 return "DW_TAG_const_type";
13015 case DW_TAG_constant
:
13016 return "DW_TAG_constant";
13017 case DW_TAG_enumerator
:
13018 return "DW_TAG_enumerator";
13019 case DW_TAG_file_type
:
13020 return "DW_TAG_file_type";
13021 case DW_TAG_friend
:
13022 return "DW_TAG_friend";
13023 case DW_TAG_namelist
:
13024 return "DW_TAG_namelist";
13025 case DW_TAG_namelist_item
:
13026 return "DW_TAG_namelist_item";
13027 case DW_TAG_packed_type
:
13028 return "DW_TAG_packed_type";
13029 case DW_TAG_subprogram
:
13030 return "DW_TAG_subprogram";
13031 case DW_TAG_template_type_param
:
13032 return "DW_TAG_template_type_param";
13033 case DW_TAG_template_value_param
:
13034 return "DW_TAG_template_value_param";
13035 case DW_TAG_thrown_type
:
13036 return "DW_TAG_thrown_type";
13037 case DW_TAG_try_block
:
13038 return "DW_TAG_try_block";
13039 case DW_TAG_variant_part
:
13040 return "DW_TAG_variant_part";
13041 case DW_TAG_variable
:
13042 return "DW_TAG_variable";
13043 case DW_TAG_volatile_type
:
13044 return "DW_TAG_volatile_type";
13045 case DW_TAG_dwarf_procedure
:
13046 return "DW_TAG_dwarf_procedure";
13047 case DW_TAG_restrict_type
:
13048 return "DW_TAG_restrict_type";
13049 case DW_TAG_interface_type
:
13050 return "DW_TAG_interface_type";
13051 case DW_TAG_namespace
:
13052 return "DW_TAG_namespace";
13053 case DW_TAG_imported_module
:
13054 return "DW_TAG_imported_module";
13055 case DW_TAG_unspecified_type
:
13056 return "DW_TAG_unspecified_type";
13057 case DW_TAG_partial_unit
:
13058 return "DW_TAG_partial_unit";
13059 case DW_TAG_imported_unit
:
13060 return "DW_TAG_imported_unit";
13061 case DW_TAG_condition
:
13062 return "DW_TAG_condition";
13063 case DW_TAG_shared_type
:
13064 return "DW_TAG_shared_type";
13065 case DW_TAG_type_unit
:
13066 return "DW_TAG_type_unit";
13067 case DW_TAG_MIPS_loop
:
13068 return "DW_TAG_MIPS_loop";
13069 case DW_TAG_HP_array_descriptor
:
13070 return "DW_TAG_HP_array_descriptor";
13071 case DW_TAG_format_label
:
13072 return "DW_TAG_format_label";
13073 case DW_TAG_function_template
:
13074 return "DW_TAG_function_template";
13075 case DW_TAG_class_template
:
13076 return "DW_TAG_class_template";
13077 case DW_TAG_GNU_BINCL
:
13078 return "DW_TAG_GNU_BINCL";
13079 case DW_TAG_GNU_EINCL
:
13080 return "DW_TAG_GNU_EINCL";
13081 case DW_TAG_upc_shared_type
:
13082 return "DW_TAG_upc_shared_type";
13083 case DW_TAG_upc_strict_type
:
13084 return "DW_TAG_upc_strict_type";
13085 case DW_TAG_upc_relaxed_type
:
13086 return "DW_TAG_upc_relaxed_type";
13087 case DW_TAG_PGI_kanji_type
:
13088 return "DW_TAG_PGI_kanji_type";
13089 case DW_TAG_PGI_interface_block
:
13090 return "DW_TAG_PGI_interface_block";
13091 case DW_TAG_GNU_call_site
:
13092 return "DW_TAG_GNU_call_site";
13094 return "DW_TAG_<unknown>";
13098 /* Convert a DWARF attribute code into its string name. */
13101 dwarf_attr_name (unsigned attr
)
13105 case DW_AT_sibling
:
13106 return "DW_AT_sibling";
13107 case DW_AT_location
:
13108 return "DW_AT_location";
13110 return "DW_AT_name";
13111 case DW_AT_ordering
:
13112 return "DW_AT_ordering";
13113 case DW_AT_subscr_data
:
13114 return "DW_AT_subscr_data";
13115 case DW_AT_byte_size
:
13116 return "DW_AT_byte_size";
13117 case DW_AT_bit_offset
:
13118 return "DW_AT_bit_offset";
13119 case DW_AT_bit_size
:
13120 return "DW_AT_bit_size";
13121 case DW_AT_element_list
:
13122 return "DW_AT_element_list";
13123 case DW_AT_stmt_list
:
13124 return "DW_AT_stmt_list";
13126 return "DW_AT_low_pc";
13127 case DW_AT_high_pc
:
13128 return "DW_AT_high_pc";
13129 case DW_AT_language
:
13130 return "DW_AT_language";
13132 return "DW_AT_member";
13134 return "DW_AT_discr";
13135 case DW_AT_discr_value
:
13136 return "DW_AT_discr_value";
13137 case DW_AT_visibility
:
13138 return "DW_AT_visibility";
13140 return "DW_AT_import";
13141 case DW_AT_string_length
:
13142 return "DW_AT_string_length";
13143 case DW_AT_common_reference
:
13144 return "DW_AT_common_reference";
13145 case DW_AT_comp_dir
:
13146 return "DW_AT_comp_dir";
13147 case DW_AT_const_value
:
13148 return "DW_AT_const_value";
13149 case DW_AT_containing_type
:
13150 return "DW_AT_containing_type";
13151 case DW_AT_default_value
:
13152 return "DW_AT_default_value";
13154 return "DW_AT_inline";
13155 case DW_AT_is_optional
:
13156 return "DW_AT_is_optional";
13157 case DW_AT_lower_bound
:
13158 return "DW_AT_lower_bound";
13159 case DW_AT_producer
:
13160 return "DW_AT_producer";
13161 case DW_AT_prototyped
:
13162 return "DW_AT_prototyped";
13163 case DW_AT_return_addr
:
13164 return "DW_AT_return_addr";
13165 case DW_AT_start_scope
:
13166 return "DW_AT_start_scope";
13167 case DW_AT_bit_stride
:
13168 return "DW_AT_bit_stride";
13169 case DW_AT_upper_bound
:
13170 return "DW_AT_upper_bound";
13171 case DW_AT_abstract_origin
:
13172 return "DW_AT_abstract_origin";
13173 case DW_AT_accessibility
:
13174 return "DW_AT_accessibility";
13175 case DW_AT_address_class
:
13176 return "DW_AT_address_class";
13177 case DW_AT_artificial
:
13178 return "DW_AT_artificial";
13179 case DW_AT_base_types
:
13180 return "DW_AT_base_types";
13181 case DW_AT_calling_convention
:
13182 return "DW_AT_calling_convention";
13184 return "DW_AT_count";
13185 case DW_AT_data_member_location
:
13186 return "DW_AT_data_member_location";
13187 case DW_AT_decl_column
:
13188 return "DW_AT_decl_column";
13189 case DW_AT_decl_file
:
13190 return "DW_AT_decl_file";
13191 case DW_AT_decl_line
:
13192 return "DW_AT_decl_line";
13193 case DW_AT_declaration
:
13194 return "DW_AT_declaration";
13195 case DW_AT_discr_list
:
13196 return "DW_AT_discr_list";
13197 case DW_AT_encoding
:
13198 return "DW_AT_encoding";
13199 case DW_AT_external
:
13200 return "DW_AT_external";
13201 case DW_AT_frame_base
:
13202 return "DW_AT_frame_base";
13204 return "DW_AT_friend";
13205 case DW_AT_identifier_case
:
13206 return "DW_AT_identifier_case";
13207 case DW_AT_macro_info
:
13208 return "DW_AT_macro_info";
13209 case DW_AT_namelist_items
:
13210 return "DW_AT_namelist_items";
13211 case DW_AT_priority
:
13212 return "DW_AT_priority";
13213 case DW_AT_segment
:
13214 return "DW_AT_segment";
13215 case DW_AT_specification
:
13216 return "DW_AT_specification";
13217 case DW_AT_static_link
:
13218 return "DW_AT_static_link";
13220 return "DW_AT_type";
13221 case DW_AT_use_location
:
13222 return "DW_AT_use_location";
13223 case DW_AT_variable_parameter
:
13224 return "DW_AT_variable_parameter";
13225 case DW_AT_virtuality
:
13226 return "DW_AT_virtuality";
13227 case DW_AT_vtable_elem_location
:
13228 return "DW_AT_vtable_elem_location";
13229 /* DWARF 3 values. */
13230 case DW_AT_allocated
:
13231 return "DW_AT_allocated";
13232 case DW_AT_associated
:
13233 return "DW_AT_associated";
13234 case DW_AT_data_location
:
13235 return "DW_AT_data_location";
13236 case DW_AT_byte_stride
:
13237 return "DW_AT_byte_stride";
13238 case DW_AT_entry_pc
:
13239 return "DW_AT_entry_pc";
13240 case DW_AT_use_UTF8
:
13241 return "DW_AT_use_UTF8";
13242 case DW_AT_extension
:
13243 return "DW_AT_extension";
13245 return "DW_AT_ranges";
13246 case DW_AT_trampoline
:
13247 return "DW_AT_trampoline";
13248 case DW_AT_call_column
:
13249 return "DW_AT_call_column";
13250 case DW_AT_call_file
:
13251 return "DW_AT_call_file";
13252 case DW_AT_call_line
:
13253 return "DW_AT_call_line";
13254 case DW_AT_description
:
13255 return "DW_AT_description";
13256 case DW_AT_binary_scale
:
13257 return "DW_AT_binary_scale";
13258 case DW_AT_decimal_scale
:
13259 return "DW_AT_decimal_scale";
13261 return "DW_AT_small";
13262 case DW_AT_decimal_sign
:
13263 return "DW_AT_decimal_sign";
13264 case DW_AT_digit_count
:
13265 return "DW_AT_digit_count";
13266 case DW_AT_picture_string
:
13267 return "DW_AT_picture_string";
13268 case DW_AT_mutable
:
13269 return "DW_AT_mutable";
13270 case DW_AT_threads_scaled
:
13271 return "DW_AT_threads_scaled";
13272 case DW_AT_explicit
:
13273 return "DW_AT_explicit";
13274 case DW_AT_object_pointer
:
13275 return "DW_AT_object_pointer";
13276 case DW_AT_endianity
:
13277 return "DW_AT_endianity";
13278 case DW_AT_elemental
:
13279 return "DW_AT_elemental";
13281 return "DW_AT_pure";
13282 case DW_AT_recursive
:
13283 return "DW_AT_recursive";
13284 /* DWARF 4 values. */
13285 case DW_AT_signature
:
13286 return "DW_AT_signature";
13287 case DW_AT_linkage_name
:
13288 return "DW_AT_linkage_name";
13289 /* SGI/MIPS extensions. */
13290 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13291 case DW_AT_MIPS_fde
:
13292 return "DW_AT_MIPS_fde";
13294 case DW_AT_MIPS_loop_begin
:
13295 return "DW_AT_MIPS_loop_begin";
13296 case DW_AT_MIPS_tail_loop_begin
:
13297 return "DW_AT_MIPS_tail_loop_begin";
13298 case DW_AT_MIPS_epilog_begin
:
13299 return "DW_AT_MIPS_epilog_begin";
13300 case DW_AT_MIPS_loop_unroll_factor
:
13301 return "DW_AT_MIPS_loop_unroll_factor";
13302 case DW_AT_MIPS_software_pipeline_depth
:
13303 return "DW_AT_MIPS_software_pipeline_depth";
13304 case DW_AT_MIPS_linkage_name
:
13305 return "DW_AT_MIPS_linkage_name";
13306 case DW_AT_MIPS_stride
:
13307 return "DW_AT_MIPS_stride";
13308 case DW_AT_MIPS_abstract_name
:
13309 return "DW_AT_MIPS_abstract_name";
13310 case DW_AT_MIPS_clone_origin
:
13311 return "DW_AT_MIPS_clone_origin";
13312 case DW_AT_MIPS_has_inlines
:
13313 return "DW_AT_MIPS_has_inlines";
13314 /* HP extensions. */
13315 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13316 case DW_AT_HP_block_index
:
13317 return "DW_AT_HP_block_index";
13319 case DW_AT_HP_unmodifiable
:
13320 return "DW_AT_HP_unmodifiable";
13321 case DW_AT_HP_actuals_stmt_list
:
13322 return "DW_AT_HP_actuals_stmt_list";
13323 case DW_AT_HP_proc_per_section
:
13324 return "DW_AT_HP_proc_per_section";
13325 case DW_AT_HP_raw_data_ptr
:
13326 return "DW_AT_HP_raw_data_ptr";
13327 case DW_AT_HP_pass_by_reference
:
13328 return "DW_AT_HP_pass_by_reference";
13329 case DW_AT_HP_opt_level
:
13330 return "DW_AT_HP_opt_level";
13331 case DW_AT_HP_prof_version_id
:
13332 return "DW_AT_HP_prof_version_id";
13333 case DW_AT_HP_opt_flags
:
13334 return "DW_AT_HP_opt_flags";
13335 case DW_AT_HP_cold_region_low_pc
:
13336 return "DW_AT_HP_cold_region_low_pc";
13337 case DW_AT_HP_cold_region_high_pc
:
13338 return "DW_AT_HP_cold_region_high_pc";
13339 case DW_AT_HP_all_variables_modifiable
:
13340 return "DW_AT_HP_all_variables_modifiable";
13341 case DW_AT_HP_linkage_name
:
13342 return "DW_AT_HP_linkage_name";
13343 case DW_AT_HP_prof_flags
:
13344 return "DW_AT_HP_prof_flags";
13345 /* GNU extensions. */
13346 case DW_AT_sf_names
:
13347 return "DW_AT_sf_names";
13348 case DW_AT_src_info
:
13349 return "DW_AT_src_info";
13350 case DW_AT_mac_info
:
13351 return "DW_AT_mac_info";
13352 case DW_AT_src_coords
:
13353 return "DW_AT_src_coords";
13354 case DW_AT_body_begin
:
13355 return "DW_AT_body_begin";
13356 case DW_AT_body_end
:
13357 return "DW_AT_body_end";
13358 case DW_AT_GNU_vector
:
13359 return "DW_AT_GNU_vector";
13360 case DW_AT_GNU_odr_signature
:
13361 return "DW_AT_GNU_odr_signature";
13362 /* VMS extensions. */
13363 case DW_AT_VMS_rtnbeg_pd_address
:
13364 return "DW_AT_VMS_rtnbeg_pd_address";
13365 /* UPC extension. */
13366 case DW_AT_upc_threads_scaled
:
13367 return "DW_AT_upc_threads_scaled";
13368 /* PGI (STMicroelectronics) extensions. */
13369 case DW_AT_PGI_lbase
:
13370 return "DW_AT_PGI_lbase";
13371 case DW_AT_PGI_soffset
:
13372 return "DW_AT_PGI_soffset";
13373 case DW_AT_PGI_lstride
:
13374 return "DW_AT_PGI_lstride";
13376 return "DW_AT_<unknown>";
13380 /* Convert a DWARF value form code into its string name. */
13383 dwarf_form_name (unsigned form
)
13388 return "DW_FORM_addr";
13389 case DW_FORM_block2
:
13390 return "DW_FORM_block2";
13391 case DW_FORM_block4
:
13392 return "DW_FORM_block4";
13393 case DW_FORM_data2
:
13394 return "DW_FORM_data2";
13395 case DW_FORM_data4
:
13396 return "DW_FORM_data4";
13397 case DW_FORM_data8
:
13398 return "DW_FORM_data8";
13399 case DW_FORM_string
:
13400 return "DW_FORM_string";
13401 case DW_FORM_block
:
13402 return "DW_FORM_block";
13403 case DW_FORM_block1
:
13404 return "DW_FORM_block1";
13405 case DW_FORM_data1
:
13406 return "DW_FORM_data1";
13408 return "DW_FORM_flag";
13409 case DW_FORM_sdata
:
13410 return "DW_FORM_sdata";
13412 return "DW_FORM_strp";
13413 case DW_FORM_udata
:
13414 return "DW_FORM_udata";
13415 case DW_FORM_ref_addr
:
13416 return "DW_FORM_ref_addr";
13418 return "DW_FORM_ref1";
13420 return "DW_FORM_ref2";
13422 return "DW_FORM_ref4";
13424 return "DW_FORM_ref8";
13425 case DW_FORM_ref_udata
:
13426 return "DW_FORM_ref_udata";
13427 case DW_FORM_indirect
:
13428 return "DW_FORM_indirect";
13429 case DW_FORM_sec_offset
:
13430 return "DW_FORM_sec_offset";
13431 case DW_FORM_exprloc
:
13432 return "DW_FORM_exprloc";
13433 case DW_FORM_flag_present
:
13434 return "DW_FORM_flag_present";
13435 case DW_FORM_ref_sig8
:
13436 return "DW_FORM_ref_sig8";
13438 return "DW_FORM_<unknown>";
13442 /* Convert a DWARF stack opcode into its string name. */
13445 dwarf_stack_op_name (unsigned op
)
13450 return "DW_OP_addr";
13452 return "DW_OP_deref";
13453 case DW_OP_const1u
:
13454 return "DW_OP_const1u";
13455 case DW_OP_const1s
:
13456 return "DW_OP_const1s";
13457 case DW_OP_const2u
:
13458 return "DW_OP_const2u";
13459 case DW_OP_const2s
:
13460 return "DW_OP_const2s";
13461 case DW_OP_const4u
:
13462 return "DW_OP_const4u";
13463 case DW_OP_const4s
:
13464 return "DW_OP_const4s";
13465 case DW_OP_const8u
:
13466 return "DW_OP_const8u";
13467 case DW_OP_const8s
:
13468 return "DW_OP_const8s";
13470 return "DW_OP_constu";
13472 return "DW_OP_consts";
13474 return "DW_OP_dup";
13476 return "DW_OP_drop";
13478 return "DW_OP_over";
13480 return "DW_OP_pick";
13482 return "DW_OP_swap";
13484 return "DW_OP_rot";
13486 return "DW_OP_xderef";
13488 return "DW_OP_abs";
13490 return "DW_OP_and";
13492 return "DW_OP_div";
13494 return "DW_OP_minus";
13496 return "DW_OP_mod";
13498 return "DW_OP_mul";
13500 return "DW_OP_neg";
13502 return "DW_OP_not";
13506 return "DW_OP_plus";
13507 case DW_OP_plus_uconst
:
13508 return "DW_OP_plus_uconst";
13510 return "DW_OP_shl";
13512 return "DW_OP_shr";
13514 return "DW_OP_shra";
13516 return "DW_OP_xor";
13518 return "DW_OP_bra";
13532 return "DW_OP_skip";
13534 return "DW_OP_lit0";
13536 return "DW_OP_lit1";
13538 return "DW_OP_lit2";
13540 return "DW_OP_lit3";
13542 return "DW_OP_lit4";
13544 return "DW_OP_lit5";
13546 return "DW_OP_lit6";
13548 return "DW_OP_lit7";
13550 return "DW_OP_lit8";
13552 return "DW_OP_lit9";
13554 return "DW_OP_lit10";
13556 return "DW_OP_lit11";
13558 return "DW_OP_lit12";
13560 return "DW_OP_lit13";
13562 return "DW_OP_lit14";
13564 return "DW_OP_lit15";
13566 return "DW_OP_lit16";
13568 return "DW_OP_lit17";
13570 return "DW_OP_lit18";
13572 return "DW_OP_lit19";
13574 return "DW_OP_lit20";
13576 return "DW_OP_lit21";
13578 return "DW_OP_lit22";
13580 return "DW_OP_lit23";
13582 return "DW_OP_lit24";
13584 return "DW_OP_lit25";
13586 return "DW_OP_lit26";
13588 return "DW_OP_lit27";
13590 return "DW_OP_lit28";
13592 return "DW_OP_lit29";
13594 return "DW_OP_lit30";
13596 return "DW_OP_lit31";
13598 return "DW_OP_reg0";
13600 return "DW_OP_reg1";
13602 return "DW_OP_reg2";
13604 return "DW_OP_reg3";
13606 return "DW_OP_reg4";
13608 return "DW_OP_reg5";
13610 return "DW_OP_reg6";
13612 return "DW_OP_reg7";
13614 return "DW_OP_reg8";
13616 return "DW_OP_reg9";
13618 return "DW_OP_reg10";
13620 return "DW_OP_reg11";
13622 return "DW_OP_reg12";
13624 return "DW_OP_reg13";
13626 return "DW_OP_reg14";
13628 return "DW_OP_reg15";
13630 return "DW_OP_reg16";
13632 return "DW_OP_reg17";
13634 return "DW_OP_reg18";
13636 return "DW_OP_reg19";
13638 return "DW_OP_reg20";
13640 return "DW_OP_reg21";
13642 return "DW_OP_reg22";
13644 return "DW_OP_reg23";
13646 return "DW_OP_reg24";
13648 return "DW_OP_reg25";
13650 return "DW_OP_reg26";
13652 return "DW_OP_reg27";
13654 return "DW_OP_reg28";
13656 return "DW_OP_reg29";
13658 return "DW_OP_reg30";
13660 return "DW_OP_reg31";
13662 return "DW_OP_breg0";
13664 return "DW_OP_breg1";
13666 return "DW_OP_breg2";
13668 return "DW_OP_breg3";
13670 return "DW_OP_breg4";
13672 return "DW_OP_breg5";
13674 return "DW_OP_breg6";
13676 return "DW_OP_breg7";
13678 return "DW_OP_breg8";
13680 return "DW_OP_breg9";
13682 return "DW_OP_breg10";
13684 return "DW_OP_breg11";
13686 return "DW_OP_breg12";
13688 return "DW_OP_breg13";
13690 return "DW_OP_breg14";
13692 return "DW_OP_breg15";
13694 return "DW_OP_breg16";
13696 return "DW_OP_breg17";
13698 return "DW_OP_breg18";
13700 return "DW_OP_breg19";
13702 return "DW_OP_breg20";
13704 return "DW_OP_breg21";
13706 return "DW_OP_breg22";
13708 return "DW_OP_breg23";
13710 return "DW_OP_breg24";
13712 return "DW_OP_breg25";
13714 return "DW_OP_breg26";
13716 return "DW_OP_breg27";
13718 return "DW_OP_breg28";
13720 return "DW_OP_breg29";
13722 return "DW_OP_breg30";
13724 return "DW_OP_breg31";
13726 return "DW_OP_regx";
13728 return "DW_OP_fbreg";
13730 return "DW_OP_bregx";
13732 return "DW_OP_piece";
13733 case DW_OP_deref_size
:
13734 return "DW_OP_deref_size";
13735 case DW_OP_xderef_size
:
13736 return "DW_OP_xderef_size";
13738 return "DW_OP_nop";
13739 /* DWARF 3 extensions. */
13740 case DW_OP_push_object_address
:
13741 return "DW_OP_push_object_address";
13743 return "DW_OP_call2";
13745 return "DW_OP_call4";
13746 case DW_OP_call_ref
:
13747 return "DW_OP_call_ref";
13748 case DW_OP_form_tls_address
:
13749 return "DW_OP_form_tls_address";
13750 case DW_OP_call_frame_cfa
:
13751 return "DW_OP_call_frame_cfa";
13752 case DW_OP_bit_piece
:
13753 return "DW_OP_bit_piece";
13754 /* DWARF 4 extensions. */
13755 case DW_OP_implicit_value
:
13756 return "DW_OP_implicit_value";
13757 case DW_OP_stack_value
:
13758 return "DW_OP_stack_value";
13759 /* GNU extensions. */
13760 case DW_OP_GNU_push_tls_address
:
13761 return "DW_OP_GNU_push_tls_address";
13762 case DW_OP_GNU_uninit
:
13763 return "DW_OP_GNU_uninit";
13764 case DW_OP_GNU_implicit_pointer
:
13765 return "DW_OP_GNU_implicit_pointer";
13766 case DW_OP_GNU_entry_value
:
13767 return "DW_OP_GNU_entry_value";
13768 case DW_OP_GNU_const_type
:
13769 return "DW_OP_GNU_const_type";
13770 case DW_OP_GNU_regval_type
:
13771 return "DW_OP_GNU_regval_type";
13772 case DW_OP_GNU_deref_type
:
13773 return "DW_OP_GNU_deref_type";
13774 case DW_OP_GNU_convert
:
13775 return "DW_OP_GNU_convert";
13776 case DW_OP_GNU_reinterpret
:
13777 return "DW_OP_GNU_reinterpret";
13784 dwarf_bool_name (unsigned mybool
)
13792 /* Convert a DWARF type code into its string name. */
13795 dwarf_type_encoding_name (unsigned enc
)
13800 return "DW_ATE_void";
13801 case DW_ATE_address
:
13802 return "DW_ATE_address";
13803 case DW_ATE_boolean
:
13804 return "DW_ATE_boolean";
13805 case DW_ATE_complex_float
:
13806 return "DW_ATE_complex_float";
13808 return "DW_ATE_float";
13809 case DW_ATE_signed
:
13810 return "DW_ATE_signed";
13811 case DW_ATE_signed_char
:
13812 return "DW_ATE_signed_char";
13813 case DW_ATE_unsigned
:
13814 return "DW_ATE_unsigned";
13815 case DW_ATE_unsigned_char
:
13816 return "DW_ATE_unsigned_char";
13818 case DW_ATE_imaginary_float
:
13819 return "DW_ATE_imaginary_float";
13820 case DW_ATE_packed_decimal
:
13821 return "DW_ATE_packed_decimal";
13822 case DW_ATE_numeric_string
:
13823 return "DW_ATE_numeric_string";
13824 case DW_ATE_edited
:
13825 return "DW_ATE_edited";
13826 case DW_ATE_signed_fixed
:
13827 return "DW_ATE_signed_fixed";
13828 case DW_ATE_unsigned_fixed
:
13829 return "DW_ATE_unsigned_fixed";
13830 case DW_ATE_decimal_float
:
13831 return "DW_ATE_decimal_float";
13834 return "DW_ATE_UTF";
13835 /* HP extensions. */
13836 case DW_ATE_HP_float80
:
13837 return "DW_ATE_HP_float80";
13838 case DW_ATE_HP_complex_float80
:
13839 return "DW_ATE_HP_complex_float80";
13840 case DW_ATE_HP_float128
:
13841 return "DW_ATE_HP_float128";
13842 case DW_ATE_HP_complex_float128
:
13843 return "DW_ATE_HP_complex_float128";
13844 case DW_ATE_HP_floathpintel
:
13845 return "DW_ATE_HP_floathpintel";
13846 case DW_ATE_HP_imaginary_float80
:
13847 return "DW_ATE_HP_imaginary_float80";
13848 case DW_ATE_HP_imaginary_float128
:
13849 return "DW_ATE_HP_imaginary_float128";
13851 return "DW_ATE_<unknown>";
13855 /* Convert a DWARF call frame info operation to its string name. */
13859 dwarf_cfi_name (unsigned cfi_opc
)
13863 case DW_CFA_advance_loc
:
13864 return "DW_CFA_advance_loc";
13865 case DW_CFA_offset
:
13866 return "DW_CFA_offset";
13867 case DW_CFA_restore
:
13868 return "DW_CFA_restore";
13870 return "DW_CFA_nop";
13871 case DW_CFA_set_loc
:
13872 return "DW_CFA_set_loc";
13873 case DW_CFA_advance_loc1
:
13874 return "DW_CFA_advance_loc1";
13875 case DW_CFA_advance_loc2
:
13876 return "DW_CFA_advance_loc2";
13877 case DW_CFA_advance_loc4
:
13878 return "DW_CFA_advance_loc4";
13879 case DW_CFA_offset_extended
:
13880 return "DW_CFA_offset_extended";
13881 case DW_CFA_restore_extended
:
13882 return "DW_CFA_restore_extended";
13883 case DW_CFA_undefined
:
13884 return "DW_CFA_undefined";
13885 case DW_CFA_same_value
:
13886 return "DW_CFA_same_value";
13887 case DW_CFA_register
:
13888 return "DW_CFA_register";
13889 case DW_CFA_remember_state
:
13890 return "DW_CFA_remember_state";
13891 case DW_CFA_restore_state
:
13892 return "DW_CFA_restore_state";
13893 case DW_CFA_def_cfa
:
13894 return "DW_CFA_def_cfa";
13895 case DW_CFA_def_cfa_register
:
13896 return "DW_CFA_def_cfa_register";
13897 case DW_CFA_def_cfa_offset
:
13898 return "DW_CFA_def_cfa_offset";
13900 case DW_CFA_def_cfa_expression
:
13901 return "DW_CFA_def_cfa_expression";
13902 case DW_CFA_expression
:
13903 return "DW_CFA_expression";
13904 case DW_CFA_offset_extended_sf
:
13905 return "DW_CFA_offset_extended_sf";
13906 case DW_CFA_def_cfa_sf
:
13907 return "DW_CFA_def_cfa_sf";
13908 case DW_CFA_def_cfa_offset_sf
:
13909 return "DW_CFA_def_cfa_offset_sf";
13910 case DW_CFA_val_offset
:
13911 return "DW_CFA_val_offset";
13912 case DW_CFA_val_offset_sf
:
13913 return "DW_CFA_val_offset_sf";
13914 case DW_CFA_val_expression
:
13915 return "DW_CFA_val_expression";
13916 /* SGI/MIPS specific. */
13917 case DW_CFA_MIPS_advance_loc8
:
13918 return "DW_CFA_MIPS_advance_loc8";
13919 /* GNU extensions. */
13920 case DW_CFA_GNU_window_save
:
13921 return "DW_CFA_GNU_window_save";
13922 case DW_CFA_GNU_args_size
:
13923 return "DW_CFA_GNU_args_size";
13924 case DW_CFA_GNU_negative_offset_extended
:
13925 return "DW_CFA_GNU_negative_offset_extended";
13927 return "DW_CFA_<unknown>";
13933 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13937 print_spaces (indent
, f
);
13938 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13939 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13941 if (die
->parent
!= NULL
)
13943 print_spaces (indent
, f
);
13944 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13945 die
->parent
->offset
);
13948 print_spaces (indent
, f
);
13949 fprintf_unfiltered (f
, " has children: %s\n",
13950 dwarf_bool_name (die
->child
!= NULL
));
13952 print_spaces (indent
, f
);
13953 fprintf_unfiltered (f
, " attributes:\n");
13955 for (i
= 0; i
< die
->num_attrs
; ++i
)
13957 print_spaces (indent
, f
);
13958 fprintf_unfiltered (f
, " %s (%s) ",
13959 dwarf_attr_name (die
->attrs
[i
].name
),
13960 dwarf_form_name (die
->attrs
[i
].form
));
13962 switch (die
->attrs
[i
].form
)
13964 case DW_FORM_ref_addr
:
13966 fprintf_unfiltered (f
, "address: ");
13967 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13969 case DW_FORM_block2
:
13970 case DW_FORM_block4
:
13971 case DW_FORM_block
:
13972 case DW_FORM_block1
:
13973 fprintf_unfiltered (f
, "block: size %d",
13974 DW_BLOCK (&die
->attrs
[i
])->size
);
13976 case DW_FORM_exprloc
:
13977 fprintf_unfiltered (f
, "expression: size %u",
13978 DW_BLOCK (&die
->attrs
[i
])->size
);
13983 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13984 (long) (DW_ADDR (&die
->attrs
[i
])));
13986 case DW_FORM_data1
:
13987 case DW_FORM_data2
:
13988 case DW_FORM_data4
:
13989 case DW_FORM_data8
:
13990 case DW_FORM_udata
:
13991 case DW_FORM_sdata
:
13992 fprintf_unfiltered (f
, "constant: %s",
13993 pulongest (DW_UNSND (&die
->attrs
[i
])));
13995 case DW_FORM_sec_offset
:
13996 fprintf_unfiltered (f
, "section offset: %s",
13997 pulongest (DW_UNSND (&die
->attrs
[i
])));
13999 case DW_FORM_ref_sig8
:
14000 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14001 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14002 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
14004 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14006 case DW_FORM_string
:
14008 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14009 DW_STRING (&die
->attrs
[i
])
14010 ? DW_STRING (&die
->attrs
[i
]) : "",
14011 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14014 if (DW_UNSND (&die
->attrs
[i
]))
14015 fprintf_unfiltered (f
, "flag: TRUE");
14017 fprintf_unfiltered (f
, "flag: FALSE");
14019 case DW_FORM_flag_present
:
14020 fprintf_unfiltered (f
, "flag: TRUE");
14022 case DW_FORM_indirect
:
14023 /* The reader will have reduced the indirect form to
14024 the "base form" so this form should not occur. */
14025 fprintf_unfiltered (f
,
14026 "unexpected attribute form: DW_FORM_indirect");
14029 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14030 die
->attrs
[i
].form
);
14033 fprintf_unfiltered (f
, "\n");
14038 dump_die_for_error (struct die_info
*die
)
14040 dump_die_shallow (gdb_stderr
, 0, die
);
14044 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14046 int indent
= level
* 4;
14048 gdb_assert (die
!= NULL
);
14050 if (level
>= max_level
)
14053 dump_die_shallow (f
, indent
, die
);
14055 if (die
->child
!= NULL
)
14057 print_spaces (indent
, f
);
14058 fprintf_unfiltered (f
, " Children:");
14059 if (level
+ 1 < max_level
)
14061 fprintf_unfiltered (f
, "\n");
14062 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14066 fprintf_unfiltered (f
,
14067 " [not printed, max nesting level reached]\n");
14071 if (die
->sibling
!= NULL
&& level
> 0)
14073 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14077 /* This is called from the pdie macro in gdbinit.in.
14078 It's not static so gcc will keep a copy callable from gdb. */
14081 dump_die (struct die_info
*die
, int max_level
)
14083 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14087 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14091 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14097 is_ref_attr (struct attribute
*attr
)
14099 switch (attr
->form
)
14101 case DW_FORM_ref_addr
:
14106 case DW_FORM_ref_udata
:
14113 static unsigned int
14114 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14116 if (is_ref_attr (attr
))
14117 return DW_ADDR (attr
);
14119 complaint (&symfile_complaints
,
14120 _("unsupported die ref attribute form: '%s'"),
14121 dwarf_form_name (attr
->form
));
14125 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14126 * the value held by the attribute is not constant. */
14129 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14131 if (attr
->form
== DW_FORM_sdata
)
14132 return DW_SND (attr
);
14133 else if (attr
->form
== DW_FORM_udata
14134 || attr
->form
== DW_FORM_data1
14135 || attr
->form
== DW_FORM_data2
14136 || attr
->form
== DW_FORM_data4
14137 || attr
->form
== DW_FORM_data8
)
14138 return DW_UNSND (attr
);
14141 complaint (&symfile_complaints
,
14142 _("Attribute value is not a constant (%s)"),
14143 dwarf_form_name (attr
->form
));
14144 return default_value
;
14148 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14149 unit and add it to our queue.
14150 The result is non-zero if PER_CU was queued, otherwise the result is zero
14151 meaning either PER_CU is already queued or it is already loaded. */
14154 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14155 struct dwarf2_per_cu_data
*per_cu
)
14157 /* We may arrive here during partial symbol reading, if we need full
14158 DIEs to process an unusual case (e.g. template arguments). Do
14159 not queue PER_CU, just tell our caller to load its DIEs. */
14160 if (dwarf2_per_objfile
->reading_partial_symbols
)
14162 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14167 /* Mark the dependence relation so that we don't flush PER_CU
14169 dwarf2_add_dependence (this_cu
, per_cu
);
14171 /* If it's already on the queue, we have nothing to do. */
14172 if (per_cu
->queued
)
14175 /* If the compilation unit is already loaded, just mark it as
14177 if (per_cu
->cu
!= NULL
)
14179 per_cu
->cu
->last_used
= 0;
14183 /* Add it to the queue. */
14184 queue_comp_unit (per_cu
, this_cu
->objfile
);
14189 /* Follow reference or signature attribute ATTR of SRC_DIE.
14190 On entry *REF_CU is the CU of SRC_DIE.
14191 On exit *REF_CU is the CU of the result. */
14193 static struct die_info
*
14194 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14195 struct dwarf2_cu
**ref_cu
)
14197 struct die_info
*die
;
14199 if (is_ref_attr (attr
))
14200 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14201 else if (attr
->form
== DW_FORM_ref_sig8
)
14202 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14205 dump_die_for_error (src_die
);
14206 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14207 (*ref_cu
)->objfile
->name
);
14213 /* Follow reference OFFSET.
14214 On entry *REF_CU is the CU of the source die referencing OFFSET.
14215 On exit *REF_CU is the CU of the result.
14216 Returns NULL if OFFSET is invalid. */
14218 static struct die_info
*
14219 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14221 struct die_info temp_die
;
14222 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14224 gdb_assert (cu
->per_cu
!= NULL
);
14228 if (cu
->per_cu
->debug_type_section
)
14230 /* .debug_types CUs cannot reference anything outside their CU.
14231 If they need to, they have to reference a signatured type via
14232 DW_FORM_ref_sig8. */
14233 if (! offset_in_cu_p (&cu
->header
, offset
))
14236 else if (! offset_in_cu_p (&cu
->header
, offset
))
14238 struct dwarf2_per_cu_data
*per_cu
;
14240 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14242 /* If necessary, add it to the queue and load its DIEs. */
14243 if (maybe_queue_comp_unit (cu
, per_cu
))
14244 load_full_comp_unit (per_cu
, cu
->objfile
);
14246 target_cu
= per_cu
->cu
;
14248 else if (cu
->dies
== NULL
)
14250 /* We're loading full DIEs during partial symbol reading. */
14251 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14252 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
14255 *ref_cu
= target_cu
;
14256 temp_die
.offset
= offset
;
14257 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14260 /* Follow reference attribute ATTR of SRC_DIE.
14261 On entry *REF_CU is the CU of SRC_DIE.
14262 On exit *REF_CU is the CU of the result. */
14264 static struct die_info
*
14265 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14266 struct dwarf2_cu
**ref_cu
)
14268 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14269 struct dwarf2_cu
*cu
= *ref_cu
;
14270 struct die_info
*die
;
14272 die
= follow_die_offset (offset
, ref_cu
);
14274 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14275 "at 0x%x [in module %s]"),
14276 offset
, src_die
->offset
, cu
->objfile
->name
);
14281 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14282 Returned value is intended for DW_OP_call*. Returned
14283 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14285 struct dwarf2_locexpr_baton
14286 dwarf2_fetch_die_location_block (unsigned int offset
,
14287 struct dwarf2_per_cu_data
*per_cu
,
14288 CORE_ADDR (*get_frame_pc
) (void *baton
),
14291 struct dwarf2_cu
*cu
;
14292 struct die_info
*die
;
14293 struct attribute
*attr
;
14294 struct dwarf2_locexpr_baton retval
;
14296 dw2_setup (per_cu
->objfile
);
14298 if (per_cu
->cu
== NULL
)
14302 die
= follow_die_offset (offset
, &cu
);
14304 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14305 offset
, per_cu
->cu
->objfile
->name
);
14307 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14310 /* DWARF: "If there is no such attribute, then there is no effect.".
14311 DATA is ignored if SIZE is 0. */
14313 retval
.data
= NULL
;
14316 else if (attr_form_is_section_offset (attr
))
14318 struct dwarf2_loclist_baton loclist_baton
;
14319 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14322 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14324 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14326 retval
.size
= size
;
14330 if (!attr_form_is_block (attr
))
14331 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14332 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14333 offset
, per_cu
->cu
->objfile
->name
);
14335 retval
.data
= DW_BLOCK (attr
)->data
;
14336 retval
.size
= DW_BLOCK (attr
)->size
;
14338 retval
.per_cu
= cu
->per_cu
;
14340 age_cached_comp_units ();
14345 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14349 dwarf2_get_die_type (unsigned int die_offset
,
14350 struct dwarf2_per_cu_data
*per_cu
)
14352 dw2_setup (per_cu
->objfile
);
14353 return get_die_type_at_offset (die_offset
, per_cu
);
14356 /* Follow the signature attribute ATTR in SRC_DIE.
14357 On entry *REF_CU is the CU of SRC_DIE.
14358 On exit *REF_CU is the CU of the result. */
14360 static struct die_info
*
14361 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14362 struct dwarf2_cu
**ref_cu
)
14364 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14365 struct die_info temp_die
;
14366 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14367 struct dwarf2_cu
*sig_cu
;
14368 struct die_info
*die
;
14370 /* sig_type will be NULL if the signatured type is missing from
14372 if (sig_type
== NULL
)
14373 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14374 "at 0x%x [in module %s]"),
14375 src_die
->offset
, objfile
->name
);
14377 /* If necessary, add it to the queue and load its DIEs. */
14379 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14380 read_signatured_type (objfile
, sig_type
);
14382 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14384 sig_cu
= sig_type
->per_cu
.cu
;
14385 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14386 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14393 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14394 "from DIE at 0x%x [in module %s]"),
14395 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14398 /* Given an offset of a signatured type, return its signatured_type. */
14400 static struct signatured_type
*
14401 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14402 struct dwarf2_section_info
*section
,
14403 unsigned int offset
)
14405 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14406 unsigned int length
, initial_length_size
;
14407 unsigned int sig_offset
;
14408 struct signatured_type find_entry
, *type_sig
;
14410 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14411 sig_offset
= (initial_length_size
14413 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14414 + 1 /*address_size*/);
14415 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14416 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14418 /* This is only used to lookup previously recorded types.
14419 If we didn't find it, it's our bug. */
14420 gdb_assert (type_sig
!= NULL
);
14421 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14426 /* Read in signatured type at OFFSET and build its CU and die(s). */
14429 read_signatured_type_at_offset (struct objfile
*objfile
,
14430 struct dwarf2_section_info
*sect
,
14431 unsigned int offset
)
14433 struct signatured_type
*type_sig
;
14435 dwarf2_read_section (objfile
, sect
);
14437 /* We have the section offset, but we need the signature to do the
14438 hash table lookup. */
14439 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14441 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14443 read_signatured_type (objfile
, type_sig
);
14445 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14448 /* Read in a signatured type and build its CU and DIEs. */
14451 read_signatured_type (struct objfile
*objfile
,
14452 struct signatured_type
*type_sig
)
14454 gdb_byte
*types_ptr
;
14455 struct die_reader_specs reader_specs
;
14456 struct dwarf2_cu
*cu
;
14457 ULONGEST signature
;
14458 struct cleanup
*back_to
, *free_cu_cleanup
;
14459 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14461 dwarf2_read_section (objfile
, section
);
14462 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14464 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14466 cu
= xmalloc (sizeof (*cu
));
14467 init_one_comp_unit (cu
, objfile
);
14469 type_sig
->per_cu
.cu
= cu
;
14470 cu
->per_cu
= &type_sig
->per_cu
;
14472 /* If an error occurs while loading, release our storage. */
14473 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14475 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14476 types_ptr
, objfile
->obfd
);
14477 gdb_assert (signature
== type_sig
->signature
);
14480 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14484 &cu
->comp_unit_obstack
,
14485 hashtab_obstack_allocate
,
14486 dummy_obstack_deallocate
);
14488 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14489 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14491 init_cu_die_reader (&reader_specs
, cu
);
14493 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14496 /* We try not to read any attributes in this function, because not
14497 all objfiles needed for references have been loaded yet, and symbol
14498 table processing isn't initialized. But we have to set the CU language,
14499 or we won't be able to build types correctly. */
14500 prepare_one_comp_unit (cu
, cu
->dies
);
14502 do_cleanups (back_to
);
14504 /* We've successfully allocated this compilation unit. Let our caller
14505 clean it up when finished with it. */
14506 discard_cleanups (free_cu_cleanup
);
14508 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14509 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14512 /* Decode simple location descriptions.
14513 Given a pointer to a dwarf block that defines a location, compute
14514 the location and return the value.
14516 NOTE drow/2003-11-18: This function is called in two situations
14517 now: for the address of static or global variables (partial symbols
14518 only) and for offsets into structures which are expected to be
14519 (more or less) constant. The partial symbol case should go away,
14520 and only the constant case should remain. That will let this
14521 function complain more accurately. A few special modes are allowed
14522 without complaint for global variables (for instance, global
14523 register values and thread-local values).
14525 A location description containing no operations indicates that the
14526 object is optimized out. The return value is 0 for that case.
14527 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14528 callers will only want a very basic result and this can become a
14531 Note that stack[0] is unused except as a default error return. */
14534 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14536 struct objfile
*objfile
= cu
->objfile
;
14538 int size
= blk
->size
;
14539 gdb_byte
*data
= blk
->data
;
14540 CORE_ADDR stack
[64];
14542 unsigned int bytes_read
, unsnd
;
14548 stack
[++stacki
] = 0;
14587 stack
[++stacki
] = op
- DW_OP_lit0
;
14622 stack
[++stacki
] = op
- DW_OP_reg0
;
14624 dwarf2_complex_location_expr_complaint ();
14628 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14630 stack
[++stacki
] = unsnd
;
14632 dwarf2_complex_location_expr_complaint ();
14636 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14641 case DW_OP_const1u
:
14642 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14646 case DW_OP_const1s
:
14647 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14651 case DW_OP_const2u
:
14652 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14656 case DW_OP_const2s
:
14657 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14661 case DW_OP_const4u
:
14662 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14666 case DW_OP_const4s
:
14667 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14671 case DW_OP_const8u
:
14672 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14677 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14683 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14688 stack
[stacki
+ 1] = stack
[stacki
];
14693 stack
[stacki
- 1] += stack
[stacki
];
14697 case DW_OP_plus_uconst
:
14698 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14704 stack
[stacki
- 1] -= stack
[stacki
];
14709 /* If we're not the last op, then we definitely can't encode
14710 this using GDB's address_class enum. This is valid for partial
14711 global symbols, although the variable's address will be bogus
14714 dwarf2_complex_location_expr_complaint ();
14717 case DW_OP_GNU_push_tls_address
:
14718 /* The top of the stack has the offset from the beginning
14719 of the thread control block at which the variable is located. */
14720 /* Nothing should follow this operator, so the top of stack would
14722 /* This is valid for partial global symbols, but the variable's
14723 address will be bogus in the psymtab. Make it always at least
14724 non-zero to not look as a variable garbage collected by linker
14725 which have DW_OP_addr 0. */
14727 dwarf2_complex_location_expr_complaint ();
14731 case DW_OP_GNU_uninit
:
14736 const char *name
= dwarf_stack_op_name (op
);
14739 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14742 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14746 return (stack
[stacki
]);
14749 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14750 outside of the allocated space. Also enforce minimum>0. */
14751 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14753 complaint (&symfile_complaints
,
14754 _("location description stack overflow"));
14760 complaint (&symfile_complaints
,
14761 _("location description stack underflow"));
14765 return (stack
[stacki
]);
14768 /* memory allocation interface */
14770 static struct dwarf_block
*
14771 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14773 struct dwarf_block
*blk
;
14775 blk
= (struct dwarf_block
*)
14776 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14780 static struct abbrev_info
*
14781 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14783 struct abbrev_info
*abbrev
;
14785 abbrev
= (struct abbrev_info
*)
14786 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14787 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14791 static struct die_info
*
14792 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14794 struct die_info
*die
;
14795 size_t size
= sizeof (struct die_info
);
14798 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14800 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14801 memset (die
, 0, sizeof (struct die_info
));
14806 /* Macro support. */
14808 /* Return the full name of file number I in *LH's file name table.
14809 Use COMP_DIR as the name of the current directory of the
14810 compilation. The result is allocated using xmalloc; the caller is
14811 responsible for freeing it. */
14813 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14815 /* Is the file number a valid index into the line header's file name
14816 table? Remember that file numbers start with one, not zero. */
14817 if (1 <= file
&& file
<= lh
->num_file_names
)
14819 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14821 if (IS_ABSOLUTE_PATH (fe
->name
))
14822 return xstrdup (fe
->name
);
14830 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14836 dir_len
= strlen (dir
);
14837 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14838 strcpy (full_name
, dir
);
14839 full_name
[dir_len
] = '/';
14840 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14844 return xstrdup (fe
->name
);
14849 /* The compiler produced a bogus file number. We can at least
14850 record the macro definitions made in the file, even if we
14851 won't be able to find the file by name. */
14852 char fake_name
[80];
14854 sprintf (fake_name
, "<bad macro file number %d>", file
);
14856 complaint (&symfile_complaints
,
14857 _("bad file number in macro information (%d)"),
14860 return xstrdup (fake_name
);
14865 static struct macro_source_file
*
14866 macro_start_file (int file
, int line
,
14867 struct macro_source_file
*current_file
,
14868 const char *comp_dir
,
14869 struct line_header
*lh
, struct objfile
*objfile
)
14871 /* The full name of this source file. */
14872 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14874 /* We don't create a macro table for this compilation unit
14875 at all until we actually get a filename. */
14876 if (! pending_macros
)
14877 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14878 objfile
->macro_cache
);
14880 if (! current_file
)
14881 /* If we have no current file, then this must be the start_file
14882 directive for the compilation unit's main source file. */
14883 current_file
= macro_set_main (pending_macros
, full_name
);
14885 current_file
= macro_include (current_file
, line
, full_name
);
14889 return current_file
;
14893 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14894 followed by a null byte. */
14896 copy_string (const char *buf
, int len
)
14898 char *s
= xmalloc (len
+ 1);
14900 memcpy (s
, buf
, len
);
14906 static const char *
14907 consume_improper_spaces (const char *p
, const char *body
)
14911 complaint (&symfile_complaints
,
14912 _("macro definition contains spaces "
14913 "in formal argument list:\n`%s'"),
14925 parse_macro_definition (struct macro_source_file
*file
, int line
,
14930 /* The body string takes one of two forms. For object-like macro
14931 definitions, it should be:
14933 <macro name> " " <definition>
14935 For function-like macro definitions, it should be:
14937 <macro name> "() " <definition>
14939 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14941 Spaces may appear only where explicitly indicated, and in the
14944 The Dwarf 2 spec says that an object-like macro's name is always
14945 followed by a space, but versions of GCC around March 2002 omit
14946 the space when the macro's definition is the empty string.
14948 The Dwarf 2 spec says that there should be no spaces between the
14949 formal arguments in a function-like macro's formal argument list,
14950 but versions of GCC around March 2002 include spaces after the
14954 /* Find the extent of the macro name. The macro name is terminated
14955 by either a space or null character (for an object-like macro) or
14956 an opening paren (for a function-like macro). */
14957 for (p
= body
; *p
; p
++)
14958 if (*p
== ' ' || *p
== '(')
14961 if (*p
== ' ' || *p
== '\0')
14963 /* It's an object-like macro. */
14964 int name_len
= p
- body
;
14965 char *name
= copy_string (body
, name_len
);
14966 const char *replacement
;
14969 replacement
= body
+ name_len
+ 1;
14972 dwarf2_macro_malformed_definition_complaint (body
);
14973 replacement
= body
+ name_len
;
14976 macro_define_object (file
, line
, name
, replacement
);
14980 else if (*p
== '(')
14982 /* It's a function-like macro. */
14983 char *name
= copy_string (body
, p
- body
);
14986 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14990 p
= consume_improper_spaces (p
, body
);
14992 /* Parse the formal argument list. */
14993 while (*p
&& *p
!= ')')
14995 /* Find the extent of the current argument name. */
14996 const char *arg_start
= p
;
14998 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15001 if (! *p
|| p
== arg_start
)
15002 dwarf2_macro_malformed_definition_complaint (body
);
15005 /* Make sure argv has room for the new argument. */
15006 if (argc
>= argv_size
)
15009 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15012 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15015 p
= consume_improper_spaces (p
, body
);
15017 /* Consume the comma, if present. */
15022 p
= consume_improper_spaces (p
, body
);
15031 /* Perfectly formed definition, no complaints. */
15032 macro_define_function (file
, line
, name
,
15033 argc
, (const char **) argv
,
15035 else if (*p
== '\0')
15037 /* Complain, but do define it. */
15038 dwarf2_macro_malformed_definition_complaint (body
);
15039 macro_define_function (file
, line
, name
,
15040 argc
, (const char **) argv
,
15044 /* Just complain. */
15045 dwarf2_macro_malformed_definition_complaint (body
);
15048 /* Just complain. */
15049 dwarf2_macro_malformed_definition_complaint (body
);
15055 for (i
= 0; i
< argc
; i
++)
15061 dwarf2_macro_malformed_definition_complaint (body
);
15064 /* Skip some bytes from BYTES according to the form given in FORM.
15065 Returns the new pointer. */
15068 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15069 enum dwarf_form form
,
15070 unsigned int offset_size
,
15071 struct dwarf2_section_info
*section
)
15073 unsigned int bytes_read
;
15077 case DW_FORM_data1
:
15082 case DW_FORM_data2
:
15086 case DW_FORM_data4
:
15090 case DW_FORM_data8
:
15094 case DW_FORM_string
:
15095 read_direct_string (abfd
, bytes
, &bytes_read
);
15096 bytes
+= bytes_read
;
15099 case DW_FORM_sec_offset
:
15101 bytes
+= offset_size
;
15104 case DW_FORM_block
:
15105 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15106 bytes
+= bytes_read
;
15109 case DW_FORM_block1
:
15110 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15112 case DW_FORM_block2
:
15113 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15115 case DW_FORM_block4
:
15116 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15119 case DW_FORM_sdata
:
15120 case DW_FORM_udata
:
15121 bytes
= skip_leb128 (abfd
, bytes
);
15127 complaint (&symfile_complaints
,
15128 _("invalid form 0x%x in `%s'"),
15130 section
->asection
->name
);
15138 /* A helper for dwarf_decode_macros that handles skipping an unknown
15139 opcode. Returns an updated pointer to the macro data buffer; or,
15140 on error, issues a complaint and returns NULL. */
15143 skip_unknown_opcode (unsigned int opcode
,
15144 gdb_byte
**opcode_definitions
,
15147 unsigned int offset_size
,
15148 struct dwarf2_section_info
*section
)
15150 unsigned int bytes_read
, i
;
15154 if (opcode_definitions
[opcode
] == NULL
)
15156 complaint (&symfile_complaints
,
15157 _("unrecognized DW_MACFINO opcode 0x%x"),
15162 defn
= opcode_definitions
[opcode
];
15163 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15164 defn
+= bytes_read
;
15166 for (i
= 0; i
< arg
; ++i
)
15168 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15169 if (mac_ptr
== NULL
)
15171 /* skip_form_bytes already issued the complaint. */
15179 /* A helper function which parses the header of a macro section.
15180 If the macro section is the extended (for now called "GNU") type,
15181 then this updates *OFFSET_SIZE. Returns a pointer to just after
15182 the header, or issues a complaint and returns NULL on error. */
15185 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15188 unsigned int *offset_size
,
15189 int section_is_gnu
)
15191 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15193 if (section_is_gnu
)
15195 unsigned int version
, flags
;
15197 version
= read_2_bytes (abfd
, mac_ptr
);
15200 complaint (&symfile_complaints
,
15201 _("unrecognized version `%d' in .debug_macro section"),
15207 flags
= read_1_byte (abfd
, mac_ptr
);
15209 *offset_size
= (flags
& 1) ? 8 : 4;
15211 if ((flags
& 2) != 0)
15212 /* We don't need the line table offset. */
15213 mac_ptr
+= *offset_size
;
15215 /* Vendor opcode descriptions. */
15216 if ((flags
& 4) != 0)
15218 unsigned int i
, count
;
15220 count
= read_1_byte (abfd
, mac_ptr
);
15222 for (i
= 0; i
< count
; ++i
)
15224 unsigned int opcode
, bytes_read
;
15227 opcode
= read_1_byte (abfd
, mac_ptr
);
15229 opcode_definitions
[opcode
] = mac_ptr
;
15230 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15231 mac_ptr
+= bytes_read
;
15240 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15241 including DW_GNU_MACINFO_transparent_include. */
15244 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15245 struct macro_source_file
*current_file
,
15246 struct line_header
*lh
, char *comp_dir
,
15247 struct dwarf2_section_info
*section
,
15248 int section_is_gnu
,
15249 unsigned int offset_size
,
15250 struct objfile
*objfile
)
15252 enum dwarf_macro_record_type macinfo_type
;
15253 int at_commandline
;
15254 gdb_byte
*opcode_definitions
[256];
15256 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15257 &offset_size
, section_is_gnu
);
15258 if (mac_ptr
== NULL
)
15260 /* We already issued a complaint. */
15264 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15265 GDB is still reading the definitions from command line. First
15266 DW_MACINFO_start_file will need to be ignored as it was already executed
15267 to create CURRENT_FILE for the main source holding also the command line
15268 definitions. On first met DW_MACINFO_start_file this flag is reset to
15269 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15271 at_commandline
= 1;
15275 /* Do we at least have room for a macinfo type byte? */
15276 if (mac_ptr
>= mac_end
)
15278 dwarf2_macros_too_long_complaint (section
);
15282 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15285 /* Note that we rely on the fact that the corresponding GNU and
15286 DWARF constants are the same. */
15287 switch (macinfo_type
)
15289 /* A zero macinfo type indicates the end of the macro
15294 case DW_MACRO_GNU_define
:
15295 case DW_MACRO_GNU_undef
:
15296 case DW_MACRO_GNU_define_indirect
:
15297 case DW_MACRO_GNU_undef_indirect
:
15299 unsigned int bytes_read
;
15304 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15305 mac_ptr
+= bytes_read
;
15307 if (macinfo_type
== DW_MACRO_GNU_define
15308 || macinfo_type
== DW_MACRO_GNU_undef
)
15310 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15311 mac_ptr
+= bytes_read
;
15315 LONGEST str_offset
;
15317 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15318 mac_ptr
+= offset_size
;
15320 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15323 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15324 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15325 if (! current_file
)
15327 /* DWARF violation as no main source is present. */
15328 complaint (&symfile_complaints
,
15329 _("debug info with no main source gives macro %s "
15331 is_define
? _("definition") : _("undefinition"),
15335 if ((line
== 0 && !at_commandline
)
15336 || (line
!= 0 && at_commandline
))
15337 complaint (&symfile_complaints
,
15338 _("debug info gives %s macro %s with %s line %d: %s"),
15339 at_commandline
? _("command-line") : _("in-file"),
15340 is_define
? _("definition") : _("undefinition"),
15341 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15344 parse_macro_definition (current_file
, line
, body
);
15347 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15348 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15349 macro_undef (current_file
, line
, body
);
15354 case DW_MACRO_GNU_start_file
:
15356 unsigned int bytes_read
;
15359 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15360 mac_ptr
+= bytes_read
;
15361 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15362 mac_ptr
+= bytes_read
;
15364 if ((line
== 0 && !at_commandline
)
15365 || (line
!= 0 && at_commandline
))
15366 complaint (&symfile_complaints
,
15367 _("debug info gives source %d included "
15368 "from %s at %s line %d"),
15369 file
, at_commandline
? _("command-line") : _("file"),
15370 line
== 0 ? _("zero") : _("non-zero"), line
);
15372 if (at_commandline
)
15374 /* This DW_MACRO_GNU_start_file was executed in the
15376 at_commandline
= 0;
15379 current_file
= macro_start_file (file
, line
,
15380 current_file
, comp_dir
,
15385 case DW_MACRO_GNU_end_file
:
15386 if (! current_file
)
15387 complaint (&symfile_complaints
,
15388 _("macro debug info has an unmatched "
15389 "`close_file' directive"));
15392 current_file
= current_file
->included_by
;
15393 if (! current_file
)
15395 enum dwarf_macro_record_type next_type
;
15397 /* GCC circa March 2002 doesn't produce the zero
15398 type byte marking the end of the compilation
15399 unit. Complain if it's not there, but exit no
15402 /* Do we at least have room for a macinfo type byte? */
15403 if (mac_ptr
>= mac_end
)
15405 dwarf2_macros_too_long_complaint (section
);
15409 /* We don't increment mac_ptr here, so this is just
15411 next_type
= read_1_byte (abfd
, mac_ptr
);
15412 if (next_type
!= 0)
15413 complaint (&symfile_complaints
,
15414 _("no terminating 0-type entry for "
15415 "macros in `.debug_macinfo' section"));
15422 case DW_MACRO_GNU_transparent_include
:
15426 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15427 mac_ptr
+= offset_size
;
15429 dwarf_decode_macro_bytes (abfd
,
15430 section
->buffer
+ offset
,
15431 mac_end
, current_file
,
15433 section
, section_is_gnu
,
15434 offset_size
, objfile
);
15438 case DW_MACINFO_vendor_ext
:
15439 if (!section_is_gnu
)
15441 unsigned int bytes_read
;
15444 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15445 mac_ptr
+= bytes_read
;
15446 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15447 mac_ptr
+= bytes_read
;
15449 /* We don't recognize any vendor extensions. */
15455 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15456 mac_ptr
, abfd
, offset_size
,
15458 if (mac_ptr
== NULL
)
15462 } while (macinfo_type
!= 0);
15466 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15467 char *comp_dir
, bfd
*abfd
,
15468 struct dwarf2_cu
*cu
,
15469 struct dwarf2_section_info
*section
,
15470 int section_is_gnu
)
15472 gdb_byte
*mac_ptr
, *mac_end
;
15473 struct macro_source_file
*current_file
= 0;
15474 enum dwarf_macro_record_type macinfo_type
;
15475 unsigned int offset_size
= cu
->header
.offset_size
;
15476 gdb_byte
*opcode_definitions
[256];
15478 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15479 if (section
->buffer
== NULL
)
15481 complaint (&symfile_complaints
, _("missing %s section"),
15482 section
->asection
->name
);
15486 /* First pass: Find the name of the base filename.
15487 This filename is needed in order to process all macros whose definition
15488 (or undefinition) comes from the command line. These macros are defined
15489 before the first DW_MACINFO_start_file entry, and yet still need to be
15490 associated to the base file.
15492 To determine the base file name, we scan the macro definitions until we
15493 reach the first DW_MACINFO_start_file entry. We then initialize
15494 CURRENT_FILE accordingly so that any macro definition found before the
15495 first DW_MACINFO_start_file can still be associated to the base file. */
15497 mac_ptr
= section
->buffer
+ offset
;
15498 mac_end
= section
->buffer
+ section
->size
;
15500 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15501 &offset_size
, section_is_gnu
);
15502 if (mac_ptr
== NULL
)
15504 /* We already issued a complaint. */
15510 /* Do we at least have room for a macinfo type byte? */
15511 if (mac_ptr
>= mac_end
)
15513 /* Complaint is printed during the second pass as GDB will probably
15514 stop the first pass earlier upon finding
15515 DW_MACINFO_start_file. */
15519 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15522 /* Note that we rely on the fact that the corresponding GNU and
15523 DWARF constants are the same. */
15524 switch (macinfo_type
)
15526 /* A zero macinfo type indicates the end of the macro
15531 case DW_MACRO_GNU_define
:
15532 case DW_MACRO_GNU_undef
:
15533 /* Only skip the data by MAC_PTR. */
15535 unsigned int bytes_read
;
15537 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15538 mac_ptr
+= bytes_read
;
15539 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15540 mac_ptr
+= bytes_read
;
15544 case DW_MACRO_GNU_start_file
:
15546 unsigned int bytes_read
;
15549 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15550 mac_ptr
+= bytes_read
;
15551 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15552 mac_ptr
+= bytes_read
;
15554 current_file
= macro_start_file (file
, line
, current_file
,
15555 comp_dir
, lh
, cu
->objfile
);
15559 case DW_MACRO_GNU_end_file
:
15560 /* No data to skip by MAC_PTR. */
15563 case DW_MACRO_GNU_define_indirect
:
15564 case DW_MACRO_GNU_undef_indirect
:
15566 unsigned int bytes_read
;
15568 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15569 mac_ptr
+= bytes_read
;
15570 mac_ptr
+= offset_size
;
15574 case DW_MACRO_GNU_transparent_include
:
15575 /* Note that, according to the spec, a transparent include
15576 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15577 skip this opcode. */
15578 mac_ptr
+= offset_size
;
15581 case DW_MACINFO_vendor_ext
:
15582 /* Only skip the data by MAC_PTR. */
15583 if (!section_is_gnu
)
15585 unsigned int bytes_read
;
15587 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15588 mac_ptr
+= bytes_read
;
15589 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15590 mac_ptr
+= bytes_read
;
15595 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15596 mac_ptr
, abfd
, offset_size
,
15598 if (mac_ptr
== NULL
)
15602 } while (macinfo_type
!= 0 && current_file
== NULL
);
15604 /* Second pass: Process all entries.
15606 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15607 command-line macro definitions/undefinitions. This flag is unset when we
15608 reach the first DW_MACINFO_start_file entry. */
15610 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15611 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15612 offset_size
, cu
->objfile
);
15615 /* Check if the attribute's form is a DW_FORM_block*
15616 if so return true else false. */
15618 attr_form_is_block (struct attribute
*attr
)
15620 return (attr
== NULL
? 0 :
15621 attr
->form
== DW_FORM_block1
15622 || attr
->form
== DW_FORM_block2
15623 || attr
->form
== DW_FORM_block4
15624 || attr
->form
== DW_FORM_block
15625 || attr
->form
== DW_FORM_exprloc
);
15628 /* Return non-zero if ATTR's value is a section offset --- classes
15629 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15630 You may use DW_UNSND (attr) to retrieve such offsets.
15632 Section 7.5.4, "Attribute Encodings", explains that no attribute
15633 may have a value that belongs to more than one of these classes; it
15634 would be ambiguous if we did, because we use the same forms for all
15637 attr_form_is_section_offset (struct attribute
*attr
)
15639 return (attr
->form
== DW_FORM_data4
15640 || attr
->form
== DW_FORM_data8
15641 || attr
->form
== DW_FORM_sec_offset
);
15645 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15646 zero otherwise. When this function returns true, you can apply
15647 dwarf2_get_attr_constant_value to it.
15649 However, note that for some attributes you must check
15650 attr_form_is_section_offset before using this test. DW_FORM_data4
15651 and DW_FORM_data8 are members of both the constant class, and of
15652 the classes that contain offsets into other debug sections
15653 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15654 that, if an attribute's can be either a constant or one of the
15655 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15656 taken as section offsets, not constants. */
15658 attr_form_is_constant (struct attribute
*attr
)
15660 switch (attr
->form
)
15662 case DW_FORM_sdata
:
15663 case DW_FORM_udata
:
15664 case DW_FORM_data1
:
15665 case DW_FORM_data2
:
15666 case DW_FORM_data4
:
15667 case DW_FORM_data8
:
15674 /* A helper function that fills in a dwarf2_loclist_baton. */
15677 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15678 struct dwarf2_loclist_baton
*baton
,
15679 struct attribute
*attr
)
15681 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15682 &dwarf2_per_objfile
->loc
);
15684 baton
->per_cu
= cu
->per_cu
;
15685 gdb_assert (baton
->per_cu
);
15686 /* We don't know how long the location list is, but make sure we
15687 don't run off the edge of the section. */
15688 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15689 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15690 baton
->base_address
= cu
->base_address
;
15694 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15695 struct dwarf2_cu
*cu
)
15697 if (attr_form_is_section_offset (attr
)
15698 /* ".debug_loc" may not exist at all, or the offset may be outside
15699 the section. If so, fall through to the complaint in the
15701 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15702 &dwarf2_per_objfile
->loc
))
15704 struct dwarf2_loclist_baton
*baton
;
15706 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15707 sizeof (struct dwarf2_loclist_baton
));
15709 fill_in_loclist_baton (cu
, baton
, attr
);
15711 if (cu
->base_known
== 0)
15712 complaint (&symfile_complaints
,
15713 _("Location list used without "
15714 "specifying the CU base address."));
15716 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15717 SYMBOL_LOCATION_BATON (sym
) = baton
;
15721 struct dwarf2_locexpr_baton
*baton
;
15723 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15724 sizeof (struct dwarf2_locexpr_baton
));
15725 baton
->per_cu
= cu
->per_cu
;
15726 gdb_assert (baton
->per_cu
);
15728 if (attr_form_is_block (attr
))
15730 /* Note that we're just copying the block's data pointer
15731 here, not the actual data. We're still pointing into the
15732 info_buffer for SYM's objfile; right now we never release
15733 that buffer, but when we do clean up properly this may
15735 baton
->size
= DW_BLOCK (attr
)->size
;
15736 baton
->data
= DW_BLOCK (attr
)->data
;
15740 dwarf2_invalid_attrib_class_complaint ("location description",
15741 SYMBOL_NATURAL_NAME (sym
));
15745 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15746 SYMBOL_LOCATION_BATON (sym
) = baton
;
15750 /* Return the OBJFILE associated with the compilation unit CU. If CU
15751 came from a separate debuginfo file, then the master objfile is
15755 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15757 struct objfile
*objfile
= per_cu
->objfile
;
15759 /* Return the master objfile, so that we can report and look up the
15760 correct file containing this variable. */
15761 if (objfile
->separate_debug_objfile_backlink
)
15762 objfile
= objfile
->separate_debug_objfile_backlink
;
15767 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15768 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15769 CU_HEADERP first. */
15771 static const struct comp_unit_head
*
15772 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15773 struct dwarf2_per_cu_data
*per_cu
)
15775 struct objfile
*objfile
;
15776 struct dwarf2_per_objfile
*per_objfile
;
15777 gdb_byte
*info_ptr
;
15780 return &per_cu
->cu
->header
;
15782 objfile
= per_cu
->objfile
;
15783 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15784 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15786 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15787 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15792 /* Return the address size given in the compilation unit header for CU. */
15795 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15797 struct comp_unit_head cu_header_local
;
15798 const struct comp_unit_head
*cu_headerp
;
15800 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15802 return cu_headerp
->addr_size
;
15805 /* Return the offset size given in the compilation unit header for CU. */
15808 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15810 struct comp_unit_head cu_header_local
;
15811 const struct comp_unit_head
*cu_headerp
;
15813 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15815 return cu_headerp
->offset_size
;
15818 /* See its dwarf2loc.h declaration. */
15821 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15823 struct comp_unit_head cu_header_local
;
15824 const struct comp_unit_head
*cu_headerp
;
15826 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15828 if (cu_headerp
->version
== 2)
15829 return cu_headerp
->addr_size
;
15831 return cu_headerp
->offset_size
;
15834 /* Return the text offset of the CU. The returned offset comes from
15835 this CU's objfile. If this objfile came from a separate debuginfo
15836 file, then the offset may be different from the corresponding
15837 offset in the parent objfile. */
15840 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15842 struct objfile
*objfile
= per_cu
->objfile
;
15844 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15847 /* Locate the .debug_info compilation unit from CU's objfile which contains
15848 the DIE at OFFSET. Raises an error on failure. */
15850 static struct dwarf2_per_cu_data
*
15851 dwarf2_find_containing_comp_unit (unsigned int offset
,
15852 struct objfile
*objfile
)
15854 struct dwarf2_per_cu_data
*this_cu
;
15858 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15861 int mid
= low
+ (high
- low
) / 2;
15863 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15868 gdb_assert (low
== high
);
15869 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15872 error (_("Dwarf Error: could not find partial DIE containing "
15873 "offset 0x%lx [in module %s]"),
15874 (long) offset
, bfd_get_filename (objfile
->obfd
));
15876 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15877 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15881 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15882 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15883 && offset
>= this_cu
->offset
+ this_cu
->length
)
15884 error (_("invalid dwarf2 offset %u"), offset
);
15885 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15890 /* Locate the compilation unit from OBJFILE which is located at exactly
15891 OFFSET. Raises an error on failure. */
15893 static struct dwarf2_per_cu_data
*
15894 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15896 struct dwarf2_per_cu_data
*this_cu
;
15898 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15899 if (this_cu
->offset
!= offset
)
15900 error (_("no compilation unit with offset %u."), offset
);
15904 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15907 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15909 memset (cu
, 0, sizeof (*cu
));
15910 cu
->objfile
= objfile
;
15911 obstack_init (&cu
->comp_unit_obstack
);
15914 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15917 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15919 struct attribute
*attr
;
15921 /* Set the language we're debugging. */
15922 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15924 set_cu_language (DW_UNSND (attr
), cu
);
15927 cu
->language
= language_minimal
;
15928 cu
->language_defn
= language_def (cu
->language
);
15932 /* Release one cached compilation unit, CU. We unlink it from the tree
15933 of compilation units, but we don't remove it from the read_in_chain;
15934 the caller is responsible for that.
15935 NOTE: DATA is a void * because this function is also used as a
15936 cleanup routine. */
15939 free_one_comp_unit (void *data
)
15941 struct dwarf2_cu
*cu
= data
;
15943 if (cu
->per_cu
!= NULL
)
15944 cu
->per_cu
->cu
= NULL
;
15947 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15952 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15953 when we're finished with it. We can't free the pointer itself, but be
15954 sure to unlink it from the cache. Also release any associated storage
15955 and perform cache maintenance.
15957 Only used during partial symbol parsing. */
15960 free_stack_comp_unit (void *data
)
15962 struct dwarf2_cu
*cu
= data
;
15964 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15965 cu
->partial_dies
= NULL
;
15967 if (cu
->per_cu
!= NULL
)
15969 /* This compilation unit is on the stack in our caller, so we
15970 should not xfree it. Just unlink it. */
15971 cu
->per_cu
->cu
= NULL
;
15974 /* If we had a per-cu pointer, then we may have other compilation
15975 units loaded, so age them now. */
15976 age_cached_comp_units ();
15980 /* Free all cached compilation units. */
15983 free_cached_comp_units (void *data
)
15985 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15987 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15988 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15989 while (per_cu
!= NULL
)
15991 struct dwarf2_per_cu_data
*next_cu
;
15993 next_cu
= per_cu
->cu
->read_in_chain
;
15995 free_one_comp_unit (per_cu
->cu
);
15996 *last_chain
= next_cu
;
16002 /* Increase the age counter on each cached compilation unit, and free
16003 any that are too old. */
16006 age_cached_comp_units (void)
16008 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16010 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16011 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16012 while (per_cu
!= NULL
)
16014 per_cu
->cu
->last_used
++;
16015 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16016 dwarf2_mark (per_cu
->cu
);
16017 per_cu
= per_cu
->cu
->read_in_chain
;
16020 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16021 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16022 while (per_cu
!= NULL
)
16024 struct dwarf2_per_cu_data
*next_cu
;
16026 next_cu
= per_cu
->cu
->read_in_chain
;
16028 if (!per_cu
->cu
->mark
)
16030 free_one_comp_unit (per_cu
->cu
);
16031 *last_chain
= next_cu
;
16034 last_chain
= &per_cu
->cu
->read_in_chain
;
16040 /* Remove a single compilation unit from the cache. */
16043 free_one_cached_comp_unit (void *target_cu
)
16045 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16047 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16048 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16049 while (per_cu
!= NULL
)
16051 struct dwarf2_per_cu_data
*next_cu
;
16053 next_cu
= per_cu
->cu
->read_in_chain
;
16055 if (per_cu
->cu
== target_cu
)
16057 free_one_comp_unit (per_cu
->cu
);
16058 *last_chain
= next_cu
;
16062 last_chain
= &per_cu
->cu
->read_in_chain
;
16068 /* Release all extra memory associated with OBJFILE. */
16071 dwarf2_free_objfile (struct objfile
*objfile
)
16073 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16075 if (dwarf2_per_objfile
== NULL
)
16078 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16079 free_cached_comp_units (NULL
);
16081 if (dwarf2_per_objfile
->quick_file_names_table
)
16082 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16084 /* Everything else should be on the objfile obstack. */
16087 /* A pair of DIE offset and GDB type pointer. We store these
16088 in a hash table separate from the DIEs, and preserve them
16089 when the DIEs are flushed out of cache. */
16091 struct dwarf2_offset_and_type
16093 unsigned int offset
;
16097 /* Hash function for a dwarf2_offset_and_type. */
16100 offset_and_type_hash (const void *item
)
16102 const struct dwarf2_offset_and_type
*ofs
= item
;
16104 return ofs
->offset
;
16107 /* Equality function for a dwarf2_offset_and_type. */
16110 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16112 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16113 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16115 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16118 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16119 table if necessary. For convenience, return TYPE.
16121 The DIEs reading must have careful ordering to:
16122 * Not cause infite loops trying to read in DIEs as a prerequisite for
16123 reading current DIE.
16124 * Not trying to dereference contents of still incompletely read in types
16125 while reading in other DIEs.
16126 * Enable referencing still incompletely read in types just by a pointer to
16127 the type without accessing its fields.
16129 Therefore caller should follow these rules:
16130 * Try to fetch any prerequisite types we may need to build this DIE type
16131 before building the type and calling set_die_type.
16132 * After building type call set_die_type for current DIE as soon as
16133 possible before fetching more types to complete the current type.
16134 * Make the type as complete as possible before fetching more types. */
16136 static struct type
*
16137 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16139 struct dwarf2_offset_and_type
**slot
, ofs
;
16140 struct objfile
*objfile
= cu
->objfile
;
16141 htab_t
*type_hash_ptr
;
16143 /* For Ada types, make sure that the gnat-specific data is always
16144 initialized (if not already set). There are a few types where
16145 we should not be doing so, because the type-specific area is
16146 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16147 where the type-specific area is used to store the floatformat).
16148 But this is not a problem, because the gnat-specific information
16149 is actually not needed for these types. */
16150 if (need_gnat_info (cu
)
16151 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16152 && TYPE_CODE (type
) != TYPE_CODE_FLT
16153 && !HAVE_GNAT_AUX_INFO (type
))
16154 INIT_GNAT_SPECIFIC (type
);
16156 if (cu
->per_cu
->debug_type_section
)
16157 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16159 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16161 if (*type_hash_ptr
== NULL
)
16164 = htab_create_alloc_ex (127,
16165 offset_and_type_hash
,
16166 offset_and_type_eq
,
16168 &objfile
->objfile_obstack
,
16169 hashtab_obstack_allocate
,
16170 dummy_obstack_deallocate
);
16173 ofs
.offset
= die
->offset
;
16175 slot
= (struct dwarf2_offset_and_type
**)
16176 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16178 complaint (&symfile_complaints
,
16179 _("A problem internal to GDB: DIE 0x%x has type already set"),
16181 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16186 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16187 table, or return NULL if the die does not have a saved type. */
16189 static struct type
*
16190 get_die_type_at_offset (unsigned int offset
,
16191 struct dwarf2_per_cu_data
*per_cu
)
16193 struct dwarf2_offset_and_type
*slot
, ofs
;
16196 if (per_cu
->debug_type_section
)
16197 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16199 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16200 if (type_hash
== NULL
)
16203 ofs
.offset
= offset
;
16204 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16211 /* Look up the type for DIE in the appropriate type_hash table,
16212 or return NULL if DIE does not have a saved type. */
16214 static struct type
*
16215 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16217 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16220 /* Add a dependence relationship from CU to REF_PER_CU. */
16223 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16224 struct dwarf2_per_cu_data
*ref_per_cu
)
16228 if (cu
->dependencies
== NULL
)
16230 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16231 NULL
, &cu
->comp_unit_obstack
,
16232 hashtab_obstack_allocate
,
16233 dummy_obstack_deallocate
);
16235 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16237 *slot
= ref_per_cu
;
16240 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16241 Set the mark field in every compilation unit in the
16242 cache that we must keep because we are keeping CU. */
16245 dwarf2_mark_helper (void **slot
, void *data
)
16247 struct dwarf2_per_cu_data
*per_cu
;
16249 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16251 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16252 reading of the chain. As such dependencies remain valid it is not much
16253 useful to track and undo them during QUIT cleanups. */
16254 if (per_cu
->cu
== NULL
)
16257 if (per_cu
->cu
->mark
)
16259 per_cu
->cu
->mark
= 1;
16261 if (per_cu
->cu
->dependencies
!= NULL
)
16262 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16267 /* Set the mark field in CU and in every other compilation unit in the
16268 cache that we must keep because we are keeping CU. */
16271 dwarf2_mark (struct dwarf2_cu
*cu
)
16276 if (cu
->dependencies
!= NULL
)
16277 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16281 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16285 per_cu
->cu
->mark
= 0;
16286 per_cu
= per_cu
->cu
->read_in_chain
;
16290 /* Trivial hash function for partial_die_info: the hash value of a DIE
16291 is its offset in .debug_info for this objfile. */
16294 partial_die_hash (const void *item
)
16296 const struct partial_die_info
*part_die
= item
;
16298 return part_die
->offset
;
16301 /* Trivial comparison function for partial_die_info structures: two DIEs
16302 are equal if they have the same offset. */
16305 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16307 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16308 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16310 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16313 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16314 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16317 set_dwarf2_cmd (char *args
, int from_tty
)
16319 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16323 show_dwarf2_cmd (char *args
, int from_tty
)
16325 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16328 /* If section described by INFO was mmapped, munmap it now. */
16331 munmap_section_buffer (struct dwarf2_section_info
*info
)
16333 if (info
->map_addr
!= NULL
)
16338 res
= munmap (info
->map_addr
, info
->map_len
);
16339 gdb_assert (res
== 0);
16341 /* Without HAVE_MMAP, we should never be here to begin with. */
16342 gdb_assert_not_reached ("no mmap support");
16347 /* munmap debug sections for OBJFILE, if necessary. */
16350 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16352 struct dwarf2_per_objfile
*data
= d
;
16354 struct dwarf2_section_info
*section
;
16356 /* This is sorted according to the order they're defined in to make it easier
16357 to keep in sync. */
16358 munmap_section_buffer (&data
->info
);
16359 munmap_section_buffer (&data
->abbrev
);
16360 munmap_section_buffer (&data
->line
);
16361 munmap_section_buffer (&data
->loc
);
16362 munmap_section_buffer (&data
->macinfo
);
16363 munmap_section_buffer (&data
->macro
);
16364 munmap_section_buffer (&data
->str
);
16365 munmap_section_buffer (&data
->ranges
);
16366 munmap_section_buffer (&data
->frame
);
16367 munmap_section_buffer (&data
->eh_frame
);
16368 munmap_section_buffer (&data
->gdb_index
);
16371 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16373 munmap_section_buffer (section
);
16375 VEC_free (dwarf2_section_info_def
, data
->types
);
16379 /* The "save gdb-index" command. */
16381 /* The contents of the hash table we create when building the string
16383 struct strtab_entry
16385 offset_type offset
;
16389 /* Hash function for a strtab_entry.
16391 Function is used only during write_hash_table so no index format backward
16392 compatibility is needed. */
16395 hash_strtab_entry (const void *e
)
16397 const struct strtab_entry
*entry
= e
;
16398 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16401 /* Equality function for a strtab_entry. */
16404 eq_strtab_entry (const void *a
, const void *b
)
16406 const struct strtab_entry
*ea
= a
;
16407 const struct strtab_entry
*eb
= b
;
16408 return !strcmp (ea
->str
, eb
->str
);
16411 /* Create a strtab_entry hash table. */
16414 create_strtab (void)
16416 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16417 xfree
, xcalloc
, xfree
);
16420 /* Add a string to the constant pool. Return the string's offset in
16424 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16427 struct strtab_entry entry
;
16428 struct strtab_entry
*result
;
16431 slot
= htab_find_slot (table
, &entry
, INSERT
);
16436 result
= XNEW (struct strtab_entry
);
16437 result
->offset
= obstack_object_size (cpool
);
16439 obstack_grow_str0 (cpool
, str
);
16442 return result
->offset
;
16445 /* An entry in the symbol table. */
16446 struct symtab_index_entry
16448 /* The name of the symbol. */
16450 /* The offset of the name in the constant pool. */
16451 offset_type index_offset
;
16452 /* A sorted vector of the indices of all the CUs that hold an object
16454 VEC (offset_type
) *cu_indices
;
16457 /* The symbol table. This is a power-of-2-sized hash table. */
16458 struct mapped_symtab
16460 offset_type n_elements
;
16462 struct symtab_index_entry
**data
;
16465 /* Hash function for a symtab_index_entry. */
16468 hash_symtab_entry (const void *e
)
16470 const struct symtab_index_entry
*entry
= e
;
16471 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16472 sizeof (offset_type
) * VEC_length (offset_type
,
16473 entry
->cu_indices
),
16477 /* Equality function for a symtab_index_entry. */
16480 eq_symtab_entry (const void *a
, const void *b
)
16482 const struct symtab_index_entry
*ea
= a
;
16483 const struct symtab_index_entry
*eb
= b
;
16484 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16485 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16487 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16488 VEC_address (offset_type
, eb
->cu_indices
),
16489 sizeof (offset_type
) * len
);
16492 /* Destroy a symtab_index_entry. */
16495 delete_symtab_entry (void *p
)
16497 struct symtab_index_entry
*entry
= p
;
16498 VEC_free (offset_type
, entry
->cu_indices
);
16502 /* Create a hash table holding symtab_index_entry objects. */
16505 create_symbol_hash_table (void)
16507 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16508 delete_symtab_entry
, xcalloc
, xfree
);
16511 /* Create a new mapped symtab object. */
16513 static struct mapped_symtab
*
16514 create_mapped_symtab (void)
16516 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16517 symtab
->n_elements
= 0;
16518 symtab
->size
= 1024;
16519 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16523 /* Destroy a mapped_symtab. */
16526 cleanup_mapped_symtab (void *p
)
16528 struct mapped_symtab
*symtab
= p
;
16529 /* The contents of the array are freed when the other hash table is
16531 xfree (symtab
->data
);
16535 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16538 Function is used only during write_hash_table so no index format backward
16539 compatibility is needed. */
16541 static struct symtab_index_entry
**
16542 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16544 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16546 index
= hash
& (symtab
->size
- 1);
16547 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16551 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16552 return &symtab
->data
[index
];
16553 index
= (index
+ step
) & (symtab
->size
- 1);
16557 /* Expand SYMTAB's hash table. */
16560 hash_expand (struct mapped_symtab
*symtab
)
16562 offset_type old_size
= symtab
->size
;
16564 struct symtab_index_entry
**old_entries
= symtab
->data
;
16567 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16569 for (i
= 0; i
< old_size
; ++i
)
16571 if (old_entries
[i
])
16573 struct symtab_index_entry
**slot
= find_slot (symtab
,
16574 old_entries
[i
]->name
);
16575 *slot
= old_entries
[i
];
16579 xfree (old_entries
);
16582 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16583 is the index of the CU in which the symbol appears. */
16586 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16587 offset_type cu_index
)
16589 struct symtab_index_entry
**slot
;
16591 ++symtab
->n_elements
;
16592 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16593 hash_expand (symtab
);
16595 slot
= find_slot (symtab
, name
);
16598 *slot
= XNEW (struct symtab_index_entry
);
16599 (*slot
)->name
= name
;
16600 (*slot
)->cu_indices
= NULL
;
16602 /* Don't push an index twice. Due to how we add entries we only
16603 have to check the last one. */
16604 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16605 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16606 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16609 /* Add a vector of indices to the constant pool. */
16612 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16613 struct symtab_index_entry
*entry
)
16617 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16620 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16621 offset_type val
= MAYBE_SWAP (len
);
16626 entry
->index_offset
= obstack_object_size (cpool
);
16628 obstack_grow (cpool
, &val
, sizeof (val
));
16630 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16633 val
= MAYBE_SWAP (iter
);
16634 obstack_grow (cpool
, &val
, sizeof (val
));
16639 struct symtab_index_entry
*old_entry
= *slot
;
16640 entry
->index_offset
= old_entry
->index_offset
;
16643 return entry
->index_offset
;
16646 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16647 constant pool entries going into the obstack CPOOL. */
16650 write_hash_table (struct mapped_symtab
*symtab
,
16651 struct obstack
*output
, struct obstack
*cpool
)
16654 htab_t symbol_hash_table
;
16657 symbol_hash_table
= create_symbol_hash_table ();
16658 str_table
= create_strtab ();
16660 /* We add all the index vectors to the constant pool first, to
16661 ensure alignment is ok. */
16662 for (i
= 0; i
< symtab
->size
; ++i
)
16664 if (symtab
->data
[i
])
16665 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16668 /* Now write out the hash table. */
16669 for (i
= 0; i
< symtab
->size
; ++i
)
16671 offset_type str_off
, vec_off
;
16673 if (symtab
->data
[i
])
16675 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16676 vec_off
= symtab
->data
[i
]->index_offset
;
16680 /* While 0 is a valid constant pool index, it is not valid
16681 to have 0 for both offsets. */
16686 str_off
= MAYBE_SWAP (str_off
);
16687 vec_off
= MAYBE_SWAP (vec_off
);
16689 obstack_grow (output
, &str_off
, sizeof (str_off
));
16690 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16693 htab_delete (str_table
);
16694 htab_delete (symbol_hash_table
);
16697 /* Struct to map psymtab to CU index in the index file. */
16698 struct psymtab_cu_index_map
16700 struct partial_symtab
*psymtab
;
16701 unsigned int cu_index
;
16705 hash_psymtab_cu_index (const void *item
)
16707 const struct psymtab_cu_index_map
*map
= item
;
16709 return htab_hash_pointer (map
->psymtab
);
16713 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16715 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16716 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16718 return lhs
->psymtab
== rhs
->psymtab
;
16721 /* Helper struct for building the address table. */
16722 struct addrmap_index_data
16724 struct objfile
*objfile
;
16725 struct obstack
*addr_obstack
;
16726 htab_t cu_index_htab
;
16728 /* Non-zero if the previous_* fields are valid.
16729 We can't write an entry until we see the next entry (since it is only then
16730 that we know the end of the entry). */
16731 int previous_valid
;
16732 /* Index of the CU in the table of all CUs in the index file. */
16733 unsigned int previous_cu_index
;
16734 /* Start address of the CU. */
16735 CORE_ADDR previous_cu_start
;
16738 /* Write an address entry to OBSTACK. */
16741 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16742 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16744 offset_type cu_index_to_write
;
16746 CORE_ADDR baseaddr
;
16748 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16750 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16751 obstack_grow (obstack
, addr
, 8);
16752 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16753 obstack_grow (obstack
, addr
, 8);
16754 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16755 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16758 /* Worker function for traversing an addrmap to build the address table. */
16761 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16763 struct addrmap_index_data
*data
= datap
;
16764 struct partial_symtab
*pst
= obj
;
16765 offset_type cu_index
;
16768 if (data
->previous_valid
)
16769 add_address_entry (data
->objfile
, data
->addr_obstack
,
16770 data
->previous_cu_start
, start_addr
,
16771 data
->previous_cu_index
);
16773 data
->previous_cu_start
= start_addr
;
16776 struct psymtab_cu_index_map find_map
, *map
;
16777 find_map
.psymtab
= pst
;
16778 map
= htab_find (data
->cu_index_htab
, &find_map
);
16779 gdb_assert (map
!= NULL
);
16780 data
->previous_cu_index
= map
->cu_index
;
16781 data
->previous_valid
= 1;
16784 data
->previous_valid
= 0;
16789 /* Write OBJFILE's address map to OBSTACK.
16790 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16791 in the index file. */
16794 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16795 htab_t cu_index_htab
)
16797 struct addrmap_index_data addrmap_index_data
;
16799 /* When writing the address table, we have to cope with the fact that
16800 the addrmap iterator only provides the start of a region; we have to
16801 wait until the next invocation to get the start of the next region. */
16803 addrmap_index_data
.objfile
= objfile
;
16804 addrmap_index_data
.addr_obstack
= obstack
;
16805 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16806 addrmap_index_data
.previous_valid
= 0;
16808 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16809 &addrmap_index_data
);
16811 /* It's highly unlikely the last entry (end address = 0xff...ff)
16812 is valid, but we should still handle it.
16813 The end address is recorded as the start of the next region, but that
16814 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16816 if (addrmap_index_data
.previous_valid
)
16817 add_address_entry (objfile
, obstack
,
16818 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16819 addrmap_index_data
.previous_cu_index
);
16822 /* Add a list of partial symbols to SYMTAB. */
16825 write_psymbols (struct mapped_symtab
*symtab
,
16827 struct partial_symbol
**psymp
,
16829 offset_type cu_index
,
16832 for (; count
-- > 0; ++psymp
)
16834 void **slot
, *lookup
;
16836 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16837 error (_("Ada is not currently supported by the index"));
16839 /* We only want to add a given psymbol once. However, we also
16840 want to account for whether it is global or static. So, we
16841 may add it twice, using slightly different values. */
16844 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16846 lookup
= (void *) val
;
16851 /* Only add a given psymbol once. */
16852 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16856 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16861 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16862 exception if there is an error. */
16865 write_obstack (FILE *file
, struct obstack
*obstack
)
16867 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16869 != obstack_object_size (obstack
))
16870 error (_("couldn't data write to file"));
16873 /* Unlink a file if the argument is not NULL. */
16876 unlink_if_set (void *p
)
16878 char **filename
= p
;
16880 unlink (*filename
);
16883 /* A helper struct used when iterating over debug_types. */
16884 struct signatured_type_index_data
16886 struct objfile
*objfile
;
16887 struct mapped_symtab
*symtab
;
16888 struct obstack
*types_list
;
16893 /* A helper function that writes a single signatured_type to an
16897 write_one_signatured_type (void **slot
, void *d
)
16899 struct signatured_type_index_data
*info
= d
;
16900 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16901 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16902 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16905 write_psymbols (info
->symtab
,
16907 info
->objfile
->global_psymbols
.list
16908 + psymtab
->globals_offset
,
16909 psymtab
->n_global_syms
, info
->cu_index
,
16911 write_psymbols (info
->symtab
,
16913 info
->objfile
->static_psymbols
.list
16914 + psymtab
->statics_offset
,
16915 psymtab
->n_static_syms
, info
->cu_index
,
16918 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16919 obstack_grow (info
->types_list
, val
, 8);
16920 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16921 obstack_grow (info
->types_list
, val
, 8);
16922 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16923 obstack_grow (info
->types_list
, val
, 8);
16930 /* Create an index file for OBJFILE in the directory DIR. */
16933 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16935 struct cleanup
*cleanup
;
16936 char *filename
, *cleanup_filename
;
16937 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16938 struct obstack cu_list
, types_cu_list
;
16941 struct mapped_symtab
*symtab
;
16942 offset_type val
, size_of_contents
, total_len
;
16946 htab_t cu_index_htab
;
16947 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16949 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16952 if (dwarf2_per_objfile
->using_index
)
16953 error (_("Cannot use an index to create the index"));
16955 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16956 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16958 if (stat (objfile
->name
, &st
) < 0)
16959 perror_with_name (objfile
->name
);
16961 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16962 INDEX_SUFFIX
, (char *) NULL
);
16963 cleanup
= make_cleanup (xfree
, filename
);
16965 out_file
= fopen (filename
, "wb");
16967 error (_("Can't open `%s' for writing"), filename
);
16969 cleanup_filename
= filename
;
16970 make_cleanup (unlink_if_set
, &cleanup_filename
);
16972 symtab
= create_mapped_symtab ();
16973 make_cleanup (cleanup_mapped_symtab
, symtab
);
16975 obstack_init (&addr_obstack
);
16976 make_cleanup_obstack_free (&addr_obstack
);
16978 obstack_init (&cu_list
);
16979 make_cleanup_obstack_free (&cu_list
);
16981 obstack_init (&types_cu_list
);
16982 make_cleanup_obstack_free (&types_cu_list
);
16984 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16985 NULL
, xcalloc
, xfree
);
16986 make_cleanup_htab_delete (psyms_seen
);
16988 /* While we're scanning CU's create a table that maps a psymtab pointer
16989 (which is what addrmap records) to its index (which is what is recorded
16990 in the index file). This will later be needed to write the address
16992 cu_index_htab
= htab_create_alloc (100,
16993 hash_psymtab_cu_index
,
16994 eq_psymtab_cu_index
,
16995 NULL
, xcalloc
, xfree
);
16996 make_cleanup_htab_delete (cu_index_htab
);
16997 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16998 xmalloc (sizeof (struct psymtab_cu_index_map
)
16999 * dwarf2_per_objfile
->n_comp_units
);
17000 make_cleanup (xfree
, psymtab_cu_index_map
);
17002 /* The CU list is already sorted, so we don't need to do additional
17003 work here. Also, the debug_types entries do not appear in
17004 all_comp_units, but only in their own hash table. */
17005 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17007 struct dwarf2_per_cu_data
*per_cu
17008 = dwarf2_per_objfile
->all_comp_units
[i
];
17009 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17011 struct psymtab_cu_index_map
*map
;
17014 write_psymbols (symtab
,
17016 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17017 psymtab
->n_global_syms
, i
,
17019 write_psymbols (symtab
,
17021 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17022 psymtab
->n_static_syms
, i
,
17025 map
= &psymtab_cu_index_map
[i
];
17026 map
->psymtab
= psymtab
;
17028 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17029 gdb_assert (slot
!= NULL
);
17030 gdb_assert (*slot
== NULL
);
17033 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
17034 obstack_grow (&cu_list
, val
, 8);
17035 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17036 obstack_grow (&cu_list
, val
, 8);
17039 /* Dump the address map. */
17040 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17042 /* Write out the .debug_type entries, if any. */
17043 if (dwarf2_per_objfile
->signatured_types
)
17045 struct signatured_type_index_data sig_data
;
17047 sig_data
.objfile
= objfile
;
17048 sig_data
.symtab
= symtab
;
17049 sig_data
.types_list
= &types_cu_list
;
17050 sig_data
.psyms_seen
= psyms_seen
;
17051 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17052 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17053 write_one_signatured_type
, &sig_data
);
17056 obstack_init (&constant_pool
);
17057 make_cleanup_obstack_free (&constant_pool
);
17058 obstack_init (&symtab_obstack
);
17059 make_cleanup_obstack_free (&symtab_obstack
);
17060 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17062 obstack_init (&contents
);
17063 make_cleanup_obstack_free (&contents
);
17064 size_of_contents
= 6 * sizeof (offset_type
);
17065 total_len
= size_of_contents
;
17067 /* The version number. */
17068 val
= MAYBE_SWAP (5);
17069 obstack_grow (&contents
, &val
, sizeof (val
));
17071 /* The offset of the CU list from the start of the file. */
17072 val
= MAYBE_SWAP (total_len
);
17073 obstack_grow (&contents
, &val
, sizeof (val
));
17074 total_len
+= obstack_object_size (&cu_list
);
17076 /* The offset of the types CU list from the start of the file. */
17077 val
= MAYBE_SWAP (total_len
);
17078 obstack_grow (&contents
, &val
, sizeof (val
));
17079 total_len
+= obstack_object_size (&types_cu_list
);
17081 /* The offset of the address table from the start of the file. */
17082 val
= MAYBE_SWAP (total_len
);
17083 obstack_grow (&contents
, &val
, sizeof (val
));
17084 total_len
+= obstack_object_size (&addr_obstack
);
17086 /* The offset of the symbol table from the start of the file. */
17087 val
= MAYBE_SWAP (total_len
);
17088 obstack_grow (&contents
, &val
, sizeof (val
));
17089 total_len
+= obstack_object_size (&symtab_obstack
);
17091 /* The offset of the constant pool from the start of the file. */
17092 val
= MAYBE_SWAP (total_len
);
17093 obstack_grow (&contents
, &val
, sizeof (val
));
17094 total_len
+= obstack_object_size (&constant_pool
);
17096 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17098 write_obstack (out_file
, &contents
);
17099 write_obstack (out_file
, &cu_list
);
17100 write_obstack (out_file
, &types_cu_list
);
17101 write_obstack (out_file
, &addr_obstack
);
17102 write_obstack (out_file
, &symtab_obstack
);
17103 write_obstack (out_file
, &constant_pool
);
17107 /* We want to keep the file, so we set cleanup_filename to NULL
17108 here. See unlink_if_set. */
17109 cleanup_filename
= NULL
;
17111 do_cleanups (cleanup
);
17114 /* Implementation of the `save gdb-index' command.
17116 Note that the file format used by this command is documented in the
17117 GDB manual. Any changes here must be documented there. */
17120 save_gdb_index_command (char *arg
, int from_tty
)
17122 struct objfile
*objfile
;
17125 error (_("usage: save gdb-index DIRECTORY"));
17127 ALL_OBJFILES (objfile
)
17131 /* If the objfile does not correspond to an actual file, skip it. */
17132 if (stat (objfile
->name
, &st
) < 0)
17135 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17136 if (dwarf2_per_objfile
)
17138 volatile struct gdb_exception except
;
17140 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17142 write_psymtabs_to_index (objfile
, arg
);
17144 if (except
.reason
< 0)
17145 exception_fprintf (gdb_stderr
, except
,
17146 _("Error while writing index for `%s': "),
17154 int dwarf2_always_disassemble
;
17157 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17158 struct cmd_list_element
*c
, const char *value
)
17160 fprintf_filtered (file
,
17161 _("Whether to always disassemble "
17162 "DWARF expressions is %s.\n"),
17167 show_check_physname (struct ui_file
*file
, int from_tty
,
17168 struct cmd_list_element
*c
, const char *value
)
17170 fprintf_filtered (file
,
17171 _("Whether to check \"physname\" is %s.\n"),
17175 void _initialize_dwarf2_read (void);
17178 _initialize_dwarf2_read (void)
17180 struct cmd_list_element
*c
;
17182 dwarf2_objfile_data_key
17183 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17185 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17186 Set DWARF 2 specific variables.\n\
17187 Configure DWARF 2 variables such as the cache size"),
17188 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17189 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17191 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17192 Show DWARF 2 specific variables\n\
17193 Show DWARF 2 variables such as the cache size"),
17194 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17195 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17197 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17198 &dwarf2_max_cache_age
, _("\
17199 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17200 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17201 A higher limit means that cached compilation units will be stored\n\
17202 in memory longer, and more total memory will be used. Zero disables\n\
17203 caching, which can slow down startup."),
17205 show_dwarf2_max_cache_age
,
17206 &set_dwarf2_cmdlist
,
17207 &show_dwarf2_cmdlist
);
17209 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17210 &dwarf2_always_disassemble
, _("\
17211 Set whether `info address' always disassembles DWARF expressions."), _("\
17212 Show whether `info address' always disassembles DWARF expressions."), _("\
17213 When enabled, DWARF expressions are always printed in an assembly-like\n\
17214 syntax. When disabled, expressions will be printed in a more\n\
17215 conversational style, when possible."),
17217 show_dwarf2_always_disassemble
,
17218 &set_dwarf2_cmdlist
,
17219 &show_dwarf2_cmdlist
);
17221 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17222 Set debugging of the dwarf2 DIE reader."), _("\
17223 Show debugging of the dwarf2 DIE reader."), _("\
17224 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17225 The value is the maximum depth to print."),
17228 &setdebuglist
, &showdebuglist
);
17230 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17231 Set cross-checking of \"physname\" code against demangler."), _("\
17232 Show cross-checking of \"physname\" code against demangler."), _("\
17233 When enabled, GDB's internal \"physname\" code is checked against\n\
17235 NULL
, show_check_physname
,
17236 &setdebuglist
, &showdebuglist
);
17238 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17240 Save a gdb-index file.\n\
17241 Usage: save gdb-index DIRECTORY"),
17243 set_cmd_completer (c
, filename_completer
);