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
);
3466 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3468 pst
->dirname
= DW_STRING (attr
);
3470 pst
->read_symtab_private
= this_cu
;
3472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3474 /* Store the function that reads in the rest of the symbol table. */
3475 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3477 this_cu
->v
.psymtab
= pst
;
3479 dwarf2_find_base_address (comp_unit_die
, &cu
);
3481 /* Possibly set the default values of LOWPC and HIGHPC from
3483 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3484 &best_highpc
, &cu
, pst
);
3485 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3486 /* Store the contiguous range if it is not empty; it can be empty for
3487 CUs with no code. */
3488 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3489 best_lowpc
+ baseaddr
,
3490 best_highpc
+ baseaddr
- 1, pst
);
3492 /* Check if comp unit has_children.
3493 If so, read the rest of the partial symbols from this comp unit.
3494 If not, there's no more debug_info for this comp unit. */
3497 struct partial_die_info
*first_die
;
3498 CORE_ADDR lowpc
, highpc
;
3500 lowpc
= ((CORE_ADDR
) -1);
3501 highpc
= ((CORE_ADDR
) 0);
3503 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3505 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3506 ! has_pc_info
, &cu
);
3508 /* If we didn't find a lowpc, set it to highpc to avoid
3509 complaints from `maint check'. */
3510 if (lowpc
== ((CORE_ADDR
) -1))
3513 /* If the compilation unit didn't have an explicit address range,
3514 then use the information extracted from its child dies. */
3518 best_highpc
= highpc
;
3521 pst
->textlow
= best_lowpc
+ baseaddr
;
3522 pst
->texthigh
= best_highpc
+ baseaddr
;
3524 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3525 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3526 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3527 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3528 sort_pst_symbols (pst
);
3530 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3531 + cu
.header
.initial_length_size
);
3533 if (this_cu
->debug_type_section
)
3535 /* It's not clear we want to do anything with stmt lists here.
3536 Waiting to see what gcc ultimately does. */
3540 /* Get the list of files included in the current compilation unit,
3541 and build a psymtab for each of them. */
3542 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3545 do_cleanups (back_to_inner
);
3550 /* Traversal function for htab_traverse_noresize.
3551 Process one .debug_types comp-unit. */
3554 process_type_comp_unit (void **slot
, void *info
)
3556 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3557 struct objfile
*objfile
= (struct objfile
*) info
;
3558 struct dwarf2_per_cu_data
*this_cu
;
3560 this_cu
= &entry
->per_cu
;
3562 gdb_assert (this_cu
->debug_type_section
->readin
);
3563 process_psymtab_comp_unit (objfile
, this_cu
,
3564 this_cu
->debug_type_section
->buffer
,
3565 (this_cu
->debug_type_section
->buffer
3567 this_cu
->debug_type_section
->size
);
3572 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3573 Build partial symbol tables for the .debug_types comp-units. */
3576 build_type_psymtabs (struct objfile
*objfile
)
3578 if (! create_debug_types_hash_table (objfile
))
3581 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3582 process_type_comp_unit
, objfile
);
3585 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3588 psymtabs_addrmap_cleanup (void *o
)
3590 struct objfile
*objfile
= o
;
3592 objfile
->psymtabs_addrmap
= NULL
;
3595 /* Build the partial symbol table by doing a quick pass through the
3596 .debug_info and .debug_abbrev sections. */
3599 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3602 struct cleanup
*back_to
, *addrmap_cleanup
;
3603 struct obstack temp_obstack
;
3605 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3607 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3608 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3610 /* Any cached compilation units will be linked by the per-objfile
3611 read_in_chain. Make sure to free them when we're done. */
3612 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3614 build_type_psymtabs (objfile
);
3616 create_all_comp_units (objfile
);
3618 /* Create a temporary address map on a temporary obstack. We later
3619 copy this to the final obstack. */
3620 obstack_init (&temp_obstack
);
3621 make_cleanup_obstack_free (&temp_obstack
);
3622 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3623 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3625 /* Since the objects we're extracting from .debug_info vary in
3626 length, only the individual functions to extract them (like
3627 read_comp_unit_head and load_partial_die) can really know whether
3628 the buffer is large enough to hold another complete object.
3630 At the moment, they don't actually check that. If .debug_info
3631 holds just one extra byte after the last compilation unit's dies,
3632 then read_comp_unit_head will happily read off the end of the
3633 buffer. read_partial_die is similarly casual. Those functions
3636 For this loop condition, simply checking whether there's any data
3637 left at all should be sufficient. */
3639 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3640 + dwarf2_per_objfile
->info
.size
))
3642 struct dwarf2_per_cu_data
*this_cu
;
3644 this_cu
= dwarf2_find_comp_unit (info_ptr
3645 - dwarf2_per_objfile
->info
.buffer
,
3648 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3649 dwarf2_per_objfile
->info
.buffer
,
3651 dwarf2_per_objfile
->info
.size
);
3654 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3655 &objfile
->objfile_obstack
);
3656 discard_cleanups (addrmap_cleanup
);
3658 do_cleanups (back_to
);
3661 /* Load the partial DIEs for a secondary CU into memory. */
3664 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3665 struct objfile
*objfile
)
3667 bfd
*abfd
= objfile
->obfd
;
3669 struct die_info
*comp_unit_die
;
3670 struct dwarf2_cu
*cu
;
3671 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3673 struct die_reader_specs reader_specs
;
3676 gdb_assert (! this_cu
->debug_type_section
);
3678 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3679 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3681 if (this_cu
->cu
== NULL
)
3683 cu
= xmalloc (sizeof (*cu
));
3684 init_one_comp_unit (cu
, objfile
);
3688 /* If an error occurs while loading, release our storage. */
3689 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3691 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3692 dwarf2_per_objfile
->info
.buffer
,
3693 dwarf2_per_objfile
->info
.size
,
3696 /* Skip dummy compilation units. */
3697 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
3698 + dwarf2_per_objfile
->info
.size
)
3699 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3701 do_cleanups (free_cu_cleanup
);
3705 /* Link this compilation unit into the compilation unit tree. */
3707 cu
->per_cu
= this_cu
;
3709 /* Link this CU into read_in_chain. */
3710 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3711 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3716 info_ptr
+= cu
->header
.first_die_offset
;
3719 /* Read the abbrevs for this compilation unit into a table. */
3720 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3721 dwarf2_read_abbrevs (abfd
, cu
);
3722 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3724 /* Read the compilation unit die. */
3725 init_cu_die_reader (&reader_specs
, cu
);
3726 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3729 prepare_one_comp_unit (cu
, comp_unit_die
);
3731 /* Check if comp unit has_children.
3732 If so, read the rest of the partial symbols from this comp unit.
3733 If not, there's no more debug_info for this comp unit. */
3735 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3737 do_cleanups (free_abbrevs_cleanup
);
3741 /* We've successfully allocated this compilation unit. Let our
3742 caller clean it up when finished with it. */
3743 discard_cleanups (free_cu_cleanup
);
3747 /* Create a list of all compilation units in OBJFILE. We do this only
3748 if an inter-comp-unit reference is found; presumably if there is one,
3749 there will be many, and one will occur early in the .debug_info section.
3750 So there's no point in building this list incrementally. */
3753 create_all_comp_units (struct objfile
*objfile
)
3757 struct dwarf2_per_cu_data
**all_comp_units
;
3760 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3761 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3765 all_comp_units
= xmalloc (n_allocated
3766 * sizeof (struct dwarf2_per_cu_data
*));
3768 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3769 + dwarf2_per_objfile
->info
.size
)
3771 unsigned int length
, initial_length_size
;
3772 struct dwarf2_per_cu_data
*this_cu
;
3773 unsigned int offset
;
3775 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3777 /* Read just enough information to find out where the next
3778 compilation unit is. */
3779 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3780 &initial_length_size
);
3782 /* Save the compilation unit for later lookup. */
3783 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3784 sizeof (struct dwarf2_per_cu_data
));
3785 memset (this_cu
, 0, sizeof (*this_cu
));
3786 this_cu
->offset
= offset
;
3787 this_cu
->length
= length
+ initial_length_size
;
3788 this_cu
->objfile
= objfile
;
3790 if (n_comp_units
== n_allocated
)
3793 all_comp_units
= xrealloc (all_comp_units
,
3795 * sizeof (struct dwarf2_per_cu_data
*));
3797 all_comp_units
[n_comp_units
++] = this_cu
;
3799 info_ptr
= info_ptr
+ this_cu
->length
;
3802 dwarf2_per_objfile
->all_comp_units
3803 = obstack_alloc (&objfile
->objfile_obstack
,
3804 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3805 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3806 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3807 xfree (all_comp_units
);
3808 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3811 /* Process all loaded DIEs for compilation unit CU, starting at
3812 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3813 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3814 DW_AT_ranges). If NEED_PC is set, then this function will set
3815 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3816 and record the covered ranges in the addrmap. */
3819 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3820 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3822 struct partial_die_info
*pdi
;
3824 /* Now, march along the PDI's, descending into ones which have
3825 interesting children but skipping the children of the other ones,
3826 until we reach the end of the compilation unit. */
3832 fixup_partial_die (pdi
, cu
);
3834 /* Anonymous namespaces or modules have no name but have interesting
3835 children, so we need to look at them. Ditto for anonymous
3838 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3839 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3843 case DW_TAG_subprogram
:
3844 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3846 case DW_TAG_constant
:
3847 case DW_TAG_variable
:
3848 case DW_TAG_typedef
:
3849 case DW_TAG_union_type
:
3850 if (!pdi
->is_declaration
)
3852 add_partial_symbol (pdi
, cu
);
3855 case DW_TAG_class_type
:
3856 case DW_TAG_interface_type
:
3857 case DW_TAG_structure_type
:
3858 if (!pdi
->is_declaration
)
3860 add_partial_symbol (pdi
, cu
);
3863 case DW_TAG_enumeration_type
:
3864 if (!pdi
->is_declaration
)
3865 add_partial_enumeration (pdi
, cu
);
3867 case DW_TAG_base_type
:
3868 case DW_TAG_subrange_type
:
3869 /* File scope base type definitions are added to the partial
3871 add_partial_symbol (pdi
, cu
);
3873 case DW_TAG_namespace
:
3874 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3877 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3884 /* If the die has a sibling, skip to the sibling. */
3886 pdi
= pdi
->die_sibling
;
3890 /* Functions used to compute the fully scoped name of a partial DIE.
3892 Normally, this is simple. For C++, the parent DIE's fully scoped
3893 name is concatenated with "::" and the partial DIE's name. For
3894 Java, the same thing occurs except that "." is used instead of "::".
3895 Enumerators are an exception; they use the scope of their parent
3896 enumeration type, i.e. the name of the enumeration type is not
3897 prepended to the enumerator.
3899 There are two complexities. One is DW_AT_specification; in this
3900 case "parent" means the parent of the target of the specification,
3901 instead of the direct parent of the DIE. The other is compilers
3902 which do not emit DW_TAG_namespace; in this case we try to guess
3903 the fully qualified name of structure types from their members'
3904 linkage names. This must be done using the DIE's children rather
3905 than the children of any DW_AT_specification target. We only need
3906 to do this for structures at the top level, i.e. if the target of
3907 any DW_AT_specification (if any; otherwise the DIE itself) does not
3910 /* Compute the scope prefix associated with PDI's parent, in
3911 compilation unit CU. The result will be allocated on CU's
3912 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3913 field. NULL is returned if no prefix is necessary. */
3915 partial_die_parent_scope (struct partial_die_info
*pdi
,
3916 struct dwarf2_cu
*cu
)
3918 char *grandparent_scope
;
3919 struct partial_die_info
*parent
, *real_pdi
;
3921 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3922 then this means the parent of the specification DIE. */
3925 while (real_pdi
->has_specification
)
3926 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3928 parent
= real_pdi
->die_parent
;
3932 if (parent
->scope_set
)
3933 return parent
->scope
;
3935 fixup_partial_die (parent
, cu
);
3937 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3939 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3940 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3941 Work around this problem here. */
3942 if (cu
->language
== language_cplus
3943 && parent
->tag
== DW_TAG_namespace
3944 && strcmp (parent
->name
, "::") == 0
3945 && grandparent_scope
== NULL
)
3947 parent
->scope
= NULL
;
3948 parent
->scope_set
= 1;
3952 if (pdi
->tag
== DW_TAG_enumerator
)
3953 /* Enumerators should not get the name of the enumeration as a prefix. */
3954 parent
->scope
= grandparent_scope
;
3955 else if (parent
->tag
== DW_TAG_namespace
3956 || parent
->tag
== DW_TAG_module
3957 || parent
->tag
== DW_TAG_structure_type
3958 || parent
->tag
== DW_TAG_class_type
3959 || parent
->tag
== DW_TAG_interface_type
3960 || parent
->tag
== DW_TAG_union_type
3961 || parent
->tag
== DW_TAG_enumeration_type
)
3963 if (grandparent_scope
== NULL
)
3964 parent
->scope
= parent
->name
;
3966 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3968 parent
->name
, 0, cu
);
3972 /* FIXME drow/2004-04-01: What should we be doing with
3973 function-local names? For partial symbols, we should probably be
3975 complaint (&symfile_complaints
,
3976 _("unhandled containing DIE tag %d for DIE at %d"),
3977 parent
->tag
, pdi
->offset
);
3978 parent
->scope
= grandparent_scope
;
3981 parent
->scope_set
= 1;
3982 return parent
->scope
;
3985 /* Return the fully scoped name associated with PDI, from compilation unit
3986 CU. The result will be allocated with malloc. */
3988 partial_die_full_name (struct partial_die_info
*pdi
,
3989 struct dwarf2_cu
*cu
)
3993 /* If this is a template instantiation, we can not work out the
3994 template arguments from partial DIEs. So, unfortunately, we have
3995 to go through the full DIEs. At least any work we do building
3996 types here will be reused if full symbols are loaded later. */
3997 if (pdi
->has_template_arguments
)
3999 fixup_partial_die (pdi
, cu
);
4001 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4003 struct die_info
*die
;
4004 struct attribute attr
;
4005 struct dwarf2_cu
*ref_cu
= cu
;
4008 attr
.form
= DW_FORM_ref_addr
;
4009 attr
.u
.addr
= pdi
->offset
;
4010 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4012 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4016 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4017 if (parent_scope
== NULL
)
4020 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4024 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4026 struct objfile
*objfile
= cu
->objfile
;
4028 char *actual_name
= NULL
;
4029 const struct partial_symbol
*psym
= NULL
;
4031 int built_actual_name
= 0;
4033 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4035 actual_name
= partial_die_full_name (pdi
, cu
);
4037 built_actual_name
= 1;
4039 if (actual_name
== NULL
)
4040 actual_name
= pdi
->name
;
4044 case DW_TAG_subprogram
:
4045 if (pdi
->is_external
|| cu
->language
== language_ada
)
4047 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4048 of the global scope. But in Ada, we want to be able to access
4049 nested procedures globally. So all Ada subprograms are stored
4050 in the global scope. */
4051 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4052 mst_text, objfile); */
4053 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4055 VAR_DOMAIN
, LOC_BLOCK
,
4056 &objfile
->global_psymbols
,
4057 0, pdi
->lowpc
+ baseaddr
,
4058 cu
->language
, objfile
);
4062 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4063 mst_file_text, objfile); */
4064 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4066 VAR_DOMAIN
, LOC_BLOCK
,
4067 &objfile
->static_psymbols
,
4068 0, pdi
->lowpc
+ baseaddr
,
4069 cu
->language
, objfile
);
4072 case DW_TAG_constant
:
4074 struct psymbol_allocation_list
*list
;
4076 if (pdi
->is_external
)
4077 list
= &objfile
->global_psymbols
;
4079 list
= &objfile
->static_psymbols
;
4080 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4081 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4082 list
, 0, 0, cu
->language
, objfile
);
4085 case DW_TAG_variable
:
4087 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4091 && !dwarf2_per_objfile
->has_section_at_zero
)
4093 /* A global or static variable may also have been stripped
4094 out by the linker if unused, in which case its address
4095 will be nullified; do not add such variables into partial
4096 symbol table then. */
4098 else if (pdi
->is_external
)
4101 Don't enter into the minimal symbol tables as there is
4102 a minimal symbol table entry from the ELF symbols already.
4103 Enter into partial symbol table if it has a location
4104 descriptor or a type.
4105 If the location descriptor is missing, new_symbol will create
4106 a LOC_UNRESOLVED symbol, the address of the variable will then
4107 be determined from the minimal symbol table whenever the variable
4109 The address for the partial symbol table entry is not
4110 used by GDB, but it comes in handy for debugging partial symbol
4113 if (pdi
->locdesc
|| pdi
->has_type
)
4114 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4116 VAR_DOMAIN
, LOC_STATIC
,
4117 &objfile
->global_psymbols
,
4119 cu
->language
, objfile
);
4123 /* Static Variable. Skip symbols without location descriptors. */
4124 if (pdi
->locdesc
== NULL
)
4126 if (built_actual_name
)
4127 xfree (actual_name
);
4130 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4131 mst_file_data, objfile); */
4132 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4134 VAR_DOMAIN
, LOC_STATIC
,
4135 &objfile
->static_psymbols
,
4137 cu
->language
, objfile
);
4140 case DW_TAG_typedef
:
4141 case DW_TAG_base_type
:
4142 case DW_TAG_subrange_type
:
4143 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4145 VAR_DOMAIN
, LOC_TYPEDEF
,
4146 &objfile
->static_psymbols
,
4147 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4149 case DW_TAG_namespace
:
4150 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4152 VAR_DOMAIN
, LOC_TYPEDEF
,
4153 &objfile
->global_psymbols
,
4154 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4156 case DW_TAG_class_type
:
4157 case DW_TAG_interface_type
:
4158 case DW_TAG_structure_type
:
4159 case DW_TAG_union_type
:
4160 case DW_TAG_enumeration_type
:
4161 /* Skip external references. The DWARF standard says in the section
4162 about "Structure, Union, and Class Type Entries": "An incomplete
4163 structure, union or class type is represented by a structure,
4164 union or class entry that does not have a byte size attribute
4165 and that has a DW_AT_declaration attribute." */
4166 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4168 if (built_actual_name
)
4169 xfree (actual_name
);
4173 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4174 static vs. global. */
4175 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4177 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4178 (cu
->language
== language_cplus
4179 || cu
->language
== language_java
)
4180 ? &objfile
->global_psymbols
4181 : &objfile
->static_psymbols
,
4182 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4185 case DW_TAG_enumerator
:
4186 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4188 VAR_DOMAIN
, LOC_CONST
,
4189 (cu
->language
== language_cplus
4190 || cu
->language
== language_java
)
4191 ? &objfile
->global_psymbols
4192 : &objfile
->static_psymbols
,
4193 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4199 if (built_actual_name
)
4200 xfree (actual_name
);
4203 /* Read a partial die corresponding to a namespace; also, add a symbol
4204 corresponding to that namespace to the symbol table. NAMESPACE is
4205 the name of the enclosing namespace. */
4208 add_partial_namespace (struct partial_die_info
*pdi
,
4209 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4210 int need_pc
, struct dwarf2_cu
*cu
)
4212 /* Add a symbol for the namespace. */
4214 add_partial_symbol (pdi
, cu
);
4216 /* Now scan partial symbols in that namespace. */
4218 if (pdi
->has_children
)
4219 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4222 /* Read a partial die corresponding to a Fortran module. */
4225 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4226 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4228 /* Now scan partial symbols in that module. */
4230 if (pdi
->has_children
)
4231 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4234 /* Read a partial die corresponding to a subprogram and create a partial
4235 symbol for that subprogram. When the CU language allows it, this
4236 routine also defines a partial symbol for each nested subprogram
4237 that this subprogram contains.
4239 DIE my also be a lexical block, in which case we simply search
4240 recursively for suprograms defined inside that lexical block.
4241 Again, this is only performed when the CU language allows this
4242 type of definitions. */
4245 add_partial_subprogram (struct partial_die_info
*pdi
,
4246 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4247 int need_pc
, struct dwarf2_cu
*cu
)
4249 if (pdi
->tag
== DW_TAG_subprogram
)
4251 if (pdi
->has_pc_info
)
4253 if (pdi
->lowpc
< *lowpc
)
4254 *lowpc
= pdi
->lowpc
;
4255 if (pdi
->highpc
> *highpc
)
4256 *highpc
= pdi
->highpc
;
4260 struct objfile
*objfile
= cu
->objfile
;
4262 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4263 SECT_OFF_TEXT (objfile
));
4264 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4265 pdi
->lowpc
+ baseaddr
,
4266 pdi
->highpc
- 1 + baseaddr
,
4267 cu
->per_cu
->v
.psymtab
);
4269 if (!pdi
->is_declaration
)
4270 /* Ignore subprogram DIEs that do not have a name, they are
4271 illegal. Do not emit a complaint at this point, we will
4272 do so when we convert this psymtab into a symtab. */
4274 add_partial_symbol (pdi
, cu
);
4278 if (! pdi
->has_children
)
4281 if (cu
->language
== language_ada
)
4283 pdi
= pdi
->die_child
;
4286 fixup_partial_die (pdi
, cu
);
4287 if (pdi
->tag
== DW_TAG_subprogram
4288 || pdi
->tag
== DW_TAG_lexical_block
)
4289 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4290 pdi
= pdi
->die_sibling
;
4295 /* Read a partial die corresponding to an enumeration type. */
4298 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4299 struct dwarf2_cu
*cu
)
4301 struct partial_die_info
*pdi
;
4303 if (enum_pdi
->name
!= NULL
)
4304 add_partial_symbol (enum_pdi
, cu
);
4306 pdi
= enum_pdi
->die_child
;
4309 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4310 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4312 add_partial_symbol (pdi
, cu
);
4313 pdi
= pdi
->die_sibling
;
4317 /* Return the initial uleb128 in the die at INFO_PTR. */
4320 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4322 unsigned int bytes_read
;
4324 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4327 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4328 Return the corresponding abbrev, or NULL if the number is zero (indicating
4329 an empty DIE). In either case *BYTES_READ will be set to the length of
4330 the initial number. */
4332 static struct abbrev_info
*
4333 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4334 struct dwarf2_cu
*cu
)
4336 bfd
*abfd
= cu
->objfile
->obfd
;
4337 unsigned int abbrev_number
;
4338 struct abbrev_info
*abbrev
;
4340 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4342 if (abbrev_number
== 0)
4345 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4348 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4349 abbrev_number
, bfd_get_filename (abfd
));
4355 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4356 Returns a pointer to the end of a series of DIEs, terminated by an empty
4357 DIE. Any children of the skipped DIEs will also be skipped. */
4360 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4362 struct abbrev_info
*abbrev
;
4363 unsigned int bytes_read
;
4367 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4369 return info_ptr
+ bytes_read
;
4371 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4375 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4376 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4377 abbrev corresponding to that skipped uleb128 should be passed in
4378 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4382 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4383 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4385 unsigned int bytes_read
;
4386 struct attribute attr
;
4387 bfd
*abfd
= cu
->objfile
->obfd
;
4388 unsigned int form
, i
;
4390 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4392 /* The only abbrev we care about is DW_AT_sibling. */
4393 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4395 read_attribute (&attr
, &abbrev
->attrs
[i
],
4396 abfd
, info_ptr
, cu
);
4397 if (attr
.form
== DW_FORM_ref_addr
)
4398 complaint (&symfile_complaints
,
4399 _("ignoring absolute DW_AT_sibling"));
4401 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4404 /* If it isn't DW_AT_sibling, skip this attribute. */
4405 form
= abbrev
->attrs
[i
].form
;
4409 case DW_FORM_ref_addr
:
4410 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4411 and later it is offset sized. */
4412 if (cu
->header
.version
== 2)
4413 info_ptr
+= cu
->header
.addr_size
;
4415 info_ptr
+= cu
->header
.offset_size
;
4418 info_ptr
+= cu
->header
.addr_size
;
4425 case DW_FORM_flag_present
:
4437 case DW_FORM_ref_sig8
:
4440 case DW_FORM_string
:
4441 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4442 info_ptr
+= bytes_read
;
4444 case DW_FORM_sec_offset
:
4446 info_ptr
+= cu
->header
.offset_size
;
4448 case DW_FORM_exprloc
:
4450 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4451 info_ptr
+= bytes_read
;
4453 case DW_FORM_block1
:
4454 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4456 case DW_FORM_block2
:
4457 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4459 case DW_FORM_block4
:
4460 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4464 case DW_FORM_ref_udata
:
4465 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4467 case DW_FORM_indirect
:
4468 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4469 info_ptr
+= bytes_read
;
4470 /* We need to continue parsing from here, so just go back to
4472 goto skip_attribute
;
4475 error (_("Dwarf Error: Cannot handle %s "
4476 "in DWARF reader [in module %s]"),
4477 dwarf_form_name (form
),
4478 bfd_get_filename (abfd
));
4482 if (abbrev
->has_children
)
4483 return skip_children (buffer
, info_ptr
, cu
);
4488 /* Locate ORIG_PDI's sibling.
4489 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4493 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4494 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4495 bfd
*abfd
, struct dwarf2_cu
*cu
)
4497 /* Do we know the sibling already? */
4499 if (orig_pdi
->sibling
)
4500 return orig_pdi
->sibling
;
4502 /* Are there any children to deal with? */
4504 if (!orig_pdi
->has_children
)
4507 /* Skip the children the long way. */
4509 return skip_children (buffer
, info_ptr
, cu
);
4512 /* Expand this partial symbol table into a full symbol table. */
4515 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4521 warning (_("bug: psymtab for %s is already read in."),
4528 printf_filtered (_("Reading in symbols for %s..."),
4530 gdb_flush (gdb_stdout
);
4533 /* Restore our global data. */
4534 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4535 dwarf2_objfile_data_key
);
4537 /* If this psymtab is constructed from a debug-only objfile, the
4538 has_section_at_zero flag will not necessarily be correct. We
4539 can get the correct value for this flag by looking at the data
4540 associated with the (presumably stripped) associated objfile. */
4541 if (pst
->objfile
->separate_debug_objfile_backlink
)
4543 struct dwarf2_per_objfile
*dpo_backlink
4544 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4545 dwarf2_objfile_data_key
);
4547 dwarf2_per_objfile
->has_section_at_zero
4548 = dpo_backlink
->has_section_at_zero
;
4551 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4553 psymtab_to_symtab_1 (pst
);
4555 /* Finish up the debug error message. */
4557 printf_filtered (_("done.\n"));
4562 /* Add PER_CU to the queue. */
4565 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4567 struct dwarf2_queue_item
*item
;
4570 item
= xmalloc (sizeof (*item
));
4571 item
->per_cu
= per_cu
;
4574 if (dwarf2_queue
== NULL
)
4575 dwarf2_queue
= item
;
4577 dwarf2_queue_tail
->next
= item
;
4579 dwarf2_queue_tail
= item
;
4582 /* Process the queue. */
4585 process_queue (struct objfile
*objfile
)
4587 struct dwarf2_queue_item
*item
, *next_item
;
4589 /* The queue starts out with one item, but following a DIE reference
4590 may load a new CU, adding it to the end of the queue. */
4591 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4593 if (dwarf2_per_objfile
->using_index
4594 ? !item
->per_cu
->v
.quick
->symtab
4595 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4596 process_full_comp_unit (item
->per_cu
);
4598 item
->per_cu
->queued
= 0;
4599 next_item
= item
->next
;
4603 dwarf2_queue_tail
= NULL
;
4606 /* Free all allocated queue entries. This function only releases anything if
4607 an error was thrown; if the queue was processed then it would have been
4608 freed as we went along. */
4611 dwarf2_release_queue (void *dummy
)
4613 struct dwarf2_queue_item
*item
, *last
;
4615 item
= dwarf2_queue
;
4618 /* Anything still marked queued is likely to be in an
4619 inconsistent state, so discard it. */
4620 if (item
->per_cu
->queued
)
4622 if (item
->per_cu
->cu
!= NULL
)
4623 free_one_cached_comp_unit (item
->per_cu
->cu
);
4624 item
->per_cu
->queued
= 0;
4632 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4635 /* Read in full symbols for PST, and anything it depends on. */
4638 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4640 struct dwarf2_per_cu_data
*per_cu
;
4641 struct cleanup
*back_to
;
4644 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4645 if (!pst
->dependencies
[i
]->readin
)
4647 /* Inform about additional files that need to be read in. */
4650 /* FIXME: i18n: Need to make this a single string. */
4651 fputs_filtered (" ", gdb_stdout
);
4653 fputs_filtered ("and ", gdb_stdout
);
4655 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4656 wrap_here (""); /* Flush output. */
4657 gdb_flush (gdb_stdout
);
4659 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4662 per_cu
= pst
->read_symtab_private
;
4666 /* It's an include file, no symbols to read for it.
4667 Everything is in the parent symtab. */
4672 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4675 /* Load the DIEs associated with PER_CU into memory. */
4678 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4679 struct objfile
*objfile
)
4681 bfd
*abfd
= objfile
->obfd
;
4682 struct dwarf2_cu
*cu
;
4683 unsigned int offset
;
4684 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4685 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4686 struct attribute
*attr
;
4689 gdb_assert (! per_cu
->debug_type_section
);
4691 /* Set local variables from the partial symbol table info. */
4692 offset
= per_cu
->offset
;
4694 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4695 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4696 beg_of_comp_unit
= info_ptr
;
4698 if (per_cu
->cu
== NULL
)
4700 cu
= xmalloc (sizeof (*cu
));
4701 init_one_comp_unit (cu
, objfile
);
4705 /* If an error occurs while loading, release our storage. */
4706 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4708 /* Read in the comp_unit header. */
4709 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4711 /* Skip dummy compilation units. */
4712 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4713 + dwarf2_per_objfile
->info
.size
)
4714 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4716 do_cleanups (free_cu_cleanup
);
4720 /* Complete the cu_header. */
4721 cu
->header
.offset
= offset
;
4722 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4724 /* Read the abbrevs for this compilation unit. */
4725 dwarf2_read_abbrevs (abfd
, cu
);
4726 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4728 /* Link this compilation unit into the compilation unit tree. */
4730 cu
->per_cu
= per_cu
;
4732 /* Link this CU into read_in_chain. */
4733 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4734 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4739 info_ptr
+= cu
->header
.first_die_offset
;
4742 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4744 /* We try not to read any attributes in this function, because not
4745 all objfiles needed for references have been loaded yet, and symbol
4746 table processing isn't initialized. But we have to set the CU language,
4747 or we won't be able to build types correctly. */
4748 prepare_one_comp_unit (cu
, cu
->dies
);
4750 /* Similarly, if we do not read the producer, we can not apply
4751 producer-specific interpretation. */
4752 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4754 cu
->producer
= DW_STRING (attr
);
4758 do_cleanups (free_abbrevs_cleanup
);
4760 /* We've successfully allocated this compilation unit. Let our
4761 caller clean it up when finished with it. */
4762 discard_cleanups (free_cu_cleanup
);
4766 /* Add a DIE to the delayed physname list. */
4769 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4770 const char *name
, struct die_info
*die
,
4771 struct dwarf2_cu
*cu
)
4773 struct delayed_method_info mi
;
4775 mi
.fnfield_index
= fnfield_index
;
4779 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4782 /* A cleanup for freeing the delayed method list. */
4785 free_delayed_list (void *ptr
)
4787 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4788 if (cu
->method_list
!= NULL
)
4790 VEC_free (delayed_method_info
, cu
->method_list
);
4791 cu
->method_list
= NULL
;
4795 /* Compute the physnames of any methods on the CU's method list.
4797 The computation of method physnames is delayed in order to avoid the
4798 (bad) condition that one of the method's formal parameters is of an as yet
4802 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4805 struct delayed_method_info
*mi
;
4806 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4808 const char *physname
;
4809 struct fn_fieldlist
*fn_flp
4810 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4811 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4812 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4816 /* Generate full symbol information for PST and CU, whose DIEs have
4817 already been loaded into memory. */
4820 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4822 struct dwarf2_cu
*cu
= per_cu
->cu
;
4823 struct objfile
*objfile
= per_cu
->objfile
;
4824 CORE_ADDR lowpc
, highpc
;
4825 struct symtab
*symtab
;
4826 struct cleanup
*back_to
, *delayed_list_cleanup
;
4829 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4832 back_to
= make_cleanup (really_free_pendings
, NULL
);
4833 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4835 cu
->list_in_scope
= &file_symbols
;
4837 /* Do line number decoding in read_file_scope () */
4838 process_die (cu
->dies
, cu
);
4840 /* Now that we have processed all the DIEs in the CU, all the types
4841 should be complete, and it should now be safe to compute all of the
4843 compute_delayed_physnames (cu
);
4844 do_cleanups (delayed_list_cleanup
);
4846 /* Some compilers don't define a DW_AT_high_pc attribute for the
4847 compilation unit. If the DW_AT_high_pc is missing, synthesize
4848 it, by scanning the DIE's below the compilation unit. */
4849 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4851 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4855 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4857 /* Set symtab language to language from DW_AT_language. If the
4858 compilation is from a C file generated by language preprocessors, do
4859 not set the language if it was already deduced by start_subfile. */
4860 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4861 symtab
->language
= cu
->language
;
4863 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4864 produce DW_AT_location with location lists but it can be possibly
4865 invalid without -fvar-tracking.
4867 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4868 needed, it would be wrong due to missing DW_AT_producer there.
4870 Still one can confuse GDB by using non-standard GCC compilation
4871 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4873 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4874 symtab
->locations_valid
= 1;
4876 if (gcc_4_minor
>= 5)
4877 symtab
->epilogue_unwind_valid
= 1;
4879 symtab
->call_site_htab
= cu
->call_site_htab
;
4882 if (dwarf2_per_objfile
->using_index
)
4883 per_cu
->v
.quick
->symtab
= symtab
;
4886 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4887 pst
->symtab
= symtab
;
4891 do_cleanups (back_to
);
4894 /* Process a die and its children. */
4897 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4901 case DW_TAG_padding
:
4903 case DW_TAG_compile_unit
:
4904 read_file_scope (die
, cu
);
4906 case DW_TAG_type_unit
:
4907 read_type_unit_scope (die
, cu
);
4909 case DW_TAG_subprogram
:
4910 case DW_TAG_inlined_subroutine
:
4911 read_func_scope (die
, cu
);
4913 case DW_TAG_lexical_block
:
4914 case DW_TAG_try_block
:
4915 case DW_TAG_catch_block
:
4916 read_lexical_block_scope (die
, cu
);
4918 case DW_TAG_GNU_call_site
:
4919 read_call_site_scope (die
, cu
);
4921 case DW_TAG_class_type
:
4922 case DW_TAG_interface_type
:
4923 case DW_TAG_structure_type
:
4924 case DW_TAG_union_type
:
4925 process_structure_scope (die
, cu
);
4927 case DW_TAG_enumeration_type
:
4928 process_enumeration_scope (die
, cu
);
4931 /* These dies have a type, but processing them does not create
4932 a symbol or recurse to process the children. Therefore we can
4933 read them on-demand through read_type_die. */
4934 case DW_TAG_subroutine_type
:
4935 case DW_TAG_set_type
:
4936 case DW_TAG_array_type
:
4937 case DW_TAG_pointer_type
:
4938 case DW_TAG_ptr_to_member_type
:
4939 case DW_TAG_reference_type
:
4940 case DW_TAG_string_type
:
4943 case DW_TAG_base_type
:
4944 case DW_TAG_subrange_type
:
4945 case DW_TAG_typedef
:
4946 /* Add a typedef symbol for the type definition, if it has a
4948 new_symbol (die
, read_type_die (die
, cu
), cu
);
4950 case DW_TAG_common_block
:
4951 read_common_block (die
, cu
);
4953 case DW_TAG_common_inclusion
:
4955 case DW_TAG_namespace
:
4956 processing_has_namespace_info
= 1;
4957 read_namespace (die
, cu
);
4960 processing_has_namespace_info
= 1;
4961 read_module (die
, cu
);
4963 case DW_TAG_imported_declaration
:
4964 case DW_TAG_imported_module
:
4965 processing_has_namespace_info
= 1;
4966 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4967 || cu
->language
!= language_fortran
))
4968 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4969 dwarf_tag_name (die
->tag
));
4970 read_import_statement (die
, cu
);
4973 new_symbol (die
, NULL
, cu
);
4978 /* A helper function for dwarf2_compute_name which determines whether DIE
4979 needs to have the name of the scope prepended to the name listed in the
4983 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4985 struct attribute
*attr
;
4989 case DW_TAG_namespace
:
4990 case DW_TAG_typedef
:
4991 case DW_TAG_class_type
:
4992 case DW_TAG_interface_type
:
4993 case DW_TAG_structure_type
:
4994 case DW_TAG_union_type
:
4995 case DW_TAG_enumeration_type
:
4996 case DW_TAG_enumerator
:
4997 case DW_TAG_subprogram
:
5001 case DW_TAG_variable
:
5002 case DW_TAG_constant
:
5003 /* We only need to prefix "globally" visible variables. These include
5004 any variable marked with DW_AT_external or any variable that
5005 lives in a namespace. [Variables in anonymous namespaces
5006 require prefixing, but they are not DW_AT_external.] */
5008 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5010 struct dwarf2_cu
*spec_cu
= cu
;
5012 return die_needs_namespace (die_specification (die
, &spec_cu
),
5016 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5017 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5018 && die
->parent
->tag
!= DW_TAG_module
)
5020 /* A variable in a lexical block of some kind does not need a
5021 namespace, even though in C++ such variables may be external
5022 and have a mangled name. */
5023 if (die
->parent
->tag
== DW_TAG_lexical_block
5024 || die
->parent
->tag
== DW_TAG_try_block
5025 || die
->parent
->tag
== DW_TAG_catch_block
5026 || die
->parent
->tag
== DW_TAG_subprogram
)
5035 /* Retrieve the last character from a mem_file. */
5038 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5040 char *last_char_p
= (char *) object
;
5043 *last_char_p
= buffer
[length
- 1];
5046 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5047 compute the physname for the object, which include a method's
5048 formal parameters (C++/Java) and return type (Java).
5050 For Ada, return the DIE's linkage name rather than the fully qualified
5051 name. PHYSNAME is ignored..
5053 The result is allocated on the objfile_obstack and canonicalized. */
5056 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5060 name
= dwarf2_name (die
, cu
);
5062 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5063 compute it by typename_concat inside GDB. */
5064 if (cu
->language
== language_ada
5065 || (cu
->language
== language_fortran
&& physname
))
5067 /* For Ada unit, we prefer the linkage name over the name, as
5068 the former contains the exported name, which the user expects
5069 to be able to reference. Ideally, we want the user to be able
5070 to reference this entity using either natural or linkage name,
5071 but we haven't started looking at this enhancement yet. */
5072 struct attribute
*attr
;
5074 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5076 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5077 if (attr
&& DW_STRING (attr
))
5078 return DW_STRING (attr
);
5081 /* These are the only languages we know how to qualify names in. */
5083 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5084 || cu
->language
== language_fortran
))
5086 if (die_needs_namespace (die
, cu
))
5090 struct ui_file
*buf
;
5092 prefix
= determine_prefix (die
, cu
);
5093 buf
= mem_fileopen ();
5094 if (*prefix
!= '\0')
5096 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5099 fputs_unfiltered (prefixed_name
, buf
);
5100 xfree (prefixed_name
);
5103 fputs_unfiltered (name
, buf
);
5105 /* Template parameters may be specified in the DIE's DW_AT_name, or
5106 as children with DW_TAG_template_type_param or
5107 DW_TAG_value_type_param. If the latter, add them to the name
5108 here. If the name already has template parameters, then
5109 skip this step; some versions of GCC emit both, and
5110 it is more efficient to use the pre-computed name.
5112 Something to keep in mind about this process: it is very
5113 unlikely, or in some cases downright impossible, to produce
5114 something that will match the mangled name of a function.
5115 If the definition of the function has the same debug info,
5116 we should be able to match up with it anyway. But fallbacks
5117 using the minimal symbol, for instance to find a method
5118 implemented in a stripped copy of libstdc++, will not work.
5119 If we do not have debug info for the definition, we will have to
5120 match them up some other way.
5122 When we do name matching there is a related problem with function
5123 templates; two instantiated function templates are allowed to
5124 differ only by their return types, which we do not add here. */
5126 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5128 struct attribute
*attr
;
5129 struct die_info
*child
;
5132 die
->building_fullname
= 1;
5134 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5139 struct dwarf2_locexpr_baton
*baton
;
5142 if (child
->tag
!= DW_TAG_template_type_param
5143 && child
->tag
!= DW_TAG_template_value_param
)
5148 fputs_unfiltered ("<", buf
);
5152 fputs_unfiltered (", ", buf
);
5154 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5157 complaint (&symfile_complaints
,
5158 _("template parameter missing DW_AT_type"));
5159 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5162 type
= die_type (child
, cu
);
5164 if (child
->tag
== DW_TAG_template_type_param
)
5166 c_print_type (type
, "", buf
, -1, 0);
5170 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5173 complaint (&symfile_complaints
,
5174 _("template parameter missing "
5175 "DW_AT_const_value"));
5176 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5180 dwarf2_const_value_attr (attr
, type
, name
,
5181 &cu
->comp_unit_obstack
, cu
,
5182 &value
, &bytes
, &baton
);
5184 if (TYPE_NOSIGN (type
))
5185 /* GDB prints characters as NUMBER 'CHAR'. If that's
5186 changed, this can use value_print instead. */
5187 c_printchar (value
, type
, buf
);
5190 struct value_print_options opts
;
5193 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5197 else if (bytes
!= NULL
)
5199 v
= allocate_value (type
);
5200 memcpy (value_contents_writeable (v
), bytes
,
5201 TYPE_LENGTH (type
));
5204 v
= value_from_longest (type
, value
);
5206 /* Specify decimal so that we do not depend on
5208 get_formatted_print_options (&opts
, 'd');
5210 value_print (v
, buf
, &opts
);
5216 die
->building_fullname
= 0;
5220 /* Close the argument list, with a space if necessary
5221 (nested templates). */
5222 char last_char
= '\0';
5223 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5224 if (last_char
== '>')
5225 fputs_unfiltered (" >", buf
);
5227 fputs_unfiltered (">", buf
);
5231 /* For Java and C++ methods, append formal parameter type
5232 information, if PHYSNAME. */
5234 if (physname
&& die
->tag
== DW_TAG_subprogram
5235 && (cu
->language
== language_cplus
5236 || cu
->language
== language_java
))
5238 struct type
*type
= read_type_die (die
, cu
);
5240 c_type_print_args (type
, buf
, 1, cu
->language
);
5242 if (cu
->language
== language_java
)
5244 /* For java, we must append the return type to method
5246 if (die
->tag
== DW_TAG_subprogram
)
5247 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5250 else if (cu
->language
== language_cplus
)
5252 /* Assume that an artificial first parameter is
5253 "this", but do not crash if it is not. RealView
5254 marks unnamed (and thus unused) parameters as
5255 artificial; there is no way to differentiate
5257 if (TYPE_NFIELDS (type
) > 0
5258 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5259 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5260 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5262 fputs_unfiltered (" const", buf
);
5266 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5268 ui_file_delete (buf
);
5270 if (cu
->language
== language_cplus
)
5273 = dwarf2_canonicalize_name (name
, cu
,
5274 &cu
->objfile
->objfile_obstack
);
5285 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5286 If scope qualifiers are appropriate they will be added. The result
5287 will be allocated on the objfile_obstack, or NULL if the DIE does
5288 not have a name. NAME may either be from a previous call to
5289 dwarf2_name or NULL.
5291 The output string will be canonicalized (if C++/Java). */
5294 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5296 return dwarf2_compute_name (name
, die
, cu
, 0);
5299 /* Construct a physname for the given DIE in CU. NAME may either be
5300 from a previous call to dwarf2_name or NULL. The result will be
5301 allocated on the objfile_objstack or NULL if the DIE does not have a
5304 The output string will be canonicalized (if C++/Java). */
5307 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5309 struct attribute
*attr
;
5310 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5311 struct cleanup
*back_to
;
5314 /* In this case dwarf2_compute_name is just a shortcut not building anything
5316 if (!die_needs_namespace (die
, cu
))
5317 return dwarf2_compute_name (name
, die
, cu
, 1);
5319 back_to
= make_cleanup (null_cleanup
, NULL
);
5321 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5323 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5325 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5327 if (attr
&& DW_STRING (attr
))
5331 mangled
= DW_STRING (attr
);
5333 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5334 type. It is easier for GDB users to search for such functions as
5335 `name(params)' than `long name(params)'. In such case the minimal
5336 symbol names do not match the full symbol names but for template
5337 functions there is never a need to look up their definition from their
5338 declaration so the only disadvantage remains the minimal symbol
5339 variant `long name(params)' does not have the proper inferior type.
5342 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5343 | (cu
->language
== language_java
5344 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5348 make_cleanup (xfree
, demangled
);
5358 if (canon
== NULL
|| check_physname
)
5360 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5362 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5364 /* It may not mean a bug in GDB. The compiler could also
5365 compute DW_AT_linkage_name incorrectly. But in such case
5366 GDB would need to be bug-to-bug compatible. */
5368 complaint (&symfile_complaints
,
5369 _("Computed physname <%s> does not match demangled <%s> "
5370 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5371 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5373 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5374 is available here - over computed PHYSNAME. It is safer
5375 against both buggy GDB and buggy compilers. */
5389 retval
= obsavestring (retval
, strlen (retval
),
5390 &cu
->objfile
->objfile_obstack
);
5392 do_cleanups (back_to
);
5396 /* Read the import statement specified by the given die and record it. */
5399 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5401 struct attribute
*import_attr
;
5402 struct die_info
*imported_die
, *child_die
;
5403 struct dwarf2_cu
*imported_cu
;
5404 const char *imported_name
;
5405 const char *imported_name_prefix
;
5406 const char *canonical_name
;
5407 const char *import_alias
;
5408 const char *imported_declaration
= NULL
;
5409 const char *import_prefix
;
5410 VEC (const_char_ptr
) *excludes
= NULL
;
5411 struct cleanup
*cleanups
;
5415 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5416 if (import_attr
== NULL
)
5418 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5419 dwarf_tag_name (die
->tag
));
5424 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5425 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5426 if (imported_name
== NULL
)
5428 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5430 The import in the following code:
5444 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5445 <52> DW_AT_decl_file : 1
5446 <53> DW_AT_decl_line : 6
5447 <54> DW_AT_import : <0x75>
5448 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5450 <5b> DW_AT_decl_file : 1
5451 <5c> DW_AT_decl_line : 2
5452 <5d> DW_AT_type : <0x6e>
5454 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5455 <76> DW_AT_byte_size : 4
5456 <77> DW_AT_encoding : 5 (signed)
5458 imports the wrong die ( 0x75 instead of 0x58 ).
5459 This case will be ignored until the gcc bug is fixed. */
5463 /* Figure out the local name after import. */
5464 import_alias
= dwarf2_name (die
, cu
);
5466 /* Figure out where the statement is being imported to. */
5467 import_prefix
= determine_prefix (die
, cu
);
5469 /* Figure out what the scope of the imported die is and prepend it
5470 to the name of the imported die. */
5471 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5473 if (imported_die
->tag
!= DW_TAG_namespace
5474 && imported_die
->tag
!= DW_TAG_module
)
5476 imported_declaration
= imported_name
;
5477 canonical_name
= imported_name_prefix
;
5479 else if (strlen (imported_name_prefix
) > 0)
5481 temp
= alloca (strlen (imported_name_prefix
)
5482 + 2 + strlen (imported_name
) + 1);
5483 strcpy (temp
, imported_name_prefix
);
5484 strcat (temp
, "::");
5485 strcat (temp
, imported_name
);
5486 canonical_name
= temp
;
5489 canonical_name
= imported_name
;
5491 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5493 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5494 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5495 child_die
= sibling_die (child_die
))
5497 /* DWARF-4: A Fortran use statement with a “rename list” may be
5498 represented by an imported module entry with an import attribute
5499 referring to the module and owned entries corresponding to those
5500 entities that are renamed as part of being imported. */
5502 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5504 complaint (&symfile_complaints
,
5505 _("child DW_TAG_imported_declaration expected "
5506 "- DIE at 0x%x [in module %s]"),
5507 child_die
->offset
, cu
->objfile
->name
);
5511 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5512 if (import_attr
== NULL
)
5514 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5515 dwarf_tag_name (child_die
->tag
));
5520 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5522 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5523 if (imported_name
== NULL
)
5525 complaint (&symfile_complaints
,
5526 _("child DW_TAG_imported_declaration has unknown "
5527 "imported name - DIE at 0x%x [in module %s]"),
5528 child_die
->offset
, cu
->objfile
->name
);
5532 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5534 process_die (child_die
, cu
);
5537 cp_add_using_directive (import_prefix
,
5540 imported_declaration
,
5542 &cu
->objfile
->objfile_obstack
);
5544 do_cleanups (cleanups
);
5548 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5550 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5553 /* Cleanup function for read_file_scope. */
5556 free_cu_line_header (void *arg
)
5558 struct dwarf2_cu
*cu
= arg
;
5560 free_line_header (cu
->line_header
);
5561 cu
->line_header
= NULL
;
5565 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5566 char **name
, char **comp_dir
)
5568 struct attribute
*attr
;
5573 /* Find the filename. Do not use dwarf2_name here, since the filename
5574 is not a source language identifier. */
5575 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5578 *name
= DW_STRING (attr
);
5581 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5583 *comp_dir
= DW_STRING (attr
);
5584 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5586 *comp_dir
= ldirname (*name
);
5587 if (*comp_dir
!= NULL
)
5588 make_cleanup (xfree
, *comp_dir
);
5590 if (*comp_dir
!= NULL
)
5592 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5593 directory, get rid of it. */
5594 char *cp
= strchr (*comp_dir
, ':');
5596 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5601 *name
= "<unknown>";
5604 /* Handle DW_AT_stmt_list for a compilation unit. */
5607 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5608 const char *comp_dir
)
5610 struct attribute
*attr
;
5611 struct objfile
*objfile
= cu
->objfile
;
5612 bfd
*abfd
= objfile
->obfd
;
5614 /* Decode line number information if present. We do this before
5615 processing child DIEs, so that the line header table is available
5616 for DW_AT_decl_file. */
5617 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5620 unsigned int line_offset
= DW_UNSND (attr
);
5621 struct line_header
*line_header
5622 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5626 cu
->line_header
= line_header
;
5627 make_cleanup (free_cu_line_header
, cu
);
5628 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5633 /* Process DW_TAG_compile_unit. */
5636 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5638 struct objfile
*objfile
= cu
->objfile
;
5639 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5640 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5641 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5642 struct attribute
*attr
;
5644 char *comp_dir
= NULL
;
5645 struct die_info
*child_die
;
5646 bfd
*abfd
= objfile
->obfd
;
5649 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5651 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5653 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5654 from finish_block. */
5655 if (lowpc
== ((CORE_ADDR
) -1))
5660 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5662 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5665 set_cu_language (DW_UNSND (attr
), cu
);
5668 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5670 cu
->producer
= DW_STRING (attr
);
5672 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5673 standardised yet. As a workaround for the language detection we fall
5674 back to the DW_AT_producer string. */
5675 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5676 cu
->language
= language_opencl
;
5678 /* We assume that we're processing GCC output. */
5679 processing_gcc_compilation
= 2;
5681 processing_has_namespace_info
= 0;
5683 start_symtab (name
, comp_dir
, lowpc
);
5684 record_debugformat ("DWARF 2");
5685 record_producer (cu
->producer
);
5687 initialize_cu_func_list (cu
);
5689 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5691 /* Process all dies in compilation unit. */
5692 if (die
->child
!= NULL
)
5694 child_die
= die
->child
;
5695 while (child_die
&& child_die
->tag
)
5697 process_die (child_die
, cu
);
5698 child_die
= sibling_die (child_die
);
5702 /* Decode macro information, if present. Dwarf 2 macro information
5703 refers to information in the line number info statement program
5704 header, so we can only read it if we've read the header
5706 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5707 if (attr
&& cu
->line_header
)
5709 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5710 complaint (&symfile_complaints
,
5711 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5713 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5715 &dwarf2_per_objfile
->macro
, 1);
5719 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5720 if (attr
&& cu
->line_header
)
5722 unsigned int macro_offset
= DW_UNSND (attr
);
5724 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5726 &dwarf2_per_objfile
->macinfo
, 0);
5729 do_cleanups (back_to
);
5732 /* Process DW_TAG_type_unit.
5733 For TUs we want to skip the first top level sibling if it's not the
5734 actual type being defined by this TU. In this case the first top
5735 level sibling is there to provide context only. */
5738 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5740 struct objfile
*objfile
= cu
->objfile
;
5741 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5743 struct attribute
*attr
;
5745 char *comp_dir
= NULL
;
5746 struct die_info
*child_die
;
5747 bfd
*abfd
= objfile
->obfd
;
5749 /* start_symtab needs a low pc, but we don't really have one.
5750 Do what read_file_scope would do in the absence of such info. */
5751 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5753 /* Find the filename. Do not use dwarf2_name here, since the filename
5754 is not a source language identifier. */
5755 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5757 name
= DW_STRING (attr
);
5759 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5761 comp_dir
= DW_STRING (attr
);
5762 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5764 comp_dir
= ldirname (name
);
5765 if (comp_dir
!= NULL
)
5766 make_cleanup (xfree
, comp_dir
);
5772 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5774 set_cu_language (DW_UNSND (attr
), cu
);
5776 /* This isn't technically needed today. It is done for symmetry
5777 with read_file_scope. */
5778 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5780 cu
->producer
= DW_STRING (attr
);
5782 /* We assume that we're processing GCC output. */
5783 processing_gcc_compilation
= 2;
5785 processing_has_namespace_info
= 0;
5787 start_symtab (name
, comp_dir
, lowpc
);
5788 record_debugformat ("DWARF 2");
5789 record_producer (cu
->producer
);
5791 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5793 /* Process the dies in the type unit. */
5794 if (die
->child
== NULL
)
5796 dump_die_for_error (die
);
5797 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5798 bfd_get_filename (abfd
));
5801 child_die
= die
->child
;
5803 while (child_die
&& child_die
->tag
)
5805 process_die (child_die
, cu
);
5807 child_die
= sibling_die (child_die
);
5810 do_cleanups (back_to
);
5814 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5815 struct dwarf2_cu
*cu
)
5817 struct function_range
*thisfn
;
5819 thisfn
= (struct function_range
*)
5820 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5821 thisfn
->name
= name
;
5822 thisfn
->lowpc
= lowpc
;
5823 thisfn
->highpc
= highpc
;
5824 thisfn
->seen_line
= 0;
5825 thisfn
->next
= NULL
;
5827 if (cu
->last_fn
== NULL
)
5828 cu
->first_fn
= thisfn
;
5830 cu
->last_fn
->next
= thisfn
;
5832 cu
->last_fn
= thisfn
;
5835 /* qsort helper for inherit_abstract_dies. */
5838 unsigned_int_compar (const void *ap
, const void *bp
)
5840 unsigned int a
= *(unsigned int *) ap
;
5841 unsigned int b
= *(unsigned int *) bp
;
5843 return (a
> b
) - (b
> a
);
5846 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5847 Inherit only the children of the DW_AT_abstract_origin DIE not being
5848 already referenced by DW_AT_abstract_origin from the children of the
5852 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5854 struct die_info
*child_die
;
5855 unsigned die_children_count
;
5856 /* CU offsets which were referenced by children of the current DIE. */
5858 unsigned *offsets_end
, *offsetp
;
5859 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5860 struct die_info
*origin_die
;
5861 /* Iterator of the ORIGIN_DIE children. */
5862 struct die_info
*origin_child_die
;
5863 struct cleanup
*cleanups
;
5864 struct attribute
*attr
;
5865 struct dwarf2_cu
*origin_cu
;
5866 struct pending
**origin_previous_list_in_scope
;
5868 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5872 /* Note that following die references may follow to a die in a
5876 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5878 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5880 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5881 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5883 if (die
->tag
!= origin_die
->tag
5884 && !(die
->tag
== DW_TAG_inlined_subroutine
5885 && origin_die
->tag
== DW_TAG_subprogram
))
5886 complaint (&symfile_complaints
,
5887 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5888 die
->offset
, origin_die
->offset
);
5890 child_die
= die
->child
;
5891 die_children_count
= 0;
5892 while (child_die
&& child_die
->tag
)
5894 child_die
= sibling_die (child_die
);
5895 die_children_count
++;
5897 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5898 cleanups
= make_cleanup (xfree
, offsets
);
5900 offsets_end
= offsets
;
5901 child_die
= die
->child
;
5902 while (child_die
&& child_die
->tag
)
5904 /* For each CHILD_DIE, find the corresponding child of
5905 ORIGIN_DIE. If there is more than one layer of
5906 DW_AT_abstract_origin, follow them all; there shouldn't be,
5907 but GCC versions at least through 4.4 generate this (GCC PR
5909 struct die_info
*child_origin_die
= child_die
;
5910 struct dwarf2_cu
*child_origin_cu
= cu
;
5914 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5918 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5922 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5923 counterpart may exist. */
5924 if (child_origin_die
!= child_die
)
5926 if (child_die
->tag
!= child_origin_die
->tag
5927 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5928 && child_origin_die
->tag
== DW_TAG_subprogram
))
5929 complaint (&symfile_complaints
,
5930 _("Child DIE 0x%x and its abstract origin 0x%x have "
5931 "different tags"), child_die
->offset
,
5932 child_origin_die
->offset
);
5933 if (child_origin_die
->parent
!= origin_die
)
5934 complaint (&symfile_complaints
,
5935 _("Child DIE 0x%x and its abstract origin 0x%x have "
5936 "different parents"), child_die
->offset
,
5937 child_origin_die
->offset
);
5939 *offsets_end
++ = child_origin_die
->offset
;
5941 child_die
= sibling_die (child_die
);
5943 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5944 unsigned_int_compar
);
5945 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5946 if (offsetp
[-1] == *offsetp
)
5947 complaint (&symfile_complaints
,
5948 _("Multiple children of DIE 0x%x refer "
5949 "to DIE 0x%x as their abstract origin"),
5950 die
->offset
, *offsetp
);
5953 origin_child_die
= origin_die
->child
;
5954 while (origin_child_die
&& origin_child_die
->tag
)
5956 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5957 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5959 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5961 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5962 process_die (origin_child_die
, origin_cu
);
5964 origin_child_die
= sibling_die (origin_child_die
);
5966 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5968 do_cleanups (cleanups
);
5972 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5974 struct objfile
*objfile
= cu
->objfile
;
5975 struct context_stack
*new;
5978 struct die_info
*child_die
;
5979 struct attribute
*attr
, *call_line
, *call_file
;
5982 struct block
*block
;
5983 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5984 VEC (symbolp
) *template_args
= NULL
;
5985 struct template_symbol
*templ_func
= NULL
;
5989 /* If we do not have call site information, we can't show the
5990 caller of this inlined function. That's too confusing, so
5991 only use the scope for local variables. */
5992 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5993 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5994 if (call_line
== NULL
|| call_file
== NULL
)
5996 read_lexical_block_scope (die
, cu
);
6001 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6003 name
= dwarf2_name (die
, cu
);
6005 /* Ignore functions with missing or empty names. These are actually
6006 illegal according to the DWARF standard. */
6009 complaint (&symfile_complaints
,
6010 _("missing name for subprogram DIE at %d"), die
->offset
);
6014 /* Ignore functions with missing or invalid low and high pc attributes. */
6015 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6017 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6018 if (!attr
|| !DW_UNSND (attr
))
6019 complaint (&symfile_complaints
,
6020 _("cannot get low and high bounds "
6021 "for subprogram DIE at %d"),
6029 /* Record the function range for dwarf_decode_lines. */
6030 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
6032 /* If we have any template arguments, then we must allocate a
6033 different sort of symbol. */
6034 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6036 if (child_die
->tag
== DW_TAG_template_type_param
6037 || child_die
->tag
== DW_TAG_template_value_param
)
6039 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6040 struct template_symbol
);
6041 templ_func
->base
.is_cplus_template_function
= 1;
6046 new = push_context (0, lowpc
);
6047 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6048 (struct symbol
*) templ_func
);
6050 /* If there is a location expression for DW_AT_frame_base, record
6052 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6054 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6055 expression is being recorded directly in the function's symbol
6056 and not in a separate frame-base object. I guess this hack is
6057 to avoid adding some sort of frame-base adjunct/annex to the
6058 function's symbol :-(. The problem with doing this is that it
6059 results in a function symbol with a location expression that
6060 has nothing to do with the location of the function, ouch! The
6061 relationship should be: a function's symbol has-a frame base; a
6062 frame-base has-a location expression. */
6063 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6065 cu
->list_in_scope
= &local_symbols
;
6067 if (die
->child
!= NULL
)
6069 child_die
= die
->child
;
6070 while (child_die
&& child_die
->tag
)
6072 if (child_die
->tag
== DW_TAG_template_type_param
6073 || child_die
->tag
== DW_TAG_template_value_param
)
6075 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6078 VEC_safe_push (symbolp
, template_args
, arg
);
6081 process_die (child_die
, cu
);
6082 child_die
= sibling_die (child_die
);
6086 inherit_abstract_dies (die
, cu
);
6088 /* If we have a DW_AT_specification, we might need to import using
6089 directives from the context of the specification DIE. See the
6090 comment in determine_prefix. */
6091 if (cu
->language
== language_cplus
6092 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6094 struct dwarf2_cu
*spec_cu
= cu
;
6095 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6099 child_die
= spec_die
->child
;
6100 while (child_die
&& child_die
->tag
)
6102 if (child_die
->tag
== DW_TAG_imported_module
)
6103 process_die (child_die
, spec_cu
);
6104 child_die
= sibling_die (child_die
);
6107 /* In some cases, GCC generates specification DIEs that
6108 themselves contain DW_AT_specification attributes. */
6109 spec_die
= die_specification (spec_die
, &spec_cu
);
6113 new = pop_context ();
6114 /* Make a block for the local symbols within. */
6115 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6116 lowpc
, highpc
, objfile
);
6118 /* For C++, set the block's scope. */
6119 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6120 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6121 determine_prefix (die
, cu
),
6122 processing_has_namespace_info
);
6124 /* If we have address ranges, record them. */
6125 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6127 /* Attach template arguments to function. */
6128 if (! VEC_empty (symbolp
, template_args
))
6130 gdb_assert (templ_func
!= NULL
);
6132 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6133 templ_func
->template_arguments
6134 = obstack_alloc (&objfile
->objfile_obstack
,
6135 (templ_func
->n_template_arguments
6136 * sizeof (struct symbol
*)));
6137 memcpy (templ_func
->template_arguments
,
6138 VEC_address (symbolp
, template_args
),
6139 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6140 VEC_free (symbolp
, template_args
);
6143 /* In C++, we can have functions nested inside functions (e.g., when
6144 a function declares a class that has methods). This means that
6145 when we finish processing a function scope, we may need to go
6146 back to building a containing block's symbol lists. */
6147 local_symbols
= new->locals
;
6148 param_symbols
= new->params
;
6149 using_directives
= new->using_directives
;
6151 /* If we've finished processing a top-level function, subsequent
6152 symbols go in the file symbol list. */
6153 if (outermost_context_p ())
6154 cu
->list_in_scope
= &file_symbols
;
6157 /* Process all the DIES contained within a lexical block scope. Start
6158 a new scope, process the dies, and then close the scope. */
6161 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6163 struct objfile
*objfile
= cu
->objfile
;
6164 struct context_stack
*new;
6165 CORE_ADDR lowpc
, highpc
;
6166 struct die_info
*child_die
;
6169 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6171 /* Ignore blocks with missing or invalid low and high pc attributes. */
6172 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6173 as multiple lexical blocks? Handling children in a sane way would
6174 be nasty. Might be easier to properly extend generic blocks to
6176 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6181 push_context (0, lowpc
);
6182 if (die
->child
!= NULL
)
6184 child_die
= die
->child
;
6185 while (child_die
&& child_die
->tag
)
6187 process_die (child_die
, cu
);
6188 child_die
= sibling_die (child_die
);
6191 new = pop_context ();
6193 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6196 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6199 /* Note that recording ranges after traversing children, as we
6200 do here, means that recording a parent's ranges entails
6201 walking across all its children's ranges as they appear in
6202 the address map, which is quadratic behavior.
6204 It would be nicer to record the parent's ranges before
6205 traversing its children, simply overriding whatever you find
6206 there. But since we don't even decide whether to create a
6207 block until after we've traversed its children, that's hard
6209 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6211 local_symbols
= new->locals
;
6212 using_directives
= new->using_directives
;
6215 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6218 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6220 struct objfile
*objfile
= cu
->objfile
;
6221 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6222 CORE_ADDR pc
, baseaddr
;
6223 struct attribute
*attr
;
6224 struct call_site
*call_site
, call_site_local
;
6227 struct die_info
*child_die
;
6229 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6231 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6234 complaint (&symfile_complaints
,
6235 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6236 "DIE 0x%x [in module %s]"),
6237 die
->offset
, cu
->objfile
->name
);
6240 pc
= DW_ADDR (attr
) + baseaddr
;
6242 if (cu
->call_site_htab
== NULL
)
6243 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6244 NULL
, &objfile
->objfile_obstack
,
6245 hashtab_obstack_allocate
, NULL
);
6246 call_site_local
.pc
= pc
;
6247 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6250 complaint (&symfile_complaints
,
6251 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6252 "DIE 0x%x [in module %s]"),
6253 paddress (gdbarch
, pc
), die
->offset
, cu
->objfile
->name
);
6257 /* Count parameters at the caller. */
6260 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6261 child_die
= sibling_die (child_die
))
6263 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6265 complaint (&symfile_complaints
,
6266 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6267 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6268 child_die
->tag
, child_die
->offset
, cu
->objfile
->name
);
6275 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6276 (sizeof (*call_site
)
6277 + (sizeof (*call_site
->parameter
)
6280 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6283 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6285 struct die_info
*func_die
;
6287 /* Skip also over DW_TAG_inlined_subroutine. */
6288 for (func_die
= die
->parent
;
6289 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6290 && func_die
->tag
!= DW_TAG_subroutine_type
;
6291 func_die
= func_die
->parent
);
6293 /* DW_AT_GNU_all_call_sites is a superset
6294 of DW_AT_GNU_all_tail_call_sites. */
6296 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6297 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6299 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6300 not complete. But keep CALL_SITE for look ups via call_site_htab,
6301 both the initial caller containing the real return address PC and
6302 the final callee containing the current PC of a chain of tail
6303 calls do not need to have the tail call list complete. But any
6304 function candidate for a virtual tail call frame searched via
6305 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6306 determined unambiguously. */
6310 struct type
*func_type
= NULL
;
6313 func_type
= get_die_type (func_die
, cu
);
6314 if (func_type
!= NULL
)
6316 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6318 /* Enlist this call site to the function. */
6319 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6320 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6323 complaint (&symfile_complaints
,
6324 _("Cannot find function owning DW_TAG_GNU_call_site "
6325 "DIE 0x%x [in module %s]"),
6326 die
->offset
, cu
->objfile
->name
);
6330 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6332 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6333 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6334 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6335 /* Keep NULL DWARF_BLOCK. */;
6336 else if (attr_form_is_block (attr
))
6338 struct dwarf2_locexpr_baton
*dlbaton
;
6340 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6341 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6342 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6343 dlbaton
->per_cu
= cu
->per_cu
;
6345 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6347 else if (is_ref_attr (attr
))
6349 struct objfile
*objfile
= cu
->objfile
;
6350 struct dwarf2_cu
*target_cu
= cu
;
6351 struct die_info
*target_die
;
6353 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6354 gdb_assert (target_cu
->objfile
== objfile
);
6355 if (die_is_declaration (target_die
, target_cu
))
6357 const char *target_physname
;
6359 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6360 if (target_physname
== NULL
)
6361 complaint (&symfile_complaints
,
6362 _("DW_AT_GNU_call_site_target target DIE has invalid "
6363 "physname, for referencing DIE 0x%x [in module %s]"),
6364 die
->offset
, cu
->objfile
->name
);
6366 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6372 /* DW_AT_entry_pc should be preferred. */
6373 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6374 complaint (&symfile_complaints
,
6375 _("DW_AT_GNU_call_site_target target DIE has invalid "
6376 "low pc, for referencing DIE 0x%x [in module %s]"),
6377 die
->offset
, cu
->objfile
->name
);
6379 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6383 complaint (&symfile_complaints
,
6384 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6385 "block nor reference, for DIE 0x%x [in module %s]"),
6386 die
->offset
, cu
->objfile
->name
);
6388 call_site
->per_cu
= cu
->per_cu
;
6390 for (child_die
= die
->child
;
6391 child_die
&& child_die
->tag
;
6392 child_die
= sibling_die (child_die
))
6394 struct dwarf2_locexpr_baton
*dlbaton
;
6395 struct call_site_parameter
*parameter
;
6397 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6399 /* Already printed the complaint above. */
6403 gdb_assert (call_site
->parameter_count
< nparams
);
6404 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6406 /* DW_AT_location specifies the register number. Value of the data
6407 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6409 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6410 if (!attr
|| !attr_form_is_block (attr
))
6412 complaint (&symfile_complaints
,
6413 _("No DW_FORM_block* DW_AT_location for "
6414 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6415 child_die
->offset
, cu
->objfile
->name
);
6418 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6419 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6420 if (parameter
->dwarf_reg
== -1
6421 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6422 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6423 ¶meter
->fb_offset
))
6425 complaint (&symfile_complaints
,
6426 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6427 "for DW_FORM_block* DW_AT_location for "
6428 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6429 child_die
->offset
, cu
->objfile
->name
);
6433 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6434 if (!attr_form_is_block (attr
))
6436 complaint (&symfile_complaints
,
6437 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6438 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6439 child_die
->offset
, cu
->objfile
->name
);
6442 parameter
->value
= DW_BLOCK (attr
)->data
;
6443 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6445 /* Parameters are not pre-cleared by memset above. */
6446 parameter
->data_value
= NULL
;
6447 parameter
->data_value_size
= 0;
6448 call_site
->parameter_count
++;
6450 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6453 if (!attr_form_is_block (attr
))
6454 complaint (&symfile_complaints
,
6455 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6456 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6457 child_die
->offset
, cu
->objfile
->name
);
6460 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6461 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6467 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6468 Return 1 if the attributes are present and valid, otherwise, return 0.
6469 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6472 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6473 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6474 struct partial_symtab
*ranges_pst
)
6476 struct objfile
*objfile
= cu
->objfile
;
6477 struct comp_unit_head
*cu_header
= &cu
->header
;
6478 bfd
*obfd
= objfile
->obfd
;
6479 unsigned int addr_size
= cu_header
->addr_size
;
6480 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6481 /* Base address selection entry. */
6492 found_base
= cu
->base_known
;
6493 base
= cu
->base_address
;
6495 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6496 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6498 complaint (&symfile_complaints
,
6499 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6503 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6505 /* Read in the largest possible address. */
6506 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6507 if ((marker
& mask
) == mask
)
6509 /* If we found the largest possible address, then
6510 read the base address. */
6511 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6512 buffer
+= 2 * addr_size
;
6513 offset
+= 2 * addr_size
;
6519 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6523 CORE_ADDR range_beginning
, range_end
;
6525 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6526 buffer
+= addr_size
;
6527 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6528 buffer
+= addr_size
;
6529 offset
+= 2 * addr_size
;
6531 /* An end of list marker is a pair of zero addresses. */
6532 if (range_beginning
== 0 && range_end
== 0)
6533 /* Found the end of list entry. */
6536 /* Each base address selection entry is a pair of 2 values.
6537 The first is the largest possible address, the second is
6538 the base address. Check for a base address here. */
6539 if ((range_beginning
& mask
) == mask
)
6541 /* If we found the largest possible address, then
6542 read the base address. */
6543 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6550 /* We have no valid base address for the ranges
6552 complaint (&symfile_complaints
,
6553 _("Invalid .debug_ranges data (no base address)"));
6557 if (range_beginning
> range_end
)
6559 /* Inverted range entries are invalid. */
6560 complaint (&symfile_complaints
,
6561 _("Invalid .debug_ranges data (inverted range)"));
6565 /* Empty range entries have no effect. */
6566 if (range_beginning
== range_end
)
6569 range_beginning
+= base
;
6572 if (ranges_pst
!= NULL
)
6573 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6574 range_beginning
+ baseaddr
,
6575 range_end
- 1 + baseaddr
,
6578 /* FIXME: This is recording everything as a low-high
6579 segment of consecutive addresses. We should have a
6580 data structure for discontiguous block ranges
6584 low
= range_beginning
;
6590 if (range_beginning
< low
)
6591 low
= range_beginning
;
6592 if (range_end
> high
)
6598 /* If the first entry is an end-of-list marker, the range
6599 describes an empty scope, i.e. no instructions. */
6605 *high_return
= high
;
6609 /* Get low and high pc attributes from a die. Return 1 if the attributes
6610 are present and valid, otherwise, return 0. Return -1 if the range is
6611 discontinuous, i.e. derived from DW_AT_ranges information. */
6613 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6614 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6615 struct partial_symtab
*pst
)
6617 struct attribute
*attr
;
6622 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6625 high
= DW_ADDR (attr
);
6626 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6628 low
= DW_ADDR (attr
);
6630 /* Found high w/o low attribute. */
6633 /* Found consecutive range of addresses. */
6638 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6641 /* Value of the DW_AT_ranges attribute is the offset in the
6642 .debug_ranges section. */
6643 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6645 /* Found discontinuous range of addresses. */
6650 /* read_partial_die has also the strict LOW < HIGH requirement. */
6654 /* When using the GNU linker, .gnu.linkonce. sections are used to
6655 eliminate duplicate copies of functions and vtables and such.
6656 The linker will arbitrarily choose one and discard the others.
6657 The AT_*_pc values for such functions refer to local labels in
6658 these sections. If the section from that file was discarded, the
6659 labels are not in the output, so the relocs get a value of 0.
6660 If this is a discarded function, mark the pc bounds as invalid,
6661 so that GDB will ignore it. */
6662 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6671 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6672 its low and high PC addresses. Do nothing if these addresses could not
6673 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6674 and HIGHPC to the high address if greater than HIGHPC. */
6677 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6678 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6679 struct dwarf2_cu
*cu
)
6681 CORE_ADDR low
, high
;
6682 struct die_info
*child
= die
->child
;
6684 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6686 *lowpc
= min (*lowpc
, low
);
6687 *highpc
= max (*highpc
, high
);
6690 /* If the language does not allow nested subprograms (either inside
6691 subprograms or lexical blocks), we're done. */
6692 if (cu
->language
!= language_ada
)
6695 /* Check all the children of the given DIE. If it contains nested
6696 subprograms, then check their pc bounds. Likewise, we need to
6697 check lexical blocks as well, as they may also contain subprogram
6699 while (child
&& child
->tag
)
6701 if (child
->tag
== DW_TAG_subprogram
6702 || child
->tag
== DW_TAG_lexical_block
)
6703 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6704 child
= sibling_die (child
);
6708 /* Get the low and high pc's represented by the scope DIE, and store
6709 them in *LOWPC and *HIGHPC. If the correct values can't be
6710 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6713 get_scope_pc_bounds (struct die_info
*die
,
6714 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6715 struct dwarf2_cu
*cu
)
6717 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6718 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6719 CORE_ADDR current_low
, current_high
;
6721 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6723 best_low
= current_low
;
6724 best_high
= current_high
;
6728 struct die_info
*child
= die
->child
;
6730 while (child
&& child
->tag
)
6732 switch (child
->tag
) {
6733 case DW_TAG_subprogram
:
6734 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6736 case DW_TAG_namespace
:
6738 /* FIXME: carlton/2004-01-16: Should we do this for
6739 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6740 that current GCC's always emit the DIEs corresponding
6741 to definitions of methods of classes as children of a
6742 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6743 the DIEs giving the declarations, which could be
6744 anywhere). But I don't see any reason why the
6745 standards says that they have to be there. */
6746 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6748 if (current_low
!= ((CORE_ADDR
) -1))
6750 best_low
= min (best_low
, current_low
);
6751 best_high
= max (best_high
, current_high
);
6759 child
= sibling_die (child
);
6764 *highpc
= best_high
;
6767 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6770 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6771 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6773 struct attribute
*attr
;
6775 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6778 CORE_ADDR high
= DW_ADDR (attr
);
6780 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6783 CORE_ADDR low
= DW_ADDR (attr
);
6785 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6789 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6792 bfd
*obfd
= cu
->objfile
->obfd
;
6794 /* The value of the DW_AT_ranges attribute is the offset of the
6795 address range list in the .debug_ranges section. */
6796 unsigned long offset
= DW_UNSND (attr
);
6797 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6799 /* For some target architectures, but not others, the
6800 read_address function sign-extends the addresses it returns.
6801 To recognize base address selection entries, we need a
6803 unsigned int addr_size
= cu
->header
.addr_size
;
6804 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6806 /* The base address, to which the next pair is relative. Note
6807 that this 'base' is a DWARF concept: most entries in a range
6808 list are relative, to reduce the number of relocs against the
6809 debugging information. This is separate from this function's
6810 'baseaddr' argument, which GDB uses to relocate debugging
6811 information from a shared library based on the address at
6812 which the library was loaded. */
6813 CORE_ADDR base
= cu
->base_address
;
6814 int base_known
= cu
->base_known
;
6816 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6817 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6819 complaint (&symfile_complaints
,
6820 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6827 unsigned int bytes_read
;
6828 CORE_ADDR start
, end
;
6830 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6831 buffer
+= bytes_read
;
6832 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6833 buffer
+= bytes_read
;
6835 /* Did we find the end of the range list? */
6836 if (start
== 0 && end
== 0)
6839 /* Did we find a base address selection entry? */
6840 else if ((start
& base_select_mask
) == base_select_mask
)
6846 /* We found an ordinary address range. */
6851 complaint (&symfile_complaints
,
6852 _("Invalid .debug_ranges data "
6853 "(no base address)"));
6859 /* Inverted range entries are invalid. */
6860 complaint (&symfile_complaints
,
6861 _("Invalid .debug_ranges data "
6862 "(inverted range)"));
6866 /* Empty range entries have no effect. */
6870 record_block_range (block
,
6871 baseaddr
+ base
+ start
,
6872 baseaddr
+ base
+ end
- 1);
6878 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6879 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6880 during 4.6.0 experimental. */
6883 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6886 int major
, minor
, release
;
6888 if (cu
->producer
== NULL
)
6890 /* For unknown compilers expect their behavior is DWARF version
6893 GCC started to support .debug_types sections by -gdwarf-4 since
6894 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6895 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6896 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6897 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6902 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6904 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6906 /* For non-GCC compilers expect their behavior is DWARF version
6911 cs
= &cu
->producer
[strlen ("GNU ")];
6912 while (*cs
&& !isdigit (*cs
))
6914 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6916 /* Not recognized as GCC. */
6921 return major
< 4 || (major
== 4 && minor
< 6);
6924 /* Return the default accessibility type if it is not overriden by
6925 DW_AT_accessibility. */
6927 static enum dwarf_access_attribute
6928 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6930 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6932 /* The default DWARF 2 accessibility for members is public, the default
6933 accessibility for inheritance is private. */
6935 if (die
->tag
!= DW_TAG_inheritance
)
6936 return DW_ACCESS_public
;
6938 return DW_ACCESS_private
;
6942 /* DWARF 3+ defines the default accessibility a different way. The same
6943 rules apply now for DW_TAG_inheritance as for the members and it only
6944 depends on the container kind. */
6946 if (die
->parent
->tag
== DW_TAG_class_type
)
6947 return DW_ACCESS_private
;
6949 return DW_ACCESS_public
;
6953 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6954 offset. If the attribute was not found return 0, otherwise return
6955 1. If it was found but could not properly be handled, set *OFFSET
6959 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6962 struct attribute
*attr
;
6964 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6969 /* Note that we do not check for a section offset first here.
6970 This is because DW_AT_data_member_location is new in DWARF 4,
6971 so if we see it, we can assume that a constant form is really
6972 a constant and not a section offset. */
6973 if (attr_form_is_constant (attr
))
6974 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6975 else if (attr_form_is_section_offset (attr
))
6976 dwarf2_complex_location_expr_complaint ();
6977 else if (attr_form_is_block (attr
))
6978 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6980 dwarf2_complex_location_expr_complaint ();
6988 /* Add an aggregate field to the field list. */
6991 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6992 struct dwarf2_cu
*cu
)
6994 struct objfile
*objfile
= cu
->objfile
;
6995 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6996 struct nextfield
*new_field
;
6997 struct attribute
*attr
;
6999 char *fieldname
= "";
7001 /* Allocate a new field list entry and link it in. */
7002 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7003 make_cleanup (xfree
, new_field
);
7004 memset (new_field
, 0, sizeof (struct nextfield
));
7006 if (die
->tag
== DW_TAG_inheritance
)
7008 new_field
->next
= fip
->baseclasses
;
7009 fip
->baseclasses
= new_field
;
7013 new_field
->next
= fip
->fields
;
7014 fip
->fields
= new_field
;
7018 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7020 new_field
->accessibility
= DW_UNSND (attr
);
7022 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7023 if (new_field
->accessibility
!= DW_ACCESS_public
)
7024 fip
->non_public_fields
= 1;
7026 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7028 new_field
->virtuality
= DW_UNSND (attr
);
7030 new_field
->virtuality
= DW_VIRTUALITY_none
;
7032 fp
= &new_field
->field
;
7034 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7038 /* Data member other than a C++ static data member. */
7040 /* Get type of field. */
7041 fp
->type
= die_type (die
, cu
);
7043 SET_FIELD_BITPOS (*fp
, 0);
7045 /* Get bit size of field (zero if none). */
7046 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7049 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7053 FIELD_BITSIZE (*fp
) = 0;
7056 /* Get bit offset of field. */
7057 if (handle_data_member_location (die
, cu
, &offset
))
7058 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7059 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7062 if (gdbarch_bits_big_endian (gdbarch
))
7064 /* For big endian bits, the DW_AT_bit_offset gives the
7065 additional bit offset from the MSB of the containing
7066 anonymous object to the MSB of the field. We don't
7067 have to do anything special since we don't need to
7068 know the size of the anonymous object. */
7069 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7073 /* For little endian bits, compute the bit offset to the
7074 MSB of the anonymous object, subtract off the number of
7075 bits from the MSB of the field to the MSB of the
7076 object, and then subtract off the number of bits of
7077 the field itself. The result is the bit offset of
7078 the LSB of the field. */
7080 int bit_offset
= DW_UNSND (attr
);
7082 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7085 /* The size of the anonymous object containing
7086 the bit field is explicit, so use the
7087 indicated size (in bytes). */
7088 anonymous_size
= DW_UNSND (attr
);
7092 /* The size of the anonymous object containing
7093 the bit field must be inferred from the type
7094 attribute of the data member containing the
7096 anonymous_size
= TYPE_LENGTH (fp
->type
);
7098 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7099 - bit_offset
- FIELD_BITSIZE (*fp
);
7103 /* Get name of field. */
7104 fieldname
= dwarf2_name (die
, cu
);
7105 if (fieldname
== NULL
)
7108 /* The name is already allocated along with this objfile, so we don't
7109 need to duplicate it for the type. */
7110 fp
->name
= fieldname
;
7112 /* Change accessibility for artificial fields (e.g. virtual table
7113 pointer or virtual base class pointer) to private. */
7114 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7116 FIELD_ARTIFICIAL (*fp
) = 1;
7117 new_field
->accessibility
= DW_ACCESS_private
;
7118 fip
->non_public_fields
= 1;
7121 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7123 /* C++ static member. */
7125 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7126 is a declaration, but all versions of G++ as of this writing
7127 (so through at least 3.2.1) incorrectly generate
7128 DW_TAG_variable tags. */
7130 const char *physname
;
7132 /* Get name of field. */
7133 fieldname
= dwarf2_name (die
, cu
);
7134 if (fieldname
== NULL
)
7137 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7139 /* Only create a symbol if this is an external value.
7140 new_symbol checks this and puts the value in the global symbol
7141 table, which we want. If it is not external, new_symbol
7142 will try to put the value in cu->list_in_scope which is wrong. */
7143 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7145 /* A static const member, not much different than an enum as far as
7146 we're concerned, except that we can support more types. */
7147 new_symbol (die
, NULL
, cu
);
7150 /* Get physical name. */
7151 physname
= dwarf2_physname (fieldname
, die
, cu
);
7153 /* The name is already allocated along with this objfile, so we don't
7154 need to duplicate it for the type. */
7155 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7156 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7157 FIELD_NAME (*fp
) = fieldname
;
7159 else if (die
->tag
== DW_TAG_inheritance
)
7163 /* C++ base class field. */
7164 if (handle_data_member_location (die
, cu
, &offset
))
7165 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7166 FIELD_BITSIZE (*fp
) = 0;
7167 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7168 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7169 fip
->nbaseclasses
++;
7173 /* Add a typedef defined in the scope of the FIP's class. */
7176 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7177 struct dwarf2_cu
*cu
)
7179 struct objfile
*objfile
= cu
->objfile
;
7180 struct typedef_field_list
*new_field
;
7181 struct attribute
*attr
;
7182 struct typedef_field
*fp
;
7183 char *fieldname
= "";
7185 /* Allocate a new field list entry and link it in. */
7186 new_field
= xzalloc (sizeof (*new_field
));
7187 make_cleanup (xfree
, new_field
);
7189 gdb_assert (die
->tag
== DW_TAG_typedef
);
7191 fp
= &new_field
->field
;
7193 /* Get name of field. */
7194 fp
->name
= dwarf2_name (die
, cu
);
7195 if (fp
->name
== NULL
)
7198 fp
->type
= read_type_die (die
, cu
);
7200 new_field
->next
= fip
->typedef_field_list
;
7201 fip
->typedef_field_list
= new_field
;
7202 fip
->typedef_field_list_count
++;
7205 /* Create the vector of fields, and attach it to the type. */
7208 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7209 struct dwarf2_cu
*cu
)
7211 int nfields
= fip
->nfields
;
7213 /* Record the field count, allocate space for the array of fields,
7214 and create blank accessibility bitfields if necessary. */
7215 TYPE_NFIELDS (type
) = nfields
;
7216 TYPE_FIELDS (type
) = (struct field
*)
7217 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7218 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7220 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7222 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7224 TYPE_FIELD_PRIVATE_BITS (type
) =
7225 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7226 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7228 TYPE_FIELD_PROTECTED_BITS (type
) =
7229 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7230 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7232 TYPE_FIELD_IGNORE_BITS (type
) =
7233 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7234 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7237 /* If the type has baseclasses, allocate and clear a bit vector for
7238 TYPE_FIELD_VIRTUAL_BITS. */
7239 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7241 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7242 unsigned char *pointer
;
7244 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7245 pointer
= TYPE_ALLOC (type
, num_bytes
);
7246 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7247 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7248 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7251 /* Copy the saved-up fields into the field vector. Start from the head of
7252 the list, adding to the tail of the field array, so that they end up in
7253 the same order in the array in which they were added to the list. */
7254 while (nfields
-- > 0)
7256 struct nextfield
*fieldp
;
7260 fieldp
= fip
->fields
;
7261 fip
->fields
= fieldp
->next
;
7265 fieldp
= fip
->baseclasses
;
7266 fip
->baseclasses
= fieldp
->next
;
7269 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7270 switch (fieldp
->accessibility
)
7272 case DW_ACCESS_private
:
7273 if (cu
->language
!= language_ada
)
7274 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7277 case DW_ACCESS_protected
:
7278 if (cu
->language
!= language_ada
)
7279 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7282 case DW_ACCESS_public
:
7286 /* Unknown accessibility. Complain and treat it as public. */
7288 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7289 fieldp
->accessibility
);
7293 if (nfields
< fip
->nbaseclasses
)
7295 switch (fieldp
->virtuality
)
7297 case DW_VIRTUALITY_virtual
:
7298 case DW_VIRTUALITY_pure_virtual
:
7299 if (cu
->language
== language_ada
)
7300 error (_("unexpected virtuality in component of Ada type"));
7301 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7308 /* Add a member function to the proper fieldlist. */
7311 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7312 struct type
*type
, struct dwarf2_cu
*cu
)
7314 struct objfile
*objfile
= cu
->objfile
;
7315 struct attribute
*attr
;
7316 struct fnfieldlist
*flp
;
7318 struct fn_field
*fnp
;
7320 struct nextfnfield
*new_fnfield
;
7321 struct type
*this_type
;
7322 enum dwarf_access_attribute accessibility
;
7324 if (cu
->language
== language_ada
)
7325 error (_("unexpected member function in Ada type"));
7327 /* Get name of member function. */
7328 fieldname
= dwarf2_name (die
, cu
);
7329 if (fieldname
== NULL
)
7332 /* Look up member function name in fieldlist. */
7333 for (i
= 0; i
< fip
->nfnfields
; i
++)
7335 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7339 /* Create new list element if necessary. */
7340 if (i
< fip
->nfnfields
)
7341 flp
= &fip
->fnfieldlists
[i
];
7344 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7346 fip
->fnfieldlists
= (struct fnfieldlist
*)
7347 xrealloc (fip
->fnfieldlists
,
7348 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7349 * sizeof (struct fnfieldlist
));
7350 if (fip
->nfnfields
== 0)
7351 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7353 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7354 flp
->name
= fieldname
;
7357 i
= fip
->nfnfields
++;
7360 /* Create a new member function field and chain it to the field list
7362 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7363 make_cleanup (xfree
, new_fnfield
);
7364 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7365 new_fnfield
->next
= flp
->head
;
7366 flp
->head
= new_fnfield
;
7369 /* Fill in the member function field info. */
7370 fnp
= &new_fnfield
->fnfield
;
7372 /* Delay processing of the physname until later. */
7373 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7375 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7380 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7381 fnp
->physname
= physname
? physname
: "";
7384 fnp
->type
= alloc_type (objfile
);
7385 this_type
= read_type_die (die
, cu
);
7386 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7388 int nparams
= TYPE_NFIELDS (this_type
);
7390 /* TYPE is the domain of this method, and THIS_TYPE is the type
7391 of the method itself (TYPE_CODE_METHOD). */
7392 smash_to_method_type (fnp
->type
, type
,
7393 TYPE_TARGET_TYPE (this_type
),
7394 TYPE_FIELDS (this_type
),
7395 TYPE_NFIELDS (this_type
),
7396 TYPE_VARARGS (this_type
));
7398 /* Handle static member functions.
7399 Dwarf2 has no clean way to discern C++ static and non-static
7400 member functions. G++ helps GDB by marking the first
7401 parameter for non-static member functions (which is the this
7402 pointer) as artificial. We obtain this information from
7403 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7404 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7405 fnp
->voffset
= VOFFSET_STATIC
;
7408 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7409 dwarf2_full_name (fieldname
, die
, cu
));
7411 /* Get fcontext from DW_AT_containing_type if present. */
7412 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7413 fnp
->fcontext
= die_containing_type (die
, cu
);
7415 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7416 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7418 /* Get accessibility. */
7419 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7421 accessibility
= DW_UNSND (attr
);
7423 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7424 switch (accessibility
)
7426 case DW_ACCESS_private
:
7427 fnp
->is_private
= 1;
7429 case DW_ACCESS_protected
:
7430 fnp
->is_protected
= 1;
7434 /* Check for artificial methods. */
7435 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7436 if (attr
&& DW_UNSND (attr
) != 0)
7437 fnp
->is_artificial
= 1;
7439 /* Get index in virtual function table if it is a virtual member
7440 function. For older versions of GCC, this is an offset in the
7441 appropriate virtual table, as specified by DW_AT_containing_type.
7442 For everyone else, it is an expression to be evaluated relative
7443 to the object address. */
7445 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7448 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7450 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7452 /* Old-style GCC. */
7453 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7455 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7456 || (DW_BLOCK (attr
)->size
> 1
7457 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7458 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7460 struct dwarf_block blk
;
7463 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7465 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7466 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7467 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7468 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7469 dwarf2_complex_location_expr_complaint ();
7471 fnp
->voffset
/= cu
->header
.addr_size
;
7475 dwarf2_complex_location_expr_complaint ();
7478 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7480 else if (attr_form_is_section_offset (attr
))
7482 dwarf2_complex_location_expr_complaint ();
7486 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7492 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7493 if (attr
&& DW_UNSND (attr
))
7495 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7496 complaint (&symfile_complaints
,
7497 _("Member function \"%s\" (offset %d) is virtual "
7498 "but the vtable offset is not specified"),
7499 fieldname
, die
->offset
);
7500 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7501 TYPE_CPLUS_DYNAMIC (type
) = 1;
7506 /* Create the vector of member function fields, and attach it to the type. */
7509 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7510 struct dwarf2_cu
*cu
)
7512 struct fnfieldlist
*flp
;
7513 int total_length
= 0;
7516 if (cu
->language
== language_ada
)
7517 error (_("unexpected member functions in Ada type"));
7519 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7520 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7521 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7523 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7525 struct nextfnfield
*nfp
= flp
->head
;
7526 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7529 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7530 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7531 fn_flp
->fn_fields
= (struct fn_field
*)
7532 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7533 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7534 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7536 total_length
+= flp
->length
;
7539 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7540 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7543 /* Returns non-zero if NAME is the name of a vtable member in CU's
7544 language, zero otherwise. */
7546 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7548 static const char vptr
[] = "_vptr";
7549 static const char vtable
[] = "vtable";
7551 /* Look for the C++ and Java forms of the vtable. */
7552 if ((cu
->language
== language_java
7553 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7554 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7555 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7561 /* GCC outputs unnamed structures that are really pointers to member
7562 functions, with the ABI-specified layout. If TYPE describes
7563 such a structure, smash it into a member function type.
7565 GCC shouldn't do this; it should just output pointer to member DIEs.
7566 This is GCC PR debug/28767. */
7569 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7571 struct type
*pfn_type
, *domain_type
, *new_type
;
7573 /* Check for a structure with no name and two children. */
7574 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7577 /* Check for __pfn and __delta members. */
7578 if (TYPE_FIELD_NAME (type
, 0) == NULL
7579 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7580 || TYPE_FIELD_NAME (type
, 1) == NULL
7581 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7584 /* Find the type of the method. */
7585 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7586 if (pfn_type
== NULL
7587 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7588 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7591 /* Look for the "this" argument. */
7592 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7593 if (TYPE_NFIELDS (pfn_type
) == 0
7594 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7595 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7598 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7599 new_type
= alloc_type (objfile
);
7600 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7601 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7602 TYPE_VARARGS (pfn_type
));
7603 smash_to_methodptr_type (type
, new_type
);
7606 /* Called when we find the DIE that starts a structure or union scope
7607 (definition) to create a type for the structure or union. Fill in
7608 the type's name and general properties; the members will not be
7609 processed until process_structure_type.
7611 NOTE: we need to call these functions regardless of whether or not the
7612 DIE has a DW_AT_name attribute, since it might be an anonymous
7613 structure or union. This gets the type entered into our set of
7616 However, if the structure is incomplete (an opaque struct/union)
7617 then suppress creating a symbol table entry for it since gdb only
7618 wants to find the one with the complete definition. Note that if
7619 it is complete, we just call new_symbol, which does it's own
7620 checking about whether the struct/union is anonymous or not (and
7621 suppresses creating a symbol table entry itself). */
7623 static struct type
*
7624 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7626 struct objfile
*objfile
= cu
->objfile
;
7628 struct attribute
*attr
;
7631 /* If the definition of this type lives in .debug_types, read that type.
7632 Don't follow DW_AT_specification though, that will take us back up
7633 the chain and we want to go down. */
7634 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7637 struct dwarf2_cu
*type_cu
= cu
;
7638 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7640 /* We could just recurse on read_structure_type, but we need to call
7641 get_die_type to ensure only one type for this DIE is created.
7642 This is important, for example, because for c++ classes we need
7643 TYPE_NAME set which is only done by new_symbol. Blech. */
7644 type
= read_type_die (type_die
, type_cu
);
7646 /* TYPE_CU may not be the same as CU.
7647 Ensure TYPE is recorded in CU's type_hash table. */
7648 return set_die_type (die
, type
, cu
);
7651 type
= alloc_type (objfile
);
7652 INIT_CPLUS_SPECIFIC (type
);
7654 name
= dwarf2_name (die
, cu
);
7657 if (cu
->language
== language_cplus
7658 || cu
->language
== language_java
)
7660 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7662 /* dwarf2_full_name might have already finished building the DIE's
7663 type. If so, there is no need to continue. */
7664 if (get_die_type (die
, cu
) != NULL
)
7665 return get_die_type (die
, cu
);
7667 TYPE_TAG_NAME (type
) = full_name
;
7668 if (die
->tag
== DW_TAG_structure_type
7669 || die
->tag
== DW_TAG_class_type
)
7670 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7674 /* The name is already allocated along with this objfile, so
7675 we don't need to duplicate it for the type. */
7676 TYPE_TAG_NAME (type
) = (char *) name
;
7677 if (die
->tag
== DW_TAG_class_type
)
7678 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7682 if (die
->tag
== DW_TAG_structure_type
)
7684 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7686 else if (die
->tag
== DW_TAG_union_type
)
7688 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7692 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7695 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7696 TYPE_DECLARED_CLASS (type
) = 1;
7698 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7701 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7705 TYPE_LENGTH (type
) = 0;
7708 TYPE_STUB_SUPPORTED (type
) = 1;
7709 if (die_is_declaration (die
, cu
))
7710 TYPE_STUB (type
) = 1;
7711 else if (attr
== NULL
&& die
->child
== NULL
7712 && producer_is_realview (cu
->producer
))
7713 /* RealView does not output the required DW_AT_declaration
7714 on incomplete types. */
7715 TYPE_STUB (type
) = 1;
7717 /* We need to add the type field to the die immediately so we don't
7718 infinitely recurse when dealing with pointers to the structure
7719 type within the structure itself. */
7720 set_die_type (die
, type
, cu
);
7722 /* set_die_type should be already done. */
7723 set_descriptive_type (type
, die
, cu
);
7728 /* Finish creating a structure or union type, including filling in
7729 its members and creating a symbol for it. */
7732 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7734 struct objfile
*objfile
= cu
->objfile
;
7735 struct die_info
*child_die
= die
->child
;
7738 type
= get_die_type (die
, cu
);
7740 type
= read_structure_type (die
, cu
);
7742 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7744 struct field_info fi
;
7745 struct die_info
*child_die
;
7746 VEC (symbolp
) *template_args
= NULL
;
7747 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7749 memset (&fi
, 0, sizeof (struct field_info
));
7751 child_die
= die
->child
;
7753 while (child_die
&& child_die
->tag
)
7755 if (child_die
->tag
== DW_TAG_member
7756 || child_die
->tag
== DW_TAG_variable
)
7758 /* NOTE: carlton/2002-11-05: A C++ static data member
7759 should be a DW_TAG_member that is a declaration, but
7760 all versions of G++ as of this writing (so through at
7761 least 3.2.1) incorrectly generate DW_TAG_variable
7762 tags for them instead. */
7763 dwarf2_add_field (&fi
, child_die
, cu
);
7765 else if (child_die
->tag
== DW_TAG_subprogram
)
7767 /* C++ member function. */
7768 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7770 else if (child_die
->tag
== DW_TAG_inheritance
)
7772 /* C++ base class field. */
7773 dwarf2_add_field (&fi
, child_die
, cu
);
7775 else if (child_die
->tag
== DW_TAG_typedef
)
7776 dwarf2_add_typedef (&fi
, child_die
, cu
);
7777 else if (child_die
->tag
== DW_TAG_template_type_param
7778 || child_die
->tag
== DW_TAG_template_value_param
)
7780 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7783 VEC_safe_push (symbolp
, template_args
, arg
);
7786 child_die
= sibling_die (child_die
);
7789 /* Attach template arguments to type. */
7790 if (! VEC_empty (symbolp
, template_args
))
7792 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7793 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7794 = VEC_length (symbolp
, template_args
);
7795 TYPE_TEMPLATE_ARGUMENTS (type
)
7796 = obstack_alloc (&objfile
->objfile_obstack
,
7797 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7798 * sizeof (struct symbol
*)));
7799 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7800 VEC_address (symbolp
, template_args
),
7801 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7802 * sizeof (struct symbol
*)));
7803 VEC_free (symbolp
, template_args
);
7806 /* Attach fields and member functions to the type. */
7808 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7811 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7813 /* Get the type which refers to the base class (possibly this
7814 class itself) which contains the vtable pointer for the current
7815 class from the DW_AT_containing_type attribute. This use of
7816 DW_AT_containing_type is a GNU extension. */
7818 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7820 struct type
*t
= die_containing_type (die
, cu
);
7822 TYPE_VPTR_BASETYPE (type
) = t
;
7827 /* Our own class provides vtbl ptr. */
7828 for (i
= TYPE_NFIELDS (t
) - 1;
7829 i
>= TYPE_N_BASECLASSES (t
);
7832 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7834 if (is_vtable_name (fieldname
, cu
))
7836 TYPE_VPTR_FIELDNO (type
) = i
;
7841 /* Complain if virtual function table field not found. */
7842 if (i
< TYPE_N_BASECLASSES (t
))
7843 complaint (&symfile_complaints
,
7844 _("virtual function table pointer "
7845 "not found when defining class '%s'"),
7846 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7851 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7854 else if (cu
->producer
7855 && strncmp (cu
->producer
,
7856 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7858 /* The IBM XLC compiler does not provide direct indication
7859 of the containing type, but the vtable pointer is
7860 always named __vfp. */
7864 for (i
= TYPE_NFIELDS (type
) - 1;
7865 i
>= TYPE_N_BASECLASSES (type
);
7868 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7870 TYPE_VPTR_FIELDNO (type
) = i
;
7871 TYPE_VPTR_BASETYPE (type
) = type
;
7878 /* Copy fi.typedef_field_list linked list elements content into the
7879 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7880 if (fi
.typedef_field_list
)
7882 int i
= fi
.typedef_field_list_count
;
7884 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7885 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7886 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7887 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7889 /* Reverse the list order to keep the debug info elements order. */
7892 struct typedef_field
*dest
, *src
;
7894 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7895 src
= &fi
.typedef_field_list
->field
;
7896 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7901 do_cleanups (back_to
);
7903 if (HAVE_CPLUS_STRUCT (type
))
7904 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7907 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7909 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7910 snapshots) has been known to create a die giving a declaration
7911 for a class that has, as a child, a die giving a definition for a
7912 nested class. So we have to process our children even if the
7913 current die is a declaration. Normally, of course, a declaration
7914 won't have any children at all. */
7916 while (child_die
!= NULL
&& child_die
->tag
)
7918 if (child_die
->tag
== DW_TAG_member
7919 || child_die
->tag
== DW_TAG_variable
7920 || child_die
->tag
== DW_TAG_inheritance
7921 || child_die
->tag
== DW_TAG_template_value_param
7922 || child_die
->tag
== DW_TAG_template_type_param
)
7927 process_die (child_die
, cu
);
7929 child_die
= sibling_die (child_die
);
7932 /* Do not consider external references. According to the DWARF standard,
7933 these DIEs are identified by the fact that they have no byte_size
7934 attribute, and a declaration attribute. */
7935 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7936 || !die_is_declaration (die
, cu
))
7937 new_symbol (die
, type
, cu
);
7940 /* Given a DW_AT_enumeration_type die, set its type. We do not
7941 complete the type's fields yet, or create any symbols. */
7943 static struct type
*
7944 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7946 struct objfile
*objfile
= cu
->objfile
;
7948 struct attribute
*attr
;
7951 /* If the definition of this type lives in .debug_types, read that type.
7952 Don't follow DW_AT_specification though, that will take us back up
7953 the chain and we want to go down. */
7954 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7957 struct dwarf2_cu
*type_cu
= cu
;
7958 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7960 type
= read_type_die (type_die
, type_cu
);
7962 /* TYPE_CU may not be the same as CU.
7963 Ensure TYPE is recorded in CU's type_hash table. */
7964 return set_die_type (die
, type
, cu
);
7967 type
= alloc_type (objfile
);
7969 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7970 name
= dwarf2_full_name (NULL
, die
, cu
);
7972 TYPE_TAG_NAME (type
) = (char *) name
;
7974 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7977 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7981 TYPE_LENGTH (type
) = 0;
7984 /* The enumeration DIE can be incomplete. In Ada, any type can be
7985 declared as private in the package spec, and then defined only
7986 inside the package body. Such types are known as Taft Amendment
7987 Types. When another package uses such a type, an incomplete DIE
7988 may be generated by the compiler. */
7989 if (die_is_declaration (die
, cu
))
7990 TYPE_STUB (type
) = 1;
7992 return set_die_type (die
, type
, cu
);
7995 /* Given a pointer to a die which begins an enumeration, process all
7996 the dies that define the members of the enumeration, and create the
7997 symbol for the enumeration type.
7999 NOTE: We reverse the order of the element list. */
8002 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8004 struct type
*this_type
;
8006 this_type
= get_die_type (die
, cu
);
8007 if (this_type
== NULL
)
8008 this_type
= read_enumeration_type (die
, cu
);
8010 if (die
->child
!= NULL
)
8012 struct die_info
*child_die
;
8014 struct field
*fields
= NULL
;
8016 int unsigned_enum
= 1;
8019 child_die
= die
->child
;
8020 while (child_die
&& child_die
->tag
)
8022 if (child_die
->tag
!= DW_TAG_enumerator
)
8024 process_die (child_die
, cu
);
8028 name
= dwarf2_name (child_die
, cu
);
8031 sym
= new_symbol (child_die
, this_type
, cu
);
8032 if (SYMBOL_VALUE (sym
) < 0)
8035 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8037 fields
= (struct field
*)
8039 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8040 * sizeof (struct field
));
8043 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8044 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8045 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8046 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8052 child_die
= sibling_die (child_die
);
8057 TYPE_NFIELDS (this_type
) = num_fields
;
8058 TYPE_FIELDS (this_type
) = (struct field
*)
8059 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8060 memcpy (TYPE_FIELDS (this_type
), fields
,
8061 sizeof (struct field
) * num_fields
);
8065 TYPE_UNSIGNED (this_type
) = 1;
8068 /* If we are reading an enum from a .debug_types unit, and the enum
8069 is a declaration, and the enum is not the signatured type in the
8070 unit, then we do not want to add a symbol for it. Adding a
8071 symbol would in some cases obscure the true definition of the
8072 enum, giving users an incomplete type when the definition is
8073 actually available. Note that we do not want to do this for all
8074 enums which are just declarations, because C++0x allows forward
8075 enum declarations. */
8076 if (cu
->per_cu
->debug_type_section
8077 && die_is_declaration (die
, cu
))
8079 struct signatured_type
*type_sig
;
8082 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8083 cu
->per_cu
->debug_type_section
,
8084 cu
->per_cu
->offset
);
8085 if (type_sig
->type_offset
!= die
->offset
)
8089 new_symbol (die
, this_type
, cu
);
8092 /* Extract all information from a DW_TAG_array_type DIE and put it in
8093 the DIE's type field. For now, this only handles one dimensional
8096 static struct type
*
8097 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8099 struct objfile
*objfile
= cu
->objfile
;
8100 struct die_info
*child_die
;
8102 struct type
*element_type
, *range_type
, *index_type
;
8103 struct type
**range_types
= NULL
;
8104 struct attribute
*attr
;
8106 struct cleanup
*back_to
;
8109 element_type
= die_type (die
, cu
);
8111 /* The die_type call above may have already set the type for this DIE. */
8112 type
= get_die_type (die
, cu
);
8116 /* Irix 6.2 native cc creates array types without children for
8117 arrays with unspecified length. */
8118 if (die
->child
== NULL
)
8120 index_type
= objfile_type (objfile
)->builtin_int
;
8121 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8122 type
= create_array_type (NULL
, element_type
, range_type
);
8123 return set_die_type (die
, type
, cu
);
8126 back_to
= make_cleanup (null_cleanup
, NULL
);
8127 child_die
= die
->child
;
8128 while (child_die
&& child_die
->tag
)
8130 if (child_die
->tag
== DW_TAG_subrange_type
)
8132 struct type
*child_type
= read_type_die (child_die
, cu
);
8134 if (child_type
!= NULL
)
8136 /* The range type was succesfully read. Save it for the
8137 array type creation. */
8138 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8140 range_types
= (struct type
**)
8141 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8142 * sizeof (struct type
*));
8144 make_cleanup (free_current_contents
, &range_types
);
8146 range_types
[ndim
++] = child_type
;
8149 child_die
= sibling_die (child_die
);
8152 /* Dwarf2 dimensions are output from left to right, create the
8153 necessary array types in backwards order. */
8155 type
= element_type
;
8157 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8162 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8167 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8170 /* Understand Dwarf2 support for vector types (like they occur on
8171 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8172 array type. This is not part of the Dwarf2/3 standard yet, but a
8173 custom vendor extension. The main difference between a regular
8174 array and the vector variant is that vectors are passed by value
8176 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8178 make_vector_type (type
);
8180 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8181 implementation may choose to implement triple vectors using this
8183 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8186 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8187 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8189 complaint (&symfile_complaints
,
8190 _("DW_AT_byte_size for array type smaller "
8191 "than the total size of elements"));
8194 name
= dwarf2_name (die
, cu
);
8196 TYPE_NAME (type
) = name
;
8198 /* Install the type in the die. */
8199 set_die_type (die
, type
, cu
);
8201 /* set_die_type should be already done. */
8202 set_descriptive_type (type
, die
, cu
);
8204 do_cleanups (back_to
);
8209 static enum dwarf_array_dim_ordering
8210 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8212 struct attribute
*attr
;
8214 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8216 if (attr
) return DW_SND (attr
);
8218 /* GNU F77 is a special case, as at 08/2004 array type info is the
8219 opposite order to the dwarf2 specification, but data is still
8220 laid out as per normal fortran.
8222 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8223 version checking. */
8225 if (cu
->language
== language_fortran
8226 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8228 return DW_ORD_row_major
;
8231 switch (cu
->language_defn
->la_array_ordering
)
8233 case array_column_major
:
8234 return DW_ORD_col_major
;
8235 case array_row_major
:
8237 return DW_ORD_row_major
;
8241 /* Extract all information from a DW_TAG_set_type DIE and put it in
8242 the DIE's type field. */
8244 static struct type
*
8245 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8247 struct type
*domain_type
, *set_type
;
8248 struct attribute
*attr
;
8250 domain_type
= die_type (die
, cu
);
8252 /* The die_type call above may have already set the type for this DIE. */
8253 set_type
= get_die_type (die
, cu
);
8257 set_type
= create_set_type (NULL
, domain_type
);
8259 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8261 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8263 return set_die_type (die
, set_type
, cu
);
8266 /* First cut: install each common block member as a global variable. */
8269 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8271 struct die_info
*child_die
;
8272 struct attribute
*attr
;
8274 CORE_ADDR base
= (CORE_ADDR
) 0;
8276 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8279 /* Support the .debug_loc offsets. */
8280 if (attr_form_is_block (attr
))
8282 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8284 else if (attr_form_is_section_offset (attr
))
8286 dwarf2_complex_location_expr_complaint ();
8290 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8291 "common block member");
8294 if (die
->child
!= NULL
)
8296 child_die
= die
->child
;
8297 while (child_die
&& child_die
->tag
)
8301 sym
= new_symbol (child_die
, NULL
, cu
);
8303 && handle_data_member_location (child_die
, cu
, &offset
))
8305 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8306 add_symbol_to_list (sym
, &global_symbols
);
8308 child_die
= sibling_die (child_die
);
8313 /* Create a type for a C++ namespace. */
8315 static struct type
*
8316 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8318 struct objfile
*objfile
= cu
->objfile
;
8319 const char *previous_prefix
, *name
;
8323 /* For extensions, reuse the type of the original namespace. */
8324 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8326 struct die_info
*ext_die
;
8327 struct dwarf2_cu
*ext_cu
= cu
;
8329 ext_die
= dwarf2_extension (die
, &ext_cu
);
8330 type
= read_type_die (ext_die
, ext_cu
);
8332 /* EXT_CU may not be the same as CU.
8333 Ensure TYPE is recorded in CU's type_hash table. */
8334 return set_die_type (die
, type
, cu
);
8337 name
= namespace_name (die
, &is_anonymous
, cu
);
8339 /* Now build the name of the current namespace. */
8341 previous_prefix
= determine_prefix (die
, cu
);
8342 if (previous_prefix
[0] != '\0')
8343 name
= typename_concat (&objfile
->objfile_obstack
,
8344 previous_prefix
, name
, 0, cu
);
8346 /* Create the type. */
8347 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8349 TYPE_NAME (type
) = (char *) name
;
8350 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8352 return set_die_type (die
, type
, cu
);
8355 /* Read a C++ namespace. */
8358 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8360 struct objfile
*objfile
= cu
->objfile
;
8363 /* Add a symbol associated to this if we haven't seen the namespace
8364 before. Also, add a using directive if it's an anonymous
8367 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8371 type
= read_type_die (die
, cu
);
8372 new_symbol (die
, type
, cu
);
8374 namespace_name (die
, &is_anonymous
, cu
);
8377 const char *previous_prefix
= determine_prefix (die
, cu
);
8379 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8380 NULL
, NULL
, &objfile
->objfile_obstack
);
8384 if (die
->child
!= NULL
)
8386 struct die_info
*child_die
= die
->child
;
8388 while (child_die
&& child_die
->tag
)
8390 process_die (child_die
, cu
);
8391 child_die
= sibling_die (child_die
);
8396 /* Read a Fortran module as type. This DIE can be only a declaration used for
8397 imported module. Still we need that type as local Fortran "use ... only"
8398 declaration imports depend on the created type in determine_prefix. */
8400 static struct type
*
8401 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8403 struct objfile
*objfile
= cu
->objfile
;
8407 module_name
= dwarf2_name (die
, cu
);
8409 complaint (&symfile_complaints
,
8410 _("DW_TAG_module has no name, offset 0x%x"),
8412 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8414 /* determine_prefix uses TYPE_TAG_NAME. */
8415 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8417 return set_die_type (die
, type
, cu
);
8420 /* Read a Fortran module. */
8423 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8425 struct die_info
*child_die
= die
->child
;
8427 while (child_die
&& child_die
->tag
)
8429 process_die (child_die
, cu
);
8430 child_die
= sibling_die (child_die
);
8434 /* Return the name of the namespace represented by DIE. Set
8435 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8439 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8441 struct die_info
*current_die
;
8442 const char *name
= NULL
;
8444 /* Loop through the extensions until we find a name. */
8446 for (current_die
= die
;
8447 current_die
!= NULL
;
8448 current_die
= dwarf2_extension (die
, &cu
))
8450 name
= dwarf2_name (current_die
, cu
);
8455 /* Is it an anonymous namespace? */
8457 *is_anonymous
= (name
== NULL
);
8459 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8464 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8465 the user defined type vector. */
8467 static struct type
*
8468 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8470 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8471 struct comp_unit_head
*cu_header
= &cu
->header
;
8473 struct attribute
*attr_byte_size
;
8474 struct attribute
*attr_address_class
;
8475 int byte_size
, addr_class
;
8476 struct type
*target_type
;
8478 target_type
= die_type (die
, cu
);
8480 /* The die_type call above may have already set the type for this DIE. */
8481 type
= get_die_type (die
, cu
);
8485 type
= lookup_pointer_type (target_type
);
8487 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8489 byte_size
= DW_UNSND (attr_byte_size
);
8491 byte_size
= cu_header
->addr_size
;
8493 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8494 if (attr_address_class
)
8495 addr_class
= DW_UNSND (attr_address_class
);
8497 addr_class
= DW_ADDR_none
;
8499 /* If the pointer size or address class is different than the
8500 default, create a type variant marked as such and set the
8501 length accordingly. */
8502 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8504 if (gdbarch_address_class_type_flags_p (gdbarch
))
8508 type_flags
= gdbarch_address_class_type_flags
8509 (gdbarch
, byte_size
, addr_class
);
8510 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8512 type
= make_type_with_address_space (type
, type_flags
);
8514 else if (TYPE_LENGTH (type
) != byte_size
)
8516 complaint (&symfile_complaints
,
8517 _("invalid pointer size %d"), byte_size
);
8521 /* Should we also complain about unhandled address classes? */
8525 TYPE_LENGTH (type
) = byte_size
;
8526 return set_die_type (die
, type
, cu
);
8529 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8530 the user defined type vector. */
8532 static struct type
*
8533 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8536 struct type
*to_type
;
8537 struct type
*domain
;
8539 to_type
= die_type (die
, cu
);
8540 domain
= die_containing_type (die
, cu
);
8542 /* The calls above may have already set the type for this DIE. */
8543 type
= get_die_type (die
, cu
);
8547 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8548 type
= lookup_methodptr_type (to_type
);
8550 type
= lookup_memberptr_type (to_type
, domain
);
8552 return set_die_type (die
, type
, cu
);
8555 /* Extract all information from a DW_TAG_reference_type DIE and add to
8556 the user defined type vector. */
8558 static struct type
*
8559 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8561 struct comp_unit_head
*cu_header
= &cu
->header
;
8562 struct type
*type
, *target_type
;
8563 struct attribute
*attr
;
8565 target_type
= die_type (die
, cu
);
8567 /* The die_type call above may have already set the type for this DIE. */
8568 type
= get_die_type (die
, cu
);
8572 type
= lookup_reference_type (target_type
);
8573 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8576 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8580 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8582 return set_die_type (die
, type
, cu
);
8585 static struct type
*
8586 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8588 struct type
*base_type
, *cv_type
;
8590 base_type
= die_type (die
, cu
);
8592 /* The die_type call above may have already set the type for this DIE. */
8593 cv_type
= get_die_type (die
, cu
);
8597 /* In case the const qualifier is applied to an array type, the element type
8598 is so qualified, not the array type (section 6.7.3 of C99). */
8599 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8601 struct type
*el_type
, *inner_array
;
8603 base_type
= copy_type (base_type
);
8604 inner_array
= base_type
;
8606 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8608 TYPE_TARGET_TYPE (inner_array
) =
8609 copy_type (TYPE_TARGET_TYPE (inner_array
));
8610 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8613 el_type
= TYPE_TARGET_TYPE (inner_array
);
8614 TYPE_TARGET_TYPE (inner_array
) =
8615 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8617 return set_die_type (die
, base_type
, cu
);
8620 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8621 return set_die_type (die
, cv_type
, cu
);
8624 static struct type
*
8625 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8627 struct type
*base_type
, *cv_type
;
8629 base_type
= die_type (die
, cu
);
8631 /* The die_type call above may have already set the type for this DIE. */
8632 cv_type
= get_die_type (die
, cu
);
8636 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8637 return set_die_type (die
, cv_type
, cu
);
8640 /* Extract all information from a DW_TAG_string_type DIE and add to
8641 the user defined type vector. It isn't really a user defined type,
8642 but it behaves like one, with other DIE's using an AT_user_def_type
8643 attribute to reference it. */
8645 static struct type
*
8646 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8648 struct objfile
*objfile
= cu
->objfile
;
8649 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8650 struct type
*type
, *range_type
, *index_type
, *char_type
;
8651 struct attribute
*attr
;
8652 unsigned int length
;
8654 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8657 length
= DW_UNSND (attr
);
8661 /* Check for the DW_AT_byte_size attribute. */
8662 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8665 length
= DW_UNSND (attr
);
8673 index_type
= objfile_type (objfile
)->builtin_int
;
8674 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8675 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8676 type
= create_string_type (NULL
, char_type
, range_type
);
8678 return set_die_type (die
, type
, cu
);
8681 /* Handle DIES due to C code like:
8685 int (*funcp)(int a, long l);
8689 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8691 static struct type
*
8692 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8694 struct type
*type
; /* Type that this function returns. */
8695 struct type
*ftype
; /* Function that returns above type. */
8696 struct attribute
*attr
;
8698 type
= die_type (die
, cu
);
8700 /* The die_type call above may have already set the type for this DIE. */
8701 ftype
= get_die_type (die
, cu
);
8705 ftype
= lookup_function_type (type
);
8707 /* All functions in C++, Pascal and Java have prototypes. */
8708 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8709 if ((attr
&& (DW_UNSND (attr
) != 0))
8710 || cu
->language
== language_cplus
8711 || cu
->language
== language_java
8712 || cu
->language
== language_pascal
)
8713 TYPE_PROTOTYPED (ftype
) = 1;
8714 else if (producer_is_realview (cu
->producer
))
8715 /* RealView does not emit DW_AT_prototyped. We can not
8716 distinguish prototyped and unprototyped functions; default to
8717 prototyped, since that is more common in modern code (and
8718 RealView warns about unprototyped functions). */
8719 TYPE_PROTOTYPED (ftype
) = 1;
8721 /* Store the calling convention in the type if it's available in
8722 the subroutine die. Otherwise set the calling convention to
8723 the default value DW_CC_normal. */
8724 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8726 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8727 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8728 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8730 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8732 /* We need to add the subroutine type to the die immediately so
8733 we don't infinitely recurse when dealing with parameters
8734 declared as the same subroutine type. */
8735 set_die_type (die
, ftype
, cu
);
8737 if (die
->child
!= NULL
)
8739 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8740 struct die_info
*child_die
;
8741 int nparams
, iparams
;
8743 /* Count the number of parameters.
8744 FIXME: GDB currently ignores vararg functions, but knows about
8745 vararg member functions. */
8747 child_die
= die
->child
;
8748 while (child_die
&& child_die
->tag
)
8750 if (child_die
->tag
== DW_TAG_formal_parameter
)
8752 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8753 TYPE_VARARGS (ftype
) = 1;
8754 child_die
= sibling_die (child_die
);
8757 /* Allocate storage for parameters and fill them in. */
8758 TYPE_NFIELDS (ftype
) = nparams
;
8759 TYPE_FIELDS (ftype
) = (struct field
*)
8760 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8762 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8763 even if we error out during the parameters reading below. */
8764 for (iparams
= 0; iparams
< nparams
; iparams
++)
8765 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8768 child_die
= die
->child
;
8769 while (child_die
&& child_die
->tag
)
8771 if (child_die
->tag
== DW_TAG_formal_parameter
)
8773 struct type
*arg_type
;
8775 /* DWARF version 2 has no clean way to discern C++
8776 static and non-static member functions. G++ helps
8777 GDB by marking the first parameter for non-static
8778 member functions (which is the this pointer) as
8779 artificial. We pass this information to
8780 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8782 DWARF version 3 added DW_AT_object_pointer, which GCC
8783 4.5 does not yet generate. */
8784 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8786 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8789 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8791 /* GCC/43521: In java, the formal parameter
8792 "this" is sometimes not marked with DW_AT_artificial. */
8793 if (cu
->language
== language_java
)
8795 const char *name
= dwarf2_name (child_die
, cu
);
8797 if (name
&& !strcmp (name
, "this"))
8798 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8801 arg_type
= die_type (child_die
, cu
);
8803 /* RealView does not mark THIS as const, which the testsuite
8804 expects. GCC marks THIS as const in method definitions,
8805 but not in the class specifications (GCC PR 43053). */
8806 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8807 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8810 struct dwarf2_cu
*arg_cu
= cu
;
8811 const char *name
= dwarf2_name (child_die
, cu
);
8813 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8816 /* If the compiler emits this, use it. */
8817 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8820 else if (name
&& strcmp (name
, "this") == 0)
8821 /* Function definitions will have the argument names. */
8823 else if (name
== NULL
&& iparams
== 0)
8824 /* Declarations may not have the names, so like
8825 elsewhere in GDB, assume an artificial first
8826 argument is "this". */
8830 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8834 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8837 child_die
= sibling_die (child_die
);
8844 static struct type
*
8845 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8847 struct objfile
*objfile
= cu
->objfile
;
8848 const char *name
= NULL
;
8849 struct type
*this_type
;
8851 name
= dwarf2_full_name (NULL
, die
, cu
);
8852 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8853 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8854 TYPE_NAME (this_type
) = (char *) name
;
8855 set_die_type (die
, this_type
, cu
);
8856 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8860 /* Find a representation of a given base type and install
8861 it in the TYPE field of the die. */
8863 static struct type
*
8864 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8866 struct objfile
*objfile
= cu
->objfile
;
8868 struct attribute
*attr
;
8869 int encoding
= 0, size
= 0;
8871 enum type_code code
= TYPE_CODE_INT
;
8873 struct type
*target_type
= NULL
;
8875 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8878 encoding
= DW_UNSND (attr
);
8880 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8883 size
= DW_UNSND (attr
);
8885 name
= dwarf2_name (die
, cu
);
8888 complaint (&symfile_complaints
,
8889 _("DW_AT_name missing from DW_TAG_base_type"));
8894 case DW_ATE_address
:
8895 /* Turn DW_ATE_address into a void * pointer. */
8896 code
= TYPE_CODE_PTR
;
8897 type_flags
|= TYPE_FLAG_UNSIGNED
;
8898 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8900 case DW_ATE_boolean
:
8901 code
= TYPE_CODE_BOOL
;
8902 type_flags
|= TYPE_FLAG_UNSIGNED
;
8904 case DW_ATE_complex_float
:
8905 code
= TYPE_CODE_COMPLEX
;
8906 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8908 case DW_ATE_decimal_float
:
8909 code
= TYPE_CODE_DECFLOAT
;
8912 code
= TYPE_CODE_FLT
;
8916 case DW_ATE_unsigned
:
8917 type_flags
|= TYPE_FLAG_UNSIGNED
;
8918 if (cu
->language
== language_fortran
8920 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8921 code
= TYPE_CODE_CHAR
;
8923 case DW_ATE_signed_char
:
8924 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8925 || cu
->language
== language_pascal
8926 || cu
->language
== language_fortran
)
8927 code
= TYPE_CODE_CHAR
;
8929 case DW_ATE_unsigned_char
:
8930 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8931 || cu
->language
== language_pascal
8932 || cu
->language
== language_fortran
)
8933 code
= TYPE_CODE_CHAR
;
8934 type_flags
|= TYPE_FLAG_UNSIGNED
;
8937 /* We just treat this as an integer and then recognize the
8938 type by name elsewhere. */
8942 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8943 dwarf_type_encoding_name (encoding
));
8947 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8948 TYPE_NAME (type
) = name
;
8949 TYPE_TARGET_TYPE (type
) = target_type
;
8951 if (name
&& strcmp (name
, "char") == 0)
8952 TYPE_NOSIGN (type
) = 1;
8954 return set_die_type (die
, type
, cu
);
8957 /* Read the given DW_AT_subrange DIE. */
8959 static struct type
*
8960 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8962 struct type
*base_type
;
8963 struct type
*range_type
;
8964 struct attribute
*attr
;
8968 LONGEST negative_mask
;
8970 base_type
= die_type (die
, cu
);
8971 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8972 check_typedef (base_type
);
8974 /* The die_type call above may have already set the type for this DIE. */
8975 range_type
= get_die_type (die
, cu
);
8979 if (cu
->language
== language_fortran
)
8981 /* FORTRAN implies a lower bound of 1, if not given. */
8985 /* FIXME: For variable sized arrays either of these could be
8986 a variable rather than a constant value. We'll allow it,
8987 but we don't know how to handle it. */
8988 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8990 low
= dwarf2_get_attr_constant_value (attr
, 0);
8992 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8995 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8997 /* GCC encodes arrays with unspecified or dynamic length
8998 with a DW_FORM_block1 attribute or a reference attribute.
8999 FIXME: GDB does not yet know how to handle dynamic
9000 arrays properly, treat them as arrays with unspecified
9003 FIXME: jimb/2003-09-22: GDB does not really know
9004 how to handle arrays of unspecified length
9005 either; we just represent them as zero-length
9006 arrays. Choose an appropriate upper bound given
9007 the lower bound we've computed above. */
9011 high
= dwarf2_get_attr_constant_value (attr
, 1);
9015 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9018 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9019 high
= low
+ count
- 1;
9023 /* Unspecified array length. */
9028 /* Dwarf-2 specifications explicitly allows to create subrange types
9029 without specifying a base type.
9030 In that case, the base type must be set to the type of
9031 the lower bound, upper bound or count, in that order, if any of these
9032 three attributes references an object that has a type.
9033 If no base type is found, the Dwarf-2 specifications say that
9034 a signed integer type of size equal to the size of an address should
9036 For the following C code: `extern char gdb_int [];'
9037 GCC produces an empty range DIE.
9038 FIXME: muller/2010-05-28: Possible references to object for low bound,
9039 high bound or count are not yet handled by this code. */
9040 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9042 struct objfile
*objfile
= cu
->objfile
;
9043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9044 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9045 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9047 /* Test "int", "long int", and "long long int" objfile types,
9048 and select the first one having a size above or equal to the
9049 architecture address size. */
9050 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9051 base_type
= int_type
;
9054 int_type
= objfile_type (objfile
)->builtin_long
;
9055 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9056 base_type
= int_type
;
9059 int_type
= objfile_type (objfile
)->builtin_long_long
;
9060 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9061 base_type
= int_type
;
9067 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9068 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9069 low
|= negative_mask
;
9070 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9071 high
|= negative_mask
;
9073 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9075 /* Mark arrays with dynamic length at least as an array of unspecified
9076 length. GDB could check the boundary but before it gets implemented at
9077 least allow accessing the array elements. */
9078 if (attr
&& attr_form_is_block (attr
))
9079 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9081 /* Ada expects an empty array on no boundary attributes. */
9082 if (attr
== NULL
&& cu
->language
!= language_ada
)
9083 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9085 name
= dwarf2_name (die
, cu
);
9087 TYPE_NAME (range_type
) = name
;
9089 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9091 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9093 set_die_type (die
, range_type
, cu
);
9095 /* set_die_type should be already done. */
9096 set_descriptive_type (range_type
, die
, cu
);
9101 static struct type
*
9102 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9106 /* For now, we only support the C meaning of an unspecified type: void. */
9108 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9109 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9111 return set_die_type (die
, type
, cu
);
9114 /* Trivial hash function for die_info: the hash value of a DIE
9115 is its offset in .debug_info for this objfile. */
9118 die_hash (const void *item
)
9120 const struct die_info
*die
= item
;
9125 /* Trivial comparison function for die_info structures: two DIEs
9126 are equal if they have the same offset. */
9129 die_eq (const void *item_lhs
, const void *item_rhs
)
9131 const struct die_info
*die_lhs
= item_lhs
;
9132 const struct die_info
*die_rhs
= item_rhs
;
9134 return die_lhs
->offset
== die_rhs
->offset
;
9137 /* Read a whole compilation unit into a linked list of dies. */
9139 static struct die_info
*
9140 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9142 struct die_reader_specs reader_specs
;
9143 int read_abbrevs
= 0;
9144 struct cleanup
*back_to
= NULL
;
9145 struct die_info
*die
;
9147 if (cu
->dwarf2_abbrevs
== NULL
)
9149 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
9150 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9154 gdb_assert (cu
->die_hash
== NULL
);
9156 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9160 &cu
->comp_unit_obstack
,
9161 hashtab_obstack_allocate
,
9162 dummy_obstack_deallocate
);
9164 init_cu_die_reader (&reader_specs
, cu
);
9166 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9169 do_cleanups (back_to
);
9174 /* Main entry point for reading a DIE and all children.
9175 Read the DIE and dump it if requested. */
9177 static struct die_info
*
9178 read_die_and_children (const struct die_reader_specs
*reader
,
9180 gdb_byte
**new_info_ptr
,
9181 struct die_info
*parent
)
9183 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9184 new_info_ptr
, parent
);
9186 if (dwarf2_die_debug
)
9188 fprintf_unfiltered (gdb_stdlog
,
9189 "\nRead die from %s of %s:\n",
9190 (reader
->cu
->per_cu
->debug_type_section
9193 reader
->abfd
->filename
);
9194 dump_die (result
, dwarf2_die_debug
);
9200 /* Read a single die and all its descendents. Set the die's sibling
9201 field to NULL; set other fields in the die correctly, and set all
9202 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9203 location of the info_ptr after reading all of those dies. PARENT
9204 is the parent of the die in question. */
9206 static struct die_info
*
9207 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9209 gdb_byte
**new_info_ptr
,
9210 struct die_info
*parent
)
9212 struct die_info
*die
;
9216 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9219 *new_info_ptr
= cur_ptr
;
9222 store_in_ref_table (die
, reader
->cu
);
9225 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9229 *new_info_ptr
= cur_ptr
;
9232 die
->sibling
= NULL
;
9233 die
->parent
= parent
;
9237 /* Read a die, all of its descendents, and all of its siblings; set
9238 all of the fields of all of the dies correctly. Arguments are as
9239 in read_die_and_children. */
9241 static struct die_info
*
9242 read_die_and_siblings (const struct die_reader_specs
*reader
,
9244 gdb_byte
**new_info_ptr
,
9245 struct die_info
*parent
)
9247 struct die_info
*first_die
, *last_sibling
;
9251 first_die
= last_sibling
= NULL
;
9255 struct die_info
*die
9256 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9260 *new_info_ptr
= cur_ptr
;
9267 last_sibling
->sibling
= die
;
9273 /* Read the die from the .debug_info section buffer. Set DIEP to
9274 point to a newly allocated die with its information, except for its
9275 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9276 whether the die has children or not. */
9279 read_full_die (const struct die_reader_specs
*reader
,
9280 struct die_info
**diep
, gdb_byte
*info_ptr
,
9283 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9284 struct abbrev_info
*abbrev
;
9285 struct die_info
*die
;
9286 struct dwarf2_cu
*cu
= reader
->cu
;
9287 bfd
*abfd
= reader
->abfd
;
9289 offset
= info_ptr
- reader
->buffer
;
9290 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9291 info_ptr
+= bytes_read
;
9299 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9301 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9303 bfd_get_filename (abfd
));
9305 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9306 die
->offset
= offset
;
9307 die
->tag
= abbrev
->tag
;
9308 die
->abbrev
= abbrev_number
;
9310 die
->num_attrs
= abbrev
->num_attrs
;
9312 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9313 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9314 abfd
, info_ptr
, cu
);
9317 *has_children
= abbrev
->has_children
;
9321 /* In DWARF version 2, the description of the debugging information is
9322 stored in a separate .debug_abbrev section. Before we read any
9323 dies from a section we read in all abbreviations and install them
9324 in a hash table. This function also sets flags in CU describing
9325 the data found in the abbrev table. */
9328 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9330 struct comp_unit_head
*cu_header
= &cu
->header
;
9331 gdb_byte
*abbrev_ptr
;
9332 struct abbrev_info
*cur_abbrev
;
9333 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9334 unsigned int abbrev_form
, hash_number
;
9335 struct attr_abbrev
*cur_attrs
;
9336 unsigned int allocated_attrs
;
9338 /* Initialize dwarf2 abbrevs. */
9339 obstack_init (&cu
->abbrev_obstack
);
9340 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9342 * sizeof (struct abbrev_info
*)));
9343 memset (cu
->dwarf2_abbrevs
, 0,
9344 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9346 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9347 &dwarf2_per_objfile
->abbrev
);
9348 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9349 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9350 abbrev_ptr
+= bytes_read
;
9352 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9353 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9355 /* Loop until we reach an abbrev number of 0. */
9356 while (abbrev_number
)
9358 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9360 /* read in abbrev header */
9361 cur_abbrev
->number
= abbrev_number
;
9362 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9363 abbrev_ptr
+= bytes_read
;
9364 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9367 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9368 cu
->has_namespace_info
= 1;
9370 /* now read in declarations */
9371 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9372 abbrev_ptr
+= bytes_read
;
9373 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9374 abbrev_ptr
+= bytes_read
;
9377 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9379 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9381 = xrealloc (cur_attrs
, (allocated_attrs
9382 * sizeof (struct attr_abbrev
)));
9385 /* Record whether this compilation unit might have
9386 inter-compilation-unit references. If we don't know what form
9387 this attribute will have, then it might potentially be a
9388 DW_FORM_ref_addr, so we conservatively expect inter-CU
9391 if (abbrev_form
== DW_FORM_ref_addr
9392 || abbrev_form
== DW_FORM_indirect
)
9393 cu
->has_form_ref_addr
= 1;
9395 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9396 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9397 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9398 abbrev_ptr
+= bytes_read
;
9399 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9400 abbrev_ptr
+= bytes_read
;
9403 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9404 (cur_abbrev
->num_attrs
9405 * sizeof (struct attr_abbrev
)));
9406 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9407 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9409 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9410 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9411 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9413 /* Get next abbreviation.
9414 Under Irix6 the abbreviations for a compilation unit are not
9415 always properly terminated with an abbrev number of 0.
9416 Exit loop if we encounter an abbreviation which we have
9417 already read (which means we are about to read the abbreviations
9418 for the next compile unit) or if the end of the abbreviation
9419 table is reached. */
9420 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9421 >= dwarf2_per_objfile
->abbrev
.size
)
9423 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9424 abbrev_ptr
+= bytes_read
;
9425 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9432 /* Release the memory used by the abbrev table for a compilation unit. */
9435 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9437 struct dwarf2_cu
*cu
= ptr_to_cu
;
9439 obstack_free (&cu
->abbrev_obstack
, NULL
);
9440 cu
->dwarf2_abbrevs
= NULL
;
9443 /* Lookup an abbrev_info structure in the abbrev hash table. */
9445 static struct abbrev_info
*
9446 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9448 unsigned int hash_number
;
9449 struct abbrev_info
*abbrev
;
9451 hash_number
= number
% ABBREV_HASH_SIZE
;
9452 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9456 if (abbrev
->number
== number
)
9459 abbrev
= abbrev
->next
;
9464 /* Returns nonzero if TAG represents a type that we might generate a partial
9468 is_type_tag_for_partial (int tag
)
9473 /* Some types that would be reasonable to generate partial symbols for,
9474 that we don't at present. */
9475 case DW_TAG_array_type
:
9476 case DW_TAG_file_type
:
9477 case DW_TAG_ptr_to_member_type
:
9478 case DW_TAG_set_type
:
9479 case DW_TAG_string_type
:
9480 case DW_TAG_subroutine_type
:
9482 case DW_TAG_base_type
:
9483 case DW_TAG_class_type
:
9484 case DW_TAG_interface_type
:
9485 case DW_TAG_enumeration_type
:
9486 case DW_TAG_structure_type
:
9487 case DW_TAG_subrange_type
:
9488 case DW_TAG_typedef
:
9489 case DW_TAG_union_type
:
9496 /* Load all DIEs that are interesting for partial symbols into memory. */
9498 static struct partial_die_info
*
9499 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9500 int building_psymtab
, struct dwarf2_cu
*cu
)
9502 struct partial_die_info
*part_die
;
9503 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9504 struct abbrev_info
*abbrev
;
9505 unsigned int bytes_read
;
9506 unsigned int load_all
= 0;
9508 int nesting_level
= 1;
9513 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9517 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9521 &cu
->comp_unit_obstack
,
9522 hashtab_obstack_allocate
,
9523 dummy_obstack_deallocate
);
9525 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9526 sizeof (struct partial_die_info
));
9530 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9532 /* A NULL abbrev means the end of a series of children. */
9535 if (--nesting_level
== 0)
9537 /* PART_DIE was probably the last thing allocated on the
9538 comp_unit_obstack, so we could call obstack_free
9539 here. We don't do that because the waste is small,
9540 and will be cleaned up when we're done with this
9541 compilation unit. This way, we're also more robust
9542 against other users of the comp_unit_obstack. */
9545 info_ptr
+= bytes_read
;
9546 last_die
= parent_die
;
9547 parent_die
= parent_die
->die_parent
;
9551 /* Check for template arguments. We never save these; if
9552 they're seen, we just mark the parent, and go on our way. */
9553 if (parent_die
!= NULL
9554 && cu
->language
== language_cplus
9555 && (abbrev
->tag
== DW_TAG_template_type_param
9556 || abbrev
->tag
== DW_TAG_template_value_param
))
9558 parent_die
->has_template_arguments
= 1;
9562 /* We don't need a partial DIE for the template argument. */
9563 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9569 /* We only recurse into subprograms looking for template arguments.
9570 Skip their other children. */
9572 && cu
->language
== language_cplus
9573 && parent_die
!= NULL
9574 && parent_die
->tag
== DW_TAG_subprogram
)
9576 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9580 /* Check whether this DIE is interesting enough to save. Normally
9581 we would not be interested in members here, but there may be
9582 later variables referencing them via DW_AT_specification (for
9585 && !is_type_tag_for_partial (abbrev
->tag
)
9586 && abbrev
->tag
!= DW_TAG_constant
9587 && abbrev
->tag
!= DW_TAG_enumerator
9588 && abbrev
->tag
!= DW_TAG_subprogram
9589 && abbrev
->tag
!= DW_TAG_lexical_block
9590 && abbrev
->tag
!= DW_TAG_variable
9591 && abbrev
->tag
!= DW_TAG_namespace
9592 && abbrev
->tag
!= DW_TAG_module
9593 && abbrev
->tag
!= DW_TAG_member
)
9595 /* Otherwise we skip to the next sibling, if any. */
9596 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9600 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9601 buffer
, info_ptr
, cu
);
9603 /* This two-pass algorithm for processing partial symbols has a
9604 high cost in cache pressure. Thus, handle some simple cases
9605 here which cover the majority of C partial symbols. DIEs
9606 which neither have specification tags in them, nor could have
9607 specification tags elsewhere pointing at them, can simply be
9608 processed and discarded.
9610 This segment is also optional; scan_partial_symbols and
9611 add_partial_symbol will handle these DIEs if we chain
9612 them in normally. When compilers which do not emit large
9613 quantities of duplicate debug information are more common,
9614 this code can probably be removed. */
9616 /* Any complete simple types at the top level (pretty much all
9617 of them, for a language without namespaces), can be processed
9619 if (parent_die
== NULL
9620 && part_die
->has_specification
== 0
9621 && part_die
->is_declaration
== 0
9622 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9623 || part_die
->tag
== DW_TAG_base_type
9624 || part_die
->tag
== DW_TAG_subrange_type
))
9626 if (building_psymtab
&& part_die
->name
!= NULL
)
9627 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9628 VAR_DOMAIN
, LOC_TYPEDEF
,
9629 &cu
->objfile
->static_psymbols
,
9630 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9631 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9635 /* The exception for DW_TAG_typedef with has_children above is
9636 a workaround of GCC PR debug/47510. In the case of this complaint
9637 type_name_no_tag_or_error will error on such types later.
9639 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9640 it could not find the child DIEs referenced later, this is checked
9641 above. In correct DWARF DW_TAG_typedef should have no children. */
9643 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9644 complaint (&symfile_complaints
,
9645 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9646 "- DIE at 0x%x [in module %s]"),
9647 part_die
->offset
, cu
->objfile
->name
);
9649 /* If we're at the second level, and we're an enumerator, and
9650 our parent has no specification (meaning possibly lives in a
9651 namespace elsewhere), then we can add the partial symbol now
9652 instead of queueing it. */
9653 if (part_die
->tag
== DW_TAG_enumerator
9654 && parent_die
!= NULL
9655 && parent_die
->die_parent
== NULL
9656 && parent_die
->tag
== DW_TAG_enumeration_type
9657 && parent_die
->has_specification
== 0)
9659 if (part_die
->name
== NULL
)
9660 complaint (&symfile_complaints
,
9661 _("malformed enumerator DIE ignored"));
9662 else if (building_psymtab
)
9663 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9664 VAR_DOMAIN
, LOC_CONST
,
9665 (cu
->language
== language_cplus
9666 || cu
->language
== language_java
)
9667 ? &cu
->objfile
->global_psymbols
9668 : &cu
->objfile
->static_psymbols
,
9669 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9671 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9675 /* We'll save this DIE so link it in. */
9676 part_die
->die_parent
= parent_die
;
9677 part_die
->die_sibling
= NULL
;
9678 part_die
->die_child
= NULL
;
9680 if (last_die
&& last_die
== parent_die
)
9681 last_die
->die_child
= part_die
;
9683 last_die
->die_sibling
= part_die
;
9685 last_die
= part_die
;
9687 if (first_die
== NULL
)
9688 first_die
= part_die
;
9690 /* Maybe add the DIE to the hash table. Not all DIEs that we
9691 find interesting need to be in the hash table, because we
9692 also have the parent/sibling/child chains; only those that we
9693 might refer to by offset later during partial symbol reading.
9695 For now this means things that might have be the target of a
9696 DW_AT_specification, DW_AT_abstract_origin, or
9697 DW_AT_extension. DW_AT_extension will refer only to
9698 namespaces; DW_AT_abstract_origin refers to functions (and
9699 many things under the function DIE, but we do not recurse
9700 into function DIEs during partial symbol reading) and
9701 possibly variables as well; DW_AT_specification refers to
9702 declarations. Declarations ought to have the DW_AT_declaration
9703 flag. It happens that GCC forgets to put it in sometimes, but
9704 only for functions, not for types.
9706 Adding more things than necessary to the hash table is harmless
9707 except for the performance cost. Adding too few will result in
9708 wasted time in find_partial_die, when we reread the compilation
9709 unit with load_all_dies set. */
9712 || abbrev
->tag
== DW_TAG_constant
9713 || abbrev
->tag
== DW_TAG_subprogram
9714 || abbrev
->tag
== DW_TAG_variable
9715 || abbrev
->tag
== DW_TAG_namespace
9716 || part_die
->is_declaration
)
9720 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9721 part_die
->offset
, INSERT
);
9725 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9726 sizeof (struct partial_die_info
));
9728 /* For some DIEs we want to follow their children (if any). For C
9729 we have no reason to follow the children of structures; for other
9730 languages we have to, so that we can get at method physnames
9731 to infer fully qualified class names, for DW_AT_specification,
9732 and for C++ template arguments. For C++, we also look one level
9733 inside functions to find template arguments (if the name of the
9734 function does not already contain the template arguments).
9736 For Ada, we need to scan the children of subprograms and lexical
9737 blocks as well because Ada allows the definition of nested
9738 entities that could be interesting for the debugger, such as
9739 nested subprograms for instance. */
9740 if (last_die
->has_children
9742 || last_die
->tag
== DW_TAG_namespace
9743 || last_die
->tag
== DW_TAG_module
9744 || last_die
->tag
== DW_TAG_enumeration_type
9745 || (cu
->language
== language_cplus
9746 && last_die
->tag
== DW_TAG_subprogram
9747 && (last_die
->name
== NULL
9748 || strchr (last_die
->name
, '<') == NULL
))
9749 || (cu
->language
!= language_c
9750 && (last_die
->tag
== DW_TAG_class_type
9751 || last_die
->tag
== DW_TAG_interface_type
9752 || last_die
->tag
== DW_TAG_structure_type
9753 || last_die
->tag
== DW_TAG_union_type
))
9754 || (cu
->language
== language_ada
9755 && (last_die
->tag
== DW_TAG_subprogram
9756 || last_die
->tag
== DW_TAG_lexical_block
))))
9759 parent_die
= last_die
;
9763 /* Otherwise we skip to the next sibling, if any. */
9764 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9766 /* Back to the top, do it again. */
9770 /* Read a minimal amount of information into the minimal die structure. */
9773 read_partial_die (struct partial_die_info
*part_die
,
9774 struct abbrev_info
*abbrev
,
9775 unsigned int abbrev_len
, bfd
*abfd
,
9776 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9777 struct dwarf2_cu
*cu
)
9780 struct attribute attr
;
9781 int has_low_pc_attr
= 0;
9782 int has_high_pc_attr
= 0;
9784 memset (part_die
, 0, sizeof (struct partial_die_info
));
9786 part_die
->offset
= info_ptr
- buffer
;
9788 info_ptr
+= abbrev_len
;
9793 part_die
->tag
= abbrev
->tag
;
9794 part_die
->has_children
= abbrev
->has_children
;
9796 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9798 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9800 /* Store the data if it is of an attribute we want to keep in a
9801 partial symbol table. */
9805 switch (part_die
->tag
)
9807 case DW_TAG_compile_unit
:
9808 case DW_TAG_type_unit
:
9809 /* Compilation units have a DW_AT_name that is a filename, not
9810 a source language identifier. */
9811 case DW_TAG_enumeration_type
:
9812 case DW_TAG_enumerator
:
9813 /* These tags always have simple identifiers already; no need
9814 to canonicalize them. */
9815 part_die
->name
= DW_STRING (&attr
);
9819 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9820 &cu
->objfile
->objfile_obstack
);
9824 case DW_AT_linkage_name
:
9825 case DW_AT_MIPS_linkage_name
:
9826 /* Note that both forms of linkage name might appear. We
9827 assume they will be the same, and we only store the last
9829 if (cu
->language
== language_ada
)
9830 part_die
->name
= DW_STRING (&attr
);
9831 part_die
->linkage_name
= DW_STRING (&attr
);
9834 has_low_pc_attr
= 1;
9835 part_die
->lowpc
= DW_ADDR (&attr
);
9838 has_high_pc_attr
= 1;
9839 part_die
->highpc
= DW_ADDR (&attr
);
9841 case DW_AT_location
:
9842 /* Support the .debug_loc offsets. */
9843 if (attr_form_is_block (&attr
))
9845 part_die
->locdesc
= DW_BLOCK (&attr
);
9847 else if (attr_form_is_section_offset (&attr
))
9849 dwarf2_complex_location_expr_complaint ();
9853 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9854 "partial symbol information");
9857 case DW_AT_external
:
9858 part_die
->is_external
= DW_UNSND (&attr
);
9860 case DW_AT_declaration
:
9861 part_die
->is_declaration
= DW_UNSND (&attr
);
9864 part_die
->has_type
= 1;
9866 case DW_AT_abstract_origin
:
9867 case DW_AT_specification
:
9868 case DW_AT_extension
:
9869 part_die
->has_specification
= 1;
9870 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9873 /* Ignore absolute siblings, they might point outside of
9874 the current compile unit. */
9875 if (attr
.form
== DW_FORM_ref_addr
)
9876 complaint (&symfile_complaints
,
9877 _("ignoring absolute DW_AT_sibling"));
9879 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9881 case DW_AT_byte_size
:
9882 part_die
->has_byte_size
= 1;
9884 case DW_AT_calling_convention
:
9885 /* DWARF doesn't provide a way to identify a program's source-level
9886 entry point. DW_AT_calling_convention attributes are only meant
9887 to describe functions' calling conventions.
9889 However, because it's a necessary piece of information in
9890 Fortran, and because DW_CC_program is the only piece of debugging
9891 information whose definition refers to a 'main program' at all,
9892 several compilers have begun marking Fortran main programs with
9893 DW_CC_program --- even when those functions use the standard
9894 calling conventions.
9896 So until DWARF specifies a way to provide this information and
9897 compilers pick up the new representation, we'll support this
9899 if (DW_UNSND (&attr
) == DW_CC_program
9900 && cu
->language
== language_fortran
)
9902 set_main_name (part_die
->name
);
9904 /* As this DIE has a static linkage the name would be difficult
9905 to look up later. */
9906 language_of_main
= language_fortran
;
9914 if (has_low_pc_attr
&& has_high_pc_attr
)
9916 /* When using the GNU linker, .gnu.linkonce. sections are used to
9917 eliminate duplicate copies of functions and vtables and such.
9918 The linker will arbitrarily choose one and discard the others.
9919 The AT_*_pc values for such functions refer to local labels in
9920 these sections. If the section from that file was discarded, the
9921 labels are not in the output, so the relocs get a value of 0.
9922 If this is a discarded function, mark the pc bounds as invalid,
9923 so that GDB will ignore it. */
9924 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9926 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9928 complaint (&symfile_complaints
,
9929 _("DW_AT_low_pc %s is zero "
9930 "for DIE at 0x%x [in module %s]"),
9931 paddress (gdbarch
, part_die
->lowpc
),
9932 part_die
->offset
, cu
->objfile
->name
);
9934 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9935 else if (part_die
->lowpc
>= part_die
->highpc
)
9937 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9939 complaint (&symfile_complaints
,
9940 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9941 "for DIE at 0x%x [in module %s]"),
9942 paddress (gdbarch
, part_die
->lowpc
),
9943 paddress (gdbarch
, part_die
->highpc
),
9944 part_die
->offset
, cu
->objfile
->name
);
9947 part_die
->has_pc_info
= 1;
9953 /* Find a cached partial DIE at OFFSET in CU. */
9955 static struct partial_die_info
*
9956 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9958 struct partial_die_info
*lookup_die
= NULL
;
9959 struct partial_die_info part_die
;
9961 part_die
.offset
= offset
;
9962 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9967 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9968 except in the case of .debug_types DIEs which do not reference
9969 outside their CU (they do however referencing other types via
9970 DW_FORM_ref_sig8). */
9972 static struct partial_die_info
*
9973 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9975 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9976 struct partial_die_info
*pd
= NULL
;
9978 if (cu
->per_cu
->debug_type_section
)
9980 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9986 if (offset_in_cu_p (&cu
->header
, offset
))
9988 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9993 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9995 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9996 load_partial_comp_unit (per_cu
, cu
->objfile
);
9998 per_cu
->cu
->last_used
= 0;
9999 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10001 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10003 struct cleanup
*back_to
;
10004 struct partial_die_info comp_unit_die
;
10005 struct abbrev_info
*abbrev
;
10006 unsigned int bytes_read
;
10009 per_cu
->load_all_dies
= 1;
10011 /* Re-read the DIEs. */
10012 back_to
= make_cleanup (null_cleanup
, 0);
10013 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10015 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
10016 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10018 info_ptr
= (dwarf2_per_objfile
->info
.buffer
10019 + per_cu
->cu
->header
.offset
10020 + per_cu
->cu
->header
.first_die_offset
);
10021 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10022 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10023 per_cu
->cu
->objfile
->obfd
,
10024 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10026 if (comp_unit_die
.has_children
)
10027 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
10028 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10030 do_cleanups (back_to
);
10032 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10038 internal_error (__FILE__
, __LINE__
,
10039 _("could not find partial DIE 0x%x "
10040 "in cache [from module %s]\n"),
10041 offset
, bfd_get_filename (cu
->objfile
->obfd
));
10045 /* See if we can figure out if the class lives in a namespace. We do
10046 this by looking for a member function; its demangled name will
10047 contain namespace info, if there is any. */
10050 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10051 struct dwarf2_cu
*cu
)
10053 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10054 what template types look like, because the demangler
10055 frequently doesn't give the same name as the debug info. We
10056 could fix this by only using the demangled name to get the
10057 prefix (but see comment in read_structure_type). */
10059 struct partial_die_info
*real_pdi
;
10060 struct partial_die_info
*child_pdi
;
10062 /* If this DIE (this DIE's specification, if any) has a parent, then
10063 we should not do this. We'll prepend the parent's fully qualified
10064 name when we create the partial symbol. */
10066 real_pdi
= struct_pdi
;
10067 while (real_pdi
->has_specification
)
10068 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10070 if (real_pdi
->die_parent
!= NULL
)
10073 for (child_pdi
= struct_pdi
->die_child
;
10075 child_pdi
= child_pdi
->die_sibling
)
10077 if (child_pdi
->tag
== DW_TAG_subprogram
10078 && child_pdi
->linkage_name
!= NULL
)
10080 char *actual_class_name
10081 = language_class_name_from_physname (cu
->language_defn
,
10082 child_pdi
->linkage_name
);
10083 if (actual_class_name
!= NULL
)
10086 = obsavestring (actual_class_name
,
10087 strlen (actual_class_name
),
10088 &cu
->objfile
->objfile_obstack
);
10089 xfree (actual_class_name
);
10096 /* Adjust PART_DIE before generating a symbol for it. This function
10097 may set the is_external flag or change the DIE's name. */
10100 fixup_partial_die (struct partial_die_info
*part_die
,
10101 struct dwarf2_cu
*cu
)
10103 /* Once we've fixed up a die, there's no point in doing so again.
10104 This also avoids a memory leak if we were to call
10105 guess_partial_die_structure_name multiple times. */
10106 if (part_die
->fixup_called
)
10109 /* If we found a reference attribute and the DIE has no name, try
10110 to find a name in the referred to DIE. */
10112 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10114 struct partial_die_info
*spec_die
;
10116 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10118 fixup_partial_die (spec_die
, cu
);
10120 if (spec_die
->name
)
10122 part_die
->name
= spec_die
->name
;
10124 /* Copy DW_AT_external attribute if it is set. */
10125 if (spec_die
->is_external
)
10126 part_die
->is_external
= spec_die
->is_external
;
10130 /* Set default names for some unnamed DIEs. */
10132 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10133 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10135 /* If there is no parent die to provide a namespace, and there are
10136 children, see if we can determine the namespace from their linkage
10138 NOTE: We need to do this even if cu->has_namespace_info != 0.
10139 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10140 if (cu
->language
== language_cplus
10141 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10142 && part_die
->die_parent
== NULL
10143 && part_die
->has_children
10144 && (part_die
->tag
== DW_TAG_class_type
10145 || part_die
->tag
== DW_TAG_structure_type
10146 || part_die
->tag
== DW_TAG_union_type
))
10147 guess_partial_die_structure_name (part_die
, cu
);
10149 /* GCC might emit a nameless struct or union that has a linkage
10150 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10151 if (part_die
->name
== NULL
10152 && (part_die
->tag
== DW_TAG_class_type
10153 || part_die
->tag
== DW_TAG_interface_type
10154 || part_die
->tag
== DW_TAG_structure_type
10155 || part_die
->tag
== DW_TAG_union_type
)
10156 && part_die
->linkage_name
!= NULL
)
10160 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10165 /* Strip any leading namespaces/classes, keep only the base name.
10166 DW_AT_name for named DIEs does not contain the prefixes. */
10167 base
= strrchr (demangled
, ':');
10168 if (base
&& base
> demangled
&& base
[-1] == ':')
10173 part_die
->name
= obsavestring (base
, strlen (base
),
10174 &cu
->objfile
->objfile_obstack
);
10179 part_die
->fixup_called
= 1;
10182 /* Read an attribute value described by an attribute form. */
10185 read_attribute_value (struct attribute
*attr
, unsigned form
,
10186 bfd
*abfd
, gdb_byte
*info_ptr
,
10187 struct dwarf2_cu
*cu
)
10189 struct comp_unit_head
*cu_header
= &cu
->header
;
10190 unsigned int bytes_read
;
10191 struct dwarf_block
*blk
;
10196 case DW_FORM_ref_addr
:
10197 if (cu
->header
.version
== 2)
10198 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10200 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10201 &cu
->header
, &bytes_read
);
10202 info_ptr
+= bytes_read
;
10205 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10206 info_ptr
+= bytes_read
;
10208 case DW_FORM_block2
:
10209 blk
= dwarf_alloc_block (cu
);
10210 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10212 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10213 info_ptr
+= blk
->size
;
10214 DW_BLOCK (attr
) = blk
;
10216 case DW_FORM_block4
:
10217 blk
= dwarf_alloc_block (cu
);
10218 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10220 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10221 info_ptr
+= blk
->size
;
10222 DW_BLOCK (attr
) = blk
;
10224 case DW_FORM_data2
:
10225 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10228 case DW_FORM_data4
:
10229 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10232 case DW_FORM_data8
:
10233 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10236 case DW_FORM_sec_offset
:
10237 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10238 info_ptr
+= bytes_read
;
10240 case DW_FORM_string
:
10241 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10242 DW_STRING_IS_CANONICAL (attr
) = 0;
10243 info_ptr
+= bytes_read
;
10246 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10248 DW_STRING_IS_CANONICAL (attr
) = 0;
10249 info_ptr
+= bytes_read
;
10251 case DW_FORM_exprloc
:
10252 case DW_FORM_block
:
10253 blk
= dwarf_alloc_block (cu
);
10254 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10255 info_ptr
+= bytes_read
;
10256 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10257 info_ptr
+= blk
->size
;
10258 DW_BLOCK (attr
) = blk
;
10260 case DW_FORM_block1
:
10261 blk
= dwarf_alloc_block (cu
);
10262 blk
->size
= read_1_byte (abfd
, info_ptr
);
10264 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10265 info_ptr
+= blk
->size
;
10266 DW_BLOCK (attr
) = blk
;
10268 case DW_FORM_data1
:
10269 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10273 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10276 case DW_FORM_flag_present
:
10277 DW_UNSND (attr
) = 1;
10279 case DW_FORM_sdata
:
10280 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10281 info_ptr
+= bytes_read
;
10283 case DW_FORM_udata
:
10284 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10285 info_ptr
+= bytes_read
;
10288 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10292 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10296 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10300 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10303 case DW_FORM_ref_sig8
:
10304 /* Convert the signature to something we can record in DW_UNSND
10306 NOTE: This is NULL if the type wasn't found. */
10307 DW_SIGNATURED_TYPE (attr
) =
10308 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10311 case DW_FORM_ref_udata
:
10312 DW_ADDR (attr
) = (cu
->header
.offset
10313 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10314 info_ptr
+= bytes_read
;
10316 case DW_FORM_indirect
:
10317 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10318 info_ptr
+= bytes_read
;
10319 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10322 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10323 dwarf_form_name (form
),
10324 bfd_get_filename (abfd
));
10327 /* We have seen instances where the compiler tried to emit a byte
10328 size attribute of -1 which ended up being encoded as an unsigned
10329 0xffffffff. Although 0xffffffff is technically a valid size value,
10330 an object of this size seems pretty unlikely so we can relatively
10331 safely treat these cases as if the size attribute was invalid and
10332 treat them as zero by default. */
10333 if (attr
->name
== DW_AT_byte_size
10334 && form
== DW_FORM_data4
10335 && DW_UNSND (attr
) >= 0xffffffff)
10338 (&symfile_complaints
,
10339 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10340 hex_string (DW_UNSND (attr
)));
10341 DW_UNSND (attr
) = 0;
10347 /* Read an attribute described by an abbreviated attribute. */
10350 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10351 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10353 attr
->name
= abbrev
->name
;
10354 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10357 /* Read dwarf information from a buffer. */
10359 static unsigned int
10360 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10362 return bfd_get_8 (abfd
, buf
);
10366 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10368 return bfd_get_signed_8 (abfd
, buf
);
10371 static unsigned int
10372 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10374 return bfd_get_16 (abfd
, buf
);
10378 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10380 return bfd_get_signed_16 (abfd
, buf
);
10383 static unsigned int
10384 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10386 return bfd_get_32 (abfd
, buf
);
10390 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10392 return bfd_get_signed_32 (abfd
, buf
);
10396 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10398 return bfd_get_64 (abfd
, buf
);
10402 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10403 unsigned int *bytes_read
)
10405 struct comp_unit_head
*cu_header
= &cu
->header
;
10406 CORE_ADDR retval
= 0;
10408 if (cu_header
->signed_addr_p
)
10410 switch (cu_header
->addr_size
)
10413 retval
= bfd_get_signed_16 (abfd
, buf
);
10416 retval
= bfd_get_signed_32 (abfd
, buf
);
10419 retval
= bfd_get_signed_64 (abfd
, buf
);
10422 internal_error (__FILE__
, __LINE__
,
10423 _("read_address: bad switch, signed [in module %s]"),
10424 bfd_get_filename (abfd
));
10429 switch (cu_header
->addr_size
)
10432 retval
= bfd_get_16 (abfd
, buf
);
10435 retval
= bfd_get_32 (abfd
, buf
);
10438 retval
= bfd_get_64 (abfd
, buf
);
10441 internal_error (__FILE__
, __LINE__
,
10442 _("read_address: bad switch, "
10443 "unsigned [in module %s]"),
10444 bfd_get_filename (abfd
));
10448 *bytes_read
= cu_header
->addr_size
;
10452 /* Read the initial length from a section. The (draft) DWARF 3
10453 specification allows the initial length to take up either 4 bytes
10454 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10455 bytes describe the length and all offsets will be 8 bytes in length
10458 An older, non-standard 64-bit format is also handled by this
10459 function. The older format in question stores the initial length
10460 as an 8-byte quantity without an escape value. Lengths greater
10461 than 2^32 aren't very common which means that the initial 4 bytes
10462 is almost always zero. Since a length value of zero doesn't make
10463 sense for the 32-bit format, this initial zero can be considered to
10464 be an escape value which indicates the presence of the older 64-bit
10465 format. As written, the code can't detect (old format) lengths
10466 greater than 4GB. If it becomes necessary to handle lengths
10467 somewhat larger than 4GB, we could allow other small values (such
10468 as the non-sensical values of 1, 2, and 3) to also be used as
10469 escape values indicating the presence of the old format.
10471 The value returned via bytes_read should be used to increment the
10472 relevant pointer after calling read_initial_length().
10474 [ Note: read_initial_length() and read_offset() are based on the
10475 document entitled "DWARF Debugging Information Format", revision
10476 3, draft 8, dated November 19, 2001. This document was obtained
10479 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10481 This document is only a draft and is subject to change. (So beware.)
10483 Details regarding the older, non-standard 64-bit format were
10484 determined empirically by examining 64-bit ELF files produced by
10485 the SGI toolchain on an IRIX 6.5 machine.
10487 - Kevin, July 16, 2002
10491 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10493 LONGEST length
= bfd_get_32 (abfd
, buf
);
10495 if (length
== 0xffffffff)
10497 length
= bfd_get_64 (abfd
, buf
+ 4);
10500 else if (length
== 0)
10502 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10503 length
= bfd_get_64 (abfd
, buf
);
10514 /* Cover function for read_initial_length.
10515 Returns the length of the object at BUF, and stores the size of the
10516 initial length in *BYTES_READ and stores the size that offsets will be in
10518 If the initial length size is not equivalent to that specified in
10519 CU_HEADER then issue a complaint.
10520 This is useful when reading non-comp-unit headers. */
10523 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10524 const struct comp_unit_head
*cu_header
,
10525 unsigned int *bytes_read
,
10526 unsigned int *offset_size
)
10528 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10530 gdb_assert (cu_header
->initial_length_size
== 4
10531 || cu_header
->initial_length_size
== 8
10532 || cu_header
->initial_length_size
== 12);
10534 if (cu_header
->initial_length_size
!= *bytes_read
)
10535 complaint (&symfile_complaints
,
10536 _("intermixed 32-bit and 64-bit DWARF sections"));
10538 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10542 /* Read an offset from the data stream. The size of the offset is
10543 given by cu_header->offset_size. */
10546 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10547 unsigned int *bytes_read
)
10549 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10551 *bytes_read
= cu_header
->offset_size
;
10555 /* Read an offset from the data stream. */
10558 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10560 LONGEST retval
= 0;
10562 switch (offset_size
)
10565 retval
= bfd_get_32 (abfd
, buf
);
10568 retval
= bfd_get_64 (abfd
, buf
);
10571 internal_error (__FILE__
, __LINE__
,
10572 _("read_offset_1: bad switch [in module %s]"),
10573 bfd_get_filename (abfd
));
10580 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10582 /* If the size of a host char is 8 bits, we can return a pointer
10583 to the buffer, otherwise we have to copy the data to a buffer
10584 allocated on the temporary obstack. */
10585 gdb_assert (HOST_CHAR_BIT
== 8);
10590 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10592 /* If the size of a host char is 8 bits, we can return a pointer
10593 to the string, otherwise we have to copy the string to a buffer
10594 allocated on the temporary obstack. */
10595 gdb_assert (HOST_CHAR_BIT
== 8);
10598 *bytes_read_ptr
= 1;
10601 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10602 return (char *) buf
;
10606 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10608 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10609 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10610 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10611 bfd_get_filename (abfd
));
10612 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10613 error (_("DW_FORM_strp pointing outside of "
10614 ".debug_str section [in module %s]"),
10615 bfd_get_filename (abfd
));
10616 gdb_assert (HOST_CHAR_BIT
== 8);
10617 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10619 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10623 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10624 const struct comp_unit_head
*cu_header
,
10625 unsigned int *bytes_read_ptr
)
10627 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10629 return read_indirect_string_at_offset (abfd
, str_offset
);
10632 static unsigned long
10633 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10635 unsigned long result
;
10636 unsigned int num_read
;
10638 unsigned char byte
;
10646 byte
= bfd_get_8 (abfd
, buf
);
10649 result
|= ((unsigned long)(byte
& 127) << shift
);
10650 if ((byte
& 128) == 0)
10656 *bytes_read_ptr
= num_read
;
10661 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10664 int i
, shift
, num_read
;
10665 unsigned char byte
;
10673 byte
= bfd_get_8 (abfd
, buf
);
10676 result
|= ((long)(byte
& 127) << shift
);
10678 if ((byte
& 128) == 0)
10683 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10684 result
|= -(((long)1) << shift
);
10685 *bytes_read_ptr
= num_read
;
10689 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10692 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10698 byte
= bfd_get_8 (abfd
, buf
);
10700 if ((byte
& 128) == 0)
10706 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10713 cu
->language
= language_c
;
10715 case DW_LANG_C_plus_plus
:
10716 cu
->language
= language_cplus
;
10719 cu
->language
= language_d
;
10721 case DW_LANG_Fortran77
:
10722 case DW_LANG_Fortran90
:
10723 case DW_LANG_Fortran95
:
10724 cu
->language
= language_fortran
;
10726 case DW_LANG_Mips_Assembler
:
10727 cu
->language
= language_asm
;
10730 cu
->language
= language_java
;
10732 case DW_LANG_Ada83
:
10733 case DW_LANG_Ada95
:
10734 cu
->language
= language_ada
;
10736 case DW_LANG_Modula2
:
10737 cu
->language
= language_m2
;
10739 case DW_LANG_Pascal83
:
10740 cu
->language
= language_pascal
;
10743 cu
->language
= language_objc
;
10745 case DW_LANG_Cobol74
:
10746 case DW_LANG_Cobol85
:
10748 cu
->language
= language_minimal
;
10751 cu
->language_defn
= language_def (cu
->language
);
10754 /* Return the named attribute or NULL if not there. */
10756 static struct attribute
*
10757 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10760 struct attribute
*spec
= NULL
;
10762 for (i
= 0; i
< die
->num_attrs
; ++i
)
10764 if (die
->attrs
[i
].name
== name
)
10765 return &die
->attrs
[i
];
10766 if (die
->attrs
[i
].name
== DW_AT_specification
10767 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10768 spec
= &die
->attrs
[i
];
10773 die
= follow_die_ref (die
, spec
, &cu
);
10774 return dwarf2_attr (die
, name
, cu
);
10780 /* Return the named attribute or NULL if not there,
10781 but do not follow DW_AT_specification, etc.
10782 This is for use in contexts where we're reading .debug_types dies.
10783 Following DW_AT_specification, DW_AT_abstract_origin will take us
10784 back up the chain, and we want to go down. */
10786 static struct attribute
*
10787 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10788 struct dwarf2_cu
*cu
)
10792 for (i
= 0; i
< die
->num_attrs
; ++i
)
10793 if (die
->attrs
[i
].name
== name
)
10794 return &die
->attrs
[i
];
10799 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10800 and holds a non-zero value. This function should only be used for
10801 DW_FORM_flag or DW_FORM_flag_present attributes. */
10804 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10806 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10808 return (attr
&& DW_UNSND (attr
));
10812 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10814 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10815 which value is non-zero. However, we have to be careful with
10816 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10817 (via dwarf2_flag_true_p) follows this attribute. So we may
10818 end up accidently finding a declaration attribute that belongs
10819 to a different DIE referenced by the specification attribute,
10820 even though the given DIE does not have a declaration attribute. */
10821 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10822 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10825 /* Return the die giving the specification for DIE, if there is
10826 one. *SPEC_CU is the CU containing DIE on input, and the CU
10827 containing the return value on output. If there is no
10828 specification, but there is an abstract origin, that is
10831 static struct die_info
*
10832 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10834 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10837 if (spec_attr
== NULL
)
10838 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10840 if (spec_attr
== NULL
)
10843 return follow_die_ref (die
, spec_attr
, spec_cu
);
10846 /* Free the line_header structure *LH, and any arrays and strings it
10848 NOTE: This is also used as a "cleanup" function. */
10851 free_line_header (struct line_header
*lh
)
10853 if (lh
->standard_opcode_lengths
)
10854 xfree (lh
->standard_opcode_lengths
);
10856 /* Remember that all the lh->file_names[i].name pointers are
10857 pointers into debug_line_buffer, and don't need to be freed. */
10858 if (lh
->file_names
)
10859 xfree (lh
->file_names
);
10861 /* Similarly for the include directory names. */
10862 if (lh
->include_dirs
)
10863 xfree (lh
->include_dirs
);
10868 /* Add an entry to LH's include directory table. */
10871 add_include_dir (struct line_header
*lh
, char *include_dir
)
10873 /* Grow the array if necessary. */
10874 if (lh
->include_dirs_size
== 0)
10876 lh
->include_dirs_size
= 1; /* for testing */
10877 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10878 * sizeof (*lh
->include_dirs
));
10880 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10882 lh
->include_dirs_size
*= 2;
10883 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10884 (lh
->include_dirs_size
10885 * sizeof (*lh
->include_dirs
)));
10888 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10891 /* Add an entry to LH's file name table. */
10894 add_file_name (struct line_header
*lh
,
10896 unsigned int dir_index
,
10897 unsigned int mod_time
,
10898 unsigned int length
)
10900 struct file_entry
*fe
;
10902 /* Grow the array if necessary. */
10903 if (lh
->file_names_size
== 0)
10905 lh
->file_names_size
= 1; /* for testing */
10906 lh
->file_names
= xmalloc (lh
->file_names_size
10907 * sizeof (*lh
->file_names
));
10909 else if (lh
->num_file_names
>= lh
->file_names_size
)
10911 lh
->file_names_size
*= 2;
10912 lh
->file_names
= xrealloc (lh
->file_names
,
10913 (lh
->file_names_size
10914 * sizeof (*lh
->file_names
)));
10917 fe
= &lh
->file_names
[lh
->num_file_names
++];
10919 fe
->dir_index
= dir_index
;
10920 fe
->mod_time
= mod_time
;
10921 fe
->length
= length
;
10922 fe
->included_p
= 0;
10926 /* Read the statement program header starting at OFFSET in
10927 .debug_line, according to the endianness of ABFD. Return a pointer
10928 to a struct line_header, allocated using xmalloc.
10930 NOTE: the strings in the include directory and file name tables of
10931 the returned object point into debug_line_buffer, and must not be
10934 static struct line_header
*
10935 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10936 struct dwarf2_cu
*cu
)
10938 struct cleanup
*back_to
;
10939 struct line_header
*lh
;
10940 gdb_byte
*line_ptr
;
10941 unsigned int bytes_read
, offset_size
;
10943 char *cur_dir
, *cur_file
;
10945 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10946 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10948 complaint (&symfile_complaints
, _("missing .debug_line section"));
10952 /* Make sure that at least there's room for the total_length field.
10953 That could be 12 bytes long, but we're just going to fudge that. */
10954 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10956 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10960 lh
= xmalloc (sizeof (*lh
));
10961 memset (lh
, 0, sizeof (*lh
));
10962 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10965 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10967 /* Read in the header. */
10969 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10970 &bytes_read
, &offset_size
);
10971 line_ptr
+= bytes_read
;
10972 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10973 + dwarf2_per_objfile
->line
.size
))
10975 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10978 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10979 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10981 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10982 line_ptr
+= offset_size
;
10983 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10985 if (lh
->version
>= 4)
10987 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10991 lh
->maximum_ops_per_instruction
= 1;
10993 if (lh
->maximum_ops_per_instruction
== 0)
10995 lh
->maximum_ops_per_instruction
= 1;
10996 complaint (&symfile_complaints
,
10997 _("invalid maximum_ops_per_instruction "
10998 "in `.debug_line' section"));
11001 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11003 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11005 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11007 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11009 lh
->standard_opcode_lengths
11010 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11012 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11013 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11015 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11019 /* Read directory table. */
11020 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11022 line_ptr
+= bytes_read
;
11023 add_include_dir (lh
, cur_dir
);
11025 line_ptr
+= bytes_read
;
11027 /* Read file name table. */
11028 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11030 unsigned int dir_index
, mod_time
, length
;
11032 line_ptr
+= bytes_read
;
11033 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11034 line_ptr
+= bytes_read
;
11035 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11036 line_ptr
+= bytes_read
;
11037 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11038 line_ptr
+= bytes_read
;
11040 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11042 line_ptr
+= bytes_read
;
11043 lh
->statement_program_start
= line_ptr
;
11045 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11046 + dwarf2_per_objfile
->line
.size
))
11047 complaint (&symfile_complaints
,
11048 _("line number info header doesn't "
11049 "fit in `.debug_line' section"));
11051 discard_cleanups (back_to
);
11055 /* This function exists to work around a bug in certain compilers
11056 (particularly GCC 2.95), in which the first line number marker of a
11057 function does not show up until after the prologue, right before
11058 the second line number marker. This function shifts ADDRESS down
11059 to the beginning of the function if necessary, and is called on
11060 addresses passed to record_line. */
11063 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
11065 struct function_range
*fn
;
11067 /* Find the function_range containing address. */
11071 if (!cu
->cached_fn
)
11072 cu
->cached_fn
= cu
->first_fn
;
11074 fn
= cu
->cached_fn
;
11076 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11082 while (fn
&& fn
!= cu
->cached_fn
)
11083 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11093 if (address
!= fn
->lowpc
)
11094 complaint (&symfile_complaints
,
11095 _("misplaced first line number at 0x%lx for '%s'"),
11096 (unsigned long) address
, fn
->name
);
11101 /* Subroutine of dwarf_decode_lines to simplify it.
11102 Return the file name of the psymtab for included file FILE_INDEX
11103 in line header LH of PST.
11104 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11105 If space for the result is malloc'd, it will be freed by a cleanup.
11106 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11109 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11110 const struct partial_symtab
*pst
,
11111 const char *comp_dir
)
11113 const struct file_entry fe
= lh
->file_names
[file_index
];
11114 char *include_name
= fe
.name
;
11115 char *include_name_to_compare
= include_name
;
11116 char *dir_name
= NULL
;
11117 const char *pst_filename
;
11118 char *copied_name
= NULL
;
11122 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11124 if (!IS_ABSOLUTE_PATH (include_name
)
11125 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11127 /* Avoid creating a duplicate psymtab for PST.
11128 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11129 Before we do the comparison, however, we need to account
11130 for DIR_NAME and COMP_DIR.
11131 First prepend dir_name (if non-NULL). If we still don't
11132 have an absolute path prepend comp_dir (if non-NULL).
11133 However, the directory we record in the include-file's
11134 psymtab does not contain COMP_DIR (to match the
11135 corresponding symtab(s)).
11140 bash$ gcc -g ./hello.c
11141 include_name = "hello.c"
11143 DW_AT_comp_dir = comp_dir = "/tmp"
11144 DW_AT_name = "./hello.c" */
11146 if (dir_name
!= NULL
)
11148 include_name
= concat (dir_name
, SLASH_STRING
,
11149 include_name
, (char *)NULL
);
11150 include_name_to_compare
= include_name
;
11151 make_cleanup (xfree
, include_name
);
11153 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11155 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11156 include_name
, (char *)NULL
);
11160 pst_filename
= pst
->filename
;
11161 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11163 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11164 pst_filename
, (char *)NULL
);
11165 pst_filename
= copied_name
;
11168 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11170 if (include_name_to_compare
!= include_name
)
11171 xfree (include_name_to_compare
);
11172 if (copied_name
!= NULL
)
11173 xfree (copied_name
);
11177 return include_name
;
11180 /* Ignore this record_line request. */
11183 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11188 /* Decode the Line Number Program (LNP) for the given line_header
11189 structure and CU. The actual information extracted and the type
11190 of structures created from the LNP depends on the value of PST.
11192 1. If PST is NULL, then this procedure uses the data from the program
11193 to create all necessary symbol tables, and their linetables.
11195 2. If PST is not NULL, this procedure reads the program to determine
11196 the list of files included by the unit represented by PST, and
11197 builds all the associated partial symbol tables.
11199 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11200 It is used for relative paths in the line table.
11201 NOTE: When processing partial symtabs (pst != NULL),
11202 comp_dir == pst->dirname.
11204 NOTE: It is important that psymtabs have the same file name (via strcmp)
11205 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11206 symtab we don't use it in the name of the psymtabs we create.
11207 E.g. expand_line_sal requires this when finding psymtabs to expand.
11208 A good testcase for this is mb-inline.exp. */
11211 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11212 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11214 gdb_byte
*line_ptr
, *extended_end
;
11215 gdb_byte
*line_end
;
11216 unsigned int bytes_read
, extended_len
;
11217 unsigned char op_code
, extended_op
, adj_opcode
;
11218 CORE_ADDR baseaddr
;
11219 struct objfile
*objfile
= cu
->objfile
;
11220 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11221 const int decode_for_pst_p
= (pst
!= NULL
);
11222 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11223 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11226 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11228 line_ptr
= lh
->statement_program_start
;
11229 line_end
= lh
->statement_program_end
;
11231 /* Read the statement sequences until there's nothing left. */
11232 while (line_ptr
< line_end
)
11234 /* state machine registers */
11235 CORE_ADDR address
= 0;
11236 unsigned int file
= 1;
11237 unsigned int line
= 1;
11238 unsigned int column
= 0;
11239 int is_stmt
= lh
->default_is_stmt
;
11240 int basic_block
= 0;
11241 int end_sequence
= 0;
11243 unsigned char op_index
= 0;
11245 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11247 /* Start a subfile for the current file of the state machine. */
11248 /* lh->include_dirs and lh->file_names are 0-based, but the
11249 directory and file name numbers in the statement program
11251 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11255 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11257 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11260 /* Decode the table. */
11261 while (!end_sequence
)
11263 op_code
= read_1_byte (abfd
, line_ptr
);
11265 if (line_ptr
> line_end
)
11267 dwarf2_debug_line_missing_end_sequence_complaint ();
11271 if (op_code
>= lh
->opcode_base
)
11273 /* Special operand. */
11274 adj_opcode
= op_code
- lh
->opcode_base
;
11275 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11276 / lh
->maximum_ops_per_instruction
)
11277 * lh
->minimum_instruction_length
);
11278 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11279 % lh
->maximum_ops_per_instruction
);
11280 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11281 if (lh
->num_file_names
< file
|| file
== 0)
11282 dwarf2_debug_line_missing_file_complaint ();
11283 /* For now we ignore lines not starting on an
11284 instruction boundary. */
11285 else if (op_index
== 0)
11287 lh
->file_names
[file
- 1].included_p
= 1;
11288 if (!decode_for_pst_p
&& is_stmt
)
11290 if (last_subfile
!= current_subfile
)
11292 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11294 (*p_record_line
) (last_subfile
, 0, addr
);
11295 last_subfile
= current_subfile
;
11297 /* Append row to matrix using current values. */
11298 addr
= check_cu_functions (address
, cu
);
11299 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11300 (*p_record_line
) (current_subfile
, line
, addr
);
11305 else switch (op_code
)
11307 case DW_LNS_extended_op
:
11308 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11310 line_ptr
+= bytes_read
;
11311 extended_end
= line_ptr
+ extended_len
;
11312 extended_op
= read_1_byte (abfd
, line_ptr
);
11314 switch (extended_op
)
11316 case DW_LNE_end_sequence
:
11317 p_record_line
= record_line
;
11320 case DW_LNE_set_address
:
11321 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11323 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11325 /* This line table is for a function which has been
11326 GCd by the linker. Ignore it. PR gdb/12528 */
11329 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11331 complaint (&symfile_complaints
,
11332 _(".debug_line address at offset 0x%lx is 0 "
11334 line_offset
, cu
->objfile
->name
);
11335 p_record_line
= noop_record_line
;
11339 line_ptr
+= bytes_read
;
11340 address
+= baseaddr
;
11342 case DW_LNE_define_file
:
11345 unsigned int dir_index
, mod_time
, length
;
11347 cur_file
= read_direct_string (abfd
, line_ptr
,
11349 line_ptr
+= bytes_read
;
11351 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11352 line_ptr
+= bytes_read
;
11354 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11355 line_ptr
+= bytes_read
;
11357 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11358 line_ptr
+= bytes_read
;
11359 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11362 case DW_LNE_set_discriminator
:
11363 /* The discriminator is not interesting to the debugger;
11365 line_ptr
= extended_end
;
11368 complaint (&symfile_complaints
,
11369 _("mangled .debug_line section"));
11372 /* Make sure that we parsed the extended op correctly. If e.g.
11373 we expected a different address size than the producer used,
11374 we may have read the wrong number of bytes. */
11375 if (line_ptr
!= extended_end
)
11377 complaint (&symfile_complaints
,
11378 _("mangled .debug_line section"));
11383 if (lh
->num_file_names
< file
|| file
== 0)
11384 dwarf2_debug_line_missing_file_complaint ();
11387 lh
->file_names
[file
- 1].included_p
= 1;
11388 if (!decode_for_pst_p
&& is_stmt
)
11390 if (last_subfile
!= current_subfile
)
11392 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11394 (*p_record_line
) (last_subfile
, 0, addr
);
11395 last_subfile
= current_subfile
;
11397 addr
= check_cu_functions (address
, cu
);
11398 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11399 (*p_record_line
) (current_subfile
, line
, addr
);
11404 case DW_LNS_advance_pc
:
11407 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11409 address
+= (((op_index
+ adjust
)
11410 / lh
->maximum_ops_per_instruction
)
11411 * lh
->minimum_instruction_length
);
11412 op_index
= ((op_index
+ adjust
)
11413 % lh
->maximum_ops_per_instruction
);
11414 line_ptr
+= bytes_read
;
11417 case DW_LNS_advance_line
:
11418 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11419 line_ptr
+= bytes_read
;
11421 case DW_LNS_set_file
:
11423 /* The arrays lh->include_dirs and lh->file_names are
11424 0-based, but the directory and file name numbers in
11425 the statement program are 1-based. */
11426 struct file_entry
*fe
;
11429 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11430 line_ptr
+= bytes_read
;
11431 if (lh
->num_file_names
< file
|| file
== 0)
11432 dwarf2_debug_line_missing_file_complaint ();
11435 fe
= &lh
->file_names
[file
- 1];
11437 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11438 if (!decode_for_pst_p
)
11440 last_subfile
= current_subfile
;
11441 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11446 case DW_LNS_set_column
:
11447 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11448 line_ptr
+= bytes_read
;
11450 case DW_LNS_negate_stmt
:
11451 is_stmt
= (!is_stmt
);
11453 case DW_LNS_set_basic_block
:
11456 /* Add to the address register of the state machine the
11457 address increment value corresponding to special opcode
11458 255. I.e., this value is scaled by the minimum
11459 instruction length since special opcode 255 would have
11460 scaled the increment. */
11461 case DW_LNS_const_add_pc
:
11463 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11465 address
+= (((op_index
+ adjust
)
11466 / lh
->maximum_ops_per_instruction
)
11467 * lh
->minimum_instruction_length
);
11468 op_index
= ((op_index
+ adjust
)
11469 % lh
->maximum_ops_per_instruction
);
11472 case DW_LNS_fixed_advance_pc
:
11473 address
+= read_2_bytes (abfd
, line_ptr
);
11479 /* Unknown standard opcode, ignore it. */
11482 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11484 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11485 line_ptr
+= bytes_read
;
11490 if (lh
->num_file_names
< file
|| file
== 0)
11491 dwarf2_debug_line_missing_file_complaint ();
11494 lh
->file_names
[file
- 1].included_p
= 1;
11495 if (!decode_for_pst_p
)
11497 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11498 (*p_record_line
) (current_subfile
, 0, addr
);
11503 if (decode_for_pst_p
)
11507 /* Now that we're done scanning the Line Header Program, we can
11508 create the psymtab of each included file. */
11509 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11510 if (lh
->file_names
[file_index
].included_p
== 1)
11512 char *include_name
=
11513 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11514 if (include_name
!= NULL
)
11515 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11520 /* Make sure a symtab is created for every file, even files
11521 which contain only variables (i.e. no code with associated
11525 struct file_entry
*fe
;
11527 for (i
= 0; i
< lh
->num_file_names
; i
++)
11531 fe
= &lh
->file_names
[i
];
11533 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11534 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11536 /* Skip the main file; we don't need it, and it must be
11537 allocated last, so that it will show up before the
11538 non-primary symtabs in the objfile's symtab list. */
11539 if (current_subfile
== first_subfile
)
11542 if (current_subfile
->symtab
== NULL
)
11543 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11545 fe
->symtab
= current_subfile
->symtab
;
11550 /* Start a subfile for DWARF. FILENAME is the name of the file and
11551 DIRNAME the name of the source directory which contains FILENAME
11552 or NULL if not known. COMP_DIR is the compilation directory for the
11553 linetable's compilation unit or NULL if not known.
11554 This routine tries to keep line numbers from identical absolute and
11555 relative file names in a common subfile.
11557 Using the `list' example from the GDB testsuite, which resides in
11558 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11559 of /srcdir/list0.c yields the following debugging information for list0.c:
11561 DW_AT_name: /srcdir/list0.c
11562 DW_AT_comp_dir: /compdir
11563 files.files[0].name: list0.h
11564 files.files[0].dir: /srcdir
11565 files.files[1].name: list0.c
11566 files.files[1].dir: /srcdir
11568 The line number information for list0.c has to end up in a single
11569 subfile, so that `break /srcdir/list0.c:1' works as expected.
11570 start_subfile will ensure that this happens provided that we pass the
11571 concatenation of files.files[1].dir and files.files[1].name as the
11575 dwarf2_start_subfile (char *filename
, const char *dirname
,
11576 const char *comp_dir
)
11580 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11581 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11582 second argument to start_subfile. To be consistent, we do the
11583 same here. In order not to lose the line information directory,
11584 we concatenate it to the filename when it makes sense.
11585 Note that the Dwarf3 standard says (speaking of filenames in line
11586 information): ``The directory index is ignored for file names
11587 that represent full path names''. Thus ignoring dirname in the
11588 `else' branch below isn't an issue. */
11590 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11591 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11593 fullname
= filename
;
11595 start_subfile (fullname
, comp_dir
);
11597 if (fullname
!= filename
)
11602 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11603 struct dwarf2_cu
*cu
)
11605 struct objfile
*objfile
= cu
->objfile
;
11606 struct comp_unit_head
*cu_header
= &cu
->header
;
11608 /* NOTE drow/2003-01-30: There used to be a comment and some special
11609 code here to turn a symbol with DW_AT_external and a
11610 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11611 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11612 with some versions of binutils) where shared libraries could have
11613 relocations against symbols in their debug information - the
11614 minimal symbol would have the right address, but the debug info
11615 would not. It's no longer necessary, because we will explicitly
11616 apply relocations when we read in the debug information now. */
11618 /* A DW_AT_location attribute with no contents indicates that a
11619 variable has been optimized away. */
11620 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11622 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11626 /* Handle one degenerate form of location expression specially, to
11627 preserve GDB's previous behavior when section offsets are
11628 specified. If this is just a DW_OP_addr then mark this symbol
11631 if (attr_form_is_block (attr
)
11632 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11633 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11635 unsigned int dummy
;
11637 SYMBOL_VALUE_ADDRESS (sym
) =
11638 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11639 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11640 fixup_symbol_section (sym
, objfile
);
11641 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11642 SYMBOL_SECTION (sym
));
11646 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11647 expression evaluator, and use LOC_COMPUTED only when necessary
11648 (i.e. when the value of a register or memory location is
11649 referenced, or a thread-local block, etc.). Then again, it might
11650 not be worthwhile. I'm assuming that it isn't unless performance
11651 or memory numbers show me otherwise. */
11653 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11654 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11656 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11657 cu
->has_loclist
= 1;
11660 /* Given a pointer to a DWARF information entry, figure out if we need
11661 to make a symbol table entry for it, and if so, create a new entry
11662 and return a pointer to it.
11663 If TYPE is NULL, determine symbol type from the die, otherwise
11664 used the passed type.
11665 If SPACE is not NULL, use it to hold the new symbol. If it is
11666 NULL, allocate a new symbol on the objfile's obstack. */
11668 static struct symbol
*
11669 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11670 struct symbol
*space
)
11672 struct objfile
*objfile
= cu
->objfile
;
11673 struct symbol
*sym
= NULL
;
11675 struct attribute
*attr
= NULL
;
11676 struct attribute
*attr2
= NULL
;
11677 CORE_ADDR baseaddr
;
11678 struct pending
**list_to_add
= NULL
;
11680 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11682 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11684 name
= dwarf2_name (die
, cu
);
11687 const char *linkagename
;
11688 int suppress_add
= 0;
11693 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11694 OBJSTAT (objfile
, n_syms
++);
11696 /* Cache this symbol's name and the name's demangled form (if any). */
11697 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11698 linkagename
= dwarf2_physname (name
, die
, cu
);
11699 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11701 /* Fortran does not have mangling standard and the mangling does differ
11702 between gfortran, iFort etc. */
11703 if (cu
->language
== language_fortran
11704 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11705 symbol_set_demangled_name (&(sym
->ginfo
),
11706 (char *) dwarf2_full_name (name
, die
, cu
),
11709 /* Default assumptions.
11710 Use the passed type or decode it from the die. */
11711 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11712 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11714 SYMBOL_TYPE (sym
) = type
;
11716 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11717 attr
= dwarf2_attr (die
,
11718 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11722 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11725 attr
= dwarf2_attr (die
,
11726 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11730 int file_index
= DW_UNSND (attr
);
11732 if (cu
->line_header
== NULL
11733 || file_index
> cu
->line_header
->num_file_names
)
11734 complaint (&symfile_complaints
,
11735 _("file index out of range"));
11736 else if (file_index
> 0)
11738 struct file_entry
*fe
;
11740 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11741 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11748 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11751 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11753 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11754 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11755 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11756 add_symbol_to_list (sym
, cu
->list_in_scope
);
11758 case DW_TAG_subprogram
:
11759 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11761 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11762 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11763 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11764 || cu
->language
== language_ada
)
11766 /* Subprograms marked external are stored as a global symbol.
11767 Ada subprograms, whether marked external or not, are always
11768 stored as a global symbol, because we want to be able to
11769 access them globally. For instance, we want to be able
11770 to break on a nested subprogram without having to
11771 specify the context. */
11772 list_to_add
= &global_symbols
;
11776 list_to_add
= cu
->list_in_scope
;
11779 case DW_TAG_inlined_subroutine
:
11780 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11782 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11783 SYMBOL_INLINED (sym
) = 1;
11784 /* Do not add the symbol to any lists. It will be found via
11785 BLOCK_FUNCTION from the blockvector. */
11787 case DW_TAG_template_value_param
:
11789 /* Fall through. */
11790 case DW_TAG_constant
:
11791 case DW_TAG_variable
:
11792 case DW_TAG_member
:
11793 /* Compilation with minimal debug info may result in
11794 variables with missing type entries. Change the
11795 misleading `void' type to something sensible. */
11796 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11798 = objfile_type (objfile
)->nodebug_data_symbol
;
11800 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11801 /* In the case of DW_TAG_member, we should only be called for
11802 static const members. */
11803 if (die
->tag
== DW_TAG_member
)
11805 /* dwarf2_add_field uses die_is_declaration,
11806 so we do the same. */
11807 gdb_assert (die_is_declaration (die
, cu
));
11812 dwarf2_const_value (attr
, sym
, cu
);
11813 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11816 if (attr2
&& (DW_UNSND (attr2
) != 0))
11817 list_to_add
= &global_symbols
;
11819 list_to_add
= cu
->list_in_scope
;
11823 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11826 var_decode_location (attr
, sym
, cu
);
11827 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11828 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11829 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11830 && !dwarf2_per_objfile
->has_section_at_zero
)
11832 /* When a static variable is eliminated by the linker,
11833 the corresponding debug information is not stripped
11834 out, but the variable address is set to null;
11835 do not add such variables into symbol table. */
11837 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11839 /* Workaround gfortran PR debug/40040 - it uses
11840 DW_AT_location for variables in -fPIC libraries which may
11841 get overriden by other libraries/executable and get
11842 a different address. Resolve it by the minimal symbol
11843 which may come from inferior's executable using copy
11844 relocation. Make this workaround only for gfortran as for
11845 other compilers GDB cannot guess the minimal symbol
11846 Fortran mangling kind. */
11847 if (cu
->language
== language_fortran
&& die
->parent
11848 && die
->parent
->tag
== DW_TAG_module
11850 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11851 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11853 /* A variable with DW_AT_external is never static,
11854 but it may be block-scoped. */
11855 list_to_add
= (cu
->list_in_scope
== &file_symbols
11856 ? &global_symbols
: cu
->list_in_scope
);
11859 list_to_add
= cu
->list_in_scope
;
11863 /* We do not know the address of this symbol.
11864 If it is an external symbol and we have type information
11865 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11866 The address of the variable will then be determined from
11867 the minimal symbol table whenever the variable is
11869 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11870 if (attr2
&& (DW_UNSND (attr2
) != 0)
11871 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11873 /* A variable with DW_AT_external is never static, but it
11874 may be block-scoped. */
11875 list_to_add
= (cu
->list_in_scope
== &file_symbols
11876 ? &global_symbols
: cu
->list_in_scope
);
11878 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11880 else if (!die_is_declaration (die
, cu
))
11882 /* Use the default LOC_OPTIMIZED_OUT class. */
11883 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11885 list_to_add
= cu
->list_in_scope
;
11889 case DW_TAG_formal_parameter
:
11890 /* If we are inside a function, mark this as an argument. If
11891 not, we might be looking at an argument to an inlined function
11892 when we do not have enough information to show inlined frames;
11893 pretend it's a local variable in that case so that the user can
11895 if (context_stack_depth
> 0
11896 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11897 SYMBOL_IS_ARGUMENT (sym
) = 1;
11898 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11901 var_decode_location (attr
, sym
, cu
);
11903 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11906 dwarf2_const_value (attr
, sym
, cu
);
11909 list_to_add
= cu
->list_in_scope
;
11911 case DW_TAG_unspecified_parameters
:
11912 /* From varargs functions; gdb doesn't seem to have any
11913 interest in this information, so just ignore it for now.
11916 case DW_TAG_template_type_param
:
11918 /* Fall through. */
11919 case DW_TAG_class_type
:
11920 case DW_TAG_interface_type
:
11921 case DW_TAG_structure_type
:
11922 case DW_TAG_union_type
:
11923 case DW_TAG_set_type
:
11924 case DW_TAG_enumeration_type
:
11925 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11926 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11929 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11930 really ever be static objects: otherwise, if you try
11931 to, say, break of a class's method and you're in a file
11932 which doesn't mention that class, it won't work unless
11933 the check for all static symbols in lookup_symbol_aux
11934 saves you. See the OtherFileClass tests in
11935 gdb.c++/namespace.exp. */
11939 list_to_add
= (cu
->list_in_scope
== &file_symbols
11940 && (cu
->language
== language_cplus
11941 || cu
->language
== language_java
)
11942 ? &global_symbols
: cu
->list_in_scope
);
11944 /* The semantics of C++ state that "struct foo {
11945 ... }" also defines a typedef for "foo". A Java
11946 class declaration also defines a typedef for the
11948 if (cu
->language
== language_cplus
11949 || cu
->language
== language_java
11950 || cu
->language
== language_ada
)
11952 /* The symbol's name is already allocated along
11953 with this objfile, so we don't need to
11954 duplicate it for the type. */
11955 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11956 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11961 case DW_TAG_typedef
:
11962 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11963 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11964 list_to_add
= cu
->list_in_scope
;
11966 case DW_TAG_base_type
:
11967 case DW_TAG_subrange_type
:
11968 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11969 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11970 list_to_add
= cu
->list_in_scope
;
11972 case DW_TAG_enumerator
:
11973 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11976 dwarf2_const_value (attr
, sym
, cu
);
11979 /* NOTE: carlton/2003-11-10: See comment above in the
11980 DW_TAG_class_type, etc. block. */
11982 list_to_add
= (cu
->list_in_scope
== &file_symbols
11983 && (cu
->language
== language_cplus
11984 || cu
->language
== language_java
)
11985 ? &global_symbols
: cu
->list_in_scope
);
11988 case DW_TAG_namespace
:
11989 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11990 list_to_add
= &global_symbols
;
11993 /* Not a tag we recognize. Hopefully we aren't processing
11994 trash data, but since we must specifically ignore things
11995 we don't recognize, there is nothing else we should do at
11997 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11998 dwarf_tag_name (die
->tag
));
12004 sym
->hash_next
= objfile
->template_symbols
;
12005 objfile
->template_symbols
= sym
;
12006 list_to_add
= NULL
;
12009 if (list_to_add
!= NULL
)
12010 add_symbol_to_list (sym
, list_to_add
);
12012 /* For the benefit of old versions of GCC, check for anonymous
12013 namespaces based on the demangled name. */
12014 if (!processing_has_namespace_info
12015 && cu
->language
== language_cplus
)
12016 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12021 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12023 static struct symbol
*
12024 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12026 return new_symbol_full (die
, type
, cu
, NULL
);
12029 /* Given an attr with a DW_FORM_dataN value in host byte order,
12030 zero-extend it as appropriate for the symbol's type. The DWARF
12031 standard (v4) is not entirely clear about the meaning of using
12032 DW_FORM_dataN for a constant with a signed type, where the type is
12033 wider than the data. The conclusion of a discussion on the DWARF
12034 list was that this is unspecified. We choose to always zero-extend
12035 because that is the interpretation long in use by GCC. */
12038 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12039 const char *name
, struct obstack
*obstack
,
12040 struct dwarf2_cu
*cu
, long *value
, int bits
)
12042 struct objfile
*objfile
= cu
->objfile
;
12043 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12044 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12045 LONGEST l
= DW_UNSND (attr
);
12047 if (bits
< sizeof (*value
) * 8)
12049 l
&= ((LONGEST
) 1 << bits
) - 1;
12052 else if (bits
== sizeof (*value
) * 8)
12056 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12057 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12064 /* Read a constant value from an attribute. Either set *VALUE, or if
12065 the value does not fit in *VALUE, set *BYTES - either already
12066 allocated on the objfile obstack, or newly allocated on OBSTACK,
12067 or, set *BATON, if we translated the constant to a location
12071 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12072 const char *name
, struct obstack
*obstack
,
12073 struct dwarf2_cu
*cu
,
12074 long *value
, gdb_byte
**bytes
,
12075 struct dwarf2_locexpr_baton
**baton
)
12077 struct objfile
*objfile
= cu
->objfile
;
12078 struct comp_unit_head
*cu_header
= &cu
->header
;
12079 struct dwarf_block
*blk
;
12080 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12081 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12087 switch (attr
->form
)
12093 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12094 dwarf2_const_value_length_mismatch_complaint (name
,
12095 cu_header
->addr_size
,
12096 TYPE_LENGTH (type
));
12097 /* Symbols of this form are reasonably rare, so we just
12098 piggyback on the existing location code rather than writing
12099 a new implementation of symbol_computed_ops. */
12100 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12101 sizeof (struct dwarf2_locexpr_baton
));
12102 (*baton
)->per_cu
= cu
->per_cu
;
12103 gdb_assert ((*baton
)->per_cu
);
12105 (*baton
)->size
= 2 + cu_header
->addr_size
;
12106 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12107 (*baton
)->data
= data
;
12109 data
[0] = DW_OP_addr
;
12110 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12111 byte_order
, DW_ADDR (attr
));
12112 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12115 case DW_FORM_string
:
12117 /* DW_STRING is already allocated on the objfile obstack, point
12119 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12121 case DW_FORM_block1
:
12122 case DW_FORM_block2
:
12123 case DW_FORM_block4
:
12124 case DW_FORM_block
:
12125 case DW_FORM_exprloc
:
12126 blk
= DW_BLOCK (attr
);
12127 if (TYPE_LENGTH (type
) != blk
->size
)
12128 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12129 TYPE_LENGTH (type
));
12130 *bytes
= blk
->data
;
12133 /* The DW_AT_const_value attributes are supposed to carry the
12134 symbol's value "represented as it would be on the target
12135 architecture." By the time we get here, it's already been
12136 converted to host endianness, so we just need to sign- or
12137 zero-extend it as appropriate. */
12138 case DW_FORM_data1
:
12139 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12140 obstack
, cu
, value
, 8);
12142 case DW_FORM_data2
:
12143 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12144 obstack
, cu
, value
, 16);
12146 case DW_FORM_data4
:
12147 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12148 obstack
, cu
, value
, 32);
12150 case DW_FORM_data8
:
12151 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12152 obstack
, cu
, value
, 64);
12155 case DW_FORM_sdata
:
12156 *value
= DW_SND (attr
);
12159 case DW_FORM_udata
:
12160 *value
= DW_UNSND (attr
);
12164 complaint (&symfile_complaints
,
12165 _("unsupported const value attribute form: '%s'"),
12166 dwarf_form_name (attr
->form
));
12173 /* Copy constant value from an attribute to a symbol. */
12176 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12177 struct dwarf2_cu
*cu
)
12179 struct objfile
*objfile
= cu
->objfile
;
12180 struct comp_unit_head
*cu_header
= &cu
->header
;
12183 struct dwarf2_locexpr_baton
*baton
;
12185 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12186 SYMBOL_PRINT_NAME (sym
),
12187 &objfile
->objfile_obstack
, cu
,
12188 &value
, &bytes
, &baton
);
12192 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12193 SYMBOL_LOCATION_BATON (sym
) = baton
;
12194 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12196 else if (bytes
!= NULL
)
12198 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12199 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12203 SYMBOL_VALUE (sym
) = value
;
12204 SYMBOL_CLASS (sym
) = LOC_CONST
;
12208 /* Return the type of the die in question using its DW_AT_type attribute. */
12210 static struct type
*
12211 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12213 struct attribute
*type_attr
;
12215 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12218 /* A missing DW_AT_type represents a void type. */
12219 return objfile_type (cu
->objfile
)->builtin_void
;
12222 return lookup_die_type (die
, type_attr
, cu
);
12225 /* True iff CU's producer generates GNAT Ada auxiliary information
12226 that allows to find parallel types through that information instead
12227 of having to do expensive parallel lookups by type name. */
12230 need_gnat_info (struct dwarf2_cu
*cu
)
12232 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12233 of GNAT produces this auxiliary information, without any indication
12234 that it is produced. Part of enhancing the FSF version of GNAT
12235 to produce that information will be to put in place an indicator
12236 that we can use in order to determine whether the descriptive type
12237 info is available or not. One suggestion that has been made is
12238 to use a new attribute, attached to the CU die. For now, assume
12239 that the descriptive type info is not available. */
12243 /* Return the auxiliary type of the die in question using its
12244 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12245 attribute is not present. */
12247 static struct type
*
12248 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12250 struct attribute
*type_attr
;
12252 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12256 return lookup_die_type (die
, type_attr
, cu
);
12259 /* If DIE has a descriptive_type attribute, then set the TYPE's
12260 descriptive type accordingly. */
12263 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12264 struct dwarf2_cu
*cu
)
12266 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12268 if (descriptive_type
)
12270 ALLOCATE_GNAT_AUX_TYPE (type
);
12271 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12275 /* Return the containing type of the die in question using its
12276 DW_AT_containing_type attribute. */
12278 static struct type
*
12279 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12281 struct attribute
*type_attr
;
12283 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12285 error (_("Dwarf Error: Problem turning containing type into gdb type "
12286 "[in module %s]"), cu
->objfile
->name
);
12288 return lookup_die_type (die
, type_attr
, cu
);
12291 /* Look up the type of DIE in CU using its type attribute ATTR.
12292 If there is no type substitute an error marker. */
12294 static struct type
*
12295 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12296 struct dwarf2_cu
*cu
)
12298 struct type
*this_type
;
12300 /* First see if we have it cached. */
12302 if (is_ref_attr (attr
))
12304 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12306 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12308 else if (attr
->form
== DW_FORM_ref_sig8
)
12310 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12311 struct dwarf2_cu
*sig_cu
;
12312 unsigned int offset
;
12314 /* sig_type will be NULL if the signatured type is missing from
12316 if (sig_type
== NULL
)
12317 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12318 "at 0x%x [in module %s]"),
12319 die
->offset
, cu
->objfile
->name
);
12321 gdb_assert (sig_type
->per_cu
.debug_type_section
);
12322 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12323 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12327 dump_die_for_error (die
);
12328 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12329 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
12332 /* If not cached we need to read it in. */
12334 if (this_type
== NULL
)
12336 struct die_info
*type_die
;
12337 struct dwarf2_cu
*type_cu
= cu
;
12339 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12340 /* If the type is cached, we should have found it above. */
12341 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12342 this_type
= read_type_die_1 (type_die
, type_cu
);
12345 /* If we still don't have a type use an error marker. */
12347 if (this_type
== NULL
)
12349 char *message
, *saved
;
12351 /* read_type_die already issued a complaint. */
12352 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12356 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12357 message
, strlen (message
));
12360 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12366 /* Return the type in DIE, CU.
12367 Returns NULL for invalid types.
12369 This first does a lookup in the appropriate type_hash table,
12370 and only reads the die in if necessary.
12372 NOTE: This can be called when reading in partial or full symbols. */
12374 static struct type
*
12375 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12377 struct type
*this_type
;
12379 this_type
= get_die_type (die
, cu
);
12383 return read_type_die_1 (die
, cu
);
12386 /* Read the type in DIE, CU.
12387 Returns NULL for invalid types. */
12389 static struct type
*
12390 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12392 struct type
*this_type
= NULL
;
12396 case DW_TAG_class_type
:
12397 case DW_TAG_interface_type
:
12398 case DW_TAG_structure_type
:
12399 case DW_TAG_union_type
:
12400 this_type
= read_structure_type (die
, cu
);
12402 case DW_TAG_enumeration_type
:
12403 this_type
= read_enumeration_type (die
, cu
);
12405 case DW_TAG_subprogram
:
12406 case DW_TAG_subroutine_type
:
12407 case DW_TAG_inlined_subroutine
:
12408 this_type
= read_subroutine_type (die
, cu
);
12410 case DW_TAG_array_type
:
12411 this_type
= read_array_type (die
, cu
);
12413 case DW_TAG_set_type
:
12414 this_type
= read_set_type (die
, cu
);
12416 case DW_TAG_pointer_type
:
12417 this_type
= read_tag_pointer_type (die
, cu
);
12419 case DW_TAG_ptr_to_member_type
:
12420 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12422 case DW_TAG_reference_type
:
12423 this_type
= read_tag_reference_type (die
, cu
);
12425 case DW_TAG_const_type
:
12426 this_type
= read_tag_const_type (die
, cu
);
12428 case DW_TAG_volatile_type
:
12429 this_type
= read_tag_volatile_type (die
, cu
);
12431 case DW_TAG_string_type
:
12432 this_type
= read_tag_string_type (die
, cu
);
12434 case DW_TAG_typedef
:
12435 this_type
= read_typedef (die
, cu
);
12437 case DW_TAG_subrange_type
:
12438 this_type
= read_subrange_type (die
, cu
);
12440 case DW_TAG_base_type
:
12441 this_type
= read_base_type (die
, cu
);
12443 case DW_TAG_unspecified_type
:
12444 this_type
= read_unspecified_type (die
, cu
);
12446 case DW_TAG_namespace
:
12447 this_type
= read_namespace_type (die
, cu
);
12449 case DW_TAG_module
:
12450 this_type
= read_module_type (die
, cu
);
12453 complaint (&symfile_complaints
,
12454 _("unexpected tag in read_type_die: '%s'"),
12455 dwarf_tag_name (die
->tag
));
12462 /* See if we can figure out if the class lives in a namespace. We do
12463 this by looking for a member function; its demangled name will
12464 contain namespace info, if there is any.
12465 Return the computed name or NULL.
12466 Space for the result is allocated on the objfile's obstack.
12467 This is the full-die version of guess_partial_die_structure_name.
12468 In this case we know DIE has no useful parent. */
12471 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12473 struct die_info
*spec_die
;
12474 struct dwarf2_cu
*spec_cu
;
12475 struct die_info
*child
;
12478 spec_die
= die_specification (die
, &spec_cu
);
12479 if (spec_die
!= NULL
)
12485 for (child
= die
->child
;
12487 child
= child
->sibling
)
12489 if (child
->tag
== DW_TAG_subprogram
)
12491 struct attribute
*attr
;
12493 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12495 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12499 = language_class_name_from_physname (cu
->language_defn
,
12503 if (actual_name
!= NULL
)
12505 char *die_name
= dwarf2_name (die
, cu
);
12507 if (die_name
!= NULL
12508 && strcmp (die_name
, actual_name
) != 0)
12510 /* Strip off the class name from the full name.
12511 We want the prefix. */
12512 int die_name_len
= strlen (die_name
);
12513 int actual_name_len
= strlen (actual_name
);
12515 /* Test for '::' as a sanity check. */
12516 if (actual_name_len
> die_name_len
+ 2
12517 && actual_name
[actual_name_len
12518 - die_name_len
- 1] == ':')
12520 obsavestring (actual_name
,
12521 actual_name_len
- die_name_len
- 2,
12522 &cu
->objfile
->objfile_obstack
);
12525 xfree (actual_name
);
12534 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12535 prefix part in such case. See
12536 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12539 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12541 struct attribute
*attr
;
12544 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12545 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12548 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12549 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12552 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12554 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12555 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12558 /* dwarf2_name had to be already called. */
12559 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12561 /* Strip the base name, keep any leading namespaces/classes. */
12562 base
= strrchr (DW_STRING (attr
), ':');
12563 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12566 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12567 &cu
->objfile
->objfile_obstack
);
12570 /* Return the name of the namespace/class that DIE is defined within,
12571 or "" if we can't tell. The caller should not xfree the result.
12573 For example, if we're within the method foo() in the following
12583 then determine_prefix on foo's die will return "N::C". */
12586 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12588 struct die_info
*parent
, *spec_die
;
12589 struct dwarf2_cu
*spec_cu
;
12590 struct type
*parent_type
;
12593 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12594 && cu
->language
!= language_fortran
)
12597 retval
= anonymous_struct_prefix (die
, cu
);
12601 /* We have to be careful in the presence of DW_AT_specification.
12602 For example, with GCC 3.4, given the code
12606 // Definition of N::foo.
12610 then we'll have a tree of DIEs like this:
12612 1: DW_TAG_compile_unit
12613 2: DW_TAG_namespace // N
12614 3: DW_TAG_subprogram // declaration of N::foo
12615 4: DW_TAG_subprogram // definition of N::foo
12616 DW_AT_specification // refers to die #3
12618 Thus, when processing die #4, we have to pretend that we're in
12619 the context of its DW_AT_specification, namely the contex of die
12622 spec_die
= die_specification (die
, &spec_cu
);
12623 if (spec_die
== NULL
)
12624 parent
= die
->parent
;
12627 parent
= spec_die
->parent
;
12631 if (parent
== NULL
)
12633 else if (parent
->building_fullname
)
12636 const char *parent_name
;
12638 /* It has been seen on RealView 2.2 built binaries,
12639 DW_TAG_template_type_param types actually _defined_ as
12640 children of the parent class:
12643 template class <class Enum> Class{};
12644 Class<enum E> class_e;
12646 1: DW_TAG_class_type (Class)
12647 2: DW_TAG_enumeration_type (E)
12648 3: DW_TAG_enumerator (enum1:0)
12649 3: DW_TAG_enumerator (enum2:1)
12651 2: DW_TAG_template_type_param
12652 DW_AT_type DW_FORM_ref_udata (E)
12654 Besides being broken debug info, it can put GDB into an
12655 infinite loop. Consider:
12657 When we're building the full name for Class<E>, we'll start
12658 at Class, and go look over its template type parameters,
12659 finding E. We'll then try to build the full name of E, and
12660 reach here. We're now trying to build the full name of E,
12661 and look over the parent DIE for containing scope. In the
12662 broken case, if we followed the parent DIE of E, we'd again
12663 find Class, and once again go look at its template type
12664 arguments, etc., etc. Simply don't consider such parent die
12665 as source-level parent of this die (it can't be, the language
12666 doesn't allow it), and break the loop here. */
12667 name
= dwarf2_name (die
, cu
);
12668 parent_name
= dwarf2_name (parent
, cu
);
12669 complaint (&symfile_complaints
,
12670 _("template param type '%s' defined within parent '%s'"),
12671 name
? name
: "<unknown>",
12672 parent_name
? parent_name
: "<unknown>");
12676 switch (parent
->tag
)
12678 case DW_TAG_namespace
:
12679 parent_type
= read_type_die (parent
, cu
);
12680 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12681 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12682 Work around this problem here. */
12683 if (cu
->language
== language_cplus
12684 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12686 /* We give a name to even anonymous namespaces. */
12687 return TYPE_TAG_NAME (parent_type
);
12688 case DW_TAG_class_type
:
12689 case DW_TAG_interface_type
:
12690 case DW_TAG_structure_type
:
12691 case DW_TAG_union_type
:
12692 case DW_TAG_module
:
12693 parent_type
= read_type_die (parent
, cu
);
12694 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12695 return TYPE_TAG_NAME (parent_type
);
12697 /* An anonymous structure is only allowed non-static data
12698 members; no typedefs, no member functions, et cetera.
12699 So it does not need a prefix. */
12701 case DW_TAG_compile_unit
:
12702 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12703 if (cu
->language
== language_cplus
12704 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12705 && die
->child
!= NULL
12706 && (die
->tag
== DW_TAG_class_type
12707 || die
->tag
== DW_TAG_structure_type
12708 || die
->tag
== DW_TAG_union_type
))
12710 char *name
= guess_full_die_structure_name (die
, cu
);
12716 return determine_prefix (parent
, cu
);
12720 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12721 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12722 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12723 an obconcat, otherwise allocate storage for the result. The CU argument is
12724 used to determine the language and hence, the appropriate separator. */
12726 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12729 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12730 int physname
, struct dwarf2_cu
*cu
)
12732 const char *lead
= "";
12735 if (suffix
== NULL
|| suffix
[0] == '\0'
12736 || prefix
== NULL
|| prefix
[0] == '\0')
12738 else if (cu
->language
== language_java
)
12740 else if (cu
->language
== language_fortran
&& physname
)
12742 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12743 DW_AT_MIPS_linkage_name is preferred and used instead. */
12751 if (prefix
== NULL
)
12753 if (suffix
== NULL
)
12759 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12761 strcpy (retval
, lead
);
12762 strcat (retval
, prefix
);
12763 strcat (retval
, sep
);
12764 strcat (retval
, suffix
);
12769 /* We have an obstack. */
12770 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12774 /* Return sibling of die, NULL if no sibling. */
12776 static struct die_info
*
12777 sibling_die (struct die_info
*die
)
12779 return die
->sibling
;
12782 /* Get name of a die, return NULL if not found. */
12785 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12786 struct obstack
*obstack
)
12788 if (name
&& cu
->language
== language_cplus
)
12790 char *canon_name
= cp_canonicalize_string (name
);
12792 if (canon_name
!= NULL
)
12794 if (strcmp (canon_name
, name
) != 0)
12795 name
= obsavestring (canon_name
, strlen (canon_name
),
12797 xfree (canon_name
);
12804 /* Get name of a die, return NULL if not found. */
12807 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12809 struct attribute
*attr
;
12811 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12812 if ((!attr
|| !DW_STRING (attr
))
12813 && die
->tag
!= DW_TAG_class_type
12814 && die
->tag
!= DW_TAG_interface_type
12815 && die
->tag
!= DW_TAG_structure_type
12816 && die
->tag
!= DW_TAG_union_type
)
12821 case DW_TAG_compile_unit
:
12822 /* Compilation units have a DW_AT_name that is a filename, not
12823 a source language identifier. */
12824 case DW_TAG_enumeration_type
:
12825 case DW_TAG_enumerator
:
12826 /* These tags always have simple identifiers already; no need
12827 to canonicalize them. */
12828 return DW_STRING (attr
);
12830 case DW_TAG_subprogram
:
12831 /* Java constructors will all be named "<init>", so return
12832 the class name when we see this special case. */
12833 if (cu
->language
== language_java
12834 && DW_STRING (attr
) != NULL
12835 && strcmp (DW_STRING (attr
), "<init>") == 0)
12837 struct dwarf2_cu
*spec_cu
= cu
;
12838 struct die_info
*spec_die
;
12840 /* GCJ will output '<init>' for Java constructor names.
12841 For this special case, return the name of the parent class. */
12843 /* GCJ may output suprogram DIEs with AT_specification set.
12844 If so, use the name of the specified DIE. */
12845 spec_die
= die_specification (die
, &spec_cu
);
12846 if (spec_die
!= NULL
)
12847 return dwarf2_name (spec_die
, spec_cu
);
12852 if (die
->tag
== DW_TAG_class_type
)
12853 return dwarf2_name (die
, cu
);
12855 while (die
->tag
!= DW_TAG_compile_unit
);
12859 case DW_TAG_class_type
:
12860 case DW_TAG_interface_type
:
12861 case DW_TAG_structure_type
:
12862 case DW_TAG_union_type
:
12863 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12864 structures or unions. These were of the form "._%d" in GCC 4.1,
12865 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12866 and GCC 4.4. We work around this problem by ignoring these. */
12867 if (attr
&& DW_STRING (attr
)
12868 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12869 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12872 /* GCC might emit a nameless typedef that has a linkage name. See
12873 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12874 if (!attr
|| DW_STRING (attr
) == NULL
)
12876 char *demangled
= NULL
;
12878 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12880 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12882 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12885 /* Avoid demangling DW_STRING (attr) the second time on a second
12886 call for the same DIE. */
12887 if (!DW_STRING_IS_CANONICAL (attr
))
12888 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12894 /* FIXME: we already did this for the partial symbol... */
12895 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12896 &cu
->objfile
->objfile_obstack
);
12897 DW_STRING_IS_CANONICAL (attr
) = 1;
12900 /* Strip any leading namespaces/classes, keep only the base name.
12901 DW_AT_name for named DIEs does not contain the prefixes. */
12902 base
= strrchr (DW_STRING (attr
), ':');
12903 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12906 return DW_STRING (attr
);
12915 if (!DW_STRING_IS_CANONICAL (attr
))
12918 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12919 &cu
->objfile
->objfile_obstack
);
12920 DW_STRING_IS_CANONICAL (attr
) = 1;
12922 return DW_STRING (attr
);
12925 /* Return the die that this die in an extension of, or NULL if there
12926 is none. *EXT_CU is the CU containing DIE on input, and the CU
12927 containing the return value on output. */
12929 static struct die_info
*
12930 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12932 struct attribute
*attr
;
12934 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12938 return follow_die_ref (die
, attr
, ext_cu
);
12941 /* Convert a DIE tag into its string name. */
12944 dwarf_tag_name (unsigned tag
)
12948 case DW_TAG_padding
:
12949 return "DW_TAG_padding";
12950 case DW_TAG_array_type
:
12951 return "DW_TAG_array_type";
12952 case DW_TAG_class_type
:
12953 return "DW_TAG_class_type";
12954 case DW_TAG_entry_point
:
12955 return "DW_TAG_entry_point";
12956 case DW_TAG_enumeration_type
:
12957 return "DW_TAG_enumeration_type";
12958 case DW_TAG_formal_parameter
:
12959 return "DW_TAG_formal_parameter";
12960 case DW_TAG_imported_declaration
:
12961 return "DW_TAG_imported_declaration";
12963 return "DW_TAG_label";
12964 case DW_TAG_lexical_block
:
12965 return "DW_TAG_lexical_block";
12966 case DW_TAG_member
:
12967 return "DW_TAG_member";
12968 case DW_TAG_pointer_type
:
12969 return "DW_TAG_pointer_type";
12970 case DW_TAG_reference_type
:
12971 return "DW_TAG_reference_type";
12972 case DW_TAG_compile_unit
:
12973 return "DW_TAG_compile_unit";
12974 case DW_TAG_string_type
:
12975 return "DW_TAG_string_type";
12976 case DW_TAG_structure_type
:
12977 return "DW_TAG_structure_type";
12978 case DW_TAG_subroutine_type
:
12979 return "DW_TAG_subroutine_type";
12980 case DW_TAG_typedef
:
12981 return "DW_TAG_typedef";
12982 case DW_TAG_union_type
:
12983 return "DW_TAG_union_type";
12984 case DW_TAG_unspecified_parameters
:
12985 return "DW_TAG_unspecified_parameters";
12986 case DW_TAG_variant
:
12987 return "DW_TAG_variant";
12988 case DW_TAG_common_block
:
12989 return "DW_TAG_common_block";
12990 case DW_TAG_common_inclusion
:
12991 return "DW_TAG_common_inclusion";
12992 case DW_TAG_inheritance
:
12993 return "DW_TAG_inheritance";
12994 case DW_TAG_inlined_subroutine
:
12995 return "DW_TAG_inlined_subroutine";
12996 case DW_TAG_module
:
12997 return "DW_TAG_module";
12998 case DW_TAG_ptr_to_member_type
:
12999 return "DW_TAG_ptr_to_member_type";
13000 case DW_TAG_set_type
:
13001 return "DW_TAG_set_type";
13002 case DW_TAG_subrange_type
:
13003 return "DW_TAG_subrange_type";
13004 case DW_TAG_with_stmt
:
13005 return "DW_TAG_with_stmt";
13006 case DW_TAG_access_declaration
:
13007 return "DW_TAG_access_declaration";
13008 case DW_TAG_base_type
:
13009 return "DW_TAG_base_type";
13010 case DW_TAG_catch_block
:
13011 return "DW_TAG_catch_block";
13012 case DW_TAG_const_type
:
13013 return "DW_TAG_const_type";
13014 case DW_TAG_constant
:
13015 return "DW_TAG_constant";
13016 case DW_TAG_enumerator
:
13017 return "DW_TAG_enumerator";
13018 case DW_TAG_file_type
:
13019 return "DW_TAG_file_type";
13020 case DW_TAG_friend
:
13021 return "DW_TAG_friend";
13022 case DW_TAG_namelist
:
13023 return "DW_TAG_namelist";
13024 case DW_TAG_namelist_item
:
13025 return "DW_TAG_namelist_item";
13026 case DW_TAG_packed_type
:
13027 return "DW_TAG_packed_type";
13028 case DW_TAG_subprogram
:
13029 return "DW_TAG_subprogram";
13030 case DW_TAG_template_type_param
:
13031 return "DW_TAG_template_type_param";
13032 case DW_TAG_template_value_param
:
13033 return "DW_TAG_template_value_param";
13034 case DW_TAG_thrown_type
:
13035 return "DW_TAG_thrown_type";
13036 case DW_TAG_try_block
:
13037 return "DW_TAG_try_block";
13038 case DW_TAG_variant_part
:
13039 return "DW_TAG_variant_part";
13040 case DW_TAG_variable
:
13041 return "DW_TAG_variable";
13042 case DW_TAG_volatile_type
:
13043 return "DW_TAG_volatile_type";
13044 case DW_TAG_dwarf_procedure
:
13045 return "DW_TAG_dwarf_procedure";
13046 case DW_TAG_restrict_type
:
13047 return "DW_TAG_restrict_type";
13048 case DW_TAG_interface_type
:
13049 return "DW_TAG_interface_type";
13050 case DW_TAG_namespace
:
13051 return "DW_TAG_namespace";
13052 case DW_TAG_imported_module
:
13053 return "DW_TAG_imported_module";
13054 case DW_TAG_unspecified_type
:
13055 return "DW_TAG_unspecified_type";
13056 case DW_TAG_partial_unit
:
13057 return "DW_TAG_partial_unit";
13058 case DW_TAG_imported_unit
:
13059 return "DW_TAG_imported_unit";
13060 case DW_TAG_condition
:
13061 return "DW_TAG_condition";
13062 case DW_TAG_shared_type
:
13063 return "DW_TAG_shared_type";
13064 case DW_TAG_type_unit
:
13065 return "DW_TAG_type_unit";
13066 case DW_TAG_MIPS_loop
:
13067 return "DW_TAG_MIPS_loop";
13068 case DW_TAG_HP_array_descriptor
:
13069 return "DW_TAG_HP_array_descriptor";
13070 case DW_TAG_format_label
:
13071 return "DW_TAG_format_label";
13072 case DW_TAG_function_template
:
13073 return "DW_TAG_function_template";
13074 case DW_TAG_class_template
:
13075 return "DW_TAG_class_template";
13076 case DW_TAG_GNU_BINCL
:
13077 return "DW_TAG_GNU_BINCL";
13078 case DW_TAG_GNU_EINCL
:
13079 return "DW_TAG_GNU_EINCL";
13080 case DW_TAG_upc_shared_type
:
13081 return "DW_TAG_upc_shared_type";
13082 case DW_TAG_upc_strict_type
:
13083 return "DW_TAG_upc_strict_type";
13084 case DW_TAG_upc_relaxed_type
:
13085 return "DW_TAG_upc_relaxed_type";
13086 case DW_TAG_PGI_kanji_type
:
13087 return "DW_TAG_PGI_kanji_type";
13088 case DW_TAG_PGI_interface_block
:
13089 return "DW_TAG_PGI_interface_block";
13090 case DW_TAG_GNU_call_site
:
13091 return "DW_TAG_GNU_call_site";
13093 return "DW_TAG_<unknown>";
13097 /* Convert a DWARF attribute code into its string name. */
13100 dwarf_attr_name (unsigned attr
)
13104 case DW_AT_sibling
:
13105 return "DW_AT_sibling";
13106 case DW_AT_location
:
13107 return "DW_AT_location";
13109 return "DW_AT_name";
13110 case DW_AT_ordering
:
13111 return "DW_AT_ordering";
13112 case DW_AT_subscr_data
:
13113 return "DW_AT_subscr_data";
13114 case DW_AT_byte_size
:
13115 return "DW_AT_byte_size";
13116 case DW_AT_bit_offset
:
13117 return "DW_AT_bit_offset";
13118 case DW_AT_bit_size
:
13119 return "DW_AT_bit_size";
13120 case DW_AT_element_list
:
13121 return "DW_AT_element_list";
13122 case DW_AT_stmt_list
:
13123 return "DW_AT_stmt_list";
13125 return "DW_AT_low_pc";
13126 case DW_AT_high_pc
:
13127 return "DW_AT_high_pc";
13128 case DW_AT_language
:
13129 return "DW_AT_language";
13131 return "DW_AT_member";
13133 return "DW_AT_discr";
13134 case DW_AT_discr_value
:
13135 return "DW_AT_discr_value";
13136 case DW_AT_visibility
:
13137 return "DW_AT_visibility";
13139 return "DW_AT_import";
13140 case DW_AT_string_length
:
13141 return "DW_AT_string_length";
13142 case DW_AT_common_reference
:
13143 return "DW_AT_common_reference";
13144 case DW_AT_comp_dir
:
13145 return "DW_AT_comp_dir";
13146 case DW_AT_const_value
:
13147 return "DW_AT_const_value";
13148 case DW_AT_containing_type
:
13149 return "DW_AT_containing_type";
13150 case DW_AT_default_value
:
13151 return "DW_AT_default_value";
13153 return "DW_AT_inline";
13154 case DW_AT_is_optional
:
13155 return "DW_AT_is_optional";
13156 case DW_AT_lower_bound
:
13157 return "DW_AT_lower_bound";
13158 case DW_AT_producer
:
13159 return "DW_AT_producer";
13160 case DW_AT_prototyped
:
13161 return "DW_AT_prototyped";
13162 case DW_AT_return_addr
:
13163 return "DW_AT_return_addr";
13164 case DW_AT_start_scope
:
13165 return "DW_AT_start_scope";
13166 case DW_AT_bit_stride
:
13167 return "DW_AT_bit_stride";
13168 case DW_AT_upper_bound
:
13169 return "DW_AT_upper_bound";
13170 case DW_AT_abstract_origin
:
13171 return "DW_AT_abstract_origin";
13172 case DW_AT_accessibility
:
13173 return "DW_AT_accessibility";
13174 case DW_AT_address_class
:
13175 return "DW_AT_address_class";
13176 case DW_AT_artificial
:
13177 return "DW_AT_artificial";
13178 case DW_AT_base_types
:
13179 return "DW_AT_base_types";
13180 case DW_AT_calling_convention
:
13181 return "DW_AT_calling_convention";
13183 return "DW_AT_count";
13184 case DW_AT_data_member_location
:
13185 return "DW_AT_data_member_location";
13186 case DW_AT_decl_column
:
13187 return "DW_AT_decl_column";
13188 case DW_AT_decl_file
:
13189 return "DW_AT_decl_file";
13190 case DW_AT_decl_line
:
13191 return "DW_AT_decl_line";
13192 case DW_AT_declaration
:
13193 return "DW_AT_declaration";
13194 case DW_AT_discr_list
:
13195 return "DW_AT_discr_list";
13196 case DW_AT_encoding
:
13197 return "DW_AT_encoding";
13198 case DW_AT_external
:
13199 return "DW_AT_external";
13200 case DW_AT_frame_base
:
13201 return "DW_AT_frame_base";
13203 return "DW_AT_friend";
13204 case DW_AT_identifier_case
:
13205 return "DW_AT_identifier_case";
13206 case DW_AT_macro_info
:
13207 return "DW_AT_macro_info";
13208 case DW_AT_namelist_items
:
13209 return "DW_AT_namelist_items";
13210 case DW_AT_priority
:
13211 return "DW_AT_priority";
13212 case DW_AT_segment
:
13213 return "DW_AT_segment";
13214 case DW_AT_specification
:
13215 return "DW_AT_specification";
13216 case DW_AT_static_link
:
13217 return "DW_AT_static_link";
13219 return "DW_AT_type";
13220 case DW_AT_use_location
:
13221 return "DW_AT_use_location";
13222 case DW_AT_variable_parameter
:
13223 return "DW_AT_variable_parameter";
13224 case DW_AT_virtuality
:
13225 return "DW_AT_virtuality";
13226 case DW_AT_vtable_elem_location
:
13227 return "DW_AT_vtable_elem_location";
13228 /* DWARF 3 values. */
13229 case DW_AT_allocated
:
13230 return "DW_AT_allocated";
13231 case DW_AT_associated
:
13232 return "DW_AT_associated";
13233 case DW_AT_data_location
:
13234 return "DW_AT_data_location";
13235 case DW_AT_byte_stride
:
13236 return "DW_AT_byte_stride";
13237 case DW_AT_entry_pc
:
13238 return "DW_AT_entry_pc";
13239 case DW_AT_use_UTF8
:
13240 return "DW_AT_use_UTF8";
13241 case DW_AT_extension
:
13242 return "DW_AT_extension";
13244 return "DW_AT_ranges";
13245 case DW_AT_trampoline
:
13246 return "DW_AT_trampoline";
13247 case DW_AT_call_column
:
13248 return "DW_AT_call_column";
13249 case DW_AT_call_file
:
13250 return "DW_AT_call_file";
13251 case DW_AT_call_line
:
13252 return "DW_AT_call_line";
13253 case DW_AT_description
:
13254 return "DW_AT_description";
13255 case DW_AT_binary_scale
:
13256 return "DW_AT_binary_scale";
13257 case DW_AT_decimal_scale
:
13258 return "DW_AT_decimal_scale";
13260 return "DW_AT_small";
13261 case DW_AT_decimal_sign
:
13262 return "DW_AT_decimal_sign";
13263 case DW_AT_digit_count
:
13264 return "DW_AT_digit_count";
13265 case DW_AT_picture_string
:
13266 return "DW_AT_picture_string";
13267 case DW_AT_mutable
:
13268 return "DW_AT_mutable";
13269 case DW_AT_threads_scaled
:
13270 return "DW_AT_threads_scaled";
13271 case DW_AT_explicit
:
13272 return "DW_AT_explicit";
13273 case DW_AT_object_pointer
:
13274 return "DW_AT_object_pointer";
13275 case DW_AT_endianity
:
13276 return "DW_AT_endianity";
13277 case DW_AT_elemental
:
13278 return "DW_AT_elemental";
13280 return "DW_AT_pure";
13281 case DW_AT_recursive
:
13282 return "DW_AT_recursive";
13283 /* DWARF 4 values. */
13284 case DW_AT_signature
:
13285 return "DW_AT_signature";
13286 case DW_AT_linkage_name
:
13287 return "DW_AT_linkage_name";
13288 /* SGI/MIPS extensions. */
13289 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13290 case DW_AT_MIPS_fde
:
13291 return "DW_AT_MIPS_fde";
13293 case DW_AT_MIPS_loop_begin
:
13294 return "DW_AT_MIPS_loop_begin";
13295 case DW_AT_MIPS_tail_loop_begin
:
13296 return "DW_AT_MIPS_tail_loop_begin";
13297 case DW_AT_MIPS_epilog_begin
:
13298 return "DW_AT_MIPS_epilog_begin";
13299 case DW_AT_MIPS_loop_unroll_factor
:
13300 return "DW_AT_MIPS_loop_unroll_factor";
13301 case DW_AT_MIPS_software_pipeline_depth
:
13302 return "DW_AT_MIPS_software_pipeline_depth";
13303 case DW_AT_MIPS_linkage_name
:
13304 return "DW_AT_MIPS_linkage_name";
13305 case DW_AT_MIPS_stride
:
13306 return "DW_AT_MIPS_stride";
13307 case DW_AT_MIPS_abstract_name
:
13308 return "DW_AT_MIPS_abstract_name";
13309 case DW_AT_MIPS_clone_origin
:
13310 return "DW_AT_MIPS_clone_origin";
13311 case DW_AT_MIPS_has_inlines
:
13312 return "DW_AT_MIPS_has_inlines";
13313 /* HP extensions. */
13314 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13315 case DW_AT_HP_block_index
:
13316 return "DW_AT_HP_block_index";
13318 case DW_AT_HP_unmodifiable
:
13319 return "DW_AT_HP_unmodifiable";
13320 case DW_AT_HP_actuals_stmt_list
:
13321 return "DW_AT_HP_actuals_stmt_list";
13322 case DW_AT_HP_proc_per_section
:
13323 return "DW_AT_HP_proc_per_section";
13324 case DW_AT_HP_raw_data_ptr
:
13325 return "DW_AT_HP_raw_data_ptr";
13326 case DW_AT_HP_pass_by_reference
:
13327 return "DW_AT_HP_pass_by_reference";
13328 case DW_AT_HP_opt_level
:
13329 return "DW_AT_HP_opt_level";
13330 case DW_AT_HP_prof_version_id
:
13331 return "DW_AT_HP_prof_version_id";
13332 case DW_AT_HP_opt_flags
:
13333 return "DW_AT_HP_opt_flags";
13334 case DW_AT_HP_cold_region_low_pc
:
13335 return "DW_AT_HP_cold_region_low_pc";
13336 case DW_AT_HP_cold_region_high_pc
:
13337 return "DW_AT_HP_cold_region_high_pc";
13338 case DW_AT_HP_all_variables_modifiable
:
13339 return "DW_AT_HP_all_variables_modifiable";
13340 case DW_AT_HP_linkage_name
:
13341 return "DW_AT_HP_linkage_name";
13342 case DW_AT_HP_prof_flags
:
13343 return "DW_AT_HP_prof_flags";
13344 /* GNU extensions. */
13345 case DW_AT_sf_names
:
13346 return "DW_AT_sf_names";
13347 case DW_AT_src_info
:
13348 return "DW_AT_src_info";
13349 case DW_AT_mac_info
:
13350 return "DW_AT_mac_info";
13351 case DW_AT_src_coords
:
13352 return "DW_AT_src_coords";
13353 case DW_AT_body_begin
:
13354 return "DW_AT_body_begin";
13355 case DW_AT_body_end
:
13356 return "DW_AT_body_end";
13357 case DW_AT_GNU_vector
:
13358 return "DW_AT_GNU_vector";
13359 case DW_AT_GNU_odr_signature
:
13360 return "DW_AT_GNU_odr_signature";
13361 /* VMS extensions. */
13362 case DW_AT_VMS_rtnbeg_pd_address
:
13363 return "DW_AT_VMS_rtnbeg_pd_address";
13364 /* UPC extension. */
13365 case DW_AT_upc_threads_scaled
:
13366 return "DW_AT_upc_threads_scaled";
13367 /* PGI (STMicroelectronics) extensions. */
13368 case DW_AT_PGI_lbase
:
13369 return "DW_AT_PGI_lbase";
13370 case DW_AT_PGI_soffset
:
13371 return "DW_AT_PGI_soffset";
13372 case DW_AT_PGI_lstride
:
13373 return "DW_AT_PGI_lstride";
13375 return "DW_AT_<unknown>";
13379 /* Convert a DWARF value form code into its string name. */
13382 dwarf_form_name (unsigned form
)
13387 return "DW_FORM_addr";
13388 case DW_FORM_block2
:
13389 return "DW_FORM_block2";
13390 case DW_FORM_block4
:
13391 return "DW_FORM_block4";
13392 case DW_FORM_data2
:
13393 return "DW_FORM_data2";
13394 case DW_FORM_data4
:
13395 return "DW_FORM_data4";
13396 case DW_FORM_data8
:
13397 return "DW_FORM_data8";
13398 case DW_FORM_string
:
13399 return "DW_FORM_string";
13400 case DW_FORM_block
:
13401 return "DW_FORM_block";
13402 case DW_FORM_block1
:
13403 return "DW_FORM_block1";
13404 case DW_FORM_data1
:
13405 return "DW_FORM_data1";
13407 return "DW_FORM_flag";
13408 case DW_FORM_sdata
:
13409 return "DW_FORM_sdata";
13411 return "DW_FORM_strp";
13412 case DW_FORM_udata
:
13413 return "DW_FORM_udata";
13414 case DW_FORM_ref_addr
:
13415 return "DW_FORM_ref_addr";
13417 return "DW_FORM_ref1";
13419 return "DW_FORM_ref2";
13421 return "DW_FORM_ref4";
13423 return "DW_FORM_ref8";
13424 case DW_FORM_ref_udata
:
13425 return "DW_FORM_ref_udata";
13426 case DW_FORM_indirect
:
13427 return "DW_FORM_indirect";
13428 case DW_FORM_sec_offset
:
13429 return "DW_FORM_sec_offset";
13430 case DW_FORM_exprloc
:
13431 return "DW_FORM_exprloc";
13432 case DW_FORM_flag_present
:
13433 return "DW_FORM_flag_present";
13434 case DW_FORM_ref_sig8
:
13435 return "DW_FORM_ref_sig8";
13437 return "DW_FORM_<unknown>";
13441 /* Convert a DWARF stack opcode into its string name. */
13444 dwarf_stack_op_name (unsigned op
)
13449 return "DW_OP_addr";
13451 return "DW_OP_deref";
13452 case DW_OP_const1u
:
13453 return "DW_OP_const1u";
13454 case DW_OP_const1s
:
13455 return "DW_OP_const1s";
13456 case DW_OP_const2u
:
13457 return "DW_OP_const2u";
13458 case DW_OP_const2s
:
13459 return "DW_OP_const2s";
13460 case DW_OP_const4u
:
13461 return "DW_OP_const4u";
13462 case DW_OP_const4s
:
13463 return "DW_OP_const4s";
13464 case DW_OP_const8u
:
13465 return "DW_OP_const8u";
13466 case DW_OP_const8s
:
13467 return "DW_OP_const8s";
13469 return "DW_OP_constu";
13471 return "DW_OP_consts";
13473 return "DW_OP_dup";
13475 return "DW_OP_drop";
13477 return "DW_OP_over";
13479 return "DW_OP_pick";
13481 return "DW_OP_swap";
13483 return "DW_OP_rot";
13485 return "DW_OP_xderef";
13487 return "DW_OP_abs";
13489 return "DW_OP_and";
13491 return "DW_OP_div";
13493 return "DW_OP_minus";
13495 return "DW_OP_mod";
13497 return "DW_OP_mul";
13499 return "DW_OP_neg";
13501 return "DW_OP_not";
13505 return "DW_OP_plus";
13506 case DW_OP_plus_uconst
:
13507 return "DW_OP_plus_uconst";
13509 return "DW_OP_shl";
13511 return "DW_OP_shr";
13513 return "DW_OP_shra";
13515 return "DW_OP_xor";
13517 return "DW_OP_bra";
13531 return "DW_OP_skip";
13533 return "DW_OP_lit0";
13535 return "DW_OP_lit1";
13537 return "DW_OP_lit2";
13539 return "DW_OP_lit3";
13541 return "DW_OP_lit4";
13543 return "DW_OP_lit5";
13545 return "DW_OP_lit6";
13547 return "DW_OP_lit7";
13549 return "DW_OP_lit8";
13551 return "DW_OP_lit9";
13553 return "DW_OP_lit10";
13555 return "DW_OP_lit11";
13557 return "DW_OP_lit12";
13559 return "DW_OP_lit13";
13561 return "DW_OP_lit14";
13563 return "DW_OP_lit15";
13565 return "DW_OP_lit16";
13567 return "DW_OP_lit17";
13569 return "DW_OP_lit18";
13571 return "DW_OP_lit19";
13573 return "DW_OP_lit20";
13575 return "DW_OP_lit21";
13577 return "DW_OP_lit22";
13579 return "DW_OP_lit23";
13581 return "DW_OP_lit24";
13583 return "DW_OP_lit25";
13585 return "DW_OP_lit26";
13587 return "DW_OP_lit27";
13589 return "DW_OP_lit28";
13591 return "DW_OP_lit29";
13593 return "DW_OP_lit30";
13595 return "DW_OP_lit31";
13597 return "DW_OP_reg0";
13599 return "DW_OP_reg1";
13601 return "DW_OP_reg2";
13603 return "DW_OP_reg3";
13605 return "DW_OP_reg4";
13607 return "DW_OP_reg5";
13609 return "DW_OP_reg6";
13611 return "DW_OP_reg7";
13613 return "DW_OP_reg8";
13615 return "DW_OP_reg9";
13617 return "DW_OP_reg10";
13619 return "DW_OP_reg11";
13621 return "DW_OP_reg12";
13623 return "DW_OP_reg13";
13625 return "DW_OP_reg14";
13627 return "DW_OP_reg15";
13629 return "DW_OP_reg16";
13631 return "DW_OP_reg17";
13633 return "DW_OP_reg18";
13635 return "DW_OP_reg19";
13637 return "DW_OP_reg20";
13639 return "DW_OP_reg21";
13641 return "DW_OP_reg22";
13643 return "DW_OP_reg23";
13645 return "DW_OP_reg24";
13647 return "DW_OP_reg25";
13649 return "DW_OP_reg26";
13651 return "DW_OP_reg27";
13653 return "DW_OP_reg28";
13655 return "DW_OP_reg29";
13657 return "DW_OP_reg30";
13659 return "DW_OP_reg31";
13661 return "DW_OP_breg0";
13663 return "DW_OP_breg1";
13665 return "DW_OP_breg2";
13667 return "DW_OP_breg3";
13669 return "DW_OP_breg4";
13671 return "DW_OP_breg5";
13673 return "DW_OP_breg6";
13675 return "DW_OP_breg7";
13677 return "DW_OP_breg8";
13679 return "DW_OP_breg9";
13681 return "DW_OP_breg10";
13683 return "DW_OP_breg11";
13685 return "DW_OP_breg12";
13687 return "DW_OP_breg13";
13689 return "DW_OP_breg14";
13691 return "DW_OP_breg15";
13693 return "DW_OP_breg16";
13695 return "DW_OP_breg17";
13697 return "DW_OP_breg18";
13699 return "DW_OP_breg19";
13701 return "DW_OP_breg20";
13703 return "DW_OP_breg21";
13705 return "DW_OP_breg22";
13707 return "DW_OP_breg23";
13709 return "DW_OP_breg24";
13711 return "DW_OP_breg25";
13713 return "DW_OP_breg26";
13715 return "DW_OP_breg27";
13717 return "DW_OP_breg28";
13719 return "DW_OP_breg29";
13721 return "DW_OP_breg30";
13723 return "DW_OP_breg31";
13725 return "DW_OP_regx";
13727 return "DW_OP_fbreg";
13729 return "DW_OP_bregx";
13731 return "DW_OP_piece";
13732 case DW_OP_deref_size
:
13733 return "DW_OP_deref_size";
13734 case DW_OP_xderef_size
:
13735 return "DW_OP_xderef_size";
13737 return "DW_OP_nop";
13738 /* DWARF 3 extensions. */
13739 case DW_OP_push_object_address
:
13740 return "DW_OP_push_object_address";
13742 return "DW_OP_call2";
13744 return "DW_OP_call4";
13745 case DW_OP_call_ref
:
13746 return "DW_OP_call_ref";
13747 case DW_OP_form_tls_address
:
13748 return "DW_OP_form_tls_address";
13749 case DW_OP_call_frame_cfa
:
13750 return "DW_OP_call_frame_cfa";
13751 case DW_OP_bit_piece
:
13752 return "DW_OP_bit_piece";
13753 /* DWARF 4 extensions. */
13754 case DW_OP_implicit_value
:
13755 return "DW_OP_implicit_value";
13756 case DW_OP_stack_value
:
13757 return "DW_OP_stack_value";
13758 /* GNU extensions. */
13759 case DW_OP_GNU_push_tls_address
:
13760 return "DW_OP_GNU_push_tls_address";
13761 case DW_OP_GNU_uninit
:
13762 return "DW_OP_GNU_uninit";
13763 case DW_OP_GNU_implicit_pointer
:
13764 return "DW_OP_GNU_implicit_pointer";
13765 case DW_OP_GNU_entry_value
:
13766 return "DW_OP_GNU_entry_value";
13767 case DW_OP_GNU_const_type
:
13768 return "DW_OP_GNU_const_type";
13769 case DW_OP_GNU_regval_type
:
13770 return "DW_OP_GNU_regval_type";
13771 case DW_OP_GNU_deref_type
:
13772 return "DW_OP_GNU_deref_type";
13773 case DW_OP_GNU_convert
:
13774 return "DW_OP_GNU_convert";
13775 case DW_OP_GNU_reinterpret
:
13776 return "DW_OP_GNU_reinterpret";
13783 dwarf_bool_name (unsigned mybool
)
13791 /* Convert a DWARF type code into its string name. */
13794 dwarf_type_encoding_name (unsigned enc
)
13799 return "DW_ATE_void";
13800 case DW_ATE_address
:
13801 return "DW_ATE_address";
13802 case DW_ATE_boolean
:
13803 return "DW_ATE_boolean";
13804 case DW_ATE_complex_float
:
13805 return "DW_ATE_complex_float";
13807 return "DW_ATE_float";
13808 case DW_ATE_signed
:
13809 return "DW_ATE_signed";
13810 case DW_ATE_signed_char
:
13811 return "DW_ATE_signed_char";
13812 case DW_ATE_unsigned
:
13813 return "DW_ATE_unsigned";
13814 case DW_ATE_unsigned_char
:
13815 return "DW_ATE_unsigned_char";
13817 case DW_ATE_imaginary_float
:
13818 return "DW_ATE_imaginary_float";
13819 case DW_ATE_packed_decimal
:
13820 return "DW_ATE_packed_decimal";
13821 case DW_ATE_numeric_string
:
13822 return "DW_ATE_numeric_string";
13823 case DW_ATE_edited
:
13824 return "DW_ATE_edited";
13825 case DW_ATE_signed_fixed
:
13826 return "DW_ATE_signed_fixed";
13827 case DW_ATE_unsigned_fixed
:
13828 return "DW_ATE_unsigned_fixed";
13829 case DW_ATE_decimal_float
:
13830 return "DW_ATE_decimal_float";
13833 return "DW_ATE_UTF";
13834 /* HP extensions. */
13835 case DW_ATE_HP_float80
:
13836 return "DW_ATE_HP_float80";
13837 case DW_ATE_HP_complex_float80
:
13838 return "DW_ATE_HP_complex_float80";
13839 case DW_ATE_HP_float128
:
13840 return "DW_ATE_HP_float128";
13841 case DW_ATE_HP_complex_float128
:
13842 return "DW_ATE_HP_complex_float128";
13843 case DW_ATE_HP_floathpintel
:
13844 return "DW_ATE_HP_floathpintel";
13845 case DW_ATE_HP_imaginary_float80
:
13846 return "DW_ATE_HP_imaginary_float80";
13847 case DW_ATE_HP_imaginary_float128
:
13848 return "DW_ATE_HP_imaginary_float128";
13850 return "DW_ATE_<unknown>";
13854 /* Convert a DWARF call frame info operation to its string name. */
13858 dwarf_cfi_name (unsigned cfi_opc
)
13862 case DW_CFA_advance_loc
:
13863 return "DW_CFA_advance_loc";
13864 case DW_CFA_offset
:
13865 return "DW_CFA_offset";
13866 case DW_CFA_restore
:
13867 return "DW_CFA_restore";
13869 return "DW_CFA_nop";
13870 case DW_CFA_set_loc
:
13871 return "DW_CFA_set_loc";
13872 case DW_CFA_advance_loc1
:
13873 return "DW_CFA_advance_loc1";
13874 case DW_CFA_advance_loc2
:
13875 return "DW_CFA_advance_loc2";
13876 case DW_CFA_advance_loc4
:
13877 return "DW_CFA_advance_loc4";
13878 case DW_CFA_offset_extended
:
13879 return "DW_CFA_offset_extended";
13880 case DW_CFA_restore_extended
:
13881 return "DW_CFA_restore_extended";
13882 case DW_CFA_undefined
:
13883 return "DW_CFA_undefined";
13884 case DW_CFA_same_value
:
13885 return "DW_CFA_same_value";
13886 case DW_CFA_register
:
13887 return "DW_CFA_register";
13888 case DW_CFA_remember_state
:
13889 return "DW_CFA_remember_state";
13890 case DW_CFA_restore_state
:
13891 return "DW_CFA_restore_state";
13892 case DW_CFA_def_cfa
:
13893 return "DW_CFA_def_cfa";
13894 case DW_CFA_def_cfa_register
:
13895 return "DW_CFA_def_cfa_register";
13896 case DW_CFA_def_cfa_offset
:
13897 return "DW_CFA_def_cfa_offset";
13899 case DW_CFA_def_cfa_expression
:
13900 return "DW_CFA_def_cfa_expression";
13901 case DW_CFA_expression
:
13902 return "DW_CFA_expression";
13903 case DW_CFA_offset_extended_sf
:
13904 return "DW_CFA_offset_extended_sf";
13905 case DW_CFA_def_cfa_sf
:
13906 return "DW_CFA_def_cfa_sf";
13907 case DW_CFA_def_cfa_offset_sf
:
13908 return "DW_CFA_def_cfa_offset_sf";
13909 case DW_CFA_val_offset
:
13910 return "DW_CFA_val_offset";
13911 case DW_CFA_val_offset_sf
:
13912 return "DW_CFA_val_offset_sf";
13913 case DW_CFA_val_expression
:
13914 return "DW_CFA_val_expression";
13915 /* SGI/MIPS specific. */
13916 case DW_CFA_MIPS_advance_loc8
:
13917 return "DW_CFA_MIPS_advance_loc8";
13918 /* GNU extensions. */
13919 case DW_CFA_GNU_window_save
:
13920 return "DW_CFA_GNU_window_save";
13921 case DW_CFA_GNU_args_size
:
13922 return "DW_CFA_GNU_args_size";
13923 case DW_CFA_GNU_negative_offset_extended
:
13924 return "DW_CFA_GNU_negative_offset_extended";
13926 return "DW_CFA_<unknown>";
13932 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13936 print_spaces (indent
, f
);
13937 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13938 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13940 if (die
->parent
!= NULL
)
13942 print_spaces (indent
, f
);
13943 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13944 die
->parent
->offset
);
13947 print_spaces (indent
, f
);
13948 fprintf_unfiltered (f
, " has children: %s\n",
13949 dwarf_bool_name (die
->child
!= NULL
));
13951 print_spaces (indent
, f
);
13952 fprintf_unfiltered (f
, " attributes:\n");
13954 for (i
= 0; i
< die
->num_attrs
; ++i
)
13956 print_spaces (indent
, f
);
13957 fprintf_unfiltered (f
, " %s (%s) ",
13958 dwarf_attr_name (die
->attrs
[i
].name
),
13959 dwarf_form_name (die
->attrs
[i
].form
));
13961 switch (die
->attrs
[i
].form
)
13963 case DW_FORM_ref_addr
:
13965 fprintf_unfiltered (f
, "address: ");
13966 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13968 case DW_FORM_block2
:
13969 case DW_FORM_block4
:
13970 case DW_FORM_block
:
13971 case DW_FORM_block1
:
13972 fprintf_unfiltered (f
, "block: size %d",
13973 DW_BLOCK (&die
->attrs
[i
])->size
);
13975 case DW_FORM_exprloc
:
13976 fprintf_unfiltered (f
, "expression: size %u",
13977 DW_BLOCK (&die
->attrs
[i
])->size
);
13982 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13983 (long) (DW_ADDR (&die
->attrs
[i
])));
13985 case DW_FORM_data1
:
13986 case DW_FORM_data2
:
13987 case DW_FORM_data4
:
13988 case DW_FORM_data8
:
13989 case DW_FORM_udata
:
13990 case DW_FORM_sdata
:
13991 fprintf_unfiltered (f
, "constant: %s",
13992 pulongest (DW_UNSND (&die
->attrs
[i
])));
13994 case DW_FORM_sec_offset
:
13995 fprintf_unfiltered (f
, "section offset: %s",
13996 pulongest (DW_UNSND (&die
->attrs
[i
])));
13998 case DW_FORM_ref_sig8
:
13999 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14000 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14001 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
14003 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14005 case DW_FORM_string
:
14007 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14008 DW_STRING (&die
->attrs
[i
])
14009 ? DW_STRING (&die
->attrs
[i
]) : "",
14010 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14013 if (DW_UNSND (&die
->attrs
[i
]))
14014 fprintf_unfiltered (f
, "flag: TRUE");
14016 fprintf_unfiltered (f
, "flag: FALSE");
14018 case DW_FORM_flag_present
:
14019 fprintf_unfiltered (f
, "flag: TRUE");
14021 case DW_FORM_indirect
:
14022 /* The reader will have reduced the indirect form to
14023 the "base form" so this form should not occur. */
14024 fprintf_unfiltered (f
,
14025 "unexpected attribute form: DW_FORM_indirect");
14028 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14029 die
->attrs
[i
].form
);
14032 fprintf_unfiltered (f
, "\n");
14037 dump_die_for_error (struct die_info
*die
)
14039 dump_die_shallow (gdb_stderr
, 0, die
);
14043 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14045 int indent
= level
* 4;
14047 gdb_assert (die
!= NULL
);
14049 if (level
>= max_level
)
14052 dump_die_shallow (f
, indent
, die
);
14054 if (die
->child
!= NULL
)
14056 print_spaces (indent
, f
);
14057 fprintf_unfiltered (f
, " Children:");
14058 if (level
+ 1 < max_level
)
14060 fprintf_unfiltered (f
, "\n");
14061 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14065 fprintf_unfiltered (f
,
14066 " [not printed, max nesting level reached]\n");
14070 if (die
->sibling
!= NULL
&& level
> 0)
14072 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14076 /* This is called from the pdie macro in gdbinit.in.
14077 It's not static so gcc will keep a copy callable from gdb. */
14080 dump_die (struct die_info
*die
, int max_level
)
14082 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14086 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14090 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14096 is_ref_attr (struct attribute
*attr
)
14098 switch (attr
->form
)
14100 case DW_FORM_ref_addr
:
14105 case DW_FORM_ref_udata
:
14112 static unsigned int
14113 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14115 if (is_ref_attr (attr
))
14116 return DW_ADDR (attr
);
14118 complaint (&symfile_complaints
,
14119 _("unsupported die ref attribute form: '%s'"),
14120 dwarf_form_name (attr
->form
));
14124 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14125 * the value held by the attribute is not constant. */
14128 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14130 if (attr
->form
== DW_FORM_sdata
)
14131 return DW_SND (attr
);
14132 else if (attr
->form
== DW_FORM_udata
14133 || attr
->form
== DW_FORM_data1
14134 || attr
->form
== DW_FORM_data2
14135 || attr
->form
== DW_FORM_data4
14136 || attr
->form
== DW_FORM_data8
)
14137 return DW_UNSND (attr
);
14140 complaint (&symfile_complaints
,
14141 _("Attribute value is not a constant (%s)"),
14142 dwarf_form_name (attr
->form
));
14143 return default_value
;
14147 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14148 unit and add it to our queue.
14149 The result is non-zero if PER_CU was queued, otherwise the result is zero
14150 meaning either PER_CU is already queued or it is already loaded. */
14153 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14154 struct dwarf2_per_cu_data
*per_cu
)
14156 /* We may arrive here during partial symbol reading, if we need full
14157 DIEs to process an unusual case (e.g. template arguments). Do
14158 not queue PER_CU, just tell our caller to load its DIEs. */
14159 if (dwarf2_per_objfile
->reading_partial_symbols
)
14161 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14166 /* Mark the dependence relation so that we don't flush PER_CU
14168 dwarf2_add_dependence (this_cu
, per_cu
);
14170 /* If it's already on the queue, we have nothing to do. */
14171 if (per_cu
->queued
)
14174 /* If the compilation unit is already loaded, just mark it as
14176 if (per_cu
->cu
!= NULL
)
14178 per_cu
->cu
->last_used
= 0;
14182 /* Add it to the queue. */
14183 queue_comp_unit (per_cu
, this_cu
->objfile
);
14188 /* Follow reference or signature attribute ATTR of SRC_DIE.
14189 On entry *REF_CU is the CU of SRC_DIE.
14190 On exit *REF_CU is the CU of the result. */
14192 static struct die_info
*
14193 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14194 struct dwarf2_cu
**ref_cu
)
14196 struct die_info
*die
;
14198 if (is_ref_attr (attr
))
14199 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14200 else if (attr
->form
== DW_FORM_ref_sig8
)
14201 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14204 dump_die_for_error (src_die
);
14205 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14206 (*ref_cu
)->objfile
->name
);
14212 /* Follow reference OFFSET.
14213 On entry *REF_CU is the CU of the source die referencing OFFSET.
14214 On exit *REF_CU is the CU of the result.
14215 Returns NULL if OFFSET is invalid. */
14217 static struct die_info
*
14218 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14220 struct die_info temp_die
;
14221 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14223 gdb_assert (cu
->per_cu
!= NULL
);
14227 if (cu
->per_cu
->debug_type_section
)
14229 /* .debug_types CUs cannot reference anything outside their CU.
14230 If they need to, they have to reference a signatured type via
14231 DW_FORM_ref_sig8. */
14232 if (! offset_in_cu_p (&cu
->header
, offset
))
14235 else if (! offset_in_cu_p (&cu
->header
, offset
))
14237 struct dwarf2_per_cu_data
*per_cu
;
14239 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14241 /* If necessary, add it to the queue and load its DIEs. */
14242 if (maybe_queue_comp_unit (cu
, per_cu
))
14243 load_full_comp_unit (per_cu
, cu
->objfile
);
14245 target_cu
= per_cu
->cu
;
14247 else if (cu
->dies
== NULL
)
14249 /* We're loading full DIEs during partial symbol reading. */
14250 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14251 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
14254 *ref_cu
= target_cu
;
14255 temp_die
.offset
= offset
;
14256 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14259 /* Follow reference attribute ATTR of SRC_DIE.
14260 On entry *REF_CU is the CU of SRC_DIE.
14261 On exit *REF_CU is the CU of the result. */
14263 static struct die_info
*
14264 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14265 struct dwarf2_cu
**ref_cu
)
14267 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14268 struct dwarf2_cu
*cu
= *ref_cu
;
14269 struct die_info
*die
;
14271 die
= follow_die_offset (offset
, ref_cu
);
14273 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14274 "at 0x%x [in module %s]"),
14275 offset
, src_die
->offset
, cu
->objfile
->name
);
14280 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14281 Returned value is intended for DW_OP_call*. Returned
14282 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14284 struct dwarf2_locexpr_baton
14285 dwarf2_fetch_die_location_block (unsigned int offset
,
14286 struct dwarf2_per_cu_data
*per_cu
,
14287 CORE_ADDR (*get_frame_pc
) (void *baton
),
14290 struct dwarf2_cu
*cu
;
14291 struct die_info
*die
;
14292 struct attribute
*attr
;
14293 struct dwarf2_locexpr_baton retval
;
14295 dw2_setup (per_cu
->objfile
);
14297 if (per_cu
->cu
== NULL
)
14301 die
= follow_die_offset (offset
, &cu
);
14303 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14304 offset
, per_cu
->cu
->objfile
->name
);
14306 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14309 /* DWARF: "If there is no such attribute, then there is no effect.".
14310 DATA is ignored if SIZE is 0. */
14312 retval
.data
= NULL
;
14315 else if (attr_form_is_section_offset (attr
))
14317 struct dwarf2_loclist_baton loclist_baton
;
14318 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14321 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14323 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14325 retval
.size
= size
;
14329 if (!attr_form_is_block (attr
))
14330 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14331 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14332 offset
, per_cu
->cu
->objfile
->name
);
14334 retval
.data
= DW_BLOCK (attr
)->data
;
14335 retval
.size
= DW_BLOCK (attr
)->size
;
14337 retval
.per_cu
= cu
->per_cu
;
14339 age_cached_comp_units ();
14344 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14348 dwarf2_get_die_type (unsigned int die_offset
,
14349 struct dwarf2_per_cu_data
*per_cu
)
14351 dw2_setup (per_cu
->objfile
);
14352 return get_die_type_at_offset (die_offset
, per_cu
);
14355 /* Follow the signature attribute ATTR in SRC_DIE.
14356 On entry *REF_CU is the CU of SRC_DIE.
14357 On exit *REF_CU is the CU of the result. */
14359 static struct die_info
*
14360 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14361 struct dwarf2_cu
**ref_cu
)
14363 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14364 struct die_info temp_die
;
14365 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14366 struct dwarf2_cu
*sig_cu
;
14367 struct die_info
*die
;
14369 /* sig_type will be NULL if the signatured type is missing from
14371 if (sig_type
== NULL
)
14372 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14373 "at 0x%x [in module %s]"),
14374 src_die
->offset
, objfile
->name
);
14376 /* If necessary, add it to the queue and load its DIEs. */
14378 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14379 read_signatured_type (objfile
, sig_type
);
14381 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14383 sig_cu
= sig_type
->per_cu
.cu
;
14384 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14385 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14392 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14393 "from DIE at 0x%x [in module %s]"),
14394 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14397 /* Given an offset of a signatured type, return its signatured_type. */
14399 static struct signatured_type
*
14400 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14401 struct dwarf2_section_info
*section
,
14402 unsigned int offset
)
14404 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14405 unsigned int length
, initial_length_size
;
14406 unsigned int sig_offset
;
14407 struct signatured_type find_entry
, *type_sig
;
14409 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14410 sig_offset
= (initial_length_size
14412 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14413 + 1 /*address_size*/);
14414 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14415 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14417 /* This is only used to lookup previously recorded types.
14418 If we didn't find it, it's our bug. */
14419 gdb_assert (type_sig
!= NULL
);
14420 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14425 /* Read in signatured type at OFFSET and build its CU and die(s). */
14428 read_signatured_type_at_offset (struct objfile
*objfile
,
14429 struct dwarf2_section_info
*sect
,
14430 unsigned int offset
)
14432 struct signatured_type
*type_sig
;
14434 dwarf2_read_section (objfile
, sect
);
14436 /* We have the section offset, but we need the signature to do the
14437 hash table lookup. */
14438 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14440 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14442 read_signatured_type (objfile
, type_sig
);
14444 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14447 /* Read in a signatured type and build its CU and DIEs. */
14450 read_signatured_type (struct objfile
*objfile
,
14451 struct signatured_type
*type_sig
)
14453 gdb_byte
*types_ptr
;
14454 struct die_reader_specs reader_specs
;
14455 struct dwarf2_cu
*cu
;
14456 ULONGEST signature
;
14457 struct cleanup
*back_to
, *free_cu_cleanup
;
14458 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14460 dwarf2_read_section (objfile
, section
);
14461 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14463 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14465 cu
= xmalloc (sizeof (*cu
));
14466 init_one_comp_unit (cu
, objfile
);
14468 type_sig
->per_cu
.cu
= cu
;
14469 cu
->per_cu
= &type_sig
->per_cu
;
14471 /* If an error occurs while loading, release our storage. */
14472 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14474 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14475 types_ptr
, objfile
->obfd
);
14476 gdb_assert (signature
== type_sig
->signature
);
14479 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14483 &cu
->comp_unit_obstack
,
14484 hashtab_obstack_allocate
,
14485 dummy_obstack_deallocate
);
14487 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14488 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14490 init_cu_die_reader (&reader_specs
, cu
);
14492 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14495 /* We try not to read any attributes in this function, because not
14496 all objfiles needed for references have been loaded yet, and symbol
14497 table processing isn't initialized. But we have to set the CU language,
14498 or we won't be able to build types correctly. */
14499 prepare_one_comp_unit (cu
, cu
->dies
);
14501 do_cleanups (back_to
);
14503 /* We've successfully allocated this compilation unit. Let our caller
14504 clean it up when finished with it. */
14505 discard_cleanups (free_cu_cleanup
);
14507 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14508 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14511 /* Decode simple location descriptions.
14512 Given a pointer to a dwarf block that defines a location, compute
14513 the location and return the value.
14515 NOTE drow/2003-11-18: This function is called in two situations
14516 now: for the address of static or global variables (partial symbols
14517 only) and for offsets into structures which are expected to be
14518 (more or less) constant. The partial symbol case should go away,
14519 and only the constant case should remain. That will let this
14520 function complain more accurately. A few special modes are allowed
14521 without complaint for global variables (for instance, global
14522 register values and thread-local values).
14524 A location description containing no operations indicates that the
14525 object is optimized out. The return value is 0 for that case.
14526 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14527 callers will only want a very basic result and this can become a
14530 Note that stack[0] is unused except as a default error return. */
14533 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14535 struct objfile
*objfile
= cu
->objfile
;
14537 int size
= blk
->size
;
14538 gdb_byte
*data
= blk
->data
;
14539 CORE_ADDR stack
[64];
14541 unsigned int bytes_read
, unsnd
;
14547 stack
[++stacki
] = 0;
14586 stack
[++stacki
] = op
- DW_OP_lit0
;
14621 stack
[++stacki
] = op
- DW_OP_reg0
;
14623 dwarf2_complex_location_expr_complaint ();
14627 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14629 stack
[++stacki
] = unsnd
;
14631 dwarf2_complex_location_expr_complaint ();
14635 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14640 case DW_OP_const1u
:
14641 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14645 case DW_OP_const1s
:
14646 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14650 case DW_OP_const2u
:
14651 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14655 case DW_OP_const2s
:
14656 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14660 case DW_OP_const4u
:
14661 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14665 case DW_OP_const4s
:
14666 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14671 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14677 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14682 stack
[stacki
+ 1] = stack
[stacki
];
14687 stack
[stacki
- 1] += stack
[stacki
];
14691 case DW_OP_plus_uconst
:
14692 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14698 stack
[stacki
- 1] -= stack
[stacki
];
14703 /* If we're not the last op, then we definitely can't encode
14704 this using GDB's address_class enum. This is valid for partial
14705 global symbols, although the variable's address will be bogus
14708 dwarf2_complex_location_expr_complaint ();
14711 case DW_OP_GNU_push_tls_address
:
14712 /* The top of the stack has the offset from the beginning
14713 of the thread control block at which the variable is located. */
14714 /* Nothing should follow this operator, so the top of stack would
14716 /* This is valid for partial global symbols, but the variable's
14717 address will be bogus in the psymtab. */
14719 dwarf2_complex_location_expr_complaint ();
14722 case DW_OP_GNU_uninit
:
14727 const char *name
= dwarf_stack_op_name (op
);
14730 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14733 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14737 return (stack
[stacki
]);
14740 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14741 outside of the allocated space. Also enforce minimum>0. */
14742 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14744 complaint (&symfile_complaints
,
14745 _("location description stack overflow"));
14751 complaint (&symfile_complaints
,
14752 _("location description stack underflow"));
14756 return (stack
[stacki
]);
14759 /* memory allocation interface */
14761 static struct dwarf_block
*
14762 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14764 struct dwarf_block
*blk
;
14766 blk
= (struct dwarf_block
*)
14767 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14771 static struct abbrev_info
*
14772 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14774 struct abbrev_info
*abbrev
;
14776 abbrev
= (struct abbrev_info
*)
14777 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14778 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14782 static struct die_info
*
14783 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14785 struct die_info
*die
;
14786 size_t size
= sizeof (struct die_info
);
14789 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14791 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14792 memset (die
, 0, sizeof (struct die_info
));
14797 /* Macro support. */
14799 /* Return the full name of file number I in *LH's file name table.
14800 Use COMP_DIR as the name of the current directory of the
14801 compilation. The result is allocated using xmalloc; the caller is
14802 responsible for freeing it. */
14804 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14806 /* Is the file number a valid index into the line header's file name
14807 table? Remember that file numbers start with one, not zero. */
14808 if (1 <= file
&& file
<= lh
->num_file_names
)
14810 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14812 if (IS_ABSOLUTE_PATH (fe
->name
))
14813 return xstrdup (fe
->name
);
14821 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14827 dir_len
= strlen (dir
);
14828 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14829 strcpy (full_name
, dir
);
14830 full_name
[dir_len
] = '/';
14831 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14835 return xstrdup (fe
->name
);
14840 /* The compiler produced a bogus file number. We can at least
14841 record the macro definitions made in the file, even if we
14842 won't be able to find the file by name. */
14843 char fake_name
[80];
14845 sprintf (fake_name
, "<bad macro file number %d>", file
);
14847 complaint (&symfile_complaints
,
14848 _("bad file number in macro information (%d)"),
14851 return xstrdup (fake_name
);
14856 static struct macro_source_file
*
14857 macro_start_file (int file
, int line
,
14858 struct macro_source_file
*current_file
,
14859 const char *comp_dir
,
14860 struct line_header
*lh
, struct objfile
*objfile
)
14862 /* The full name of this source file. */
14863 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14865 /* We don't create a macro table for this compilation unit
14866 at all until we actually get a filename. */
14867 if (! pending_macros
)
14868 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14869 objfile
->macro_cache
);
14871 if (! current_file
)
14872 /* If we have no current file, then this must be the start_file
14873 directive for the compilation unit's main source file. */
14874 current_file
= macro_set_main (pending_macros
, full_name
);
14876 current_file
= macro_include (current_file
, line
, full_name
);
14880 return current_file
;
14884 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14885 followed by a null byte. */
14887 copy_string (const char *buf
, int len
)
14889 char *s
= xmalloc (len
+ 1);
14891 memcpy (s
, buf
, len
);
14897 static const char *
14898 consume_improper_spaces (const char *p
, const char *body
)
14902 complaint (&symfile_complaints
,
14903 _("macro definition contains spaces "
14904 "in formal argument list:\n`%s'"),
14916 parse_macro_definition (struct macro_source_file
*file
, int line
,
14921 /* The body string takes one of two forms. For object-like macro
14922 definitions, it should be:
14924 <macro name> " " <definition>
14926 For function-like macro definitions, it should be:
14928 <macro name> "() " <definition>
14930 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14932 Spaces may appear only where explicitly indicated, and in the
14935 The Dwarf 2 spec says that an object-like macro's name is always
14936 followed by a space, but versions of GCC around March 2002 omit
14937 the space when the macro's definition is the empty string.
14939 The Dwarf 2 spec says that there should be no spaces between the
14940 formal arguments in a function-like macro's formal argument list,
14941 but versions of GCC around March 2002 include spaces after the
14945 /* Find the extent of the macro name. The macro name is terminated
14946 by either a space or null character (for an object-like macro) or
14947 an opening paren (for a function-like macro). */
14948 for (p
= body
; *p
; p
++)
14949 if (*p
== ' ' || *p
== '(')
14952 if (*p
== ' ' || *p
== '\0')
14954 /* It's an object-like macro. */
14955 int name_len
= p
- body
;
14956 char *name
= copy_string (body
, name_len
);
14957 const char *replacement
;
14960 replacement
= body
+ name_len
+ 1;
14963 dwarf2_macro_malformed_definition_complaint (body
);
14964 replacement
= body
+ name_len
;
14967 macro_define_object (file
, line
, name
, replacement
);
14971 else if (*p
== '(')
14973 /* It's a function-like macro. */
14974 char *name
= copy_string (body
, p
- body
);
14977 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14981 p
= consume_improper_spaces (p
, body
);
14983 /* Parse the formal argument list. */
14984 while (*p
&& *p
!= ')')
14986 /* Find the extent of the current argument name. */
14987 const char *arg_start
= p
;
14989 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14992 if (! *p
|| p
== arg_start
)
14993 dwarf2_macro_malformed_definition_complaint (body
);
14996 /* Make sure argv has room for the new argument. */
14997 if (argc
>= argv_size
)
15000 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15003 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15006 p
= consume_improper_spaces (p
, body
);
15008 /* Consume the comma, if present. */
15013 p
= consume_improper_spaces (p
, body
);
15022 /* Perfectly formed definition, no complaints. */
15023 macro_define_function (file
, line
, name
,
15024 argc
, (const char **) argv
,
15026 else if (*p
== '\0')
15028 /* Complain, but do define it. */
15029 dwarf2_macro_malformed_definition_complaint (body
);
15030 macro_define_function (file
, line
, name
,
15031 argc
, (const char **) argv
,
15035 /* Just complain. */
15036 dwarf2_macro_malformed_definition_complaint (body
);
15039 /* Just complain. */
15040 dwarf2_macro_malformed_definition_complaint (body
);
15046 for (i
= 0; i
< argc
; i
++)
15052 dwarf2_macro_malformed_definition_complaint (body
);
15055 /* Skip some bytes from BYTES according to the form given in FORM.
15056 Returns the new pointer. */
15059 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15060 enum dwarf_form form
,
15061 unsigned int offset_size
,
15062 struct dwarf2_section_info
*section
)
15064 unsigned int bytes_read
;
15068 case DW_FORM_data1
:
15073 case DW_FORM_data2
:
15077 case DW_FORM_data4
:
15081 case DW_FORM_data8
:
15085 case DW_FORM_string
:
15086 read_direct_string (abfd
, bytes
, &bytes_read
);
15087 bytes
+= bytes_read
;
15090 case DW_FORM_sec_offset
:
15092 bytes
+= offset_size
;
15095 case DW_FORM_block
:
15096 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15097 bytes
+= bytes_read
;
15100 case DW_FORM_block1
:
15101 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15103 case DW_FORM_block2
:
15104 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15106 case DW_FORM_block4
:
15107 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15110 case DW_FORM_sdata
:
15111 case DW_FORM_udata
:
15112 bytes
= skip_leb128 (abfd
, bytes
);
15118 complaint (&symfile_complaints
,
15119 _("invalid form 0x%x in `%s'"),
15121 section
->asection
->name
);
15129 /* A helper for dwarf_decode_macros that handles skipping an unknown
15130 opcode. Returns an updated pointer to the macro data buffer; or,
15131 on error, issues a complaint and returns NULL. */
15134 skip_unknown_opcode (unsigned int opcode
,
15135 gdb_byte
**opcode_definitions
,
15138 unsigned int offset_size
,
15139 struct dwarf2_section_info
*section
)
15141 unsigned int bytes_read
, i
;
15145 if (opcode_definitions
[opcode
] == NULL
)
15147 complaint (&symfile_complaints
,
15148 _("unrecognized DW_MACFINO opcode 0x%x"),
15153 defn
= opcode_definitions
[opcode
];
15154 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15155 defn
+= bytes_read
;
15157 for (i
= 0; i
< arg
; ++i
)
15159 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15160 if (mac_ptr
== NULL
)
15162 /* skip_form_bytes already issued the complaint. */
15170 /* A helper function which parses the header of a macro section.
15171 If the macro section is the extended (for now called "GNU") type,
15172 then this updates *OFFSET_SIZE. Returns a pointer to just after
15173 the header, or issues a complaint and returns NULL on error. */
15176 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15179 unsigned int *offset_size
,
15180 int section_is_gnu
)
15182 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15184 if (section_is_gnu
)
15186 unsigned int version
, flags
;
15188 version
= read_2_bytes (abfd
, mac_ptr
);
15191 complaint (&symfile_complaints
,
15192 _("unrecognized version `%d' in .debug_macro section"),
15198 flags
= read_1_byte (abfd
, mac_ptr
);
15200 *offset_size
= (flags
& 1) ? 8 : 4;
15202 if ((flags
& 2) != 0)
15203 /* We don't need the line table offset. */
15204 mac_ptr
+= *offset_size
;
15206 /* Vendor opcode descriptions. */
15207 if ((flags
& 4) != 0)
15209 unsigned int i
, count
;
15211 count
= read_1_byte (abfd
, mac_ptr
);
15213 for (i
= 0; i
< count
; ++i
)
15215 unsigned int opcode
, bytes_read
;
15218 opcode
= read_1_byte (abfd
, mac_ptr
);
15220 opcode_definitions
[opcode
] = mac_ptr
;
15221 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15222 mac_ptr
+= bytes_read
;
15231 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15232 including DW_GNU_MACINFO_transparent_include. */
15235 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15236 struct macro_source_file
*current_file
,
15237 struct line_header
*lh
, char *comp_dir
,
15238 struct dwarf2_section_info
*section
,
15239 int section_is_gnu
,
15240 unsigned int offset_size
,
15241 struct objfile
*objfile
)
15243 enum dwarf_macro_record_type macinfo_type
;
15244 int at_commandline
;
15245 gdb_byte
*opcode_definitions
[256];
15247 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15248 &offset_size
, section_is_gnu
);
15249 if (mac_ptr
== NULL
)
15251 /* We already issued a complaint. */
15255 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15256 GDB is still reading the definitions from command line. First
15257 DW_MACINFO_start_file will need to be ignored as it was already executed
15258 to create CURRENT_FILE for the main source holding also the command line
15259 definitions. On first met DW_MACINFO_start_file this flag is reset to
15260 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15262 at_commandline
= 1;
15266 /* Do we at least have room for a macinfo type byte? */
15267 if (mac_ptr
>= mac_end
)
15269 dwarf2_macros_too_long_complaint (section
);
15273 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15276 /* Note that we rely on the fact that the corresponding GNU and
15277 DWARF constants are the same. */
15278 switch (macinfo_type
)
15280 /* A zero macinfo type indicates the end of the macro
15285 case DW_MACRO_GNU_define
:
15286 case DW_MACRO_GNU_undef
:
15287 case DW_MACRO_GNU_define_indirect
:
15288 case DW_MACRO_GNU_undef_indirect
:
15290 unsigned int bytes_read
;
15295 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15296 mac_ptr
+= bytes_read
;
15298 if (macinfo_type
== DW_MACRO_GNU_define
15299 || macinfo_type
== DW_MACRO_GNU_undef
)
15301 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15302 mac_ptr
+= bytes_read
;
15306 LONGEST str_offset
;
15308 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15309 mac_ptr
+= offset_size
;
15311 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15314 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15315 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15316 if (! current_file
)
15318 /* DWARF violation as no main source is present. */
15319 complaint (&symfile_complaints
,
15320 _("debug info with no main source gives macro %s "
15322 is_define
? _("definition") : _("undefinition"),
15326 if ((line
== 0 && !at_commandline
)
15327 || (line
!= 0 && at_commandline
))
15328 complaint (&symfile_complaints
,
15329 _("debug info gives %s macro %s with %s line %d: %s"),
15330 at_commandline
? _("command-line") : _("in-file"),
15331 is_define
? _("definition") : _("undefinition"),
15332 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15335 parse_macro_definition (current_file
, line
, body
);
15338 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15339 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15340 macro_undef (current_file
, line
, body
);
15345 case DW_MACRO_GNU_start_file
:
15347 unsigned int bytes_read
;
15350 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15351 mac_ptr
+= bytes_read
;
15352 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15353 mac_ptr
+= bytes_read
;
15355 if ((line
== 0 && !at_commandline
)
15356 || (line
!= 0 && at_commandline
))
15357 complaint (&symfile_complaints
,
15358 _("debug info gives source %d included "
15359 "from %s at %s line %d"),
15360 file
, at_commandline
? _("command-line") : _("file"),
15361 line
== 0 ? _("zero") : _("non-zero"), line
);
15363 if (at_commandline
)
15365 /* This DW_MACRO_GNU_start_file was executed in the
15367 at_commandline
= 0;
15370 current_file
= macro_start_file (file
, line
,
15371 current_file
, comp_dir
,
15376 case DW_MACRO_GNU_end_file
:
15377 if (! current_file
)
15378 complaint (&symfile_complaints
,
15379 _("macro debug info has an unmatched "
15380 "`close_file' directive"));
15383 current_file
= current_file
->included_by
;
15384 if (! current_file
)
15386 enum dwarf_macro_record_type next_type
;
15388 /* GCC circa March 2002 doesn't produce the zero
15389 type byte marking the end of the compilation
15390 unit. Complain if it's not there, but exit no
15393 /* Do we at least have room for a macinfo type byte? */
15394 if (mac_ptr
>= mac_end
)
15396 dwarf2_macros_too_long_complaint (section
);
15400 /* We don't increment mac_ptr here, so this is just
15402 next_type
= read_1_byte (abfd
, mac_ptr
);
15403 if (next_type
!= 0)
15404 complaint (&symfile_complaints
,
15405 _("no terminating 0-type entry for "
15406 "macros in `.debug_macinfo' section"));
15413 case DW_MACRO_GNU_transparent_include
:
15417 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15418 mac_ptr
+= offset_size
;
15420 dwarf_decode_macro_bytes (abfd
,
15421 section
->buffer
+ offset
,
15422 mac_end
, current_file
,
15424 section
, section_is_gnu
,
15425 offset_size
, objfile
);
15429 case DW_MACINFO_vendor_ext
:
15430 if (!section_is_gnu
)
15432 unsigned int bytes_read
;
15435 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15436 mac_ptr
+= bytes_read
;
15437 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15438 mac_ptr
+= bytes_read
;
15440 /* We don't recognize any vendor extensions. */
15446 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15447 mac_ptr
, abfd
, offset_size
,
15449 if (mac_ptr
== NULL
)
15453 } while (macinfo_type
!= 0);
15457 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15458 char *comp_dir
, bfd
*abfd
,
15459 struct dwarf2_cu
*cu
,
15460 struct dwarf2_section_info
*section
,
15461 int section_is_gnu
)
15463 gdb_byte
*mac_ptr
, *mac_end
;
15464 struct macro_source_file
*current_file
= 0;
15465 enum dwarf_macro_record_type macinfo_type
;
15466 unsigned int offset_size
= cu
->header
.offset_size
;
15467 gdb_byte
*opcode_definitions
[256];
15469 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15470 if (section
->buffer
== NULL
)
15472 complaint (&symfile_complaints
, _("missing %s section"),
15473 section
->asection
->name
);
15477 /* First pass: Find the name of the base filename.
15478 This filename is needed in order to process all macros whose definition
15479 (or undefinition) comes from the command line. These macros are defined
15480 before the first DW_MACINFO_start_file entry, and yet still need to be
15481 associated to the base file.
15483 To determine the base file name, we scan the macro definitions until we
15484 reach the first DW_MACINFO_start_file entry. We then initialize
15485 CURRENT_FILE accordingly so that any macro definition found before the
15486 first DW_MACINFO_start_file can still be associated to the base file. */
15488 mac_ptr
= section
->buffer
+ offset
;
15489 mac_end
= section
->buffer
+ section
->size
;
15491 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15492 &offset_size
, section_is_gnu
);
15493 if (mac_ptr
== NULL
)
15495 /* We already issued a complaint. */
15501 /* Do we at least have room for a macinfo type byte? */
15502 if (mac_ptr
>= mac_end
)
15504 /* Complaint is printed during the second pass as GDB will probably
15505 stop the first pass earlier upon finding
15506 DW_MACINFO_start_file. */
15510 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15513 /* Note that we rely on the fact that the corresponding GNU and
15514 DWARF constants are the same. */
15515 switch (macinfo_type
)
15517 /* A zero macinfo type indicates the end of the macro
15522 case DW_MACRO_GNU_define
:
15523 case DW_MACRO_GNU_undef
:
15524 /* Only skip the data by MAC_PTR. */
15526 unsigned int bytes_read
;
15528 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15529 mac_ptr
+= bytes_read
;
15530 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15531 mac_ptr
+= bytes_read
;
15535 case DW_MACRO_GNU_start_file
:
15537 unsigned int bytes_read
;
15540 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15541 mac_ptr
+= bytes_read
;
15542 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15543 mac_ptr
+= bytes_read
;
15545 current_file
= macro_start_file (file
, line
, current_file
,
15546 comp_dir
, lh
, cu
->objfile
);
15550 case DW_MACRO_GNU_end_file
:
15551 /* No data to skip by MAC_PTR. */
15554 case DW_MACRO_GNU_define_indirect
:
15555 case DW_MACRO_GNU_undef_indirect
:
15557 unsigned int bytes_read
;
15559 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15560 mac_ptr
+= bytes_read
;
15561 mac_ptr
+= offset_size
;
15565 case DW_MACRO_GNU_transparent_include
:
15566 /* Note that, according to the spec, a transparent include
15567 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15568 skip this opcode. */
15569 mac_ptr
+= offset_size
;
15572 case DW_MACINFO_vendor_ext
:
15573 /* Only skip the data by MAC_PTR. */
15574 if (!section_is_gnu
)
15576 unsigned int bytes_read
;
15578 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15579 mac_ptr
+= bytes_read
;
15580 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15581 mac_ptr
+= bytes_read
;
15586 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15587 mac_ptr
, abfd
, offset_size
,
15589 if (mac_ptr
== NULL
)
15593 } while (macinfo_type
!= 0 && current_file
== NULL
);
15595 /* Second pass: Process all entries.
15597 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15598 command-line macro definitions/undefinitions. This flag is unset when we
15599 reach the first DW_MACINFO_start_file entry. */
15601 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15602 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15603 offset_size
, cu
->objfile
);
15606 /* Check if the attribute's form is a DW_FORM_block*
15607 if so return true else false. */
15609 attr_form_is_block (struct attribute
*attr
)
15611 return (attr
== NULL
? 0 :
15612 attr
->form
== DW_FORM_block1
15613 || attr
->form
== DW_FORM_block2
15614 || attr
->form
== DW_FORM_block4
15615 || attr
->form
== DW_FORM_block
15616 || attr
->form
== DW_FORM_exprloc
);
15619 /* Return non-zero if ATTR's value is a section offset --- classes
15620 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15621 You may use DW_UNSND (attr) to retrieve such offsets.
15623 Section 7.5.4, "Attribute Encodings", explains that no attribute
15624 may have a value that belongs to more than one of these classes; it
15625 would be ambiguous if we did, because we use the same forms for all
15628 attr_form_is_section_offset (struct attribute
*attr
)
15630 return (attr
->form
== DW_FORM_data4
15631 || attr
->form
== DW_FORM_data8
15632 || attr
->form
== DW_FORM_sec_offset
);
15636 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15637 zero otherwise. When this function returns true, you can apply
15638 dwarf2_get_attr_constant_value to it.
15640 However, note that for some attributes you must check
15641 attr_form_is_section_offset before using this test. DW_FORM_data4
15642 and DW_FORM_data8 are members of both the constant class, and of
15643 the classes that contain offsets into other debug sections
15644 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15645 that, if an attribute's can be either a constant or one of the
15646 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15647 taken as section offsets, not constants. */
15649 attr_form_is_constant (struct attribute
*attr
)
15651 switch (attr
->form
)
15653 case DW_FORM_sdata
:
15654 case DW_FORM_udata
:
15655 case DW_FORM_data1
:
15656 case DW_FORM_data2
:
15657 case DW_FORM_data4
:
15658 case DW_FORM_data8
:
15665 /* A helper function that fills in a dwarf2_loclist_baton. */
15668 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15669 struct dwarf2_loclist_baton
*baton
,
15670 struct attribute
*attr
)
15672 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15673 &dwarf2_per_objfile
->loc
);
15675 baton
->per_cu
= cu
->per_cu
;
15676 gdb_assert (baton
->per_cu
);
15677 /* We don't know how long the location list is, but make sure we
15678 don't run off the edge of the section. */
15679 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15680 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15681 baton
->base_address
= cu
->base_address
;
15685 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15686 struct dwarf2_cu
*cu
)
15688 if (attr_form_is_section_offset (attr
)
15689 /* ".debug_loc" may not exist at all, or the offset may be outside
15690 the section. If so, fall through to the complaint in the
15692 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15693 &dwarf2_per_objfile
->loc
))
15695 struct dwarf2_loclist_baton
*baton
;
15697 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15698 sizeof (struct dwarf2_loclist_baton
));
15700 fill_in_loclist_baton (cu
, baton
, attr
);
15702 if (cu
->base_known
== 0)
15703 complaint (&symfile_complaints
,
15704 _("Location list used without "
15705 "specifying the CU base address."));
15707 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15708 SYMBOL_LOCATION_BATON (sym
) = baton
;
15712 struct dwarf2_locexpr_baton
*baton
;
15714 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15715 sizeof (struct dwarf2_locexpr_baton
));
15716 baton
->per_cu
= cu
->per_cu
;
15717 gdb_assert (baton
->per_cu
);
15719 if (attr_form_is_block (attr
))
15721 /* Note that we're just copying the block's data pointer
15722 here, not the actual data. We're still pointing into the
15723 info_buffer for SYM's objfile; right now we never release
15724 that buffer, but when we do clean up properly this may
15726 baton
->size
= DW_BLOCK (attr
)->size
;
15727 baton
->data
= DW_BLOCK (attr
)->data
;
15731 dwarf2_invalid_attrib_class_complaint ("location description",
15732 SYMBOL_NATURAL_NAME (sym
));
15736 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15737 SYMBOL_LOCATION_BATON (sym
) = baton
;
15741 /* Return the OBJFILE associated with the compilation unit CU. If CU
15742 came from a separate debuginfo file, then the master objfile is
15746 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15748 struct objfile
*objfile
= per_cu
->objfile
;
15750 /* Return the master objfile, so that we can report and look up the
15751 correct file containing this variable. */
15752 if (objfile
->separate_debug_objfile_backlink
)
15753 objfile
= objfile
->separate_debug_objfile_backlink
;
15758 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15759 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15760 CU_HEADERP first. */
15762 static const struct comp_unit_head
*
15763 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15764 struct dwarf2_per_cu_data
*per_cu
)
15766 struct objfile
*objfile
;
15767 struct dwarf2_per_objfile
*per_objfile
;
15768 gdb_byte
*info_ptr
;
15771 return &per_cu
->cu
->header
;
15773 objfile
= per_cu
->objfile
;
15774 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15775 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15777 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15778 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15783 /* Return the address size given in the compilation unit header for CU. */
15786 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15788 struct comp_unit_head cu_header_local
;
15789 const struct comp_unit_head
*cu_headerp
;
15791 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15793 return cu_headerp
->addr_size
;
15796 /* Return the offset size given in the compilation unit header for CU. */
15799 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15801 struct comp_unit_head cu_header_local
;
15802 const struct comp_unit_head
*cu_headerp
;
15804 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15806 return cu_headerp
->offset_size
;
15809 /* See its dwarf2loc.h declaration. */
15812 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15814 struct comp_unit_head cu_header_local
;
15815 const struct comp_unit_head
*cu_headerp
;
15817 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15819 if (cu_headerp
->version
== 2)
15820 return cu_headerp
->addr_size
;
15822 return cu_headerp
->offset_size
;
15825 /* Return the text offset of the CU. The returned offset comes from
15826 this CU's objfile. If this objfile came from a separate debuginfo
15827 file, then the offset may be different from the corresponding
15828 offset in the parent objfile. */
15831 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15833 struct objfile
*objfile
= per_cu
->objfile
;
15835 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15838 /* Locate the .debug_info compilation unit from CU's objfile which contains
15839 the DIE at OFFSET. Raises an error on failure. */
15841 static struct dwarf2_per_cu_data
*
15842 dwarf2_find_containing_comp_unit (unsigned int offset
,
15843 struct objfile
*objfile
)
15845 struct dwarf2_per_cu_data
*this_cu
;
15849 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15852 int mid
= low
+ (high
- low
) / 2;
15854 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15859 gdb_assert (low
== high
);
15860 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15863 error (_("Dwarf Error: could not find partial DIE containing "
15864 "offset 0x%lx [in module %s]"),
15865 (long) offset
, bfd_get_filename (objfile
->obfd
));
15867 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15868 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15872 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15873 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15874 && offset
>= this_cu
->offset
+ this_cu
->length
)
15875 error (_("invalid dwarf2 offset %u"), offset
);
15876 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15881 /* Locate the compilation unit from OBJFILE which is located at exactly
15882 OFFSET. Raises an error on failure. */
15884 static struct dwarf2_per_cu_data
*
15885 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15887 struct dwarf2_per_cu_data
*this_cu
;
15889 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15890 if (this_cu
->offset
!= offset
)
15891 error (_("no compilation unit with offset %u."), offset
);
15895 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15898 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15900 memset (cu
, 0, sizeof (*cu
));
15901 cu
->objfile
= objfile
;
15902 obstack_init (&cu
->comp_unit_obstack
);
15905 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15908 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15910 struct attribute
*attr
;
15912 /* Set the language we're debugging. */
15913 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15915 set_cu_language (DW_UNSND (attr
), cu
);
15918 cu
->language
= language_minimal
;
15919 cu
->language_defn
= language_def (cu
->language
);
15923 /* Release one cached compilation unit, CU. We unlink it from the tree
15924 of compilation units, but we don't remove it from the read_in_chain;
15925 the caller is responsible for that.
15926 NOTE: DATA is a void * because this function is also used as a
15927 cleanup routine. */
15930 free_one_comp_unit (void *data
)
15932 struct dwarf2_cu
*cu
= data
;
15934 if (cu
->per_cu
!= NULL
)
15935 cu
->per_cu
->cu
= NULL
;
15938 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15943 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15944 when we're finished with it. We can't free the pointer itself, but be
15945 sure to unlink it from the cache. Also release any associated storage
15946 and perform cache maintenance.
15948 Only used during partial symbol parsing. */
15951 free_stack_comp_unit (void *data
)
15953 struct dwarf2_cu
*cu
= data
;
15955 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15956 cu
->partial_dies
= NULL
;
15958 if (cu
->per_cu
!= NULL
)
15960 /* This compilation unit is on the stack in our caller, so we
15961 should not xfree it. Just unlink it. */
15962 cu
->per_cu
->cu
= NULL
;
15965 /* If we had a per-cu pointer, then we may have other compilation
15966 units loaded, so age them now. */
15967 age_cached_comp_units ();
15971 /* Free all cached compilation units. */
15974 free_cached_comp_units (void *data
)
15976 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15978 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15979 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15980 while (per_cu
!= NULL
)
15982 struct dwarf2_per_cu_data
*next_cu
;
15984 next_cu
= per_cu
->cu
->read_in_chain
;
15986 free_one_comp_unit (per_cu
->cu
);
15987 *last_chain
= next_cu
;
15993 /* Increase the age counter on each cached compilation unit, and free
15994 any that are too old. */
15997 age_cached_comp_units (void)
15999 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16001 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16002 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16003 while (per_cu
!= NULL
)
16005 per_cu
->cu
->last_used
++;
16006 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16007 dwarf2_mark (per_cu
->cu
);
16008 per_cu
= per_cu
->cu
->read_in_chain
;
16011 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16012 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16013 while (per_cu
!= NULL
)
16015 struct dwarf2_per_cu_data
*next_cu
;
16017 next_cu
= per_cu
->cu
->read_in_chain
;
16019 if (!per_cu
->cu
->mark
)
16021 free_one_comp_unit (per_cu
->cu
);
16022 *last_chain
= next_cu
;
16025 last_chain
= &per_cu
->cu
->read_in_chain
;
16031 /* Remove a single compilation unit from the cache. */
16034 free_one_cached_comp_unit (void *target_cu
)
16036 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16038 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16039 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16040 while (per_cu
!= NULL
)
16042 struct dwarf2_per_cu_data
*next_cu
;
16044 next_cu
= per_cu
->cu
->read_in_chain
;
16046 if (per_cu
->cu
== target_cu
)
16048 free_one_comp_unit (per_cu
->cu
);
16049 *last_chain
= next_cu
;
16053 last_chain
= &per_cu
->cu
->read_in_chain
;
16059 /* Release all extra memory associated with OBJFILE. */
16062 dwarf2_free_objfile (struct objfile
*objfile
)
16064 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16066 if (dwarf2_per_objfile
== NULL
)
16069 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16070 free_cached_comp_units (NULL
);
16072 if (dwarf2_per_objfile
->quick_file_names_table
)
16073 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16075 /* Everything else should be on the objfile obstack. */
16078 /* A pair of DIE offset and GDB type pointer. We store these
16079 in a hash table separate from the DIEs, and preserve them
16080 when the DIEs are flushed out of cache. */
16082 struct dwarf2_offset_and_type
16084 unsigned int offset
;
16088 /* Hash function for a dwarf2_offset_and_type. */
16091 offset_and_type_hash (const void *item
)
16093 const struct dwarf2_offset_and_type
*ofs
= item
;
16095 return ofs
->offset
;
16098 /* Equality function for a dwarf2_offset_and_type. */
16101 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16103 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16104 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16106 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16109 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16110 table if necessary. For convenience, return TYPE.
16112 The DIEs reading must have careful ordering to:
16113 * Not cause infite loops trying to read in DIEs as a prerequisite for
16114 reading current DIE.
16115 * Not trying to dereference contents of still incompletely read in types
16116 while reading in other DIEs.
16117 * Enable referencing still incompletely read in types just by a pointer to
16118 the type without accessing its fields.
16120 Therefore caller should follow these rules:
16121 * Try to fetch any prerequisite types we may need to build this DIE type
16122 before building the type and calling set_die_type.
16123 * After building type call set_die_type for current DIE as soon as
16124 possible before fetching more types to complete the current type.
16125 * Make the type as complete as possible before fetching more types. */
16127 static struct type
*
16128 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16130 struct dwarf2_offset_and_type
**slot
, ofs
;
16131 struct objfile
*objfile
= cu
->objfile
;
16132 htab_t
*type_hash_ptr
;
16134 /* For Ada types, make sure that the gnat-specific data is always
16135 initialized (if not already set). There are a few types where
16136 we should not be doing so, because the type-specific area is
16137 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16138 where the type-specific area is used to store the floatformat).
16139 But this is not a problem, because the gnat-specific information
16140 is actually not needed for these types. */
16141 if (need_gnat_info (cu
)
16142 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16143 && TYPE_CODE (type
) != TYPE_CODE_FLT
16144 && !HAVE_GNAT_AUX_INFO (type
))
16145 INIT_GNAT_SPECIFIC (type
);
16147 if (cu
->per_cu
->debug_type_section
)
16148 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16150 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16152 if (*type_hash_ptr
== NULL
)
16155 = htab_create_alloc_ex (127,
16156 offset_and_type_hash
,
16157 offset_and_type_eq
,
16159 &objfile
->objfile_obstack
,
16160 hashtab_obstack_allocate
,
16161 dummy_obstack_deallocate
);
16164 ofs
.offset
= die
->offset
;
16166 slot
= (struct dwarf2_offset_and_type
**)
16167 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16169 complaint (&symfile_complaints
,
16170 _("A problem internal to GDB: DIE 0x%x has type already set"),
16172 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16177 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16178 table, or return NULL if the die does not have a saved type. */
16180 static struct type
*
16181 get_die_type_at_offset (unsigned int offset
,
16182 struct dwarf2_per_cu_data
*per_cu
)
16184 struct dwarf2_offset_and_type
*slot
, ofs
;
16187 if (per_cu
->debug_type_section
)
16188 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16190 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16191 if (type_hash
== NULL
)
16194 ofs
.offset
= offset
;
16195 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16202 /* Look up the type for DIE in the appropriate type_hash table,
16203 or return NULL if DIE does not have a saved type. */
16205 static struct type
*
16206 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16208 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16211 /* Add a dependence relationship from CU to REF_PER_CU. */
16214 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16215 struct dwarf2_per_cu_data
*ref_per_cu
)
16219 if (cu
->dependencies
== NULL
)
16221 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16222 NULL
, &cu
->comp_unit_obstack
,
16223 hashtab_obstack_allocate
,
16224 dummy_obstack_deallocate
);
16226 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16228 *slot
= ref_per_cu
;
16231 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16232 Set the mark field in every compilation unit in the
16233 cache that we must keep because we are keeping CU. */
16236 dwarf2_mark_helper (void **slot
, void *data
)
16238 struct dwarf2_per_cu_data
*per_cu
;
16240 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16242 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16243 reading of the chain. As such dependencies remain valid it is not much
16244 useful to track and undo them during QUIT cleanups. */
16245 if (per_cu
->cu
== NULL
)
16248 if (per_cu
->cu
->mark
)
16250 per_cu
->cu
->mark
= 1;
16252 if (per_cu
->cu
->dependencies
!= NULL
)
16253 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16258 /* Set the mark field in CU and in every other compilation unit in the
16259 cache that we must keep because we are keeping CU. */
16262 dwarf2_mark (struct dwarf2_cu
*cu
)
16267 if (cu
->dependencies
!= NULL
)
16268 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16272 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16276 per_cu
->cu
->mark
= 0;
16277 per_cu
= per_cu
->cu
->read_in_chain
;
16281 /* Trivial hash function for partial_die_info: the hash value of a DIE
16282 is its offset in .debug_info for this objfile. */
16285 partial_die_hash (const void *item
)
16287 const struct partial_die_info
*part_die
= item
;
16289 return part_die
->offset
;
16292 /* Trivial comparison function for partial_die_info structures: two DIEs
16293 are equal if they have the same offset. */
16296 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16298 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16299 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16301 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16304 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16305 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16308 set_dwarf2_cmd (char *args
, int from_tty
)
16310 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16314 show_dwarf2_cmd (char *args
, int from_tty
)
16316 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16319 /* If section described by INFO was mmapped, munmap it now. */
16322 munmap_section_buffer (struct dwarf2_section_info
*info
)
16324 if (info
->map_addr
!= NULL
)
16329 res
= munmap (info
->map_addr
, info
->map_len
);
16330 gdb_assert (res
== 0);
16332 /* Without HAVE_MMAP, we should never be here to begin with. */
16333 gdb_assert_not_reached ("no mmap support");
16338 /* munmap debug sections for OBJFILE, if necessary. */
16341 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16343 struct dwarf2_per_objfile
*data
= d
;
16345 struct dwarf2_section_info
*section
;
16347 /* This is sorted according to the order they're defined in to make it easier
16348 to keep in sync. */
16349 munmap_section_buffer (&data
->info
);
16350 munmap_section_buffer (&data
->abbrev
);
16351 munmap_section_buffer (&data
->line
);
16352 munmap_section_buffer (&data
->loc
);
16353 munmap_section_buffer (&data
->macinfo
);
16354 munmap_section_buffer (&data
->macro
);
16355 munmap_section_buffer (&data
->str
);
16356 munmap_section_buffer (&data
->ranges
);
16357 munmap_section_buffer (&data
->frame
);
16358 munmap_section_buffer (&data
->eh_frame
);
16359 munmap_section_buffer (&data
->gdb_index
);
16362 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16364 munmap_section_buffer (section
);
16366 VEC_free (dwarf2_section_info_def
, data
->types
);
16370 /* The "save gdb-index" command. */
16372 /* The contents of the hash table we create when building the string
16374 struct strtab_entry
16376 offset_type offset
;
16380 /* Hash function for a strtab_entry.
16382 Function is used only during write_hash_table so no index format backward
16383 compatibility is needed. */
16386 hash_strtab_entry (const void *e
)
16388 const struct strtab_entry
*entry
= e
;
16389 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16392 /* Equality function for a strtab_entry. */
16395 eq_strtab_entry (const void *a
, const void *b
)
16397 const struct strtab_entry
*ea
= a
;
16398 const struct strtab_entry
*eb
= b
;
16399 return !strcmp (ea
->str
, eb
->str
);
16402 /* Create a strtab_entry hash table. */
16405 create_strtab (void)
16407 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16408 xfree
, xcalloc
, xfree
);
16411 /* Add a string to the constant pool. Return the string's offset in
16415 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16418 struct strtab_entry entry
;
16419 struct strtab_entry
*result
;
16422 slot
= htab_find_slot (table
, &entry
, INSERT
);
16427 result
= XNEW (struct strtab_entry
);
16428 result
->offset
= obstack_object_size (cpool
);
16430 obstack_grow_str0 (cpool
, str
);
16433 return result
->offset
;
16436 /* An entry in the symbol table. */
16437 struct symtab_index_entry
16439 /* The name of the symbol. */
16441 /* The offset of the name in the constant pool. */
16442 offset_type index_offset
;
16443 /* A sorted vector of the indices of all the CUs that hold an object
16445 VEC (offset_type
) *cu_indices
;
16448 /* The symbol table. This is a power-of-2-sized hash table. */
16449 struct mapped_symtab
16451 offset_type n_elements
;
16453 struct symtab_index_entry
**data
;
16456 /* Hash function for a symtab_index_entry. */
16459 hash_symtab_entry (const void *e
)
16461 const struct symtab_index_entry
*entry
= e
;
16462 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16463 sizeof (offset_type
) * VEC_length (offset_type
,
16464 entry
->cu_indices
),
16468 /* Equality function for a symtab_index_entry. */
16471 eq_symtab_entry (const void *a
, const void *b
)
16473 const struct symtab_index_entry
*ea
= a
;
16474 const struct symtab_index_entry
*eb
= b
;
16475 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16476 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16478 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16479 VEC_address (offset_type
, eb
->cu_indices
),
16480 sizeof (offset_type
) * len
);
16483 /* Destroy a symtab_index_entry. */
16486 delete_symtab_entry (void *p
)
16488 struct symtab_index_entry
*entry
= p
;
16489 VEC_free (offset_type
, entry
->cu_indices
);
16493 /* Create a hash table holding symtab_index_entry objects. */
16496 create_symbol_hash_table (void)
16498 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16499 delete_symtab_entry
, xcalloc
, xfree
);
16502 /* Create a new mapped symtab object. */
16504 static struct mapped_symtab
*
16505 create_mapped_symtab (void)
16507 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16508 symtab
->n_elements
= 0;
16509 symtab
->size
= 1024;
16510 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16514 /* Destroy a mapped_symtab. */
16517 cleanup_mapped_symtab (void *p
)
16519 struct mapped_symtab
*symtab
= p
;
16520 /* The contents of the array are freed when the other hash table is
16522 xfree (symtab
->data
);
16526 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16529 Function is used only during write_hash_table so no index format backward
16530 compatibility is needed. */
16532 static struct symtab_index_entry
**
16533 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16535 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16537 index
= hash
& (symtab
->size
- 1);
16538 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16542 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16543 return &symtab
->data
[index
];
16544 index
= (index
+ step
) & (symtab
->size
- 1);
16548 /* Expand SYMTAB's hash table. */
16551 hash_expand (struct mapped_symtab
*symtab
)
16553 offset_type old_size
= symtab
->size
;
16555 struct symtab_index_entry
**old_entries
= symtab
->data
;
16558 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16560 for (i
= 0; i
< old_size
; ++i
)
16562 if (old_entries
[i
])
16564 struct symtab_index_entry
**slot
= find_slot (symtab
,
16565 old_entries
[i
]->name
);
16566 *slot
= old_entries
[i
];
16570 xfree (old_entries
);
16573 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16574 is the index of the CU in which the symbol appears. */
16577 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16578 offset_type cu_index
)
16580 struct symtab_index_entry
**slot
;
16582 ++symtab
->n_elements
;
16583 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16584 hash_expand (symtab
);
16586 slot
= find_slot (symtab
, name
);
16589 *slot
= XNEW (struct symtab_index_entry
);
16590 (*slot
)->name
= name
;
16591 (*slot
)->cu_indices
= NULL
;
16593 /* Don't push an index twice. Due to how we add entries we only
16594 have to check the last one. */
16595 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16596 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16597 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16600 /* Add a vector of indices to the constant pool. */
16603 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16604 struct symtab_index_entry
*entry
)
16608 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16611 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16612 offset_type val
= MAYBE_SWAP (len
);
16617 entry
->index_offset
= obstack_object_size (cpool
);
16619 obstack_grow (cpool
, &val
, sizeof (val
));
16621 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16624 val
= MAYBE_SWAP (iter
);
16625 obstack_grow (cpool
, &val
, sizeof (val
));
16630 struct symtab_index_entry
*old_entry
= *slot
;
16631 entry
->index_offset
= old_entry
->index_offset
;
16634 return entry
->index_offset
;
16637 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16638 constant pool entries going into the obstack CPOOL. */
16641 write_hash_table (struct mapped_symtab
*symtab
,
16642 struct obstack
*output
, struct obstack
*cpool
)
16645 htab_t symbol_hash_table
;
16648 symbol_hash_table
= create_symbol_hash_table ();
16649 str_table
= create_strtab ();
16651 /* We add all the index vectors to the constant pool first, to
16652 ensure alignment is ok. */
16653 for (i
= 0; i
< symtab
->size
; ++i
)
16655 if (symtab
->data
[i
])
16656 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16659 /* Now write out the hash table. */
16660 for (i
= 0; i
< symtab
->size
; ++i
)
16662 offset_type str_off
, vec_off
;
16664 if (symtab
->data
[i
])
16666 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16667 vec_off
= symtab
->data
[i
]->index_offset
;
16671 /* While 0 is a valid constant pool index, it is not valid
16672 to have 0 for both offsets. */
16677 str_off
= MAYBE_SWAP (str_off
);
16678 vec_off
= MAYBE_SWAP (vec_off
);
16680 obstack_grow (output
, &str_off
, sizeof (str_off
));
16681 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16684 htab_delete (str_table
);
16685 htab_delete (symbol_hash_table
);
16688 /* Struct to map psymtab to CU index in the index file. */
16689 struct psymtab_cu_index_map
16691 struct partial_symtab
*psymtab
;
16692 unsigned int cu_index
;
16696 hash_psymtab_cu_index (const void *item
)
16698 const struct psymtab_cu_index_map
*map
= item
;
16700 return htab_hash_pointer (map
->psymtab
);
16704 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16706 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16707 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16709 return lhs
->psymtab
== rhs
->psymtab
;
16712 /* Helper struct for building the address table. */
16713 struct addrmap_index_data
16715 struct objfile
*objfile
;
16716 struct obstack
*addr_obstack
;
16717 htab_t cu_index_htab
;
16719 /* Non-zero if the previous_* fields are valid.
16720 We can't write an entry until we see the next entry (since it is only then
16721 that we know the end of the entry). */
16722 int previous_valid
;
16723 /* Index of the CU in the table of all CUs in the index file. */
16724 unsigned int previous_cu_index
;
16725 /* Start address of the CU. */
16726 CORE_ADDR previous_cu_start
;
16729 /* Write an address entry to OBSTACK. */
16732 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16733 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16735 offset_type cu_index_to_write
;
16737 CORE_ADDR baseaddr
;
16739 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16741 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16742 obstack_grow (obstack
, addr
, 8);
16743 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16744 obstack_grow (obstack
, addr
, 8);
16745 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16746 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16749 /* Worker function for traversing an addrmap to build the address table. */
16752 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16754 struct addrmap_index_data
*data
= datap
;
16755 struct partial_symtab
*pst
= obj
;
16756 offset_type cu_index
;
16759 if (data
->previous_valid
)
16760 add_address_entry (data
->objfile
, data
->addr_obstack
,
16761 data
->previous_cu_start
, start_addr
,
16762 data
->previous_cu_index
);
16764 data
->previous_cu_start
= start_addr
;
16767 struct psymtab_cu_index_map find_map
, *map
;
16768 find_map
.psymtab
= pst
;
16769 map
= htab_find (data
->cu_index_htab
, &find_map
);
16770 gdb_assert (map
!= NULL
);
16771 data
->previous_cu_index
= map
->cu_index
;
16772 data
->previous_valid
= 1;
16775 data
->previous_valid
= 0;
16780 /* Write OBJFILE's address map to OBSTACK.
16781 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16782 in the index file. */
16785 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16786 htab_t cu_index_htab
)
16788 struct addrmap_index_data addrmap_index_data
;
16790 /* When writing the address table, we have to cope with the fact that
16791 the addrmap iterator only provides the start of a region; we have to
16792 wait until the next invocation to get the start of the next region. */
16794 addrmap_index_data
.objfile
= objfile
;
16795 addrmap_index_data
.addr_obstack
= obstack
;
16796 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16797 addrmap_index_data
.previous_valid
= 0;
16799 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16800 &addrmap_index_data
);
16802 /* It's highly unlikely the last entry (end address = 0xff...ff)
16803 is valid, but we should still handle it.
16804 The end address is recorded as the start of the next region, but that
16805 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16807 if (addrmap_index_data
.previous_valid
)
16808 add_address_entry (objfile
, obstack
,
16809 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16810 addrmap_index_data
.previous_cu_index
);
16813 /* Add a list of partial symbols to SYMTAB. */
16816 write_psymbols (struct mapped_symtab
*symtab
,
16818 struct partial_symbol
**psymp
,
16820 offset_type cu_index
,
16823 for (; count
-- > 0; ++psymp
)
16825 void **slot
, *lookup
;
16827 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16828 error (_("Ada is not currently supported by the index"));
16830 /* We only want to add a given psymbol once. However, we also
16831 want to account for whether it is global or static. So, we
16832 may add it twice, using slightly different values. */
16835 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16837 lookup
= (void *) val
;
16842 /* Only add a given psymbol once. */
16843 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16847 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16852 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16853 exception if there is an error. */
16856 write_obstack (FILE *file
, struct obstack
*obstack
)
16858 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16860 != obstack_object_size (obstack
))
16861 error (_("couldn't data write to file"));
16864 /* Unlink a file if the argument is not NULL. */
16867 unlink_if_set (void *p
)
16869 char **filename
= p
;
16871 unlink (*filename
);
16874 /* A helper struct used when iterating over debug_types. */
16875 struct signatured_type_index_data
16877 struct objfile
*objfile
;
16878 struct mapped_symtab
*symtab
;
16879 struct obstack
*types_list
;
16884 /* A helper function that writes a single signatured_type to an
16888 write_one_signatured_type (void **slot
, void *d
)
16890 struct signatured_type_index_data
*info
= d
;
16891 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16892 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16893 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16896 write_psymbols (info
->symtab
,
16898 info
->objfile
->global_psymbols
.list
16899 + psymtab
->globals_offset
,
16900 psymtab
->n_global_syms
, info
->cu_index
,
16902 write_psymbols (info
->symtab
,
16904 info
->objfile
->static_psymbols
.list
16905 + psymtab
->statics_offset
,
16906 psymtab
->n_static_syms
, info
->cu_index
,
16909 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16910 obstack_grow (info
->types_list
, val
, 8);
16911 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16912 obstack_grow (info
->types_list
, val
, 8);
16913 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16914 obstack_grow (info
->types_list
, val
, 8);
16921 /* Create an index file for OBJFILE in the directory DIR. */
16924 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16926 struct cleanup
*cleanup
;
16927 char *filename
, *cleanup_filename
;
16928 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16929 struct obstack cu_list
, types_cu_list
;
16932 struct mapped_symtab
*symtab
;
16933 offset_type val
, size_of_contents
, total_len
;
16937 htab_t cu_index_htab
;
16938 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16940 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16943 if (dwarf2_per_objfile
->using_index
)
16944 error (_("Cannot use an index to create the index"));
16946 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16947 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16949 if (stat (objfile
->name
, &st
) < 0)
16950 perror_with_name (objfile
->name
);
16952 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16953 INDEX_SUFFIX
, (char *) NULL
);
16954 cleanup
= make_cleanup (xfree
, filename
);
16956 out_file
= fopen (filename
, "wb");
16958 error (_("Can't open `%s' for writing"), filename
);
16960 cleanup_filename
= filename
;
16961 make_cleanup (unlink_if_set
, &cleanup_filename
);
16963 symtab
= create_mapped_symtab ();
16964 make_cleanup (cleanup_mapped_symtab
, symtab
);
16966 obstack_init (&addr_obstack
);
16967 make_cleanup_obstack_free (&addr_obstack
);
16969 obstack_init (&cu_list
);
16970 make_cleanup_obstack_free (&cu_list
);
16972 obstack_init (&types_cu_list
);
16973 make_cleanup_obstack_free (&types_cu_list
);
16975 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16976 NULL
, xcalloc
, xfree
);
16977 make_cleanup_htab_delete (psyms_seen
);
16979 /* While we're scanning CU's create a table that maps a psymtab pointer
16980 (which is what addrmap records) to its index (which is what is recorded
16981 in the index file). This will later be needed to write the address
16983 cu_index_htab
= htab_create_alloc (100,
16984 hash_psymtab_cu_index
,
16985 eq_psymtab_cu_index
,
16986 NULL
, xcalloc
, xfree
);
16987 make_cleanup_htab_delete (cu_index_htab
);
16988 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16989 xmalloc (sizeof (struct psymtab_cu_index_map
)
16990 * dwarf2_per_objfile
->n_comp_units
);
16991 make_cleanup (xfree
, psymtab_cu_index_map
);
16993 /* The CU list is already sorted, so we don't need to do additional
16994 work here. Also, the debug_types entries do not appear in
16995 all_comp_units, but only in their own hash table. */
16996 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16998 struct dwarf2_per_cu_data
*per_cu
16999 = dwarf2_per_objfile
->all_comp_units
[i
];
17000 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17002 struct psymtab_cu_index_map
*map
;
17005 write_psymbols (symtab
,
17007 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17008 psymtab
->n_global_syms
, i
,
17010 write_psymbols (symtab
,
17012 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17013 psymtab
->n_static_syms
, i
,
17016 map
= &psymtab_cu_index_map
[i
];
17017 map
->psymtab
= psymtab
;
17019 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17020 gdb_assert (slot
!= NULL
);
17021 gdb_assert (*slot
== NULL
);
17024 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
17025 obstack_grow (&cu_list
, val
, 8);
17026 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17027 obstack_grow (&cu_list
, val
, 8);
17030 /* Dump the address map. */
17031 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17033 /* Write out the .debug_type entries, if any. */
17034 if (dwarf2_per_objfile
->signatured_types
)
17036 struct signatured_type_index_data sig_data
;
17038 sig_data
.objfile
= objfile
;
17039 sig_data
.symtab
= symtab
;
17040 sig_data
.types_list
= &types_cu_list
;
17041 sig_data
.psyms_seen
= psyms_seen
;
17042 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17043 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17044 write_one_signatured_type
, &sig_data
);
17047 obstack_init (&constant_pool
);
17048 make_cleanup_obstack_free (&constant_pool
);
17049 obstack_init (&symtab_obstack
);
17050 make_cleanup_obstack_free (&symtab_obstack
);
17051 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17053 obstack_init (&contents
);
17054 make_cleanup_obstack_free (&contents
);
17055 size_of_contents
= 6 * sizeof (offset_type
);
17056 total_len
= size_of_contents
;
17058 /* The version number. */
17059 val
= MAYBE_SWAP (5);
17060 obstack_grow (&contents
, &val
, sizeof (val
));
17062 /* The offset of the CU list from the start of the file. */
17063 val
= MAYBE_SWAP (total_len
);
17064 obstack_grow (&contents
, &val
, sizeof (val
));
17065 total_len
+= obstack_object_size (&cu_list
);
17067 /* The offset of the types CU list from the start of the file. */
17068 val
= MAYBE_SWAP (total_len
);
17069 obstack_grow (&contents
, &val
, sizeof (val
));
17070 total_len
+= obstack_object_size (&types_cu_list
);
17072 /* The offset of the address table from the start of the file. */
17073 val
= MAYBE_SWAP (total_len
);
17074 obstack_grow (&contents
, &val
, sizeof (val
));
17075 total_len
+= obstack_object_size (&addr_obstack
);
17077 /* The offset of the symbol table from the start of the file. */
17078 val
= MAYBE_SWAP (total_len
);
17079 obstack_grow (&contents
, &val
, sizeof (val
));
17080 total_len
+= obstack_object_size (&symtab_obstack
);
17082 /* The offset of the constant pool from the start of the file. */
17083 val
= MAYBE_SWAP (total_len
);
17084 obstack_grow (&contents
, &val
, sizeof (val
));
17085 total_len
+= obstack_object_size (&constant_pool
);
17087 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17089 write_obstack (out_file
, &contents
);
17090 write_obstack (out_file
, &cu_list
);
17091 write_obstack (out_file
, &types_cu_list
);
17092 write_obstack (out_file
, &addr_obstack
);
17093 write_obstack (out_file
, &symtab_obstack
);
17094 write_obstack (out_file
, &constant_pool
);
17098 /* We want to keep the file, so we set cleanup_filename to NULL
17099 here. See unlink_if_set. */
17100 cleanup_filename
= NULL
;
17102 do_cleanups (cleanup
);
17105 /* Implementation of the `save gdb-index' command.
17107 Note that the file format used by this command is documented in the
17108 GDB manual. Any changes here must be documented there. */
17111 save_gdb_index_command (char *arg
, int from_tty
)
17113 struct objfile
*objfile
;
17116 error (_("usage: save gdb-index DIRECTORY"));
17118 ALL_OBJFILES (objfile
)
17122 /* If the objfile does not correspond to an actual file, skip it. */
17123 if (stat (objfile
->name
, &st
) < 0)
17126 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17127 if (dwarf2_per_objfile
)
17129 volatile struct gdb_exception except
;
17131 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17133 write_psymtabs_to_index (objfile
, arg
);
17135 if (except
.reason
< 0)
17136 exception_fprintf (gdb_stderr
, except
,
17137 _("Error while writing index for `%s': "),
17145 int dwarf2_always_disassemble
;
17148 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17149 struct cmd_list_element
*c
, const char *value
)
17151 fprintf_filtered (file
,
17152 _("Whether to always disassemble "
17153 "DWARF expressions is %s.\n"),
17158 show_check_physname (struct ui_file
*file
, int from_tty
,
17159 struct cmd_list_element
*c
, const char *value
)
17161 fprintf_filtered (file
,
17162 _("Whether to check \"physname\" is %s.\n"),
17166 void _initialize_dwarf2_read (void);
17169 _initialize_dwarf2_read (void)
17171 struct cmd_list_element
*c
;
17173 dwarf2_objfile_data_key
17174 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17176 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17177 Set DWARF 2 specific variables.\n\
17178 Configure DWARF 2 variables such as the cache size"),
17179 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17180 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17182 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17183 Show DWARF 2 specific variables\n\
17184 Show DWARF 2 variables such as the cache size"),
17185 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17186 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17188 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17189 &dwarf2_max_cache_age
, _("\
17190 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17191 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17192 A higher limit means that cached compilation units will be stored\n\
17193 in memory longer, and more total memory will be used. Zero disables\n\
17194 caching, which can slow down startup."),
17196 show_dwarf2_max_cache_age
,
17197 &set_dwarf2_cmdlist
,
17198 &show_dwarf2_cmdlist
);
17200 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17201 &dwarf2_always_disassemble
, _("\
17202 Set whether `info address' always disassembles DWARF expressions."), _("\
17203 Show whether `info address' always disassembles DWARF expressions."), _("\
17204 When enabled, DWARF expressions are always printed in an assembly-like\n\
17205 syntax. When disabled, expressions will be printed in a more\n\
17206 conversational style, when possible."),
17208 show_dwarf2_always_disassemble
,
17209 &set_dwarf2_cmdlist
,
17210 &show_dwarf2_cmdlist
);
17212 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17213 Set debugging of the dwarf2 DIE reader."), _("\
17214 Show debugging of the dwarf2 DIE reader."), _("\
17215 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17216 The value is the maximum depth to print."),
17219 &setdebuglist
, &showdebuglist
);
17221 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17222 Set cross-checking of \"physname\" code against demangler."), _("\
17223 Show cross-checking of \"physname\" code against demangler."), _("\
17224 When enabled, GDB's internal \"physname\" code is checked against\n\
17226 NULL
, show_check_physname
,
17227 &setdebuglist
, &showdebuglist
);
17229 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17231 Save a gdb-index file.\n\
17232 Usage: save gdb-index DIRECTORY"),
17234 set_cmd_completer (c
, filename_completer
);