1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname
= 0;
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
131 static int processing_has_namespace_info
;
133 static const struct objfile_data
*dwarf2_objfile_data_key
;
135 struct dwarf2_section_info
140 /* Not NULL if the section was actually mmapped. */
142 /* Page aligned size of mmapped area. */
143 bfd_size_type map_len
;
144 /* True if we have tried to read this section. */
148 typedef struct dwarf2_section_info dwarf2_section_info_def
;
149 DEF_VEC_O (dwarf2_section_info_def
);
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type
;
155 DEF_VEC_I (offset_type
);
157 /* A description of the mapped index. The file format is described in
158 a comment by the code that writes the index. */
161 /* Index data format version. */
164 /* The total length of the buffer. */
167 /* A pointer to the address table data. */
168 const gdb_byte
*address_table
;
170 /* Size of the address table data in bytes. */
171 offset_type address_table_size
;
173 /* The symbol table, implemented as a hash table. */
174 const offset_type
*symbol_table
;
176 /* Size in slots, each slot is 2 offset_types. */
177 offset_type symbol_table_slots
;
179 /* A pointer to the constant pool. */
180 const char *constant_pool
;
183 struct dwarf2_per_objfile
185 struct dwarf2_section_info info
;
186 struct dwarf2_section_info abbrev
;
187 struct dwarf2_section_info line
;
188 struct dwarf2_section_info loc
;
189 struct dwarf2_section_info macinfo
;
190 struct dwarf2_section_info str
;
191 struct dwarf2_section_info ranges
;
192 struct dwarf2_section_info frame
;
193 struct dwarf2_section_info eh_frame
;
194 struct dwarf2_section_info gdb_index
;
196 VEC (dwarf2_section_info_def
) *types
;
199 struct objfile
*objfile
;
201 /* A list of all the compilation units. This is used to locate
202 the target compilation unit of a particular reference. */
203 struct dwarf2_per_cu_data
**all_comp_units
;
205 /* The number of compilation units in ALL_COMP_UNITS. */
208 /* The number of .debug_types-related CUs. */
209 int n_type_comp_units
;
211 /* The .debug_types-related CUs. */
212 struct dwarf2_per_cu_data
**type_comp_units
;
214 /* A chain of compilation units that are currently read in, so that
215 they can be freed later. */
216 struct dwarf2_per_cu_data
*read_in_chain
;
218 /* A table mapping .debug_types signatures to its signatured_type entry.
219 This is NULL if the .debug_types section hasn't been read in yet. */
220 htab_t signatured_types
;
222 /* A flag indicating wether this objfile has a section loaded at a
224 int has_section_at_zero
;
226 /* True if we are using the mapped index,
227 or we are faking it for OBJF_READNOW's sake. */
228 unsigned char using_index
;
230 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
231 struct mapped_index
*index_table
;
233 /* When using index_table, this keeps track of all quick_file_names entries.
234 TUs can share line table entries with CUs or other TUs, and there can be
235 a lot more TUs than unique line tables, so we maintain a separate table
236 of all line table entries to support the sharing. */
237 htab_t quick_file_names_table
;
239 /* Set during partial symbol reading, to prevent queueing of full
241 int reading_partial_symbols
;
243 /* Table mapping type .debug_info DIE offsets to types.
244 This is NULL if not allocated yet.
245 It (currently) makes sense to allocate debug_types_type_hash lazily.
246 To keep things simple we allocate both lazily. */
247 htab_t debug_info_type_hash
;
249 /* Table mapping type .debug_types DIE offsets to types.
250 This is NULL if not allocated yet. */
251 htab_t debug_types_type_hash
;
254 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
256 /* Default names of the debugging sections. */
258 /* Note that if the debugging section has been compressed, it might
259 have a name like .zdebug_info. */
261 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
262 { ".debug_info", ".zdebug_info" },
263 { ".debug_abbrev", ".zdebug_abbrev" },
264 { ".debug_line", ".zdebug_line" },
265 { ".debug_loc", ".zdebug_loc" },
266 { ".debug_macinfo", ".zdebug_macinfo" },
267 { ".debug_str", ".zdebug_str" },
268 { ".debug_ranges", ".zdebug_ranges" },
269 { ".debug_types", ".zdebug_types" },
270 { ".debug_frame", ".zdebug_frame" },
271 { ".eh_frame", NULL
},
272 { ".gdb_index", ".zgdb_index" }
275 /* local data types */
277 /* We hold several abbreviation tables in memory at the same time. */
278 #ifndef ABBREV_HASH_SIZE
279 #define ABBREV_HASH_SIZE 121
282 /* The data in a compilation unit header, after target2host
283 translation, looks like this. */
284 struct comp_unit_head
288 unsigned char addr_size
;
289 unsigned char signed_addr_p
;
290 unsigned int abbrev_offset
;
292 /* Size of file offsets; either 4 or 8. */
293 unsigned int offset_size
;
295 /* Size of the length field; either 4 or 12. */
296 unsigned int initial_length_size
;
298 /* Offset to the first byte of this compilation unit header in the
299 .debug_info section, for resolving relative reference dies. */
302 /* Offset to first die in this cu from the start of the cu.
303 This will be the first byte following the compilation unit header. */
304 unsigned int first_die_offset
;
307 /* Type used for delaying computation of method physnames.
308 See comments for compute_delayed_physnames. */
309 struct delayed_method_info
311 /* The type to which the method is attached, i.e., its parent class. */
314 /* The index of the method in the type's function fieldlists. */
317 /* The index of the method in the fieldlist. */
320 /* The name of the DIE. */
323 /* The DIE associated with this method. */
324 struct die_info
*die
;
327 typedef struct delayed_method_info delayed_method_info
;
328 DEF_VEC_O (delayed_method_info
);
330 /* Internal state when decoding a particular compilation unit. */
333 /* The objfile containing this compilation unit. */
334 struct objfile
*objfile
;
336 /* The header of the compilation unit. */
337 struct comp_unit_head header
;
339 /* Base address of this compilation unit. */
340 CORE_ADDR base_address
;
342 /* Non-zero if base_address has been set. */
345 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
347 /* The language we are debugging. */
348 enum language language
;
349 const struct language_defn
*language_defn
;
351 const char *producer
;
353 /* The generic symbol table building routines have separate lists for
354 file scope symbols and all all other scopes (local scopes). So
355 we need to select the right one to pass to add_symbol_to_list().
356 We do it by keeping a pointer to the correct list in list_in_scope.
358 FIXME: The original dwarf code just treated the file scope as the
359 first local scope, and all other local scopes as nested local
360 scopes, and worked fine. Check to see if we really need to
361 distinguish these in buildsym.c. */
362 struct pending
**list_in_scope
;
364 /* DWARF abbreviation table associated with this compilation unit. */
365 struct abbrev_info
**dwarf2_abbrevs
;
367 /* Storage for the abbrev table. */
368 struct obstack abbrev_obstack
;
370 /* Hash table holding all the loaded partial DIEs. */
373 /* Storage for things with the same lifetime as this read-in compilation
374 unit, including partial DIEs. */
375 struct obstack comp_unit_obstack
;
377 /* When multiple dwarf2_cu structures are living in memory, this field
378 chains them all together, so that they can be released efficiently.
379 We will probably also want a generation counter so that most-recently-used
380 compilation units are cached... */
381 struct dwarf2_per_cu_data
*read_in_chain
;
383 /* Backchain to our per_cu entry if the tree has been built. */
384 struct dwarf2_per_cu_data
*per_cu
;
386 /* How many compilation units ago was this CU last referenced? */
389 /* A hash table of die offsets for following references. */
392 /* Full DIEs if read in. */
393 struct die_info
*dies
;
395 /* A set of pointers to dwarf2_per_cu_data objects for compilation
396 units referenced by this one. Only set during full symbol processing;
397 partial symbol tables do not have dependencies. */
400 /* Header data from the line table, during full symbol processing. */
401 struct line_header
*line_header
;
403 /* A list of methods which need to have physnames computed
404 after all type information has been read. */
405 VEC (delayed_method_info
) *method_list
;
407 /* Mark used when releasing cached dies. */
408 unsigned int mark
: 1;
410 /* This flag will be set if this compilation unit might include
411 inter-compilation-unit references. */
412 unsigned int has_form_ref_addr
: 1;
414 /* This flag will be set if this compilation unit includes any
415 DW_TAG_namespace DIEs. If we know that there are explicit
416 DIEs for namespaces, we don't need to try to infer them
417 from mangled names. */
418 unsigned int has_namespace_info
: 1;
420 /* This CU references .debug_loc. See the symtab->locations_valid field.
421 This test is imperfect as there may exist optimized debug code not using
422 any location list and still facing inlining issues if handled as
423 unoptimized code. For a future better test see GCC PR other/32998. */
425 unsigned int has_loclist
: 1;
428 /* Persistent data held for a compilation unit, even when not
429 processing it. We put a pointer to this structure in the
430 read_symtab_private field of the psymtab. If we encounter
431 inter-compilation-unit references, we also maintain a sorted
432 list of all compilation units. */
434 struct dwarf2_per_cu_data
436 /* The start offset and length of this compilation unit. 2**29-1
437 bytes should suffice to store the length of any compilation unit
438 - if it doesn't, GDB will fall over anyway.
439 NOTE: Unlike comp_unit_head.length, this length includes
440 initial_length_size. */
442 unsigned int length
: 29;
444 /* Flag indicating this compilation unit will be read in before
445 any of the current compilation units are processed. */
446 unsigned int queued
: 1;
448 /* This flag will be set if we need to load absolutely all DIEs
449 for this compilation unit, instead of just the ones we think
450 are interesting. It gets set if we look for a DIE in the
451 hash table and don't find it. */
452 unsigned int load_all_dies
: 1;
454 /* Non-null if this CU is from .debug_types; in which case it points
455 to the section. Otherwise it's from .debug_info. */
456 struct dwarf2_section_info
*debug_type_section
;
458 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
459 of the CU cache it gets reset to NULL again. */
460 struct dwarf2_cu
*cu
;
462 /* The corresponding objfile. */
463 struct objfile
*objfile
;
465 /* When using partial symbol tables, the 'psymtab' field is active.
466 Otherwise the 'quick' field is active. */
469 /* The partial symbol table associated with this compilation unit,
470 or NULL for partial units (which do not have an associated
472 struct partial_symtab
*psymtab
;
474 /* Data needed by the "quick" functions. */
475 struct dwarf2_per_cu_quick_data
*quick
;
479 /* Entry in the signatured_types hash table. */
481 struct signatured_type
485 /* Offset in .debug_types of the type defined by this TU. */
486 unsigned int type_offset
;
488 /* The CU(/TU) of this type. */
489 struct dwarf2_per_cu_data per_cu
;
492 /* Struct used to pass misc. parameters to read_die_and_children, et
493 al. which are used for both .debug_info and .debug_types dies.
494 All parameters here are unchanging for the life of the call. This
495 struct exists to abstract away the constant parameters of die
498 struct die_reader_specs
500 /* The bfd of this objfile. */
503 /* The CU of the DIE we are parsing. */
504 struct dwarf2_cu
*cu
;
506 /* Pointer to start of section buffer.
507 This is either the start of .debug_info or .debug_types. */
508 const gdb_byte
*buffer
;
511 /* The line number information for a compilation unit (found in the
512 .debug_line section) begins with a "statement program header",
513 which contains the following information. */
516 unsigned int total_length
;
517 unsigned short version
;
518 unsigned int header_length
;
519 unsigned char minimum_instruction_length
;
520 unsigned char maximum_ops_per_instruction
;
521 unsigned char default_is_stmt
;
523 unsigned char line_range
;
524 unsigned char opcode_base
;
526 /* standard_opcode_lengths[i] is the number of operands for the
527 standard opcode whose value is i. This means that
528 standard_opcode_lengths[0] is unused, and the last meaningful
529 element is standard_opcode_lengths[opcode_base - 1]. */
530 unsigned char *standard_opcode_lengths
;
532 /* The include_directories table. NOTE! These strings are not
533 allocated with xmalloc; instead, they are pointers into
534 debug_line_buffer. If you try to free them, `free' will get
536 unsigned int num_include_dirs
, include_dirs_size
;
539 /* The file_names table. NOTE! These strings are not allocated
540 with xmalloc; instead, they are pointers into debug_line_buffer.
541 Don't try to free them directly. */
542 unsigned int num_file_names
, file_names_size
;
546 unsigned int dir_index
;
547 unsigned int mod_time
;
549 int included_p
; /* Non-zero if referenced by the Line Number Program. */
550 struct symtab
*symtab
; /* The associated symbol table, if any. */
553 /* The start and end of the statement program following this
554 header. These point into dwarf2_per_objfile->line_buffer. */
555 gdb_byte
*statement_program_start
, *statement_program_end
;
558 /* When we construct a partial symbol table entry we only
559 need this much information. */
560 struct partial_die_info
562 /* Offset of this DIE. */
565 /* DWARF-2 tag for this DIE. */
566 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
568 /* Assorted flags describing the data found in this DIE. */
569 unsigned int has_children
: 1;
570 unsigned int is_external
: 1;
571 unsigned int is_declaration
: 1;
572 unsigned int has_type
: 1;
573 unsigned int has_specification
: 1;
574 unsigned int has_pc_info
: 1;
576 /* Flag set if the SCOPE field of this structure has been
578 unsigned int scope_set
: 1;
580 /* Flag set if the DIE has a byte_size attribute. */
581 unsigned int has_byte_size
: 1;
583 /* Flag set if any of the DIE's children are template arguments. */
584 unsigned int has_template_arguments
: 1;
586 /* Flag set if fixup_partial_die has been called on this die. */
587 unsigned int fixup_called
: 1;
589 /* The name of this DIE. Normally the value of DW_AT_name, but
590 sometimes a default name for unnamed DIEs. */
593 /* The linkage name, if present. */
594 const char *linkage_name
;
596 /* The scope to prepend to our children. This is generally
597 allocated on the comp_unit_obstack, so will disappear
598 when this compilation unit leaves the cache. */
601 /* The location description associated with this DIE, if any. */
602 struct dwarf_block
*locdesc
;
604 /* If HAS_PC_INFO, the PC range associated with this DIE. */
608 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
609 DW_AT_sibling, if any. */
610 /* NOTE: This member isn't strictly necessary, read_partial_die could
611 return DW_AT_sibling values to its caller load_partial_dies. */
614 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
615 DW_AT_specification (or DW_AT_abstract_origin or
617 unsigned int spec_offset
;
619 /* Pointers to this DIE's parent, first child, and next sibling,
621 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
624 /* This data structure holds the information of an abbrev. */
627 unsigned int number
; /* number identifying abbrev */
628 enum dwarf_tag tag
; /* dwarf tag */
629 unsigned short has_children
; /* boolean */
630 unsigned short num_attrs
; /* number of attributes */
631 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
632 struct abbrev_info
*next
; /* next in chain */
637 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
638 ENUM_BITFIELD(dwarf_form
) form
: 16;
641 /* Attributes have a name and a value. */
644 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
645 ENUM_BITFIELD(dwarf_form
) form
: 15;
647 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
648 field should be in u.str (existing only for DW_STRING) but it is kept
649 here for better struct attribute alignment. */
650 unsigned int string_is_canonical
: 1;
655 struct dwarf_block
*blk
;
659 struct signatured_type
*signatured_type
;
664 /* This data structure holds a complete die structure. */
667 /* DWARF-2 tag for this DIE. */
668 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
670 /* Number of attributes */
671 unsigned char num_attrs
;
673 /* True if we're presently building the full type name for the
674 type derived from this DIE. */
675 unsigned char building_fullname
: 1;
680 /* Offset in .debug_info or .debug_types section. */
683 /* The dies in a compilation unit form an n-ary tree. PARENT
684 points to this die's parent; CHILD points to the first child of
685 this node; and all the children of a given node are chained
686 together via their SIBLING fields. */
687 struct die_info
*child
; /* Its first child, if any. */
688 struct die_info
*sibling
; /* Its next sibling, if any. */
689 struct die_info
*parent
; /* Its parent, if any. */
691 /* An array of attributes, with NUM_ATTRS elements. There may be
692 zero, but it's not common and zero-sized arrays are not
693 sufficiently portable C. */
694 struct attribute attrs
[1];
697 struct function_range
700 CORE_ADDR lowpc
, highpc
;
702 struct function_range
*next
;
705 /* Get at parts of an attribute structure. */
707 #define DW_STRING(attr) ((attr)->u.str)
708 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
709 #define DW_UNSND(attr) ((attr)->u.unsnd)
710 #define DW_BLOCK(attr) ((attr)->u.blk)
711 #define DW_SND(attr) ((attr)->u.snd)
712 #define DW_ADDR(attr) ((attr)->u.addr)
713 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
715 /* Blocks are a bunch of untyped bytes. */
722 #ifndef ATTR_ALLOC_CHUNK
723 #define ATTR_ALLOC_CHUNK 4
726 /* Allocate fields for structs, unions and enums in this size. */
727 #ifndef DW_FIELD_ALLOC_CHUNK
728 #define DW_FIELD_ALLOC_CHUNK 4
731 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
732 but this would require a corresponding change in unpack_field_as_long
734 static int bits_per_byte
= 8;
736 /* The routines that read and process dies for a C struct or C++ class
737 pass lists of data member fields and lists of member function fields
738 in an instance of a field_info structure, as defined below. */
741 /* List of data member and baseclasses fields. */
744 struct nextfield
*next
;
749 *fields
, *baseclasses
;
751 /* Number of fields (including baseclasses). */
754 /* Number of baseclasses. */
757 /* Set if the accesibility of one of the fields is not public. */
758 int non_public_fields
;
760 /* Member function fields array, entries are allocated in the order they
761 are encountered in the object file. */
764 struct nextfnfield
*next
;
765 struct fn_field fnfield
;
769 /* Member function fieldlist array, contains name of possibly overloaded
770 member function, number of overloaded member functions and a pointer
771 to the head of the member function field chain. */
776 struct nextfnfield
*head
;
780 /* Number of entries in the fnfieldlists array. */
783 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
784 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
785 struct typedef_field_list
787 struct typedef_field field
;
788 struct typedef_field_list
*next
;
791 unsigned typedef_field_list_count
;
794 /* One item on the queue of compilation units to read in full symbols
796 struct dwarf2_queue_item
798 struct dwarf2_per_cu_data
*per_cu
;
799 struct dwarf2_queue_item
*next
;
802 /* The current queue. */
803 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
805 /* Loaded secondary compilation units are kept in memory until they
806 have not been referenced for the processing of this many
807 compilation units. Set this to zero to disable caching. Cache
808 sizes of up to at least twenty will improve startup time for
809 typical inter-CU-reference binaries, at an obvious memory cost. */
810 static int dwarf2_max_cache_age
= 5;
812 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
813 struct cmd_list_element
*c
, const char *value
)
815 fprintf_filtered (file
, _("The upper bound on the age of cached "
816 "dwarf2 compilation units is %s.\n"),
821 /* Various complaints about symbol reading that don't abort the process. */
824 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
826 complaint (&symfile_complaints
,
827 _("statement list doesn't fit in .debug_line section"));
831 dwarf2_debug_line_missing_file_complaint (void)
833 complaint (&symfile_complaints
,
834 _(".debug_line section has line data without a file"));
838 dwarf2_debug_line_missing_end_sequence_complaint (void)
840 complaint (&symfile_complaints
,
841 _(".debug_line section has line "
842 "program sequence without an end"));
846 dwarf2_complex_location_expr_complaint (void)
848 complaint (&symfile_complaints
, _("location expression too complex"));
852 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
855 complaint (&symfile_complaints
,
856 _("const value length mismatch for '%s', got %d, expected %d"),
861 dwarf2_macros_too_long_complaint (void)
863 complaint (&symfile_complaints
,
864 _("macro info runs off end of `.debug_macinfo' section"));
868 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
870 complaint (&symfile_complaints
,
871 _("macro debug info contains a "
872 "malformed macro definition:\n`%s'"),
877 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
879 complaint (&symfile_complaints
,
880 _("invalid attribute class or form for '%s' in '%s'"),
884 /* local function prototypes */
886 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
888 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
891 static void dwarf2_find_base_address (struct die_info
*die
,
892 struct dwarf2_cu
*cu
);
894 static void dwarf2_build_psymtabs_hard (struct objfile
*);
896 static void scan_partial_symbols (struct partial_die_info
*,
897 CORE_ADDR
*, CORE_ADDR
*,
898 int, struct dwarf2_cu
*);
900 static void add_partial_symbol (struct partial_die_info
*,
903 static void add_partial_namespace (struct partial_die_info
*pdi
,
904 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
905 int need_pc
, struct dwarf2_cu
*cu
);
907 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
908 CORE_ADDR
*highpc
, int need_pc
,
909 struct dwarf2_cu
*cu
);
911 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
912 struct dwarf2_cu
*cu
);
914 static void add_partial_subprogram (struct partial_die_info
*pdi
,
915 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
916 int need_pc
, struct dwarf2_cu
*cu
);
918 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
919 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
920 bfd
*abfd
, struct dwarf2_cu
*cu
);
922 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
924 static void psymtab_to_symtab_1 (struct partial_symtab
*);
926 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
928 static void dwarf2_free_abbrev_table (void *);
930 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
933 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
936 static struct partial_die_info
*load_partial_dies (bfd
*,
937 gdb_byte
*, gdb_byte
*,
938 int, struct dwarf2_cu
*);
940 static gdb_byte
*read_partial_die (struct partial_die_info
*,
941 struct abbrev_info
*abbrev
,
943 gdb_byte
*, gdb_byte
*,
946 static struct partial_die_info
*find_partial_die (unsigned int,
949 static void fixup_partial_die (struct partial_die_info
*,
952 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
953 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
955 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
956 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
958 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
960 static int read_1_signed_byte (bfd
*, gdb_byte
*);
962 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
964 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
966 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
968 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
971 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
973 static LONGEST read_checked_initial_length_and_offset
974 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
975 unsigned int *, unsigned int *);
977 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
980 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
982 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
984 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
986 static char *read_indirect_string (bfd
*, gdb_byte
*,
987 const struct comp_unit_head
*,
990 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
992 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
994 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
996 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
998 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1001 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1003 struct dwarf2_cu
*);
1005 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1006 struct dwarf2_cu
*cu
);
1008 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1010 static struct die_info
*die_specification (struct die_info
*die
,
1011 struct dwarf2_cu
**);
1013 static void free_line_header (struct line_header
*lh
);
1015 static void add_file_name (struct line_header
*, char *, unsigned int,
1016 unsigned int, unsigned int);
1018 static struct line_header
*(dwarf_decode_line_header
1019 (unsigned int offset
,
1020 bfd
*abfd
, struct dwarf2_cu
*cu
));
1022 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1023 struct dwarf2_cu
*, struct partial_symtab
*);
1025 static void dwarf2_start_subfile (char *, const char *, const char *);
1027 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1028 struct dwarf2_cu
*);
1030 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1031 struct dwarf2_cu
*, struct symbol
*);
1033 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1034 struct dwarf2_cu
*);
1036 static void dwarf2_const_value_attr (struct attribute
*attr
,
1039 struct obstack
*obstack
,
1040 struct dwarf2_cu
*cu
, long *value
,
1042 struct dwarf2_locexpr_baton
**baton
);
1044 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1046 static int need_gnat_info (struct dwarf2_cu
*);
1048 static struct type
*die_descriptive_type (struct die_info
*,
1049 struct dwarf2_cu
*);
1051 static void set_descriptive_type (struct type
*, struct die_info
*,
1052 struct dwarf2_cu
*);
1054 static struct type
*die_containing_type (struct die_info
*,
1055 struct dwarf2_cu
*);
1057 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1058 struct dwarf2_cu
*);
1060 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1062 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1064 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1066 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1067 const char *suffix
, int physname
,
1068 struct dwarf2_cu
*cu
);
1070 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1072 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1074 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1076 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1079 struct dwarf2_cu
*, struct partial_symtab
*);
1081 static int dwarf2_get_pc_bounds (struct die_info
*,
1082 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1083 struct partial_symtab
*);
1085 static void get_scope_pc_bounds (struct die_info
*,
1086 CORE_ADDR
*, CORE_ADDR
*,
1087 struct dwarf2_cu
*);
1089 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1090 CORE_ADDR
, struct dwarf2_cu
*);
1092 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1093 struct dwarf2_cu
*);
1095 static void dwarf2_attach_fields_to_type (struct field_info
*,
1096 struct type
*, struct dwarf2_cu
*);
1098 static void dwarf2_add_member_fn (struct field_info
*,
1099 struct die_info
*, struct type
*,
1100 struct dwarf2_cu
*);
1102 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1104 struct dwarf2_cu
*);
1106 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1108 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1110 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1112 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1114 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1116 static struct type
*read_module_type (struct die_info
*die
,
1117 struct dwarf2_cu
*cu
);
1119 static const char *namespace_name (struct die_info
*die
,
1120 int *is_anonymous
, struct dwarf2_cu
*);
1122 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1124 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1126 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1127 struct dwarf2_cu
*);
1129 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1131 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1133 gdb_byte
**new_info_ptr
,
1134 struct die_info
*parent
);
1136 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1138 gdb_byte
**new_info_ptr
,
1139 struct die_info
*parent
);
1141 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1143 gdb_byte
**new_info_ptr
,
1144 struct die_info
*parent
);
1146 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1147 struct die_info
**, gdb_byte
*,
1150 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1152 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1155 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1157 static const char *dwarf2_full_name (char *name
,
1158 struct die_info
*die
,
1159 struct dwarf2_cu
*cu
);
1161 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1162 struct dwarf2_cu
**);
1164 static char *dwarf_tag_name (unsigned int);
1166 static char *dwarf_attr_name (unsigned int);
1168 static char *dwarf_form_name (unsigned int);
1170 static char *dwarf_bool_name (unsigned int);
1172 static char *dwarf_type_encoding_name (unsigned int);
1175 static char *dwarf_cfi_name (unsigned int);
1178 static struct die_info
*sibling_die (struct die_info
*);
1180 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1182 static void dump_die_for_error (struct die_info
*);
1184 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1187 /*static*/ void dump_die (struct die_info
*, int max_level
);
1189 static void store_in_ref_table (struct die_info
*,
1190 struct dwarf2_cu
*);
1192 static int is_ref_attr (struct attribute
*);
1194 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1196 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1198 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1200 struct dwarf2_cu
**);
1202 static struct die_info
*follow_die_ref (struct die_info
*,
1204 struct dwarf2_cu
**);
1206 static struct die_info
*follow_die_sig (struct die_info
*,
1208 struct dwarf2_cu
**);
1210 static struct signatured_type
*lookup_signatured_type_at_offset
1211 (struct objfile
*objfile
,
1212 struct dwarf2_section_info
*section
,
1213 unsigned int offset
);
1215 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1216 struct dwarf2_section_info
*sect
,
1217 unsigned int offset
);
1219 static void read_signatured_type (struct objfile
*,
1220 struct signatured_type
*type_sig
);
1222 /* memory allocation interface */
1224 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1226 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1228 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1230 static void initialize_cu_func_list (struct dwarf2_cu
*);
1232 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1233 struct dwarf2_cu
*);
1235 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1236 char *, bfd
*, struct dwarf2_cu
*);
1238 static int attr_form_is_block (struct attribute
*);
1240 static int attr_form_is_section_offset (struct attribute
*);
1242 static int attr_form_is_constant (struct attribute
*);
1244 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1245 struct dwarf2_loclist_baton
*baton
,
1246 struct attribute
*attr
);
1248 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1250 struct dwarf2_cu
*cu
);
1252 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1253 struct abbrev_info
*abbrev
,
1254 struct dwarf2_cu
*cu
);
1256 static void free_stack_comp_unit (void *);
1258 static hashval_t
partial_die_hash (const void *item
);
1260 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1262 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1263 (unsigned int offset
, struct objfile
*objfile
);
1265 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1266 (unsigned int offset
, struct objfile
*objfile
);
1268 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1269 struct objfile
*objfile
);
1271 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1272 struct die_info
*comp_unit_die
);
1274 static void free_one_comp_unit (void *);
1276 static void free_cached_comp_units (void *);
1278 static void age_cached_comp_units (void);
1280 static void free_one_cached_comp_unit (void *);
1282 static struct type
*set_die_type (struct die_info
*, struct type
*,
1283 struct dwarf2_cu
*);
1285 static void create_all_comp_units (struct objfile
*);
1287 static int create_debug_types_hash_table (struct objfile
*objfile
);
1289 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1292 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1294 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1295 struct dwarf2_per_cu_data
*);
1297 static void dwarf2_mark (struct dwarf2_cu
*);
1299 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1301 static struct type
*get_die_type_at_offset (unsigned int,
1302 struct dwarf2_per_cu_data
*per_cu
);
1304 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1306 static void dwarf2_release_queue (void *dummy
);
1308 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1309 struct objfile
*objfile
);
1311 static void process_queue (struct objfile
*objfile
);
1313 static void find_file_and_directory (struct die_info
*die
,
1314 struct dwarf2_cu
*cu
,
1315 char **name
, char **comp_dir
);
1317 static char *file_full_name (int file
, struct line_header
*lh
,
1318 const char *comp_dir
);
1320 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1323 unsigned int buffer_size
,
1326 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1327 struct dwarf2_cu
*cu
);
1329 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1333 /* Convert VALUE between big- and little-endian. */
1335 byte_swap (offset_type value
)
1339 result
= (value
& 0xff) << 24;
1340 result
|= (value
& 0xff00) << 8;
1341 result
|= (value
& 0xff0000) >> 8;
1342 result
|= (value
& 0xff000000) >> 24;
1346 #define MAYBE_SWAP(V) byte_swap (V)
1349 #define MAYBE_SWAP(V) (V)
1350 #endif /* WORDS_BIGENDIAN */
1352 /* The suffix for an index file. */
1353 #define INDEX_SUFFIX ".gdb-index"
1355 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1356 struct dwarf2_cu
*cu
);
1358 /* Try to locate the sections we need for DWARF 2 debugging
1359 information and return true if we have enough to do something.
1360 NAMES points to the dwarf2 section names, or is NULL if the standard
1361 ELF names are used. */
1364 dwarf2_has_info (struct objfile
*objfile
,
1365 const struct dwarf2_debug_sections
*names
)
1367 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1368 if (!dwarf2_per_objfile
)
1370 /* Initialize per-objfile state. */
1371 struct dwarf2_per_objfile
*data
1372 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1374 memset (data
, 0, sizeof (*data
));
1375 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1376 dwarf2_per_objfile
= data
;
1378 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1380 dwarf2_per_objfile
->objfile
= objfile
;
1382 return (dwarf2_per_objfile
->info
.asection
!= NULL
1383 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1386 /* When loading sections, we look either for uncompressed section or for
1387 compressed section names. */
1390 section_is_p (const char *section_name
,
1391 const struct dwarf2_section_names
*names
)
1393 if (names
->normal
!= NULL
1394 && strcmp (section_name
, names
->normal
) == 0)
1396 if (names
->compressed
!= NULL
1397 && strcmp (section_name
, names
->compressed
) == 0)
1402 /* This function is mapped across the sections and remembers the
1403 offset and size of each of the debugging sections we are interested
1407 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1409 const struct dwarf2_debug_sections
*names
;
1412 names
= &dwarf2_elf_names
;
1414 names
= (const struct dwarf2_debug_sections
*) vnames
;
1416 if (section_is_p (sectp
->name
, &names
->info
))
1418 dwarf2_per_objfile
->info
.asection
= sectp
;
1419 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1421 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1423 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1424 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, &names
->line
))
1428 dwarf2_per_objfile
->line
.asection
= sectp
;
1429 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, &names
->loc
))
1433 dwarf2_per_objfile
->loc
.asection
= sectp
;
1434 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1436 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1438 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1439 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1441 else if (section_is_p (sectp
->name
, &names
->str
))
1443 dwarf2_per_objfile
->str
.asection
= sectp
;
1444 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1446 else if (section_is_p (sectp
->name
, &names
->frame
))
1448 dwarf2_per_objfile
->frame
.asection
= sectp
;
1449 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1451 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1453 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1455 if (aflag
& SEC_HAS_CONTENTS
)
1457 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1458 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1461 else if (section_is_p (sectp
->name
, &names
->ranges
))
1463 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1464 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1466 else if (section_is_p (sectp
->name
, &names
->types
))
1468 struct dwarf2_section_info type_section
;
1470 memset (&type_section
, 0, sizeof (type_section
));
1471 type_section
.asection
= sectp
;
1472 type_section
.size
= bfd_get_section_size (sectp
);
1474 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1477 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1479 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1480 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1483 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1484 && bfd_section_vma (abfd
, sectp
) == 0)
1485 dwarf2_per_objfile
->has_section_at_zero
= 1;
1488 /* Decompress a section that was compressed using zlib. Store the
1489 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1492 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1493 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1495 bfd
*abfd
= objfile
->obfd
;
1497 error (_("Support for zlib-compressed DWARF data (from '%s') "
1498 "is disabled in this copy of GDB"),
1499 bfd_get_filename (abfd
));
1501 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1502 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1503 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1504 bfd_size_type uncompressed_size
;
1505 gdb_byte
*uncompressed_buffer
;
1508 int header_size
= 12;
1510 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1511 || bfd_bread (compressed_buffer
,
1512 compressed_size
, abfd
) != compressed_size
)
1513 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1514 bfd_get_filename (abfd
));
1516 /* Read the zlib header. In this case, it should be "ZLIB" followed
1517 by the uncompressed section size, 8 bytes in big-endian order. */
1518 if (compressed_size
< header_size
1519 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1520 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1521 bfd_get_filename (abfd
));
1522 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1523 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1524 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1525 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1526 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1527 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1528 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1529 uncompressed_size
+= compressed_buffer
[11];
1531 /* It is possible the section consists of several compressed
1532 buffers concatenated together, so we uncompress in a loop. */
1536 strm
.avail_in
= compressed_size
- header_size
;
1537 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1538 strm
.avail_out
= uncompressed_size
;
1539 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1541 rc
= inflateInit (&strm
);
1542 while (strm
.avail_in
> 0)
1545 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1546 bfd_get_filename (abfd
), rc
);
1547 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1548 + (uncompressed_size
- strm
.avail_out
));
1549 rc
= inflate (&strm
, Z_FINISH
);
1550 if (rc
!= Z_STREAM_END
)
1551 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1552 bfd_get_filename (abfd
), rc
);
1553 rc
= inflateReset (&strm
);
1555 rc
= inflateEnd (&strm
);
1557 || strm
.avail_out
!= 0)
1558 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1559 bfd_get_filename (abfd
), rc
);
1561 do_cleanups (cleanup
);
1562 *outbuf
= uncompressed_buffer
;
1563 *outsize
= uncompressed_size
;
1567 /* A helper function that decides whether a section is empty. */
1570 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1572 return info
->asection
== NULL
|| info
->size
== 0;
1575 /* Read the contents of the section SECTP from object file specified by
1576 OBJFILE, store info about the section into INFO.
1577 If the section is compressed, uncompress it before returning. */
1580 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1582 bfd
*abfd
= objfile
->obfd
;
1583 asection
*sectp
= info
->asection
;
1584 gdb_byte
*buf
, *retbuf
;
1585 unsigned char header
[4];
1589 info
->buffer
= NULL
;
1590 info
->map_addr
= NULL
;
1593 if (dwarf2_section_empty_p (info
))
1596 /* Check if the file has a 4-byte header indicating compression. */
1597 if (info
->size
> sizeof (header
)
1598 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1599 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1601 /* Upon decompression, update the buffer and its size. */
1602 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1604 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1612 pagesize
= getpagesize ();
1614 /* Only try to mmap sections which are large enough: we don't want to
1615 waste space due to fragmentation. Also, only try mmap for sections
1616 without relocations. */
1618 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1620 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1621 MAP_PRIVATE
, sectp
->filepos
,
1622 &info
->map_addr
, &info
->map_len
);
1624 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1626 #if HAVE_POSIX_MADVISE
1627 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1634 /* If we get here, we are a normal, not-compressed section. */
1636 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1638 /* When debugging .o files, we may need to apply relocations; see
1639 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1640 We never compress sections in .o files, so we only need to
1641 try this when the section is not compressed. */
1642 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1645 info
->buffer
= retbuf
;
1649 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1650 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1651 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1652 bfd_get_filename (abfd
));
1655 /* A helper function that returns the size of a section in a safe way.
1656 If you are positive that the section has been read before using the
1657 size, then it is safe to refer to the dwarf2_section_info object's
1658 "size" field directly. In other cases, you must call this
1659 function, because for compressed sections the size field is not set
1660 correctly until the section has been read. */
1662 static bfd_size_type
1663 dwarf2_section_size (struct objfile
*objfile
,
1664 struct dwarf2_section_info
*info
)
1667 dwarf2_read_section (objfile
, info
);
1671 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1675 dwarf2_get_section_info (struct objfile
*objfile
,
1676 enum dwarf2_section_enum sect
,
1677 asection
**sectp
, gdb_byte
**bufp
,
1678 bfd_size_type
*sizep
)
1680 struct dwarf2_per_objfile
*data
1681 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1682 struct dwarf2_section_info
*info
;
1684 /* We may see an objfile without any DWARF, in which case we just
1695 case DWARF2_DEBUG_FRAME
:
1696 info
= &data
->frame
;
1698 case DWARF2_EH_FRAME
:
1699 info
= &data
->eh_frame
;
1702 gdb_assert_not_reached ("unexpected section");
1705 dwarf2_read_section (objfile
, info
);
1707 *sectp
= info
->asection
;
1708 *bufp
= info
->buffer
;
1709 *sizep
= info
->size
;
1713 /* DWARF quick_symbols_functions support. */
1715 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1716 unique line tables, so we maintain a separate table of all .debug_line
1717 derived entries to support the sharing.
1718 All the quick functions need is the list of file names. We discard the
1719 line_header when we're done and don't need to record it here. */
1720 struct quick_file_names
1722 /* The offset in .debug_line of the line table. We hash on this. */
1723 unsigned int offset
;
1725 /* The number of entries in file_names, real_names. */
1726 unsigned int num_file_names
;
1728 /* The file names from the line table, after being run through
1730 const char **file_names
;
1732 /* The file names from the line table after being run through
1733 gdb_realpath. These are computed lazily. */
1734 const char **real_names
;
1737 /* When using the index (and thus not using psymtabs), each CU has an
1738 object of this type. This is used to hold information needed by
1739 the various "quick" methods. */
1740 struct dwarf2_per_cu_quick_data
1742 /* The file table. This can be NULL if there was no file table
1743 or it's currently not read in.
1744 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1745 struct quick_file_names
*file_names
;
1747 /* The corresponding symbol table. This is NULL if symbols for this
1748 CU have not yet been read. */
1749 struct symtab
*symtab
;
1751 /* A temporary mark bit used when iterating over all CUs in
1752 expand_symtabs_matching. */
1753 unsigned int mark
: 1;
1755 /* True if we've tried to read the file table and found there isn't one.
1756 There will be no point in trying to read it again next time. */
1757 unsigned int no_file_data
: 1;
1760 /* Hash function for a quick_file_names. */
1763 hash_file_name_entry (const void *e
)
1765 const struct quick_file_names
*file_data
= e
;
1767 return file_data
->offset
;
1770 /* Equality function for a quick_file_names. */
1773 eq_file_name_entry (const void *a
, const void *b
)
1775 const struct quick_file_names
*ea
= a
;
1776 const struct quick_file_names
*eb
= b
;
1778 return ea
->offset
== eb
->offset
;
1781 /* Delete function for a quick_file_names. */
1784 delete_file_name_entry (void *e
)
1786 struct quick_file_names
*file_data
= e
;
1789 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1791 xfree ((void*) file_data
->file_names
[i
]);
1792 if (file_data
->real_names
)
1793 xfree ((void*) file_data
->real_names
[i
]);
1796 /* The space for the struct itself lives on objfile_obstack,
1797 so we don't free it here. */
1800 /* Create a quick_file_names hash table. */
1803 create_quick_file_names_table (unsigned int nr_initial_entries
)
1805 return htab_create_alloc (nr_initial_entries
,
1806 hash_file_name_entry
, eq_file_name_entry
,
1807 delete_file_name_entry
, xcalloc
, xfree
);
1810 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1811 have to be created afterwards. You should call age_cached_comp_units after
1812 processing PER_CU->CU. dw2_setup must have been already called. */
1815 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1817 if (per_cu
->debug_type_section
)
1818 read_signatured_type_at_offset (per_cu
->objfile
,
1819 per_cu
->debug_type_section
,
1822 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1824 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1826 gdb_assert (per_cu
->cu
!= NULL
);
1829 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1833 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1834 struct dwarf2_per_cu_data
*per_cu
)
1836 struct cleanup
*back_to
;
1838 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1840 queue_comp_unit (per_cu
, objfile
);
1844 process_queue (objfile
);
1846 /* Age the cache, releasing compilation units that have not
1847 been used recently. */
1848 age_cached_comp_units ();
1850 do_cleanups (back_to
);
1853 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1854 the objfile from which this CU came. Returns the resulting symbol
1857 static struct symtab
*
1858 dw2_instantiate_symtab (struct objfile
*objfile
,
1859 struct dwarf2_per_cu_data
*per_cu
)
1861 if (!per_cu
->v
.quick
->symtab
)
1863 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1864 increment_reading_symtab ();
1865 dw2_do_instantiate_symtab (objfile
, per_cu
);
1866 do_cleanups (back_to
);
1868 return per_cu
->v
.quick
->symtab
;
1871 /* Return the CU given its index. */
1873 static struct dwarf2_per_cu_data
*
1874 dw2_get_cu (int index
)
1876 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1878 index
-= dwarf2_per_objfile
->n_comp_units
;
1879 return dwarf2_per_objfile
->type_comp_units
[index
];
1881 return dwarf2_per_objfile
->all_comp_units
[index
];
1884 /* A helper function that knows how to read a 64-bit value in a way
1885 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1889 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1891 if (sizeof (ULONGEST
) < 8)
1895 /* Ignore the upper 4 bytes if they are all zero. */
1896 for (i
= 0; i
< 4; ++i
)
1897 if (bytes
[i
+ 4] != 0)
1900 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1903 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1907 /* Read the CU list from the mapped index, and use it to create all
1908 the CU objects for this objfile. Return 0 if something went wrong,
1909 1 if everything went ok. */
1912 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1913 offset_type cu_list_elements
)
1917 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1918 dwarf2_per_objfile
->all_comp_units
1919 = obstack_alloc (&objfile
->objfile_obstack
,
1920 dwarf2_per_objfile
->n_comp_units
1921 * sizeof (struct dwarf2_per_cu_data
*));
1923 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1925 struct dwarf2_per_cu_data
*the_cu
;
1926 ULONGEST offset
, length
;
1928 if (!extract_cu_value (cu_list
, &offset
)
1929 || !extract_cu_value (cu_list
+ 8, &length
))
1933 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1934 struct dwarf2_per_cu_data
);
1935 the_cu
->offset
= offset
;
1936 the_cu
->length
= length
;
1937 the_cu
->objfile
= objfile
;
1938 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1939 struct dwarf2_per_cu_quick_data
);
1940 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1946 /* Create the signatured type hash table from the index. */
1949 create_signatured_type_table_from_index (struct objfile
*objfile
,
1950 struct dwarf2_section_info
*section
,
1951 const gdb_byte
*bytes
,
1952 offset_type elements
)
1955 htab_t sig_types_hash
;
1957 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1958 dwarf2_per_objfile
->type_comp_units
1959 = obstack_alloc (&objfile
->objfile_obstack
,
1960 dwarf2_per_objfile
->n_type_comp_units
1961 * sizeof (struct dwarf2_per_cu_data
*));
1963 sig_types_hash
= allocate_signatured_type_table (objfile
);
1965 for (i
= 0; i
< elements
; i
+= 3)
1967 struct signatured_type
*type_sig
;
1968 ULONGEST offset
, type_offset
, signature
;
1971 if (!extract_cu_value (bytes
, &offset
)
1972 || !extract_cu_value (bytes
+ 8, &type_offset
))
1974 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1977 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1978 struct signatured_type
);
1979 type_sig
->signature
= signature
;
1980 type_sig
->type_offset
= type_offset
;
1981 type_sig
->per_cu
.debug_type_section
= section
;
1982 type_sig
->per_cu
.offset
= offset
;
1983 type_sig
->per_cu
.objfile
= objfile
;
1984 type_sig
->per_cu
.v
.quick
1985 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1986 struct dwarf2_per_cu_quick_data
);
1988 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1991 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1994 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1999 /* Read the address map data from the mapped index, and use it to
2000 populate the objfile's psymtabs_addrmap. */
2003 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2005 const gdb_byte
*iter
, *end
;
2006 struct obstack temp_obstack
;
2007 struct addrmap
*mutable_map
;
2008 struct cleanup
*cleanup
;
2011 obstack_init (&temp_obstack
);
2012 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2013 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2015 iter
= index
->address_table
;
2016 end
= iter
+ index
->address_table_size
;
2018 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2022 ULONGEST hi
, lo
, cu_index
;
2023 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2025 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2027 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2030 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2031 dw2_get_cu (cu_index
));
2034 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2035 &objfile
->objfile_obstack
);
2036 do_cleanups (cleanup
);
2039 /* The hash function for strings in the mapped index. This is the same as
2040 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2041 implementation. This is necessary because the hash function is tied to the
2042 format of the mapped index file. The hash values do not have to match with
2045 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2048 mapped_index_string_hash (int index_version
, const void *p
)
2050 const unsigned char *str
= (const unsigned char *) p
;
2054 while ((c
= *str
++) != 0)
2056 if (index_version
>= 5)
2058 r
= r
* 67 + c
- 113;
2064 /* Find a slot in the mapped index INDEX for the object named NAME.
2065 If NAME is found, set *VEC_OUT to point to the CU vector in the
2066 constant pool and return 1. If NAME cannot be found, return 0. */
2069 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2070 offset_type
**vec_out
)
2072 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2074 offset_type slot
, step
;
2075 int (*cmp
) (const char *, const char *);
2077 if (current_language
->la_language
== language_cplus
2078 || current_language
->la_language
== language_java
2079 || current_language
->la_language
== language_fortran
)
2081 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2083 const char *paren
= strchr (name
, '(');
2089 dup
= xmalloc (paren
- name
+ 1);
2090 memcpy (dup
, name
, paren
- name
);
2091 dup
[paren
- name
] = 0;
2093 make_cleanup (xfree
, dup
);
2098 /* Index version 4 did not support case insensitive searches. But the
2099 indexes for case insensitive languages are built in lowercase, therefore
2100 simulate our NAME being searched is also lowercased. */
2101 hash
= mapped_index_string_hash ((index
->version
== 4
2102 && case_sensitivity
== case_sensitive_off
2103 ? 5 : index
->version
),
2106 slot
= hash
& (index
->symbol_table_slots
- 1);
2107 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2108 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2112 /* Convert a slot number to an offset into the table. */
2113 offset_type i
= 2 * slot
;
2115 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2117 do_cleanups (back_to
);
2121 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2122 if (!cmp (name
, str
))
2124 *vec_out
= (offset_type
*) (index
->constant_pool
2125 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2126 do_cleanups (back_to
);
2130 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2134 /* Read the index file. If everything went ok, initialize the "quick"
2135 elements of all the CUs and return 1. Otherwise, return 0. */
2138 dwarf2_read_index (struct objfile
*objfile
)
2141 struct mapped_index
*map
;
2142 offset_type
*metadata
;
2143 const gdb_byte
*cu_list
;
2144 const gdb_byte
*types_list
= NULL
;
2145 offset_type version
, cu_list_elements
;
2146 offset_type types_list_elements
= 0;
2149 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2152 /* Older elfutils strip versions could keep the section in the main
2153 executable while splitting it for the separate debug info file. */
2154 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2155 & SEC_HAS_CONTENTS
) == 0)
2158 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2160 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2161 /* Version check. */
2162 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2163 /* Versions earlier than 3 emitted every copy of a psymbol. This
2164 causes the index to behave very poorly for certain requests. Version 3
2165 contained incomplete addrmap. So, it seems better to just ignore such
2166 indices. Index version 4 uses a different hash function than index
2167 version 5 and later. */
2170 /* Indexes with higher version than the one supported by GDB may be no
2171 longer backward compatible. */
2175 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2176 map
->version
= version
;
2177 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2179 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2182 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2183 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2187 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2188 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2189 - MAYBE_SWAP (metadata
[i
]))
2193 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2194 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2195 - MAYBE_SWAP (metadata
[i
]));
2198 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2199 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2200 - MAYBE_SWAP (metadata
[i
]))
2201 / (2 * sizeof (offset_type
)));
2204 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2206 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2209 if (types_list_elements
)
2211 struct dwarf2_section_info
*section
;
2213 /* We can only handle a single .debug_types when we have an
2215 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2218 section
= VEC_index (dwarf2_section_info_def
,
2219 dwarf2_per_objfile
->types
, 0);
2221 if (!create_signatured_type_table_from_index (objfile
, section
,
2223 types_list_elements
))
2227 create_addrmap_from_index (objfile
, map
);
2229 dwarf2_per_objfile
->index_table
= map
;
2230 dwarf2_per_objfile
->using_index
= 1;
2231 dwarf2_per_objfile
->quick_file_names_table
=
2232 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2237 /* A helper for the "quick" functions which sets the global
2238 dwarf2_per_objfile according to OBJFILE. */
2241 dw2_setup (struct objfile
*objfile
)
2243 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2244 gdb_assert (dwarf2_per_objfile
);
2247 /* A helper for the "quick" functions which attempts to read the line
2248 table for THIS_CU. */
2250 static struct quick_file_names
*
2251 dw2_get_file_names (struct objfile
*objfile
,
2252 struct dwarf2_per_cu_data
*this_cu
)
2254 bfd
*abfd
= objfile
->obfd
;
2255 struct line_header
*lh
;
2256 struct attribute
*attr
;
2257 struct cleanup
*cleanups
;
2258 struct die_info
*comp_unit_die
;
2259 struct dwarf2_section_info
* sec
;
2260 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2261 int has_children
, i
;
2262 struct dwarf2_cu cu
;
2263 unsigned int bytes_read
, buffer_size
;
2264 struct die_reader_specs reader_specs
;
2265 char *name
, *comp_dir
;
2267 struct quick_file_names
*qfn
;
2268 unsigned int line_offset
;
2270 if (this_cu
->v
.quick
->file_names
!= NULL
)
2271 return this_cu
->v
.quick
->file_names
;
2272 /* If we know there is no line data, no point in looking again. */
2273 if (this_cu
->v
.quick
->no_file_data
)
2276 init_one_comp_unit (&cu
, objfile
);
2277 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2279 if (this_cu
->debug_type_section
)
2280 sec
= this_cu
->debug_type_section
;
2282 sec
= &dwarf2_per_objfile
->info
;
2283 dwarf2_read_section (objfile
, sec
);
2284 buffer_size
= sec
->size
;
2285 buffer
= sec
->buffer
;
2286 info_ptr
= buffer
+ this_cu
->offset
;
2287 beg_of_comp_unit
= info_ptr
;
2289 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2290 buffer
, buffer_size
,
2293 /* Complete the cu_header. */
2294 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2295 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2298 cu
.per_cu
= this_cu
;
2300 dwarf2_read_abbrevs (abfd
, &cu
);
2301 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2303 if (this_cu
->debug_type_section
)
2304 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2305 init_cu_die_reader (&reader_specs
, &cu
);
2306 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2312 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2315 struct quick_file_names find_entry
;
2317 line_offset
= DW_UNSND (attr
);
2319 /* We may have already read in this line header (TU line header sharing).
2320 If we have we're done. */
2321 find_entry
.offset
= line_offset
;
2322 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2323 &find_entry
, INSERT
);
2326 do_cleanups (cleanups
);
2327 this_cu
->v
.quick
->file_names
= *slot
;
2331 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2335 do_cleanups (cleanups
);
2336 this_cu
->v
.quick
->no_file_data
= 1;
2340 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2341 qfn
->offset
= line_offset
;
2342 gdb_assert (slot
!= NULL
);
2345 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2347 qfn
->num_file_names
= lh
->num_file_names
;
2348 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2349 lh
->num_file_names
* sizeof (char *));
2350 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2351 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2352 qfn
->real_names
= NULL
;
2354 free_line_header (lh
);
2355 do_cleanups (cleanups
);
2357 this_cu
->v
.quick
->file_names
= qfn
;
2361 /* A helper for the "quick" functions which computes and caches the
2362 real path for a given file name from the line table. */
2365 dw2_get_real_path (struct objfile
*objfile
,
2366 struct quick_file_names
*qfn
, int index
)
2368 if (qfn
->real_names
== NULL
)
2369 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2370 qfn
->num_file_names
, sizeof (char *));
2372 if (qfn
->real_names
[index
] == NULL
)
2373 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2375 return qfn
->real_names
[index
];
2378 static struct symtab
*
2379 dw2_find_last_source_symtab (struct objfile
*objfile
)
2383 dw2_setup (objfile
);
2384 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2385 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2388 /* Traversal function for dw2_forget_cached_source_info. */
2391 dw2_free_cached_file_names (void **slot
, void *info
)
2393 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2395 if (file_data
->real_names
)
2399 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2401 xfree ((void*) file_data
->real_names
[i
]);
2402 file_data
->real_names
[i
] = NULL
;
2410 dw2_forget_cached_source_info (struct objfile
*objfile
)
2412 dw2_setup (objfile
);
2414 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2415 dw2_free_cached_file_names
, NULL
);
2419 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2420 const char *full_path
, const char *real_path
,
2421 struct symtab
**result
)
2424 int check_basename
= lbasename (name
) == name
;
2425 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2427 dw2_setup (objfile
);
2429 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2430 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2433 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2434 struct quick_file_names
*file_data
;
2436 if (per_cu
->v
.quick
->symtab
)
2439 file_data
= dw2_get_file_names (objfile
, per_cu
);
2440 if (file_data
== NULL
)
2443 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2445 const char *this_name
= file_data
->file_names
[j
];
2447 if (FILENAME_CMP (name
, this_name
) == 0)
2449 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2453 if (check_basename
&& ! base_cu
2454 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2457 if (full_path
!= NULL
)
2459 const char *this_real_name
= dw2_get_real_path (objfile
,
2462 if (this_real_name
!= NULL
2463 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2465 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2470 if (real_path
!= NULL
)
2472 const char *this_real_name
= dw2_get_real_path (objfile
,
2475 if (this_real_name
!= NULL
2476 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2478 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2487 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2494 static struct symtab
*
2495 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2496 const char *name
, domain_enum domain
)
2498 /* We do all the work in the pre_expand_symtabs_matching hook
2503 /* A helper function that expands all symtabs that hold an object
2507 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2509 dw2_setup (objfile
);
2511 /* index_table is NULL if OBJF_READNOW. */
2512 if (dwarf2_per_objfile
->index_table
)
2516 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2519 offset_type i
, len
= MAYBE_SWAP (*vec
);
2520 for (i
= 0; i
< len
; ++i
)
2522 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2523 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2525 dw2_instantiate_symtab (objfile
, per_cu
);
2532 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2533 enum block_enum block_kind
, const char *name
,
2536 dw2_do_expand_symtabs_matching (objfile
, name
);
2540 dw2_print_stats (struct objfile
*objfile
)
2544 dw2_setup (objfile
);
2546 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2547 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2549 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2551 if (!per_cu
->v
.quick
->symtab
)
2554 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2558 dw2_dump (struct objfile
*objfile
)
2560 /* Nothing worth printing. */
2564 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2565 struct section_offsets
*delta
)
2567 /* There's nothing to relocate here. */
2571 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2572 const char *func_name
)
2574 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2578 dw2_expand_all_symtabs (struct objfile
*objfile
)
2582 dw2_setup (objfile
);
2584 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2585 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2587 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2589 dw2_instantiate_symtab (objfile
, per_cu
);
2594 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2595 const char *filename
)
2599 dw2_setup (objfile
);
2601 /* We don't need to consider type units here.
2602 This is only called for examining code, e.g. expand_line_sal.
2603 There can be an order of magnitude (or more) more type units
2604 than comp units, and we avoid them if we can. */
2606 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2609 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2610 struct quick_file_names
*file_data
;
2612 if (per_cu
->v
.quick
->symtab
)
2615 file_data
= dw2_get_file_names (objfile
, per_cu
);
2616 if (file_data
== NULL
)
2619 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2621 const char *this_name
= file_data
->file_names
[j
];
2622 if (FILENAME_CMP (this_name
, filename
) == 0)
2624 dw2_instantiate_symtab (objfile
, per_cu
);
2632 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2634 struct dwarf2_per_cu_data
*per_cu
;
2636 struct quick_file_names
*file_data
;
2638 dw2_setup (objfile
);
2640 /* index_table is NULL if OBJF_READNOW. */
2641 if (!dwarf2_per_objfile
->index_table
)
2644 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2648 /* Note that this just looks at the very first one named NAME -- but
2649 actually we are looking for a function. find_main_filename
2650 should be rewritten so that it doesn't require a custom hook. It
2651 could just use the ordinary symbol tables. */
2652 /* vec[0] is the length, which must always be >0. */
2653 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2655 file_data
= dw2_get_file_names (objfile
, per_cu
);
2656 if (file_data
== NULL
)
2659 return file_data
->file_names
[file_data
->num_file_names
- 1];
2663 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2664 struct objfile
*objfile
, int global
,
2665 int (*callback
) (struct block
*,
2666 struct symbol
*, void *),
2667 void *data
, symbol_compare_ftype
*match
,
2668 symbol_compare_ftype
*ordered_compare
)
2670 /* Currently unimplemented; used for Ada. The function can be called if the
2671 current language is Ada for a non-Ada objfile using GNU index. As Ada
2672 does not look for non-Ada symbols this function should just return. */
2676 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2677 int (*file_matcher
) (const char *, void *),
2678 int (*name_matcher
) (const char *, void *),
2679 enum search_domain kind
,
2684 struct mapped_index
*index
;
2686 dw2_setup (objfile
);
2688 /* index_table is NULL if OBJF_READNOW. */
2689 if (!dwarf2_per_objfile
->index_table
)
2691 index
= dwarf2_per_objfile
->index_table
;
2693 if (file_matcher
!= NULL
)
2694 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2695 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2698 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2699 struct quick_file_names
*file_data
;
2701 per_cu
->v
.quick
->mark
= 0;
2702 if (per_cu
->v
.quick
->symtab
)
2705 file_data
= dw2_get_file_names (objfile
, per_cu
);
2706 if (file_data
== NULL
)
2709 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2711 if (file_matcher (file_data
->file_names
[j
], data
))
2713 per_cu
->v
.quick
->mark
= 1;
2719 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2721 offset_type idx
= 2 * iter
;
2723 offset_type
*vec
, vec_len
, vec_idx
;
2725 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2728 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2730 if (! (*name_matcher
) (name
, data
))
2733 /* The name was matched, now expand corresponding CUs that were
2735 vec
= (offset_type
*) (index
->constant_pool
2736 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2737 vec_len
= MAYBE_SWAP (vec
[0]);
2738 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2740 struct dwarf2_per_cu_data
*per_cu
;
2742 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2743 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2744 dw2_instantiate_symtab (objfile
, per_cu
);
2749 static struct symtab
*
2750 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2751 struct minimal_symbol
*msymbol
,
2753 struct obj_section
*section
,
2756 struct dwarf2_per_cu_data
*data
;
2758 dw2_setup (objfile
);
2760 if (!objfile
->psymtabs_addrmap
)
2763 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2767 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2768 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2769 paddress (get_objfile_arch (objfile
), pc
));
2771 return dw2_instantiate_symtab (objfile
, data
);
2775 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2780 dw2_setup (objfile
);
2782 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2783 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2786 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2787 struct quick_file_names
*file_data
;
2789 if (per_cu
->v
.quick
->symtab
)
2792 file_data
= dw2_get_file_names (objfile
, per_cu
);
2793 if (file_data
== NULL
)
2796 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2798 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2800 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2806 dw2_has_symbols (struct objfile
*objfile
)
2811 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2814 dw2_find_last_source_symtab
,
2815 dw2_forget_cached_source_info
,
2818 dw2_pre_expand_symtabs_matching
,
2822 dw2_expand_symtabs_for_function
,
2823 dw2_expand_all_symtabs
,
2824 dw2_expand_symtabs_with_filename
,
2825 dw2_find_symbol_file
,
2826 dw2_map_matching_symbols
,
2827 dw2_expand_symtabs_matching
,
2828 dw2_find_pc_sect_symtab
,
2829 dw2_map_symbol_filenames
2832 /* Initialize for reading DWARF for this objfile. Return 0 if this
2833 file will use psymtabs, or 1 if using the GNU index. */
2836 dwarf2_initialize_objfile (struct objfile
*objfile
)
2838 /* If we're about to read full symbols, don't bother with the
2839 indices. In this case we also don't care if some other debug
2840 format is making psymtabs, because they are all about to be
2842 if ((objfile
->flags
& OBJF_READNOW
))
2846 dwarf2_per_objfile
->using_index
= 1;
2847 create_all_comp_units (objfile
);
2848 create_debug_types_hash_table (objfile
);
2849 dwarf2_per_objfile
->quick_file_names_table
=
2850 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2852 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2853 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2855 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2857 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2858 struct dwarf2_per_cu_quick_data
);
2861 /* Return 1 so that gdb sees the "quick" functions. However,
2862 these functions will be no-ops because we will have expanded
2867 if (dwarf2_read_index (objfile
))
2875 /* Build a partial symbol table. */
2878 dwarf2_build_psymtabs (struct objfile
*objfile
)
2880 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2882 init_psymbol_list (objfile
, 1024);
2885 dwarf2_build_psymtabs_hard (objfile
);
2888 /* Return TRUE if OFFSET is within CU_HEADER. */
2891 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2893 unsigned int bottom
= cu_header
->offset
;
2894 unsigned int top
= (cu_header
->offset
2896 + cu_header
->initial_length_size
);
2898 return (offset
>= bottom
&& offset
< top
);
2901 /* Read in the comp unit header information from the debug_info at info_ptr.
2902 NOTE: This leaves members offset, first_die_offset to be filled in
2906 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2907 gdb_byte
*info_ptr
, bfd
*abfd
)
2910 unsigned int bytes_read
;
2912 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2913 cu_header
->initial_length_size
= bytes_read
;
2914 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2915 info_ptr
+= bytes_read
;
2916 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2918 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2920 info_ptr
+= bytes_read
;
2921 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2923 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2924 if (signed_addr
< 0)
2925 internal_error (__FILE__
, __LINE__
,
2926 _("read_comp_unit_head: dwarf from non elf file"));
2927 cu_header
->signed_addr_p
= signed_addr
;
2933 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2934 gdb_byte
*buffer
, unsigned int buffer_size
,
2937 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2939 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2941 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2942 error (_("Dwarf Error: wrong version in compilation unit header "
2943 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2944 bfd_get_filename (abfd
));
2946 if (header
->abbrev_offset
2947 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2948 &dwarf2_per_objfile
->abbrev
))
2949 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2950 "(offset 0x%lx + 6) [in module %s]"),
2951 (long) header
->abbrev_offset
,
2952 (long) (beg_of_comp_unit
- buffer
),
2953 bfd_get_filename (abfd
));
2955 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2956 > buffer
+ buffer_size
)
2957 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2958 "(offset 0x%lx + 0) [in module %s]"),
2959 (long) header
->length
,
2960 (long) (beg_of_comp_unit
- buffer
),
2961 bfd_get_filename (abfd
));
2966 /* Read in the types comp unit header information from .debug_types entry at
2967 types_ptr. The result is a pointer to one past the end of the header. */
2970 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2971 struct dwarf2_section_info
*section
,
2972 ULONGEST
*signature
,
2973 gdb_byte
*types_ptr
, bfd
*abfd
)
2975 gdb_byte
*initial_types_ptr
= types_ptr
;
2977 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
2978 cu_header
->offset
= types_ptr
- section
->buffer
;
2980 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2982 *signature
= read_8_bytes (abfd
, types_ptr
);
2984 types_ptr
+= cu_header
->offset_size
;
2985 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2990 /* Allocate a new partial symtab for file named NAME and mark this new
2991 partial symtab as being an include of PST. */
2994 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2995 struct objfile
*objfile
)
2997 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2999 subpst
->section_offsets
= pst
->section_offsets
;
3000 subpst
->textlow
= 0;
3001 subpst
->texthigh
= 0;
3003 subpst
->dependencies
= (struct partial_symtab
**)
3004 obstack_alloc (&objfile
->objfile_obstack
,
3005 sizeof (struct partial_symtab
*));
3006 subpst
->dependencies
[0] = pst
;
3007 subpst
->number_of_dependencies
= 1;
3009 subpst
->globals_offset
= 0;
3010 subpst
->n_global_syms
= 0;
3011 subpst
->statics_offset
= 0;
3012 subpst
->n_static_syms
= 0;
3013 subpst
->symtab
= NULL
;
3014 subpst
->read_symtab
= pst
->read_symtab
;
3017 /* No private part is necessary for include psymtabs. This property
3018 can be used to differentiate between such include psymtabs and
3019 the regular ones. */
3020 subpst
->read_symtab_private
= NULL
;
3023 /* Read the Line Number Program data and extract the list of files
3024 included by the source file represented by PST. Build an include
3025 partial symtab for each of these included files. */
3028 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3029 struct die_info
*die
,
3030 struct partial_symtab
*pst
)
3032 struct objfile
*objfile
= cu
->objfile
;
3033 bfd
*abfd
= objfile
->obfd
;
3034 struct line_header
*lh
= NULL
;
3035 struct attribute
*attr
;
3037 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3040 unsigned int line_offset
= DW_UNSND (attr
);
3042 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3045 return; /* No linetable, so no includes. */
3047 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3048 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3050 free_line_header (lh
);
3054 hash_type_signature (const void *item
)
3056 const struct signatured_type
*type_sig
= item
;
3058 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3059 return type_sig
->signature
;
3063 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3065 const struct signatured_type
*lhs
= item_lhs
;
3066 const struct signatured_type
*rhs
= item_rhs
;
3068 return lhs
->signature
== rhs
->signature
;
3071 /* Allocate a hash table for signatured types. */
3074 allocate_signatured_type_table (struct objfile
*objfile
)
3076 return htab_create_alloc_ex (41,
3077 hash_type_signature
,
3080 &objfile
->objfile_obstack
,
3081 hashtab_obstack_allocate
,
3082 dummy_obstack_deallocate
);
3085 /* A helper function to add a signatured type CU to a list. */
3088 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3090 struct signatured_type
*sigt
= *slot
;
3091 struct dwarf2_per_cu_data
***datap
= datum
;
3093 **datap
= &sigt
->per_cu
;
3099 /* Create the hash table of all entries in the .debug_types section.
3100 The result is zero if there is an error (e.g. missing .debug_types section),
3101 otherwise non-zero. */
3104 create_debug_types_hash_table (struct objfile
*objfile
)
3106 htab_t types_htab
= NULL
;
3107 struct dwarf2_per_cu_data
**iter
;
3109 struct dwarf2_section_info
*section
;
3111 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3113 dwarf2_per_objfile
->signatured_types
= NULL
;
3118 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3122 gdb_byte
*info_ptr
, *end_ptr
;
3124 dwarf2_read_section (objfile
, section
);
3125 info_ptr
= section
->buffer
;
3127 if (info_ptr
== NULL
)
3130 if (types_htab
== NULL
)
3131 types_htab
= allocate_signatured_type_table (objfile
);
3133 if (dwarf2_die_debug
)
3134 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3136 end_ptr
= info_ptr
+ section
->size
;
3137 while (info_ptr
< end_ptr
)
3139 unsigned int offset
;
3140 unsigned int offset_size
;
3141 unsigned int type_offset
;
3142 unsigned int length
, initial_length_size
;
3143 unsigned short version
;
3145 struct signatured_type
*type_sig
;
3147 gdb_byte
*ptr
= info_ptr
;
3149 offset
= ptr
- section
->buffer
;
3151 /* We need to read the type's signature in order to build the hash
3152 table, but we don't need to read anything else just yet. */
3154 /* Sanity check to ensure entire cu is present. */
3155 length
= read_initial_length (objfile
->obfd
, ptr
,
3156 &initial_length_size
);
3157 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3159 complaint (&symfile_complaints
,
3160 _("debug type entry runs off end "
3161 "of `.debug_types' section, ignored"));
3165 offset_size
= initial_length_size
== 4 ? 4 : 8;
3166 ptr
+= initial_length_size
;
3167 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3169 ptr
+= offset_size
; /* abbrev offset */
3170 ptr
+= 1; /* address size */
3171 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3173 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3175 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3176 memset (type_sig
, 0, sizeof (*type_sig
));
3177 type_sig
->signature
= signature
;
3178 type_sig
->type_offset
= type_offset
;
3179 type_sig
->per_cu
.objfile
= objfile
;
3180 type_sig
->per_cu
.debug_type_section
= section
;
3181 type_sig
->per_cu
.offset
= offset
;
3183 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3184 gdb_assert (slot
!= NULL
);
3187 const struct signatured_type
*dup_sig
= *slot
;
3189 complaint (&symfile_complaints
,
3190 _("debug type entry at offset 0x%x is duplicate to the "
3191 "entry at offset 0x%x, signature 0x%s"),
3192 offset
, dup_sig
->per_cu
.offset
,
3193 phex (signature
, sizeof (signature
)));
3194 gdb_assert (signature
== dup_sig
->signature
);
3198 if (dwarf2_die_debug
)
3199 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3200 offset
, phex (signature
, sizeof (signature
)));
3202 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3206 dwarf2_per_objfile
->signatured_types
= types_htab
;
3208 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3209 dwarf2_per_objfile
->type_comp_units
3210 = obstack_alloc (&objfile
->objfile_obstack
,
3211 dwarf2_per_objfile
->n_type_comp_units
3212 * sizeof (struct dwarf2_per_cu_data
*));
3213 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3214 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3215 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3216 == dwarf2_per_objfile
->n_type_comp_units
);
3221 /* Lookup a signature based type.
3222 Returns NULL if SIG is not present in the table. */
3224 static struct signatured_type
*
3225 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3227 struct signatured_type find_entry
, *entry
;
3229 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3231 complaint (&symfile_complaints
,
3232 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3236 find_entry
.signature
= sig
;
3237 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3241 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3244 init_cu_die_reader (struct die_reader_specs
*reader
,
3245 struct dwarf2_cu
*cu
)
3247 reader
->abfd
= cu
->objfile
->obfd
;
3249 if (cu
->per_cu
->debug_type_section
)
3251 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3252 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3256 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3257 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3261 /* Find the base address of the compilation unit for range lists and
3262 location lists. It will normally be specified by DW_AT_low_pc.
3263 In DWARF-3 draft 4, the base address could be overridden by
3264 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3265 compilation units with discontinuous ranges. */
3268 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3270 struct attribute
*attr
;
3273 cu
->base_address
= 0;
3275 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3278 cu
->base_address
= DW_ADDR (attr
);
3283 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3286 cu
->base_address
= DW_ADDR (attr
);
3292 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3293 to combine the common parts.
3294 Process a compilation unit for a psymtab.
3295 BUFFER is a pointer to the beginning of the dwarf section buffer,
3296 either .debug_info or debug_types.
3297 INFO_PTR is a pointer to the start of the CU.
3298 Returns a pointer to the next CU. */
3301 process_psymtab_comp_unit (struct objfile
*objfile
,
3302 struct dwarf2_per_cu_data
*this_cu
,
3303 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3304 unsigned int buffer_size
)
3306 bfd
*abfd
= objfile
->obfd
;
3307 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3308 struct die_info
*comp_unit_die
;
3309 struct partial_symtab
*pst
;
3311 struct cleanup
*back_to_inner
;
3312 struct dwarf2_cu cu
;
3313 int has_children
, has_pc_info
;
3314 struct attribute
*attr
;
3315 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3316 struct die_reader_specs reader_specs
;
3317 const char *filename
;
3319 init_one_comp_unit (&cu
, objfile
);
3320 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3322 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3323 buffer
, buffer_size
,
3326 /* Complete the cu_header. */
3327 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3328 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3330 cu
.list_in_scope
= &file_symbols
;
3332 /* If this compilation unit was already read in, free the
3333 cached copy in order to read it in again. This is
3334 necessary because we skipped some symbols when we first
3335 read in the compilation unit (see load_partial_dies).
3336 This problem could be avoided, but the benefit is
3338 if (this_cu
->cu
!= NULL
)
3339 free_one_cached_comp_unit (this_cu
->cu
);
3341 /* Note that this is a pointer to our stack frame, being
3342 added to a global data structure. It will be cleaned up
3343 in free_stack_comp_unit when we finish with this
3344 compilation unit. */
3346 cu
.per_cu
= this_cu
;
3348 /* Read the abbrevs for this compilation unit into a table. */
3349 dwarf2_read_abbrevs (abfd
, &cu
);
3350 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3352 /* Read the compilation unit die. */
3353 if (this_cu
->debug_type_section
)
3354 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3355 init_cu_die_reader (&reader_specs
, &cu
);
3356 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3359 if (this_cu
->debug_type_section
)
3361 /* LENGTH has not been set yet for type units. */
3362 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3363 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3365 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3367 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3368 + cu
.header
.initial_length_size
);
3369 do_cleanups (back_to_inner
);
3373 prepare_one_comp_unit (&cu
, comp_unit_die
);
3375 /* Allocate a new partial symbol table structure. */
3376 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3377 if (attr
== NULL
|| !DW_STRING (attr
))
3380 filename
= DW_STRING (attr
);
3381 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3383 /* TEXTLOW and TEXTHIGH are set below. */
3385 objfile
->global_psymbols
.next
,
3386 objfile
->static_psymbols
.next
);
3388 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3390 pst
->dirname
= DW_STRING (attr
);
3392 pst
->read_symtab_private
= this_cu
;
3394 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3396 /* Store the function that reads in the rest of the symbol table. */
3397 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3399 this_cu
->v
.psymtab
= pst
;
3401 dwarf2_find_base_address (comp_unit_die
, &cu
);
3403 /* Possibly set the default values of LOWPC and HIGHPC from
3405 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3406 &best_highpc
, &cu
, pst
);
3407 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3408 /* Store the contiguous range if it is not empty; it can be empty for
3409 CUs with no code. */
3410 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3411 best_lowpc
+ baseaddr
,
3412 best_highpc
+ baseaddr
- 1, pst
);
3414 /* Check if comp unit has_children.
3415 If so, read the rest of the partial symbols from this comp unit.
3416 If not, there's no more debug_info for this comp unit. */
3419 struct partial_die_info
*first_die
;
3420 CORE_ADDR lowpc
, highpc
;
3422 lowpc
= ((CORE_ADDR
) -1);
3423 highpc
= ((CORE_ADDR
) 0);
3425 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3427 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3428 ! has_pc_info
, &cu
);
3430 /* If we didn't find a lowpc, set it to highpc to avoid
3431 complaints from `maint check'. */
3432 if (lowpc
== ((CORE_ADDR
) -1))
3435 /* If the compilation unit didn't have an explicit address range,
3436 then use the information extracted from its child dies. */
3440 best_highpc
= highpc
;
3443 pst
->textlow
= best_lowpc
+ baseaddr
;
3444 pst
->texthigh
= best_highpc
+ baseaddr
;
3446 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3447 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3448 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3449 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3450 sort_pst_symbols (pst
);
3452 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3453 + cu
.header
.initial_length_size
);
3455 if (this_cu
->debug_type_section
)
3457 /* It's not clear we want to do anything with stmt lists here.
3458 Waiting to see what gcc ultimately does. */
3462 /* Get the list of files included in the current compilation unit,
3463 and build a psymtab for each of them. */
3464 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3467 do_cleanups (back_to_inner
);
3472 /* Traversal function for htab_traverse_noresize.
3473 Process one .debug_types comp-unit. */
3476 process_type_comp_unit (void **slot
, void *info
)
3478 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3479 struct objfile
*objfile
= (struct objfile
*) info
;
3480 struct dwarf2_per_cu_data
*this_cu
;
3482 this_cu
= &entry
->per_cu
;
3484 gdb_assert (this_cu
->debug_type_section
->readin
);
3485 process_psymtab_comp_unit (objfile
, this_cu
,
3486 this_cu
->debug_type_section
->buffer
,
3487 (this_cu
->debug_type_section
->buffer
3489 this_cu
->debug_type_section
->size
);
3494 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3495 Build partial symbol tables for the .debug_types comp-units. */
3498 build_type_psymtabs (struct objfile
*objfile
)
3500 if (! create_debug_types_hash_table (objfile
))
3503 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3504 process_type_comp_unit
, objfile
);
3507 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3510 psymtabs_addrmap_cleanup (void *o
)
3512 struct objfile
*objfile
= o
;
3514 objfile
->psymtabs_addrmap
= NULL
;
3517 /* Build the partial symbol table by doing a quick pass through the
3518 .debug_info and .debug_abbrev sections. */
3521 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3524 struct cleanup
*back_to
, *addrmap_cleanup
;
3525 struct obstack temp_obstack
;
3527 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3529 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3530 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3532 /* Any cached compilation units will be linked by the per-objfile
3533 read_in_chain. Make sure to free them when we're done. */
3534 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3536 build_type_psymtabs (objfile
);
3538 create_all_comp_units (objfile
);
3540 /* Create a temporary address map on a temporary obstack. We later
3541 copy this to the final obstack. */
3542 obstack_init (&temp_obstack
);
3543 make_cleanup_obstack_free (&temp_obstack
);
3544 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3545 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3547 /* Since the objects we're extracting from .debug_info vary in
3548 length, only the individual functions to extract them (like
3549 read_comp_unit_head and load_partial_die) can really know whether
3550 the buffer is large enough to hold another complete object.
3552 At the moment, they don't actually check that. If .debug_info
3553 holds just one extra byte after the last compilation unit's dies,
3554 then read_comp_unit_head will happily read off the end of the
3555 buffer. read_partial_die is similarly casual. Those functions
3558 For this loop condition, simply checking whether there's any data
3559 left at all should be sufficient. */
3561 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3562 + dwarf2_per_objfile
->info
.size
))
3564 struct dwarf2_per_cu_data
*this_cu
;
3566 this_cu
= dwarf2_find_comp_unit (info_ptr
3567 - dwarf2_per_objfile
->info
.buffer
,
3570 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3571 dwarf2_per_objfile
->info
.buffer
,
3573 dwarf2_per_objfile
->info
.size
);
3576 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3577 &objfile
->objfile_obstack
);
3578 discard_cleanups (addrmap_cleanup
);
3580 do_cleanups (back_to
);
3583 /* Load the partial DIEs for a secondary CU into memory. */
3586 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3587 struct objfile
*objfile
)
3589 bfd
*abfd
= objfile
->obfd
;
3590 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3591 struct die_info
*comp_unit_die
;
3592 struct dwarf2_cu
*cu
;
3593 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3595 struct die_reader_specs reader_specs
;
3598 gdb_assert (! this_cu
->debug_type_section
);
3600 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3601 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3602 beg_of_comp_unit
= info_ptr
;
3604 if (this_cu
->cu
== NULL
)
3606 cu
= xmalloc (sizeof (*cu
));
3607 init_one_comp_unit (cu
, objfile
);
3611 /* If an error occurs while loading, release our storage. */
3612 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3614 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3615 dwarf2_per_objfile
->info
.buffer
,
3616 dwarf2_per_objfile
->info
.size
,
3619 /* Complete the cu_header. */
3620 cu
->header
.offset
= this_cu
->offset
;
3621 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3623 /* Link this compilation unit into the compilation unit tree. */
3625 cu
->per_cu
= this_cu
;
3627 /* Link this CU into read_in_chain. */
3628 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3629 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3634 info_ptr
+= cu
->header
.first_die_offset
;
3637 /* Read the abbrevs for this compilation unit into a table. */
3638 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3639 dwarf2_read_abbrevs (abfd
, cu
);
3640 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3642 /* Read the compilation unit die. */
3643 init_cu_die_reader (&reader_specs
, cu
);
3644 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3647 prepare_one_comp_unit (cu
, comp_unit_die
);
3649 /* Check if comp unit has_children.
3650 If so, read the rest of the partial symbols from this comp unit.
3651 If not, there's no more debug_info for this comp unit. */
3653 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3655 do_cleanups (free_abbrevs_cleanup
);
3659 /* We've successfully allocated this compilation unit. Let our
3660 caller clean it up when finished with it. */
3661 discard_cleanups (free_cu_cleanup
);
3665 /* Create a list of all compilation units in OBJFILE. We do this only
3666 if an inter-comp-unit reference is found; presumably if there is one,
3667 there will be many, and one will occur early in the .debug_info section.
3668 So there's no point in building this list incrementally. */
3671 create_all_comp_units (struct objfile
*objfile
)
3675 struct dwarf2_per_cu_data
**all_comp_units
;
3678 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3679 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3683 all_comp_units
= xmalloc (n_allocated
3684 * sizeof (struct dwarf2_per_cu_data
*));
3686 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3687 + dwarf2_per_objfile
->info
.size
)
3689 unsigned int length
, initial_length_size
;
3690 struct dwarf2_per_cu_data
*this_cu
;
3691 unsigned int offset
;
3693 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3695 /* Read just enough information to find out where the next
3696 compilation unit is. */
3697 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3698 &initial_length_size
);
3700 /* Save the compilation unit for later lookup. */
3701 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3702 sizeof (struct dwarf2_per_cu_data
));
3703 memset (this_cu
, 0, sizeof (*this_cu
));
3704 this_cu
->offset
= offset
;
3705 this_cu
->length
= length
+ initial_length_size
;
3706 this_cu
->objfile
= objfile
;
3708 if (n_comp_units
== n_allocated
)
3711 all_comp_units
= xrealloc (all_comp_units
,
3713 * sizeof (struct dwarf2_per_cu_data
*));
3715 all_comp_units
[n_comp_units
++] = this_cu
;
3717 info_ptr
= info_ptr
+ this_cu
->length
;
3720 dwarf2_per_objfile
->all_comp_units
3721 = obstack_alloc (&objfile
->objfile_obstack
,
3722 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3723 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3724 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3725 xfree (all_comp_units
);
3726 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3729 /* Process all loaded DIEs for compilation unit CU, starting at
3730 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3731 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3732 DW_AT_ranges). If NEED_PC is set, then this function will set
3733 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3734 and record the covered ranges in the addrmap. */
3737 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3738 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3740 struct partial_die_info
*pdi
;
3742 /* Now, march along the PDI's, descending into ones which have
3743 interesting children but skipping the children of the other ones,
3744 until we reach the end of the compilation unit. */
3750 fixup_partial_die (pdi
, cu
);
3752 /* Anonymous namespaces or modules have no name but have interesting
3753 children, so we need to look at them. Ditto for anonymous
3756 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3757 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3761 case DW_TAG_subprogram
:
3762 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3764 case DW_TAG_constant
:
3765 case DW_TAG_variable
:
3766 case DW_TAG_typedef
:
3767 case DW_TAG_union_type
:
3768 if (!pdi
->is_declaration
)
3770 add_partial_symbol (pdi
, cu
);
3773 case DW_TAG_class_type
:
3774 case DW_TAG_interface_type
:
3775 case DW_TAG_structure_type
:
3776 if (!pdi
->is_declaration
)
3778 add_partial_symbol (pdi
, cu
);
3781 case DW_TAG_enumeration_type
:
3782 if (!pdi
->is_declaration
)
3783 add_partial_enumeration (pdi
, cu
);
3785 case DW_TAG_base_type
:
3786 case DW_TAG_subrange_type
:
3787 /* File scope base type definitions are added to the partial
3789 add_partial_symbol (pdi
, cu
);
3791 case DW_TAG_namespace
:
3792 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3795 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3802 /* If the die has a sibling, skip to the sibling. */
3804 pdi
= pdi
->die_sibling
;
3808 /* Functions used to compute the fully scoped name of a partial DIE.
3810 Normally, this is simple. For C++, the parent DIE's fully scoped
3811 name is concatenated with "::" and the partial DIE's name. For
3812 Java, the same thing occurs except that "." is used instead of "::".
3813 Enumerators are an exception; they use the scope of their parent
3814 enumeration type, i.e. the name of the enumeration type is not
3815 prepended to the enumerator.
3817 There are two complexities. One is DW_AT_specification; in this
3818 case "parent" means the parent of the target of the specification,
3819 instead of the direct parent of the DIE. The other is compilers
3820 which do not emit DW_TAG_namespace; in this case we try to guess
3821 the fully qualified name of structure types from their members'
3822 linkage names. This must be done using the DIE's children rather
3823 than the children of any DW_AT_specification target. We only need
3824 to do this for structures at the top level, i.e. if the target of
3825 any DW_AT_specification (if any; otherwise the DIE itself) does not
3828 /* Compute the scope prefix associated with PDI's parent, in
3829 compilation unit CU. The result will be allocated on CU's
3830 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3831 field. NULL is returned if no prefix is necessary. */
3833 partial_die_parent_scope (struct partial_die_info
*pdi
,
3834 struct dwarf2_cu
*cu
)
3836 char *grandparent_scope
;
3837 struct partial_die_info
*parent
, *real_pdi
;
3839 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3840 then this means the parent of the specification DIE. */
3843 while (real_pdi
->has_specification
)
3844 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3846 parent
= real_pdi
->die_parent
;
3850 if (parent
->scope_set
)
3851 return parent
->scope
;
3853 fixup_partial_die (parent
, cu
);
3855 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3857 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3858 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3859 Work around this problem here. */
3860 if (cu
->language
== language_cplus
3861 && parent
->tag
== DW_TAG_namespace
3862 && strcmp (parent
->name
, "::") == 0
3863 && grandparent_scope
== NULL
)
3865 parent
->scope
= NULL
;
3866 parent
->scope_set
= 1;
3870 if (parent
->tag
== DW_TAG_namespace
3871 || parent
->tag
== DW_TAG_module
3872 || parent
->tag
== DW_TAG_structure_type
3873 || parent
->tag
== DW_TAG_class_type
3874 || parent
->tag
== DW_TAG_interface_type
3875 || parent
->tag
== DW_TAG_union_type
3876 || parent
->tag
== DW_TAG_enumeration_type
)
3878 if (grandparent_scope
== NULL
)
3879 parent
->scope
= parent
->name
;
3881 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3883 parent
->name
, 0, cu
);
3885 else if (parent
->tag
== DW_TAG_enumerator
)
3886 /* Enumerators should not get the name of the enumeration as a prefix. */
3887 parent
->scope
= grandparent_scope
;
3890 /* FIXME drow/2004-04-01: What should we be doing with
3891 function-local names? For partial symbols, we should probably be
3893 complaint (&symfile_complaints
,
3894 _("unhandled containing DIE tag %d for DIE at %d"),
3895 parent
->tag
, pdi
->offset
);
3896 parent
->scope
= grandparent_scope
;
3899 parent
->scope_set
= 1;
3900 return parent
->scope
;
3903 /* Return the fully scoped name associated with PDI, from compilation unit
3904 CU. The result will be allocated with malloc. */
3906 partial_die_full_name (struct partial_die_info
*pdi
,
3907 struct dwarf2_cu
*cu
)
3911 /* If this is a template instantiation, we can not work out the
3912 template arguments from partial DIEs. So, unfortunately, we have
3913 to go through the full DIEs. At least any work we do building
3914 types here will be reused if full symbols are loaded later. */
3915 if (pdi
->has_template_arguments
)
3917 fixup_partial_die (pdi
, cu
);
3919 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3921 struct die_info
*die
;
3922 struct attribute attr
;
3923 struct dwarf2_cu
*ref_cu
= cu
;
3926 attr
.form
= DW_FORM_ref_addr
;
3927 attr
.u
.addr
= pdi
->offset
;
3928 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3930 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3934 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3935 if (parent_scope
== NULL
)
3938 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3942 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3944 struct objfile
*objfile
= cu
->objfile
;
3946 char *actual_name
= NULL
;
3947 const struct partial_symbol
*psym
= NULL
;
3949 int built_actual_name
= 0;
3951 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3953 actual_name
= partial_die_full_name (pdi
, cu
);
3955 built_actual_name
= 1;
3957 if (actual_name
== NULL
)
3958 actual_name
= pdi
->name
;
3962 case DW_TAG_subprogram
:
3963 if (pdi
->is_external
|| cu
->language
== language_ada
)
3965 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3966 of the global scope. But in Ada, we want to be able to access
3967 nested procedures globally. So all Ada subprograms are stored
3968 in the global scope. */
3969 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3970 mst_text, objfile); */
3971 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3973 VAR_DOMAIN
, LOC_BLOCK
,
3974 &objfile
->global_psymbols
,
3975 0, pdi
->lowpc
+ baseaddr
,
3976 cu
->language
, objfile
);
3980 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3981 mst_file_text, objfile); */
3982 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3984 VAR_DOMAIN
, LOC_BLOCK
,
3985 &objfile
->static_psymbols
,
3986 0, pdi
->lowpc
+ baseaddr
,
3987 cu
->language
, objfile
);
3990 case DW_TAG_constant
:
3992 struct psymbol_allocation_list
*list
;
3994 if (pdi
->is_external
)
3995 list
= &objfile
->global_psymbols
;
3997 list
= &objfile
->static_psymbols
;
3998 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3999 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4000 list
, 0, 0, cu
->language
, objfile
);
4003 case DW_TAG_variable
:
4005 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4009 && !dwarf2_per_objfile
->has_section_at_zero
)
4011 /* A global or static variable may also have been stripped
4012 out by the linker if unused, in which case its address
4013 will be nullified; do not add such variables into partial
4014 symbol table then. */
4016 else if (pdi
->is_external
)
4019 Don't enter into the minimal symbol tables as there is
4020 a minimal symbol table entry from the ELF symbols already.
4021 Enter into partial symbol table if it has a location
4022 descriptor or a type.
4023 If the location descriptor is missing, new_symbol will create
4024 a LOC_UNRESOLVED symbol, the address of the variable will then
4025 be determined from the minimal symbol table whenever the variable
4027 The address for the partial symbol table entry is not
4028 used by GDB, but it comes in handy for debugging partial symbol
4031 if (pdi
->locdesc
|| pdi
->has_type
)
4032 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4034 VAR_DOMAIN
, LOC_STATIC
,
4035 &objfile
->global_psymbols
,
4037 cu
->language
, objfile
);
4041 /* Static Variable. Skip symbols without location descriptors. */
4042 if (pdi
->locdesc
== NULL
)
4044 if (built_actual_name
)
4045 xfree (actual_name
);
4048 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4049 mst_file_data, objfile); */
4050 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4052 VAR_DOMAIN
, LOC_STATIC
,
4053 &objfile
->static_psymbols
,
4055 cu
->language
, objfile
);
4058 case DW_TAG_typedef
:
4059 case DW_TAG_base_type
:
4060 case DW_TAG_subrange_type
:
4061 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4063 VAR_DOMAIN
, LOC_TYPEDEF
,
4064 &objfile
->static_psymbols
,
4065 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4067 case DW_TAG_namespace
:
4068 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4070 VAR_DOMAIN
, LOC_TYPEDEF
,
4071 &objfile
->global_psymbols
,
4072 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4074 case DW_TAG_class_type
:
4075 case DW_TAG_interface_type
:
4076 case DW_TAG_structure_type
:
4077 case DW_TAG_union_type
:
4078 case DW_TAG_enumeration_type
:
4079 /* Skip external references. The DWARF standard says in the section
4080 about "Structure, Union, and Class Type Entries": "An incomplete
4081 structure, union or class type is represented by a structure,
4082 union or class entry that does not have a byte size attribute
4083 and that has a DW_AT_declaration attribute." */
4084 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4086 if (built_actual_name
)
4087 xfree (actual_name
);
4091 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4092 static vs. global. */
4093 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4095 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4096 (cu
->language
== language_cplus
4097 || cu
->language
== language_java
)
4098 ? &objfile
->global_psymbols
4099 : &objfile
->static_psymbols
,
4100 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4103 case DW_TAG_enumerator
:
4104 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4106 VAR_DOMAIN
, LOC_CONST
,
4107 (cu
->language
== language_cplus
4108 || cu
->language
== language_java
)
4109 ? &objfile
->global_psymbols
4110 : &objfile
->static_psymbols
,
4111 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4117 if (built_actual_name
)
4118 xfree (actual_name
);
4121 /* Read a partial die corresponding to a namespace; also, add a symbol
4122 corresponding to that namespace to the symbol table. NAMESPACE is
4123 the name of the enclosing namespace. */
4126 add_partial_namespace (struct partial_die_info
*pdi
,
4127 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4128 int need_pc
, struct dwarf2_cu
*cu
)
4130 /* Add a symbol for the namespace. */
4132 add_partial_symbol (pdi
, cu
);
4134 /* Now scan partial symbols in that namespace. */
4136 if (pdi
->has_children
)
4137 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4140 /* Read a partial die corresponding to a Fortran module. */
4143 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4144 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4146 /* Now scan partial symbols in that module. */
4148 if (pdi
->has_children
)
4149 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4152 /* Read a partial die corresponding to a subprogram and create a partial
4153 symbol for that subprogram. When the CU language allows it, this
4154 routine also defines a partial symbol for each nested subprogram
4155 that this subprogram contains.
4157 DIE my also be a lexical block, in which case we simply search
4158 recursively for suprograms defined inside that lexical block.
4159 Again, this is only performed when the CU language allows this
4160 type of definitions. */
4163 add_partial_subprogram (struct partial_die_info
*pdi
,
4164 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4165 int need_pc
, struct dwarf2_cu
*cu
)
4167 if (pdi
->tag
== DW_TAG_subprogram
)
4169 if (pdi
->has_pc_info
)
4171 if (pdi
->lowpc
< *lowpc
)
4172 *lowpc
= pdi
->lowpc
;
4173 if (pdi
->highpc
> *highpc
)
4174 *highpc
= pdi
->highpc
;
4178 struct objfile
*objfile
= cu
->objfile
;
4180 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4181 SECT_OFF_TEXT (objfile
));
4182 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4183 pdi
->lowpc
+ baseaddr
,
4184 pdi
->highpc
- 1 + baseaddr
,
4185 cu
->per_cu
->v
.psymtab
);
4187 if (!pdi
->is_declaration
)
4188 /* Ignore subprogram DIEs that do not have a name, they are
4189 illegal. Do not emit a complaint at this point, we will
4190 do so when we convert this psymtab into a symtab. */
4192 add_partial_symbol (pdi
, cu
);
4196 if (! pdi
->has_children
)
4199 if (cu
->language
== language_ada
)
4201 pdi
= pdi
->die_child
;
4204 fixup_partial_die (pdi
, cu
);
4205 if (pdi
->tag
== DW_TAG_subprogram
4206 || pdi
->tag
== DW_TAG_lexical_block
)
4207 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4208 pdi
= pdi
->die_sibling
;
4213 /* Read a partial die corresponding to an enumeration type. */
4216 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4217 struct dwarf2_cu
*cu
)
4219 struct partial_die_info
*pdi
;
4221 if (enum_pdi
->name
!= NULL
)
4222 add_partial_symbol (enum_pdi
, cu
);
4224 pdi
= enum_pdi
->die_child
;
4227 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4228 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4230 add_partial_symbol (pdi
, cu
);
4231 pdi
= pdi
->die_sibling
;
4235 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4236 Return the corresponding abbrev, or NULL if the number is zero (indicating
4237 an empty DIE). In either case *BYTES_READ will be set to the length of
4238 the initial number. */
4240 static struct abbrev_info
*
4241 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4242 struct dwarf2_cu
*cu
)
4244 bfd
*abfd
= cu
->objfile
->obfd
;
4245 unsigned int abbrev_number
;
4246 struct abbrev_info
*abbrev
;
4248 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4250 if (abbrev_number
== 0)
4253 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4256 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4257 abbrev_number
, bfd_get_filename (abfd
));
4263 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4264 Returns a pointer to the end of a series of DIEs, terminated by an empty
4265 DIE. Any children of the skipped DIEs will also be skipped. */
4268 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4270 struct abbrev_info
*abbrev
;
4271 unsigned int bytes_read
;
4275 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4277 return info_ptr
+ bytes_read
;
4279 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4283 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4284 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4285 abbrev corresponding to that skipped uleb128 should be passed in
4286 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4290 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4291 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4293 unsigned int bytes_read
;
4294 struct attribute attr
;
4295 bfd
*abfd
= cu
->objfile
->obfd
;
4296 unsigned int form
, i
;
4298 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4300 /* The only abbrev we care about is DW_AT_sibling. */
4301 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4303 read_attribute (&attr
, &abbrev
->attrs
[i
],
4304 abfd
, info_ptr
, cu
);
4305 if (attr
.form
== DW_FORM_ref_addr
)
4306 complaint (&symfile_complaints
,
4307 _("ignoring absolute DW_AT_sibling"));
4309 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4312 /* If it isn't DW_AT_sibling, skip this attribute. */
4313 form
= abbrev
->attrs
[i
].form
;
4317 case DW_FORM_ref_addr
:
4318 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4319 and later it is offset sized. */
4320 if (cu
->header
.version
== 2)
4321 info_ptr
+= cu
->header
.addr_size
;
4323 info_ptr
+= cu
->header
.offset_size
;
4326 info_ptr
+= cu
->header
.addr_size
;
4333 case DW_FORM_flag_present
:
4345 case DW_FORM_ref_sig8
:
4348 case DW_FORM_string
:
4349 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4350 info_ptr
+= bytes_read
;
4352 case DW_FORM_sec_offset
:
4354 info_ptr
+= cu
->header
.offset_size
;
4356 case DW_FORM_exprloc
:
4358 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4359 info_ptr
+= bytes_read
;
4361 case DW_FORM_block1
:
4362 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4364 case DW_FORM_block2
:
4365 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4367 case DW_FORM_block4
:
4368 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4372 case DW_FORM_ref_udata
:
4373 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4375 case DW_FORM_indirect
:
4376 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4377 info_ptr
+= bytes_read
;
4378 /* We need to continue parsing from here, so just go back to
4380 goto skip_attribute
;
4383 error (_("Dwarf Error: Cannot handle %s "
4384 "in DWARF reader [in module %s]"),
4385 dwarf_form_name (form
),
4386 bfd_get_filename (abfd
));
4390 if (abbrev
->has_children
)
4391 return skip_children (buffer
, info_ptr
, cu
);
4396 /* Locate ORIG_PDI's sibling.
4397 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4401 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4402 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4403 bfd
*abfd
, struct dwarf2_cu
*cu
)
4405 /* Do we know the sibling already? */
4407 if (orig_pdi
->sibling
)
4408 return orig_pdi
->sibling
;
4410 /* Are there any children to deal with? */
4412 if (!orig_pdi
->has_children
)
4415 /* Skip the children the long way. */
4417 return skip_children (buffer
, info_ptr
, cu
);
4420 /* Expand this partial symbol table into a full symbol table. */
4423 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4429 warning (_("bug: psymtab for %s is already read in."),
4436 printf_filtered (_("Reading in symbols for %s..."),
4438 gdb_flush (gdb_stdout
);
4441 /* Restore our global data. */
4442 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4443 dwarf2_objfile_data_key
);
4445 /* If this psymtab is constructed from a debug-only objfile, the
4446 has_section_at_zero flag will not necessarily be correct. We
4447 can get the correct value for this flag by looking at the data
4448 associated with the (presumably stripped) associated objfile. */
4449 if (pst
->objfile
->separate_debug_objfile_backlink
)
4451 struct dwarf2_per_objfile
*dpo_backlink
4452 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4453 dwarf2_objfile_data_key
);
4455 dwarf2_per_objfile
->has_section_at_zero
4456 = dpo_backlink
->has_section_at_zero
;
4459 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4461 psymtab_to_symtab_1 (pst
);
4463 /* Finish up the debug error message. */
4465 printf_filtered (_("done.\n"));
4470 /* Add PER_CU to the queue. */
4473 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4475 struct dwarf2_queue_item
*item
;
4478 item
= xmalloc (sizeof (*item
));
4479 item
->per_cu
= per_cu
;
4482 if (dwarf2_queue
== NULL
)
4483 dwarf2_queue
= item
;
4485 dwarf2_queue_tail
->next
= item
;
4487 dwarf2_queue_tail
= item
;
4490 /* Process the queue. */
4493 process_queue (struct objfile
*objfile
)
4495 struct dwarf2_queue_item
*item
, *next_item
;
4497 /* The queue starts out with one item, but following a DIE reference
4498 may load a new CU, adding it to the end of the queue. */
4499 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4501 if (dwarf2_per_objfile
->using_index
4502 ? !item
->per_cu
->v
.quick
->symtab
4503 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4504 process_full_comp_unit (item
->per_cu
);
4506 item
->per_cu
->queued
= 0;
4507 next_item
= item
->next
;
4511 dwarf2_queue_tail
= NULL
;
4514 /* Free all allocated queue entries. This function only releases anything if
4515 an error was thrown; if the queue was processed then it would have been
4516 freed as we went along. */
4519 dwarf2_release_queue (void *dummy
)
4521 struct dwarf2_queue_item
*item
, *last
;
4523 item
= dwarf2_queue
;
4526 /* Anything still marked queued is likely to be in an
4527 inconsistent state, so discard it. */
4528 if (item
->per_cu
->queued
)
4530 if (item
->per_cu
->cu
!= NULL
)
4531 free_one_cached_comp_unit (item
->per_cu
->cu
);
4532 item
->per_cu
->queued
= 0;
4540 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4543 /* Read in full symbols for PST, and anything it depends on. */
4546 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4548 struct dwarf2_per_cu_data
*per_cu
;
4549 struct cleanup
*back_to
;
4552 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4553 if (!pst
->dependencies
[i
]->readin
)
4555 /* Inform about additional files that need to be read in. */
4558 /* FIXME: i18n: Need to make this a single string. */
4559 fputs_filtered (" ", gdb_stdout
);
4561 fputs_filtered ("and ", gdb_stdout
);
4563 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4564 wrap_here (""); /* Flush output. */
4565 gdb_flush (gdb_stdout
);
4567 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4570 per_cu
= pst
->read_symtab_private
;
4574 /* It's an include file, no symbols to read for it.
4575 Everything is in the parent symtab. */
4580 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4583 /* Load the DIEs associated with PER_CU into memory. */
4586 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4587 struct objfile
*objfile
)
4589 bfd
*abfd
= objfile
->obfd
;
4590 struct dwarf2_cu
*cu
;
4591 unsigned int offset
;
4592 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4593 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4594 struct attribute
*attr
;
4597 gdb_assert (! per_cu
->debug_type_section
);
4599 /* Set local variables from the partial symbol table info. */
4600 offset
= per_cu
->offset
;
4602 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4603 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4604 beg_of_comp_unit
= info_ptr
;
4606 if (per_cu
->cu
== NULL
)
4608 cu
= xmalloc (sizeof (*cu
));
4609 init_one_comp_unit (cu
, objfile
);
4613 /* If an error occurs while loading, release our storage. */
4614 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4616 /* Read in the comp_unit header. */
4617 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4619 /* Complete the cu_header. */
4620 cu
->header
.offset
= offset
;
4621 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4623 /* Read the abbrevs for this compilation unit. */
4624 dwarf2_read_abbrevs (abfd
, cu
);
4625 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4627 /* Link this compilation unit into the compilation unit tree. */
4629 cu
->per_cu
= per_cu
;
4631 /* Link this CU into read_in_chain. */
4632 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4633 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4638 info_ptr
+= cu
->header
.first_die_offset
;
4641 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4643 /* We try not to read any attributes in this function, because not
4644 all objfiles needed for references have been loaded yet, and symbol
4645 table processing isn't initialized. But we have to set the CU language,
4646 or we won't be able to build types correctly. */
4647 prepare_one_comp_unit (cu
, cu
->dies
);
4649 /* Similarly, if we do not read the producer, we can not apply
4650 producer-specific interpretation. */
4651 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4653 cu
->producer
= DW_STRING (attr
);
4657 do_cleanups (free_abbrevs_cleanup
);
4659 /* We've successfully allocated this compilation unit. Let our
4660 caller clean it up when finished with it. */
4661 discard_cleanups (free_cu_cleanup
);
4665 /* Add a DIE to the delayed physname list. */
4668 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4669 const char *name
, struct die_info
*die
,
4670 struct dwarf2_cu
*cu
)
4672 struct delayed_method_info mi
;
4674 mi
.fnfield_index
= fnfield_index
;
4678 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4681 /* A cleanup for freeing the delayed method list. */
4684 free_delayed_list (void *ptr
)
4686 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4687 if (cu
->method_list
!= NULL
)
4689 VEC_free (delayed_method_info
, cu
->method_list
);
4690 cu
->method_list
= NULL
;
4694 /* Compute the physnames of any methods on the CU's method list.
4696 The computation of method physnames is delayed in order to avoid the
4697 (bad) condition that one of the method's formal parameters is of an as yet
4701 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4704 struct delayed_method_info
*mi
;
4705 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4707 const char *physname
;
4708 struct fn_fieldlist
*fn_flp
4709 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4710 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4711 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4715 /* Check for GCC >= 4.x. Return minor version (x) of 4.x in such case. If it
4716 is not GCC or it is GCC older than 4.x return -1. If it is GCC 5.x or
4717 higher return INT_MAX. */
4720 producer_is_gcc_ge_4 (struct dwarf2_cu
*cu
)
4725 if (cu
->producer
== NULL
)
4727 /* For unknown compilers expect their behavior is not compliant. For GCC
4728 this case can also happen for -gdwarf-4 type units supported since
4734 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4736 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4738 /* For non-GCC compilers expect their behavior is not compliant. */
4742 cs
= &cu
->producer
[strlen ("GNU ")];
4743 while (*cs
&& !isdigit (*cs
))
4745 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4747 /* Not recognized as GCC. */
4759 /* Generate full symbol information for PST and CU, whose DIEs have
4760 already been loaded into memory. */
4763 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4765 struct dwarf2_cu
*cu
= per_cu
->cu
;
4766 struct objfile
*objfile
= per_cu
->objfile
;
4767 CORE_ADDR lowpc
, highpc
;
4768 struct symtab
*symtab
;
4769 struct cleanup
*back_to
, *delayed_list_cleanup
;
4772 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4775 back_to
= make_cleanup (really_free_pendings
, NULL
);
4776 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4778 cu
->list_in_scope
= &file_symbols
;
4780 /* Do line number decoding in read_file_scope () */
4781 process_die (cu
->dies
, cu
);
4783 /* Now that we have processed all the DIEs in the CU, all the types
4784 should be complete, and it should now be safe to compute all of the
4786 compute_delayed_physnames (cu
);
4787 do_cleanups (delayed_list_cleanup
);
4789 /* Some compilers don't define a DW_AT_high_pc attribute for the
4790 compilation unit. If the DW_AT_high_pc is missing, synthesize
4791 it, by scanning the DIE's below the compilation unit. */
4792 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4794 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4798 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
);
4800 /* Set symtab language to language from DW_AT_language. If the
4801 compilation is from a C file generated by language preprocessors, do
4802 not set the language if it was already deduced by start_subfile. */
4803 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4804 symtab
->language
= cu
->language
;
4806 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4807 produce DW_AT_location with location lists but it can be possibly
4808 invalid without -fvar-tracking.
4810 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4811 needed, it would be wrong due to missing DW_AT_producer there.
4813 Still one can confuse GDB by using non-standard GCC compilation
4814 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4816 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4817 symtab
->locations_valid
= 1;
4819 if (gcc_4_minor
>= 5)
4820 symtab
->epilogue_unwind_valid
= 1;
4823 if (dwarf2_per_objfile
->using_index
)
4824 per_cu
->v
.quick
->symtab
= symtab
;
4827 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4828 pst
->symtab
= symtab
;
4832 do_cleanups (back_to
);
4835 /* Process a die and its children. */
4838 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4842 case DW_TAG_padding
:
4844 case DW_TAG_compile_unit
:
4845 read_file_scope (die
, cu
);
4847 case DW_TAG_type_unit
:
4848 read_type_unit_scope (die
, cu
);
4850 case DW_TAG_subprogram
:
4851 case DW_TAG_inlined_subroutine
:
4852 read_func_scope (die
, cu
);
4854 case DW_TAG_lexical_block
:
4855 case DW_TAG_try_block
:
4856 case DW_TAG_catch_block
:
4857 read_lexical_block_scope (die
, cu
);
4859 case DW_TAG_class_type
:
4860 case DW_TAG_interface_type
:
4861 case DW_TAG_structure_type
:
4862 case DW_TAG_union_type
:
4863 process_structure_scope (die
, cu
);
4865 case DW_TAG_enumeration_type
:
4866 process_enumeration_scope (die
, cu
);
4869 /* These dies have a type, but processing them does not create
4870 a symbol or recurse to process the children. Therefore we can
4871 read them on-demand through read_type_die. */
4872 case DW_TAG_subroutine_type
:
4873 case DW_TAG_set_type
:
4874 case DW_TAG_array_type
:
4875 case DW_TAG_pointer_type
:
4876 case DW_TAG_ptr_to_member_type
:
4877 case DW_TAG_reference_type
:
4878 case DW_TAG_string_type
:
4881 case DW_TAG_base_type
:
4882 case DW_TAG_subrange_type
:
4883 case DW_TAG_typedef
:
4884 /* Add a typedef symbol for the type definition, if it has a
4886 new_symbol (die
, read_type_die (die
, cu
), cu
);
4888 case DW_TAG_common_block
:
4889 read_common_block (die
, cu
);
4891 case DW_TAG_common_inclusion
:
4893 case DW_TAG_namespace
:
4894 processing_has_namespace_info
= 1;
4895 read_namespace (die
, cu
);
4898 processing_has_namespace_info
= 1;
4899 read_module (die
, cu
);
4901 case DW_TAG_imported_declaration
:
4902 case DW_TAG_imported_module
:
4903 processing_has_namespace_info
= 1;
4904 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4905 || cu
->language
!= language_fortran
))
4906 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4907 dwarf_tag_name (die
->tag
));
4908 read_import_statement (die
, cu
);
4911 new_symbol (die
, NULL
, cu
);
4916 /* A helper function for dwarf2_compute_name which determines whether DIE
4917 needs to have the name of the scope prepended to the name listed in the
4921 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4923 struct attribute
*attr
;
4927 case DW_TAG_namespace
:
4928 case DW_TAG_typedef
:
4929 case DW_TAG_class_type
:
4930 case DW_TAG_interface_type
:
4931 case DW_TAG_structure_type
:
4932 case DW_TAG_union_type
:
4933 case DW_TAG_enumeration_type
:
4934 case DW_TAG_enumerator
:
4935 case DW_TAG_subprogram
:
4939 case DW_TAG_variable
:
4940 case DW_TAG_constant
:
4941 /* We only need to prefix "globally" visible variables. These include
4942 any variable marked with DW_AT_external or any variable that
4943 lives in a namespace. [Variables in anonymous namespaces
4944 require prefixing, but they are not DW_AT_external.] */
4946 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4948 struct dwarf2_cu
*spec_cu
= cu
;
4950 return die_needs_namespace (die_specification (die
, &spec_cu
),
4954 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4955 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4956 && die
->parent
->tag
!= DW_TAG_module
)
4958 /* A variable in a lexical block of some kind does not need a
4959 namespace, even though in C++ such variables may be external
4960 and have a mangled name. */
4961 if (die
->parent
->tag
== DW_TAG_lexical_block
4962 || die
->parent
->tag
== DW_TAG_try_block
4963 || die
->parent
->tag
== DW_TAG_catch_block
4964 || die
->parent
->tag
== DW_TAG_subprogram
)
4973 /* Retrieve the last character from a mem_file. */
4976 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4978 char *last_char_p
= (char *) object
;
4981 *last_char_p
= buffer
[length
- 1];
4984 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4985 compute the physname for the object, which include a method's
4986 formal parameters (C++/Java) and return type (Java).
4988 For Ada, return the DIE's linkage name rather than the fully qualified
4989 name. PHYSNAME is ignored..
4991 The result is allocated on the objfile_obstack and canonicalized. */
4994 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4998 name
= dwarf2_name (die
, cu
);
5000 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5001 compute it by typename_concat inside GDB. */
5002 if (cu
->language
== language_ada
5003 || (cu
->language
== language_fortran
&& physname
))
5005 /* For Ada unit, we prefer the linkage name over the name, as
5006 the former contains the exported name, which the user expects
5007 to be able to reference. Ideally, we want the user to be able
5008 to reference this entity using either natural or linkage name,
5009 but we haven't started looking at this enhancement yet. */
5010 struct attribute
*attr
;
5012 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5014 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5015 if (attr
&& DW_STRING (attr
))
5016 return DW_STRING (attr
);
5019 /* These are the only languages we know how to qualify names in. */
5021 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5022 || cu
->language
== language_fortran
))
5024 if (die_needs_namespace (die
, cu
))
5028 struct ui_file
*buf
;
5030 prefix
= determine_prefix (die
, cu
);
5031 buf
= mem_fileopen ();
5032 if (*prefix
!= '\0')
5034 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5037 fputs_unfiltered (prefixed_name
, buf
);
5038 xfree (prefixed_name
);
5041 fputs_unfiltered (name
, buf
);
5043 /* Template parameters may be specified in the DIE's DW_AT_name, or
5044 as children with DW_TAG_template_type_param or
5045 DW_TAG_value_type_param. If the latter, add them to the name
5046 here. If the name already has template parameters, then
5047 skip this step; some versions of GCC emit both, and
5048 it is more efficient to use the pre-computed name.
5050 Something to keep in mind about this process: it is very
5051 unlikely, or in some cases downright impossible, to produce
5052 something that will match the mangled name of a function.
5053 If the definition of the function has the same debug info,
5054 we should be able to match up with it anyway. But fallbacks
5055 using the minimal symbol, for instance to find a method
5056 implemented in a stripped copy of libstdc++, will not work.
5057 If we do not have debug info for the definition, we will have to
5058 match them up some other way.
5060 When we do name matching there is a related problem with function
5061 templates; two instantiated function templates are allowed to
5062 differ only by their return types, which we do not add here. */
5064 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5066 struct attribute
*attr
;
5067 struct die_info
*child
;
5070 die
->building_fullname
= 1;
5072 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5077 struct dwarf2_locexpr_baton
*baton
;
5080 if (child
->tag
!= DW_TAG_template_type_param
5081 && child
->tag
!= DW_TAG_template_value_param
)
5086 fputs_unfiltered ("<", buf
);
5090 fputs_unfiltered (", ", buf
);
5092 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5095 complaint (&symfile_complaints
,
5096 _("template parameter missing DW_AT_type"));
5097 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5100 type
= die_type (child
, cu
);
5102 if (child
->tag
== DW_TAG_template_type_param
)
5104 c_print_type (type
, "", buf
, -1, 0);
5108 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5111 complaint (&symfile_complaints
,
5112 _("template parameter missing "
5113 "DW_AT_const_value"));
5114 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5118 dwarf2_const_value_attr (attr
, type
, name
,
5119 &cu
->comp_unit_obstack
, cu
,
5120 &value
, &bytes
, &baton
);
5122 if (TYPE_NOSIGN (type
))
5123 /* GDB prints characters as NUMBER 'CHAR'. If that's
5124 changed, this can use value_print instead. */
5125 c_printchar (value
, type
, buf
);
5128 struct value_print_options opts
;
5131 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5135 else if (bytes
!= NULL
)
5137 v
= allocate_value (type
);
5138 memcpy (value_contents_writeable (v
), bytes
,
5139 TYPE_LENGTH (type
));
5142 v
= value_from_longest (type
, value
);
5144 /* Specify decimal so that we do not depend on
5146 get_formatted_print_options (&opts
, 'd');
5148 value_print (v
, buf
, &opts
);
5154 die
->building_fullname
= 0;
5158 /* Close the argument list, with a space if necessary
5159 (nested templates). */
5160 char last_char
= '\0';
5161 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5162 if (last_char
== '>')
5163 fputs_unfiltered (" >", buf
);
5165 fputs_unfiltered (">", buf
);
5169 /* For Java and C++ methods, append formal parameter type
5170 information, if PHYSNAME. */
5172 if (physname
&& die
->tag
== DW_TAG_subprogram
5173 && (cu
->language
== language_cplus
5174 || cu
->language
== language_java
))
5176 struct type
*type
= read_type_die (die
, cu
);
5178 c_type_print_args (type
, buf
, 1, cu
->language
);
5180 if (cu
->language
== language_java
)
5182 /* For java, we must append the return type to method
5184 if (die
->tag
== DW_TAG_subprogram
)
5185 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5188 else if (cu
->language
== language_cplus
)
5190 /* Assume that an artificial first parameter is
5191 "this", but do not crash if it is not. RealView
5192 marks unnamed (and thus unused) parameters as
5193 artificial; there is no way to differentiate
5195 if (TYPE_NFIELDS (type
) > 0
5196 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5197 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5198 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5200 fputs_unfiltered (" const", buf
);
5204 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5206 ui_file_delete (buf
);
5208 if (cu
->language
== language_cplus
)
5211 = dwarf2_canonicalize_name (name
, cu
,
5212 &cu
->objfile
->objfile_obstack
);
5223 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5224 If scope qualifiers are appropriate they will be added. The result
5225 will be allocated on the objfile_obstack, or NULL if the DIE does
5226 not have a name. NAME may either be from a previous call to
5227 dwarf2_name or NULL.
5229 The output string will be canonicalized (if C++/Java). */
5232 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5234 return dwarf2_compute_name (name
, die
, cu
, 0);
5237 /* Construct a physname for the given DIE in CU. NAME may either be
5238 from a previous call to dwarf2_name or NULL. The result will be
5239 allocated on the objfile_objstack or NULL if the DIE does not have a
5242 The output string will be canonicalized (if C++/Java). */
5245 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5247 struct attribute
*attr
;
5248 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5249 struct cleanup
*back_to
;
5252 /* In this case dwarf2_compute_name is just a shortcut not building anything
5254 if (!die_needs_namespace (die
, cu
))
5255 return dwarf2_compute_name (name
, die
, cu
, 1);
5257 back_to
= make_cleanup (null_cleanup
, NULL
);
5259 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5261 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5263 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5265 if (attr
&& DW_STRING (attr
))
5269 mangled
= DW_STRING (attr
);
5271 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5272 type. It is easier for GDB users to search for such functions as
5273 `name(params)' than `long name(params)'. In such case the minimal
5274 symbol names do not match the full symbol names but for template
5275 functions there is never a need to look up their definition from their
5276 declaration so the only disadvantage remains the minimal symbol
5277 variant `long name(params)' does not have the proper inferior type.
5280 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5281 | (cu
->language
== language_java
5282 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5286 make_cleanup (xfree
, demangled
);
5296 if (canon
== NULL
|| check_physname
)
5298 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5300 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5302 /* It may not mean a bug in GDB. The compiler could also
5303 compute DW_AT_linkage_name incorrectly. But in such case
5304 GDB would need to be bug-to-bug compatible. */
5306 complaint (&symfile_complaints
,
5307 _("Computed physname <%s> does not match demangled <%s> "
5308 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5309 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5311 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5312 is available here - over computed PHYSNAME. It is safer
5313 against both buggy GDB and buggy compilers. */
5327 retval
= obsavestring (retval
, strlen (retval
),
5328 &cu
->objfile
->objfile_obstack
);
5330 do_cleanups (back_to
);
5334 /* Read the import statement specified by the given die and record it. */
5337 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5339 struct attribute
*import_attr
;
5340 struct die_info
*imported_die
, *child_die
;
5341 struct dwarf2_cu
*imported_cu
;
5342 const char *imported_name
;
5343 const char *imported_name_prefix
;
5344 const char *canonical_name
;
5345 const char *import_alias
;
5346 const char *imported_declaration
= NULL
;
5347 const char *import_prefix
;
5348 VEC (const_char_ptr
) *excludes
= NULL
;
5349 struct cleanup
*cleanups
;
5353 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5354 if (import_attr
== NULL
)
5356 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5357 dwarf_tag_name (die
->tag
));
5362 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5363 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5364 if (imported_name
== NULL
)
5366 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5368 The import in the following code:
5382 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5383 <52> DW_AT_decl_file : 1
5384 <53> DW_AT_decl_line : 6
5385 <54> DW_AT_import : <0x75>
5386 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5388 <5b> DW_AT_decl_file : 1
5389 <5c> DW_AT_decl_line : 2
5390 <5d> DW_AT_type : <0x6e>
5392 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5393 <76> DW_AT_byte_size : 4
5394 <77> DW_AT_encoding : 5 (signed)
5396 imports the wrong die ( 0x75 instead of 0x58 ).
5397 This case will be ignored until the gcc bug is fixed. */
5401 /* Figure out the local name after import. */
5402 import_alias
= dwarf2_name (die
, cu
);
5404 /* Figure out where the statement is being imported to. */
5405 import_prefix
= determine_prefix (die
, cu
);
5407 /* Figure out what the scope of the imported die is and prepend it
5408 to the name of the imported die. */
5409 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5411 if (imported_die
->tag
!= DW_TAG_namespace
5412 && imported_die
->tag
!= DW_TAG_module
)
5414 imported_declaration
= imported_name
;
5415 canonical_name
= imported_name_prefix
;
5417 else if (strlen (imported_name_prefix
) > 0)
5419 temp
= alloca (strlen (imported_name_prefix
)
5420 + 2 + strlen (imported_name
) + 1);
5421 strcpy (temp
, imported_name_prefix
);
5422 strcat (temp
, "::");
5423 strcat (temp
, imported_name
);
5424 canonical_name
= temp
;
5427 canonical_name
= imported_name
;
5429 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5431 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5432 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5433 child_die
= sibling_die (child_die
))
5435 /* DWARF-4: A Fortran use statement with a “rename list” may be
5436 represented by an imported module entry with an import attribute
5437 referring to the module and owned entries corresponding to those
5438 entities that are renamed as part of being imported. */
5440 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5442 complaint (&symfile_complaints
,
5443 _("child DW_TAG_imported_declaration expected "
5444 "- DIE at 0x%x [in module %s]"),
5445 child_die
->offset
, cu
->objfile
->name
);
5449 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5450 if (import_attr
== NULL
)
5452 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5453 dwarf_tag_name (child_die
->tag
));
5458 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5460 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5461 if (imported_name
== NULL
)
5463 complaint (&symfile_complaints
,
5464 _("child DW_TAG_imported_declaration has unknown "
5465 "imported name - DIE at 0x%x [in module %s]"),
5466 child_die
->offset
, cu
->objfile
->name
);
5470 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5472 process_die (child_die
, cu
);
5475 cp_add_using_directive (import_prefix
,
5478 imported_declaration
,
5480 &cu
->objfile
->objfile_obstack
);
5482 do_cleanups (cleanups
);
5486 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5488 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5491 /* Cleanup function for read_file_scope. */
5494 free_cu_line_header (void *arg
)
5496 struct dwarf2_cu
*cu
= arg
;
5498 free_line_header (cu
->line_header
);
5499 cu
->line_header
= NULL
;
5503 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5504 char **name
, char **comp_dir
)
5506 struct attribute
*attr
;
5511 /* Find the filename. Do not use dwarf2_name here, since the filename
5512 is not a source language identifier. */
5513 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5516 *name
= DW_STRING (attr
);
5519 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5521 *comp_dir
= DW_STRING (attr
);
5522 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5524 *comp_dir
= ldirname (*name
);
5525 if (*comp_dir
!= NULL
)
5526 make_cleanup (xfree
, *comp_dir
);
5528 if (*comp_dir
!= NULL
)
5530 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5531 directory, get rid of it. */
5532 char *cp
= strchr (*comp_dir
, ':');
5534 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5539 *name
= "<unknown>";
5542 /* Handle DW_AT_stmt_list for a compilation unit. */
5545 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5546 const char *comp_dir
)
5548 struct attribute
*attr
;
5549 struct objfile
*objfile
= cu
->objfile
;
5550 bfd
*abfd
= objfile
->obfd
;
5552 /* Decode line number information if present. We do this before
5553 processing child DIEs, so that the line header table is available
5554 for DW_AT_decl_file. */
5555 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5558 unsigned int line_offset
= DW_UNSND (attr
);
5559 struct line_header
*line_header
5560 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5564 cu
->line_header
= line_header
;
5565 make_cleanup (free_cu_line_header
, cu
);
5566 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5571 /* Process DW_TAG_compile_unit. */
5574 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5576 struct objfile
*objfile
= cu
->objfile
;
5577 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5578 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5579 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5580 struct attribute
*attr
;
5582 char *comp_dir
= NULL
;
5583 struct die_info
*child_die
;
5584 bfd
*abfd
= objfile
->obfd
;
5587 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5589 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5591 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5592 from finish_block. */
5593 if (lowpc
== ((CORE_ADDR
) -1))
5598 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5600 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5603 set_cu_language (DW_UNSND (attr
), cu
);
5606 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5608 cu
->producer
= DW_STRING (attr
);
5610 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5611 standardised yet. As a workaround for the language detection we fall
5612 back to the DW_AT_producer string. */
5613 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5614 cu
->language
= language_opencl
;
5616 /* We assume that we're processing GCC output. */
5617 processing_gcc_compilation
= 2;
5619 processing_has_namespace_info
= 0;
5621 start_symtab (name
, comp_dir
, lowpc
);
5622 record_debugformat ("DWARF 2");
5623 record_producer (cu
->producer
);
5625 initialize_cu_func_list (cu
);
5627 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5629 /* Process all dies in compilation unit. */
5630 if (die
->child
!= NULL
)
5632 child_die
= die
->child
;
5633 while (child_die
&& child_die
->tag
)
5635 process_die (child_die
, cu
);
5636 child_die
= sibling_die (child_die
);
5640 /* Decode macro information, if present. Dwarf 2 macro information
5641 refers to information in the line number info statement program
5642 header, so we can only read it if we've read the header
5644 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5645 if (attr
&& cu
->line_header
)
5647 unsigned int macro_offset
= DW_UNSND (attr
);
5649 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5650 comp_dir
, abfd
, cu
);
5652 do_cleanups (back_to
);
5655 /* Process DW_TAG_type_unit.
5656 For TUs we want to skip the first top level sibling if it's not the
5657 actual type being defined by this TU. In this case the first top
5658 level sibling is there to provide context only. */
5661 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5663 struct objfile
*objfile
= cu
->objfile
;
5664 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5666 struct attribute
*attr
;
5668 char *comp_dir
= NULL
;
5669 struct die_info
*child_die
;
5670 bfd
*abfd
= objfile
->obfd
;
5672 /* start_symtab needs a low pc, but we don't really have one.
5673 Do what read_file_scope would do in the absence of such info. */
5674 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5676 /* Find the filename. Do not use dwarf2_name here, since the filename
5677 is not a source language identifier. */
5678 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5680 name
= DW_STRING (attr
);
5682 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5684 comp_dir
= DW_STRING (attr
);
5685 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5687 comp_dir
= ldirname (name
);
5688 if (comp_dir
!= NULL
)
5689 make_cleanup (xfree
, comp_dir
);
5695 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5697 set_cu_language (DW_UNSND (attr
), cu
);
5699 /* This isn't technically needed today. It is done for symmetry
5700 with read_file_scope. */
5701 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5703 cu
->producer
= DW_STRING (attr
);
5705 /* We assume that we're processing GCC output. */
5706 processing_gcc_compilation
= 2;
5708 processing_has_namespace_info
= 0;
5710 start_symtab (name
, comp_dir
, lowpc
);
5711 record_debugformat ("DWARF 2");
5712 record_producer (cu
->producer
);
5714 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5716 /* Process the dies in the type unit. */
5717 if (die
->child
== NULL
)
5719 dump_die_for_error (die
);
5720 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5721 bfd_get_filename (abfd
));
5724 child_die
= die
->child
;
5726 while (child_die
&& child_die
->tag
)
5728 process_die (child_die
, cu
);
5730 child_die
= sibling_die (child_die
);
5733 do_cleanups (back_to
);
5737 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5738 struct dwarf2_cu
*cu
)
5740 struct function_range
*thisfn
;
5742 thisfn
= (struct function_range
*)
5743 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5744 thisfn
->name
= name
;
5745 thisfn
->lowpc
= lowpc
;
5746 thisfn
->highpc
= highpc
;
5747 thisfn
->seen_line
= 0;
5748 thisfn
->next
= NULL
;
5750 if (cu
->last_fn
== NULL
)
5751 cu
->first_fn
= thisfn
;
5753 cu
->last_fn
->next
= thisfn
;
5755 cu
->last_fn
= thisfn
;
5758 /* qsort helper for inherit_abstract_dies. */
5761 unsigned_int_compar (const void *ap
, const void *bp
)
5763 unsigned int a
= *(unsigned int *) ap
;
5764 unsigned int b
= *(unsigned int *) bp
;
5766 return (a
> b
) - (b
> a
);
5769 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5770 Inherit only the children of the DW_AT_abstract_origin DIE not being
5771 already referenced by DW_AT_abstract_origin from the children of the
5775 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5777 struct die_info
*child_die
;
5778 unsigned die_children_count
;
5779 /* CU offsets which were referenced by children of the current DIE. */
5781 unsigned *offsets_end
, *offsetp
;
5782 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5783 struct die_info
*origin_die
;
5784 /* Iterator of the ORIGIN_DIE children. */
5785 struct die_info
*origin_child_die
;
5786 struct cleanup
*cleanups
;
5787 struct attribute
*attr
;
5788 struct dwarf2_cu
*origin_cu
;
5789 struct pending
**origin_previous_list_in_scope
;
5791 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5795 /* Note that following die references may follow to a die in a
5799 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5801 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5803 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5804 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5806 if (die
->tag
!= origin_die
->tag
5807 && !(die
->tag
== DW_TAG_inlined_subroutine
5808 && origin_die
->tag
== DW_TAG_subprogram
))
5809 complaint (&symfile_complaints
,
5810 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5811 die
->offset
, origin_die
->offset
);
5813 child_die
= die
->child
;
5814 die_children_count
= 0;
5815 while (child_die
&& child_die
->tag
)
5817 child_die
= sibling_die (child_die
);
5818 die_children_count
++;
5820 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5821 cleanups
= make_cleanup (xfree
, offsets
);
5823 offsets_end
= offsets
;
5824 child_die
= die
->child
;
5825 while (child_die
&& child_die
->tag
)
5827 /* For each CHILD_DIE, find the corresponding child of
5828 ORIGIN_DIE. If there is more than one layer of
5829 DW_AT_abstract_origin, follow them all; there shouldn't be,
5830 but GCC versions at least through 4.4 generate this (GCC PR
5832 struct die_info
*child_origin_die
= child_die
;
5833 struct dwarf2_cu
*child_origin_cu
= cu
;
5837 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5841 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5845 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5846 counterpart may exist. */
5847 if (child_origin_die
!= child_die
)
5849 if (child_die
->tag
!= child_origin_die
->tag
5850 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5851 && child_origin_die
->tag
== DW_TAG_subprogram
))
5852 complaint (&symfile_complaints
,
5853 _("Child DIE 0x%x and its abstract origin 0x%x have "
5854 "different tags"), child_die
->offset
,
5855 child_origin_die
->offset
);
5856 if (child_origin_die
->parent
!= origin_die
)
5857 complaint (&symfile_complaints
,
5858 _("Child DIE 0x%x and its abstract origin 0x%x have "
5859 "different parents"), child_die
->offset
,
5860 child_origin_die
->offset
);
5862 *offsets_end
++ = child_origin_die
->offset
;
5864 child_die
= sibling_die (child_die
);
5866 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5867 unsigned_int_compar
);
5868 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5869 if (offsetp
[-1] == *offsetp
)
5870 complaint (&symfile_complaints
,
5871 _("Multiple children of DIE 0x%x refer "
5872 "to DIE 0x%x as their abstract origin"),
5873 die
->offset
, *offsetp
);
5876 origin_child_die
= origin_die
->child
;
5877 while (origin_child_die
&& origin_child_die
->tag
)
5879 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5880 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5882 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5884 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5885 process_die (origin_child_die
, origin_cu
);
5887 origin_child_die
= sibling_die (origin_child_die
);
5889 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5891 do_cleanups (cleanups
);
5895 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5897 struct objfile
*objfile
= cu
->objfile
;
5898 struct context_stack
*new;
5901 struct die_info
*child_die
;
5902 struct attribute
*attr
, *call_line
, *call_file
;
5905 struct block
*block
;
5906 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5907 VEC (symbolp
) *template_args
= NULL
;
5908 struct template_symbol
*templ_func
= NULL
;
5912 /* If we do not have call site information, we can't show the
5913 caller of this inlined function. That's too confusing, so
5914 only use the scope for local variables. */
5915 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5916 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5917 if (call_line
== NULL
|| call_file
== NULL
)
5919 read_lexical_block_scope (die
, cu
);
5924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5926 name
= dwarf2_name (die
, cu
);
5928 /* Ignore functions with missing or empty names. These are actually
5929 illegal according to the DWARF standard. */
5932 complaint (&symfile_complaints
,
5933 _("missing name for subprogram DIE at %d"), die
->offset
);
5937 /* Ignore functions with missing or invalid low and high pc attributes. */
5938 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5940 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5941 if (!attr
|| !DW_UNSND (attr
))
5942 complaint (&symfile_complaints
,
5943 _("cannot get low and high bounds "
5944 "for subprogram DIE at %d"),
5952 /* Record the function range for dwarf_decode_lines. */
5953 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5955 /* If we have any template arguments, then we must allocate a
5956 different sort of symbol. */
5957 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5959 if (child_die
->tag
== DW_TAG_template_type_param
5960 || child_die
->tag
== DW_TAG_template_value_param
)
5962 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5963 struct template_symbol
);
5964 templ_func
->base
.is_cplus_template_function
= 1;
5969 new = push_context (0, lowpc
);
5970 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5971 (struct symbol
*) templ_func
);
5973 /* If there is a location expression for DW_AT_frame_base, record
5975 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5977 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5978 expression is being recorded directly in the function's symbol
5979 and not in a separate frame-base object. I guess this hack is
5980 to avoid adding some sort of frame-base adjunct/annex to the
5981 function's symbol :-(. The problem with doing this is that it
5982 results in a function symbol with a location expression that
5983 has nothing to do with the location of the function, ouch! The
5984 relationship should be: a function's symbol has-a frame base; a
5985 frame-base has-a location expression. */
5986 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5988 cu
->list_in_scope
= &local_symbols
;
5990 if (die
->child
!= NULL
)
5992 child_die
= die
->child
;
5993 while (child_die
&& child_die
->tag
)
5995 if (child_die
->tag
== DW_TAG_template_type_param
5996 || child_die
->tag
== DW_TAG_template_value_param
)
5998 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6001 VEC_safe_push (symbolp
, template_args
, arg
);
6004 process_die (child_die
, cu
);
6005 child_die
= sibling_die (child_die
);
6009 inherit_abstract_dies (die
, cu
);
6011 /* If we have a DW_AT_specification, we might need to import using
6012 directives from the context of the specification DIE. See the
6013 comment in determine_prefix. */
6014 if (cu
->language
== language_cplus
6015 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6017 struct dwarf2_cu
*spec_cu
= cu
;
6018 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6022 child_die
= spec_die
->child
;
6023 while (child_die
&& child_die
->tag
)
6025 if (child_die
->tag
== DW_TAG_imported_module
)
6026 process_die (child_die
, spec_cu
);
6027 child_die
= sibling_die (child_die
);
6030 /* In some cases, GCC generates specification DIEs that
6031 themselves contain DW_AT_specification attributes. */
6032 spec_die
= die_specification (spec_die
, &spec_cu
);
6036 new = pop_context ();
6037 /* Make a block for the local symbols within. */
6038 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6039 lowpc
, highpc
, objfile
);
6041 /* For C++, set the block's scope. */
6042 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6043 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6044 determine_prefix (die
, cu
),
6045 processing_has_namespace_info
);
6047 /* If we have address ranges, record them. */
6048 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6050 /* Attach template arguments to function. */
6051 if (! VEC_empty (symbolp
, template_args
))
6053 gdb_assert (templ_func
!= NULL
);
6055 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6056 templ_func
->template_arguments
6057 = obstack_alloc (&objfile
->objfile_obstack
,
6058 (templ_func
->n_template_arguments
6059 * sizeof (struct symbol
*)));
6060 memcpy (templ_func
->template_arguments
,
6061 VEC_address (symbolp
, template_args
),
6062 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6063 VEC_free (symbolp
, template_args
);
6066 /* In C++, we can have functions nested inside functions (e.g., when
6067 a function declares a class that has methods). This means that
6068 when we finish processing a function scope, we may need to go
6069 back to building a containing block's symbol lists. */
6070 local_symbols
= new->locals
;
6071 param_symbols
= new->params
;
6072 using_directives
= new->using_directives
;
6074 /* If we've finished processing a top-level function, subsequent
6075 symbols go in the file symbol list. */
6076 if (outermost_context_p ())
6077 cu
->list_in_scope
= &file_symbols
;
6080 /* Process all the DIES contained within a lexical block scope. Start
6081 a new scope, process the dies, and then close the scope. */
6084 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6086 struct objfile
*objfile
= cu
->objfile
;
6087 struct context_stack
*new;
6088 CORE_ADDR lowpc
, highpc
;
6089 struct die_info
*child_die
;
6092 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6094 /* Ignore blocks with missing or invalid low and high pc attributes. */
6095 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6096 as multiple lexical blocks? Handling children in a sane way would
6097 be nasty. Might be easier to properly extend generic blocks to
6099 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6104 push_context (0, lowpc
);
6105 if (die
->child
!= NULL
)
6107 child_die
= die
->child
;
6108 while (child_die
&& child_die
->tag
)
6110 process_die (child_die
, cu
);
6111 child_die
= sibling_die (child_die
);
6114 new = pop_context ();
6116 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6119 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6122 /* Note that recording ranges after traversing children, as we
6123 do here, means that recording a parent's ranges entails
6124 walking across all its children's ranges as they appear in
6125 the address map, which is quadratic behavior.
6127 It would be nicer to record the parent's ranges before
6128 traversing its children, simply overriding whatever you find
6129 there. But since we don't even decide whether to create a
6130 block until after we've traversed its children, that's hard
6132 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6134 local_symbols
= new->locals
;
6135 using_directives
= new->using_directives
;
6138 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6139 Return 1 if the attributes are present and valid, otherwise, return 0.
6140 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6143 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6144 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6145 struct partial_symtab
*ranges_pst
)
6147 struct objfile
*objfile
= cu
->objfile
;
6148 struct comp_unit_head
*cu_header
= &cu
->header
;
6149 bfd
*obfd
= objfile
->obfd
;
6150 unsigned int addr_size
= cu_header
->addr_size
;
6151 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6152 /* Base address selection entry. */
6163 found_base
= cu
->base_known
;
6164 base
= cu
->base_address
;
6166 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6167 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6169 complaint (&symfile_complaints
,
6170 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6174 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6176 /* Read in the largest possible address. */
6177 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6178 if ((marker
& mask
) == mask
)
6180 /* If we found the largest possible address, then
6181 read the base address. */
6182 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6183 buffer
+= 2 * addr_size
;
6184 offset
+= 2 * addr_size
;
6190 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6194 CORE_ADDR range_beginning
, range_end
;
6196 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6197 buffer
+= addr_size
;
6198 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6199 buffer
+= addr_size
;
6200 offset
+= 2 * addr_size
;
6202 /* An end of list marker is a pair of zero addresses. */
6203 if (range_beginning
== 0 && range_end
== 0)
6204 /* Found the end of list entry. */
6207 /* Each base address selection entry is a pair of 2 values.
6208 The first is the largest possible address, the second is
6209 the base address. Check for a base address here. */
6210 if ((range_beginning
& mask
) == mask
)
6212 /* If we found the largest possible address, then
6213 read the base address. */
6214 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6221 /* We have no valid base address for the ranges
6223 complaint (&symfile_complaints
,
6224 _("Invalid .debug_ranges data (no base address)"));
6228 if (range_beginning
> range_end
)
6230 /* Inverted range entries are invalid. */
6231 complaint (&symfile_complaints
,
6232 _("Invalid .debug_ranges data (inverted range)"));
6236 /* Empty range entries have no effect. */
6237 if (range_beginning
== range_end
)
6240 range_beginning
+= base
;
6243 if (ranges_pst
!= NULL
)
6244 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6245 range_beginning
+ baseaddr
,
6246 range_end
- 1 + baseaddr
,
6249 /* FIXME: This is recording everything as a low-high
6250 segment of consecutive addresses. We should have a
6251 data structure for discontiguous block ranges
6255 low
= range_beginning
;
6261 if (range_beginning
< low
)
6262 low
= range_beginning
;
6263 if (range_end
> high
)
6269 /* If the first entry is an end-of-list marker, the range
6270 describes an empty scope, i.e. no instructions. */
6276 *high_return
= high
;
6280 /* Get low and high pc attributes from a die. Return 1 if the attributes
6281 are present and valid, otherwise, return 0. Return -1 if the range is
6282 discontinuous, i.e. derived from DW_AT_ranges information. */
6284 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6285 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6286 struct partial_symtab
*pst
)
6288 struct attribute
*attr
;
6293 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6296 high
= DW_ADDR (attr
);
6297 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6299 low
= DW_ADDR (attr
);
6301 /* Found high w/o low attribute. */
6304 /* Found consecutive range of addresses. */
6309 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6312 /* Value of the DW_AT_ranges attribute is the offset in the
6313 .debug_ranges section. */
6314 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6316 /* Found discontinuous range of addresses. */
6321 /* read_partial_die has also the strict LOW < HIGH requirement. */
6325 /* When using the GNU linker, .gnu.linkonce. sections are used to
6326 eliminate duplicate copies of functions and vtables and such.
6327 The linker will arbitrarily choose one and discard the others.
6328 The AT_*_pc values for such functions refer to local labels in
6329 these sections. If the section from that file was discarded, the
6330 labels are not in the output, so the relocs get a value of 0.
6331 If this is a discarded function, mark the pc bounds as invalid,
6332 so that GDB will ignore it. */
6333 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6341 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6342 its low and high PC addresses. Do nothing if these addresses could not
6343 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6344 and HIGHPC to the high address if greater than HIGHPC. */
6347 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6348 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6349 struct dwarf2_cu
*cu
)
6351 CORE_ADDR low
, high
;
6352 struct die_info
*child
= die
->child
;
6354 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6356 *lowpc
= min (*lowpc
, low
);
6357 *highpc
= max (*highpc
, high
);
6360 /* If the language does not allow nested subprograms (either inside
6361 subprograms or lexical blocks), we're done. */
6362 if (cu
->language
!= language_ada
)
6365 /* Check all the children of the given DIE. If it contains nested
6366 subprograms, then check their pc bounds. Likewise, we need to
6367 check lexical blocks as well, as they may also contain subprogram
6369 while (child
&& child
->tag
)
6371 if (child
->tag
== DW_TAG_subprogram
6372 || child
->tag
== DW_TAG_lexical_block
)
6373 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6374 child
= sibling_die (child
);
6378 /* Get the low and high pc's represented by the scope DIE, and store
6379 them in *LOWPC and *HIGHPC. If the correct values can't be
6380 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6383 get_scope_pc_bounds (struct die_info
*die
,
6384 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6385 struct dwarf2_cu
*cu
)
6387 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6388 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6389 CORE_ADDR current_low
, current_high
;
6391 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6393 best_low
= current_low
;
6394 best_high
= current_high
;
6398 struct die_info
*child
= die
->child
;
6400 while (child
&& child
->tag
)
6402 switch (child
->tag
) {
6403 case DW_TAG_subprogram
:
6404 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6406 case DW_TAG_namespace
:
6408 /* FIXME: carlton/2004-01-16: Should we do this for
6409 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6410 that current GCC's always emit the DIEs corresponding
6411 to definitions of methods of classes as children of a
6412 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6413 the DIEs giving the declarations, which could be
6414 anywhere). But I don't see any reason why the
6415 standards says that they have to be there. */
6416 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6418 if (current_low
!= ((CORE_ADDR
) -1))
6420 best_low
= min (best_low
, current_low
);
6421 best_high
= max (best_high
, current_high
);
6429 child
= sibling_die (child
);
6434 *highpc
= best_high
;
6437 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6440 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6441 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6443 struct attribute
*attr
;
6445 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6448 CORE_ADDR high
= DW_ADDR (attr
);
6450 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6453 CORE_ADDR low
= DW_ADDR (attr
);
6455 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6459 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6462 bfd
*obfd
= cu
->objfile
->obfd
;
6464 /* The value of the DW_AT_ranges attribute is the offset of the
6465 address range list in the .debug_ranges section. */
6466 unsigned long offset
= DW_UNSND (attr
);
6467 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6469 /* For some target architectures, but not others, the
6470 read_address function sign-extends the addresses it returns.
6471 To recognize base address selection entries, we need a
6473 unsigned int addr_size
= cu
->header
.addr_size
;
6474 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6476 /* The base address, to which the next pair is relative. Note
6477 that this 'base' is a DWARF concept: most entries in a range
6478 list are relative, to reduce the number of relocs against the
6479 debugging information. This is separate from this function's
6480 'baseaddr' argument, which GDB uses to relocate debugging
6481 information from a shared library based on the address at
6482 which the library was loaded. */
6483 CORE_ADDR base
= cu
->base_address
;
6484 int base_known
= cu
->base_known
;
6486 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6487 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6489 complaint (&symfile_complaints
,
6490 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6497 unsigned int bytes_read
;
6498 CORE_ADDR start
, end
;
6500 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6501 buffer
+= bytes_read
;
6502 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6503 buffer
+= bytes_read
;
6505 /* Did we find the end of the range list? */
6506 if (start
== 0 && end
== 0)
6509 /* Did we find a base address selection entry? */
6510 else if ((start
& base_select_mask
) == base_select_mask
)
6516 /* We found an ordinary address range. */
6521 complaint (&symfile_complaints
,
6522 _("Invalid .debug_ranges data "
6523 "(no base address)"));
6529 /* Inverted range entries are invalid. */
6530 complaint (&symfile_complaints
,
6531 _("Invalid .debug_ranges data "
6532 "(inverted range)"));
6536 /* Empty range entries have no effect. */
6540 record_block_range (block
,
6541 baseaddr
+ base
+ start
,
6542 baseaddr
+ base
+ end
- 1);
6548 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6549 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6550 during 4.6.0 experimental. */
6553 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6556 int major
, minor
, release
;
6558 if (cu
->producer
== NULL
)
6560 /* For unknown compilers expect their behavior is DWARF version
6563 GCC started to support .debug_types sections by -gdwarf-4 since
6564 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6565 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6566 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6567 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6572 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6574 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6576 /* For non-GCC compilers expect their behavior is DWARF version
6581 cs
= &cu
->producer
[strlen ("GNU ")];
6582 while (*cs
&& !isdigit (*cs
))
6584 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6586 /* Not recognized as GCC. */
6591 return major
< 4 || (major
== 4 && minor
< 6);
6594 /* Return the default accessibility type if it is not overriden by
6595 DW_AT_accessibility. */
6597 static enum dwarf_access_attribute
6598 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6600 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6602 /* The default DWARF 2 accessibility for members is public, the default
6603 accessibility for inheritance is private. */
6605 if (die
->tag
!= DW_TAG_inheritance
)
6606 return DW_ACCESS_public
;
6608 return DW_ACCESS_private
;
6612 /* DWARF 3+ defines the default accessibility a different way. The same
6613 rules apply now for DW_TAG_inheritance as for the members and it only
6614 depends on the container kind. */
6616 if (die
->parent
->tag
== DW_TAG_class_type
)
6617 return DW_ACCESS_private
;
6619 return DW_ACCESS_public
;
6623 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6624 offset. If the attribute was not found return 0, otherwise return
6625 1. If it was found but could not properly be handled, set *OFFSET
6629 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6632 struct attribute
*attr
;
6634 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6639 /* Note that we do not check for a section offset first here.
6640 This is because DW_AT_data_member_location is new in DWARF 4,
6641 so if we see it, we can assume that a constant form is really
6642 a constant and not a section offset. */
6643 if (attr_form_is_constant (attr
))
6644 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6645 else if (attr_form_is_section_offset (attr
))
6646 dwarf2_complex_location_expr_complaint ();
6647 else if (attr_form_is_block (attr
))
6648 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6650 dwarf2_complex_location_expr_complaint ();
6658 /* Add an aggregate field to the field list. */
6661 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6662 struct dwarf2_cu
*cu
)
6664 struct objfile
*objfile
= cu
->objfile
;
6665 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6666 struct nextfield
*new_field
;
6667 struct attribute
*attr
;
6669 char *fieldname
= "";
6671 /* Allocate a new field list entry and link it in. */
6672 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6673 make_cleanup (xfree
, new_field
);
6674 memset (new_field
, 0, sizeof (struct nextfield
));
6676 if (die
->tag
== DW_TAG_inheritance
)
6678 new_field
->next
= fip
->baseclasses
;
6679 fip
->baseclasses
= new_field
;
6683 new_field
->next
= fip
->fields
;
6684 fip
->fields
= new_field
;
6688 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6690 new_field
->accessibility
= DW_UNSND (attr
);
6692 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6693 if (new_field
->accessibility
!= DW_ACCESS_public
)
6694 fip
->non_public_fields
= 1;
6696 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6698 new_field
->virtuality
= DW_UNSND (attr
);
6700 new_field
->virtuality
= DW_VIRTUALITY_none
;
6702 fp
= &new_field
->field
;
6704 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6708 /* Data member other than a C++ static data member. */
6710 /* Get type of field. */
6711 fp
->type
= die_type (die
, cu
);
6713 SET_FIELD_BITPOS (*fp
, 0);
6715 /* Get bit size of field (zero if none). */
6716 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6719 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6723 FIELD_BITSIZE (*fp
) = 0;
6726 /* Get bit offset of field. */
6727 if (handle_data_member_location (die
, cu
, &offset
))
6728 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6729 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6732 if (gdbarch_bits_big_endian (gdbarch
))
6734 /* For big endian bits, the DW_AT_bit_offset gives the
6735 additional bit offset from the MSB of the containing
6736 anonymous object to the MSB of the field. We don't
6737 have to do anything special since we don't need to
6738 know the size of the anonymous object. */
6739 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6743 /* For little endian bits, compute the bit offset to the
6744 MSB of the anonymous object, subtract off the number of
6745 bits from the MSB of the field to the MSB of the
6746 object, and then subtract off the number of bits of
6747 the field itself. The result is the bit offset of
6748 the LSB of the field. */
6750 int bit_offset
= DW_UNSND (attr
);
6752 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6755 /* The size of the anonymous object containing
6756 the bit field is explicit, so use the
6757 indicated size (in bytes). */
6758 anonymous_size
= DW_UNSND (attr
);
6762 /* The size of the anonymous object containing
6763 the bit field must be inferred from the type
6764 attribute of the data member containing the
6766 anonymous_size
= TYPE_LENGTH (fp
->type
);
6768 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6769 - bit_offset
- FIELD_BITSIZE (*fp
);
6773 /* Get name of field. */
6774 fieldname
= dwarf2_name (die
, cu
);
6775 if (fieldname
== NULL
)
6778 /* The name is already allocated along with this objfile, so we don't
6779 need to duplicate it for the type. */
6780 fp
->name
= fieldname
;
6782 /* Change accessibility for artificial fields (e.g. virtual table
6783 pointer or virtual base class pointer) to private. */
6784 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6786 FIELD_ARTIFICIAL (*fp
) = 1;
6787 new_field
->accessibility
= DW_ACCESS_private
;
6788 fip
->non_public_fields
= 1;
6791 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6793 /* C++ static member. */
6795 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6796 is a declaration, but all versions of G++ as of this writing
6797 (so through at least 3.2.1) incorrectly generate
6798 DW_TAG_variable tags. */
6800 const char *physname
;
6802 /* Get name of field. */
6803 fieldname
= dwarf2_name (die
, cu
);
6804 if (fieldname
== NULL
)
6807 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6809 /* Only create a symbol if this is an external value.
6810 new_symbol checks this and puts the value in the global symbol
6811 table, which we want. If it is not external, new_symbol
6812 will try to put the value in cu->list_in_scope which is wrong. */
6813 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6815 /* A static const member, not much different than an enum as far as
6816 we're concerned, except that we can support more types. */
6817 new_symbol (die
, NULL
, cu
);
6820 /* Get physical name. */
6821 physname
= dwarf2_physname (fieldname
, die
, cu
);
6823 /* The name is already allocated along with this objfile, so we don't
6824 need to duplicate it for the type. */
6825 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6826 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6827 FIELD_NAME (*fp
) = fieldname
;
6829 else if (die
->tag
== DW_TAG_inheritance
)
6833 /* C++ base class field. */
6834 if (handle_data_member_location (die
, cu
, &offset
))
6835 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6836 FIELD_BITSIZE (*fp
) = 0;
6837 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6838 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6839 fip
->nbaseclasses
++;
6843 /* Add a typedef defined in the scope of the FIP's class. */
6846 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6847 struct dwarf2_cu
*cu
)
6849 struct objfile
*objfile
= cu
->objfile
;
6850 struct typedef_field_list
*new_field
;
6851 struct attribute
*attr
;
6852 struct typedef_field
*fp
;
6853 char *fieldname
= "";
6855 /* Allocate a new field list entry and link it in. */
6856 new_field
= xzalloc (sizeof (*new_field
));
6857 make_cleanup (xfree
, new_field
);
6859 gdb_assert (die
->tag
== DW_TAG_typedef
);
6861 fp
= &new_field
->field
;
6863 /* Get name of field. */
6864 fp
->name
= dwarf2_name (die
, cu
);
6865 if (fp
->name
== NULL
)
6868 fp
->type
= read_type_die (die
, cu
);
6870 new_field
->next
= fip
->typedef_field_list
;
6871 fip
->typedef_field_list
= new_field
;
6872 fip
->typedef_field_list_count
++;
6875 /* Create the vector of fields, and attach it to the type. */
6878 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6879 struct dwarf2_cu
*cu
)
6881 int nfields
= fip
->nfields
;
6883 /* Record the field count, allocate space for the array of fields,
6884 and create blank accessibility bitfields if necessary. */
6885 TYPE_NFIELDS (type
) = nfields
;
6886 TYPE_FIELDS (type
) = (struct field
*)
6887 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6888 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6890 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6892 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6894 TYPE_FIELD_PRIVATE_BITS (type
) =
6895 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6896 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6898 TYPE_FIELD_PROTECTED_BITS (type
) =
6899 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6900 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6902 TYPE_FIELD_IGNORE_BITS (type
) =
6903 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6904 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6907 /* If the type has baseclasses, allocate and clear a bit vector for
6908 TYPE_FIELD_VIRTUAL_BITS. */
6909 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6911 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6912 unsigned char *pointer
;
6914 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6915 pointer
= TYPE_ALLOC (type
, num_bytes
);
6916 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6917 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6918 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6921 /* Copy the saved-up fields into the field vector. Start from the head of
6922 the list, adding to the tail of the field array, so that they end up in
6923 the same order in the array in which they were added to the list. */
6924 while (nfields
-- > 0)
6926 struct nextfield
*fieldp
;
6930 fieldp
= fip
->fields
;
6931 fip
->fields
= fieldp
->next
;
6935 fieldp
= fip
->baseclasses
;
6936 fip
->baseclasses
= fieldp
->next
;
6939 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6940 switch (fieldp
->accessibility
)
6942 case DW_ACCESS_private
:
6943 if (cu
->language
!= language_ada
)
6944 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6947 case DW_ACCESS_protected
:
6948 if (cu
->language
!= language_ada
)
6949 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6952 case DW_ACCESS_public
:
6956 /* Unknown accessibility. Complain and treat it as public. */
6958 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6959 fieldp
->accessibility
);
6963 if (nfields
< fip
->nbaseclasses
)
6965 switch (fieldp
->virtuality
)
6967 case DW_VIRTUALITY_virtual
:
6968 case DW_VIRTUALITY_pure_virtual
:
6969 if (cu
->language
== language_ada
)
6970 error (_("unexpected virtuality in component of Ada type"));
6971 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6978 /* Add a member function to the proper fieldlist. */
6981 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6982 struct type
*type
, struct dwarf2_cu
*cu
)
6984 struct objfile
*objfile
= cu
->objfile
;
6985 struct attribute
*attr
;
6986 struct fnfieldlist
*flp
;
6988 struct fn_field
*fnp
;
6990 struct nextfnfield
*new_fnfield
;
6991 struct type
*this_type
;
6992 enum dwarf_access_attribute accessibility
;
6994 if (cu
->language
== language_ada
)
6995 error (_("unexpected member function in Ada type"));
6997 /* Get name of member function. */
6998 fieldname
= dwarf2_name (die
, cu
);
6999 if (fieldname
== NULL
)
7002 /* Look up member function name in fieldlist. */
7003 for (i
= 0; i
< fip
->nfnfields
; i
++)
7005 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7009 /* Create new list element if necessary. */
7010 if (i
< fip
->nfnfields
)
7011 flp
= &fip
->fnfieldlists
[i
];
7014 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7016 fip
->fnfieldlists
= (struct fnfieldlist
*)
7017 xrealloc (fip
->fnfieldlists
,
7018 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7019 * sizeof (struct fnfieldlist
));
7020 if (fip
->nfnfields
== 0)
7021 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7023 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7024 flp
->name
= fieldname
;
7027 i
= fip
->nfnfields
++;
7030 /* Create a new member function field and chain it to the field list
7032 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7033 make_cleanup (xfree
, new_fnfield
);
7034 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7035 new_fnfield
->next
= flp
->head
;
7036 flp
->head
= new_fnfield
;
7039 /* Fill in the member function field info. */
7040 fnp
= &new_fnfield
->fnfield
;
7042 /* Delay processing of the physname until later. */
7043 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7045 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7050 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7051 fnp
->physname
= physname
? physname
: "";
7054 fnp
->type
= alloc_type (objfile
);
7055 this_type
= read_type_die (die
, cu
);
7056 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7058 int nparams
= TYPE_NFIELDS (this_type
);
7060 /* TYPE is the domain of this method, and THIS_TYPE is the type
7061 of the method itself (TYPE_CODE_METHOD). */
7062 smash_to_method_type (fnp
->type
, type
,
7063 TYPE_TARGET_TYPE (this_type
),
7064 TYPE_FIELDS (this_type
),
7065 TYPE_NFIELDS (this_type
),
7066 TYPE_VARARGS (this_type
));
7068 /* Handle static member functions.
7069 Dwarf2 has no clean way to discern C++ static and non-static
7070 member functions. G++ helps GDB by marking the first
7071 parameter for non-static member functions (which is the this
7072 pointer) as artificial. We obtain this information from
7073 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7074 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7075 fnp
->voffset
= VOFFSET_STATIC
;
7078 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7079 dwarf2_full_name (fieldname
, die
, cu
));
7081 /* Get fcontext from DW_AT_containing_type if present. */
7082 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7083 fnp
->fcontext
= die_containing_type (die
, cu
);
7085 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7086 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7088 /* Get accessibility. */
7089 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7091 accessibility
= DW_UNSND (attr
);
7093 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7094 switch (accessibility
)
7096 case DW_ACCESS_private
:
7097 fnp
->is_private
= 1;
7099 case DW_ACCESS_protected
:
7100 fnp
->is_protected
= 1;
7104 /* Check for artificial methods. */
7105 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7106 if (attr
&& DW_UNSND (attr
) != 0)
7107 fnp
->is_artificial
= 1;
7109 /* Get index in virtual function table if it is a virtual member
7110 function. For older versions of GCC, this is an offset in the
7111 appropriate virtual table, as specified by DW_AT_containing_type.
7112 For everyone else, it is an expression to be evaluated relative
7113 to the object address. */
7115 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7118 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7120 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7122 /* Old-style GCC. */
7123 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7125 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7126 || (DW_BLOCK (attr
)->size
> 1
7127 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7128 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7130 struct dwarf_block blk
;
7133 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7135 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7136 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7137 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7138 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7139 dwarf2_complex_location_expr_complaint ();
7141 fnp
->voffset
/= cu
->header
.addr_size
;
7145 dwarf2_complex_location_expr_complaint ();
7148 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7150 else if (attr_form_is_section_offset (attr
))
7152 dwarf2_complex_location_expr_complaint ();
7156 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7162 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7163 if (attr
&& DW_UNSND (attr
))
7165 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7166 complaint (&symfile_complaints
,
7167 _("Member function \"%s\" (offset %d) is virtual "
7168 "but the vtable offset is not specified"),
7169 fieldname
, die
->offset
);
7170 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7171 TYPE_CPLUS_DYNAMIC (type
) = 1;
7176 /* Create the vector of member function fields, and attach it to the type. */
7179 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7180 struct dwarf2_cu
*cu
)
7182 struct fnfieldlist
*flp
;
7183 int total_length
= 0;
7186 if (cu
->language
== language_ada
)
7187 error (_("unexpected member functions in Ada type"));
7189 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7190 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7191 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7193 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7195 struct nextfnfield
*nfp
= flp
->head
;
7196 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7199 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7200 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7201 fn_flp
->fn_fields
= (struct fn_field
*)
7202 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7203 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7204 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7206 total_length
+= flp
->length
;
7209 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7210 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7213 /* Returns non-zero if NAME is the name of a vtable member in CU's
7214 language, zero otherwise. */
7216 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7218 static const char vptr
[] = "_vptr";
7219 static const char vtable
[] = "vtable";
7221 /* Look for the C++ and Java forms of the vtable. */
7222 if ((cu
->language
== language_java
7223 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7224 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7225 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7231 /* GCC outputs unnamed structures that are really pointers to member
7232 functions, with the ABI-specified layout. If TYPE describes
7233 such a structure, smash it into a member function type.
7235 GCC shouldn't do this; it should just output pointer to member DIEs.
7236 This is GCC PR debug/28767. */
7239 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7241 struct type
*pfn_type
, *domain_type
, *new_type
;
7243 /* Check for a structure with no name and two children. */
7244 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7247 /* Check for __pfn and __delta members. */
7248 if (TYPE_FIELD_NAME (type
, 0) == NULL
7249 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7250 || TYPE_FIELD_NAME (type
, 1) == NULL
7251 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7254 /* Find the type of the method. */
7255 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7256 if (pfn_type
== NULL
7257 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7258 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7261 /* Look for the "this" argument. */
7262 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7263 if (TYPE_NFIELDS (pfn_type
) == 0
7264 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7265 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7268 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7269 new_type
= alloc_type (objfile
);
7270 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7271 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7272 TYPE_VARARGS (pfn_type
));
7273 smash_to_methodptr_type (type
, new_type
);
7276 /* Called when we find the DIE that starts a structure or union scope
7277 (definition) to create a type for the structure or union. Fill in
7278 the type's name and general properties; the members will not be
7279 processed until process_structure_type.
7281 NOTE: we need to call these functions regardless of whether or not the
7282 DIE has a DW_AT_name attribute, since it might be an anonymous
7283 structure or union. This gets the type entered into our set of
7286 However, if the structure is incomplete (an opaque struct/union)
7287 then suppress creating a symbol table entry for it since gdb only
7288 wants to find the one with the complete definition. Note that if
7289 it is complete, we just call new_symbol, which does it's own
7290 checking about whether the struct/union is anonymous or not (and
7291 suppresses creating a symbol table entry itself). */
7293 static struct type
*
7294 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7296 struct objfile
*objfile
= cu
->objfile
;
7298 struct attribute
*attr
;
7301 /* If the definition of this type lives in .debug_types, read that type.
7302 Don't follow DW_AT_specification though, that will take us back up
7303 the chain and we want to go down. */
7304 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7307 struct dwarf2_cu
*type_cu
= cu
;
7308 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7310 /* We could just recurse on read_structure_type, but we need to call
7311 get_die_type to ensure only one type for this DIE is created.
7312 This is important, for example, because for c++ classes we need
7313 TYPE_NAME set which is only done by new_symbol. Blech. */
7314 type
= read_type_die (type_die
, type_cu
);
7316 /* TYPE_CU may not be the same as CU.
7317 Ensure TYPE is recorded in CU's type_hash table. */
7318 return set_die_type (die
, type
, cu
);
7321 type
= alloc_type (objfile
);
7322 INIT_CPLUS_SPECIFIC (type
);
7324 name
= dwarf2_name (die
, cu
);
7327 if (cu
->language
== language_cplus
7328 || cu
->language
== language_java
)
7330 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7332 /* dwarf2_full_name might have already finished building the DIE's
7333 type. If so, there is no need to continue. */
7334 if (get_die_type (die
, cu
) != NULL
)
7335 return get_die_type (die
, cu
);
7337 TYPE_TAG_NAME (type
) = full_name
;
7338 if (die
->tag
== DW_TAG_structure_type
7339 || die
->tag
== DW_TAG_class_type
)
7340 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7344 /* The name is already allocated along with this objfile, so
7345 we don't need to duplicate it for the type. */
7346 TYPE_TAG_NAME (type
) = (char *) name
;
7347 if (die
->tag
== DW_TAG_class_type
)
7348 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7352 if (die
->tag
== DW_TAG_structure_type
)
7354 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7356 else if (die
->tag
== DW_TAG_union_type
)
7358 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7362 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7365 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7366 TYPE_DECLARED_CLASS (type
) = 1;
7368 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7371 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7375 TYPE_LENGTH (type
) = 0;
7378 TYPE_STUB_SUPPORTED (type
) = 1;
7379 if (die_is_declaration (die
, cu
))
7380 TYPE_STUB (type
) = 1;
7381 else if (attr
== NULL
&& die
->child
== NULL
7382 && producer_is_realview (cu
->producer
))
7383 /* RealView does not output the required DW_AT_declaration
7384 on incomplete types. */
7385 TYPE_STUB (type
) = 1;
7387 /* We need to add the type field to the die immediately so we don't
7388 infinitely recurse when dealing with pointers to the structure
7389 type within the structure itself. */
7390 set_die_type (die
, type
, cu
);
7392 /* set_die_type should be already done. */
7393 set_descriptive_type (type
, die
, cu
);
7398 /* Finish creating a structure or union type, including filling in
7399 its members and creating a symbol for it. */
7402 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7404 struct objfile
*objfile
= cu
->objfile
;
7405 struct die_info
*child_die
= die
->child
;
7408 type
= get_die_type (die
, cu
);
7410 type
= read_structure_type (die
, cu
);
7412 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7414 struct field_info fi
;
7415 struct die_info
*child_die
;
7416 VEC (symbolp
) *template_args
= NULL
;
7417 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7419 memset (&fi
, 0, sizeof (struct field_info
));
7421 child_die
= die
->child
;
7423 while (child_die
&& child_die
->tag
)
7425 if (child_die
->tag
== DW_TAG_member
7426 || child_die
->tag
== DW_TAG_variable
)
7428 /* NOTE: carlton/2002-11-05: A C++ static data member
7429 should be a DW_TAG_member that is a declaration, but
7430 all versions of G++ as of this writing (so through at
7431 least 3.2.1) incorrectly generate DW_TAG_variable
7432 tags for them instead. */
7433 dwarf2_add_field (&fi
, child_die
, cu
);
7435 else if (child_die
->tag
== DW_TAG_subprogram
)
7437 /* C++ member function. */
7438 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7440 else if (child_die
->tag
== DW_TAG_inheritance
)
7442 /* C++ base class field. */
7443 dwarf2_add_field (&fi
, child_die
, cu
);
7445 else if (child_die
->tag
== DW_TAG_typedef
)
7446 dwarf2_add_typedef (&fi
, child_die
, cu
);
7447 else if (child_die
->tag
== DW_TAG_template_type_param
7448 || child_die
->tag
== DW_TAG_template_value_param
)
7450 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7453 VEC_safe_push (symbolp
, template_args
, arg
);
7456 child_die
= sibling_die (child_die
);
7459 /* Attach template arguments to type. */
7460 if (! VEC_empty (symbolp
, template_args
))
7462 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7463 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7464 = VEC_length (symbolp
, template_args
);
7465 TYPE_TEMPLATE_ARGUMENTS (type
)
7466 = obstack_alloc (&objfile
->objfile_obstack
,
7467 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7468 * sizeof (struct symbol
*)));
7469 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7470 VEC_address (symbolp
, template_args
),
7471 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7472 * sizeof (struct symbol
*)));
7473 VEC_free (symbolp
, template_args
);
7476 /* Attach fields and member functions to the type. */
7478 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7481 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7483 /* Get the type which refers to the base class (possibly this
7484 class itself) which contains the vtable pointer for the current
7485 class from the DW_AT_containing_type attribute. This use of
7486 DW_AT_containing_type is a GNU extension. */
7488 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7490 struct type
*t
= die_containing_type (die
, cu
);
7492 TYPE_VPTR_BASETYPE (type
) = t
;
7497 /* Our own class provides vtbl ptr. */
7498 for (i
= TYPE_NFIELDS (t
) - 1;
7499 i
>= TYPE_N_BASECLASSES (t
);
7502 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7504 if (is_vtable_name (fieldname
, cu
))
7506 TYPE_VPTR_FIELDNO (type
) = i
;
7511 /* Complain if virtual function table field not found. */
7512 if (i
< TYPE_N_BASECLASSES (t
))
7513 complaint (&symfile_complaints
,
7514 _("virtual function table pointer "
7515 "not found when defining class '%s'"),
7516 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7521 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7524 else if (cu
->producer
7525 && strncmp (cu
->producer
,
7526 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7528 /* The IBM XLC compiler does not provide direct indication
7529 of the containing type, but the vtable pointer is
7530 always named __vfp. */
7534 for (i
= TYPE_NFIELDS (type
) - 1;
7535 i
>= TYPE_N_BASECLASSES (type
);
7538 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7540 TYPE_VPTR_FIELDNO (type
) = i
;
7541 TYPE_VPTR_BASETYPE (type
) = type
;
7548 /* Copy fi.typedef_field_list linked list elements content into the
7549 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7550 if (fi
.typedef_field_list
)
7552 int i
= fi
.typedef_field_list_count
;
7554 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7555 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7556 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7557 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7559 /* Reverse the list order to keep the debug info elements order. */
7562 struct typedef_field
*dest
, *src
;
7564 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7565 src
= &fi
.typedef_field_list
->field
;
7566 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7571 do_cleanups (back_to
);
7573 if (HAVE_CPLUS_STRUCT (type
))
7574 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7577 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7579 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7580 snapshots) has been known to create a die giving a declaration
7581 for a class that has, as a child, a die giving a definition for a
7582 nested class. So we have to process our children even if the
7583 current die is a declaration. Normally, of course, a declaration
7584 won't have any children at all. */
7586 while (child_die
!= NULL
&& child_die
->tag
)
7588 if (child_die
->tag
== DW_TAG_member
7589 || child_die
->tag
== DW_TAG_variable
7590 || child_die
->tag
== DW_TAG_inheritance
7591 || child_die
->tag
== DW_TAG_template_value_param
7592 || child_die
->tag
== DW_TAG_template_type_param
)
7597 process_die (child_die
, cu
);
7599 child_die
= sibling_die (child_die
);
7602 /* Do not consider external references. According to the DWARF standard,
7603 these DIEs are identified by the fact that they have no byte_size
7604 attribute, and a declaration attribute. */
7605 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7606 || !die_is_declaration (die
, cu
))
7607 new_symbol (die
, type
, cu
);
7610 /* Given a DW_AT_enumeration_type die, set its type. We do not
7611 complete the type's fields yet, or create any symbols. */
7613 static struct type
*
7614 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7616 struct objfile
*objfile
= cu
->objfile
;
7618 struct attribute
*attr
;
7621 /* If the definition of this type lives in .debug_types, read that type.
7622 Don't follow DW_AT_specification though, that will take us back up
7623 the chain and we want to go down. */
7624 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7627 struct dwarf2_cu
*type_cu
= cu
;
7628 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7630 type
= read_type_die (type_die
, type_cu
);
7632 /* TYPE_CU may not be the same as CU.
7633 Ensure TYPE is recorded in CU's type_hash table. */
7634 return set_die_type (die
, type
, cu
);
7637 type
= alloc_type (objfile
);
7639 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7640 name
= dwarf2_full_name (NULL
, die
, cu
);
7642 TYPE_TAG_NAME (type
) = (char *) name
;
7644 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7647 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7651 TYPE_LENGTH (type
) = 0;
7654 /* The enumeration DIE can be incomplete. In Ada, any type can be
7655 declared as private in the package spec, and then defined only
7656 inside the package body. Such types are known as Taft Amendment
7657 Types. When another package uses such a type, an incomplete DIE
7658 may be generated by the compiler. */
7659 if (die_is_declaration (die
, cu
))
7660 TYPE_STUB (type
) = 1;
7662 return set_die_type (die
, type
, cu
);
7665 /* Given a pointer to a die which begins an enumeration, process all
7666 the dies that define the members of the enumeration, and create the
7667 symbol for the enumeration type.
7669 NOTE: We reverse the order of the element list. */
7672 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7674 struct type
*this_type
;
7676 this_type
= get_die_type (die
, cu
);
7677 if (this_type
== NULL
)
7678 this_type
= read_enumeration_type (die
, cu
);
7680 if (die
->child
!= NULL
)
7682 struct die_info
*child_die
;
7684 struct field
*fields
= NULL
;
7686 int unsigned_enum
= 1;
7689 child_die
= die
->child
;
7690 while (child_die
&& child_die
->tag
)
7692 if (child_die
->tag
!= DW_TAG_enumerator
)
7694 process_die (child_die
, cu
);
7698 name
= dwarf2_name (child_die
, cu
);
7701 sym
= new_symbol (child_die
, this_type
, cu
);
7702 if (SYMBOL_VALUE (sym
) < 0)
7705 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7707 fields
= (struct field
*)
7709 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7710 * sizeof (struct field
));
7713 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7714 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7715 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7716 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7722 child_die
= sibling_die (child_die
);
7727 TYPE_NFIELDS (this_type
) = num_fields
;
7728 TYPE_FIELDS (this_type
) = (struct field
*)
7729 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7730 memcpy (TYPE_FIELDS (this_type
), fields
,
7731 sizeof (struct field
) * num_fields
);
7735 TYPE_UNSIGNED (this_type
) = 1;
7738 /* If we are reading an enum from a .debug_types unit, and the enum
7739 is a declaration, and the enum is not the signatured type in the
7740 unit, then we do not want to add a symbol for it. Adding a
7741 symbol would in some cases obscure the true definition of the
7742 enum, giving users an incomplete type when the definition is
7743 actually available. Note that we do not want to do this for all
7744 enums which are just declarations, because C++0x allows forward
7745 enum declarations. */
7746 if (cu
->per_cu
->debug_type_section
7747 && die_is_declaration (die
, cu
))
7749 struct signatured_type
*type_sig
;
7752 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7753 cu
->per_cu
->debug_type_section
,
7754 cu
->per_cu
->offset
);
7755 if (type_sig
->type_offset
!= die
->offset
)
7759 new_symbol (die
, this_type
, cu
);
7762 /* Extract all information from a DW_TAG_array_type DIE and put it in
7763 the DIE's type field. For now, this only handles one dimensional
7766 static struct type
*
7767 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7769 struct objfile
*objfile
= cu
->objfile
;
7770 struct die_info
*child_die
;
7772 struct type
*element_type
, *range_type
, *index_type
;
7773 struct type
**range_types
= NULL
;
7774 struct attribute
*attr
;
7776 struct cleanup
*back_to
;
7779 element_type
= die_type (die
, cu
);
7781 /* The die_type call above may have already set the type for this DIE. */
7782 type
= get_die_type (die
, cu
);
7786 /* Irix 6.2 native cc creates array types without children for
7787 arrays with unspecified length. */
7788 if (die
->child
== NULL
)
7790 index_type
= objfile_type (objfile
)->builtin_int
;
7791 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7792 type
= create_array_type (NULL
, element_type
, range_type
);
7793 return set_die_type (die
, type
, cu
);
7796 back_to
= make_cleanup (null_cleanup
, NULL
);
7797 child_die
= die
->child
;
7798 while (child_die
&& child_die
->tag
)
7800 if (child_die
->tag
== DW_TAG_subrange_type
)
7802 struct type
*child_type
= read_type_die (child_die
, cu
);
7804 if (child_type
!= NULL
)
7806 /* The range type was succesfully read. Save it for the
7807 array type creation. */
7808 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7810 range_types
= (struct type
**)
7811 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7812 * sizeof (struct type
*));
7814 make_cleanup (free_current_contents
, &range_types
);
7816 range_types
[ndim
++] = child_type
;
7819 child_die
= sibling_die (child_die
);
7822 /* Dwarf2 dimensions are output from left to right, create the
7823 necessary array types in backwards order. */
7825 type
= element_type
;
7827 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7832 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7837 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7840 /* Understand Dwarf2 support for vector types (like they occur on
7841 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7842 array type. This is not part of the Dwarf2/3 standard yet, but a
7843 custom vendor extension. The main difference between a regular
7844 array and the vector variant is that vectors are passed by value
7846 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7848 make_vector_type (type
);
7850 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7851 implementation may choose to implement triple vectors using this
7853 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7856 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7857 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7859 complaint (&symfile_complaints
,
7860 _("DW_AT_byte_size for array type smaller "
7861 "than the total size of elements"));
7864 name
= dwarf2_name (die
, cu
);
7866 TYPE_NAME (type
) = name
;
7868 /* Install the type in the die. */
7869 set_die_type (die
, type
, cu
);
7871 /* set_die_type should be already done. */
7872 set_descriptive_type (type
, die
, cu
);
7874 do_cleanups (back_to
);
7879 static enum dwarf_array_dim_ordering
7880 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7882 struct attribute
*attr
;
7884 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7886 if (attr
) return DW_SND (attr
);
7888 /* GNU F77 is a special case, as at 08/2004 array type info is the
7889 opposite order to the dwarf2 specification, but data is still
7890 laid out as per normal fortran.
7892 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7893 version checking. */
7895 if (cu
->language
== language_fortran
7896 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7898 return DW_ORD_row_major
;
7901 switch (cu
->language_defn
->la_array_ordering
)
7903 case array_column_major
:
7904 return DW_ORD_col_major
;
7905 case array_row_major
:
7907 return DW_ORD_row_major
;
7911 /* Extract all information from a DW_TAG_set_type DIE and put it in
7912 the DIE's type field. */
7914 static struct type
*
7915 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7917 struct type
*domain_type
, *set_type
;
7918 struct attribute
*attr
;
7920 domain_type
= die_type (die
, cu
);
7922 /* The die_type call above may have already set the type for this DIE. */
7923 set_type
= get_die_type (die
, cu
);
7927 set_type
= create_set_type (NULL
, domain_type
);
7929 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7931 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7933 return set_die_type (die
, set_type
, cu
);
7936 /* First cut: install each common block member as a global variable. */
7939 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7941 struct die_info
*child_die
;
7942 struct attribute
*attr
;
7944 CORE_ADDR base
= (CORE_ADDR
) 0;
7946 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7949 /* Support the .debug_loc offsets. */
7950 if (attr_form_is_block (attr
))
7952 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7954 else if (attr_form_is_section_offset (attr
))
7956 dwarf2_complex_location_expr_complaint ();
7960 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7961 "common block member");
7964 if (die
->child
!= NULL
)
7966 child_die
= die
->child
;
7967 while (child_die
&& child_die
->tag
)
7971 sym
= new_symbol (child_die
, NULL
, cu
);
7973 && handle_data_member_location (child_die
, cu
, &offset
))
7975 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
7976 add_symbol_to_list (sym
, &global_symbols
);
7978 child_die
= sibling_die (child_die
);
7983 /* Create a type for a C++ namespace. */
7985 static struct type
*
7986 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7988 struct objfile
*objfile
= cu
->objfile
;
7989 const char *previous_prefix
, *name
;
7993 /* For extensions, reuse the type of the original namespace. */
7994 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7996 struct die_info
*ext_die
;
7997 struct dwarf2_cu
*ext_cu
= cu
;
7999 ext_die
= dwarf2_extension (die
, &ext_cu
);
8000 type
= read_type_die (ext_die
, ext_cu
);
8002 /* EXT_CU may not be the same as CU.
8003 Ensure TYPE is recorded in CU's type_hash table. */
8004 return set_die_type (die
, type
, cu
);
8007 name
= namespace_name (die
, &is_anonymous
, cu
);
8009 /* Now build the name of the current namespace. */
8011 previous_prefix
= determine_prefix (die
, cu
);
8012 if (previous_prefix
[0] != '\0')
8013 name
= typename_concat (&objfile
->objfile_obstack
,
8014 previous_prefix
, name
, 0, cu
);
8016 /* Create the type. */
8017 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8019 TYPE_NAME (type
) = (char *) name
;
8020 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8022 return set_die_type (die
, type
, cu
);
8025 /* Read a C++ namespace. */
8028 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8030 struct objfile
*objfile
= cu
->objfile
;
8033 /* Add a symbol associated to this if we haven't seen the namespace
8034 before. Also, add a using directive if it's an anonymous
8037 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8041 type
= read_type_die (die
, cu
);
8042 new_symbol (die
, type
, cu
);
8044 namespace_name (die
, &is_anonymous
, cu
);
8047 const char *previous_prefix
= determine_prefix (die
, cu
);
8049 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8050 NULL
, NULL
, &objfile
->objfile_obstack
);
8054 if (die
->child
!= NULL
)
8056 struct die_info
*child_die
= die
->child
;
8058 while (child_die
&& child_die
->tag
)
8060 process_die (child_die
, cu
);
8061 child_die
= sibling_die (child_die
);
8066 /* Read a Fortran module as type. This DIE can be only a declaration used for
8067 imported module. Still we need that type as local Fortran "use ... only"
8068 declaration imports depend on the created type in determine_prefix. */
8070 static struct type
*
8071 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8073 struct objfile
*objfile
= cu
->objfile
;
8077 module_name
= dwarf2_name (die
, cu
);
8079 complaint (&symfile_complaints
,
8080 _("DW_TAG_module has no name, offset 0x%x"),
8082 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8084 /* determine_prefix uses TYPE_TAG_NAME. */
8085 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8087 return set_die_type (die
, type
, cu
);
8090 /* Read a Fortran module. */
8093 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8095 struct die_info
*child_die
= die
->child
;
8097 while (child_die
&& child_die
->tag
)
8099 process_die (child_die
, cu
);
8100 child_die
= sibling_die (child_die
);
8104 /* Return the name of the namespace represented by DIE. Set
8105 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8109 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8111 struct die_info
*current_die
;
8112 const char *name
= NULL
;
8114 /* Loop through the extensions until we find a name. */
8116 for (current_die
= die
;
8117 current_die
!= NULL
;
8118 current_die
= dwarf2_extension (die
, &cu
))
8120 name
= dwarf2_name (current_die
, cu
);
8125 /* Is it an anonymous namespace? */
8127 *is_anonymous
= (name
== NULL
);
8129 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8134 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8135 the user defined type vector. */
8137 static struct type
*
8138 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8140 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8141 struct comp_unit_head
*cu_header
= &cu
->header
;
8143 struct attribute
*attr_byte_size
;
8144 struct attribute
*attr_address_class
;
8145 int byte_size
, addr_class
;
8146 struct type
*target_type
;
8148 target_type
= die_type (die
, cu
);
8150 /* The die_type call above may have already set the type for this DIE. */
8151 type
= get_die_type (die
, cu
);
8155 type
= lookup_pointer_type (target_type
);
8157 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8159 byte_size
= DW_UNSND (attr_byte_size
);
8161 byte_size
= cu_header
->addr_size
;
8163 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8164 if (attr_address_class
)
8165 addr_class
= DW_UNSND (attr_address_class
);
8167 addr_class
= DW_ADDR_none
;
8169 /* If the pointer size or address class is different than the
8170 default, create a type variant marked as such and set the
8171 length accordingly. */
8172 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8174 if (gdbarch_address_class_type_flags_p (gdbarch
))
8178 type_flags
= gdbarch_address_class_type_flags
8179 (gdbarch
, byte_size
, addr_class
);
8180 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8182 type
= make_type_with_address_space (type
, type_flags
);
8184 else if (TYPE_LENGTH (type
) != byte_size
)
8186 complaint (&symfile_complaints
,
8187 _("invalid pointer size %d"), byte_size
);
8191 /* Should we also complain about unhandled address classes? */
8195 TYPE_LENGTH (type
) = byte_size
;
8196 return set_die_type (die
, type
, cu
);
8199 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8200 the user defined type vector. */
8202 static struct type
*
8203 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8206 struct type
*to_type
;
8207 struct type
*domain
;
8209 to_type
= die_type (die
, cu
);
8210 domain
= die_containing_type (die
, cu
);
8212 /* The calls above may have already set the type for this DIE. */
8213 type
= get_die_type (die
, cu
);
8217 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8218 type
= lookup_methodptr_type (to_type
);
8220 type
= lookup_memberptr_type (to_type
, domain
);
8222 return set_die_type (die
, type
, cu
);
8225 /* Extract all information from a DW_TAG_reference_type DIE and add to
8226 the user defined type vector. */
8228 static struct type
*
8229 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8231 struct comp_unit_head
*cu_header
= &cu
->header
;
8232 struct type
*type
, *target_type
;
8233 struct attribute
*attr
;
8235 target_type
= die_type (die
, cu
);
8237 /* The die_type call above may have already set the type for this DIE. */
8238 type
= get_die_type (die
, cu
);
8242 type
= lookup_reference_type (target_type
);
8243 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8246 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8250 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8252 return set_die_type (die
, type
, cu
);
8255 static struct type
*
8256 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8258 struct type
*base_type
, *cv_type
;
8260 base_type
= die_type (die
, cu
);
8262 /* The die_type call above may have already set the type for this DIE. */
8263 cv_type
= get_die_type (die
, cu
);
8267 /* In case the const qualifier is applied to an array type, the element type
8268 is so qualified, not the array type (section 6.7.3 of C99). */
8269 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8271 struct type
*el_type
, *inner_array
;
8273 base_type
= copy_type (base_type
);
8274 inner_array
= base_type
;
8276 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8278 TYPE_TARGET_TYPE (inner_array
) =
8279 copy_type (TYPE_TARGET_TYPE (inner_array
));
8280 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8283 el_type
= TYPE_TARGET_TYPE (inner_array
);
8284 TYPE_TARGET_TYPE (inner_array
) =
8285 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8287 return set_die_type (die
, base_type
, cu
);
8290 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8291 return set_die_type (die
, cv_type
, cu
);
8294 static struct type
*
8295 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8297 struct type
*base_type
, *cv_type
;
8299 base_type
= die_type (die
, cu
);
8301 /* The die_type call above may have already set the type for this DIE. */
8302 cv_type
= get_die_type (die
, cu
);
8306 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8307 return set_die_type (die
, cv_type
, cu
);
8310 /* Extract all information from a DW_TAG_string_type DIE and add to
8311 the user defined type vector. It isn't really a user defined type,
8312 but it behaves like one, with other DIE's using an AT_user_def_type
8313 attribute to reference it. */
8315 static struct type
*
8316 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8318 struct objfile
*objfile
= cu
->objfile
;
8319 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8320 struct type
*type
, *range_type
, *index_type
, *char_type
;
8321 struct attribute
*attr
;
8322 unsigned int length
;
8324 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8327 length
= DW_UNSND (attr
);
8331 /* Check for the DW_AT_byte_size attribute. */
8332 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8335 length
= DW_UNSND (attr
);
8343 index_type
= objfile_type (objfile
)->builtin_int
;
8344 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8345 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8346 type
= create_string_type (NULL
, char_type
, range_type
);
8348 return set_die_type (die
, type
, cu
);
8351 /* Handle DIES due to C code like:
8355 int (*funcp)(int a, long l);
8359 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8361 static struct type
*
8362 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8364 struct type
*type
; /* Type that this function returns. */
8365 struct type
*ftype
; /* Function that returns above type. */
8366 struct attribute
*attr
;
8368 type
= die_type (die
, cu
);
8370 /* The die_type call above may have already set the type for this DIE. */
8371 ftype
= get_die_type (die
, cu
);
8375 ftype
= lookup_function_type (type
);
8377 /* All functions in C++, Pascal and Java have prototypes. */
8378 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8379 if ((attr
&& (DW_UNSND (attr
) != 0))
8380 || cu
->language
== language_cplus
8381 || cu
->language
== language_java
8382 || cu
->language
== language_pascal
)
8383 TYPE_PROTOTYPED (ftype
) = 1;
8384 else if (producer_is_realview (cu
->producer
))
8385 /* RealView does not emit DW_AT_prototyped. We can not
8386 distinguish prototyped and unprototyped functions; default to
8387 prototyped, since that is more common in modern code (and
8388 RealView warns about unprototyped functions). */
8389 TYPE_PROTOTYPED (ftype
) = 1;
8391 /* Store the calling convention in the type if it's available in
8392 the subroutine die. Otherwise set the calling convention to
8393 the default value DW_CC_normal. */
8394 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8396 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8397 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8398 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8400 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8402 /* We need to add the subroutine type to the die immediately so
8403 we don't infinitely recurse when dealing with parameters
8404 declared as the same subroutine type. */
8405 set_die_type (die
, ftype
, cu
);
8407 if (die
->child
!= NULL
)
8409 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8410 struct die_info
*child_die
;
8411 int nparams
, iparams
;
8413 /* Count the number of parameters.
8414 FIXME: GDB currently ignores vararg functions, but knows about
8415 vararg member functions. */
8417 child_die
= die
->child
;
8418 while (child_die
&& child_die
->tag
)
8420 if (child_die
->tag
== DW_TAG_formal_parameter
)
8422 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8423 TYPE_VARARGS (ftype
) = 1;
8424 child_die
= sibling_die (child_die
);
8427 /* Allocate storage for parameters and fill them in. */
8428 TYPE_NFIELDS (ftype
) = nparams
;
8429 TYPE_FIELDS (ftype
) = (struct field
*)
8430 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8432 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8433 even if we error out during the parameters reading below. */
8434 for (iparams
= 0; iparams
< nparams
; iparams
++)
8435 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8438 child_die
= die
->child
;
8439 while (child_die
&& child_die
->tag
)
8441 if (child_die
->tag
== DW_TAG_formal_parameter
)
8443 struct type
*arg_type
;
8445 /* DWARF version 2 has no clean way to discern C++
8446 static and non-static member functions. G++ helps
8447 GDB by marking the first parameter for non-static
8448 member functions (which is the this pointer) as
8449 artificial. We pass this information to
8450 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8452 DWARF version 3 added DW_AT_object_pointer, which GCC
8453 4.5 does not yet generate. */
8454 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8456 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8459 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8461 /* GCC/43521: In java, the formal parameter
8462 "this" is sometimes not marked with DW_AT_artificial. */
8463 if (cu
->language
== language_java
)
8465 const char *name
= dwarf2_name (child_die
, cu
);
8467 if (name
&& !strcmp (name
, "this"))
8468 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8471 arg_type
= die_type (child_die
, cu
);
8473 /* RealView does not mark THIS as const, which the testsuite
8474 expects. GCC marks THIS as const in method definitions,
8475 but not in the class specifications (GCC PR 43053). */
8476 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8477 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8480 struct dwarf2_cu
*arg_cu
= cu
;
8481 const char *name
= dwarf2_name (child_die
, cu
);
8483 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8486 /* If the compiler emits this, use it. */
8487 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8490 else if (name
&& strcmp (name
, "this") == 0)
8491 /* Function definitions will have the argument names. */
8493 else if (name
== NULL
&& iparams
== 0)
8494 /* Declarations may not have the names, so like
8495 elsewhere in GDB, assume an artificial first
8496 argument is "this". */
8500 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8504 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8507 child_die
= sibling_die (child_die
);
8514 static struct type
*
8515 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8517 struct objfile
*objfile
= cu
->objfile
;
8518 const char *name
= NULL
;
8519 struct type
*this_type
;
8521 name
= dwarf2_full_name (NULL
, die
, cu
);
8522 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8523 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8524 TYPE_NAME (this_type
) = (char *) name
;
8525 set_die_type (die
, this_type
, cu
);
8526 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8530 /* Find a representation of a given base type and install
8531 it in the TYPE field of the die. */
8533 static struct type
*
8534 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8536 struct objfile
*objfile
= cu
->objfile
;
8538 struct attribute
*attr
;
8539 int encoding
= 0, size
= 0;
8541 enum type_code code
= TYPE_CODE_INT
;
8543 struct type
*target_type
= NULL
;
8545 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8548 encoding
= DW_UNSND (attr
);
8550 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8553 size
= DW_UNSND (attr
);
8555 name
= dwarf2_name (die
, cu
);
8558 complaint (&symfile_complaints
,
8559 _("DW_AT_name missing from DW_TAG_base_type"));
8564 case DW_ATE_address
:
8565 /* Turn DW_ATE_address into a void * pointer. */
8566 code
= TYPE_CODE_PTR
;
8567 type_flags
|= TYPE_FLAG_UNSIGNED
;
8568 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8570 case DW_ATE_boolean
:
8571 code
= TYPE_CODE_BOOL
;
8572 type_flags
|= TYPE_FLAG_UNSIGNED
;
8574 case DW_ATE_complex_float
:
8575 code
= TYPE_CODE_COMPLEX
;
8576 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8578 case DW_ATE_decimal_float
:
8579 code
= TYPE_CODE_DECFLOAT
;
8582 code
= TYPE_CODE_FLT
;
8586 case DW_ATE_unsigned
:
8587 type_flags
|= TYPE_FLAG_UNSIGNED
;
8588 if (cu
->language
== language_fortran
8590 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8591 code
= TYPE_CODE_CHAR
;
8593 case DW_ATE_signed_char
:
8594 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8595 || cu
->language
== language_pascal
8596 || cu
->language
== language_fortran
)
8597 code
= TYPE_CODE_CHAR
;
8599 case DW_ATE_unsigned_char
:
8600 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8601 || cu
->language
== language_pascal
8602 || cu
->language
== language_fortran
)
8603 code
= TYPE_CODE_CHAR
;
8604 type_flags
|= TYPE_FLAG_UNSIGNED
;
8607 /* We just treat this as an integer and then recognize the
8608 type by name elsewhere. */
8612 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8613 dwarf_type_encoding_name (encoding
));
8617 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8618 TYPE_NAME (type
) = name
;
8619 TYPE_TARGET_TYPE (type
) = target_type
;
8621 if (name
&& strcmp (name
, "char") == 0)
8622 TYPE_NOSIGN (type
) = 1;
8624 return set_die_type (die
, type
, cu
);
8627 /* Read the given DW_AT_subrange DIE. */
8629 static struct type
*
8630 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8632 struct type
*base_type
;
8633 struct type
*range_type
;
8634 struct attribute
*attr
;
8638 LONGEST negative_mask
;
8640 base_type
= die_type (die
, cu
);
8641 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8642 check_typedef (base_type
);
8644 /* The die_type call above may have already set the type for this DIE. */
8645 range_type
= get_die_type (die
, cu
);
8649 if (cu
->language
== language_fortran
)
8651 /* FORTRAN implies a lower bound of 1, if not given. */
8655 /* FIXME: For variable sized arrays either of these could be
8656 a variable rather than a constant value. We'll allow it,
8657 but we don't know how to handle it. */
8658 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8660 low
= dwarf2_get_attr_constant_value (attr
, 0);
8662 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8665 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8667 /* GCC encodes arrays with unspecified or dynamic length
8668 with a DW_FORM_block1 attribute or a reference attribute.
8669 FIXME: GDB does not yet know how to handle dynamic
8670 arrays properly, treat them as arrays with unspecified
8673 FIXME: jimb/2003-09-22: GDB does not really know
8674 how to handle arrays of unspecified length
8675 either; we just represent them as zero-length
8676 arrays. Choose an appropriate upper bound given
8677 the lower bound we've computed above. */
8681 high
= dwarf2_get_attr_constant_value (attr
, 1);
8685 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8688 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8689 high
= low
+ count
- 1;
8693 /* Unspecified array length. */
8698 /* Dwarf-2 specifications explicitly allows to create subrange types
8699 without specifying a base type.
8700 In that case, the base type must be set to the type of
8701 the lower bound, upper bound or count, in that order, if any of these
8702 three attributes references an object that has a type.
8703 If no base type is found, the Dwarf-2 specifications say that
8704 a signed integer type of size equal to the size of an address should
8706 For the following C code: `extern char gdb_int [];'
8707 GCC produces an empty range DIE.
8708 FIXME: muller/2010-05-28: Possible references to object for low bound,
8709 high bound or count are not yet handled by this code. */
8710 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8712 struct objfile
*objfile
= cu
->objfile
;
8713 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8714 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8715 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8717 /* Test "int", "long int", and "long long int" objfile types,
8718 and select the first one having a size above or equal to the
8719 architecture address size. */
8720 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8721 base_type
= int_type
;
8724 int_type
= objfile_type (objfile
)->builtin_long
;
8725 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8726 base_type
= int_type
;
8729 int_type
= objfile_type (objfile
)->builtin_long_long
;
8730 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8731 base_type
= int_type
;
8737 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8738 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8739 low
|= negative_mask
;
8740 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8741 high
|= negative_mask
;
8743 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8745 /* Mark arrays with dynamic length at least as an array of unspecified
8746 length. GDB could check the boundary but before it gets implemented at
8747 least allow accessing the array elements. */
8748 if (attr
&& attr_form_is_block (attr
))
8749 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8751 /* Ada expects an empty array on no boundary attributes. */
8752 if (attr
== NULL
&& cu
->language
!= language_ada
)
8753 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8755 name
= dwarf2_name (die
, cu
);
8757 TYPE_NAME (range_type
) = name
;
8759 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8761 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8763 set_die_type (die
, range_type
, cu
);
8765 /* set_die_type should be already done. */
8766 set_descriptive_type (range_type
, die
, cu
);
8771 static struct type
*
8772 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8776 /* For now, we only support the C meaning of an unspecified type: void. */
8778 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8779 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8781 return set_die_type (die
, type
, cu
);
8784 /* Trivial hash function for die_info: the hash value of a DIE
8785 is its offset in .debug_info for this objfile. */
8788 die_hash (const void *item
)
8790 const struct die_info
*die
= item
;
8795 /* Trivial comparison function for die_info structures: two DIEs
8796 are equal if they have the same offset. */
8799 die_eq (const void *item_lhs
, const void *item_rhs
)
8801 const struct die_info
*die_lhs
= item_lhs
;
8802 const struct die_info
*die_rhs
= item_rhs
;
8804 return die_lhs
->offset
== die_rhs
->offset
;
8807 /* Read a whole compilation unit into a linked list of dies. */
8809 static struct die_info
*
8810 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8812 struct die_reader_specs reader_specs
;
8813 int read_abbrevs
= 0;
8814 struct cleanup
*back_to
= NULL
;
8815 struct die_info
*die
;
8817 if (cu
->dwarf2_abbrevs
== NULL
)
8819 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8820 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8824 gdb_assert (cu
->die_hash
== NULL
);
8826 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8830 &cu
->comp_unit_obstack
,
8831 hashtab_obstack_allocate
,
8832 dummy_obstack_deallocate
);
8834 init_cu_die_reader (&reader_specs
, cu
);
8836 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8839 do_cleanups (back_to
);
8844 /* Main entry point for reading a DIE and all children.
8845 Read the DIE and dump it if requested. */
8847 static struct die_info
*
8848 read_die_and_children (const struct die_reader_specs
*reader
,
8850 gdb_byte
**new_info_ptr
,
8851 struct die_info
*parent
)
8853 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8854 new_info_ptr
, parent
);
8856 if (dwarf2_die_debug
)
8858 fprintf_unfiltered (gdb_stdlog
,
8859 "\nRead die from %s of %s:\n",
8860 (reader
->cu
->per_cu
->debug_type_section
8863 reader
->abfd
->filename
);
8864 dump_die (result
, dwarf2_die_debug
);
8870 /* Read a single die and all its descendents. Set the die's sibling
8871 field to NULL; set other fields in the die correctly, and set all
8872 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8873 location of the info_ptr after reading all of those dies. PARENT
8874 is the parent of the die in question. */
8876 static struct die_info
*
8877 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8879 gdb_byte
**new_info_ptr
,
8880 struct die_info
*parent
)
8882 struct die_info
*die
;
8886 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8889 *new_info_ptr
= cur_ptr
;
8892 store_in_ref_table (die
, reader
->cu
);
8895 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8899 *new_info_ptr
= cur_ptr
;
8902 die
->sibling
= NULL
;
8903 die
->parent
= parent
;
8907 /* Read a die, all of its descendents, and all of its siblings; set
8908 all of the fields of all of the dies correctly. Arguments are as
8909 in read_die_and_children. */
8911 static struct die_info
*
8912 read_die_and_siblings (const struct die_reader_specs
*reader
,
8914 gdb_byte
**new_info_ptr
,
8915 struct die_info
*parent
)
8917 struct die_info
*first_die
, *last_sibling
;
8921 first_die
= last_sibling
= NULL
;
8925 struct die_info
*die
8926 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8930 *new_info_ptr
= cur_ptr
;
8937 last_sibling
->sibling
= die
;
8943 /* Read the die from the .debug_info section buffer. Set DIEP to
8944 point to a newly allocated die with its information, except for its
8945 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8946 whether the die has children or not. */
8949 read_full_die (const struct die_reader_specs
*reader
,
8950 struct die_info
**diep
, gdb_byte
*info_ptr
,
8953 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8954 struct abbrev_info
*abbrev
;
8955 struct die_info
*die
;
8956 struct dwarf2_cu
*cu
= reader
->cu
;
8957 bfd
*abfd
= reader
->abfd
;
8959 offset
= info_ptr
- reader
->buffer
;
8960 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8961 info_ptr
+= bytes_read
;
8969 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8971 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8973 bfd_get_filename (abfd
));
8975 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8976 die
->offset
= offset
;
8977 die
->tag
= abbrev
->tag
;
8978 die
->abbrev
= abbrev_number
;
8980 die
->num_attrs
= abbrev
->num_attrs
;
8982 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8983 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8984 abfd
, info_ptr
, cu
);
8987 *has_children
= abbrev
->has_children
;
8991 /* In DWARF version 2, the description of the debugging information is
8992 stored in a separate .debug_abbrev section. Before we read any
8993 dies from a section we read in all abbreviations and install them
8994 in a hash table. This function also sets flags in CU describing
8995 the data found in the abbrev table. */
8998 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9000 struct comp_unit_head
*cu_header
= &cu
->header
;
9001 gdb_byte
*abbrev_ptr
;
9002 struct abbrev_info
*cur_abbrev
;
9003 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9004 unsigned int abbrev_form
, hash_number
;
9005 struct attr_abbrev
*cur_attrs
;
9006 unsigned int allocated_attrs
;
9008 /* Initialize dwarf2 abbrevs. */
9009 obstack_init (&cu
->abbrev_obstack
);
9010 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9012 * sizeof (struct abbrev_info
*)));
9013 memset (cu
->dwarf2_abbrevs
, 0,
9014 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9016 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9017 &dwarf2_per_objfile
->abbrev
);
9018 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9019 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9020 abbrev_ptr
+= bytes_read
;
9022 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9023 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9025 /* Loop until we reach an abbrev number of 0. */
9026 while (abbrev_number
)
9028 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9030 /* read in abbrev header */
9031 cur_abbrev
->number
= abbrev_number
;
9032 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9033 abbrev_ptr
+= bytes_read
;
9034 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9037 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9038 cu
->has_namespace_info
= 1;
9040 /* now read in declarations */
9041 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9042 abbrev_ptr
+= bytes_read
;
9043 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9044 abbrev_ptr
+= bytes_read
;
9047 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9049 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9051 = xrealloc (cur_attrs
, (allocated_attrs
9052 * sizeof (struct attr_abbrev
)));
9055 /* Record whether this compilation unit might have
9056 inter-compilation-unit references. If we don't know what form
9057 this attribute will have, then it might potentially be a
9058 DW_FORM_ref_addr, so we conservatively expect inter-CU
9061 if (abbrev_form
== DW_FORM_ref_addr
9062 || abbrev_form
== DW_FORM_indirect
)
9063 cu
->has_form_ref_addr
= 1;
9065 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9066 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9067 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9068 abbrev_ptr
+= bytes_read
;
9069 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9070 abbrev_ptr
+= bytes_read
;
9073 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9074 (cur_abbrev
->num_attrs
9075 * sizeof (struct attr_abbrev
)));
9076 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9077 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9079 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9080 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9081 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9083 /* Get next abbreviation.
9084 Under Irix6 the abbreviations for a compilation unit are not
9085 always properly terminated with an abbrev number of 0.
9086 Exit loop if we encounter an abbreviation which we have
9087 already read (which means we are about to read the abbreviations
9088 for the next compile unit) or if the end of the abbreviation
9089 table is reached. */
9090 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9091 >= dwarf2_per_objfile
->abbrev
.size
)
9093 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9094 abbrev_ptr
+= bytes_read
;
9095 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9102 /* Release the memory used by the abbrev table for a compilation unit. */
9105 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9107 struct dwarf2_cu
*cu
= ptr_to_cu
;
9109 obstack_free (&cu
->abbrev_obstack
, NULL
);
9110 cu
->dwarf2_abbrevs
= NULL
;
9113 /* Lookup an abbrev_info structure in the abbrev hash table. */
9115 static struct abbrev_info
*
9116 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9118 unsigned int hash_number
;
9119 struct abbrev_info
*abbrev
;
9121 hash_number
= number
% ABBREV_HASH_SIZE
;
9122 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9126 if (abbrev
->number
== number
)
9129 abbrev
= abbrev
->next
;
9134 /* Returns nonzero if TAG represents a type that we might generate a partial
9138 is_type_tag_for_partial (int tag
)
9143 /* Some types that would be reasonable to generate partial symbols for,
9144 that we don't at present. */
9145 case DW_TAG_array_type
:
9146 case DW_TAG_file_type
:
9147 case DW_TAG_ptr_to_member_type
:
9148 case DW_TAG_set_type
:
9149 case DW_TAG_string_type
:
9150 case DW_TAG_subroutine_type
:
9152 case DW_TAG_base_type
:
9153 case DW_TAG_class_type
:
9154 case DW_TAG_interface_type
:
9155 case DW_TAG_enumeration_type
:
9156 case DW_TAG_structure_type
:
9157 case DW_TAG_subrange_type
:
9158 case DW_TAG_typedef
:
9159 case DW_TAG_union_type
:
9166 /* Load all DIEs that are interesting for partial symbols into memory. */
9168 static struct partial_die_info
*
9169 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9170 int building_psymtab
, struct dwarf2_cu
*cu
)
9172 struct partial_die_info
*part_die
;
9173 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9174 struct abbrev_info
*abbrev
;
9175 unsigned int bytes_read
;
9176 unsigned int load_all
= 0;
9178 int nesting_level
= 1;
9183 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9187 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9191 &cu
->comp_unit_obstack
,
9192 hashtab_obstack_allocate
,
9193 dummy_obstack_deallocate
);
9195 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9196 sizeof (struct partial_die_info
));
9200 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9202 /* A NULL abbrev means the end of a series of children. */
9205 if (--nesting_level
== 0)
9207 /* PART_DIE was probably the last thing allocated on the
9208 comp_unit_obstack, so we could call obstack_free
9209 here. We don't do that because the waste is small,
9210 and will be cleaned up when we're done with this
9211 compilation unit. This way, we're also more robust
9212 against other users of the comp_unit_obstack. */
9215 info_ptr
+= bytes_read
;
9216 last_die
= parent_die
;
9217 parent_die
= parent_die
->die_parent
;
9221 /* Check for template arguments. We never save these; if
9222 they're seen, we just mark the parent, and go on our way. */
9223 if (parent_die
!= NULL
9224 && cu
->language
== language_cplus
9225 && (abbrev
->tag
== DW_TAG_template_type_param
9226 || abbrev
->tag
== DW_TAG_template_value_param
))
9228 parent_die
->has_template_arguments
= 1;
9232 /* We don't need a partial DIE for the template argument. */
9233 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9239 /* We only recurse into subprograms looking for template arguments.
9240 Skip their other children. */
9242 && cu
->language
== language_cplus
9243 && parent_die
!= NULL
9244 && parent_die
->tag
== DW_TAG_subprogram
)
9246 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9250 /* Check whether this DIE is interesting enough to save. Normally
9251 we would not be interested in members here, but there may be
9252 later variables referencing them via DW_AT_specification (for
9255 && !is_type_tag_for_partial (abbrev
->tag
)
9256 && abbrev
->tag
!= DW_TAG_constant
9257 && abbrev
->tag
!= DW_TAG_enumerator
9258 && abbrev
->tag
!= DW_TAG_subprogram
9259 && abbrev
->tag
!= DW_TAG_lexical_block
9260 && abbrev
->tag
!= DW_TAG_variable
9261 && abbrev
->tag
!= DW_TAG_namespace
9262 && abbrev
->tag
!= DW_TAG_module
9263 && abbrev
->tag
!= DW_TAG_member
)
9265 /* Otherwise we skip to the next sibling, if any. */
9266 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9270 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9271 buffer
, info_ptr
, cu
);
9273 /* This two-pass algorithm for processing partial symbols has a
9274 high cost in cache pressure. Thus, handle some simple cases
9275 here which cover the majority of C partial symbols. DIEs
9276 which neither have specification tags in them, nor could have
9277 specification tags elsewhere pointing at them, can simply be
9278 processed and discarded.
9280 This segment is also optional; scan_partial_symbols and
9281 add_partial_symbol will handle these DIEs if we chain
9282 them in normally. When compilers which do not emit large
9283 quantities of duplicate debug information are more common,
9284 this code can probably be removed. */
9286 /* Any complete simple types at the top level (pretty much all
9287 of them, for a language without namespaces), can be processed
9289 if (parent_die
== NULL
9290 && part_die
->has_specification
== 0
9291 && part_die
->is_declaration
== 0
9292 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9293 || part_die
->tag
== DW_TAG_base_type
9294 || part_die
->tag
== DW_TAG_subrange_type
))
9296 if (building_psymtab
&& part_die
->name
!= NULL
)
9297 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9298 VAR_DOMAIN
, LOC_TYPEDEF
,
9299 &cu
->objfile
->static_psymbols
,
9300 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9301 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9305 /* The exception for DW_TAG_typedef with has_children above is
9306 a workaround of GCC PR debug/47510. In the case of this complaint
9307 type_name_no_tag_or_error will error on such types later.
9309 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9310 it could not find the child DIEs referenced later, this is checked
9311 above. In correct DWARF DW_TAG_typedef should have no children. */
9313 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9314 complaint (&symfile_complaints
,
9315 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9316 "- DIE at 0x%x [in module %s]"),
9317 part_die
->offset
, cu
->objfile
->name
);
9319 /* If we're at the second level, and we're an enumerator, and
9320 our parent has no specification (meaning possibly lives in a
9321 namespace elsewhere), then we can add the partial symbol now
9322 instead of queueing it. */
9323 if (part_die
->tag
== DW_TAG_enumerator
9324 && parent_die
!= NULL
9325 && parent_die
->die_parent
== NULL
9326 && parent_die
->tag
== DW_TAG_enumeration_type
9327 && parent_die
->has_specification
== 0)
9329 if (part_die
->name
== NULL
)
9330 complaint (&symfile_complaints
,
9331 _("malformed enumerator DIE ignored"));
9332 else if (building_psymtab
)
9333 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9334 VAR_DOMAIN
, LOC_CONST
,
9335 (cu
->language
== language_cplus
9336 || cu
->language
== language_java
)
9337 ? &cu
->objfile
->global_psymbols
9338 : &cu
->objfile
->static_psymbols
,
9339 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9341 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9345 /* We'll save this DIE so link it in. */
9346 part_die
->die_parent
= parent_die
;
9347 part_die
->die_sibling
= NULL
;
9348 part_die
->die_child
= NULL
;
9350 if (last_die
&& last_die
== parent_die
)
9351 last_die
->die_child
= part_die
;
9353 last_die
->die_sibling
= part_die
;
9355 last_die
= part_die
;
9357 if (first_die
== NULL
)
9358 first_die
= part_die
;
9360 /* Maybe add the DIE to the hash table. Not all DIEs that we
9361 find interesting need to be in the hash table, because we
9362 also have the parent/sibling/child chains; only those that we
9363 might refer to by offset later during partial symbol reading.
9365 For now this means things that might have be the target of a
9366 DW_AT_specification, DW_AT_abstract_origin, or
9367 DW_AT_extension. DW_AT_extension will refer only to
9368 namespaces; DW_AT_abstract_origin refers to functions (and
9369 many things under the function DIE, but we do not recurse
9370 into function DIEs during partial symbol reading) and
9371 possibly variables as well; DW_AT_specification refers to
9372 declarations. Declarations ought to have the DW_AT_declaration
9373 flag. It happens that GCC forgets to put it in sometimes, but
9374 only for functions, not for types.
9376 Adding more things than necessary to the hash table is harmless
9377 except for the performance cost. Adding too few will result in
9378 wasted time in find_partial_die, when we reread the compilation
9379 unit with load_all_dies set. */
9382 || abbrev
->tag
== DW_TAG_constant
9383 || abbrev
->tag
== DW_TAG_subprogram
9384 || abbrev
->tag
== DW_TAG_variable
9385 || abbrev
->tag
== DW_TAG_namespace
9386 || part_die
->is_declaration
)
9390 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9391 part_die
->offset
, INSERT
);
9395 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9396 sizeof (struct partial_die_info
));
9398 /* For some DIEs we want to follow their children (if any). For C
9399 we have no reason to follow the children of structures; for other
9400 languages we have to, so that we can get at method physnames
9401 to infer fully qualified class names, for DW_AT_specification,
9402 and for C++ template arguments. For C++, we also look one level
9403 inside functions to find template arguments (if the name of the
9404 function does not already contain the template arguments).
9406 For Ada, we need to scan the children of subprograms and lexical
9407 blocks as well because Ada allows the definition of nested
9408 entities that could be interesting for the debugger, such as
9409 nested subprograms for instance. */
9410 if (last_die
->has_children
9412 || last_die
->tag
== DW_TAG_namespace
9413 || last_die
->tag
== DW_TAG_module
9414 || last_die
->tag
== DW_TAG_enumeration_type
9415 || (cu
->language
== language_cplus
9416 && last_die
->tag
== DW_TAG_subprogram
9417 && (last_die
->name
== NULL
9418 || strchr (last_die
->name
, '<') == NULL
))
9419 || (cu
->language
!= language_c
9420 && (last_die
->tag
== DW_TAG_class_type
9421 || last_die
->tag
== DW_TAG_interface_type
9422 || last_die
->tag
== DW_TAG_structure_type
9423 || last_die
->tag
== DW_TAG_union_type
))
9424 || (cu
->language
== language_ada
9425 && (last_die
->tag
== DW_TAG_subprogram
9426 || last_die
->tag
== DW_TAG_lexical_block
))))
9429 parent_die
= last_die
;
9433 /* Otherwise we skip to the next sibling, if any. */
9434 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9436 /* Back to the top, do it again. */
9440 /* Read a minimal amount of information into the minimal die structure. */
9443 read_partial_die (struct partial_die_info
*part_die
,
9444 struct abbrev_info
*abbrev
,
9445 unsigned int abbrev_len
, bfd
*abfd
,
9446 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9447 struct dwarf2_cu
*cu
)
9450 struct attribute attr
;
9451 int has_low_pc_attr
= 0;
9452 int has_high_pc_attr
= 0;
9454 memset (part_die
, 0, sizeof (struct partial_die_info
));
9456 part_die
->offset
= info_ptr
- buffer
;
9458 info_ptr
+= abbrev_len
;
9463 part_die
->tag
= abbrev
->tag
;
9464 part_die
->has_children
= abbrev
->has_children
;
9466 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9468 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9470 /* Store the data if it is of an attribute we want to keep in a
9471 partial symbol table. */
9475 switch (part_die
->tag
)
9477 case DW_TAG_compile_unit
:
9478 case DW_TAG_type_unit
:
9479 /* Compilation units have a DW_AT_name that is a filename, not
9480 a source language identifier. */
9481 case DW_TAG_enumeration_type
:
9482 case DW_TAG_enumerator
:
9483 /* These tags always have simple identifiers already; no need
9484 to canonicalize them. */
9485 part_die
->name
= DW_STRING (&attr
);
9489 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9490 &cu
->objfile
->objfile_obstack
);
9494 case DW_AT_linkage_name
:
9495 case DW_AT_MIPS_linkage_name
:
9496 /* Note that both forms of linkage name might appear. We
9497 assume they will be the same, and we only store the last
9499 if (cu
->language
== language_ada
)
9500 part_die
->name
= DW_STRING (&attr
);
9501 part_die
->linkage_name
= DW_STRING (&attr
);
9504 has_low_pc_attr
= 1;
9505 part_die
->lowpc
= DW_ADDR (&attr
);
9508 has_high_pc_attr
= 1;
9509 part_die
->highpc
= DW_ADDR (&attr
);
9511 case DW_AT_location
:
9512 /* Support the .debug_loc offsets. */
9513 if (attr_form_is_block (&attr
))
9515 part_die
->locdesc
= DW_BLOCK (&attr
);
9517 else if (attr_form_is_section_offset (&attr
))
9519 dwarf2_complex_location_expr_complaint ();
9523 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9524 "partial symbol information");
9527 case DW_AT_external
:
9528 part_die
->is_external
= DW_UNSND (&attr
);
9530 case DW_AT_declaration
:
9531 part_die
->is_declaration
= DW_UNSND (&attr
);
9534 part_die
->has_type
= 1;
9536 case DW_AT_abstract_origin
:
9537 case DW_AT_specification
:
9538 case DW_AT_extension
:
9539 part_die
->has_specification
= 1;
9540 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9543 /* Ignore absolute siblings, they might point outside of
9544 the current compile unit. */
9545 if (attr
.form
== DW_FORM_ref_addr
)
9546 complaint (&symfile_complaints
,
9547 _("ignoring absolute DW_AT_sibling"));
9549 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9551 case DW_AT_byte_size
:
9552 part_die
->has_byte_size
= 1;
9554 case DW_AT_calling_convention
:
9555 /* DWARF doesn't provide a way to identify a program's source-level
9556 entry point. DW_AT_calling_convention attributes are only meant
9557 to describe functions' calling conventions.
9559 However, because it's a necessary piece of information in
9560 Fortran, and because DW_CC_program is the only piece of debugging
9561 information whose definition refers to a 'main program' at all,
9562 several compilers have begun marking Fortran main programs with
9563 DW_CC_program --- even when those functions use the standard
9564 calling conventions.
9566 So until DWARF specifies a way to provide this information and
9567 compilers pick up the new representation, we'll support this
9569 if (DW_UNSND (&attr
) == DW_CC_program
9570 && cu
->language
== language_fortran
)
9572 set_main_name (part_die
->name
);
9574 /* As this DIE has a static linkage the name would be difficult
9575 to look up later. */
9576 language_of_main
= language_fortran
;
9584 if (has_low_pc_attr
&& has_high_pc_attr
)
9586 /* When using the GNU linker, .gnu.linkonce. sections are used to
9587 eliminate duplicate copies of functions and vtables and such.
9588 The linker will arbitrarily choose one and discard the others.
9589 The AT_*_pc values for such functions refer to local labels in
9590 these sections. If the section from that file was discarded, the
9591 labels are not in the output, so the relocs get a value of 0.
9592 If this is a discarded function, mark the pc bounds as invalid,
9593 so that GDB will ignore it. */
9594 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9596 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9598 complaint (&symfile_complaints
,
9599 _("DW_AT_low_pc %s is zero "
9600 "for DIE at 0x%x [in module %s]"),
9601 paddress (gdbarch
, part_die
->lowpc
),
9602 part_die
->offset
, cu
->objfile
->name
);
9604 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9605 else if (part_die
->lowpc
>= part_die
->highpc
)
9607 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9609 complaint (&symfile_complaints
,
9610 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9611 "for DIE at 0x%x [in module %s]"),
9612 paddress (gdbarch
, part_die
->lowpc
),
9613 paddress (gdbarch
, part_die
->highpc
),
9614 part_die
->offset
, cu
->objfile
->name
);
9617 part_die
->has_pc_info
= 1;
9623 /* Find a cached partial DIE at OFFSET in CU. */
9625 static struct partial_die_info
*
9626 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9628 struct partial_die_info
*lookup_die
= NULL
;
9629 struct partial_die_info part_die
;
9631 part_die
.offset
= offset
;
9632 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9637 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9638 except in the case of .debug_types DIEs which do not reference
9639 outside their CU (they do however referencing other types via
9640 DW_FORM_ref_sig8). */
9642 static struct partial_die_info
*
9643 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9645 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9646 struct partial_die_info
*pd
= NULL
;
9648 if (cu
->per_cu
->debug_type_section
)
9650 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9656 if (offset_in_cu_p (&cu
->header
, offset
))
9658 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9663 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9665 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9666 load_partial_comp_unit (per_cu
, cu
->objfile
);
9668 per_cu
->cu
->last_used
= 0;
9669 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9671 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9673 struct cleanup
*back_to
;
9674 struct partial_die_info comp_unit_die
;
9675 struct abbrev_info
*abbrev
;
9676 unsigned int bytes_read
;
9679 per_cu
->load_all_dies
= 1;
9681 /* Re-read the DIEs. */
9682 back_to
= make_cleanup (null_cleanup
, 0);
9683 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9685 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9686 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9688 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9689 + per_cu
->cu
->header
.offset
9690 + per_cu
->cu
->header
.first_die_offset
);
9691 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9692 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9693 per_cu
->cu
->objfile
->obfd
,
9694 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9696 if (comp_unit_die
.has_children
)
9697 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9698 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9700 do_cleanups (back_to
);
9702 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9708 internal_error (__FILE__
, __LINE__
,
9709 _("could not find partial DIE 0x%x "
9710 "in cache [from module %s]\n"),
9711 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9715 /* See if we can figure out if the class lives in a namespace. We do
9716 this by looking for a member function; its demangled name will
9717 contain namespace info, if there is any. */
9720 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9721 struct dwarf2_cu
*cu
)
9723 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9724 what template types look like, because the demangler
9725 frequently doesn't give the same name as the debug info. We
9726 could fix this by only using the demangled name to get the
9727 prefix (but see comment in read_structure_type). */
9729 struct partial_die_info
*real_pdi
;
9730 struct partial_die_info
*child_pdi
;
9732 /* If this DIE (this DIE's specification, if any) has a parent, then
9733 we should not do this. We'll prepend the parent's fully qualified
9734 name when we create the partial symbol. */
9736 real_pdi
= struct_pdi
;
9737 while (real_pdi
->has_specification
)
9738 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9740 if (real_pdi
->die_parent
!= NULL
)
9743 for (child_pdi
= struct_pdi
->die_child
;
9745 child_pdi
= child_pdi
->die_sibling
)
9747 if (child_pdi
->tag
== DW_TAG_subprogram
9748 && child_pdi
->linkage_name
!= NULL
)
9750 char *actual_class_name
9751 = language_class_name_from_physname (cu
->language_defn
,
9752 child_pdi
->linkage_name
);
9753 if (actual_class_name
!= NULL
)
9756 = obsavestring (actual_class_name
,
9757 strlen (actual_class_name
),
9758 &cu
->objfile
->objfile_obstack
);
9759 xfree (actual_class_name
);
9766 /* Adjust PART_DIE before generating a symbol for it. This function
9767 may set the is_external flag or change the DIE's name. */
9770 fixup_partial_die (struct partial_die_info
*part_die
,
9771 struct dwarf2_cu
*cu
)
9773 /* Once we've fixed up a die, there's no point in doing so again.
9774 This also avoids a memory leak if we were to call
9775 guess_partial_die_structure_name multiple times. */
9776 if (part_die
->fixup_called
)
9779 /* If we found a reference attribute and the DIE has no name, try
9780 to find a name in the referred to DIE. */
9782 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9784 struct partial_die_info
*spec_die
;
9786 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9788 fixup_partial_die (spec_die
, cu
);
9792 part_die
->name
= spec_die
->name
;
9794 /* Copy DW_AT_external attribute if it is set. */
9795 if (spec_die
->is_external
)
9796 part_die
->is_external
= spec_die
->is_external
;
9800 /* Set default names for some unnamed DIEs. */
9802 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9803 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9805 /* If there is no parent die to provide a namespace, and there are
9806 children, see if we can determine the namespace from their linkage
9808 NOTE: We need to do this even if cu->has_namespace_info != 0.
9809 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9810 if (cu
->language
== language_cplus
9811 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
9812 && part_die
->die_parent
== NULL
9813 && part_die
->has_children
9814 && (part_die
->tag
== DW_TAG_class_type
9815 || part_die
->tag
== DW_TAG_structure_type
9816 || part_die
->tag
== DW_TAG_union_type
))
9817 guess_partial_die_structure_name (part_die
, cu
);
9819 /* GCC might emit a nameless struct or union that has a linkage
9820 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9821 if (part_die
->name
== NULL
9822 && (part_die
->tag
== DW_TAG_structure_type
9823 || part_die
->tag
== DW_TAG_union_type
9824 || part_die
->tag
== DW_TAG_class_type
)
9825 && part_die
->linkage_name
!= NULL
)
9829 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9832 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9833 &cu
->objfile
->objfile_obstack
);
9838 part_die
->fixup_called
= 1;
9841 /* Read an attribute value described by an attribute form. */
9844 read_attribute_value (struct attribute
*attr
, unsigned form
,
9845 bfd
*abfd
, gdb_byte
*info_ptr
,
9846 struct dwarf2_cu
*cu
)
9848 struct comp_unit_head
*cu_header
= &cu
->header
;
9849 unsigned int bytes_read
;
9850 struct dwarf_block
*blk
;
9855 case DW_FORM_ref_addr
:
9856 if (cu
->header
.version
== 2)
9857 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9859 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9860 &cu
->header
, &bytes_read
);
9861 info_ptr
+= bytes_read
;
9864 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9865 info_ptr
+= bytes_read
;
9867 case DW_FORM_block2
:
9868 blk
= dwarf_alloc_block (cu
);
9869 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9871 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9872 info_ptr
+= blk
->size
;
9873 DW_BLOCK (attr
) = blk
;
9875 case DW_FORM_block4
:
9876 blk
= dwarf_alloc_block (cu
);
9877 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9879 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9880 info_ptr
+= blk
->size
;
9881 DW_BLOCK (attr
) = blk
;
9884 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9888 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9892 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9895 case DW_FORM_sec_offset
:
9896 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9897 info_ptr
+= bytes_read
;
9899 case DW_FORM_string
:
9900 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9901 DW_STRING_IS_CANONICAL (attr
) = 0;
9902 info_ptr
+= bytes_read
;
9905 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9907 DW_STRING_IS_CANONICAL (attr
) = 0;
9908 info_ptr
+= bytes_read
;
9910 case DW_FORM_exprloc
:
9912 blk
= dwarf_alloc_block (cu
);
9913 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9914 info_ptr
+= bytes_read
;
9915 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9916 info_ptr
+= blk
->size
;
9917 DW_BLOCK (attr
) = blk
;
9919 case DW_FORM_block1
:
9920 blk
= dwarf_alloc_block (cu
);
9921 blk
->size
= read_1_byte (abfd
, info_ptr
);
9923 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9924 info_ptr
+= blk
->size
;
9925 DW_BLOCK (attr
) = blk
;
9928 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9932 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9935 case DW_FORM_flag_present
:
9936 DW_UNSND (attr
) = 1;
9939 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9940 info_ptr
+= bytes_read
;
9943 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9944 info_ptr
+= bytes_read
;
9947 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9951 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9955 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9959 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9962 case DW_FORM_ref_sig8
:
9963 /* Convert the signature to something we can record in DW_UNSND
9965 NOTE: This is NULL if the type wasn't found. */
9966 DW_SIGNATURED_TYPE (attr
) =
9967 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9970 case DW_FORM_ref_udata
:
9971 DW_ADDR (attr
) = (cu
->header
.offset
9972 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9973 info_ptr
+= bytes_read
;
9975 case DW_FORM_indirect
:
9976 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9977 info_ptr
+= bytes_read
;
9978 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9981 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9982 dwarf_form_name (form
),
9983 bfd_get_filename (abfd
));
9986 /* We have seen instances where the compiler tried to emit a byte
9987 size attribute of -1 which ended up being encoded as an unsigned
9988 0xffffffff. Although 0xffffffff is technically a valid size value,
9989 an object of this size seems pretty unlikely so we can relatively
9990 safely treat these cases as if the size attribute was invalid and
9991 treat them as zero by default. */
9992 if (attr
->name
== DW_AT_byte_size
9993 && form
== DW_FORM_data4
9994 && DW_UNSND (attr
) >= 0xffffffff)
9997 (&symfile_complaints
,
9998 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9999 hex_string (DW_UNSND (attr
)));
10000 DW_UNSND (attr
) = 0;
10006 /* Read an attribute described by an abbreviated attribute. */
10009 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10010 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10012 attr
->name
= abbrev
->name
;
10013 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10016 /* Read dwarf information from a buffer. */
10018 static unsigned int
10019 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10021 return bfd_get_8 (abfd
, buf
);
10025 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10027 return bfd_get_signed_8 (abfd
, buf
);
10030 static unsigned int
10031 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10033 return bfd_get_16 (abfd
, buf
);
10037 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10039 return bfd_get_signed_16 (abfd
, buf
);
10042 static unsigned int
10043 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10045 return bfd_get_32 (abfd
, buf
);
10049 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10051 return bfd_get_signed_32 (abfd
, buf
);
10055 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10057 return bfd_get_64 (abfd
, buf
);
10061 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10062 unsigned int *bytes_read
)
10064 struct comp_unit_head
*cu_header
= &cu
->header
;
10065 CORE_ADDR retval
= 0;
10067 if (cu_header
->signed_addr_p
)
10069 switch (cu_header
->addr_size
)
10072 retval
= bfd_get_signed_16 (abfd
, buf
);
10075 retval
= bfd_get_signed_32 (abfd
, buf
);
10078 retval
= bfd_get_signed_64 (abfd
, buf
);
10081 internal_error (__FILE__
, __LINE__
,
10082 _("read_address: bad switch, signed [in module %s]"),
10083 bfd_get_filename (abfd
));
10088 switch (cu_header
->addr_size
)
10091 retval
= bfd_get_16 (abfd
, buf
);
10094 retval
= bfd_get_32 (abfd
, buf
);
10097 retval
= bfd_get_64 (abfd
, buf
);
10100 internal_error (__FILE__
, __LINE__
,
10101 _("read_address: bad switch, "
10102 "unsigned [in module %s]"),
10103 bfd_get_filename (abfd
));
10107 *bytes_read
= cu_header
->addr_size
;
10111 /* Read the initial length from a section. The (draft) DWARF 3
10112 specification allows the initial length to take up either 4 bytes
10113 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10114 bytes describe the length and all offsets will be 8 bytes in length
10117 An older, non-standard 64-bit format is also handled by this
10118 function. The older format in question stores the initial length
10119 as an 8-byte quantity without an escape value. Lengths greater
10120 than 2^32 aren't very common which means that the initial 4 bytes
10121 is almost always zero. Since a length value of zero doesn't make
10122 sense for the 32-bit format, this initial zero can be considered to
10123 be an escape value which indicates the presence of the older 64-bit
10124 format. As written, the code can't detect (old format) lengths
10125 greater than 4GB. If it becomes necessary to handle lengths
10126 somewhat larger than 4GB, we could allow other small values (such
10127 as the non-sensical values of 1, 2, and 3) to also be used as
10128 escape values indicating the presence of the old format.
10130 The value returned via bytes_read should be used to increment the
10131 relevant pointer after calling read_initial_length().
10133 [ Note: read_initial_length() and read_offset() are based on the
10134 document entitled "DWARF Debugging Information Format", revision
10135 3, draft 8, dated November 19, 2001. This document was obtained
10138 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10140 This document is only a draft and is subject to change. (So beware.)
10142 Details regarding the older, non-standard 64-bit format were
10143 determined empirically by examining 64-bit ELF files produced by
10144 the SGI toolchain on an IRIX 6.5 machine.
10146 - Kevin, July 16, 2002
10150 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10152 LONGEST length
= bfd_get_32 (abfd
, buf
);
10154 if (length
== 0xffffffff)
10156 length
= bfd_get_64 (abfd
, buf
+ 4);
10159 else if (length
== 0)
10161 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10162 length
= bfd_get_64 (abfd
, buf
);
10173 /* Cover function for read_initial_length.
10174 Returns the length of the object at BUF, and stores the size of the
10175 initial length in *BYTES_READ and stores the size that offsets will be in
10177 If the initial length size is not equivalent to that specified in
10178 CU_HEADER then issue a complaint.
10179 This is useful when reading non-comp-unit headers. */
10182 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10183 const struct comp_unit_head
*cu_header
,
10184 unsigned int *bytes_read
,
10185 unsigned int *offset_size
)
10187 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10189 gdb_assert (cu_header
->initial_length_size
== 4
10190 || cu_header
->initial_length_size
== 8
10191 || cu_header
->initial_length_size
== 12);
10193 if (cu_header
->initial_length_size
!= *bytes_read
)
10194 complaint (&symfile_complaints
,
10195 _("intermixed 32-bit and 64-bit DWARF sections"));
10197 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10201 /* Read an offset from the data stream. The size of the offset is
10202 given by cu_header->offset_size. */
10205 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10206 unsigned int *bytes_read
)
10208 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10210 *bytes_read
= cu_header
->offset_size
;
10214 /* Read an offset from the data stream. */
10217 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10219 LONGEST retval
= 0;
10221 switch (offset_size
)
10224 retval
= bfd_get_32 (abfd
, buf
);
10227 retval
= bfd_get_64 (abfd
, buf
);
10230 internal_error (__FILE__
, __LINE__
,
10231 _("read_offset_1: bad switch [in module %s]"),
10232 bfd_get_filename (abfd
));
10239 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10241 /* If the size of a host char is 8 bits, we can return a pointer
10242 to the buffer, otherwise we have to copy the data to a buffer
10243 allocated on the temporary obstack. */
10244 gdb_assert (HOST_CHAR_BIT
== 8);
10249 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10251 /* If the size of a host char is 8 bits, we can return a pointer
10252 to the string, otherwise we have to copy the string to a buffer
10253 allocated on the temporary obstack. */
10254 gdb_assert (HOST_CHAR_BIT
== 8);
10257 *bytes_read_ptr
= 1;
10260 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10261 return (char *) buf
;
10265 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10266 const struct comp_unit_head
*cu_header
,
10267 unsigned int *bytes_read_ptr
)
10269 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10271 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10272 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10274 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10275 bfd_get_filename (abfd
));
10278 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10280 error (_("DW_FORM_strp pointing outside of "
10281 ".debug_str section [in module %s]"),
10282 bfd_get_filename (abfd
));
10285 gdb_assert (HOST_CHAR_BIT
== 8);
10286 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10288 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10291 static unsigned long
10292 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10294 unsigned long result
;
10295 unsigned int num_read
;
10297 unsigned char byte
;
10305 byte
= bfd_get_8 (abfd
, buf
);
10308 result
|= ((unsigned long)(byte
& 127) << shift
);
10309 if ((byte
& 128) == 0)
10315 *bytes_read_ptr
= num_read
;
10320 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10323 int i
, shift
, num_read
;
10324 unsigned char byte
;
10332 byte
= bfd_get_8 (abfd
, buf
);
10335 result
|= ((long)(byte
& 127) << shift
);
10337 if ((byte
& 128) == 0)
10342 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10343 result
|= -(((long)1) << shift
);
10344 *bytes_read_ptr
= num_read
;
10348 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10351 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10357 byte
= bfd_get_8 (abfd
, buf
);
10359 if ((byte
& 128) == 0)
10365 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10372 cu
->language
= language_c
;
10374 case DW_LANG_C_plus_plus
:
10375 cu
->language
= language_cplus
;
10378 cu
->language
= language_d
;
10380 case DW_LANG_Fortran77
:
10381 case DW_LANG_Fortran90
:
10382 case DW_LANG_Fortran95
:
10383 cu
->language
= language_fortran
;
10385 case DW_LANG_Mips_Assembler
:
10386 cu
->language
= language_asm
;
10389 cu
->language
= language_java
;
10391 case DW_LANG_Ada83
:
10392 case DW_LANG_Ada95
:
10393 cu
->language
= language_ada
;
10395 case DW_LANG_Modula2
:
10396 cu
->language
= language_m2
;
10398 case DW_LANG_Pascal83
:
10399 cu
->language
= language_pascal
;
10402 cu
->language
= language_objc
;
10404 case DW_LANG_Cobol74
:
10405 case DW_LANG_Cobol85
:
10407 cu
->language
= language_minimal
;
10410 cu
->language_defn
= language_def (cu
->language
);
10413 /* Return the named attribute or NULL if not there. */
10415 static struct attribute
*
10416 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10419 struct attribute
*spec
= NULL
;
10421 for (i
= 0; i
< die
->num_attrs
; ++i
)
10423 if (die
->attrs
[i
].name
== name
)
10424 return &die
->attrs
[i
];
10425 if (die
->attrs
[i
].name
== DW_AT_specification
10426 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10427 spec
= &die
->attrs
[i
];
10432 die
= follow_die_ref (die
, spec
, &cu
);
10433 return dwarf2_attr (die
, name
, cu
);
10439 /* Return the named attribute or NULL if not there,
10440 but do not follow DW_AT_specification, etc.
10441 This is for use in contexts where we're reading .debug_types dies.
10442 Following DW_AT_specification, DW_AT_abstract_origin will take us
10443 back up the chain, and we want to go down. */
10445 static struct attribute
*
10446 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10447 struct dwarf2_cu
*cu
)
10451 for (i
= 0; i
< die
->num_attrs
; ++i
)
10452 if (die
->attrs
[i
].name
== name
)
10453 return &die
->attrs
[i
];
10458 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10459 and holds a non-zero value. This function should only be used for
10460 DW_FORM_flag or DW_FORM_flag_present attributes. */
10463 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10465 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10467 return (attr
&& DW_UNSND (attr
));
10471 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10473 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10474 which value is non-zero. However, we have to be careful with
10475 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10476 (via dwarf2_flag_true_p) follows this attribute. So we may
10477 end up accidently finding a declaration attribute that belongs
10478 to a different DIE referenced by the specification attribute,
10479 even though the given DIE does not have a declaration attribute. */
10480 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10481 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10484 /* Return the die giving the specification for DIE, if there is
10485 one. *SPEC_CU is the CU containing DIE on input, and the CU
10486 containing the return value on output. If there is no
10487 specification, but there is an abstract origin, that is
10490 static struct die_info
*
10491 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10493 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10496 if (spec_attr
== NULL
)
10497 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10499 if (spec_attr
== NULL
)
10502 return follow_die_ref (die
, spec_attr
, spec_cu
);
10505 /* Free the line_header structure *LH, and any arrays and strings it
10507 NOTE: This is also used as a "cleanup" function. */
10510 free_line_header (struct line_header
*lh
)
10512 if (lh
->standard_opcode_lengths
)
10513 xfree (lh
->standard_opcode_lengths
);
10515 /* Remember that all the lh->file_names[i].name pointers are
10516 pointers into debug_line_buffer, and don't need to be freed. */
10517 if (lh
->file_names
)
10518 xfree (lh
->file_names
);
10520 /* Similarly for the include directory names. */
10521 if (lh
->include_dirs
)
10522 xfree (lh
->include_dirs
);
10527 /* Add an entry to LH's include directory table. */
10530 add_include_dir (struct line_header
*lh
, char *include_dir
)
10532 /* Grow the array if necessary. */
10533 if (lh
->include_dirs_size
== 0)
10535 lh
->include_dirs_size
= 1; /* for testing */
10536 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10537 * sizeof (*lh
->include_dirs
));
10539 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10541 lh
->include_dirs_size
*= 2;
10542 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10543 (lh
->include_dirs_size
10544 * sizeof (*lh
->include_dirs
)));
10547 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10550 /* Add an entry to LH's file name table. */
10553 add_file_name (struct line_header
*lh
,
10555 unsigned int dir_index
,
10556 unsigned int mod_time
,
10557 unsigned int length
)
10559 struct file_entry
*fe
;
10561 /* Grow the array if necessary. */
10562 if (lh
->file_names_size
== 0)
10564 lh
->file_names_size
= 1; /* for testing */
10565 lh
->file_names
= xmalloc (lh
->file_names_size
10566 * sizeof (*lh
->file_names
));
10568 else if (lh
->num_file_names
>= lh
->file_names_size
)
10570 lh
->file_names_size
*= 2;
10571 lh
->file_names
= xrealloc (lh
->file_names
,
10572 (lh
->file_names_size
10573 * sizeof (*lh
->file_names
)));
10576 fe
= &lh
->file_names
[lh
->num_file_names
++];
10578 fe
->dir_index
= dir_index
;
10579 fe
->mod_time
= mod_time
;
10580 fe
->length
= length
;
10581 fe
->included_p
= 0;
10585 /* Read the statement program header starting at OFFSET in
10586 .debug_line, according to the endianness of ABFD. Return a pointer
10587 to a struct line_header, allocated using xmalloc.
10589 NOTE: the strings in the include directory and file name tables of
10590 the returned object point into debug_line_buffer, and must not be
10593 static struct line_header
*
10594 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10595 struct dwarf2_cu
*cu
)
10597 struct cleanup
*back_to
;
10598 struct line_header
*lh
;
10599 gdb_byte
*line_ptr
;
10600 unsigned int bytes_read
, offset_size
;
10602 char *cur_dir
, *cur_file
;
10604 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10605 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10607 complaint (&symfile_complaints
, _("missing .debug_line section"));
10611 /* Make sure that at least there's room for the total_length field.
10612 That could be 12 bytes long, but we're just going to fudge that. */
10613 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10615 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10619 lh
= xmalloc (sizeof (*lh
));
10620 memset (lh
, 0, sizeof (*lh
));
10621 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10624 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10626 /* Read in the header. */
10628 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10629 &bytes_read
, &offset_size
);
10630 line_ptr
+= bytes_read
;
10631 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10632 + dwarf2_per_objfile
->line
.size
))
10634 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10637 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10638 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10640 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10641 line_ptr
+= offset_size
;
10642 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10644 if (lh
->version
>= 4)
10646 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10650 lh
->maximum_ops_per_instruction
= 1;
10652 if (lh
->maximum_ops_per_instruction
== 0)
10654 lh
->maximum_ops_per_instruction
= 1;
10655 complaint (&symfile_complaints
,
10656 _("invalid maximum_ops_per_instruction "
10657 "in `.debug_line' section"));
10660 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10662 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10664 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10666 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10668 lh
->standard_opcode_lengths
10669 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10671 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10672 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10674 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10678 /* Read directory table. */
10679 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10681 line_ptr
+= bytes_read
;
10682 add_include_dir (lh
, cur_dir
);
10684 line_ptr
+= bytes_read
;
10686 /* Read file name table. */
10687 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10689 unsigned int dir_index
, mod_time
, length
;
10691 line_ptr
+= bytes_read
;
10692 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10693 line_ptr
+= bytes_read
;
10694 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10695 line_ptr
+= bytes_read
;
10696 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10697 line_ptr
+= bytes_read
;
10699 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10701 line_ptr
+= bytes_read
;
10702 lh
->statement_program_start
= line_ptr
;
10704 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10705 + dwarf2_per_objfile
->line
.size
))
10706 complaint (&symfile_complaints
,
10707 _("line number info header doesn't "
10708 "fit in `.debug_line' section"));
10710 discard_cleanups (back_to
);
10714 /* This function exists to work around a bug in certain compilers
10715 (particularly GCC 2.95), in which the first line number marker of a
10716 function does not show up until after the prologue, right before
10717 the second line number marker. This function shifts ADDRESS down
10718 to the beginning of the function if necessary, and is called on
10719 addresses passed to record_line. */
10722 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10724 struct function_range
*fn
;
10726 /* Find the function_range containing address. */
10730 if (!cu
->cached_fn
)
10731 cu
->cached_fn
= cu
->first_fn
;
10733 fn
= cu
->cached_fn
;
10735 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10741 while (fn
&& fn
!= cu
->cached_fn
)
10742 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10752 if (address
!= fn
->lowpc
)
10753 complaint (&symfile_complaints
,
10754 _("misplaced first line number at 0x%lx for '%s'"),
10755 (unsigned long) address
, fn
->name
);
10760 /* Subroutine of dwarf_decode_lines to simplify it.
10761 Return the file name of the psymtab for included file FILE_INDEX
10762 in line header LH of PST.
10763 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10764 If space for the result is malloc'd, it will be freed by a cleanup.
10765 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10768 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10769 const struct partial_symtab
*pst
,
10770 const char *comp_dir
)
10772 const struct file_entry fe
= lh
->file_names
[file_index
];
10773 char *include_name
= fe
.name
;
10774 char *include_name_to_compare
= include_name
;
10775 char *dir_name
= NULL
;
10776 const char *pst_filename
;
10777 char *copied_name
= NULL
;
10781 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10783 if (!IS_ABSOLUTE_PATH (include_name
)
10784 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10786 /* Avoid creating a duplicate psymtab for PST.
10787 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10788 Before we do the comparison, however, we need to account
10789 for DIR_NAME and COMP_DIR.
10790 First prepend dir_name (if non-NULL). If we still don't
10791 have an absolute path prepend comp_dir (if non-NULL).
10792 However, the directory we record in the include-file's
10793 psymtab does not contain COMP_DIR (to match the
10794 corresponding symtab(s)).
10799 bash$ gcc -g ./hello.c
10800 include_name = "hello.c"
10802 DW_AT_comp_dir = comp_dir = "/tmp"
10803 DW_AT_name = "./hello.c" */
10805 if (dir_name
!= NULL
)
10807 include_name
= concat (dir_name
, SLASH_STRING
,
10808 include_name
, (char *)NULL
);
10809 include_name_to_compare
= include_name
;
10810 make_cleanup (xfree
, include_name
);
10812 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10814 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10815 include_name
, (char *)NULL
);
10819 pst_filename
= pst
->filename
;
10820 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10822 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10823 pst_filename
, (char *)NULL
);
10824 pst_filename
= copied_name
;
10827 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10829 if (include_name_to_compare
!= include_name
)
10830 xfree (include_name_to_compare
);
10831 if (copied_name
!= NULL
)
10832 xfree (copied_name
);
10836 return include_name
;
10839 /* Ignore this record_line request. */
10842 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10847 /* Decode the Line Number Program (LNP) for the given line_header
10848 structure and CU. The actual information extracted and the type
10849 of structures created from the LNP depends on the value of PST.
10851 1. If PST is NULL, then this procedure uses the data from the program
10852 to create all necessary symbol tables, and their linetables.
10854 2. If PST is not NULL, this procedure reads the program to determine
10855 the list of files included by the unit represented by PST, and
10856 builds all the associated partial symbol tables.
10858 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10859 It is used for relative paths in the line table.
10860 NOTE: When processing partial symtabs (pst != NULL),
10861 comp_dir == pst->dirname.
10863 NOTE: It is important that psymtabs have the same file name (via strcmp)
10864 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10865 symtab we don't use it in the name of the psymtabs we create.
10866 E.g. expand_line_sal requires this when finding psymtabs to expand.
10867 A good testcase for this is mb-inline.exp. */
10870 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10871 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10873 gdb_byte
*line_ptr
, *extended_end
;
10874 gdb_byte
*line_end
;
10875 unsigned int bytes_read
, extended_len
;
10876 unsigned char op_code
, extended_op
, adj_opcode
;
10877 CORE_ADDR baseaddr
;
10878 struct objfile
*objfile
= cu
->objfile
;
10879 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10880 const int decode_for_pst_p
= (pst
!= NULL
);
10881 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10882 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10885 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10887 line_ptr
= lh
->statement_program_start
;
10888 line_end
= lh
->statement_program_end
;
10890 /* Read the statement sequences until there's nothing left. */
10891 while (line_ptr
< line_end
)
10893 /* state machine registers */
10894 CORE_ADDR address
= 0;
10895 unsigned int file
= 1;
10896 unsigned int line
= 1;
10897 unsigned int column
= 0;
10898 int is_stmt
= lh
->default_is_stmt
;
10899 int basic_block
= 0;
10900 int end_sequence
= 0;
10902 unsigned char op_index
= 0;
10904 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10906 /* Start a subfile for the current file of the state machine. */
10907 /* lh->include_dirs and lh->file_names are 0-based, but the
10908 directory and file name numbers in the statement program
10910 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10914 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10916 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10919 /* Decode the table. */
10920 while (!end_sequence
)
10922 op_code
= read_1_byte (abfd
, line_ptr
);
10924 if (line_ptr
> line_end
)
10926 dwarf2_debug_line_missing_end_sequence_complaint ();
10930 if (op_code
>= lh
->opcode_base
)
10932 /* Special operand. */
10933 adj_opcode
= op_code
- lh
->opcode_base
;
10934 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10935 / lh
->maximum_ops_per_instruction
)
10936 * lh
->minimum_instruction_length
);
10937 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10938 % lh
->maximum_ops_per_instruction
);
10939 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10940 if (lh
->num_file_names
< file
|| file
== 0)
10941 dwarf2_debug_line_missing_file_complaint ();
10942 /* For now we ignore lines not starting on an
10943 instruction boundary. */
10944 else if (op_index
== 0)
10946 lh
->file_names
[file
- 1].included_p
= 1;
10947 if (!decode_for_pst_p
&& is_stmt
)
10949 if (last_subfile
!= current_subfile
)
10951 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10953 (*p_record_line
) (last_subfile
, 0, addr
);
10954 last_subfile
= current_subfile
;
10956 /* Append row to matrix using current values. */
10957 addr
= check_cu_functions (address
, cu
);
10958 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10959 (*p_record_line
) (current_subfile
, line
, addr
);
10964 else switch (op_code
)
10966 case DW_LNS_extended_op
:
10967 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10969 line_ptr
+= bytes_read
;
10970 extended_end
= line_ptr
+ extended_len
;
10971 extended_op
= read_1_byte (abfd
, line_ptr
);
10973 switch (extended_op
)
10975 case DW_LNE_end_sequence
:
10976 p_record_line
= record_line
;
10979 case DW_LNE_set_address
:
10980 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10982 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10984 /* This line table is for a function which has been
10985 GCd by the linker. Ignore it. PR gdb/12528 */
10988 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10990 complaint (&symfile_complaints
,
10991 _(".debug_line address at offset 0x%lx is 0 "
10993 line_offset
, cu
->objfile
->name
);
10994 p_record_line
= noop_record_line
;
10998 line_ptr
+= bytes_read
;
10999 address
+= baseaddr
;
11001 case DW_LNE_define_file
:
11004 unsigned int dir_index
, mod_time
, length
;
11006 cur_file
= read_direct_string (abfd
, line_ptr
,
11008 line_ptr
+= bytes_read
;
11010 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11011 line_ptr
+= bytes_read
;
11013 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11014 line_ptr
+= bytes_read
;
11016 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11017 line_ptr
+= bytes_read
;
11018 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11021 case DW_LNE_set_discriminator
:
11022 /* The discriminator is not interesting to the debugger;
11024 line_ptr
= extended_end
;
11027 complaint (&symfile_complaints
,
11028 _("mangled .debug_line section"));
11031 /* Make sure that we parsed the extended op correctly. If e.g.
11032 we expected a different address size than the producer used,
11033 we may have read the wrong number of bytes. */
11034 if (line_ptr
!= extended_end
)
11036 complaint (&symfile_complaints
,
11037 _("mangled .debug_line section"));
11042 if (lh
->num_file_names
< file
|| file
== 0)
11043 dwarf2_debug_line_missing_file_complaint ();
11046 lh
->file_names
[file
- 1].included_p
= 1;
11047 if (!decode_for_pst_p
&& is_stmt
)
11049 if (last_subfile
!= current_subfile
)
11051 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11053 (*p_record_line
) (last_subfile
, 0, addr
);
11054 last_subfile
= current_subfile
;
11056 addr
= check_cu_functions (address
, cu
);
11057 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11058 (*p_record_line
) (current_subfile
, line
, addr
);
11063 case DW_LNS_advance_pc
:
11066 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11068 address
+= (((op_index
+ adjust
)
11069 / lh
->maximum_ops_per_instruction
)
11070 * lh
->minimum_instruction_length
);
11071 op_index
= ((op_index
+ adjust
)
11072 % lh
->maximum_ops_per_instruction
);
11073 line_ptr
+= bytes_read
;
11076 case DW_LNS_advance_line
:
11077 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11078 line_ptr
+= bytes_read
;
11080 case DW_LNS_set_file
:
11082 /* The arrays lh->include_dirs and lh->file_names are
11083 0-based, but the directory and file name numbers in
11084 the statement program are 1-based. */
11085 struct file_entry
*fe
;
11088 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11089 line_ptr
+= bytes_read
;
11090 if (lh
->num_file_names
< file
|| file
== 0)
11091 dwarf2_debug_line_missing_file_complaint ();
11094 fe
= &lh
->file_names
[file
- 1];
11096 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11097 if (!decode_for_pst_p
)
11099 last_subfile
= current_subfile
;
11100 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11105 case DW_LNS_set_column
:
11106 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11107 line_ptr
+= bytes_read
;
11109 case DW_LNS_negate_stmt
:
11110 is_stmt
= (!is_stmt
);
11112 case DW_LNS_set_basic_block
:
11115 /* Add to the address register of the state machine the
11116 address increment value corresponding to special opcode
11117 255. I.e., this value is scaled by the minimum
11118 instruction length since special opcode 255 would have
11119 scaled the increment. */
11120 case DW_LNS_const_add_pc
:
11122 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11124 address
+= (((op_index
+ adjust
)
11125 / lh
->maximum_ops_per_instruction
)
11126 * lh
->minimum_instruction_length
);
11127 op_index
= ((op_index
+ adjust
)
11128 % lh
->maximum_ops_per_instruction
);
11131 case DW_LNS_fixed_advance_pc
:
11132 address
+= read_2_bytes (abfd
, line_ptr
);
11138 /* Unknown standard opcode, ignore it. */
11141 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11143 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11144 line_ptr
+= bytes_read
;
11149 if (lh
->num_file_names
< file
|| file
== 0)
11150 dwarf2_debug_line_missing_file_complaint ();
11153 lh
->file_names
[file
- 1].included_p
= 1;
11154 if (!decode_for_pst_p
)
11156 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11157 (*p_record_line
) (current_subfile
, 0, addr
);
11162 if (decode_for_pst_p
)
11166 /* Now that we're done scanning the Line Header Program, we can
11167 create the psymtab of each included file. */
11168 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11169 if (lh
->file_names
[file_index
].included_p
== 1)
11171 char *include_name
=
11172 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11173 if (include_name
!= NULL
)
11174 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11179 /* Make sure a symtab is created for every file, even files
11180 which contain only variables (i.e. no code with associated
11184 struct file_entry
*fe
;
11186 for (i
= 0; i
< lh
->num_file_names
; i
++)
11190 fe
= &lh
->file_names
[i
];
11192 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11193 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11195 /* Skip the main file; we don't need it, and it must be
11196 allocated last, so that it will show up before the
11197 non-primary symtabs in the objfile's symtab list. */
11198 if (current_subfile
== first_subfile
)
11201 if (current_subfile
->symtab
== NULL
)
11202 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11204 fe
->symtab
= current_subfile
->symtab
;
11209 /* Start a subfile for DWARF. FILENAME is the name of the file and
11210 DIRNAME the name of the source directory which contains FILENAME
11211 or NULL if not known. COMP_DIR is the compilation directory for the
11212 linetable's compilation unit or NULL if not known.
11213 This routine tries to keep line numbers from identical absolute and
11214 relative file names in a common subfile.
11216 Using the `list' example from the GDB testsuite, which resides in
11217 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11218 of /srcdir/list0.c yields the following debugging information for list0.c:
11220 DW_AT_name: /srcdir/list0.c
11221 DW_AT_comp_dir: /compdir
11222 files.files[0].name: list0.h
11223 files.files[0].dir: /srcdir
11224 files.files[1].name: list0.c
11225 files.files[1].dir: /srcdir
11227 The line number information for list0.c has to end up in a single
11228 subfile, so that `break /srcdir/list0.c:1' works as expected.
11229 start_subfile will ensure that this happens provided that we pass the
11230 concatenation of files.files[1].dir and files.files[1].name as the
11234 dwarf2_start_subfile (char *filename
, const char *dirname
,
11235 const char *comp_dir
)
11239 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11240 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11241 second argument to start_subfile. To be consistent, we do the
11242 same here. In order not to lose the line information directory,
11243 we concatenate it to the filename when it makes sense.
11244 Note that the Dwarf3 standard says (speaking of filenames in line
11245 information): ``The directory index is ignored for file names
11246 that represent full path names''. Thus ignoring dirname in the
11247 `else' branch below isn't an issue. */
11249 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11250 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11252 fullname
= filename
;
11254 start_subfile (fullname
, comp_dir
);
11256 if (fullname
!= filename
)
11261 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11262 struct dwarf2_cu
*cu
)
11264 struct objfile
*objfile
= cu
->objfile
;
11265 struct comp_unit_head
*cu_header
= &cu
->header
;
11267 /* NOTE drow/2003-01-30: There used to be a comment and some special
11268 code here to turn a symbol with DW_AT_external and a
11269 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11270 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11271 with some versions of binutils) where shared libraries could have
11272 relocations against symbols in their debug information - the
11273 minimal symbol would have the right address, but the debug info
11274 would not. It's no longer necessary, because we will explicitly
11275 apply relocations when we read in the debug information now. */
11277 /* A DW_AT_location attribute with no contents indicates that a
11278 variable has been optimized away. */
11279 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11281 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11285 /* Handle one degenerate form of location expression specially, to
11286 preserve GDB's previous behavior when section offsets are
11287 specified. If this is just a DW_OP_addr then mark this symbol
11290 if (attr_form_is_block (attr
)
11291 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11292 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11294 unsigned int dummy
;
11296 SYMBOL_VALUE_ADDRESS (sym
) =
11297 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11298 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11299 fixup_symbol_section (sym
, objfile
);
11300 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11301 SYMBOL_SECTION (sym
));
11305 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11306 expression evaluator, and use LOC_COMPUTED only when necessary
11307 (i.e. when the value of a register or memory location is
11308 referenced, or a thread-local block, etc.). Then again, it might
11309 not be worthwhile. I'm assuming that it isn't unless performance
11310 or memory numbers show me otherwise. */
11312 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11313 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11315 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11316 cu
->has_loclist
= 1;
11319 /* Given a pointer to a DWARF information entry, figure out if we need
11320 to make a symbol table entry for it, and if so, create a new entry
11321 and return a pointer to it.
11322 If TYPE is NULL, determine symbol type from the die, otherwise
11323 used the passed type.
11324 If SPACE is not NULL, use it to hold the new symbol. If it is
11325 NULL, allocate a new symbol on the objfile's obstack. */
11327 static struct symbol
*
11328 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11329 struct symbol
*space
)
11331 struct objfile
*objfile
= cu
->objfile
;
11332 struct symbol
*sym
= NULL
;
11334 struct attribute
*attr
= NULL
;
11335 struct attribute
*attr2
= NULL
;
11336 CORE_ADDR baseaddr
;
11337 struct pending
**list_to_add
= NULL
;
11339 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11341 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11343 name
= dwarf2_name (die
, cu
);
11346 const char *linkagename
;
11347 int suppress_add
= 0;
11352 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11353 OBJSTAT (objfile
, n_syms
++);
11355 /* Cache this symbol's name and the name's demangled form (if any). */
11356 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11357 linkagename
= dwarf2_physname (name
, die
, cu
);
11358 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11360 /* Fortran does not have mangling standard and the mangling does differ
11361 between gfortran, iFort etc. */
11362 if (cu
->language
== language_fortran
11363 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11364 symbol_set_demangled_name (&(sym
->ginfo
),
11365 (char *) dwarf2_full_name (name
, die
, cu
),
11368 /* Default assumptions.
11369 Use the passed type or decode it from the die. */
11370 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11371 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11373 SYMBOL_TYPE (sym
) = type
;
11375 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11376 attr
= dwarf2_attr (die
,
11377 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11381 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11384 attr
= dwarf2_attr (die
,
11385 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11389 int file_index
= DW_UNSND (attr
);
11391 if (cu
->line_header
== NULL
11392 || file_index
> cu
->line_header
->num_file_names
)
11393 complaint (&symfile_complaints
,
11394 _("file index out of range"));
11395 else if (file_index
> 0)
11397 struct file_entry
*fe
;
11399 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11400 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11407 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11410 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11412 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11413 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11414 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11415 add_symbol_to_list (sym
, cu
->list_in_scope
);
11417 case DW_TAG_subprogram
:
11418 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11420 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11421 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11422 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11423 || cu
->language
== language_ada
)
11425 /* Subprograms marked external are stored as a global symbol.
11426 Ada subprograms, whether marked external or not, are always
11427 stored as a global symbol, because we want to be able to
11428 access them globally. For instance, we want to be able
11429 to break on a nested subprogram without having to
11430 specify the context. */
11431 list_to_add
= &global_symbols
;
11435 list_to_add
= cu
->list_in_scope
;
11438 case DW_TAG_inlined_subroutine
:
11439 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11441 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11442 SYMBOL_INLINED (sym
) = 1;
11443 /* Do not add the symbol to any lists. It will be found via
11444 BLOCK_FUNCTION from the blockvector. */
11446 case DW_TAG_template_value_param
:
11448 /* Fall through. */
11449 case DW_TAG_constant
:
11450 case DW_TAG_variable
:
11451 case DW_TAG_member
:
11452 /* Compilation with minimal debug info may result in
11453 variables with missing type entries. Change the
11454 misleading `void' type to something sensible. */
11455 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11457 = objfile_type (objfile
)->nodebug_data_symbol
;
11459 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11460 /* In the case of DW_TAG_member, we should only be called for
11461 static const members. */
11462 if (die
->tag
== DW_TAG_member
)
11464 /* dwarf2_add_field uses die_is_declaration,
11465 so we do the same. */
11466 gdb_assert (die_is_declaration (die
, cu
));
11471 dwarf2_const_value (attr
, sym
, cu
);
11472 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11475 if (attr2
&& (DW_UNSND (attr2
) != 0))
11476 list_to_add
= &global_symbols
;
11478 list_to_add
= cu
->list_in_scope
;
11482 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11485 var_decode_location (attr
, sym
, cu
);
11486 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11487 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11488 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11489 && !dwarf2_per_objfile
->has_section_at_zero
)
11491 /* When a static variable is eliminated by the linker,
11492 the corresponding debug information is not stripped
11493 out, but the variable address is set to null;
11494 do not add such variables into symbol table. */
11496 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11498 /* Workaround gfortran PR debug/40040 - it uses
11499 DW_AT_location for variables in -fPIC libraries which may
11500 get overriden by other libraries/executable and get
11501 a different address. Resolve it by the minimal symbol
11502 which may come from inferior's executable using copy
11503 relocation. Make this workaround only for gfortran as for
11504 other compilers GDB cannot guess the minimal symbol
11505 Fortran mangling kind. */
11506 if (cu
->language
== language_fortran
&& die
->parent
11507 && die
->parent
->tag
== DW_TAG_module
11509 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11510 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11512 /* A variable with DW_AT_external is never static,
11513 but it may be block-scoped. */
11514 list_to_add
= (cu
->list_in_scope
== &file_symbols
11515 ? &global_symbols
: cu
->list_in_scope
);
11518 list_to_add
= cu
->list_in_scope
;
11522 /* We do not know the address of this symbol.
11523 If it is an external symbol and we have type information
11524 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11525 The address of the variable will then be determined from
11526 the minimal symbol table whenever the variable is
11528 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11529 if (attr2
&& (DW_UNSND (attr2
) != 0)
11530 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11532 /* A variable with DW_AT_external is never static, but it
11533 may be block-scoped. */
11534 list_to_add
= (cu
->list_in_scope
== &file_symbols
11535 ? &global_symbols
: cu
->list_in_scope
);
11537 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11539 else if (!die_is_declaration (die
, cu
))
11541 /* Use the default LOC_OPTIMIZED_OUT class. */
11542 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11544 list_to_add
= cu
->list_in_scope
;
11548 case DW_TAG_formal_parameter
:
11549 /* If we are inside a function, mark this as an argument. If
11550 not, we might be looking at an argument to an inlined function
11551 when we do not have enough information to show inlined frames;
11552 pretend it's a local variable in that case so that the user can
11554 if (context_stack_depth
> 0
11555 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11556 SYMBOL_IS_ARGUMENT (sym
) = 1;
11557 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11560 var_decode_location (attr
, sym
, cu
);
11562 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11565 dwarf2_const_value (attr
, sym
, cu
);
11567 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11568 if (attr
&& DW_UNSND (attr
))
11570 struct type
*ref_type
;
11572 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11573 SYMBOL_TYPE (sym
) = ref_type
;
11576 list_to_add
= cu
->list_in_scope
;
11578 case DW_TAG_unspecified_parameters
:
11579 /* From varargs functions; gdb doesn't seem to have any
11580 interest in this information, so just ignore it for now.
11583 case DW_TAG_template_type_param
:
11585 /* Fall through. */
11586 case DW_TAG_class_type
:
11587 case DW_TAG_interface_type
:
11588 case DW_TAG_structure_type
:
11589 case DW_TAG_union_type
:
11590 case DW_TAG_set_type
:
11591 case DW_TAG_enumeration_type
:
11592 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11593 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11596 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11597 really ever be static objects: otherwise, if you try
11598 to, say, break of a class's method and you're in a file
11599 which doesn't mention that class, it won't work unless
11600 the check for all static symbols in lookup_symbol_aux
11601 saves you. See the OtherFileClass tests in
11602 gdb.c++/namespace.exp. */
11606 list_to_add
= (cu
->list_in_scope
== &file_symbols
11607 && (cu
->language
== language_cplus
11608 || cu
->language
== language_java
)
11609 ? &global_symbols
: cu
->list_in_scope
);
11611 /* The semantics of C++ state that "struct foo {
11612 ... }" also defines a typedef for "foo". A Java
11613 class declaration also defines a typedef for the
11615 if (cu
->language
== language_cplus
11616 || cu
->language
== language_java
11617 || cu
->language
== language_ada
)
11619 /* The symbol's name is already allocated along
11620 with this objfile, so we don't need to
11621 duplicate it for the type. */
11622 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11623 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11628 case DW_TAG_typedef
:
11629 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11630 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11631 list_to_add
= cu
->list_in_scope
;
11633 case DW_TAG_base_type
:
11634 case DW_TAG_subrange_type
:
11635 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11636 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11637 list_to_add
= cu
->list_in_scope
;
11639 case DW_TAG_enumerator
:
11640 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11643 dwarf2_const_value (attr
, sym
, cu
);
11646 /* NOTE: carlton/2003-11-10: See comment above in the
11647 DW_TAG_class_type, etc. block. */
11649 list_to_add
= (cu
->list_in_scope
== &file_symbols
11650 && (cu
->language
== language_cplus
11651 || cu
->language
== language_java
)
11652 ? &global_symbols
: cu
->list_in_scope
);
11655 case DW_TAG_namespace
:
11656 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11657 list_to_add
= &global_symbols
;
11660 /* Not a tag we recognize. Hopefully we aren't processing
11661 trash data, but since we must specifically ignore things
11662 we don't recognize, there is nothing else we should do at
11664 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11665 dwarf_tag_name (die
->tag
));
11671 sym
->hash_next
= objfile
->template_symbols
;
11672 objfile
->template_symbols
= sym
;
11673 list_to_add
= NULL
;
11676 if (list_to_add
!= NULL
)
11677 add_symbol_to_list (sym
, list_to_add
);
11679 /* For the benefit of old versions of GCC, check for anonymous
11680 namespaces based on the demangled name. */
11681 if (!processing_has_namespace_info
11682 && cu
->language
== language_cplus
)
11683 cp_scan_for_anonymous_namespaces (sym
);
11688 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11690 static struct symbol
*
11691 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11693 return new_symbol_full (die
, type
, cu
, NULL
);
11696 /* Given an attr with a DW_FORM_dataN value in host byte order,
11697 zero-extend it as appropriate for the symbol's type. The DWARF
11698 standard (v4) is not entirely clear about the meaning of using
11699 DW_FORM_dataN for a constant with a signed type, where the type is
11700 wider than the data. The conclusion of a discussion on the DWARF
11701 list was that this is unspecified. We choose to always zero-extend
11702 because that is the interpretation long in use by GCC. */
11705 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11706 const char *name
, struct obstack
*obstack
,
11707 struct dwarf2_cu
*cu
, long *value
, int bits
)
11709 struct objfile
*objfile
= cu
->objfile
;
11710 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11711 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11712 LONGEST l
= DW_UNSND (attr
);
11714 if (bits
< sizeof (*value
) * 8)
11716 l
&= ((LONGEST
) 1 << bits
) - 1;
11719 else if (bits
== sizeof (*value
) * 8)
11723 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11724 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11731 /* Read a constant value from an attribute. Either set *VALUE, or if
11732 the value does not fit in *VALUE, set *BYTES - either already
11733 allocated on the objfile obstack, or newly allocated on OBSTACK,
11734 or, set *BATON, if we translated the constant to a location
11738 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11739 const char *name
, struct obstack
*obstack
,
11740 struct dwarf2_cu
*cu
,
11741 long *value
, gdb_byte
**bytes
,
11742 struct dwarf2_locexpr_baton
**baton
)
11744 struct objfile
*objfile
= cu
->objfile
;
11745 struct comp_unit_head
*cu_header
= &cu
->header
;
11746 struct dwarf_block
*blk
;
11747 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11748 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11754 switch (attr
->form
)
11760 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11761 dwarf2_const_value_length_mismatch_complaint (name
,
11762 cu_header
->addr_size
,
11763 TYPE_LENGTH (type
));
11764 /* Symbols of this form are reasonably rare, so we just
11765 piggyback on the existing location code rather than writing
11766 a new implementation of symbol_computed_ops. */
11767 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11768 sizeof (struct dwarf2_locexpr_baton
));
11769 (*baton
)->per_cu
= cu
->per_cu
;
11770 gdb_assert ((*baton
)->per_cu
);
11772 (*baton
)->size
= 2 + cu_header
->addr_size
;
11773 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11774 (*baton
)->data
= data
;
11776 data
[0] = DW_OP_addr
;
11777 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11778 byte_order
, DW_ADDR (attr
));
11779 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11782 case DW_FORM_string
:
11784 /* DW_STRING is already allocated on the objfile obstack, point
11786 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11788 case DW_FORM_block1
:
11789 case DW_FORM_block2
:
11790 case DW_FORM_block4
:
11791 case DW_FORM_block
:
11792 case DW_FORM_exprloc
:
11793 blk
= DW_BLOCK (attr
);
11794 if (TYPE_LENGTH (type
) != blk
->size
)
11795 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11796 TYPE_LENGTH (type
));
11797 *bytes
= blk
->data
;
11800 /* The DW_AT_const_value attributes are supposed to carry the
11801 symbol's value "represented as it would be on the target
11802 architecture." By the time we get here, it's already been
11803 converted to host endianness, so we just need to sign- or
11804 zero-extend it as appropriate. */
11805 case DW_FORM_data1
:
11806 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11807 obstack
, cu
, value
, 8);
11809 case DW_FORM_data2
:
11810 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11811 obstack
, cu
, value
, 16);
11813 case DW_FORM_data4
:
11814 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11815 obstack
, cu
, value
, 32);
11817 case DW_FORM_data8
:
11818 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11819 obstack
, cu
, value
, 64);
11822 case DW_FORM_sdata
:
11823 *value
= DW_SND (attr
);
11826 case DW_FORM_udata
:
11827 *value
= DW_UNSND (attr
);
11831 complaint (&symfile_complaints
,
11832 _("unsupported const value attribute form: '%s'"),
11833 dwarf_form_name (attr
->form
));
11840 /* Copy constant value from an attribute to a symbol. */
11843 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11844 struct dwarf2_cu
*cu
)
11846 struct objfile
*objfile
= cu
->objfile
;
11847 struct comp_unit_head
*cu_header
= &cu
->header
;
11850 struct dwarf2_locexpr_baton
*baton
;
11852 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11853 SYMBOL_PRINT_NAME (sym
),
11854 &objfile
->objfile_obstack
, cu
,
11855 &value
, &bytes
, &baton
);
11859 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11860 SYMBOL_LOCATION_BATON (sym
) = baton
;
11861 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11863 else if (bytes
!= NULL
)
11865 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11866 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11870 SYMBOL_VALUE (sym
) = value
;
11871 SYMBOL_CLASS (sym
) = LOC_CONST
;
11875 /* Return the type of the die in question using its DW_AT_type attribute. */
11877 static struct type
*
11878 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11880 struct attribute
*type_attr
;
11882 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11885 /* A missing DW_AT_type represents a void type. */
11886 return objfile_type (cu
->objfile
)->builtin_void
;
11889 return lookup_die_type (die
, type_attr
, cu
);
11892 /* True iff CU's producer generates GNAT Ada auxiliary information
11893 that allows to find parallel types through that information instead
11894 of having to do expensive parallel lookups by type name. */
11897 need_gnat_info (struct dwarf2_cu
*cu
)
11899 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11900 of GNAT produces this auxiliary information, without any indication
11901 that it is produced. Part of enhancing the FSF version of GNAT
11902 to produce that information will be to put in place an indicator
11903 that we can use in order to determine whether the descriptive type
11904 info is available or not. One suggestion that has been made is
11905 to use a new attribute, attached to the CU die. For now, assume
11906 that the descriptive type info is not available. */
11910 /* Return the auxiliary type of the die in question using its
11911 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11912 attribute is not present. */
11914 static struct type
*
11915 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11917 struct attribute
*type_attr
;
11919 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11923 return lookup_die_type (die
, type_attr
, cu
);
11926 /* If DIE has a descriptive_type attribute, then set the TYPE's
11927 descriptive type accordingly. */
11930 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11931 struct dwarf2_cu
*cu
)
11933 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11935 if (descriptive_type
)
11937 ALLOCATE_GNAT_AUX_TYPE (type
);
11938 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11942 /* Return the containing type of the die in question using its
11943 DW_AT_containing_type attribute. */
11945 static struct type
*
11946 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11948 struct attribute
*type_attr
;
11950 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11952 error (_("Dwarf Error: Problem turning containing type into gdb type "
11953 "[in module %s]"), cu
->objfile
->name
);
11955 return lookup_die_type (die
, type_attr
, cu
);
11958 /* Look up the type of DIE in CU using its type attribute ATTR.
11959 If there is no type substitute an error marker. */
11961 static struct type
*
11962 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11963 struct dwarf2_cu
*cu
)
11965 struct type
*this_type
;
11967 /* First see if we have it cached. */
11969 if (is_ref_attr (attr
))
11971 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11973 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11975 else if (attr
->form
== DW_FORM_ref_sig8
)
11977 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11978 struct dwarf2_cu
*sig_cu
;
11979 unsigned int offset
;
11981 /* sig_type will be NULL if the signatured type is missing from
11983 if (sig_type
== NULL
)
11984 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11985 "at 0x%x [in module %s]"),
11986 die
->offset
, cu
->objfile
->name
);
11988 gdb_assert (sig_type
->per_cu
.debug_type_section
);
11989 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
11990 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11994 dump_die_for_error (die
);
11995 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11996 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11999 /* If not cached we need to read it in. */
12001 if (this_type
== NULL
)
12003 struct die_info
*type_die
;
12004 struct dwarf2_cu
*type_cu
= cu
;
12006 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12007 /* If the type is cached, we should have found it above. */
12008 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12009 this_type
= read_type_die_1 (type_die
, type_cu
);
12012 /* If we still don't have a type use an error marker. */
12014 if (this_type
== NULL
)
12016 char *message
, *saved
;
12018 /* read_type_die already issued a complaint. */
12019 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12023 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12024 message
, strlen (message
));
12027 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12033 /* Return the type in DIE, CU.
12034 Returns NULL for invalid types.
12036 This first does a lookup in the appropriate type_hash table,
12037 and only reads the die in if necessary.
12039 NOTE: This can be called when reading in partial or full symbols. */
12041 static struct type
*
12042 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12044 struct type
*this_type
;
12046 this_type
= get_die_type (die
, cu
);
12050 return read_type_die_1 (die
, cu
);
12053 /* Read the type in DIE, CU.
12054 Returns NULL for invalid types. */
12056 static struct type
*
12057 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12059 struct type
*this_type
= NULL
;
12063 case DW_TAG_class_type
:
12064 case DW_TAG_interface_type
:
12065 case DW_TAG_structure_type
:
12066 case DW_TAG_union_type
:
12067 this_type
= read_structure_type (die
, cu
);
12069 case DW_TAG_enumeration_type
:
12070 this_type
= read_enumeration_type (die
, cu
);
12072 case DW_TAG_subprogram
:
12073 case DW_TAG_subroutine_type
:
12074 case DW_TAG_inlined_subroutine
:
12075 this_type
= read_subroutine_type (die
, cu
);
12077 case DW_TAG_array_type
:
12078 this_type
= read_array_type (die
, cu
);
12080 case DW_TAG_set_type
:
12081 this_type
= read_set_type (die
, cu
);
12083 case DW_TAG_pointer_type
:
12084 this_type
= read_tag_pointer_type (die
, cu
);
12086 case DW_TAG_ptr_to_member_type
:
12087 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12089 case DW_TAG_reference_type
:
12090 this_type
= read_tag_reference_type (die
, cu
);
12092 case DW_TAG_const_type
:
12093 this_type
= read_tag_const_type (die
, cu
);
12095 case DW_TAG_volatile_type
:
12096 this_type
= read_tag_volatile_type (die
, cu
);
12098 case DW_TAG_string_type
:
12099 this_type
= read_tag_string_type (die
, cu
);
12101 case DW_TAG_typedef
:
12102 this_type
= read_typedef (die
, cu
);
12104 case DW_TAG_subrange_type
:
12105 this_type
= read_subrange_type (die
, cu
);
12107 case DW_TAG_base_type
:
12108 this_type
= read_base_type (die
, cu
);
12110 case DW_TAG_unspecified_type
:
12111 this_type
= read_unspecified_type (die
, cu
);
12113 case DW_TAG_namespace
:
12114 this_type
= read_namespace_type (die
, cu
);
12116 case DW_TAG_module
:
12117 this_type
= read_module_type (die
, cu
);
12120 complaint (&symfile_complaints
,
12121 _("unexpected tag in read_type_die: '%s'"),
12122 dwarf_tag_name (die
->tag
));
12129 /* See if we can figure out if the class lives in a namespace. We do
12130 this by looking for a member function; its demangled name will
12131 contain namespace info, if there is any.
12132 Return the computed name or NULL.
12133 Space for the result is allocated on the objfile's obstack.
12134 This is the full-die version of guess_partial_die_structure_name.
12135 In this case we know DIE has no useful parent. */
12138 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12140 struct die_info
*spec_die
;
12141 struct dwarf2_cu
*spec_cu
;
12142 struct die_info
*child
;
12145 spec_die
= die_specification (die
, &spec_cu
);
12146 if (spec_die
!= NULL
)
12152 for (child
= die
->child
;
12154 child
= child
->sibling
)
12156 if (child
->tag
== DW_TAG_subprogram
)
12158 struct attribute
*attr
;
12160 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12162 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12166 = language_class_name_from_physname (cu
->language_defn
,
12170 if (actual_name
!= NULL
)
12172 char *die_name
= dwarf2_name (die
, cu
);
12174 if (die_name
!= NULL
12175 && strcmp (die_name
, actual_name
) != 0)
12177 /* Strip off the class name from the full name.
12178 We want the prefix. */
12179 int die_name_len
= strlen (die_name
);
12180 int actual_name_len
= strlen (actual_name
);
12182 /* Test for '::' as a sanity check. */
12183 if (actual_name_len
> die_name_len
+ 2
12184 && actual_name
[actual_name_len
12185 - die_name_len
- 1] == ':')
12187 obsavestring (actual_name
,
12188 actual_name_len
- die_name_len
- 2,
12189 &cu
->objfile
->objfile_obstack
);
12192 xfree (actual_name
);
12201 /* Return the name of the namespace/class that DIE is defined within,
12202 or "" if we can't tell. The caller should not xfree the result.
12204 For example, if we're within the method foo() in the following
12214 then determine_prefix on foo's die will return "N::C". */
12217 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12219 struct die_info
*parent
, *spec_die
;
12220 struct dwarf2_cu
*spec_cu
;
12221 struct type
*parent_type
;
12223 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12224 && cu
->language
!= language_fortran
)
12227 /* We have to be careful in the presence of DW_AT_specification.
12228 For example, with GCC 3.4, given the code
12232 // Definition of N::foo.
12236 then we'll have a tree of DIEs like this:
12238 1: DW_TAG_compile_unit
12239 2: DW_TAG_namespace // N
12240 3: DW_TAG_subprogram // declaration of N::foo
12241 4: DW_TAG_subprogram // definition of N::foo
12242 DW_AT_specification // refers to die #3
12244 Thus, when processing die #4, we have to pretend that we're in
12245 the context of its DW_AT_specification, namely the contex of die
12248 spec_die
= die_specification (die
, &spec_cu
);
12249 if (spec_die
== NULL
)
12250 parent
= die
->parent
;
12253 parent
= spec_die
->parent
;
12257 if (parent
== NULL
)
12259 else if (parent
->building_fullname
)
12262 const char *parent_name
;
12264 /* It has been seen on RealView 2.2 built binaries,
12265 DW_TAG_template_type_param types actually _defined_ as
12266 children of the parent class:
12269 template class <class Enum> Class{};
12270 Class<enum E> class_e;
12272 1: DW_TAG_class_type (Class)
12273 2: DW_TAG_enumeration_type (E)
12274 3: DW_TAG_enumerator (enum1:0)
12275 3: DW_TAG_enumerator (enum2:1)
12277 2: DW_TAG_template_type_param
12278 DW_AT_type DW_FORM_ref_udata (E)
12280 Besides being broken debug info, it can put GDB into an
12281 infinite loop. Consider:
12283 When we're building the full name for Class<E>, we'll start
12284 at Class, and go look over its template type parameters,
12285 finding E. We'll then try to build the full name of E, and
12286 reach here. We're now trying to build the full name of E,
12287 and look over the parent DIE for containing scope. In the
12288 broken case, if we followed the parent DIE of E, we'd again
12289 find Class, and once again go look at its template type
12290 arguments, etc., etc. Simply don't consider such parent die
12291 as source-level parent of this die (it can't be, the language
12292 doesn't allow it), and break the loop here. */
12293 name
= dwarf2_name (die
, cu
);
12294 parent_name
= dwarf2_name (parent
, cu
);
12295 complaint (&symfile_complaints
,
12296 _("template param type '%s' defined within parent '%s'"),
12297 name
? name
: "<unknown>",
12298 parent_name
? parent_name
: "<unknown>");
12302 switch (parent
->tag
)
12304 case DW_TAG_namespace
:
12305 parent_type
= read_type_die (parent
, cu
);
12306 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12307 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12308 Work around this problem here. */
12309 if (cu
->language
== language_cplus
12310 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12312 /* We give a name to even anonymous namespaces. */
12313 return TYPE_TAG_NAME (parent_type
);
12314 case DW_TAG_class_type
:
12315 case DW_TAG_interface_type
:
12316 case DW_TAG_structure_type
:
12317 case DW_TAG_union_type
:
12318 case DW_TAG_module
:
12319 parent_type
= read_type_die (parent
, cu
);
12320 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12321 return TYPE_TAG_NAME (parent_type
);
12323 /* An anonymous structure is only allowed non-static data
12324 members; no typedefs, no member functions, et cetera.
12325 So it does not need a prefix. */
12327 case DW_TAG_compile_unit
:
12328 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12329 if (cu
->language
== language_cplus
12330 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12331 && die
->child
!= NULL
12332 && (die
->tag
== DW_TAG_class_type
12333 || die
->tag
== DW_TAG_structure_type
12334 || die
->tag
== DW_TAG_union_type
))
12336 char *name
= guess_full_die_structure_name (die
, cu
);
12342 return determine_prefix (parent
, cu
);
12346 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12347 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12348 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12349 an obconcat, otherwise allocate storage for the result. The CU argument is
12350 used to determine the language and hence, the appropriate separator. */
12352 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12355 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12356 int physname
, struct dwarf2_cu
*cu
)
12358 const char *lead
= "";
12361 if (suffix
== NULL
|| suffix
[0] == '\0'
12362 || prefix
== NULL
|| prefix
[0] == '\0')
12364 else if (cu
->language
== language_java
)
12366 else if (cu
->language
== language_fortran
&& physname
)
12368 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12369 DW_AT_MIPS_linkage_name is preferred and used instead. */
12377 if (prefix
== NULL
)
12379 if (suffix
== NULL
)
12385 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12387 strcpy (retval
, lead
);
12388 strcat (retval
, prefix
);
12389 strcat (retval
, sep
);
12390 strcat (retval
, suffix
);
12395 /* We have an obstack. */
12396 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12400 /* Return sibling of die, NULL if no sibling. */
12402 static struct die_info
*
12403 sibling_die (struct die_info
*die
)
12405 return die
->sibling
;
12408 /* Get name of a die, return NULL if not found. */
12411 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12412 struct obstack
*obstack
)
12414 if (name
&& cu
->language
== language_cplus
)
12416 char *canon_name
= cp_canonicalize_string (name
);
12418 if (canon_name
!= NULL
)
12420 if (strcmp (canon_name
, name
) != 0)
12421 name
= obsavestring (canon_name
, strlen (canon_name
),
12423 xfree (canon_name
);
12430 /* Get name of a die, return NULL if not found. */
12433 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12435 struct attribute
*attr
;
12437 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12438 if ((!attr
|| !DW_STRING (attr
))
12439 && die
->tag
!= DW_TAG_class_type
12440 && die
->tag
!= DW_TAG_interface_type
12441 && die
->tag
!= DW_TAG_structure_type
12442 && die
->tag
!= DW_TAG_union_type
)
12447 case DW_TAG_compile_unit
:
12448 /* Compilation units have a DW_AT_name that is a filename, not
12449 a source language identifier. */
12450 case DW_TAG_enumeration_type
:
12451 case DW_TAG_enumerator
:
12452 /* These tags always have simple identifiers already; no need
12453 to canonicalize them. */
12454 return DW_STRING (attr
);
12456 case DW_TAG_subprogram
:
12457 /* Java constructors will all be named "<init>", so return
12458 the class name when we see this special case. */
12459 if (cu
->language
== language_java
12460 && DW_STRING (attr
) != NULL
12461 && strcmp (DW_STRING (attr
), "<init>") == 0)
12463 struct dwarf2_cu
*spec_cu
= cu
;
12464 struct die_info
*spec_die
;
12466 /* GCJ will output '<init>' for Java constructor names.
12467 For this special case, return the name of the parent class. */
12469 /* GCJ may output suprogram DIEs with AT_specification set.
12470 If so, use the name of the specified DIE. */
12471 spec_die
= die_specification (die
, &spec_cu
);
12472 if (spec_die
!= NULL
)
12473 return dwarf2_name (spec_die
, spec_cu
);
12478 if (die
->tag
== DW_TAG_class_type
)
12479 return dwarf2_name (die
, cu
);
12481 while (die
->tag
!= DW_TAG_compile_unit
);
12485 case DW_TAG_class_type
:
12486 case DW_TAG_interface_type
:
12487 case DW_TAG_structure_type
:
12488 case DW_TAG_union_type
:
12489 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12490 structures or unions. These were of the form "._%d" in GCC 4.1,
12491 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12492 and GCC 4.4. We work around this problem by ignoring these. */
12493 if (attr
&& DW_STRING (attr
)
12494 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12495 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12498 /* GCC might emit a nameless typedef that has a linkage name. See
12499 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12500 if (!attr
|| DW_STRING (attr
) == NULL
)
12502 char *demangled
= NULL
;
12504 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12506 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12508 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12511 /* Avoid demangling DW_STRING (attr) the second time on a second
12512 call for the same DIE. */
12513 if (!DW_STRING_IS_CANONICAL (attr
))
12514 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12518 /* FIXME: we already did this for the partial symbol... */
12520 = obsavestring (demangled
, strlen (demangled
),
12521 &cu
->objfile
->objfile_obstack
);
12522 DW_STRING_IS_CANONICAL (attr
) = 1;
12532 if (!DW_STRING_IS_CANONICAL (attr
))
12535 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12536 &cu
->objfile
->objfile_obstack
);
12537 DW_STRING_IS_CANONICAL (attr
) = 1;
12539 return DW_STRING (attr
);
12542 /* Return the die that this die in an extension of, or NULL if there
12543 is none. *EXT_CU is the CU containing DIE on input, and the CU
12544 containing the return value on output. */
12546 static struct die_info
*
12547 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12549 struct attribute
*attr
;
12551 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12555 return follow_die_ref (die
, attr
, ext_cu
);
12558 /* Convert a DIE tag into its string name. */
12561 dwarf_tag_name (unsigned tag
)
12565 case DW_TAG_padding
:
12566 return "DW_TAG_padding";
12567 case DW_TAG_array_type
:
12568 return "DW_TAG_array_type";
12569 case DW_TAG_class_type
:
12570 return "DW_TAG_class_type";
12571 case DW_TAG_entry_point
:
12572 return "DW_TAG_entry_point";
12573 case DW_TAG_enumeration_type
:
12574 return "DW_TAG_enumeration_type";
12575 case DW_TAG_formal_parameter
:
12576 return "DW_TAG_formal_parameter";
12577 case DW_TAG_imported_declaration
:
12578 return "DW_TAG_imported_declaration";
12580 return "DW_TAG_label";
12581 case DW_TAG_lexical_block
:
12582 return "DW_TAG_lexical_block";
12583 case DW_TAG_member
:
12584 return "DW_TAG_member";
12585 case DW_TAG_pointer_type
:
12586 return "DW_TAG_pointer_type";
12587 case DW_TAG_reference_type
:
12588 return "DW_TAG_reference_type";
12589 case DW_TAG_compile_unit
:
12590 return "DW_TAG_compile_unit";
12591 case DW_TAG_string_type
:
12592 return "DW_TAG_string_type";
12593 case DW_TAG_structure_type
:
12594 return "DW_TAG_structure_type";
12595 case DW_TAG_subroutine_type
:
12596 return "DW_TAG_subroutine_type";
12597 case DW_TAG_typedef
:
12598 return "DW_TAG_typedef";
12599 case DW_TAG_union_type
:
12600 return "DW_TAG_union_type";
12601 case DW_TAG_unspecified_parameters
:
12602 return "DW_TAG_unspecified_parameters";
12603 case DW_TAG_variant
:
12604 return "DW_TAG_variant";
12605 case DW_TAG_common_block
:
12606 return "DW_TAG_common_block";
12607 case DW_TAG_common_inclusion
:
12608 return "DW_TAG_common_inclusion";
12609 case DW_TAG_inheritance
:
12610 return "DW_TAG_inheritance";
12611 case DW_TAG_inlined_subroutine
:
12612 return "DW_TAG_inlined_subroutine";
12613 case DW_TAG_module
:
12614 return "DW_TAG_module";
12615 case DW_TAG_ptr_to_member_type
:
12616 return "DW_TAG_ptr_to_member_type";
12617 case DW_TAG_set_type
:
12618 return "DW_TAG_set_type";
12619 case DW_TAG_subrange_type
:
12620 return "DW_TAG_subrange_type";
12621 case DW_TAG_with_stmt
:
12622 return "DW_TAG_with_stmt";
12623 case DW_TAG_access_declaration
:
12624 return "DW_TAG_access_declaration";
12625 case DW_TAG_base_type
:
12626 return "DW_TAG_base_type";
12627 case DW_TAG_catch_block
:
12628 return "DW_TAG_catch_block";
12629 case DW_TAG_const_type
:
12630 return "DW_TAG_const_type";
12631 case DW_TAG_constant
:
12632 return "DW_TAG_constant";
12633 case DW_TAG_enumerator
:
12634 return "DW_TAG_enumerator";
12635 case DW_TAG_file_type
:
12636 return "DW_TAG_file_type";
12637 case DW_TAG_friend
:
12638 return "DW_TAG_friend";
12639 case DW_TAG_namelist
:
12640 return "DW_TAG_namelist";
12641 case DW_TAG_namelist_item
:
12642 return "DW_TAG_namelist_item";
12643 case DW_TAG_packed_type
:
12644 return "DW_TAG_packed_type";
12645 case DW_TAG_subprogram
:
12646 return "DW_TAG_subprogram";
12647 case DW_TAG_template_type_param
:
12648 return "DW_TAG_template_type_param";
12649 case DW_TAG_template_value_param
:
12650 return "DW_TAG_template_value_param";
12651 case DW_TAG_thrown_type
:
12652 return "DW_TAG_thrown_type";
12653 case DW_TAG_try_block
:
12654 return "DW_TAG_try_block";
12655 case DW_TAG_variant_part
:
12656 return "DW_TAG_variant_part";
12657 case DW_TAG_variable
:
12658 return "DW_TAG_variable";
12659 case DW_TAG_volatile_type
:
12660 return "DW_TAG_volatile_type";
12661 case DW_TAG_dwarf_procedure
:
12662 return "DW_TAG_dwarf_procedure";
12663 case DW_TAG_restrict_type
:
12664 return "DW_TAG_restrict_type";
12665 case DW_TAG_interface_type
:
12666 return "DW_TAG_interface_type";
12667 case DW_TAG_namespace
:
12668 return "DW_TAG_namespace";
12669 case DW_TAG_imported_module
:
12670 return "DW_TAG_imported_module";
12671 case DW_TAG_unspecified_type
:
12672 return "DW_TAG_unspecified_type";
12673 case DW_TAG_partial_unit
:
12674 return "DW_TAG_partial_unit";
12675 case DW_TAG_imported_unit
:
12676 return "DW_TAG_imported_unit";
12677 case DW_TAG_condition
:
12678 return "DW_TAG_condition";
12679 case DW_TAG_shared_type
:
12680 return "DW_TAG_shared_type";
12681 case DW_TAG_type_unit
:
12682 return "DW_TAG_type_unit";
12683 case DW_TAG_MIPS_loop
:
12684 return "DW_TAG_MIPS_loop";
12685 case DW_TAG_HP_array_descriptor
:
12686 return "DW_TAG_HP_array_descriptor";
12687 case DW_TAG_format_label
:
12688 return "DW_TAG_format_label";
12689 case DW_TAG_function_template
:
12690 return "DW_TAG_function_template";
12691 case DW_TAG_class_template
:
12692 return "DW_TAG_class_template";
12693 case DW_TAG_GNU_BINCL
:
12694 return "DW_TAG_GNU_BINCL";
12695 case DW_TAG_GNU_EINCL
:
12696 return "DW_TAG_GNU_EINCL";
12697 case DW_TAG_upc_shared_type
:
12698 return "DW_TAG_upc_shared_type";
12699 case DW_TAG_upc_strict_type
:
12700 return "DW_TAG_upc_strict_type";
12701 case DW_TAG_upc_relaxed_type
:
12702 return "DW_TAG_upc_relaxed_type";
12703 case DW_TAG_PGI_kanji_type
:
12704 return "DW_TAG_PGI_kanji_type";
12705 case DW_TAG_PGI_interface_block
:
12706 return "DW_TAG_PGI_interface_block";
12708 return "DW_TAG_<unknown>";
12712 /* Convert a DWARF attribute code into its string name. */
12715 dwarf_attr_name (unsigned attr
)
12719 case DW_AT_sibling
:
12720 return "DW_AT_sibling";
12721 case DW_AT_location
:
12722 return "DW_AT_location";
12724 return "DW_AT_name";
12725 case DW_AT_ordering
:
12726 return "DW_AT_ordering";
12727 case DW_AT_subscr_data
:
12728 return "DW_AT_subscr_data";
12729 case DW_AT_byte_size
:
12730 return "DW_AT_byte_size";
12731 case DW_AT_bit_offset
:
12732 return "DW_AT_bit_offset";
12733 case DW_AT_bit_size
:
12734 return "DW_AT_bit_size";
12735 case DW_AT_element_list
:
12736 return "DW_AT_element_list";
12737 case DW_AT_stmt_list
:
12738 return "DW_AT_stmt_list";
12740 return "DW_AT_low_pc";
12741 case DW_AT_high_pc
:
12742 return "DW_AT_high_pc";
12743 case DW_AT_language
:
12744 return "DW_AT_language";
12746 return "DW_AT_member";
12748 return "DW_AT_discr";
12749 case DW_AT_discr_value
:
12750 return "DW_AT_discr_value";
12751 case DW_AT_visibility
:
12752 return "DW_AT_visibility";
12754 return "DW_AT_import";
12755 case DW_AT_string_length
:
12756 return "DW_AT_string_length";
12757 case DW_AT_common_reference
:
12758 return "DW_AT_common_reference";
12759 case DW_AT_comp_dir
:
12760 return "DW_AT_comp_dir";
12761 case DW_AT_const_value
:
12762 return "DW_AT_const_value";
12763 case DW_AT_containing_type
:
12764 return "DW_AT_containing_type";
12765 case DW_AT_default_value
:
12766 return "DW_AT_default_value";
12768 return "DW_AT_inline";
12769 case DW_AT_is_optional
:
12770 return "DW_AT_is_optional";
12771 case DW_AT_lower_bound
:
12772 return "DW_AT_lower_bound";
12773 case DW_AT_producer
:
12774 return "DW_AT_producer";
12775 case DW_AT_prototyped
:
12776 return "DW_AT_prototyped";
12777 case DW_AT_return_addr
:
12778 return "DW_AT_return_addr";
12779 case DW_AT_start_scope
:
12780 return "DW_AT_start_scope";
12781 case DW_AT_bit_stride
:
12782 return "DW_AT_bit_stride";
12783 case DW_AT_upper_bound
:
12784 return "DW_AT_upper_bound";
12785 case DW_AT_abstract_origin
:
12786 return "DW_AT_abstract_origin";
12787 case DW_AT_accessibility
:
12788 return "DW_AT_accessibility";
12789 case DW_AT_address_class
:
12790 return "DW_AT_address_class";
12791 case DW_AT_artificial
:
12792 return "DW_AT_artificial";
12793 case DW_AT_base_types
:
12794 return "DW_AT_base_types";
12795 case DW_AT_calling_convention
:
12796 return "DW_AT_calling_convention";
12798 return "DW_AT_count";
12799 case DW_AT_data_member_location
:
12800 return "DW_AT_data_member_location";
12801 case DW_AT_decl_column
:
12802 return "DW_AT_decl_column";
12803 case DW_AT_decl_file
:
12804 return "DW_AT_decl_file";
12805 case DW_AT_decl_line
:
12806 return "DW_AT_decl_line";
12807 case DW_AT_declaration
:
12808 return "DW_AT_declaration";
12809 case DW_AT_discr_list
:
12810 return "DW_AT_discr_list";
12811 case DW_AT_encoding
:
12812 return "DW_AT_encoding";
12813 case DW_AT_external
:
12814 return "DW_AT_external";
12815 case DW_AT_frame_base
:
12816 return "DW_AT_frame_base";
12818 return "DW_AT_friend";
12819 case DW_AT_identifier_case
:
12820 return "DW_AT_identifier_case";
12821 case DW_AT_macro_info
:
12822 return "DW_AT_macro_info";
12823 case DW_AT_namelist_items
:
12824 return "DW_AT_namelist_items";
12825 case DW_AT_priority
:
12826 return "DW_AT_priority";
12827 case DW_AT_segment
:
12828 return "DW_AT_segment";
12829 case DW_AT_specification
:
12830 return "DW_AT_specification";
12831 case DW_AT_static_link
:
12832 return "DW_AT_static_link";
12834 return "DW_AT_type";
12835 case DW_AT_use_location
:
12836 return "DW_AT_use_location";
12837 case DW_AT_variable_parameter
:
12838 return "DW_AT_variable_parameter";
12839 case DW_AT_virtuality
:
12840 return "DW_AT_virtuality";
12841 case DW_AT_vtable_elem_location
:
12842 return "DW_AT_vtable_elem_location";
12843 /* DWARF 3 values. */
12844 case DW_AT_allocated
:
12845 return "DW_AT_allocated";
12846 case DW_AT_associated
:
12847 return "DW_AT_associated";
12848 case DW_AT_data_location
:
12849 return "DW_AT_data_location";
12850 case DW_AT_byte_stride
:
12851 return "DW_AT_byte_stride";
12852 case DW_AT_entry_pc
:
12853 return "DW_AT_entry_pc";
12854 case DW_AT_use_UTF8
:
12855 return "DW_AT_use_UTF8";
12856 case DW_AT_extension
:
12857 return "DW_AT_extension";
12859 return "DW_AT_ranges";
12860 case DW_AT_trampoline
:
12861 return "DW_AT_trampoline";
12862 case DW_AT_call_column
:
12863 return "DW_AT_call_column";
12864 case DW_AT_call_file
:
12865 return "DW_AT_call_file";
12866 case DW_AT_call_line
:
12867 return "DW_AT_call_line";
12868 case DW_AT_description
:
12869 return "DW_AT_description";
12870 case DW_AT_binary_scale
:
12871 return "DW_AT_binary_scale";
12872 case DW_AT_decimal_scale
:
12873 return "DW_AT_decimal_scale";
12875 return "DW_AT_small";
12876 case DW_AT_decimal_sign
:
12877 return "DW_AT_decimal_sign";
12878 case DW_AT_digit_count
:
12879 return "DW_AT_digit_count";
12880 case DW_AT_picture_string
:
12881 return "DW_AT_picture_string";
12882 case DW_AT_mutable
:
12883 return "DW_AT_mutable";
12884 case DW_AT_threads_scaled
:
12885 return "DW_AT_threads_scaled";
12886 case DW_AT_explicit
:
12887 return "DW_AT_explicit";
12888 case DW_AT_object_pointer
:
12889 return "DW_AT_object_pointer";
12890 case DW_AT_endianity
:
12891 return "DW_AT_endianity";
12892 case DW_AT_elemental
:
12893 return "DW_AT_elemental";
12895 return "DW_AT_pure";
12896 case DW_AT_recursive
:
12897 return "DW_AT_recursive";
12898 /* DWARF 4 values. */
12899 case DW_AT_signature
:
12900 return "DW_AT_signature";
12901 case DW_AT_linkage_name
:
12902 return "DW_AT_linkage_name";
12903 /* SGI/MIPS extensions. */
12904 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12905 case DW_AT_MIPS_fde
:
12906 return "DW_AT_MIPS_fde";
12908 case DW_AT_MIPS_loop_begin
:
12909 return "DW_AT_MIPS_loop_begin";
12910 case DW_AT_MIPS_tail_loop_begin
:
12911 return "DW_AT_MIPS_tail_loop_begin";
12912 case DW_AT_MIPS_epilog_begin
:
12913 return "DW_AT_MIPS_epilog_begin";
12914 case DW_AT_MIPS_loop_unroll_factor
:
12915 return "DW_AT_MIPS_loop_unroll_factor";
12916 case DW_AT_MIPS_software_pipeline_depth
:
12917 return "DW_AT_MIPS_software_pipeline_depth";
12918 case DW_AT_MIPS_linkage_name
:
12919 return "DW_AT_MIPS_linkage_name";
12920 case DW_AT_MIPS_stride
:
12921 return "DW_AT_MIPS_stride";
12922 case DW_AT_MIPS_abstract_name
:
12923 return "DW_AT_MIPS_abstract_name";
12924 case DW_AT_MIPS_clone_origin
:
12925 return "DW_AT_MIPS_clone_origin";
12926 case DW_AT_MIPS_has_inlines
:
12927 return "DW_AT_MIPS_has_inlines";
12928 /* HP extensions. */
12929 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12930 case DW_AT_HP_block_index
:
12931 return "DW_AT_HP_block_index";
12933 case DW_AT_HP_unmodifiable
:
12934 return "DW_AT_HP_unmodifiable";
12935 case DW_AT_HP_actuals_stmt_list
:
12936 return "DW_AT_HP_actuals_stmt_list";
12937 case DW_AT_HP_proc_per_section
:
12938 return "DW_AT_HP_proc_per_section";
12939 case DW_AT_HP_raw_data_ptr
:
12940 return "DW_AT_HP_raw_data_ptr";
12941 case DW_AT_HP_pass_by_reference
:
12942 return "DW_AT_HP_pass_by_reference";
12943 case DW_AT_HP_opt_level
:
12944 return "DW_AT_HP_opt_level";
12945 case DW_AT_HP_prof_version_id
:
12946 return "DW_AT_HP_prof_version_id";
12947 case DW_AT_HP_opt_flags
:
12948 return "DW_AT_HP_opt_flags";
12949 case DW_AT_HP_cold_region_low_pc
:
12950 return "DW_AT_HP_cold_region_low_pc";
12951 case DW_AT_HP_cold_region_high_pc
:
12952 return "DW_AT_HP_cold_region_high_pc";
12953 case DW_AT_HP_all_variables_modifiable
:
12954 return "DW_AT_HP_all_variables_modifiable";
12955 case DW_AT_HP_linkage_name
:
12956 return "DW_AT_HP_linkage_name";
12957 case DW_AT_HP_prof_flags
:
12958 return "DW_AT_HP_prof_flags";
12959 /* GNU extensions. */
12960 case DW_AT_sf_names
:
12961 return "DW_AT_sf_names";
12962 case DW_AT_src_info
:
12963 return "DW_AT_src_info";
12964 case DW_AT_mac_info
:
12965 return "DW_AT_mac_info";
12966 case DW_AT_src_coords
:
12967 return "DW_AT_src_coords";
12968 case DW_AT_body_begin
:
12969 return "DW_AT_body_begin";
12970 case DW_AT_body_end
:
12971 return "DW_AT_body_end";
12972 case DW_AT_GNU_vector
:
12973 return "DW_AT_GNU_vector";
12974 case DW_AT_GNU_odr_signature
:
12975 return "DW_AT_GNU_odr_signature";
12976 /* VMS extensions. */
12977 case DW_AT_VMS_rtnbeg_pd_address
:
12978 return "DW_AT_VMS_rtnbeg_pd_address";
12979 /* UPC extension. */
12980 case DW_AT_upc_threads_scaled
:
12981 return "DW_AT_upc_threads_scaled";
12982 /* PGI (STMicroelectronics) extensions. */
12983 case DW_AT_PGI_lbase
:
12984 return "DW_AT_PGI_lbase";
12985 case DW_AT_PGI_soffset
:
12986 return "DW_AT_PGI_soffset";
12987 case DW_AT_PGI_lstride
:
12988 return "DW_AT_PGI_lstride";
12990 return "DW_AT_<unknown>";
12994 /* Convert a DWARF value form code into its string name. */
12997 dwarf_form_name (unsigned form
)
13002 return "DW_FORM_addr";
13003 case DW_FORM_block2
:
13004 return "DW_FORM_block2";
13005 case DW_FORM_block4
:
13006 return "DW_FORM_block4";
13007 case DW_FORM_data2
:
13008 return "DW_FORM_data2";
13009 case DW_FORM_data4
:
13010 return "DW_FORM_data4";
13011 case DW_FORM_data8
:
13012 return "DW_FORM_data8";
13013 case DW_FORM_string
:
13014 return "DW_FORM_string";
13015 case DW_FORM_block
:
13016 return "DW_FORM_block";
13017 case DW_FORM_block1
:
13018 return "DW_FORM_block1";
13019 case DW_FORM_data1
:
13020 return "DW_FORM_data1";
13022 return "DW_FORM_flag";
13023 case DW_FORM_sdata
:
13024 return "DW_FORM_sdata";
13026 return "DW_FORM_strp";
13027 case DW_FORM_udata
:
13028 return "DW_FORM_udata";
13029 case DW_FORM_ref_addr
:
13030 return "DW_FORM_ref_addr";
13032 return "DW_FORM_ref1";
13034 return "DW_FORM_ref2";
13036 return "DW_FORM_ref4";
13038 return "DW_FORM_ref8";
13039 case DW_FORM_ref_udata
:
13040 return "DW_FORM_ref_udata";
13041 case DW_FORM_indirect
:
13042 return "DW_FORM_indirect";
13043 case DW_FORM_sec_offset
:
13044 return "DW_FORM_sec_offset";
13045 case DW_FORM_exprloc
:
13046 return "DW_FORM_exprloc";
13047 case DW_FORM_flag_present
:
13048 return "DW_FORM_flag_present";
13049 case DW_FORM_ref_sig8
:
13050 return "DW_FORM_ref_sig8";
13052 return "DW_FORM_<unknown>";
13056 /* Convert a DWARF stack opcode into its string name. */
13059 dwarf_stack_op_name (unsigned op
)
13064 return "DW_OP_addr";
13066 return "DW_OP_deref";
13067 case DW_OP_const1u
:
13068 return "DW_OP_const1u";
13069 case DW_OP_const1s
:
13070 return "DW_OP_const1s";
13071 case DW_OP_const2u
:
13072 return "DW_OP_const2u";
13073 case DW_OP_const2s
:
13074 return "DW_OP_const2s";
13075 case DW_OP_const4u
:
13076 return "DW_OP_const4u";
13077 case DW_OP_const4s
:
13078 return "DW_OP_const4s";
13079 case DW_OP_const8u
:
13080 return "DW_OP_const8u";
13081 case DW_OP_const8s
:
13082 return "DW_OP_const8s";
13084 return "DW_OP_constu";
13086 return "DW_OP_consts";
13088 return "DW_OP_dup";
13090 return "DW_OP_drop";
13092 return "DW_OP_over";
13094 return "DW_OP_pick";
13096 return "DW_OP_swap";
13098 return "DW_OP_rot";
13100 return "DW_OP_xderef";
13102 return "DW_OP_abs";
13104 return "DW_OP_and";
13106 return "DW_OP_div";
13108 return "DW_OP_minus";
13110 return "DW_OP_mod";
13112 return "DW_OP_mul";
13114 return "DW_OP_neg";
13116 return "DW_OP_not";
13120 return "DW_OP_plus";
13121 case DW_OP_plus_uconst
:
13122 return "DW_OP_plus_uconst";
13124 return "DW_OP_shl";
13126 return "DW_OP_shr";
13128 return "DW_OP_shra";
13130 return "DW_OP_xor";
13132 return "DW_OP_bra";
13146 return "DW_OP_skip";
13148 return "DW_OP_lit0";
13150 return "DW_OP_lit1";
13152 return "DW_OP_lit2";
13154 return "DW_OP_lit3";
13156 return "DW_OP_lit4";
13158 return "DW_OP_lit5";
13160 return "DW_OP_lit6";
13162 return "DW_OP_lit7";
13164 return "DW_OP_lit8";
13166 return "DW_OP_lit9";
13168 return "DW_OP_lit10";
13170 return "DW_OP_lit11";
13172 return "DW_OP_lit12";
13174 return "DW_OP_lit13";
13176 return "DW_OP_lit14";
13178 return "DW_OP_lit15";
13180 return "DW_OP_lit16";
13182 return "DW_OP_lit17";
13184 return "DW_OP_lit18";
13186 return "DW_OP_lit19";
13188 return "DW_OP_lit20";
13190 return "DW_OP_lit21";
13192 return "DW_OP_lit22";
13194 return "DW_OP_lit23";
13196 return "DW_OP_lit24";
13198 return "DW_OP_lit25";
13200 return "DW_OP_lit26";
13202 return "DW_OP_lit27";
13204 return "DW_OP_lit28";
13206 return "DW_OP_lit29";
13208 return "DW_OP_lit30";
13210 return "DW_OP_lit31";
13212 return "DW_OP_reg0";
13214 return "DW_OP_reg1";
13216 return "DW_OP_reg2";
13218 return "DW_OP_reg3";
13220 return "DW_OP_reg4";
13222 return "DW_OP_reg5";
13224 return "DW_OP_reg6";
13226 return "DW_OP_reg7";
13228 return "DW_OP_reg8";
13230 return "DW_OP_reg9";
13232 return "DW_OP_reg10";
13234 return "DW_OP_reg11";
13236 return "DW_OP_reg12";
13238 return "DW_OP_reg13";
13240 return "DW_OP_reg14";
13242 return "DW_OP_reg15";
13244 return "DW_OP_reg16";
13246 return "DW_OP_reg17";
13248 return "DW_OP_reg18";
13250 return "DW_OP_reg19";
13252 return "DW_OP_reg20";
13254 return "DW_OP_reg21";
13256 return "DW_OP_reg22";
13258 return "DW_OP_reg23";
13260 return "DW_OP_reg24";
13262 return "DW_OP_reg25";
13264 return "DW_OP_reg26";
13266 return "DW_OP_reg27";
13268 return "DW_OP_reg28";
13270 return "DW_OP_reg29";
13272 return "DW_OP_reg30";
13274 return "DW_OP_reg31";
13276 return "DW_OP_breg0";
13278 return "DW_OP_breg1";
13280 return "DW_OP_breg2";
13282 return "DW_OP_breg3";
13284 return "DW_OP_breg4";
13286 return "DW_OP_breg5";
13288 return "DW_OP_breg6";
13290 return "DW_OP_breg7";
13292 return "DW_OP_breg8";
13294 return "DW_OP_breg9";
13296 return "DW_OP_breg10";
13298 return "DW_OP_breg11";
13300 return "DW_OP_breg12";
13302 return "DW_OP_breg13";
13304 return "DW_OP_breg14";
13306 return "DW_OP_breg15";
13308 return "DW_OP_breg16";
13310 return "DW_OP_breg17";
13312 return "DW_OP_breg18";
13314 return "DW_OP_breg19";
13316 return "DW_OP_breg20";
13318 return "DW_OP_breg21";
13320 return "DW_OP_breg22";
13322 return "DW_OP_breg23";
13324 return "DW_OP_breg24";
13326 return "DW_OP_breg25";
13328 return "DW_OP_breg26";
13330 return "DW_OP_breg27";
13332 return "DW_OP_breg28";
13334 return "DW_OP_breg29";
13336 return "DW_OP_breg30";
13338 return "DW_OP_breg31";
13340 return "DW_OP_regx";
13342 return "DW_OP_fbreg";
13344 return "DW_OP_bregx";
13346 return "DW_OP_piece";
13347 case DW_OP_deref_size
:
13348 return "DW_OP_deref_size";
13349 case DW_OP_xderef_size
:
13350 return "DW_OP_xderef_size";
13352 return "DW_OP_nop";
13353 /* DWARF 3 extensions. */
13354 case DW_OP_push_object_address
:
13355 return "DW_OP_push_object_address";
13357 return "DW_OP_call2";
13359 return "DW_OP_call4";
13360 case DW_OP_call_ref
:
13361 return "DW_OP_call_ref";
13362 case DW_OP_form_tls_address
:
13363 return "DW_OP_form_tls_address";
13364 case DW_OP_call_frame_cfa
:
13365 return "DW_OP_call_frame_cfa";
13366 case DW_OP_bit_piece
:
13367 return "DW_OP_bit_piece";
13368 /* DWARF 4 extensions. */
13369 case DW_OP_implicit_value
:
13370 return "DW_OP_implicit_value";
13371 case DW_OP_stack_value
:
13372 return "DW_OP_stack_value";
13373 /* GNU extensions. */
13374 case DW_OP_GNU_push_tls_address
:
13375 return "DW_OP_GNU_push_tls_address";
13376 case DW_OP_GNU_uninit
:
13377 return "DW_OP_GNU_uninit";
13378 case DW_OP_GNU_implicit_pointer
:
13379 return "DW_OP_GNU_implicit_pointer";
13380 case DW_OP_GNU_entry_value
:
13381 return "DW_OP_GNU_entry_value";
13382 case DW_OP_GNU_const_type
:
13383 return "DW_OP_GNU_const_type";
13384 case DW_OP_GNU_regval_type
:
13385 return "DW_OP_GNU_regval_type";
13386 case DW_OP_GNU_deref_type
:
13387 return "DW_OP_GNU_deref_type";
13388 case DW_OP_GNU_convert
:
13389 return "DW_OP_GNU_convert";
13390 case DW_OP_GNU_reinterpret
:
13391 return "DW_OP_GNU_reinterpret";
13398 dwarf_bool_name (unsigned mybool
)
13406 /* Convert a DWARF type code into its string name. */
13409 dwarf_type_encoding_name (unsigned enc
)
13414 return "DW_ATE_void";
13415 case DW_ATE_address
:
13416 return "DW_ATE_address";
13417 case DW_ATE_boolean
:
13418 return "DW_ATE_boolean";
13419 case DW_ATE_complex_float
:
13420 return "DW_ATE_complex_float";
13422 return "DW_ATE_float";
13423 case DW_ATE_signed
:
13424 return "DW_ATE_signed";
13425 case DW_ATE_signed_char
:
13426 return "DW_ATE_signed_char";
13427 case DW_ATE_unsigned
:
13428 return "DW_ATE_unsigned";
13429 case DW_ATE_unsigned_char
:
13430 return "DW_ATE_unsigned_char";
13432 case DW_ATE_imaginary_float
:
13433 return "DW_ATE_imaginary_float";
13434 case DW_ATE_packed_decimal
:
13435 return "DW_ATE_packed_decimal";
13436 case DW_ATE_numeric_string
:
13437 return "DW_ATE_numeric_string";
13438 case DW_ATE_edited
:
13439 return "DW_ATE_edited";
13440 case DW_ATE_signed_fixed
:
13441 return "DW_ATE_signed_fixed";
13442 case DW_ATE_unsigned_fixed
:
13443 return "DW_ATE_unsigned_fixed";
13444 case DW_ATE_decimal_float
:
13445 return "DW_ATE_decimal_float";
13448 return "DW_ATE_UTF";
13449 /* HP extensions. */
13450 case DW_ATE_HP_float80
:
13451 return "DW_ATE_HP_float80";
13452 case DW_ATE_HP_complex_float80
:
13453 return "DW_ATE_HP_complex_float80";
13454 case DW_ATE_HP_float128
:
13455 return "DW_ATE_HP_float128";
13456 case DW_ATE_HP_complex_float128
:
13457 return "DW_ATE_HP_complex_float128";
13458 case DW_ATE_HP_floathpintel
:
13459 return "DW_ATE_HP_floathpintel";
13460 case DW_ATE_HP_imaginary_float80
:
13461 return "DW_ATE_HP_imaginary_float80";
13462 case DW_ATE_HP_imaginary_float128
:
13463 return "DW_ATE_HP_imaginary_float128";
13465 return "DW_ATE_<unknown>";
13469 /* Convert a DWARF call frame info operation to its string name. */
13473 dwarf_cfi_name (unsigned cfi_opc
)
13477 case DW_CFA_advance_loc
:
13478 return "DW_CFA_advance_loc";
13479 case DW_CFA_offset
:
13480 return "DW_CFA_offset";
13481 case DW_CFA_restore
:
13482 return "DW_CFA_restore";
13484 return "DW_CFA_nop";
13485 case DW_CFA_set_loc
:
13486 return "DW_CFA_set_loc";
13487 case DW_CFA_advance_loc1
:
13488 return "DW_CFA_advance_loc1";
13489 case DW_CFA_advance_loc2
:
13490 return "DW_CFA_advance_loc2";
13491 case DW_CFA_advance_loc4
:
13492 return "DW_CFA_advance_loc4";
13493 case DW_CFA_offset_extended
:
13494 return "DW_CFA_offset_extended";
13495 case DW_CFA_restore_extended
:
13496 return "DW_CFA_restore_extended";
13497 case DW_CFA_undefined
:
13498 return "DW_CFA_undefined";
13499 case DW_CFA_same_value
:
13500 return "DW_CFA_same_value";
13501 case DW_CFA_register
:
13502 return "DW_CFA_register";
13503 case DW_CFA_remember_state
:
13504 return "DW_CFA_remember_state";
13505 case DW_CFA_restore_state
:
13506 return "DW_CFA_restore_state";
13507 case DW_CFA_def_cfa
:
13508 return "DW_CFA_def_cfa";
13509 case DW_CFA_def_cfa_register
:
13510 return "DW_CFA_def_cfa_register";
13511 case DW_CFA_def_cfa_offset
:
13512 return "DW_CFA_def_cfa_offset";
13514 case DW_CFA_def_cfa_expression
:
13515 return "DW_CFA_def_cfa_expression";
13516 case DW_CFA_expression
:
13517 return "DW_CFA_expression";
13518 case DW_CFA_offset_extended_sf
:
13519 return "DW_CFA_offset_extended_sf";
13520 case DW_CFA_def_cfa_sf
:
13521 return "DW_CFA_def_cfa_sf";
13522 case DW_CFA_def_cfa_offset_sf
:
13523 return "DW_CFA_def_cfa_offset_sf";
13524 case DW_CFA_val_offset
:
13525 return "DW_CFA_val_offset";
13526 case DW_CFA_val_offset_sf
:
13527 return "DW_CFA_val_offset_sf";
13528 case DW_CFA_val_expression
:
13529 return "DW_CFA_val_expression";
13530 /* SGI/MIPS specific. */
13531 case DW_CFA_MIPS_advance_loc8
:
13532 return "DW_CFA_MIPS_advance_loc8";
13533 /* GNU extensions. */
13534 case DW_CFA_GNU_window_save
:
13535 return "DW_CFA_GNU_window_save";
13536 case DW_CFA_GNU_args_size
:
13537 return "DW_CFA_GNU_args_size";
13538 case DW_CFA_GNU_negative_offset_extended
:
13539 return "DW_CFA_GNU_negative_offset_extended";
13541 return "DW_CFA_<unknown>";
13547 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13551 print_spaces (indent
, f
);
13552 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13553 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13555 if (die
->parent
!= NULL
)
13557 print_spaces (indent
, f
);
13558 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13559 die
->parent
->offset
);
13562 print_spaces (indent
, f
);
13563 fprintf_unfiltered (f
, " has children: %s\n",
13564 dwarf_bool_name (die
->child
!= NULL
));
13566 print_spaces (indent
, f
);
13567 fprintf_unfiltered (f
, " attributes:\n");
13569 for (i
= 0; i
< die
->num_attrs
; ++i
)
13571 print_spaces (indent
, f
);
13572 fprintf_unfiltered (f
, " %s (%s) ",
13573 dwarf_attr_name (die
->attrs
[i
].name
),
13574 dwarf_form_name (die
->attrs
[i
].form
));
13576 switch (die
->attrs
[i
].form
)
13578 case DW_FORM_ref_addr
:
13580 fprintf_unfiltered (f
, "address: ");
13581 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13583 case DW_FORM_block2
:
13584 case DW_FORM_block4
:
13585 case DW_FORM_block
:
13586 case DW_FORM_block1
:
13587 fprintf_unfiltered (f
, "block: size %d",
13588 DW_BLOCK (&die
->attrs
[i
])->size
);
13590 case DW_FORM_exprloc
:
13591 fprintf_unfiltered (f
, "expression: size %u",
13592 DW_BLOCK (&die
->attrs
[i
])->size
);
13597 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13598 (long) (DW_ADDR (&die
->attrs
[i
])));
13600 case DW_FORM_data1
:
13601 case DW_FORM_data2
:
13602 case DW_FORM_data4
:
13603 case DW_FORM_data8
:
13604 case DW_FORM_udata
:
13605 case DW_FORM_sdata
:
13606 fprintf_unfiltered (f
, "constant: %s",
13607 pulongest (DW_UNSND (&die
->attrs
[i
])));
13609 case DW_FORM_sec_offset
:
13610 fprintf_unfiltered (f
, "section offset: %s",
13611 pulongest (DW_UNSND (&die
->attrs
[i
])));
13613 case DW_FORM_ref_sig8
:
13614 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13615 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13616 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13618 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13620 case DW_FORM_string
:
13622 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13623 DW_STRING (&die
->attrs
[i
])
13624 ? DW_STRING (&die
->attrs
[i
]) : "",
13625 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13628 if (DW_UNSND (&die
->attrs
[i
]))
13629 fprintf_unfiltered (f
, "flag: TRUE");
13631 fprintf_unfiltered (f
, "flag: FALSE");
13633 case DW_FORM_flag_present
:
13634 fprintf_unfiltered (f
, "flag: TRUE");
13636 case DW_FORM_indirect
:
13637 /* The reader will have reduced the indirect form to
13638 the "base form" so this form should not occur. */
13639 fprintf_unfiltered (f
,
13640 "unexpected attribute form: DW_FORM_indirect");
13643 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13644 die
->attrs
[i
].form
);
13647 fprintf_unfiltered (f
, "\n");
13652 dump_die_for_error (struct die_info
*die
)
13654 dump_die_shallow (gdb_stderr
, 0, die
);
13658 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13660 int indent
= level
* 4;
13662 gdb_assert (die
!= NULL
);
13664 if (level
>= max_level
)
13667 dump_die_shallow (f
, indent
, die
);
13669 if (die
->child
!= NULL
)
13671 print_spaces (indent
, f
);
13672 fprintf_unfiltered (f
, " Children:");
13673 if (level
+ 1 < max_level
)
13675 fprintf_unfiltered (f
, "\n");
13676 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13680 fprintf_unfiltered (f
,
13681 " [not printed, max nesting level reached]\n");
13685 if (die
->sibling
!= NULL
&& level
> 0)
13687 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13691 /* This is called from the pdie macro in gdbinit.in.
13692 It's not static so gcc will keep a copy callable from gdb. */
13695 dump_die (struct die_info
*die
, int max_level
)
13697 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13701 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13705 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13711 is_ref_attr (struct attribute
*attr
)
13713 switch (attr
->form
)
13715 case DW_FORM_ref_addr
:
13720 case DW_FORM_ref_udata
:
13727 static unsigned int
13728 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13730 if (is_ref_attr (attr
))
13731 return DW_ADDR (attr
);
13733 complaint (&symfile_complaints
,
13734 _("unsupported die ref attribute form: '%s'"),
13735 dwarf_form_name (attr
->form
));
13739 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13740 * the value held by the attribute is not constant. */
13743 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13745 if (attr
->form
== DW_FORM_sdata
)
13746 return DW_SND (attr
);
13747 else if (attr
->form
== DW_FORM_udata
13748 || attr
->form
== DW_FORM_data1
13749 || attr
->form
== DW_FORM_data2
13750 || attr
->form
== DW_FORM_data4
13751 || attr
->form
== DW_FORM_data8
)
13752 return DW_UNSND (attr
);
13755 complaint (&symfile_complaints
,
13756 _("Attribute value is not a constant (%s)"),
13757 dwarf_form_name (attr
->form
));
13758 return default_value
;
13762 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13763 unit and add it to our queue.
13764 The result is non-zero if PER_CU was queued, otherwise the result is zero
13765 meaning either PER_CU is already queued or it is already loaded. */
13768 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13769 struct dwarf2_per_cu_data
*per_cu
)
13771 /* We may arrive here during partial symbol reading, if we need full
13772 DIEs to process an unusual case (e.g. template arguments). Do
13773 not queue PER_CU, just tell our caller to load its DIEs. */
13774 if (dwarf2_per_objfile
->reading_partial_symbols
)
13776 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13781 /* Mark the dependence relation so that we don't flush PER_CU
13783 dwarf2_add_dependence (this_cu
, per_cu
);
13785 /* If it's already on the queue, we have nothing to do. */
13786 if (per_cu
->queued
)
13789 /* If the compilation unit is already loaded, just mark it as
13791 if (per_cu
->cu
!= NULL
)
13793 per_cu
->cu
->last_used
= 0;
13797 /* Add it to the queue. */
13798 queue_comp_unit (per_cu
, this_cu
->objfile
);
13803 /* Follow reference or signature attribute ATTR of SRC_DIE.
13804 On entry *REF_CU is the CU of SRC_DIE.
13805 On exit *REF_CU is the CU of the result. */
13807 static struct die_info
*
13808 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13809 struct dwarf2_cu
**ref_cu
)
13811 struct die_info
*die
;
13813 if (is_ref_attr (attr
))
13814 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13815 else if (attr
->form
== DW_FORM_ref_sig8
)
13816 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13819 dump_die_for_error (src_die
);
13820 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13821 (*ref_cu
)->objfile
->name
);
13827 /* Follow reference OFFSET.
13828 On entry *REF_CU is the CU of the source die referencing OFFSET.
13829 On exit *REF_CU is the CU of the result.
13830 Returns NULL if OFFSET is invalid. */
13832 static struct die_info
*
13833 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13835 struct die_info temp_die
;
13836 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13838 gdb_assert (cu
->per_cu
!= NULL
);
13842 if (cu
->per_cu
->debug_type_section
)
13844 /* .debug_types CUs cannot reference anything outside their CU.
13845 If they need to, they have to reference a signatured type via
13846 DW_FORM_ref_sig8. */
13847 if (! offset_in_cu_p (&cu
->header
, offset
))
13850 else if (! offset_in_cu_p (&cu
->header
, offset
))
13852 struct dwarf2_per_cu_data
*per_cu
;
13854 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13856 /* If necessary, add it to the queue and load its DIEs. */
13857 if (maybe_queue_comp_unit (cu
, per_cu
))
13858 load_full_comp_unit (per_cu
, cu
->objfile
);
13860 target_cu
= per_cu
->cu
;
13862 else if (cu
->dies
== NULL
)
13864 /* We're loading full DIEs during partial symbol reading. */
13865 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13866 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13869 *ref_cu
= target_cu
;
13870 temp_die
.offset
= offset
;
13871 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13874 /* Follow reference attribute ATTR of SRC_DIE.
13875 On entry *REF_CU is the CU of SRC_DIE.
13876 On exit *REF_CU is the CU of the result. */
13878 static struct die_info
*
13879 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13880 struct dwarf2_cu
**ref_cu
)
13882 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13883 struct dwarf2_cu
*cu
= *ref_cu
;
13884 struct die_info
*die
;
13886 die
= follow_die_offset (offset
, ref_cu
);
13888 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13889 "at 0x%x [in module %s]"),
13890 offset
, src_die
->offset
, cu
->objfile
->name
);
13895 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13896 value is intended for DW_OP_call*. You must call xfree on returned
13897 dwarf2_locexpr_baton->data. */
13899 struct dwarf2_locexpr_baton
13900 dwarf2_fetch_die_location_block (unsigned int offset
,
13901 struct dwarf2_per_cu_data
*per_cu
,
13902 CORE_ADDR (*get_frame_pc
) (void *baton
),
13905 struct dwarf2_cu
*cu
;
13906 struct die_info
*die
;
13907 struct attribute
*attr
;
13908 struct dwarf2_locexpr_baton retval
;
13910 dw2_setup (per_cu
->objfile
);
13912 if (per_cu
->cu
== NULL
)
13916 die
= follow_die_offset (offset
, &cu
);
13918 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13919 offset
, per_cu
->cu
->objfile
->name
);
13921 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13924 /* DWARF: "If there is no such attribute, then there is no effect.". */
13926 retval
.data
= NULL
;
13929 else if (attr_form_is_section_offset (attr
))
13931 struct dwarf2_loclist_baton loclist_baton
;
13932 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13935 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13937 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13939 retval
.size
= size
;
13943 if (!attr_form_is_block (attr
))
13944 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13945 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13946 offset
, per_cu
->cu
->objfile
->name
);
13948 retval
.data
= DW_BLOCK (attr
)->data
;
13949 retval
.size
= DW_BLOCK (attr
)->size
;
13951 retval
.per_cu
= cu
->per_cu
;
13954 retval
.data
= xmemdup (retval
.data
, retval
.size
, retval
.size
);
13956 age_cached_comp_units ();
13961 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13965 dwarf2_get_die_type (unsigned int die_offset
,
13966 struct dwarf2_per_cu_data
*per_cu
)
13968 dw2_setup (per_cu
->objfile
);
13969 return get_die_type_at_offset (die_offset
, per_cu
);
13972 /* Follow the signature attribute ATTR in SRC_DIE.
13973 On entry *REF_CU is the CU of SRC_DIE.
13974 On exit *REF_CU is the CU of the result. */
13976 static struct die_info
*
13977 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13978 struct dwarf2_cu
**ref_cu
)
13980 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13981 struct die_info temp_die
;
13982 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13983 struct dwarf2_cu
*sig_cu
;
13984 struct die_info
*die
;
13986 /* sig_type will be NULL if the signatured type is missing from
13988 if (sig_type
== NULL
)
13989 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13990 "at 0x%x [in module %s]"),
13991 src_die
->offset
, objfile
->name
);
13993 /* If necessary, add it to the queue and load its DIEs. */
13995 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13996 read_signatured_type (objfile
, sig_type
);
13998 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14000 sig_cu
= sig_type
->per_cu
.cu
;
14001 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14002 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14009 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14010 "from DIE at 0x%x [in module %s]"),
14011 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14014 /* Given an offset of a signatured type, return its signatured_type. */
14016 static struct signatured_type
*
14017 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14018 struct dwarf2_section_info
*section
,
14019 unsigned int offset
)
14021 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14022 unsigned int length
, initial_length_size
;
14023 unsigned int sig_offset
;
14024 struct signatured_type find_entry
, *type_sig
;
14026 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14027 sig_offset
= (initial_length_size
14029 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14030 + 1 /*address_size*/);
14031 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14032 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14034 /* This is only used to lookup previously recorded types.
14035 If we didn't find it, it's our bug. */
14036 gdb_assert (type_sig
!= NULL
);
14037 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14042 /* Read in signatured type at OFFSET and build its CU and die(s). */
14045 read_signatured_type_at_offset (struct objfile
*objfile
,
14046 struct dwarf2_section_info
*sect
,
14047 unsigned int offset
)
14049 struct signatured_type
*type_sig
;
14051 dwarf2_read_section (objfile
, sect
);
14053 /* We have the section offset, but we need the signature to do the
14054 hash table lookup. */
14055 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14057 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14059 read_signatured_type (objfile
, type_sig
);
14061 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14064 /* Read in a signatured type and build its CU and DIEs. */
14067 read_signatured_type (struct objfile
*objfile
,
14068 struct signatured_type
*type_sig
)
14070 gdb_byte
*types_ptr
;
14071 struct die_reader_specs reader_specs
;
14072 struct dwarf2_cu
*cu
;
14073 ULONGEST signature
;
14074 struct cleanup
*back_to
, *free_cu_cleanup
;
14075 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14077 dwarf2_read_section (objfile
, section
);
14078 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14080 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14082 cu
= xmalloc (sizeof (*cu
));
14083 init_one_comp_unit (cu
, objfile
);
14085 type_sig
->per_cu
.cu
= cu
;
14086 cu
->per_cu
= &type_sig
->per_cu
;
14088 /* If an error occurs while loading, release our storage. */
14089 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14091 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14092 types_ptr
, objfile
->obfd
);
14093 gdb_assert (signature
== type_sig
->signature
);
14096 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14100 &cu
->comp_unit_obstack
,
14101 hashtab_obstack_allocate
,
14102 dummy_obstack_deallocate
);
14104 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14105 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14107 init_cu_die_reader (&reader_specs
, cu
);
14109 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14112 /* We try not to read any attributes in this function, because not
14113 all objfiles needed for references have been loaded yet, and symbol
14114 table processing isn't initialized. But we have to set the CU language,
14115 or we won't be able to build types correctly. */
14116 prepare_one_comp_unit (cu
, cu
->dies
);
14118 do_cleanups (back_to
);
14120 /* We've successfully allocated this compilation unit. Let our caller
14121 clean it up when finished with it. */
14122 discard_cleanups (free_cu_cleanup
);
14124 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14125 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14128 /* Decode simple location descriptions.
14129 Given a pointer to a dwarf block that defines a location, compute
14130 the location and return the value.
14132 NOTE drow/2003-11-18: This function is called in two situations
14133 now: for the address of static or global variables (partial symbols
14134 only) and for offsets into structures which are expected to be
14135 (more or less) constant. The partial symbol case should go away,
14136 and only the constant case should remain. That will let this
14137 function complain more accurately. A few special modes are allowed
14138 without complaint for global variables (for instance, global
14139 register values and thread-local values).
14141 A location description containing no operations indicates that the
14142 object is optimized out. The return value is 0 for that case.
14143 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14144 callers will only want a very basic result and this can become a
14147 Note that stack[0] is unused except as a default error return. */
14150 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14152 struct objfile
*objfile
= cu
->objfile
;
14154 int size
= blk
->size
;
14155 gdb_byte
*data
= blk
->data
;
14156 CORE_ADDR stack
[64];
14158 unsigned int bytes_read
, unsnd
;
14164 stack
[++stacki
] = 0;
14203 stack
[++stacki
] = op
- DW_OP_lit0
;
14238 stack
[++stacki
] = op
- DW_OP_reg0
;
14240 dwarf2_complex_location_expr_complaint ();
14244 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14246 stack
[++stacki
] = unsnd
;
14248 dwarf2_complex_location_expr_complaint ();
14252 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14257 case DW_OP_const1u
:
14258 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14262 case DW_OP_const1s
:
14263 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14267 case DW_OP_const2u
:
14268 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14272 case DW_OP_const2s
:
14273 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14277 case DW_OP_const4u
:
14278 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14282 case DW_OP_const4s
:
14283 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14288 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14294 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14299 stack
[stacki
+ 1] = stack
[stacki
];
14304 stack
[stacki
- 1] += stack
[stacki
];
14308 case DW_OP_plus_uconst
:
14309 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14315 stack
[stacki
- 1] -= stack
[stacki
];
14320 /* If we're not the last op, then we definitely can't encode
14321 this using GDB's address_class enum. This is valid for partial
14322 global symbols, although the variable's address will be bogus
14325 dwarf2_complex_location_expr_complaint ();
14328 case DW_OP_GNU_push_tls_address
:
14329 /* The top of the stack has the offset from the beginning
14330 of the thread control block at which the variable is located. */
14331 /* Nothing should follow this operator, so the top of stack would
14333 /* This is valid for partial global symbols, but the variable's
14334 address will be bogus in the psymtab. */
14336 dwarf2_complex_location_expr_complaint ();
14339 case DW_OP_GNU_uninit
:
14344 const char *name
= dwarf_stack_op_name (op
);
14347 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14350 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14354 return (stack
[stacki
]);
14357 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14358 outside of the allocated space. Also enforce minimum>0. */
14359 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14361 complaint (&symfile_complaints
,
14362 _("location description stack overflow"));
14368 complaint (&symfile_complaints
,
14369 _("location description stack underflow"));
14373 return (stack
[stacki
]);
14376 /* memory allocation interface */
14378 static struct dwarf_block
*
14379 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14381 struct dwarf_block
*blk
;
14383 blk
= (struct dwarf_block
*)
14384 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14388 static struct abbrev_info
*
14389 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14391 struct abbrev_info
*abbrev
;
14393 abbrev
= (struct abbrev_info
*)
14394 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14395 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14399 static struct die_info
*
14400 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14402 struct die_info
*die
;
14403 size_t size
= sizeof (struct die_info
);
14406 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14408 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14409 memset (die
, 0, sizeof (struct die_info
));
14414 /* Macro support. */
14416 /* Return the full name of file number I in *LH's file name table.
14417 Use COMP_DIR as the name of the current directory of the
14418 compilation. The result is allocated using xmalloc; the caller is
14419 responsible for freeing it. */
14421 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14423 /* Is the file number a valid index into the line header's file name
14424 table? Remember that file numbers start with one, not zero. */
14425 if (1 <= file
&& file
<= lh
->num_file_names
)
14427 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14429 if (IS_ABSOLUTE_PATH (fe
->name
))
14430 return xstrdup (fe
->name
);
14438 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14444 dir_len
= strlen (dir
);
14445 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14446 strcpy (full_name
, dir
);
14447 full_name
[dir_len
] = '/';
14448 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14452 return xstrdup (fe
->name
);
14457 /* The compiler produced a bogus file number. We can at least
14458 record the macro definitions made in the file, even if we
14459 won't be able to find the file by name. */
14460 char fake_name
[80];
14462 sprintf (fake_name
, "<bad macro file number %d>", file
);
14464 complaint (&symfile_complaints
,
14465 _("bad file number in macro information (%d)"),
14468 return xstrdup (fake_name
);
14473 static struct macro_source_file
*
14474 macro_start_file (int file
, int line
,
14475 struct macro_source_file
*current_file
,
14476 const char *comp_dir
,
14477 struct line_header
*lh
, struct objfile
*objfile
)
14479 /* The full name of this source file. */
14480 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14482 /* We don't create a macro table for this compilation unit
14483 at all until we actually get a filename. */
14484 if (! pending_macros
)
14485 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14486 objfile
->macro_cache
);
14488 if (! current_file
)
14489 /* If we have no current file, then this must be the start_file
14490 directive for the compilation unit's main source file. */
14491 current_file
= macro_set_main (pending_macros
, full_name
);
14493 current_file
= macro_include (current_file
, line
, full_name
);
14497 return current_file
;
14501 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14502 followed by a null byte. */
14504 copy_string (const char *buf
, int len
)
14506 char *s
= xmalloc (len
+ 1);
14508 memcpy (s
, buf
, len
);
14514 static const char *
14515 consume_improper_spaces (const char *p
, const char *body
)
14519 complaint (&symfile_complaints
,
14520 _("macro definition contains spaces "
14521 "in formal argument list:\n`%s'"),
14533 parse_macro_definition (struct macro_source_file
*file
, int line
,
14538 /* The body string takes one of two forms. For object-like macro
14539 definitions, it should be:
14541 <macro name> " " <definition>
14543 For function-like macro definitions, it should be:
14545 <macro name> "() " <definition>
14547 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14549 Spaces may appear only where explicitly indicated, and in the
14552 The Dwarf 2 spec says that an object-like macro's name is always
14553 followed by a space, but versions of GCC around March 2002 omit
14554 the space when the macro's definition is the empty string.
14556 The Dwarf 2 spec says that there should be no spaces between the
14557 formal arguments in a function-like macro's formal argument list,
14558 but versions of GCC around March 2002 include spaces after the
14562 /* Find the extent of the macro name. The macro name is terminated
14563 by either a space or null character (for an object-like macro) or
14564 an opening paren (for a function-like macro). */
14565 for (p
= body
; *p
; p
++)
14566 if (*p
== ' ' || *p
== '(')
14569 if (*p
== ' ' || *p
== '\0')
14571 /* It's an object-like macro. */
14572 int name_len
= p
- body
;
14573 char *name
= copy_string (body
, name_len
);
14574 const char *replacement
;
14577 replacement
= body
+ name_len
+ 1;
14580 dwarf2_macro_malformed_definition_complaint (body
);
14581 replacement
= body
+ name_len
;
14584 macro_define_object (file
, line
, name
, replacement
);
14588 else if (*p
== '(')
14590 /* It's a function-like macro. */
14591 char *name
= copy_string (body
, p
- body
);
14594 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14598 p
= consume_improper_spaces (p
, body
);
14600 /* Parse the formal argument list. */
14601 while (*p
&& *p
!= ')')
14603 /* Find the extent of the current argument name. */
14604 const char *arg_start
= p
;
14606 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14609 if (! *p
|| p
== arg_start
)
14610 dwarf2_macro_malformed_definition_complaint (body
);
14613 /* Make sure argv has room for the new argument. */
14614 if (argc
>= argv_size
)
14617 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14620 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14623 p
= consume_improper_spaces (p
, body
);
14625 /* Consume the comma, if present. */
14630 p
= consume_improper_spaces (p
, body
);
14639 /* Perfectly formed definition, no complaints. */
14640 macro_define_function (file
, line
, name
,
14641 argc
, (const char **) argv
,
14643 else if (*p
== '\0')
14645 /* Complain, but do define it. */
14646 dwarf2_macro_malformed_definition_complaint (body
);
14647 macro_define_function (file
, line
, name
,
14648 argc
, (const char **) argv
,
14652 /* Just complain. */
14653 dwarf2_macro_malformed_definition_complaint (body
);
14656 /* Just complain. */
14657 dwarf2_macro_malformed_definition_complaint (body
);
14663 for (i
= 0; i
< argc
; i
++)
14669 dwarf2_macro_malformed_definition_complaint (body
);
14674 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14675 char *comp_dir
, bfd
*abfd
,
14676 struct dwarf2_cu
*cu
)
14678 gdb_byte
*mac_ptr
, *mac_end
;
14679 struct macro_source_file
*current_file
= 0;
14680 enum dwarf_macinfo_record_type macinfo_type
;
14681 int at_commandline
;
14683 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14684 &dwarf2_per_objfile
->macinfo
);
14685 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14687 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14691 /* First pass: Find the name of the base filename.
14692 This filename is needed in order to process all macros whose definition
14693 (or undefinition) comes from the command line. These macros are defined
14694 before the first DW_MACINFO_start_file entry, and yet still need to be
14695 associated to the base file.
14697 To determine the base file name, we scan the macro definitions until we
14698 reach the first DW_MACINFO_start_file entry. We then initialize
14699 CURRENT_FILE accordingly so that any macro definition found before the
14700 first DW_MACINFO_start_file can still be associated to the base file. */
14702 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14703 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14704 + dwarf2_per_objfile
->macinfo
.size
;
14708 /* Do we at least have room for a macinfo type byte? */
14709 if (mac_ptr
>= mac_end
)
14711 /* Complaint is printed during the second pass as GDB will probably
14712 stop the first pass earlier upon finding
14713 DW_MACINFO_start_file. */
14717 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14720 switch (macinfo_type
)
14722 /* A zero macinfo type indicates the end of the macro
14727 case DW_MACINFO_define
:
14728 case DW_MACINFO_undef
:
14729 /* Only skip the data by MAC_PTR. */
14731 unsigned int bytes_read
;
14733 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14734 mac_ptr
+= bytes_read
;
14735 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14736 mac_ptr
+= bytes_read
;
14740 case DW_MACINFO_start_file
:
14742 unsigned int bytes_read
;
14745 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14746 mac_ptr
+= bytes_read
;
14747 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14748 mac_ptr
+= bytes_read
;
14750 current_file
= macro_start_file (file
, line
, current_file
,
14751 comp_dir
, lh
, cu
->objfile
);
14755 case DW_MACINFO_end_file
:
14756 /* No data to skip by MAC_PTR. */
14759 case DW_MACINFO_vendor_ext
:
14760 /* Only skip the data by MAC_PTR. */
14762 unsigned int bytes_read
;
14764 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14765 mac_ptr
+= bytes_read
;
14766 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14767 mac_ptr
+= bytes_read
;
14774 } while (macinfo_type
!= 0 && current_file
== NULL
);
14776 /* Second pass: Process all entries.
14778 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14779 command-line macro definitions/undefinitions. This flag is unset when we
14780 reach the first DW_MACINFO_start_file entry. */
14782 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14784 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14785 GDB is still reading the definitions from command line. First
14786 DW_MACINFO_start_file will need to be ignored as it was already executed
14787 to create CURRENT_FILE for the main source holding also the command line
14788 definitions. On first met DW_MACINFO_start_file this flag is reset to
14789 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14791 at_commandline
= 1;
14795 /* Do we at least have room for a macinfo type byte? */
14796 if (mac_ptr
>= mac_end
)
14798 dwarf2_macros_too_long_complaint ();
14802 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14805 switch (macinfo_type
)
14807 /* A zero macinfo type indicates the end of the macro
14812 case DW_MACINFO_define
:
14813 case DW_MACINFO_undef
:
14815 unsigned int bytes_read
;
14819 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14820 mac_ptr
+= bytes_read
;
14821 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14822 mac_ptr
+= bytes_read
;
14824 if (! current_file
)
14826 /* DWARF violation as no main source is present. */
14827 complaint (&symfile_complaints
,
14828 _("debug info with no main source gives macro %s "
14830 macinfo_type
== DW_MACINFO_define
?
14832 macinfo_type
== DW_MACINFO_undef
?
14833 _("undefinition") :
14834 _("something-or-other"), line
, body
);
14837 if ((line
== 0 && !at_commandline
)
14838 || (line
!= 0 && at_commandline
))
14839 complaint (&symfile_complaints
,
14840 _("debug info gives %s macro %s with %s line %d: %s"),
14841 at_commandline
? _("command-line") : _("in-file"),
14842 macinfo_type
== DW_MACINFO_define
?
14844 macinfo_type
== DW_MACINFO_undef
?
14845 _("undefinition") :
14846 _("something-or-other"),
14847 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14849 if (macinfo_type
== DW_MACINFO_define
)
14850 parse_macro_definition (current_file
, line
, body
);
14851 else if (macinfo_type
== DW_MACINFO_undef
)
14852 macro_undef (current_file
, line
, body
);
14856 case DW_MACINFO_start_file
:
14858 unsigned int bytes_read
;
14861 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14862 mac_ptr
+= bytes_read
;
14863 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14864 mac_ptr
+= bytes_read
;
14866 if ((line
== 0 && !at_commandline
)
14867 || (line
!= 0 && at_commandline
))
14868 complaint (&symfile_complaints
,
14869 _("debug info gives source %d included "
14870 "from %s at %s line %d"),
14871 file
, at_commandline
? _("command-line") : _("file"),
14872 line
== 0 ? _("zero") : _("non-zero"), line
);
14874 if (at_commandline
)
14876 /* This DW_MACINFO_start_file was executed in the pass one. */
14877 at_commandline
= 0;
14880 current_file
= macro_start_file (file
, line
,
14881 current_file
, comp_dir
,
14886 case DW_MACINFO_end_file
:
14887 if (! current_file
)
14888 complaint (&symfile_complaints
,
14889 _("macro debug info has an unmatched "
14890 "`close_file' directive"));
14893 current_file
= current_file
->included_by
;
14894 if (! current_file
)
14896 enum dwarf_macinfo_record_type next_type
;
14898 /* GCC circa March 2002 doesn't produce the zero
14899 type byte marking the end of the compilation
14900 unit. Complain if it's not there, but exit no
14903 /* Do we at least have room for a macinfo type byte? */
14904 if (mac_ptr
>= mac_end
)
14906 dwarf2_macros_too_long_complaint ();
14910 /* We don't increment mac_ptr here, so this is just
14912 next_type
= read_1_byte (abfd
, mac_ptr
);
14913 if (next_type
!= 0)
14914 complaint (&symfile_complaints
,
14915 _("no terminating 0-type entry for "
14916 "macros in `.debug_macinfo' section"));
14923 case DW_MACINFO_vendor_ext
:
14925 unsigned int bytes_read
;
14928 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14929 mac_ptr
+= bytes_read
;
14930 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14931 mac_ptr
+= bytes_read
;
14933 /* We don't recognize any vendor extensions. */
14937 } while (macinfo_type
!= 0);
14940 /* Check if the attribute's form is a DW_FORM_block*
14941 if so return true else false. */
14943 attr_form_is_block (struct attribute
*attr
)
14945 return (attr
== NULL
? 0 :
14946 attr
->form
== DW_FORM_block1
14947 || attr
->form
== DW_FORM_block2
14948 || attr
->form
== DW_FORM_block4
14949 || attr
->form
== DW_FORM_block
14950 || attr
->form
== DW_FORM_exprloc
);
14953 /* Return non-zero if ATTR's value is a section offset --- classes
14954 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14955 You may use DW_UNSND (attr) to retrieve such offsets.
14957 Section 7.5.4, "Attribute Encodings", explains that no attribute
14958 may have a value that belongs to more than one of these classes; it
14959 would be ambiguous if we did, because we use the same forms for all
14962 attr_form_is_section_offset (struct attribute
*attr
)
14964 return (attr
->form
== DW_FORM_data4
14965 || attr
->form
== DW_FORM_data8
14966 || attr
->form
== DW_FORM_sec_offset
);
14970 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14971 zero otherwise. When this function returns true, you can apply
14972 dwarf2_get_attr_constant_value to it.
14974 However, note that for some attributes you must check
14975 attr_form_is_section_offset before using this test. DW_FORM_data4
14976 and DW_FORM_data8 are members of both the constant class, and of
14977 the classes that contain offsets into other debug sections
14978 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14979 that, if an attribute's can be either a constant or one of the
14980 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14981 taken as section offsets, not constants. */
14983 attr_form_is_constant (struct attribute
*attr
)
14985 switch (attr
->form
)
14987 case DW_FORM_sdata
:
14988 case DW_FORM_udata
:
14989 case DW_FORM_data1
:
14990 case DW_FORM_data2
:
14991 case DW_FORM_data4
:
14992 case DW_FORM_data8
:
14999 /* A helper function that fills in a dwarf2_loclist_baton. */
15002 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15003 struct dwarf2_loclist_baton
*baton
,
15004 struct attribute
*attr
)
15006 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15007 &dwarf2_per_objfile
->loc
);
15009 baton
->per_cu
= cu
->per_cu
;
15010 gdb_assert (baton
->per_cu
);
15011 /* We don't know how long the location list is, but make sure we
15012 don't run off the edge of the section. */
15013 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15014 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15015 baton
->base_address
= cu
->base_address
;
15019 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15020 struct dwarf2_cu
*cu
)
15022 if (attr_form_is_section_offset (attr
)
15023 /* ".debug_loc" may not exist at all, or the offset may be outside
15024 the section. If so, fall through to the complaint in the
15026 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15027 &dwarf2_per_objfile
->loc
))
15029 struct dwarf2_loclist_baton
*baton
;
15031 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15032 sizeof (struct dwarf2_loclist_baton
));
15034 fill_in_loclist_baton (cu
, baton
, attr
);
15036 if (cu
->base_known
== 0)
15037 complaint (&symfile_complaints
,
15038 _("Location list used without "
15039 "specifying the CU base address."));
15041 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15042 SYMBOL_LOCATION_BATON (sym
) = baton
;
15046 struct dwarf2_locexpr_baton
*baton
;
15048 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15049 sizeof (struct dwarf2_locexpr_baton
));
15050 baton
->per_cu
= cu
->per_cu
;
15051 gdb_assert (baton
->per_cu
);
15053 if (attr_form_is_block (attr
))
15055 /* Note that we're just copying the block's data pointer
15056 here, not the actual data. We're still pointing into the
15057 info_buffer for SYM's objfile; right now we never release
15058 that buffer, but when we do clean up properly this may
15060 baton
->size
= DW_BLOCK (attr
)->size
;
15061 baton
->data
= DW_BLOCK (attr
)->data
;
15065 dwarf2_invalid_attrib_class_complaint ("location description",
15066 SYMBOL_NATURAL_NAME (sym
));
15068 baton
->data
= NULL
;
15071 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15072 SYMBOL_LOCATION_BATON (sym
) = baton
;
15076 /* Return the OBJFILE associated with the compilation unit CU. If CU
15077 came from a separate debuginfo file, then the master objfile is
15081 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15083 struct objfile
*objfile
= per_cu
->objfile
;
15085 /* Return the master objfile, so that we can report and look up the
15086 correct file containing this variable. */
15087 if (objfile
->separate_debug_objfile_backlink
)
15088 objfile
= objfile
->separate_debug_objfile_backlink
;
15093 /* Return the address size given in the compilation unit header for CU. */
15096 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15099 return per_cu
->cu
->header
.addr_size
;
15102 /* If the CU is not currently read in, we re-read its header. */
15103 struct objfile
*objfile
= per_cu
->objfile
;
15104 struct dwarf2_per_objfile
*per_objfile
15105 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15106 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15107 struct comp_unit_head cu_header
;
15109 memset (&cu_header
, 0, sizeof cu_header
);
15110 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15111 return cu_header
.addr_size
;
15115 /* Return the offset size given in the compilation unit header for CU. */
15118 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15121 return per_cu
->cu
->header
.offset_size
;
15124 /* If the CU is not currently read in, we re-read its header. */
15125 struct objfile
*objfile
= per_cu
->objfile
;
15126 struct dwarf2_per_objfile
*per_objfile
15127 = objfile_data (objfile
, dwarf2_objfile_data_key
);
15128 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15129 struct comp_unit_head cu_header
;
15131 memset (&cu_header
, 0, sizeof cu_header
);
15132 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
15133 return cu_header
.offset_size
;
15137 /* Return the text offset of the CU. The returned offset comes from
15138 this CU's objfile. If this objfile came from a separate debuginfo
15139 file, then the offset may be different from the corresponding
15140 offset in the parent objfile. */
15143 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15145 struct objfile
*objfile
= per_cu
->objfile
;
15147 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15150 /* Locate the .debug_info compilation unit from CU's objfile which contains
15151 the DIE at OFFSET. Raises an error on failure. */
15153 static struct dwarf2_per_cu_data
*
15154 dwarf2_find_containing_comp_unit (unsigned int offset
,
15155 struct objfile
*objfile
)
15157 struct dwarf2_per_cu_data
*this_cu
;
15161 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15164 int mid
= low
+ (high
- low
) / 2;
15166 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15171 gdb_assert (low
== high
);
15172 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15175 error (_("Dwarf Error: could not find partial DIE containing "
15176 "offset 0x%lx [in module %s]"),
15177 (long) offset
, bfd_get_filename (objfile
->obfd
));
15179 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15180 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15184 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15185 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15186 && offset
>= this_cu
->offset
+ this_cu
->length
)
15187 error (_("invalid dwarf2 offset %u"), offset
);
15188 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15193 /* Locate the compilation unit from OBJFILE which is located at exactly
15194 OFFSET. Raises an error on failure. */
15196 static struct dwarf2_per_cu_data
*
15197 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15199 struct dwarf2_per_cu_data
*this_cu
;
15201 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15202 if (this_cu
->offset
!= offset
)
15203 error (_("no compilation unit with offset %u."), offset
);
15207 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15210 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15212 memset (cu
, 0, sizeof (*cu
));
15213 cu
->objfile
= objfile
;
15214 obstack_init (&cu
->comp_unit_obstack
);
15217 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15220 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15222 struct attribute
*attr
;
15224 /* Set the language we're debugging. */
15225 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15227 set_cu_language (DW_UNSND (attr
), cu
);
15230 cu
->language
= language_minimal
;
15231 cu
->language_defn
= language_def (cu
->language
);
15235 /* Release one cached compilation unit, CU. We unlink it from the tree
15236 of compilation units, but we don't remove it from the read_in_chain;
15237 the caller is responsible for that.
15238 NOTE: DATA is a void * because this function is also used as a
15239 cleanup routine. */
15242 free_one_comp_unit (void *data
)
15244 struct dwarf2_cu
*cu
= data
;
15246 if (cu
->per_cu
!= NULL
)
15247 cu
->per_cu
->cu
= NULL
;
15250 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15255 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15256 when we're finished with it. We can't free the pointer itself, but be
15257 sure to unlink it from the cache. Also release any associated storage
15258 and perform cache maintenance.
15260 Only used during partial symbol parsing. */
15263 free_stack_comp_unit (void *data
)
15265 struct dwarf2_cu
*cu
= data
;
15267 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15268 cu
->partial_dies
= NULL
;
15270 if (cu
->per_cu
!= NULL
)
15272 /* This compilation unit is on the stack in our caller, so we
15273 should not xfree it. Just unlink it. */
15274 cu
->per_cu
->cu
= NULL
;
15277 /* If we had a per-cu pointer, then we may have other compilation
15278 units loaded, so age them now. */
15279 age_cached_comp_units ();
15283 /* Free all cached compilation units. */
15286 free_cached_comp_units (void *data
)
15288 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15290 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15291 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15292 while (per_cu
!= NULL
)
15294 struct dwarf2_per_cu_data
*next_cu
;
15296 next_cu
= per_cu
->cu
->read_in_chain
;
15298 free_one_comp_unit (per_cu
->cu
);
15299 *last_chain
= next_cu
;
15305 /* Increase the age counter on each cached compilation unit, and free
15306 any that are too old. */
15309 age_cached_comp_units (void)
15311 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15313 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15314 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15315 while (per_cu
!= NULL
)
15317 per_cu
->cu
->last_used
++;
15318 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15319 dwarf2_mark (per_cu
->cu
);
15320 per_cu
= per_cu
->cu
->read_in_chain
;
15323 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15324 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15325 while (per_cu
!= NULL
)
15327 struct dwarf2_per_cu_data
*next_cu
;
15329 next_cu
= per_cu
->cu
->read_in_chain
;
15331 if (!per_cu
->cu
->mark
)
15333 free_one_comp_unit (per_cu
->cu
);
15334 *last_chain
= next_cu
;
15337 last_chain
= &per_cu
->cu
->read_in_chain
;
15343 /* Remove a single compilation unit from the cache. */
15346 free_one_cached_comp_unit (void *target_cu
)
15348 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15350 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15351 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15352 while (per_cu
!= NULL
)
15354 struct dwarf2_per_cu_data
*next_cu
;
15356 next_cu
= per_cu
->cu
->read_in_chain
;
15358 if (per_cu
->cu
== target_cu
)
15360 free_one_comp_unit (per_cu
->cu
);
15361 *last_chain
= next_cu
;
15365 last_chain
= &per_cu
->cu
->read_in_chain
;
15371 /* Release all extra memory associated with OBJFILE. */
15374 dwarf2_free_objfile (struct objfile
*objfile
)
15376 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15378 if (dwarf2_per_objfile
== NULL
)
15381 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15382 free_cached_comp_units (NULL
);
15384 if (dwarf2_per_objfile
->quick_file_names_table
)
15385 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15387 /* Everything else should be on the objfile obstack. */
15390 /* A pair of DIE offset and GDB type pointer. We store these
15391 in a hash table separate from the DIEs, and preserve them
15392 when the DIEs are flushed out of cache. */
15394 struct dwarf2_offset_and_type
15396 unsigned int offset
;
15400 /* Hash function for a dwarf2_offset_and_type. */
15403 offset_and_type_hash (const void *item
)
15405 const struct dwarf2_offset_and_type
*ofs
= item
;
15407 return ofs
->offset
;
15410 /* Equality function for a dwarf2_offset_and_type. */
15413 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15415 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15416 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15418 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15421 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15422 table if necessary. For convenience, return TYPE.
15424 The DIEs reading must have careful ordering to:
15425 * Not cause infite loops trying to read in DIEs as a prerequisite for
15426 reading current DIE.
15427 * Not trying to dereference contents of still incompletely read in types
15428 while reading in other DIEs.
15429 * Enable referencing still incompletely read in types just by a pointer to
15430 the type without accessing its fields.
15432 Therefore caller should follow these rules:
15433 * Try to fetch any prerequisite types we may need to build this DIE type
15434 before building the type and calling set_die_type.
15435 * After building type call set_die_type for current DIE as soon as
15436 possible before fetching more types to complete the current type.
15437 * Make the type as complete as possible before fetching more types. */
15439 static struct type
*
15440 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15442 struct dwarf2_offset_and_type
**slot
, ofs
;
15443 struct objfile
*objfile
= cu
->objfile
;
15444 htab_t
*type_hash_ptr
;
15446 /* For Ada types, make sure that the gnat-specific data is always
15447 initialized (if not already set). There are a few types where
15448 we should not be doing so, because the type-specific area is
15449 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15450 where the type-specific area is used to store the floatformat).
15451 But this is not a problem, because the gnat-specific information
15452 is actually not needed for these types. */
15453 if (need_gnat_info (cu
)
15454 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15455 && TYPE_CODE (type
) != TYPE_CODE_FLT
15456 && !HAVE_GNAT_AUX_INFO (type
))
15457 INIT_GNAT_SPECIFIC (type
);
15459 if (cu
->per_cu
->debug_type_section
)
15460 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15462 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15464 if (*type_hash_ptr
== NULL
)
15467 = htab_create_alloc_ex (127,
15468 offset_and_type_hash
,
15469 offset_and_type_eq
,
15471 &objfile
->objfile_obstack
,
15472 hashtab_obstack_allocate
,
15473 dummy_obstack_deallocate
);
15476 ofs
.offset
= die
->offset
;
15478 slot
= (struct dwarf2_offset_and_type
**)
15479 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15481 complaint (&symfile_complaints
,
15482 _("A problem internal to GDB: DIE 0x%x has type already set"),
15484 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15489 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15490 table, or return NULL if the die does not have a saved type. */
15492 static struct type
*
15493 get_die_type_at_offset (unsigned int offset
,
15494 struct dwarf2_per_cu_data
*per_cu
)
15496 struct dwarf2_offset_and_type
*slot
, ofs
;
15499 if (per_cu
->debug_type_section
)
15500 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15502 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15503 if (type_hash
== NULL
)
15506 ofs
.offset
= offset
;
15507 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15514 /* Look up the type for DIE in the appropriate type_hash table,
15515 or return NULL if DIE does not have a saved type. */
15517 static struct type
*
15518 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15520 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15523 /* Add a dependence relationship from CU to REF_PER_CU. */
15526 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15527 struct dwarf2_per_cu_data
*ref_per_cu
)
15531 if (cu
->dependencies
== NULL
)
15533 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15534 NULL
, &cu
->comp_unit_obstack
,
15535 hashtab_obstack_allocate
,
15536 dummy_obstack_deallocate
);
15538 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15540 *slot
= ref_per_cu
;
15543 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15544 Set the mark field in every compilation unit in the
15545 cache that we must keep because we are keeping CU. */
15548 dwarf2_mark_helper (void **slot
, void *data
)
15550 struct dwarf2_per_cu_data
*per_cu
;
15552 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15554 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15555 reading of the chain. As such dependencies remain valid it is not much
15556 useful to track and undo them during QUIT cleanups. */
15557 if (per_cu
->cu
== NULL
)
15560 if (per_cu
->cu
->mark
)
15562 per_cu
->cu
->mark
= 1;
15564 if (per_cu
->cu
->dependencies
!= NULL
)
15565 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15570 /* Set the mark field in CU and in every other compilation unit in the
15571 cache that we must keep because we are keeping CU. */
15574 dwarf2_mark (struct dwarf2_cu
*cu
)
15579 if (cu
->dependencies
!= NULL
)
15580 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15584 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15588 per_cu
->cu
->mark
= 0;
15589 per_cu
= per_cu
->cu
->read_in_chain
;
15593 /* Trivial hash function for partial_die_info: the hash value of a DIE
15594 is its offset in .debug_info for this objfile. */
15597 partial_die_hash (const void *item
)
15599 const struct partial_die_info
*part_die
= item
;
15601 return part_die
->offset
;
15604 /* Trivial comparison function for partial_die_info structures: two DIEs
15605 are equal if they have the same offset. */
15608 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15610 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15611 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15613 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15616 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15617 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15620 set_dwarf2_cmd (char *args
, int from_tty
)
15622 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15626 show_dwarf2_cmd (char *args
, int from_tty
)
15628 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15631 /* If section described by INFO was mmapped, munmap it now. */
15634 munmap_section_buffer (struct dwarf2_section_info
*info
)
15636 if (info
->map_addr
!= NULL
)
15641 res
= munmap (info
->map_addr
, info
->map_len
);
15642 gdb_assert (res
== 0);
15644 /* Without HAVE_MMAP, we should never be here to begin with. */
15645 gdb_assert_not_reached ("no mmap support");
15650 /* munmap debug sections for OBJFILE, if necessary. */
15653 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15655 struct dwarf2_per_objfile
*data
= d
;
15657 struct dwarf2_section_info
*section
;
15659 /* This is sorted according to the order they're defined in to make it easier
15660 to keep in sync. */
15661 munmap_section_buffer (&data
->info
);
15662 munmap_section_buffer (&data
->abbrev
);
15663 munmap_section_buffer (&data
->line
);
15664 munmap_section_buffer (&data
->loc
);
15665 munmap_section_buffer (&data
->macinfo
);
15666 munmap_section_buffer (&data
->str
);
15667 munmap_section_buffer (&data
->ranges
);
15668 munmap_section_buffer (&data
->frame
);
15669 munmap_section_buffer (&data
->eh_frame
);
15670 munmap_section_buffer (&data
->gdb_index
);
15673 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
15675 munmap_section_buffer (section
);
15677 VEC_free (dwarf2_section_info_def
, data
->types
);
15681 /* The "save gdb-index" command. */
15683 /* The contents of the hash table we create when building the string
15685 struct strtab_entry
15687 offset_type offset
;
15691 /* Hash function for a strtab_entry.
15693 Function is used only during write_hash_table so no index format backward
15694 compatibility is needed. */
15697 hash_strtab_entry (const void *e
)
15699 const struct strtab_entry
*entry
= e
;
15700 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15703 /* Equality function for a strtab_entry. */
15706 eq_strtab_entry (const void *a
, const void *b
)
15708 const struct strtab_entry
*ea
= a
;
15709 const struct strtab_entry
*eb
= b
;
15710 return !strcmp (ea
->str
, eb
->str
);
15713 /* Create a strtab_entry hash table. */
15716 create_strtab (void)
15718 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15719 xfree
, xcalloc
, xfree
);
15722 /* Add a string to the constant pool. Return the string's offset in
15726 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15729 struct strtab_entry entry
;
15730 struct strtab_entry
*result
;
15733 slot
= htab_find_slot (table
, &entry
, INSERT
);
15738 result
= XNEW (struct strtab_entry
);
15739 result
->offset
= obstack_object_size (cpool
);
15741 obstack_grow_str0 (cpool
, str
);
15744 return result
->offset
;
15747 /* An entry in the symbol table. */
15748 struct symtab_index_entry
15750 /* The name of the symbol. */
15752 /* The offset of the name in the constant pool. */
15753 offset_type index_offset
;
15754 /* A sorted vector of the indices of all the CUs that hold an object
15756 VEC (offset_type
) *cu_indices
;
15759 /* The symbol table. This is a power-of-2-sized hash table. */
15760 struct mapped_symtab
15762 offset_type n_elements
;
15764 struct symtab_index_entry
**data
;
15767 /* Hash function for a symtab_index_entry. */
15770 hash_symtab_entry (const void *e
)
15772 const struct symtab_index_entry
*entry
= e
;
15773 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15774 sizeof (offset_type
) * VEC_length (offset_type
,
15775 entry
->cu_indices
),
15779 /* Equality function for a symtab_index_entry. */
15782 eq_symtab_entry (const void *a
, const void *b
)
15784 const struct symtab_index_entry
*ea
= a
;
15785 const struct symtab_index_entry
*eb
= b
;
15786 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15787 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15789 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15790 VEC_address (offset_type
, eb
->cu_indices
),
15791 sizeof (offset_type
) * len
);
15794 /* Destroy a symtab_index_entry. */
15797 delete_symtab_entry (void *p
)
15799 struct symtab_index_entry
*entry
= p
;
15800 VEC_free (offset_type
, entry
->cu_indices
);
15804 /* Create a hash table holding symtab_index_entry objects. */
15807 create_symbol_hash_table (void)
15809 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15810 delete_symtab_entry
, xcalloc
, xfree
);
15813 /* Create a new mapped symtab object. */
15815 static struct mapped_symtab
*
15816 create_mapped_symtab (void)
15818 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15819 symtab
->n_elements
= 0;
15820 symtab
->size
= 1024;
15821 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15825 /* Destroy a mapped_symtab. */
15828 cleanup_mapped_symtab (void *p
)
15830 struct mapped_symtab
*symtab
= p
;
15831 /* The contents of the array are freed when the other hash table is
15833 xfree (symtab
->data
);
15837 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15840 Function is used only during write_hash_table so no index format backward
15841 compatibility is needed. */
15843 static struct symtab_index_entry
**
15844 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15846 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
15848 index
= hash
& (symtab
->size
- 1);
15849 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15853 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15854 return &symtab
->data
[index
];
15855 index
= (index
+ step
) & (symtab
->size
- 1);
15859 /* Expand SYMTAB's hash table. */
15862 hash_expand (struct mapped_symtab
*symtab
)
15864 offset_type old_size
= symtab
->size
;
15866 struct symtab_index_entry
**old_entries
= symtab
->data
;
15869 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15871 for (i
= 0; i
< old_size
; ++i
)
15873 if (old_entries
[i
])
15875 struct symtab_index_entry
**slot
= find_slot (symtab
,
15876 old_entries
[i
]->name
);
15877 *slot
= old_entries
[i
];
15881 xfree (old_entries
);
15884 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15885 is the index of the CU in which the symbol appears. */
15888 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15889 offset_type cu_index
)
15891 struct symtab_index_entry
**slot
;
15893 ++symtab
->n_elements
;
15894 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15895 hash_expand (symtab
);
15897 slot
= find_slot (symtab
, name
);
15900 *slot
= XNEW (struct symtab_index_entry
);
15901 (*slot
)->name
= name
;
15902 (*slot
)->cu_indices
= NULL
;
15904 /* Don't push an index twice. Due to how we add entries we only
15905 have to check the last one. */
15906 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15907 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15908 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15911 /* Add a vector of indices to the constant pool. */
15914 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15915 struct symtab_index_entry
*entry
)
15919 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15922 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15923 offset_type val
= MAYBE_SWAP (len
);
15928 entry
->index_offset
= obstack_object_size (cpool
);
15930 obstack_grow (cpool
, &val
, sizeof (val
));
15932 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15935 val
= MAYBE_SWAP (iter
);
15936 obstack_grow (cpool
, &val
, sizeof (val
));
15941 struct symtab_index_entry
*old_entry
= *slot
;
15942 entry
->index_offset
= old_entry
->index_offset
;
15945 return entry
->index_offset
;
15948 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15949 constant pool entries going into the obstack CPOOL. */
15952 write_hash_table (struct mapped_symtab
*symtab
,
15953 struct obstack
*output
, struct obstack
*cpool
)
15956 htab_t symbol_hash_table
;
15959 symbol_hash_table
= create_symbol_hash_table ();
15960 str_table
= create_strtab ();
15962 /* We add all the index vectors to the constant pool first, to
15963 ensure alignment is ok. */
15964 for (i
= 0; i
< symtab
->size
; ++i
)
15966 if (symtab
->data
[i
])
15967 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15970 /* Now write out the hash table. */
15971 for (i
= 0; i
< symtab
->size
; ++i
)
15973 offset_type str_off
, vec_off
;
15975 if (symtab
->data
[i
])
15977 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15978 vec_off
= symtab
->data
[i
]->index_offset
;
15982 /* While 0 is a valid constant pool index, it is not valid
15983 to have 0 for both offsets. */
15988 str_off
= MAYBE_SWAP (str_off
);
15989 vec_off
= MAYBE_SWAP (vec_off
);
15991 obstack_grow (output
, &str_off
, sizeof (str_off
));
15992 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15995 htab_delete (str_table
);
15996 htab_delete (symbol_hash_table
);
15999 /* Struct to map psymtab to CU index in the index file. */
16000 struct psymtab_cu_index_map
16002 struct partial_symtab
*psymtab
;
16003 unsigned int cu_index
;
16007 hash_psymtab_cu_index (const void *item
)
16009 const struct psymtab_cu_index_map
*map
= item
;
16011 return htab_hash_pointer (map
->psymtab
);
16015 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16017 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16018 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16020 return lhs
->psymtab
== rhs
->psymtab
;
16023 /* Helper struct for building the address table. */
16024 struct addrmap_index_data
16026 struct objfile
*objfile
;
16027 struct obstack
*addr_obstack
;
16028 htab_t cu_index_htab
;
16030 /* Non-zero if the previous_* fields are valid.
16031 We can't write an entry until we see the next entry (since it is only then
16032 that we know the end of the entry). */
16033 int previous_valid
;
16034 /* Index of the CU in the table of all CUs in the index file. */
16035 unsigned int previous_cu_index
;
16036 /* Start address of the CU. */
16037 CORE_ADDR previous_cu_start
;
16040 /* Write an address entry to OBSTACK. */
16043 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16044 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16046 offset_type cu_index_to_write
;
16048 CORE_ADDR baseaddr
;
16050 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16052 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16053 obstack_grow (obstack
, addr
, 8);
16054 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16055 obstack_grow (obstack
, addr
, 8);
16056 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16057 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16060 /* Worker function for traversing an addrmap to build the address table. */
16063 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16065 struct addrmap_index_data
*data
= datap
;
16066 struct partial_symtab
*pst
= obj
;
16067 offset_type cu_index
;
16070 if (data
->previous_valid
)
16071 add_address_entry (data
->objfile
, data
->addr_obstack
,
16072 data
->previous_cu_start
, start_addr
,
16073 data
->previous_cu_index
);
16075 data
->previous_cu_start
= start_addr
;
16078 struct psymtab_cu_index_map find_map
, *map
;
16079 find_map
.psymtab
= pst
;
16080 map
= htab_find (data
->cu_index_htab
, &find_map
);
16081 gdb_assert (map
!= NULL
);
16082 data
->previous_cu_index
= map
->cu_index
;
16083 data
->previous_valid
= 1;
16086 data
->previous_valid
= 0;
16091 /* Write OBJFILE's address map to OBSTACK.
16092 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16093 in the index file. */
16096 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16097 htab_t cu_index_htab
)
16099 struct addrmap_index_data addrmap_index_data
;
16101 /* When writing the address table, we have to cope with the fact that
16102 the addrmap iterator only provides the start of a region; we have to
16103 wait until the next invocation to get the start of the next region. */
16105 addrmap_index_data
.objfile
= objfile
;
16106 addrmap_index_data
.addr_obstack
= obstack
;
16107 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16108 addrmap_index_data
.previous_valid
= 0;
16110 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16111 &addrmap_index_data
);
16113 /* It's highly unlikely the last entry (end address = 0xff...ff)
16114 is valid, but we should still handle it.
16115 The end address is recorded as the start of the next region, but that
16116 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16118 if (addrmap_index_data
.previous_valid
)
16119 add_address_entry (objfile
, obstack
,
16120 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16121 addrmap_index_data
.previous_cu_index
);
16124 /* Add a list of partial symbols to SYMTAB. */
16127 write_psymbols (struct mapped_symtab
*symtab
,
16129 struct partial_symbol
**psymp
,
16131 offset_type cu_index
,
16134 for (; count
-- > 0; ++psymp
)
16136 void **slot
, *lookup
;
16138 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16139 error (_("Ada is not currently supported by the index"));
16141 /* We only want to add a given psymbol once. However, we also
16142 want to account for whether it is global or static. So, we
16143 may add it twice, using slightly different values. */
16146 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16148 lookup
= (void *) val
;
16153 /* Only add a given psymbol once. */
16154 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16158 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16163 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16164 exception if there is an error. */
16167 write_obstack (FILE *file
, struct obstack
*obstack
)
16169 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16171 != obstack_object_size (obstack
))
16172 error (_("couldn't data write to file"));
16175 /* Unlink a file if the argument is not NULL. */
16178 unlink_if_set (void *p
)
16180 char **filename
= p
;
16182 unlink (*filename
);
16185 /* A helper struct used when iterating over debug_types. */
16186 struct signatured_type_index_data
16188 struct objfile
*objfile
;
16189 struct mapped_symtab
*symtab
;
16190 struct obstack
*types_list
;
16195 /* A helper function that writes a single signatured_type to an
16199 write_one_signatured_type (void **slot
, void *d
)
16201 struct signatured_type_index_data
*info
= d
;
16202 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16203 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16204 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16207 write_psymbols (info
->symtab
,
16209 info
->objfile
->global_psymbols
.list
16210 + psymtab
->globals_offset
,
16211 psymtab
->n_global_syms
, info
->cu_index
,
16213 write_psymbols (info
->symtab
,
16215 info
->objfile
->static_psymbols
.list
16216 + psymtab
->statics_offset
,
16217 psymtab
->n_static_syms
, info
->cu_index
,
16220 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16221 obstack_grow (info
->types_list
, val
, 8);
16222 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16223 obstack_grow (info
->types_list
, val
, 8);
16224 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16225 obstack_grow (info
->types_list
, val
, 8);
16232 /* A cleanup function for an htab_t. */
16235 cleanup_htab (void *arg
)
16240 /* Create an index file for OBJFILE in the directory DIR. */
16243 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16245 struct cleanup
*cleanup
;
16246 char *filename
, *cleanup_filename
;
16247 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16248 struct obstack cu_list
, types_cu_list
;
16251 struct mapped_symtab
*symtab
;
16252 offset_type val
, size_of_contents
, total_len
;
16256 htab_t cu_index_htab
;
16257 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16259 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16262 if (dwarf2_per_objfile
->using_index
)
16263 error (_("Cannot use an index to create the index"));
16265 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16266 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16268 if (stat (objfile
->name
, &st
) < 0)
16269 perror_with_name (objfile
->name
);
16271 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16272 INDEX_SUFFIX
, (char *) NULL
);
16273 cleanup
= make_cleanup (xfree
, filename
);
16275 out_file
= fopen (filename
, "wb");
16277 error (_("Can't open `%s' for writing"), filename
);
16279 cleanup_filename
= filename
;
16280 make_cleanup (unlink_if_set
, &cleanup_filename
);
16282 symtab
= create_mapped_symtab ();
16283 make_cleanup (cleanup_mapped_symtab
, symtab
);
16285 obstack_init (&addr_obstack
);
16286 make_cleanup_obstack_free (&addr_obstack
);
16288 obstack_init (&cu_list
);
16289 make_cleanup_obstack_free (&cu_list
);
16291 obstack_init (&types_cu_list
);
16292 make_cleanup_obstack_free (&types_cu_list
);
16294 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16295 NULL
, xcalloc
, xfree
);
16296 make_cleanup (cleanup_htab
, psyms_seen
);
16298 /* While we're scanning CU's create a table that maps a psymtab pointer
16299 (which is what addrmap records) to its index (which is what is recorded
16300 in the index file). This will later be needed to write the address
16302 cu_index_htab
= htab_create_alloc (100,
16303 hash_psymtab_cu_index
,
16304 eq_psymtab_cu_index
,
16305 NULL
, xcalloc
, xfree
);
16306 make_cleanup (cleanup_htab
, cu_index_htab
);
16307 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16308 xmalloc (sizeof (struct psymtab_cu_index_map
)
16309 * dwarf2_per_objfile
->n_comp_units
);
16310 make_cleanup (xfree
, psymtab_cu_index_map
);
16312 /* The CU list is already sorted, so we don't need to do additional
16313 work here. Also, the debug_types entries do not appear in
16314 all_comp_units, but only in their own hash table. */
16315 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16317 struct dwarf2_per_cu_data
*per_cu
16318 = dwarf2_per_objfile
->all_comp_units
[i
];
16319 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16321 struct psymtab_cu_index_map
*map
;
16324 write_psymbols (symtab
,
16326 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16327 psymtab
->n_global_syms
, i
,
16329 write_psymbols (symtab
,
16331 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16332 psymtab
->n_static_syms
, i
,
16335 map
= &psymtab_cu_index_map
[i
];
16336 map
->psymtab
= psymtab
;
16338 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16339 gdb_assert (slot
!= NULL
);
16340 gdb_assert (*slot
== NULL
);
16343 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16344 obstack_grow (&cu_list
, val
, 8);
16345 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16346 obstack_grow (&cu_list
, val
, 8);
16349 /* Dump the address map. */
16350 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16352 /* Write out the .debug_type entries, if any. */
16353 if (dwarf2_per_objfile
->signatured_types
)
16355 struct signatured_type_index_data sig_data
;
16357 sig_data
.objfile
= objfile
;
16358 sig_data
.symtab
= symtab
;
16359 sig_data
.types_list
= &types_cu_list
;
16360 sig_data
.psyms_seen
= psyms_seen
;
16361 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16362 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16363 write_one_signatured_type
, &sig_data
);
16366 obstack_init (&constant_pool
);
16367 make_cleanup_obstack_free (&constant_pool
);
16368 obstack_init (&symtab_obstack
);
16369 make_cleanup_obstack_free (&symtab_obstack
);
16370 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16372 obstack_init (&contents
);
16373 make_cleanup_obstack_free (&contents
);
16374 size_of_contents
= 6 * sizeof (offset_type
);
16375 total_len
= size_of_contents
;
16377 /* The version number. */
16378 val
= MAYBE_SWAP (5);
16379 obstack_grow (&contents
, &val
, sizeof (val
));
16381 /* The offset of the CU list from the start of the file. */
16382 val
= MAYBE_SWAP (total_len
);
16383 obstack_grow (&contents
, &val
, sizeof (val
));
16384 total_len
+= obstack_object_size (&cu_list
);
16386 /* The offset of the types CU list from the start of the file. */
16387 val
= MAYBE_SWAP (total_len
);
16388 obstack_grow (&contents
, &val
, sizeof (val
));
16389 total_len
+= obstack_object_size (&types_cu_list
);
16391 /* The offset of the address table from the start of the file. */
16392 val
= MAYBE_SWAP (total_len
);
16393 obstack_grow (&contents
, &val
, sizeof (val
));
16394 total_len
+= obstack_object_size (&addr_obstack
);
16396 /* The offset of the symbol table from the start of the file. */
16397 val
= MAYBE_SWAP (total_len
);
16398 obstack_grow (&contents
, &val
, sizeof (val
));
16399 total_len
+= obstack_object_size (&symtab_obstack
);
16401 /* The offset of the constant pool from the start of the file. */
16402 val
= MAYBE_SWAP (total_len
);
16403 obstack_grow (&contents
, &val
, sizeof (val
));
16404 total_len
+= obstack_object_size (&constant_pool
);
16406 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16408 write_obstack (out_file
, &contents
);
16409 write_obstack (out_file
, &cu_list
);
16410 write_obstack (out_file
, &types_cu_list
);
16411 write_obstack (out_file
, &addr_obstack
);
16412 write_obstack (out_file
, &symtab_obstack
);
16413 write_obstack (out_file
, &constant_pool
);
16417 /* We want to keep the file, so we set cleanup_filename to NULL
16418 here. See unlink_if_set. */
16419 cleanup_filename
= NULL
;
16421 do_cleanups (cleanup
);
16424 /* Implementation of the `save gdb-index' command.
16426 Note that the file format used by this command is documented in the
16427 GDB manual. Any changes here must be documented there. */
16430 save_gdb_index_command (char *arg
, int from_tty
)
16432 struct objfile
*objfile
;
16435 error (_("usage: save gdb-index DIRECTORY"));
16437 ALL_OBJFILES (objfile
)
16441 /* If the objfile does not correspond to an actual file, skip it. */
16442 if (stat (objfile
->name
, &st
) < 0)
16445 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16446 if (dwarf2_per_objfile
)
16448 volatile struct gdb_exception except
;
16450 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16452 write_psymtabs_to_index (objfile
, arg
);
16454 if (except
.reason
< 0)
16455 exception_fprintf (gdb_stderr
, except
,
16456 _("Error while writing index for `%s': "),
16464 int dwarf2_always_disassemble
;
16467 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16468 struct cmd_list_element
*c
, const char *value
)
16470 fprintf_filtered (file
,
16471 _("Whether to always disassemble "
16472 "DWARF expressions is %s.\n"),
16477 show_check_physname (struct ui_file
*file
, int from_tty
,
16478 struct cmd_list_element
*c
, const char *value
)
16480 fprintf_filtered (file
,
16481 _("Whether to check \"physname\" is %s.\n"),
16485 void _initialize_dwarf2_read (void);
16488 _initialize_dwarf2_read (void)
16490 struct cmd_list_element
*c
;
16492 dwarf2_objfile_data_key
16493 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16495 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16496 Set DWARF 2 specific variables.\n\
16497 Configure DWARF 2 variables such as the cache size"),
16498 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16499 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16501 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16502 Show DWARF 2 specific variables\n\
16503 Show DWARF 2 variables such as the cache size"),
16504 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16505 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16507 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16508 &dwarf2_max_cache_age
, _("\
16509 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16510 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16511 A higher limit means that cached compilation units will be stored\n\
16512 in memory longer, and more total memory will be used. Zero disables\n\
16513 caching, which can slow down startup."),
16515 show_dwarf2_max_cache_age
,
16516 &set_dwarf2_cmdlist
,
16517 &show_dwarf2_cmdlist
);
16519 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16520 &dwarf2_always_disassemble
, _("\
16521 Set whether `info address' always disassembles DWARF expressions."), _("\
16522 Show whether `info address' always disassembles DWARF expressions."), _("\
16523 When enabled, DWARF expressions are always printed in an assembly-like\n\
16524 syntax. When disabled, expressions will be printed in a more\n\
16525 conversational style, when possible."),
16527 show_dwarf2_always_disassemble
,
16528 &set_dwarf2_cmdlist
,
16529 &show_dwarf2_cmdlist
);
16531 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16532 Set debugging of the dwarf2 DIE reader."), _("\
16533 Show debugging of the dwarf2 DIE reader."), _("\
16534 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16535 The value is the maximum depth to print."),
16538 &setdebuglist
, &showdebuglist
);
16540 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
16541 Set cross-checking of \"physname\" code against demangler."), _("\
16542 Show cross-checking of \"physname\" code against demangler."), _("\
16543 When enabled, GDB's internal \"physname\" code is checked against\n\
16545 NULL
, show_check_physname
,
16546 &setdebuglist
, &showdebuglist
);
16548 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16550 Save a gdb-index file.\n\
16551 Usage: save gdb-index DIRECTORY"),
16553 set_cmd_completer (c
, filename_completer
);